#include <iostream>
using namespace std;

int main() {
  int N, num, count = 0;

  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> num;
    for (int j = 2; j <= num; j++) {
      if (j == num)
        count++;
      if (num % j == 0)
        break;
    }
  }
  cout << count << endl;
  return 0;
}

#include <iostream>
#include <math.h>
using namespace std;

int main() {
  int N, num, count = 0;
  bool flag;

  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> num;
    flag = true;
    if (num == 2)
      count++;
    if (num % 2 == 0)
      flag = false;
    for (int j = 3; j <= sqrt(num); j += 2) {
      if (num % j == 0) {
        flag = false;
        break;
      }
    }
    if (flag == true)
      count++;
  }
  cout << count << endl;
  return 0;
}


#include <iostream>
using namespace std;
int n;
int a;
int p = 0;

void is_prime() {
  for (int i = 2; i <= a / 2; i++) {
    if (a % i == 0) {
      return;
    }
  }

  p++;
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    is_prime();
  }

  cout << p << endl;
  return 0;
}

#include <iostream>
using namespace std;
int n;
int a;
int p = 0;

void is_prime() {
  for (int i = 2; i * i <= a; i++) {
    if (a % i == 0) {
      return;
    }
  }

  p++;
}

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    is_prime();
  }

  cout << p << endl;
  return 0;
}


#include <stdio.h>
#define N 10000

int isPrime(int);

int main() {

  int i, j, n, x, a[N], key, count = 0;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }

  for (i = 0; i < n; i++) {
    if (isPrime(a[i])) {
      count++;
    }
  }

  printf("%d\\n", count);

  return 0;
}

int isPrime(int x) {

  int i;
  if (x <= 1)
    return 0;

  for (i = 2; i < x - 1; i++) {
    if (x % i == 0) {
      return 0;
    }
  }

  return 1;
}

#include <math.h>
#include <stdio.h>
#define N 10000

int isPrime(int);

int main() {

  int i, j, n, x, key, count = 0;
  int a[N];
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }

  for (i = 0; i < n; i++) {
    if (isPrime(a[i])) {

      count++;
    }
  }

  printf("%d\\n", count);

  return 0;
}

int isPrime(int x) {

  int i;
  if (x <= 1)
    return 0;

  for (i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      return 0;
    }
  }

  return 1;
}


#include <cmath>
#include <iostream>
using namespace std;

int main() {
  long n;
  cin >> n;
  long cnt = 0;
  for (long i = 0; i < n; i++) {
    long m;
    cin >> m;
    bool p = 0;
    long o;
    o = sqrt(m);
    for (long j = 0; j < o; j++) {
      if (m % j == 0) {
        p = 1;
        break;
      }
    }
    if (p == 1)
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}

#include <cmath>
#include <iostream>
#include <vector>
using namespace std;

int main() {
  long n;
  cin >> n;
  long cnt = 0;
  for (long i = 0; i < n; i++) {
    long m;
    cin >> m;
    bool p = 1;
    long o;
    o = sqrt(m);
    for (long j = 0; j < o; j++) {
      if (j > 0 && m % (j + 1) == 0) {
        p = 0;
      }
    }
    if (p == 1)
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}


#include <iostream>

using namespace std;

bool isPrime(int num) {
  if (num != 2 && num % 2 == 0) {

    return false;
  }

  for (int i = 3; i < num; i += 2) {
    if (num % i == 0) {
      return false;
    }
  }

  return true;
}

int main() {
  int n;
  int num;
  int ans = 0;

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> num;
    if (isPrime(num)) {
      ans++;
    }
  }

  cout << ans << endl;
}

#include <cmath>
#include <iostream>

using namespace std;

bool isPrime(int num) {
  if (num != 2 && num % 2 == 0) {

    return false;
  }

  for (int i = 3; i <= num / i; i += 2) {
    if (num % i == 0) {
      return false;
    }
  }

  return true;
}

int main() {
  int n;
  int num;
  int ans = 0;

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> num;
    if (isPrime(num)) {
      ans++;
    }
  }

  cout << ans << endl;
}


#include <algorithm>
#include <cmath>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

bool isPrime(int x) {
  for (int i = 2; i < x; ++i) {
    if (x % i == 0) {
      return false;
    }
  }
  return true;
}

int main() {
  int n, x, c = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> x;
    if (isPrime(x)) {
      ++c;
    }
  }
  cout << c << endl;
}

#include <algorithm>
#include <cmath>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

bool isPrime(int x) {
  int max = sqrt(x);
  for (int i = 2; i <= max; ++i) {
    if (x % i == 0) {
      return false;
    }
  }
  return true;
}

int main() {
  int n, x, c = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> x;
    if (isPrime(x)) {
      ++c;
    }
  }
  cout << c << endl;
}


#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;

#define FOR(i, n, m) for (ll i = (ll)(m); i < (ll)(n); ++i)
#define REP(i, n) FOR(i, n, 0)
#define IREP(i, n) for (ll i = (ll)(n); i >= 0; --i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

struct PrimeList {
  PrimeList() { prime.clear(); };
  ~PrimeList(){};

  void init(int n) {
    std::vector<bool> isComposite(n + 1);
    for (int i = 2; i <= n; ++i) {
      if (isComposite[i])
        continue;
      prime.push_back(i);
      for (int j = i; j <= n; j += i) {
        isComposite[j] = true;
      }
    }
  }

  std::vector<int> prime;
};

int A[10005];

int main() {
  int N;
  cin >> N;
  PrimeList p;

  int max = 0;
  REP(i, N) {
    cin >> A[i];
    max = std::max(max, A[i]);
  }
  p.init(max);
  sort(A, A + N);
  int sum = 0;
  int pi = 0;
  REP(i, N) {
    while (p.prime[pi] <= A[i] && p.prime.size() > pi) {
      if (p.prime[pi] == A[i]) {
        sum++;
        break;
      }
      pi++;
    }
  }
  cout << sum << endl;
  return 0;
}

#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;

#define FOR(i, n, m) for (ll i = (ll)(m); i < (ll)(n); ++i)
#define REP(i, n) FOR(i, n, 0)
#define IREP(i, n) for (ll i = (ll)(n); i >= 0; --i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

struct PrimeList {
  PrimeList() { prime.clear(); };
  ~PrimeList(){};

  void init(int n) {
    std::vector<bool> isComposite(n + 1);
    for (int i = 2; i <= n; ++i) {
      if (isComposite[i])
        continue;
      prime.push_back(i);
      for (int j = i; j <= n; j += i) {
        isComposite[j] = true;
      }
    }
  }

  std::vector<int> prime;
};

int A[10005];

int main() {
  int N;
  cin >> N;
  PrimeList p;

  int max = 0;
  REP(i, N) {
    cin >> A[i];
    max = std::max(max, A[i]);
  }
  p.init(10001);
  sort(A, A + N);
  int sum = 0;
  int pi = 0;
  REP(i, N) {
    bool isP = true;
    REP(j, p.prime.size()) {
      if (A[i] <= p.prime[j])
        break;
      if (A[i] % p.prime[j] == 0) {
        isP = false;
        break;
      }
    }
    if (isP) {
      sum++;
    }
  }
  cout << sum << endl;
  return 0;
}


#include <algorithm>
#include <bitset>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define REP(i, n) for (int i = 0; i < (int)n; ++i)

bool isPrime(int num) {
  // if(num < 2) return false;
  if (num == 2)
    return true;
  if (num % 2 == 0)
    return false;

  for (int i = 3; i < num; i += 2) {
    if (num % i == 0)
      return false;
  }
  return true;
}

int main() {
  int N;
  int count = 0;
  int num;

  cin >> N;

  REP(i, N) {
    cin >> num;
    if (isPrime(num))
      ++count;
  }

  cout << count << endl;

  return 0;
}

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define REP(i, n) for (int i = 0; i < (int)n; ++i)

bool isPrime(int num) {
  // if(num < 2) return false;
  if (num == 2)
    return true;
  if (num % 2 == 0)
    return false;

  // +1 重要
  for (int i = 3; i < sqrt(num) + 1; i += 2) {
    if (num % i == 0)
      return false;
  }
  return true;
}

int main() {
  int N;
  int count = 0;
  int num;

  cin >> N;

  REP(i, N) {
    cin >> num;
    if (isPrime(num))
      ++count;
  }

  cout << count << endl;

  return 0;
}


#include <cmath>
#include <cstdio>

int judge(int n) {
  int i, a = 1;
  for (i = 2; i < sqrt(n) + 1; i++)
    if (n % i == 0 && n != 2)
      a = 0;
  return a;
}

int main() {
  int i, n, count;
  int a[1000];
  while (~scanf("%d", &n)) {
    count = 0;
    while (n--)
      scanf("%d", &a[count++]);
    int ans = 0;
    for (i = 0; i < count; i++)
      if (judge(a[i]))
        ans++;
    printf("%d\\n", ans);
  }
  return 0;
}

#include <cmath>
#include <cstdio>

int a[10000];

int judge(int n) {
  int i, a = 1;
  for (i = 2; i < sqrt(n) + 1; i++)
    if (n % i == 0 && n != 2)
      a = 0;
  return a;
}

int main() {
  int i, n, count;

  while (~scanf("%d", &n)) {
    count = 0;
    while (n--)
      scanf("%d", &a[count++]);
    int ans = 0;
    for (i = 0; i < count; i++)
      if (judge(a[i]))
        ans++;
    printf("%d\\n", ans);
  }
  return 0;
}


#include <iostream>
using namespace std;

int main() {
  unsigned int n, j;
  cin >> n;
  unsigned int num[n], count = 0;
  for (int i = 0; i < n; i++) {
    cin >> num[i];
  }
  for (int i = 0; i < n; i++) {
    for (j = 2; j < num[i]; j++) {
      if ((num[i] % j) == 0) {
        break;
      }
    }
    if (j == num[i])
      count++;
  }
  cout << count << endl;
  return 0;
}

#include <iostream>
#include <math.h>
using namespace std;

bool isPrime(int num) {
  if (num <= 1)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false;
  else {
    bool prime = true;
    int divisor = 3;
    double num_d = static_cast<double>(num);
    int upperLimit = static_cast<int>(sqrt(num_d) + 1);

    while (divisor <= upperLimit) {
      if (num % divisor == 0)
        prime = false;
      divisor += 2;
    }
    return prime;
  }
}
int main() {
  unsigned int n, j;
  cin >> n;
  unsigned int num[n], count = 0;
  for (int i = 0; i < n; i++) {
    cin >> num[i];
  }
  for (int i = 0; i < n; i++) {
    if (isPrime(num[i]))
      count++;
  }
  cout << count << endl;
  return 0;
}


#include <algorithm>
#include <iostream>
#include <math.h>
#include <sstream>
#include <stdio.h>
#include <string>
using namespace std;

int GCD(int x, int y) {
  if (y == 0) {
    return x;
  }
  return GCD(y, x % y);
}

bool isPrime(int N) {
  for (int i = 2; i < N; i++) {
    if (GCD(N, i) != 1)
      return false;
  }
  return true;
}

int main() {
  int n;
  cin >> n;
  int primeNumberCount = 0;
  for (int i = 0; i < n; i++) {
    int num;
    cin >> num;
    if (isPrime(num) == true)
      primeNumberCount++;
  }
  cout << primeNumberCount << endl;
  return 0;
}

#include <algorithm>
#include <iostream>
#include <math.h>
#include <sstream>
#include <stdio.h>
#include <string>
using namespace std;

int GCD(int x, int y) {
  if (y == 0) {
    return x;
  }
  return GCD(y, x % y);
}

bool isPrime(int N) {
  if (N == 2)
    true;
  if (N % 2 == 0)
    false;
  for (int i = 2; i * i <= N; i++) {
    if (GCD(N, i) != 1)
      return false;
  }
  return true;
}

int main() {
  int n;
  cin >> n;
  int primeNumberCount = 0;
  for (int i = 0; i < n; i++) {
    int num;
    cin >> num;
    if (isPrime(num) == true)
      primeNumberCount++;
  }
  cout << primeNumberCount << endl;
  return 0;
}


#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  const int MAX = 10001;
  int primes[MAX];
  for (int i = 0; i < MAX; i++)
    primes[i] = -1;

  for (int i = 2; i < MAX; i++) {
    if (primes[i] == 0)
      continue;
    primes[i] = 1;
    for (int j = i * 2; j < MAX; j += i) {
      primes[j] = 0;
    }
  }

  int N, ans = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int t;
    cin >> t;
    ans += primes[t];
  }
  cout << ans << endl;
}

#include <iostream>
using namespace std;
int main() {
  int N;
  cin >> N;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int p;
    cin >> p;
    ans++;
    for (int j = 2; j * j <= p; j++) {
      if (p % j == 0) {
        ans--;
        break;
      }
    }
  }
  cout << ans << endl;
}


#include <iostream>
#include <math.h>
#include <string>
using namespace std;

bool prime(int);

int main() {
  int n, k, c = 0;
  cin >> n;
  while (n--) {
    cin >> k;
    if (prime(k))
      c++;
  }
  cout << c << endl;
  return 0;
}

bool prime(int a) {
  for (int i = 2; i < a; i++) {
    if (a % i == 0)
      return false;
  }
  return true;
}

#include <iostream>
#include <math.h>
#include <string>
using namespace std;

bool prime(int);

int main() {
  int n, k, c = 0;
  cin >> n;
  while (n--) {
    cin >> k;
    if (prime(k))
      c++;
  }
  cout << c << endl;
  return 0;
}

bool prime(int a) {
  for (int i = 2; i < (int)(sqrt((double)a)) + 1; i++) {
    if (a % i == 0)
      return false;
  }
  return true;
}


#include <iostream>
#include <math.h>
using namespace std;

int main() {
  bool *is_prime = new bool[100000001];
  for (int i = 2; i <= 100000000; i++)
    is_prime[i] = true;
  for (int i = 2; i <= sqrt(100000000); i++)
    if (is_prime[i])
      for (int j = 2; i * j <= 100000000; j++)
        is_prime[i * j] = false;
  int n;
  cin >> n;
  int input[n];
  for (int i = 0; i < n; i++)
    cin >> input[i];
  int cnt = 0;
  for (int i = 0; i < n; i++)
    if (is_prime[input[i]])
      cnt++;
  cout << cnt << endl;
}

#include <iostream>
#include <math.h>
using namespace std;

int main() {
  int n;
  cin >> n;
  int input[n];
  for (int i = 0; i < n; i++)
    cin >> input[i];
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 2; j <= sqrt(input[i]); j++) {
      if (input[i] % j == 0) {
        cnt++;
        break;
      }
    }
  }
  cout << n - cnt << endl;
}


#include <iostream>

bool isPrime(int n) {
  int c = 0;
  for (int i = 2; i <= n; ++i) {
    if (n % i == 0)
      c++;
    if (c == 2)
      return false;
  }
  return true;
}

int main() {
  int n, c = 0;
  std::cin >> n;
  for (int i = 0; i < n; ++i) {
    int a;
    std::cin >> a;
    if (isPrime(a))
      c++;
  }
  std::cout << c << '\\n';
}

#include <cmath>
#include <iostream>

bool isPrime(int n) {
  int c = 0;
  for (int i = 1; i <= (int)sqrt(n); ++i) {
    if (n % i == 0)
      c++;
    if (c == 2)
      return false;
  }
  return true;
}

int main() {
  int n, c = 0;
  std::cin >> n;
  for (int i = 0; i < n; ++i) {
    int a;
    std::cin >> a;
    if (isPrime(a))
      c++;
  }
  std::cout << c << '\\n';
}


#include <iostream>
using namespace std;

int main() {
  int N, a, ans = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a;
    bool flag = true;
    if (a != 2 && a % 2 == 0 || a == 1) {
      flag = false;
    } else if (a != 2) {
      for (int j = 3; j < a; j += 2) {
        if (a % j == 0) {
          flag = false;
          break;
        }
      }
    }
    if (flag) {
      ans += 1;
    }
  }
  cout << ans << endl;
  return 0;
}

#include <iostream>
using namespace std;

int main() {
  int N, a, ans = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a;
    bool flag = true;
    if (a != 2 && a % 2 == 0 || a == 1) {
      flag = false;
    } else if (a > 2) {
      for (int j = 3; j * j <= a; j += 2) {
        if (a % j == 0) {
          flag = false;
          break;
        }
      }
    }
    if (flag) {
      ans += 1;
    }
  }
  cout << ans << endl;
  return 0;
}


// 2015/05/19 Tazoe

#include <iostream>
using namespace std;

bool is_prime[100000001];

int main() {
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i < 100000001; i++) {
    is_prime[i] = true;
  }

  for (int i = 2; i * i < 100000001; i++) {
    if (is_prime[i]) {
      for (int j = i * i; j < 100000001; j += i) {
        is_prime[j] = false;
      }
    }
  }

  int n;
  cin >> n;

  int cnt = 0;

  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;

    if (is_prime[x]) {
      cnt++;
    }
  }

  cout << cnt << endl;

  return 0;
}

// 2015/05/19 Tazoe

#include <iostream>
using namespace std;

bool isprime(int x) {
  if (x == 2)
    return true;

  if (x < 2 || x % 2 == 0)
    return false;

  for (int i = 3; i * i <= x; i += 2) {
    if (x % i == 0)
      return false;
  }

  return true;
}

int main() {
  int n;
  cin >> n;

  int cnt = 0;

  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;

    if (isprime(x)) {
      cnt++;
    }
  }

  cout << cnt << endl;

  return 0;
}


// 2017/05/19 Tazoe

#include <iostream>
using namespace std;

bool isprime(int x) {
  if (x == 2)
    return true;

  if (x < 2 || x % 2 == 0)
    return false;

  for (int i = 3; i * i <= x; i += 2) {
    if (x % i == 0)
      return false;
  }

  return true;
}

int main() {
  int n;
  cin >> n;

  int cnt = 0;

  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;

    if (isprime(x)) {
      cnt++;
    }
  }

  cout << cnt << endl;

  return 0;
}


#include <iostream>
using namespace std;

void inputData(int R[], int *N) {
  cin >> *N;
  for (int i = 0; i < *N; i++) {
    cin >> R[i];
  }
}

bool isPrimeNumber(int in) {
  if (in == 2)
    return true;
  if (in % 2 == 0)
    return false;
  int s;
  if ((in / 2) % 2 == 0) {
    s = (in / 2) - 1;
  } else {
    s = (in / 2);
  }
  for (int i = s; i >= 3; i = i - 2) {
    if ((in % i) == 0) {
      return false;
    }
  }
  return true;
}

static const int MAX = 10000;

int main() {
  int R[MAX];
  int N;
  int count = 0;
  inputData(R, &N);
  for (int i = 0; i < N; i++) {
    if (isPrimeNumber(R[i])) {
      count++;
    }
  }
  cout << count << endl;
  return 0;
}

#include <cmath>
#include <iostream>
using namespace std;

void inputData(int R[], int *N) {
  cin >> *N;
  for (int i = 0; i < *N; i++) {
    cin >> R[i];
  }
}

bool isPrimeNumber(int in) {
  if (in == 2)
    return true;
  if (in % 2 == 0)
    return false;
  int s = (int)sqrt((double)in);

  for (int i = 3; i <= s; i = i + 2) {
    if ((in % i) == 0) {
      return false;
    }
  }
  return true;
}

static const int MAX = 10000;

int main() {
  int R[MAX];
  int N;
  int count = 0;
  inputData(R, &N);
  for (int i = 0; i < N; i++) {
    if (isPrimeNumber(R[i])) {
      count++;
    }
  }
  cout << count << endl;
  return 0;
}


#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>

bool isPrime(std::size_t a) {
  if (a == 2) {
    return true;
  } else if (a % 2 == 0) {
    return false;
  }

  for (std::size_t i = 3; i < a / 2; i = i + 2) {
    if (a % i == 0) {
      return false;
    }
  }

  return true;
}

int main() {
  std::size_t n;
  std::cin >> n;

  std::size_t count = 0;
  for (std::size_t i = 0; i < n; ++i) {
    std::size_t a;
    std::cin >> a;
    if (isPrime(a)) {
      count++;
    }
  }

  std::cout << count << std::endl;

  return 0;
}

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>

bool isPrime(std::size_t a) {
  if (a == 2) {
    return true;
  } else if (a % 2 == 0) {
    return false;
  }

  for (std::size_t i = 3; i <= (std::size_t)(sqrt(a)); i = i + 2) {
    if (a % i == 0) {
      return false;
    }
  }

  return true;
}

int main() {
  std::size_t n;
  std::cin >> n;

  std::size_t count = 0;
  for (std::size_t i = 0; i < n; ++i) {
    std::size_t a;
    std::cin >> a;
    if (isPrime(a)) {
      count++;
    }
  }

  std::cout << count << std::endl;

  return 0;
}


#include <algorithm>
#include <cstring>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <vector>
using namespace std;

const long long int N = 100000000;
bool prime[N + 1];
void solve() {

  fill(prime, prime + N + 1, true);
  prime[0] = false;
  prime[1] = false;
  for (int i = 2; i < N + 1; i++)
    if (prime[i])
      for (int j = 2 * i; j < N + 1; j += i)
        prime[j] = false;
}

int main() {

  solve();
  int n, cnt = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a = 0;
    cin >> a;
    if (prime[a])
      cnt++;
  }
  cout << cnt << endl;

  return 0;
}

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <vector>
using namespace std;

const long long int N = 100000000;

bool solve(long long int x) {

  if (x == 2)
    return true;
  if (x < 2 || x % 2 == 0)
    return false;

  for (int i = 3; i <= sqrt(x); i += 2)
    if (x % i == 0)
      return false;
  return true;
}

int main() {

  int n, cnt = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a = 0;
    cin >> a;
    if (solve(a))
      cnt++;
  }
  cout << cnt << endl;

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

int prime[100000001];

void isPrime() {
  for (int i = 0; i < 100000000; ++i) {
    prime[i] = 1;
  }
  prime[0] = prime[1] = 0;

  for (int i = 2; i < 100000000 / 2; ++i) {
    if (prime[i] == 1) {
      for (int j = i + i; j < 100000000; j += i)
        prime[j] = 0;
    }
  }
}

int main() {
  int n;
  cin >> n;
  isPrime();
  int sum = 0;
  for (int i = 0; i < n; ++i) {
    int t;
    cin >> t;
    sum += prime[t];
  }
  cout << sum << endl;
}

#include <bits/stdc++.h>
using namespace std;

bool isPrime(int x) {
  if (x == 1)
    return false;
  if (x == 2)
    return true;
  if (x % 2 == 0)
    return false;
  int i = 3;
  while (i <= sqrt(x)) {
    if (x % i == 0)
      return false;
    i += 2;
  }
  return true;
}

int main() {
  int n;
  cin >> n;
  int sum = 0;
  for (int i = 0; i < n; ++i) {
    int t;
    cin >> t;
    sum += isPrime(t);
  }
  cout << sum << endl;
}


#include <bits/stdc++.h>
using namespace std;

int isPrime(int x) {
  if (x <= 1) {
    return 0;
  }
  for (int i = 2; i < x - 1; i++) {
    if (x % i == 0)
      return 0;
  }
  return true;
}

int main() {

  int n;
  cin >> n;
  int a, cnt = 0;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (isPrime(a)) {
      cnt++;
    }
  }
  cout << cnt << endl;

  return 0;
}

#include <bits/stdc++.h>
using namespace std;

int isPrime(int x) {

  if (x == 2) {
    return 1;
  } else if (x < 2 || x % 2 == 0) {
    return 0;
  }
  int i = 3;
  while (i <= sqrt(x)) {
    if (x % i == 0)
      return 0;
    i = i + 2;
  }
  return true;
}

int main() {

  int n;
  cin >> n;
  int a, cnt = 0;
  for (int i = 0; i < n; i++) {
    cin >> a;
    if (isPrime(a)) {
      cnt++;
    }
  }
  cout << cnt << endl;

  return 0;
}


#include <bits/stdc++.h>
#define MAX 100000000
using namespace std;
int eratos[MAX]; // eratos[n - 1] ???0??????n????´???°???1???????´???°??§??????

void Eratos() {
  eratos[0] = 1;
  for (int i = 1; i * i <= MAX; i++) {
    if (eratos[i - 1] == 0) {
      for (int j = i * 2; j <= MAX; j += i) {
        eratos[j] = 1;
      }
    }
  }
}

int main() {
  int n, res;
  Eratos();
  cin >> n;
  for (int i = 0, tmp; i < n; i++) {
    cin >> tmp;
    if (eratos[tmp - 1] == 0)
      res++;
  }
  cout << res << endl;
  return 0;
}

#include <bits/stdc++.h>
#define MAX 100000000
using namespace std;

int main() {
  int n, res = 0;
  cin >> n;
  for (int i = 0, tmp; i < n; i++) {
    cin >> tmp;
    for (int j = 2; j * j <= tmp; j++) {
      if (tmp % j == 0) {
        res++;
        break;
      }
    }
  }
  cout << n - res << endl;
  return 0;
}


#include <iostream>
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, a) for (int i = 0; i < (a); i++)

int main() {
  bool primes[10001] = {};

  FOR(i, 2, 100 + 1) {
    if (primes[i] == 0) {
      FOR(j, 2, (10000 / i) + 1) { primes[i * j] = 1; }
    }
  }

  int n;
  cin >> n;

  int cnt = 0;
  REP(i, n) {
    int a;
    cin >> a;
    if (primes[a] == 0)
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}

#include <cmath>
#include <iostream>
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, a) for (int i = 0; i < (a); i++)

bool IsPrime(int n) {
  FOR(i, 2, int(sqrt(n)) + 1) {
    if (n % i == 0)
      return false;
  }
  return true;
}

int main() {
  int n;
  cin >> n;

  int cnt = 0;
  REP(i, n) {
    int a;
    cin >> a;
    if (IsPrime(a))
      cnt++;
  }
  cout << cnt << endl;
  return 0;
}


#include <iostream>
using namespace std;

int prime(int p) {
  int i, flag = 0;
  if (p == 2) {
    return 0;
  } else {
    for (i = 2; i < p; i++) {
      if (p % i == 0) {
        flag = 1;
        break;
      }
    }
    return flag;
  }
}

int main() {
  int n, i, p, P = 0;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> p;
    P = P + prime(p);
  }
  cout << n - P << endl;
}

#include <iostream>
#include <math.h>
using namespace std;

int prime(int p) {
  int i, flag = 0;
  if (p == 2) {
    return 0;
  } else {
    for (i = 2; i <= sqrt(p); i++) {
      if (p % i == 0) {
        flag = 1;
        break;
      }
    }
    return flag;
  }
}

int main() {
  int n, i, p, P = 0;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> p;
    P = P + prime(p);
  }
  cout << n - P << endl;
}


#include <iostream>
using namespace std;

bool judgeSosu(int n) {
  for (int i = 2; i <= n - 1; i++) {
    if (n % i == 0)
      return false;
  }
  return true;
}

int main() {
  const int N = 10000;
  int n;
  cin >> n;

  int seisu[N];
  int counter = 0;

  for (int i = 0; i < n; i++) {
    cin >> seisu[i];
  }
  for (int i = 0; i < n; i++) {
    if (judgeSosu(seisu[i]))
      counter++;
  }
  cout << counter << endl;
}

#include <cmath>
#include <iostream>
using namespace std;

bool isPrime(int n) {
  if (n == 2)
    return true;
  if (n < 2 || n % 2 == 0)
    return false;
  int i = 3;
  while (i <= sqrt(static_cast<double>(n))) {
    if (n % i == 0)
      return false;
    i += 2;
  }
  return true;
}

int main() {
  int n;
  cin >> n;
  int suuti;
  int counter = 0;
  for (int i = 0; i < n; i++) {
    cin >> suuti;
    if (isPrime(suuti))
      counter++;
  }
  cout << counter << endl;
}


#include <iostream>
#include <vector>
using namespace std;

vector<int> p;
bool isPN(int n) {
  int i, j;
  bool ret = false;
  for (i = 0; i < p.size() && p[i] <= n; i++) {
    if (n == p[i]) {
      ret = true;
      break;
    } else if (n % p[i] == 0)
      break;
  }
  if (i >= p.size() || p[i] > n) {
    if (p[p.size() - 1] < n) {
      for (i = p[p.size() - 1] + 2; i <= n; i += 2) {
        for (j = 0; j < p.size() && p[j] * p[j] < i; j++) {
          if (i % p[j] == 0)
            break;
        }
        if (j >= p.size() || p[j] * p[j] >= i) {
          p.push_back(i);
          if (i == n) {
            ret = true;
            break;
          }
        }
      }
    }
  }
  return ret;
}
int main() {
  int N, ret = 0, i, t;
  p.push_back(2);
  p.push_back(3);
  cin >> N;
  for (i = 0; i < N; i++) {
    cin >> t;
    if (isPN(t))
      ret++;
  }
  cout << ret << endl;
  return 0;
}

#include <iostream>
#include <vector>
using namespace std;

int main() {
  int N, max = 2, ret = 0, i, j;
  cin >> N;
  vector<int> a(N);
  for (i = 0; i < N; i++) {
    cin >> a[i];
    if (max < a[i])
      max = a[i];
  }
  vector<bool> p(max + 1, true);
  for (i = 2; i * i <= max; i++) {
    if (p[i])
      for (j = i * 2; j <= max; j += i)
        p[j] = false;
  }
  for (i = 0; i < N; i++) {
    if (p[a[i]])
      ret++;
  }
  cout << ret << endl;
  return 0;
}


#include <iostream>
using namespace std;

int PrimeNumber(int a) {
  int b = a, i;

  for (i = 2; i < a; i++) {
    while (b % i == 0)
      b = b / i;
    if (b == 1) {
      return 0;
    }
  }
  return 1;
}

int main() {
  int n;
  cin >> n;
  int a[n], i, j = 0;

  for (i = 0; i < n; i++) {
    cin >> a[i];
    j += PrimeNumber(a[i]);
  }
  cout << j << endl;

  return 0;
}

#include <cmath>
#include <iostream>
using namespace std;

bool IsPrime(int a) {
  if (a == 2)
    return true;

  if (a < 2 || a % 2 == 0)
    return false;

  int i = 3;
  while (i <= sqrt(a)) {
    if (a % i == 0)
      return false;
    i = i + 2;
  }

  return true;
}

int main() {
  int n;
  cin >> n;
  int a[n], i, j = 0;

  for (i = 0; i < n; i++) {
    cin >> a[i];
    if (IsPrime(a[i]))
      j++;
  }
  cout << j << endl;

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int maxn = 50001;

int prime[maxn], cnt, res;
bool isprime[maxn];

void maketable() {
  int base = (int)sqrt((double)maxn);
  isprime[0] = isprime[1] = 1;
  for (int i = 2; i < base; i++) {
    if (!isprime[i]) {
      prime[cnt++] = i;
      for (int j = i + i; j < maxn; j += i) {
        isprime[j] = 1;
      }
    }
  }
}

void solve(int n) {
  int k = (int)sqrt((double)n);
  for (int i = 0; prime[i] <= k; i++) {
    if (n % prime[i] == 0) {
      return;
    }
  }
  res++;
}

int main() {
  maketable();
  int n, s;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &s);
    solve(s);
  }
  printf("%d\\n", res);
  return 0;
}

#include <bits/stdc++.h>

using namespace std;

const int maxn = 50001;

int prime[maxn], cnt, res;
bool isprime[maxn];

void maketable() {
  int base = (int)sqrt((double)maxn);
  isprime[0] = isprime[1] = 1;
  for (int i = 2; i < maxn; i++) { // 此处i<maxn与以前的不同
    if (!isprime[i]) {
      prime[cnt++] = i;
      for (int j = i + i; j < maxn; j += i) {
        isprime[j] = 1;
      }
    }
  }
}

void solve(int n) {
  int k = (int)sqrt((double)n);
  for (int i = 0; prime[i] <= k; i++) {
    if (n % prime[i] == 0) {
      return;
    }
  }
  res++;
}

int main() {
  maketable();
  int n, s;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &s);
    solve(s);
  }
  printf("%d\\n", res);
  return 0;
}


#include <algorithm>
#include <cstdio>
#include <fstream>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define MAX 100000001

void eratos(bool *p) {
  for (int i = 1; i < MAX; ++i) {
    p[i] = true;
  }
  for (int i = 2; i * i < MAX; ++i) {
    for (int j = 2; i * j < MAX; ++j) {
      p[i * j] = false;
    }
  }
}

int main() {
  int n, sum = 0;
  vector<bool> p(MAX);
  cin >> n;
  vector<int> arr(n);
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }

  for (int i = 1; i < MAX; ++i) {
    p[i] = true;
  }
  for (int i = 2; i * i < MAX; ++i) {
    for (int j = 2; i * j < MAX; ++j) {
      p[i * j] = false;
    }
  }

  for (int i = 0; i < n; ++i) {
    if (p[arr[i]] == true)
      ++sum;
  }
  cout << sum << endl;
  return 0;
}

#include <algorithm>
#include <cstdio>
#include <fstream>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
#define MAX 100000001
/*
void eratos(bool *p){
        for(int i=1; i<MAX; ++i){
                p[i] = true;
        }
        for(int i=2; i*i<MAX; ++i){
                for(int j=2; i*j<MAX; ++j){
                        p[i*j] = false;
                }
        }
}
*/

int main() {
  int n, sum = 0;
  vector<bool> p(MAX);
  cin >> n;
  vector<int> arr(n);
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }

  for (int i = 1; i < MAX; ++i) {
    p[i] = true;
  }

  for (int i = 2; i * i < MAX; ++i) {
    if (p[i] == true) {
      for (int j = 2; i * j < MAX; ++j) {
        p[i * j] = false;
      }
    }
  }

  for (int i = 0; i < n; ++i) {
    if (p[arr[i]] == true)
      ++sum;
  }
  cout << sum << endl;
  return 0;
}


#include <iostream>
#include <math.h>

using namespace std;

bool is_prime[10000000];
int primes[100000000];
int prime_count = 0;

void set_prime() {
  int j, end_point;
  bool flag;
  for (int i = 5; i < 100000000; i += 2) {
    flag = false;
    end_point = (int)sqrt((double)i);

    for (j = 0; j < prime_count && primes[j] <= end_point; j++) {
      if (i % primes[j] == 0) {
        flag = true;
        break;
      }
    }
    if (!flag) {
      is_prime[i] = true;
      primes[prime_count++] = i;
    }
  }
}

int main() {
  for (int i = 2; i <= 3; i++) {
    is_prime[i] = true;
    primes[prime_count++] = i;
  }
  set_prime();
  int N, num, count;

  count = 0;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> num;
    if (is_prime[num])
      count++;
  }
  cout << count << endl;

  return 0;
}

#include <iostream>
#include <math.h>

using namespace std;

bool is_prime(int num) {
  if (num == 2 || num == 3 || num == 5 || num == 7)
    return true;
  if (num % 2 == 0)
    return false;
  for (int i = 3; i * i <= num; i += 1)
    if (num % i == 0)
      return false;
  return true;
}

int main() {
  int N, num, count;

  count = 0;

  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> num;
    if (is_prime(num))
      count++;
  }
  cout << count << endl;

  return 0;
}


#include <iostream>
using namespace std;

int main() {
  int T;
  long long s[200005];
  cin >> T;
  for (int i = 0; i < T; i++)
    cin >> s[i];
  long long max = -2000000001;
  for (int i = T - 1; i >= 0; i--) {
    for (int j = i - 1; j >= 0; j--) {
      if (s[i] - s[j] > max) {
        max = s[i] - s[j];
      }
    }
  }
  cout << max << endl;
  return 0;
}

#include <iostream>
using namespace std;

int main() {
  int T;
  long long s[200005];
  cin >> T;
  for (int i = 0; i < T; i++)
    cin >> s[i];
  long long max1 = -2000000001, min1 = s[0];
  for (int i = 1; i < T; i++) {
    max1 = max(max1, s[i] - min1);
    min1 = min(min1, s[i]);
  }
  cout << max1 << endl;
  return 0;
}


#include <iostream>

int main() {
  int n, max, min;
  std::cin >> n;
  int R[n];
  for (int t = 0; t <= n - 1; t++) {
    std::cin >> R[t];
  }

  min = R[0];
  for (int j = 1; j <= n - 1; j++) {
    for (int i = 0; i < j; i++) {
      if (j == 1) {
        max = R[j] - R[i];
      }
      if (R[j] < R[j - 1]) {
        break;
      }
      if (R[i] <= min && R[j] - R[i] > max) {
        max = R[j] - R[i];
        min = R[i];
      }
    }
  }
  std::cout << max << "\\n";

  return 0;
}

#include <iostream>

int main() {
  int n, max, min, mins;
  std::cin >> n;
  int R[n];
  for (int t = 0; t <= n - 1; t++) {
    std::cin >> R[t];
  }

  min = R[0];
  mins = 0;
  for (int j = 1; j <= n - 1; j++) {
    for (int i = j - 1; i < j; i++) {
      if (R[i] <= min) {
        min = R[i];
        mins = i;
      }
      if (j == 1) {
        max = R[j] - min;
      }

      if (R[j] - min > max) {
        max = R[j] - min;
      }
      /*			if(R[j]<R[j-1]){
                                      break;
                              }
                              if( R[i]<=min && R[j]-R[i]>max){
                                      max=R[j]-R[i];
                                      min=R[i];

                              }*/
    }
  }
  std::cout << max << "\\n";

  return 0;
}


#include <iostream>
using namespace std;

int main() {

  int n;
  cin >> n;
  int r[n];
  for (int i = 0; i < n; i++)
    cin >> r[i];

  long int max = -1000000000;

  for (int i = 0; i < n; i++)
    for (int j = i + 1; j < n; j++)
      if (max < r[j] - r[i]) {
        max = r[j] - r[i];
      }

  cout << max << endl;
}

#include <iostream>
using namespace std;

int main() {

  int n;
  cin >> n;
  int r[n];
  for (int i = 0; i < n; i++)
    cin >> r[i];

  int max = -999999999;
  int minr = r[0];
  for (int i = 0; i < n; i++) {
    if (r[i] <= minr) {
      for (int j = i + 1; j < n; j++) {
        if (max < r[j] - r[i])
          max = r[j] - r[i];
      }
      minr = r[i];
    }
  }

  cout << max << endl;
}


#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

int main() {
  int count;
  std::vector<int> X;
  cin >> count;
  for (int i = 0; i < count; ++i) {
    int x;
    cin >> x;
    X.push_back(x);
  }
  int d = INT_MIN;
  for (int j = 1; j < X.size(); ++j) {
    for (int i = 0; i < j; ++i) {
      d = max(X[j] - X[i], d);
    }
  }
  cout << d << endl;
}

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdint>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

int main() {
  int count;
  std::vector<int> X;
  cin >> count;
  for (int i = 0; i < count; ++i) {
    int x;
    cin >> x;
    X.push_back(x);
  }
  int minX = INT_MAX;
  int maxProfit = INT_MIN;
  for (int j = 1; j < X.size(); ++j) {
    minX = min(minX, X[j - 1]);
    maxProfit = max(X[j] - minX, maxProfit);
  }
  cout << maxProfit << endl;
}


// 2???n???200,000
// 1???Rt???10

#include <iostream>
#include <limits>
#include <vector>

int main() {
  int N;
  std::vector<int> R;

  std::cin >> N;
  R.resize(N);

  for (int i = 0; i < N; ++i) {
    std::cin >> R[i];
  }

  std::vector<int> R_min;
  std::vector<int> R_max;

  R_min[0] = R[0];
  R_max[N - 1] = R[N - 1];

  for (int i = 1; i < N; ++i) {
    R_min[i] = std::min(R[i], R[i - 1]);
  }
  for (int i = N - 2; i >= 0; --i) {
    R_max[i] = std::max(R[i], R[i + 1]);
  }

  int max_diff = std::numeric_limits<int>::min();
  for (int i = 0; i < N; ++i) {
    max_diff = std::max(max_diff, R_max[i] - R_min[i]);
  }

  std::cout << max_diff << std::endl;
}

// 2???n???200,000
// 1???Rt???10

#include <iostream>
#include <limits>
#include <vector>

int main() {
  int N;
  std::vector<int> R;

  std::cin >> N;
  R.resize(N);

  for (int i = 0; i < N; ++i) {
    std::cin >> R[i];
  }

  std::vector<int> R_min(N);
  std::vector<int> R_max(N);

  R_min[0] = R[0];
  R_max[N - 1] = R[N - 1];

  for (int i = 1; i < N; ++i) {
    R_min[i] = std::min(R[i], R_min[i - 1]);
  }
  for (int i = N - 2; i >= 0; --i) {
    R_max[i] = std::max(R[i], R_max[i + 1]);
  }

  // for(int i=0; i<N; ++i){
  //   std::cout << R[i] << ' ';
  // }
  // std::cout << std::endl;
  // for(int i=0; i<N; ++i){
  //   std::cout << R_min[i] << ' ';
  // }
  // std::cout << std::endl;
  // for(int i=0; i<N; ++i){
  //   std::cout << R_max[i] << ' ';
  // }
  // std::cout << std::endl;

  int max_diff = std::numeric_limits<int>::min();
  // for(int i=0; i<N; ++i){
  //   max_diff = std::max(max_diff, R_max[i] - R_min[i]);
  // }
  for (int i = 0; i < N - 1; ++i) {
    max_diff = std::max(max_diff, R_max[i + 1] - R_min[i]);
  }

  std::cout << max_diff << std::endl;
}


#include <limits>
#include <stdio.h>
#include <vector>

int main() {
  int n;
  scanf("%d", &n);
  std::vector<int> d;

  for (int i = 0; i < n; i++) {
    int b;
    scanf("%d", &b);
    d.push_back(b);
  }

  int profit = std::numeric_limits<int>::min();
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      if (profit < d[j] - d[i])
        profit = d[j] - d[i];
    }
  }
  printf("%d\\n", profit);
}

#include <algorithm>
#include <limits>
#include <stdio.h>
#include <vector>

/*
??????
*/

int main() {
  int n;
  std::vector<int> price;

  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    int b;
    scanf("%d", &b);
    price.push_back(b);
  }

  int pmin = std::numeric_limits<int>::max();
  int maxprofit = std::numeric_limits<int>::min();
  for (auto p = price.begin(); p != price.end(); p++) {
    maxprofit = std::max(maxprofit, *p - pmin);
    pmin = std::min(pmin, *p);
  }

  printf("%d\\n", maxprofit);
}


#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n;
  int r[200000];
  int max = -1000000000, ans = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> r[i];
    for (int j = i; j > 0; j--) {
      ans = r[i] - r[j - 1];
      if (max < ans)
        max = ans;
    }
  }
  cout << max << endl;
  return 0;
}

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int nmin = (1 << 31) - 1;
  int ans = 1 << 31;
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int dummy;
    cin >> dummy;
    ans = max(ans, dummy - nmin);
    nmin = min(nmin, dummy);
  }
  cout << ans << endl;
  return 0;
}


#include <iostream>
using namespace std;

int main() {
  long long n, num[200000];
  long long temp, max = -1000000000;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> num[i];
  }

  for (int i = 0; i < n - 1; i++) {
    temp = num[i + 1];
    for (int j = i + 2; j < n; j++) {
      if (temp < num[j]) {
        temp = num[j];
      }
    }

    if (temp - num[i] > max) {
      max = temp - num[i];
    }
  }

  cout << max << endl;

  return 0;
}

#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  long long n, num[200000];
  long long temp, nmax = -1000000000, nmin;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> num[i];
  }

  nmin = num[0];
  for (int i = 1; i < n; i++) {
    nmax = max(nmax, num[i] - nmin);
    nmin = min(nmin, num[i]);
  }

  cout << nmax << endl;

  return 0;
}


#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main(void) {
  while (1) {
    int n;
    cin >> n;
    vector<int> r(n);

    int sell, buy;
    int profit;
    for (int i = 0; i < n; i++) {
      cin >> r[i];
      if (i == 1) {
        profit = r[1] - r[0];
      } else if (i > 1) {
        profit = max(profit, r[i] - buy);
      }
      if (i == 0) {
        buy = r[i];
      } else if (buy > r[i]) {
        buy = r[i];
      }
    }

    cout << profit << endl;
  }
  return 0;
}

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main(void) {
  int n;
  cin >> n;
  vector<int> r(n);

  int buy;
  int profit;
  for (int i = 0; i < n; i++) {
    cin >> r[i];
    if (i == 1) {
      profit = r[1] - r[0];
    } else if (i > 1) {
      profit = max(profit, r[i] - buy);
    }
    if (i == 0) {
      buy = r[i];
    } else if (buy > r[i]) {
      buy = r[i];
    }
  }

  cout << profit << endl;
  return 0;
}


#include <algorithm>
#include <iostream>
using namespace std;
static const int MAX = 20000;

int main() {
  int R[MAX], n;

  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> R[i];

  int maxv = -2000000000;
  int minv = R[0];

  for (int i = 1; i < n; i++) {
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }

  cout << maxv << endl;

  return 0;
}

#include <algorithm>
#include <iostream>
using namespace std;
static const int MAX = 200000;

int main() {
  int R[MAX], n;

  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> R[i];

  int maxv = -2000000000;
  int minv = R[0];

  for (int i = 1; i < n; i++) {
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }

  cout << maxv << endl;

  return 0;
}


#include <stdio.h>

#define N 200000

int main() {
  int n, i, j;
  scanf("%d", &n);
  int num[N];
  for (i = 0; i < n; i++)
    scanf("%d", &num[i]);
  int max = num[1] - num[0];
  for (i = 0; i <= n - 2; i++) {
    for (j = i + 1; j <= n - 1; j++) {
      int diff = num[j] - num[i];
      if (diff > max)
        max = diff;
    }
  }
  printf("%d\\n", max);
  return 0;
}

#include <stdio.h>

#define N 200000

int main() {
  int n, i, j, maxi, maxj;
  scanf("%d", &n);
  int num[N];
  for (i = 0; i < n; i++)
    scanf("%d", &num[i]);
  int max = num[1] - num[0];
  maxj = num[1];
  maxi = num[0];
  for (i = 0; i <= n - 2; i++) {
    if (num[i] > maxi)
      continue;
    for (j = i + 1; j <= n - 1; j++) {
      int diff = num[j] - num[i];
      if (diff > max) {
        max = diff;
        maxi = num[i];
        maxj = num[j];
      }
    }
  }
  printf("%d\\n", max);
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define FOR(i, s, e) for ((i) = (s); (i) < (int)(e); (i)++)
#define REP(i, e) FOR(i, 0, e)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define mp(x, y) make_pair((x), (y))

typedef long long ll;
typedef pair<int, int> PII;

const double EPS = 1e-10;

const int N = 200000;
int r[N];
int n;

int main() {
  int i, j;
  scanf("%d ", &n);
  for (i = 0; i < n; i++)
    scanf("%d ", r + i);

  // O(n^2):TLE
  int res = r[1] - r[0];
  for (i = 0; i < n - 1; i++)
    for (j = i + 1; j < n; j++) {
      res = (res < r[j] - r[i]) ? r[j] - r[i] : res;
    }

  /*
    int maxj = r[1];
    int mini = r[0];
    for (j=1; j<n; j++) {
      if (maxj-mini < r[j]-mini) maxj = r[j];
      if (r[j] < mini) mini = r[j];
    }
  */

  printf("%d\\n", res);

  return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, s, e) for ((i) = (s); (i) < (int)(e); (i)++)
#define REP(i, e) FOR(i, 0, e)

#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define mp(x, y) make_pair((x), (y))

typedef long long ll;
typedef pair<int, int> PII;

const double EPS = 1e-10;

const int N = 200000;
int r[N];
int n;

int main() {
  int i, j;
  scanf("%d ", &n);
  for (i = 0; i < n; i++)
    scanf("%d ", r + i);

  /*
    //O(n^2):TLE
    int res = r[1] - r[0];
    for (i=0; i<n-1; i++)
      for (j=i+1; j<n; j++) {
        res = (res < r[j] - r[i]) ? r[j] - r[i] : res;
      }
    printf("%d\\n", res);
  */

  /*
    //WA(miniが余計に更新されてmaxj-miniがおかしなことになる)
    int maxj = r[1];
    int mini = r[0];
    for (j=1; j<n; j++) {
      if (maxj-mini < r[j]-mini) {
        maxj = r[j];
        if (j < n-1 && r[j] < mini) mini = r[j];
      }
  //    if (j < n-1 && r[j] < mini) mini = r[j];
    }
    printf("%d\\n", maxj-mini);
  */

  // resにmax-minを持たせる(上のようにminiの更新で変なことにならない)
  int res = r[1] - r[0];
  int mini = r[0];
  for (j = 1; j < n; j++) {
    if (res < r[j] - mini)
      res = r[j] - mini;
    if (r[j] < mini)
      mini = r[j];
  }

  printf("%d\\n", res);

  return 0;
}


#include <iostream>
using namespace std;

static const int Len = 200000;
int a[Len];

int main() {

  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];

  int maxV = -1000000001;
  for (int j = 1; j < n; j++) {
    for (int i = 0; i < j; i++) {
      maxV = maxV >= (a[j] - a[i]) ? maxV : a[j] - a[i];
    }
  }
  cout << maxV << endl;

  return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int main() {
  long n;
  cin >> n;
  // n = 3;
  long max = -1000000000;
  vector<long> R(n);
  for (long i = 0; i < n; i++) {
    cin >> R[i];
  }
  /*
  R[0] = 4;
  R[1] = 3;
  R[2] = 2;
  */
  for (long i = 0; i < n; i++) {
    for (long j = i + 1; j < n; j++) {
      if (R[j] - R[i] > max) {
        max = R[j] - R[i];
      }
    }
  }
  cout << max << endl;
  return 0;
}

#include <iostream>
#include <vector>
using namespace std;

int main() {
  long n;
  cin >> n;
  // n = 6;
  long max = -1000000000;
  vector<long> R(n);
  for (long i = 0; i < n; i++) {
    cin >> R[i];
  }
  long Rmin = R[0];
  /*
  R[0] = 5;
  R[1] = 3;
  R[2] = 1;
  R[3] = 3;
  R[4] = 4;
  R[5] = 3;
  */
  for (long i = 1; i < n; i++) {
    if (R[i] - Rmin > max)
      max = R[i] - Rmin;
    if (R[i] < Rmin)
      Rmin = R[i];
  }
  cout << max << endl;
  return 0;
}


#include <iostream>
using namespace std;
int main(void) {
  // Here your code !
  int n, key, p = 0, q = 0;
  bool l = true;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  key = a[1] - a[0];
  for (int i = 0; i < n; i++) {
    if (a[i] < q) {
      l = false;
    }
    if (a[i] < p && a[i] > q && l) {
      continue;
    }
    for (int j = 0; j < i; j++) {
      if (a[i] - a[j] > key) {
        key = a[i] - a[j];
        p = a[i];
        q = a[j];
        l = true;
      }
    }
  }
  cout << key << endl;
}

#include <iostream>
using namespace std;
int main(void) {
  // Here your code !
  int n; // ???????????°
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int min, ans;
  min = a[0];
  ans = a[1] - a[0];
  for (int i = 1; i < n; i++) {
    if (a[i] < min) {
      min = a[i];
    } else if (ans < a[i] - min) {
      ans = a[i] - min;
    }
  }
  cout << ans << endl;
}


#include <iostream>

int main() {
  int n;
  int r[200000];
  std::cin >> n;
  for (int i = 0; i < n; i++) {
    std::cin >> r[i];
  }
  int s = r[1] - r[0];
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      int ss = r[j] - r[i];
      if (ss > s) {
        s = ss;
      }
    }
  }
  std::cout << s << std::endl;
  return 0;
}

#include <iostream>

int main() {
  int n;
  int r[200000];
  std::cin >> n;
  for (int i = 0; i < n; i++) {
    std::cin >> r[i];
  }
  int s = r[1] - r[0];
  int rr = r[0];
  for (int i = 1; i < n; i++) {
    if (r[i] - rr > s) {
      s = r[i] - rr;
    }
    if (r[i] < rr) {
      rr = r[i];
    }
  }
  std::cout << s << std::endl;
  return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;

  vector<int> v(n, 0);
  for (auto &&x : v) {
    cin >> x;
  }

  int ans = v[1] - v[0];

  for (int i = 1; i < n; ++i) {
    for (int j = 0; j < i; ++j) {
      ans = max(ans, v[i] - v[j]);
    }
  }

  cout << ans << endl;

  return 0;
}

#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n;
  cin >> n;

  vector<int> v(n, 0);
  for (auto &&x : v) {
    cin >> x;
  }

  int ans = v[1] - v[0];

  int minv = v[0];

  for (int i = 1; i < n; ++i) {
    ans = max(ans, v[i] - minv);
    minv = min(minv, v[i]);
  }

  cout << ans << endl;

  return 0;
}


#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  long price[n];
  for (int i = 0; i < n; i++) {
    cin >> price[i];
  }
  long max = -10000000000;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      if (max < price[j] - price[i])
        max = price[j] - price[i];
    }
  }
  cout << max << endl;
}

#include <algorithm>
#include <iostream>
using namespace std;
static const int MAX = 200000;
int main() {
  int R[MAX], n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> R[i];
  int maxv = -2000000000;
  int minv = R[0];

  for (int i = 1; i < n; i++) {
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }
  cout << maxv << endl;
}


#include <climits>
#include <iostream>
#include <vector>

using namespace std;

unsigned N;
int MAX = INT_MIN;

int main() {
  cin >> N;

  vector<int> R(N);

  for (vector<int>::size_type i = 0; i < N; i++) {
    cin >> R[i];
  }

  for (vector<int>::size_type i = 0; i < N; i++) {
    for (vector<int>::size_type j = i + 1; j < N; j++) {
      if (R[j] - R[i] > MAX) {
        MAX = R[j] - R[i];
      }
    }
  }

  cout << MAX << endl;

  return 0;
}

// Time : O( N(N + 1) / 2 )

#include <iostream>
#include <limits>
#include <queue>

using namespace std;

int main() {
  int n, MAX = numeric_limits<int>::min();

  queue<int> R;

  cin >> n;

  for (int i = 0; i < n; i++) {
    int temp;

    cin >> temp;

    R.push(temp);

    if (MAX < R.back() - R.front() && R.size() > 1) {
      MAX = R.back() - R.front();
    }

    if (R.back() < R.front()) {
      while (R.size() > 1) {
        R.pop();
      }
    }
  }

  cout << MAX << endl;

  return 0;
}


#include <algorithm>
#include <cctype>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  long long int min = 1000000000 + 5;
  long long int max = -1;
  long long int result;
  while (n--) {
    long long int x;
    cin >> x;
    result = x - min;
    if (x < min)
      min = x;
    // cout<<min<<endl;
    if (result > max)
      max = result;
  }
  if (max == 0)
    cout << "-1" << endl;
  else
    cout << max << endl;
  while (1)
    ;
  return 0;
}

#include <algorithm>
#include <cctype>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  long long int first;
  cin >> first;
  long long int min = first;
  n--;
  long long int max = -1000000000;
  long long int result;
  while (n--) {
    long long int x;
    cin >> x;
    result = x - min;
    if (x < min)
      min = x;
    // cout<<min<<endl;
    if (result > max)
      max = result;
  }
  cout << max << endl;
  // while(1);
  return 0;
}


#include <iostream>
using namespace std;

const int MAX = 200001;

int main() {
  int n;
  cin >> n;
  int R[MAX];

  for (int i = 0; i < n; i++)
    cin >> R[i];

  int minv = -10E10;
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < i; j++) {
      minv = max(R[i] - R[j], minv);
    }
  }
  cout << minv << endl;
  return 0;
}

#include <iostream>
using namespace std;

const int MAX = 200001;

int main() {
  int n;
  cin >> n;
  int R[MAX];

  for (int i = 0; i < n; i++)
    cin >> R[i];

  int minv = R[0];
  int maxv = R[1] - R[0];
  for (int i = 1; i < n; i++) {
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }
  cout << maxv << endl;
  return 0;
}


#include <iostream>
using namespace std;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 999999999
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \\
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \\
       << " " << __FILE__ << endl;

int main() {
  int n, maxv;
  cin >> n;
  int R[n];
  REP(i, n) cin >> R[i];
  maxv = R[1] - R[0];

  REP(i, n) {
    FOR(j, i + 1, n) {
      if (maxv < (R[j] - R[i]))
        maxv = R[j] - R[i];
    }
  }
  cout << maxv << endl;
}

#include <iostream>
using namespace std;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 999999999
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                                               \\
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \\
       << " " << __FILE__ << endl;

int main() {
  int n, maxv, minv;
  cin >> n;
  int R[n];
  REP(i, n) cin >> R[i];
  maxv = R[1] - R[0];
  minv = R[0];

  FOR(i, 1, n) {
    maxv = max(maxv, (R[i] - minv));
    minv = min(minv, R[i]);
  }
  cout << maxv << endl;
  return 0;
}


#include <limits.h>
#include <stdio.h>

#define MAX 200000

int main() {
  int n;
  long value[MAX];
  scanf("%d", &n);
  if (n < 2 || n > 200000) {
    printf("Error: n is out of range");
    return -1;
  }

  for (int i = 0; i < n; i++) {
    scanf("%ld", &value[i]);
    if (value[i] < 1 || value[i] > 10e9) {
      printf("Error: value[i] is out of range");
      return -1;
    }
  }

  /* for(int i = 0; i < n; i++) { */
  /*   printf("%d\\n", value[i]); */
  /* } */

  long max_prof = LONG_MIN;
  long prof;
  for (int i = n - 1; i >= 0; i--) {
    for (int j = i - 1; j >= 0; j--) {
      /* printf("i = %d, v[i] = %ld, j = %d, v[j] = %ld", i, value[i], j,
       * value[j]); */
      prof = value[i] - value[j];
      if (prof > max_prof) {
        max_prof = prof;
      }
    }
  }
  printf("%ld\\n", max_prof);
}

#include <limits.h>
#include <stdio.h>

#define MAX 200000

int main() {
  int n;
  long value[MAX];
  long prof;
  long min_prof = LONG_MAX;
  long max_prof = LONG_MIN;

  scanf("%d", &n);
  if (n < 2 || n > 200000) {
    printf("Error: n is out of range");
    return -1;
  }

  for (int i = 0; i < n; i++) {
    scanf("%ld", &value[i]);
    if (value[i] < 1 || value[i] > 10e9) {
      printf("Error: value[i] is out of range");
      return -1;
    }
  }

  for (int i = 0; i < n; i++) {
    // check max
    if ((max_prof < value[i] - min_prof) && i >= 1) {
      /* printf("## %ld, %ld", value[i], min_prof); */
      max_prof = value[i] - min_prof;
    }
    // check min
    if (value[i] < min_prof) {
      min_prof = value[i];
    }
    /* printf("min: %ld\\n", min_prof); */
    /* printf("max: %ld\\n", max_prof); */
  }
  printf("%ld\\n", max_prof);
}


#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  vector<int> a;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];

  int maxv = -2000000000, minv = a[0];

  for (int i = 1; i < n; i++) {
    maxv = max(maxv, a[i] - minv);
    minv = min(minv, a[i]);
  }
  cout << maxv << endl;
}

#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  vector<int> a;
  int n, r;
  cin >> n;

  int maxv = -2000000000, minv = 2000000000;

  for (int i = 0; i < n; i++) {
    cin >> r;
    maxv = max(maxv, r - minv);
    minv = min(minv, r);
  }
  cout << maxv << endl;
}


#include <algorithm>
#include <iostream>

using namespace std;

int main(void) {

  int R[20000] = {0}, maxv = -1000000000, minv;
  int i, n;

  cin >> n;

  for (i = 0; i < n; i++)
    cin >> R[i];

  minv = R[0];

  for (i = 1; i < n; i++) {
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }

  cout << maxv << endl;

  return 0;
}

#include <algorithm>
#include <iostream>

using namespace std;

int main() {

  int R[200000], n;

  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> R[i];

  int maxv = -2000000000;
  int minv = R[0];

  for (int i = 1; i < n; i++) {
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }

  cout << maxv << endl;

  return 0;
}


#include <iostream>

using namespace std;

int main() {
  int n, r[200000], max = -2000000000;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> r[i];
  for (int i = 1; i < n; i++)
    for (int j = 0; j < i; j++) {
      if (r[i] - r[j] >= max) {
        max = r[i] - r[j];
      }
    }
  cout << max << endl;
  return 0;
}

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  int n, r[200000], minr = 2000000000, ans = -2000000000;
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> r[i];
  for (int i = 0; i < n; i++) {
    ans = max(r[i] - minr, ans);
    minr = min(r[i], minr);
  }

  cout << ans << endl;
  return 0;
}


#include <iostream>
using namespace std;

int rt[200000];

int main() {
  ios::sync_with_stdio(false);
  int n;
  int i, j;
  int max = 0x80000000;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> rt[i];
    for (j = 0; j < i; j++) {
      if (rt[i] - rt[j] > max) {
        max = rt[i] - rt[j];
      }
    }
  }
  cout << max << endl;
  return 0;
}

#include <iostream>
using namespace std;

int rt[200000];

int main() {
  ios::sync_with_stdio(false);
  int n;
  int i, j;
  int max, min;
  cin >> n;
  max = 0x80000000;
  for (i = 0; i < n; i++) {
    cin >> rt[i];
  }
  min = rt[0];
  for (i = 1; i < n; i++) {
    if ((rt[i] - min) > max) {
      max = rt[i] - min;
    }
    if ((rt[i]) < min) {
      min = rt[i];
    }
  }
  cout << max << endl;
  return 0;
}


#include <iostream>
#include <vector>
using namespace std;
//---------------------------------------
int max_profit(vector<int> vec);
//---------------------------------------

int main(void) {
  int num;
  vector<int> num_all;

  cin >> num;

  for (int i = 0; i < num; i++) {
    int n;
    cin >> n;
    num_all.push_back(n);
  }
  cout << max_profit(num_all) << endl;

  return 0;
}
//--------------------------------------------
int max_profit(vector<int> vec) {
  int minv = vec[0];
  int maxv = vec[1] - vec[0];

  for (int j = 1; j < vec.size(); j++) {
    if ((vec[j] - minv) > maxv) {
      maxv = vec[j] - minv;
    }
    if ((vec[j] < minv)) { //????????????????????????
      minv = vec[j];
    }
  }
  return maxv;
}
/*time error
int max_profit(vector<int> vec)
{
        int max = vec[1] - vec[0]; //???????????????????????\\????????????

        for(int i = vec.size() - 1; i > 0; i--){
                for(int j = 0; j < i; j++){
                        int num = vec[i] - vec[j];
                        if(max < num){
                                max = num;
                        }
                }
        }
        return max;
}
*/


#include <iostream>
#include <string>
using namespace std;

int main() {
  int n, v;
  int price[200000] = {0};
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> v;
    price[i] = v;
  }

  int max = 0;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      if (max == 0)
        max = (price[j] - price[i]);

      if ((price[j] - price[i]) > max)
        max = (price[j] - price[i]);
    }
  }

  cout << max << endl;

  return 0;
}

#include <iostream>
#include <string>
using namespace std;

int main() {
  int n, v;
  int R[200000] = {0};
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> v;
    R[i] = v;
  }

  int minv = R[0];
  int maxv = R[1] - R[0];
  for (int j = 1; j < n; j++) {
    if (maxv < (R[j] - minv))
      maxv = (R[j] - minv);
    if (minv > R[j])
      minv = R[j];

    // cout << "DEBUG:" << "minv=" << minv << ",maxv=" << maxv << endl;
  }

  cout << maxv << endl;

  return 0;
}


#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <string>
#include <typeinfo>
#include <vector>
#define _USE_MATH_DEFINES
#include <cmath>

using namespace std;

int main() {

  int n;
  cin >> n;

  vector<long> r(n);
  for (int i = 0; i < n; i++) {
    cin >> r[i];
  }

  int max = r[1] - r[0];

  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      if (max < r[j] - r[i]) {
        max = r[j] - r[i];
      }
    }
  }

  cout << max << endl;
  return 0;
}

#include <algorithm>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <string>
#include <typeinfo>
#include <vector>
#define _USE_MATH_DEFINES
#include <cmath>

using namespace std;

int main() {

  int n;
  cin >> n;

  vector<int> r(n);

  for (int i = 0; i < n; i++) {
    cin >> r[i];
  }

  int maxv = -2000000000;
  int minv = r[0];

  for (int i = 1; i < n; i++) {
    maxv = max(maxv, r[i] - minv);
    minv = min(minv, r[i]);
  }

  cout << maxv << endl;

  return 0;

  // TLE
  // int max = r[1] - r[0];
  //
  // for(int i=0; i<n-1; i++){
  //     for(int j=i+1; j<n; j++){
  //         if(max<r[j]-r[i]){
  //             max = r[j]-r[i];
  //         }
  //     }
  // }
  //
  // cout << max << endl;
}


#include <iostream>
using namespace std;
int main(void) {
  int n, R[200001];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> R[i];
  }
  int m = -1000000000;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (R[j] - R[i] > m)
        m = R[j] - R[i];
    }
  }

  cout << m << endl;

  return 0;
}

#include <iostream>
using namespace std;
int main(void) {
  int n, R[200001];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> R[i];
  }
  int minv = R[0];
  int maxv = -1000000001;
  for (int j = 1; j < n; j++) {
    if (R[j] - minv > maxv)
      maxv = R[j] - minv;
    if (R[j] < minv)
      minv = R[j];
  }

  cout << maxv << endl;

  return 0;
}


#include <cmath>
#include <iostream>

#define SIZE 200000

using namespace std;

int main(void) {
  int n, max, tmp, list[SIZE];

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> list[i];
  }

  max = list[1] - list[0];
  for (int i = n - 2; i >= 0; i--) {
    for (int j = i + 1; j < n; j++) {
      tmp = list[j] - list[i];
      if (max < tmp) {
        max = tmp;
      }
    }
  }

  cout << max << "\\n";

  return 0;
}

#include <cmath>
#include <iostream>

#define SIZE 200000

using namespace std;

int main(void) {
  int n, max, min, tmp;

  cin >> n;

  cin >> tmp >> max;

  min = max;
  max -= tmp;
  min = (tmp < min) ? tmp : min;

  for (int i = 0; i < n - 2; i++) {
    cin >> tmp;
    max = (max < tmp - min) ? (tmp - min) : max;
    min = (tmp < min) ? tmp : min;
  }

  std::cout << max << "\\n";

  return 0;
}


#include <iostream>
using namespace std;

int main() {
  int n;
  int i, j;
  int *p;
  int pro = -1000000000;

  cin >> n;
  p = new int[n];

  for (i = 0; i < n; i++) {
    cin >> p[i];
  }

  for (j = 1; j < n; j++) {
    for (i = 0; i < j; i++) {
      if (pro < p[j] - p[i]) {
        pro = p[j] - p[i];
      }
    }
  }

  cout << pro << endl;

  delete[] p;
  return 0;
}

#include <iostream>
using namespace std;

int main() {
  int n;
  int i, j;
  int *p;
  int max = -1000000000;
  int min;

  cin >> n;
  p = new int[n];

  for (i = 0; i < n; i++) {
    cin >> p[i];
  }

  min = p[0];
  for (j = 1; j < n; j++) {
    if (max < p[j] - min) {
      max = p[j] - min;
    }
    if (min > p[j]) {
      min = p[j];
    }
  }

  cout << max << endl;

  delete[] p;
  return 0;
}


#include "bits/stdc++.h"

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> R(n);
  for (int i = 0; i < n; ++i)
    cin >> R[i];
  auto itr_min = min_element(R.begin(), R.end());
  auto itr_max = max_element(itr_min, R.end());
  cout << ((*itr_max - *itr_min) <= 0 ? -1 : (*itr_max - *itr_min)) << endl;
  system("pause");
}

#include "bits/stdc++.h"

using namespace std;

int main() {
  int n;
  cin >> n;
  int ans = -999999999, minv;
  cin >> minv;
  for (int i = 1; i < n; ++i) {
    int a;
    cin >> a;
    ans = max(ans, a - minv);
    minv = min(minv, a);
  }
  cout << ans << endl;
  // system("pause");
}


#include <iostream>
using namespace std;

int main() {
  int n, r[200000], max;
  cin >> n;
  cin >> r[0];
  max = -r[0];
  for (int i = 1; i < n; i++) {
    cin >> r[i];
    for (int j = 0; j < i; j++)
      if (r[i] - r[j] > max)
        max = r[i] - r[j];
  }
  cout << max << endl;
  cin >> n;

  return 0;
}

#include <iostream>
using namespace std;

int main() {
  int n, r;
  long long max = -2000000000, min = 2000000000;
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> r;
    if (r - min > max)
      max = r - min;
    if (r < min)
      min = r;
  }
  cout << max << endl;

  return 0;
}


#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>

using namespace std;
int main() {
  int n;
  cin >> n;
  int maxV = -1000000000;
  vector<int> v;
  int a;
  for (int i = 0; i < n; i++) {
    cin >> a;
    v.push_back(a);
  }
  for (int i = 0; i < n; i++) {
    for (int j = n - 1; j > i; j--) {
      if (i == j) {
        break;
      }
      maxV = max(maxV, v[j] - v[i]);
    }
  }
  cout << maxV << endl;
  return 0;
}

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <vector>

using namespace std;
int main() {
  int n;
  cin >> n;
  int maxV = -1000000000;

  vector<int> v;
  int a;
  for (int i = 0; i < n; i++) {
    cin >> a;
    v.push_back(a);
  }
  int minV = v[0];
  for (int i = 1; i < n; i++) {
    maxV = max(maxV, v[i] - minV);
    minV = min(minV, v[i]);
  }
  cout << maxV << endl;
  return 0;
}


#include <iostream>
using namespace std;

int main() {
  int n;
  long int r[200000];
  long int maxv = -1000000000000;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> r[i];
  }

  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (maxv < r[j] - r[i])
        maxv = r[j] - r[i];
    }
  }
  cout << maxv << endl;
}

#include <iostream>
using namespace std;

int main() {
  int n;
  long int r[200000];
  long int maxv = -1000000000000;
  long int minv = 1000000000000;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> r[i];
  }

  for (int i = 0; i < n; i++) {
    maxv = (maxv < (r[i] - minv)) ? (r[i] - minv) : maxv;
    minv = (minv > r[i]) ? r[i] : minv;
  }
  cout << maxv << endl;
}


#include <iostream>
using namespace std;

int main() {

  int n;
  cin >> n;

  int *r = new int[n];
  for (int i = 0; i < n; ++i) {
    cin >> r[i];
  }

  int ans = -1000000000;
  for (int j = 0; j < n; ++j) {
    for (int k = j + 1; k < n; ++k) {
      int tmp = r[k] - r[j];
      if (ans < tmp)
        ans = tmp;
    }
  }
  cout << ans << endl;

  return 0;
}

#include <algorithm>
#include <iostream>
using namespace std;

int main() {

  int n;
  cin >> n;

  int *r = new int[n];
  int maxv = -2000000000;
  int minv = 1000000000;

  if (n == 2) {
    cin >> r[0] >> r[1];
    maxv = r[1] - r[0];
    cout << maxv << endl;
    return 0;
  }

  for (int i = 0; i < n; ++i) {
    cin >> r[i];
    maxv = max(maxv, r[i] - minv);
    minv = min(minv, r[i]);
  }

  cout << maxv << endl;

  delete[] r;
  return 0;
}


#include <iostream>
using namespace std;

int main(int argc, char const *argv[]) {
  int n = 0;
  cin >> n;
  int *a = new int[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int max = -2147483647;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if ((a[j] - a[i]) > max) {
        max = a[j] - a[i];
      }
    }
  }
  cout << max << endl;

  delete[] a;
  return 0;
}

#include <iostream>
using namespace std;

int main(int argc, char const *argv[]) {
  int n = 0;
  cin >> n;
  int min;
  cin >> min;
  int maxp = -2147483647;
  for (int i = 0; i < n - 1; i++) {
    int x = 0;
    cin >> x;
    if (maxp < x - min)
      maxp = x - min;
    if (x < min)
      min = x;
  }
  cout << maxp << endl;
  return 0;
}


#include <iostream>
using namespace std;

int main() {
  int n, sum = -2000000000;

  cin >> n;

  int r[n];

  for (int i = 0; i < n; i++)
    cin >> r[i];

  for (int i = 0; i < n - 1; i++) {
    //        cin >> r[i];
    for (int j = i + 1; j < n; j++) {
      //          cin >> r[j];
      if (sum <= r[j] - r[i])
        sum = r[j] - r[i];
    }
  }

  cout << sum << endl;

  return 0;
}

#include <iostream>
using namespace std;

int main() {
  int n, r;
  int max, min;

  cin >> n;

  cin >> r;          // 最初の数を入れる
  min = r;           // 最小値は最初の数
  max = -2000000000; // 差の最大値は-20億で初期化

  for (int i = 0; i < n - 1; i++) // 初めの数はもう入力しているので、n - 1
  {
    cin >> r;
    if (max < r - min)
      max = r - min;
    if (min > r)
      min = r;
  }

  cout << max << endl;

  return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n, max;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i != n; i++)
    cin >> a[i];
  max = a[1] - a[0];
  for (int i = 1; i != n; i++)
    for (int j = 0; j != i; j++)
      max = (a[i] - a[j] > max ? a[i] - a[j] : max);
  cout << max << endl;
}

#include <iostream>
#include <vector>
using namespace std;

int main() {
  int n, min, sub;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i != n; i++) {
    cin >> a[i];
    if (i == 0)
      min = a[0];
    if (i == 1)
      sub = a[1] - a[0];
    if (i > 1 && sub < a[i] - min)
      sub = a[i] - min;
    if (i > 0 && a[i] < min)
      min = a[i];
  }
  cout << sub << endl;
}


#include <iostream>
using namespace std;
int main() {
  int n, tag, i, j;
  int *p;
  cin >> n;
  p = new int[n];
  for (i = 0; i < n; i++)
    cin >> p[i];
  tag = p[1] - p[0];
  for (i = 0; i < n - 1; i++)
    for (j = i + 1; j < n; j++) {
      if (p[j] - p[i] > tag)
        tag = p[j] - p[i];
    }
  cout << tag << endl;
  delete[] p;
  return 0;
}

#include <iostream>
using namespace std;
int main() {
  int n, tag, minv, i, j;
  int *p;
  cin >> n;
  p = new int[n];
  for (i = 0; i < n; i++)
    cin >> p[i];
  tag = p[1] - p[0];
  minv = p[0];
  for (i = 1; i < n; i++) {
    if (p[i] - minv > tag)
      tag = p[i] - minv;
    if (minv > p[i])
      minv = p[i];
  }
  cout << tag << endl;
  delete[] p;
  return 0;
}


#include <stdio.h>

#define INPUT_MAX_NUM (200000)

int main(void) {
  // input num
  int num = 0;
  //  printf("input num\\n");
  scanf("%d", &num);

  // input value
  int r[INPUT_MAX_NUM];
  for (int i = 0; i < num; i++) {
    scanf("%d", &r[i]);
  }

  // max value of diff
  int max_diff;
  max_diff = r[1] - r[0];
  for (int i = 1; i < num; i++) {
    for (int j = i; j < num; j++) {
      if (max_diff < r[j] - r[i - 1]) {
        max_diff = r[j] - r[i - 1];
      }
    }
  }
  // printf("max_diff = %d\\n", max_diff);
  printf("%d\\n", max_diff);

  return 0;
}

#include <stdio.h>

#define INPUT_MAX_NUM (200000)

int main(void) {
  // input num
  int num = 0;
  //  printf("input num\\n");
  scanf("%d", &num);

  // input value
  int r[INPUT_MAX_NUM];
  for (int i = 0; i < num; i++) {
    scanf("%d", &r[i]);
  }

  // max value of diff
  /*
  int max_diff;
  max_diff = r[1] - r[0];
  for (int i = 1; i < num; i++ ) {
    for (int j = i; j < num; j++ ) {
      if ( max_diff < r[j] - r[i-1] ) {
        max_diff = r[j] - r[i-1];
      }
    }
  }
  */

  int max_diff = r[1] - r[0];
  int min = r[0];
  for (int i = 1; i < num; i++) {
    if (max_diff < r[i] - min) {
      max_diff = r[i] - min;
    }
    if (min > r[i]) {
      min = r[i];
    }
  }
  // printf("max_diff = %d\\n", max_diff);
  printf("%d\\n", max_diff);

  return 0;
}


#include <bits/stdc++.h>

#define pout(n) printf("%d\\n", n)

#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, n, a) for (int i = n - 1; i >= a; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const int d8y[8] = {0, 1, 1, 1, 0, -1, -1, -1};

#define MAX_N (int)2e5 + 20
#define INF 1e12 + 20

typedef long long ll;
using namespace std;

int n;
int main() {
  cin >> n;
  int r[n];
  rep(i, 0, n) { cin >> r[i]; }
  int ans = INT_MIN;
  rep(i, 0, n - 1) {
    rep(j, i + 1, n) { ans = max(r[j] - r[i], ans); }
  }
  pout(ans);
  return 0;
}

#include <bits/stdc++.h>

#define pout(n) printf("%d\\n", n)

#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, n, a) for (int i = n - 1; i >= a; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const int d8y[8] = {0, 1, 1, 1, 0, -1, -1, -1};

#define MAX_N (int)2e5 + 20
#define INF 1e12 + 20

typedef long long ll;
using namespace std;

int n;
int main() {
  cin >> n;
  int r[n];
  rep(i, 0, n) { cin >> r[i]; }
  int ans = INT_MIN;
  int mi = r[0];
  rep(i, 1, n) {
    ans = max(ans, r[i] - mi);
    mi = min(mi, r[i]);
  }
  pout(ans);
  return 0;
}


#include <climits>
#include <cstdio>
#include <cstdlib>
#include <iostream>

typedef int type;
typedef long long ll;
using namespace std;
const bool isDebug = false;

void showArray(type A[], int N) {
  for (int i = 0; i < N; i++) {
    printf("%d", A[i]);
    if (i != N - 1)
      printf(" ");
  }
  printf("\\n");
}

int bubbleSort(type A[], int N) {
  bool flag_inv = true;
  int changeTime = 0;
  while (flag_inv) {
    if (isDebug)
      showArray(A, N);
    flag_inv = false;
    for (int j = N - 1; j >= 1; j--) {
      if (A[j] < A[j - 1]) {
        type tmp = A[j];
        A[j] = A[j - 1];
        A[j - 1] = tmp;

        changeTime++;
        flag_inv = true;
      }
    }
  }
  return changeTime;
}

#define MAX_N 2000000
#define INF INT_MAX
int N;
ll A[MAX_N];
void input() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
}

void solve() {
  ll maxDiff = -1 * INF;
  ll minR = INF;
  for (int i_border = 1; i_border < N; i_border++) {
    //????°??????´??°
    if (A[i_border - 1] < minR) {
      minR = A[i_border - 1];
    }

    ll maxR = 0;
    //?????§?????´??°???O(N)??????????????£???????????????
    for (int i_k = i_border; i_k < N; i_k++) {
      if (A[i_k] > maxR)
        maxR = A[i_k];
    }

    if (maxDiff < maxR - minR)
      maxDiff = maxR - minR;
    if (isDebug)
      printf("%lld %lld %lld\\n", minR, maxR, maxDiff);
  }

  printf("%lld\\n", maxDiff);
}

int main() {
  input();
  solve();
  return 0;
}

#include <climits>
#include <cstdio>
#include <cstdlib>
#include <iostream>

typedef int type;
typedef long long ll;
using namespace std;
const bool isDebug = false;

void showArray(type A[], int N) {
  for (int i = 0; i < N; i++) {
    printf("%d", A[i]);
    if (i != N - 1)
      printf(" ");
  }
  printf("\\n");
}

int bubbleSort(type A[], int N) {
  bool flag_inv = true;
  int changeTime = 0;
  while (flag_inv) {
    if (isDebug)
      showArray(A, N);
    flag_inv = false;
    for (int j = N - 1; j >= 1; j--) {
      if (A[j] < A[j - 1]) {
        type tmp = A[j];
        A[j] = A[j - 1];
        A[j - 1] = tmp;

        changeTime++;
        flag_inv = true;
      }
    }
  }
  return changeTime;
}

#define MAX_N 2000000
#define INF INT_MAX
int N;
ll A[MAX_N];
void input() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
}

// void solve(){
//     ll maxDiff = -1*INF;
//     ll minR = INF;
//     for(int i_border = 1; i_border < N; i_border++){
//         //????°??????´??°
//         if(A[i_border-1] < minR){
//             minR = A[i_border-1];
//         }
//
//         ll maxR = 0;
//         //?????§?????´??°???O(N)??????????????£???????????????
//         for(int i_k=i_border; i_k < N; i_k++){
//             if(A[i_k] > maxR) maxR = A[i_k];
//         }
//
//         if(maxDiff < maxR-minR) maxDiff = maxR-minR;
//         if(isDebug) printf("%lld %lld %lld\\n", minR, maxR, maxDiff);
//     }
//
//     printf("%lld\\n", maxDiff);
// }
void solve() {
  ll maxDiff = -1 * INF;
  ll minR = A[0];
  for (int i_border = 1; i_border < N; i_border++) {

    if (maxDiff < A[i_border] - minR)
      maxDiff = A[i_border] - minR;
    if (isDebug)
      printf("%lld %lld\\n", minR, maxDiff);

    //????°??????´??°
    if (A[i_border] < minR) {
      minR = A[i_border];
    }
  }

  printf("%lld\\n", maxDiff);
}

int main() {
  input();
  solve();
  return 0;
}


#include <iostream>
using namespace std;

int main() {
  int c;
  cin >> c;
  int t[c];
  int max[1];
  for (int i = 0; i < c; ++i) {
    cin >> t[i];
  }
  max[0] = t[1] - t[0];
  for (int i = 0; i < c; ++i) {
    for (int j = i + 1; j < c; ++j) {
      if (max[0] < t[j] - t[i]) {
        max[0] = t[j] - t[i];
      }
    }
  }
  cout << max[0] << endl;
  return 0;
}

#include <algorithm>
#include <iostream>
using namespace std;
static const int MAX = 200000;

int main() {
  int R[MAX], n;

  cin >> n;
  for (int i = 0; i < n; ++i)
    cin >> R[i];

  int maxv = -2000000000;
  int minv = R[0];

  for (int i = 1; i < n; ++i) {
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }

  cout << maxv << endl;

  return 0;
}


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <list>
#include <map>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;

  vector<int> r;
  for (int i = 0; i < n; i++) {
    int ri;
    cin >> ri;
    r.push_back(ri);
  }

  int diffmax = r[1] - r[0];
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      diffmax = max(diffmax, r[j] - r[i]);
    }
  }

  cout << diffmax << endl;

  return 0;
}

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <list>
#include <map>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;

  vector<int> r;
  for (int i = 0; i < n; i++) {
    int ri;
    cin >> ri;
    r.push_back(ri);
  }

  int diffmax = r[1] - r[0];
  int rmin = r[0];
  for (int i = 1; i < n; i++) {
    diffmax = max(diffmax, r[i] - rmin);
    rmin = min(rmin, r[i]);
  }

  cout << diffmax << endl;

  return 0;
}


#include <iostream>
using namespace std;
static const int MAX = 200000;

int main() {
  int n, rt[MAX];
  cin >> n;

  for (int i = 0; i < n; i++)
    cin >> rt[i];
  int maxv = rt[1] - rt[0];
  for (int j = 1; j < n; j++) {
    for (int i = 0; i < j; i++) {
      maxv = maxv < rt[j] - rt[i] ? rt[j] - rt[i] : maxv;
    }
  }
  cout << maxv << endl;
  return 0;
}

#include <algorithm>
#include <iostream>
using namespace std;
const int MAX = 2000000;

int main(void) {
  int n, rt[MAX];

  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> rt[i];

  int maxv = -2000000000;
  int minv = rt[0];

  for (int i = 1; i < n; i++) {
    maxv = max(maxv, rt[i] - minv);
    minv = min(minv, rt[i]);
  }
  cout << maxv << endl;
  return 0;
}


#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  int r[n];
  for (int i = 0; i < n; i++) {
    cin >> r[i];
  }
  int max = r[1] - r[0];
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      if (r[j] - r[i] > max) {
        max = r[j] - r[i];
      }
    }
  }
  cout << max << endl;
  return 0;
}

#include <iostream>
using namespace std;
int max(int a, int b) { return a > b ? a : b; }
int min(int a, int b) { return a < b ? a : b; }
int main() {
  int n;
  cin >> n;
  int r[n];
  for (int i = 0; i < n; i++) {
    cin >> r[i];
  }
  int minv = r[0];
  int maxv = -2000000000;
  for (int i = 1; i < n; i++) {
    maxv = max(maxv, r[i] - minv);
    minv = min(minv, r[i]);
  }
  cout << maxv << endl;
  return 0;
}


#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  int array[n];
  for (int i = 0; i < n; i++) {
    cin >> array[i];
  }
  int max = array[1] - array[0];

  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      if (array[j] - array[i] > max) {
        max = array[j] - array[i];
      }
    }
  }
  cout << max << "\\n";
}

#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  int array[n];
  for (int i = 0; i < n; i++) {
    cin >> array[i];
  }
  int min = array[0];
  int max = array[1] - array[0];

  for (int i = 1; i < n; i++) {

    if ((array[i] - min) > max) {
      max = array[i] - min;
    }
    if (array[i] < min) {
      min = array[i];
    }
  }
  cout << max << "\\n";
}


#include <climits>
#include <cstdio>

int max(int a, int b) { return (a > b) ? a : b; }

int maxRange(int *a, int start, int end) {
  int max = INT_MIN;
  for (int i = start; i <= end; i++) {
    if (a[i] > max)
      max = a[i];
  }
  return max;
}

int main() {
  int N;
  scanf("%d", &N);
  int R[N];
  for (int i = 0; i < N; i++)
    scanf("%d", &R[i]);

  int max_range = INT_MIN;
  int min = R[0];
  for (int i = 0; i < N - 1; i++) {
    if (R[i] < min)
      min = R[i];
    max_range = max(max_range, maxRange(R, i + 1, N - 1) - min);
  }
  printf("%d\\n", max_range);
  return 0;
}

#include <climits>
#include <cstdio>

int max(int a, int b) { return (a > b) ? a : b; }

int maxRange(int *a, int start, int end) {
  int max = INT_MIN;
  for (int i = start; i <= end; i++) {
    if (a[i] > max)
      max = a[i];
  }
  return max;
}

int main() {
  int N;
  scanf("%d", &N);
  int R[N];
  for (int i = 0; i < N; i++)
    scanf("%d", &R[i]);

  int max_range = INT_MIN;
  int min = R[0];
  int max_v = maxRange(R, 1, N - 1);
  for (int i = 0; i < N - 1; i++) {
    if (R[i] < min)
      min = R[i];
    if (R[i] == max_v)
      max_v = maxRange(R, i + 1, N - 1);
    max_range = max(max_range, max_v - min);
  }
  printf("%d\\n", max_range);
  return 0;
}


#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  int r[n];
  for (int i = 0; i < n; ++i) {
    cin >> r[i];
  }
  int M = r[1] - r[0];
  for (int i = 0; i < n - 1; ++i) {
    for (int j = i + 1; j < n; ++j) {
      M = max(M, r[j] - r[i]);
    }
  }
  cout << M << endl;
  return 0;
}

#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  int M = -1000000000;
  int m;
  cin >> m;
  for (int i = 1; i < n; ++i) {
    int r;
    cin >> r;
    M = max(M, r - m);
    m = min(m, r);
  }
  cout << M << endl;
  return 0;
}


#include <iostream>
using namespace std;

int main() {
  int R[200000], max_gain, n, i, j;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> R[i];
  }
  max_gain = R[1] - R[0];
  for (i = 0; i < n - 1; i++) {
    for (j = i + 1; j < n; j++) {
      if (max_gain < R[j] - R[i])
        max_gain = R[j] - R[i];
    }
  }
  cout << max_gain << endl;
  return 0;
}

#include <iostream>
using namespace std;

int main() {
  int R, n, i, max_gain, min;
  cin >> n;
  cin >> R;
  min = R;
  cin >> R;
  max_gain = R - min;
  if (min > R)
    min = R;
  for (i = 2; i < n; i++) {
    cin >> R;
    if (max_gain < R - min)
      max_gain = R - min;
    if (min > R)
      min = R;
  }
  cout << max_gain << endl;
  return 0;
}


#include <iostream>

void input_array(int a[], int n) {
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
  }
}

int max_value(int a[], int n) {

  int max_v = a[1] - a[0];
  int idx_before, idx_before_max_a, idx_max_a;

  for (int i = 0; i < n; i++) {
    int max_a = a[i + 1];
    if (i > 0 && i < n - 1) {
      while (a[i] > a[idx_before] && i < n - 1) {
        i += 1;
      }
      if (i == n - 1) {
        break;
      }

      max_a = a[i + 1];
      idx_max_a = i + 1;

      if (idx_max_a <= idx_before_max_a) {
        idx_before = i;
        max_v = a[idx_before_max_a] - a[i];

      } else {
        for (int j = i + 2; j < n; j++) {
          if (a[j] > max_a) {
            max_a = a[j];
            idx_max_a = j;
          }
        }
        idx_before = i;
        if ((max_a - a[i]) > max_v) {
          max_v = max_a - a[i];
          idx_before_max_a = idx_max_a;
        }
      }
    } else {
      for (int j = i + 2; j < n; j++) {
        if (a[j] > max_a) {
          max_a = a[j];
          idx_max_a = j;
        }
      }
      idx_before = i;
      max_v = max_a - a[i];
      idx_before_max_a = idx_max_a;
    }
  }
  return max_v;
}

int main() {

  int n;
  std::cin >> n;
  int R[n];
  input_array(R, n);
  int v = max_value(R, n);
  std::cout << v << '\\n';
  return 0;
}

#include <iostream>

void input_array(int a[], int n) {
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
  }
}

int max_value(int a[], int n) {

  int minv = a[0];
  int maxv = a[1] - minv;

  for (int i = 1; i < n; i++) {
    maxv = (maxv < (a[i] - minv)) ? a[i] - minv : maxv;
    minv = (minv < a[i]) ? minv : a[i];
  }

  return maxv;
}

int main() {

  int n;
  std::cin >> n;
  int R[n];
  input_array(R, n);
  int v = max_value(R, n);
  std::cout << v << '\\n';
  return 0;
}


#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  int money[200001];
  int min;
  int profit = 1 - 1000000000;

  for (int i = 1; i <= n; i++) {
    cin >> money[i];
  }
  for (int j = 1; j < n; j++) {
    min = money[j];
    for (int k = j + 1; k <= n; k++) {
      if (money[k] - min > profit) {
        profit = money[k] - min;
      }
    }
  }

  cout << profit << endl;
  return 0;
}

#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  int money[200001];
  money[0] = 2000000000;
  int maxProfit = 1 - 1000000000;
  int min = money[0];

  for (int i = 1; i <= n; i++) {
    cin >> money[i];
    if (money[i] - min > maxProfit) {
      maxProfit = money[i] - min;
    }
    if (min > money[i]) {
      min = money[i];
    }
  }
  cout << maxProfit << endl;
  return 0;
}


#include <iostream>

using namespace std;
static const int MAX = 200000;

int main() {
  int a[MAX], n;
  cin >> n;
  int max, tmp;
  max = -1000000000;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int j = 1; j < n; j++) {
    for (int i = 0; i < j; i++) {
      tmp = a[j] - a[i];
      if (max < tmp) {
        max = tmp;
      }
    }
  }
  cout << max << endl;
}

#include <iostream>

using namespace std;
static const int MAX = 200000;

int main() {
  int a[MAX], n;
  cin >> n;
  int max, tmp;
  int min;
  max = -1000000000;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  min = a[0];
  for (int i = 1; i < n; i++) {
    tmp = a[i] - min;
    if (max < tmp) {
      max = tmp;
    }
    if (min > a[i]) {
      min = a[i];
    }
  }
  cout << max << endl;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, dif;
  cin >> n;
  int *r = new int[n];
  for (int i = 0; i < n; i++) {
    cin >> r[i];
  }
  int currentMax = r[1] - r[0];
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < i; j++) {
      dif = r[i] - r[j];
      if (dif > currentMax) {
        currentMax = dif;
      }
    }
  }

  cout << currentMax << endl;

  return 0;
}

#include <iostream>
using namespace std;

int main() {
  int n, dif;
  cin >> n;
  int *r = new int[n];
  for (int i = 0; i < n; i++) {
    cin >> r[i];
  }
  int currentMax = r[1] - r[0];
  int currentMin = r[0];
  for (int i = 1; i < n; i++) {
    if (r[i] - currentMin > currentMax)
      currentMax = r[i] - currentMin;
    if (r[i] < currentMin)
      currentMin = r[i];
  }

  cout << currentMax << endl;

  return 0;
}


#include <cmath>
#include <iostream>
#include <vector>
using namespace std;

int main() {

  long long n, MAX = -1000000000;
  cin >> n;
  vector<int> R(n);

  /* 株価の値を入力 */
  for (int i = 0; i < n; i++) {
    cin >> R[i];
  }

  /* 株価の最大値を探す */
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (MAX < R[j] - R[i])
        MAX = R[j] - R[i];
    }
  }

  cout << MAX << endl;

  return 0;
}

#include <cmath>
#include <iostream>
#include <vector>
using namespace std;

int main() {

  long long n, MAX = -1000000000;
  cin >> n;
  vector<int> R(n);

  /* 株価の値を入力 */
  for (int i = 0; i < n; i++) {
    cin >> R[i];
  }

  /* 株価の最大値を探す */
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (MAX < R[j] - R[i])
        MAX = R[j] - R[i];
      if (R[i] >= R[j])
        break;
    }
  }

  cout << MAX << endl;

  return 0;
}


#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  int R[n];
  int maxv = -2000000000;

  for (size_t i = 0; i < n; i++) {
    cin >> R[i];
  }

  for (size_t i = 1; i < n; i++) {
    for (size_t j = 0; j < i; j++) {
      if (maxv <= R[i] - R[j]) {
        maxv = R[i] - R[j];
      }
    }
  }

  cout << maxv << endl;
}

// ALDS_1_1_D.cpp
#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  int R[n];
  int maxv = -2000000000;

  for (size_t i = 0; i < n; i++) {
    cin >> R[i];
  }

  int minv = R[0];

  for (size_t i = 1; i < n; i++) {
    if (maxv < R[i] - minv) {
      maxv = R[i] - minv;
    }
    if (minv > R[i]) {
      minv = R[i];
    }
  }

  cout << maxv << endl;
}


#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  int Rt[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &Rt[i]);
  }

  int max = Rt[1] - Rt[0];

  for (int j = 1; j < n; j++) {
    int min = Rt[0];
    for (int i = 1; i < j; i++) {
      if (Rt[i] < min) {
        min = Rt[i];
      }
    }
    if (Rt[j] - min > max) {
      max = Rt[j] - min;
    }
  }

  printf("%d\\n", max);
  return 0;
}

#include <algorithm>
#include <cstdio>
#include <iostream>

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  int Rt[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", &Rt[i]);
  }

  int maxv = Rt[1] - Rt[0];
  int minv = Rt[0];

  for (int j = 1; j < n; j++) {
    minv = min(minv, Rt[j - 1]);
    maxv = max(maxv, Rt[j] - minv);
  }

  printf("%d\\n", maxv);

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main() {
  int n;

  scanf("%d", n);
  vector<int> r(n), max_n(n);
  for (int i = 0; i < n; ++i)
    cin >> r[i];

  max_n[n - 2] = r[n - 1];
  for (int i = n - 3; i >= 0; --i)
    max_n[i] = max(r[i + 1], max_n[i + 1]);

  int ans = -1e9 - 1;
  for (int i = 0; i < n - 1; ++i)
    ans = max(ans, max_n[i] - r[i]);

  cout << ans << "\\n";

  return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main() {
  int n;

  scanf("%d", &n);
  vector<int> r(n), max_n(n);
  for (int i = 0; i < n; ++i)
    scanf("%d", &r[i]);

  max_n[n - 2] = r[n - 1];
  for (int i = n - 3; i >= 0; --i)
    max_n[i] = max(r[i + 1], max_n[i + 1]);

  int ans = -1e9 - 1;
  for (int i = 0; i < n - 1; ++i)
    ans = max(ans, max_n[i] - r[i]);

  cout << ans << "\\n";

  return 0;
}


#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

int R[200008];
int n;
int dif;

void input() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> R[i];
}

void solve() {
  dif = -2000000000;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (dif < (R[j] - R[i])) {
        dif = R[j] - R[i];
      }
    }
  }
  cout << dif << endl;
}
int main() {
  input();
  solve();
}

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

using namespace std;

int R[200008];
int n, dif, minv;

void input() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> R[i];
}

void solve() {
  dif = -2000000000;
  minv = R[0];
  for (int i = 1; i < n; i++) {
    dif = max(dif, R[i] - minv);
    minv = min(minv, R[i]);
  }
  cout << dif << endl;
}
int main() {
  input();
  solve();
}


#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

int main() {
  int R[200000];
  int t;
  int max = -2000000001; // 最大利益
  int min;
  cin >> t;

  for (int i = 0; i < t; i++)
    cin >> R[i];

  for (int j = 0; j < t; j++) {
    for (int i = 0; i < j; i++) {
      max = (max < R[j] - R[i]) ? R[j] - R[i] : max;
    }
  }
  cout << max << endl;

  return 0;
}

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;

int main() {
  int R[200000];
  int n;
  int maxv, minv;

  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> R[i];
  maxv = -2000000001;
  minv = R[0];
  for (int i = 1; i < n; i++) {
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }
  cout << maxv << endl;
  return 0;
}


#include <cmath>
#include <iostream>
using namespace std;

int main() {
  unsigned long n = 0;
  long a[200000] = {0}, pf = 0;

  cin >> n;

  for (unsigned long i = 0; i < n; i++)
    cin >> a[i];

  pf = a[1] - a[0];

  for (unsigned long i = 0; i < n - 1; i++) {
    for (unsigned long j = i + 1; j < n; j++) {
      if (a[j] - a[i] > pf)
        pf = a[j] - a[i];
    }
  }

  cout << pf << endl;

  return 0;
}

#include <iostream>
using namespace std;

int main() {
  unsigned long n = 0;
  long a = 0, b = 0, pf = 0;

  cin >> n;
  cin >> a;

  b = a;
  pf = -a;

  for (unsigned long i = 0; i < n - 1; i++) {
    cin >> a;

    if (a - b >= pf)
      pf = a - b;
    if (a < b)
      b = a;
  }

  cout << pf << endl;

  return 0;
}


#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
const int INF = 0x3f3f3f3f;

int main() {
  int m, n;
  while (scanf("%d", &n)) {
    int ans = -INF;
    cin >> m;
    int Min = m;
    for (int i = 2; i <= n; i++) {
      cin >> m;
      ans = max(ans, m - Min);
      Min = min(Min, m);
    }
    printf("%d\\n", ans);
  }
  return 0;
}

#include <algorithm>
#include <cstdio>
#include <iostream>
using namespace std;
const int INF = 0x3f3f3f3f;

int main() {
  int m, n;
  cin >> n;
  int ans = -INF;
  cin >> m;
  int Min = m;
  for (int i = 2; i <= n; i++) {
    cin >> m;
    ans = max(ans, m - Min);
    Min = min(Min, m);
  }
  printf("%d\\n", ans);
  return 0;
}


#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int A[100000];

void sort(int N) {
  for (int i = 1; i < N; i++) {
    for (int t = i; t > 0; t--) {
      if (A[t] < A[t - 1]) {
        swap(A[t], A[t - 1]);
      } else {
        break;
      }
    }
  }
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }

  int mx = -1000000000;
  for (int i = 0; i < n - 1; i++) {
    for (int t = i + 1; t < n; t++) {
      mx = max(A[t] - A[i], mx);
    }
  }

  cout << mx << endl;

  return 0;
}

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {
  int n;
  int a[200000];
  cin >> n;
  int mi = 2000000000, mx = -1000000000;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mx = max(mx, a[i] - mi);
    mi = min(mi, a[i]);
  }

  cout << mx << endl;

  return 0;
}


#include <iostream>

using namespace std;

int main() {
  int n;
  cin >> n;
  int r[n];
  for (int i = 0; i < n; i++)
    cin >> r[i];
  int a = r[1] - r[0];
  for (int i = 1; i < n; i++) {
    for (int o = i - 1; o >= 0; o--) {
      if (r[i] - r[o] > a)
        a = r[i] - r[o];
    }
  }
  cout << a << endl;
}

#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int n, c, b = 2000000000, a = -1000000001;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> c;
    a = max(c - b, a);
    b = min(c, b);
  }
  cout << a << endl;
}


#include <iostream>
using namespace std;

int main() {
  int n, i, j;
  long m = -1000000000, k = 0;
  int a[200000];
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }

  for (i = 0; i < n - 1; i++) {
    for (j = i; j < n - 1; j++) {
      k = a[j + 1] - a[i];
      if (m < k) {
        m = k;
      }
    }
  }

  cout << m << endl;

  return 0;
}

#include <iostream>
using namespace std;

int main() {
  int n, i, j, l = 0;
  long m = -1000000000, k = 0;
  int a[200000];
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }

  l = a[0];
  for (i = 1; i < n; i++) {
    k = a[i] - l;
    if (m < k) {
      m = k;
    }
    if (a[i] < l) {
      l = a[i];
    }
  }

  cout << m << endl;

  return 0;
}


#include <iostream>
using namespace std;

int main() {
  int n, i, j, p;
  cin >> n;
  int a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }

  p = a[1] - a[0];
  for (i = 0; i < n - 1; i++) {
    for (j = i + 1; j < n; j++) {
      if (p < a[j] - a[i])
        p = a[j] - a[i];
    }
  }

  cout << p << endl;
  return 0;
}

#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int n, i, j, maxp, minp;
  cin >> n;
  int a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }

  maxp = a[1] - a[0];
  minp = a[0];
  for (i = 1; i < n; i++) {
    maxp = max(maxp, a[i] - minp);
    minp = min(minp, a[i]);
  }

  cout << maxp << endl;
  return 0;
}


#include <iostream>
using namespace std;
#define is_uruu main

int is_uruu() {
  int n, max = -1000000000;
  cin >> n;
  int R[n];
  for (int i = 0; i < n; i++)
    cin >> R[i];

  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      if (R[j] - R[i] > max)
        max = R[j] - R[i];
    }
  }

  cout << max << endl;
  return 0;
}

#include <iostream>
using namespace std;
#define is_uruu main

int is_uruu() {
  int n, maxv = -1000000000;
  cin >> n;
  int R[n];
  for (int i = 0; i < n; i++)
    cin >> R[i];

  int minv = R[0];
  for (int i = 1; i < n; i++) {
    maxv = max(maxv, R[i] - minv);
    minv = min(minv, R[i]);
  }

  cout << maxv << endl;
  return 0;
}