import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }


enum INF = 10L^^18;

int N, H, W;
int[] X, Y;
long[] A;

void main() {
  try {
    for (; ; ) {
      N = readInt();
      H = readInt();
      W = readInt();
      X = new int[N];
      Y = new int[N];
      A = new long[N];
      foreach (i; 0 .. N) {
        X[i] = readInt() - 1;
        Y[i] = readInt() - 1;
        A[i] = readLong();
      }
      
      alias Entry = Tuple!(long, "val", int, "key");
      auto qX = new BinaryHeap!(Array!Entry)[H];
      auto qY = new BinaryHeap!(Array!Entry)[W];
      foreach (i; 0 .. N) {
        qX[X[i]].insert(Entry(A[i], i));
        qY[Y[i]].insert(Entry(A[i], i));
      }
      
      auto es = new Entry[N];
      foreach (i; 0 .. N) {
        es[i] = Entry(A[i], i);
      }
      sort(es);
      reverse(es);
      
      auto usedX = new bool[H];
      auto usedY = new bool[W];
      long ans;
      foreach (j; 0 .. N) {
        const i = es[j].key;
        debug {
          writeln(i, " ", es[j], " ", qX[X[i]].front, " ", qY[Y[i]].front);
        }
        qX[X[i]].removeFront;
        qY[Y[i]].removeFront;
        if (!usedX[X[i]] && !usedY[Y[i]]) {
          const aX = qX[X[i]].empty ? Entry(-INF, -1) : qX[X[i]].front;
          const aY = qY[Y[i]].empty ? Entry(-INF, -1) : qY[Y[i]].front;
          if (aX < aY) {
            usedX[X[i]] = true;
            ans += A[i];
          } else {
            usedY[Y[i]] = true;
            ans += A[i];
          }
        } else if (!usedX[X[i]]) {
          usedX[X[i]] = true;
          ans += A[i];
        } else if (!usedY[Y[i]]) {
          usedY[Y[i]] = true;
          ans += A[i];
        } else {
          // discard
        }
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}
