4-ary words with given trace and subtrace

Here we consider the number $S(n;t,s)$ of length $n$ words $a_1 a_2\ldots a_n$ over the alphabet $\{0,1,\ldots,k-1\}$ with $k=4$ that have trace $t$ and subtrace $s$. The trace of a $k$-ary word is the sum of its digits mod $k$, i.e., $t=a_1+a_2+\cdots+a_n \pmod{k}$. The subtrace is the sum of the products of all $n(n-1)/2$ pairs of digits taken mod $k$, i.e., $s=\sum_{1\leq i\lt j\leq n} a_i a_j$.

(trace,subtrace)
$n$ (0,0) (0,1)
(2,3)
(0,2) (0,3)
(2,1)
(1,0)
(3,0)
(1,1)
(3,1)
(1,2)
(3,2)
(1,3)
(3,3)
(2,0) (2,2)
1 1000 1000 10
2 2002 2020 20
3 4606 6064 40
4 824824 16161616 160
5 56804080 40805680 5640
6 272272 240240 192320 192320 272 240
7 1184896 1120896 8961184 8961120 1184 1120
8 47633584 44803584 40964096 40964096 4608 4608
9 1753615360 1753615360 1753615360 1753615360 17536 17536
10 6579265280 6528065792 6963261440 6963261440 65792 65280

Examples

The two 4-ary strings of trace 0, subtrace 3 and length 2 are $\{13, 31\}$. The four 4-ary strings of trace 0, subtrace 0 and length 3 are $\{000, 022, 202, 220\}$. The four 4-ary strings of trace 2, subtrace 0 and length 3 are $\{002, 020, 200, 222\}$.

Enumeration (OEIS)

References