Lee is used to finish his stories in a stylish way, this time he barely failed it, but Ice Bear came and helped him. Lee is so grateful for it, so he decided to show Ice Bear his new game called "Critic"...The game is a one versus one game. It has $$$t$$$ rounds, each round has two integers $$$s_i$$$ and $$$e_i$$$ (which are determined and are known before the game begins, $$$s_i$$$ and $$$e_i$$$ may differ from round to round). The integer $$$s_i$$$ is written on the board at the beginning of the corresponding round. The players will take turns. Each player will erase the number on the board (let's say it was $$$a$$$) and will choose to write either $$$2 \cdot a$$$ or $$$a + 1$$$ instead. Whoever writes a number strictly greater than $$$e_i$$$ loses that round and the other one wins that round.Now Lee wants to play "Critic" against Ice Bear, for each round he has chosen the round's $$$s_i$$$ and $$$e_i$$$ in advance. Lee will start the first round, the loser of each round will start the next round.The winner of the last round is the winner of the game, and the loser of the last round is the loser of the game.Determine if Lee can be the winner independent of Ice Bear's moves or not. Also, determine if Lee can be the loser independent of Ice Bear's moves or not.

The first line contains the integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of rounds the game has.  Then $$$t$$$ lines follow, each contains two integers $$$s_i$$$ and $$$e_i$$$ ($$$1 \le s_i \le e_i \le 10^{18}$$$) — the $$$i$$$-th round's information. The rounds are played in the same order as given in input, $$$s_i$$$ and $$$e_i$$$ for all rounds are known to everyone before the game starts.

Print two integers. The first one should be 1 if Lee can be the winner independent of Ice Bear's moves, and 0 otherwise. The second one should be 1 if Lee can be the loser independent of Ice Bear's moves, and 0 otherwise.

NoteRemember, whoever writes an integer greater than $$$e_i$$$ loses.

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)

	n := readNum(reader)
	var f, s = 1, 0
	for n > 0 {
		n--
		var x, y uint64
		bb, _ := reader.ReadBytes('\n')
		pos := readUint64(bb, 0, &x)
		readUint64(bb, pos+1, &y)

		if f == s {
			continue
		}

		a := chk(x, y)
		b := lck(x, y)

		if s == 1 {
			a ^= 1
			b ^= 1
		}
		s, f = a, b
	}

	fmt.Printf("%d %d\n", s, f)
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

func chk(s, e uint64) int {
	if s == e {
		return 0
	}
	if s+1 == e {
		return 1
	}
	if e&1 == 1 {
		return 1 - int(s&1)
	}
	if s <= e/4 {
		return chk(s, e/4)
	}
	if s > (e/4)*2 {
		return int((e - s) & 1)
	}
	return 1
}

func lck(s, e uint64) int {
	if e < 2*s {
		return 1
	}
	return chk(s, e/2)
}


One day Masha was walking in the park and found a graph under a tree... Surprised? Did you think that this problem would have some logical and reasoned story? No way! So, the problem...Masha has an oriented graph which $$$i$$$-th vertex contains some positive integer $$$a_i$$$. Initially Masha can put a coin at some vertex. In one operation she can move a coin placed in some vertex $$$u$$$ to any other vertex $$$v$$$ such that there is an oriented edge $$$u \to v$$$ in the graph. Each time when the coin is placed in some vertex $$$i$$$, Masha write down an integer $$$a_i$$$ in her notebook (in particular, when Masha initially puts a coin at some vertex, she writes an integer written at this vertex in her notebook). Masha wants to make exactly $$$k - 1$$$ operations in such way that the maximum number written in her notebook is as small as possible.

The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le m \le 2 \cdot 10^5$$$, $$$1 \le k \le 10^{18}$$$) — the number of vertices and edges in the graph, and the number of operation that Masha should make. The second line contains $$$n$$$ integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$) — the numbers written in graph vertices. Each of the following $$$m$$$ lines contains two integers $$$u$$$ and $$$v$$$ ($$$1 \le u \ne v \le n$$$) — it means that there is an edge $$$u \to v$$$ in the graph. It's guaranteed that graph doesn't contain loops and multi-edges.

Print one integer — the minimum value of the maximum number that Masha wrote in her notebook during optimal coin movements. If Masha won't be able to perform $$$k - 1$$$ operations, print $$$-1$$$.

NoteGraph described in the first and the second examples is illustrated below.  In the first example Masha can initially put a coin at vertex $$$1$$$. After that she can perform three operations: $$$1 \to 3$$$, $$$3 \to 4$$$ and $$$4 \to 5$$$. Integers $$$1, 2, 3$$$ and $$$4$$$ will be written in the notepad.In the second example Masha can initially put a coin at vertex $$$2$$$. After that she can perform $$$99$$$ operations: $$$2 \to 5$$$, $$$5 \to 6$$$, $$$6 \to 2$$$, $$$2 \to 5$$$, and so on. Integers $$$10, 4, 5, 10, 4, 5, \ldots, 10, 4, 5, 10$$$ will be written in the notepad.In the third example Masha won't be able to perform $$$4$$$ operations.

package main

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

const N = 200007

var n, m, totE int
var K int64
var a, f, d, g, to, sub [N]int

func addEdge(x, y int)  {
	totE ++
	sub[totE] = y
	to[totE] = g[x]
	g[x] = totE
}

func Check(val int) bool {
	q := make([]int, 0, n)
	totNum := 0
	for i := 0; i < n; i ++ {
		f[i] = 0
		d[i] = 0
	}
	for i := 0; i < n; i ++ {
		if a[i] <= val {
			totNum ++
			for p := g[i]; p != 0; p = to[p] {
				y := sub[p]
				if a[y] <= val {
					d[y] ++
				}
			}
		}
	}
	L := 0
	for i := 0; i < n; i ++ {
		if a[i] <= val && d[i] == 0 {
			q = append(q, i)
			L ++
			f[i] = 1
			d[i] --
		}
	}
	for L > 0 {
		x := q[0]
		if int64(f[x]) >= K {
			return true
		}
		q = q[1:]
		totNum --
		L --
		for p := g[x]; p != 0; p = to[p] {
			y := sub[p]
			if a[y] <= val {
				if f[x] + 1 > f[y] {
					f[y] = f[x] + 1
				}
				d[y] --
				if d[y] == 0 {
					d[y] --
					q = append(q, y)
					L ++
				}
			}
		}
	}
	return totNum > 0
}

func main()  {
	var in = bufio.NewReader(os.Stdin)
	minv := math.MaxInt32
	maxv := -math.MaxInt32
	fmt.Fscan(in, &n, &m, &K)
	for i := 0; i < n; i ++ {
		fmt.Fscan(in, &a[i])
		if a[i] < minv {
			minv = a[i]
		}
		if a[i] > maxv {
			maxv = a[i]
		}
	}
	for i := 0; i < m; i ++ {
		var x, y int
		fmt.Fscan(in, &x, &y)
		addEdge(x-1, y-1)
	}
	L, R := minv, maxv
	for L < R {
		mid := (L+R)/2
		if Check(mid){
			R = mid
		} else {
			L = mid + 1
		}
	}
	if Check(R) {
		fmt.Println(R)
	} else {
		fmt.Println(-1)
	}
}

package main

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

const N = 200007

var n, m, totE int
var K int64
var a, f, d, g, to, sub, q [N]int

var In = bufio.NewReader(os.Stdin)

func ReadInt(out *int) error {
	var ans, sign int = 0, 1
	var readed = false
	c, err := In.ReadByte()
	for ; err == nil && (c < '0' || '9' < c); c, err = In.ReadByte() {
		if c == '-' {
			sign = -sign
		}
	}
	for ; err == nil && '0' <= c && c <= '9'; c, err = In.ReadByte() {
		ans = ans<<3 + ans<<1 + int(c-'0')
		readed = true
	}
	if readed {
		*out = ans * sign
		return nil
	}
	return err
}

func ReadInt64(out *int64) error {
	var ans, sign int64 = 0, 1
	var readed = false
	c, err := In.ReadByte()
	for ; err == nil && (c < '0' || '9' < c); c, err = In.ReadByte() {
		if c == '-' {
			sign = -sign
		}
	}
	for ; err == nil && '0' <= c && c <= '9'; c, err = In.ReadByte() {
		ans = ans<<3 + ans<<1 + int64(c-'0')
		readed = true
	}
	if readed {
		*out = ans * sign
		return nil
	}
	return err
}

func addEdge(x, y int)  {
	totE ++
	sub[totE] = y
	to[totE] = g[x]
	g[x] = totE
}

func Check(val int) bool {
	totNum := 0
	for i := 0; i < n; i ++ {
		f[i] = 0
		d[i] = 0
	}
	for i := 0; i < n; i ++ {
		if a[i] <= val {
			totNum ++
			for p := g[i]; p != 0; p = to[p] {
				y := sub[p]
				if a[y] <= val {
					d[y] ++
				}
			}
		}
	}
	st, ed := 1, 0
	for i := 0; i < n; i ++ {
		if a[i] <= val && d[i] == 0 {
			ed ++
			q[ed] = i
			f[i] = 1
			d[i] --
		}
	}
	for st <= ed {
		x := q[st]
		if int64(f[x]) >= K {
			return true
		}
		st ++
		totNum --
		for p := g[x]; p != 0; p = to[p] {
			y := sub[p]
			if a[y] <= val {
				if f[x] + 1 > f[y] {
					f[y] = f[x] + 1
				}
				d[y] --
				if d[y] == 0 {
					d[y] --
					ed ++
					q[ed] = y
				}
			}
		}
	}
	return totNum > 0
}

func main()  {
	minv := math.MaxInt32
	maxv := -math.MaxInt32
	ReadInt(&n)
	ReadInt(&m)
	ReadInt64(&K)
	for i := 0; i < n; i ++ {
		ReadInt(&a[i])
		if a[i] < minv {
			minv = a[i]
		}
		if a[i] > maxv {
			maxv = a[i]
		}
	}
	for i := 0; i < m; i ++ {
		var x, y int
		ReadInt(&x)
		ReadInt(&y)
		addEdge(x-1, y-1)
	}
	L, R := minv, maxv
	for L < R {
		mid := (L+R)/2
		if Check(mid){
			R = mid
		} else {
			L = mid + 1
		}
	}
	if Check(R) {
		fmt.Println(R)
	} else {
		fmt.Println(-1)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
func gi64() int64 { i,e := strconv.ParseInt(gs(),10,64); if e != nil {panic(e)}; return i }
func gis(n int) []int  { res := make([]int,n); for i:=0;i<n;i++ { res[i] = gi() }; return res }
func ia(m int) []int { return make([]int,m) }
func iai(m int,v int) []int { a := make([]int,m); for i:=0;i<m;i++ { a[i] = v }; return a }
func fill2(m int) ([]int,[]int) { a,b := ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i] = gi(),gi()}; return a,b }
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	N,M,K := gi(),gi(),gi64(); A := gis(N); U,V := fill2(M); for i:=0;i<M;i++ { U[i]--; V[i]-- }
	gr := make([][]int,N)
	for i:=0;i<M;i++ { u,v := U[i],V[i]; gr[u] = append(gr[u],v) }
	visited := make([]bool,N)
	depth := make([]int64,N)
	check := func(v int) bool {
		for i:=0;i<N;i++ { visited[i] = false; depth[i] = -1 }
		var dfs func(n int)
		dfs = func(n int) {
			if depth[n] != -1 { return }
			if A[n] > v { depth[n] = 0; return }
			if visited[n] { depth[n] = 1000000000000000001; return }
			visited[n] = true; m := int64(1)
			for _,c := range gr[n] {
				dfs(c)
				if 1 + depth[c] > m { m = 1 + depth[c] }
			}
			depth[n] = m
		}
		for i:=0;i<N;i++ { dfs(i); if depth[i] >= K { return true } }
		return false
	}
	l,u := 0,1000000001
	for u-l > 1 { m := (u+l)>>1; if check(m) { u = m } else { l = m } }
	if u > 1000000000 { fmt.Println(-1) } else { fmt.Println(u) }
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
var wrtr = bufio.NewWriterSize(os.Stdout, 10_000_000)
var rdr = bufio.NewScanner(os.Stdin)
func gs() string  { rdr.Scan(); return rdr.Text() }
func gi() int     { i,e := strconv.Atoi(gs()); if e != nil {panic(e)}; return i }
func gi64() int64 { i,e := strconv.ParseInt(gs(),10,64); if e != nil {panic(e)}; return i }
func gis(n int) []int  { res := make([]int,n); for i:=0;i<n;i++ { res[i] = gi() }; return res }
func ia(m int) []int { return make([]int,m) }
func iai(m int,v int) []int { a := make([]int,m); for i:=0;i<m;i++ { a[i] = v }; return a }
func fill2(m int) ([]int,[]int) { a,b := ia(m),ia(m); for i:=0;i<m;i++ {a[i],b[i] = gi(),gi()}; return a,b }
func max(a,b int) int { if a > b { return a }; return b }
func min(a,b int) int { if a > b { return b }; return a }
func minarr(a []int) int { ans := a[0]; for _,aa := range(a) { if aa < ans { ans = aa } }; return ans }
type PI struct{ x, y int }
func Kosaraju(n int, diredges []PI) (int, []int) {
	g, grev, visited, visitedInv, scc, s, counter := make([][]int, n), make([][]int, n), make([]bool, n), make([]bool, n), make([]int, n), make([]int, 0, n), 0
	var dfs1, dfs2 func(int)
	for _, xx := range diredges { x, y := xx.x, xx.y; g[x] = append(g[x], y); grev[y] = append(grev[y], x) }
	dfs1 = func(u int) { if !visited[u] { visited[u] = true; for _, c := range g[u] { dfs1(c) }; s = append(s, u) } }
	for i := 0; i < n; i++ { dfs1(i) }
	dfs2 = func(u int) {
		if !visitedInv[u] { visitedInv[u] = true; for _, c := range grev[u] { dfs2(c) }; scc[u] = counter }
	}
	for i := n - 1; i >= 0; i-- { nn := s[i]; if !visitedInv[nn] { dfs2(nn); counter += 1 } }; return counter, scc
}
func main() {
	//f1, _ := os.Create("cpu.prof"); pprof.StartCPUProfile(f1); defer pprof.StopCPUProfile()
	defer wrtr.Flush()
	infn := ""; if infn == "" && len(os.Args) > 1 {	infn = os.Args[1] }
	if infn != "" {	f, e := os.Open(infn); if e != nil { panic(e) }; rdr = bufio.NewScanner(f) }
	rdr.Split(bufio.ScanWords); rdr.Buffer(make([]byte,1024),1_000_000_000)
	// PROGRAM STARTS HERE
	N,M,K := gi(),gi(),gi64(); A := gis(N); U,V := fill2(M); for i:=0;i<M;i++ { U[i]--; V[i]-- }
	// Special case for K == 1
	if K == 1 {fmt.Println(minarr(A)); return }
	check := func(ub int) bool {
		a := []PI{}
		for i:=0;i<M;i++ { u,v := U[i],V[i]; if A[u] <= ub && A[v] <= ub {a = append(a,PI{u,v}) } }
		cnt,_ := Kosaraju(N,a)
		if cnt < N { return true } // We found a cycle
		darr := iai(N,-1)
		gr := make([][]int,N)
		for _,p := range a { gr[p.x] = append(gr[p.x],p.y) }
		var dfs func(n int) int
		dfs = func(n int) int {
			if darr[n] == -1 {
				mv := 1
				for _,c := range gr[n] {  mv = max(mv,1+dfs(c)) }
				darr[n] = mv
			}
			return darr[n]
		}
		for i:=0;i<N;i++ { if int64(dfs(i)) >= K { return true } }
		return false
	}
	if !check(1000000000) {
		fmt.Println(-1)
	} else {
		check(4)
		l,u := 0,1000000000
		for u-l > 1 {
			m := (l+u)>>1
			if check(m) { u = m } else { l = m }
		}
		fmt.Println(u)
	}
}

package main

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

var in = bufio.NewReader(os.Stdin)

func read(out *int64) error {
	var ans, sign int64 = 0, 1
	var readed = false
	c, err := in.ReadByte()
	for ; err == nil && (c < '0' || '9' < c); c, err = in.ReadByte() {
		if c == '-' {
			sign = -sign
		}
	}
	for ; err == nil && '0' <= c && c <= '9'; c, err = in.ReadByte() {
		ans = ans<<3 + ans<<1 + int64(c-'0')
		readed = true
	}
	if readed {
		*out = ans * sign
		return nil
	}
	return err
}

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

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

var n, m, k, idx, cnt int64
var h, e, ne, ai, din, dist [200007]int64

func add(a, b int64) {
	e[idx] = b
	ne[idx] = h[a]
	h[a] = idx
	idx++
}

type node struct {
	a, b int64
}

var pi [200007]node
var si [400007]int64

func top() {
	var Len int64 = 0
	for i := int64(1); i <= n; i++ {
		if din[i] == 0 {
			dist[i] = 1
			si[Len] = i
			Len++
		}
	}
	var p int64 = 0
	for p != Len {
		t := si[p]
		p++
		cnt++
		for i := h[t]; i != int64(-1); i = ne[i] {
			j := e[i]
			din[j]--
			dist[j] = max(dist[j], dist[t]+1)
			if din[j] == 0 {
				si[Len] = j
				Len++
			}
		}
	}
}
func check(x int64) bool {
	cnt = 0
	for i := int64(1); i <= n; i++ {
		h[i] = -1
		dist[i] = 0
		din[i] = 0
	}
	idx = 0
	for i := int64(1); i <= m; i++ {
		a, b := pi[i].a, pi[i].b
		if ai[a] <= x && ai[b] <= x {
			add(a, b)
			din[b]++
		}
	}
	top()
	if cnt < n {
		return true
	} else {
		for i := int64(1); i <= n; i++ {
			if dist[i] >= k {
				return true
			}
		}
	}
	return false
}
func main() {
	read(&n)
	read(&m)
	read(&k)
	var mi int64 = 10000000000
	for i := int64(1); i <= n; i++ {
		read(&ai[i])
		mi = min(mi, ai[i])
	}
	var l, r int64 = 1, 10000000000
	for i := int64(1); i <= m; i++ {
		read(&pi[i].a)
		read(&pi[i].b)
	}
	if m == 0 && k == 1 {
		fmt.Println(mi)
		return
	}
	for l < r {
		mid := (l + r) / 2
		if check(mid) {
			r = mid
		} else {
			l = mid + 1
		}
	}
	if l == int64(10000000000) {
		fmt.Println(-1)
	} else {
		fmt.Println(l)
	}
}

package main

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

const N = 200007

var n, m, totE int
var K int64
var a, f, d, g, to, sub [N]int

func addEdge(x, y int)  {
	totE ++
	sub[totE] = y
	to[totE] = g[x]
	g[x] = totE
}

func Check(val int) bool {
	q := make([]int, 0, n)
	totNum := 0
	for i := 0; i < n; i ++ {
		f[i] = 0
		d[i] = 0
	}
	for i := 0; i < n; i ++ {
		if a[i] <= val {
			totNum ++
			for p := g[i]; p != 0; p = to[p] {
				y := sub[p]
				if a[y] <= val {
					d[y] ++
				}
			}
		}
	}
	L := 0
	for i := 0; i < n; i ++ {
		if a[i] <= val && d[i] == 0 {
			q = append(q, i)
			L ++
			f[i] = 1
			d[i] --
		}
	}
	for L > 1{
		x := q[0]
		if int64(f[x]) >= K {
			return true
		}
		q = q[1:]
		totNum --
		L --
		for p := g[x]; p != 0; p = to[p] {
			y := sub[p]
			if a[y] <= val {
				if f[x] + 1 > f[y] {
					f[y] = f[x] + 1
				}
				d[y] --
				if d[y] == 0 {
					d[y] --
					q = append(q, y)
					L ++
				}
			}
		}
	}
	return totNum > 0
}

func main()  {
	var in = bufio.NewReader(os.Stdin)
	minv := math.MaxInt32
	maxv := -math.MaxInt32
	fmt.Fscan(in, &n, &m, &K)
	for i := 0; i < n; i ++ {
		fmt.Fscan(in, &a[i])
		if a[i] < minv {
			minv = a[i]
		}
		if a[i] > maxv {
			maxv = a[i]
		}
	}
	for i := 0; i < m; i ++ {
		var x, y int
		fmt.Fscan(in, &x, &y)
		addEdge(x-1, y-1)
	}
	L, R := minv, maxv
	for L < R {
		mid := (L+R)/2
		if Check(mid){
			R = mid
		} else {
			L = mid + 1
		}
	}
	if Check(R) {
		fmt.Println(R)
	} else {
		fmt.Println(-1)
	}
}

package main

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

const N = 200007

var n, m, totE int
var K int64
var a, f, d, g, to, sub, q [N]int

var In = bufio.NewReader(os.Stdin)

func ReadInt(out *int) error {
	var ans, sign int = 0, 1
	var readed = false
	c, err := In.ReadByte()
	for ; err == nil && (c < '0' || '9' < c); c, err = In.ReadByte() {
		if c == '-' {
			sign = -sign
		}
	}
	for ; err == nil && '0' <= c && c <= '9'; c, err = In.ReadByte() {
		ans = ans<<3 + ans<<1 + int(c-'0')
		readed = true
	}
	if readed {
		*out = ans * sign
		return nil
	}
	return err
}

func ReadInt64(out *int64) error {
	var ans, sign int64 = 0, 1
	var readed = false
	c, err := In.ReadByte()
	for ; err == nil && (c < '0' || '9' < c); c, err = In.ReadByte() {
		if c == '-' {
			sign = -sign
		}
	}
	for ; err == nil && '0' <= c && c <= '9'; c, err = In.ReadByte() {
		ans = ans<<3 + ans<<1 + int64(c-'0')
		readed = true
	}
	if readed {
		*out = ans * sign
		return nil
	}
	return err
}

func addEdge(x, y int)  {
	totE ++
	sub[totE] = y
	to[totE] = g[x]
	g[x] = totE
}

func Check(val int) bool {
	totNum := 0
	for i := 0; i < n; i ++ {
		f[i] = 0
		d[i] = 0
	}
	for i := 0; i < n; i ++ {
		if a[i] <= val {
			totNum ++
			for p := g[i]; p != 0; p = to[p] {
				y := sub[p]
				if a[y] <= val {
					d[y] ++
				}
			}
		}
	}
	st, ed := 0, 1
	for i := 0; i < n; i ++ {
		if a[i] <= val && d[i] == 0 {
			ed ++
			q[ed] = i
			f[i] = 1
		}
	}
	for st <= ed {
		x := q[st]
		if int64(f[x]) >= K {
			return true
		}
		st ++
		totNum --
		for p := g[x]; p != 0; p = to[p] {
			y := sub[p]
			if a[y] <= val {
				if f[x] + 1 > f[y] {
					f[y] = f[x] + 1
				}
				d[y] --
				if d[y] == 0 {
					d[y] --
					ed ++
					q[ed] = y
				}
			}
		}
	}
	return totNum > 0
}

func main()  {
	minv := math.MaxInt32
	maxv := -math.MaxInt32
	ReadInt(&n)
	ReadInt(&m)
	ReadInt64(&K)
	for i := 0; i < n; i ++ {
		ReadInt(&a[i])
		if a[i] < minv {
			minv = a[i]
		}
		if a[i] > maxv {
			maxv = a[i]
		}
	}
	for i := 0; i < m; i ++ {
		var x, y int
		ReadInt(&x)
		ReadInt(&y)
		addEdge(x-1, y-1)
	}
	L, R := minv, maxv
	for L < R {
		mid := (L+R)/2
		if Check(mid){
			R = mid
		} else {
			L = mid + 1
		}
	}
	if Check(R) {
		fmt.Println(R)
	} else {
		fmt.Println(-1)
	}
}


Jett is tired after destroying the town and she wants to have a rest. She likes high places, that's why for having a rest she wants to get high and she decided to craft staircases.A staircase is a squared figure that consists of square cells. Each staircase consists of an arbitrary number of stairs. If a staircase has $$$n$$$ stairs, then it is made of $$$n$$$ columns, the first column is $$$1$$$ cell high, the second column is $$$2$$$ cells high, $$$\ldots$$$, the $$$n$$$-th column if $$$n$$$ cells high. The lowest cells of all stairs must be in the same row.A staircase with $$$n$$$ stairs is called nice, if it may be covered by $$$n$$$ disjoint squares made of cells. All squares should fully consist of cells of a staircase. This is how a nice covered staircase with $$$7$$$ stairs looks like:  Find out the maximal number of different nice staircases, that can be built, using no more than $$$x$$$ cells, in total. No cell can be used more than once.

The first line contains a single integer $$$t$$$ $$$(1 \le t \le 1000)$$$  — the number of test cases. The description of each test case contains a single integer $$$x$$$ $$$(1 \le x \le 10^{18})$$$  — the number of cells for building staircases.

For each test case output a single integer  — the number of different nice staircases, that can be built, using not more than $$$x$$$ cells, in total.

NoteIn the first test case, it is possible to build only one staircase, that consists of $$$1$$$ stair. It's nice. That's why the answer is $$$1$$$.In the second test case, it is possible to build two different nice staircases: one consists of $$$1$$$ stair, and another consists of $$$3$$$ stairs. This will cost $$$7$$$ cells. In this case, there is one cell left, but it is not possible to use it for building any nice staircases, that have not been built yet. That's why the answer is $$$2$$$.In the third test case, it is possible to build only one of two nice staircases: with $$$1$$$ stair or with $$$3$$$ stairs. In the first case, there will be $$$5$$$ cells left, that may be used only to build a staircase with $$$2$$$ stairs. This staircase is not nice, and Jett only builds nice staircases. That's why in this case the answer is $$$1$$$. If Jett builds a staircase with $$$3$$$ stairs, then there are no more cells left, so the answer is $$$1$$$ again.

package main
import (
	"fmt"
)
func main(){
	var query int
	var dp [128]int64
	var now,base int64
	dp[0] = 0
	now = 1
	base = 1
	len := 1
	for {
		dp[len] = dp[len - 1] + now * (now + 1) / 2
		base = base * 2
		now = now + base
		if dp[len] > 1000000000000000000{
			break
		}
		len++
	}
	fmt.Scanln(&query)
	for i := 0; i < query; i++{
		var n int64
		fmt.Scanln(&n)
		for j := 1; j <= len; j++{
			if dp[j] > n{
				fmt.Println(j - 1)
				break
			}
		}
	}
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)

	tc := readNum(reader)

	var buf bytes.Buffer

	for tc > 0 {
		tc--

		var x uint64

		s, _ := reader.ReadBytes('\n')

		readUint64(s, 0, &x)

		res := solve(int64(x))

		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	fmt.Print(buf.String())
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

func solve(x int64) int {
	var ans int
	for i := 1; count(1<<i-1) <= x; i++ {
		ans++
		x -= count(1<<i - 1)
	}

	return ans
}

func count(n int) int64 {
	N := int64(n)

	return N * (N + 1) / 2
}

package main

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

func val (x int64) int64 {
	var b float64 = -3
	var a float64 = 4
	var c float64 = 9 + float64(x-1)

	res := b + math.Sqrt(c)
	res /= a
	return int64(math.Floor(res))
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	bf := make([]byte, 1024*1024)
	sc.Buffer(bf, 10*1024*1024)
	sc.Split(bufio.ScanWords)

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

	for t := in(); t > 0; t-- {
		x := in()

		var cnt int64 = -1
		var v int64
		for x >= 0 {
			v = int64(math.Pow(2, float64(cnt+1)) - 1)
			x -= (2*v*v + 3*v + 1)
			cnt++
		}

		fmt.Println(cnt)
	}
}

package main

import "fmt"

func calc(a int64) int64 {
	return a * (a + 1) / 2
}

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

	for t := 0; t < T; t++ {
		var x int64
		fmt.Scan(&x)
		ans := 0
		for i := int64(1); i < int64(64); i++ {
			y := calc((int64(1) << i) - 1)
			if (y <= x) {
				ans++
				x -= y
			} else {
				break
			}
		}
		fmt.Println(ans)
	}

}

package main

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

var rw = NewFastIO(os.Stdin, os.Stdout)

func main() {
	defer rw.Flush()
	for tt := rw.NextInt(); tt > 0; tt-- {
		n := rw.NextInt64()
		for i := 0; ; i++ {
			x := int64(1) << i
			if x*(x-1)/2 > n {
				rw.Println(i - 1)
				break
			} else {
				n -= x * (x - 1) / 2
			}
		}
	}
}

// @meooow template uwu
type FastIO struct {
	*bufio.Writer
	r    io.Reader
	buf  [8192]byte
	i, n int
}

func NewFastIO(r io.Reader, w io.Writer) *FastIO {
	return &FastIO{r: r, Writer: bufio.NewWriter(w)}
}

func (f *FastIO) readC() byte {
	if f.i == f.n {
		f.n, _ = f.r.Read(f.buf[:])
		if f.n == 0 {
			panic("EOF")
		}
		f.i = 0
	}
	f.i++
	return f.buf[f.i-1]
}

func (f *FastIO) Next() string {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	var s []byte
	for ; c > ' '; c = f.readC() {
		s = append(s, c)
	}
	return string(s)
}

func (f *FastIO) NextInt() int {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := 0
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}
func (f *FastIO) NextInt64() int64 {
	c := f.readC()
	for ; c <= ' '; c = f.readC() {
	}
	neg := false
	if c == '-' {
		neg = true
		c = f.readC()
	}
	n := int64(0)
	for ; '0' <= c && c <= '9'; c = f.readC() {
		n = n*10 + int64(c) - '0'
	}
	if neg {
		return -n
	}
	return n
}

func (f *FastIO) NextInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt()
	}
	return a
}
func (f *FastIO) NextInt64s(n int) []int64 {
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = f.NextInt64()
	}
	return a
}

func (f *FastIO) Println(a ...interface{}) {
	fmt.Fprintln(f, a...)
}

func (f *FastIO) Print(a ...interface{}) {
	fmt.Fprint(f, a...)
}
func (f *FastIO) PrintInts(a ...int) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}
func (f *FastIO) PrintlnInts(a ...int) {
	f.PrintInts(a...)
	f.Println()
}
func (f *FastIO) PrintInt64s(a ...int64) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}
func (f *FastIO) PrintlnInt64s(a ...int64) {
	f.PrintInt64s(a...)
	f.Println()
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscan(in, &t)
	// pre compute all the nice stairs before running the test cases
	niceStairs := make([]int64, 32)
	pow := 0
	i := 0
	for last := int64(0); last <= int64(1e18); {
		niceStairs[i] = 1<<pow + 2*last
		last = niceStairs[i]
		pow += 2
		i++
	}
	for ; t > 0; t-- {
		x := int64(0)
		cnt := 0
		fmt.Fscan(in, &x)
		for i := 0; i < len(niceStairs); i++ {
			if x < niceStairs[i] {
				break
			}
			x -= niceStairs[i]
			cnt++
		}
		fmt.Fprintln(out, cnt)
	}
}

package main

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

const (
	SCANNER_BUF_SIZE = 2 << 20

	INF = int64(math.MaxInt64)
	MOD = 1e9 + 7
)

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

func init() {
	writer = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, SCANNER_BUF_SIZE), SCANNER_BUF_SIZE)
}

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

func sint64() int64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func suint64() uint64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

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

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

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

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

type staircase struct {
	baseLength   int64
	totalSquares int64
}

func (s staircase) Next() staircase {
	return staircase{
		baseLength: s.baseLength*2 + 1,
		totalSquares: s.totalSquares*2 + ((s.baseLength+1)*(s.baseLength+1)),
	}
}

var dp = []staircase{
	{
		baseLength: 1,
		totalSquares: 1,
	},
}

func init() {
	for i := 0; i < 30; i++ {
		dp = append(dp, dp[len(dp)-1].Next())
	}
}

func main() {
	defer writer.Flush()
	t := sint64()
	for ; t > 0; t-- {
		printf("%d\n", sol(sint64()))
	}
}

func sol(n int64) int64 {
	ret := int64(0)
	for _, sc := range dp {
		if n >= sc.totalSquares {
			n -= sc.totalSquares
			ret++
			continue
		}
		break
	}
	return ret
}

package main
import (
	"fmt"
)
func main(){
	var query int
	var dp [128]int64
	var now,base int64
	dp[0] = 0
	now = 1
	base = 1
	len := 1
	for {
		dp[len] = dp[len - 1] + now * (now + 1) / 2
		base = base * 2
		now = now + base
		if dp[len] > 1000000000000000000{
			break
		}
		len++
	}
	fmt.Scanf("%d", &query)
	for i := 0; i < query; i++{
		var n int64
		fmt.Scanf("%d", &n)
		if n == 0 {
			continue
			query++
		}
		for j := 1; j <= len; j++{
			if dp[j] > n{
				fmt.Println(j - 1)
				break
			}
		}
	}
}

package main
import (
	"fmt"
)
func main(){
	var query int
	var dp [128]int64
	var now,base int64
	dp[0] = 0
	now = 1
	base = 1
	len := 1
	for {
		dp[len] = dp[len - 1] + now * (now + 1) / 2
		base = base * 2
		now = now + base
		if dp[len] > 1000000000000000000{
			break
		}
		len++
	}
	fmt.Scanf("%d", &query)
	for i := 0; i < query; i++{
		var n int64
		fmt.Scanf("%d", &n)
		if n == 0 {
			continue
		}
		for j := 1; j <= len; j++{
			if dp[j] > n{
				fmt.Println(j - 1)
				break
			}
		}
	}
}

package main
import (
	"fmt"
)
func main(){
	var query int
	var dp [128]int64
	var now,base int64
	dp[0] = 0
	now = 1
	base = 1
	len := 1
	for {
		dp[len] = dp[len - 1] + now * (now + 1) / 2
		base = base * 2
		now = now + base
		if dp[len] > 1000000000000000000{
			break
		}
		len++
	}
	fmt.Scanf("%d", &query)
	for i := 0; i < query; i++{
		var n int64
		fmt.Scanf("%d", &n)
		for j := 1; j <= len; j++{
			if dp[j] > n{
				fmt.Println(j - 1)
				break
			}
		}
	}
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)

	tc := readNum(reader)

	var buf bytes.Buffer

	for tc > 0 {
		tc--

		var x uint64

		s, _ := reader.ReadBytes('\n')

		readUint64(s, 0, &x)

		res := solve(int64(x))

		buf.WriteString(fmt.Sprintf("%d\n", res))
	}

	fmt.Print(buf.String())
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

const N = 31

var X [N]int64

func init() {
	X[1] = 1

	for i := 2; i < N; i++ {
		I := int64(i)
		X[i] = I*I + 2*X[i-1]
	}
}

func solve(x int64) int {

	for i := 1; i < N; i++ {
		if X[i] >= x {
			return i - 1
		}
	}
	return N - 1
}

package main

import "fmt"

func calc(a int64) int64 {
	return a * (a + 1) / 2
}

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

	for t := 0; t < T; t++ {
		var x int64
		fmt.Scanf("%d", &x)
		ans := 0
		for i := 1; i < 64; i++ {
			y := calc((int64(1) << i) - 1)
			if (y <= x) {
				ans++
				x -= y
			} else {
				break
			}
		}
		fmt.Println(ans)
	}

}


It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of n distinct integers. And then they take turns to make the following moves. During each move, either Alice or Bob (the player whose turn is the current) can choose two distinct integers x and y from the set, such that the set doesn't contain their absolute difference |x - y|. Then this player adds integer |x - y| to the set (so, the size of the set increases by one).If the current player has no valid move, he (or she) loses the game. The question is who will finally win the game if both players play optimally. Remember that Alice always moves first.

The first line contains an integer n (2 ≤ n ≤ 100) — the initial number of elements in the set. The second line contains n distinct space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the elements of the set.

Print a single line with the winner's name. If Alice wins print "Alice", otherwise print "Bob" (without quotes).

NoteConsider the first test sample. Alice moves first, and the only move she can do is to choose 2 and 3, then to add 1 to the set. Next Bob moves, there is no valid move anymore, so the winner is Alice.

package main

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

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

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

func main(){
	var n int
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	n, _ = strconv.Atoi(r.Text())
	a := make([]int, n)
	g, m := 0, 0
	for i:=0; i<n; i++ {
		r.Scan()
		a[i], _ = strconv.Atoi(r.Text())
		g = gcd(a[i], g)
		m = max(m, a[i])
	}
	if ((m/g)-n)%2 != 0 {
		w.WriteString("Alice\n")
		w.Flush()
	} else {
		w.WriteString("Bob\n")
		w.Flush()
	}
}

package main

import "fmt"

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

func main() {
    var n,a int
    fmt.Scan(&n)
    m, g := 0, 0
    for i := 0; i < n; i++ {
        fmt.Scan(&a)
        if m < a { m = a }
        g = gcd(a,g)
    }
    if ((m/g)-n)%2 == 1 { fmt.Println("Alice") } else { fmt.Println("Bob") }
}

// 346A
package main

import (
	"fmt"
)

func gcd(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}
func main() {
	var n int
	gcd1, max := 0, 0
	var a [110]int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
		if max < a[i] {
			max = a[i]
		}
		gcd1 = gcd(gcd1, a[i])
	}
	x := (max / gcd1) - n
	if x%2 != 0 {
		fmt.Println("Alice")
	} else {
		fmt.Println("Bob")
	}
}

package main

import "fmt"

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

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

func main() {
	var n int
	fmt.Scanln(&n)

	nums := make([]int, n)
	for i := range nums {
		fmt.Scanf("%d", &nums[i])
	}

	div := gcd(nums[0], nums[1])
	top := max(nums[0], nums[1])
	for i := 2; i < n; i++ {
		div = gcd(div, nums[i])
		top = max(top, nums[i])
	}

	alice := (top / div - n) % 2 == 1
	if alice {
		fmt.Println("Alice")
	} else {
		fmt.Println("Bob")
	}
}

// 346A-mic_rizal
package main

import (
	"fmt"
	"sort"
)

func gcd(x, y int64) int64 {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func main() {
	var n, i, x, b int64
	fmt.Scan(&n)
	a := make([]int, n)
	for i = 0; i < n; i++ {
		fmt.Scan(&x)
		a[i] = int(x)
	}
	b = int64(a[0])
	for i = 1; i < n; i++ {
		b = gcd(int64(a[i]), b)
	}
	sort.Sort(sort.IntSlice(a))
	a[n-1] /= int(b)
	if (a[n-1]-int(n))%2 == 0 {
		fmt.Println("Bob")
	} else {
		fmt.Println("Alice")
	}
}

// Author: sighduck
// URL: https://codeforces.com/problemset/problem/346/A

package main

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

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

func Solve(n int, a []int) string {
	max := 0
	for _, elem := range a {
		if elem > max {
			max = elem
		}
	}
	d := a[0]
	for i := 1; i < n; i++ {
		d = gcd(d, a[i])
	}
	moves := max/d - n
	if moves%2 == 1 {
		return "Alice"
	}
	return "Bob"
}

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

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

	fmt.Fprintf(writer, "%s\n", Solve(n, a))
}

package main

import (
    "strconv"
    "bufio"
    "os"
    "fmt"
)
// var file, _ = os.Open("input.txt")
// var outfile, _ = os.Create("output.txt")
// var in = bufio.NewScanner(file)
// var out = bufio.NewWriter(outfile)
var in = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func next() string {
    if !in.Scan() {
        panic("Scan error")
    }
    return in.Text()
}

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

func nextFloat() float64 {
    ret, _ := strconv.ParseFloat(next(), 64)
    return ret
}

func gcd(x int, y int) int {
    for ; x > 0 && y > 0; {
        if x > y {
            x = x % y
        } else {
            y = y % x
        }
    }
    return x + y
}

func main() {
    defer out.Flush()
    in.Split(bufio.ScanWords)
    n := nextInt()
    x := make([]int, n)
    max := 1
    for i := 0; i < n; i++ {
        x[i] = nextInt()
        if max < x[i] {
            max = x[i]
        }
    }
    g := gcd(x[0], x[1])

    for i := 2; i < n; i++ {
        g = gcd(g, x[i])
    }
    res := max / g - n
    if res % 2 == 0 {
        fmt.Fprintln(out, "Bob")
    } else {
        fmt.Fprintln(out, "Alice")
    }
}

// 346A
package main

import (
	"fmt"
)

func gcd(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}
func main() {
	var n int
	gcd1, max := 0, 0
	var a [110]int
	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
		if max < a[i] {
			max = a[i]
		}
		gcd1 = gcd(gcd1, a[i])
	}
	x := (max / gcd1) - n
	if x%2 == 0 {
		fmt.Println("Alice")
	} else {
		fmt.Println("Bob")
	}
}

package main

import (
    "strconv"
    "bufio"
    "os"
    "fmt"
)
// var file, _ = os.Open("input.txt")
// var outfile, _ = os.Create("output.txt")
// var in = bufio.NewScanner(file)
// var out = bufio.NewWriter(outfile)
var in = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func next() string {
    if !in.Scan() {
        panic("Scan error")
    }
    return in.Text()
}

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

func nextFloat() float64 {
    ret, _ := strconv.ParseFloat(next(), 64)
    return ret
}

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

func main() {
    defer out.Flush()
    in.Split(bufio.ScanWords)
    n := nextInt()
    x := make([]int, n)
    max := 1
    m := make(map[int]bool)
    for i := 0; i < n; i++ {
        x[i] = nextInt()
        if max < x[i] {
            max = x[i]
        }
        m[x[i]] = true
    }
    for ;; {
        ok := false
        for i := 0; i < len(x) - 1; i++ {
            a := abs(x[i] - x[i + 1])
            if !m[a] {
                x = append(x, a)
                m[a] = true
                ok = true
            }
        }
        if m[1] || !ok {
            break
        }
    }
    res := max - n
    if !m[1] {
        res = len(x) - n
    }
    if res % 2 == 0 {
        fmt.Fprintln(out, "Bob")
    } else {
        fmt.Fprintln(out, "Alice")
    }
}


One day Jeff got hold of an integer sequence a1, a2, ..., an of length n. The boy immediately decided to analyze the sequence. For that, he needs to find all values of x, for which these conditions hold:  x occurs in sequence a.  Consider all positions of numbers x in the sequence a (such i, that ai = x). These numbers, sorted in the increasing order, must form an arithmetic progression. Help Jeff, find all x that meet the problem conditions.

The first line contains integer n (1 ≤ n ≤ 105). The next line contains integers a1, a2, ..., an (1 ≤ ai ≤ 105). The numbers are separated by spaces.

In the first line print integer t — the number of valid x. On each of the next t lines print two integers x and px, where x is current suitable value, px is the common difference between numbers in the progression (if x occurs exactly once in the sequence, px must equal 0). Print the pairs in the order of increasing x.

NoteIn the first test 2 occurs exactly once in the sequence, ergo p2 = 0.

package main

//import "fmt"
import "os"
import "bufio"
import "strconv"

func main(){
	var n int
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	n, _ = strconv.Atoi(r.Text())
	first := make([]int, 100001)
	last := make([]int, 100001)
	diff := make([]int, 100001)
	for i:=0; i<100001; i++ {
		first[i] = -1
		diff[i] = 0
		last[i] = -1
	}
	a := 0
	count := 0
	for j:=0; j<n; j++ {
		r.Scan()
		a, _ = strconv.Atoi(r.Text())
		if first[a] == -1 {
			first[a] = j
			count += 1
		} else {
			if diff[a] == 0 {
				diff[a] = j - first[a]
			} else if diff[a] > 0 && j-last[a] != diff[a] {
				diff[a] = -1
				count -= 1
			}
		}
		last[a] = j
	}
	w.WriteString(strconv.Itoa(count)+"\n")
	w.Flush()
	for k:=0; k<100001; k++ {
		if first[k] >= 0 {
			if diff[k] >= 0 {
				w.WriteString(strconv.Itoa(k)+" "+strconv.Itoa(diff[k])+" ")
				w.Flush()
				w.WriteString("\n")
				w.Flush()
			}
		}
	}
}

// http://codeforces.com/problemset/problem/352/B
// B. Jeff and Periods

package main

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

func main() {
	var (
		n, i, max, all int32
		last, diff, a  []int32
		lai, dai       *int32
		in             *bufio.Reader
		out            *bufio.Writer
	)

	in = bufio.NewReader(os.Stdin)
	out = bufio.NewWriter(os.Stdout)

	fmt.Fscan(in, &n)
	a = make([]int32, n+1, n+1)
	for i = 1; i <= n; i++ {
		fmt.Fscan(in, &a[i])
		if a[i] > max {
			max = a[i]
		}
	}

	last = make([]int32, max+1, max+1)
	diff = make([]int32, max+1, max+1)

	for i = 1; i <= n; i++ {
		lai = &last[a[i]]
		if 0 == *lai {
			all++
			*lai = i
			continue
		}
		dai = &diff[a[i]]
		if *lai > 0 {
			if *dai == 0 {
				*dai = i - *lai
				*lai = i
				continue
			}
			if *dai == i-*lai {
				*lai = i
				continue
			}
			all--
			*lai = -1
		}
	}

	//last = last[0 : max+1]
	//fmt.Println(last)

	fmt.Fprintln(out, all)
	for i = 1; i <= max; i++ {
		if last[i] > 0 {
			fmt.Fprintln(out, i, diff[i])
		}
	}
	out.Flush()
}

package main

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

type Answer struct {
    a,b int
}

type Element struct {
    v,p int
}

type ElementSlice []Element

func (e ElementSlice) Len() int { return len(e) }
func (e ElementSlice) Swap(i,j int) { e[i], e[j] = e[j], e[i] }
func (e ElementSlice) Less(i,j int) bool {
    if e[i].v == e[j].v { return e[i].p < e[j].p }
    return e[i].v < e[j].v
}

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    writer := bufio.NewWriter(os.Stdout)
    var n int
    fmt.Scan(&n)
    a := make(ElementSlice,n)
    for i := 0; i < n; i++ {
        scanner.Scan()
        a[i].v, _ = strconv.Atoi(scanner.Text())
        a[i].p = i
    }
    sort.Sort(a)
    cnt := 0
    ans := make([]Answer,0,n)
    for i := 0; i < n; i++ {
        ok, d := true, 0
        if (i+1 < n) && (a[i+1].v == a[i].v) {
            d = a[i+1].p - a[i].p
            i++
            for (i+1 < n) && (a[i+1].v == a[i].v) {
                if (a[i+1].p - a[i].p) != d { ok = false }
                i++
            }
        }
        if ok {
            cnt++
            ans = append(ans,Answer{a[i].v,d})
        }
    }
    fmt.Println(cnt)
    for i := 0; i < len(ans); i++ {
        writer.WriteString(strconv.Itoa(ans[i].a)+" "+strconv.Itoa(ans[i].b)+"\n")
    }
    writer.Flush()
}

// 352B
package main

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

func main() {
	var n, i, max, all int32
	var last, diff, a []int32
	var c, d *int32
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	fmt.Fscan(in, &n)
	a = make([]int32, n+1, n+1)
	for i = 1; i <= n; i++ {
		fmt.Fscan(in, &a[i])
		if a[i] > max {
			max = a[i]
		}
	}
	last = make([]int32, max+1, max+1)
	diff = make([]int32, max+1, max+1)
	for i = 1; i <= n; i++ {
		c = &last[a[i]]
		if 0 == *c {
			all++
			*c = i
			continue
		}
		d = &diff[a[i]]
		if *c > 0 {
			if *d == 0 {
				*d = i - *c
				*c = i
				continue
			}
			if *d == i-*c {
				*c = i
				continue
			}
			all--
			*c = -1
		}
	}
	fmt.Fprintln(out, all)
	for i = 1; i <= max; i++ {
		if last[i] > 0 {
			fmt.Fprintln(out, i, diff[i])
		}
	}
	out.Flush()
}

// 352b-mic_rizal
package main

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

func main() {
    var n, x int
    var p, c [100010]int
    z := bufio.NewReader(os.Stdin)
    fmt.Scan(&n)
    for i := 0; i < 100010; i++ {
        p[i] = 0
        c[i] = -1
    }
    cou := 0
    for i := 1; i <= n; i++ {
        fmt.Fscan(z, &x)
        if c[x] == -1 {
            p[x] = 0
            cou++
        } else if p[x] == 0 {
            p[x] = i - c[x]
        } else if p[x] != -1 && i-c[x] != p[x] {
            p[x] = -1
            cou--
        }
        c[x] = i
    }
    fmt.Println(cou)
    for i := 1; i < 100010; i++ {
        if c[i] != -1 && p[i] != -1 {
            fmt.Println(i, p[i])
        }
    }
}

package main

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

type Element struct {
    v,p int
}

type ElementSlice []Element

func (e ElementSlice) Len() int { return len(e) }
func (e ElementSlice) Swap(i,j int) { e[i], e[j] = e[j], e[i] }
func (e ElementSlice) Less(i,j int) bool {
    if e[i].v == e[j].v { return e[i].p < e[j].p }
    return e[i].v < e[j].v
}

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    writer := bufio.NewWriter(os.Stdout)
    var n int
    fmt.Scan(&n)
    a := make(ElementSlice,n)
    for i := 0; i < n; i++ {
        scanner.Scan()
        a[i].v, _ = strconv.Atoi(scanner.Text())
        a[i].p = i
    }
    sort.Sort(a)
    cnt := 0
    for i := 0; i < n; i++ {
        ok, d := true, 0
        if (i+1 < n) && (a[i+1].v == a[i].v) {
            d = a[i+1].p - a[i].p
            i++
            for (i+1 < n) && (a[i+1].v == a[i].v) {
                if (a[i+1].p - a[i].p) != d { ok = false }
                i++
            }
        }
        if ok {
            cnt++
            writer.WriteString(strconv.Itoa(a[i].v)+" "+strconv.Itoa(d)+"\n")
        }
    }
    fmt.Println(cnt)
    writer.Flush()
}


Your friend Mishka and you attend a calculus lecture. Lecture lasts n minutes. Lecturer tells ai theorems during the i-th minute.Mishka is really interested in calculus, though it is so hard to stay awake for all the time of lecture. You are given an array t of Mishka's behavior. If Mishka is asleep during the i-th minute of the lecture then ti will be equal to 0, otherwise it will be equal to 1. When Mishka is awake he writes down all the theorems he is being told — ai during the i-th minute. Otherwise he writes nothing.You know some secret technique to keep Mishka awake for k minutes straight. However you can use it only once. You can start using it at the beginning of any minute between 1 and n - k + 1. If you use it on some minute i then Mishka will be awake during minutes j such that  and will write down all the theorems lecturer tells.You task is to calculate the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.

The first line of the input contains two integer numbers n and k (1 ≤ k ≤ n ≤ 105) — the duration of the lecture in minutes and the number of minutes you can keep Mishka awake. The second line of the input contains n integer numbers a1, a2, ... an (1 ≤ ai ≤ 104) — the number of theorems lecturer tells during the i-th minute. The third line of the input contains n integer numbers t1, t2, ... tn (0 ≤ ti ≤ 1) — type of Mishka's behavior at the i-th minute of the lecture.

Print only one integer — the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up.

NoteIn the sample case the better way is to use the secret technique at the beginning of the third minute. Then the number of theorems Mishka will be able to write down will be equal to 16.

package main

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

var in = bufio.NewScanner(os.Stdin)

func nextInt() int {
	in.Scan()
	r := 0
	for _, c := range in.Bytes() {
		r *= 10
		r += int(c - '0')
	}
	return r
}

func main() {
	in.Split(bufio.ScanWords)
	n, k, c, r, s := nextInt(), nextInt(), 0, 0, 0
	a, t := make([]int, n), make([]int, n)
	for i := range a {
		a[i] = nextInt()
	}
	for i := range a {
		t[i] = nextInt()
		if t[i] == 0 {
			c += a[i]
		} else {
			s += a[i]
		}
		if i >= k && t[i-k] == 0 {
			c -= a[i-k]
		}
		if r < c {
			r = c
		}
	}
	fmt.Println(r + s)
}

package main

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

type scanner struct {
	*bufio.Scanner
}

func (s *scanner) nextInt() int64 {
	s.Scan()
	v, _ := strconv.ParseInt(s.Text(), 10, 64)
	return v
}

func main() {
	in := &scanner{bufio.NewScanner(os.Stdin)}
	in.Split(bufio.ScanWords)

	n, k := in.nextInt(), in.nextInt()

	var a, t []int64
	a = make([]int64, n+10)
	t = make([]int64, n+10)
	for i := int64(1); i <= n; i++ {
		a[i] = in.nextInt()
	}
	var sum int64
	for i := int64(1); i <= n; i++ {
		t[i] = in.nextInt()
		if t[i] > 0 {
			sum += a[i]
		}
	}
	var base, awake int64
	var ans int64
	for i := int64(1); i <= n+1; i++ {
		awake += a[i]
		if t[i] > 0 {
			base += a[i]
		}
		if i < k {
			continue
		}
		j := i - k
		awake -= a[j]
		if t[j] > 0 {
			base -= a[j]
		}
		if v := sum - base + awake; v > ans {
			ans = v
		}
	}
	fmt.Println(ans)
}

package main

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

func main() {
	var n, k int
	stdin := bufio.NewReader(os.Stdin)
	fmt.Fscanf(stdin, "%d %d\n", &n, &k)
	theorems := make([]int, 0, n)
	wakes := make([]int, 0, n)
	// load theorems
	for i := 0; i < n; i++ {
		var t int
		format := "%d"
		if i == n-1 {
			format = "%d\n"
		}
		fmt.Fscanf(stdin, format, &t)
		theorems = append(theorems, t)
	}
	// load wakes
	for i := 0; i < n; i++ {
		var s int
		format := "%d"
		if i == n-1 {
			format = "%d\n"
		}
		fmt.Fscanf(stdin, format, &s)
		wakes = append(wakes, s)
	}
	// count number of theorems without wake up mischa
	// construct prefix sum, for calculating segment sum
	numTheorem := 0
	prefixSum := make([]int, n)
	for i := 0; i < n; i++ {
		// add previous result
		if i > 0 {
			prefixSum[i] += prefixSum[i-1]
		}
		if wakes[i] == 0 {
			prefixSum[i] += theorems[i]
		} else {
			numTheorem += theorems[i]
		}
	}
	// get max value of theorem number while using the technique
	// use prefix sum to calculate it
	maxSegmentTheorem := 0
	for i := 0; i <= n-k; i++ {
		tmpTheorem := prefixSum[i+k-1]
		if i > 0 {
			tmpTheorem -= prefixSum[i-1]
		}
		if tmpTheorem > maxSegmentTheorem {
			maxSegmentTheorem = tmpTheorem
		}
	}
	fmt.Println(numTheorem + maxSegmentTheorem)
}

package main

/*
	To maximize the number of theorem written by Mishka, we need to maximize the effect of
	secret technique by executing it at the right time.

	So the formula for getting the maximum number of theorem is:
	number of theorem written when woke up + max effect of secret technique

	The challenge here is in the implementation of searching the maximum effect of secret technique.
	If we use normal search which uses double loop, we will get TLE (Time Limit Exceeded) error,
	because the complexity will become O(n^2).

	Thus we need faster method which is prefixed sum: https://www.youtube.com/watch?v=wGtO8pFo-cs. With
	this algorithm we could solve this problem with O(n).

	Using prefixed sum, we could calculate the number of effect resulted from secret technique in [i, i+k-1]
	with following formula:

	sumSecretTech(i, k) = {
		if i > 0: prefixedSum[i+k-1] - prefixedSum[i-1],
		if i == 0: prefixedSum[i+k-1]
	}

	If you find it difficult to grasp the idea of this formula, try to visualize it with example. Basically this
	formula is my mathematical representation for that visualization.
*/

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

func main() {
	var n, k int
	stdin := bufio.NewReader(os.Stdin)
	fmt.Fscanf(stdin, "%d %d\n", &n, &k)
	theorems := make([]int, 0, n)
	wakes := make([]int, 0, n)
	// load theorems
	for i := 0; i < n; i++ {
		var t int
		format := "%d"
		if i == n-1 {
			format = "%d\n"
		}
		fmt.Fscanf(stdin, format, &t)
		theorems = append(theorems, t)
	}
	// load wakes
	for i := 0; i < n; i++ {
		var s int
		format := "%d"
		if i == n-1 {
			format = "%d\n"
		}
		fmt.Fscanf(stdin, format, &s)
		wakes = append(wakes, s)
	}
	// calculate prefix sum & number of theorems will be written
	// by Mishka initially
	numTheorem := 0
	prefixSum := make([]int, n)
	for i := 0; i < n; i++ {
		// add previous result to prefix sum
		if i > 0 {
			prefixSum[i] += prefixSum[i-1]
		}
		// only calculate the effect of technique in prefixed sum
		if wakes[i] == 0 {
			prefixSum[i] += theorems[i]
			continue
		}
		// count number of theorems will be written initially
		numTheorem += theorems[i]
	}
	// calculate the maximum effect of secret technique
	maxTechEffect := 0
	for i := 0; i <= n-k; i++ {
		techEffect := prefixSum[i+k-1]
		if i > 0 {
			techEffect -= prefixSum[i-1]
		}
		if techEffect > maxTechEffect {
			maxTechEffect = techEffect
		}
	}
	fmt.Println(numTheorem + maxTechEffect)
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}
func scanf(f string, a ...interface{}) {
    fmt.Fscanf(reader, f, a...)
}

func main() {
    defer writer.Flush()

    var n, k int
    scanf("%d%d\n", &n, &k)
    var a [100000]int
    var t [100000]int
    var s int = 0
    for i := 0; i < n; i++ {
        scanf("%d", &a[i]);
    }
    scanf("\n");
    for i := 0; i < n; i++ {
        scanf("%d", &t[i]);
        if t[i] == 1 {
            s += a[i];
        }
    }
    for i := 0; i < k; i++ {
        if t[i] == 0 {
            s += a[i];
        }
    }
    var ans int = s
    for i := k; i < n; i++ {
        if t[i-k] == 0 {
            s -= a[i-k]
        }
        if t[i] == 0 {
            s += a[i]
        }
        if ans < s {
            ans = s
        }
    }
    printf("%d\n", ans)
}

package main

// #include <stdio.h>
//
// void scan(long *a) {
//	   scanf("%ld", a);
// }
import "C"

import (
	"fmt"
)

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

	return y
}

func main() {
	var n, k int
	var a [100002]int
	var t [100002]int

	var cint C.long

	fmt.Scanf("%d %d\n", &n, &k)

	for i := 1; i <= n; i++ {
		C.scan(&cint)
		a[i] = int(cint)
	}

	m := 0
	for i := 1; i <= n; i++ {
		C.scan(&cint)
		t[i] = int(cint)
		if t[i] > 0 {
			m += a[i]
		}
	}

	s := 0
	for i := 1; i <= k; i++ {
		if t[i] == 0 {
			s += a[i]
		}
	}

	temp := s
	for i := k + 1; i <= n; i++ {
		if t[i-k] == 0 {
			s -= a[i-k]
		}
		if t[i] == 0 {
			s += a[i]
		}

		temp = max_int(temp, s)
	}

	fmt.Println(m + temp)
}

package main

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

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

	return y
}

func main() {
	var n, k int
	var a [100002]int
	var t [100002]int
	var reader *bufio.Reader = bufio.NewReader(os.Stdin)

	fmt.Fscanf(reader, "%d %d\n", &n, &k)

	for i := 1; i < n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
	}

	fmt.Fscanf(reader, "%d\n", &a[n])

	m := 0
	for i := 1; i <= n; i++ {
		fmt.Fscanf(reader, "%d", &t[i])
		if t[i] > 0 {
			m += a[i]
		}
	}

	s := 0
	for i := 1; i <= k; i++ {
		if t[i] == 0 {
			s += a[i]
		}
	}

	temp := s
	for i := k + 1; i <= n; i++ {
		if t[i-k] == 0 {
			s -= a[i-k]
		}

		if t[i] == 0 {
			s += a[i]
		}

		temp = max_int(temp, s)
	}

	fmt.Println(m + temp)
}

package main

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

type scanner struct {
	*bufio.Scanner
}

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

func main() {
	in := &scanner{bufio.NewScanner(os.Stdin)}
	in.Split(bufio.ScanWords)

	n, k := in.nextInt(), in.nextInt()

	var a, t []int
	a = make([]int, n+1)
	t = make([]int, n+1)
	for i := 1; i <= n; i++ {
		a[i] = in.nextInt()
	}
	fmt.Scanln()
	var sum int
	for i := 1; i <= n; i++ {
		t[i] = in.nextInt()
		if t[i] > 0 {
			sum += a[i]
		}
	}
	var base, awake int
	var ans int
	for i := 1; i <= n; i++ {
		awake += a[i]
		if t[i] > 0 {
			base += a[i]
		}
		if i < k {
			continue
		}
		if t := sum - base + awake; t > ans {
			ans = t
		}
		j := i - k + 1
		awake -= a[j]
		if t[j] > 0 {
			base -= a[j]
		}
	}
	fmt.Println(ans)
}

package main

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

type scanner struct {
	*bufio.Scanner
}

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

func main() {
	in := &scanner{bufio.NewScanner(os.Stdin)}
	in.Split(bufio.ScanWords)

	n, k := in.nextInt(), in.nextInt()

	var a, t []int
	a = make([]int, n+10)
	t = make([]int, n+10)
	for i := 1; i <= n; i++ {
		a[i] = in.nextInt()
	}
	fmt.Scanln()
	var sum int
	for i := 1; i <= n; i++ {
		t[i] = in.nextInt()
		if t[i] > 0 {
			sum += a[i]
		}
	}
	var base, awake int
	var ans int
	for i := 1; i <= n+1; i++ {
		awake += a[i]
		if t[i] > 0 {
			base += a[i]
		}
		if i < k {
			continue
		}
		j := i - k
		awake -= a[j]
		if t[j] > 0 {
			base -= a[j]
		}
		if t := sum - base + awake; t > ans {
			ans = t
		}
	}
	fmt.Println(ans)
}

package main

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

type scanner struct {
	*bufio.Scanner
}

func (s *scanner) nextInt() int64 {
	s.Scan()
	v, _ := strconv.ParseInt(s.Text(), 10, 64)
	return v
}

func main() {
	in := &scanner{bufio.NewScanner(os.Stdin)}
	in.Split(bufio.ScanWords)

	n, k := in.nextInt(), in.nextInt()

	var a, t []int64
	a = make([]int64, n+10)
	t = make([]int64, n+10)
	for i := int64(1); i <= n; i++ {
		a[i] = in.nextInt()
	}
	fmt.Scanln()
	var sum int64
	for i := int64(1); i <= n; i++ {
		t[i] = in.nextInt()
		if t[i] > 0 {
			sum += a[i]
		}
	}
	var base, awake int64
	var ans int64
	for i := int64(1); i <= n+1; i++ {
		awake += a[i]
		if t[i] > 0 {
			base += a[i]
		}
		if i < k {
			continue
		}
		j := i - k
		awake -= a[j]
		if t[j] > 0 {
			base -= a[j]
		}
		if v := sum - base + awake; v > ans {
			ans = v
		}
	}
	fmt.Println(ans)
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}
func scanf(f string, a ...interface{}) {
    fmt.Fscanf(reader, f, a...)
}

func main() {
    defer writer.Flush()

    var n, k int
    scanf("%d%d ", &n, &k)
    var a [100000]int
    var t [100000]int
    var s int = 0
    for i := 0; i < n; i++ {
        scanf("%d ", &a[i]);
    }
    for i := 0; i < n; i++ {
        scanf("%d ", &t[i]);
        if t[i] == 1 {
            s += a[i];
        }
    }
    for i := 0; i < k; i++ {
        if t[i] == 0 {
            s += a[i];
        }
    }
    var ans int = s
    for i := k; i < n; i++ {
        if t[i-k] == 0 {
            s -= a[i-k]
        }
        if t[i] == 0 {
            s += a[i]
        }
        if ans < s {
            ans = s
        }
    }
    printf("%d\n", ans)
}

package main

import (
	"fmt"
)

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

	return y
}

func main() {
	var n, k int
	var a [100002]int
	var t [100002]int

	fmt.Scanf("%d %d\n", &n, &k)

	fmt.Println(n, k) //
	for i := 1; i <= n; i++ {
		fmt.Scanf("%d", &a[i])

		fmt.Print(a[i], " ") //
	}

	fmt.Println()
	for i := 1; i <= n; i++ {
		fmt.Scanf("%d", &t[i])
		fmt.Print(t[i], " ") //
	}
	fmt.Println()

	s := 0
	for i := 1; i <= k; i++ {
		if t[i] == 0 {
			s += a[i]
		}
	}

	m := s
	for i := k + 1; i <= n; i++ {
		if t[i-k] == 0 {
			s -= a[i-k]
		}

		if t[i] == 0 {
			s += a[i]
		}

		m = max_int(m, s)
	}

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

	fmt.Println(m)
}

package main

import (
	"fmt"
)

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

	return y
}

func main() {
	var n, k int
	var a [100002]int
	var t [100002]int

	fmt.Scanf("%d %d\n", &n, &k)

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

	for i := 1; i <= n; i++ {
		fmt.Scanf("%d", &t[i])
	}

	s := 0
	for i := 1; i <= k; i++ {
		if t[i] == 0 {
			s += a[i]
		}
	}

	m := s
	for i := k + 1; i <= n; i++ {
		if t[i-k] == 0 {
			s -= a[i-k]
		}

		if t[i] == 0 {
			s += a[i]
		}

		m = max_int(m, s)
	}

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

	fmt.Println(m)
}


This is an interactive problem. Remember to flush your output while communicating with the testing program. You may use fflush(stdout) in C++, system.out.flush() in Java, stdout.flush() in Python or flush(output) in Pascal to flush the output. If you use some other programming language, consult its documentation. You may also refer to the guide on interactive problems: https://codeforces.com/blog/entry/45307.The jury picked an integer $$$x$$$ not less than $$$0$$$ and not greater than $$$2^{14} - 1$$$. You have to guess this integer.To do so, you may ask no more than $$$2$$$ queries. Each query should consist of $$$100$$$ integer numbers $$$a_1$$$, $$$a_2$$$, ..., $$$a_{100}$$$ (each integer should be not less than $$$0$$$ and not greater than $$$2^{14} - 1$$$). In response to your query, the jury will pick one integer $$$i$$$ ($$$1 \le i \le 100$$$) and tell you the value of $$$a_i \oplus x$$$ (the bitwise XOR of $$$a_i$$$ and $$$x$$$). There is an additional constraint on the queries: all $$$200$$$ integers you use in the queries should be distinct.It is guaranteed that the value of $$$x$$$ is fixed beforehand in each test, but the choice of $$$i$$$ in every query may depend on the integers you send.

To give the answer, your program should print one line $$$!$$$ $$$x$$$ with a line break in the end. After that, it should flush the output and terminate gracefully.

NoteThe example of interaction is not correct — you should sumbit exactly $$$100$$$ integers in each query. Everything else is correct.Hacks are forbidden in this problem.

package main

import (
	. "fmt"
)

// github.com/EndlessCheng/codeforces-go
func CF1207E() {
	a := [2]int{0, 7}
	for i := range a {
		Print("? ")
		for j := 1; j <= 100; j++ {
			Print(" ", j<<a[i])
		}
		Println()
		Scan(&a[i])
	}
	Println("!", a[0]>>7<<7|a[1]&(1<<7-1))
}

func main() { CF1207E() }

package main

import (
	. "fmt"
)

// github.com/EndlessCheng/codeforces-go
func CF1207E() {
	a := [2]int{0, 7}
	for i := range a {
		Print("? ")
		for j := 1; j <= 100; j++ {
			Print(" ", j<<a[i])
		}
		Println()
		Scan(&a[i])
	}
	Println("!", a[0]&(1<<14-1<<7)|a[1]&(1<<7-1))
}

func main() { CF1207E() }

package main

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

const N = 100

func write(a string) {
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()

	f.Write([]byte(a))
	f.Write([]byte("\n"))
}

func gen() [N]uint64 {
	res := [N]uint64{}
	for i := uint64(1); i <= N; i++ {
		res[i-1] = i
	}

	return res
}

func join(a [N]uint64) string {
	s := fmt.Sprint(a)
	s = s[1 : len(s)-1]

	return s
}

func main() {
	ans := [2]uint64{}

	for j := 0; j < 2; j++ {
		sample := gen()

		for i, n := range sample {
			if j == 1 {
				sample[i] = n << 7
			}
		}

		q := "? " + join(sample)
		write(q)

		fmt.Scan(&ans[j])
	}

	res := (ans[0]>>7)<<7 + ans[1]&127
	fmt.Println("!", res)
}

package main

import (
	. "fmt"
)

// github.com/EndlessCheng/codeforces-go
func CF1207E() {
	a := [2]int{0, 7}
	for i := range a {
		Print("? ")
		for j := 0; j < 100; j++ {
			Print(" ", j<<a[i])
		}
		Println()
		Scan(&a[i])
	}
	Println("!", a[0]&(1<<14-1<<7)|a[1]&(1<<7-1))
}

func main() { CF1207E() }

package main

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

const N = 200

func write(a string) {
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()

	f.Write([]byte(a))
	f.Write([]byte("\n"))
}

func gen() [N]uint64 {
	res := [N]uint64{}
	for i := uint64(1); i <= N; i++ {
		res[i-1] = i
	}

	return res
}

func join(a [N]uint64) string {
	s := fmt.Sprint(a)
	s = s[1 : len(s)-1]

	return s
}

func main() {
	ans := [2]uint64{}

	for j := 0; j < 2; j++ {
		sample := gen()

		for i, n := range sample {
			if j == 1 {
				sample[i] = n << 7
			}
		}

		q := "? " + join(sample)
		write(q)

		fmt.Scan(&ans[j])
	}

	res := (ans[0]>>7)<<7 + ans[1]&127
	fmt.Println(res)
}

package main

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

const N = 200

func write(a string) {
	f := bufio.NewWriter(os.Stdout)
	defer f.Flush()

	f.Write([]byte(a))
	f.Write([]byte("\n"))
}

func gen() [N]uint64 {
	res := [N]uint64{}
	for i := uint64(1); i <= N; i++ {
		res[i-1] = i
	}

	return res
}

func join(a [N]uint64) string {
	s := fmt.Sprint(a)
	s = s[1 : len(s)-1]

	return s
}

func main() {
	ans := [2]uint64{}

	for j := 0; j < 2; j++ {
		sample := gen()

		for i, n := range sample {
			if j == 1 {
				sample[i] = n << 7
			}
		}

		q := "? " + join(sample)
		write(q)

		fmt.Scan(&ans[j])
	}

	res := (ans[0]>>7)<<7 + ans[1]&127
	fmt.Println("!", res)
}


Sasha has an array of integers a1, a2, ..., an. You have to perform m queries. There might be queries of two types:  1 l r x — increase all integers on the segment from l to r by values x;  2 l r — find , where f(x) is the x-th Fibonacci number. As this number may be large, you only have to find it modulo 109 + 7. In this problem we define Fibonacci numbers as follows: f(1) = 1, f(2) = 1, f(x) = f(x - 1) + f(x - 2) for all x > 2.Sasha is a very talented boy and he managed to perform all queries in five seconds. Will you be able to write the program that performs as well as Sasha?

The first line of the input contains two integers n and m (1 ≤ n ≤ 100 000, 1 ≤ m ≤ 100 000) — the number of elements in the array and the number of queries respectively. The next line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109). Then follow m lines with queries descriptions. Each of them contains integers tpi, li, ri and may be xi (1 ≤ tpi ≤ 2, 1 ≤ li ≤ ri ≤ n, 1 ≤ xi ≤ 109). Here tpi = 1 corresponds to the queries of the first type and tpi corresponds to the queries of the second type. It's guaranteed that the input will contains at least one query of the second type.

For each query of the second type print the answer modulo 109 + 7.

NoteInitially, array a is equal to 1, 1, 2, 1, 1.The answer for the first query of the second type is f(1) + f(1) + f(2) + f(1) + f(1) = 1 + 1 + 1 + 1 + 1 = 5. After the query 1 2 4 2 array a is equal to 1, 3, 4, 3, 1.The answer for the second query of the second type is f(3) + f(4) + f(3) = 2 + 3 + 2 = 7.The answer for the third query of the second type is f(1) + f(3) + f(4) + f(3) + f(1) = 1 + 2 + 3 + 2 + 1 = 9.

package main

import "bufio"
import "os"
import "io/ioutil"
import "strconv"

const mod = 1000000007

type Matrix struct {
	x, y, z, t int
}

func zeroMatrix() Matrix {
	return Matrix{
		x: 0, y: 0,
		z: 0, t: 0,
	}
}

func fibMatrix() Matrix {
	return Matrix{
		x: 0, y: 1,
		z: 1, t: 1,
	}
}

func oneMatrix() Matrix {
	return Matrix{
		x: 1, y: 0,
		z: 0, t: 1,
	}
}

func add(x int, y int) int {
	return (x + y) % mod
}

func mul(x int, y int) int {
	if (x <= 44000) && (y <= 44000) {
		return x * y % mod
	}
	return int((int64(x) * int64(y)) % int64(mod))
}

func (a Matrix) add(b Matrix) Matrix {
	return Matrix{
		x: add(a.x, b.x), y: add(a.y, b.y),
		z: add(a.z, b.z), t: add(a.t, b.t),
	}
}

func (a Matrix) mul(b Matrix) Matrix {
	return Matrix{
		x: add(mul(a.x, b.x), mul(a.y, b.z)), y: add(mul(a.x, b.y), mul(a.y, b.t)),
		z: add(mul(a.z, b.x), mul(a.t, b.z)), t: add(mul(a.z, b.y), mul(a.t, b.t)),
	}
}

func (a Matrix) pow(n int) Matrix {
	ret := oneMatrix()
	for n > 0 {
		if (n & 1) == 1 {
			ret = ret.mul(a)
		}
		a = a.mul(a)
		n >>= 1
	}
	return ret
}

type SegmentTree struct {
	from  int
	to    int
	value Matrix
	total Matrix
	left  *SegmentTree
	right *SegmentTree
}

func createSegmentTree(f int, t int) *SegmentTree {
	var left *SegmentTree
	var right *SegmentTree
	total := oneMatrix()
	if f < t {
		m := (f + t) >> 1
		left = createSegmentTree(f, m)
		right = createSegmentTree(m+1, t)
		total = left.total.add(right.total)
	}
	return &SegmentTree{
		from:  f,
		to:    t,
		value: oneMatrix(),
		left:  left,
		right: right,
		total: total,
	}
}

func (tree *SegmentTree) lazyUpdate() {
	tree.left.value = tree.left.value.mul(tree.value)
	tree.left.total = tree.left.total.mul(tree.value)
	tree.right.value = tree.right.value.mul(tree.value)
	tree.right.total = tree.right.total.mul(tree.value)
	tree.value = oneMatrix()
}

func (tree *SegmentTree) multiply(l int, r int, k Matrix) {
	if (tree.from > r) || (tree.to < l) {
		return
	}
	if (tree.from >= l) && (tree.to <= r) {
		tree.value = tree.value.mul(k)
		tree.total = tree.total.mul(k)
		return
	}
	tree.lazyUpdate()
	tree.left.multiply(l, r, k)
	tree.right.multiply(l, r, k)
	tree.total = tree.left.total.add(tree.right.total)
}

func (tree *SegmentTree) sum(l int, r int) Matrix {
	if (tree.from > r) || (tree.to < l) {
		return zeroMatrix()
	}
	if (tree.from >= l) && (tree.to <= r) {
		return tree.total
	}
	tree.lazyUpdate()
	leftSum := tree.left.sum(l, r)
	rightSum := tree.right.sum(l, r)
	return leftSum.add(rightSum)
}

func main() {
	defer out.Flush()

	var n, q, a int
	readInt(&n)
	readInt(&q)

	tree := createSegmentTree(0, n-1)
	fib := fibMatrix()

	for i := 0; i < n; i++ {
		readInt(&a)
		tree.multiply(i, i, fib.pow(a+1))
	}

	var t, l, r, x int
	for i := 0; i < q; i++ {
		readInt(&t)
		readInt(&l)
		readInt(&r)
		l--
		r--
		if t == 1 {
			readInt(&x)
			tree.multiply(l, r, fib.pow(x))
		} else {
			ret := tree.sum(l, r)
			writeInt(ret.x)
			writeByte('\n')
		}
	}
}

// Input output
var out *bufio.Writer
var iPointer int
var nPointer int
var iBuffer []byte

func init() {
	out = bufio.NewWriter(os.Stdout)
	iPointer = 0
	iBuffer, _ = ioutil.ReadAll(os.Stdin)
	nPointer = len(iBuffer)
}

func isDigit(c byte) bool {
	return (c >= '0') && (c <= '9')
}

func readInt(v *int) bool {
	neg := false
	for (iPointer < nPointer) && !isDigit(iBuffer[iPointer]) {
		neg = (iBuffer[iPointer] == '-')
		iPointer++
	}
	if iPointer >= nPointer {
		return false
	}
	var a int
	for (iPointer < nPointer) && isDigit(iBuffer[iPointer]) {
		a = a*10 + int(iBuffer[iPointer]-'0')
		iPointer++
	}
	if neg {
		*v = -a
	} else {
		*v = a
	}
	return true
}

func writeByte(v byte) {
	out.WriteByte(v)
}

func writeInt(v int) {
	out.WriteString(strconv.Itoa(v))
}

package main

import "bufio"
import "os"
import "io/ioutil"
import "strconv"

const mod = 1000000007

type Matrix struct {
	x, y, z, t int
}

func zeroMatrix() Matrix {
	return Matrix{
		x: 0, y: 0,
		z: 0, t: 0,
	}
}

func fibMatrix() Matrix {
	return Matrix{
		x: 0, y: 1,
		z: 1, t: 1,
	}
}

func oneMatrix() Matrix {
	return Matrix{
		x: 1, y: 0,
		z: 0, t: 1,
	}
}

func add(x int, y int) int {
	return (x + y) % mod
}

func mul(x int, y int) int {
	return int((int64(x) * int64(y)) % int64(mod))
}

func (a Matrix) add(b Matrix) Matrix {
	return Matrix{
		x: add(a.x, b.x), y: add(a.y, b.y),
		z: add(a.z, b.z), t: add(a.t, b.t),
	}
}

func (a Matrix) mul(b Matrix) Matrix {
	return Matrix{
		x: add(mul(a.x, b.x), mul(a.y, b.z)), y: add(mul(a.x, b.y), mul(a.y, b.t)),
		z: add(mul(a.z, b.x), mul(a.t, b.z)), t: add(mul(a.z, b.y), mul(a.t, b.t)),
	}
}

func (a Matrix) pow(n int) Matrix {
	ret := oneMatrix()
	for n > 0 {
		if (n & 1) == 1 {
			ret = ret.mul(a)
		}
		a = a.mul(a)
		n >>= 1
	}
	return ret
}

type SegmentTree struct {
	from  int
	to    int
	value Matrix
	total Matrix
	left  *SegmentTree
	right *SegmentTree
}

func createSegmentTree(f int, t int) *SegmentTree {
	var left *SegmentTree
	var right *SegmentTree
	total := oneMatrix()
	if f < t {
		m := (f + t) >> 1
		left = createSegmentTree(f, m)
		right = createSegmentTree(m+1, t)
		total = left.total.add(right.total)
	}
	return &SegmentTree{
		from:  f,
		to:    t,
		value: oneMatrix(),
		left:  left,
		right: right,
		total: total,
	}
}

func (tree *SegmentTree) lazyUpdate() {
	tree.left.value = tree.left.value.mul(tree.value)
	tree.left.total = tree.left.total.mul(tree.value)
	tree.right.value = tree.right.value.mul(tree.value)
	tree.right.total = tree.right.total.mul(tree.value)
	tree.value = oneMatrix()
}

func (tree *SegmentTree) multiply(l int, r int, k Matrix) {
	if (tree.from > r) || (tree.to < l) {
		return
	}
	if (tree.from >= l) && (tree.to <= r) {
		tree.value = tree.value.mul(k)
		tree.total = tree.total.mul(k)
		return
	}
	tree.lazyUpdate()
	tree.left.multiply(l, r, k)
	tree.right.multiply(l, r, k)
	tree.total = tree.left.total.add(tree.right.total)
}

func (tree *SegmentTree) sum(l int, r int) Matrix {
	if (tree.from > r) || (tree.to < l) {
		return zeroMatrix()
	}
	if (tree.from >= l) && (tree.to <= r) {
		return tree.total
	}
	tree.lazyUpdate()
	leftSum := tree.left.sum(l, r)
	rightSum := tree.right.sum(l, r)
	return leftSum.add(rightSum)
}

func main() {
	defer out.Flush()

	var n, q, a int
	readInt(&n)
	readInt(&q)

	tree := createSegmentTree(0, n-1)
	fib := fibMatrix()

	for i := 0; i < n; i++ {
		readInt(&a)
		tree.multiply(i, i, fib.pow(a+1))
	}

	var t, l, r, x int
	for i := 0; i < q; i++ {
		readInt(&t)
		readInt(&l)
		readInt(&r)
		l--
		r--
		if t == 1 {
			readInt(&x)
			tree.multiply(l, r, fib.pow(x))
		} else {
			ret := tree.sum(l, r)
			writeInt(ret.x)
			writeByte('\n')
		}
	}
}

// Input output
var out *bufio.Writer
var iPointer int
var nPointer int
var iBuffer []byte

func init() {
	out = bufio.NewWriter(os.Stdout)
	iPointer = 0
	iBuffer, _ = ioutil.ReadAll(os.Stdin)
	nPointer = len(iBuffer)
}

func isDigit(c byte) bool {
	return (c >= '0') && (c <= '9')
}

func readInt(v *int) bool {
	neg := false
	for (iPointer < nPointer) && !isDigit(iBuffer[iPointer]) {
		neg = (iBuffer[iPointer] == '-')
		iPointer++
	}
	if iPointer >= nPointer {
		return false
	}
	var a int
	for (iPointer < nPointer) && isDigit(iBuffer[iPointer]) {
		a = a*10 + int(iBuffer[iPointer]-'0')
		iPointer++
	}
	if neg {
		*v = -a
	} else {
		*v = a
	}
	return true
}

func writeByte(v byte) {
	out.WriteByte(v)
}

func writeInt(v int) {
	out.WriteString(strconv.Itoa(v))
}


This is an interactive problem.Vladik has favorite game, in which he plays all his free time.Game field could be represented as n × m matrix which consists of cells of three types:   «.» — normal cell, player can visit it.  «F» — finish cell, player has to finish his way there to win. There is exactly one cell of this type.  «*» — dangerous cell, if player comes to this cell, he loses. Initially player is located in the left top cell with coordinates (1, 1). Player has access to 4 buttons "U", "D", "L", "R", each of them move player up, down, left and right directions respectively.But it’s not that easy! Sometimes friends play game and change functions of buttons. Function of buttons "L" and "R" could have been swapped, also functions of buttons "U" and "D" could have been swapped. Note that functions of buttons can be changed only at the beginning of the game.Help Vladik win the game!

First line contains two space-separated integers n and m (1 ≤ n, m ≤ 100) — number of rows and columns respectively. Each of next n lines contains m characters describing corresponding row of field. Set of characters in field is described above. Guaranteed that cell with coordinates (1, 1) is normal and there is at least one way from initial cell to finish cell without dangerous cells.

NoteIn first test case all four directions swapped with their opposite directions. Protocol of interaction In more convenient form:This test could be presenter for hack in following way: 4 3 1 1...**.F*....

package main

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

func solve(s string) string {
	return s
}

func output(i int, ans string) {
	fmt.Printf("Case #%d: %s\n", i, ans)
}

type coord struct {
	x int
	y int
}

type path []string

var moves = []coord{coord{1, 0}, coord{-1, 0}, coord{0, 1}, coord{0, -1}}
var moveStr = []string{"R", "L", "D", "U"}

func findRoute(board [][]int, current coord) string {
	visit := map[coord]string{}
	visit[current] = ""
	cpos := []coord{current}
	for true {
		//fmt.Println(visit)
		npos := []coord{}
		for _, v := range cpos {
			sv := visit[v]
			for i, m := range moves {
				np := v
				np.x += m.x
				np.y += m.y
				_, ok := visit[np]
				if ok == true {
					continue
				}
				if np.x < 0 || np.x >= (len(board)) {
					continue
				}
				if np.y < 0 || np.y >= (len(board[0])) {
					continue
				}
				if board[np.x][np.y] < 0 {
					continue
				} else if board[np.x][np.y] > 0 {
					return sv + moveStr[i]
				}
				npos = append(npos, np)
				visit[np] = sv + moveStr[i]
			}
		}
		cpos = npos
	}
	return ""
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 1000000), 1000000)

	scanner.Scan()
	size := strings.Split(scanner.Text(), " ")
	height, _ := strconv.Atoi(size[0])
	width, _ := strconv.Atoi(size[1])

	board := make([][]int, width)
	for i := 0; i < width; i++ {
		board[i] = make([]int, height)
	}
	for y := 0; y < height; y++ {
		scanner.Scan()
		for x, v := range scanner.Text() {
			switch v {
			case '.':
				board[x][y] = 0
			case 'F':
				board[x][y] = 1
			case '*':
				board[x][y] = -1
			}
		}
	}
	expectedX := 0
	expectedY := 0

	x := 0
	y := 0
	first := true
	route := findRoute(board, coord{x, y})
	for true {
		if first {
			first = false
		} else {
			scanner.Scan()
			coord := strings.Split(scanner.Text(), " ")
			//	fmt.Println(coord)
			x, _ = strconv.Atoi(coord[0])
			y, _ = strconv.Atoi(coord[1])
			x -= 1
			y -= 1
			x, y = y, x
		}
		if expectedX != x {
			moveStr[1], moveStr[0] = moveStr[0], moveStr[1]
			route = findRoute(board, coord{x, y})
			//	fmt.Println("SWAPX", x, expectedX)
			expectedX = x
		}
		if expectedY != y {
			moveStr[2], moveStr[3] = moveStr[3], moveStr[2]
			route = findRoute(board, coord{x, y})
			//	fmt.Println("SWAPY", y, expectedY)
			expectedY = y
		}
		if board[x][y] > 0 {
			return
		}
		//fmt.Println(route, x, y)

		n := route[0]
		route = route[1:]
		fmt.Println(string(n))
		for i := range moves {
			if moveStr[i] == string(n) {
				expectedX += moves[i].x
				expectedY += moves[i].y
			}
		}
	}
}

package main

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

func solve(s string) string {
	return s
}

func output(i int, ans string) {
	fmt.Printf("Case #%d: %s\n", i, ans)
}

type coord struct {
	x int
	y int
}

type path []string

var moves = []coord{coord{1, 0}, coord{-1, 0}, coord{0, 1}, coord{0, -1}}
var moveStr = []string{"R", "L", "D", "U"}

func findRoute(board [][]int, current coord) string {
	visit := map[coord]string{}
	visit[current] = ""
	cpos := []coord{current}
	for true {
		//fmt.Println(visit)
		npos := []coord{}
		for _, v := range cpos {
			sv := visit[v]
			for i, m := range moves {
				np := v
				np.x += m.x
				np.y += m.y
				_, ok := visit[np]
				if ok == true {
					continue
				}
				if np.x < 0 || np.x >= (len(board)) {
					continue
				}
				if np.y < 0 || np.y >= (len(board[0])) {
					continue
				}
				if board[np.x][np.y] < 0 {
					continue
				} else if board[np.x][np.y] > 0 {
					return sv + moveStr[i]
				}
				npos = append(npos, np)
				visit[np] = sv + moveStr[i]
			}
		}
		cpos = npos
	}
	return ""
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 1000000), 1000000)

	scanner.Scan()
	size := strings.Split(scanner.Text(), " ")
	height, _ := strconv.Atoi(size[0])
	width, _ := strconv.Atoi(size[1])

	board := make([][]int, width)
	for i := 0; i < width; i++ {
		board[i] = make([]int, height)
	}
	for y := 0; y < height; y++ {
		scanner.Scan()
		for x, v := range scanner.Text() {
			switch v {
			case '.':
				board[x][y] = 0
			case 'F':
				board[x][y] = 1
			case '*':
				board[x][y] = -1
			}
		}
	}
	expectedX := 0
	expectedY := 0

	x := 0
	y := 0
	first := true
	route := findRoute(board, coord{x, y})

	for true {

		if len(route) == 0 {
			break
		}
		if first {
			first = false
		} else {
			scanner.Scan()
			coord := strings.Split(scanner.Text(), " ")
			//	fmt.Println(coord)
			x, _ = strconv.Atoi(coord[0])
			y, _ = strconv.Atoi(coord[1])
			x -= 1
			y -= 1
			x, y = y, x
		}
		if expectedX != x {
			moveStr[1], moveStr[0] = moveStr[0], moveStr[1]
			route = findRoute(board, coord{x, y})
			//	fmt.Println("SWAPX", x, expectedX)
			expectedX = x
		}
		if expectedY != y {
			moveStr[2], moveStr[3] = moveStr[3], moveStr[2]
			route = findRoute(board, coord{x, y})
			//	fmt.Println("SWAPY", y, expectedY)
			expectedY = y
		}
		//fmt.Println(route, x, y)

		n := route[0]
		route = route[1:]
		fmt.Println(string(n))
		for i := range moves {
			if moveStr[i] == string(n) {
				expectedX += moves[i].x
				expectedY += moves[i].y
			}
		}
	}
}


Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d.Note that the order of the points inside the group of three chosen points doesn't matter.

The first line contains two integers: n and d (1 ≤ n ≤ 105; 1 ≤ d ≤ 109). The next line contains n integers x1, x2, ..., xn, their absolute value doesn't exceed 109 — the x-coordinates of the points that Petya has got. It is guaranteed that the coordinates of the points in the input strictly increase.

Print a single integer — the number of groups of three points, where the distance between two farthest points doesn't exceed d. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

NoteIn the first sample any group of three points meets our conditions.In the seconds sample only 2 groups of three points meet our conditions: {-3, -2, -1} and {-2, -1, 0}.In the third sample only one group does: {1, 10, 20}.

package main

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

func main(){
	var n, d int64
	var a [100010]int64
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	n, _ = strconv.ParseInt(r.Text(), 0, 64)
	r.Scan()
	d, _ = strconv.ParseInt(r.Text(), 0, 64)
	for i:=0; int64(i)<n; i++ {
		r.Scan()
		a[i], _ = strconv.ParseInt(r.Text(), 0, 64)
	}
	var count, p1, p2 int64 = 0, 0, 0
	for p2 < n {
		if a[p2]-a[p1] <= d {
			count += (p2-p1) * (p2-p1-1)/2
			p2 += 1
		} else {
			p1 += 1
		}
	}
	w.WriteString(strconv.FormatInt(count, 10)+"\n")
	w.Flush()
}

package main

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

func main() {
    var n,d,i,j,ans int64
    var arr [100005]int64
    fmt.Scan(&n,&d)
    input := bufio.NewScanner(os.Stdin)
    input.Split(bufio.ScanWords)
    for i=0;i<n;i++ {
    	input.Scan()
    	aa,_:=strconv.ParseInt(input.Text(),0,64)
    	arr[i]=aa
    	//fmt.Scan(&arr[i])
    }
    ans=0
    j=0
    for i=0;i<n;i++ {
    	for ;arr[j]-arr[i]<=d && j<n; {
    		j++
    	}
    	ans+=(j-i-1)*(j-i-2)/2
    }
    fmt.Println(ans)
}

//http://codeforces.com/problemset/problem/251/A
//A. Points on Line
// ha a ket kozelebbi eseten se haladja meg az erdekesebb

package main

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

func Bin2(n int32) int64 {
	return (int64(n) * int64((n - 1))) / 2
}

func main() {
	var (
		x          []int32
		n, d, i, j int32
		ans        int64
		in         *bufio.Reader
	)

	in = bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n)
	if n < 3 {
		goto OK
	}

	fmt.Fscan(in, &d)
	x = make([]int32, n, n)

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

	for j = 2; j < n && x[j]-x[0] <= d; j++ {
		ans += Bin2(j)
	}

	i = 0
	for j < n {
		for ; i < j && (x[j]-x[i] > d); i++ {
		}
		for ; j < n && x[j]-x[i] <= d; j++ {
			ans += Bin2(j - i)
		}
	}
OK:
	fmt.Println(ans)
}

package main

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

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

    ScanInts := func(a... *int64) {
        for i := 0; i < len(a); i++ {
            scanner.Scan()
            *(a[i]), _ = strconv.ParseInt(scanner.Text(),10,64)
        }
    }

    BinSearch := func(v int64, a []int64) int64 {
        l, r := int64(0), int64(len(a))
        for r-l > 1 {
            m := (l+r)/2
            if a[m] <= v { l = m } else { r = m }
        }
        return l
    }

    Comb2 := func(a int64) int64 {
        return (a*(a-1))/2
    }

    var n,d int64
    ScanInts(&n,&d)
    a := make([]int64,n)
    for i := int64(0); i < n; i++ {
        ScanInts(&a[i])
    }

    ans := int64(0)
    for l := int64(0); l <= (n-3); l++ {
        r := BinSearch(d+a[l],a)
        if r-l > 1 { ans += Comb2(r-l) }
    }
    fmt.Println(ans)
}

// 251A-mic
package main

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

func main() {
	var n, d, x, i, hasil, a int64
	var data [100005]int64
	z := bufio.NewReader(os.Stdin)
	fmt.Scan(&n, &d)
	for i = 0; i < n; i++ {
		fmt.Fscan(z, &data[i])
	}
	for i = 0; i < n; i++ {
		for data[x+1]-data[i] <= d && x < n-1 {
			x++
		}
		if data[x]-data[i] <= d {
			a = x - i
			a *= (a - 1)
			a /= 2
			hasil += a
		} else if x == n-2 {
			break
		}
	}
	fmt.Println(hasil)
}

package main

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

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	n, d := scanInt(scanner), scanInt(scanner)
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = scanInt(scanner)
	}
	total := int64(0)
	for i := 2; i < n; i++ {
		threshold := arr[i]-d
		low, high := 0, i
		for low != high {
			mid := (low+high)/2
			if arr[mid] < threshold {
				low = mid+1
			} else {
				high = mid
			}
		}
		x := int64(i-low-1)
		total += (x+1)*x/2
	}
	writer.WriteString(fmt.Sprintf("%d\n", total))
}

package main

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

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	n, d := scanInt(scanner), scanInt(scanner)
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = scanInt(scanner)
	}
	total := int64(0)
	left := 0
	for right := 2; right < n; right++ {
		for arr[left]+d < arr[right] {
			left++
		}
		x := int64(right-left-1)
		total += (x+1)*x/2
	}
	writer.WriteString(fmt.Sprintf("%d\n", total))
}

//http://codeforces.com/problemset/problem/251/A
//A. Points on Line
// ha a ket kozelebbi eseten se haladja meg az erdekesebb

package main

import (
	"fmt"
)

func Bin2(n int32) int32 {
	return (n * (n - 1)) / 2
}

func main() {
	var (
		x               []int32
		n, d, i, j, ans int32
	)

	fmt.Scan(&n)
	if n < 3 {
		goto OK
	}

	fmt.Scan(&d)
	x = make([]int32, n, n)

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

	for j = 2; j < n && x[j]-x[0] <= d; j++ {
		ans += Bin2(j)
	}

	i = 0
	for j < n {
		for ; i < j && (x[j]-x[i] > d); i++ {
		}
		for ; j < n && x[j]-x[i] <= d; j++ {
			ans += Bin2(j - i)
		}
	}
OK:
	fmt.Println(ans)
}

package main

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

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

    ScanInts := func(a... *int64) {
        for i := 0; i < len(a); i++ {
            scanner.Scan()
            *(a[i]), _ = strconv.ParseInt(scanner.Text(),10,64)
        }
    }

    Comb2 := func(a int64) int64 {
        return (a*(a-1))/2
    }

    var n,d int64
    ScanInts(&n,&d)
    a := make([]int64,n)
    for i := int64(0); i < n; i++ {
        ScanInts(&a[i])
    }

    ans, l, r := int64(0), int64(0), int64(n-1)
    for l < r {
        if a[r]-a[l] <= d {
            ans += Comb2(r-l)
            l++
            r = int64(n-1)
        } else {
            r--
        }
    }
    fmt.Println(ans)
}

package main

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

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	n, d := scanInt(scanner), scanInt(scanner)
	arr := make([]int, n)
	for i := 0; i < n; i++ {
		arr[i] = scanInt(scanner)
	}
	total := int64(0)
	left := 0
	for right := 2; right < n; right++ {
		for arr[left]+d < arr[right] {
			left++
		}
		x := int64(left-right-1)
		total += (x+1)*x/2
	}
	writer.WriteString(fmt.Sprintf("%d\n", total))
}