#include <bits/stdc++.h>
using namespace std;
long long maximum = numeric_limits<int>::max();
inline int bit(int x, int i) { return (x >> i) & 1; }
bool sortbysec(const pair<int, int>& a, const pair<int, int>& b) {
  return (a.second < b.second);
}
long long int get_hash(long long int x, long long int y, long long int z) {
  return (z) + (3001) * (y) + (3001 * 3001 * (x));
}
long long int com(long long int n, long long int m) {
  long long int ans = 1;
  m = max(m, n - m);
  for (long long int i = 1; i < n - m; i++) {
    ans = (ans * (m + i)) / i;
  }
  return ans;
}
int solve() {
  long long int n, m, k;
  cin >> n >> m >> k;
  vector<int> v(n);
  for (long long int i = 0; i < n; i++) cin >> v[i];
  k = min(k, m - 1);
  long long int ans = -1;
  int moves = m - 1 - k;
  for (int i = 0; i <= k; i++) {
    long long int temp_ans = 1e18;
    for (int j = 0; j <= moves; j++) {
      long long int mini = max(v[i + j], v[i + j + n - m]);
      temp_ans = min(temp_ans, mini);
    }
    ans = max(ans, temp_ans);
  }
  cout << ans << endl;
}
int n;
vector<long long int> gr[150001];
vector<long long int> iota(int n) {
  vector<long long int> a(n);
  iota(a.begin(), a.end(), 1);
  return a;
}
int get_parent(int i, vector<long long int> par) {
  while (par[i] != i) i = par[i];
  return i;
}
void dfs(int node) {
  cout << node << " ";
  for (auto x : gr[node]) {
    dfs(x);
  }
}
set<long long int> s;
multiset<long long int> dif;
long long int a;
void add_postion(long long int a) {
  s.insert(a);
  auto it = s.find(a);
  if (next(it) != s.end()) dif.insert(*next(it) - a);
  if (it != s.begin()) {
    dif.insert(a - *prev(it));
    if (next(it) != s.end()) dif.erase(dif.find(*next(it) - *prev(it)));
  }
}
void erase_position(long long int a) {
  auto it = s.find(a);
  if (next(it) != s.end()) dif.erase(dif.find(*next(it) - a));
  if (it != s.begin()) {
    dif.erase(dif.find(a - *prev(it)));
    if (next(it) != s.end()) dif.insert(*next(it) - *prev(it));
  }
  s.erase(it);
}
long long int query() {
  if (s.size() <= 2) return 0;
  return *(--s.end()) - *s.begin() - *(--dif.end());
}
vector<long long int> adj_test[11];
vector<long long int> h(11, 0);
auto par = iota(11);
void dfs_test(int v, int p = -1) {
  if (p + 1) {
    h[v] = h[p] + 1;
  }
  par[v] = p;
  for (auto u : adj_test[v]) {
    if (p - u) dfs_test(u, v);
  }
}
int LCA(int v, int u) {
  if (v == u) return v;
  if (h[v] < h[u]) swap(v, u);
  return LCA(par[v], u);
}
int TIME = 0;
vector<long long int> st(11, 0);
vector<long long int> ft(11, 0);
vector<long long int> color(11, -1);
void dfs_time(int v) {
  st[v] = TIME++;
  color[v] = 1;
  for (auto u : adj_test[v]) {
    if (color[u] == -1) dfs_time(u);
  }
  ft[v] = TIME;
}
int arr[10000];
int block[100];
int blk_sz;
void update(int idx, int val) {
  int blockNumber = idx / blk_sz;
  block[blockNumber] += val - arr[idx];
  arr[idx] = val;
}
bool bin_search(int x[], int n, int k) {
  int p = 0;
  for (int a = n; a >= 1; a /= 2) {
    while (p + a < n && x[p + a] <= k) p += a;
  }
  return x[p] == k;
}
int count_same(int x[], int n, int k) {
  int p = -1, q = -1;
  for (int a = n; a >= 1; a /= 2) {
    while (p + a < n && x[p + a] < k) p += a;
    while (q + a < n && x[q + a] <= k) q += a;
  }
  return q - p;
}
int query(int l, int r) {
  int sum = 0;
  while (l < r and l % blk_sz != 0 and l != 0) {
    sum += arr[l];
    l++;
  }
  while (l + blk_sz <= r) {
    sum += block[l / blk_sz];
    l += blk_sz;
  }
  while (l <= r) {
    sum += arr[l];
    l++;
  }
  return sum;
}
void preprocess(int input[], int n) {
  int blk_idx = -1;
  blk_sz = sqrt(n);
  for (int i = 0; i < n; i++) {
    arr[i] = input[i];
    if (i % blk_sz == 0) {
      blk_idx++;
    }
    block[blk_idx] += arr[i];
  }
}
void showdq(deque<long long int> g) {
  deque<long long int>::iterator it;
  for (it = g.begin(); it != g.end(); ++it) cout << *it << ' ';
  cout << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n;
  cin >> n;
  vector<long long int> v(n);
  for (long long int i = 0; i < n; i++) cin >> v[i];
  long long int ans = 0;
  vector<long long int> cnt(n);
  cnt[n - 1] = !v[n - 1];
  for (long long int i = n - 2; i > -1; i--) {
    cnt[i] += cnt[i + 1] + !v[i];
  }
  for (long long int i = 0; i < n; i++) {
    if (v[i]) {
      ans += cnt[i];
    }
  }
  cout << ans;
}
class Node {
 public:
  int data;
  Node* left;
  Node* right;
  Node* next;
  Node(int d) {
    data = d;
    left = NULL;
    right = NULL;
  }
};
class Solution {
 public:
  Node* insert(Node* root, int data) {
    if (root == NULL) {
      return new Node(data);
    } else {
      Node* cur;
      if (data <= root->data) {
        cur = insert(root->left, data);
        root->left = cur;
      } else {
        cur = insert(root->right, data);
        root->right = cur;
      }
      return root;
    }
  }
  int get_height_bfs(Node* root) {
    int h = 0;
    queue<Node*> q;
    q.push(root);
    while (!q.empty()) {
      h++;
      Node* temp = q.front();
      q.pop();
      if (temp->left) q.push(temp->left);
      if (temp->right) q.push(temp->right);
    }
  }
  int get_Height(Node* root, int h) {
    if (root == nullptr)
      return h - 1;
    else {
      return max(get_Height(root->left, h + 1), get_Height(root->right, h + 1));
    }
  }
  int getHeight(Node* root) {
    int ans = 0;
    ans = get_Height(root, 0);
    return ans;
  }
  Node* removeDuplicates(Node* head) {
    Node* current = head;
    while (current != nullptr && current->next != nullptr) {
      Node* temp = current->next;
      if (current->data == temp->data) {
        current->next = temp->next;
        delete temp;
      } else {
        current = current->next;
      }
    }
    return head;
  }
};
void make_tree() {
  Solution myTree;
  Node* root = NULL;
  int t;
  cin >> t;
  int data;
  while (t-- > 0) {
    cin >> data;
    root = myTree.insert(root, data);
  }
  int height = myTree.getHeight(root);
  cout << height;
}
class BinaryTree {
 public:
  int value;
  BinaryTree* left;
  BinaryTree* right;
  BinaryTree(int value) {
    this->value = value;
    left = NULL;
    right = NULL;
  }
};
void dfs(BinaryTree* root, int sum, vector<int>& ans) {
  int sum1 = sum, sum2 = sum;
  if (root != nullptr and root->left != nullptr) sum1 += root->left->value;
  if (root != nullptr) dfs(root->left, sum1, ans);
  if (root != nullptr and root->right != nullptr) sum2 += root->right->value;
  if (root != nullptr) dfs(root->right, sum2, ans);
  if (root != nullptr and root->right == nullptr and root->left == nullptr)
    ans.push_back(sum);
}
vector<int> branchSums(BinaryTree* root) {
  vector<int> ans = {};
  if (root != nullptr) dfs(root, root->value, ans);
  return {ans};
}

### Prompt

Construct a CPP code solution to the problem outlined:

Iahub helps his grandfather at the farm. Today he must milk the cows. There are n cows sitting in a row, numbered from 1 to n from left to right. Each cow is either facing to the left or facing to the right. When Iahub milks a cow, all the cows that see the current cow get scared and lose one unit of the quantity of milk that they can give. A cow facing left sees all the cows with lower indices than her index, and a cow facing right sees all the cows with higher indices than her index. A cow that got scared once can get scared again (and lose one more unit of milk). A cow that has been milked once cannot get scared and lose any more milk. You can assume that a cow never loses all the milk she can give (a cow gives an infinitely amount of milk).

Iahub can decide the order in which he milks the cows. But he must milk each cow exactly once. Iahub wants to lose as little milk as possible. Print the minimum amount of milk that is lost.

Input

The first line contains an integer n (1 ≤ n ≤ 200000). The second line contains n integers a1, a2, ..., an, where ai is 0 if the cow number i is facing left, and 1 if it is facing right.

Output

Print a single integer, the minimum amount of lost milk.

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

Examples

Input

4
0 0 1 0


Output

1

Input

5
1 0 1 0 1


Output

3

Note

In the first sample Iahub milks the cows in the following order: cow 3, cow 4, cow 2, cow 1. When he milks cow 3, cow 4 loses 1 unit of milk. After that, no more milk is lost.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long maximum = numeric_limits<int>::max();
inline int bit(int x, int i) { return (x >> i) & 1; }
bool sortbysec(const pair<int, int>& a, const pair<int, int>& b) {
  return (a.second < b.second);
}
long long int get_hash(long long int x, long long int y, long long int z) {
  return (z) + (3001) * (y) + (3001 * 3001 * (x));
}
long long int com(long long int n, long long int m) {
  long long int ans = 1;
  m = max(m, n - m);
  for (long long int i = 1; i < n - m; i++) {
    ans = (ans * (m + i)) / i;
  }
  return ans;
}
int solve() {
  long long int n, m, k;
  cin >> n >> m >> k;
  vector<int> v(n);
  for (long long int i = 0; i < n; i++) cin >> v[i];
  k = min(k, m - 1);
  long long int ans = -1;
  int moves = m - 1 - k;
  for (int i = 0; i <= k; i++) {
    long long int temp_ans = 1e18;
    for (int j = 0; j <= moves; j++) {
      long long int mini = max(v[i + j], v[i + j + n - m]);
      temp_ans = min(temp_ans, mini);
    }
    ans = max(ans, temp_ans);
  }
  cout << ans << endl;
}
int n;
vector<long long int> gr[150001];
vector<long long int> iota(int n) {
  vector<long long int> a(n);
  iota(a.begin(), a.end(), 1);
  return a;
}
int get_parent(int i, vector<long long int> par) {
  while (par[i] != i) i = par[i];
  return i;
}
void dfs(int node) {
  cout << node << " ";
  for (auto x : gr[node]) {
    dfs(x);
  }
}
set<long long int> s;
multiset<long long int> dif;
long long int a;
void add_postion(long long int a) {
  s.insert(a);
  auto it = s.find(a);
  if (next(it) != s.end()) dif.insert(*next(it) - a);
  if (it != s.begin()) {
    dif.insert(a - *prev(it));
    if (next(it) != s.end()) dif.erase(dif.find(*next(it) - *prev(it)));
  }
}
void erase_position(long long int a) {
  auto it = s.find(a);
  if (next(it) != s.end()) dif.erase(dif.find(*next(it) - a));
  if (it != s.begin()) {
    dif.erase(dif.find(a - *prev(it)));
    if (next(it) != s.end()) dif.insert(*next(it) - *prev(it));
  }
  s.erase(it);
}
long long int query() {
  if (s.size() <= 2) return 0;
  return *(--s.end()) - *s.begin() - *(--dif.end());
}
vector<long long int> adj_test[11];
vector<long long int> h(11, 0);
auto par = iota(11);
void dfs_test(int v, int p = -1) {
  if (p + 1) {
    h[v] = h[p] + 1;
  }
  par[v] = p;
  for (auto u : adj_test[v]) {
    if (p - u) dfs_test(u, v);
  }
}
int LCA(int v, int u) {
  if (v == u) return v;
  if (h[v] < h[u]) swap(v, u);
  return LCA(par[v], u);
}
int TIME = 0;
vector<long long int> st(11, 0);
vector<long long int> ft(11, 0);
vector<long long int> color(11, -1);
void dfs_time(int v) {
  st[v] = TIME++;
  color[v] = 1;
  for (auto u : adj_test[v]) {
    if (color[u] == -1) dfs_time(u);
  }
  ft[v] = TIME;
}
int arr[10000];
int block[100];
int blk_sz;
void update(int idx, int val) {
  int blockNumber = idx / blk_sz;
  block[blockNumber] += val - arr[idx];
  arr[idx] = val;
}
bool bin_search(int x[], int n, int k) {
  int p = 0;
  for (int a = n; a >= 1; a /= 2) {
    while (p + a < n && x[p + a] <= k) p += a;
  }
  return x[p] == k;
}
int count_same(int x[], int n, int k) {
  int p = -1, q = -1;
  for (int a = n; a >= 1; a /= 2) {
    while (p + a < n && x[p + a] < k) p += a;
    while (q + a < n && x[q + a] <= k) q += a;
  }
  return q - p;
}
int query(int l, int r) {
  int sum = 0;
  while (l < r and l % blk_sz != 0 and l != 0) {
    sum += arr[l];
    l++;
  }
  while (l + blk_sz <= r) {
    sum += block[l / blk_sz];
    l += blk_sz;
  }
  while (l <= r) {
    sum += arr[l];
    l++;
  }
  return sum;
}
void preprocess(int input[], int n) {
  int blk_idx = -1;
  blk_sz = sqrt(n);
  for (int i = 0; i < n; i++) {
    arr[i] = input[i];
    if (i % blk_sz == 0) {
      blk_idx++;
    }
    block[blk_idx] += arr[i];
  }
}
void showdq(deque<long long int> g) {
  deque<long long int>::iterator it;
  for (it = g.begin(); it != g.end(); ++it) cout << *it << ' ';
  cout << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n;
  cin >> n;
  vector<long long int> v(n);
  for (long long int i = 0; i < n; i++) cin >> v[i];
  long long int ans = 0;
  vector<long long int> cnt(n);
  cnt[n - 1] = !v[n - 1];
  for (long long int i = n - 2; i > -1; i--) {
    cnt[i] += cnt[i + 1] + !v[i];
  }
  for (long long int i = 0; i < n; i++) {
    if (v[i]) {
      ans += cnt[i];
    }
  }
  cout << ans;
}
class Node {
 public:
  int data;
  Node* left;
  Node* right;
  Node* next;
  Node(int d) {
    data = d;
    left = NULL;
    right = NULL;
  }
};
class Solution {
 public:
  Node* insert(Node* root, int data) {
    if (root == NULL) {
      return new Node(data);
    } else {
      Node* cur;
      if (data <= root->data) {
        cur = insert(root->left, data);
        root->left = cur;
      } else {
        cur = insert(root->right, data);
        root->right = cur;
      }
      return root;
    }
  }
  int get_height_bfs(Node* root) {
    int h = 0;
    queue<Node*> q;
    q.push(root);
    while (!q.empty()) {
      h++;
      Node* temp = q.front();
      q.pop();
      if (temp->left) q.push(temp->left);
      if (temp->right) q.push(temp->right);
    }
  }
  int get_Height(Node* root, int h) {
    if (root == nullptr)
      return h - 1;
    else {
      return max(get_Height(root->left, h + 1), get_Height(root->right, h + 1));
    }
  }
  int getHeight(Node* root) {
    int ans = 0;
    ans = get_Height(root, 0);
    return ans;
  }
  Node* removeDuplicates(Node* head) {
    Node* current = head;
    while (current != nullptr && current->next != nullptr) {
      Node* temp = current->next;
      if (current->data == temp->data) {
        current->next = temp->next;
        delete temp;
      } else {
        current = current->next;
      }
    }
    return head;
  }
};
void make_tree() {
  Solution myTree;
  Node* root = NULL;
  int t;
  cin >> t;
  int data;
  while (t-- > 0) {
    cin >> data;
    root = myTree.insert(root, data);
  }
  int height = myTree.getHeight(root);
  cout << height;
}
class BinaryTree {
 public:
  int value;
  BinaryTree* left;
  BinaryTree* right;
  BinaryTree(int value) {
    this->value = value;
    left = NULL;
    right = NULL;
  }
};
void dfs(BinaryTree* root, int sum, vector<int>& ans) {
  int sum1 = sum, sum2 = sum;
  if (root != nullptr and root->left != nullptr) sum1 += root->left->value;
  if (root != nullptr) dfs(root->left, sum1, ans);
  if (root != nullptr and root->right != nullptr) sum2 += root->right->value;
  if (root != nullptr) dfs(root->right, sum2, ans);
  if (root != nullptr and root->right == nullptr and root->left == nullptr)
    ans.push_back(sum);
}
vector<int> branchSums(BinaryTree* root) {
  vector<int> ans = {};
  if (root != nullptr) dfs(root, root->value, ans);
  return {ans};
}

```