Consider the permutation of $1,2,...,n$, which we denote as $\{a_1,a_2,...,a_n\}$. Let $f(n)$ be the number of these permutations satisfying the following conditions:
(1)$a_1=1$
(2)$|a_i-a_{i-1}|\le2, i=1,2,...,n-1$
what is the residue when we divide $f(2015)$ by $4$ ?
1. **Define the problem and recurrence relation:**
   We are given a permutation of $\{1, 2, \ldots, n\}$, denoted as $\{a_1, a_2, \ldots, a_n\}$, and we need to find the number of such permutations, $f(n)$, that satisfy:
   - $a_1 = 1$
   - $|a_i - a_{i-1}| \leq 2$ for $i = 2, 3, \ldots, n$

   The recurrence relation for $f(n)$ is given by:
   \[
   f(n) = f(n-1) + f(n-3) + 1
   \]

2. **Analyze the recurrence relation modulo 4:**
   We need to find the residue of $f(2015)$ modulo 4. To do this, we will compute the first few values of $f(n) \mod 4$ and identify any repeating pattern.

3. **Compute initial values:**
   Let's compute the initial values of $f(n) \mod 4$:
   \[
   \begin{aligned}
   f(1) & = 1 \\
   f(2) & = 1 \\
   f(3) & = 2 \\
   f(4) & = f(3) + f(1) + 1 = 2 + 1 + 1 = 4 \equiv 0 \mod 4 \\
   f(5) & = f(4) + f(2) + 1 = 0 + 1 + 1 = 2 \mod 4 \\
   f(6) & = f(5) + f(3) + 1 = 2 + 2 + 1 = 5 \equiv 1 \mod 4 \\
   f(7) & = f(6) + f(4) + 1 = 1 + 0 + 1 = 2 \mod 4 \\
   f(8) & = f(7) + f(5) + 1 = 2 + 2 + 1 = 5 \equiv 1 \mod 4 \\
   f(9) & = f(8) + f(6) + 1 = 1 + 1 + 1 = 3 \mod 4 \\
   f(10) & = f(9) + f(7) + 1 = 3 + 2 + 1 = 6 \equiv 2 \mod 4 \\
   f(11) & = f(10) + f(8) + 1 = 2 + 1 + 1 = 4 \equiv 0 \mod 4 \\
   f(12) & = f(11) + f(9) + 1 = 0 + 3 + 1 = 4 \equiv 0 \mod 4 \\
   f(13) & = f(12) + f(10) + 1 = 0 + 2 + 1 = 3 \mod 4 \\
   f(14) & = f(13) + f(11) + 1 = 3 + 0 + 1 = 4 \equiv 0 \mod 4 \\
   \end{aligned}
   \]

4. **Identify the repeating pattern:**
   From the computed values, we observe the pattern:
   \[
   1, 1, 2, 0, 2, 1, 2, 1, 3, 2, 0, 0, 3, 0
   \]
   This pattern repeats every 14 terms.

5. **Determine the position of $f(2015)$ in the pattern:**
   Since the period is 14, we need to find the position of $2015$ modulo 14:
   \[
   2015 \mod 14 = 13
   \]
   Therefore, $f(2015) \equiv f(13) \mod 4$.

6. **Find the value of $f(13) \mod 4$:**
   From our pattern, $f(13) \equiv 3 \mod 4$.

The final answer is $\boxed{3}$.