Continous functions on cofinite topology 
Let $X$ be the cofinite topology and let $f\colon X\to X$ a non-constant function. Show that $f\colon X\to X$ is continuous iff for every inifinite subset $A\subseteq X$, $f(A)$ is infinite.

I am lost with this problem and don't even know if it's true. For the implication from left to right, I supposed that $f(A)$ is finite, so there is a infinite subset of $A$, $B$, such that there are not elements in $X$ that their image lies in $B$. But from here, how does the continuity help us? $A$ is not necessarily an open set, so don't know how to proceed.
 A: Here’s an approach using closed sets.
$(\rightarrow)$
Assume by contradiction that $A$ is infinite but $f(A)$ is finite. Then $f(A)$ is closed; since $f$ is continuous, $f^{-1}(f(A))$ is closed. Therefore, $f^{-1}(f(A))$ is either finite or all of $X$. If it is finite, then $A\subseteq f^{-1}(f(A))$ implies $A$ is finite, a contradiction.
Now suppose $f^{-1}(f(A))=X$. Suppose $V\subseteq f(A)$. Since $V$ is finite, $V$ is closed. But $f^{-1}(f(A)-V) = f^{-1}(f(A))-f^{-1}(V)$, so $f^{-1}(V)$ must either be $\varnothing$ or $X$. Therefore, there exists a singleton $\{y\}$ such that $f^{-1}(y)=X$, contradicting the assumption that $f$ is not constant. As such, $f^{-1}$ cannot be continuous, as desired.
$(\leftarrow)$
Let $V\ne X$ be a closed set of $X$. Then $V$ is finite, so if $f^{-1}(V)$ was infinite, then $f(f^{-1}(V))\subseteq V$ would be infinite by assumption, a contradiction. Clearly $f^{-1}(X)$ is closed, so the proof is complete.

EDIT: Here is some more justification for the $f^{-1}(f(A)) = X$ case.
Recall we assumed the existence of an infinite set $A\subseteq X$, so $X$ is infinite. Because $V$ is closed, $f^{-1}(V)$ is closed. $f(A)-V$ is also closed because $f(A)$ is finite, so
$$f^{-1}(f(A)-V) = f^{-1}(f(A))-f^{-1}(V) = X - f^{-1}(V)$$
is also closed. $f^{-1}(V)$ can either be $\varnothing$, a finite set, or $X$ itself. If $f^{-1}(V)$ is finite and not empty, then $X-f^{-1}(V)\ne X$ is closed, impossible because it is an infinite set.
Hence for all singletons $y\in f(A)$, $f^{-1}(y) = X$ or $f^{-1}(y)=\varnothing$. If all of the fibers $f^{-1}(y)=\varnothing$, then
$$f^{-1}(f(A)) = f^{-1}\left(\bigcup_{y\in f(A)} y\right) =\bigcup_{y\in f(A)} f^{-1}(y)= \varnothing,$$
a contradiction.
A: $(\implies)$ We prove the contrapositive. Suppose $A \subseteq X$ is infinite, but $f(A)$ is finite. We aim to show $f$ is not continuous, or that $f$ is constant. If $f$ is not continuous, then we are done, so we assume $f$ is continuous, and aim to show $f$ is constant.
We then have $X \setminus f(A)$ is cofinite, and hence open. I claim that
$$A \subseteq X \setminus f^{-1}(X \setminus f(A)),$$
which implies that $X \setminus f^{-1}(X \setminus f(A))$ is infinite, hence $f^{-1}(X \setminus f(A))$ is not cofinite. But, since $f$ is continuous, it must be open, and the only open set that isn't cofinite is $\emptyset$. Note the claim is equivalent to
$$f^{-1}(X \setminus f(A)) \cap A = \emptyset.$$
If there were some $a$ in the left hand side, then $f(a) \in X \setminus f(A)$, while $a \in A$, so $f(a) \in f(A)$, which is a contradiction. Thus, the claim holds, and so
$$f^{-1}(X \setminus f(A)) = \emptyset.$$
Then, $X \setminus f(A)$ contains no points in the range of $f$, i.e. $f(A) = f(X)$, and so $f$ has a finite range. Let this range be $y_1, \ldots, y_n$ be the distinct points in this range.
Note that $f^{-1}\{y_i\}$ for $i = 1, \ldots, n$ form a family of pairwise disjoint subsets of $X$. It is therefore not possible for two such sets to be cofinite. But, $f^{-1}(y_i) = f^{-1}(\{y_i\} \cup (X \setminus f(X)))$ is the inverse image of a cofinite set, and hence open. So, all but one of these sets must be empty (and one must be non-empty and hence cofinite, since all points in $X$ must map somewhere). Thus, the range can only consist of a single point, i.e. $f$ is constant, as required.
$(\impliedby)$ Suppose the infinite set condition holds, and $\mathcal{U}$ is open. We wish to show that $f^{-1}(\mathcal{U})$ is open as well. If $\mathcal{U} = \emptyset$, then this is clearly true, so we assume that $X \setminus \mathcal{U}$ is finite.
Suppose $A = f^{-1}(X \setminus \mathcal{U})$ were infinite. Then $f(A)$ would be infinite as well. But, $f(A) \subseteq X \setminus \mathcal{U}$, a finite set, so this would be a contradiction. Thus, $A$ is finite, and $X \setminus A$, i.e. $X \setminus f^{-1}(X \setminus \mathcal{U})$ is cofinite. We just need to show:
$$X \setminus f^{-1}(X \setminus \mathcal{U}) \subseteq f^{-1}(\mathcal{U}),$$
which will show $f^{-1}(\mathcal{U})$ contains a cofinite set, and hence is cofinite. But, this follows easily from the fact that $f^{-1}(X \setminus \mathcal{U})$ and $f^{-1}(\mathcal{U})$ are disjoint, as the inverse images of disjoint sets. This completes the proof.
