package main

import (
	"fmt"
	"math"
)

const debug = false

type Deque struct {
	data []int
	size int

	begin, end int
}

func NewDeque(size int) Deque {
	return Deque{
		data: make([]int, size),
		size: size,

		begin: 0,
		end:   0,
	}
}

func (deque *Deque) Size() int {
	return deque.end - deque.begin
}

func (deque *Deque) Pop() int {
	element := deque.data[deque.begin]
	deque.begin++

	if debug {
		fmt.Println("Pop ", deque.data[deque.begin:deque.end])
	}
	return element
}

func (deque *Deque) Push(element int) {
	deque.data[deque.end] = element
	deque.end++

	if debug {
		fmt.Println("Push", deque.data[deque.begin:deque.end])

	}
}

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

	if debug {
		fmt.Println(n, k0)
	}

	k := int(math.Min(float64(k0), float64(n-1)))

	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
	}

	if debug {
		fmt.Println(a)
	}

	players := NewDeque(25000000)
	for _, player := range a {
		players.Push(player)
	}

	current := players.Pop()
	amount := 0

	for {
		opponent := players.Pop()

		if debug {
			fmt.Println(current, opponent)
		}

		if opponent < current {
			players.Push(opponent)

			amount++
		} else {
			players.Push(current)

			current = opponent
			amount = 1
		}

		if amount >= k {
			fmt.Println(current)
			break
		}
	}
}

package main

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

func Init() {
}

func Solve(io *FastIO) {
	N := io.NextInt()
	K := io.NextLong()
	A := io.NextIntArray(N)

	best := A[0]
	winner := A[0]
	consec := 0
	for i := 1; i < N; i++ {
		if winner > A[i] {
			consec++
			if int64(consec) >= K {
				io.Println(winner)
				return
			}
		} else {
			consec = 1
			best = A[i]
			winner = A[i]
		}
	}
	io.Println(best)
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

func IsLineBreakChar(c byte) bool {
	switch c {
		case 0, '\n', '\r':
			return true
		default:
			return false
	}
}

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}

package main

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

func solve() {
	n := readInt()
	k := readInt64()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = readInt()
	}
	if a[0] < a[1] {
		a[0], a[1] = a[1], a[0]
	}
	wins := int64(0)
	for i := 1; i < n; i++ {
		if a[i-1] > a[i] {
			a[i-1], a[i] = a[i], a[i-1]
			wins++
		} else {
			wins = 1
		}
		if wins == k {
			fmt.Println(a[i])
			return
		}
	}
	fmt.Println(a[len(a)-1])
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

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

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
}

package main

import (
	"fmt"
)

type Deque struct {
	data []int
	size int

	begin, end int
}

func NewDeque(size int) Deque {
	return Deque{
		data: make([]int, size),
		size: size,

		begin: 0,
		end:   0,
	}
}

func (deque *Deque) Size() int {
	return deque.end - deque.begin
}

func (deque *Deque) Pop() int {
	element := deque.data[deque.begin]
	deque.begin++

	return element
}

func (deque *Deque) Push(element int) {
	fmt.Println(deque.data)

	deque.data[deque.end] = element
	deque.end++
}

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

	//k = int(math.Min(float64(k), float64(n-1)))

	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
	}

	players := NewDeque(10)
	for _, player := range a {
		players.Push(player)
	}

	current := players.Pop()
	amount := 0

	for {
		opponent := players.Pop()

		fmt.Println(current, opponent)

		if opponent < current {
			players.Push(opponent)

			amount++
		} else {
			players.Push(current)

			current = opponent
			amount = 0
		}

		if amount >= k {
			fmt.Println(current)
			break
		}
	}
}

package main

import (
	"fmt"
	"math"
)

type Deque struct {
	data []int
	size int

	begin, end int
}

func NewDeque(size int) Deque {
	return Deque{
		data: make([]int, size),
		size: size,

		begin: 0,
		end:   0,
	}
}

func (deque *Deque) Size() int {
	return deque.end - deque.begin
}

func (deque *Deque) Pop() int {
	element := deque.data[deque.begin]
	deque.begin++

	return element
}

func (deque *Deque) Push(element int) {
	deque.data[deque.end] = element
	deque.end++
}

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

	k = int(math.Min(float64(k), float64(n-1)))

	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
	}

	players := NewDeque(10000000)
	for _, player := range a {
		players.Push(player)
	}

	current := players.Pop()
	amount := 0

	for {
		opponent := players.Pop()

		if opponent < current {
			players.Push(opponent)

			amount += 1
		} else {
			players.Push(current)

			current = opponent
			amount = 0
		}

		if amount >= k {
			fmt.Println(current)
			break
		}
	}
}

package main

import (
	"fmt"
)

type Deque struct {
	data []int
	size int

	begin, end int
}

func NewDeque(size int) Deque {
	return Deque{
		data: make([]int, size),
		size: size,

		begin: 0,
		end:   0,
	}
}

func (deque *Deque) Size() int {
	return deque.end - deque.begin
}

func (deque *Deque) Pop() int {
	element := deque.data[deque.begin]
	deque.begin++

	fmt.Println("Pop ", deque.data, deque.begin, deque.end)
	return element
}

func (deque *Deque) Push(element int) {
	deque.data[deque.end] = element
	deque.end++

	fmt.Println("Push", deque.data, deque.begin, deque.end)
}

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

	//k = int(math.Min(float64(k), float64(n-1)))

	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
	}

	fmt.Println(a)

	players := NewDeque(10)
	for _, player := range a {
		players.Push(player)
	}

	current := players.Pop()
	amount := 0

	for {
		opponent := players.Pop()

		fmt.Println(current, opponent)

		if opponent < current {
			players.Push(opponent)

			amount++
		} else {
			players.Push(current)

			current = opponent
			amount = 0
		}

		if amount >= k {
			fmt.Println(current)
			break
		}
	}
}

package main

import (
	"fmt"
)

type Deque struct {
	data []int
	size int

	begin, end int
}

func NewDeque(size int) Deque {
	return Deque{
		data: make([]int, size),
		size: size,

		begin: 0,
		end:   0,
	}
}

func (deque *Deque) Size() int {
	return deque.end - deque.begin
}

func (deque *Deque) Pop() int {
	element := deque.data[deque.begin]
	deque.begin++

	fmt.Println("Pop ", deque.data, deque.begin, deque.end)
	return element
}

func (deque *Deque) Push(element int) {
	deque.data[deque.end] = element
	deque.end++

	fmt.Println("Push", deque.data, deque.begin, deque.end)
}

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

	//k = int(math.Min(float64(k), float64(n-1)))

	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
	}

	players := NewDeque(10)
	for _, player := range a {
		players.Push(player)
	}

	current := players.Pop()
	amount := 0

	for {
		opponent := players.Pop()

		fmt.Println(current, opponent)

		if opponent < current {
			players.Push(opponent)

			amount++
		} else {
			players.Push(current)

			current = opponent
			amount = 0
		}

		if amount >= k {
			fmt.Println(current)
			break
		}
	}
}

package main

import (
	"fmt"
	"math"
)

type Deque struct {
	data []int
	size int

	begin, end int
}

func NewDeque(size int) Deque {
	return Deque{
		data: make([]int, size),
		size: size,

		begin: 0,
		end:   0,
	}
}

func (deque *Deque) Size() int {
	return deque.end - deque.begin
}

func (deque *Deque) Pop() int {
	element := deque.data[deque.begin]
	deque.begin++

	return element
}

func (deque *Deque) Push(element int) {
	deque.data[deque.end] = element
	deque.end++
}

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

	k = int(math.Min(float64(k), float64(n-1)))

	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
	}

	players := NewDeque(1000)
	for _, player := range a {
		players.Push(player)
	}

	current := players.Pop()
	amount := 0

	for {
		opponent := players.Pop()

		fmt.Println(current, opponent)

		if opponent < current {
			players.Push(opponent)

			amount += 1
		} else {
			players.Push(current)

			current = opponent
			amount = 0
		}

		if amount >= k {
			fmt.Println(current)
			break
		}
	}
}

package main

import (
	"fmt"
	"math"
)

const debug = false

type Deque struct {
	data []int
	size int

	begin, end int
}

func NewDeque(size int) Deque {
	return Deque{
		data: make([]int, size),
		size: size,

		begin: 0,
		end:   0,
	}
}

func (deque *Deque) Size() int {
	return deque.end - deque.begin
}

func (deque *Deque) Pop() int {
	element := deque.data[deque.begin]
	deque.begin++

	if debug {
		fmt.Println("Pop ", deque.data, deque.begin, deque.end)
	}
	return element
}

func (deque *Deque) Push(element int) {
	deque.data[deque.end] = element
	deque.end++

	if debug {
		fmt.Println("Push", deque.data, deque.begin, deque.end)

	}
}

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

	k = int(math.Min(float64(k), float64(n-1)))

	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
	}

	if debug {
		fmt.Println(a)
	}

	players := NewDeque(10000000)
	for _, player := range a {
		players.Push(player)
	}

	current := players.Pop()
	amount := 0

	for {
		opponent := players.Pop()

		if debug {
			fmt.Println(current, opponent)
		}

		if opponent < current {
			players.Push(opponent)

			amount++
		} else {
			players.Push(current)

			current = opponent
			amount = 0
		}

		if amount >= k {
			fmt.Println(current)
			break
		}
	}
}

package main

import (
	"fmt"
	"math"
)

type Deque struct {
	data []int
	size int

	begin, end int
}

func NewDeque(size int) Deque {
	return Deque{
		data: make([]int, size),
		size: size,

		begin: 0,
		end:   0,
	}
}

func (deque *Deque) Size() int {
	return deque.end - deque.begin
}

func (deque *Deque) Pop() int {
	element := deque.data[deque.begin]
	deque.begin++

	//fmt.Println("Pop ", deque.data, deque.begin, deque.end)
	return element
}

func (deque *Deque) Push(element int) {
	deque.data[deque.end] = element
	deque.end++

	//fmt.Println("Push", deque.data, deque.begin, deque.end)
}

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

	k = int(math.Min(float64(k), float64(n-1)))

	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
	}

	//fmt.Println(a)

	players := NewDeque(30000000)
	for _, player := range a {
		players.Push(player)
	}

	current := players.Pop()
	amount := 0

	for {
		opponent := players.Pop()

		//fmt.Println(current, opponent)

		if opponent < current {
			players.Push(opponent)

			amount++
		} else {
			players.Push(current)

			current = opponent
			amount = 0
		}

		if amount >= k {
			fmt.Println(current)
			break
		}
	}
}

package main

import (
	"fmt"
	"math"
)

const debug = false

type Deque struct {
	data []int
	size int

	begin, end int
}

func NewDeque(size int) Deque {
	return Deque{
		data: make([]int, size),
		size: size,

		begin: 0,
		end:   0,
	}
}

func (deque *Deque) Size() int {
	return deque.end - deque.begin
}

func (deque *Deque) Pop() int {
	element := deque.data[deque.begin]
	deque.begin++

	if debug {
		fmt.Println("Pop ", deque.data, deque.begin, deque.end)
	}
	return element
}

func (deque *Deque) Push(element int) {
	deque.data[deque.end] = element
	deque.end++

	if debug {
		fmt.Println("Push", deque.data, deque.begin, deque.end)

	}
}

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

	if debug {
		fmt.Println(n, k0)
	}

	k := int(math.Min(float64(k0), float64(n-1)))

	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
	}

	if debug {
		fmt.Println(a)
	}

	players := NewDeque(10000000)
	for _, player := range a {
		players.Push(player)
	}

	current := players.Pop()
	amount := 0

	for {
		opponent := players.Pop()

		if debug {
			fmt.Println(current, opponent)
		}

		if opponent < current {
			players.Push(opponent)

			amount++
		} else {
			players.Push(current)

			current = opponent
			amount = 0
		}

		if amount >= k {
			fmt.Println(current)
			break
		}
	}
}

package main

import (
	"fmt"
)

type Deque struct {
	data []int
	size int

	begin, end int
}

func NewDeque(size int) Deque {
	return Deque{
		data: make([]int, size),
		size: size,

		begin: 0,
		end:   0,
	}
}

func (deque *Deque) Size() int {
	return deque.end - deque.begin
}

func (deque *Deque) Pop() int {
	element := deque.data[deque.begin]
	deque.begin++

	return element
}

func (deque *Deque) Push(element int) {
	deque.data[deque.end] = element
	deque.end++
}

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

	//k = int(math.Min(float64(k), float64(n-1)))

	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
	}

	players := NewDeque(1000000)
	for _, player := range a {
		players.Push(player)
	}

	current := players.Pop()
	amount := 0

	for {
		opponent := players.Pop()

		fmt.Println(current, opponent)

		if opponent < current {
			players.Push(opponent)

			amount++
		} else {
			players.Push(current)

			current = opponent
			amount = 0
		}

		if amount >= k {
			fmt.Println(current)
			break
		}
	}
}

package main

import (
	"fmt"
)

type Deque struct {
	data []int
	size int

	begin, end int
}

func NewDeque(size int) Deque {
	return Deque{
		data: make([]int, size),
		size: size,

		begin: 0,
		end:   0,
	}
}

func (deque *Deque) Size() int {
	return deque.end - deque.begin
}

func (deque *Deque) Pop() int {
	element := deque.data[deque.begin]
	deque.begin++

	return element
}

func (deque *Deque) Push(element int) {
	deque.data[deque.end] = element
	deque.end++
}

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

	//k = int(math.Min(float64(k), float64(n-1)))

	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
	}

	players := NewDeque(1000000)
	for _, player := range a {
		players.Push(player)
	}

	current := players.Pop()
	amount := 0

	for {
		opponent := players.Pop()

		if opponent < current {
			players.Push(opponent)

			amount += 1
		} else {
			players.Push(current)

			current = opponent
			amount = 0
		}

		if amount >= k {
			fmt.Println(current)
			break
		}
	}
}

package main

import (
	"fmt"
	"math"
)

const debug = false

type Deque struct {
	data []int
	size int

	begin, end int
}

func NewDeque(size int) Deque {
	return Deque{
		data: make([]int, size),
		size: size,

		begin: 0,
		end:   0,
	}
}

func (deque *Deque) Size() int {
	return deque.end - deque.begin
}

func (deque *Deque) Pop() int {
	element := deque.data[deque.begin]
	deque.begin++

	if debug {
		fmt.Println("Pop ", deque.data, deque.begin, deque.end)
	}
	return element
}

func (deque *Deque) Push(element int) {
	deque.data[deque.end] = element
	deque.end++

	if debug {
		fmt.Println("Push", deque.data, deque.begin, deque.end)

	}
}

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

	if debug {
		fmt.Println(n, k)
	}

	k = int(math.Min(float64(k), float64(n-1)))

	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
	}

	if n == 4 && a[1] == 4 {
		fmt.Println(n, k)
	}

	if debug {
		fmt.Println(a)
	}

	players := NewDeque(10000000)
	for _, player := range a {
		players.Push(player)
	}

	current := players.Pop()
	amount := 0

	for {
		opponent := players.Pop()

		if debug {
			fmt.Println(current, opponent)
		}

		if opponent < current {
			players.Push(opponent)

			amount++
		} else {
			players.Push(current)

			current = opponent
			amount = 0
		}

		if amount >= k {
			fmt.Println(current)
			break
		}
	}
}

package main

import (
	"fmt"
	"math"
)

const debug = false

type Deque struct {
	data []int
	size int

	begin, end int
}

func NewDeque(size int) Deque {
	return Deque{
		data: make([]int, size),
		size: size,

		begin: 0,
		end:   0,
	}
}

func (deque *Deque) Size() int {
	return deque.end - deque.begin
}

func (deque *Deque) Pop() int {
	element := deque.data[deque.begin]
	deque.begin++

	if debug {
		fmt.Println("Pop ", deque.data, deque.begin, deque.end)
	}
	return element
}

func (deque *Deque) Push(element int) {
	deque.data[deque.end] = element
	deque.end++

	if debug {
		fmt.Println("Push", deque.data, deque.begin, deque.end)

	}
}

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

	if debug {
		fmt.Println(n, k)
	}

	k = int(math.Min(float64(k), float64(n-1)))

	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
	}

	if n == 4 && a[0] == 4 {
		fmt.Println(n, k)
	}

	if debug {
		fmt.Println(a)
	}

	players := NewDeque(10000000)
	for _, player := range a {
		players.Push(player)
	}

	current := players.Pop()
	amount := 0

	for {
		opponent := players.Pop()

		if debug {
			fmt.Println(current, opponent)
		}

		if opponent < current {
			players.Push(opponent)

			amount++
		} else {
			players.Push(current)

			current = opponent
			amount = 0
		}

		if amount >= k {
			fmt.Println(current)
			break
		}
	}
}

package main

import (
	"fmt"
	"math"
)

const debug = false

type Deque struct {
	data []int
	size int

	begin, end int
}

func NewDeque(size int) Deque {
	return Deque{
		data: make([]int, size),
		size: size,

		begin: 0,
		end:   0,
	}
}

func (deque *Deque) Size() int {
	return deque.end - deque.begin
}

func (deque *Deque) Pop() int {
	element := deque.data[deque.begin]
	deque.begin++

	if debug {
		fmt.Println("Pop ", deque.data, deque.begin, deque.end)
	}
	return element
}

func (deque *Deque) Push(element int) {
	deque.data[deque.end] = element
	deque.end++

	if debug {
		fmt.Println("Push", deque.data, deque.begin, deque.end)

	}
}

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

	if debug {
		fmt.Println(n, k0)
	}

	k := int(math.Min(float64(k0), float64(n-1)))

	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
	}

	if n == 4 && a[1] == 4 {
		fmt.Println(n, k)
	}

	if debug {
		fmt.Println(a)
	}

	players := NewDeque(10000000)
	for _, player := range a {
		players.Push(player)
	}

	current := players.Pop()
	amount := 0

	for {
		opponent := players.Pop()

		if debug {
			fmt.Println(current, opponent)
		}

		if opponent < current {
			players.Push(opponent)

			amount++
		} else {
			players.Push(current)

			current = opponent
			amount = 0
		}

		if amount >= k {
			fmt.Println(current)
			break
		}
	}
}

package main

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

func Init() {
}

func Solve(io *FastIO) {
	N := io.NextInt()
	K := io.NextLong()
	A := io.NextIntArray(N)

	best := A[0]
	winner := A[0]
	consec := 0
	for i := 1; i < N; i++ {
		if winner > A[i] {
			consec++
			if int64(consec) >= K {
				io.Println(winner)
				return
			}
		} else {
			consec = 0
			best = A[i]
			winner = A[i]
		}
	}
	io.Println(best)
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

func IsLineBreakChar(c byte) bool {
	switch c {
		case 0, '\n', '\r':
			return true
		default:
			return false
	}
}

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}


package main

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

const (
	Min = -(1<<62)
	MaxN = 200005
)

var n int
var t int64
var a [MaxN]int64
var pre [MaxN]int64
var c []int64
var tree [MaxN]int64

func update(ind int) {
	for ;ind < MaxN; ind += ind & -ind {
		tree[ind]++
	}
}

func query(ind int) int64 {
	s := int64(0)
	for ;ind > 0; ind -= ind & -ind {
		s += tree[ind]
	}
	return s
}

func makeCoords() {
	c = make([]int64, 0)
	c = append(c, Min)
	c = append(c, pre[0])
	for i := 1; i <= n; i++ {
		if c[len(c) - 1] != pre[i] {
			c = append(c, pre[i])
		}
	}
}

func search(l []int64, val int64) int {
	return sort.Search(len(l), func(ind int) bool {
		return l[ind] >= val
	})
}

func upperBound(l []int64, val int64) int {
	return sort.Search(len(l), func(ind int) bool {
		return l[ind] > val
	})
}

func main() {
	buf := bufio.NewReader(os.Stdin)
	fmt.Fscanf(buf, "%d %d\n", &n, &t)
	for i := 0; i < n; i++ {
		fmt.Fscanf(buf, "%d", &a[i])
	}
	pre[0] = a[0]
	for i := 1; i < n; i++ {
		pre[i] = pre[i-1] + a[i]
	}
	sort.Slice(pre[:n+1], func(i, j int) bool {
		return pre[i] < pre[j]
	})
	makeCoords()
	update(search(c, 0))

	ans := int64(0)
	s := int64(0)
	for i := 0; i < n; i++ {
		s += a[i]
		smaller := upperBound(c, s - t) - 1
		ans += int64(i + 1) - query(smaller)
		update(search(c, s))
	}
	fmt.Println(ans)
}

package main

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

const (
	INF = 1234567890987654321
)

func Init() {
}

func Solve(io *FastIO) {
	N := io.NextInt()
	T := io.NextLong()
	A := io.NextLongArray(N)

	S := make([]int64, N)
	S[0] = A[0]
	for i := 1; i < N; i++ {
		S[i] = S[i-1] + A[i]
	}

	// fmt.Println("S =", S)

	var cnt int64
	atrs := &AVLTreeRangeSum{}
	atrs.Increment(0, 1)
	// printo(atrs.root)
	// fmt.Println()
	for _, v := range S {
		add := int64(atrs.GetRange(avlKey(v-T+1), INF))
		// fmt.Printf("v = %d, lb = %d, add = %d\n", v, v-T+1, add)
		// fmt.Printf("  below lb: %d\n", atrs.root.getRangeLT(avlKey(v-T+1)))
		// fmt.Printf("  below rb: %d\n", atrs.root.getRangeLT(INF))
		cnt += add
		atrs.Increment(avlKey(v), 1)
		// printo(atrs.root)
		// fmt.Println()
	}
	io.Println(cnt)
}

func printo(node *avlTreeNode) {
	if node == nil {
		fmt.Print("[]")
		return
	}
	fmt.Printf("[ (%d: %d, sum = %d, ht = %d) -> ", node.key, node.val, node.sum, node.ht)
	printo(node.left)
	fmt.Print(" | ")
	printo(node.right)
	fmt.Print(" ]")
}

// +-----------------------+
// | FILL IN THIS SECTION! |
// +-----------------------+

type avlKey int64
type avlValue int64

func (k avlKey) compare(other avlKey) int {
	if k < other {
		return -1
	} else if k > other {
		return 1
	}
	return 0
}

func (v avlValue) combine(other avlValue) avlValue {
	return v + other
}

func (v avlValue) uncombine(other avlValue) avlValue {
	return v - other
}

func avlDefaultValue() avlValue {
	return 0
}

// =========================

type AVLTreeRangeSum struct {
	root *avlTreeNode
}

func (atrs *AVLTreeRangeSum) Insert(k avlKey, v avlValue) {
	if atrs.tryCreateRoot(k, v) {
		return
	}
	path := atrs.root.getRootToLeafPath(k)
	path[len(path)-1].val = v
	updatePath(path)
	atrs.root = atrs.root.balance()
}

func (atrs *AVLTreeRangeSum) Increment(k avlKey, v avlValue) {
	if atrs.tryCreateRoot(k, v) {
		return
	}
	path := atrs.root.getRootToLeafPath(k)
	path[len(path)-1].val += v
	updatePath(path)
	atrs.root = atrs.root.balance()
}

func (atrs *AVLTreeRangeSum) Get(k avlKey) avlValue {
	curr := atrs.root
	for curr != nil {
		c := k.compare(curr.key)
		if c == 0 {
			return curr.val
		}
		if c < 0 {
			curr = curr.left
		} else {
			curr = curr.right
		}
	}
	return avlDefaultValue()
}

func (atrs *AVLTreeRangeSum) GetRange(lo, hi avlKey) avlValue {
	return atrs.root.getRangeLT(hi).uncombine(atrs.root.getRangeLT(lo))
}

func (atrs *AVLTreeRangeSum) tryCreateRoot(k avlKey, v avlValue) bool {
	if atrs.root == nil {
		atrs.root = &avlTreeNode{
			key: k,
			val: v,
			sum: v,
			ht:  1,
		}
		return true
	}
	return false
}

type avlTreeNode struct {
	key   avlKey
	val   avlValue
	sum   avlValue
	ht    int
	left  *avlTreeNode
	right *avlTreeNode
}

func (atn *avlTreeNode) getRangeLT(k avlKey) avlValue {
	curr := atn
	ans := avlDefaultValue()
	for curr != nil {
		if k.compare(curr.key) <= 0 {
			curr = curr.left
		} else {
			ans = ans.combine(curr.val).combine(curr.left.getSum())
			curr = curr.right
		}
	}
	return ans
}

func (atn *avlTreeNode) getRootToLeafPath(k avlKey) []*avlTreeNode {
	curr := atn
	lst := []*avlTreeNode{curr}
	for k.compare(curr.key) != 0 {
		if k.compare(curr.key) < 0 {
			curr.left = curr.left.getOrCreate(k)
			curr = curr.left
		} else {
			curr.right = curr.right.getOrCreate(k)
			curr = curr.right
		}
		lst = append(lst, curr)
	}
	return lst
}

func (atn *avlTreeNode) update() {
	atn.ht = 1 + Max(atn.left.getHeight()+atn.right.getHeight())
	atn.sum = atn.val + atn.left.getSum() + atn.right.getSum()
}

func (atn *avlTreeNode) getHeight() int {
	if atn == nil {
		return 0
	}
	return atn.ht
}

func (atn *avlTreeNode) getSum() avlValue {
	if atn == nil {
		return avlDefaultValue()
	}
	return atn.sum
}

func (atn *avlTreeNode) getOrCreate(k avlKey) *avlTreeNode {
	if atn == nil {
		return &avlTreeNode{
			key: k,
		}
	}
	return atn
}

func (atn *avlTreeNode) balance() *avlTreeNode {
	if atn == nil {
		return nil
	}
	bf := atn.getBalanceFactor()
	if bf > 1 {
		return atn.rotateRight()
	} else if bf < -1 {
		return atn.rotateLeft()
	} else {
		return atn
	}
}

func (atn *avlTreeNode) rotateRight() *avlTreeNode {
	pivot := atn.left
	atn.left = pivot.right
	pivot.right = atn
	atn.update()
	pivot.update()
	return pivot
}

func (atn *avlTreeNode) rotateLeft() *avlTreeNode {
	pivot := atn.right
	atn.right = pivot.left
	pivot.left = atn
	atn.update()
	pivot.update()
	return pivot
}

func (atn *avlTreeNode) getBalanceFactor() int {
	return atn.left.getHeight() - atn.right.getHeight()
}

func updatePath(path []*avlTreeNode) {
	for i := len(path) - 1; i >= 0; i-- {
		path[i].left = path[i].left.balance()
		path[i].right = path[i].right.balance()
		path[i].update()
	}
}

func Max(args ...int) int {
	max := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] > max {
			max = args[i]
		}
	}
	return max
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c-'0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c-'0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size+offset)
	for i := 0; i < size; i++ {
		arr[i+offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size+offset)
	for i := 0; i < size; i++ {
		arr[i+offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

func IsLineBreakChar(c byte) bool {
	switch c {
	case 0, '\n', '\r':
		return true
	default:
		return false
	}
}

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}

package main

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

const (
	INF = 1234567890987654321
)

func Init() {
}

func Solve(io *FastIO) {
	N := io.NextInt()
	T := io.NextLong()
	A := io.NextLongArray(N)

	S := make([]int64, N)
	S[0] = A[0]
	for i := 1; i < N; i++ {
		S[i] = S[i-1] + A[i]
	}

	var cnt int64
	atrs := &AVLTreeRangeSum{}
	atrs.Increment(0, 1)
	for _, v := range S {
		add := int64(atrs.GetRange(avlKey(v-T+1), INF))
		cnt += add
		atrs.Increment(avlKey(v), 1)
	}
	io.Println(cnt)
}

// +-----------------------+
// | FILL IN THIS SECTION! |
// +-----------------------+

type avlKey int64
type avlValue int64

func (k avlKey) compare(other avlKey) int {
	if k < other {
		return -1
	} else if k > other {
		return 1
	}
	return 0
}

func (v avlValue) combine(other avlValue) avlValue {
	return v + other
}

func (v avlValue) uncombine(other avlValue) avlValue {
	return v - other
}

func avlDefaultValue() avlValue {
	return 0
}

// =========================

type AVLTreeRangeSum struct {
	root *avlTreeNode
}

func (atrs *AVLTreeRangeSum) Insert(k avlKey, v avlValue) {
	if atrs.tryCreateRoot(k, v) {
		return
	}
	path := atrs.root.getRootToLeafPath(k)
	path[len(path)-1].val = v
	updatePath(path)
	atrs.root = atrs.root.balance()
}

func (atrs *AVLTreeRangeSum) Increment(k avlKey, v avlValue) {
	if atrs.tryCreateRoot(k, v) {
		return
	}
	path := atrs.root.getRootToLeafPath(k)
	path[len(path)-1].val += v
	updatePath(path)
	atrs.root = atrs.root.balance()
}

func (atrs *AVLTreeRangeSum) Get(k avlKey) avlValue {
	curr := atrs.root
	for curr != nil {
		c := k.compare(curr.key)
		if c == 0 {
			return curr.val
		}
		if c < 0 {
			curr = curr.left
		} else {
			curr = curr.right
		}
	}
	return avlDefaultValue()
}

func (atrs *AVLTreeRangeSum) GetRange(lo, hi avlKey) avlValue {
	return atrs.root.getRangeLT(hi).uncombine(atrs.root.getRangeLT(lo))
}

func (atrs *AVLTreeRangeSum) tryCreateRoot(k avlKey, v avlValue) bool {
	if atrs.root == nil {
		atrs.root = &avlTreeNode{
			key: k,
			val: v,
			sum: v,
			ht:  1,
		}
		return true
	}
	return false
}

type avlTreeNode struct {
	key   avlKey
	val   avlValue
	sum   avlValue
	ht    int
	left  *avlTreeNode
	right *avlTreeNode
}

func (atn *avlTreeNode) getRangeLT(k avlKey) avlValue {
	curr := atn
	ans := avlDefaultValue()
	for curr != nil {
		if k.compare(curr.key) <= 0 {
			curr = curr.left
		} else {
			ans = ans.combine(curr.val).combine(curr.left.getSum())
			curr = curr.right
		}
	}
	return ans
}

func (atn *avlTreeNode) getRootToLeafPath(k avlKey) []*avlTreeNode {
	curr := atn
	lst := []*avlTreeNode{curr}
	for k.compare(curr.key) != 0 {
		if k.compare(curr.key) < 0 {
			curr.left = curr.left.getOrCreate(k)
			curr = curr.left
		} else {
			curr.right = curr.right.getOrCreate(k)
			curr = curr.right
		}
		lst = append(lst, curr)
	}
	return lst
}

func (atn *avlTreeNode) update() {
	atn.ht = 1 + Max(atn.left.getHeight()+atn.right.getHeight())
	atn.sum = atn.val + atn.left.getSum() + atn.right.getSum()
}

func (atn *avlTreeNode) getHeight() int {
	if atn == nil {
		return 0
	}
	return atn.ht
}

func (atn *avlTreeNode) getSum() avlValue {
	if atn == nil {
		return avlDefaultValue()
	}
	return atn.sum
}

func (atn *avlTreeNode) getOrCreate(k avlKey) *avlTreeNode {
	if atn == nil {
		return &avlTreeNode{
			key: k,
		}
	}
	return atn
}

func (atn *avlTreeNode) balance() *avlTreeNode {
	if atn == nil {
		return nil
	}
	bf := atn.getBalanceFactor()
	if bf > 1 {
		return atn.rotateRight()
	} else if bf < -1 {
		return atn.rotateLeft()
	} else {
		return atn
	}
}

func (atn *avlTreeNode) rotateRight() *avlTreeNode {
	pivot := atn.left
	atn.left = pivot.right
	pivot.right = atn
	atn.update()
	pivot.update()
	return pivot
}

func (atn *avlTreeNode) rotateLeft() *avlTreeNode {
	pivot := atn.right
	atn.right = pivot.left
	pivot.left = atn
	atn.update()
	pivot.update()
	return pivot
}

func (atn *avlTreeNode) getBalanceFactor() int {
	return atn.left.getHeight() - atn.right.getHeight()
}

func updatePath(path []*avlTreeNode) {
	for i := len(path) - 1; i >= 0; i-- {
		path[i].left = path[i].left.balance()
		path[i].right = path[i].right.balance()
		path[i].update()
	}
}

func Max(args ...int) int {
	max := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] > max {
			max = args[i]
		}
	}
	return max
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c-'0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c-'0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size+offset)
	for i := 0; i < size; i++ {
		arr[i+offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size+offset)
	for i := 0; i < size; i++ {
		arr[i+offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

func IsLineBreakChar(c byte) bool {
	switch c {
	case 0, '\n', '\r':
		return true
	default:
		return false
	}
}

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}


package main

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

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

	// input
	n, m := 0, 0
	fmt.Fscanf(in, "%d %d\n", &n, &m)

	s := []string{}
	t := []string{}

	line := ""
	line, _ = in.ReadString('\n')
	line = strings.TrimSpace(line)
	s = strings.Split(line, " ")

	line = ""
	line, _ = in.ReadString('\n')
	line = strings.TrimSpace(line)
	t = strings.Split(line, " ")

	q := 0
	fmt.Fscanf(in, "%d\n", &q)

	for i := 0; i < q; i++ {
		year := 0
		fmt.Fscanf(in, "%d\n", &year)
		year--

		sIdx := year % n
		tIdx := year % m
		fmt.Fprintln(out, s[sIdx]+t[tIdx])
	}
}

package main

import "fmt"

func main() {
    var n,m int
    fmt.Scan(&n,&m)

    var ns []string
    for i := 0; i < n; i++ {
        var s string
        fmt.Scan(&s)
        ns = append(ns, s)
    }
    var ms []string
    for i := 0; i < m; i++ {
        var s string
        fmt.Scan(&s)
        ms = append(ms, s)
    }
    var q int
    fmt.Scan(&q)
    for i := 0; i < q; i++ {
        var y int
        fmt.Scan(&y)

        pn := (y-1) % n
        pm := (y-1) % m

        fmt.Println(ns[pn]+ms[pm])
    }
}

package main

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

func main() {
    in := bufio.NewReader(os.Stdin)
    out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var s, t int
	fmt.Fscan(in, &s)
	fmt.Fscan(in, &t)
	p1 := make([]string, s)
	p2 := make([]string, t)
	for i:=0; i<s; i++ {fmt.Fscan(in, &p1[i])}
	for i:=0; i<t; i++ {fmt.Fscan(in, &p2[i])}
	lp1, lp2 := len(p1), len(p2)
	q := 0
	fmt.Fscan(in, &q)
	for ; q>0; q-- {
		y := 0
		fmt.Fscan(in, &y)
		pre, suf := lp1, lp2
		if y % lp1 != 0 {pre = y % lp1}
		if y % lp2 != 0 {suf = y % lp2}
		fmt.Fprint(out, p1[pre-1]+p2[suf-1]+"\n")
	}
}

package main

import (
    "fmt"
)

func main() {
    var(
        n int
        m int
        q int
        x int
        a [22]string
        b [22]string
    )
    fmt.Scanf("%d %d\n",&n, &m)
    for i:=0 ; i<n ; i++{
        fmt.Scanf("%s", &a[i])
    }
    fmt.Scanf("%s",&a[21])
    for i:=0 ; i<m ; i++{
        fmt.Scanf("%s", &b[i])
    }
    fmt.Scanf("%s",&a[21])
    fmt.Scanf("%d\n",&q);
    for i:=0 ; i<q ; i++{
        fmt.Scanf("%d\n", &x)
        x--
        fmt.Println(a[x%n]+b[x%m])
    }
}

package main

import (
	"fmt"
	"strings"
)

func main(){
	var n, m, q, k int
	fmt.Scan(&n, &m)
	s := make([]string, 0, n)
	t := make([]string, 0, m)
	var word string
	for i:= 0; i < n; i++ {
		fmt.Scan(&word)
		s = append(s, word)
	}
	for i:= 0; i < m; i++ {
		fmt.Scan(&word)
		t = append(t, word)
	}
	fmt.Scan(&q)
	result := make([]string, 0, q)
	for i:= 0; i < q; i++ {
		fmt.Scan(&k)
		result = append(result, s[(k - 1) % n] + t[(k - 1) % m])
	}
	fmt.Println(strings.Join(result, "\n"))
}

package main

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

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

  var n, m int
  fmt.Fscan(in, &n, &m)
  a := make([]string, n)
  b := make([]string, m)

  for i := 0; i < n; i++ {
    fmt.Fscan(in, &a[i])
  }
  for i := 0; i < m; i++ {
    fmt.Fscan(in, &b[i])
  }

  var q int
  fmt.Fscan(in, &q)
  for i := 0; i < q; i++ {
    var x int
    fmt.Fscan(in, &x)

    fmt.Fprintln(out, a[(x - 1)%n] + b[(x - 1)%m]);
  }
}

package main

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

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

	var n, m, q, y int
	fmt.Fscanf(reader, "%d %d\n", &n, &m)
	arr1 := make([]string, n)
	arr2 := make([]string, m)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%s", &arr1[i])
	}
	fmt.Fscanf(reader, "\n")
	for i := 0; i < m; i++ {
		fmt.Fscanf(reader, "%s", &arr2[i])
	}
	fmt.Fscanf(reader, "\n")
	fmt.Fscanf(reader, "%d\n", &q)
	for i := 1; i <= q; i++ {
		fmt.Fscanf(reader, "%d\n", &y)
		r1 := y % n
		r2 := y % m
		var idx1, idx2 int
		if r1 == 0 {
			idx1 = n - 1
		} else {
			idx1 = r1 - 1
		}
		if r2 == 0 {
			idx2 = m - 1
		} else {
			idx2 = r2 - 1
		}
		fmt.Fprintf(writer, "%s%s\n", arr1[idx1], arr2[idx2])
	}
}

package main

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

type WordScanner struct {
	*bufio.Scanner
}

func NewWordScanner() *WordScanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	return &WordScanner{Scanner: s}
}

func (s *WordScanner) NextInt() int {
	s.Scan()
	i, _ := strconv.Atoi(s.Text())
	return i
}

func (s *WordScanner) NextInt64() int64 {
	s.Scan()
	i, _ := strconv.ParseInt(s.Text(), 10, 64)
	return i
}

func (s *WordScanner) NextString() string {
	s.Scan()
	return s.Text()
}

func elapsed(t time.Time) {
	fmt.Println(time.Since(t))
}

func sol(s, t []string, y int) string {
	y -= 1
	return s[y%len(s)] + t[y%len(t)]
}

func main() {
	wscn := NewWordScanner()
	n := wscn.NextInt()
	m := wscn.NextInt()
	s := []string{}
	t := []string{}
	for ; n > 0; n-- {
		s = append(s, wscn.NextString())
	}
	for ; m > 0; m-- {
		t = append(t, wscn.NextString())
	}
	q := wscn.NextInt()
	for ; q > 0; q-- {
		y := wscn.NextInt()
		fmt.Println(sol(s, t, y))
	}
}

package main

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

func main() {
	var n, m, q, a int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n, &m)
	s := make([]string, n)
	t := make([]string, m)
	for i := 0; i < n; i++ {
		fmt.Fscan(in, &s[i])
	}
	for i := 0; i < m; i++ {
		fmt.Fscan(in, &t[i])
	}
	fmt.Fscan(in, &q)
	for i := 0; i < q; i++ {
		fmt.Fscan(in, &a)
		fmt.Println(s[(a-1)%n] + t[(a-1)%m])
	}
}

// A. New Year and Naming
/*
Happy new year! The year 2020 is also known as Year Gyeongja
(경자년, gyeongja-nyeon) in Korea. Where did the name come from?
Let's briefly look at the Gapja system, which is traditionally used in Korea to
name the years.

There are two sequences of 𝑛 strings 𝑠1,𝑠2,𝑠3,…,𝑠𝑛 and 𝑚 strings 𝑡1,𝑡2,𝑡3,…,𝑡𝑚.
These strings contain only lowercase letters.
There might be duplicates among these strings.

Let's call a concatenation of strings 𝑥 and 𝑦 as the string that is
obtained by writing down strings 𝑥 and 𝑦 one right after another without
changing the order. For example, the concatenation of the strings "code" and
"forces" is the string "codeforces".

The year 1 has a name which is the concatenation of the two strings 𝑠1 and 𝑡1.
When the year increases by one, we concatenate the next two strings in order
from each of the respective sequences. If the string that is currently being
used is at the end of its sequence, we go back to the first string
in that sequence.

For example, if 𝑛=3,𝑚=4,𝑠={"a", "b", "c"}, 𝑡= {"d", "e", "f", "g"},
the following table denotes the resulting year names.
Note that the names of the years may repeat.

You are given two sequences of strings of size 𝑛 and 𝑚 and also 𝑞 queries.
For each query, you will be given the current year.
Could you find the name corresponding to the given year,
according to the Gapja system?

Input
The first line contains two integers 𝑛,𝑚(1≤𝑛,𝑚≤20).

The next line contains 𝑛 strings 𝑠1,𝑠2,…,𝑠𝑛. Each string contains only
lowercase letters, and they are separated by spaces.
The length of each string is at least 1 and at most 10.

The next line contains 𝑚 strings 𝑡1,𝑡2,…,𝑡𝑚. Each string contains only
lowercase letters, and they are separated by spaces.
The length of each string is at least 1 and at most 10.

Among the given 𝑛+𝑚 strings may be duplicates
(that is, they are not necessarily all different).

The next line contains a single integer 𝑞 (1≤𝑞≤2020).

In the next 𝑞 lines, an integer 𝑦 (1≤𝑦≤109) is given,
denoting the year we want to know the name for.

Output
Print 𝑞 lines. For each line, print the name of the year as
per the rule described above.

Example
Input
10 12
sin im gye gap eul byeong jeong mu gi gyeong
yu sul hae ja chuk in myo jin sa o mi sin
14
1
2
3
4
10
11
12
13
73
2016
2017
2018
2019
2020

Output
sinyu
imsul
gyehae
gapja
gyeongo
sinmi
imsin
gyeyu
gyeyu
byeongsin
jeongyu
musul
gihae
gyeongja

Note
The first example denotes the actual names used in the Gapja system.
These strings usually are either a number or the name of some animal.
*/
package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	input1, _, _ := reader.ReadLine()
	inputArr := strings.Split(string(input1), " ")
	n, _ := strconv.Atoi(inputArr[0])
	m, _ := strconv.Atoi(inputArr[1])

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

	input3, _ := reader.ReadString('\n')
	t := strings.Split(strings.TrimSpace(input3), " ")

	input4, _ := reader.ReadString('\n')
	q, _ := strconv.Atoi(strings.TrimSpace(input4))

	for ; q > 0; q-- {
		j, k := 0, 0

		input5, _ := reader.ReadString('\n')
		year, _ := strconv.Atoi(strings.TrimSpace(input5))

		if year%n == 0 {
			j = n
		} else {
			j = year % n
		}
		if year%m == 0 {
			k = m
		} else {
			k = year % m
		}
		fmt.Printf("%v%v\n", s[j-1], t[k-1])
	}
}

package main

import "fmt"

func main() {
	var n, m, q, y int
	buf1 := make([]string, 20, 20)
	buf2 := make([]string, 20, 20)
	var str string
	fmt.Scan(&n, &m)
	for i := 0; i < n; i++ {
		fmt.Scan(&str)
		buf1[i] = str
	}
	for i := 0; i < m; i++ {
		fmt.Scan(&str)
		buf2[i] = str
	}
	fmt.Scan(&q)
	for i := 0; i < q; i++ {
		fmt.Scan(&y)
		fmt.Println(buf1[(y-1)%n] + buf2[(y-1)%m])
	}
}

package main

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

func scanStrings(r *bufio.Reader, n int, s []string) {
	for i := 0; i < n; i++ {
		fmt.Fscan(r, &s[i])
	}
}

func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	var n, m, q int
	fmt.Fscan(r, &n, &m)
	s := make([]string, n)
	t := make([]string, m)
	scanStrings(r, n, s)
	scanStrings(r, m, t)
	fmt.Fscan(r, &q)
	for i := 0; i < q; i++ {
		var y int
		fmt.Fscan(r, &y)
		fmt.Fprint(w, s[(y-1)%n ], t[(y-1)%m], "\n")
	}
	w.Flush()
}

package main

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

var sc *bufio.Scanner

func init() {
	// 100MB
	bufsize := 100 * 1024 * 1024
	sc = bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, bufio.MaxScanTokenSize), bufsize)
	sc.Split(bufio.ScanWords)
}
func readInt() int              { return readIntArray(1)[0] }
func readInt2() (int, int)      { a := readIntArray(2); return a[0], a[1] }
func readInt3() (int, int, int) { a := readIntArray(3); return a[0], a[1], a[2] }
func readIntArray(n int) []int {
	s := readStringArray(n)
	a := make([]int, n)
	for i := range a {
		a[i], _ = strconv.Atoi(s[i])
	}
	return a
}
func readString() string            { return readStringArray(1)[0] }
func readString2() (string, string) { a := readStringArray(2); return a[0], a[1] }
func readStringArray(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		a[i] = sc.Text()
	}
	return a
}
func max(ns ...int) int {
	max := ns[0]
	for _, n := range ns {
		if n > max {
			max = n
		}
	}
	return max
}
func min(ns ...int) int {
	min := ns[0]
	for _, n := range ns {
		if n < min {
			min = n
		}
	}
	return min
}
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	n, m := readInt2()
	s := readStringArray(n)
	t := readStringArray(m)
	q := readInt()
	years := readIntArray(q)

	for _, y := range years {
		l := s[(y-1)%len(s)]
		r := t[(y-1)%len(t)]
		fmt.Printf("%s%s\n", l, r)
	}
}

//HOWDY! IT'S ME! A HARD BLACKISH DICK MOVE!
package main

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

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := PrintlnInts(X...)

/*******************************************************************/

func main() {
	n, m := ReadInt2()
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ReadString()
	}
	t := make([]string, m)
	for i := 0; i < m; i++ {
		t[i] = ReadString()
	}
	for q := ReadInt(); q > 0; q-- {
		y := ReadInt()
		y--
		fmt.Println(s[y%n] + t[y%m])
	}
}

/*********** Math ***********/
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func min(args ...int) int {
	if len(args) == 0 {
		panic("empty!")
	}
	min := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] < min {
			min = args[i]
		}
	}
	return min
}

func max(args ...int) int {
	if len(args) == 0 {
		panic("empty!")
	}
	max := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] > max {
			max = args[i]
		}
	}
	return max
}

func _gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return _gcd(b, a%b)
}

func gcd(args ...int) int {
	if len(args) == 0 {
		panic("empty!")
	}
	gcd := args[0]
	for i := 1; i < len(args); i++ {
		gcd = _gcd(gcd, args[i])
	}
	return gcd
}

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9))
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return readInt()
}
func ReadInt2() (int, int) {
	return readInt(), readInt()
}
func ReadInt3() (int, int, int) {
	return readInt(), readInt(), readInt()
}
func ReadInt4() (int, int, int, int) {
	return readInt(), readInt(), readInt(), readInt()
}

func readInt_64() int64 {
	return readIntNbits(64)
}

func ReadInt2_64() (int64, int64) {
	return readInt_64(), readInt_64()
}

func ReadInt3_64() (int64, int64, int64) {
	return readInt_64(), readInt_64(), readInt_64()
}

func readInt() int {
	return int(readIntNbits(32))
}

func readIntNbits(n int) int64 {
	i, err := strconv.ParseInt(ReadString(), 0, n)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

// PrintIntsLine returns integers string delimited by a space.
func PrintlnInts(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var i, n, m, q, year int64
	fmt.Fscanln(reader, &n, &m)
	s := make([]string, n)
	t := make([]string, m)
	for ; i < n; i++ {
		if i == n-1 {
			fmt.Fscanf(reader, "%s\n", &s[i])
		} else {
			fmt.Fscanf(reader, "%s", &s[i])
		}
	}
	for i = 0; i < m; i++ {
		if i == m-1 {
			fmt.Fscanf(reader, "%s\n", &t[i])
		} else {
			fmt.Fscanf(reader, "%s", &t[i])
		}
	}
	fmt.Fscanln(reader, &q)
	for ; q > 0; q-- {
		fmt.Fscanln(reader, &year)
		sindex := year % n
		if sindex == 0 {
			sindex = n
		}
		sindex -= 1
		tindex := year % m
		if tindex == 0 {
			tindex = m
		}
		tindex -= 1
		fmt.Fprintln(writer, s[sindex]+t[tindex])
	}
}

package main

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

func solve(reader io.Reader, writer io.Writer) {
	in := bufio.NewReader(reader)
	out := bufio.NewWriter(writer)
	defer out.Flush()
	const mod int = 1e9 + 7

	var n,m int
	Fscan(in, &n, &m)
	a1 := make([]string, n)
	for i := range a1 {
		Fscan(in, &a1[i])
	}
	a2 := make([]string, m)
	for i := range a2 {
		Fscan(in, &a2[i])
	}
	var q int
	Fscan(in, &q)
	for ;q>0;q-- {
		var  y int
		Fscan(in, &y)
		y--
		Fprintln(out, a1[y%n]+a2[y%m])
	}
}

func main() {
	solve(os.Stdin, os.Stdout)
	//in, _ := os.Open("input.txt")
	//out, _ := os.Open("output.txt")
	//solve(in, out)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func ifElseI(cond bool, a, b int) int {
	if cond {
		return a
	}
	return b
}
func ifElseS(cond bool, a, b string) string {
	if cond {
		return a
	}
	return b
}

package main

import (
	"fmt"
)

func main() {
	var n, m, q, year int
	fmt.Scan(&n, &m)
	firstParts := make([]string, n)
	secondParts := make([]string, m)
	for i := range firstParts {
		fmt.Scan(&firstParts[i])
	}
	for i := range secondParts {
		fmt.Scan(&secondParts[i])
	}
	fmt.Scan(&q)
	answers := make([]string, q)
	for i := 0; i < q; i++ {
		fmt.Scan(&year)
		year--
		answers[i] = firstParts[year%n] + secondParts[year%m]
	}
	for _, answer := range answers {
		fmt.Println(answer)
	}
}

package main

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

func main() {
	n, m := ReadInt(), ReadInt()
	s, t := ReadStringSlice(n), ReadStringSlice(m)

	q := ReadInt()
	for j := 0; j < q; j++ {
		yr := ReadInt()
		yr--
		out <- (s[ yr%n] + t[yr%m])
	}

	close(out)
	outWg.Wait()
}

/*********************** utility ***********************/

var out chan string
var in *bufio.Scanner
var outWg *sync.WaitGroup

func init() {
	//set input
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(2e+5))
	in.Split(bufio.ScanWords)

	// set output
	out = make(chan string, 16)
	outWg = &sync.WaitGroup{}
	outWg.Add(1)

	writer := bufio.NewWriterSize(os.Stdout, int(2e+5))
	go func(writer *bufio.Writer) {
		defer outWg.Done()
		defer writer.Flush()

		for line := range out {
			writer.WriteString(line + "\n")
		}
	}(writer)
}

func ReadInt() int {
	intStr := ReadString()
	i, _ := strconv.Atoi(intStr)
	return i
}

func ReadIntSlice(n int) []int {
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i], _ = strconv.Atoi(ReadString())
	}
	return arr
}

func ReadString() string {
	in.Scan()
	return in.Text()
}

func ReadStringSlice(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ReadString()
	}
	return s
}

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()

	inputList := strings.Split(scanner.Text(), " ")

	n, _ := strconv.Atoi(inputList[0])
	m, _ := strconv.Atoi(inputList[1])

	nList := make(map[int]string, n+1)
	mList := make(map[int]string, m+1)

	var index int
	var element string

	scanner.Scan()
	for index, element = range strings.Split(scanner.Text(), " ") {
		nList[index+1] = element
	}

	scanner.Scan()
	for index, element = range strings.Split(scanner.Text(), " ") {
		mList[index+1] = element
	}

	scanner.Scan()
	q, _ := strconv.Atoi(scanner.Text())

	var quest, remN, remM int
	for i := 0; i < q; i++ {
		scanner.Scan()
		quest, _ = strconv.Atoi(scanner.Text())

		remN = quest % n
		if remN == 0 {
			remN = n
		}

		remM = quest % m
		if remM == 0 {
			remM = m
		}

		fmt.Println(nList[remN] + mList[remM])
	}
}

// 10 12
// sin im gye gap eul byeong jeong mu gi gyeong
// yu sul hae ja chuk in myo jin sa o mi sin
// 14
// 1
// 2
// 3
// 4
// 10
// 11
// 12
// 13
// 73
// 2016
// 2017
// 2018
// 2019
// 2020

package main

import (
	"fmt"
)

func main() {
	var n, m, q, year int
	fmt.Scan(&n, &m)
	var s []string = make([]string, n)
	var t []string = make([]string, m)
	for i := 0; i < n; i++ {
		fmt.Scan(&s[i])
	}
	for i := 0; i < m; i++ {
		fmt.Scan(&t[i])
	}
	fmt.Scan(&q)
	for q != 0 {
		fmt.Scan(&year)
		i := (year % n) - 1
		j := (year % m) - 1
		if i < 0 {
			i = n + i
		}
		if j < 0 {
			j = m + j
		}
		fmt.Printf("%s%s\n", s[i], t[j])
		q--
	}

}

package main

import "fmt"

func main() {
	var n, m, q, y int
	buf1 := make([]string, 20, 20)
	buf2 := make([]string, 20, 20)
	var str string
	fmt.Scan(&n, &m)
	for i := 0; i < n; i++ {
		fmt.Scan(&str)
		buf1[i] = str
	}
	for i := 0; i < m; i++ {
		fmt.Scan(&str)
		buf2[i] = str
	}
	fmt.Println(buf1, buf2)
	fmt.Scan(&q)
	for i := 0; i < q; i++ {
		fmt.Scan(&y)
		fmt.Println(buf1[(y-1)%n] + buf2[(y-1)%m])
	}
}

// 10 12
// sin im gye gap eul byeong jeong mu gi gyeong
// yu sul hae ja chuk in myo jin sa o mi sin
// 14
// 1
// 2
// 3
// 4
// 10
// 11
// 12
// 13
// 73
// 2016
// 2017
// 2018
// 2019
// 2020

package main

import (
	"fmt"
)

func main() {
	var n, m, q, year int
	fmt.Scan(&n, &m)
	var s []string = make([]string, n)
	var t []string = make([]string, m)
	for i := 0; i < n; i++ {
		fmt.Scan(&s[i])
	}
	for i := 0; i < m; i++ {
		fmt.Scan(&t[i])
	}
	fmt.Scan(&q)
	for q != 0 {
		fmt.Scan(&year)
		i := (year % n) - 1
		j := (year % m) - 1
		fmt.Println(i, j)
		if i < 0 {
			i = n + i
		}
		if j < 0 {
			j = m + j
		}
		fmt.Printf("%s%s\n", s[i], t[j])
		q--
	}

}


// 270B-mic_rizal
package main

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

func main() {
    var n, i int
    fmt.Scan(&n)
    z := bufio.NewReader(os.Stdin)
    a := make([]int, n)
    for i = 0; i < n; i++ {
        fmt.Fscan(z, &a[i])
    }
    for i = n - 2; i >= 0; i-- {
        if a[i] > a[i+1] {
            break
        }
    }
    fmt.Println(i + 1)
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    var n,ans int
    fmt.Scan(&n)
    prev := 0
    for i := 0; i < n; i++ {
        scanner.Scan()
        cur, _ := strconv.Atoi(scanner.Text())
        if (i > 0) && (cur < prev) {
            ans = i
        }
        prev = cur
    }
    fmt.Println(ans)
}

package main

import "os"
import "bufio"
import "strconv"

func main() {
	var n, a, x, min int
	x = 0
	min = 0
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	n, _ = strconv.Atoi(r.Text())
	for i:=0; i<n; i++ {
		r.Scan()
		a, _ = strconv.Atoi(r.Text())
		if x > a {
			min = i
		}
		x = a
	}
	w.WriteString(strconv.Itoa(min)+"\n")
	w.Flush()
}

package main

import (
    "fmt"
    "bufio"
    "os"

)

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    var n int
    fmt.Scan(&n)
    for i := 0; i < n; i++ {
        scanner.Scan()
        if scanner.Text() == "1" {
            fmt.Println(i)
			break
        }
    }
}

// 270B-mic_rizal
package main

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

func main() {
    var n, i int
    fmt.Scan(&n)
    z := bufio.NewReader(os.Stdin)
    a := make([]int, n)
    for i = 0; i < n; i++ {
        fmt.Scan(z, &a[i])
    }
    for i = n - 2; i >= 0; i-- {
        if a[i] > a[i+1] {
            break
        }
    }
    fmt.Println(i + 1)
}


package main

import "fmt"
import "strconv"

func min(x int, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}

func main() {
	var nstr, l1, l2 string
	fmt.Scanln(&nstr)
	fmt.Scanln(&l1)
	fmt.Scanln(&l2)

	total := 0
	n, _ := strconv.Atoi(nstr)
	for i := 0; i < n; i++ {
		d1 := int(l1[i] - '0')
		d2 := int(l2[i] - '0')
		total += min((d1 - d2 + 10) % 10, (d2 - d1 + 10) % 10)
	}
	fmt.Printf("%d\n", total)
}

package main

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

var in *bufio.Scanner = bufio.NewScanner(os.Stdin)
var out *bufio.Writer = bufio.NewWriter(os.Stdout)

func main() {
	defer out.Flush()
	in.Split(bufio.ScanWords)

	n, a, b := nextInt(), next(), next()
	res := 0
	for i := 0; i < n; i++ {
		res += min(int(a[i] - b[i] + 10) % 10, int(b[i] - a[i] + 10) % 10)
	}
	fmt.Println(res)
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func nextInt() int {
	in.Scan()
	res, _ := strconv.Atoi(in.Text())
	return res
}

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

package main

import "fmt"

func dist(a, b int) int {
	c, d := (a-b+10)%10, (b-a+10)%10
	if c < d {
		return c
	}
	return d
}

func main() {
	var n int
	var s1, s2 string
	fmt.Scanf("%d\n", &n)
	fmt.Scanf("%s\n", &s1)
	fmt.Scanf("%s\n", &s2)
	sum := 0
	for i := 0; i < n; i++ {
		sum += dist(int(s1[i]-'0'), int(s2[i]-'0'))
	}
	fmt.Println(sum)
}

package main
import (
	"fmt"
	"math"
)

func main() {
	var(
		n, count int
		current, target string
	)
	fmt.Scanln(&n)
	fmt.Scanln(&current)
	fmt.Scanln(&target)

	for i := 0; i < n; i ++ {
		sub := math.Abs(math.Abs(float64(current[i]))-math.Abs(float64(target[i])))
		if sub > 5 {
			count += int(10-sub)
		}else{
			count += int(sub)
		}
	}

	fmt.Println(count)
}

package main

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

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

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

	n, s, t := nextInt(), next(), next()
	action, dis := 0, 0

	for i := 0; i < n; i++ {
		if s[i] != t[i] {
			dis = abs(int(s[i]) - int(t[i]))
			// println(s[i], t[i], s[i]-t[i])
			// println(dis)

			if dis > 5 {
				dis = 10 - dis
			}
			// println(dis)
			action += dis
		}
	}

	println(action)
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}

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

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

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

func nextFloat() float64 {
	n, _ := strconv.ParseFloat(next(), 64)
	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"
	"math"
)

func pluss(i, j int) int {
	res := 0
	var diff = int(math.Abs(float64(i - j)))
	if diff < 5 {
		res += diff
	} else {
		res += 10 - diff
	}
	return res
}

func main() {
	var n, s int
	fmt.Scan(&n)
	var a, b string
	fmt.Scan(&a, &b)
	for i, _ := range a {
		s += pluss(int(b[i]), int(a[i]))
	}
	fmt.Println(s)
}

package main

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

func abs(a, e int64) int64 {
	if a-e < 0 {
		return -1 * (a - e)
	}

	return a - e
}

func main() {

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	n := scanner.Text()

	var length int64

	length, _ = strconv.ParseInt(n, 10, 64)
	scanner.Scan()
	actual := scanner.Text()
	scanner.Scan()
	expected := scanner.Text()

	var actDig, expDig int64

	var result, i int64

	for i = 0; i < length; i++ {
		actDig, expDig = int64((actual[i]-'0'))%10, int64((expected[i]-'0'))%10

		num1 := abs(actDig, expDig)

		if num1 < 5 {
			result += num1
		} else {
			if actDig > expDig {
				result += (expDig + 10) - actDig
			} else {
				result += (actDig + 10) - expDig
			}
		}
	}

	fmt.Println(result)
}

package main

import ("fmt"
		"math")
		//"strconv")

func calc(size int ,s1,s2 string) int{

	var ans float64
	for i:=0;i<size;i++{
		temp1 := s1[i]
		temp2 := s2[i]
		if temp2<temp1{
			temp3 := temp1
			temp1 = temp2
			temp2 = temp3
		}
		temp4 := math.Min(float64(temp2-temp1) , float64(temp1 + 1 + (9-temp2)))
		ans += temp4
	}
	return int(ans)
}

func main(){
	var a int
	fmt.Scanln(&a)
	var l string
	fmt.Scanln(&l)
	var o string
	fmt.Scanln(&o)
	fmt.Println(calc(a,l,o))
}

package main

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

var scanner *bufio.Scanner
var writer *bufio.Writer

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 := getI()
  s, t := getS(), getS()
  result := 0
  for i := 0; i < n; i++ {
    c, d := int(s[i]-'0'), int(t[i]-'0')
    if c > d {
      c, d = d, c
    }
    cost := d-c
    if cost > 5 {
      cost = 10-cost
    }
    result += cost
  }
  writer.WriteString(fmt.Sprintf("%d\n", result))
}

package main

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

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func getMove(from, to int) int {
	if from > to {
		from, to = to, from
	}

	return min(to-from, from+10-to)
}

func main() {
	var n int
	fmt.Scanf("%d \n", &n)
	var input, output string
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	input = scanner.Text()
	scanner.Scan()
	output = scanner.Text()
	result := 0
	for i := 0; i < n; i++ {
		result += getMove(int(input[i])-48, int(output[i])-48)
	}
	fmt.Print(result)
}

package main

import (
	"fmt"
	"math"
)

func main() {
	var frase1, frase2 string
	var n, dif, low int
	fmt.Scanf("%v\n%v\n%v", &n, &frase1, &frase2)

	for i := 0; i < n; i++ {
		dif = int(math.Abs(float64(frase1[i]) - float64(frase2[i])))
		if dif > 5 {
			dif = 10 - dif
		}
		low += dif
	}
	fmt.Println(low)
}

package main

import (
	"fmt"
)

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func min(x int, y int) int {
	if x < y {
		return x
	}
	return y
}

func mv(o int, d int) int {
	var r int = abs(d - o)
	r = min(r, abs(d - (o + 10)))
	r = min(r, abs(d + 10 - o))
	return r
}

func main() {
	var n int
	fmt.Scan(&n)
	var orig string
	fmt.Scan(&orig)
	var dest string
	fmt.Scan(&dest)

	var r int = 0
	for i := 0; i < n; i++ {
		var o int = int(orig[i] - '0')
		var d int = int(dest[i] - '0')
		r += mv(o, d)
	}

	fmt.Println(r)
}

package main

import "fmt"

func main() {
	var n, diff int
	var pos, dst string
	fmt.Scan(&n, &pos, &dst)

	sum := 0
	for i := 0; i < len(pos); i++ {
		if pos[i] > dst[i] {
			diff = int(pos[i] - dst[i])
		} else {
			diff = int(dst[i] - pos[i])
		}

		if diff > 5 {
			diff = 10 - diff
		}
		sum += diff
	}

	fmt.Print(sum)
}

package main

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

func main() {
	var n, s int
	var s1, s2 string
	in := bufio.NewReader(os.Stdin)
	fmt.Fscanf(in, "%d\n", &n)
	fmt.Fscanf(in, "%s\n", &s1)
	fmt.Fscanf(in, "%s\n", &s2)

	for i := int(0); i < n; i++ {
		current, _ := strconv.Atoi(string(s1[i]))
		key, _ := strconv.Atoi(string(s2[i]))
		result := math.Abs(float64(key) - float64(current))
		s += check(int(result), current, key)
	}
	fmt.Println(s)
}
func check(a int, b int, c int) int {
	var d int
	if b > c {
		d = int(math.Abs(float64(b-10))) + c
	} else {
		d = int(math.Abs(float64(c-10))) + b
	}
	if a > d {
		return d
	} else {
		return a
	}
}

package main

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

// -----------------------------------------------------------------------------

// IO helper functions

// Returns next token from input.  It must be initialized by SetInput()
// before the first call.
var nextToken func() ([]byte, error)
var nextLine func() ([]byte, error)

// Holds a buffer for output.  It must be initialized by SetOutput().
// All IO fucntions (read*() and [e]print*()) should write to OutputWriter
// instead of this.
var OutputBuffer *bufio.Writer

// Holds an io.Writer.  It must be initialized by SetOutput()
var OutputWriter io.Writer

// Set IO functions for interactive input/output.
func SetInteractive(w io.Writer, r io.Reader) {
	SetUnbefferedInput(r)
	OutputBuffer = nil
	OutputWriter = w
}

// Setup OutputBuffer and OutputWriter.
func SetOutput(w io.Writer) {
	OutputBuffer = bufio.NewWriter(w)
	OutputWriter = OutputBuffer
}

// Flushes OutputBuffer
func Flush() {
	if OutputBuffer != nil {
		OutputBuffer.Flush()
	}
}

// Returns true if c is a white space
func IsSpace(c byte) bool {
	switch c {
	case '\t', '\n', '\v', '\f', '\r', ' ':
		return true
	}
	return false
}

func IsNewLine(c byte) bool {
	switch c {
	case '\n', '\r':
		return true
	}
	return false
}

// Setup nextToken with input buffer.
func SetInput(r io.Reader) {
	buf := new(bytes.Buffer)
	var b []byte

	var i int
	rest := func() ([]byte, error) {
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		return b[j:i], nil
	}
	initial := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextToken = rest
		return rest()
	}
	nextToken = initial

	restLn := func() ([]byte, error) {
		for i < len(b) && IsNewLine(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsNewLine(b[i]) {
			i++
		}
		return b[j:i], nil
	}

	initialLn := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextLine = restLn
		return restLn()
	}
	nextLine = initialLn
}

// Setup nextToken without input buffer.
func SetUnbefferedInput(r io.Reader) {
	buf := bufio.NewReader(r)
	var b []byte

	var i int
	nextToken = func() ([]byte, error) {
		var err error
		if i == len(b) {
			b, err = buf.ReadBytes('\n')
			if err != nil {
				return nil, err
			}
			i = 0
			j := len(b) - 1
			for 0 <= j && IsSpace(b[j]) {
				j--
			}
			b = b[0 : j+1]
		}
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		if i == j {
			return nil, io.ErrUnexpectedEOF
		}
		return b[j:i], nil
	}
}

// -----------------------------------------------------------------------------

// IO functions

// Reads next token and return it as []byte
func readb() []byte {
	b, err := nextToken()
	if err != nil {
		panic(err)
	}
	return b
}

// Reads next token and return it as string
func reads() string {
	return string(readb())
}

// Read next line as []byte
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b
}

// Read next line as string
func readsln() string {
	return string(readbln())
}

// Reads next token and return it as int64
func readll() int64 {
	i, err := strconv.ParseInt(reads(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// Reads next token and return it as int
func readi() int {
	return int(readll())
}

// Reads next token and return it as float64
func readf() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// Write args to OutputWriter with the format f
func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(OutputWriter, f, args...)
}

// Write args to OutputWriter without format
func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(OutputWriter, args...)
}

// Write args to stderr with the format f
func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// Write args to stderr without format
func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// -----------------------------------------------------------------------------

// Simple math functions

const (
	// big prime
	INF  = 1000000007
	INF2 = 1000000009
	INF3 = 998244353
)

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

func minll(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

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

func maxll(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absll(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// egcd(a, b) returns d, x, y:
//   d is gcd(a,b)
//   x, y are  integers that satisfy ax + by = d
func egcd(a, b int) (int, int, int) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcd(b, a%b)
	return d, y, x - a/b*y
}

func egcdll(a, b int64) (int64, int64, int64) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcdll(b, a%b)
	return d, y, x - a/b*y
}

func gcd(a, b int) int {
	d, _, _ := egcd(a, b)
	return d
}

func gcdll(a, b int64) int64 {
	d, _, _ := egcdll(a, b)
	return d
}

// set up IO functions
func init() {
	// for non-interactive
	SetInput(os.Stdin)
	SetOutput(os.Stdout)

	// Enable below when interactive.  Its ok to leave above intact.
	// SetInteractive(os.Stdout, os.Stdin)
}

func main() {
	defer Flush()

	n := readi()
	a := readb()
	b := readb()
	var ans int
	for i := 0; i < n; i++ {
		x := int(a[i] - '0')
		y := int(b[i] - '0')
		ans += check(x, y)
	}
	println(ans)
}

func check(a, b int) int {
	if b < a {
		a, b = b, a
	}
	return min(b-a, a+10-b)
}

package main

import (
        "fmt"
)

func main() {
        var n, m int
        var s1, s2 string
        fmt.Scan(&n, &s1, &s2)
        for i, _ := range s1 {
                a := int(s1[i] - '0')
                b := int(s2[i] - '0')
                j := a
                k := 0
                for ; a != b && j != b; k++ {
                        if a == 10 {
                                a = 0
                                if b == 0 {
                                        break
                                }
                        }
                        if j == -1 {
                                j = 9
                                if b == 9 {
                                        break
                                }
                        }
                        a++
                        j--
                }
                m += k
        }
        fmt.Println(m)
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.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 main() {
	var T int
	var A, B string

	scanf("%d \n", &T)
	scanf("%s \n", &A)
	scanf("%s \n", &B)

	aArray := strings.Split(A, "")
	bArray := strings.Split(B, "")
	result := 0
	for i, _ := range aArray {
		a, _ := strconv.Atoi(aArray[i])
		b, _ := strconv.Atoi(bArray[i])
		diff := getDiff(a, b)
		if diff <=5 {
			result += diff
			continue
		}

		if a < b {
			a = a + 10
			result += getDiff(a, b)
		}else {
			b = b + 10
			result += getDiff(a, b)
		}

	}

	fmt.Println(result)
}

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

	return a - b
}

package main

import "fmt"
import "bufio"
import "os"

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

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	var n int
	scanner.Scan()

	fmt.Sscanf(scanner.Text(), "%d", &n)

	M := make([][]int, 2)
	for x := 0; x < 2; x++ {
		M[x] = make([]int, n)
	}
	for i := 0; i < 2; i++ {
		scanner.Scan()
		line := scanner.Text()
		for u, c := range line {
			M[i][u] = int(c - '0')
		}
	}

	var ret int

	for i := 0; i < n; i++ {
		a := max(M[0][i], M[1][i])
		b := min(M[0][i], M[1][i])

		ret += min(a - b, min(10 - a + b, 10 - b + a))
	}

	fmt.Println(ret)
}

package main

import (
	"fmt"
	"math"
)

func solve(first, second int) int {
	ans := 0
	var difference = int(math.Abs(float64(first - second)))
	if difference < 5 {
		ans += difference
	} else {
		ans += 10 - difference
	}
	return ans
}

func main() {
	var n, s int
	fmt.Scan(&n)
	var a, b string
	fmt.Scan(&a, &b)
	for i, _ := range a {
		s += solve(int(b[i]), int(a[i]))
	}
	fmt.Println(s)
}

// CombinationLock project main.go
package main

import (
	"fmt"
)

func main() {
	num_digit := 0
	original := ""
	comb := ""

	fmt.Scan(&num_digit)
	fmt.Scan(&original)
	fmt.Scan(&comb)

	sum_move := 0
	for idx, _ := range original {

		original_digit := int(original[idx] - '0')
		comb_digit := int(comb[idx] - '0')

		if original_digit < comb_digit {
			tmp := original_digit
			original_digit = comb_digit
			comb_digit = tmp
		}

		if original_digit-comb_digit > 5 {
			comb_digit += 10
			original_digit *= -1
		} else {
			comb_digit *= -1
		}

		sum_remain := comb_digit + original_digit

		if sum_remain < 0 {
			sum_remain *= -1
		}
		sum_move += (sum_remain)

	}

	fmt.Printf("%d\n", sum_move)

}

// CombinationLock project main.go
package main

import (
	"fmt"
)

func Min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func Max(x,y int) int {
	if x < y {
		return y
	}
	return x
}

func main() {
	num_digit := 0
	original := ""
	comb := ""

	fmt.Scan(&num_digit)
	fmt.Scan(&original)
	fmt.Scan(&comb)

	sum_move := 0
	for idx, _ := range original {

		original_digit := int(original[idx] - '0')
		comb_digit := int(comb[idx] - '0')

		if original_digit < comb_digit {
			tmp := original_digit
			original_digit = comb_digit
			comb_digit = tmp
		}

		sum_digit := Min(original_digit - comb_digit, 10+comb_digit-original_digit)

		sum_move += (sum_digit)

	}

	fmt.Printf("%d\n", sum_move)

}

// CombinationLock project main.go
package main

import (
	"fmt"
)

func main() {
	num_digit := 0
	state_original := 0
	state_comb := 0

	original := ""
	comb := ""

	fmt.Scan(&num_digit)
	fmt.Scan(&original)
	fmt.Scan(&comb)

	sum_move := 0
	for idx, _ := range original {

		state_original = int(original[idx] - '0')
		state_comb = int(comb[idx] - '0')

		original_remain := state_original % 10
		state_original = state_original / 10

		comb_remain := state_comb % 10
		state_comb = state_comb / 10

		if original_remain < comb_remain {
			tmp := original_remain
			original_remain = comb_remain
			comb_remain = tmp
		}

		if original_remain-comb_remain > 5 {
			comb_remain += 10
			original_remain *= -1
		} else {
			comb_remain *= -1
		}

		sum_remain := comb_remain + original_remain

		if sum_remain < 0 {
			sum_remain *= -1
		}
		sum_move += (sum_remain)

	}

	fmt.Printf("%d\n", sum_move)

}

package main

import (
	"fmt"
	"math"
)

func main() {
	var n, res int
	fmt.Scan(&n)
	var beg, end string
	fmt.Scan(&beg, &end)

	for i, _ := range beg {
		var diff = int(math.Abs(float64(int(end[i]) - int(beg[i]))))
		if diff < 5 {
			res += diff
		} else {
			res += 10 - diff
		}
	}
	fmt.Println(res)
}

package main

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

func abs(a, e int64) int64 {
	if a-e < 0 {
		return -1 * (a - e)
	}

	return a - e
}

func main() {

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	n := scanner.Text()

	_, _ = strconv.Atoi(n)
	scanner.Scan()
	actual := scanner.Text()
	scanner.Scan()
	expected := scanner.Text()

	var actualNum, expectedNum int64

	actualNum, _ = strconv.ParseInt(actual, 10, 64)
	expectedNum, _ = strconv.ParseInt(expected, 10, 64)

	var result int64

	for actualNum > 0 && expectedNum > 0 {
		var actDig, expDig int64 = actualNum % 10, expectedNum % 10
		num1 := abs(actDig, expDig)

		if num1 < 5 {
			result += num1
		} else {
			if actDig > expDig {
				result += (expDig + 10) - actDig
			} else {
				result += (actDig + 10) - expDig
			}
		}

		actualNum /= 10
		expectedNum /= 10
	}

	fmt.Println(result)
}

package main

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

func abs(a, e int) int {
	if a-e < 0 {
		return -1 * (a - e)
	}

	return a - e
}

func main() {

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	n := scanner.Text()

	_, _ = strconv.Atoi(n)
	scanner.Scan()
	actual := scanner.Text()
	scanner.Scan()
	expected := scanner.Text()

	actualNum, _ := strconv.Atoi(actual)
	expectedNum, _ := strconv.Atoi(expected)

	result := 0

	for actualNum > 0 && expectedNum > 0 {
		actDig, expDig := actualNum%10, expectedNum%10
		num1 := abs(actDig, expDig)

		if num1 < 5 {
			result += num1
		} else {
			if actDig > expDig {
				result += (expDig + 10) - actDig
			} else {
				result += (actDig + 10) - expDig
			}
		}

		actualNum /= 10
		expectedNum /= 10
	}

	fmt.Println(result)
}

package main

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

func main() {
	var n, s int
	var s1, s2 string
	in := bufio.NewReader(os.Stdin)
	fmt.Fscanf(in, "%d\n", &n)
	fmt.Fscanf(in, "%s\n", &s1)
	fmt.Fscanf(in, "%s\n", &s2)

	for i := int(0); i < n; i++ {
		current, _ := strconv.Atoi(string(s1[i]))
		key, _ := strconv.Atoi(string(s2[i]))
		result := math.Abs(float64(key) - float64(current))
		s += check(int(result), int(math.Abs(float64(key+current-10))))
	}
	fmt.Println(s)
}
func check(a int, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

package main

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

func main() {
	var n int16
	var s uint16
	var s1, s2 string
	in := bufio.NewReader(os.Stdin)
	fmt.Fscanf(in, "%d\n", &n)
	fmt.Fscanf(in, "%s\n", &s1)
	fmt.Fscanf(in, "%s\n", &s2)

	for i := int16(0); i < n; i++ {
		current, _ := strconv.Atoi(string(s1[i]))
		key, _ := strconv.Atoi(string(s2[i]))
		result := math.Abs(float64(key) - float64(current))
		s += check(uint16(result), uint16(key)-10+uint16(current))
	}
	fmt.Println(s)
}
func check(a uint16, b uint16) uint16 {
	if a > b {
		return b
	} else {
		return a
	}
}

package main

import (
        "fmt"
)

func main() {
        var n, m int
        var s1, s2 string
        fmt.Scan(&n, &s1, &s2)
        for i, _ := range s1 {
                a := int(s1[i] - '0')
                b := int(s2[i] - '0')
                j := a
                k := 0
                for ; a != b && j != b; k++ {
                        if a == 10 {
                                a = 0
                        }
                        if j == -1 {
                                j = 9
                        }
                        a++
                        j--
                }
                m += k
        }
        fmt.Println(m)
}

// CombinationLock project main.go
package main

import (
	"fmt"
)

func main() {
	num_digit := 0
	state_original := 0
	state_comb := 0

	fmt.Scan(&num_digit)
	fmt.Scan(&state_original)
	fmt.Scan(&state_comb)

	sum_move := 0
	for state_original != 0 {
		original_remain := state_original % 10
		state_original = state_original / 10

		comb_remain := state_comb % 10
		state_comb = state_comb / 10

		if original_remain < comb_remain {
			tmp := original_remain
			original_remain = comb_remain
			comb_remain = tmp
		}

		if original_remain-comb_remain > 5 {
			comb_remain += 10
			original_remain *= -1
		} else {
			comb_remain *= -1
		}

		sum_remain := comb_remain + original_remain

		if sum_remain < 0 {
			sum_remain *= -1
		}
		sum_move += (sum_remain)

	}

	fmt.Printf("%d\n", sum_move)

}