Buggy python submission (verdict: Time Limit Exceeded):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    X,Y,Z = LI()
    xyz = []
    for _ in range(X+Y+Z):
        x,y,z = LI()
        xyz.append((x,y,z,x-y,y-z,z-x))

    xyz.sort(key=lambda _: _[3] - _[2])
    xs = xyz[Y+Z:]
    yz = xyz[:Y+Z]
    yz.sort(key=lambda _: _[4])
    ys = yz[Z:]
    zs = yz[:Z]

    f = True
    while f:
        f = False
        xs.sort(key=lambda _: _[3])
        ys.sort(key=lambda _: -_[3])
        for i in range(min(X,Y)):
            if xs[i][3] - ys[i][3] >= 0:
                break
            # print('xy', xs[i],ys[i])
            xs[i],ys[i] = ys[i],xs[i]
            f = True

        ys.sort(key=lambda _: _[4])
        zs.sort(key=lambda _: -_[4])
        for i in range(min(Y,Z)):
            if ys[i][4] - zs[i][4] >= 0:
                break
            # print('yz', ys[i],zs[i])
            ys[i],zs[i] = ys[i],zs[i]
            f = True

        zs.sort(key=lambda _: _[5])
        xs.sort(key=lambda _: -_[5])
        for i in range(min(Z,X)):
            if zs[i][5] - xs[i][5] >= 0:
                break
            # print('zx', zs[i],xs[i])
            zs[i],xs[i] = zs[i],xs[i]
            f = True

        xs.sort(key=lambda _: _[3])
        ys.sort(key=lambda _: _[4])
        zs.sort(key=lambda _: _[5])

        for i in range(min([X,Y,Z])):
            if xs[i][3] + ys[i][4] + zs[i][5] >= 0:
                break
            # print('xyz1', xs[i],ys[i],zs[i])
            xs[i],ys[i],zs[i] = zs[i],xs[i],ys[i]
            f = True

        for i in range(min([X,Y,Z])):
            if xs[-i-1][5] + ys[-i-1][3] + zs[-i-1][4] <= 0:
                break
            # print('xyz2', xs[-i-1],ys[-i-1],zs[-i-1])
            xs[-i-1],ys[-i-1],zs[-i-1] = ys[-i-1],zs[-i-1],xs[-i-1]
            f = True

    r = 0
    # print(xs)
    # print(ys)
    # print(zs)
    for c in xs:
        r += c[0]
    for c in ys:
        r += c[1]
    for c in zs:
        r += c[2]

    return r




print(main())


Fixed submission:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    X,Y,Z = LI()
    xyz = sorted([LI() for _ in range(X+Y+Z)], key=lambda x: x[0]-x[1])
    ys = xyz[:Y]
    yq = []
    tr = 0
    for x,y,z in ys:
        heapq.heappush(yq, y-z)
        tr += y
    ya = [tr]
    for i in range(Z):
        x,y,z = xyz[Y+i]
        tr += y
        heapq.heappush(yq, y-z)
        t = heapq.heappop(yq)
        tr -= t
        ya.append(tr)

    xs = xyz[Y+Z:]
    xq = []
    tr = 0
    for x,y,z in xs:
        heapq.heappush(xq, x-z)
        tr += x
    xa = [tr]
    for i in range(Z):
        x,y,z = xyz[-X-i-1]
        tr += x
        heapq.heappush(xq, x-z)
        t = heapq.heappop(xq)
        tr -= t
        xa.append(tr)

    r = 0
    for a,b in zip(ya, xa[::-1]):
        tr = a+b
        if r < tr:
            r = tr

    return r




print(main())

Buggy python submission (verdict: Time Limit Exceeded):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    X,Y,Z = LI()
    xyz = []
    for _ in range(X+Y+Z):
        x,y,z = LI()
        xyz.append((x,y,z,x-y,y-z,z-x))

    xyz.sort(key=lambda _: _[3] - _[2])
    xs = xyz[Y+Z:]
    yz = xyz[:Y+Z]
    yz.sort(key=lambda _: _[4])
    ys = yz[Z:]
    zs = yz[:Z]

    f = True
    while f:
        f = False
        xs.sort(key=lambda _: _[3])
        ys.sort(key=lambda _: -_[3])
        for i in range(min(X,Y)):
            if xs[i][3] - ys[i][3] >= 0:
                break
            # print('xy', xs[i],ys[i])
            xs[i],ys[i] = ys[i],xs[i]
            f = True

        ys.sort(key=lambda _: _[4])
        zs.sort(key=lambda _: -_[4])
        for i in range(min(Y,Z)):
            if ys[i][4] - zs[i][4] >= 0:
                break
            # print('yz', ys[i],zs[i])
            ys[i],zs[i] = ys[i],zs[i]
            f = True

        zs.sort(key=lambda _: _[5])
        xs.sort(key=lambda _: -_[5])
        for i in range(min(Z,X)):
            if zs[i][5] - xs[i][5] >= 0:
                break
            # print('zx', zs[i],xs[i])
            zs[i],xs[i] = zs[i],xs[i]
            f = True

        xs.sort(key=lambda _: _[3])
        ys.sort(key=lambda _: _[4])
        zs.sort(key=lambda _: _[5])

        for i in range(min([X,Y,Z])):
            if xs[i][3] + ys[i][4] + zs[i][5] >= 0:
                break
            # print('xyz1', xs[i],ys[i],zs[i])
            xs[i],ys[i],zs[i] = zs[i],xs[i],ys[i]
            f = True

        for i in range(min([X,Y,Z])):
            if xs[-i-1][5] + ys[-i-1][3] + zs[-i-1][4] <= 0:
                break
            # print('xyz2', xs[-i-1],ys[-i-1],zs[-i-1])
            xs[-i-1],ys[-i-1],zs[-i-1] = ys[-i-1],zs[-i-1],xs[-i-1]
            f = True

    r = 0
    # print(xs)
    # print(ys)
    # print(zs)
    for c in xs:
        r += c[0]
    for c in ys:
        r += c[1]
    for c in zs:
        r += c[2]

    return r




print(main())


Fixed submission:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    X,Y,Z = LI()
    xyz = sorted([LI() for _ in range(X+Y+Z)], key=lambda x: x[0]-x[1])
    ys = xyz[:Y]
    yq = []
    tr = 0
    for x,y,z in ys:
        heapq.heappush(yq, y-z)
        tr += y
    ya = [tr]
    for i in range(Z):
        x,y,z = xyz[Y+i]
        tr += y
        heapq.heappush(yq, y-z)
        t = heapq.heappop(yq)
        tr -= t
        ya.append(tr)

    xs = xyz[Y+Z:]
    xq = []
    tr = 0
    for x,y,z in xs:
        heapq.heappush(xq, x-z)
        tr += x
    xa = [tr]
    for i in range(Z):
        x,y,z = xyz[-X-i-1]
        tr += x
        heapq.heappush(xq, x-z)
        t = heapq.heappop(xq)
        tr -= t
        xa.append(tr)

    r = 0
    for a,b in zip(ya, xa[::-1]):
        tr = a+b
        if r < tr:
            r = tr

    return r




print(main())