CF 2A, 2B solutions (in C++, second fits 8mb RAM now).