Language: C++

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	l := scanInt()
	a := scanInt()
	b := scanInt()
	m = scanInt()

	ans := ImatrixInit(3)
	arr := []int{1, 0, 0, 1, 1, 0, 0, b % m, 1}
	mat := MatrixInit(3, 3, arr)
	for i := 0; i < 18; i++ {
		mat.arr[0] *= 10
		mat.arr[0] %= m
		idx1 := sort.Search(l-1, func(idx int) bool {
			num := len(strconv.Itoa(a + b*(idx+1)))
			return i+1 <= num
		})
		idx2 := sort.Search(l-1, func(idx int) bool {
			num := len(strconv.Itoa(a + b*(idx+1)))
			return i+2 <= num
		})
		num := idx2 - idx1
		ans = MulMatrix(ans, PowMatrix(mat, num))
	}
	c := MatrixInit(1, 3, []int{a % m, (a + b) % m, 1})
	ans = MulMatrix(c, ans)
	fmt.Fprintln(wr, ans.At(0, 0))
}

var m int

// Matrix type
type Matrix struct {
	arr      []int
	row, col int
}

// MatrixInit function
func MatrixInit(row, col int, a []int) Matrix {
	arr := make([]int, row*col)
	copy(arr, a)
	res := Matrix{arr, row, col}
	return res
}

// ImatrixInit function
func ImatrixInit(n int) Matrix {
	arr := make([]int, n*n)
	for i := 0; i < n; i++ {
		arr[i+i*n] = 1
	}
	res := Matrix{arr, n, n}
	return res
}

// At function for Matrix
func (mat Matrix) At(i, j int) int {
	return mat.arr[i*mat.col+j]
}

// AddMatrix function
func AddMatrix(a, b Matrix) Matrix {
	if a.row != b.row || a.col != b.col {
		return Matrix{}
	}
	for i := 0; i < a.row*a.col; i++ {
		a.arr[i] += b.arr[i]
	}
	return a
}

// SubMatrix function
func SubMatrix(a, b Matrix) Matrix {
	if a.row != b.row || a.col != b.col {
		return Matrix{}
	}
	for i := 0; i < a.row*a.col; i++ {
		a.arr[i] -= b.arr[i]
	}
	return a
}

// MulMatrix function
func MulMatrix(a, b Matrix) Matrix {
	if a.col != b.row {
		return Matrix{}
	}
	res := MatrixInit(a.row, b.col, nil)
	for i := 0; i < res.row; i++ {
		for j := 0; j < res.col; j++ {
			for k := 0; k < a.col; k++ {
				res.arr[i*res.col+j] += (a.arr[i*a.col+k] * b.arr[k*b.col+j]) % m
				res.arr[i*res.col+j] %= m
			}
		}
	}
	return res
}

// PowMatrix function
func PowMatrix(a Matrix, n int) Matrix {
	if a.row != a.col {
		return Matrix{}
	}
	res := ImatrixInit(a.row)
	for n > 0 {
		if n&1 == 1 {
			res = MulMatrix(res, a)
		}
		a = MulMatrix(a, a)
		n >>= 1
	}
	return res
}


Compiler output:
a.cc:1:1: error: 'package' does not name a type
    1 | package main
      | ^~~~~~~
a.cc:14:1: error: 'func' does not name a type
   14 | func scanRunes() []rune    { return []rune(scanString()) }
      | ^~~~
a.cc:15:1: error: 'func' does not name a type
   15 | func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
      | ^~~~
a.cc:16:1: error: 'func' does not name a type
   16 | func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
      | ^~~~
a.cc:17:1: error: 'func' does not name a type
   17 | func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }
      | ^~~~
a.cc:19:1: error: 'func' does not name a type
   19 | func scanInts(n int) []int {
      | ^~~~
a.cc:27:1: error: 'func' does not name a type
   27 | func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }
      | ^~~~
a.cc:27:28: error: expected unqualified-id before ')' token
   27 | func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }
      |                            ^
a.cc:29:1: error: 'func' does not name a type
   29 | func abs(a int) int {
      | ^~~~
a.cc:35:1: error: 'func' does not name a type
   35 | func min(a, b int) int {
      | ^~~~
a.cc:41:1: error: 'func' does not name a type
   41 | func max(a, b int) int {
      | ^~~~
a.cc:49:1: error: 'func' does not name a type
   49 | func main() {
      | ^~~~
a.cc:81:1: error: 'var' does not name a type
   81 | var m int
      | ^~~
a.cc:90:1: error: 'func' does not name a type
   90 | func MatrixInit(row, col int, a []int) Matrix {
      | ^~~~
a.cc:98:1: error: 'func' does not name a type
   98 | func ImatrixInit(n int) Matrix {
      | ^~~~
a.cc:108:6: error: expected constructor, destructor, or type conversion before '(' token
  108 | func (mat Matrix) At(i, j int) int {
      |      ^
a.cc:113:1: error: 'func' does not name a type
  113 | func AddMatrix(a, b Matrix) Matrix {
      | ^~~~
a.cc:124:1: error: 'func' does not name a type
  124 | func SubMatrix(a, b Matrix) Matrix {
      | ^~~~
a.cc:135:1: error: 'func' does not name a type
  135 | func MulMatrix(a, b Matrix) Matrix {
      | ^~~~
a.cc:152:1: error: 'func' does not name a type
  152 | func PowMatrix(a Matrix, n int) Matrix {
      | ^~~~