Let $S$ be the set of all ordered triples $\left(a,b,c\right)$ of positive integers such that $\left(b-c\right)^2+\left(c-a\right)^2+\left(a-b\right)^2=2018$ and $a+b+c\leq M$ for some positive integer $M$. Given that $\displaystyle\sum_{\left(a,b,c\right)\in S}a=k$, what is \[\displaystyle\sum_{\left(a,b,c\right)\in S}a\left(a^2-bc\right)\] in terms of $k$?

[i]2018 CCA Math Bonanza Lightning Round #4.1[/i]
1. Let \( T \) be the desired sum, \(\sum_{(a,b,c) \in S} a(a^2 - bc)\).
2. Observe that the set \( S \) is symmetric with respect to \( a, b, \) and \( c \). This means that for any permutation of \( (a, b, c) \), the expression \((b-c)^2 + (c-a)^2 + (a-b)^2\) remains the same.
3. We can use the symmetry to simplify the sum. Since \( S \) is symmetric, we can write:
   \[
   3T = \sum_{(a,b,c) \in S} \left( a^3 + b^3 + c^3 - 3abc \right)
   \]
4. Using the identity for the sum of cubes, we have:
   \[
   a^3 + b^3 + c^3 - 3abc = \frac{(a+b+c)((a-b)^2 + (b-c)^2 + (c-a)^2)}{2}
   \]
5. Given that \((b-c)^2 + (c-a)^2 + (a-b)^2 = 2018\), we substitute this into the equation:
   \[
   a^3 + b^3 + c^3 - 3abc = \frac{(a+b+c) \cdot 2018}{2}
   \]
6. Therefore, we can rewrite the sum as:
   \[
   3T = \sum_{(a,b,c) \in S} \frac{(a+b+c) \cdot 2018}{2}
   \]
7. Since \( a + b + c \) is the same for all permutations of \( (a, b, c) \) in \( S \), we can factor out the constant \( 2018/2 = 1009 \):
   \[
   3T = 1009 \sum_{(a,b,c) \in S} (a + b + c)
   \]
8. Given that \(\sum_{(a,b,c) \in S} a = k\), and by symmetry, \(\sum_{(a,b,c) \in S} b = k\) and \(\sum_{(a,b,c) \in S} c = k\), we have:
   \[
   \sum_{(a,b,c) \in S} (a + b + c) = 3k
   \]
9. Substituting this back into the equation for \( 3T \):
   \[
   3T = 1009 \cdot 3k
   \]
10. Simplifying, we get:
    \[
    3T = 3027k
    \]
11. Therefore, \( T \) is:
    \[
    T = 1009k
    \]

The final answer is \(\boxed{1009k}\).