Завтра у хоккейной команды, которой руководит Евгений, важный матч. Евгению нужно выбрать шесть игроков, которые выйдут на лед в стартовом составе: один вратарь, два защитника и три нападающих.

Так как это стартовый состав, Евгения больше волнует, насколько красива будет команда на льду, чем способности игроков. А именно, Евгений хочет выбрать такой стартовый состав, чтобы номера любых двух игроков из стартового состава отличались не более, чем в два раза. Например, игроки с номерами 13, 14, 10, 18, 15 и 20 устроят Евгения, а если, например, на лед выйдут игроки с номерами 8 и 17, то это не устроит Евгения.

Про каждого из игроков вам известно, на какой позиции он играет (вратарь, защитник или нападающий), а также его номер. В хоккее номера игроков не обязательно идут подряд. Посчитайте число различных стартовых составов из одного вратаря, двух защитников и трех нападающих, которые может выбрать Евгений, чтобы выполнялось его условие красоты.


-----Входные данные-----

Первая строка содержит три целых числа g, d и f (1 ≤ g ≤ 1 000, 1 ≤ d ≤ 1 000, 1 ≤ f ≤ 1 000) — число вратарей, защитников и нападающих в команде Евгения. 

Вторая строка содержит g целых чисел, каждое в пределах от 1 до 100 000 — номера вратарей.

Третья строка содержит d целых чисел, каждое в пределах от 1 до 100 000 — номера защитников.

Четвертая строка содержит f целых чисел, каждое в пределах от 1 до 100 000 — номера нападающих.

Гарантируется, что общее количество игроков не превосходит 1 000, т. е. g + d + f ≤ 1 000. Все g + d + f номеров игроков различны.


-----Выходные данные-----

Выведите одно целое число — количество возможных стартовых составов.


-----Примеры-----
Входные данные
1 2 3
15
10 19
20 11 13

Выходные данные
1

Входные данные
2 3 4
16 40
20 12 19
13 21 11 10

Выходные данные
6



-----Примечание-----

В первом примере всего один вариант для выбора состава, который удовлетворяет описанным условиям, поэтому ответ 1.

Во втором примере подходят следующие игровые сочетания (в порядке вратарь-защитник-защитник-нападающий-нападающий-нападающий):  16 20 12 13 21 11  16 20 12 13 11 10  16 20 19 13 21 11  16 20 19 13 11 10  16 12 19 13 21 11  16 12 19 13 11 10 

Таким образом, ответ на этот пример — 6.

Difficulty: interview

Starter code:

Solutions:
import bisect
from functools import lru_cache

g, d, f = tuple(map(int, input().split()))

goals = list(map(int, input().split()))
defs = list(map(int, input().split()))
forwards = list(map(int, input().split()))

goals.sort()
defs.sort()
forwards.sort()

forwards.append(100000000)
defs.append(100000000)
goals.append(100000000)

numers = []
roles = []
gi, di, fi = 0, 0, 0

for i in range(d + g + f):
    numers.append(min(goals[gi], defs[di], forwards[fi]))

    if numers[-1] == goals[gi]:
        roles.append(1)
        gi += 1

    if numers[-1] == forwards[fi]:
        roles.append(3)
        fi += 1

    if numers[-1] == defs[di]:
        roles.append(2)
        di += 1

#print(numers)
#print(roles)


@lru_cache()
def my_comb(n, k):
    if k == 0:
        return 1
    if n < k:
        return 0
    if n == k:
        return 1
    if k == 3:
        return (n * (n - 1) * (n - 2)) // 6
    if k == 2:
        return (n * (n - 1)) // 2
    if k == 1:
        return n
    assert False


def solve(numers, roles):
    ans = 0
    for i in range(len(numers)):
        # check all combinations with guy i

        possible_max_num = bisect.bisect_right(numers, numers[i] * 2)

        if possible_max_num - i < 5:
            continue

        avaliable_f = roles[i + 1: possible_max_num].count(3)
        avaliable_d = roles[i + 1: possible_max_num].count(2)
        avaliable_g = roles[i + 1: possible_max_num].count(1)

        needed_f, needed_d, needed_g = 3, 2, 1

        if roles[i] == 1:
            needed_g -= 1
        elif roles[i] == 2:
            needed_d -= 1
        else:
            needed_f -= 1

        possible_combinations_with_ith = my_comb(avaliable_d, needed_d) * my_comb(avaliable_f, needed_f) * my_comb(
            avaliable_g, needed_g)
        ans += possible_combinations_with_ith

    return ans


print(solve(numers, roles))


import sys
from bisect import bisect_left, bisect_right

def binom(n, k):
    if k > n:
        return 0
    elif k == 0:
        return 1
    elif k == 1:
        return n
    elif k == 2:
        return (n * (n - 1)) // 2
    elif k == 3:
        return (n * (n - 1) * (n - 2)) // 6
    else:
        raise NotImplementedError


def ways_to_pick(xs, wx, lo, hi):
    idx_lo = bisect_left(xs, lo)
    idx_hi = bisect_right(xs, hi)
    return binom(idx_hi - idx_lo, wx)


def number_of_teams(gs, wg, ds, wd, fs, wf, lo, hi):
    return ways_to_pick(gs, wg, lo, hi) * \
           ways_to_pick(ds, wd, lo, hi) * \
           ways_to_pick(fs, wf, lo, hi)


ng, nd, nf = list(map(int, input().split()))
gs = list(sorted(map(int, input().split())))
ds = list(sorted(map(int, input().split())))
fs = list(sorted(map(int, input().split())))

wg = 1
wd = 2
wf = 3

if nd < 2 or nf < 3:
    print(0)
    return

ans = 0
for idx, min_el in enumerate(gs):
    ans += number_of_teams(gs[idx + 1:], wg - 1,
                           ds, wd,
                           fs, wf,
                           min_el, 2 * min_el)
for idx, min_el in enumerate(ds):
    ans += number_of_teams(gs, wg,
                           ds[idx + 1:], wd - 1,
                           fs, wf,
                           min_el, 2 * min_el)
for idx, min_el in enumerate(fs):
    ans += number_of_teams(gs, wg,
                           ds, wd,
                           fs[idx + 1:], wf - 1,
                           min_el, 2 * min_el)
print(ans)


def sub_pairs(r, l):
    if r-l<2: return 0
    n = r-l
    return (n*(n-1))//2

def sub_triples(r, l):
    if r-l<3: return 0
    n = r-l
    return (n*(n-1)*(n-2))//6

def fast(g, d, f):
    g.sort()
    d.sort()
    f.sort()
    res = 0
    gl, dl, fl = 0, 0, 0
    gr, dr, fr = 0, 0, 0
    while gl < len(g) and dl < len(d)-1 and fl < len(f)-2:
        mn = min(g[gl], d[dl], f[fl])
        mx = mn*2
        while gr < len(g) and g[gr] <= mx: gr+=1
        while dr < len(d) and d[dr] <= mx: dr+=1
        while fr < len(f) and f[fr] <= mx: fr+=1
        if g[gl] == mn:
            res += sub_pairs(dr, dl) * sub_triples(fr, fl)
            gl+=1
        elif d[dl] == mn:
            res += (max(0, dr-dl-1))*max(0, gr-gl) * sub_triples(fr, fl)
            dl+=1
        else:
            res += sub_pairs(fr, fl+1)*max(0, gr-gl) * sub_pairs(dr, dl)
            fl+=1
##        print(res, mn, mx, (gl, gr), (dl, dr), (fl, fr))
    return res        


        


input()
g = [int(x) for x in input().split()]
d = [int(x) for x in input().split()]
f = [int(x) for x in input().split()]
print(fast(g, d, f))


import bisect

def count(a, low):
    top = low*2
    lowi = bisect.bisect_left(a, low)
    topi = bisect.bisect_right(a, top)
    return topi - lowi

gn, dn, fn = map(int, input().split())
g = [int(x) for x in input().split()]
d = [int(x) for x in input().split()]
f = [int(x) for x in input().split()]

g = sorted(g)
d = sorted(d)
f = sorted(f)

ans = 0
for x in g:
    dc = count(d, x)
    fc = count(f, x)
    ans += dc * (dc-1) * fc * (fc-1) * (fc-2) // 12
for x in d:
    gc = count(g, x)
    dc = count(d, x)
    fc = count(f, x)
    ans += gc * (dc-1) * fc * (fc-1) * (fc-2) // 6
for x in f:
    gc = count(g, x)
    dc = count(d, x)
    fc = count(f, x)
    ans += gc * dc * (dc - 1) * (fc - 1) * (fc - 2) // 4

print(ans)

g, d, f = (int(s) for s in input().split())
gs = sorted([int(s) for s in input().split()])
ds = sorted([int(s) for s in input().split()])
fs = sorted([int(s) for s in input().split()])

gn = [0] * 100001
dn = [0] * 100001
fn = [0] * 100001

for a in gs:
    gn[a] += 1

for a in ds:
    dn[a] += 1

for a in fs:
    fn[a] += 1

gx = 0
dx = 0
fx = 0

for i in range(100001):
    gx += gn[i]
    dx += dn[i]
    fx += fn[i]

    gn[i] = gx
    dn[i] = dx
    fn[i] = fx

def team_count(a, b):
    if a > 100000:
        a = 100000
    if b > 100000:
        b = 100000
    gc = gn[b] - gn[a]
    dc = dn[b] - dn[a]
    fc = fn[b] - fn[a]

    val = gc * dc * (dc - 1) * fc * (fc - 1) * (fc - 2) // 12
    if val < 0:
        print(val)
    return val

res = team_count(0, 2)
for i in range(1, 50001):
    res += team_count(i, 2 * i + 2) - team_count(i, 2 * i)

print(res)


import getpass
import sys
import math
import itertools
import bisect


def lcm(a, b):
    return a * b // math.gcd(a, b)


def ria():
    return [int(i) for i in input().split()]


def dr(v):
    sm = sum([int(i) for i in str(v)])
    return sm if sm < 10 else dr(sm)


def range_sum(a, b):
    ass = (((b - a + 1) // 2) * (a + b))
    if (a - b) % 2 == 0:
        ass += (b - a + 2) // 2
    return ass


def comba(n, x):
    return (math.factorial(n) // math.factorial(n - x)) // math.factorial(x)


files = True
debug = False

if getpass.getuser() == 'frohenk' and files:
    debug = True
    sys.stdin = open("test.in")
    # sys.stdout = open('test.out', 'w')
    pass

g, d, f = ria()
gs = sorted(ria())
ds = sorted(ria())
fs = sorted(ria())

ar = []
for i in gs:
    ar.append((i, 0))
for i in ds:
    ar.append((i, 1))
for i in fs:
    ar.append((i, 2))
ar = sorted(ar)
suma = 0
for i, tp in ar:
    gl = bisect.bisect_right(gs, i * 2) - bisect.bisect_left(gs, i)
    dl = bisect.bisect_right(ds, i * 2) - bisect.bisect_left(ds, i)
    fl = bisect.bisect_right(fs, i * 2) - bisect.bisect_left(fs, i)
    if gl < 1 or dl < 2 or fl < 3:
        continue
    mp = 1
    if tp == 0:
        pass
    else:
        mp *= comba(gl, 1)
    
    if tp == 1:
        mp *= comba(dl - 1, 1)
    else:
        mp *= comba(dl, 2)

    if tp == 2:
        mp *= comba(fl - 1, 2)
    else:
        mp *= comba(fl, 3)
    suma += mp
print(suma)


g, d, f = map(int, input().split())
gg = list(map(int, input().split()))
dd = list(map(int, input().split()))
ff = list(map(int, input().split()))
gg.sort()
dd.sort()
ff.sort()
def get_kolvo(left, right, lst):
    l = -1
    r = len(lst)
    while r - l > 1:
        m = (r + l) // 2
        if lst[m] >= left:
            r = m
        else:
            l = m
    ql = r
    l = -1
    r = len(lst)
    while r - l > 1:
        m = (r + l) // 2
        if lst[m] > right:
            r = m
        else:
            l = m
    
    qr = l
        
    return qr - ql + 1
    
def c(n, k):
    if k == 1:
        return n
    elif k == 2:
        return n * (n - 1) // 2
    elif k == 3:
        return n * (n - 1) * (n - 2) // 6

def get(l, r):
    return c(get_kolvo(l, r, gg), 1) * c(get_kolvo(l, r, dd), 2) * c(get_kolvo(l, r, ff), 3)
    
ans = 0
for i in range(4, 100001):
    ans += get(i, 2 * i) - get(i, 2 * i - 2)
print(ans)

import sys
import math
import random
import time

def func_cnk(keepers, defenders, attackers, flag):
    if flag == 'kpr':
        kpr = 1
        defs = math.factorial(defenders) // math.factorial(2) // math.factorial(defenders - 2)
        atts = math.factorial(attackers) // math.factorial(3) // math.factorial(attackers - 3)
    elif flag == 'def':
        kpr = keepers
        defs = defenders - 1
        atts = math.factorial(attackers) // math.factorial(3) // math.factorial(attackers - 3)
    elif flag == 'att':
        kpr = keepers
        defs = math.factorial(defenders) // math.factorial(2) // math.factorial(defenders - 2)
        atts = math.factorial(attackers - 1) // math.factorial(2) // math.factorial(attackers - 3)
    return kpr * int(defs) * int(atts)

g, d, f = list(map(int, input().split()))
x = list(map(int, input().split()))
y = list(map(int, input().split()))
z = list(map(int, input().split()))
#N = 100000
#x = random.sample(range(1, N), g)
#y = random.sample(range(1, N), d)
#z = random.sample(range(1, N), f)
#print(x, y, z)

if (d < 2) or (f < 3):
    print('0')
    return

t = time.time()

res_ans = 0
dict_nums = {}

for num in x:
    dict_nums[num] = 'kpr'
for num in y:
    dict_nums[num] = 'def'
for num in z:
    dict_nums[num] = 'att'

all_nums = x + y + z
all_nums.sort()

for i in range(len(all_nums)):
    upper = all_nums[i] * 2
    j = i
    keepers = 0
    defenders = 0
    attackers = 0
    while (j < len(all_nums) and (all_nums[j] <= upper)):
        if dict_nums[all_nums[j]] == 'kpr':
            keepers = keepers + 1
        if dict_nums[all_nums[j]] == 'def':
            defenders = defenders + 1
        if dict_nums[all_nums[j]] == 'att':
            attackers = attackers + 1
        j = j + 1
    if (keepers > 0) and (defenders > 1) and (attackers > 2):
        #print(all_nums[i], func_cnk(keepers, defenders, attackers, dict_nums[all_nums[i]]))
        res_ans = res_ans + func_cnk(keepers, defenders, attackers, dict_nums[all_nums[i]])

print(res_ans)

_ = input()
a = list([(int(x), 1) for x in input().split()])
a.extend([(int(x), 2) for x in input().split()])
a.extend([(int(x), 3) for x in input().split()])
a.sort()
g, d, f, n = [0], [0], [0], len(a)
for x, y in a:
    g.append(g[-1])
    d.append(d[-1])
    f.append(f[-1])
    if y == 1: g[-1] += 1
    elif y == 2: d[-1] += 1
    else: f[-1] += 1

s = i = 0
j = 1

while i < n:
    while j < n and a[j][0] <= 2*a[i][0]: j += 1
    j -= 1
    g1 = g[j+1] - g[i]
    d1 = d[j+1] - d[i]
    f1 = f[j+1] - f[i]
    # print(i, j, g1, d1, f1)
    if a[i][1] == 1: s += d1 * (d1 - 1) * f1 * (f1 - 1) * (f1 - 2) // 12
    elif a[i][1] == 2: s += g1 * (d1 - 1) * f1 * (f1 - 1) * (f1 - 2) // 6
    else: s += g1 * d1 * (d1 - 1) * (f1 - 1) * (f1 - 2) // 4
    i += 1

print(s)


from math import factorial

n, m, k = (int(x) for x in input().split())
a = sorted([int(x) for x in input().split()])
b = sorted([int(x) for x in input().split()])
c = sorted([int(x) for x in input().split()])


def create_count_arr(a):
    a_count = [0] * (10 ** 5 + 5)
    for i in range(len(a)):
        a_count[a[i]:] = [i + 1] * ((10 ** 5 + 5) - a[i])
    return a_count


def get_num(x, y, a):
    if y >= len(a):
        y = len(a) - 1
    c = a[y] - a[x]
    if a[x] != a[x - 1]:
        c += 1
    return c


def num_of_permut(n, k):
    return factorial(n) // (factorial(k) * factorial(n - k))


a_count = create_count_arr(a)
b_count = create_count_arr(b)
c_count = create_count_arr(c)

count = 0

# print('goalkeepers')
for i in a:
    d = get_num(i, i * 2, b_count)
    f = get_num(i, i * 2, c_count)
    # print(i, d, f, end=' ')
    if d >= 2 and f >= 3:
        count += num_of_permut(d, 2) * num_of_permut(f, 3)
    #     print('ok, count =', count)
    # else:
    #     print()
# print('\ndefenders')
for i in b:
    g = get_num(i, i * 2, a_count)
    d = get_num(i, i * 2, b_count) - 1
    f = get_num(i, i * 2, c_count)
    # print(i, g, d, f, end=' ')
    if g >= 1 and d >= 1 and f >= 3:
        count += num_of_permut(d, 1) * num_of_permut(f, 3) * g
    #     print('ok, count =', count)
    # else:
    #     print()

# print('\nforwards')
for i in c:
    g = get_num(i, i * 2, a_count)
    d = get_num(i, i * 2, b_count)
    f = get_num(i, i * 2, c_count) - 1
    # print(i, g, d, f, end=' ')
    if g >= 1 and d >= 2 and f >= 2:
        count += num_of_permut(d, 2) * num_of_permut(f, 2) * g
    #     print('ok, count =', count)
    # else:
    #     print()

print(count)


s = input().split()
l = sum([int(i) for i in s])
pos = [0,0,0]
ls = []
for j in range(3): 
    ls += [[int(i) for i in input().split()]]
    ls[j] += [100100]
    ls[j].sort()
    
shet = [0,0,0]
bot_ind = 0 
top_granica = 0 
summa = 0  
i = 0 
main_list = [] 
kandidat =[] 
while i < l: 
    if ls[0][shet[0]] < ls[1][shet[1]]:
        if ls[0][shet[0]] < ls[2][shet[2]]:
            kandidat = [ls[0][shet[0]],0]
        else:
            kandidat = [ls[2][shet[2]],2]
    else:
        if ls[1][shet[1]] < ls[2][shet[2]]:
            kandidat = [ls[1][shet[1]],1]
        else:
            kandidat = [ls[2][shet[2]],2]
    if bot_ind == i:
        main_list += [kandidat] 
        shet[kandidat[1]] += 1 
        top_granica = main_list[bot_ind][0]*2 
                                            
        pos[kandidat[1]] +=1 
    else:  
        if kandidat[0] > top_granica: 
            if pos[0] > 0 and pos[1] > 1 and pos[2] > 2:  
                pos[main_list[bot_ind][1]] -= 1 
                if not main_list[bot_ind][1]: 
                    summa += pos[1]*(pos[1]-1)*pos[2]*(pos[2]-1)*(pos[2]-2)//12 
                elif main_list[bot_ind][1] == 1:
                    summa += pos[0]*pos[1]*pos[2]*(pos[2]-1)*(pos[2]-2)//6
                else:
                    summa += pos[0]*pos[1]*(pos[1]-1)*pos[2]*(pos[2]-1)//4
                bot_ind +=1 
                top_granica = main_list[bot_ind][0]*2 
            else:
                pos[main_list[bot_ind][1]] -= 1
                bot_ind +=1
                if bot_ind < i:
                    top_granica = main_list[bot_ind][0]*2
            i -= 1
               
        else:
            main_list+=[kandidat]
            shet[kandidat[1]] += 1
            pos[kandidat[1]] +=1
    i += 1 
while pos[0] > 0 and pos[1] > 1 and pos[2] > 2:
    pos[main_list[bot_ind][1]] -= 1
    if not main_list[bot_ind][1]:
        summa += pos[1]*(pos[1]-1)*pos[2]*(pos[2]-1)*(pos[2]-2)//12 
    elif main_list[bot_ind][1] == 1:
        summa += pos[0]*pos[1]*pos[2]*(pos[2]-1)*(pos[2]-2)//6 
    else:
        summa += pos[0]*pos[1]*(pos[1]-1)*pos[2]*(pos[2]-1)//4 
    bot_ind +=1
    
    
print(summa)            



from math import factorial

def bin_search(l, r, x):
	while l < r - 1:
		m = (l+r)//2
		if players[m][0] == x:
			return m
		if players[m][0] < x:
			l = m
		else:
			r = m
	return l

def cmds_in_range(rang):
	roles = []
	temp_rang = [i[1] for i in rang]
	for i in range(3):
		roles.append(temp_rang.count(i))
	if roles[0] < 1 or roles[1] < 2 or roles[2] < 3:
		return 0
	comb_d = factorial(roles[1])//(factorial(roles[1]-2)*2)
	comb_f = factorial(roles[2])//(factorial(roles[2]-3)*6)
	return roles[0] * comb_d * comb_f

input()
players = []
for i in range(3):
	for j in (int(k) for k in input().split()):
		players.append((j, i))
players.sort()
players.append((200001, 0))

count = 0
r = 0
for l in range(len(players) - 5):
	if l == 0:
		inter_cmds = 0
	else:
		inter_cmds = cmds_in_range(players[l:r + 1])
	r = bin_search(l, len(players) - 1, players[l][0] * 2)
	cur_cmds = cmds_in_range(players[l:r + 1])
	count += cur_cmds - inter_cmds
	
print(count)

g,d,f = list(map(int, input().split()))
vratars = list(map(int, input().split()))
defenders = list(map(int, input().split()))
atackers = list(map(int, input().split()))

vratars.sort()
defenders.sort()
atackers.sort()

count = 0
while 1:
	vNeed = 1
	dNeed = 2
	aNeed = 3
	try:
		if defenders[0]<atackers[0]:
			if defenders[0] < vratars[0]:
				mn = defenders.pop(0)
				d-=1
				dNeed = 1
			else:
				mn = vratars.pop(0)
				g-=1
				vNeed = 0
		else:
			if atackers[0] < vratars[0]:
				mn = atackers.pop(0)
				f-=1
				aNeed = 2
			else:
				mn = vratars.pop(0)
				g-=1
				vNeed = 0
	except IndexError:
		# print('INDERR')
		break
	# print('need', vNeed, dNeed, aNeed)
	# print('ost', g, d, f)
	if (vNeed>g) or (dNeed>d) or (aNeed>f): break
	# print('mn ', mn)
	mx = mn*2		
	if vNeed:
		vOk = 0
		for i in vratars:
			if i>mx: break
			vOk+=1
	dOk = 0
	for i in defenders:
		if i>mx: break
		dOk+=1
	aOk = 0
	for i in atackers:
		if i>mx: break
		aOk+=1


	vC = 1
	if vNeed:
		vC = vOk

	if dNeed==1:
		dC = dOk
	else:
		dC = ((dOk-1)*dOk)/2

	if aNeed==2:
		aC = ((aOk-1)*aOk)/2
	else:
		aC = ((aOk-2)*(aOk-1)*aOk)/6

	count += vC*dC*aC
	# print('c', vC, dC, aC)
print(int(count))








#упрощенное вычисление C
def c2(n):
    return n*(n-1)//2
def c3(n):
    return n*(n-1)*(n-2)//6

g,d,f=list(map(int,input().split()))
#Костыль
if g<1 or d<2 or f<3:
    print(0)
    return

ans=0
a=[]
n=g+d+f
#скидываем все в один массив и запоминаем типы
for i in map(int,input().split()):
    a.append((i,0))
for i in map(int,input().split()):
    a.append((i,1))
for i in map(int,input().split()):
    a.append((i,2))

#сортируем этот массив по номеру
a.sort()

for i in range(n): #в i перебераем минимум
    types=[0,0,0]
    j=i+0#в j перебераем максимум
    while j<n and a[j][0]<=2*a[i][0]: #если максимум в 2 раза меньше минимума, то и все остальные
        types[a[j][1]]+=1
        now_types=types.copy()
        now_types[a[j][1]]-=1
        now_types[a[i][1]]-=1
        #проверка на то, какого типа минимум и максимум, их мы не учитываем при подсчете кол-ва вариантов, потому что мы их зафиксировали, чтобы не было повторов
        if a[j][1]==0 and a[i][1]==1 or a[j][1]==1 and a[i][1]==0:
            if now_types[1]>=1 and now_types[2]>=3:
                ans+=now_types[1]*c3(now_types[2])
        elif a[j][1]==0 and a[i][1]==2 or a[j][1]==2 and a[i][1]==0:
            if now_types[1]>=2 and now_types[2]>=2:
                ans+=c2(now_types[1])*c2(now_types[2])
        elif a[j][1]==2 and a[i][1]==1 or a[j][1]==1 and a[i][1]==2:
            if now_types[0]>=1 and now_types[1]>=1 and now_types[2]>=2:
                ans+=now_types[0]*now_types[1]*c2(now_types[2])
        elif a[j][1]==1 and a[i][1]==1:
            if now_types[0]>=1 and now_types[2]>=3:
                ans+=now_types[0]*c3(now_types[2])
        elif a[j][1]==2 and a[i][1]==2:
            if now_types[0]>=1 and now_types[1]>=2 and now_types[2]>=1:
                ans+=now_types[0]*c2(now_types[1])*now_types[2]
        j+=1
print(ans)
                
                
            
            
            
        



import bisect

def binom(n, k):
    if k > n:
        return 0
    elif k == 1:
        return n
    elif k == 2:
        return n * (n - 1) // 2
    elif k == 3:
        return n * (n - 1) * (n - 2) // 6
    else:
        assert False

def get_len(arr, a, b):
    lo = bisect.bisect_left(arr, a)
    hi = bisect.bisect_right(arr, b)
    return hi - lo

def solve(gs, ds, fs):
    ans = 0

    # min is goalkeeper, could be equal to attacker or defender if there were equal numbers
    for num_g in gs:
        ways_g = 1
        len_d = get_len(ds, num_g, num_g * 2)
        ways_d = binom(len_d, 2)
        len_f = get_len(fs, num_g, num_g * 2)
        ways_f = binom(len_f, 3)
        ways = ways_g * ways_d * ways_f
        # print(f'goalkeeper: ways={ways}, ways_gdf={ways_g, ways_d, ways_f}, num_g={num_g}')
        ans += ways

    # min is defender, could be equal to attacker if there were equal numbers
    for i, num_d in enumerate(ds[:-1]):
        ways_g = get_len(gs, num_d + 1, num_d * 2)
        ways_d = get_len(ds, num_d + 1, num_d * 2)
        len_f = get_len(fs, num_d, num_d * 2)
        ways_f = binom(len_f, 3)
        ways = ways_g * ways_d * ways_f
        # print(f'defender:   ways={ways}, ways_gdf={ways_g, ways_d, ways_f}, num_d={num_d}')
        ans += ways

    # min is attacker
    for i, num_f in enumerate(fs[:-2]):
        ways_g = get_len(gs, num_f + 1, num_f * 2)
        len_d = get_len(ds, num_f + 1, num_f * 2)
        ways_d = binom(len_d, 2)
        len_f = get_len(fs, num_f + 1, num_f * 2)
        ways_f = binom(len_f, 2)
        ways = ways_g * ways_d * ways_f
        # print(f'attacker:   ways={ways}, ways_gdf={ways_g, ways_d, ways_f}, num_f={num_f}')
        ans += ways

    return ans

_, _, _ = [int(v) for v in input().split()]
gs = [int(v) for v in input().split()]
ds = [int(v) for v in input().split()]
fs = [int(v) for v in input().split()]

gs.sort()
ds.sort()
fs.sort()

ans = solve(gs, ds, fs)
print(ans)


import math
from bisect import bisect_right as bis

def nCr(n, r):
  if r > n:
    return 0
  f = math.factorial
  return f(n) // f(r) // f(n - r)

g, d, f = list(map(int, input().split()))

gs = list(map(int, input().split()))
gs.sort()
ds = list(map(int, input().split()))
ds.sort()
fs = list(map(int, input().split()))
fs.sort()


def find_max(first, nums):
  nums_max = 0
  for i in range(bis(nums, first), len(nums)):
    if nums[i] <= first * 2:
      nums_max += 1
    else:
      break
  return nums_max


def count_by_first(first, gs_count=1, ds_count=2, fs_count=3):
  gs_max = find_max(first, gs)
  ds_max = find_max(first, ds)
  fs_max = find_max(first, fs)
  return nCr(gs_max, gs_count) * nCr(ds_max, ds_count) * nCr(fs_max, fs_count)

answer = 0
for i in gs:
  answer += count_by_first(i, gs_count=0)
for i in ds:
  answer += count_by_first(i, ds_count=1)
for i in fs:
  answer += count_by_first(i, fs_count=2)

print(answer)


g, d, f = map(int, input().split())
G = sorted([0] + list(map(int, input().split())))
D = sorted([0] + list(map(int, input().split())))
F = sorted([0] + list(map(int, input().split())))
G.append(0)
D.append(0)
F.append(0)
a = [0]*1000000
b = [0]*1000000
c = [0]*1000000
x = 1
y = 1
z = 1
for i in range(1, 200001):
  if G[x] == i:
    a[i] = a[i - 1] + 1
    x += 1
  else:
    a[i] = a[i - 1]
  if D[y] == i:
    b[i] = b[i - 1] + 1
    y += 1
  else:
    b[i] = b[i - 1]
  if F[z] == i:
    c[i] = c[i - 1] + 1
    z += 1
  else:
    c[i] = c[i - 1]
q = 0
for i in range(1, 100001):
  a2 = a[2*i] - a[i]
  b2 = b[2*i] - b[i]
  c2 = c[2*i] - c[i]
  if a[i] - a[i - 1] == 1:
    q += (b2*(b2 - 1) // 2) * (c2*(c2 - 1)*(c2 - 2) // 6)
  if b[i] - b[i - 1] == 1:
    q += a2*b2*(c2*(c2 - 1)*(c2 - 2) // 6)
  if c[i] - c[i - 1] == 1:
    q += a2*(b2*(b2 - 1) // 2)*(c2*(c2 - 1) // 2)
print(q)

import math
def main():
    g, d, f = map(int, input().split())
    lst1 = list(map(int, input().split()))
    lst2 = list(map(int, input().split()))
    lst3 = list(map(int, input().split()))
    lst0 = []
    precounted = []
    ans = 0

    lst0 += [(c, 1) for c in lst1]
    lst0 += [(c, 2) for c in lst2]
    lst0 += [(c, 3) for c in lst3]

    lst0.sort()

    for i in range(len(lst0)):

        if len(precounted) == 0:
            a1, a2, a3 = (0, 0, 0)
        else:
            a1, a2, a3 = precounted[len(precounted) - 1]

        if (lst0[i][1] == 1):
            a1 += 1
        elif (lst0[i][1] == 2):
            a2 += 1
        else:
            a3 += 1

        precounted.append((a1, a2, a3))

        def product(iterable):
            prod = 1
            for n in iterable:
                prod *= n
            return prod

        def npr(n, r):
            assert 0 <= r <= n
            return product(range(n - r + 1, n + 1))

        def ncr(r, n):
            if r > n:
                return 0
            assert 0 <= r <= n
            if r > n // 2:
                r = n - r
            return npr(n, r) // math.factorial(r)

    for i in range(len(lst0) - 1):
        l = i + 1
        r = len(lst0)
        while l + 1 < r:
            m = (l + r) // 2
            if lst0[i][0] * 2 >= lst0[m][0]:
                l = m
            else:
                r = m
        max_possible_num = lst0[l][0]
        max_possible_ind = l

        a1 = precounted[max_possible_ind][0] - precounted[i][0]
        a2 = precounted[max_possible_ind][1] - precounted[i][1]
        a3 = precounted[max_possible_ind][2] - precounted[i][2]
        n1 = 1
        n2 = 2
        n3 = 3

        if lst0[i][1] == 1:
            n1 -= 1
        elif lst0[i][1] == 2:
            n2 -= 1
        else:
            n3 -= 1
        ans += ncr(n1, a1) * ncr(n2, a2) * ncr(n3, a3)

    print(ans)

main()

def compute(array):
    ggg = 0
    ddd = 0
    fff = 0
    for elem in array:
        if elem[1] == 'f':
            fff += 1
        if elem[1] == 'd':
            ddd += 1
        if elem[1] == 'g':
            ggg += 1
    return (ggg, ddd, fff)


g, d, f = list(map(int, input().split()))
gg = list(map(int, input().split()))
dd = list(map(int, input().split()))
ff = list(map(int, input().split()))
players = []
for elem in gg:
    players.append((elem, 'g'))
for elem in dd:
    players.append((elem, 'd'))
for elem in ff:
    players.append((elem, 'f'))
players = sorted(players)
count = 0
left = 0
right = 0
while players[right][0]/players[left][0] <= 2:
    right += 1
    if right == len(players):
        break
right -= 1

a, b, c = compute(players[left:right+1])
count += a * b * (b-1) / 2 * c * (c-1) * (c-2) / 6

while (1):
    right += 1
    if right == len(players):
        break

    while players[right][0]/players[left][0] > 2:
        left += 1

    a, b, c = compute(players[left:right+1])
    x, y, z = compute(players[left:right])

    count += a * b * (b-1) / 2 * c * (c-1) * (c-2) / 6
    count -= x * y * (y-1) / 2 * z * (z-1) * (z-2) / 6


print(int(count))


s = input().split()
l = sum([int(i) for i in s])

data = []
for j in range(3):
    data += [[int(i) for i in input().split()]]
    data[j] += [100001]
    data[j].sort()

cursor = [0, 0, 0]
posCnt = [0, 0, 0]
lowerBound = 0
upperBound = 0

finalCounter = 0

mainQueue = []
player = []

i = 0
while i < l:

    player = min([data[0][cursor[0]], 0], [data[1][cursor[1]], 1], [data[2][cursor[2]], 2])

    if lowerBound == i:
        mainQueue += [player]
        cursor[player[1]] += 1
        upperBound = mainQueue[lowerBound][0] * 2
        posCnt[player[1]] += 1
    else:
        if player[0] > upperBound:
            if posCnt[0] > 0 and posCnt[1] > 1 and posCnt[2] > 2:

                posCnt[mainQueue[lowerBound][1]] -= 1
                if mainQueue[lowerBound][1] == 0:
                    finalCounter += posCnt[1] * (posCnt[1] - 1) * posCnt[2] * (posCnt[2] - 1) * (posCnt[2] - 2) // 12
                elif mainQueue[lowerBound][1] == 1:
                    finalCounter += posCnt[0] * posCnt[1] * posCnt[2] * (posCnt[2] - 1) * (posCnt[2] - 2) // 6
                else:
                    finalCounter += posCnt[0] * posCnt[1] * (posCnt[1] - 1) * posCnt[2] * (posCnt[2] - 1) // 4

                lowerBound += 1
                upperBound = mainQueue[lowerBound][0] * 2
            else:
                posCnt[mainQueue[lowerBound][1]] -= 1
                lowerBound += 1
                if lowerBound < i:
                    upperBound = mainQueue[lowerBound][0] * 2
            i -= 1

        else:
            mainQueue += [player]
            cursor[player[1]] += 1
            posCnt[player[1]] += 1
    i += 1


while posCnt[0] > 0 and posCnt[1] > 1 and posCnt[2] > 2:

    posCnt[mainQueue[lowerBound][1]] -= 1
    if not mainQueue[lowerBound][1]:
        finalCounter += posCnt[1] * (posCnt[1] - 1) * posCnt[2] * (posCnt[2] - 1) * (posCnt[2] - 2) // 12
    elif mainQueue[lowerBound][1] == 1:
        finalCounter += posCnt[0] * posCnt[1] * posCnt[2] * (posCnt[2] - 1) * (posCnt[2] - 2) // 6
    else:
        finalCounter += posCnt[0] * posCnt[1] * (posCnt[1] - 1) * posCnt[2] * (posCnt[2] - 1) // 4

    lowerBound += 1

print(finalCounter)


from math import factorial

n, m, k = (int(x) for x in input().split())
a = sorted([int(x) for x in input().split()])
b = sorted([int(x) for x in input().split()])
c = sorted([int(x) for x in input().split()])


def create_count_arr(a):
    a_count = [0] * (10 ** 5 + 5)
    for i in range(len(a)):
        a_count[a[i]:] = [i + 1] * ((10 ** 5 + 5) - a[i])
    return a_count


def get_num(x, y, a):
    if y >= len(a):
        y = len(a) - 1
    c = a[y] - a[x]
    if a[x] != a[x - 1]:
        c += 1
    return c


def num_of_permut(n, k):
    return factorial(n) // (factorial(k) * factorial(n - k))


a_count = create_count_arr(a)
b_count = create_count_arr(b)
c_count = create_count_arr(c)

count = 0

for i in a:
    d = get_num(i, i * 2, b_count)
    f = get_num(i, i * 2, c_count)
    if d >= 2 and f >= 3:
        count += num_of_permut(d, 2) * num_of_permut(f, 3)
for i in b:
    g = get_num(i, i * 2, a_count)
    d = get_num(i, i * 2, b_count) - 1
    f = get_num(i, i * 2, c_count)
    if g >= 1 and d >= 1 and f >= 3:
        count += num_of_permut(d, 1) * num_of_permut(f, 3) * g
for i in c:
    g = get_num(i, i * 2, a_count)
    d = get_num(i, i * 2, b_count)
    f = get_num(i, i * 2, c_count) - 1
    if g >= 1 and d >= 2 and f >= 2:
        count += num_of_permut(d, 2) * num_of_permut(f, 2) * g
print(count)

#упрощенное вычисление C
def c2(n):
    return n*(n-1)//2
def c3(n):
    return n*(n-1)*(n-2)//6

g,d,f=map(int,input().split())
#Костыль
if g<1 or d<2 or f<3:
    print(0)
    return

ans=0
a=[]
n=g+d+f
#скидываем все в один массив и запоминаем типы
for i in map(int,input().split()):
    a.append((i,0))
for i in map(int,input().split()):
    a.append((i,1))
for i in map(int,input().split()):
    a.append((i,2))

#сортируем этот массив по номеру
a.sort()

for i in range(n): #в i перебераем минимум
    types=[0,0,0]
    j=i+0#в j перебераем максимум
    while j<n and a[j][0]<=2*a[i][0]: #если максимум в 2 раза меньше минимума, то и все остальные
        types[a[j][1]]+=1
        now_types=types.copy()
        now_types[a[j][1]]-=1
        now_types[a[i][1]]-=1
        #проверка на то, какого типа минимум и максимум, их мы не учитываем при подсчете кол-ва вариантов, потому что мы их зафиксировали, чтобы не было повторов
        if a[j][1]==0 and a[i][1]==1 or a[j][1]==1 and a[i][1]==0:
            if now_types[1]>=1 and now_types[2]>=3:
                ans+=now_types[1]*c3(now_types[2])
        elif a[j][1]==0 and a[i][1]==2 or a[j][1]==2 and a[i][1]==0:
            if now_types[1]>=2 and now_types[2]>=2:
                ans+=c2(now_types[1])*c2(now_types[2])
        elif a[j][1]==2 and a[i][1]==1 or a[j][1]==1 and a[i][1]==2:
            if now_types[0]>=1 and now_types[1]>=1 and now_types[2]>=2:
                ans+=now_types[0]*now_types[1]*c2(now_types[2])
        elif a[j][1]==1 and a[i][1]==1:
            if now_types[0]>=1 and now_types[2]>=3:
                ans+=now_types[0]*c3(now_types[2])
        elif a[j][1]==2 and a[i][1]==2:
            if now_types[0]>=1 and now_types[1]>=2 and now_types[2]>=1:
                ans+=now_types[0]*c2(now_types[1])*now_types[2]
        j+=1
print(ans)

def C(n, k):
    if n < k:
        return 0

    if k == 1:
        return n                        # Сочетания из n по 1
    elif k == 2:
        return n * (n-1) // 2           # Сочетания из n по 2
    elif k == 3:
        return n * (n-1) * (n-2) // 6   # Сочетания из n по 3


def main():
    g, d, f = [int(_) for _ in input().split()]
    gs = [int(_) for _ in input().split()]
    ds = [int(_) for _ in input().split()]
    fs = [int(_) for _ in input().split()]

    ans = 0

    gs.sort()
    ds.sort()
    fs.sort()
    # print(gs)
    # print(ds)
    # print(fs)

    gmin, dmin, fmin = 0, 0, 0
    gmax, dmax, fmax = 0, 0, 0

    while g-gmin >= 1 and d-dmin >= 2 and f-fmin >= 3:
        term = 1
        mn = min(gs[gmin], ds[dmin], fs[fmin])

        while gmax < g and gs[gmax] <= mn * 2:
            gmax += 1
        gn = gmax - gmin
        if mn == gs[gmin]:
            term *= 1
            gmin += 1
        else:
            term *= C(gn, 1)

        while dmax < d and ds[dmax] <= mn * 2:
            dmax += 1
        dn = dmax - dmin
        if mn == ds[dmin]:
            term *= C(dn-1, 1)
            dmin += 1
        else:
            term *= C(dn, 2)

        while fmax < f and fs[fmax] <= mn * 2:
            fmax += 1
        fn = fmax - fmin
        if mn == fs[fmin]:
            term *= C(fn-1, 2)
            fmin += 1
        else:
            term *= C(fn, 3)

        ans += term

    print(ans)


def print_test():
    from random import randint
    g, d, f = 200, 400, 600
    # g, d, f = 3, 4, 5
    print(g, d, f)
    for _ in range(g):
        print(randint(1, 100000), end=' ')
    print()
    for _ in range(d):
        print(randint(1, 100000), end=' ')
    print()
    for _ in range(f):
        print(randint(1, 100000), end=' ')
    print()


def __starting_point():
    main()
    # print_test()

# 3 4 5
# 71655 49064 41937
# 64260 37491 58885 40628
# 23852 36500 67530 33756 73

# 3 4 5
# 71 49 41
# 64 37 58 40
# 23 36 67 33 1

# 3 4 6
# 71 49 41
# 64 37 58 40
# 23 36 67 33 1 60

__starting_point()


s = input().split()
v = int(s[0])
z = int(s[1])
n = int(s[2])
g = [int(i) for i in input().split()]
d = [int(i) for i in input().split()]
f = [int(i) for i in input().split()]
g.sort()
d.sort()
f.sort()
iterator = [0, 0, 0]
ending = [0, 0, 0]
gap = [0, 0]
count = 0

if v < 1 or z < 2 or n < 3:
    print(0)
else:
    while iterator[0] < v and iterator[1] < z and iterator[2] < n:
        if g[iterator[0]] < d[iterator[1]] and g[iterator[0]] < f[iterator[2]]: #в случае, если вратарь -- минимальный номер
            max = g[iterator[0]]*2 + 1
            v = int(s[0])
            while ending[1] < z and d[ending[1]] < max:
                ending[1] += 1
            while ending[2] < n and f[ending[2]] < max:
                ending[2] += 1
            if ending[1] - iterator[1] < 2:
                iterator[0] += 1
                continue
            elif ending[2] - iterator[2] < 3:
                iterator[0] += 1
                continue
            else:
                gap[0] = ending[1] - iterator[1]
                gap[1] = ending[2] - iterator[2]
                count += gap[0]*(gap[0]-1)*gap[1]*(gap[1]-1)*(gap[1]-2) // 12
                iterator[0] += 1
        elif d[iterator[1]] < g[iterator[0]] and d[iterator[1]] < f[iterator[2]]: #в случае, если защитник -- минимальный номер
            max = d[iterator[1]] * 2 + 1
            while ending[0] < v and g[ending[0]] < max:
                ending[0] += 1
            while ending[1] < z and d[ending[1]] < max:
                ending[1] += 1
            while ending[2] < n and f[ending[2]] < max:
                ending[2] += 1
            if ending[0] - iterator[0] < 1:
                iterator[1] += 1
                continue
            elif ending[1] - iterator[1] < 2:
                iterator[1] += 1
                continue
            elif ending[2] - iterator[2] < 3:
                iterator[1] += 1
                continue
            else:
                gap[0] = ending[1] - iterator[1]
                gap[1] = ending[2] - iterator[2]
                count += (ending[0] - iterator[0]) * (ending[1] - iterator[1] - 1) * gap[1]*(gap[1]-1)*(gap[1]-2) // 6
                iterator[1] += 1
        elif f[iterator[2]] < g[iterator[0]] and f[iterator[2]] < d[iterator[1]]: # в случае, если нападающий -- минимальный номер
            max = f[iterator[2]] * 2 + 1
            while ending[0] < v and g[ending[0]] < max:
                ending[0] += 1
            while ending[1] < z and d[ending[1]] < max:
                ending[1] += 1
            while ending[2] < n and f[ending[2]] < max:
                ending[2] += 1
            if ending[0] - iterator[0] < 1:
                iterator[2] += 1
                continue
            elif ending[1] - iterator[1] < 2:
                iterator[2] += 1
                continue
            elif ending[2] - iterator[2] < 3:
                iterator[2] += 1
                continue
            else:
                gap[0] = ending[1] - iterator[1]
                gap[1] = ending[2] - iterator[2]
                count += (ending[0] - iterator[0]) * gap[0]*(gap[0]-1) * (gap[1]-1)*(gap[1]-2) // 4
                iterator[2] += 1
    print(count)



g,d,f = map(int,input().split())

goalkeepers = list(map(int,input().split()))
defenders = list(map(int,input().split()))
forwards = list(map(int,input().split()))



#min goalkeeper
count = 0

for keeper in goalkeepers:
    defend = len(list(filter(lambda x:x>keeper and x<=keeper*2,defenders)))
    forw = len(list(filter(lambda x:x>keeper and x<=keeper*2,forwards)))
    count+=defend*(defend - 1)*forw*(forw-1)*(forw-2)/12



# min def

for defend in defenders:
    second_defend = len(list(filter(lambda x:x>defend and x<=defend*2,defenders)))
    forw = len(list(filter(lambda x:x>defend and x<=defend*2,forwards)))
    goal  = len(list(filter(lambda x:x>defend and x<=defend*2,goalkeepers)))
    count+=second_defend*goal*forw*(forw-1)*(forw-2)/6

for defend in forwards:
    second_defend = len(list(filter(lambda x: x > defend and x <= defend * 2, defenders)))
    forw = len(list(filter(lambda x: x > defend and x <= defend * 2, forwards)))
    goal = len(list(filter(lambda x: x > defend and x <= defend * 2, goalkeepers)))
    count += second_defend *(second_defend-1)* goal * forw * (forw - 1)   / 4

print(int(count))