Say you only have 3 players.

The maximum number is: 2+2+2+1+1

If 4 then: 2+2+2+2+1+1+1

If 5 then: 2+2+2+2+2+1+1+1+1

We see that general formula is, if n>=3 players then:

(2+2+...+2)+(1+1+...1)

Where 2 appears n times and 1 appears n-1 times.

Thus,

2n+1(n-1) = 3n - 1

Thus, if you have 512 that means,

3(512)-1