Maximum with a catch

A function is given by $$f(x)=x^{3}+3$$

$$N$$ line separated lists are given in the text file, and let $$S=(f(x_{1})+f(x_{2})+\ldots +f(x_{n})) \bmod {123}$$ where $$x_{i}$$ is an element picked from the $$i$$th's list. What is the maximum possible value of $$S$$?

×