(position * 2) + if(r <= floor(n * .2), (floor(n * .2) + 1 - r) * 7, 0)
You didn't specify what to do when 20% of the number of players is not an even number. I used the "floor" function to round down. You could change it to "ceil" to round up, or "round" to round to the nearest whole number.