You are given an array $$$a$$$ of $$$n$$$ elements. Your can perform the following operation no more than $$$n$$$ times: Select three indices $$$x,y,z$$$ $$$(1 \leq x < y < z \leq n)$$$ and replace $$$a_x$$$ with $$$a_y - a_z$$$. After the operation, $$$|a_x|$$$ need to be less than $$$10^{18}$$$.Your goal is to make the resulting array non-decreasing. If there are multiple solutions, you can output any. If it is impossible to achieve, you should report it as well.

Each test contains multiple test cases. The first line will contain a single integer $$$t$$$ $$$(1 \leq t \leq 10000)$$$ — the number of test cases. Then $$$t$$$ test cases follow. The first line of each test case contains a single integer $$$n$$$ $$$(3 \leq n \leq 2 \cdot 10^5)$$$ — the size of the array $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots ,a_n$$$ $$$(-10^9 \leq a_i \leq 10^9)$$$, the elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, print $$$-1$$$ in a single line if there is no solution. Otherwise in the first line you should print a single integer $$$m$$$ $$$(0 \leq m \leq n)$$$ — number of operations you performed. Then the $$$i$$$-th of the following $$$m$$$ lines should contain three integers $$$x,y,z$$$ $$$(1 \leq x < y < z \leq n)$$$— description of the $$$i$$$-th operation. If there are multiple solutions, you can output any. Note that you don't have to minimize the number of operations in this task.

NoteIn the first example, the array becomes $$$[-6,-4,2,-1,2]$$$ after the first operation,$$$[-6,-4,-3,-1,2]$$$ after the second operation.In the second example, it is impossible to make the array sorted after any sequence of operations.In the third example, the array is already sorted, so we don't need to perform any operations.

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

func main() {
	CF1635C(os.Stdin, os.Stdout)
}

//推导：a(n-1) <= a(n)
func CF1635C(_r io.Reader, _w io.Writer) {
	in, out := bufio.NewReader(_r), bufio.NewWriter(_w)
	defer out.Flush()
	c, n := 0, 0
	fmt.Fscan(in, &c)
	for ; c > 0; c-- {
		fmt.Fscan(in, &n)
		arr := make([]int64, n)
		for i := range arr {
			fmt.Fscan(in, &arr[i])
		}
		//如果a[n-1] > a[n]直接不成立，因为没有元素可以替换
		if arr[n-2] > arr[n-1] {
			fmt.Fprintln(out, -1)
		} else if arr[n-1] < 0 { //如果a[n] < 0必须原数组就合法，否则还是无解
			for i := 0; i < n-1; i++ {
				if arr[i] > arr[i+1] {
					fmt.Fprintln(out, -1)
					break
				} else if i == n-2 {
					fmt.Fprintln(out, 0)
				}
			}
		} else if arr[n-1] >= 0 {
			fmt.Fprintln(out, n-2)
			for i := 1; i < n-1; i++ {
				fmt.Fprintln(out, i, "", n-1, "", n)
			}
		}
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T int
	fmt.Fscan(in, &T)

	for t := 0; t < T; t++ {
		var n int
		fmt.Fscan(in, &n)

		arr := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
		}

		if sort.IntsAreSorted(arr) {
			fmt.Fprintln(out, 0)
		} else if arr[n-2] > arr[n-1] || arr[n-2]-arr[n-1] > arr[n-2] {
			fmt.Fprintln(out, -1)
		} else {
			d := arr[n-2] - arr[n-1]
			s := []int{}
			for i := 0; i < n-2; i++ {
				if arr[i] != d {
					s = append(s, i)
				}
			}

			fmt.Fprintln(out, len(s))
			for _, v := range s {
				fmt.Fprintf(out, "%d %d %d\n", v+1, n-1, n)
			}
		}
	}
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

func CF1635C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var t, n int
	arr := make([]int64, 2e5+10)
	ans := make([][3]int, 10010)
Outer:
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n)
		for i := 1; i <= n; i++ {
			Fscan(in, &arr[i])
		}
		if arr[n-1] > arr[n] {
			Fprintln(out, -1)
			continue Outer
		}
		if arr[n] < 0 {
			for i := 2; i <= n; i++ {
				if arr[i] < arr[i-1] {
					Fprintln(out, -1)
					continue Outer
				}
			}
			Fprintln(out, 0)
			continue Outer
		}
		if arr[n] == 0 {
			Fprintln(out, n-2)
			for i := 1; i <= n-2; i++ {
				Fprintf(out, "%d %d %d\n", i, n-1, n)
			}
			continue Outer
		}
		a := arr[n]
		ans = ans[:0]
		times := 0
		for i := n - 2; i >= 1; i-- {
			if arr[i] > arr[i+1] {
				arr[i] = arr[i+1] - a
				times++
				ans = append(ans, [3]int{i, i + 1, n})
			}
		}
		Fprintln(out, times)
		for _, v := range ans {
			Fprintf(out, "%d %d %d\n", v[0], v[1], v[2])
		}
	}
}

func main() {
	// out := bufio.NewWriter(os.Stdout)
	// Fprintf(out, "%d %d %d\n", 0, 1, 2)
	// out.Flush()
	CF1635C(os.Stdin, os.Stdout)
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

func CF1635C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var t, n int
	arr := make([]int, 2e5+10)
	// ans := make([][3]int, 10010)
Outer:
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n)
		for i := 1; i <= n; i++ {
			Fscan(in, &arr[i])
		}
		if arr[n-1] > arr[n] {
			Fprintln(out, -1)
			continue Outer
		}
		if arr[n] < 0 {
			for i := 2; i <= n; i++ {
				if arr[i] < arr[i-1] {
					Fprintln(out, -1)
					continue Outer
				}
			}
			Fprintln(out, 0)
			continue Outer
		}
		// if arr[n] == 0 {
		Fprintln(out, n-2)
		for i := 1; i <= n-2; i++ {
			Fprintf(out, "%d %d %d\n", i, n-1, n)
		}
		// continue Outer
		// }
		// a := arr[n]
		// ans = ans[:0]
		// times := 0
		// for i := n - 2; i >= 1; i-- {
		//     if arr[i] > arr[i+1] {
		//         arr[i] = arr[i+1] - a
		//         times++
		//         ans = append(ans, [3]int{i, i + 1, n})
		//     }
		// }
		// Fprintln(out, times)
		// for _, v := range ans {
		//     Fprintf(out, "%d %d %d\n", v[0], v[1], v[2])
		// }
	}
}

func main() {
	// out := bufio.NewWriter(os.Stdout)
	// Fprintf(out, "%d %d %d\n", 0, 1, 2)
	// out.Flush()
	CF1635C(os.Stdin, os.Stdout)
}

//nolint
package main

import (
	"bufio"
	"fmt"
	"os"
)

//{
var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func print(a ...interface{})            { fmt.Fprint(writer, a...) }
func println(a ...interface{})          { fmt.Fprintln(writer, a...) }
func scan(a ...interface{})             { fmt.Fscan(reader, a...) }

func main() {
	defer writer.Flush()

	Main()
}

//}

var a = make([]int, 200_005)

func Main() {
	var t int
	scan(&t)
	for ; t > 0; t-- {
		Solve()
	}
}

func Solve() {
	var n int
	scan(&n)
	for i := 0; i < n; i++ {
		scan(&a[i])
	}
	if a[n-2] > a[n-1] {
		println(-1)
		return
	}
	if a[n-1] >= 0 {
		println(n - 2)
		for i := 0; i < n-2; i++ {
			println(i+1, n-1, n)
		}
		return
	}
	isAsc := true
	for i := 1; i < n; i++ {
		if a[i] < a[i-1] {
			isAsc = false
			break
		}
	}
	if isAsc {
		println(0)
	} else {
		println(-1)
	}

}

/*
https://codeforces.com/contest/1635/problem/C
*/

package main

import (
	//"bytes"
	"bufio"
	"fmt"
	//"math"
	"os"
	"strconv"
	"strings"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\n')
	line_arr := strings.Fields(line)
	T, _ := strconv.Atoi(line_arr[0])
	for t := 0; t<T; t++ {
		line, _ = reader.ReadString('\n')
		line_arr = strings.Fields(line)
		N, _ := strconv.Atoi(line_arr[0])
		arr := make([]int, N)
		line, _ = reader.ReadString('\n')
		line_arr = strings.Fields(line)
		for i:=0; i<N; i++ {
			arr[i], _ = strconv.Atoi(line_arr[i])
		}
		// fmt.Println("arr:", arr)

		y := arr[N-2]
		z := arr[N-1]

		if z >= 0 {
			// positive last value is treated differently
			// left one should be same or less
			// then we can anyway do the operations if not needed
			// UPDATE: since 0 case is similar to positive case including it here
			if y > z {
				fmt.Println(-1)
				continue
			} else {
				fmt.Println(N-2)
				for i:= N-3; i>=0; i-- {
					fmt.Println(i+1, i+2, N)
				}
			}
		} else {
			// For last 0 or negative value
			// it simply has to be non decreasing already else -1
			decreasing := false
			for i:=N-2; i>=0; i-- {
				if arr[i] > arr[i+1] {
					fmt.Println(-1)
					decreasing = true
					break
				}
			}

			if !decreasing {
				fmt.Println(0)
			}
		}
	}
	/*
	m, _ := strconv.Atoi(line1_arr[1])
	// fmt.Println("T:", T)
	arr := make([][]int, n)
	//used := make([][]int, n)
	for i := 0; i < n; i++ {
		arr[i] = make([]int, m)
		//used[i] = make([]int, m)
		line2, _ := reader.ReadString('\n')
		line2_arr := strings.Fields(line2)
		for j := 0; j < m; j++ {
			arr[i][j], _ = strconv.Atoi(line2_arr[j])
		}
	}
	*/
	//fmt.Println("arr:", arr)

}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)

	for ii := 0; ii < t; ii++ {
		var n int
		fmt.Fscan(in, &n)
		nums := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &nums[i])
		}
		i := n - 2
		max := n - 1
		choose := []int{n - 2, n - 1}
		for ; i >= 0; i-- {
			if nums[i]-nums[max] < nums[choose[0]]-nums[choose[1]] {
				choose = []int{i, max}
			}
			if nums[max] < nums[i] {
				max = i
			}
			if nums[i] > nums[i+1] {
				break
			}
		}
		if i == -1 {
			fmt.Fprintln(out, 0)
			continue
		}
		if i == n-2 || nums[choose[0]]-nums[choose[1]] > nums[i+1] {
			fmt.Fprintln(out, -1)
			continue
		}

		fmt.Fprintln(out, i+1)
		for j := 0; j < i+1; j++ {
			fmt.Fprintln(out, j+1, choose[0]+1, choose[1]+1)
		}
	}
}

// 1 0 1 2

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i ++ {
		var n int
		fmt.Fscan(in, &n)
		arr := make([]int, 0, n)
		for j := 0; j < n; j ++ {
			var num int
			fmt.Fscan(in, &num)
			arr = append(arr, num)
		}
		if arr[n-2] > arr[n-1] {
			fmt.Fprintln(out, -1)
			continue
		}
		if sort.IsSorted(sort.IntSlice(arr)) {
			fmt.Fprintln(out, 0)
			continue
		}
		if arr[n-1] < 0 {
			fmt.Fprintln(out, -1)
			continue
		}
		fmt.Fprintln(out, n-2)
		for j := 1; j < n-1; j ++ {
			fmt.Fprintln(out, j, n-1, n)
		}
	}
}

package main

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

/*
2
5
3 2 5 1 5
4
2 -5 -1 4
---
3		-4 -4 -4 1 5
1 4 5
2 4 5
3 4 5
2
1 3 4
2 3 4
=======
4
3
1 0 1
3
-1 0 1
4
-3 2 5 4
4
-3 2 5 9
---
1
1 2 3
0
-1
0
=======
1
6
1 5 6 4 3 -5
---
-1

*/

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	t := 1
	scanf("%d\n", &t)

	for ; t > 0; t-- {
		var n int
		scanf("%d\n", &n)

		a := make([]int64, n)

		for i := range a {
			scanf("%d", &a[i])
		}
		scanf("\n")

		diff := a[n-2] - a[n-1]

		sortFunc := func(i, j int) bool {
			return a[i] < a[j]
		}

		if sort.SliceIsSorted(a, sortFunc) {
			fmt.Fprintln(writer, 0)
		} else if a[n-1] < a[n-2] || a[n-2] < diff {
			fmt.Fprintln(writer, -1)
		} else {
			fmt.Fprintln(writer, n-2)
			for i := 0; i < n-2; i++ {
				fmt.Fprintf(writer, "%d %d %d\n", i+1, n-1, n)
			}
		}
	}
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func reversed(s string) string {
	input := []rune(s)
	li := len(input)
	ret := make([]rune, li)
	for i, r := range input {
		ret[li-i-1] = r
	}
	return string(ret)
}

//goland:noinspection GoUnusedFunction
func divCeil(num, div int) int {
	quot := num / div
	if num%div != 0 {
		quot++
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	minimum := nums[0]
	for _, num := range nums {
		if num < minimum {
			minimum = num
		}
	}
	return minimum
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) (max, idx int) {
	for i, num := range nums {
		if num > nums[idx] {
			idx = i
		}
	}

	return nums[idx], idx
}

//goland:noinspection GoUnusedFunction
func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

//goland:noinspection GoUnusedFunction
func isPrime(num int) bool {
	if num == 2 || num == 3 {
		return true
	}

	if num <= 1 || num%2 == 0 || num%3 == 0 {
		return false
	}

	for i := 5; i*i <= num; i += 6 {
		if num%i == 0 || num%(i+2) == 0 {
			return false
		}
	}

	return true
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	if num == 0 {
		return 0
	}

	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(in, &n)
		isInc := true
		var curr int
		var prev int
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &curr)
			if j > 0 && prev > curr {
				isInc = false
			}
			if j < n-1 {
				prev = curr
			}
		}
		if isInc {
			fmt.Println(0)
		} else if curr < 0 || prev > curr {
			fmt.Println(-1)
		} else {
			fmt.Println(n - 2)
			for j := n - 2; j > 0; j-- {
				fmt.Println(j, j+1, n)
			}
		}
	}
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func CF772(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var t int
	Fscan(in, &t)
	var solve func()
	solve = func() {

		var n int
		Fscan(in, &n)
		a := make([]int, n)
		flag := true
		for j := 0; j < n; j++ {
			Fscan(in, &a[j])
			if j != 0 && a[j-1] > a[j] {
				flag = false
			}
		}
		if flag {
			Fprintln(out, 0)
			return
		}
		if a[n-2] > a[n-1] {
			Fprintln(out, -1)
			return
		}
		if a[n-1] >= 0 {
			Fprintln(out, n-2)
			for i := 0; i < n-2; i++ {
				Fprintln(out, i+1, n-1, n)
			}
		} else {
			Fprintln(out, -1)
			return
		}
	}
	for i := 0; i < t; i++ {
		solve()
	}

}

func main() { CF772(os.Stdin, os.Stdout) }

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

func main() {
	CF1635C(os.Stdin, os.Stdout)
}

//推导：a(n-1) <= a(n)
func CF1635C(_r io.Reader, _w io.Writer) {
	in, out := bufio.NewReader(_r), bufio.NewWriter(_w)
	defer out.Flush()
	c, n := 0, 0
	fmt.Fscan(in, &c)
	for ; c > 0; c-- {
		fmt.Fscan(in, &n)
		arr := make([]int64, n)
		for i := range arr {
			fmt.Fscan(in, &arr[i])
		}
		//如果a[n-1] > a[n]直接不成立，因为没有元素可以替换
		if arr[n-2] > arr[n-1] {
			fmt.Fprintln(out, -1)
		} else if arr[n-1] < 0 { //如果a[n] < 0必须原数组就合法，否则还是无解
			for i := 0; i < n-1; i++ {
				if arr[i] < arr[i+1] {
					fmt.Fprintln(out, -1)
					break
				} else if  i == n-2 {
					fmt.Fprintln(out, 0)
				}
			}
		} else if arr[n-1] >= 0 {
			fmt.Fprintln(out, n-2)
			for i := 1; i < n-1; i++ {
				fmt.Fprintln(out, i, "", n-1, "", n)
			}
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

func main() {
	CF1635C(os.Stdin, os.Stdout)
}

//推导：a(n-1) <= a(n)
func CF1635C(_r io.Reader, _w io.Writer) {
	in, out := bufio.NewReader(_r), bufio.NewWriter(_w)
	defer out.Flush()
	c, n := 0, 0
	fmt.Fscan(in, &c)
	for ; c > 0; c-- {
		fmt.Fscan(in, &n)
		arr := make([]int64, n)
		for i := range arr {
			fmt.Fscan(in, &arr[i])
		}
		//如果a[n-1] > a[n]直接不成立，因为没有元素可以替换
		if arr[n-2] > arr[n-1] {
			fmt.Fprintln(out, -1)
		} else if arr[n-1] < 0 { //如果a[n] < 0必须原数组就合法，否则还是无解
			for i := n - 1; i > 0; i-- {
				if arr[i-1] > arr[i] {
					fmt.Fprintln(out, -1)
					break
				}
			}
			fmt.Fprintln(out, 0)
		} else if arr[n-1] >= 0 {
			fmt.Fprintln(out, n-2)
			for i := 1; i < n-1; i++ {
				fmt.Fprintln(out, i, "", n-1, "", n)
			}
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

func main() {
	CF1635C(os.Stdin, os.Stdout)
}

//推导：a(n-1) <= a(n).
func CF1635C(_r io.Reader, _w io.Writer) {
	in, out := bufio.NewReader(_r), bufio.NewWriter(_w)
	defer out.Flush()
	c, n := 0, 0
	fmt.Fscan(in, &c)
	for ; c > 0; c-- {
		fmt.Fscan(in, &n)
		arr := make([]int64, n)
		for i := range arr {
			fmt.Fscan(in, &arr[i])
		}
		//如果a[n-1] > a[n]直接不成立，因为没有元素可以替换
		if arr[n-2] > arr[n-1] {
			fmt.Fprintln(out, -1)
		} else if arr[n-1] < 0 { //如果a[n] < 0必须原数组就合法，否则还是无解
			for i := n - 1; i > 0; i-- {
				if arr[i-1] > arr[i] {
					fmt.Fprintln(out, -1)
					break
				}
			}
			fmt.Fprintln(out, 0)
		} else if arr[n-1] >= 0 {
			fmt.Fprintln(out, n-2)
			for i := 0; i < n-2; i++ {
				fmt.Fprintln(out, i+1, "", n-1, "", n)
			}
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

func main() {
	CF1635C(os.Stdin, os.Stdout)
}

//推导：a(n-1) <= a(n)
func CF1635C(_r io.Reader, _w io.Writer) {
	in, out := bufio.NewReader(_r), bufio.NewWriter(_w)
	defer out.Flush()
	c, n := 0, 0
	fmt.Fscan(in, &c)
	for ; c > 0; c-- {
		fmt.Fscan(in, &n)
		arr := make([]int64, n)
		for i := range arr {
			fmt.Fscan(in, &arr[i])
		}
		//如果a[n-1] > a[n]直接不成立，因为没有元素可以替换
		if arr[n-2] > arr[n-1] {
			fmt.Fprintln(out, -1)
		} else if arr[n-1] < 0 { //如果a[n] < 0必须原数组就合法，否则还是无解
			for i := n - 1; i > 0; i-- {
				if arr[i-1] > arr[i] {
					fmt.Fprintln(out, -1)
					break
				}
			}
			fmt.Fprintln(out, 0)
		} else if arr[n-1] >= 0 {
			fmt.Fprintln(out, n-2)
			for i := 0; i < n-1; i++ {
				fmt.Fprintln(out, i+1, "", n-1, "", n)
			}
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

func main() {
	CF1635C(os.Stdin, os.Stdout)
}

//推导：a(n-1) <= a(n)
func CF1635C(_r io.Reader, _w io.Writer) {
	in, out := bufio.NewReader(_r), bufio.NewWriter(_w)
	defer out.Flush()
	c, n := 0, 0
	fmt.Fscan(in, &c)
	for ; c > 0; c-- {
		fmt.Fscan(in, &n)
		arr := make([]int64, n)
		for i := range arr {
			fmt.Fscan(in, &arr[i])
		}
		//如果a[n-1] > a[n]直接不成立，因为没有元素可以替换
		if arr[n-2] > arr[n-1] {
			fmt.Fprintln(out, -1)
		} else if arr[n-1] < 0 { //如果a[n] < 0必须原数组就合法，否则还是无解
			for i := n - 1; i > 0; i-- {
				if arr[i-1] > arr[i] {
					fmt.Fprintln(out, -1)
					break
				}
			}
			fmt.Fprintln(out, 0)
		} else if arr[n-1] >= 0 {
			fmt.Fprintln(out, n-2)
			for i := 0; i < n-2; i++ {
				fmt.Fprintln(out, i+1, "", n-1, "", n)
			}
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

func main() {
	CF1635C(os.Stdin, os.Stdout)
}

//推导：a(n-1) <= a(n)
func CF1635C(_r io.Reader, _w io.Writer) {
	in, out := bufio.NewReader(_r), bufio.NewWriter(_w)
	defer out.Flush()
	c, n := 0, 0
	fmt.Fscan(in, &c)
	for ; c > 0; c-- {
		fmt.Fscan(in, &n)
		arr := make([]int64, n)
		for i := range arr {
			fmt.Fscan(in, &arr[i])
		}
		ans := [][]int{}
		//如果a[n-1] > a[n]直接不成立，因为没有元素可以替换
		if arr[n-2] > arr[n-1] {
			fmt.Fprintln(out, -1)
		} else if arr[n-1] < 0 { //如果a[n] < 0必须原数组就合法，否则还是无解
			for i := n - 1; i > 0; i-- {
				if arr[i-1] > arr[i] {
					fmt.Fprintln(out, -1)
					break
				}
			}
			fmt.Fprintln(out, 0)
		} else if arr[n-1] >= 0 { //直接倒着来一遍
			for i := n - 1; i > 0; i-- {
				if arr[i-1] > arr[i] {
					ans = append(ans, []int{i, i + 1, n})
					arr[i-1] = arr[i] - arr[n-1]
				}
			}
			fmt.Fprintln(out, len(ans))
			for _, a := range ans {
				fmt.Fprintln(out, a[0], "", a[1], "", a[2])
			}
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

func main() {
	CF1635C(os.Stdin, os.Stdout)
}

//推导：a(n-1) <= a(n)
func CF1635C(_r io.Reader, _w io.Writer) {
	in, out := bufio.NewReader(_r), bufio.NewWriter(_w)
	defer out.Flush()
	c, n := 0, 0
	fmt.Fscan(in, &c)
	for ; c > 0; c-- {
		fmt.Fscan(in, &n)
		arr := make([]int64, n)
		for i := range arr {
			fmt.Fscan(in, &arr[i])
		}
		ans := [][]int{}
		//如果a[n-1] > a[n]直接不成立，因为没有元素可以替换
		if arr[n-2] > arr[n-1] {
			fmt.Fprintln(out, -1)
		} else if arr[n-1] < 0 { //如果a[n] < 0必须原数组就合法，否则还是无解
			for i := n - 1; i > 0; i-- {
				if arr[i-1] > arr[i] {
					fmt.Fprintln(out, -1)
					break
				}
			}
			fmt.Fprintln(out, 0)
		} else if arr[n-1] >= 0 { //直接倒着来一遍
			for i := n - 1; i > 0; i-- {
				if arr[i-1] > arr[i] {
					ans = append(ans, []int{i, i + 1, n})
					arr[i-1] = arr[i] - arr[n-1]
				}
			}
			fmt.Fprintln(out, len(ans))
			for _, a := range ans {
				fmt.Fprintln(out, a[0], " ", a[1], " ", a[2])
			}
		}
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T int
	fmt.Fscan(in, &T)

	for t := 0; t < T; t++ {
		var n int
		fmt.Fscan(in, &n)

		arr := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
		}

		if arr[n-2] > arr[n-1] {
			fmt.Fprintln(out, -1)
		} else if sort.IntsAreSorted(arr) {
			fmt.Fprintln(out, 0)
		} else {
			d := arr[n-2] - arr[n-1]
			s := []int{}
			for i := 0; i < n-2; i++ {
				if arr[i] != d {
					s = append(s, i)
				}
			}

			fmt.Fprintln(out, len(s))
			for _, v := range s {
				fmt.Fprintf(out, "%d %d %d\n", v+1, n-1, n)
			}
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T int
	fmt.Fscan(in, &T)

	for t := 0; t < T; t++ {
		var n int
		fmt.Fscan(in, &n)

		arr := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
		}

		if arr[n-2] > arr[n-1] {
			fmt.Fprintln(out, -1)
		} else {
			d := arr[n-2] - arr[n-1]
			s := []int{}
			for i := 0; i < n-2; i++ {
				if arr[i] != d {
					s = append(s, i)
				}
			}

			fmt.Fprintln(out, len(s))
			for _, v := range s {
				fmt.Fprintf(out, "%d %d %d\n", v+1, n-1, n)
			}
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T int
	fmt.Fscan(in, &T)

	for t := 0; t < T; t++ {
		var n int
		fmt.Fscan(in, &n)

		arr := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
		}

		if arr[n-2] > arr[n-1] {
			fmt.Fprintln(out, -1)
		} else {
			d := arr[n-2] - arr[n-1]
			s := [][]int{}
			for i := n - 3; i >= 0; i-- {
				if arr[i] > d {
					arr[i] = d
					d = arr[i] - arr[n-1]
					s = append(s, []int{i + 1, n - 1, n})
				}
			}

			fmt.Fprintln(out, len(s))
			for _, v := range s {
				fmt.Fprintf(out, "%d %d %d\n", v[0], v[1], v[2])
			}
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T int
	fmt.Fscan(in, &T)

	for t := 0; t < T; t++ {
		var n int
		fmt.Fscan(in, &n)

		arr := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
		}

		if arr[n-2] > arr[n-1] {
			fmt.Fprintln(out, -1)
		} else {
			p := n - 2
			d := arr[p] - arr[n-1]
			s := [][]int{}
			for i := n - 3; i >= 0; i-- {
				if arr[i] > d {
					arr[i] = d
					d = arr[i] - arr[n-1]
					s = append(s, []int{i + 1, p + 1, n})
					p = i
				}
			}

			fmt.Fprintln(out, len(s))
			for _, v := range s {
				fmt.Fprintf(out, "%d %d %d\n", v[0], v[1], v[2])
			}
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T int
	fmt.Fscan(in, &T)

	for t := 0; t < T; t++ {
		var n int
		fmt.Fscan(in, &n)

		arr := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
		}

		mins := make([]int, n)
		maxes := make([]int, n)
		min := n - 1
		max := n - 1
		mins[n-1] = min
		maxes[n-1] = max
		for i := n - 2; i >= 0; i-- {
			if arr[i] < arr[min] {
				min = i
			}
			if arr[i] > arr[max] {
				max = i
			}
			mins[i] = min
			maxes[i] = max
		}

		// fmt.Println(mins)
		// fmt.Println(maxes)

		s := [][]int{}
		f := true
		for i := 0; i < n-1; i++ {
			if arr[i] > arr[i+1] {
				if i == n-2 || arr[mins[i+1]]-arr[maxes[i+1]] > arr[i+1] {
					f = false
					break
				}

				s = append(s, []int{i + 1, mins[i+1] + 1, maxes[i+1] + 1})
			}
		}

		if !f {
			fmt.Fprintln(out, -1)
		} else {
			fmt.Fprintln(out, len(s))
			for _, v := range s {
				fmt.Fprintf(out, "%d %d %d\n", v[0], v[1], v[2])
			}
		}
	}
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

func CF1635C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var t, n int
	arr := make([]int, 2e5+10)
	ans := make([][3]int, 10010)
Outer:
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n)
		for i := 1; i <= n; i++ {
			Fscan(in, &arr[i])
		}
		if arr[n-1] > arr[n] {
			Fprintln(out, -1)
			continue Outer
		}
		if arr[n] < 0 {
			for i := 2; i <= n; i++ {
				if arr[i] < arr[i-1] {
					Fprintln(out, -1)
					continue Outer
				}
			}
			Fprintln(out, 0)
			continue Outer
		}
		if arr[n] == 0 {
			Fprintln(out, n-2)
			for i := 1; i <= n-2; i++ {
				Fprintf(out, "%d %d %d\n", i, n-1, n)
			}
			continue Outer
		}
		a := arr[n]
		ans = ans[:0]
		times := 0
		for i := n - 2; i >= 1; i-- {
			if arr[i] > arr[i+1] {
				arr[i] = arr[i+1] - a
				times++
				ans = append(ans, [3]int{i, i + 1, n})
			}
		}
		Fprintln(out, times)
		for _, v := range ans {
			Fprintf(out, "%d %d %d\n", v[0], v[1], v[2])
		}

	}
}

func main() {
	// out := bufio.NewWriter(os.Stdout)
	// Fprintf(out, "%d %d %d\n", 0, 1, 2)
	// out.Flush()
	CF1635C(os.Stdin, os.Stdout)
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

func CF1635C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	var t, n int
	arr := make([]int, 2e5+10)
	ans := make([][3]int, 10010)
Outer:
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n)
		for i := 1; i <= n; i++ {
			Fscan(in, &arr[i])
		}
		if arr[n-1] > arr[n] {
			Fprintln(out, -1)
			continue Outer
		}
		if arr[n] <= 0 {
			for i := 2; i <= n; i++ {
				if arr[i] < arr[i-1] {
					Fprintln(out, -1)
					continue Outer
				}
			}
			Fprintln(out, 0)
			continue Outer
		}
		a := arr[n]
		ans = ans[:0]
		times := 0
		for i := n - 2; i >= 1; i-- {
			if arr[i] > arr[i+1] {
				arr[i] = arr[i+1] - a
				times++
				ans = append(ans, [3]int{i, i + 1, n})
			}
		}
		Fprintln(out, times)
		for _, v := range ans {
			Fprintf(out, "%d %d %d\n", v[0], v[1], v[2])
		}

	}
}

func main() {
	// out := bufio.NewWriter(os.Stdout)
	// Fprintf(out, "%d %d %d\n", 0, 1, 2)
	// out.Flush()
	CF1635C(os.Stdin, os.Stdout)
}

//nolint
package main

import (
	"bufio"
	"fmt"
	"os"
)

//{
var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func print(a ...interface{})            { fmt.Fprint(writer, a...) }
func println(a ...interface{})          { fmt.Fprintln(writer, a...) }
func scan(a ...interface{})             { fmt.Fscan(reader, a...) }

func main() {
	defer writer.Flush()

	Main()
}

//}

var a = make([]int, 200_005)

func Main() {
	var t int
	scan(&t)
	for ; t > 0; t-- {
		Solve()
	}
}

func Solve() {
	var n int
	scan(&n)
	for i := 0; i < n; i++ {
		scan(&a[i])
	}
	if a[n-2] > a[n-1] {
		println(-1)
		return
	}
	if a[n-1] >= 0 {
		println(n - 2)
		for i := 0; i < n-2; i++ {
			println(i+1, n-2, n-1)
		}
		return
	}
	isAsc := true
	for i := 1; i < n; i++ {
		if a[i] < a[i-1] {
			isAsc = false
			break
		}
	}
	if isAsc {
		println(0)
	} else {
		println(-1)
	}

}

//nolint
package main

import (
	"bufio"
	"fmt"
	"os"
)

//{
var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func print(a ...interface{})            { fmt.Fprint(writer, a...) }
func println(a ...interface{})          { fmt.Fprintln(writer, a...) }
func scan(a ...interface{})             { fmt.Fscan(reader, a...) }

func main() {
	defer writer.Flush()

	Main()
}

//}

var a = make([]int, 200_005)

func Main() {
	var t int
	scan(&t)
	for ; t > 0; t-- {
		Solve()
	}
}

func Solve() {
	var n int
	scan(&n)
	for i := 0; i < n; i++ {
		scan(&a[i])
	}
	if a[n-2] > a[n-1] {
		println(-1)
		return
	}
	if a[n-1] >= 0 {
		println(n - 2)
		for i := 0; i < n-2; i++ {
			println(i+1, n-1, n-2)
		}
		return
	}
	isAsc := true
	for i := 1; i < n; i++ {
		if a[i] < a[i-1] {
			isAsc = false
			break
		}
	}
	if isAsc {
		println(0)
	} else {
		println(-1)
	}

}

//nolint
package main

import (
	"bufio"
	"fmt"
	"os"
)

//{
var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func print(a ...interface{})            { fmt.Fprint(writer, a...) }
func println(a ...interface{})          { fmt.Fprintln(writer, a...) }
func scan(a ...interface{})             { fmt.Fscan(reader, a...) }

func main() {
	defer writer.Flush()

	Main()
}

//}

var a = make([]int, 200_005)

func Main() {
	var t int
	scan(&t)
	for ; t > 0; t-- {
		Solve()
	}
}

func Solve() {
	var n int
	scan(&n)
	for i := 0; i < n; i++ {
		scan(&a[i])
	}
	if a[n-2] > a[n-1] {
		println(-1)
		return
	}
	if a[n-1] >= 0 {
		println(n - 2)
		for i := 0; i < n-2; i++ {
			println(i, n-2, n-1)
		}
		return
	}
	isAsc := true
	for i := 1; i < n; i++ {
		if a[i] < a[i-1] {
			isAsc = false
			break
		}
	}
	if isAsc {
		println(0)
	} else {
		println(-1)
	}

}

/*
https://codeforces.com/contest/1635/problem/C
*/

package main

import (
	//"bytes"
	"bufio"
	"fmt"
	//"math"
	"os"
	"strconv"
	"strings"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\n')
	line_arr := strings.Fields(line)
	T, _ := strconv.Atoi(line_arr[0])
	for t := 0; t<T; t++ {
		line, _ = reader.ReadString('\n')
		line_arr = strings.Fields(line)
		N, _ := strconv.Atoi(line_arr[0])
		arr := make([]int, N)
		line, _ = reader.ReadString('\n')
		line_arr = strings.Fields(line)
		for i:=0; i<N; i++ {
			arr[i], _ = strconv.Atoi(line_arr[i])
		}
		// fmt.Println("arr:", arr)

		y := arr[N-2]
		z := arr[N-1]

		if z >= 1 {
			// positive last value is treated differently
			// left one should be same or less
			// then we can anyway do the operations if not needed
			if y > z {
				fmt.Println(-1)
				continue
			} else {
				fmt.Println(N-2)
				for i:= N-3; i>=0; i-- {
					fmt.Println(i+1, i+2, N)
				}
			}
		} else {
			// For last 0 or negative value
			// it simply has to be non decreasing already else -1
			decreasing := false
			for i:=N-2; i>=0; i-- {
				if arr[i] > arr[i+1] {
					fmt.Println(-1)
					decreasing = true
					break
				}
			}

			if !decreasing {
				fmt.Println(0)
			}
		}
	}
	/*
	m, _ := strconv.Atoi(line1_arr[1])
	// fmt.Println("T:", T)
	arr := make([][]int, n)
	//used := make([][]int, n)
	for i := 0; i < n; i++ {
		arr[i] = make([]int, m)
		//used[i] = make([]int, m)
		line2, _ := reader.ReadString('\n')
		line2_arr := strings.Fields(line2)
		for j := 0; j < m; j++ {
			arr[i][j], _ = strconv.Atoi(line2_arr[j])
		}
	}
	*/
	//fmt.Println("arr:", arr)

}

/*
https://codeforces.com/contest/1635/problem/C
*/

package main

import (
	//"bytes"
	"bufio"
	"fmt"
	//"math"
	"os"
	"strconv"
	"strings"
)

func main() {
	reader := bufio.NewReader(os.Stdin)
	line, _ := reader.ReadString('\n')
	line_arr := strings.Fields(line)
	T, _ := strconv.Atoi(line_arr[0])
	for t := 0; t<T; t++ {
		line, _ = reader.ReadString('\n')
		line_arr = strings.Fields(line)
		N, _ := strconv.Atoi(line_arr[0])
		arr := make([]int, N)
		line, _ = reader.ReadString('\n')
		line_arr = strings.Fields(line)
		for i:=0; i<N; i++ {
			arr[i], _ = strconv.Atoi(line_arr[i])
		}
		// fmt.Println("arr:", arr)

		y := arr[N-2]
		z := arr[N-1]

		if z >= 1 {
			// positive last value is treated differently
			// left one should be same or less
			// then we can anyway do the operations if not needed
			if y > z {
				fmt.Println(-1)
				continue
			} else {
				fmt.Println(N-2)
				for i:= N-3; i>=0; i-- {
					fmt.Println(i+1, i+2, N)
				}
			}
		} else {
			// For last 0 or negative value
			// it simply has to be non decreasing already else -1
			decreasing := false
			for i:=N-2; i>=0; i-- {
				if arr[i] >= arr[i+1] {
					fmt.Println(-1)
					decreasing = true
					break
				}
			}

			if !decreasing {
				fmt.Println(0)
			}
		}
	}
	/*
	m, _ := strconv.Atoi(line1_arr[1])
	// fmt.Println("T:", T)
	arr := make([][]int, n)
	//used := make([][]int, n)
	for i := 0; i < n; i++ {
		arr[i] = make([]int, m)
		//used[i] = make([]int, m)
		line2, _ := reader.ReadString('\n')
		line2_arr := strings.Fields(line2)
		for j := 0; j < m; j++ {
			arr[i][j], _ = strconv.Atoi(line2_arr[j])
		}
	}
	*/
	//fmt.Println("arr:", arr)

}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in, out := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)

	for ii := 0; ii < t; ii++ {
		var n int
		fmt.Fscan(in, &n)
		nums := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &nums[i])
		}
		i := n - 2
		max := n - 1
		choose := []int{n - 1, n - 2}
		for ; i >= 0; i-- {
			if nums[i]-nums[max] < nums[choose[0]]-nums[choose[1]] {
				choose = []int{i, max}
			}
			if nums[max] < nums[i] {
				max = i
			}
			if nums[i] > nums[i+1] {
				break
			}
		}
		if i == -1 {
			fmt.Fprintln(out, 0)
			continue
		}
		if i == n-2 || nums[choose[0]]-nums[choose[1]] > nums[i+1] {
			fmt.Fprintln(out, -1)
			continue
		}

		fmt.Fprintln(out, i+1)
		for j := 0; j < i+1; j++ {
			fmt.Fprintln(out, j+1, choose[0]+1, choose[1]+1)
		}
	}
}

// 1 0 1 2

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i ++ {
		var n int
		fmt.Fscan(in, &n)
		arr := make([]int, n)
		for j := 0; j < n; j ++ {
			var num int
			fmt.Fscan(in, &num)
			arr = append(arr, num)
		}
		if arr[len(arr)-2] > arr[len(arr)-1] {
			fmt.Fprint(out, -1)
			continue
		}
		if sort.IsSorted(sort.IntSlice(arr)) {
			continue
		}
		fmt.Fprintln(out, n-2)
		for j := 0; j < n-2; j ++ {
			fmt.Fprintln(out, j, n-2, n-1)
		}
	}
}

package main

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

/*
1
5
3 2 5 1 5
---
-4 -4 -4 1 5

*/

//goland:noinspection GoUnhandledErrorResult
func main() {
	defer writer.Flush()

	t := 1
	scanf("%d\n", &t)

	for ; t > 0; t-- {
		var n int
		scanf("%d\n", &n)

		a := make([]int64, n)

		for i := range a {
			scanf("%d", &a[i])
		}
		scanf("\n")

		diff := a[n-1] - a[n-2]

		sortFunc := func(i, j int) bool {
			return a[i] < a[j]
		}

		if sort.SliceIsSorted(a, sortFunc) {
			fmt.Fprintln(writer, 0)
		} else if a[n-1] < a[n-2] || diff < a[n-2] {
			fmt.Fprintln(writer, -1)
		} else {
			fmt.Fprintln(writer, n-2)
			for i := 0; i < n-2; i++ {
				fmt.Fprintf(writer, "%d %d %d\n", i+1, n-1, n)
			}
		}
	}
}

const maxUint = ^uint(0)

//goland:noinspection GoUnusedConst
const minUint = 0
const maxInt = int(maxUint >> 1)

//goland:noinspection GoUnusedConst
const minInt = -maxInt - 1

var reader = bufio.NewReader(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

func scanf(f string, a ...interface{}) {
	if _, err := fmt.Fscanf(reader, f, a...); err != nil {
		panic(err)
	}
}

//goland:noinspection GoUnusedFunction
func reversed(s string) string {
	input := []rune(s)
	li := len(input)
	ret := make([]rune, li)
	for i, r := range input {
		ret[li-i-1] = r
	}
	return string(ret)
}

//goland:noinspection GoUnusedFunction
func divCeil(num, div int) int {
	quot := num / div
	if num%div != 0 {
		quot++
	}
	return quot
}

//goland:noinspection GoUnusedFunction
func min(nums ...int) int {
	minimum := nums[0]
	for _, num := range nums {
		if num < minimum {
			minimum = num
		}
	}
	return minimum
}

//goland:noinspection GoUnusedFunction
func max(nums ...int) (max, idx int) {
	for i, num := range nums {
		if num > nums[idx] {
			idx = i
		}
	}

	return nums[idx], idx
}

//goland:noinspection GoUnusedFunction
func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

//goland:noinspection GoUnusedFunction
func isPrime(num int) bool {
	if num == 2 || num == 3 {
		return true
	}

	if num <= 1 || num%2 == 0 || num%3 == 0 {
		return false
	}

	for i := 5; i*i <= num; i += 6 {
		if num%i == 0 || num%(i+2) == 0 {
			return false
		}
	}

	return true
}

//goland:noinspection GoUnusedFunction
func gcd(a, b int) int {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

//goland:noinspection GoUnusedFunction
func lcm(a, b int) int {
	return abs(a) / gcd(a, b) * abs(b)
}

// Examples:
//	digitAt(1234, -1) -> panic!
//	digitAt(1234, 0) -> 4
//	digitAt(1234, 1) -> 3
//	digitAt(1234, 2) -> 2
//	digitAt(1234, 3) -> 1
//	digitAt(1234, 4) -> panic!
//goland:noinspection GoUnusedFunction
func digitAt(num, pos int) int {
	if num == 0 {
		return 0
	}

	num = abs(num)

	lenNum := int(math.Log10(float64(num))) + 1
	if pos < 0 || pos >= lenNum {
		err := fmt.Sprintf("Out of bound access for digit. Position passed %d, number %d", pos, num)
		panic(err)
	}

	rem := num % int(math.Pow10(pos+1))
	return rem / int(math.Pow10(pos))
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(in, &n)
		isInc := true
		var curr int
		var prev int
		for j := 0; j < n; j++ {
			fmt.Fscan(in, &curr)
			if j > 0 && prev > curr {
				isInc = false
			}
			if j < n-1 {
				prev = curr
			}
		}
		if isInc {
			fmt.Println(0)
		} else if curr < 0 || prev > curr {
			fmt.Println(-1)
		} else {
			for j := n - 2; j > 0; j-- {
				fmt.Println(j, j+1, n)
			}
		}
	}
}


There is a long plate s containing n digits. Iahub wants to delete some digits (possibly none, but he is not allowed to delete all the digits) to form his "magic number" on the plate, a number that is divisible by 5. Note that, the resulting number may contain leading zeros.Now Iahub wants to count the number of ways he can obtain magic number, modulo 1000000007 (109 + 7). Two ways are different, if the set of deleted positions in s differs.Look at the input part of the statement, s is given in a special form.

In the first line you're given a string a (1 ≤ |a| ≤ 105), containing digits only. In the second line you're given an integer k (1 ≤ k ≤ 109). The plate s is formed by concatenating k copies of a together. That is n = |a|·k.

Print a single integer — the required number of ways modulo 1000000007 (109 + 7).

NoteIn the first case, there are four possible ways to make a number that is divisible by 5: 5, 15, 25 and 125.In the second case, remember to concatenate the copies of a. The actual plate is 1399013990.In the third case, except deleting all digits, any choice will do. Therefore there are 26 - 1 = 63 possible ways to delete digits.

package main

import (
	"bufio"
	"fmt"
	"os"
)

const mod = int(1e9) + 7
var s string
var k, n int

func pw(a int, b int) int {
	var ret = 1
	for b > 0 {
		if (b & 1) == 1 {
			b--
			ret = int(int64(ret) * int64(a) % int64(mod))
		} else {
			b /= 2
			a = int(int64(a) * int64(a) % int64(mod))
		}
	}
	return ret
}

func main() {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	fmt.Fscanf(reader, "%s\n", &s)
	fmt.Fscanf(reader, "%d\n", &k)

	var blockCnt = 1
	var n = len(s)

	for i := 0; i < n; i++ {
		blockCnt = int(int64(blockCnt) * 2 % int64(mod))
	}

	var sufCnt = 0
	var mul = 1

	for i := 0; i < n; i++ {
		if s[i] == '0' || s[i] == '5' {
			sufCnt += mul
			sufCnt %= mod
		}
		mul = int(int64(mul) * 2 % int64(mod))
	}

	var inv = int64(1)
	for i := 1; i <= n; i++ {
		inv = inv * 2 % int64(mod)
	}
	inv = (inv - 1) % int64(mod)
	if inv < 0 {
		inv += int64(mod)
	}

	inv = int64(pw(int(inv), mod - 2))

	var upper = pw(2, int(int64(n) * int64(k) % int64(mod - 1)))

	upper = (upper - 1) % mod
	if upper < 0 {
		upper += mod
	}

	var ret = int64(upper) * int64(inv) % int64(mod) * int64(sufCnt) % int64(mod)
	fmt.Fprintf(writer, "%d", ret)
}

package main

import (
  "bufio"
  "io"
  "os"
  "strconv"
)

type Scanner struct {
  r            io.Reader
  split        bufio.SplitFunc
  maxTokenSize int
  token        []byte
  buf          []byte
  start        int
  end          int
}

const MaxScanTokenSize = 16777216

func NewScanner(r io.Reader) *Scanner {
  return &Scanner{
    r:            r,
    split:        bufio.ScanWords,
    maxTokenSize: MaxScanTokenSize,
    buf:          make([]byte, 4096),
  }
}

func (s *Scanner) Text() string {
  return string(s.token)
}

func (s *Scanner) Scan() bool {
  for {
    if s.end > s.start {
      advance, token, err := s.split(s.buf[s.start:s.end], false)
      if err != nil || !s.advance(advance) {
        return false
      }
      s.token = token
      if token != nil {
        return true
      }
    }
    if s.start > 0 && (s.end == len(s.buf) || s.start > len(s.buf)/2) {
      copy(s.buf, s.buf[s.start:s.end])
      s.end -= s.start
      s.start = 0
    }
    if s.end == len(s.buf) {
      if len(s.buf) >= s.maxTokenSize {
        return false
      }
      newSize := len(s.buf) * 2
      if newSize > s.maxTokenSize {
        newSize = s.maxTokenSize
      }
      newBuf := make([]byte, newSize)
      copy(newBuf, s.buf[s.start:s.end])
      s.buf = newBuf
      s.end -= s.start
      s.start = 0
      continue
    }
    for loop := 0; ; {
      n, _ := s.r.Read(s.buf[s.end:len(s.buf)])
      s.end += n
      if n > 0 {
        break
      }
      loop++
      if loop > 100 {
        break
      }
    }
  }
}

func (s *Scanner) advance(n int) bool {
  if n < 0 || n > s.end-s.start {
    return false
  }
  s.start += n
  return true
}

func (s *Scanner) Split(split bufio.SplitFunc) {
  s.split = split
}

var w *bufio.Writer = bufio.NewWriter(os.Stdout)
var sc *Scanner = NewScanner(os.Stdin)

func next() string { sc.Scan(); return sc.Text() }

func ni32() int {
  sc.Scan()
  n, _ := strconv.Atoi(sc.Text())
  return n
}

func ni64() int64 {
  sc.Scan()
  n, _ := strconv.ParseInt(sc.Text(), 10, 64)
  return n
}

func pri32(i int)   { w.WriteString(strconv.Itoa(i)) }
func pri64(i int64) { w.WriteString(strconv.FormatInt(i, 10)) }
func sp()           { w.WriteByte(' ') }
func endl()         { w.WriteByte('\n') }

var mod int64 = 1000000007

func binpow(a, n int64) int64 {
  if n == 0 {
    return int64(1)
  }
  if n%int64(2) == 1 {
    return (a * binpow(a, n-1)) % mod
  } else {
    b := binpow(a, n/2)
    return (b * b) % mod
  }
}

func main() {
  s := next()
  k := ni32()
  l := len(s)
  q := binpow(2, int64(l))
  rq := q - 1
  if rq < 0 {
    rq += mod
  }
  rq = binpow(rq, mod-2)
  qn := binpow(q, int64(k)) - 1
  if qn < 0 {
    qn += mod
  }
  A := (qn * rq) % mod
  ans := int64(0)
  x := int64(1)
  for i := 0; i < l; i++ {
    if s[i] == '0' || s[i] == '5' {
      ans = (ans + (x*A)%mod) % mod
    }
    x *= 2
    if x >= mod {
      x -= mod
    }

  }
  pri64(ans)
  w.Flush()
}

package main

import (
  "bufio"
  "os"
  "strconv"
)

var rw *bufio.ReadWriter = bufio.NewReadWriter(bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout))

func next() string {
  token := []byte{}
  for {
    c, err := rw.ReadByte()
    if err != nil || c == ' ' || c == '\n' {
      return string(token)
    } else if c == '\r' {
    _, _ = rw.ReadByte()
      return string(token)
    } else {
      token = append(token, c)
    }
  }
}

func ni() int {
  ans, _ := strconv.Atoi(next())
  return ans
}

func nll() int64 {
  ans, _ := strconv.ParseInt(next(), 10, 64)
  return ans
}

func Max(i, j int) int {
  if i >= j {
    return i
  }
  return j
}

func Min(i, j int) int {
  if i < j {
    return i
  }
  return j
}

func pri(n int)    { rw.WriteString(strconv.Itoa(n)) }
func prll(n int64) { rw.WriteString(strconv.FormatInt(n, 10)) }
func sp()          { rw.WriteByte(' ') }
func endl()        { rw.WriteByte('\n') }

var mod int64 = 1000000007
var r []int64
var rroot int64

func binpow(a, n int64) int64 {
  if n == 0 {
    return int64(1)
  }
  if n%int64(2) == 1 {
    return (a * binpow(a, n-1)) % mod
  } else {
    b := binpow(a, n/2)
    return (b * b) % mod
  }
}

func main() {
  s := next()
  k := ni()
  l := len(s)
  q := binpow(2, int64(l))
  rq := q - 1
  if rq < 0 {
    rq += mod
  }
  rq = binpow(rq, mod-2)
  qn := binpow(q, int64(k)) - 1
  if qn < 0 {
    qn += mod
  }
  A := (qn * rq) % mod
  ans := int64(0)
  x := int64(1)
  for i := 0; i < l; i++ {
    if s[i] == '0' || s[i] == '5' {
      ans = (ans + (x*A)%mod) % mod
    }
    // prll(ans)
    // sp()
    x *= 2
    if x >= mod {
      x -= mod
    }

  }
  prll(ans)
  rw.Flush()
}

package main

import (
  "bufio"
  "io"
  "os"
  "strconv"
)

type Scanner struct {
  r            io.Reader
  split        bufio.SplitFunc
  maxTokenSize int
  token        []byte
  buf          []byte
  start        int
  end          int
}

const (
  MaxScanTokenSize = 64 * 1024 * 256
)

func NewScanner(r io.Reader) *Scanner {
  return &Scanner{
    r:            r,
    split:        bufio.ScanWords,
    maxTokenSize: MaxScanTokenSize,
    buf:          make([]byte, 4096),
  }
}

func (s *Scanner) Text() string {
  return string(s.token)
}

func (s *Scanner) Scan() bool {
  for {
    if s.end > s.start {
      advance, token, err := s.split(s.buf[s.start:s.end], false)
      if err != nil || !s.advance(advance) {
        return false
      }
      s.token = token
      if token != nil {
        return true
      }
    }
    if s.start > 0 && (s.end == len(s.buf) || s.start > len(s.buf)/2) {
      copy(s.buf, s.buf[s.start:s.end])
      s.end -= s.start
      s.start = 0
    }
    if s.end == len(s.buf) {
      if len(s.buf) >= s.maxTokenSize {
        return false
      }
      newSize := len(s.buf) * 2
      if newSize > s.maxTokenSize {
        newSize = s.maxTokenSize
      }
      newBuf := make([]byte, newSize)
      copy(newBuf, s.buf[s.start:s.end])
      s.buf = newBuf
      s.end -= s.start
      s.start = 0
      continue
    }
    for loop := 0; ; {
      n, _ := s.r.Read(s.buf[s.end:len(s.buf)])
      s.end += n
      if n > 0 {
        break
      }
      loop++
      if loop > 100 {
        break
      }
    }
  }
}

func (s *Scanner) advance(n int) bool {
  if n < 0 || n > s.end-s.start {
    return false
  }
  s.start += n
  return true
}

func (s *Scanner) Split(split bufio.SplitFunc) {
  s.split = split
}

var w *bufio.Writer = bufio.NewWriter(os.Stdout)
var sc *Scanner = NewScanner(os.Stdin)

func next() string { sc.Scan(); return sc.Text() }

func ni32() int {
  sc.Scan()
  n, _ := strconv.Atoi(sc.Text())
  return n
}

func ni64() int64 {
  sc.Scan()
  n, _ := strconv.ParseInt(sc.Text(), 10, 64)
  return n
}

func pri32(i int)   { w.WriteString(strconv.Itoa(i)) }
func pri64(i int64) { w.WriteString(strconv.FormatInt(i, 10)) }
func sp()           { w.WriteByte(' ') }
func endl()         { w.WriteByte('\n') }

var mod int64 = 1000000007

func binpow(a, n int64) int64 {
  if n == 0 {
    return int64(1)
  }
  if n%int64(2) == 1 {
    return (a * binpow(a, n-1)) % mod
  } else {
    b := binpow(a, n/2)
    return (b * b) % mod
  }
}

func dec(k int64) int64 {
  ans := k - 1
  if ans < 0 {
    ans += mod
  }
  return ans
}

func rroot(k int64) int64 {
  return binpow(k, mod-2)
}

func main() {
  s := next()
  k := ni64()
  l := len(s)
  A := (dec(binpow(binpow(2, int64(l)), k)) * rroot(dec(binpow(2, int64(l))))) % mod
  ans := int64(0)
  for i := 0; i < l; i++ {
    if s[i] == '0' || s[i] == '5' {
      ans += (binpow(2, int64(i)) * A) % mod
      if ans >= mod {
        ans -= mod
      }
    }
  }
  pri64(ans % mod)
  w.Flush()
}

package main

import (
  "fmt"
  "math/big"
  "bufio"
  "os"
  "strconv"
)

var rw *bufio.ReadWriter = bufio.NewReadWriter(bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout))

func next() string {
  token := []byte{}
  for {
    c, err := rw.ReadByte()
    if err != nil || c == ' ' || c == '\n' {
      return string(token)
    } else if c == '\r' {
    _, _ = rw.ReadByte()
      return string(token)
    } else {
      token = append(token, c)
    }
  }
}

func ni() int {
  ans, _ := strconv.Atoi(next())
  return ans
}

const Mod = 1000000007

var a string
var n, k int

func Pow2(p, mod int64) int64 {
  if p == 0 {
    return 1
  } else if p == 1 {
    return 2 % mod
  } else if p % 2 == 0 {
    tmp := Pow2(p / 2, mod)
    return (tmp * tmp) % mod
  } else {
    return 2 * Pow2(p - 1, mod) % mod
  }
}

func PowMod(a, p, mod int64) int64 {
  if p == 0 {
    return 1
  } else if p == 1 {
    return a % mod
  } else if p % 2 == 0 {
    tmp := PowMod(a, p / 2, mod)
    return (tmp * tmp) % mod
  } else {
    return (a * PowMod(a, p - 1, mod)) % mod
  }
}

func CalcConstant_verySlow() int64 {
  numer := (Pow2(int64(n)*int64(k), Mod) - 1 + Mod) % Mod
  denom := (Pow2(int64(n), Mod) - 1 + Mod) % Mod
  for inverse := int64(0); inverse < Mod; inverse++ {
    if (denom * inverse) % Mod == numer {
      return inverse
    }
  }
  panic("no mult inverse")
}

func CalcConstant_slow() int64 {
  numer := big.NewInt((Pow2(int64(n)*int64(k), Mod) - 1 + Mod) % Mod)
  denom := big.NewInt((Pow2(int64(n), Mod) - 1 + Mod) % Mod)
  x := big.NewInt(0).ModInverse(denom, big.NewInt(Mod))
  return big.NewInt(0).Mod(big.NewInt(0).Mul(numer, x), big.NewInt(Mod)).Int64()
}

func CalcConstant() int64 {
  numer := (PowMod(2, int64(n)*int64(k), Mod) - 1 + Mod) % Mod
  denom := (PowMod(2, int64(n), Mod) - 1 + Mod) % Mod
  denomInverse := PowMod(denom, Mod - 2, Mod)
  return (denomInverse * numer) % Mod
}

func Solve() (cnt int) {
  pow2 := 1
  for _, c := range a {
    if c == '0' || c == '5' {
      cnt = (cnt + pow2) % Mod
    }
    pow2 = (pow2 * 2) % Mod
  }
  cnt = int((int64(cnt) * CalcConstant()) % Mod)
  return
}

func main() {
  a = next()
  k = ni()
  //fmt.Scan(&a)
  //fmt.Scan(&k)
  //a = "13990" //"1256"
  //k = 2 //200000000
  n = len(a)
  fmt.Println(Solve())
}

package main

import (
  "fmt"
  "math/big"
)

const Mod = 1000000007

var a string
var n, k int

func Pow2(p, mod int64) int64 {
  if p == 0 {
    return 1
  } else if p == 1 {
    return 2 % mod
  } else if p % 2 == 0 {
    tmp := Pow2(p / 2, mod)
    return (tmp * tmp) % mod
  } else {
    return 2 * Pow2(p - 1, mod) % mod
  }
}

func CalcConstant() int64 {
  numer := big.NewInt((Pow2(int64(n)*int64(k), Mod) - 1 + Mod) % Mod)
  denom := big.NewInt((Pow2(int64(n), Mod) - 1 + Mod) % Mod)
  x := big.NewInt(0).ModInverse(denom, big.NewInt(Mod))
  return big.NewInt(0).Mod(big.NewInt(0).Mul(numer, x), big.NewInt(Mod)).Int64()
}

func Solve() (cnt int64) {
  for i, c := range a {
    if c == '0' || c == '5' {
      cnt = (cnt + Pow2(int64(i), Mod)) % Mod
    }
  }
  cnt = (cnt * CalcConstant()) % Mod
  return
}

func main() {
  fmt.Scan(&a)
  fmt.Scan(&k)
  n = len(a)
  fmt.Println(Solve())
}

package main

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

var sc *bufio.Scanner = bufio.NewScanner(os.Stdin)

func NextString() string {
  sc.Scan()
  return sc.Text()
}

func NextInt() int {
  n, _ := strconv.Atoi(NextString())
  return n
}

const Mod = 1000000007

var a string
var n, k int

func PowMod(a, p, mod int64) int64 {
  if p == 0 {
    return 1
  } else if p == 1 {
    return a % mod
  } else if p % 2 == 0 {
    tmp := PowMod(a, p / 2, mod)
    return (tmp * tmp) % mod
  } else {
    return (a * PowMod(a, p - 1, mod)) % mod
  }
}

func CalcConstant() int64 {
  numer := (PowMod(2, int64(n)*int64(k), Mod) - 1 + Mod) % Mod
  denom := (PowMod(2, int64(n), Mod) - 1 + Mod) % Mod
  denomInverse := PowMod(denom, Mod - 2, Mod)
  return (denomInverse * numer) % Mod
}

func Solve() (cnt int) {
  pow2 := 1
  for _, c := range a {
    if c == '0' || c == '5' {
      cnt = (cnt + pow2) % Mod
    }
    pow2 = (pow2 * 2) % Mod
  }
  cnt = int((int64(cnt) * CalcConstant()) % Mod)
  return
}

func main() {
  sc.Split(bufio.ScanWords)
  fmt.Scan(&a)
  fmt.Scan(&k)
  n = len(a)
  fmt.Println(Solve())
}

package main

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

var sc *bufio.Scanner = bufio.NewScanner(os.Stdin)

func NextString() string {
  sc.Scan()
  if err := sc.Err(); err != nil {
    fmt.Println("Err 1")
  }
  return sc.Text()
}

func NextInt() int {
  n, err := strconv.Atoi(NextString())
  if err != nil {
    fmt.Println("Err 2")
  }
  return n
}

const Mod = 1000000007

var a string
var n, k int

func PowMod(a, p, mod int64) int64 {
  if p == 0 {
    return 1
  } else if p == 1 {
    return a % mod
  } else if p % 2 == 0 {
    tmp := PowMod(a, p / 2, mod)
    return (tmp * tmp) % mod
  } else {
    return (a * PowMod(a, p - 1, mod)) % mod
  }
}

func CalcConstant() int64 {
  numer := (PowMod(2, int64(n)*int64(k), Mod) - 1 + Mod) % Mod
  denom := (PowMod(2, int64(n), Mod) - 1 + Mod) % Mod
  denomInverse := PowMod(denom, Mod - 2, Mod)
  return (denomInverse * numer) % Mod
}

func Solve() (cnt int) {
  pow2 := 1
  for _, c := range a {
    if c == '0' || c == '5' {
      cnt = (cnt + pow2) % Mod
    }
    pow2 = (pow2 * 2) % Mod
  }
  cnt = int((int64(cnt) * CalcConstant()) % Mod)
  return
}

func main() {
  sc.Split(bufio.ScanWords)
  //a = NextString()
  //k = NextInt()
  //fmt.Println(a, k)
  fmt.Scan(&a)
  fmt.Scan(&k)
  //a = "13990" //"1256"
  //k = 2 //200000000
  n = len(a)
  fmt.Println(Solve())
}

package main

import (
  "fmt"
  "math/big"
)

const Mod = 1000000007

var a string
var n, k int

func Pow2(p, mod int64) int64 {
  if p == 0 {
    return 1
  } else if p == 1 {
    return 2 % mod
  } else if p % 2 == 0 {
    tmp := Pow2(p / 2, mod)
    return (tmp * tmp) % mod
  } else {
    return 2 * Pow2(p - 1, mod) % mod
  }
}

func CalcConstant_slow() int64 {
  numer := (Pow2(int64(n)*int64(k), Mod) - 1 + Mod) % Mod
  denom := (Pow2(int64(n), Mod) - 1 + Mod) % Mod
  for inverse := int64(0); inverse < Mod; inverse++ {
    if (denom * inverse) % Mod == numer {
      return inverse
    }
  }
  panic("no mult inverse")
}

func CalcConstant() int64 {
  numer := big.NewInt((Pow2(int64(n)*int64(k), Mod) - 1 + Mod) % Mod)
  denom := big.NewInt((Pow2(int64(n), Mod) - 1 + Mod) % Mod)
  x := big.NewInt(0).ModInverse(denom, big.NewInt(Mod))
  return big.NewInt(0).Mod(big.NewInt(0).Mul(numer, x), big.NewInt(Mod)).Int64()
}

func Solve() (cnt int) {
  pow2 := 1
  for _, c := range a {
    if c == '0' || c == '5' {
      cnt = (cnt + pow2) % Mod
    }
    pow2 = (pow2 * 2) % Mod
  }
  cnt = int((int64(cnt) * CalcConstant()) % Mod)
  return
}

func main() {
  fmt.Scan(&a)
  fmt.Scan(&k)
  //a = "13990" //"1256"
  //k = 2 //200000000
  n = len(a)
  fmt.Println(Solve())
}

package main

import (
  "fmt"
)

const Mod = 1000000007

var a string
var n, k int

func PowMod(a, p, mod int64) int64 {
  if p == 0 {
    return 1
  } else if p == 1 {
    return a % mod
  } else if p % 2 == 0 {
    tmp := PowMod(a, p / 2, mod)
    return (tmp * tmp) % mod
  } else {
    return (a * PowMod(a, p - 1, mod)) % mod
  }
}

func CalcConstant() int64 {
  numer := (PowMod(2, int64(n)*int64(k), Mod) - 1 + Mod) % Mod
  denom := (PowMod(2, int64(n), Mod) - 1 + Mod) % Mod
  denomInverse := PowMod(denom, Mod - 2, Mod)
  return (denomInverse * numer) % Mod
}

func Solve() (cnt int) {
  pow2 := 1
  for _, c := range a {
    if c == '0' || c == '5' {
      cnt = (cnt + pow2) % Mod
    }
    pow2 = (pow2 * 2) % Mod
  }
  cnt = int((int64(cnt) * CalcConstant()) % Mod)
  return
}

func main() {
  fmt.Scan(&a)
  fmt.Scan(&k)
  n = len(a)
  fmt.Println(Solve())
}

package main

import (
  "bufio"
  // "math/big" //too slow, poor golang poor -_-
  "os"
  "strconv"
)

var sc *bufio.Scanner = bufio.NewScanner(os.Stdin)
var w *bufio.Writer = bufio.NewWriter(os.Stdout)

func ni() int {
  sc.Scan()
  ans, _ := strconv.Atoi(sc.Text())
  return ans
}

func nll() int64 {
  sc.Scan()
  ans, _ := strconv.ParseInt(sc.Text(), 10, 64)
  return ans
}

func next() string {
  sc.Scan()
  return sc.Text()
}

func Max(i, j int) int {
  if i >= j {
    return i
  }
  return j
}

func Min(i, j int) int {
  if i < j {
    return i
  }
  return j
}

func pri(n int)    { w.WriteString(strconv.Itoa(n)) }
func prll(n int64) { w.WriteString(strconv.FormatInt(n, 10)) }
func sp()          { w.WriteByte(' ') }
func endl()        { w.WriteByte('\n') }

var mod int64 = 1000000007
var r []int64
var rroot int64

func binpow(a, n int64) int64 {
  if n == 0 {
    return int64(1)
  }
  if n%int64(2) == 1 {
    return (a * binpow(a, n-1)) % mod
  } else {
    b := binpow(a, n/2)
    return (b * b) % mod
  }
}

func main() {
  sc.Split(bufio.ScanWords)
  s := next()
  k := ni()
  l := len(s)
  q := binpow(2, int64(l))
  rq := q - 1
  if rq < 0 {
    rq += mod
  }
  rq = binpow(rq, mod-2) //reverse root of (q-1)
  qn := binpow(q, int64(k)) - 1
  if qn < 0 {
    qn += mod
  }
  A := (qn * rq) % mod
  // prll(A)
  // endl()
  ans := int64(0)
  for i := 0; i < l; i++ {
    // pri(i)
    // sp()
    // prll((binpow(2, int64(i)) * A) % mod)
    // endl()
    if s[i] == '0' || s[i] == '5' {
      ans += (binpow(2, int64(i)) * A) % mod
      if ans >= mod {
        ans -= mod
      }
    }
  }
  prll(ans)
  w.Flush()
}

package main

import (
  "bufio"
  // "math/big" //too slow, poor golang poor -_-
  "os"
  "strconv"
)

var sc *bufio.Scanner = bufio.NewScanner(os.Stdin)
var w *bufio.Writer = bufio.NewWriter(os.Stdout)

func ni() int {
  sc.Scan()
  ans, _ := strconv.Atoi(sc.Text())
  return ans
}

func nll() int64 {
  sc.Scan()
  ans, _ := strconv.ParseInt(sc.Text(), 10, 64)
  return ans
}

func next() string {
  sc.Scan()
  return sc.Text()
}

func Max(i, j int) int {
  if i >= j {
    return i
  }
  return j
}

func Min(i, j int) int {
  if i < j {
    return i
  }
  return j
}

func pri(n int)    { w.WriteString(strconv.Itoa(n)) }
func prll(n int64) { w.WriteString(strconv.FormatInt(n, 10)) }
func sp()          { w.WriteByte(' ') }
func endl()        { w.WriteByte('\n') }

var mod int64 = 1000000007

func binpow(a, n int64) int64 {
  if n == 0 {
    return int64(1)
  }
  if n%int64(2) == 1 {
    return (a * binpow(a, n-1)) % mod
  } else {
    b := binpow(a, n/2)
    return (b * b) % mod
  }
}

func dec(k int64) int64 {
  ans := k - 1
  if ans < 0 {
    ans += mod
  }
  return ans
}

func rroot(k int64) int64 {
  return binpow(k, mod-2)
}

func main() {
  sc.Split(bufio.ScanWords)
  s := next()
  if len(s) == 0 {
    s = next()
  }
  k := nll()
  l := len(s)
  A := (dec(binpow(binpow(2, int64(l)), k)) * rroot(dec(binpow(2, int64(l))))) % mod
  ans := int64(0)
  for i := 0; i < l; i++ {
    if s[i] == '0' || s[i] == '5' {
      ans = (ans + (binpow(2, int64(i))*A)%mod) % mod
    }
  }
  prll(ans)
  w.Flush()
}

package main

import (
  "bufio"
  // "math/big" //too slow, poor golang poor -_-
  "os"
  "strconv"
)

var sc *bufio.Scanner = bufio.NewScanner(os.Stdin)
var w *bufio.Writer = bufio.NewWriter(os.Stdout)

func ni() int {
  sc.Scan()
  ans, _ := strconv.Atoi(sc.Text())
  return ans
}

func nll() int64 {
  sc.Scan()
  ans, _ := strconv.ParseInt(sc.Text(), 10, 64)
  return ans
}

func next() string {
  sc.Scan()
  if len(sc.Text()) == 0 {
    sc.Scan()
  }
  return sc.Text()
}

func Max(i, j int) int {
  if i >= j {
    return i
  }
  return j
}

func Min(i, j int) int {
  if i < j {
    return i
  }
  return j
}

func pri(n int)    { w.WriteString(strconv.Itoa(n)) }
func prll(n int64) { w.WriteString(strconv.FormatInt(n, 10)) }
func sp()          { w.WriteByte(' ') }
func endl()        { w.WriteByte('\n') }

var mod int64 = 1000000007
var r []int64
var rroot int64

func binpow(a, n int64) int64 {
  if n == 0 {
    return int64(1)
  }
  if n%int64(2) == 1 {
    return (a * binpow(a, n-1)) % mod
  } else {
    b := binpow(a, n/2)
    return (b * b) % mod
  }
}

func main() {
  sc.Split(bufio.ScanWords)
  s := next()
  k := ni()
  l := len(s)
  q := binpow(2, int64(l))
  rq := q - 1
  if rq < 0 {
    rq += mod
  }
  rq = binpow(rq, mod-2) //reverse root of (q-1)
  qn := binpow(q, int64(k)) - 1
  if qn < 0 {
    qn += mod
  }
  A := (qn * rq) % mod
  // prll(A)
  // endl()
  ans := int64(0)
  for i := 0; i < l; i++ {
    // pri(i)
    // sp()
    // prll((binpow(2, int64(i)) * A) % mod)
    // endl()
    if s[i] == '0' || s[i] == '5' {
      ans = (ans + (binpow(2, int64(i))*A)%mod) % mod
    }
  }
  prll(ans)
  endl()
  w.Flush()
}

package main

import (
  "bufio"
  // "math/big" //too slow, poor golang poor -_-
  "os"
  "strconv"
)

var sc *bufio.Scanner = bufio.NewScanner(os.Stdin)
var w *bufio.Writer = bufio.NewWriter(os.Stdout)

func ni() int {
  sc.Scan()
  ans, _ := strconv.Atoi(sc.Text())
  return ans
}

func nll() int64 {
  sc.Scan()
  ans, _ := strconv.ParseInt(sc.Text(), 10, 64)
  return ans
}

func next() string {
  sc.Scan()
  if len(sc.Text()) == 0 {
    sc.Scan()
  }
  return sc.Text()
}

func Max(i, j int) int {
  if i >= j {
    return i
  }
  return j
}

func Min(i, j int) int {
  if i < j {
    return i
  }
  return j
}

func pri(n int)    { w.WriteString(strconv.Itoa(n)) }
func prll(n int64) { w.WriteString(strconv.FormatInt(n, 10)) }
func sp()          { w.WriteByte(' ') }
func endl()        { w.WriteByte('\n') }

var mod int64 = 1000000007
var r []int64
var rroot int64

func binpow(a, n int64) int64 {
  if n == 0 {
    return int64(1)
  }
  if n%int64(2) == 1 {
    return (a * binpow(a, n-1)) % mod
  } else {
    b := binpow(a, n/2)
    return (b * b) % mod
  }
}

func main() {
  sc.Split(bufio.ScanWords)
  s := next()
  k := ni()
  l := len(s)
  q := binpow(2, int64(l))
  rq := q - 1
  if rq < 0 {
    rq += mod
  }
  rq = binpow(rq, mod-2)
  qn := binpow(q, int64(k)) - 1
  if qn < 0 {
    qn += mod
  }
  A := (qn * rq) % mod
  ans := int64(0)
  x := int64(1)
  for i := 0; i < l; i++ {
    if s[i] == '0' || s[i] == '5' {
      ans = (ans + (x*A)%mod) % mod
    }
    x *= 2
    if x >= mod {
      x -= mod
    }

  }
  prll(ans)
  endl()
  w.Flush()
}

package main

import (
  "bufio"
  // "math/big" //too slow, poor golang poor -_-
  "os"
  "strconv"
)

var sc *bufio.Scanner = bufio.NewScanner(os.Stdin)
var w *bufio.Writer = bufio.NewWriter(os.Stdout)

func ni() int {
  sc.Scan()
  ans, _ := strconv.Atoi(sc.Text())
  return ans
}

func nll() int64 {
  sc.Scan()
  ans, _ := strconv.ParseInt(sc.Text(), 10, 64)
  return ans
}

func next() string {
  sc.Scan()
  if len(sc.Text()) == 0 {
    sc.Scan()
  }
  return sc.Text()
}

func Max(i, j int) int {
  if i >= j {
    return i
  }
  return j
}

func Min(i, j int) int {
  if i < j {
    return i
  }
  return j
}

func pri(n int)    { w.WriteString(strconv.Itoa(n)) }
func prll(n int64) { w.WriteString(strconv.FormatInt(n, 10)) }
func sp()          { w.WriteByte(' ') }
func endl()        { w.WriteByte('\n') }

var mod int64 = 1000000007
var r []int64
var rroot int64

func binpow(a, n int64) int64 {
  if n == 0 {
    return int64(1)
  }
  if n%int64(2) == 1 {
    return (a * binpow(a, n-1)) % mod
  } else {
    b := binpow(a, n/2)
    return (b * b) % mod
  }
}

func main() {
  sc.Split(bufio.ScanWords)
  s := next()
  k := ni()
  l := len(s)
  q := binpow(2, int64(l))
  rq := q - 1
  if rq < 0 {
    rq += mod
  }
  rq = binpow(rq, mod-2)
  qn := binpow(q, int64(k)) - 1
  if qn < 0 {
    qn += mod
  }
  A := (qn * rq) % mod
  ans := int64(0)
  x := int64(1)
  for i := 0; i < l; i++ {
    if s[i] == '0' || s[i] == '5' {
      ans = (ans + (x*A)%mod) % mod
    }
    x *= 2
    if x >= mod {
      x -= mod
    }

  }
  w.Flush()
  prll(ans % mod)
  endl()
  w.Flush()
}

package main

import (
  "bufio"
  // "math/big" //too slow, poor golang poor -_-
  "os"
  "strconv"
)

var sc *bufio.Scanner = bufio.NewScanner(os.Stdin)
var w *bufio.Writer = bufio.NewWriter(os.Stdout)

func ni() int {
  sc.Scan()
  ans, _ := strconv.Atoi(sc.Text())
  return ans
}

func nll() int64 {
  sc.Scan()
  ans, _ := strconv.ParseInt(sc.Text(), 10, 64)
  return ans
}

func next() string {
  sc.Scan()
  if len(sc.Text()) == 0 {
    sc.Scan()
  }
  return sc.Text()
}

func Max(i, j int) int {
  if i >= j {
    return i
  }
  return j
}

func Min(i, j int) int {
  if i < j {
    return i
  }
  return j
}

func pri(n int)    { w.WriteString(strconv.Itoa(n)) }
func prll(n int64) { w.WriteString(strconv.FormatInt(n, 10)) }
func sp()          { w.WriteByte(' ') }
func endl()        { w.WriteByte('\n') }

var mod int64 = 1000000007
var r []int64
var rroot int64

func binpow(a, n int64) int64 {
  if n == 0 {
    return int64(1)
  }
  if n%int64(2) == 1 {
    return (a * binpow(a, n-1)) % mod
  } else {
    b := binpow(a, n/2)
    return (b * b) % mod
  }
}

func main() {
  sc.Split(bufio.ScanWords)
  s := next()
  k := ni()
  l := len(s)
  q := binpow(2, int64(l))
  rq := q - 1
  if rq < 0 {
    rq += mod
  }
  rq = binpow(rq, mod-2) //reverse root of (q-1)
  qn := binpow(q, int64(k)) - 1
  if qn < 0 {
    qn += mod
  }
  A := (qn * rq) % mod
  // prll(A)
  // endl()
  ans := int64(0)
  for i := 0; i < l; i++ {
    // pri(i)
    // sp()
    // prll((binpow(2, int64(i)) * A) % mod)
    // endl()
    if s[i] == '0' || s[i] == '5' {
      ans += (binpow(2, int64(i)) * A) % mod
      if ans >= mod {
        ans -= mod
      }
    }
  }
  prll(ans)
  endl()
  w.Flush()
}

package main

import (
  "bufio"
  "os"
  "strconv"
)

var rw *bufio.ReadWriter = bufio.NewReadWriter(bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout))

func next() string {
  token := []byte{}
  for {
    c, err := rw.ReadByte()
    if err != nil || c == ' ' || c == '\n' {
      return string(token)
    } else {
      token = append(token, c)
    }
  }
}

func ni() int {
  ans, _ := strconv.Atoi(next())
  return ans
}

func nll() int64 {
  ans, _ := strconv.ParseInt(next(), 10, 64)
  return ans
}

func Max(i, j int) int {
  if i >= j {
    return i
  }
  return j
}

func Min(i, j int) int {
  if i < j {
    return i
  }
  return j
}

func pri(n int)    { rw.WriteString(strconv.Itoa(n)) }
func prll(n int64) { rw.WriteString(strconv.FormatInt(n, 10)) }
func sp()          { rw.WriteByte(' ') }
func endl()        { rw.WriteByte('\n') }

var mod int64 = 1000000007
var r []int64
var rroot int64

func binpow(a, n int64) int64 {
  if n == 0 {
    return int64(1)
  }
  if n%int64(2) == 1 {
    return (a * binpow(a, n-1)) % mod
  } else {
    b := binpow(a, n/2)
    return (b * b) % mod
  }
}

func main() {
  s := next()
  k := ni()
  l := len(s)
  q := binpow(2, int64(l))
  rq := q - 1
  if rq < 0 {
    rq += mod
  }
  rq = binpow(rq, mod-2)
  qn := binpow(q, int64(k)) - 1
  if qn < 0 {
    qn += mod
  }
  A := (qn * rq) % mod
  ans := int64(0)
  x := int64(1)
  for i := 0; i < l; i++ {
    if s[i] == '0' || s[i] == '5' {
      ans = (ans + (x*A)%mod) % mod
    }
    // prll(ans)
    // sp()
    x *= 2
    if x >= mod {
      x -= mod
    }

  }
  prll(ans)
  rw.Flush()
}

package main

import (
  "bufio"
  // "math/big" //too slow, poor golang poor -_-
  "os"
  "strconv"
)

var sc *bufio.Scanner = bufio.NewScanner(os.Stdin)
var w *bufio.Writer = bufio.NewWriter(os.Stdout)

func ni() int {
  sc.Scan()
  ans, _ := strconv.Atoi(sc.Text())
  return ans
}

func nll() int64 {
  sc.Scan()
  ans, _ := strconv.ParseInt(sc.Text(), 10, 64)
  return ans
}

func next() string {
  sc.Scan()
  return sc.Text()
}

func Max(i, j int) int {
  if i >= j {
    return i
  }
  return j
}

func Min(i, j int) int {
  if i < j {
    return i
  }
  return j
}

func pri(n int)    { w.WriteString(strconv.Itoa(n)) }
func prll(n int64) { w.WriteString(strconv.FormatInt(n, 10)) }
func sp()          { w.WriteByte(' ') }
func endl()        { w.WriteByte('\n') }

var mod int64 = 1000000007

func binpow(a, n int64) int64 {
  if n == 0 {
    return int64(1)
  }
  if n%int64(2) == 1 {
    return (a * binpow(a, n-1)) % mod
  } else {
    b := binpow(a, n/2)
    return (b * b) % mod
  }
}

func dec(k int64) int64 {
  ans := k - 1
  if ans < 0 {
    ans += mod
  }
  return ans
}

func rroot(k int64) int64 {
  return binpow(k, mod-2)
}

func main() {
  sc.Split(bufio.ScanWords)
  s := next()
  k := nll()
  l := len(s)
  A := (dec(binpow(binpow(2, int64(l)), k)) * rroot(dec(binpow(2, int64(l))))) % mod
  ans := int64(0)
  for i := 0; i < l; i++ {
    if s[i] == '0' || s[i] == '5' {
      ans = (ans + (binpow(2, int64(i))*A)%mod) % mod
    }
  }
  prll(ans % mod)
  w.Flush()
}

package main

import (
  "bufio"
  // "math/big" //too slow, poor golang poor -_-
  "os"
  "strconv"
)

var sc *bufio.Scanner = bufio.NewScanner(os.Stdin)
var w *bufio.Writer = bufio.NewWriter(os.Stdout)

func ni() int {
  sc.Scan()
  ans, _ := strconv.Atoi(sc.Text())
  return ans
}

func nll() int64 {
  sc.Scan()
  ans, _ := strconv.ParseInt(sc.Text(), 10, 64)
  return ans
}

func next() string {
  sc.Scan()
  return sc.Text()
}

func Max(i, j int) int {
  if i >= j {
    return i
  }
  return j
}

func Min(i, j int) int {
  if i < j {
    return i
  }
  return j
}

func pri(n int)    { w.WriteString(strconv.Itoa(n)) }
func prll(n int64) { w.WriteString(strconv.FormatInt(n, 10)) }
func sp()          { w.WriteByte(' ') }
func endl()        { w.WriteByte('\n') }

var mod int64 = 1000000007

func binpow(a, n int64) int64 {
  if n == 0 {
    return int64(1)
  }
  if n%int64(2) == 1 {
    return (a * binpow(a, n-1)) % mod
  } else {
    b := binpow(a, n/2)
    return (b * b) % mod
  }
}

func dec(k int64) int64 {
  ans := k - 1
  if ans < 0 {
    ans += mod
  }
  return ans
}

func rroot(k int64) int64 {
  return binpow(k, mod-2)
}

// A = ((2**len)**k-1) / (2**len-1)

func main() {
  sc.Split(bufio.ScanWords)
  s := next()
  k := nll()
  l := len(s)
  A := (dec(binpow(binpow(2, int64(l)), k)) * rroot(dec(binpow(2, int64(l))))) % mod
  ans := int64(0)
  for i := 0; i < l; i++ {
    if s[i] == '0' || s[i] == '5' {
      ans += (binpow(2, int64(i)) * A) % mod
      if ans >= mod {
        ans -= mod
      }
    }
  }
  prll(ans % mod)
  w.Flush()
}

package main

import (
  "bufio"
  // "math/big" //too slow, poor golang poor -_-
  "os"
  "strconv"
)

var sc *bufio.Scanner = bufio.NewScanner(os.Stdin)
var w *bufio.Writer = bufio.NewWriter(os.Stdout)

func ni() int {
  sc.Scan()
  ans, _ := strconv.Atoi(sc.Text())
  return ans
}

func nll() int64 {
  sc.Scan()
  ans, _ := strconv.ParseInt(sc.Text(), 10, 64)
  return ans
}

func next() string {
  sc.Scan()
  if len(sc.Text()) == 0 {
    sc.Scan()
  }
  return sc.Text()
}

func Max(i, j int) int {
  if i >= j {
    return i
  }
  return j
}

func Min(i, j int) int {
  if i < j {
    return i
  }
  return j
}

func pri(n int)    { w.WriteString(strconv.Itoa(n)) }
func prll(n int64) { w.WriteString(strconv.FormatInt(n, 10)) }
func sp()          { w.WriteByte(' ') }
func endl()        { w.WriteByte('\n') }

var mod int64 = 1000000007
var r []int64
var rroot int64

func binpow(a, n int64) int64 {
  if n == 0 {
    return int64(1)
  }
  if n%int64(2) == 1 {
    return (a * binpow(a, n-1)) % mod
  } else {
    b := binpow(a, n/2)
    return (b * b) % mod
  }
}

func main() {
  sc.Split(bufio.ScanWords)
  s := next()
  k := ni()
  l := len(s)
  q := binpow(2, int64(l))
  rq := q - 1
  if rq < 0 {
    rq += mod
  }
  rq = binpow(rq, mod-2) //reverse root of (q-1)
  qn := binpow(q, int64(k)) - 1
  if qn < 0 {
    qn += mod
  }
  A := (qn * rq) % mod
  // prll(A)
  // endl()
  ans := int64(0)
  for i := 0; i < l; i++ {
    // pri(i)
    // sp()
    // prll((binpow(2, int64(i)) * A) % mod)
    // endl()
    if s[i] == '0' || s[i] == '5' {
      ans += (binpow(2, int64(i)) * A) % mod
      if ans >= mod {
        ans -= mod
      }
    }
  }
  prll(ans % mod)
  endl()
  w.Flush()
}

package main

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

var sc *bufio.Scanner = bufio.NewScanner(os.Stdin)

func NextString() string {
  sc.Scan()
  if err := sc.Err(); err != nil {
    fmt.Println("Err 1", err)
  }
  return sc.Text()
}

func NextInt() int {
  n, err := strconv.Atoi(NextString())
  if err != nil {
    fmt.Println("Err 2", err)
  }
  return n
}

const Mod = 1000000007

var a string
var n, k int

func PowMod(a, p, mod int64) int64 {
  if p == 0 {
    return 1
  } else if p == 1 {
    return a % mod
  } else if p % 2 == 0 {
    tmp := PowMod(a, p / 2, mod)
    return (tmp * tmp) % mod
  } else {
    return (a * PowMod(a, p - 1, mod)) % mod
  }
}

func CalcConstant() int64 {
  numer := (PowMod(2, int64(n)*int64(k), Mod) - 1 + Mod) % Mod
  denom := (PowMod(2, int64(n), Mod) - 1 + Mod) % Mod
  denomInverse := PowMod(denom, Mod - 2, Mod)
  return (denomInverse * numer) % Mod
}

func Solve() (cnt int) {
  pow2 := 1
  for _, c := range a {
    if c == '0' || c == '5' {
      cnt = (cnt + pow2) % Mod
    }
    pow2 = (pow2 * 2) % Mod
  }
  cnt = int((int64(cnt) * CalcConstant()) % Mod)
  return
}

func main() {
  sc.Split(bufio.ScanWords)
  a = NextString()
  k = NextInt()
  //fmt.Println(a, k)
  //fmt.Scan(&a)
  //fmt.Scan(&k)
  //a = "13990" //"1256"
  //k = 2 //200000000
  n = len(a)
  fmt.Println(Solve())
}

package main

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

var sc *bufio.Scanner = bufio.NewScanner(os.Stdin)

func NextString() string {
  sc.Scan()
  if err := sc.Err(); err != nil {
    fmt.Println("Err 1")
  }
  return sc.Text()
}

func NextInt() int {
  n, err := strconv.Atoi(NextString())
  if err != nil {
    fmt.Println("Err 2")
  }
  return n
}

const Mod = 1000000007

var a string
var n, k int

func PowMod(a, p, mod int64) int64 {
  if p == 0 {
    return 1
  } else if p == 1 {
    return a % mod
  } else if p % 2 == 0 {
    tmp := PowMod(a, p / 2, mod)
    return (tmp * tmp) % mod
  } else {
    return (a * PowMod(a, p - 1, mod)) % mod
  }
}

func CalcConstant() int64 {
  numer := (PowMod(2, int64(n)*int64(k), Mod) - 1 + Mod) % Mod
  denom := (PowMod(2, int64(n), Mod) - 1 + Mod) % Mod
  denomInverse := PowMod(denom, Mod - 2, Mod)
  return (denomInverse * numer) % Mod
}

func Solve() (cnt int) {
  pow2 := 1
  for _, c := range a {
    if c == '0' || c == '5' {
      cnt = (cnt + pow2) % Mod
    }
    pow2 = (pow2 * 2) % Mod
  }
  cnt = int((int64(cnt) * CalcConstant()) % Mod)
  return
}

func main() {
  sc.Split(bufio.ScanWords)
  a = NextString()
  k = NextInt()
  //fmt.Println(a, k)
  //fmt.Scan(&a)
  //fmt.Scan(&k)
  //a = "13990" //"1256"
  //k = 2 //200000000
  n = len(a)
  fmt.Println(Solve())
}

package main

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

var sc *bufio.Scanner = bufio.NewScanner(os.Stdin)

func NextString() string {
  sc.Scan()
  return sc.Text()
}

func NextInt() int {
  n, _ := strconv.Atoi(NextString())
  return n
}

const Mod = 1000000007

var a string
var n, k int

func PowMod(a, p, mod int64) int64 {
  if p == 0 {
    return 1
  } else if p == 1 {
    return a % mod
  } else if p % 2 == 0 {
    tmp := PowMod(a, p / 2, mod)
    return (tmp * tmp) % mod
  } else {
    return (a * PowMod(a, p - 1, mod)) % mod
  }
}

func CalcConstant() int64 {
  numer := (PowMod(2, int64(n)*int64(k), Mod) - 1 + Mod) % Mod
  denom := (PowMod(2, int64(n), Mod) - 1 + Mod) % Mod
  denomInverse := PowMod(denom, Mod - 2, Mod)
  return (denomInverse * numer) % Mod
}

func Solve() (cnt int) {
  pow2 := 1
  for _, c := range a {
    if c == '0' || c == '5' {
      cnt = (cnt + pow2) % Mod
    }
    pow2 = (pow2 * 2) % Mod
  }
  cnt = int((int64(cnt) * CalcConstant()) % Mod)
  return
}

func main() {
  sc.Split(bufio.ScanWords)
  a = NextString()
  k = NextInt()
  n = len(a)
  fmt.Println(Solve())
}