Find all functions $f:\mathbb{Z} \rightarrow \mathbb{Z}$ such that $f(1) \neq f(-1)$ and $$f(m+n)^2 \mid f(m)-f(n)$$ for all integers $m, n$.

[i]Proposed by Liam Baker, South Africa[/i]
1. Given the function \( f: \mathbb{Z} \rightarrow \mathbb{Z} \) such that \( f(1) \neq f(-1) \) and \( f(m+n)^2 \mid f(m) - f(n) \) for all integers \( m, n \), we start by analyzing the given condition.
   
   \[
   f(m+n)^2 \mid f(m) - f(n) \quad \text{for all integers } m, n
   \]

2. Setting \( n = 0 \) in the given condition, we get:

   \[
   f(m+0)^2 \mid f(m) - f(0) \implies f(m)^2 \mid f(m) - f(0)
   \]

   This implies:

   \[
   f(m) \mid f(m) - f(0)
   \]

   Therefore, \( f(m) \mid f(0) \) for all \( m \in \mathbb{Z} \). Let's denote \( f(0) = c \). Thus, \( f(m) \) is a divisor of \( c \) for all \( m \).

3. Suppose there exists \( k \) such that \( f(k) = 0 \). Then, substituting \( n = k - m \) in the original condition, we get:

   \[
   f(m + (k - m))^2 \mid f(m) - f(k - m) \implies f(k)^2 \mid f(m) - f(k - m)
   \]

   Since \( f(k) = 0 \), this implies:

   \[
   0 \mid f(m) - f(k - m)
   \]

   This is a contradiction unless \( f(m) = f(k - m) \) for all \( m \). Therefore, there does not exist any \( k \) such that \( f(k) = 0 \).

4. Now, suppose \( f \) takes on an infinite number of values. Then \( f(0) \) must have an infinite number of divisors, which is impossible unless \( f(0) = 0 \). But we have already established that \( f(k) \neq 0 \) for any \( k \). Hence, \( f \) must take on a finite number of values, implying \( f \) is bounded.

5. We now prove by induction that \( f(a) \mid f(ak) \) for all \( a, k \in \mathbb{Z} \).

   **Base case:**
   \[
   f(a) \mid f(a)
   \]

   By the earlier result, \( f(a) \mid f(0) \).

   **Inductive hypothesis:**
   Assume \( f(a) \mid f(ak) \) for \( |k| \le t \).

   **Inductive step:**
   Consider \( m = at \) and \( n = -a(t-1) \):

   \[
   f(at + (-a(t-1)))^2 \mid f(at) - f(-a(t-1)) \implies f(a)^2 \mid f(at) - f(a(t-1))
   \]

   By the inductive hypothesis, \( f(a) \mid f(a(t-1)) \):

   \[
   f(a) \mid f(at) - f(a(t-1)) \implies f(a) \mid f(at)
   \]

   Similarly, for \( m = -at \) and \( n = a \):

   \[
   f(-at + a)^2 \mid f(-at) - f(a) \implies f(a)^2 \mid f(-at) - f(a)
   \]

   By the inductive hypothesis, \( f(a) \mid f(a) \):

   \[
   f(a) \mid f(-at) - f(a) \implies f(a) \mid f(-at)
   \]

   Thus, by induction, \( f(a) \mid f(ak) \) for all \( a, k \in \mathbb{Z} \).

6. By the previous result, there exists \( c \) such that \( |f(c)| \) is maximum. Consider \( m = 1 \) and \( n = -1 \):

   \[
   f(1 + (-1))^2 \mid f(1) - f(-1) \implies f(0)^2 \mid f(1) - f(-1)
   \]

   Since \( f(0) = c \):

   \[
   c^2 \mid f(1) - f(-1)
   \]

   Given \( f(1) \neq f(-1) \), we have:

   \[
   c^2 \le |f(1) - f(-1)| \le 2|c|
   \]

   This implies \( |c| \in \{1, 2\} \).

7. **Case 1: \( |c| = 1 \)**

   \[
   |f(k)| \le |c| = 1 \implies f(k) \in \{-1, 1\}
   \]

   Since \( f(1) \neq f(-1) \), we have \( f(1) = -f(-1) \).

8. **Case 2: \( |c| = 2 \)**

   \[
   |f(k)| \le |c| = 2 \implies f(k) \in \{-2, 2\}
   \]

   Since \( f(1) \neq f(-1) \), we have \( f(1) = -f(-1) \).

Thus, the only solutions are \( f \in \{1, -1\} \) or \( f \in \{2, -2\} \) with \( f(1) = -f(-1) \).

The final answer is \( \boxed{ f \in \{1, -1\} } \) or \( f \in \{2, -2\} \) with \( f(1) = -f(-1) \).