package main

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

func (io *IO) Solve() {
	io.setBuffer()
	s := io.Bytes()
	n := len(s)
	arr := make([]int, n+1)
	arr[n] = n
	var res int64
	for i := n - 1; i >= 0; i-- {
		arr[i] = arr[i+1]
		for k := 1; i+2*k < arr[i]; k++ {
			if s[i] == s[i+k] && s[i] == s[i+2*k] {
				arr[i] = i + 2*k
			}
		}
		res += int64(n - arr[i])
	}
	io.Print(res)
}

func main() {
	NewIO().Solve()
}

type IO struct {
	scanner *bufio.Scanner
	writer  io.Writer
}

func NewIO() *IO {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return &IO{scanner, os.Stdout}
}

func (io *IO) Skip() {
	io.scanner.Scan()
}

func (io *IO) Int32() (n int32) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	for _, v := range buf {
		n = n*10 + int32(v-'0')
	}
	return
}

func (io *IO) Int() (n int) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	for _, v := range buf {
		n = n*10 + int(v-'0')
	}
	return
}

func (io *IO) Bytes() []byte {
	io.scanner.Scan()
	return io.scanner.Bytes()
}

func (io *IO) IntArray(n int) (arr []int) {
	arr = make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = io.Int()
	}
	return
}

func (io *IO) Print(a interface{}) {
	fmt.Fprint(io.writer, a)
}

func (io *IO) Printf(format string, a interface{}) {
	fmt.Fprintf(io.writer, format, a)
}

func (io *IO) setBuffer() {
	io.scanner.Buffer(make([]byte, 4096), 512*1024)
}

package main

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

func solveAll(jam Jam) {
	s, l, ui, f, d, p, pf := jam.Str, jam.Long, jam.Int, jam.Float, jam.D, jam.P, jam.PF
	//	Live Templates: for0l for1l for0ui for1ui forr vl0 vln vui0 vuin ; Casts: l i

	noTriples := make(map[string]bool)
	noTriples["00"], noTriples["01"], noTriples["10"], noTriples["11"] = true, true, true, true

	added := true
	ln := 2
	for added {
		added = false

		for k := range noTriples {
			if len(k) != ln {
				continue
			}
			for _, suff := range [2]rune{'0', '1'} {
				test := k + string([]rune{suff})
				noTriplesInTest := true
				for k := 1; 2*k < len(test) && noTriplesInTest; k++ {
					for x := 0; x < len(test) - 2*k && noTriplesInTest; x++ {
						if test[x] == test[x+k] && test[x+k] == test[x+2*k] {
							noTriplesInTest = false
						}
					}
				}
				if noTriplesInTest {
					//d("%s ", test)
					noTriples[test] = true
					added = true
				}
			}
		}
		ln += 1
		//d("\n")
	}

	noTriples[""], noTriples["0"], noTriples["1"] = true, true, true

	str := s()
	pairs := uint64(len(str))*uint64(len(str)-1)/2
	//d("INIT: %d\n", pairs)
	buf := ""
	for _, r := range []rune(str) {
		buf = buf + string([]rune{r})
		//d("%s %s", string([]rune{r}), buf)
		for !noTriples[buf] {
			buf = buf[1:]
			//d(" :%s", buf)
		}
		if noTriples[buf] {
			//d(" -%d", len(buf)-1)
			pairs -= uint64(len(buf)-1)
		}
		//d("\n")
	}

	p("%d", pairs)

	if false { d("%v", []interface{}{s, l, ui, f, d, p, pf}) }
}

//	TODO wipe unused shorthand methods for math
type Uint32Sort []uint32
func (s Uint32Sort) Len() int           { return len(s) }
func (s Uint32Sort) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s Uint32Sort) Less(i, j int) bool { return s[i] < s[j] }

func t(b bool, t, f int64) int64 { if b {return t};return f }
func min(a, b int64) int64 { if a < b {return a}; return b }
func max(a, b int64) int64 { if a > b {return a}; return b }
func abs(a int64) int64 { if a < 0 { return -a }; return a }
func ti(b bool, t, f uint32) uint32 { if b {return t};return f }
func mini(a, b uint32) uint32 { if a < b { return a }; return b }
func maxi(a, b uint32) uint32 { if a > b { return a }; return b }

func round(x float64) float64 { //	https://www.cockroachlabs.com/blog/rounding-implementations-in-go/
	const (
		mask     = 0x7FF
		shift    = 64 - 11 - 1
		bias     = 1023

		signMask = 1 << 63
		fracMask = (1 << shift) - 1
		halfMask = 1 << (shift - 1)
		one      = bias << shift
	)

	bits := math.Float64bits(x)
	e := uint(bits>>shift) & mask
	switch {
	case e < bias:
		// Round abs(x)<1 including denormals.
		bits &= signMask // +-0
		if e == bias-1 {
			bits |= one // +-1
		}
	case e < bias+shift:
		// Round any abs(x)>=1 containing a fractional component [0,1).
		e -= bias
		bits += halfMask >> e
		bits &^= fracMask >> e
	}
	return math.Float64frombits(bits)
}

func main() {
	jam, closeFunc := JamNew()
	defer closeFunc()
	solveAll(jam)
}

type Jam interface {
	Scanner() *bufio.Scanner
	Writer() *bufio.Writer
	Close()

	Str() string
	Long() int64
	Int() uint32
	Float() float64

	D(format string, values ...interface{})
	P(format string, values ...interface{})
	PF(format string, values ...interface{})
}

func JamNew() (Jam, func()) {
	if len(os.Args) > 1 {
		panic("running with input file path is not supported")
	}

	var scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 0, 1024*1024), 1024*1024)

	var writer = bufio.NewWriterSize(os.Stdout, 1024*1024)
	jam := &jam{scanner, writer}
	return jam, jam.Close
}

type jam struct {
	sc *bufio.Scanner
	wr *bufio.Writer
}

func (j *jam) Close() {
	if err := j.wr.Flush(); err != nil {
		panic(err)
	}
}

func (j *jam) Scanner() *bufio.Scanner {
	return j.sc
}

func (j *jam) Writer() *bufio.Writer {
	return j.wr
}

func (j *jam) Str() string {
	if !j.sc.Scan() {
		panic("failed to scan next token")
	}

	return j.sc.Text()
}

func (j *jam) Long() int64 {
	if !j.sc.Scan() {
		panic("failed to scan next token")
	}

	res, err := strconv.ParseInt(j.sc.Text(), 10, 64)
	if err != nil {
		panic(err)
	}

	return res
}

func (j *jam) Int() uint32 {
	return uint32(j.Long())
}

func (j *jam) Float() float64 {
	j.sc.Scan()
	res, err := strconv.ParseFloat(j.sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return res
}

func (j *jam) D(format string, values ...interface{}) {
	_ /*bytesWritten*/, err := fmt.Fprintf(os.Stderr, format, values...)
	if err != nil {
		panic(err)
	}
}

func (j *jam) P(format string, values ...interface{}) {
	_, err := fmt.Fprintf(j.wr, format, values...)
	if err != nil {
		panic(err)
	}
}

func (j *jam) PF(format string, values ...interface{}) {
	_, err := fmt.Fprintf(j.wr, format, values...)
	if err != nil {
		panic(err)
	}
	if err = j.wr.Flush(); err != nil {
		panic(err)
	}
}

// tag(s): lower search
package main

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

const N = 300005
var s string
var n int

func max(a int, b int) int {
	if a > b {
		return a
	}
	return b
}

func main() {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	fmt.Fscanf(reader, "%s", &s)

	n = len(s)
	var ret = int64(n) * int64(n + 1) / 2
	var last = 0
	for i := 1; i <= n; i++ {
		var pos = last

		for j := 1; i - 2 * j >= max(i - 20, 1); j++ {
			if s[i - 1] == s[i - j - 1] && s[i - j - 1] == s[i - 2 * j - 1] {
				pos = max(i - 2 * j, last)
				break
			}
		}

		ret -= int64(i - pos)
		last = pos
	}

	fmt.Fprintf(writer, "%d", ret)
}

package main

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

func (io *IO) Solve() {
	io.setBuffer()
	s := io.Bytes()
	n := len(s)
	arr := make([]int, n+1)
	arr[n] = n
	res := 0
	for i := n - 1; i >= 0; i-- {
		arr[i] = arr[i+1]
		for k := 1; i+2*k < arr[i]; k++ {
			if s[i] == s[i+k] && s[i] == s[i+2*k] {
				arr[i] = i + 2*k
			}
		}
		res += n - arr[i]
	}
	io.Print(res)
}

func main() {
	NewIO().Solve()
}

type IO struct {
	scanner *bufio.Scanner
	writer  io.Writer
}

func NewIO() *IO {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return &IO{scanner, os.Stdout}
}

func (io *IO) Skip() {
	io.scanner.Scan()
}

func (io *IO) Int32() (n int32) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	for _, v := range buf {
		n = n*10 + int32(v-'0')
	}
	return
}

func (io *IO) Int() (n int) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	for _, v := range buf {
		n = n*10 + int(v-'0')
	}
	return
}

func (io *IO) Bytes() []byte {
	io.scanner.Scan()
	return io.scanner.Bytes()
}

func (io *IO) IntArray(n int) (arr []int) {
	arr = make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = io.Int()
	}
	return
}

func (io *IO) Print(a interface{}) {
	fmt.Fprint(io.writer, a)
}

func (io *IO) Printf(format string, a interface{}) {
	fmt.Fprintf(io.writer, format, a)
}

func (io *IO) setBuffer() {
	io.scanner.Buffer(make([]byte, 4096), 512*1024)
}

package main

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

func (io *IO) Solve() {
	s := io.Bytes()
	n := len(s)
	arr := make([]int, n+1)
	arr[n] = n
	res := 0
	for i := n - 1; i >= 0; i-- {
		arr[i] = arr[i+1]
		for k := 1; i+2*k < arr[i]; k++ {
			if s[i] == s[i+k] && s[i] == s[i+2*k] {
				arr[i] = i + 2*k
			}
		}
		res += n - arr[i]
	}
	io.Print(res)
}

func main() {
	NewIO().Solve()
}

type IO struct {
	scanner *bufio.Scanner
	writer  io.Writer
}

func NewIO() *IO {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	return &IO{scanner, os.Stdout}
}

func (io *IO) Skip() {
	io.scanner.Scan()
}

func (io *IO) Int32() (n int32) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	for _, v := range buf {
		n = n*10 + int32(v-'0')
	}
	return
}

func (io *IO) Int() (n int) {
	io.scanner.Scan()
	buf := io.scanner.Bytes()
	for _, v := range buf {
		n = n*10 + int(v-'0')
	}
	return
}

func (io *IO) Bytes() []byte {
	io.scanner.Scan()
	return io.scanner.Bytes()
}

func (io *IO) IntArray(n int) (arr []int) {
	arr = make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = io.Int()
	}
	return
}

func (io *IO) Print(a interface{}) {
	fmt.Fprint(io.writer, a)
}

func (io *IO) Printf(format string, a interface{}) {
	fmt.Fprintf(io.writer, format, a)
}

package main

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

const N = 300005
var s string
var n int

func max(a int, b int) int {
	if a > b {
		return a
	}
	return b
}

func main() {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	fmt.Fscanf(reader, "%s", &s)

	n = len(s)
	var ret = int64(n) * int64(n + 1) / 2
	var last = 0
	for i := 1; i <= n; i++ {
		var pos = last

		for j := 1; i - j - j >= max(i - 20, 1); j++ {
			if s[i - 1] == s[i - j - 1] && s[i - j - 1] == s[i - 2 * j - 1] {
				pos = max(i - 2 * j, last)
				break
			}
		}

		ret -= int64(i - pos)
	}

	fmt.Fprintf(writer, "%d", ret)
}


package main

import (
	"fmt"
)

func main() {
	var s string
	var t string

	fmt.Scan(&s, &t)

	n := len(s)

	var m map[uint8]uint8
	m = make(map[uint8]uint8)

	good := true

	for i := 0; i < n; i++ {
		c1, c2 := s[i], t[i]

		v1, ok1 := m[c1]

		if ok1 {
			if v1 != c2 {
				good = false
			}
		}

		v2, ok2 := m[c2]

		if ok2 {
			if v2 != c1 {
				good = false
			}
		}

		if good == false {
			break
		} else {
			m[c1] = c2
			m[c2] = c1
		}
	}

	if good == false {
		fmt.Println(-1)
	} else {
		var mh map[uint8]uint8
		mh = make(map[uint8]uint8)

		for k, v := range m {
			_, ok1 := mh[k]
			_, ok2 := mh[v]

			if ok1 == false && ok2 == false && k != v {
				mh[k] = v
			}
		}

		fmt.Println(len(mh))
		for k, v := range mh {
			fmt.Println(string(k), string(v))
		}
	}
}

package main

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

func solve() {
	str1 := readString()
	str2 := readString()
	mm := map[rune]rune{}
	for i := 0; i < len(str1); i++ {
		v := rune(str1[i])
		rep := rune(str2[i])
		if prev, ok := mm[v]; !ok {
			mm[v] = rep
		} else if prev != rep {
			fmt.Println(-1)
			return
		}
		if prev, ok := mm[rep]; !ok {
			mm[rep] = v
		} else if prev != v {
			fmt.Println(-1)
			return
		}
	}
	visited := map[rune]int{}
	lines := []string{}
	for k, v := range mm {
		if k != v {
			if visited[k] == 0 && visited[v] == 0 {
				lines = append(lines, fmt.Sprintln(string(v), string(k)))
				visited[k]++
				visited[v]++
			}
		}
	}
	fmt.Println(len(lines))
	for i := 0; i < len(lines); i++ {
		fmt.Print(lines[i])
	}
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

// IO

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

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

package main

import "fmt"

func main() {
	var correct, current string
	fmt.Scanln(&correct)
	fmt.Scanln(&current)

	var mp = make(map[byte]byte)
	var n = len(correct)

	for i := 0; i < n; i++ {
		var k1, k2 byte = correct[i], current[i]
		var _, ok1 = mp[k1]
		var _, ok2 = mp[k2]
		if !ok1 && !ok2 {
			if k1 != k2 {
				mp[k1] = k2
				mp[k2] = k1
			} else {
				mp[k1] = k1
			}

		} else {
			if mp[k1] != k2 || mp[k2] != k1 {
				fmt.Println(-1)
				return
			}
		}
	}

	var found = 0
	for k, v := range mp {
		if k < v {
			found++
		}
	}
	fmt.Println(found)
	for k, v := range mp {
		if k < v {
			fmt.Println(string(k), string(v))
		}
	}
}

package main

import "fmt"

func main() {
	var correct, current string
	fmt.Scanln(&correct)
	fmt.Scanln(&current)

	var mp = make(map[byte]byte)
	var n = len(correct)

	for i := 0; i < n; i++ {
		var k1, k2 byte = correct[i], current[i]
		if k1 != k2 {
			var _, ok = mp[k1]
			if !ok {
				mp[k1] = k2
				mp[k2] = k1
			} else {
				if mp[k1] != k2 || mp[k2] != k1 {
					fmt.Println(-1)
					return
				}
			}
		}
	}

	var found = len(mp) >> 1
	fmt.Println(found)
	for k, v := range mp {
		if k < v {
			fmt.Println(string(k), string(v))
		}
	}
}

package main

import "fmt"

func main() {
	var correct, current string
	fmt.Scanln(&correct)
	fmt.Scanln(&current)

	var mp = make(map[byte]byte)
	var n = len(correct)

	for i := 0; i < n; i++ {
		var k1, k2 byte = correct[i], current[i]
		var _, ok1 = mp[k1]
		var _, ok2 = mp[k2]
		if !ok1 && !ok2 {
			mp[k1] = k2
			mp[k2] = k1
		} else {
			if mp[k1] != k2 || mp[k2] != k1 {
				fmt.Println(-1)
				return
			}
		}
	}

	var found = len(mp) >> 1
	fmt.Println(found)
	for k, v := range mp {
		if k < v {
			fmt.Println(string(k), string(v))
		}
	}
}

package main

import "fmt"

func main() {
	var correct, current string
	fmt.Scanln(&correct)
	fmt.Scanln(&current)

	var mp = make(map[byte]byte)
	var n = len(correct)

	var d = 0

	for i := 0; i < n; i++ {
		var k1, k2 byte = correct[i], current[i]
		var _, ok1 = mp[k1]
		var _, ok2 = mp[k2]
		if !ok1 && !ok2 {
			if k1 != k2 {
				mp[k1] = k2
				mp[k2] = k1
			} else {
				mp[k1] = k1
				d++
			}

		} else {
			if mp[k1] != k2 || mp[k2] != k1 {
				fmt.Println(-1)
				return
			}
		}
	}

	var found = len(mp) >> 1
	fmt.Println(found - d)
	for k, v := range mp {
		if k < v {
			fmt.Println(string(k), string(v))
		}
	}
}

package main

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

func solve() {
	str1 := readString()
	str2 := readString()
	mm := map[rune]rune{}
	for i := 0; i < len(str1); i++ {
		v := rune(str1[i])
		if prev, ok := mm[v]; !ok {
			mm[v] = rune(str2[i])
		} else if prev != rune(str2[i]) {
			fmt.Println(-1)
			return
		}
	}
	visited := map[rune]int{}
	lines := []string{}
	for k, v := range mm {
		if k != v {
			if visited[k] == 0 && visited[v] == 0 {
				lines = append(lines, fmt.Sprintln(string(v), string(k)))
				visited[k]++
				visited[v]++
			}
		}
	}
	fmt.Println(len(lines))
	for i := 0; i < len(lines); i++ {
		fmt.Print(lines[i])
	}
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

// IO

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

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

package main

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

func solve() {
	str1 := readString()
	str2 := readString()
	a1 := []rune(str1)
	a2 := []rune(str2)
	mm := map[rune]rune{}
	for i := 0; i < len(a1); i++ {
		if a1[i] != a2[i] {
			rep := a2[i]
			if prev, ok := mm[rep]; !ok {
				mm[rep] = a1[i]
			} else if prev != a1[i] {
				fmt.Println(-1)
				return
			}
			for j := i; j < len(a1); j++ {
				if a1[j] == a1[i] && a2[j] != rep {
					fmt.Println(-1)
					return
				} else if a2[j] == rep && a1[j] != a1[i] {
					fmt.Println(-1)
					return
				}
				if a2[j] == rep {
					a2[j] = a1[i]
				} else if a2[j] == a1[i] {
					a2[j] = rep
				}
			}
		}
	}
	if string(a2) != str1 {
		fmt.Println(-1)
	} else {
		fmt.Println(len(mm))
		for k, v := range mm {
			fmt.Println(string(k), string(v))

		}
	}
}

func solve2() {
	str1 := readString()
	str2 := readString()
	mm := map[rune]rune{}
	for i := 0; i < len(str1); i++ {
		v := rune(str1[i])
		if prev, ok := mm[v]; !ok {
			mm[v] = rune(str2[i])
		} else if prev != rune(str2[i]) {
			fmt.Println(-1)
			return
		}
	}
	visited := map[rune]int{}
	lines := []string{}
	for k, v := range mm {
		if k != v {
			if visited[k] == 0 && visited[v] == 0 {
				lines = append(lines, fmt.Sprintln(string(v), string(k)))
				visited[k]++
				visited[v]++
			}
		}
	}
	fmt.Println(len(lines))
	for i := 0; i < len(lines); i++ {
		fmt.Print(lines[i])
	}
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

// IO

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

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

package main

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

func solve() {
	str1 := readString()
	str2 := readString()
	a1 := []rune(str1)
	a2 := []rune(str2)
	mm := map[rune]rune{}
	for i := 0; i < len(a1); i++ {
		if a1[i] != a2[i] {
			rep := a2[i]
			if prev, ok := mm[rep]; !ok {
				mm[rep] = a1[i]
			} else if prev != a1[i] {
				fmt.Println(-1)
				return
			}
			for j := i; j < len(a1); j++ {
				if a2[j] == rep {
					a2[j] = a1[i]
				} else if a2[j] == a1[i] {
					a2[j] = rep
				}
			}
		}
	}
	if string(a2) != str1 {
		fmt.Println(-1)
	} else {
		fmt.Println(len(mm))
		for k, v := range mm {
			fmt.Println(string(k), string(v))

		}
	}
}

func solve2() {
	str1 := readString()
	str2 := readString()
	mm := map[rune]rune{}
	for i := 0; i < len(str1); i++ {
		v := rune(str1[i])
		if prev, ok := mm[v]; !ok {
			mm[v] = rune(str2[i])
		} else if prev != rune(str2[i]) {
			fmt.Println(-1)
			return
		}
	}
	visited := map[rune]int{}
	lines := []string{}
	for k, v := range mm {
		if k != v {
			if visited[k] == 0 && visited[v] == 0 {
				lines = append(lines, fmt.Sprintln(string(v), string(k)))
				visited[k]++
				visited[v]++
			}
		}
	}
	fmt.Println(len(lines))
	for i := 0; i < len(lines); i++ {
		fmt.Print(lines[i])
	}
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

// IO

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

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

package main

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

func solve() {
	str1 := readString()
	str2 := readString()
	a1 := []rune(str1)
	a2 := []rune(str2)
	mm := map[rune]rune{}
	for i := 0; i < len(a1); i++ {
		if a1[i] != a2[i] {
			rep := a2[i]
			mm[a1[i]] = rep
			for j := i; j < len(a1); j++ {
				if a2[j] == rep {
					a2[j] = a1[i]
				} else if a2[j] == a1[i] {
					a2[j] = rep
				}
			}
		}
	}
	if string(a2) != str1 {
		fmt.Println(-1)
	} else {
		fmt.Println(len(mm))
		for k, v := range mm {
			fmt.Println(string(k), string(v))

		}
	}
}

func solve2() {
	str1 := readString()
	str2 := readString()
	mm := map[rune]rune{}
	for i := 0; i < len(str1); i++ {
		v := rune(str1[i])
		if prev, ok := mm[v]; !ok {
			mm[v] = rune(str2[i])
		} else if prev != rune(str2[i]) {
			fmt.Println(-1)
			return
		}
	}
	visited := map[rune]int{}
	lines := []string{}
	for k, v := range mm {
		if k != v {
			if visited[k] == 0 && visited[v] == 0 {
				lines = append(lines, fmt.Sprintln(string(v), string(k)))
				visited[k]++
				visited[v]++
			}
		}
	}
	fmt.Println(len(lines))
	for i := 0; i < len(lines); i++ {
		fmt.Print(lines[i])
	}
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

// IO

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

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

package main

import (
	"fmt"
)

func main() {
	var s string
	var t string

	fmt.Scan(&s, &t)

	n := len(s)

	var m map[uint8]uint8
	m = make(map[uint8]uint8)

	good := true

	for i := 0; i < n; i++ {
		c1, c2 := s[i], t[i]

		v1, ok1 := m[c1]

		if ok1 {
			if v1 != c2 {
				good = false
			}
		} else {
			m[c1] = c2
			m[c2] = c1
		}

		if good == false {
			break
		}
	}

	if good == false {
		fmt.Println(-1)
	} else {
		var mh map[uint8]uint8
		mh = make(map[uint8]uint8)

		for k, v := range m {
			_, ok1 := mh[k]
			_, ok2 := mh[v]

			if ok1 == false && ok2 == false && k != v {
				mh[k] = v
			}
		}

		fmt.Println(len(mh))
		for k, v := range mh {
			fmt.Println(string(k), string(v))
		}
	}
}


package main

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

func ReadInt(scanner *bufio.Scanner) int {
	if !scanner.Scan() {
		fmt.Printf("cant scan int: %s", scanner.Err())
	}
	str := scanner.Text()
	n, _ := strconv.Atoi(str)
	return n
}

func ReadIntArray(scanner *bufio.Scanner) []int {
	if !scanner.Scan() {
		fmt.Printf("cant scan array: %s", scanner.Err())
	}
	str := scanner.Text()
	tokens := strings.Split(str, " ")
	result := make([]int, len(tokens))
	for index, token := range tokens {
		n, _ := strconv.Atoi(token)
		result[index] = n
	}
	return result
}

func PrintIntArray(arr []int, writer *bufio.Writer) {
	strArray := fmt.Sprint(arr)
	_, _ = writer.WriteString(strArray[1:len(strArray)-1])
	_, _ =writer.Write([]byte{'\n'})
}

func PrintInt(number int, writer *bufio.Writer) {
	_, _ = writer.WriteString(strconv.Itoa(number))
	_, _ = writer.Write([]byte{'\n'})
}

func PrintFloat(number float64, writer *bufio.Writer) {
	_, _ = writer.WriteString(fmt.Sprintf("%.9f", number))
	_, _ = writer.Write([]byte{'\n'})
}

type Times struct {
	t1 float64
	t2 float64
}

func Solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	tmp := ReadIntArray(scanner)
	l := tmp[1]
	a := ReadIntArray(scanner)
	b := make([]Times, len(a)+2)

	t0 := 0.0
	v0 := 1.0
	prevPoint := 0.0
	for i, point := range a {
		b[i+1].t1 = t0 + (float64(point) - prevPoint) / v0
		v0 += 1.0
		t0 = b[i+1].t1
		prevPoint = float64(point)
	}
	b[len(b)-1].t1 = t0 + (float64(l) - prevPoint) / v0

	t0 = 0.0
	v0 = 1.0
	prevPoint = float64(l)
	for i := len(a)-1; i >= 0; i-- {
		b[i+1].t2 = t0 + (prevPoint - float64(a[i])) / v0
		v0 += 1.0
		t0 = b[i+1].t2
		prevPoint = float64(a[i])
	}
	b[0].t2 = t0 + prevPoint / v0

	result := 0.0
	for i, time := range b {
		if time.t1 < time.t2 {
			continue
		}
		pTime := b[i - 1]
		v1 := float64(i)
		v2 := float64(len(b) - i)
		var ds float64
		if i == 1 {
			ds = float64(a[0])
		} else if i == len(b) - 1 {
			ds = float64(l - a[len(a)-1])
		} else {
			ds = float64(a[i-1] - a[i-2])
		}
		dt := time.t2 - pTime.t1
		newT1 := pTime.t1
		if dt > 0 {
			ds -= dt * v1
			newT1 += dt
		} else {
			ds += dt * v2
		}
		result = newT1 + ds / (v1 + v2)
		break
	}
	PrintFloat(result, writer)
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	buf := make([]byte, 0, 256*1024)
	scanner.Buffer(buf, 1024*1024)
	writer := bufio.NewWriter(os.Stdout)
	t := ReadInt(scanner)
	for i := 0; i < t; i++ {
		Solve(scanner, writer)
	}
	_ = writer.Flush()
}

package main

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

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

func scan(a ...interface{}) (n int, err error) {
	return fmt.Fscan(in, a...)
}

var err error

func next() (n string) {
	scan(&n)
	return n
}

func nextInt() (n int) {
	scan(&n)
	return n
}

func nextLong() (n int64) {
	scan(&n)
	return n
}

func nextDouble() (n float64) {
	scan(&n)
	return n
}

func Max(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func solve() {
	n, l := nextInt(), nextInt()
	arr := make([]float64, n+2)
	for i := 1; i <= n; i++ {
		arr[i] = nextDouble()
	}
	arr[0], arr[n+1] = 0, float64(l)

	var curr float64 = 0
	for pow := float64(1 << 60); pow > 1e-10; pow /= 2 {
		tmp := curr + pow
		var x1, x2, t1, t2 float64 = 0, 0, tmp, tmp
		for i := 0; i <= n; i++ {
			if i == n || (arr[i+1]-arr[i])/float64(i+1) > t1 {
				x1 = arr[i] + t1*float64(i+1)
				break
			} else {
				t1 -= (arr[i+1] - arr[i]) / float64(i+1)
			}
		}
		for i := n + 1; i >= 0; i-- {
			if i == 0 || (arr[i]-arr[i-1])/float64(n-i+2) > t2 {
				x2 = arr[i] - t2*float64(n-i+2)
				break
			} else {
				t2 -= (arr[i] - arr[i-1]) / float64(n-i+2)
			}
		}
		if x1 < x2 {
			curr = tmp
		}
	}
	printf("%.9f\n", curr)
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)
	name := "in"
	file1, err := os.Open(name + ".in")
	if err == nil {
		in = bufio.NewReaderSize(file1, 8192)
	}
	// file2, err := os.Create(name + ".out")
	// if err != nil {
	// 	log.Fatal(err)
	// }
	// out = bufio.NewWriterSize(file2, 8192)
	defer out.Flush()
	// start := time.Now()

	for t, i := nextInt(), 1; t > 0; t, i = t-1, i+1 {
		// printf("Case #%d:\n", i)
		solve()
	}

	// printf("%v\n", time.Now().Sub(start))
}

package main

import "fmt"

func main() {
	test := 0
	fmt.Scan(&test)
	for test > 0 {
		n := 0
		k := 0
		fmt.Scan(&n)
		fmt.Scan(&k)
		v := 1.0
		v2 := 1.0
		t := 0.0
		t2 := 0.0
		d := 0.0
		d2 := float64(k)
		l := 0
		r := n - 1
		arr := []float64{}
		for n > 0 {
			var x float64
			fmt.Scan(&x)
			arr = append(arr, x)
			n--
		}
		for l <= r {
			if t+(arr[l]-d)/v < t2+(d2-arr[r])/v2 {
				t += (arr[l] - d) / v
				d = arr[l]
				v += 1.0
				l++
			} else {
				t2 += (d2 - arr[r]) / v2
				d2 = arr[r]
				v2 += 1.0
				r--
			}
		}
		if t > t2 {
			d2 -= v2 * (t - t2)
			t2 = t
		} else {
			d += v * (t2 - t)
			t = t2
		}
		fmt.Printf("%.7f\n", t+(d2-d)/(v+v2))
		test--
	}
}

package main

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

func main() {
	t := ReadInt()
	for i := 0; i < t; i++ {
		n, l := ReadInt(), ReadInt()
		a := make([]float64, n)
		for i := 0; i < n; i++ {
			Scan(&a[i])
		}
		fmt.Printf("%9.15f\n", solve(n, l, a))
	}
}

func solve(n int, l_ int, a []float64) float64 {
	l := float64(l_)
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = l - a[n-i-1]
	}

	ps := make([]float64, n+1)
	prev := 0.
	for i := 0; i < n; i++ {
		ps[i+1] = ps[i] + (a[i]-prev)/(float64(i)+1)
		prev = a[i]
	}

	qs := make([]float64, n+1)
	prev = 0.
	for i := 0; i < n; i++ {
		qs[i+1] = qs[i] + (b[i]-prev)/(float64(i)+1)
		prev = b[i]
	}

	lo := 0.
	hi := l
	for isLarge(hi, lo) {
		c := (hi + lo) / 2
		p := calcTime(c, a, ps)
		q := calcTime(l-c, b, qs)
		if p < q {
			lo = c
		} else {
			hi = c
		}
	}

	pos := (lo + hi) / 2
	return calcTime(pos, a, ps)
}

func isLarge(hi, lo float64) bool {
	// hi-lo > 1e-7
	return (hi-lo)/Max(1.0, lo) > 1e-13
}

func Max(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

func calcTime(pos float64, a, ps []float64) float64 {
	flags := sort.Search(len(a), func(i int) bool { return a[i] > pos })

	if flags == 0 {
		return pos
	}

	ret := 0.
	ret += ps[flags]
	diff := (pos - a[flags-1]) / float64(1+flags)
	ret += diff
	return ret
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }

package main

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

func solve() {
	t := readInt()

	for j := 0; j < t; j++ {
		n := readInt()
		l := readInt()
		a := make([]int, 0)
		a = append(a, 0)
		for i := 0; i < n; i++ {
			a = append(a, readInt())
		}
		a = append(a, l)

		leftSpeed := 1
		rightSpeed := 1

		leftIndex := 0
		rightIndex := len(a) - 2
		leftAt := float64(0)
		rightAt := float64(0)

		for leftIndex < rightIndex {
			tmpLeftAt := leftAt + float64(a[leftIndex+1]-a[leftIndex])/float64(leftSpeed)
			tmpRightAt := rightAt + float64(a[rightIndex+1]-a[rightIndex])/float64(rightSpeed)
			if tmpLeftAt < tmpRightAt {
				leftIndex++
				leftSpeed++
				leftAt = tmpLeftAt
			} else {
				rightIndex--
				rightSpeed++
				rightAt = tmpRightAt
			}
		}
		curTime := max(leftAt, rightAt)
		dist := float64(a[leftIndex+1] - a[leftIndex])
		if leftAt < rightAt {
			dist -= float64(leftSpeed) * (rightAt - leftAt)
		} else {
			dist -= float64(rightSpeed) * (leftAt - rightAt)
		}
		curTime += dist / float64(rightSpeed+leftSpeed)
		fmt.Printf("%.8f\n", curTime)
	}
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

// IO

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

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

func max(a, b float64) float64 {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

package main

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

func abs(a float64, b float64) float64 {
	if a > b {
		return a - b
	} else {
		return b - a
	}
}

func min(a float64, b float64) float64 {
	if a > b {
		return b
	}
	return a
}

func max(a float64, b float64) float64 {
	if a > b {
		return a
	}
	return b
}

func main()  {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var nt int
	fmt.Fscanf(reader, "%d\n", &nt)
	var n, L int
	for kk := 0; kk < nt; kk++ {
		fmt.Fscanf(reader, "%d %d\n", &n, &L)
		var a = make([]int, n + 2)
		for i := 1; i <= n; i++ {
			fmt.Fscanf(reader, "%d", &a[i])
		}

		fmt.Fscanf(reader, "\n")
		a[0] = 0
		a[n + 1] = L

		var timeL = make([]float64, n + 2)
		var timeR = make([]float64, n + 2)

		timeL[0] = 0
		for i := 1; i <= n + 1; i++ {
			timeL[i] = timeL[i - 1] + float64(a[i] - a[i - 1]) / float64(i)
		}

		timeR[n + 1] = 0
		for i := n; i >= 0; i-- {
			timeR[i] = timeR[i + 1] + float64(a[i + 1] - a[i]) / float64(n + 1 - i)
		}

		//fmt.Println(timeL)
		//fmt.Println(timeR)

		var ret = float64(L)

		for i := 0; i <= n; i++ {
			var fromLeft = timeL[i]
			var fromRight = timeR[i + 1]

			var speedLeft = i + 1
			var speedRight = n + 1 - i

			//fmt.Println("time: ", fromLeft, fromRight, "speed: ", speedLeft, speedRight)

			var delta = abs(fromLeft, fromRight)

			var leftPath = float64(a[i])
			var rightPath = float64(L - a[i + 1])

			if fromLeft < fromRight {
				leftPath += delta * float64(speedLeft)
			} else {
				rightPath += delta * float64(speedRight)
			}

			if leftPath + rightPath >= float64(L) {
				ret = min(ret, max(fromLeft, fromRight))
			} else {
				var remainPath = float64(L) - (leftPath + rightPath)
				ret = min(ret, max(fromLeft, fromRight) + remainPath / float64(speedLeft + speedRight))
			}
		}
		fmt.Fprintf(writer, "%f\n", ret)
	}
}


package main
import (
	"fmt"
)

func main() {
	var n,x int
	k:=0
	fmt.Scan(&n,&x)
	a:=make([]int,200)
	for i:=0;i<2*n;i++ {
		fmt.Scan(&a[i])
		if (a[i]==x) || (a[i]==(7-x)) {
			k++
		}
	}
	if k>0{
		fmt.Println("NO")
	} else {
		fmt.Println("YES")
	}
}

package main

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

func scanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	x, _ := strconv.Atoi(scanner.Text())
	return x
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	n := scanInt(scanner)
	above := 7 - scanInt(scanner)
	_, _ = scanInt(scanner), scanInt(scanner)
	for i := 1; i < n; i++ {
		a, b := scanInt(scanner), scanInt(scanner)
		no := make([]bool, 7)
		no[a] = true
		no[b] = true
		no[7-a] = true
		no[7-b] = true
		no[above] = true
		count := 0
		for j := 1; j < 7; j++ {
			if !no[j] {
				count++
				above = j
			}
		}
		if count != 1 {
			writer.WriteString("NO\n")
			return
		}
	}
	writer.WriteString("YES\n")
}

package main

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

func scanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	x, _ := strconv.Atoi(scanner.Text())
	return x
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	n := scanInt(scanner)
	above := 7 - scanInt(scanner)
	_, _ = scanInt(scanner), scanInt(scanner)
	for i := 1; i < n; i++ {
		a, b := scanInt(scanner), scanInt(scanner)
		no := make([]bool, 7)
		no[a] = true
		no[b] = true
		no[7-a] = true
		no[7-b] = true
		no[above] = true
		count, last := 0, -1
		for j := 1; j < 7; j++ {
			if !no[j] {
				count++
				last = j
			}
		}
		if count != 1 {
			writer.WriteString("NO\n")
			return
		}
		above = last
	}
	writer.WriteString("YES\n")
}

package main

import "fmt"

func main() {
    var n,x,a,b int
    fmt.Scan(&n)
    fmt.Scan(&x)
    ans := true
    for i := 0; i < n; i++ {
        fmt.Scan(&a,&b)
        if (x == a) || ((x+a) == 7) || (x == b) || ((x+b) == 7) {
            ans = false
        }
    }
    if ans { fmt.Println("YES") } else { fmt.Println("NO") }
}

package main

import "fmt"

func main() {
    var n,x,a,b int					// variabel n,x,a,b dengan jenis int
    fmt.Scan(&n)					// mengambil input
    fmt.Scan(&x)					// mengambil input
    ans := true						// variabel ans sama dengan true
    for i := 0; i < n; i++ {		// looping
        fmt.Scan(&a,&b)				// mengambil input kedua
        if (x == a) || ((x+a) == 7) || (x == b) || ((x+b) == 7) {  // jika x sama dengan a  atau x+a sama dengan 7 atau x sama dengan b atau x+b sama dengan 7
            ans = false				// ans sama dengan false
        }
    }
    if ans { fmt.Println("YES") } else { fmt.Println("NO") }  // jika ans maka cetak YES ,lainnya cetak NO
}

// 225A-mic
package main

import (
    "fmt"
)

func main() {
    var n, k, x, y int
    fmt.Scan(&n, &k)
    flag := true
    k = 7 - k
    for i := 1; i <= n; i++ {
        fmt.Scan(&x, &y)
        if x == k || x == 7-k || y == k || y == 7-k {
            flag = false
            break
        }
    }
    if flag {
        fmt.Println("YES")
    } else {
        fmt.Println("NO")
    }

}

// 225A-mic
package main

import (
	"fmt"
)

func main() {
	var n, k, x, y int
	fmt.Scan(&n, &k)
	flag := true
	for i := 1; i <= n; i++ {
		fmt.Scan(&x, &y)
		if x == k || x == y || x+k == 7 || x+y == 7 {
			flag = false
			break
		}
	}
	if flag {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}

}


package main

import "fmt"

var cost [5]int

func main() {
	fmt.Scan(&cost[1], &cost[2], &cost[3], &cost[4])
	var game string
	fmt.Scan(&game)

	sum := 0
	for _, c := range game {
		id := c - '0'
		sum += cost[id]
	}

	fmt.Println(sum)
}

package main
import "fmt"
func main() {
  var a[4] int
  fmt.Scanf("%d%d%d%d\n",&a[0],&a[1],&a[2],&a[3])
  var s string
  fmt.Scanln(&s)

  r := 0
  for _, c := range s {
    r += a[c-'1']
  }
  fmt.Println(r)
}

package main

import (
	"fmt"
	"strconv"
	"strings"
)

func solve(cMap []int, s string) {
	var sum int
	cs := strings.Split(s, "")
	for _, v := range cs {
		i, err := strconv.ParseInt(v, 10, 64)
		if err != nil {
			panic(err)
		}
		sum += cMap[i-1]
	}

	fmt.Println(sum)
}

func main() {
	var s string
	k := make([]int, 0, 4)

	var tmp int
	for i := 0; i < 4; i++ {
		fmt.Scan(&tmp)
		k = append(k, tmp)
	}

	_, err := fmt.Scan(&s)
	if err != nil {
		panic(err)
	}

	solve(k, s)
}

package main
import (
    "fmt"
    "unicode/utf8"
)
func main() {
    var a [5]int
    var str string
    fmt.Scan(&a[1],&a[2],&a[3],&a[4])
    fmt.Scan(&str)
    s :=0
    len:=utf8.RuneCountInString(str)
    for i:=0; i<len; i++ {
        s1:=int(str[i]-'0')
        //fmt.Println(s1)
        s+=a[s1]
    }
    fmt.Println(s)
}

package main

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

func main() {
	fourSquare := make([]int, 4)
	reader := bufio.NewReader(os.Stdin)
	for index := 0; index < 4; index++ {
		fmt.Fscan(reader, &fourSquare[index])
	}
	var valuesString string
	var result int
	fmt.Fscan(reader, &valuesString)
	for index := 0; index < len(valuesString); index++ {
		n, _ := strconv.Atoi(string(valuesString[index]))
		result += fourSquare[n-1]
	}
	fmt.Println(result)
}

package main

import (
	"fmt"
	"strconv"
)

func main() {
	strips:=make(map[int]int,4)
	var squares string
	var calories int
	for i:=0;i<4;i++{
		var cal int
		fmt.Scan(&cal)
		strips[i+1]=cal
	}
	fmt.Scan(&squares)

	for i,k:=range squares{
		toInt,_:=strconv.Atoi(string(k))
		calories+=strips[toInt]
		_=i
	}
	fmt.Println(calories)
}

package main

import ("fmt")

type set map[byte]bool
type long int64
type fl float64

func main(){
	var sum long
	a := make(map[string]int)
	var a1, a2, a3, a4 int
	scan(&a1, &a2, &a3, &a4)
	a["1"] = a1; a["2"] = a2; a["3"] = a3; a["4"] = a4
	var t string
	scan(&t)
	for _,v := range t{
		sum += long(a[string(v)])
	}
	sout(sum)
}

func scan(in ... interface{}){
	for _,k := range in{
		fmt.Scan(k)
	}
}

func sout(obj ... interface{}){
	for _, k := range obj{
		fmt.Print(k)
	}
	fmt.Println()
}

package main

import "fmt"

func main() {
    var a [4]int
    var s string
    for i := 0; i < 4; i++ { fmt.Scan(&a[i]) }
    fmt.Scan(&s)
    ans := 0
    for _, v := range s {
        in := int(v-'1')
        ans += a[in]
    }
    fmt.Println(ans)
}

package main

import (
	"fmt"
	"strconv"
)

func main() {
	caloriesPerStrips := []int{}
	for index := 0; index < 4; index++ {
		var element int
		fmt.Scan(&element)
		caloriesPerStrips = append(caloriesPerStrips, element)
	}
	var noOfCalories int
	var stringOfMoves string
	fmt.Scan(&stringOfMoves)

	for _, element := range stringOfMoves {
		element,_ := strconv.Atoi(string(element))
		noOfCalories = noOfCalories + caloriesPerStrips[element-1]
	}

	fmt.Print(noOfCalories)
}

// A. Black Square
/*
Quite recently, a very smart student named Jury decided that lectures are
boring, so he downloaded a game called "Black Square" on his super cool
touchscreen phone.

In this game, the phone's screen is divided into four vertical strips.
Each second, a black square appears on some of the strips. According to the
rules of the game, Jury must use this second to touch the corresponding strip
to make the square go away. As Jury is both smart and lazy, he counted that
he wastes exactly ai calories on touching the i-th strip.

You've got a string s, describing the process of the game and numbers a1, a2,
a3, a4. Calculate how many calories Jury needs to destroy all the squares?

Input
The first line contains four space-separated integers a1, a2, a3, a4
(0 ≤ a1, a2, a3, a4 ≤ 104).

The second line contains string s (1 ≤ |s| ≤ 105), where the і-th character
of the string equals "1", if on the i-th second of the game the square appears
on the first strip, "2", if it appears on the second strip, "3", if it appears
on the third strip, "4", if it appears on the fourth strip.

Output
Print a single integer — the total number of calories that Jury wastes.

Examples
Input
1 2 3 4
123214

Output
13

Input
1 5 3 2
11221

Output
13
*/
package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	input1, _ := reader.ReadString('\n')
	arr := strings.Split(strings.TrimSpace(input1), " ")

	input2, _ := reader.ReadString('\n')
	s := strings.TrimSpace(input2)

	total := 0
	for _, v := range s {
		i, _ := strconv.Atoi(string(v))

		a, _ := strconv.Atoi(arr[i-1])
		total += a
	}
	fmt.Print(total)
}

package main

import (
	"fmt"
	"strconv"
)

func main() {
	var calories [4]int
	fmt.Scanf("%d %d %d %d\n", &calories[0], &calories[1], &calories[2], &calories[3])
	// fmt.Println(calories)
	var s string
	fmt.Scanf("%s\n", &s)
	var totalCalories int
	for _, i := range s {
		x, _ := strconv.Atoi(string(i))
		// fmt.Println(i, x)

		totalCalories += calories[x-1]
	}
	fmt.Println(totalCalories)
}

package main

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

var scanner = bufio.NewScanner(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	a := make([]int, 4)

	for i:=0; i<4; i++ {
		// a[i] = nextInt()
		fmt.Scan(&a[i])
	}

	s := ""

	fmt.Scan(&s)

	calories := 0

	for i:=0; i<len(s); i++ {
		calories += a[s[i] - '0' - 1]
	}

	println(calories)
}

func next() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return n
}

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

func printf(format string, a ...interface{}) {
	fmt.Fprintf(writer, format, a...)
}

package main

import "fmt"

func main() {
	dic := map[rune]int{}

	for i := range make([]struct{}, 4) {
		var a int
		fmt.Scan(&a)
		dic[rune('0'+i+1)] = a
	}

	var s string
	fmt.Scan(&s)
	cnt := 0
	for _, v := range s {
		cnt += dic[v]
	}

	fmt.Println(cnt)
}

package main

import (
	"fmt"
)

func main() {
	var a, b, c, d, cals int
	fmt.Scanf("%d %d %d %d\n", &a, &b, &c, &d)
	var input string
	fmt.Scan(&input)
	var i int64
	for i = 0; i < int64(len(input)); i++ {
		switch string(input[i]) {
		case "1":
			cals += a
		case "2":
			cals += b
		case "3":
			cals += c
		case "4":
			cals += d
		}
	}
	fmt.Println(cals)
}

// func toInt(buf []byte) (n int) {
// 	for _, v := range buf {
// 		n = n*10 + int(v-'0')
// 	}
// 	return
// }

package main

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

func main() {
	io := newIo()
	dic := map[rune]int{}

	for i := range make([]struct{}, 4) {
		a := io.nextInt()
		dic[rune('0'+i+1)] = a
	}

	s := io.next()
	cnt := 0
	for _, v := range s {
		cnt += dic[v]
	}

	fmt.Println(cnt)
}

type _io struct {
	reader    *bufio.Reader
	tokens    []string
	nextToken int
}

func newIo() *_io {
	return &_io{
		reader: bufio.NewReader(os.Stdin),
	}
}

func (_io *_io) nextLine() string {
	var buffer []byte
	for {
		line, isPrefix, _ := _io.reader.ReadLine()
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (_io *_io) next() string {
	for _io.nextToken >= len(_io.tokens) {
		line := _io.nextLine()
		_io.tokens = strings.Fields(line)
		_io.nextToken = 0
	}
	r := _io.tokens[_io.nextToken]
	_io.nextToken++
	return r
}

func (_io *_io) nextInt() int {
	i, _ := strconv.Atoi(_io.next())
	return i
}

package main

import "fmt"

func main() {

    for {

        a := make([]int, 4)
        _, err := fmt.Scanf("%d %d %d %d", &a[0], &a[1], &a[2], &a[3]);
        if err != nil {
            //fmt.Println(err);
            break;
        }
        var b string
        var result int
        result = 0
        fmt.Scanf("%s", &b)
        fmt.Scanf("%s", &b)
        for _, i := range b {
            num := int(i - '0')
            result += a[num - 1]
        }
        fmt.Println(result);
    }
}

package main

import (
	"fmt"
)

func main() {
	var a [4]int
	for i := range a {
		fmt.Scan(&a[i])
	}
	var s string
	fmt.Scan(&s)
	z := 0
	for _, c := range s {
		z += a[int(c-'1')]
	}
	fmt.Println(z)
}

package main

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

func main() {
	var n1, n2, n3, n4 int16
	var sum uint32
	var s string
	in := bufio.NewReader(os.Stdin)
	fmt.Fscanf(in, "%d %d %d %d\n", &n1, &n2, &n3, &n4)
	fmt.Fscanf(in, "%s\n", &s)
	for i := 0; i < len(s); i++ {
		if string(s[i]) == "1" {
			sum += uint32(n1)
		} else if string(s[i]) == "2" {
			sum += uint32(n2)
		} else if string(s[i]) == "3" {
			sum += uint32(n3)
		} else if string(s[i]) == "4" {
			sum += uint32(n4)
		}
	}
	fmt.Println(sum)
}

package main

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

var scanner = bufio.NewScanner(os.Stdin)
var writer = bufio.NewWriter(os.Stdout)

//Wrong
func main() {
	defer writer.Flush()
	scanner.Split(bufio.ScanWords)

	a := make([]int, 4)

	for i:=0; i<4; i++ {
		a[i] = nextInt()
	}

	s := ""

	fmt.Scan(&s)

	calories := 0

	for i:=0; i<len(s); i++ {
		calories += a[s[i] - '0' - 1]
	}

	println(calories)
}

func next() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return n
}

func nextFloat() float64 {
	n, err := strconv.ParseFloat(next(), 64)
	if err != nil {
		panic(err)
	}
	return n
}

func println(a ...interface{}) {
	fmt.Fprintln(writer, a...)
}

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

func printf(format string, a ...interface{}) {
	fmt.Fprintf(writer, format, a...)
}

package main
import (
	"fmt"
	"unicode/utf8"
)
func main() {
	var a [5]int
	var str string
	fmt.Scan(&a[1],&a[2],&a[3],&a[4])
	fmt.Scan(&str)
	s :=0
	len:=utf8.RuneCountInString(str)
	for i:=0; i<len; i++ {
		s1:=int(str[i]-'0')
		fmt.Println(s1)
		s+=a[s1]
	}
	fmt.Println(s)
}

package main

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

func main() {
	var a, b, c, d, cals int64

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	scanner.Scan()
	a = toInt(scanner.Bytes())

	scanner.Scan()
	b = toInt(scanner.Bytes())

	scanner.Scan()
	c = toInt(scanner.Bytes())

	scanner.Scan()
	d = toInt(scanner.Bytes())

	scanner.Scan()
	input := scanner.Text()

	for i := 0; i < len(input); i++ {
		switch string(input[i]) {
		case "1":
			cals += a
		case "2":
			cals += b
		case "3":
			cals += c
		case "4":
			cals += d
		}
	}
	fmt.Println(cals)
}

func toInt(buf []byte) (n int64) {
	for _, v := range buf {
		n = n*10 + int64(v-'0')
	}
	return
}

package main

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

func main() {
	var a, b, c, d, cals int64

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	scanner.Scan()
	a = toInt(scanner.Bytes())

	scanner.Scan()
	b = toInt(scanner.Bytes())

	scanner.Scan()
	c = toInt(scanner.Bytes())

	scanner.Scan()
	d = toInt(scanner.Bytes())

	scanner.Scan()
	input := scanner.Text()
	var i int64
	for i = 0; i < int64(len(input)); i++ {
		switch string(input[i]) {
		case "1":
			cals += a
		case "2":
			cals += b
		case "3":
			cals += c
		case "4":
			cals += d
		}
	}
	fmt.Println(cals)
}

func toInt(buf []byte) (n int64) {
	for _, v := range buf {
		n = n*10 + int64(v-'0')
	}
	return
}

package main

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

func main() {
	var a, b, c, d, cals int
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(scanner.Bytes(), math.MaxInt32)

	scanner.Scan()
	a = toInt(scanner.Bytes())

	scanner.Scan()
	b = toInt(scanner.Bytes())

	scanner.Scan()
	c = toInt(scanner.Bytes())

	scanner.Scan()
	d = toInt(scanner.Bytes())

	var input string
	fmt.Scan(&input)

	for i := 0; i < len(input); i++ {
		switch string(input[i]) {
		case "1":
			cals += a
		case "2":
			cals += b
		case "3":
			cals += c
		case "4":
			cals += d
		}
	}
	fmt.Println(cals)
}

func toInt(buf []byte) (n int) {
	for _, v := range buf {
		n = n*10 + int(v-'0')
	}
	return
}

package main

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

func main() {
	var a, b, c, d, cals int
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	scanner.Scan()
	a = toInt(scanner.Bytes())

	scanner.Scan()
	b = toInt(scanner.Bytes())

	scanner.Scan()
	c = toInt(scanner.Bytes())

	scanner.Scan()
	d = toInt(scanner.Bytes())

	var input string
	fmt.Scan(&input)

	for i := 0; i < len(input); i++ {
		switch string(input[i]) {
		case "1":
			cals += a
		case "2":
			cals += b
		case "3":
			cals += c
		case "4":
			cals += d
		}
	}
	fmt.Println(cals)
}

func toInt(buf []byte) (n int) {
	for _, v := range buf {
		n = n*10 + int(v-'0')
	}
	return
}

package main

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

func main() {
	var a, b, c, d, cals int

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	scanner.Scan()
	a = toInt(scanner.Bytes())

	scanner.Scan()
	b = toInt(scanner.Bytes())

	scanner.Scan()
	c = toInt(scanner.Bytes())

	scanner.Scan()
	d = toInt(scanner.Bytes())

	scanner.Scan()
	input := scanner.Text()

	for i := 0; i < len(input); i++ {
		switch string(input[i]) {
		case "1":
			cals += a
		case "2":
			cals += b
		case "3":
			cals += c
		case "4":
			cals += d
		}
	}
	fmt.Println(cals)
}

func toInt(buf []byte) (n int) {
	for _, v := range buf {
		n = n*10 + int(v-'0')
	}
	return
}

package main

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

func main() {
	var a, b, c, d, cals int
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	scanner.Scan()
	a = toInt(scanner.Bytes())

	scanner.Scan()
	b = toInt(scanner.Bytes())

	scanner.Scan()
	c = toInt(scanner.Bytes())

	scanner.Scan()
	d = toInt(scanner.Bytes())

	var input string
	fmt.Scan(&input)
	var i int64
	for i = 0; i < int64(len(input)); i++ {
		switch string(input[i]) {
		case "1":
			cals += a
		case "2":
			cals += b
		case "3":
			cals += c
		case "4":
			cals += d
		}
	}
	fmt.Println(cals)
}

func toInt(buf []byte) (n int) {
	for _, v := range buf {
		n = n*10 + int(v-'0')
	}
	return
}

package main

import "fmt"

func main() {

    for {

        a := make([]int, 4)
        _, err := fmt.Scanf("%d %d %d %d", &a[0], &a[1], &a[2], &a[3]);
        if err != nil {
            //fmt.Println(err);
            break;
        }
        var b string
        var result int
        result = 0
        fmt.Scanf("%s", &b)
        for _, i := range b {
            num := int(i - '0')
            result += a[num - 1]
        }
        fmt.Println(result);
    }
}

package main

import "fmt"

func main() {

    for {

        a := make([]int, 4)
        _, err := fmt.Scanf("%d %d %d %d", &a[0], &a[1], &a[2], &a[3]);
        if err != nil {
            fmt.Println(err);
            break;
        }
        //fmt.Printf("%d %d %d %d", a[0], a[1], a[2], a[3]);

        var b string
        var result int
        result = 0
        fmt.Scanf("%s", &b)
        //for _, i := range b {
         //   fmt.Println(i);
       // }
        for _, i := range b {
            num := int(i - '0')
         //   fmt.Println(result, num)
            result += a[num - 1]
        }
        fmt.Println(result);
       // fmt.Println(a,b)
    }
}

package main

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

func main() {
	var n1, n2, n3, n4, sum int16
	var s string
	in := bufio.NewReader(os.Stdin)
	fmt.Fscanf(in, "%d %d %d %d\n", &n1, &n2, &n3, &n4)
	fmt.Fscanf(in, "%s\n", &s)
	for i := 0; i < len(s); i++ {
		if string(s[i]) == "1" {
			sum += n1
		} else if string(s[i]) == "2" {
			sum += n2
		} else if string(s[i]) == "3" {
			sum += n3
		} else if string(s[i]) == "4" {
			sum += n4
		}
	}
	fmt.Println(sum)
}

package main
import "fmt"
func main() {
  var a[4] int
  fmt.Scanf("%d%d%d%d",&a[0],&a[1],&a[2],&a[3])
  var s string
  fmt.Scanln(&s)

  r := 0
  for _, c := range s {
    r += a[c-'1']
  }
  fmt.Println(r)
}


package main

import "fmt"

func main() {
    var n,m int
    fmt.Scan(&n,&m)
    fmt.Println(n+m-1)
    for i := 1; i <= m; i++ {
        fmt.Println("1",i)
    }
    for i := 2; i <= n; i++ {
        fmt.Println(i,"1")
    }
}

package main

import (
    "fmt"
)

func main() {
    var n, m int
    fmt.Scanf("%d %d", &n, &m)

    fmt.Println(n + m - 1)

    for i := 1; i <= n; i++ {
        fmt.Printf("%d 1\n", i)
    }

    for i := 2; i <= m; i++ {
        fmt.Printf("1 %d\n", i)
    }
}

package main

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

type Cacher struct {
	buf []byte
	cnt int
	w   io.Writer
}

func (c *Cacher) Write(b []byte) (n int, err error) {
	if b == nil {
		n, err = fmt.Fprintf(c.w, "%d\n%s", c.cnt, c.buf)
		return
	} else {
		c.buf = append(c.buf, b...)
		c.cnt++
		return 0, nil
	}
}

func main() {
	var n, m int
	fmt.Scanf("%d %d", &n, &m)

	c := &Cacher{w: os.Stdout}

	for i := 1; i <= n; i++ {
		fmt.Fprintf(c, "%d 1\n", i)
	}

	for i := 2; i <= m; i++ {
		fmt.Fprintf(c, "1 %d\n", i)
	}
	c.Write(nil)
}

package main
import (
	"fmt"
	//"unicode/utf8"
	//"strconv"
)

func main() {
	var n,m int
	fmt.Scan(&n,&m)
	fmt.Println(n+m-1)
	for i:=1;i<=m;i++ {
		fmt.Printf("1 %d\n",i)
	}

	for i:=2;i<=n;i++ {
		fmt.Printf("%d 1\n",i)
	}
}

package main

import "fmt"

func main(){
        var a, b int
        fmt.Scan(&a, &b)
        fmt.Println(a+b-1)
        for i:=1; i<=b; i++ {
                fmt.Println(1, i)
        }
        for i:=2; i<=a; i++ {
                fmt.Println(i, 1)
        }
}

package main

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

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer := bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  n, m := getI(), getI()
  total := n+m-1
  writer.WriteString(fmt.Sprintf("%d\n", total))
  for i := 1; i <= m; i++ {
    writer.WriteString(fmt.Sprintf("1 %d\n", i))
  }
  for i := 2; i <= n; i++ {
    writer.WriteString(fmt.Sprintf("%d 1\n", i))
  }
}

package main

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

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

func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }

func getLine() string {
	s, _ := reader.ReadString('\n')
	if strings.HasSuffix(s, "\r\n") {
		s = s[:len(s)-2]
	} else if strings.HasSuffix(s, "\n") {
		s = s[:len(s)-1]
	}
	return s
}
func getLine2Int() (n int) {
	scanf("%d\n", &n)
	return
}
func getLine2Int2() (a, b int) {
	scanf("%d %d\n", &a, &b)
	return
}
func getLine2Ints(n int) []int {
	ans := make([]int, n)
	for i := 0; i < n; i++ {
		scanf("%d ", &ans[i])
	}
	scanf("%d\n", &ans[n-1])
	return ans
}

var debug = false

func see(a interface{}) {
	if debug {
		printf("DEBUG:%v\n", a)
	}
}

func main() {
	defer writer.Flush()

	n, m := getLine2Int2()
	printf("%d\n", m+n-1)
	for i := 1; i <= m; i++ {
		printf("%d %d\n", 1, i)
	}
	for i := 2; i <= n; i++ {
		printf("%d %d\n", i, m)
	}
}

// 322A
package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	fmt.Println(n + m - 1)
	for i := 1; i <= m; i++ {
		fmt.Println("1 ", i)
	}
	for i := 2; i <= n; i++ {
		fmt.Println(i, " 1")
	}
}

package main

import (
  "bufio"
  "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 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') }

func main() {
  sc.Split(bufio.ScanWords)
  n, m := ni(), ni()
  a, b := make([]int, 0), make([]int, 0)

  if n <= m {
    for i := 0; i < m; i++ {
      a = append(a, 1)
      b = append(b, i+1)
    }
    for i := 1; i < n; i++ {
      a = append(a, i+1)
      b = append(b, 1)
    }
  } else {
    for i := 0; i < n; i++ {
      a = append(a, i+1)
      b = append(b, 1)
    }
    for i := 1; i < m; i++ {
      a = append(a, 1)
      b = append(b, i+1)
    }
  }
  pri(len(a))
  endl()
  for i := 0; i < len(a); i++ {
    pri(a[i])
    sp()
    pri(b[i])
    endl()
  }
  w.Flush()
}

// 38A-mic
package main

import (
    "fmt"
)

func main() {
    var n, m int
    j := 1
    fmt.Scan(&n, &m)
    fmt.Println(n + m - 1)
    for i := 1; i <= n; i++ {
        for ; j <= m; j++ {
            fmt.Print(i)
            fmt.Print(" ")
            fmt.Print(j)
            fmt.Println()
            if j >= m {
                break
            }
        }
    }
}

package main

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

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

func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }

func getLine() string {
	s, _ := reader.ReadString('\n')
	if strings.HasSuffix(s, "\r\n") {
		s = s[:len(s)-2]
	} else if strings.HasSuffix(s, "\n") {
		s = s[:len(s)-1]
	}
	return s
}
func getLine2Int() (n int) {
	scanf("%d\n", &n)
	return
}
func getLine2Int2() (a, b int) {
	scanf("%d %d\n", &a, &b)
	return
}
func getLine2Ints(n int) []int {
	ans := make([]int, n)
	for i := 0; i < n; i++ {
		scanf("%d ", &ans[i])
	}
	scanf("%d\n", &ans[n-1])
	return ans
}

var debug = false

func see(a interface{}) {
	if debug {
		printf("DEBUG:%v\n", a)
	}
}

func main() {
	defer writer.Flush()

	n, m := getLine2Int2()
	printf("%d\n", m+n+1)
	for i := 1; i <= m; i++ {
		printf("%d %d\n", 1, i)
	}
	for i := 2; i <= n; i++ {
		printf("%d %d\n", i, m)
	}
}

package main

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

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

func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }

func getLine() string {
	s, _ := reader.ReadString('\n')
	if strings.HasSuffix(s, "\r\n") {
		s = s[:len(s)-2]
	} else if strings.HasSuffix(s, "\n") {
		s = s[:len(s)-1]
	}
	return s
}
func getLine2Int() (n int) {
	scanf("%d\n", &n)
	return
}
func getLine2Int2() (a, b int) {
	scanf("%d %d\n", &a, &b)
	return
}
func getLine2Ints(n int) []int {
	ans := make([]int, n)
	for i := 0; i < n; i++ {
		scanf("%d ", &ans[i])
	}
	scanf("%d\n", &ans[n-1])
	return ans
}

var debug = false

func see(a interface{}) {
	if debug {
		printf("DEBUG:%v\n", a)
	}
}

func d(p, a, b byte) (bool, byte) {
	return p >= a && p <= b, p - a
}

func main() {
	defer writer.Flush()

	n := getLine2Int()
	if n <= 0 {
		return
	}
	s := getLine()
	var c [26]bool
	for i := 0; i < len(s); i++ {
		if ok, t := d(s[i], 'a', 'z'); ok {
			c[t] = ok
		}
		if ok, t := d(s[i], 'A', 'Z'); ok {
			c[t] = ok
		}
	}
	ok := true
	for i := 0; ok && i < len(c); i++ {
		if !c[i] {
			ok = false
		}
	}

	if ok {
		printf("YES\n")
	} else {
		printf("NO\n")
	}
}


package main

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

/* solution */

func solve() {

	n, m := readInt(), readInt()

	e := make([][2]int, m+1)
	color := make([]int, n+1) // color
	color[1] = 0
	r, g, b := n, 0, 0
	firstG := -1
	conn := make([]int, n+1) // connections

	for i := 1; i <= m; i++ {
		u, v := readInt(), readInt()
		conn[u]++
		conn[v]++
		if u == 1 || v == 1 {
			color[u+v-1] = 1
			r--
			g++
			if firstG == -1 {
				firstG = u + v - 1
			}
		}
		e[i][0] = u
		e[i][1] = v
	}

	for i := 1; i <= m; i++ {
		u, v := e[i][0], e[i][1]
		if u == firstG || v == firstG {
			if color[u+v-firstG] == 1 {
				color[u+v-firstG] = 2
				g--
				b++
			}
		}
	}

	ok := true
	for i := 1; i <= n; i++ {
		switch color[i] {
		case 0:
			ok = ok && conn[i] == g+b
		case 1:
			ok = ok && conn[i] == r+b
		case 2:
			ok = ok && conn[i] == r+g
		}
	}

	if r <= 0 || g <= 0 || b <= 0 || !ok {
		printInt(-1)
		return
	}

	for i := 1; i <= m; i++ {
		u, v := e[i][0], e[i][1]
		if color[u] == color[v] {
			printInt(-1)
			return
		}
	}

	for i := 1; i <= n; i++ {
		printInt(color[i] + 1)
	}

}

/* stubs */

func main() {

	var f *os.File
	if runtime.GOROOT() == "C:\\Soft\\Go" {
		f, _ = os.Open("input.txt")
		defer f.Close()
	} else {
		f = os.Stdin
	}

	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	reader = bufio.NewScanner(f)

	const maxCapacity = 1024 * 1024
	buf := make([]byte, maxCapacity)
	reader.Buffer(buf, maxCapacity)

	reader.Split(bufio.ScanWords)

	solve()

}

var reader *bufio.Scanner
var writer *bufio.Writer

func read() string {
	reader.Scan()
	return reader.Text()
}

func readInt() int {
	reader.Scan()
	ret, _ := strconv.Atoi(reader.Text())
	return ret
}

func print(s string) {
	writer.WriteString(s)
	writer.WriteString("\n")
}

func printInt(i int) {
	print(strconv.Itoa(i))
}

func printInt64(i int64) {
	print(strconv.FormatInt(i, 10))
}

func readInt64() int64 {
	reader.Scan()
	ret, _ := strconv.ParseInt(reader.Text(), 10, 64)
	return ret
}

package main

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

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

	var n, m int
	Fscan(in, &n, &m)
	powP := make([]uint64, n+1)
	powP[0] = 1
	const prime uint64 = 1610612741
	for i := 1; i <= n; i++ {
		powP[i] = powP[i-1] * prime
	}
	hash := make([]uint64, n+1)
	for ; m > 0; m-- {
		var x, y int
		Fscan(in, &x, &y)
		hash[x] += powP[y]
		hash[y] += powP[x]
	}

	mp := map[uint64]int{}
	idx := 0
	for i := 1; i <= n; i++ {
		if hash[i] == 0 {
			Fprint(out, -1)
			return
		}
		if mp[hash[i]] == 0 {
			idx++
			mp[hash[i]] = idx
		}
	}
	if idx != 3 {
		Fprint(out, -1)
		return
	}
	for _, h := range hash[1:] {
		Fprint(out, mp[h], " ")
	}
}

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

package main

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

/* solution */

func solve() {

	n, m := readInt(), readInt()

	e := make([][2]int, m+1)
	color := make([]int, n+1) // color
	color[1] = 0
	r, g, b := n, 0, 0
	firstG := -1
	conn := make([]int, n+1) // connections

	for i := 1; i <= m; i++ {
		u, v := readInt(), readInt()
		conn[u]++
		conn[v]++
		if u == 1 || v == 1 {
			color[u+v-1] = 1
			r--
			g++
			if firstG == -1 {
				firstG = u + v - 1
			}
		}
		e[i][0] = u
		e[i][1] = v
	}

	for i := 1; i <= m; i++ {
		u, v := e[i][0], e[i][1]
		if color[u] == 1 && color[v] == 1 {
			color[v] = 2
			g--
			b++
		}
	}

	ok := true
	for i := 1; i <= n; i++ {
		switch color[i] {
		case 0:
			ok = ok && conn[i] == g+b
		case 1:
			ok = ok && conn[i] == r+b
		case 2:
			ok = ok && conn[i] == r+g
		}
	}

	if r <= 0 || g <= 0 || b <= 0 || !ok {
		printInt(-1)
		return
	}

	for i := 1; i <= m; i++ {
		u, v := e[i][0], e[i][1]
		if color[u] == color[v] {
			printInt(-1)
			return
		}
	}

	for i := 1; i <= n; i++ {
		printInt(color[i] + 1)
	}

}

/* stubs */

func main() {

	var f *os.File
	if runtime.GOROOT() == "C:\\Soft\\Go" {
		f, _ = os.Open("input.txt")
		defer f.Close()
	} else {
		f = os.Stdin
	}

	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	reader = bufio.NewScanner(f)

	const maxCapacity = 1024 * 1024
	buf := make([]byte, maxCapacity)
	reader.Buffer(buf, maxCapacity)

	reader.Split(bufio.ScanWords)

	solve()

}

var reader *bufio.Scanner
var writer *bufio.Writer

func read() string {
	reader.Scan()
	return reader.Text()
}

func readInt() int {
	reader.Scan()
	ret, _ := strconv.Atoi(reader.Text())
	return ret
}

func print(s string) {
	writer.WriteString(s)
	writer.WriteString("\n")
}

func printInt(i int) {
	print(strconv.Itoa(i))
}

func printInt64(i int64) {
	print(strconv.FormatInt(i, 10))
}

func readInt64() int64 {
	reader.Scan()
	ret, _ := strconv.ParseInt(reader.Text(), 10, 64)
	return ret
}