#include <stdio.h>
#include <iostream>
#include <cstdio>
#include <algorithm> 
#include <stdio.h>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <list>
#include <utility>
#include <set>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <random>

using namespace std;

static const double EPS = 1e-9;
template<class T> bool INRANGE(T x, T a, T b) { return a <= x&&x <= b; }
template<class T> void amin(T &a, T v) { if (a > v) a = v; }
template<class T> void amax(T &a, T v) { if (a < v) a = v; }
int ROUND(double x) { return (int)(x + 0.5); }
bool ISINT(double x) { return fabs(ROUND(x) - x) <= EPS; }
bool ISEQUAL(double x, double y) { return fabs(x - y) <= EPS*max(1.0, max(fabs(x), fabs(y))); }
double SQSUM(double x, double y) { return x*x + y*y; }
#define PI  (acos(-1))
#define ARRAY_NUM(a) (sizeof(a)/sizeof(a[0])) 
#define NG (-1)
#define BIG ((int)1e9+10)
#define BIGLL ((ll)4e18)
#define SZ(a) ((int)(a).size())
#define SQ(a) ((a)*(a))
typedef unsigned long long ull;
typedef long long ll;


#if 0
int main()
{
	int N;
	scanf("%d", &N);

	for (int tmpN = 1; tmpN < 1000; tmpN++)
	{
		N = tmpN;


		while (N % 2 == 0)
		{
			N /= 2;
		}

		while (N % 5 == 0)
		{
			N /= 5;
		}

		int best;
		{
			int tmp = N;
			int sum = 0;
			while (tmp)
			{
				sum += tmp % 10;
				tmp /= 10;
			}
			best = sum;
		}

		for (int i = 1; i < 1 << 18; ++i)
		{
			ll x = 0;
			ll base = 1;
			for (int d = 0; d < 18; d++)
			{
				if (i & (1 << d))
				{
					x += base;
				}
				base *= 10LL;
			}

			if (x % N == 0)
			{
				ll tmp = x;
				ll sum = 0;
				while (tmp)
				{
					sum += tmp % 10;
					tmp /= 10;
				}

				amin(best, (int)sum);
			}
		}

		cout << best << endl;

	}


	return 0;
}

#else

// あらかじめソートしておくこと。

// ＞X の要素数を求める。
template <class T>
int numElementsGreaterThanX( const vector <T>& v, T x)
{
	const int N = SZ(v);
	return N - (upper_bound(v.begin(),v.end(),x)-v.begin());
}

// ≧X の要素数を求める。
template <class T>
int numElementsGreaterThanOrEqualToX(const vector <T>& v, T x)
{
	const int N = SZ(v);
	return N - (lower_bound(v.begin(), v.end(), x) - v.begin());
}

// ＜X の要素数を求める。
template <class T>
int numElementsSmallerThanX(const vector <T>& v, T x)
{
	return lower_bound(v.begin(), v.end(), x) - v.begin();
}

// ≦X の要素数を求める。
template <class T>
int numElementsSmallerThanOrEqualToX(const vector <T>& v, T x)
{
	return upper_bound(v.begin(), v.end(), x) - v.begin();
}



int main()
{
	int N;
	scanf("%d", &N);

	vector <int> a(N), b(N), c(N);

	for (int i = 0; i < N; ++i)
	{
		scanf("%d", &a[i]);
	}
	for (int i = 0; i < N; ++i)
	{
		scanf("%d", &b[i]);
	}
	for (int i = 0; i < N; ++i)
	{
		scanf("%d", &c[i]);
	}
	sort(a.begin(),a.end());
	sort(b.begin(),b.end());
	sort(c.begin(),c.end());

	ll ans = 0;
	for (int i=0;i<N;i++)
	{

		ll x = numElementsSmallerThanX( a, b[i]);
		ll y = numElementsGreaterThanX( c, b[i]);
		ans += x*y;
	}

	cout << ans << endl;



	return 0;
}


#endif

Measured memory_bytes: 1408