We can write S as
[tex]\displaystyle S = \sum_{k=0}^{n-1} (n-k)3^k[/tex]
and expand it as
[tex]\displaystyle S = n \sum_{k=0}^{n-1} 3^k - \sum_{k=0}^{n-1} k\cdot3^k[/tex]
The first sum is geometric, nothing tricky:
[tex]\displaystyle\sum_{k=0}^{n-1} 3^k = 1 + 3 + 3^2 + \cdots + 3^{n-1} \\\\ \implies 3\sum_{k=0}^{n-1} 3^k = 3 + 3^2 + 3^3 + \cdots + 3^n \\\\ \implies -2\sum_{k=0}^{n-1} 3^k = 1 - 3^n \\\\ \implies \sum_{k=0}^{n-1} 3^k = \frac{3^n-1}2[/tex]
For the second sum, you can use the same method employed in another question of yours (24494877) to find
[tex]\displaystyle \sum_{k=0}^{n-1} k\cdot 3^k = \frac{(2n-3)3^n+3}4[/tex]
So this sum comes out to
[tex]\displaystyle S = n\cdot\frac{3^n-1}2 - \frac{(2n-3)3^n+3}4 \\\\ S = \frac{2n\cdot3^n-2n - (2n-3)3^n-3}4 \\\\ \boxed{S = \frac{3^{n+1}-2n-3}4}[/tex]