[Kotlin] matrix exponentiation in functional programming style
\ntypealias ll = Long\ntypealias ti3 = Triple<Int,Int,Int>\ntypealias vi = List<Long>\ntypealias vvi = List<vi>\nconst val mod = 1e9.toLong() + 7\n\n    \nclass
```\ntypealias ll = Long\ntypealias ti3 = Triple<Int,Int,Int>\ntypealias vi = List<Long>\ntypealias vvi = List<vi>\nconst val mod = 1e9.toLong() + 7\n\n    \nclass Solution {\n    private fun matMul(a: vvi, b: vvi): vvi {\n        val n = a.size\n        return (0 until n).map { i ->\n            (0 until n).map { j ->\n                (0 until n).sumOf { k ->\n                    a[i][k]*b[k][j]\n                }.rem(mod)\n            }\n        }\n    }\n\n    private fun matExp(a: vvi, e: Int): vvi {\n        val n = a.size\n        val ret = (0 until n).map { i ->\n            (0 until n).map { j ->\n                if (i == j) 1L else 0L\n            }\n        }.toList()\n\n        tailrec fun matExpHelper(exp: Int, base: vvi, res: vvi): vvi {\n            return when {\n                exp == 0 -> res\n                exp and 1 == 1 -> matExpHelper(exp shr 1, matMul(base, base), matMul(res, base))\n                else -> matExpHelper(exp shr 1, matMul(base, base), res)\n            }\n        }\n\n        return matExpHelper(e, a, ret)\n    }\n\n\n    fun stringCount(n: Int): Int {\n        val mp = (0 until 2).flatMap { i ->\n            (0 until 2).flatMap { j ->\n                (0 until 3).map { k ->\n                    Triple(i, j, k)\n                }\n            }\n        }.withIndex().associate { (index, triple) ->\n            triple to index\n        }.toMap()\n        \n        val m = mp.size\n        val a = MutableList(m) { MutableList(m) { 0L } }\n        \n        (0 until 2).forEach { i ->\n            (0 until 2).forEach { j ->\n                (0 until 3).forEach { k ->\n                    val ni = minOf(1, i + 1)\n                    val nj = minOf(1, j + 1)\n                    val nk = minOf(2, k + 1)\n                    val u = mp[Triple(i, j, k)]!!\n                    val v1 = mp[Triple(ni, j, k)]!!\n                    val v2 = mp[Triple(i, nj, k)]!!\n                    val v3 = mp[Triple(i, j, nk)]!!\n                    a[u][u]+= 23L\n                    a[u][v1]+= 1L\n                    a[u][v2]+= 1L\n                    a[u][v3]+= 1L\n                }\n            }\n        }\n        \n        return matExp(a, n)[0][m-1].toInt()\n    }\n}  \n```
['Dynamic Programming', 'Matrix', 'Kotlin']