MAXRGB = 3000 def solve(n, R, G, B): Rcnt = [0] * (MAXRGB + 1) Gcnt = [0] * (MAXRGB + 1) Bcnt = [0] * (MAXRGB + 1) for r in R: Rcnt[r] += 1 for g in G: Gcnt[g] += 1 for b in B: Bcnt[b] += 1 Rsum = [0] * (MAXRGB + 2) for i in range(MAXRGB + 1): Rsum[i + 1] = Rsum[i] + Rcnt[i] ans = 0 for g in range(1, MAXRGB + 1): for b in range(1, MAXRGB + 1): tmp = Rsum[min(MAXRGB + 1, g + b)] - Rsum[min(MAXRGB + 1, max(g, b, abs(g - b) + 1))] ans += tmp * Gcnt[g] * Bcnt[b] return ans def solve2d(n, R, G, B): Rcnt = [0] * (MAXRGB + 1) Gcnt = [0] * (MAXRGB + 1) Bcnt = [0] * (MAXRGB + 1) for r in R: Rcnt[r] += 1 for g in G: Gcnt[g] += 1 for b in B: Bcnt[b] += 1 C = [[0] * (2 * MAXRGB + 2) for i in range(MAXRGB + 2)] for i in range(1, MAXRGB + 1): for j in range(1, MAXRGB + 1): C[max(i, j) + 1][i + j + 1] += Gcnt[i] * Bcnt[j] for i in range(MAXRGB + 1): for j in range(2 * MAXRGB + 1): C[i + 1][j + 1] += C[i][j + 1] + C[i + 1][j] - C[i][j] ans = 0 for i in range(1, MAXRGB + 1): tmp = C[i + 1][2 * MAXRGB + 1] + C[1][i + 1] - C[i + 1][i + 1] - C[1][2 * MAXRGB + 1] ans += Rcnt[i] * tmp return ans def bruteforce(n, R, G, B): Rcnt = [0] * (MAXRGB + 1) Gcnt = [0] * (MAXRGB + 1) Bcnt = [0] * (MAXRGB + 1) for r in R: Rcnt[r] += 1 for g in G: Gcnt[g] += 1 for b in B: Bcnt[b] += 1 ans = 0 for i in range(1, MAXRGB + 1): if Rcnt[i] == 0: continue for j in range(1, min(MAXRGB + 1, i + 1)): if Gcnt[j] == 0: continue for k in range(1, min(MAXRGB + 1, i + 1)): if i + j > k and j + k > i and k + i > j: ans += Rcnt[i] * Gcnt[j] * Bcnt[k] return ans import random def gen(n): R = [random.randint(1, MAXRGB) for i in range(n)] G = [random.randint(1, MAXRGB) for i in range(n)] B = [random.randint(1, MAXRGB) for i in range(n)] return n, R, G, B def answer(): n = int(input()) R = list(map(int, input().split())) G = list(map(int, input().split())) B = list(map(int, input().split())) global MAXRGB MAXRGB = max(MAXRGB, max(R)) MAXRGB = max(MAXRGB, max(G)) MAXRGB = max(MAXRGB, max(B)) ans = solve2d(n, R, G, B) print(ans) def test(t): for i in range(t): n, R, G, B = gen(random.randint(1, 200000)) print(solve(n, R, G, B) - solve2d(n, R, G, B)) answer()