iidai/codenet huggingface dataset:
Language: Go

package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	var s string
	fmt.Scanf("%d", &n)
	fmt.Scanf("%s", &s)
	fmt.Printf("%d\n", strings.Count(s, "ABC"))
}


Example test case(s):
input: 10
ZABCDBABCQ

output: 2
Language: Go

package main

import "fmt"

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

	if A+B >= C {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Example test case(s):
input: 50 100 120

output: Yes
Language: Go

package main

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

var sc = bufio.NewScanner(os.Stdin)

func ri() (n int) {
	sc.Scan()
	for _, v := range sc.Bytes() {
		n = n*10 + int(v-48)
	}
	return
}

func ave(s []float64) float64 {
	var sum float64
	for _, v := range s {
		sum += v
	}
	return float64(sum) / float64(len(s))
}

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

func main() {
	sc.Split(bufio.ScanWords)
	n := ri()
	a := make([]float64, n)
	for i := 0; i < n; i++ {
		a[i] = float64(ri())
	}

	ave := ave(a)

	minDiff := 999999.9
	ansIndex := -1
	for i, v := range a {
		diff := diff(v, ave)
		if diff < minDiff {
			minDiff = diff
			ansIndex = i
		}
	}
	fmt.Println(ansIndex)
}


Example test case(s):
input: 3
1 2 3

output: 1
Language: Go

package main

import "fmt"

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

	a := make([][]int, n)
	p := make([]int, n)
	for i := 0; i < n; i++ {

		fmt.Scan(&p[i])
		a[i] = make([]int, m)
		for j := 0; j < m; j++ {
			fmt.Scan(&a[i][j])
		}
	}

	ans := 1200001
	var tot int
	var ok bool
	for bits := 0; bits < 1<<n; bits++ {
		tot = 0
		ok = true
		skill := make([]int, m)
		for i := 0; i < n; i++ {
			if (bits>>i)&1 == 1 {
				tot += p[i]
				for j := 0; j < m; j++ {
					skill[j] += a[i][j]
				}
			}
		}

		for _, v := range skill {
			if v < x {
				ok = false
				break
			}
		}

		if ok {
			if ans > tot {
				ans = tot
			}
		}
	}

	if ans != 1200001 {
		fmt.Println(ans)
	} else {
		fmt.Println("-1")
	}

}


Example test case(s):
input: 3 3 10
60 2 2 4
70 8 7 9
50 2 3 9

output: 120
Language: Go

package main

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

func main() {
	sc := newInputScanner(true, 256)
	N, P, S := sc.nextInt(), sc.nextInt(), sc.nextStr()
	answer := checkSubNumbers(N, P, S)
	fmt.Println(answer)
}

func checkSubNumbers(N int, P int, S string) int {
	switch P {
	case 2, 5:
		return checkTwoOrFive(N, P, S)
	default:
		return checkNotTwoNorFive(N, P, S)
	}
}

func checkTwoOrFive(N int, P int, S string) int {
	answer := 0
	var n int
	for i := N - 1; i >= 0; i-- {
		n, _ = strconv.Atoi(S[i : i+1])
		if n%P == 0 {
			answer += i + 1
		}
	}
	return answer
}

func checkNotTwoNorFive(N int, P int, S string) int {
	multiplier := 1
	answer := 0
	remainderLookup := make([]int, P)
	prevRemaider := -1
	var digit, remainder, count int
	for i := N - 1; i >= 0; i-- {
		digit = int(S[i] - '0')
		if prevRemaider == -1 {
			remainder = digit % P
		} else {
			remainder = (((multiplier * digit) % P) + prevRemaider) % P
		}
		if remainder == 0 {
			answer++
		}
		count = remainderLookup[remainder]
		answer += count
		count++
		remainderLookup[remainder] = count
		prevRemaider = remainder
		multiplier = (multiplier * 10) % P
	}
	return answer
}

type inputScanner struct {
	*bufio.Scanner
}

func newInputScanner(enabledScanWords bool, sizeInKB int) *inputScanner {
	scanner := bufio.NewScanner(os.Stdin)
	if enabledScanWords {
		scanner.Split(bufio.ScanWords)
	}
	capacity := sizeInKB * 1024
	buf := make([]byte, capacity)
	scanner.Buffer(buf, capacity)
	return &inputScanner{
		Scanner: scanner,
	}
}

func (inputSc *inputScanner) nextInt() int {
	i, e := strconv.Atoi(inputSc.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (inputSc *inputScanner) nextUInt64() uint64 {
	i, e := strconv.ParseUint(inputSc.nextStr(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func (inputSc *inputScanner) nextStr() string {
	inputSc.Scan()
	return inputSc.Text()
}


Example test case(s):
input: 4 3
3543

output: 6
Language: Go

package main

import (
	"fmt"
)

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

	var tmpSum int
	var rs int
	for i, v := range l {
		tmpSum += v
		if i >= n {
			rs = n
			break
		}
		if tmpSum <= x {
			rs = i + 2
		} else if tmpSum > x {
			break
		}
	}
	fmt.Println(rs)
}


Example test case(s):
input: 3 6
3 4 5

output: 2
Language: Go

package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e8
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	buf := make([]byte, initialBufSize)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
}

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

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

func main() {
	S := next()

	l0, l1 := 0, 0
	for i := 0; i < len(S); i++ {
		if S[i] == '0' {
			l0++
		} else {
			l1++
		}
	}
	fmt.Println(2 * min(l0, l1))
}


Example test case(s):
input: 0011

output: 4
Language: Go

package main

import "fmt"

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

	fmt.Scan(&a, &b, &c, &d, &e)

	al := []int{a, b, c, d, e}

	for n, i := range al {
		if i == 0 {
			fmt.Println(n + 1)
			break
		}
	}
}


Example test case(s):
input: 0 2 3 4 5

output: 1
Language: Go

package main

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

func mainFn() {
	n := getInt()
	ls := getIntSlice(n)
	lsRev := make([]int, n)
	copy(lsRev, ls)
	sort.Ints(ls)
	sort.Sort(sort.Reverse(sort.IntSlice(lsRev)))

	ans := 0
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			p, q := min(ls[i], ls[j]), max(ls[i], ls[j])
			x, y := q-p, q+p

			l := sort.Search(len(ls), func(i int) bool { return ls[i] > x })
			r := n - sort.Search(len(lsRev), func(i int) bool { return lsRev[i] < y })

			sum := r - l
			if (i >= l) && (i <= r) {
				sum--
			}
			if (j >= l) && (j <= r) {
				sum--
			}
			sum = max(0, sum)
			ans += sum
		}
	}

	ans /= 3
	puts(ans)
}

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

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

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

func main() {

	scanner.Split(bufio.ScanWords)
	mainFn()
	writer.Flush()
}

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

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}

func puts(a ...interface{}) {
	if _, err := fmt.Fprintln(writer, a...); err != nil {
		panic(err)
	}
}


Example test case(s):
input: 4
3 4 2 1

output: 1
Language: Go

package main

import "fmt"

type data struct {
	n, m       int
	nImg, mImg []string
}

func main() {
	d := newData()
	if d.exist() {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func newData() data {
	var n, m int
	fmt.Scanf("%d %d", &n, &m)
	nImg := load(n)
	mImg := load(m)

	return data{n: n, m: m, nImg: nImg, mImg: mImg}
}

func load(cnt int) []string {
	ret := make([]string, cnt)
	for i := 0; i < cnt; i++ {
		fmt.Scanf("%s", &ret[i])
	}

	return ret
}

func (d data) exist() bool {
	for i := 0; i <= d.n-d.m; i++ {
		for j := 0; j <= d.n-d.m; j++ {
			if d.match(i, j) {
				return true
			}
		}
	}

	return false
}

func (d data) match(x, y int) bool {
	for i := 0; i < d.m; i++ {
		for j := 0; j < d.m; j++ {
			if d.nImg[x+i][y+j] != d.mImg[i][j] {
				return false
			}
		}
	}

	return true
}


Example test case(s):
input: 3 2
#.#
.#.
#.#
#.
.#

output: Yes
Language: Go

package main

import (
	"fmt"
)

func solution(n int, a []int) int {
	var memo [1e5 + 2]int
	for _, num := range a {
		memo[num]++
		memo[num+1]++
		memo[num+2]++
	}
	out := 0
	for _, num := range memo {
		if num > 0 {
			out = max(out, num)
		}
	}
	return out
}

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 := range a {
		fmt.Scan(&a[i])
	}
	fmt.Println(solution(n, a))
}


Example test case(s):
input: 7
3 1 4 1 5 9 2

output: 4
Language: Go

package main

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

var sc = bufio.NewScanner(os.Stdin)

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

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

func pattern1(l []int) int {
	n := (l[0] * l[3]) + (l[1] * l[4])
	return n
}
func pattern2(l []int) int {
	n := 2 * l[2] * max(l[3], l[4])
	return n
}
func pattern3(l []int) int {
	n := 2*l[2]*min(l[3], l[4]) + (doch(l))
	return n
}

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 doch(l []int) int {
	if l[3] > l[4] {
		return l[0] * (l[3] - l[4])
	} else {
		return l[1] * (l[4] - l[3])
	}
}

func main() {
	len := 5
	l := scanNums(len)
	fmt.Println(min(pattern1(l), pattern2(l), pattern3(l)))

}


Example test case(s):
input: 1500 2000 1600 3 2

output: 7900
Language: Go

package main

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

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

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

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

type Val struct {
	id, num int
}
type ByNum []Val

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	A, B, C, K := sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt()
	ma := max(A, B, C)
	rest := 0
	if ma == A {
		rest += B + C
	} else if ma == B {
		rest += A + C
	} else {
		rest += A + B
	}
	for i := 1; i <= K; i++ {
		ma *= 2
	}

	fmt.Fprintln(wtr, ma+rest)
	wtr.Flush()
}


Example test case(s):
input: 5 3 11
1

output: 30
Language: Go

package main

import (
	"fmt"
	"math"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	x := m*1900 + (n-m)*100
	fmt.Println(x * int(math.Pow(2.0, float64(m))))
}


Example test case(s):
input: 1 1

output: 3800
Language: Go

package main

import (
	"fmt"
)

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

	var ans int
	if 6 <= A && A <= 12 {
		ans = B / 2
	} else if 12 < A {
		ans = B
	}
	fmt.Println(ans)
}


Example test case(s):
input: 30 100

output: 100
Language: Go

package main

import (
	"fmt"
)

const d = 1000000007

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

	mdans := map[int64]int64{}
	for index := 0; index < p; index++ {
		var n1 int64
		fmt.Scan(&n1)
		mdans[n1] = n1
	}

	dp := make([]int64, n+1, n+1)
	dp[0] = 1
	dp[1] = 1

	if _, ok := mdans[1]; ok {
		dp[1] = 0
	}

	for i := 2; i <= n; i++ {
		if _, ok := mdans[int64(i)]; ok {
			continue
		}
		dp[i] = (dp[i-1] + dp[i-2]) % d

	}

	fmt.Printf("%#v\n", dp[n])
}


Example test case(s):
input: 6 1
3

output: 4
Language: Go

package main

import (
	"fmt"
	"sort"
)

func main() {
	var N int
	fmt.Scanf("%d", &N)
	values := make([]float64, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%f", &values[i])
	}

	sort.Sort(sort.Float64Slice(values))
	var generated float64

	for i := 0; i < N-1; i++ {
		generated = (values[i] + values[i+1]) / 2
		values[i+1] = generated
	}

	fmt.Println(generated)
}


Example test case(s):
input: 2
3 4

output: 3.5
Language: Go

package main

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

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

	ns := make([]int, 4)
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d %d %d %d", &ns[0], &ns[1], &ns[2], &ns[3])

	sort.Sort(sort.IntSlice(ns))
	if ns[0] == 1 && ns[1] == 4 && ns[2] == 7 && ns[3] == 9 {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Example test case(s):
input: 1 7 9 4

output: YES
Language: Go

package main

import (
	"fmt"
)

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

		ns := primeFactorize(as[i])
		for k, v := range ns {
			ps[k] = max(ps[k], v)
		}
	}

	x := 1
	for k, v := range ps {
		for i := 1; i <= v; i++ {
			x = mul(x, k)
		}
	}

	ans := 0
	for i := 0; i < n; i++ {
		ans = add(ans, div(x, as[i]))
	}
	fmt.Println(ans)
}

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

func primeFactorize(n int) map[int]int {
	res := make(map[int]int)
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			n /= i
			res[i]++
		}
	}
	if n != 1 {
		res[n]++
	}
	return res
}

const mod int = 1000000007

func pow(n, k int) int {
	if k == 0 {
		return 1
	} else if k%2 == 1 {
		return pow(n, k-1) * n % mod
	} else {
		t := pow(n, k/2)
		return t * t % mod
	}
}

func add(a, b int) int {
	return (a + b) % mod
}

func sub(a, b int) int {
	return (a + mod - b) % mod
}

func mul(a, b int) int {
	return a % mod * b % mod % mod
}

func div(a, b int) int {
	return mul(a, pow(b, mod-2))
}


Example test case(s):
input: 3
2 3 4

output: 13
Language: Go

package main

import (
	"fmt"
)

func gcd(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}
func main() {
	var k, a, b, c int
	ans := 0
	fmt.Scan(&k)
	for a = 1; a <= k; a++ {
		for b = 1; b <= k; b++ {
			for c = 1; c <= k; c++ {
				ans += gcd(a, gcd(b, c))
			}
		}
	}
	fmt.Println(ans)
}


Example test case(s):
input: 2

output: 9
Language: Go

package main

import "fmt"

func main() {
	var s, t string
	fmt.Scan(&s, &t)
	fmt.Println(t + s)
}


Example test case(s):
input: oder atc

output: atcoder
Language: Go

package main

import (
	"fmt"
)

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

func main() {
	var H, N, A, B int
	fmt.Scan(&H, &N)
	dp := make([]int, H+10001)
	for l := 1; l < H+10001; l++ {
		dp[l] = 2100000000
	}
	amax := 0
	for i := 0; i < N; i++ {
		fmt.Scan(&A, &B)
		if A >= amax {
			amax = A
		}
		dp[A] = min(dp[A], B)
		for j := A + 1; j <= H+A+1; j++ {
			dp[j] = min(dp[j], dp[j-A]+B)
		}
	}
	fmt.Println(min(dp[H : H+amax+1]...))
}


Example test case(s):
input: 9 3
8 3
4 2
2 1

output: 4
Language: Go

package main

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

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	return t
}

type point struct {
	x, l, r int
}

type ps []point

func (p ps) Len() int {
	return len(p)
}
func (p ps) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}
func (p ps) Less(i, j int) bool {
	return p[i].r < p[j].r
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	N := nextInt(sc)
	points := make([]point, N)
	for i := 0; i < N; i++ {
		points[i].x = nextInt(sc)
		L := nextInt(sc)
		points[i].l = points[i].x - L
		points[i].r = points[i].x + L
	}
	sort.Sort(ps(points))

	start := points[0].r
	ans := 1
	for i := 0; i < len(points); i++ {
		if points[i].l < start {
			continue
		}
		start = points[i].r
		ans++
	}
	fmt.Println(ans)
}


Example test case(s):
input: 4
2 4
4 3
9 3
100 5

output: 3
Language: Go

package main

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

func main() {
	n := nextInt()
	rt := int(math.Sqrt(float64(n)))
	minf := 100
	for i := 1; i < rt+1; i++ {
		if n%i == 0 {
			b := n / i
			ndigit := 0
			for b > 0 {
				b /= 10
				ndigit++
			}
			minf = min(minf, ndigit)
		}
	}
	fmt.Println(minf)
}

const size = 1000000

var reader = bufio.NewReaderSize(os.Stdin, size)

func nextLine() string {
	var line, buffer []byte
	isPrefix := true
	var err error
	for isPrefix {
		line, isPrefix, err = reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
	}
	return string(buffer)
}
func nextStringArray() []string {
	return strings.Split(nextLine(), " ")
}
func nextInt() int {
	n, _ := strconv.Atoi(nextLine())
	return n
}
func nextIntArray() []int {
	s := strings.Split(nextLine(), " ")
	n := len(s)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i], _ = strconv.Atoi(s[i])
	}
	return a
}

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


Example test case(s):
input: 10000

output: 3
Language: Go

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]float64, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	for i := 0; i+1 < n; i++ {
		sort.Sort(sort.Float64Slice(a))
		na := make([]float64, 0)
		for j := 2; j < len(a); j++ {
			na = append(na, a[j])
		}
		na = append(na, (a[0]+a[1])/2)
		a = na
	}
	fmt.Println(a[0])
}


Example test case(s):
input: 2
3 4

output: 3.5
Language: Go

package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)

	max_tmp := 0
	max := 0
	for i := 0; i < len(s); i++ {
		flag := false
		switch string(s[i]) {
		case "A", "C", "T", "G":
			max_tmp++
		default:
			flag = true
		}

		if i == len(s)-1 {
			flag = true
		}
		if flag == true {
			if max < max_tmp {
				max = max_tmp
			}
			max_tmp = 0
		}
	}
	fmt.Println(max)
}


Example test case(s):
input: ATCODER

output: 3
Language: Go

package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
)

const Inf = 1 << 60

func main() {
	H, W, K := ReadInt(), ReadInt(), ReadInt()
	x1, y1, x2, y2 := ReadInt()-1, ReadInt()-1, ReadInt()-1, ReadInt()-1
	x1, y1 = y1, x1
	x2, y2 = y2, x2
	c := make([]string, H)
	for y := 0; y < H; y++ {
		c[y] = ReadString()
	}

	var dx = []int{1, 0, -1, 0}
	var dy = []int{0, 1, 0, -1}

	toID := func(x, y, dir int) int {
		return 4*(W*y+x) + dir
	}
	splatID := func(id int) (x, y, dir int) {
		return id / 4 % W, id / 4 / W, id % 4
	}

	dist := make([]int, W*H*4)
	for i := 0; i < W*H*4; i++ {
		dist[i] = Inf
	}

	q := Heap{}
	for i := 0; i < 4; i++ {
		q = append(q, State{
			Cost: 0,
			ID:   toID(x1, y1, i),
		})
	}
	for len(q) > 0 {
		now := q.pop()
		x, y, dir := splatID(now.ID)
		if c[y][x] == '@' {
			continue
		}
		if dist[now.ID] <= now.Cost {
			continue
		}
		dist[now.ID] = now.Cost
		if x == x2 && y == y2 {
			break
		}
		for i := 0; i < 4; i++ {
			nCost := (now.Cost + K - 1) / K * K
			nID := toID(x, y, i)
			if dist[nID] <= nCost {
				continue
			}
			q.push(State{
				Cost: nCost,
				ID:   nID,
			})
		}
		nx := x + dx[dir]
		ny := y + dy[dir]
		if 0 <= nx && nx < W && 0 <= ny && ny < H {
			nCost := now.Cost + 1
			nID := toID(nx, ny, dir)
			if dist[nID] <= nCost {
				continue
			}
			q.push(State{
				Cost: nCost,
				ID:   nID,
			})
		}
	}
	ans := Inf
	for i := 0; i < 4; i++ {
		id := toID(x2, y2, i)
		if dist[id] < ans {
			d2 := (dist[id] + K - 1) / K
			if d2 < ans {
				ans = d2
			}
		}
	}
	if ans < Inf {
		fmt.Println(ans)
	} else {
		fmt.Println(-1)
	}
}

type State struct {
	Cost, ID int
}

type HeapElement = State
type Heap []HeapElement

func (h Heap) Less(i, j int) bool    { return h[i].Cost < h[j].Cost }
func (h Heap) Len() int              { return len(h) }
func (h Heap) Swap(i, j int)         { h[i], h[j] = h[j], h[i] }
func (h *Heap) Push(x interface{})   { *h = append(*h, x.(HeapElement)) }
func (h *Heap) Pop() (x interface{}) { *h, x = (*h)[:len(*h)-1], (*h)[len(*h)-1]; return }
func (h *Heap) push(v HeapElement)   { heap.Push(h, v) }
func (h *Heap) pop() HeapElement     { return heap.Pop(h).(HeapElement) }

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Example test case(s):
input: 3 5 2
3 2 3 4
.....
.@..@
..@..

output: 5
Language: Go

package main

import (
	"fmt"
	"sort"
	"strings"
)

type city struct {
	prefecture int
	position   int
	year       int
}

type cities []*city

type cMap map[int]cities

func main() {
	var (
		n, m int
	)
	fmt.Scanf("%d %d\n", &n, &m)
	h := make(cMap)
	for i := 0; i < m; i++ {
		var x, y int
		fmt.Scanf("%d %d\n", &x, &y)
		_, exists := h[x]
		if !exists {
			h[x] = cities{{prefecture: x, year: y, position: i}}
		} else {
			h[x] = append(h[x], &city{prefecture: x, year: y, position: i})
		}
	}

	results := make([]string, m)

	for _, v := range h {
		sort.Sort(v)
		for idx, ci := range v {
			results[ci.position] = fmt.Sprintf("%06d%06d", ci.prefecture, idx+1)
		}
	}
	fmt.Println(strings.Join(results, "\n"))
}

func (c cities) Len() int {
	return len(c)
}

func (c cities) Swap(i, j int) {
	c[i], c[j] = c[j], c[i]
}

func (c cities) Less(i, j int) bool {
	return c[i].year < c[j].year
}


Example test case(s):
input: 2 3
1 32
2 63
1 12

output: 000001000002
000002000001
000001000001
Language: Go

package main

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

func main() {
	sc := NewScanner()
	A, B := sc.NextInt(), sc.NextInt()

	mx := max(A+B, A-B)
	mx = max(mx, A*B)
	fmt.Println(mx)
}

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

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

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Example test case(s):
input: -13 3

output: -10