brute force solution is way too slow