n = int(input()) q = [] for i in range(n): b = list(map(int ,input().split())) q.append(b) ans = 0 for i in q: if i[0] == 1: ans += sum([j[2] for j in q if j[0] == 0 and j[1] < q.index(i)]) print(ans)