function [elements, counts] = freq(A)
    A = sort(A);
    mask = [diff(A) > 0, true];
    elements = A(mask);
    counts = arrayfun(@(x) sum(x == A), elements);
end