Added memoisation to the frequency function fr(x)