```
public int ArrangeCoins(int n) {
if (n <= 0) { return 0; };
if (n == 1) { return 1; };
uint nAsuint = (uint)n;
uint doubleN = (uint)(nAsuint * 2);
uint upperNumber = (uint)Math.Sqrt(doubleN);
while (upperNumber > 1)
{
if ((upperNumber * (upperNumber + 1) / 2) <= nAsuint){
break;
}
upperNumber--;
}
return (int)(upperNumber);
}
```