There are so many goddamned things to explain just to answer this question.
Usually rank, but if you're say 1st, but your mark in assessments is 65, and you get 60 in the HSC exam, that's not too good. So in this instance (good rank, crap marks) you're stuffed.
Bad Rank, Good Mark
If you're getting 85+, but you're ranking is like 50th, it's alright because that would mean the people above are much better. A good UAI is possible.
As someone explained before, the 1st person gets the best mark, the last person gets the worst, and the rest are rationed marks according to the gaps between them.