package main

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

var sc *bufio.Scanner

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

const INF = 1000000000

type node struct {
	depth int
	adj   []*node
}

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	h, w := nextInt(), nextInt()

	var root node
	root.depth = -1
	board := make([][]*node, h)
	for i := range board {
		sc.Scan()
		s := sc.Text()
		line := make([]*node, w)
		for j, r := range s {
			line[j] = &node{}
			line[j].depth = INF
			if r == '#' {
				root.adj = append(root.adj, line[j])
			}
		}
		board[i] = line
	}

	for i, line := range board {
		for j := range line {
			if i > 0 {
				board[i][j].adj = append(board[i][j].adj, board[i-1][j])
			}
			if i < h-1 {
				board[i][j].adj = append(board[i][j].adj, board[i+1][j])
			}
			if j > 0 {
				board[i][j].adj = append(board[i][j].adj, board[i][j-1])
			}
			if j < w-1 {
				board[i][j].adj = append(board[i][j].adj, board[i][j+1])
			}
		}
	}

	ans := 0
	queue := []*node{&root}
	for len(queue) > 0 {
		grid := queue[0]
		queue = queue[1:]
		for _, other := range grid.adj {
			if other.depth > grid.depth+1 {
				other.depth = grid.depth + 1
				queue = append(queue, other)
				ans = other.depth
			}
		}
	}
	fmt.Println(ans)
}


package main

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

var H, W int

func main() {
	reader := bufio.NewReaderSize(os.Stdin, 1000000000)
	fmt.Scan(&H, &W)

	q := make([][]int, 0)
	m := make([][]bool, H)

	for i := 0; i < H; i++ {
		line, _, _ := reader.ReadLine()
		m[i] = make([]bool, W) // Falseで初期化されている

		for j, v := range line {
			if string(v) == "#" {
				q = append(q, []int{i, j})
				m[i][j] = true
			}
		}
	}
	fmt.Println(bfs(q, m))
}

func bfs(q [][]int, m [][]bool) int {
	var ans int

	for len(q) != 0 {
		ans++
		len := len(q)

		for i := 0; i < len; i++ {
			var y, x int = q[0][0], q[0][1]
			q = append(q[1:])

			if 0 <= y+1 && y+1 < H && m[y+1][x] == false {
				m[y+1][x] = true
				q = append(q, []int{y + 1, x})
			}
			if 0 <= y-1 && y-1 < H && m[y-1][x] == false {
				m[y-1][x] = true
				q = append(q, []int{y - 1, x})
			}
			if 0 <= x+1 && x+1 < W && m[y][x+1] == false {
				m[y][x+1] = true
				q = append(q, []int{y, x + 1})
			}
			if 0 <= x-1 && x-1 < W && m[y][x-1] == false {
				m[y][x-1] = true
				q = append(q, []int{y, x - 1})
			}
		}
	}
	return ans - 1
}

Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.

Score : 300 points

Problem Statement

You are given a grid of squares with H horizontal rows and W vertical columns, where each square is painted white or black.
HW characters from A_{11} to A_{HW} represent the colors of the squares.
A_{ij} is # if the square at the i-th row from the top and the j-th column from the left is black, and A_{ij} is . if that square is white.

We will repeatedly perform the following operation until all the squares are black:

Every white square that shares a side with a black square, becomes black.

Find the number of operations that will be performed.
The initial grid has at least one black square.

Constraints

1 \leq H,W \leq 1000

A_{ij} is # or ..

The given grid has at least one black square.

Input

Input is given from Standard Input in the following format:

H W
A_{11}A_{12}...A_{1W}
:
A_{H1}A_{H2}...A_{HW}

Output

Print the number of operations that will be performed.

Sample Input 1

3 3
...
.#.
...

Sample Output 1

2

After one operation, all but the corners of the grid will be black. After one more operation, all the squares will be black.

Sample Input 2

6 6
..#..#
......
#..#..
......
.#....
....#.

Sample Output 2

3

Submitted source-code file size, in bytes.

Execution CPU time reported by official Project CodeNet metadata, in milliseconds.

Peak memory usage reported by official Project CodeNet metadata, in kilobytes.


package main

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

var H, W int

func main() {
	reader := bufio.NewReaderSize(os.Stdin, 10000000)
	fmt.Scan(&H, &W)

	q := make([][]int, 0)
	m := make([][]bool, H)

	for i := 0; i < H; i++ {
		line, _, _ := reader.ReadLine()
		m[i] = make([]bool, W) // Falseで初期化されている

		for j, v := range line {
			if string(v) == "#" {
				q = append(q, []int{i, j})
				m[i][j] = true
			}
		}
	}
	fmt.Println(bfs(q, m))
}

func bfs(q [][]int, m [][]bool) int {
	var ans int

	for len(q) != 0 {
		ans++
		len := len(q)

		for i := 0; i < len; i++ {
			var y, x int = q[0][0], q[0][1]
			q = append(q[1:])

			if 0 <= y+1 && y+1 < H && m[y+1][x] == false {
				m[y+1][x] = true
				q = append(q, []int{y + 1, x})
			}
			if 0 <= y-1 && y-1 < H && m[y-1][x] == false {
				m[y-1][x] = true
				q = append(q, []int{y - 1, x})
			}
			if 0 <= x+1 && x+1 < W && m[y][x+1] == false {
				m[y][x+1] = true
				q = append(q, []int{y, x + 1})
			}
			if 0 <= x-1 && x-1 < W && m[y][x-1] == false {
				m[y][x-1] = true
				q = append(q, []int{y, x - 1})
			}
		}
	}
	return ans - 1
}


package main

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

var H, W int

func main() {
	fmt.Scan(&H, &W)

	reader := bufio.NewScanner(os.Stdin)
	q := make([][]int, 0)
	m := make([][]bool, H)

	for i := 0; i < H; i++ {
		m[i] = make([]bool, W) // Falseで初期化されている
		reader.Scan()

		for j := 0; j < W; j++ {
			if string(reader.Text()[j]) == "#" {
				q = append(q, []int{i, j})
				m[i][j] = true
			}
		}
	}
	fmt.Println(bfs(q, m))
}

func bfs(q [][]int, m [][]bool) int {
	var ans int

	for len(q) != 0 {
		ans++
		len := len(q)

		for i := 0; i < len; i++ {
			var y, x int = q[0][0], q[0][1]
			q = append(q[1:])

			if 0 <= y+1 && y+1 < H && m[y+1][x] == false {
				m[y+1][x] = true
				q = append(q, []int{y + 1, x})
			}
			if 0 <= y-1 && y-1 < H && m[y-1][x] == false {
				m[y-1][x] = true
				q = append(q, []int{y - 1, x})
			}
			if 0 <= x+1 && x+1 < W && m[y][x+1] == false {
				m[y][x+1] = true
				q = append(q, []int{y, x + 1})
			}
			if 0 <= x-1 && x-1 < W && m[y][x-1] == false {
				m[y][x-1] = true
				q = append(q, []int{y, x - 1})
			}
		}
	}
	return ans - 1
}


package main

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

type YX struct {
	y int
	x int
}

func main() {
	var h, w int
	fmt.Scan(&h, &w)
	var a = make([][]byte, h)
	var d = make([][]int, h)
	var reader = bufio.NewReaderSize(os.Stdin, 1024)
    var ql = make([]YX, 0)
    var ans = 0

	for y := 0; y < h; y++ {
		l, _, _ := reader.ReadLine()
		a[y] = make([]byte, w)
		d[y] = make([]int, w)
		copy(a[y], l)
		for x := 0; x < w; x++ {
			if a[y][x] == '.' {
				d[y][x] = -1
			} else {
				ql = append(ql, YX{y, x})
			}
		}
	}

	for len(ql) > 0 {
		var newql = make([]YX, 0)
		for _, q := range ql {
			el := []bool{false, false, false, false}
			if q.y > 0 {
				el[0] = true
			}
			if q.y < h-1 {
				el[2] = true
			}
			if q.x > 0 {
				el[3] = true
			}
			if q.x < w-1 {
				el[1] = true
            }
            ans = d[q.y][q.x]
			for i, e := range el {
				if e {
					switch i {
					case 0:
						y, x := q.y-1, q.x
						if d[y][x] == -1 {
							d[y][x] = d[q.y][q.x] + 1
                            newql = append(newql, YX{y, x})
						}
					case 1:
						y, x := q.y, q.x+1
						if d[y][x] == -1 {
							d[y][x] = d[q.y][q.x] + 1
							newql = append(newql, YX{y, x})
						}
					case 2:
						y, x := q.y+1, q.x
						if d[y][x] == -1 {
							d[y][x] = d[q.y][q.x] + 1
							newql = append(newql, YX{y, x})
						}
					case 3:
						y, x := q.y, q.x-1
						if d[y][x] == -1 {
							d[y][x] = d[q.y][q.x] + 1
							newql = append(newql, YX{y, x})
						}
					}
				}
			}
		}
		ql = newql
	}

	fmt.Println(ans)
}


package main

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

func main() {
    var fp *os.File
    fp = os.Stdin
    reader := bufio.NewReaderSize(fp, 1024)
    var queue [][]int
    line, _, _ := reader.ReadLine()
    arr := strings.Split(string(line), " ")
    H, _ := strconv.Atoi(arr[0])
    W, _ := strconv.Atoi(arr[1])
    visited := make([][]int, H)
    maps := make([][]byte, H)

    for i := 0; i < H; i++ {
        maps[i] = make([]byte, W)
        line, _, _ = reader.ReadLine()
        copy(maps[i], line)

        for j := 0; j < W; j++ {
            visited[i] = append(visited[i], -1)

            if maps[i][j] == '#' {
                var val []int
                val = append(val, i)
                val = append(val, j)
                queue = append(queue, val)
                visited[i][j] = 0
            }
        }
    }

    bfs(queue, visited, H, W)
}

func bfs(queue [][]int, visited [][]int, H int, W int) {
    var dx [4]int
    var dy [4]int
    dx[0] = 0
    dx[1] = 0
    dx[2] = 1
    dx[3] = -1
    dy[0] = 1
    dy[1] = -1
    dy[2] = 0
    dy[3] = 0
    var now_x, now_y, next_x, next_y int
    var cnt int = 0

    for len(queue) > 0 {
        now_x = queue[0][0]
        now_y = queue[0][1]

        for i := 0; i < 4; i++ {
            next_x = queue[0][0] + dx[i]
            next_y = queue[0][1] + dy[i]

            if next_x >= 0 && next_x <= W - 1 &&
               next_y >= 0 && next_y <= H - 1 &&
               visited[next_x][next_y] == -1 {
               var val []int
               val = append(val, next_x)
               val = append(val, next_y)
               queue = append(queue, val)
               visited[next_x][next_y] = visited[now_x][now_y] + 1
               cnt = visited[next_x][next_y]
            }
        }

        queue = remove(queue)
    }

   fmt.Println(cnt)
}

// スライスの中身削除
func remove(queue [][]int) [][]int {
    return queue[1:]
}


package main

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

func main() {
    var fp *os.File
    fp = os.Stdin
    reader := bufio.NewReaderSize(fp, 4096)
    var line string
    var line_rune []rune
    var str string
    var queue [][]int
    line = readLine(reader)
    arr := strings.Split(line, " ")
    H, _ := strconv.Atoi(arr[0])
    W, _ := strconv.Atoi(arr[1])
    maps := make([][]string, H)
    visited := make([][]int, H)

    for i := 0; i < H; i++ {
        line_rune = []rune(readLine(reader))
        for j := 0; j < W; j++ {
            str = string(line_rune[j:j+1])
            maps[i] = append(maps[i], str)
            visited[i] = append(visited[i], -1)

            if str == "#" {
                var val []int
                val = append(val, i)
                val = append(val, j)
                queue = append(queue, val)
                visited[i][j] = 0
            }
        }
    }

    bfs(queue, maps, visited, H, W)
}

func bfs(queue [][]int, maps [][]string, visited [][]int, H int, W int) {
    var dx [4]int
    var dy [4]int
    dx[0] = 0
    dx[1] = 0
    dx[2] = 1
    dx[3] = -1
    dy[0] = 1
    dy[1] = -1
    dy[2] = 0
    dy[3] = 0
    var now_x, now_y, next_x, next_y int
    var cnt int = 0

    for len(queue) > 0 {
        now_x = queue[0][0]
        now_y = queue[0][1]

        for i := 0; i < 4; i++ {
            next_x = queue[0][0] + dx[i]
            next_y = queue[0][1] + dy[i]

            if next_x >= 0 && next_x <= W - 1 &&
               next_y >= 0 && next_y <= H - 1 &&
               visited[next_x][next_y] == -1 {
               var val []int
               val = append(val, next_x)
               val = append(val, next_y)
               queue = append(queue, val)
               visited[next_x][next_y] = visited[now_x][now_y] + 1
               cnt = visited[next_x][next_y]
            }
        }

        queue = remove(queue)
    }

   fmt.Println(cnt)
}

func readLine(reader *bufio.Reader) string {
    buf := make([]byte, 0, 1000000)

    for {
        l, p, e := reader.ReadLine()

        if e != nil {
            panic(e)
        }

        buf = append(buf, l...)

        if !p {
            break
        }
    }

    return string(buf)
}

// スライスの中身削除
func remove(queue [][]int) [][]int {
    return queue[1:]
}


package main

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

func main() {
    var fp *os.File
    fp = os.Stdin
    reader := bufio.NewReaderSize(fp, 4096)
    var line string
    var str string
    var queue [][]int
    line = readLine(reader)
    arr := strings.Split(line, " ")
    H, _ := strconv.Atoi(arr[0])
    W, _ := strconv.Atoi(arr[1])
    maps := make([][]string, H)
    visited := make([][]int, H)

    for i := 0; i < H; i++ {
        line = readLine(reader)
      	for k, v := range line {
      		str = string(v)
            maps[i] = append(maps[i], str)
            visited[i] = append(visited[i], -1)

            if str == "#" {
                var val []int
                val = append(val, i)
                val = append(val, k)
                queue = append(queue, val)
                visited[i][k] = 0
            }
        }
    }

    // BFS
    var dx [4]int
    var dy [4]int
    dx[0] = 0
    dx[1] = 0
    dx[2] = 1
    dx[3] = -1
    dy[0] = 1
    dy[1] = -1
    dy[2] = 0
    dy[3] = 0
    var now_x, now_y, next_x, next_y int
    var cnt int = 0

    for len(queue) > 0 {
        now_x = queue[0][0]
        now_y = queue[0][1]

        for i := 0; i < 4; i++ {
            next_x = queue[0][0] + dx[i]
            next_y = queue[0][1] + dy[i]

            if (next_x < 0 || next_x >= H || next_y < 0 || next_y >= W) {
                continue;
            }

            if visited[next_x][next_y] == -1 {
               //maps[next_x][next_y] == "." {

            //if next_x >= 0 && next_x <= W - 1 &&
               //next_y >= 0 && next_y <= H - 1 &&
               //visited[next_x][next_y] == -1 {
               //maps[next_x][next_y] == "." {
                 var val []int
                 val = append(val, next_x)
                 val = append(val, next_y)
                 queue = append(queue, val)
                 visited[next_x][next_y] = visited[now_x][now_y] + 1
                 cnt = visited[next_x][next_y]
                 maps[next_x][next_y] = "#"
            }
        }

        queue = remove(queue, 0)
    }

    fmt.Println(cnt)
}

func readLine(reader *bufio.Reader) string {
    buf := make([]byte, 0, 1000000)

    for {
        l, p, e := reader.ReadLine()

        if e != nil {
            panic(e)
        }

        buf = append(buf, l...)

        if !p {
            break
        }
    }

    return string(buf)
}

// スライスの中身削除
func remove(ints [][]int, key int) [][]int {
    result := [][]int{}

    for k, v := range ints {
        if k != key {
            result = append(result, v)
        }
    }

    return result
}


package main

import (
	"fmt"
	"math"
	"os"
	"strings"
)

var H, W int
var A [][]Point

//var whiteNum int

type Point struct {
	x, y   int
	color  int
	isDone bool
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func (p Point) findNearestBlackDistance() (int, int, int) {
	i := 1
	var x, y1, y2 int
	for {
		for j := -1 * i; j <= i; j++ {
			k := i - abs(j)
			x = p.x + j
			y1 = p.y + k
			y2 = p.y - k
			if x >= 0 && y1 >= 0 && x < W && y1 < H {
				if A[y1][x].color == 1 {
					return i, y1, x
				}
			}
			if x >= 0 && y2 >= 0 && x < W && y2 < H {
				if A[y2][x].color == 1 {
					return i, y2, x
				}
			}

		}
		i += 1
	}
	return -1, -1, -1
}

func (p Point) doWhitesWithDistance(distance int) {
	var x, y1, y2 int
	for i := 1; i <= distance; i++ {
		for j := -1 * i; j <= i; j++ {
			k := i - abs(j)
			x = p.x + j
			y1 = p.y + k
			y2 = p.y - k
			if x >= 0 && y1 >= 0 && x < W && y1 < H {
				if A[y1][x].color == 0 {
					if A[y1][x].isDone != true {
						A[y1][x].isDone = true
						//						whiteNum -= 1
					}
				}
			}
			if x >= 0 && y2 >= 0 && x < W && y2 < H {
				if A[y2][x].color == 0 {
					if A[y2][x].isDone != true {
						A[y2][x].isDone = true
						//						whiteNum -= 1
					}
				}
			}
		}
	}
}

func main() {
	fmt.Scan(&H, &W)
	A = make([][]Point, H)
	s := ""
	for i := 0; i < H; i++ {
		A[i] = make([]Point, W)
		fmt.Scan(&s)
		info := strings.Split(s, "")
		for j := 0; j < W; j++ {
			if info[j] == "." {
				A[i][j] = Point{x: j, y: i, color: 0, isDone: false}
			} else {
				A[i][j] = Point{x: j, y: i, color: 1, isDone: true}
			}
		}
	}
	max := 0
	tmp := 0
	var x, y int

	for i := 0; i < H; i++ {
		for j := 0; j < W; j++ {
			if A[i][j].isDone != true {
				tmp, x, y = A[i][j].findNearestBlackDistance()
				if tmp == -1 {
					fmt.Println(max)
					os.Exit(0)
				}
				A[y][x].doWhitesWithDistance(tmp)
				if tmp > max {
					max = tmp
				}
			}
		}
	}
	fmt.Println(max)
}


package main

import (
	"fmt"
)

type xydata struct {
	x int
	y int
}

func main() {
	matrix := input()

	count := 0
	for {
		if true == check(matrix) {
			break
		}
		XYdata := getxydate(matrix)
		matrix = update(matrix, XYdata)
		count++
	}
	fmt.Println(count)
}

func check(matrix [][]string) bool {
	for x := 0; x < len(matrix[0]); x++ {
		for y := 0; y < len(matrix); y++ {
			if matrix[y][x] == "." {
				return false
			}
		}
	}
	return true
}

func update(matrix [][]string, inXYdata []xydata) [][]string {
	for i := 0; i < len(inXYdata); i++ {
		if (inXYdata[i].x - 1) >= 0 {
			matrix[inXYdata[i].y][inXYdata[i].x-1] = "#"
		}
		if (inXYdata[i].x + 1) < len(matrix[0]) {
			matrix[inXYdata[i].y][inXYdata[i].x+1] = "#"
		}
		if (inXYdata[i].y - 1) >= 0 {
			matrix[inXYdata[i].y-1][inXYdata[i].x] = "#"
		}
		if (inXYdata[i].y + 1) < len(matrix) {
			matrix[inXYdata[i].y+1][inXYdata[i].x] = "#"
		}
	}
	/*
		for x := 0; x < len(matrix); x++ {
			for y := 0; y < len(matrix[0]); y++ {
				fmt.Printf("%s", matrix[x][y])
			}
			fmt.Println()
		}
	*/
	return matrix
}

func getxydate(matrix [][]string) []xydata {
	var resXYdata []xydata
	//fmt.Printf("%d %d\n", len(matrix[0]), len(matrix))
	for x := 0; x < len(matrix[0]); x++ {
		for y := 0; y < len(matrix); y++ {
			if matrix[y][x] == "#" {
				resXYdata = append(resXYdata, xydata{x, y})
				//fmt.Printf("%d %d\n", x, y)
			}
		}
	}
	return resXYdata
}

func input() [][]string {
	var (
		x, y int
	)
	fmt.Scan(&x)
	fmt.Scan(&y)
	matrix := make([][]string, y)
	for yy := 0; yy < y; yy++ {
		matrix[yy] = make([]string, x)
	}

	var str string
	for yy := 0; yy < y; yy++ {
		fmt.Scan(&str)
		r := []rune(str)
		for xx := 0; xx < x; xx++ {
			matrix[yy][xx] = string(r[xx])
		}
	}
	/*
		for x := 0; x < i; x++ {
			for y := 0; y < j; y++ {
				fmt.Printf("%s", matrix[x][y])
			}
			fmt.Println()
		}
	*/
	return matrix
}


package main

import (
	"fmt"
	"strings"
	"unsafe"
)

func decode(s string) []byte {
	s = strings.Replace(s, "#", "1", -1)
	s = strings.Replace(s, ".", "0", -1)
	vec := *(*[]byte)(unsafe.Pointer(&s))

	for i := range vec {
		vec[i] -= '0'
	}
	return vec
}

func orVec(op0, op1 []byte) {
	for i := range op0 {
		op0[i] |= op1[i]
	}
}

func orMatrix(op0, op1 [][]byte) {
	for i := range op0 {
		orVec(op0[i], op1[i])
	}
}

func checkZeroVec(b []byte) bool {
	for _, v := range b {
		if v == 1 {
			return false
		}
	}
	return true
}

func checkFullVec(b, checked []byte) bool {
	for i, v := range b {
		if checked[i] == 1 {
			continue
		}
		if v == 0 {
			return false
		}
	}
	return true
}

func checkFullMatrix(d, checked [][]byte) bool {
	for i, v := range d {
		if !checkFullVec(v, checked[i]) {
			return false
		}
	}
	return true
}

func genMask(op0, op1, checked [][]byte) {
	for h := range op0 {
		for w := 0; w < len(op0[h]); w++ {
			v := op0[h][w]
			if v == 1 && checked[h][w] == 0 {
				checked[h][w] = 1
				op1[h][w] = 1
				if h != 0 {
					op1[h-1][w] = 1
				}
				if w != 0 {
					op1[h][w-1] = 1
				}
				if h != len(op0)-1 {
					op1[h+1][w] = 1
				}
				if w != len(op0[h])-1 {
					op1[h][w+1] = 1
				}
			}
		}
	}
}

func main() {
	var h, w int

	fmt.Scanf("%d%d", &h, &w)

	a := [][]byte{}
	for i := 0; i < h; i++ {
		var s string
		fmt.Scanf("%s", &s)
		a = append(a, decode(s))
	}

	buf := make([][]byte, len(a))

	for i := 0; i < h; i++ {
		buf[i] = make([]byte, len(a[i]))
	}
	checked := make([][]byte, len(a))

	for i := 0; i < h; i++ {
		checked[i] = make([]byte, len(a[i]))
	}

	if checkFullMatrix(a, checked) {
		fmt.Println(0)
		return
	}

	cnt := 0
	for {
		genMask(a, buf, checked)
		cnt++
		if checkFullMatrix(buf, checked) {
			fmt.Println(cnt)
			return
		}
		//orMatrix(a, buf)
		a, buf = buf, a
	}
}


package main

import (
	"fmt"
	"strings"
	"sync"
	"unsafe"
)

const p = 1000

var semaphore = make(chan bool, p)

func decode(s string) []byte {
	s = strings.Replace(s, "#", "1", -1)
	s = strings.Replace(s, ".", "0", -1)
	vec := *(*[]byte)(unsafe.Pointer(&s))

	for i := range vec {
		vec[i] -= '0'
	}
	return vec
}

func orVec(op0, op1 []byte) {
	for i := range op0 {
		op0[i] |= op1[i]
	}
}

func orMatrix(op0, op1 [][]byte) {
	var wg sync.WaitGroup

	for i := range op0 {
		wg.Add(1)
		semaphore <- true
		go func(op0 []byte, op1 []byte, wg *sync.WaitGroup) {
			defer func() {
				wg.Done()
				<-semaphore
			}()
			orVec(op0, op1)
		}(op0[i], op1[i], &wg)
	}
	wg.Wait()
}

func checkFullVec(b []byte) bool {
	for _, v := range b {
		if v == 0 {
			return false
		}
	}
	return true
}

func checkFullMatrix(d [][]byte) bool {
	for _, v := range d {
		if !checkFullVec(v) {
			return false
		}
	}
	return true
}

func genMask(op0, op1 [][]byte) {
	var wg sync.WaitGroup
	for h := range op0 {
		wg.Add(1)
		semaphore <- true
		go func(h int, wg *sync.WaitGroup) {
			func() {
				wg.Done()
				<-semaphore
			}()

			for w, v := range op0[h] {
				if v == 1 {
					op1[h][w] = 1
					if h != 0 {
						op1[h-1][w] = 1
					}
					if w != 0 {
						op1[h][w-1] = 1
					}
					if h != len(op0)-1 {
						op1[h+1][w] = 1
					}
					if w != len(op0[h])-1 {
						op1[h][w+1] = 1
					}
				}
			}
		}(h, &wg)

	}
	wg.Wait()
}

func main() {
	var h, w int

	fmt.Scanf("%d%d", &h, &w)

	a := [][]byte{}
	for i := 0; i < h; i++ {
		var s string
		fmt.Scanf("%s", &s)
		a = append(a, decode(s))
	}

	buf := make([][]byte, len(a))

	for i := 0; i < h; i++ {
		buf[i] = make([]byte, len(a[i]))
	}

	if checkFullMatrix(a) {
		fmt.Println(0)
		return
	}

	cnt := 0
	for {
		genMask(a, buf)
		cnt++
		if checkFullMatrix(buf) {
			fmt.Println(cnt)
			return
		}
		//orMatrix(a, buf)
		a, buf = buf, a
	}
}


package main

import (
	"fmt"
	"strings"
	"unsafe"
)

func decode(s string) []byte {
	s = strings.Replace(s, "#", "1", -1)
	s = strings.Replace(s, ".", "0", -1)
	vec := *(*[]byte)(unsafe.Pointer(&s))

	for i := range vec {
		vec[i] -= '0'
	}
	return vec
}

func orVec(op0, op1 []byte) {
	for i := range op0 {
		op0[i] |= op1[i]
	}
}

func orMatrix(op0, op1 [][]byte) {
	for i := range op0 {
		orVec(op0[i], op1[i])
	}
}

func checkFullVec(b []byte) bool {
	for _, v := range b {
		if v == 0 {
			return false
		}
	}
	return true
}

func checkFullMatrix(d [][]byte) bool {
	for _, v := range d {
		if !checkFullVec(v) {
			return false
		}
	}
	return true
}

func genMask(op0, op1 [][]byte) {
	for h := range op0 {
		for w, v := range op0[h] {
			if v == 1 {
				op1[h][w] = 1
				if h != 0 {
					op1[h-1][w] = 1
				}
				if w != 0 {
					op1[h][w-1] = 1
				}
				if h != len(op0)-1 {
					op1[h+1][w] = 1
				}
				if w != len(op0[h])-1 {
					op1[h][w+1] = 1
				}
			}
		}
	}
}

func main() {
	var h, w int

	fmt.Scanf("%d%d", &h, &w)

	a := [][]byte{}
	for i := 0; i < h; i++ {
		var s string
		fmt.Scanf("%s", &s)
		a = append(a, decode(s))
	}

	buf := make([][]byte, len(a))

	for i := 0; i < h; i++ {
		buf[i] = make([]byte, len(a[i]))
	}

	if checkFullMatrix(a) {
		fmt.Println(0)
		return
	}

	cnt := 0
	for {
		genMask(a, buf)
		cnt++
		if checkFullMatrix(buf) {
			fmt.Println(cnt)
			return
		}
		orMatrix(a, buf)
	}
}


package main

import (
	"fmt"
)

type xydata struct {
	x int
	y int
}

func main() {
	matrix := input()
	//fmt.Print(len(matrix))

	count := 0
	for {
		if true == check(matrix) {
			break
		}
		XYdata := getxydate(matrix)
		matrix = update(matrix, XYdata)
		count++
		if count > 20 {
			break
		}
	}
	fmt.Println(count)
}

func check(matrix [][]string) bool {
	for x := 0; x < len(matrix); x++ {
		for y := 0; y < len(matrix[0]); y++ {
			if matrix[x][y] == "." {
				return false
			}
		}
	}
	return true
}

func update(matrix [][]string, inXYdata []xydata) [][]string {
	for i := 0; i < len(inXYdata); i++ {
		if (inXYdata[i].x - 1) >= 0 {
			matrix[inXYdata[i].x-1][inXYdata[i].y] = "#"
		}
		if (inXYdata[i].x + 1) < len(matrix) {
			matrix[inXYdata[i].x+1][inXYdata[i].y] = "#"
		}
		if (inXYdata[i].y - 1) >= 0 {
			matrix[inXYdata[i].x][inXYdata[i].y-1] = "#"
		}
		if (inXYdata[i].y + 1) < len(matrix) {
			matrix[inXYdata[i].x][inXYdata[i].y+1] = "#"
		}
	}
	/*
		for x := 0; x < len(matrix); x++ {
			for y := 0; y < len(matrix[0]); y++ {
				fmt.Printf("%s", matrix[x][y])
			}
			fmt.Println()
		}
	*/
	return matrix
}

func getxydate(matrix [][]string) []xydata {
	var resXYdata []xydata
	for x := 0; x < len(matrix); x++ {
		for y := 0; y < len(matrix[0]); y++ {
			if matrix[x][y] == "#" {
				resXYdata = append(resXYdata, xydata{x, y})
			}
		}
	}
	return resXYdata
}

func input() [][]string {
	var (
		i, j int
	)
	fmt.Scan(&i)
	fmt.Scan(&j)
	matrix := make([][]string, i)
	for k := 0; k < j; k++ {
		matrix[k] = make([]string, j)
	}

	var str string
	for x := 0; x < i; x++ {
		fmt.Scan(&str)
		r := []rune(str)
		for y := 0; y < j; y++ {
			matrix[x][y] = string(r[y])
		}
	}
	/*
		for x := 0; x < i; x++ {
			for y := 0; y < j; y++ {
				fmt.Printf("%s", matrix[x][y])
			}
			fmt.Println()
		}
	*/
	return matrix
}


package main

import (
	"fmt"
)

var H, W int
var s string
var max int
var dir = [4][2]int{{1, 0}, {0, 1}, {-1, 0}, {0, -1}}

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

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

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

func contains(s [][2]int, e [2]int) bool {
	for _, v := range s {
		if e == v {
			return true
		}
	}
	return false
}

func bfs(h, w int, field [][]bool) int {
	min := 1
	now := [][2]int{{h, w}}
	var nextNow [][2]int
	visited := [][2]int{{h, w}}
L:
	for {
		for _, n := range now {
			for _, d := range dir {
				next := [2]int{n[0] + d[0], n[1] + d[1]}
				if 0 <= next[0] && next[0] <= H-1 && 0 <= next[1] && next[1] <= W-1 {
					if !contains(visited, next) {
						if field[next[0]][next[1]] {
							break L
						}
						visited = append(visited, next)
						nextNow = append(nextNow, next)
					}
				}
			}
		}
		now = nextNow
		nextNow = [][2]int{{}}
		min++
	}
	return min
}

func main() {
	fmt.Scan(&H, &W)
	var field [][]bool
	field = make([][]bool, H)
	for h := 0; h < H; h++ {
		field[h] = make([]bool, W)
		fmt.Scan(&s)
		for w := 0; w < W; w++ {
			if s[w] == '#' {
				field[h][w] = true
			}
		}
	}
	for h := 0; h < H; h++ {
		for w := 0; w < W; w++ {
			if !field[h][w] {
				max = Max(max, bfs(h, w, field))
			}
		}
	}
	fmt.Println(max)
}


package main

import (
	"fmt"
)

var H, W int
var s string
var dirs = [][]int{{1, 0}, {0, 1}, {-1, 0}, {0, -1}}

func check(field [][]bool) bool {
	for h := 0; h < H; h++ {
		for _, x := range field[h] {
			if !x {
				return true
			}
		}
	}
	return false
}

func main() {
	fmt.Scan(&H, &W)
	var field, new_field [][]bool
	field = make([][]bool, H)
	new_field = make([][]bool, H)
	for h := 0; h < H; h++ {
		field[h] = make([]bool, W)
		new_field[h] = make([]bool, W)
		fmt.Scan(&s)
		for w := 0; w < W; w++ {
			if s[w] == '#' {
				field[h][w] = true
				new_field[h][w] = true
			}
		}
	}
	count := 0
	for check(field) {
		for h, f := range field {
			for w, ff := range f {
				if ff {
					for _, d := range dirs {
						t := h + d[0]
						y := w + d[1]
						if 0 <= t && t <= H-1 && 0 <= y && y <= W-1 {
							new_field[t][y] = true
						}
					}
				}
			}
		}
		count++
		copy(new_field, field)
	}
	fmt.Println(count)
}


package main

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

func main() {
	H := nextInt()
	W := nextInt()
	A := make([][]byte, H)
	for i := 0; i < H; i++ {
		A[i] = nextBytes()
	}
	var cnt int
	add := make([]pair, 0)
	bfs := make([]pair, 0)
	for i := 0; i < H; i++ {
		for j := 0; j < W; j++ {
			if A[i][j] == '#' {
				add = append(add, pair{i, j})
			}
		}
	}
	for len(add) > 0 {
		bfs = make([]pair, len(add))
		for i := 0; i < len(add); i++ {
			bfs[i] = add[i]
		}
		add = make([]pair, 0)
		for len(bfs) > 0 {
			next := bfs[0]
			bfs = bfs[1:]
			for d := 0; d < 8; d += 2 {
				ny := next.a + dy[d]
				nx := next.b + dx[d]
				if ny < 0 || ny >= H || nx < 0 || nx >= W {
					continue
				}
				if A[ny][nx] == '.' {
					add = append(add, pair{ny, nx})
					A[ny][nx] = '#'
				}
			}
		}
		if len(add) > 0 {
			cnt++
			// log.Println("------", cnt)
			// for i := 0; i < H; i++ {
			// 	log.Println(string(A[i]))
			// }
		}
	}
	fmt.Println(cnt)
}

var dy = []int{1, 1, 0, -1, -1, -1, 0, 1}
var dx = []int{0, 1, 1, 1, 0, -1, -1, -1}
var inf = int(1e9)

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type pair struct {
	a, b int
}

type pairs []pair

func (p pairs) Len() int {
	return len(p)
}
func (p pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}

var nextReader func() []byte

func init() {
	nextReader = newScanner()
	log.SetFlags(log.Lshortfile)
}

func newScanner() func() []byte {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() []byte {
		r.Scan()
		return r.Bytes()
	}
}
func nextBytes() []byte {
	return nextReader()
}

func nextString() string {
	return string(nextReader())
}
func nextInt64() int64 {
	v, _ := strconv.ParseInt(string(nextReader()), 10, 64)
	return v
}
func nextInt() int {
	v, _ := strconv.Atoi(string(nextReader()))
	return v
}
func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}
func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(string(nextReader()), 64)
	return f
}


package main

import "fmt"

type rect struct {
	h int
	w int
}

func main() {
	var h, w int
	fmt.Scan(&h, &w)
	br := make([][]bool, h)
	for i := range br {
		br[i] = make([]bool, w)
	}
	ar := make([]rect, 0)
	for i := 0; i < h; i++ {
		var s string
		fmt.Scan(&s)
		for j, v := range s {
			if v == '#' {
				br[i][j] = true
				ar = append(ar, rect{h: i, w: j})
			}
		}
	}
	sum := 0
	for {
		temp := []rect{}
		sousa := false
		for _, v := range ar {
			if v.h != 0 {
				if !br[v.h-1][v.w] {
					sousa = true
					br[v.h-1][v.w] = true
					temp = append(temp, rect{h: v.h - 1, w: v.w})
				}
			}
			if v.h != h-1 {
				if !br[v.h+1][v.w] {
					sousa = true
					br[v.h+1][v.w] = true
					temp = append(temp, rect{h: v.h + 1, w: v.w})
				}
			}
			if v.w != 0 {
				if !br[v.h][v.w-1] {
					sousa = true
					br[v.h][v.w-1] = true
					temp = append(temp, rect{h: v.h, w: v.w - 1})
				}
			}
			if v.w != w-1 {
				if !br[v.h][v.w+1] {
					sousa = true
					br[v.h][v.w+1] = true
					temp = append(temp, rect{h: v.h, w: v.w + 1})
				}
			}
		}
		if sousa == false {
			fmt.Println(sum)
			return
		}
		sum++
		ar = temp
	}
}


package main

import "fmt"

type rect struct {
	h int
	w int
}

func main() {
	var h, w int
	fmt.Scan(&h, &w)
	br := make([][]bool, h)
	for i := range br {
		br[i] = make([]bool, w)
	}
	ar := make([]rect, 0)
	for i := 0; i < h; i++ {
		var s string
		fmt.Scan(&s)
		for j, v := range s {
			if v == '#' {
				br[i][j] = true
				ar = append(ar, rect{h: i, w: j})
			}
		}
	}
	sum := 0
	temp := []rect{}
	for {
		sousa := false
		for _, v := range ar {
			if v.h != 0 {
				if !br[v.h-1][v.w] {
					sousa = true
					br[v.h-1][v.w] = true
					temp = append(temp, rect{h: v.h - 1, w: v.w})
				}
			}
			if v.h != h-1 {
				if !br[v.h+1][v.w] {
					sousa = true
					br[v.h+1][v.w] = true
					temp = append(temp, rect{h: v.h + 1, w: v.w})
				}
			}
			if v.w != 0 {
				if !br[v.h][v.w-1] {
					sousa = true
					br[v.h][v.w-1] = true
					temp = append(temp, rect{h: v.h, w: v.w - 1})
				}
			}
			if v.w != w-1 {
				if !br[v.h][v.w+1] {
					sousa = true
					br[v.h][v.w+1] = true
					temp = append(temp, rect{h: v.h, w: v.w + 1})
				}
			}
		}
		if sousa == false {
			fmt.Println(sum)
			return
		}
		sum++
		ar = temp
	}
}


package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, 1000000009)
	sc.Split(bufio.ScanWords)
	n, _ := strconv.Atoi(stringLineScan())
	d := make(map[int]int)
	ans := 1
	for i := 0; i < n; i++ {
		a, _ := strconv.Atoi(stringLineScan())
		x := PrimeFactors(a)
		for _, y := range x {
			d[y]++
		}
	}
	z := 1
	for k, v := range d {
		if v%n == n-1 && k > z {
			z = k
		}
		ans *= int(math.Pow(float64(k), float64(v/n)))
	}
	fmt.Println(ans * z)
}
func PrimeFactors(n int) (pfs []int) {
	for n%2 == 0 {
		pfs = append(pfs, 2)
		n = n / 2
	}
	for i := 3; i*i <= n; i = i + 2 {
		for n%i == 0 {
			pfs = append(pfs, i)
			n = n / i
		}
	}
	if n > 2 {
		pfs = append(pfs, n)
	}
	return
}

Score : 300 points

Problem Statement

There are N integers, A_1, A_2, ..., A_N, written on the blackboard.

You will choose one of them and replace it with an integer of your choice between 1 and 10^9 (inclusive), possibly the same as the integer originally written.

Find the maximum possible greatest common divisor of the N integers on the blackboard after your move.

Constraints

All values in input are integers.

2 \leq N \leq 10^5

1 \leq A_i \leq 10^9

Output

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the maximum possible greatest common divisor of the N integers on the blackboard after your move.

Sample Input 1

3
7 6 8

Sample Output 1

2

If we replace 7 with 4, the greatest common divisor of the three integers on the blackboard will be 2, which is the maximum possible value.

Sample Input 2

3
12 15 18

Sample Output 2

6

Sample Input 3

2
1000000000 1000000000

Sample Output 3

1000000000

We can replace an integer with itself.


package main

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

func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b > 0 {
		a, b = b, a%b
	}
	return a
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

type segmentTree struct {
	data   []int
	offset int
}

func newSegmentTree(n int) segmentTree {
	var result segmentTree
	t := 1
	for t < n {
		t *= 2
	}
	result.offset = t - 1
	result.data = make([]int, 2*t-1)
	return result
}

func (st segmentTree) updateAll(a []int) {
	for i, v := range a {
		st.data[st.offset+i] = v
	}
	for i := st.offset - 1; i > -1; i-- {
		st.data[i] = gcd(st.data[i*2+1], st.data[i*2+2])
	}
}

func (st segmentTree) update(index, value int) {
	i := st.offset + index
	st.data[i] = value
	for i >= 1 {
		i = (i - 1) / 2
		st.data[i] = gcd(st.data[i*2+1], st.data[i*2+2])
	}
}

func (st segmentTree) query(start, stop int) int {
	result := 0
	l := start + st.offset
	r := stop + st.offset
	for l < r {
		if l&1 == 0 {
			result = gcd(result, st.data[l])
		}
		if r&1 == 0 {
			result = gcd(result, st.data[r-1])
		}
		l = l / 2
		r = (r - 1) / 2
	}
	return result
}

func main() {
	N := readInt()
	A := readInts(N)

	st := newSegmentTree(N)
	st.updateAll(A)

	result := st.query(1, N)
	for i := 1; i < N-1; i++ {
		result = max(result, gcd(st.query(0, i), st.query(i+1, N)))
	}
	result = max(result, st.query(0, N-1))

	fmt.Println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

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

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}

func readInts(n int) []int {
	result := make([]int, n)
	for i := 0; i < n; i++ {
		result[i] = readInt()
	}
	return result
}


package main

import "fmt"

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

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	l := make([]int, n+1)
	r := make([]int, n+1)
	l[0] = 0
	r[0] = 0
	for i := 0; i < n; i++ {
		l[i+1] = gcd(a[i], l[i])
		r[n-1-i] = gcd(a[n-1-i], r[n-i])
	}

	ans := 0
	for i := 0; i < n; i++ {
		t := gcd(l[i], r[i+1])
		if ans < t {
			ans = t
		}
	}

	fmt.Println(ans)
}


// https://atcoder.jp/contests/abc125/tasks/abc125_c

package main

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

func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}

	if b == 0 {
		return a
	}

	return gcd(b, a%b)
}

// d: debug IO. it can print debug in test.
func solve(io *Io, d *Io) {
	N := io.NextInt()
	as := io.NextInts(N)

	lgcd := make([]int, N)
	rgcd := make([]int, N)

	lgcd[0] = as[0]
	rgcd[N-1] = as[N-1]

	for i := 1; i < N; i++ {
		lgcd[i] = gcd(as[i], lgcd[i-1])
	}

	for i := N - 2; i >= 0; i-- {
		rgcd[i] = gcd(as[i], rgcd[i+1])
	}

	resMc := NewMaxCalculator(0)

	for i := 0; i < N; i++ {
		if i == 0 {
			resMc.Check(rgcd[i+1])
			continue
		} else if i == N-1 {
			resMc.Check(lgcd[i-1])
			continue
		}

		resMc.Check(gcd(lgcd[i-1], rgcd[i+1]))
	}

	io.Println(resMc.current)
}

type SegmentTree struct {
	n         int // 最下段の数
	nodes     []int
	zeroValue int
}

func (st *SegmentTree) calc(a, b int) int {
	return gcd(a, b)
}

func (st *SegmentTree) init(vs []int, zeroValue int) {
	st.zeroValue = zeroValue
	st.n = 1

	for st.n < len(vs) {
		st.n *= 2
	}

	st.nodes = make([]int, 2*st.n-1)

	for i := range st.nodes {
		st.nodes[i] = st.zeroValue
	}

	for i, v := range vs {
		st.nodes[i+st.n-1] = v
	}

	for i := st.n - 2; i >= 0; i-- {
		st.nodes[i] = st.calc(st.nodes[i*2+1], st.nodes[i*2+2])
	}
}

func (st *SegmentTree) update(i, val int) {
	i += st.n - 1
	st.nodes[i] = val

	for i > 0 {
		i = (i - 1) / 2
		st.nodes[i] = st.calc(st.nodes[2*i+1], st.nodes[2*i+2])
	}
}

// [from, to)
func (st *SegmentTree) query(from, to int) int {
	return st.queryInternal(from, to, 0, 0, st.n)
}

func (st *SegmentTree) queryInternal(from, to, k, l, r int) int {
	if r <= from || to <= l {
		return st.zeroValue
	}

	if from <= l && r <= to {
		return st.nodes[k]
	}

	vl := st.queryInternal(from, to, 2*k+1, l, (l+r)/2)
	vr := st.queryInternal(from, to, 2*k+2, (l+r)/2, r)

	return st.calc(vl, vr)
}

// セグメント木を利用

func solve2(io *Io, d *Io) {
	N := io.NextInt()
	as := io.NextInts(N)

	st := SegmentTree{}
	st.init(as, 0)

	res := 0

	for i := range as {
		l := st.query(0, i)
		r := st.query(i+1, len(as))
		res = Max(res, gcd(l, r))
	}

	io.Println(res)
}

func main() {
	io := NewIo()
	defer io.Flush()
	solve2(io, nil)
}

/* IO Helpers */

// Io combines reader, writer, & tokens as the state when processing the input
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

// NewIo creates Io with Stdin & Stdout
func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

// Flush calls the writer's Flush
func (io *Io) Flush() {
	io.writer.Flush()
}

// NextLine returns the string from reader.ReadLine()
func (io *Io) NextLine() string {
	if io.nextToken < len(io.tokens) {
		panic("io.nextToken < len(io.tokens)")
	}

	var buffer bytes.Buffer

	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer.Write(line)
		if !isPrefix {
			break
		}
	}

	return buffer.String()
}

// NextLines returns []string from next n lines
func (io *Io) NextLines(n int) []string {
	res := make([]string, n)
	for i := 0; i < n; i++ {
		res[i] = io.NextLine()
	}
	return res
}

// Next returns the string token (partial string of the line divided by spaces)
func (io *Io) Next() string {
	if io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}

	res := io.tokens[io.nextToken]
	io.nextToken++
	return res
}

// NextStrings returns the []string from the next n tokens
func (io *Io) NextStrings(n int) []string {
	res := make([]string, n)
	for i := 0; i < n; i++ {
		res[i] = io.Next()
	}
	return res
}

// NextInt returns the int from the next token
func (io *Io) NextInt() int {
	res, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return res
}

// NextInts returns the []int from the next n tokens
func (io *Io) NextInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = io.NextInt()
	}
	return res
}

// Println prints the input to the writer in an easy-to-see form
func (io *Io) Println(a ...interface{}) {
	var values []string
	for i := 0; i < len(a); i++ {
		values = append(values, "%v")
	}
	io.Printfln(strings.Join(values, " "), a...)
}

// Print calls Fprint to the writer
func (io *Io) Print(a interface{}) {
	fmt.Fprint(io.writer, a)
}

// Printfln calls Fprint to the writer
func (io *Io) Printfln(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format+"\n", a...)
}

// Debug calls Println and Flush immediately
func (io *Io) Debug(a ...interface{}) {
	if io == nil {
		return
	}

	io.Println(a...)
	io.Flush()
}

/* Math Helpers */

// Max of the ints
func Max(numbers ...int) int {
	max := numbers[0]
	for i, number := range numbers {
		if i == 0 {
			continue
		}
		if number > max {
			max = number
		}
	}
	return max
}

// Min of the ints
func Min(numbers ...int) int {
	max := numbers[0]
	for i, number := range numbers {
		if i == 0 {
			continue
		}
		if max > number {
			max = number
		}
	}
	return max
}

// DigitSum returns sum of the int's digits
func DigitSum(n int) int {
	if n < 0 {
		return -1
	}

	res := 0

	for n > 0 {
		res += n % 10
		n /= 10
	}

	return res
}

// Sum of the ints
func Sum(numbers ...int) int {
	sum := 0

	for _, number := range numbers {
		sum += number
	}

	return sum
}

// Pow calculates the pow for int with O(log e)
func Pow(a, e int) int {
	if a < 0 || e < 0 {
		panic(fmt.Sprintf("Pow was called for a < 0 or e < 0, a: %d, e: %d", a, e))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		half := Pow(a, e/2)
		return half * half
	}

	return a * Pow(a, e-1)
}

/* Structure Helpers */

// Set is orderless List
type Set map[interface{}]struct{}

// NewSet returns empty Set
func NewSet() *Set {
	return &Set{}
}

// Add the value to the set
func (set *Set) Add(value interface{}) {
	(*set)[value] = struct{}{}
}

// Includes check the set has the value
func (set *Set) Includes(value interface{}) bool {
	_, included := (*set)[value]
	return included
}

// Remove deletes the value from the set if exists
func (set *Set) Remove(value interface{}) {
	if !set.Includes(value) {
		return
	}

	delete(*set, value)
}

// ImmutableSort returns sorted slice without mutating original one
func ImmutableSort(slice []int) []int {
	res := make([]int, len(slice))
	copy(res, slice)
	sort.Ints(res)
	return res
}

// MinCalculator is helper to get min value
type MinCalculator struct {
	current int
}

// NewMinCalculator returns new MinCalculator with initial value
func NewMinCalculator(initial int) *MinCalculator {
	return &MinCalculator{
		current: initial,
	}
}

// Check compares the value with current and update current if necessary
func (mc *MinCalculator) Check(val int) {
	if val < mc.current {
		mc.current = val
	}
}

// MaxCalculator is helper to get max value
type MaxCalculator struct {
	current int
}

// NewMaxCalculator returns new MaxCalculator with initial value
func NewMaxCalculator(initial int) *MaxCalculator {
	return &MaxCalculator{
		current: initial,
	}
}

// Check compares the value with current and update current if necessary
func (mc *MaxCalculator) Check(val int) {
	if val > mc.current {
		mc.current = val
	}
}

/* Util helpers */

// Ternary is like `cond ? a : b`. should assert the returned value like `Ternary(cond, a, b).(int)`
func Ternary(cond bool, a, b interface{}) interface{} {
	if cond {
		return a
	}

	return b
}

// TernaryInt uses Ternary and assert the value as int
func TernaryInt(cond bool, a, b int) int {
	return Ternary(cond, a, b).(int)
}

// TernaryString uses Ternary and assert the value as string
func TernaryString(cond bool, a, b string) string {
	return Ternary(cond, a, b).(string)
}


package main

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

func add(cnt map[int]int, v int) {
	if _, ok := cnt[v]; !ok {
		cnt[v] = 1
		return
	}
	cnt[v]++
}

func main() {
	sc := NewScanner(os.Stdin)
	N := sc.NextInt()
	A := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = sc.NextInt()
	}
	l := make([]int, N)
	r := make([]int, N)
	l[0] = A[0]
	r[N-1] = A[N-1]
	for i := 1; i < N; i++ {
		l[i] = gcd(l[i-1], A[i])
	}
	for i := N - 2; i >= 0; i-- {
		r[i] = gcd(r[i+1], A[i])
	}
	ans := max(l[N-2], r[1])
	for i := 1; i < N-1; i++ {
		ans = max(ans, gcd(l[i-1], r[i+1]))
	}
	fmt.Println(ans)
}

func vmin(v []int) int {
	mn := math.MaxInt32
	for i := 0; i < len(v); i++ {
		mn = min(mn, v[i])
	}
	return mn
}

func gcd(x, y int) int {
	if y > 0 {
		return gcd(y, x%y)
	}
	return x
}

func lcm(x, y int) int {
	return x / gcd(x, y) * y
}

func max64(x, y int64) int64 {
	if x > y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

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

// scanner
type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner(r io.Reader) *Scanner {
	rdr := bufio.NewReaderSize(r, 1024)
	return &Scanner{r: rdr}
}

func (s *Scanner) ReadLine() {
	s.buf = make([]byte, 0)
	for {
		line, isp, err := s.r.ReadLine()
		if err != nil {
			os.Exit(1)
		}
		s.buf = append(s.buf, line...)
		if !isp {
			break
		}
	}
}

func (s *Scanner) NextInt64() int64 {
	i, err := strconv.ParseInt(s.Next(), 10, 64)
	if err != nil {
		os.Exit(1)
	}
	return i
}

func (s *Scanner) NextInt() int {
	i, err := strconv.Atoi(s.Next())
	if err != nil {
		os.Exit(1)
	}
	return i
}

func (s *Scanner) NextFloat64() float64 {
	i, err := strconv.ParseFloat(s.Next(), 64)
	if err != nil {
		os.Exit(1)
	}
	return i
}

func (s *Scanner) Next() string {
	s.Pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	next := string(s.buf[start:s.p])
	s.p++
	return next
}

func (s *Scanner) Pre() {
	if s.p >= len(s.buf) {
		s.ReadLine()
		s.p = 0
	}
}


package main

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

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func main() {
	n := oneInt()
	as := scanNums(n)
	ans := calc(n, as)
	fmt.Println(ans)

}

func calc(n int, as []int) int {
	L := make([]int, n+1)
	for i := 0; i < n; i++ {
		L[i+1] = gcd(L[i], as[i])
	}

	R := make([]int, n+1)
	for i := n - 1; i >= 0; i-- {
		R[i] = gcd(R[i+1], as[i])
	}

	ans := 0

	for i := 0; i < n; i++ {
		ans = max(ans, gcd(L[i], R[i+1]))
	}
	return ans
}

func oneInt() int {
	var a int
	fmt.Scan(&a)
	return a
}
func oneStr() string {
	var a string
	fmt.Scan(&a)
	return a
}

func readLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func scanNums(n int) (nums []int) {
	str := readLine()
	s := strings.Split(str, " ")
	for i := 0; i < n; i++ {
		num, _ := strconv.Atoi(s[i])
		nums = append(nums, num)
	}
	return nums
}

func scanStrings() (nums []string) {
	str := readLine()
	s := strings.Split(str, " ")

	return s
}

func abs(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func sortAsc(a []int) []int {
	sort.Ints(a)
	return a
}

func sortDesc(a []int) []int {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	return a
}

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

func lcm(a, b int) int {
	if a == 0 && b == 0 {
		return 0
	}
	return a * b / gcd(a, b)
}

func cumSum(nums []int) []int {
	sums := []int{0}

	for i := 0; i < len(nums); i++ {
		sums = append(sums, sums[i]+nums[i])
	}
	return sums
}


package main

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

func gcd(a, b int) int {
	if b > a {
		a, b = b, a
	}
	// 書き換え可能なパターンの計算簡略化のため
	if b == 0 {
		return a
	}
	var r int
	for {
		r = a % b
		if r == 0 {
			return b
		}
		a = b
		b = r
	}
}

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := 0; i < n; i++ {
		sc.Scan()
		a[i], _ = strconv.Atoi(sc.Text())
	}

	l := make([]int, n+1)
	l[0] = 0
	for i := 0; i < n; i++ {
		l[i+1] = gcd(l[i], a[i])
	}
	r := make([]int, n+1)
	r[n] = 0
	for i := n - 1; i >= 0; i-- {
		r[i] = gcd(r[i+1], a[i])
	}

	max := 0
	for i := 0; i < n; i++ {
		if v := gcd(l[i], r[i+1]); v > max {
			max = v
		}
	}

	fmt.Println(max)
}


package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	_ = oneInt()
	as := scanNums()
	n := len(as)

	ans := 1

	arr0 := as[:n-1]
	ans = Max(ans, gcds(arr0...))
	arr3 := as[1:]
	ans = Max(ans, gcds(arr3...))

	for i := 1; i < n-1; i++ {
		arr1 := as[:i]
		arr2 := as[i+1:]

		gcd1 := gcds(arr1...)
		gcd2 := gcds(arr2...)

		tmp := gcd(gcd1, gcd2)

		ans = Max(ans, tmp)
	}

	fmt.Println(ans)
}

func gcds(nums ...int) int {
	if len(nums) == 2 {
		return gcd(nums[0], nums[1])
	}
	if len(nums) == 1 {
		return nums[0]
	}
	tmp := []int{gcd(nums[0], nums[1])}
	tmp = append(tmp, nums[2:]...)
	ans := gcds(tmp...)

	return ans
}

func oneInt() int {
	var a int
	fmt.Scan(&a)
	return a
}
func oneStr() string {
	var a string
	fmt.Scan(&a)
	return a
}

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

func scanNums() (nums []int) {
	s := nextLine()
	numStr := strings.Split(s, " ")

	for _, n := range numStr {
		i, _ := strconv.Atoi(n)
		nums = append(nums, i)
	}
	return nums
}

func scanStrings() (strs []string) {
	s := nextLine()
	list := strings.Split(s, " ")
	strs = append(strs, list...)
	return strs
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func Max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func sortAsc(a []int) []int {
	sort.Ints(a)
	return a
}

func sortDesc(a []int) []int {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	return a
}

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

func lcm(a, b int) int {
	if a == 0 && b == 0 {
		return 0
	}
	return a * b / gcd(a, b)
}


package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	m := make([]int, n)
	l := make([]int, n-1)
	r := make([]int, n-1)
	l[0] = a[0]
	r[0] = a[n-1]

	for i := 1; i < n-1; i++ {
		l[i] = gcd(l[i-1], a[i])
		r[i] = gcd(r[i-1], a[n-1-i])
	}

	for i := 0; i < n; i++ {
		if i == 0 {
			m[i] = r[n-i-2]
		} else if i == n-1 {
			m[i] = l[n-2]
		} else {
			m[i] = gcd(l[i-1], r[n-i-2])
		}
	}

	ret := m[0]
	for i := 1; i < n; i++ {
		if m[i] > ret {
			ret = m[i]
		}
	}

	fmt.Println(ret)
}

func gcd(a int, b int) int {
	for {
		if b > a {
			a, b = b, a
		}
		c := a % b
		if c == 0 {
			return b
		}
		a, b = b, c
	}
}


package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scan(&N)
	A := make([]int64, N)
	var Amax int64
	for i := 0; i < N; i++ {
		fmt.Scan(&A[i])
		if A[i] > Amax {
			Amax = A[i]
		}
	}

	if N == 2 {
		if A[0] > A[1] {
			fmt.Println(A[0])
		} else {
			fmt.Println(A[1])
		}
	} else {
		fmt.Println(solve(N, A, Amax))
	}
}

func solve(N int, A []int64, Amax int64) int64 {
	var a int
	var b int64
	for i := 0; i < N; i++ {
		if A[i] == Amax {
			a++
		} else {
			b = A[i]
		}
	}
	if a == 1 {
		return b
	}
	if a == N-1 {
		return Amax
	}

	for i := Amax; i >= 1; i-- {
		miss := 0
		for j := 0; j < N; j++ {
			if A[j]%i != 0 {
				miss++
			}
			if miss >= 2 {
				break
			}
		}
		if miss <= 1 {
			return i
		}
	}
	return 1
}


package main

import "fmt"

func gcd(x, y int) int {
    for y > 0 {
        x, y = y, x % y
    }
    return x
}

func max(x, y int) int {
    if x > y {
        return x
    }
    return y
}

func main() {
    var n int
    fmt.Scan(&n)
    a := make([]int, n)
    for i := 0; i < n; i++ {
        fmt.Scan(&a[i])
    }
    if n == 2 {
        fmt.Println(max(a[0], a[1]))
    } else {
        g := gcd(a[0], a[n - 1])
        forward, backword := make([]int, n), make([]int, n)
        forward[0], backword[n - 1] = g, g
        for i := 1; i < n; i++ {
            g := gcd(g, a[i])
            forward[i] = g
        }
        g = a[n - 1]
        for i := n - 2; i >= 0; i-- {
            g := gcd(g, a[i])
            backword[i] = g
        }
        first, second := 1000000007, 1000000007
        for i := 0; i < n; i++ {
            v := max(forward[i], backword[i])
            if v < first {
                second = first
                first = v
            } else if v < second {
                second = v
            }
        }
        fmt.Println(second)
    }
}


package main

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

func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return nums
}

func gcd(a, b int) int {
	for b != 0 {
		rem := math.Mod(float64(a), float64(b))
		a = b
		b = int(rem)
	}

	return a
}

func main() {
	var N int
	fmt.Scan(&N)

	A := scanNums(N)

	sort.Sort(sort.Reverse(sort.IntSlice(A)))

	if N <= 2 {
		if A[0] > A[1] {
			fmt.Println(A[0])
			os.Exit(0)
		}
		fmt.Println(A[1])
		os.Exit(0)
	}

	a := gcd(A[0], A[1])
	b := gcd(A[1], A[2])
	c := gcd(A[2], A[0])

	var m int

	countA := 0
	countB := 0
	countC := 0

	for i := 0; i < N; i++ {
		if countA > 1 {
			a = 1
			break
		}
		if A[i]%a != 0 {
			countA += 1
		}
	}
	m = a

	for i := 0; i < N; i++ {
		if countB > 1 {
			b = 1
			break
		}
		if A[i]%b != 0 {
			countB += 1
		}
	}
	if b > m {
		m = b
	}

	for i := 0; i < N; i++ {
		if countC > 1 {
			c = 1
			break
		}
		if A[i]%c != 0 {
			countC += 1
		}
	}
	if c > m {
		m = c
	}

	fmt.Println(m)
}


package main

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

func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return nums
}

func gcd(a, b int) int {
	for b != 0 {
		rem := math.Mod(float64(a), float64(b))
		a = b
		b = int(rem)
	}

	return a
}

func main() {
	var N int
	fmt.Scan(&N)

	A := scanNums(N)

	sort.Sort(sort.Reverse(sort.IntSlice(A)))

	if N <= 2 {
		if A[0] > A[1] {
			fmt.Println(A[0])
			os.Exit(0)
		}
		fmt.Println(A[1])
		os.Exit(0)
	}

	a := gcd(A[0], A[1])
	b := gcd(A[1], A[2])
	c := gcd(A[2], A[0])

	var m int

	countA := 0
	countB := 0
	countC := 0

	for i := 0; i < N; i++ {
		if countA > 1 {
			a = 0
			break
		}
		if A[i]%a != 0 {
			countA += 1
		}
	}
	m = a

	for i := 0; i < N; i++ {
		if countB > 1 {
			b = 1
			break
		}
		if A[i]%b != 0 {
			countB += 1
		}
	}
	if b > m {
		m = b
	}

	for i := 0; i < N; i++ {
		if countC > 1 {
			c = 1
			break
		}
		if A[i]%c != 0 {
			countC += 1
		}
	}
	if c > m {
		m = c
	}

	fmt.Println(m)
}


package main

import (
	"fmt"
	"math"
	"sort"
)

func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return nums
}

func gcd(a, b int) int {
	for b != 0 {
		rem := math.Mod(float64(a), float64(b))
		a = b
		b = int(rem)
	}

	return a
}

func main() {
	var N int
	fmt.Scan(&N)

	A := scanNums(N)

	sort.Sort(sort.Reverse(sort.IntSlice(A)))

	a := gcd(A[0], A[1])
	b := gcd(A[1], A[2])
	c := gcd(A[2], A[0])
	m := 0

	countA := 0
	countB := 0
	countC := 0
	for i := 3; i < N; i++ {
		if countA > 1 {
			a = 0
			break
		}
		if A[i]%a != 0 {
			countA += 1
		}
	}
	m = a

	for i := 3; i < N; i++ {
		if countB > 1 {
			b = 0
			break
		}
		if A[i]%b != 0 {
			countB += 1
		}
	}
	if b > m {
		m = b
	}

	for i := 3; i < N; i++ {
		if countC > 1 {
			c = 0
			break
		}
		if A[i]%c != 0 {
			countC += 1
		}
	}

	if c > m {
		m = c
	}

	fmt.Println(m)
}


package main

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

func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return nums
}

func gcd(a, b int) int {
	for b != 0 {
		rem := math.Mod(float64(a), float64(b))
		a = b
		b = int(rem)
	}

	return a
}

func main() {
	var N int
	fmt.Scan(&N)

	A := scanNums(N)

	sort.Sort(sort.Reverse(sort.IntSlice(A)))
	fmt.Println(A)

	a := gcd(A[0], A[1])
	b := gcd(A[1], A[2])
	c := gcd(A[2], A[0])

	for i := 3; i < N; i++ {
		if A[i]%a != 0 {
			break
		} else {
			fmt.Println(a)
			os.Exit(0)
		}
	}

	for i := 3; i < N; i++ {
		if A[i]%b != 0 {
			break
		} else {
			fmt.Println(b)
			os.Exit(0)
		}
	}

	fmt.Println(c)
}


package main

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

type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		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, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) PrintLn(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

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

func (io *Io) PrintIntLn(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func (io *Io) PrintStringLn(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func gcd_array(a []int) int {
	ret := a[0]
	for i := 1; i < len(a); i++ {
		ret = gcd(a[i], ret)
	}
	return ret
}

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

	return gcd(b, a%b)
}

func main() {
	io := NewIo()
	defer io.Flush()

	N := io.NextInt()

	A := make([]int, N)

	for i := range A {
		A[i] = io.NextInt()
	}

	max := 0
	for i := range A {
		AC := make([]int, len(A))
		copy(AC, A)
		tmp := append(AC[:i], AC[i+1:]...)
		g := gcd_array(tmp)

		if g > max {
			max = g
		}
	}

	io.PrintLn(max)

}


package main

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

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt() int {
  n, _ := strconv.Atoi(NextLine())
  return n
}
func NextIntVec() []int {
  L := strings.Split(NextLine(), " ")
  N := make([]int, len(L))
  for i := range N {
    N[i], _ = strconv.Atoi(L[i])
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func Output() {
  _ = writer.Flush()
}

func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}

const p = 998244353

func Solve() {
  N := NextInt()
  A := make([]int, N)
  for i := range A {
    A[i] = NextInt()
  }
  S := SumInt(A...)
  L := S / 2 + 1
  DP := make([][]int, N + 1)
  for i := range DP {
    DP[i] = make([]int, L + 1)
  }
  DP[0][0] = 1
  for i, a := range A {
    for j := range DP[i] {
      DP[i + 1][j] += 2 * DP[i][j]
      DP[i + 1][j] %= p
      DP[i + 1][MinInt(j + a, L)] += DP[i][j]
      DP[i + 1][MinInt(j + a, L)] %= p
    }
  }
  P := 1
  for i := 0; i < N; i++ {
    P = P * 3 % p
  }
  ans := (P + p - 3 * DP[N][L]) % p
  if S % 2 < 1 { ans = (ans + p - DP[N][S / 2] * 8 / 3) % p}
  Write(ans)
  return
}

func main() {
  Solve()
  Output()
}

Score : 600 points

Problem Statement

You are given N integers. The i-th integer is a_i.
Find the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the following condition is satisfied:

Let R, G and B be the sums of the integers painted red, green and blue, respectively. There exists a triangle with positive area whose sides have lengths R, G and B.

Constraints

3 \leq N \leq 300

1 \leq a_i \leq 300(1\leq i\leq N)

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
a_1
:
a_N

Output

Print the number, modulo 998244353, of ways to paint each of the integers red, green or blue so that the condition is satisfied.

Sample Input 1

4
1
1
1
2

Sample Output 1

18

We can only paint the integers so that the lengths of the sides of the triangle will be 1, 2 and 2, and there are 18 such ways.

Sample Input 2

6
1
3
2
3
5
2

Sample Output 2

150

Sample Input 3

20
3
1
4
1
5
9
2
6
5
3
5
8
9
7
9
3
2
3
8
4

Sample Output 3

563038556


package main

import (
	"fmt"
)

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

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)

	fmt.Println(min(b/a, c))
}

Score : 100 points

Problem Statement

Takahashi likes the sound when he buys a drink from a vending machine.

That sound can be heard by spending A yen (the currency of Japan) each time.

Takahashi has B yen. He will hear the sound as many times as he can with that money, but at most C times, as he would be satisfied at that time.

How many times will he hear the sound?

Constraints

All values in input are integers.

1 \leq A, B, C \leq 100

Input

Input is given from Standard Input in the following format:

A B C

Output

Print the number of times Takahashi will hear his favorite sound.

Sample Input 1

2 11 4

Sample Output 1

4

Since he has not less than 8 yen, he will hear the sound four times and be satisfied.

Sample Input 2

3 9 5

Sample Output 2

3

He may not be able to be satisfied.

Sample Input 3

100 1 10

Sample Output 3

0


package main

import "fmt"

func main() {
	var A, B, C int
	fmt.Scan(&A, &B, &C)
	if B > A*C {
		fmt.Println(C)
	} else {
		fmt.Println(B / A)
	}
}


// ProblemURL : https://atcoder.jp/contests/abc120/tasks/abc120_a
// ---------------------------------------------
package main

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

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}
func diff(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}
func larger(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func smaller(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func largest(a, b, c int) (lgst int) {
	if a > b {
		lgst = a
	} else {
		lgst = b
	}
	if c > lgst {
		lgst = c
	}
	return
}
func smallest(a, b, c int) (slst int) {
	if a < b {
		slst = a
	} else {
		slst = b
	}
	if c < slst {
		slst = c
	}
	return
}
func intsMax(a []int) (val int) {
	if len(a) == 0 {
		panic("func intsMax: argument slice length must not be zero")
	}
	val = a[0]
	for _, aa := range a {
		if aa > val {
			val = aa
		}
	}
	return
}
func intsMaxIdx(a []int) (idx, val int) {
	if len(a) == 0 {
		panic("func intsMaxIdx: argument slice length must not be zero")
	}
	val = a[0]
	for i, aa := range a {
		if aa > val {
			idx, val = i, aa
		}
	}
	return
}
func intsMin(a []int) (val int) {
	if len(a) == 0 {
		panic("func intsMin: argument slice length must not be zero")
	}
	val = a[0]
	for _, aa := range a {
		if aa < val {
			val = aa
		}
	}
	return
}
func intsMinIdx(a []int) (idx, val int) {
	if len(a) == 0 {
		panic("func intsMinIdx: argument slice length must not be zero")
	}
	val = a[0]
	for i, aa := range a {
		if aa < val {
			idx, val = i, aa
		}
	}
	return
}
func intsSum(a []int) int {
	res := 0
	for _, v := range a {
		res += v
	}
	return res
}
func intsAve(s []int) float64 {
	return float64(intsSum(s)) / float64(len(s))
}
func intsAdd(ints *[]int, x int) { *ints = append(*ints, x) }
func intsJoin(a, b []int) []int  { return append(a, b...) }
func intsClear(a []int) []int    { return a[:0] }
func intsCopy(a []int) []int     { return append([]int(nil), a...) }
func intsSorted(a []int) []int {
	s := intsCopy(a)
	sort.Ints(s)
	return s
}
func intsReverse(a []int) {
	for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
	return
}
func intsFill(a []int, val int) {
	for i := 0; i < len(a); i++ {
		a[i] = val
	}
	return
}
func intsPeekBack(a []int) int {
	if len(a) == 0 {
		panic("func peekBack: zero length slice")
	}
	return a[len(a)-1]
}
func intsPeekFront(a []int) int {
	if len(a) == 0 {
		panic("func peekFront: zero length slice")
	}
	return a[0]
}
func intsPopBack(a []int) (int, []int) {
	if len(a) == 0 {
		panic("func popBack: zero length slice")
	}
	return a[len(a)-1], a[:len(a)-1]
}
func intsPopFront(a []int) (int, []int) {
	if len(a) == 0 {
		panic("func popFront: zero length slice")
	}
	return a[0], a[1:]
}
func intsPushBack(a []int, x int) []int  { return append(a, x) }
func intsPushFront(a []int, x int) []int { return append([]int{x}, a...) }
func intsAppendSentinelHead(a []int, sentinel int) []int {
	return append([]int{sentinel}, a...)
}
func intsAppendSentinelTail(a []int, sentinel int) []int {
	return append(a, sentinel)
}
func intsAppendSentinel(a []int, sentinel int) []int {
	return append(append([]int{sentinel}, a[:len(a):len(a)+2]...), sentinel)
}
func isEven(n int) bool    { return n&1 == 0 }
func isOdd(n int) bool     { return n&1 == 1 }
func floor(x float64) int  { return int(x) }
func ceil(x float64) int   { return int(math.Ceil(x)) }
func ceilDiv(x, y int) int { return (x + y - 1) / y }
func pow(x, y int) int {
	if y < 0 {
		panic("Exponent must be a natural number")
	}
	z := 1
	for i := y; i != 0; i >>= 1 {
		if i&1 == 1 {
			z *= x
		}
		x *= x
	}
	return z
}
func fact(x int) int {
	fact := 1
	for i := 1; i <= x; i++ {
		fact *= i
	}
	return fact
}
func sigmaK(n int) int  { return n * (n + 1) / 2 }
func sigmaKK(n int) int { return (n * (n + 1) / 2) * (2*n + 1) / 3 }
func euclideanDistance(a, b point) float64 {
	s := diff(a.x, b.x)
	s *= s
	t := diff(a.y, b.y)
	t *= t
	return math.Sqrt(float64(s) + float64(t))
}
func manhattanDistance(a, b point) int {
	s := diff(a.x, b.x)
	t := diff(a.y, b.y)
	return s + t
}
func swap(a, b *int) { *a, *b = *b, *a }
func chmax(a *int, b int) {
	if *a < b {
		*a = b
	}
}
func chmin(a *int, b int) {
	if *a > b {
		*a = b
	}
}
func cumSum(a []int) []int {
	b := append([]int{0}, a...)
	for i := 1; i < len(b); i++ {
		b[i] += b[i-1]
	}
	return b
}
func runesReverse(a []rune) {
	for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
	return
}
func bytesReverse(a []byte) {
	for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
	return
}
func strUpperCase(s string) string { return strings.ToUpper(s) }
func strLowerCase(s string) string { return strings.ToLower(s) }
func strToInt(s string) int {
	i, err := strconv.Atoi(s)
	if err != nil {
		panic(err)
	}
	return i
}
func intToStr(i int) string  { return strconv.Itoa(i) }
func CalcMod(a, mod int) int { return (a%mod + mod) % mod }
func ModPow(x, y, mod int) int {
	if y < 0 {
		panic("Exponent must be a natural number")
	}
	z := 1
	for i := y; i != 0; i >>= 1 {
		if i&1 == 1 {
			z = (z * x) % mod
		}
		x = (x * x) % mod
	}
	return z
}
func ModFact(x, mod int) int {
	fact := 1
	for i := 1; i <= x; i++ {
		fact = fact * i % mod
	}
	return fact
}
func ModInv(x, mod int) int { return ModPow(x, mod-2, mod) }
func initMatrixBool(parentSize, childSize int, initialValue bool) *[][]bool {
	res := make([][]bool, parentSize)
	for i := range res {
		res[i] = make([]bool, childSize)
		for j := range res[i] {
			res[i][j] = initialValue
		}
	}
	return &res
}
func initMatrixInt(parentSize, childSize int, initialValue int) *[][]int {
	res := make([][]int, parentSize)
	for i := range res {
		res[i] = make([]int, childSize)
		for j := range res[i] {
			res[i][j] = initialValue
		}
	}
	return &res
}

var (
	sc = bufio.NewScanner(os.Stdin)
	bw = bufio.NewWriterSize(os.Stdout, bwBufSize)
)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1e7), 1e7)
}
func ru() (n int) {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}
	for _, v := range sc.Bytes() {
		n = n*10 + int(v-48)
	}
	return
}
func ri() (n int) {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}
	b := sc.Bytes()
	neg := false
	if b[0] == 45 {
		neg = true
		b = b[1:]
	}
	for _, v := range b {
		n = n*10 + int(v-48)
	}
	if neg {
		n = -n
	}
	return
}
func ri64() (n int64) {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}
	b := sc.Bytes()
	neg := false
	if b[0] == 45 {
		neg = true
		b = b[1:]
	}
	for _, v := range b {
		n = n*10 + int64(v-48)
	}
	if neg {
		n = -n
	}
	return
}
func rf64() float64 {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}
	f, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return f
}
func rs() string {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}
	return sc.Text()
}
func rb() []byte {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}
	return sc.Bytes()
}
func rr() []rune {
	sc.Scan()
	if err := sc.Err(); err != nil {
		panic(err)
	}
	return []rune(sc.Text())
}
func ris(n int) []int {
	s := make([]int, n)
	for i := range s {
		s[i] = ri()
	}
	return s
}
func risZeroBased(n int) []int {
	s := make([]int, n)
	for i := range s {
		s[i] = ri() - 1
	}
	return s
}
func ri64s(n int) []int64 {
	s := make([]int64, n)
	for i := range s {
		s[i] = ri64()
	}
	return s
}
func rss(n int) []string {
	s := make([]string, n)
	for i := range s {
		s[i] = rs()
	}
	return s
}
func pf(format string, a ...interface{}) {
	if _, err := fmt.Fprintf(bw, format, a...); err != nil {
		panic(err)
	}
}
func pln(a ...interface{}) {
	if _, err := fmt.Fprintln(bw, a...); err != nil {
		panic(err)
	}
}
func pints(a []int) {
	for _, v := range a {
		fmt.Fprintln(bw, v)
	}
}
func pintsol(a []int) {
	s := fmt.Sprint(a)
	if _, err := fmt.Fprintln(bw, s[1:len(s)-1]); err != nil {
		panic(err)
	}
}
func dbg(a ...interface{}) {
	if _, err := fmt.Fprintln(os.Stderr, a...); err != nil {
		panic(err)
	}
}
func YESorNO(b bool) string {
	if b {
		return "YES"
	} else {
		return "NO"
	}
}
func YesOrNo(b bool) string {
	if b {
		return "Yes"
	} else {
		return "No"
	}
}
func main() {
	solve()
	bw.Flush()
}

const (
	bwBufSize = 1e6

	alphabetLower = "abcdefghijklmnopqrstuvwxyz"
	alphabetUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

	// maxInt64  = 9223372036854775807  // 9e18
	// maxInt32  = 2147483647           // 2e9
	// maxUint64 = 18446744073709551615 // 1e19
	inf = 1 << 60
	mod = 1e9 + 7
)

type pair struct{ fi, se int }
type byFiSe []pair

func (p byFiSe) Len() int      { return len(p) }
func (p byFiSe) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
func (p byFiSe) Less(i, j int) bool {
	if p[i].fi == p[j].fi {
		return p[i].se < p[j].se
	}
	return p[i].fi < p[j].fi
}

type point struct{ x, y int }

func solve() {
	a, b, c := ri(), ri(), ri()
	need := a * c
	if b >= need {
		pln(c)
	} else {
		pln(b / a)
	}
}


package main

import "fmt"

func main() {
  var a, b, c int
  fmt.Scan(&a, &b, &c)
  cnt := 0
  for {
    if b < a || b <= 0 || cnt >= c {
      fmt.Println(cnt)
      break
    }
    b = b - a
    cnt++
  }
}


package main

import "fmt"

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)
	if b*c <= a {
		fmt.Println(c)
		return
	}
	fmt.Println(b / a)
}


package main

import "fmt"

func main() {
	var A, B, C int
	fmt.Scan(&A, &B, &C)

	d := B / A
	if d < C {
		fmt.Println(d)
	} else {
		fmt.Println(C)
	}

}


package main

import "fmt"

func main() {
	var (
		a int
		b int
		c int
	)
	fmt.Scan(&a, &b, &c)

	cnt := b / a

	if c <= cnt{
		fmt.Print(c)
	}else{
		fmt.Print(cnt)
	}

}


package main

import "fmt"

func main() {
	var a, b, c int
	fmt.Scanln(&a, &b, &c)
	t := b / a
	if t > c {
		fmt.Println(c)
	} else {
		fmt.Println(t)
	}
}


package main

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

func main() {
	nextReader = NewScanner()
	line1 := nextInt()
	count := line1[1] / line1[0]

	if line1[2] > count {
		fmt.Println(count)
	} else {
		fmt.Println(line1[2])
	}
}

// ------ Mathライブラリ ---------------------------------//
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}

func maxIdx(a ...int) int {
	r := a[0]
	index := 0
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
			index = i
		}
	}
	return index
}

func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}

func minIdx(a ...int) int {
	r := a[0]
	index := 0
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
			index = i
		}
	}
	return index
}

func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}

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

// ------ Mathライブラリ ---------------------------------//

// ----- 標準入力用の関数 ----------------------------------//
var nextReader func() []string

func NewScanner() func() []string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	return func() []string {
		r.Scan()
		return strings.Fields(r.Text())
	}
}

func nextString() []string {
	return nextReader()
}

func nextInt() []int {
	var intArray []int
	strArray := nextReader()
	for _, v := range strArray {
		i, _ := strconv.Atoi(v)
		intArray = append(intArray, i)
	}
	return intArray
}

func nextFloat64() []float64 {
	var floatArray []float64
	strArray := nextReader()
	for _, v := range strArray {
		f, _ := strconv.ParseFloat(v, 64)
		floatArray = append(floatArray, f)
	}
	return floatArray
}

// ------ 標準入力用の関数 ---------------------------------//

// ------ あまり使わない -----------------------------------//
func nextInt64() []int64 {
	var int64Array []int64
	strArray := nextReader()
	for _, v := range strArray {
		i, _ := strconv.ParseInt(v, 10, 64)
		int64Array = append(int64Array, i)
	}
	return int64Array
}

// ------ あまり使わない -----------------------------------//


package main

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

var (
	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+11))
	r.Split(bufio.ScanWords)

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

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

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

func main() {
	defer stdout.Flush()
	a := readInt()
	b := readInt()
	c := readInt()

	println(minInt(b/a, c))
}

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

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

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

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

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

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

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

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

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


package main
/*
N A B
*/
import (
        "bufio"
         "fmt"
        // "log"
        "os"
        "strconv"
        "strings"
)

func main() {
        stdin := bufio.NewScanner(os.Stdin)
        stdin.Scan()
        line := strings.Split(stdin.Text(), " ")
        a, _ := strconv.Atoi(line[0])
        b, _ := strconv.Atoi(line[1])
        c, _ := strconv.Atoi(line[2])
	n:=0
	for i:=1;i*a <= b;i++ {
	if i <= c {
	n++
	}

	}
	fmt.Println(n)

}


package main

import (
  "fmt"
)

func main() {
  var A, B, C int
  fmt.Scan(&A, &B, &C)

  var c int
  for i := 1; i*A <= B; i++ {
    c++
    if c == C {
      break
    }
  }
  fmt.Println(c)
}


package main

import "fmt"

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)
	d := b/a
	if d > c {
		fmt.Println(c)
	} else {
		fmt.Println(d)
	}
}


package main

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

////////////////////////////////////////
///        templates                 ///
////////////////////////////////////////

var sc = bufio.NewScanner(os.Stdin)

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

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readBigLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func strSprit(str string) []string {
	cols := strings.Split(str, " ")
	return cols
}

func parseInt(str string) int {
	n, _ := strconv.Atoi(str)
	return n
}

func intSprit(str string) []int {
	strs := strSprit(str)
	cols := make([]int, len(strs))
	for i, v := range strs {
		cols[i] = parseInt(v)
	}
	return cols
}

func bitCount(n uint) int {

	x := uint64(n)

	const m = 1<<64 - 1
	const m0 = 0x5555555555555555
	const m1 = 0x3333333333333333
	const m2 = 0x0f0f0f0f0f0f0f0f

	x = x>>1&(m0&m) + x&(m0&m)
	x = x>>2&(m1&m) + x&(m1&m)
	x = (x>>4 + x) & (m2 & m)
	x += x >> 8
	x += x >> 16
	x += x >> 32

	return int(x) & (1<<7 - 1)
}

func bitExist(n, i int) bool {
	return ((n >> uint(i)) & 1) == 1
}

func setBit(d, n int) int {
	t := 1 << uint(n)
	return d | t
}

func intAbs(n int) int {
	return int(math.Abs(float64(n)))
}

////////////////////////////////////////
///        end templates             ///
////////////////////////////////////////

func main() {
	line := nextLine()

	spl := intSprit(line)

	t := spl[1] / spl[0]

	if t >= spl[2] {
		fmt.Println(spl[2])
	} else {
		fmt.Println(t)
	}
}


package main

import (
	"fmt"
)

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)
	d := b / a
	if c < d {
		fmt.Println(c)
	} else {
		fmt.Println(d)
	}
}


//go:generate echo "https://atcoder.jp/contests/dp/tasks/dp_a"
package main

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

type scanner struct{ *bufio.Scanner }

func newScanner(r io.Reader) *scanner {
	s := bufio.NewScanner(r)
	s.Split(bufio.ScanWords)
	s.Buffer(nil, 100000000)
	return &scanner{s}
}

func (s *scanner) Int() int {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	return n
}

func (s *scanner) IntSlice(l int) []int {
	if l == 0 {
		return []int{}
	}
	sl := make([]int, l, l)
	for i := range sl {
		sl[i] = s.Int()
	}
	return sl
}

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

func solve(n int, heights []int) int {
	t := make([]int, n+1, n+1)
	for i := range t {
		t[i] = math.MaxInt64
	}

	t[0] = 0
	for i := 1; i < n; i++ {
		if v := t[i-1] + iabs(heights[i]-heights[i-1]); v < t[i] {
			t[i] = v
		}
		if 1 < i {
			if v := t[i-2] + iabs(heights[i]-heights[i-2]); v < t[i] {
				t[i] = v
			}
		}
	}

	return t[n-1]
}

func main() {
	sc := newScanner(os.Stdin)
	n := sc.Int()
	heights := sc.IntSlice(n)
	ans := solve(n, heights)
	fmt.Println(ans)
}

Score : 100 points

Problem Statement

There are N stones, numbered 1, 2, \ldots, N.
For each i (1 \leq i \leq N), the height of Stone i is h_i.

There is a frog who is initially on Stone 1.
He will repeat the following action some number of times to reach Stone N:

If the frog is currently on Stone i, jump to Stone i + 1 or Stone i + 2. Here, a cost of |h_i - h_j| is incurred, where j is the stone to land on.

Find the minimum possible total cost incurred before the frog reaches Stone N.

Constraints

All values in input are integers.

2 \leq N \leq 10^5

1 \leq h_i \leq 10^4

Input

Input is given from Standard Input in the following format:

N
h_1 h_2 \ldots h_N

Output

Print the minimum possible total cost incurred.

Sample Input 1

4
10 30 40 20

Sample Output 1

30

If we follow the path 1 → 2 → 4, the total cost incurred would be |10 - 30| + |30 - 20| = 30.

Sample Input 2

2
10 10

Sample Output 2

0

If we follow the path 1 → 2, the total cost incurred would be |10 - 10| = 0.

Sample Input 3

6
30 10 60 10 60 50

Sample Output 3

40

If we follow the path 1 → 3 → 5 → 6, the total cost incurred would be |30 - 60| + |60 - 60| + |60 - 50| = 40.


package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := nextInt()
	h := make([]int, n)

	for i := 0; i < n; i++ {
		h[i] = nextInt()
	}

	dp := make([]int, n)
	dp[0] = 0
	for i := 1; i < n; i++ {
		if i == 1 {
			dp[i] = abs(h[i] - h[i-1])
			continue
		}
		b1 := dp[i-1] + abs(h[i]-h[i-1])
		b2 := dp[i-2] + abs(h[i]-h[i-2])
		dp[i] = min(b2, b1)
	}

	fmt.Println(dp[n-1])

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

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // Default=64
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


package main
import "fmt"
var n int
var A []int
func min(a, b int) int {
	if a < b { return a }
	return b
}
func abs(a int) int {
	if a < 0 { return -a }
	return a
}
func main() {
	_,e := fmt.Scanf("%d", &n)
	if e!= nil { return }
	if n<=1 {
		fmt.Println(0)
		return
	}
	A = make([]int, n+1)
	for i:=1; i<=n; i++ {
		_,e := fmt.Scanf("%d", &A[i])
		if e != nil { return }
	}
	if n == 2 {
		fmt.Println(abs(A[2]-A[1]))
		return
	}
	dp := make([]int, n+1)
	dp[1] = 0
	dp[2] = abs(A[2]-A[1])
	for i:=3; i<=n; i++ {
		dp[i] = min(dp[i-1] + abs(A[i] - A[i-1]), dp[i-2]+abs(A[i] - A[i-2]))
	}
	fmt.Println(dp[n])
}


package main

import (
	"fmt"
	"math"
)

// 貰うDP(動的計画法)

func main() {

	var n int
	fmt.Scan(&n)

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

	dp := make([]int, 100010)
	dp[1] = abs(h[1] - h[0])
	// 初期化(最小化問題なのでINF尼初期化)
	for i := 2; i < n; i++ {
		dp[i] = abs(h[1] - h[0])

		b1:= dp[i-1] + abs(h[i] - h[i-1])
		b2 := dp[i-2] + abs(h[i] - h[i-2])
		if b1 < b2 {
			dp[i] = b1
		} else {
			dp[i] = b2
		}
	}
	fmt.Println(dp[n-1])
}

func abs(n int) int {
	y := n >> 63
	return (n ^ y) - y
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}


package main

import (
	"fmt"
)

// A - Frog 1
// https://atcoder.jp/contests/dp/tasks/dp_a

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

func main() {
	var n int
	var cost int
	var tmp1 int
	var tmp2 int
	var currentPos int
	fmt.Scanf("%d", &n)
	h := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &h[i])
	}
	for i := 1; i < n-1; i++ {
		tmp1 = Abs(h[i] - h[currentPos])
		if currentPos == n-2 {
			cost += tmp1
			currentPos = n - 1
			break
		}
		tmp2 = Abs(h[i+1] - h[currentPos])
		if tmp1 > tmp2 {
			cost += tmp1
			currentPos = i
			continue
		}
		cost += tmp2
		currentPos = i + 1
		i = i + 2
	}
	if currentPos == n-2 {
		cost += Abs(h[n-1] - h[currentPos])
	}
	fmt.Printf("%d\n", cost)
}


package main

import (
	"fmt"
	"math"
)

var (
	n int
	h []int
	dp []int
)

func solve(idx int) int {
	if dp[idx] != -1 {
		return dp[idx]
	}

	if idx == 0 {
		dp[idx] = 0
	} else if idx == 1 {
		dp[idx] = int(math.Abs(float64(h[idx] - h[idx-1])))
	} else {
		var (
			c1, c2 int
		)
		c1 = solve(idx - 1) + int(math.Abs(float64(h[idx] - h[idx-1])))
		c2 = solve(idx - 2) + int(math.Abs(float64(h[idx] - h[idx-2])))

		dp[idx] = int(math.Min(float64(c1), float64(c2)))
	}

	return dp[idx]
}

func main() {
	fmt.Scan(&n)
	h = make([]int, n)
	dp = make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Scan(&h[i])
	}

	for i := 0; i < n; i++ {
		dp[i] = -1
	}

	//fmt.Println(h)

	var ans int = solve(n-1)
	fmt.Println(ans)
}


package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()

	h := make([]int, n+1)
	for i := 0; i < n; i++ {
		h[i] = nextInt()
	}
	dp := make([]int, n)
	for i := 0; i < n; i++ {
		dp[i] = -1
	}

	ans := dfs(0, n, h, dp)
	fmt.Println(ans)
}

// posからゴールまでの最小コストを返す関数
func dfs(pos int, n int, h []int, dp []int) int {
	// オーバーしていた場合は十分に大きいコストを返す
	if pos >= n {
		return 99999999
	}
	// ゴールしていたらこれ以上コストは掛からないので0
	if pos == n-1 {
		return 0
	}
	// すでにdfsの結果を計算済みであればそれを返す
	if dp[pos] != -1 {
		return dp[pos]
	}
	// 1つ進む場合と2つ進む場合を比較して小さい方を採用
	step1 := dfs(pos+1, n, h, dp) + int(math.Abs(float64(h[pos+1]-h[pos])))
	step2 := dfs(pos+2, n, h, dp) + int(math.Abs(float64(h[pos+2]-h[pos])))
	// 答えをメモしておく
	dp[pos] = int(math.Min(float64(step1), float64(step2)))
	return dp[pos]
}


package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()

	h := make([]int, n)
	for i := 0; i < n; i++ {
		h[i] = nextInt()
	}

	//dp[i] = iマス目にたどりつくための最小コスト
	dp := make([]int, n)

	// 1マス目は0
	dp[0] = 0
	// 2マス目はh[1]-h[0]
	dp[1] = h[1] - h[0]

	for i := 2; i < n; i++ {
		// 1マス前から移動したときの最小コスト
		step1 := dp[i-1] + int(math.Abs(float64(h[i]-h[i-1])))
		// 2マス前から移動したときの最小コスト
		step2 := dp[i-2] + int(math.Abs(float64(h[i]-h[i-2])))
		// 小さい方をdp[i]として採用する
		dp[i] = int(math.Min(float64(step1), float64(step2)))
	}

	fmt.Println(dp[n-1])
}


package main

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

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func readInt64() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

const INF = int(1e4) + 1

func main() {
	sc.Split(bufio.ScanWords)
	n := readInt()
	h := make([]int, n)
	for i := 0; i < n; i++ {
		h[i] = readInt64()
	}

	dp := make([]int, n)
	for i := 1; i < n; i++ {
		dp[i] = INF
	}

	dp[0] = 0
	dp[1] = abs(h[1] - h[0])
	for i := 2; i < n; i++ {
		dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]), dp[i-2]+abs(h[i]-h[i-2]))
	}
	fmt.Println(dp[n-1])
}

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

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


package main
import "fmt"
func main() {
  var N int
  fmt.Scanf("%d", &N)
  stones := make([]int, N)
  for i:=0;i<N;i++ {
    fmt.Scanf("%d", &stones[i])
  }
  if N == 1 {
    fmt.Println(0)
    return
  }
  if N == 2 {
    fmt.Println(abs(stones[1]-stones[0]))
    return
  }
  dp := make([]int, N)
  dp[0] = stones[0]
  dp[1] = abs(stones[1]-stones[0])
  for i:=2;i<N;i++ {
    dp[i] = min(dp[i-1]+abs(stones[i]-stones[i-1]), dp[i-2]+abs(stones[i]-stones[i-2]))
  }
  // dp[i]: min_{j=1}^2(dp[i-j]+abs(arr[i]-arr[i-j]))
  fmt.Println(dp[N-1])
}

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

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


package main

import "fmt"

func main() {
	var N int
	fmt.Scanf("%d", &N)
	h := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &h[i])
	}
	c := make([]int, N)
	c[0] = 0
	c[1] = abs(h[1] - h[0])
	for i := 0; i < N-2; i++ {
		c[i+2] = c[i] + abs(h[i+2]-h[i])
		chmin(&c[i+2], c[i+1]+abs(h[i+2]-h[i+1]))
	}
	fmt.Println(c[N-1])
}

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

func chmin(v1 *int, v2 int) {
	if *v1 > v2 {
		*v1 = v2
	}
}


package main

import (
	"fmt"
)

func main(){
	var n int
	fmt.Scan(&n)
	h := make([]int, n)
	dp := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&h[i])
	}
	dp[0] = 0
	dp[1] = abs(h[0] - h[1])
	for i := 2; i < n; i++ {
		dp[i] = min(
			dp[i-2] + abs(h[i] - h[i-2]),
			dp[i-1] + abs(h[i] - h[i-1]))
	}
	fmt.Println(dp[n-1])
}

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

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


package main

import (
	"fmt"
	"math"
)

func main(){
	var n int
	fmt.Scan(&n)
	h := make([]float64, n+2)
	for i := 0; i < n; i++ {
		fmt.Scan(&h[i])
	}
	// 足場 i にいるとき
	// 最小コスト j
	dp := make([]float64, n+2)
	dp[0] = 0
	for i := 1; i < n; i++ {
		dp[i] = math.Pow(10, 9)
	}
	for i := 0; i < n-1; i++ {
		for j := i + 1; j <= i + 2; j++ {
			dp[j] = math.Min(dp[j], dp[i] + math.Abs(h[i] - h[j]))
		}
	}
	ans := dp[n-1]
	fmt.Println(ans)
}


package main

import (
	"fmt"
	"math"
)

func main(){
	var n int
	fmt.Scan(&n)
	h := make([]float64, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&h[i])
	}
	// 足場 i にいるとき
	// 最小コスト j
	var dp[100001] float64
	dp[0] = 0
	for i := 0; i < n; i++ {
		for j := i + 1; j <= i + 2; j++ {
			if j > n - 1 {
				continue
			}
			if dp[j] == float64(0) || dp[i] + math.Abs(h[i] - h[j]) < dp[j] {
				dp[j] = dp[i] + math.Abs(h[i] - h[j])
			}
		}
	}
	ans := dp[n-1]
	fmt.Println(ans)
}


package main

import (
	"fmt"
	"math"
)

const INF = 1 << 29

func main() {
	var n int
	fmt.Scan(&n)
	h := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&h[i])
	}

	dp := make([]int, n)
	dp[0] = 0
	for i := 1; i < n; i++ {
		dp[i] = INF
	}

	for i := 0; i < n-1; i++ {
		// +1
		cost1 := dp[i] + int(math.Abs(float64(h[i]-h[i+1])))
		if cost1 < dp[i+1] {
			dp[i+1] = cost1
		}

		// +2
		if i < n-2 {
			cost2 := dp[i] + int(math.Abs(float64(h[i]-h[i+2])))
			if cost2 < dp[i+2] {
				dp[i+2] = cost2
			}
		}
	}
	fmt.Println(dp[n-1])
}


package main

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

var sc *bufio.Scanner

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

func knap(count, weightLimit int, weights []int, vals []int) int {
	values := make([][]int, count + 1)
	for i := 0; i < count + 1; i++ {
		values[i] = make([]int, weightLimit + 1)
	}

	for i := 1; i <= count; i++ {
		for j := 0; j <= weightLimit; j++ {
			values[i][j] = values[i - 1][j]
			if weights[i - 1] <= j {
				values[i][j] = maxInt(values[i][j], values[i-1][j-weights[i - 1]] + vals[i - 1])
			}
		}
	}
	return values[count][weightLimit]
}

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

func ScanIntArray(size int) []int {
	res := make([]int, size)
	for i := 0; i < size; i++ {
		sc.Scan()
		res[i], _ = strconv.Atoi(sc.Text())
	}
	return res
}

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	count := ScanInt()
	weightLimit := ScanInt()
	weights := make([]int, count)
	vals := make([]int, count)
	for i := 0; i < count; i++ {
		weights[i] = ScanInt()
		vals[i] = ScanInt()
	}
	fmt.Println(knap(count, weightLimit, weights, vals))
}


package main

import "fmt"

import "math"

/*
N 個の足場があって、i番目の足場の高さは hi です。
最初、足場 1 にカエルがいて、ぴょんぴょん跳ねながら足場 N へと向かいます。カエルは足場 i にいるときに

足場 i から足場 i+1 へと移動する (そのコストは |h(i)−h(i+1)|)
足場 i から足場 i+2 へと移動する (そのコストは |h(i)−h(i+2)|)
のいずれかの行動を選べます。カエルが足場 1 から足場 N へと移動するのに必要な最小コストを求めよ。

[input]
4
10 30 40 20

[output]
30
*/

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

func main() {
	var n int
	fmt.Scan(&n)
	h := make([]int, n+1)
	dp := make([]int, n+1)

	for i := 0; i < n; i++ {
		fmt.Scan(&h[i])
		dp[i] = int(math.Pow(10, 5))
	}

	dp[0] = 0
	for i := 0; i < n-1; i++ {
		dp[i+1] = min(dp[i]+int(math.Abs(float64(h[i]-h[i+1]))), dp[i+1])
		dp[i+2] = min(dp[i]+int(math.Abs(float64(h[i]-h[i+2]))), dp[i+2])
	}

	fmt.Println(dp[n-1])
}


package main

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

func main() {
    var n int
    fmt.Scan(&n)
    h := readOneLineNums(n)
    dp := make([]int, n+1)
    for i:=1;i<=n;i++{
        dp[i] = 1000000000
    }
    for i:=0;i<n-1;i++{
        dp[i+1] = min32(dp[i+1],dp[i] + abs32(h[i]-h[i+1]))
        if i+2<n{
            dp[i+2] = min32(dp[i+2],dp[i] + abs32(h[i]-h[i+2]))
        }
    }
    fmt.Println(dp[n-1])
}

// Pairsort
type Pair struct {
    first,second int
}

type By func(p1, p2 *Pair) bool

func (by By) Sort(pairs []Pair) {
    ps := &pairSorter{
            pairs : pairs,
            by: by,
    }
    sort.Sort(ps)
}

type pairSorter struct {
    pairs []Pair
    by func(p1, p2 *Pair) bool
}

func (s *pairSorter) Len() int {
    return len(s.pairs)
}

func (s *pairSorter) Swap(i, j int) {
    s.pairs[i], s.pairs[j] = s.pairs[j], s.pairs[i]
}

func (s *pairSorter) Less(i, j int) bool {
    return s.by(&s.pairs[i], &s.pairs[j])
}

func first (p1, p2 *Pair) bool {
        return p1.first < p2.first
}

func second (p1, p2 *Pair) bool {
        return p1.second < p2.second
}
// end

func scanPairs(len int) []Pair{
    Pairs := make([]Pair, len)
    for i:=0; i<len; i++{
        fmt.Scan(&Pairs[i].first,&Pairs[i].second)
    }
    return Pairs
}

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

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

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

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

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

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

func gcd64(a, b int64) int64 {
    if a % b == 0 {
        return b
    } else {
        return gcd64(b, a%b)
    }
}

func lcm64(a, b int64) int64 {
    return a / gcd64(a, b) * b
}

// 入力処理
var sc = bufio.NewScanner(os.Stdin)
func nextLine() string {
    sc.Scan()
    return sc.Text()
}
func nextInt() int {
    sc.Scan()
    i, e := strconv.Atoi(sc.Text())
    if e != nil {
        panic(e)
    }
    return i
}

func readLineNums(len int) (nums []int){
    for i:=0; i<len; i++{
        tmp,_ := strconv.Atoi(nextLine())
        nums = append(nums,tmp)
    }
    return
}

func readOneLineNums(len int) []int{
    nums := make([]int, 0, len+10)
    var num int
    sc.Split(bufio.ScanWords)
    for i:=0; i<len; i++{
        num = nextInt()
        nums = append(nums,num)
    }
    return nums
}

func scanNums(len int) []int{
    nums := make([]int, 0, len+10)
    var num int
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return nums
}

func scanNums64(len int) []int64{
    nums := make([]int64, 0, len+10)
    var num int64
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return nums
}

func scanString(len int) (str []string){
    var s string
    for i:=0; i<len; i++{
        fmt.Scan(&s)
        str = append(str,s)
    }
    return
}

func makeTwoNums(n,m int) ([][]int){
    Nums := make([][]int, n)
    for i:=0; i<n; i++{
        Nums[i] = make([]int, m)
    }
    return Nums
}

func sortString(s string) string{
    t := strings.Split(s, "")
    sort.Strings(t)
    return strings.Join(t, "")
}

func reverseString(s string) string{
    t := []rune(s)
    for i,j := 0, len(s)-1 ; i < j ; i, j = i+1, j-1 {
        t[i], t[j] = t[j], t[i]
    }
    return string(t)
}

func stringRev(s []byte,l int,r int) []byte{
    for i:=0;i<(r-l+1)/2;i++{
        s[l-1+i], s[r-1-i] = s[r-1-i], s[l-1+i]
    }
    return s
}

func inside(h,w,H,W int) bool{
    if h>=0 && h<H && w>=0 && w<W{
        return true
    }
    return false
}