Varies by school. Some have traditional grading (pass/high pass/pass/fail) all four years. Some do H/P/F. Some have P/F all four years. Some have P/F for the first two years and then H/HP/P/F for the clinical years.
For class rank it is just your grades, not USMLE score (at least at my school, I can't speak for others).
For your hypothetical of two people with identical grades, it can happen and then you have a tie. They don't do any valedictorian type big deals out of it. Ranking is really just for residency programs to measure your performance level against your classmates. At least from my school residencies don't get a specific rank number, they get a 1st, 2nd, 3rd, 4th or quartile designation (some places may do it different again, i can only speak for here). So it's not like having a tie is going to create a big problem.