SRM 507 DIV 2 500 Easy

Missed a few tricky cases :)