#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  ll i,n;
  cin >> n;
  vector<ll> a(n),s(n+1,0);
  ll ans=0;
  for(i=0;i<n;i++){
    cin >> a[i];
    ans+=a[i]*a[i]*(n-1);
  }
  for(i=0;i<n;i++){
    s[i+1]=s[i]+a[i];
  }
  ll ans1=0;
  for(i=0;i<n;i++){
    ans1+=2*a[i]*(s[n]-s[i+1]);
  }
  cout << ans-ans1 << endl;
}
#include <bits/stdc++.h>
using namespace std;
/* ループ処理 0からnまで*/
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main()
{
  int N;
  cin >> N;
  vector<int> A, B, C;
  rep(i, N)
  {
    int a;
    cin >> a;
    A.push_back(a);
  }
  rep(i, N)
  {
    int b;
    cin >> b;
    B.push_back(b);
  }
  rep(i, N)
  {
    int c;
    cin >> c;
    C.push_back(c);
  }
  long long cou = 0;
  sort(C.begin(), C.end());
  sort(A.begin(), A.end());
  rep(i, N)
  {
    if (C.at(i) > B.size())
    {
      continue;
    }
    int BCj = B.at(C.at(i) - 1);
    decltype(A)::iterator left = lower_bound(A.begin(), A.end(), BCj);
    if (left != A.end() && *left == BCj)
    {
      decltype(A)::iterator right = upper_bound(A.begin(), A.end(), BCj);
      cou += right - left;
    }
  }
  cout << cou << endl;
  return 0;
}