package main

import (
	"os"
	"io/ioutil"
)

var (
	iptr int = 0
	ibuf []byte
)

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

func IsDigit(b byte) bool {
	return '0' <= b && b <= '9'
}

func ReadWord() string {
	for ; iptr < len(ibuf) && IsSpace(ibuf[iptr]); iptr++ {
	}
	buf := make([]byte, 0)
	for ; iptr < len(ibuf) && IsSpace(ibuf[iptr]); iptr++ {
		buf = append(buf, ibuf[iptr])
	}
	return string(buf)
}

func ReadInt() int {
	for ; iptr < len(ibuf) && !IsDigit(ibuf[iptr]) && ibuf[iptr] != '-'; iptr++ {
	}
	s := 1
	if ibuf[iptr] == '-' {
		s = -1
		iptr++
	}

	d := 0
	for ; iptr < len(ibuf) && IsDigit(ibuf[iptr]); iptr++ {
		d = 10 * d + int(ibuf[iptr] - '0')
	}
	return s * d
}

func ReadInt64() int64 {
	for ; iptr < len(ibuf) && !IsDigit(ibuf[iptr]) && ibuf[iptr] != '-'; iptr++ {
	}
	s := int64(1)
	if ibuf[iptr] == '-' {
		s = int64(-1)
		iptr++
	}
	d := int64(0)
	for ; iptr < len(ibuf) && IsDigit(ibuf[iptr]); iptr++ {
		d = int64(10) * d + int64(ibuf[iptr] - '0')
	}
	return s * d
}

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

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

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

func LowerBound(a []int64, x int64) int {
	ub, lb := len(a), 0
	for ub - lb > 1 {
		mid := (ub + lb) / 2
		if a[mid] < x {
			lb = mid
		} else {
			ub = mid
		}
	}
	return ub
}

func UpperBound(a []int64, x int64) int {
	ub, lb := len(a), 0
	for ub - lb > 1 {
		mid := (ub + lb) / 2
		if a[mid] > x {
			ub = mid
		} else {
			lb = mid
		}
	}
	return ub
}

type Container []int64

func (a Container) Len() int {
	return len(a)
}

func (a Container) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

func init() {
	ibuf, _ = ioutil.ReadAll(os.Stdin)
}

type Q3 struct {
	Id, Who int
}

type Msg struct {
	From int
	Time int
	Dests []Q3
}

type Edge struct {
	To, Time int
}

type Graph [][]Edge
type Tree struct {
	N int
	Par []Edge
	Ch Graph
}

type LCA struct {
	Tree
	log_n uint
	depth []int
	dub [][]Edge
}

func NewTree(n int) Tree {
	t := Tree{n, make([]Edge, n), make(Graph, n)}
	for v := 0; v < n; v++ {
		t.Par[v] = Edge{v, 0}
	}
	return t
}

func (t Tree) AddPar(v int, e Edge) {
	if t.Par[v].To != v {
		panic("parent exists")
	}
	t.Par[v] = e
	t.Ch[e.To] = append(t.Ch[e.To], Edge{v, e.Time})
}

func (t Tree) AllDepth() []int {
	par, ch := t.Par, t.Ch
	depth := make([]int, len(ch))
	var dfs func(v, p, d int)
	dfs = func(v, p, d int) {
		depth[v] = d
		for _, e := range ch[v] {
			if (e.To != p) {
				dfs(e.To, v, d + 1)
			}
		}
	}
	for v, p := range par {
		if p.To == v {
			dfs(v, -1, 0)
		}
	}
	return depth
}

func NewLCA(t Tree) LCA {
	lca := LCA{t, 1, nil, nil}
	lca.depth = t.AllDepth()
	lca.log_n = 1
	for (1 << uint(lca.log_n)) < t.N {
		lca.log_n++
	}
	lca.dub = make([][]Edge, lca.log_n)
	lca.dub[0] = t.Par
	for i := uint(1); i < lca.log_n; i++ {
		lca.dub[i] = make([]Edge, t.N)
		for v := 0; v < t.N; v++ {
			e1 := lca.dub[i - 1][v]
			e2 := lca.dub[i - 1][e1.To]
			lca.dub[i][v] = Edge{e2.To, Max(e1.Time, e2.Time)}
		}
	}
	return lca
}

func (lca LCA) IsParAt(v, p, time int) bool {
	if lca.depth[v] < lca.depth[p] {
		return false
	}
	d := lca.depth[v] - lca.depth[p]
	for k := int(lca.log_n) - 1; k >= 0; k-- {
		if (d & (1 << uint(k))) != 0 {
			if lca.dub[k][v].Time > time {
				return false
			}
			v = lca.dub[k][v].To
		}
	}
	return v == p
}

var (
	n, m int
	t Tree
	msgs []Msg
)

func main() {
	n, m := ReadInt(), ReadInt()
	t := NewTree(n)
	msgs := make([]Msg, 0)
	k := 0
	for i := 0; i < m; i++ {
		c := ReadInt()
		switch c {
		case 1:
			u, v := ReadInt() - 1, ReadInt() - 1
			t.AddPar(u, Edge{v, i})
		case 2:
			v := ReadInt() - 1
			msgs = append(msgs, Msg{v, i, nil})
		case 3:
			v, i := ReadInt() - 1, ReadInt() - 1
			msgs[i].Dests = append(msgs[i].Dests, Q3{k, v})
			k++
		default:
			panic("invalid query")
		}
	}
	ans := make([][]byte, k)
	lca := NewLCA(t)
	for _, msg := range msgs {
		for _, q := range msg.Dests {
			b := lca.IsParAt(msg.From, q.Who, msg.Time)
			if b {
				ans[q.Id] = append(ans[q.Id], "YES"...)
			} else {
				ans[q.Id] = append(ans[q.Id], "NO"...)
			}
		}
	}
	buf := make([]byte, 0, 5 * k)
	for _, a := range ans {
		buf = append(buf, a...)
		buf = append(buf, '\n')
	}
	os.Stdout.Write(buf)
}

package main

import (
	"os"
	"io/ioutil"
	"fmt"
)

var (
	iptr int = 0
	ibuf []byte
)

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

func IsDigit(b byte) bool {
	return '0' <= b && b <= '9'
}

func ReadWord() string {
	for ; iptr < len(ibuf) && IsSpace(ibuf[iptr]); iptr++ {
	}
	buf := make([]byte, 0)
	for ; iptr < len(ibuf) && IsSpace(ibuf[iptr]); iptr++ {
		buf = append(buf, ibuf[iptr])
	}
	return string(buf)
}

func ReadInt() int {
	for ; iptr < len(ibuf) && !IsDigit(ibuf[iptr]) && ibuf[iptr] != '-'; iptr++ {
	}
	s := 1
	if ibuf[iptr] == '-' {
		s = -1
		iptr++
	}

	d := 0
	for ; iptr < len(ibuf) && IsDigit(ibuf[iptr]); iptr++ {
		d = 10 * d + int(ibuf[iptr] - '0')
	}
	return s * d
}

func ReadInt64() int64 {
	for ; iptr < len(ibuf) && !IsDigit(ibuf[iptr]) && ibuf[iptr] != '-'; iptr++ {
	}
	s := int64(1)
	if ibuf[iptr] == '-' {
		s = int64(-1)
		iptr++
	}
	d := int64(0)
	for ; iptr < len(ibuf) && IsDigit(ibuf[iptr]); iptr++ {
		d = int64(10) * d + int64(ibuf[iptr] - '0')
	}
	return s * d
}

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

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

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

func LowerBound(a []int64, x int64) int {
	ub, lb := len(a), 0
	for ub - lb > 1 {
		mid := (ub + lb) / 2
		if a[mid] < x {
			lb = mid
		} else {
			ub = mid
		}
	}
	return ub
}

func UpperBound(a []int64, x int64) int {
	ub, lb := len(a), 0
	for ub - lb > 1 {
		mid := (ub + lb) / 2
		if a[mid] > x {
			ub = mid
		} else {
			lb = mid
		}
	}
	return ub
}

type Container []int64

func (a Container) Len() int {
	return len(a)
}

func (a Container) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

func init() {
	ibuf, _ = ioutil.ReadAll(os.Stdin)
}

type Q3 struct {
	Id, Who int
}

type Msg struct {
	From int
	Time int
	Dests []Q3
}

type Edge struct {
	To, Time int
}

type Graph [][]Edge
type Tree struct {
	N int
	Par []Edge
	Ch Graph
}

type LCA struct {
	Tree
	log_n uint
	depth []int
	dub [][]Edge
}

func NewTree(n int) Tree {
	t := Tree{n, make([]Edge, n), make(Graph, n)}
	for v := 0; v < n; v++ {
		t.Par[v] = Edge{v, 0}
	}
	return t
}

func (t Tree) AddPar(v int, e Edge) {
	if t.Par[v].To != v {
		panic("parent exists")
	}
	t.Par[v] = e
	t.Ch[e.To] = append(t.Ch[e.To], Edge{v, e.Time})
}

func (t Tree) AllDepth() []int {
	par, ch := t.Par, t.Ch
	depth := make([]int, len(ch))
	var dfs func(v, p, d int)
	dfs = func(v, p, d int) {
		depth[v] = d
		for _, e := range ch[v] {
			if (e.To != p) {
				dfs(e.To, v, d + 1)
			}
		}
	}
	for v, p := range par {
		if p.To == v {
			dfs(v, -1, 0)
		}
	}
	return depth
}

func NewLCA(t Tree) LCA {
	lca := LCA{t, 1, nil, nil}
	lca.depth = t.AllDepth()
	lca.log_n = 1
	for (1 << uint(lca.log_n)) < t.N {
		lca.log_n++
	}
	lca.dub = make([][]Edge, lca.log_n)
	lca.dub[0] = t.Par
	for i := uint(1); i < lca.log_n; i++ {
		lca.dub[i] = make([]Edge, t.N)
		for v := 0; v < t.N; v++ {
			e1 := lca.dub[i - 1][v]
			e2 := lca.dub[i - 1][e1.To]
			lca.dub[i][v] = Edge{e2.To, Max(e1.Time, e2.Time)}
		}
	}
	return lca
}

func (lca LCA) IsParAt(v, p, time int) bool {
	if lca.depth[v] < lca.depth[p] {
		return false
	}
	d := lca.depth[v] - lca.depth[p]
	for k := int(lca.log_n) - 1; k >= 0; k-- {
		if (d & (1 << uint(k))) != 0 {
			if lca.dub[k][v].Time > time {
				return false
			}
			v = lca.dub[k][v].To
		}
	}
	return v == p
}

var (
	n, m int
	t Tree
	msgs []Msg
)

func main() {
	n, m := ReadInt(), ReadInt()
	t := NewTree(n)
	msgs := make([]Msg, 0)
	k := 0
	for i := 0; i < m; i++ {
		c := ReadInt()
		switch c {
		case 1:
			u, v := ReadInt() - 1, ReadInt() - 1
			t.AddPar(u, Edge{v, i})
		case 2:
			v := ReadInt() - 1
			msgs = append(msgs, Msg{v, i, nil})
		case 3:
			v, i := ReadInt() - 1, ReadInt() - 1
			msgs[i].Dests = append(msgs[i].Dests, Q3{k, v})
			k++
		default:
			panic("invalid query")
		}
	}
	ans := make([][]byte, k)
	lca := NewLCA(t)
	for _, msg := range msgs {
		for _, q := range msg.Dests {
			b := lca.IsParAt(msg.From, q.Who, msg.Time)
			if b {
				ans[q.Id] = append(ans[q.Id], "YES"...)
			} else {
				ans[q.Id] = append(ans[q.Id], "NO"...)
			}
		}
	}
	for _, a := range ans {
		fmt.Println(string(a))
	}
}

package main

import (
	"os"
	"io/ioutil"
)

var (
	iptr int = 0
	ibuf []byte
)

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

func IsDigit(b byte) bool {
	return '0' <= b && b <= '9'
}

func ReadWord() string {
	for ; iptr < len(ibuf) && IsSpace(ibuf[iptr]); iptr++ {
	}
	buf := make([]byte, 0)
	for ; iptr < len(ibuf) && IsSpace(ibuf[iptr]); iptr++ {
		buf = append(buf, ibuf[iptr])
	}
	return string(buf)
}

func ReadInt() int {
	for ; iptr < len(ibuf) && !IsDigit(ibuf[iptr]) && ibuf[iptr] != '-'; iptr++ {
	}
	s := 1
	if ibuf[iptr] == '-' {
		s = -1
		iptr++
	}

	d := 0
	for ; iptr < len(ibuf) && IsDigit(ibuf[iptr]); iptr++ {
		d = 10 * d + int(ibuf[iptr] - '0')
	}
	return s * d
}

func ReadInt64() int64 {
	for ; iptr < len(ibuf) && !IsDigit(ibuf[iptr]) && ibuf[iptr] != '-'; iptr++ {
	}
	s := int64(1)
	if ibuf[iptr] == '-' {
		s = int64(-1)
		iptr++
	}
	d := int64(0)
	for ; iptr < len(ibuf) && IsDigit(ibuf[iptr]); iptr++ {
		d = int64(10) * d + int64(ibuf[iptr] - '0')
	}
	return s * d
}

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

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

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

func LowerBound(a []int64, x int64) int {
	ub, lb := len(a), 0
	for ub - lb > 1 {
		mid := (ub + lb) / 2
		if a[mid] < x {
			lb = mid
		} else {
			ub = mid
		}
	}
	return ub
}

func UpperBound(a []int64, x int64) int {
	ub, lb := len(a), 0
	for ub - lb > 1 {
		mid := (ub + lb) / 2
		if a[mid] > x {
			ub = mid
		} else {
			lb = mid
		}
	}
	return ub
}

type Container []int64

func (a Container) Len() int {
	return len(a)
}

func (a Container) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

func init() {
	ibuf, _ = ioutil.ReadAll(os.Stdin)
}

type Q3 struct {
	Id, Who int
}

type Msg struct {
	From int
	Time int
	Dests []Q3
}

type Edge struct {
	To, Time int
}

type Graph [][]Edge
type Tree struct {
	N int
	Par []Edge
	Ch Graph
}

type LCA struct {
	Tree
	log_n uint
	depth []int
	dub [][]Edge
}

func NewTree(n int) Tree {
	t := Tree{n, make([]Edge, n), make(Graph, n)}
	for v := 0; v < n; v++ {
		t.Par[v] = Edge{v, 0}
	}
	return t
}

func (t Tree) AddPar(v int, e Edge) {
	if t.Par[v].To != v {
		panic("parent exists")
	}
	t.Par[v] = e
	t.Ch[e.To] = append(t.Ch[e.To], Edge{v, e.Time})
}

func (t Tree) AllDepth() []int {
	par, ch := t.Par, t.Ch
	depth := make([]int, len(ch))
	var dfs func(v, p, d int)
	dfs = func(v, p, d int) {
		depth[v] = d
		for _, e := range ch[v] {
			if (e.To != p) {
				dfs(e.To, v, d + 1)
			}
		}
	}
	for v, p := range par {
		if p.To == v {
			dfs(v, -1, 0)
		}
	}
	return depth
}

func NewLCA(t Tree) LCA {
	lca := LCA{t, 1, nil, nil}
	lca.depth = t.AllDepth()
	lca.log_n = 1
	for (1 << uint(lca.log_n)) < t.N {
		lca.log_n++
	}
	lca.dub = make([][]Edge, lca.log_n)
	lca.dub[0] = t.Par
	for i := uint(1); i < lca.log_n; i++ {
		lca.dub[i] = make([]Edge, t.N)
		for v := 0; v < t.N; v++ {
			e1 := lca.dub[i - 1][v]
			e2 := lca.dub[i - 1][e1.To]
			lca.dub[i][v] = Edge{e2.To, Max(e1.Time, e2.Time)}
		}
	}
	return lca
}

func (lca LCA) IsParAt(v, p, time int) bool {
	if lca.depth[v] < lca.depth[p] {
		return false
	}
	d := lca.depth[v] - lca.depth[p]
	for k := int(lca.log_n) - 1; k >= 0; k-- {
		if (d & (1 << uint(k))) != 0 {
			if lca.dub[k][v].Time > time {
				return false
			}
			v = lca.dub[k][v].To
		}
	}
	return v == p
}

var (
	n, m int
	t Tree
	msgs []Msg
)

func main() {
	n, m := ReadInt(), ReadInt()
	t := NewTree(n)
	msgs := make([]Msg, 0)
	k := 0
	for i := 0; i < m; i++ {
		c := ReadInt()
		switch c {
		case 1:
			u, v := ReadInt() - 1, ReadInt() - 1
			t.AddPar(u, Edge{v, i})
		case 2:
			v := ReadInt() - 1
			msgs = append(msgs, Msg{v, i, nil})
		case 3:
			v, i := ReadInt() - 1, ReadInt() - 1
			msgs[i].Dests = append(msgs[i].Dests, Q3{k, v})
			k++
		default:
			panic("invalid query")
		}
	}
	ans := make([][]byte, k)
	lca := NewLCA(t)
	for _, msg := range msgs {
		for _, q := range msg.Dests {
			b := lca.IsParAt(msg.From, q.Who, msg.Time)
			if b {
				ans[q.Id] = append(ans[q.Id], "YES"...)
			} else {
				ans[q.Id] = append(ans[q.Id], "NO"...)
			}
		}
	}
	buf := make([]byte, 5 * k)
	for _, a := range ans {
		buf = append(buf, a...)
		buf = append(buf, "\r\n"...)
	}
	os.Stdout.Write(buf)
	os.Stdout.Sync()
}

package main

import (
	"os"
	"io/ioutil"
)

var (
	iptr int = 0
	ibuf []byte
)

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

func IsDigit(b byte) bool {
	return '0' <= b && b <= '9'
}

func ReadWord() string {
	for ; iptr < len(ibuf) && IsSpace(ibuf[iptr]); iptr++ {
	}
	buf := make([]byte, 0)
	for ; iptr < len(ibuf) && IsSpace(ibuf[iptr]); iptr++ {
		buf = append(buf, ibuf[iptr])
	}
	return string(buf)
}

func ReadInt() int {
	for ; iptr < len(ibuf) && !IsDigit(ibuf[iptr]) && ibuf[iptr] != '-'; iptr++ {
	}
	s := 1
	if ibuf[iptr] == '-' {
		s = -1
		iptr++
	}

	d := 0
	for ; iptr < len(ibuf) && IsDigit(ibuf[iptr]); iptr++ {
		d = 10 * d + int(ibuf[iptr] - '0')
	}
	return s * d
}

func ReadInt64() int64 {
	for ; iptr < len(ibuf) && !IsDigit(ibuf[iptr]) && ibuf[iptr] != '-'; iptr++ {
	}
	s := int64(1)
	if ibuf[iptr] == '-' {
		s = int64(-1)
		iptr++
	}
	d := int64(0)
	for ; iptr < len(ibuf) && IsDigit(ibuf[iptr]); iptr++ {
		d = int64(10) * d + int64(ibuf[iptr] - '0')
	}
	return s * d
}

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

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

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

func LowerBound(a []int64, x int64) int {
	ub, lb := len(a), 0
	for ub - lb > 1 {
		mid := (ub + lb) / 2
		if a[mid] < x {
			lb = mid
		} else {
			ub = mid
		}
	}
	return ub
}

func UpperBound(a []int64, x int64) int {
	ub, lb := len(a), 0
	for ub - lb > 1 {
		mid := (ub + lb) / 2
		if a[mid] > x {
			ub = mid
		} else {
			lb = mid
		}
	}
	return ub
}

type Container []int64

func (a Container) Len() int {
	return len(a)
}

func (a Container) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

func init() {
	ibuf, _ = ioutil.ReadAll(os.Stdin)
}

type Q3 struct {
	Id, Who int
}

type Msg struct {
	From int
	Time int
	Dests []Q3
}

type Edge struct {
	To, Time int
}

type Graph [][]Edge
type Tree struct {
	N int
	Par []Edge
	Ch Graph
}

type LCA struct {
	Tree
	log_n uint
	depth []int
	dub [][]Edge
}

func NewTree(n int) Tree {
	t := Tree{n, make([]Edge, n), make(Graph, n)}
	for v := 0; v < n; v++ {
		t.Par[v] = Edge{v, 0}
	}
	return t
}

func (t Tree) AddPar(v int, e Edge) {
	if t.Par[v].To != v {
		panic("parent exists")
	}
	t.Par[v] = e
	t.Ch[e.To] = append(t.Ch[e.To], Edge{v, e.Time})
}

func (t Tree) AllDepth() []int {
	par, ch := t.Par, t.Ch
	depth := make([]int, len(ch))
	var dfs func(v, p, d int)
	dfs = func(v, p, d int) {
		depth[v] = d
		for _, e := range ch[v] {
			if (e.To != p) {
				dfs(e.To, v, d + 1)
			}
		}
	}
	for v, p := range par {
		if p.To == v {
			dfs(v, -1, 0)
		}
	}
	return depth
}

func NewLCA(t Tree) LCA {
	lca := LCA{t, 1, nil, nil}
	lca.depth = t.AllDepth()
	lca.log_n = 1
	for (1 << uint(lca.log_n)) < t.N {
		lca.log_n++
	}
	lca.dub = make([][]Edge, lca.log_n)
	lca.dub[0] = t.Par
	for i := uint(1); i < lca.log_n; i++ {
		lca.dub[i] = make([]Edge, t.N)
		for v := 0; v < t.N; v++ {
			e1 := lca.dub[i - 1][v]
			e2 := lca.dub[i - 1][e1.To]
			lca.dub[i][v] = Edge{e2.To, Max(e1.Time, e2.Time)}
		}
	}
	return lca
}

func (lca LCA) IsParAt(v, p, time int) bool {
	if lca.depth[v] < lca.depth[p] {
		return false
	}
	d := lca.depth[v] - lca.depth[p]
	for k := int(lca.log_n) - 1; k >= 0; k-- {
		if (d & (1 << uint(k))) != 0 {
			if lca.dub[k][v].Time > time {
				return false
			}
			v = lca.dub[k][v].To
		}
	}
	return v == p
}

var (
	n, m int
	t Tree
	msgs []Msg
)

func main() {
	n, m := ReadInt(), ReadInt()
	t := NewTree(n)
	msgs := make([]Msg, 0)
	k := 0
	for i := 0; i < m; i++ {
		c := ReadInt()
		switch c {
		case 1:
			u, v := ReadInt() - 1, ReadInt() - 1
			t.AddPar(u, Edge{v, i})
		case 2:
			v := ReadInt() - 1
			msgs = append(msgs, Msg{v, i, nil})
		case 3:
			v, i := ReadInt() - 1, ReadInt() - 1
			msgs[i].Dests = append(msgs[i].Dests, Q3{k, v})
			k++
		default:
			panic("invalid query")
		}
	}
	ans := make([][]byte, k)
	lca := NewLCA(t)
	for _, msg := range msgs {
		for _, q := range msg.Dests {
			b := lca.IsParAt(msg.From, q.Who, msg.Time)
			if b {
				ans[q.Id] = append(ans[q.Id], "YES"...)
			} else {
				ans[q.Id] = append(ans[q.Id], "NO"...)
			}
		}
	}
	buf := make([]byte, k * 4)
	for _, a := range ans {
		buf = append(buf, a...)
		buf = append(buf, '\n')
	}
	os.Stdout.Write(buf)
}

package main

import (
	"os"
	"io/ioutil"
)

var (
	iptr int = 0
	ibuf []byte
)

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

func IsDigit(b byte) bool {
	return '0' <= b && b <= '9'
}

func ReadWord() string {
	for ; iptr < len(ibuf) && IsSpace(ibuf[iptr]); iptr++ {
	}
	buf := make([]byte, 0)
	for ; iptr < len(ibuf) && IsSpace(ibuf[iptr]); iptr++ {
		buf = append(buf, ibuf[iptr])
	}
	return string(buf)
}

func ReadInt() int {
	for ; iptr < len(ibuf) && !IsDigit(ibuf[iptr]) && ibuf[iptr] != '-'; iptr++ {
	}
	s := 1
	if ibuf[iptr] == '-' {
		s = -1
		iptr++
	}

	d := 0
	for ; iptr < len(ibuf) && IsDigit(ibuf[iptr]); iptr++ {
		d = 10 * d + int(ibuf[iptr] - '0')
	}
	return s * d
}

func ReadInt64() int64 {
	for ; iptr < len(ibuf) && !IsDigit(ibuf[iptr]) && ibuf[iptr] != '-'; iptr++ {
	}
	s := int64(1)
	if ibuf[iptr] == '-' {
		s = int64(-1)
		iptr++
	}
	d := int64(0)
	for ; iptr < len(ibuf) && IsDigit(ibuf[iptr]); iptr++ {
		d = int64(10) * d + int64(ibuf[iptr] - '0')
	}
	return s * d
}

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

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

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

func LowerBound(a []int64, x int64) int {
	ub, lb := len(a), 0
	for ub - lb > 1 {
		mid := (ub + lb) / 2
		if a[mid] < x {
			lb = mid
		} else {
			ub = mid
		}
	}
	return ub
}

func UpperBound(a []int64, x int64) int {
	ub, lb := len(a), 0
	for ub - lb > 1 {
		mid := (ub + lb) / 2
		if a[mid] > x {
			ub = mid
		} else {
			lb = mid
		}
	}
	return ub
}

type Container []int64

func (a Container) Len() int {
	return len(a)
}

func (a Container) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

func init() {
	ibuf, _ = ioutil.ReadAll(os.Stdin)
}

type Q3 struct {
	Id, Who int
}

type Msg struct {
	From int
	Time int
	Dests []Q3
}

type Edge struct {
	To, Time int
}

type Graph [][]Edge
type Tree struct {
	N int
	Par []Edge
	Ch Graph
}

type LCA struct {
	Tree
	log_n uint
	depth []int
	dub [][]Edge
}

func NewTree(n int) Tree {
	t := Tree{n, make([]Edge, n), make(Graph, n)}
	for v := 0; v < n; v++ {
		t.Par[v] = Edge{v, 0}
	}
	return t
}

func (t Tree) AddPar(v int, e Edge) {
	if t.Par[v].To != v {
		panic("parent exists")
	}
	t.Par[v] = e
	t.Ch[e.To] = append(t.Ch[e.To], Edge{v, e.Time})
}

func (t Tree) AllDepth() []int {
	par, ch := t.Par, t.Ch
	depth := make([]int, len(ch))
	var dfs func(v, p, d int)
	dfs = func(v, p, d int) {
		depth[v] = d
		for _, e := range ch[v] {
			if (e.To != p) {
				dfs(e.To, v, d + 1)
			}
		}
	}
	for v, p := range par {
		if p.To == v {
			dfs(v, -1, 0)
		}
	}
	return depth
}

func NewLCA(t Tree) LCA {
	lca := LCA{t, 1, nil, nil}
	lca.depth = t.AllDepth()
	lca.log_n = 1
	for (1 << uint(lca.log_n)) < t.N {
		lca.log_n++
	}
	lca.dub = make([][]Edge, lca.log_n)
	lca.dub[0] = t.Par
	for i := uint(1); i < lca.log_n; i++ {
		lca.dub[i] = make([]Edge, t.N)
		for v := 0; v < t.N; v++ {
			e1 := lca.dub[i - 1][v]
			e2 := lca.dub[i - 1][e1.To]
			lca.dub[i][v] = Edge{e2.To, Max(e1.Time, e2.Time)}
		}
	}
	return lca
}

func (lca LCA) IsParAt(v, p, time int) bool {
	if lca.depth[v] < lca.depth[p] {
		return false
	}
	d := lca.depth[v] - lca.depth[p]
	for k := int(lca.log_n) - 1; k >= 0; k-- {
		if (d & (1 << uint(k))) != 0 {
			if lca.dub[k][v].Time > time {
				return false
			}
			v = lca.dub[k][v].To
		}
	}
	return v == p
}

var (
	n, m int
	t Tree
	msgs []Msg
)

func main() {
	n, m := ReadInt(), ReadInt()
	t := NewTree(n)
	msgs := make([]Msg, 0)
	k := 0
	for i := 0; i < m; i++ {
		c := ReadInt()
		switch c {
		case 1:
			u, v := ReadInt() - 1, ReadInt() - 1
			t.AddPar(u, Edge{v, i})
		case 2:
			v := ReadInt() - 1
			msgs = append(msgs, Msg{v, i, nil})
		case 3:
			v, i := ReadInt() - 1, ReadInt() - 1
			msgs[i].Dests = append(msgs[i].Dests, Q3{k, v})
			k++
		default:
			panic("invalid query")
		}
	}
	ans := make([][]byte, k)
	lca := NewLCA(t)
	for _, msg := range msgs {
		for _, q := range msg.Dests {
			b := lca.IsParAt(msg.From, q.Who, msg.Time)
			if b {
				ans[q.Id] = append(ans[q.Id], "YES"...)
			} else {
				ans[q.Id] = append(ans[q.Id], "NO"...)
			}
		}
	}
	buf := make([]byte, k * 4)
	for _, a := range ans {
		buf = append(buf, a...)
		buf = append(buf, "\n\r"...)
	}
	os.Stdout.Write(buf)
}

package main

import (
	"os"
	"io/ioutil"
)

var (
	iptr int = 0
	ibuf []byte
)

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

func IsDigit(b byte) bool {
	return '0' <= b && b <= '9'
}

func ReadWord() string {
	for ; iptr < len(ibuf) && IsSpace(ibuf[iptr]); iptr++ {
	}
	buf := make([]byte, 0)
	for ; iptr < len(ibuf) && IsSpace(ibuf[iptr]); iptr++ {
		buf = append(buf, ibuf[iptr])
	}
	return string(buf)
}

func ReadInt() int {
	for ; iptr < len(ibuf) && !IsDigit(ibuf[iptr]) && ibuf[iptr] != '-'; iptr++ {
	}
	s := 1
	if ibuf[iptr] == '-' {
		s = -1
		iptr++
	}

	d := 0
	for ; iptr < len(ibuf) && IsDigit(ibuf[iptr]); iptr++ {
		d = 10 * d + int(ibuf[iptr] - '0')
	}
	return s * d
}

func ReadInt64() int64 {
	for ; iptr < len(ibuf) && !IsDigit(ibuf[iptr]) && ibuf[iptr] != '-'; iptr++ {
	}
	s := int64(1)
	if ibuf[iptr] == '-' {
		s = int64(-1)
		iptr++
	}
	d := int64(0)
	for ; iptr < len(ibuf) && IsDigit(ibuf[iptr]); iptr++ {
		d = int64(10) * d + int64(ibuf[iptr] - '0')
	}
	return s * d
}

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

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

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

func LowerBound(a []int64, x int64) int {
	ub, lb := len(a), 0
	for ub - lb > 1 {
		mid := (ub + lb) / 2
		if a[mid] < x {
			lb = mid
		} else {
			ub = mid
		}
	}
	return ub
}

func UpperBound(a []int64, x int64) int {
	ub, lb := len(a), 0
	for ub - lb > 1 {
		mid := (ub + lb) / 2
		if a[mid] > x {
			ub = mid
		} else {
			lb = mid
		}
	}
	return ub
}

type Container []int64

func (a Container) Len() int {
	return len(a)
}

func (a Container) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

func init() {
	ibuf, _ = ioutil.ReadAll(os.Stdin)
}

type Q3 struct {
	Id, Who int
}

type Msg struct {
	From int
	Time int
	Dests []Q3
}

type Edge struct {
	To, Time int
}

type Graph [][]Edge
type Tree struct {
	N int
	Par []Edge
	Ch Graph
}

type LCA struct {
	Tree
	log_n uint
	depth []int
	dub [][]Edge
}

func NewTree(n int) Tree {
	t := Tree{n, make([]Edge, n), make(Graph, n)}
	for v := 0; v < n; v++ {
		t.Par[v] = Edge{v, 0}
	}
	return t
}

func (t Tree) AddPar(v int, e Edge) {
	if t.Par[v].To != v {
		panic("parent exists")
	}
	t.Par[v] = e
	t.Ch[e.To] = append(t.Ch[e.To], Edge{v, e.Time})
}

func (t Tree) AllDepth() []int {
	par, ch := t.Par, t.Ch
	depth := make([]int, len(ch))
	var dfs func(v, p, d int)
	dfs = func(v, p, d int) {
		depth[v] = d
		for _, e := range ch[v] {
			if (e.To != p) {
				dfs(e.To, v, d + 1)
			}
		}
	}
	for v, p := range par {
		if p.To == v {
			dfs(v, -1, 0)
		}
	}
	return depth
}

func NewLCA(t Tree) LCA {
	lca := LCA{t, 1, nil, nil}
	lca.depth = t.AllDepth()
	lca.log_n = 1
	for (1 << uint(lca.log_n)) < t.N {
		lca.log_n++
	}
	lca.dub = make([][]Edge, lca.log_n)
	lca.dub[0] = t.Par
	for i := uint(1); i < lca.log_n; i++ {
		lca.dub[i] = make([]Edge, t.N)
		for v := 0; v < t.N; v++ {
			e1 := lca.dub[i - 1][v]
			e2 := lca.dub[i - 1][e1.To]
			lca.dub[i][v] = Edge{e2.To, Max(e1.Time, e2.Time)}
		}
	}
	return lca
}

func (lca LCA) IsParAt(v, p, time int) bool {
	if lca.depth[v] < lca.depth[p] {
		return false
	}
	d := lca.depth[v] - lca.depth[p]
	for k := int(lca.log_n) - 1; k >= 0; k-- {
		if (d & (1 << uint(k))) != 0 {
			if lca.dub[k][v].Time > time {
				return false
			}
			v = lca.dub[k][v].To
		}
	}
	return v == p
}

var (
	n, m int
	t Tree
	msgs []Msg
)

func main() {
	n, m := ReadInt(), ReadInt()
	t := NewTree(n)
	msgs := make([]Msg, 0)
	k := 0
	for i := 0; i < m; i++ {
		c := ReadInt()
		switch c {
		case 1:
			u, v := ReadInt() - 1, ReadInt() - 1
			t.AddPar(u, Edge{v, i})
		case 2:
			v := ReadInt() - 1
			msgs = append(msgs, Msg{v, i, nil})
		case 3:
			v, i := ReadInt() - 1, ReadInt() - 1
			msgs[i].Dests = append(msgs[i].Dests, Q3{k, v})
			k++
		default:
			panic("invalid query")
		}
	}
	ans := make([][]byte, k)
	lca := NewLCA(t)
	for _, msg := range msgs {
		for _, q := range msg.Dests {
			b := lca.IsParAt(msg.From, q.Who, msg.Time)
			if b {
				ans[q.Id] = append(ans[q.Id], "YES"...)
			} else {
				ans[q.Id] = append(ans[q.Id], "NO"...)
			}
		}
	}
	buf := make([]byte, 5 * k)
	for _, a := range ans {
		buf = append(buf, a...)
		buf = append(buf, "\r\n"...)
	}
	os.Stdout.Write(buf)
	os.Stdout.Close()
}

package main

import (
	"os"
	"io/ioutil"
)

var (
	iptr int = 0
	ibuf []byte
)

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

func IsDigit(b byte) bool {
	return '0' <= b && b <= '9'
}

func ReadWord() string {
	for ; iptr < len(ibuf) && IsSpace(ibuf[iptr]); iptr++ {
	}
	buf := make([]byte, 0)
	for ; iptr < len(ibuf) && IsSpace(ibuf[iptr]); iptr++ {
		buf = append(buf, ibuf[iptr])
	}
	return string(buf)
}

func ReadInt() int {
	for ; iptr < len(ibuf) && !IsDigit(ibuf[iptr]) && ibuf[iptr] != '-'; iptr++ {
	}
	s := 1
	if ibuf[iptr] == '-' {
		s = -1
		iptr++
	}

	d := 0
	for ; iptr < len(ibuf) && IsDigit(ibuf[iptr]); iptr++ {
		d = 10 * d + int(ibuf[iptr] - '0')
	}
	return s * d
}

func ReadInt64() int64 {
	for ; iptr < len(ibuf) && !IsDigit(ibuf[iptr]) && ibuf[iptr] != '-'; iptr++ {
	}
	s := int64(1)
	if ibuf[iptr] == '-' {
		s = int64(-1)
		iptr++
	}
	d := int64(0)
	for ; iptr < len(ibuf) && IsDigit(ibuf[iptr]); iptr++ {
		d = int64(10) * d + int64(ibuf[iptr] - '0')
	}
	return s * d
}

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

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

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

func LowerBound(a []int64, x int64) int {
	ub, lb := len(a), 0
	for ub - lb > 1 {
		mid := (ub + lb) / 2
		if a[mid] < x {
			lb = mid
		} else {
			ub = mid
		}
	}
	return ub
}

func UpperBound(a []int64, x int64) int {
	ub, lb := len(a), 0
	for ub - lb > 1 {
		mid := (ub + lb) / 2
		if a[mid] > x {
			ub = mid
		} else {
			lb = mid
		}
	}
	return ub
}

type Container []int64

func (a Container) Len() int {
	return len(a)
}

func (a Container) Swap(i, j int) {
	a[i], a[j] = a[j], a[i]
}

func init() {
	ibuf, _ = ioutil.ReadAll(os.Stdin)
}

type Q3 struct {
	Id, Who int
}

type Msg struct {
	From int
	Time int
	Dests []Q3
}

type Edge struct {
	To, Time int
}

type Graph [][]Edge
type Tree struct {
	N int
	Par []Edge
	Ch Graph
}

type LCA struct {
	Tree
	log_n uint
	depth []int
	dub [][]Edge
}

func NewTree(n int) Tree {
	t := Tree{n, make([]Edge, n), make(Graph, n)}
	for v := 0; v < n; v++ {
		t.Par[v] = Edge{v, 0}
	}
	return t
}

func (t Tree) AddPar(v int, e Edge) {
	if t.Par[v].To != v {
		panic("parent exists")
	}
	t.Par[v] = e
	t.Ch[e.To] = append(t.Ch[e.To], Edge{v, e.Time})
}

func (t Tree) AllDepth() []int {
	par, ch := t.Par, t.Ch
	depth := make([]int, len(ch))
	var dfs func(v, p, d int)
	dfs = func(v, p, d int) {
		depth[v] = d
		for _, e := range ch[v] {
			if (e.To != p) {
				dfs(e.To, v, d + 1)
			}
		}
	}
	for v, p := range par {
		if p.To == v {
			dfs(v, -1, 0)
		}
	}
	return depth
}

func NewLCA(t Tree) LCA {
	lca := LCA{t, 1, nil, nil}
	lca.depth = t.AllDepth()
	lca.log_n = 1
	for (1 << uint(lca.log_n)) < t.N {
		lca.log_n++
	}
	lca.dub = make([][]Edge, lca.log_n)
	lca.dub[0] = t.Par
	for i := uint(1); i < lca.log_n; i++ {
		lca.dub[i] = make([]Edge, t.N)
		for v := 0; v < t.N; v++ {
			e1 := lca.dub[i - 1][v]
			e2 := lca.dub[i - 1][e1.To]
			lca.dub[i][v] = Edge{e2.To, Max(e1.Time, e2.Time)}
		}
	}
	return lca
}

func (lca LCA) IsParAt(v, p, time int) bool {
	if lca.depth[v] < lca.depth[p] {
		return false
	}
	d := lca.depth[v] - lca.depth[p]
	for k := int(lca.log_n) - 1; k >= 0; k-- {
		if (d & (1 << uint(k))) != 0 {
			if lca.dub[k][v].Time > time {
				return false
			}
			v = lca.dub[k][v].To
		}
	}
	return v == p
}

var (
	n, m int
	t Tree
	msgs []Msg
)

func main() {
	n, m := ReadInt(), ReadInt()
	t := NewTree(n)
	msgs := make([]Msg, 0)
	k := 0
	for i := 0; i < m; i++ {
		c := ReadInt()
		switch c {
		case 1:
			u, v := ReadInt() - 1, ReadInt() - 1
			t.AddPar(u, Edge{v, i})
		case 2:
			v := ReadInt() - 1
			msgs = append(msgs, Msg{v, i, nil})
		case 3:
			v, i := ReadInt() - 1, ReadInt() - 1
			msgs[i].Dests = append(msgs[i].Dests, Q3{k, v})
			k++
		default:
			panic("invalid query")
		}
	}
	ans := make([][]byte, k)
	lca := NewLCA(t)
	for _, msg := range msgs {
		for _, q := range msg.Dests {
			b := lca.IsParAt(msg.From, q.Who, msg.Time)
			if b {
				ans[q.Id] = append(ans[q.Id], "YES"...)
			} else {
				ans[q.Id] = append(ans[q.Id], "NO"...)
			}
		}
	}
	buf := make([]byte, 5 * k)
	for _, a := range ans {
		buf = append(buf, a...)
		buf = append(buf, "\r\n"...)
	}
	os.Stdout.Write(buf)
}


package main

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

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

	solve := func(Case int) {
		var n int
		var w int64
		Fscan(in, &n, &w)
		low := (w + 1) / 2
		a := make([]int,  n)
		//s := int64(0)
		okI := -1
		for i := range a {
			Fscan(in, &a[i])
			v := int64(a[i])
			if low <= v && v <= w {
				okI = i
			}
			//s += v
		}
		if okI != -1 {
			Fprintln(out, 1)
			Fprintln(out, okI+1)
			return
		}
		s := int64(0)
		ans := []int{}
		for i, V := range a {
			v := int64(V)
			if v > w {
				continue
			}
			s+=v
			ans = append(ans, i+1)
			if low <= s && s <= w {
				Fprintln(out, len(ans))
				for _, v := range ans {
					Fprint(out, v, " ")
				}
				Fprintln(out)
				return
			}
		}
		Fprintln(out, -1)
	}

	var t int
	Fscan(in, &t)
	for Case := 1; Case <= t; Case++ {
		solve(Case)
	}
}

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

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
}

func main() {
	defer writer.Flush()
	t := sint64()
	for ; t > 0; t-- {
		n, W := sint64(), sint64()
		w := make([]int64, n)
		for i := range w {
			w[i] = sint64()
		}
		res := sol(w, W)
		if res == nil {
			printf("-1\n")
		} else {
			printf("%d\n", len(res))
			for _, r := range res {
				printf("%d ", r)
			}
			printf("\n")
		}
	}
}

func sol(w []int64, W int64) []int64 {
	res := []int64{}
	currSum := int64(0)
	for i := range w {
		if w[i] > W {
			continue
		}
		if within(w[i], W) {
			return []int64{int64(i+1)}
		}
		currSum += w[i]
		res = append(res, int64(i+1))
		if within(currSum, W) {
			return res
		}
	}
	return nil
}

func within(w, W int64) bool {
	if W&1 == 0 {
		return w >= W/2 && w <= W
	}
	return w >= (W+1)/2 && w <= W
}

package main

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

func main() {
	//rd, _ := os.Open("input")
	//in := bufio.NewReader(rd)
	in := bufio.NewReader(os.Stdin)

	var t, n, W, w int64
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &n, &W)

		m := 0
		currentLoad := int64(0)
		result := make([]int, 0, 1000)
		for i := 0; int64(i) < n; i++ {
			fmt.Fscan(in, &w)
			if currentLoad+w <= W {
				result = append(result, i+1)
				m++
				currentLoad += w
			}
			if w >= (W+1)/2 && w <= W {
				result = []int{i + 1}
				m = 1
				currentLoad = w
			}
			if currentLoad >= (W+1)/2 {
				in.ReadString('\n')
				break
			}
		}
		if currentLoad < (W+1)/2 {
			fmt.Println(-1)
		} else {
			fmt.Println(m)
			for i := range result {
				fmt.Printf("%d ", result[i])
			}
			fmt.Println()
		}
	}
}

package main

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

func main() {
	//rd, _ := os.Open("input")
	//in := bufio.NewReader(rd)
	in := bufio.NewReader(os.Stdin)

	var t, n, W, w int64
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &n, &W)
		m := 0
		currentLoad := int64(0)
		result := ""
		for i := 0; int64(i) < n; i++ {
			fmt.Fscan(in, &w)
			if currentLoad < (W+1)/2 && currentLoad+w <= W {
				result += strconv.Itoa(i+1) + " "
				m++
				currentLoad += w
			}
		}
		if currentLoad < (W+1)/2 {
			fmt.Println(-1)
		} else {
			fmt.Println(m)
			fmt.Println(result)
		}
	}
}

package main

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

type item struct {
	number int
	weight int
}

func main() {
	//rd, _ := os.Open("input")
	//in := bufio.NewReader(rd)
	in := bufio.NewReader(os.Stdin)

	var t, n, W int
	fmt.Fscan(in, &t)

	for ; t > 0; t-- {
		fmt.Fscan(in, &n, &W)
		items := make([]item, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &items[i].weight)
			items[i].number = i + 1
		}
		sort.Slice(items, func(i, j int) bool {
			return items[i].weight > items[j].weight
		})
		m := 0
		w := 0
		result := ""
		for i := range items {
			if w+items[i].weight <= W {
				result += strconv.Itoa(items[i].number) + " "
				m++
				w += items[i].weight
				if w >= (W+1)/2 {
					break
				}
			}
		}
		if w < (W+1)/2 {
			fmt.Println(-1)
		} else {
			fmt.Println(m)
			fmt.Println(result)
		}
	}
}


//359B
package main
import "fmt"

func main() {
	var nn, kk int
	var flag bool
	fmt.Scan(&nn, &kk)
		flag=false
		for i:=1; i<=kk; i++ {
			if flag==false {
				flag=true
				fmt.Print(2*i-1, 2*i, " ")
			} else {
				fmt.Print(" ", 2*i-1, 2*i)
			}
		}
		for i:=kk+1; i<=nn; i++ {
			if flag==false {
				fmt.Print(2*i, 2*i-1, " ")
			} else {
				fmt.Print(" ", 2*i, 2*i-1)
			}
		}
		fmt.Println()
}

package main

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

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

	var n, k int
	Fscan(in, &n, &k)
	a := make([]interface{}, 2*n)
	for i := range a {
		a[i] = 2*n - i
	}
	for i := 0; i < k; i++ {
		a[2*i], a[2*i+1] = a[2*i+1], a[2*i]
	}
	Fprint(out, a...)
}

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

// 359B
package main

import (
	"fmt"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	for i := 1; i <= n; i++ {
		if i <= k {
			fmt.Print(i*2, i*2-1, " ")
		} else {
			fmt.Print(i*2-1, i*2, " ")
		}
	}
	fmt.Print("")
}

//359B
package main
import "fmt"

func main() {
	var nn, kk int
	var flag bool
	fmt.Scan(&nn, &kk)
		flag=false
		for i:=1; i<=kk; i++ {
			if flag==false {
				flag=true
				fmt.Print(2*i-1, 2*i)
			} else {
				fmt.Print(" ", 2*i-1, 2*i)
			}
		}
		for i:=kk+1; i<=nn; i++ {
			if flag==false {
				fmt.Print(2*i, 2*i-1)
			} else {
				fmt.Print(" ", 2*i, 2*i-1)
			}
		}
		fmt.Println()
}

//359B
package main
import "fmt"

func main() {
	var nn, kk int
	var flag bool
	fmt.Scan(&nn, &kk)
		flag=false
		for i:=1; i<=kk; i++ {
			if flag==false {
				flag=true
				fmt.Printf("%d %d",2*i-1,2*i)
			} else {
				fmt.Printf(" %d %d",2*i-1,2*i)
			}
		}
		for i:=kk+1; i<=nn; i++ {
			if flag==false {
				fmt.Printf("%d %d",2*i,2*i-1)
			} else {
				fmt.Print(" %d %d", 2*i,2*i-1)
			}
		}
		fmt.Println()
}


package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	f := make([]int, n)
	for i := 0; i < n; i++ {
		var x int
		fmt.Scan(&x)
		f[i] = x - 1
	}
	sort.Ints(f)
	z, p := 0, n-1
	for p >= 0 {
		z += 2 * f[p]
		p -= k
	}
	fmt.Println(z)
}

package main

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

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

func ReadInt32() int {
    scanner.Scan()
    ans, _ := strconv.Atoi(scanner.Text())
    return ans
}

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

    n := ReadInt32()
    k := ReadInt32()
    a := make([]int, n)
    ans := 0

    for i := 0; i < n; i++ {
        a[i] = ReadInt32()
    }

    sort.Ints(a)

    for i := n - 1; i >= 0; i -= k {
        ans += (a[i] - 1) * 2
    }
    writer.WriteString(strconv.Itoa(ans) + "\n")
}

package main

import (
	"fmt"
	"sort"
)

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

	fn := make([]int, n, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&fn[i])
	}
	sort.Sort(sort.Reverse(sort.IntSlice(fn)))

	ans := 0
	for i := 0; i < n; i += k {
		ans += 2 * (fn[i] - 1)
	}

	fmt.Println(ans)
}

package main

import (
	"fmt"
)

const maxF = 2000

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	num := make([]int, maxF+1)
	for i := 0; i < n; i++ {
		var f int
		fmt.Scan(&f)
		num[f]++
	}
	cur := k
	ans := 0
	for i := maxF; i > 1; i-- {
		for cur+num[i] > k {
			ans += 2 * (i - 1)
			num[i] -= k - cur
			cur = 0
		}
		cur += num[i]
	}
	fmt.Println(ans)
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int

	fmt.Scan(&n, &k)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	ret := 0
	for i := 0; i < n; i += k {
		ret += 2 * (a[i] - 1)
	}
	fmt.Println(ret)
}

package main

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

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

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

	n, k := nextInt(), nextInt()
	f := make([]int, 2001)
	lastFloor := 0
	second := 0

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

	for i := 2000; i >= 0; i-- {
		if f[i] != 0 {
			// println("i:", i," second:", second," f[i]:", f[i], " lastFloor:", lastFloor, " f[lastFloor]:", f[lastFloor])
			if f[i] + f[lastFloor] < k {
				if f[lastFloor] == 0 {
					lastFloor = i
				} else {
					f[lastFloor] += f[i]
				}

			} else {
				if f[lastFloor] > 0 {
					f[i] -= k - f[lastFloor]
					second += lastFloor * 2
					// println(i, f[lastFloor])
				}

				second += (f[i] / k) * i * 2
				f[i] %= k
				lastFloor = i
			}

			// println("i:", i," second:", second," f[i]:", f[i], " lastFloor:", lastFloor, " f[lastFloor]:", f[lastFloor])
		}
	}

	// if f[lastFloor] > 0 {
	// 	second += 2
	// }

	if f[lastFloor] > 0 {
		second += lastFloor * 2
	}

	println(second)
}

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

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

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

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

package main

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

func main() {
	var n, k int
	if _, err := fmt.Scanf("%d %d\n", &n, &k); err != nil {
		return
	}

	f := make([]int, n)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	for i := 0; scanner.Scan(); i++ {
		a, err := strconv.Atoi(scanner.Text())
		if err != nil {
			return
		}
		f[i] = a
	}

	merge_sort(f, 0, n-1)

	time := 0
	for i := n - 1; i >= 0; i -= k {
		time += 2 * (f[i] - 1)
	}
	fmt.Println(time)
}

func merge(buffer []int, start, middle, end int) {
	sorted := make([]int, end-start+1)

	i := start
	j := middle + 1
	k := 0
	for i <= middle && j <= end {
		if buffer[i] <= buffer[j] {
			sorted[k] = buffer[i]
			i++
		} else {
			sorted[k] = buffer[j]
			j++
		}
		k++
	}
	for i <= middle {
		sorted[k] = buffer[i]
		k++
		i++
	}
	for j <= end {
		sorted[k] = buffer[j]
		k++
		j++
	}

	i = start
	k = 0
	for i <= end {
		buffer[i] = sorted[k]
		i++
		k++
	}
}

func merge_sort(buffer []int, start, end int) {
	if end > start {
		middle := (end + start) / 2
		merge_sort(buffer, start, middle)
		merge_sort(buffer, middle+1, end)
		merge(buffer, start, middle, end)
	}
}

package main

import (
	"bufio"
	"bytes"
	"errors"
	"io"
	"math/rand"
	"os"
	"strconv"
	"time"
	"unicode/utf8"
	"sort"
)

// ******************************** CODE STARTS ********************************

const ()

var (
)

func solve() {
	n := readInt()
	k := readInt()
	array := make([]int, n)
	for i := 0; i < n; i++ {
		array[i] = readInt()
	}
	sort.Sort(sort.IntSlice(array))
	dp := make([]int, n + 1)
	for p := n - 1; p >= 0; p-- {
		dp[p] = -1
		for i := 0; i < k && p + i < n; i++ {
			value := 2 * (array[p + i] - 1) + dp[p + i + 1]
			if dp[p] == -1 || dp[p] > value {
				dp[p] = value
			}
		}
	}
	printInt(dp[0])
	printLine()
}

// ********************************* CODE ENDS *********************************

// IO.

var (
	scanner *Scanner
	writer  *bufio.Writer
)

func main() {
	input := os.Stdin
	output := os.Stdout
	//	input, _ := os.Open("")
	//	output, _ := os.Create("")

	defer input.Close()
	defer output.Close()

	scanner = NewScanner(input)
	scanner.Split(bufio.ScanWords)

	writer = bufio.NewWriter(output)
	defer writer.Flush()

	rand.Seed(int64(time.Now().Nanosecond()))
	solve()
}

// Read.

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

func readLine() string {
	scanner.Split(bufio.ScanLines)
	defer scanner.Split(bufio.ScanWords)
	return readString()
}

func readInt() int {
	ans, _ := strconv.ParseInt(readString(), 10, 0)
	return int(ans)
}

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

func readFloat64() float64 {
	ans, _ := strconv.ParseFloat(readString(), 64)
	return ans
}

// Write.

func printString(value string) {
	writer.WriteString(value)
}

func printLine() {
	printString("\n")
}

func printSpace() {
	printString(" ")
}

func printInt(value int) {
	printString(strconv.FormatInt(int64(value), 10))
}

func printInt64(value int64) {
	printString(strconv.FormatInt(value, 10))
}

func printFloat64(value float64) {
	printString(strconv.FormatFloat(value, 'f', 20, 64))
}

// Tuple

type Tuple struct {
	a, b int
}

func (p Tuple) Equals(key Key) bool {
	return p.a == key.(Tuple).a
}

func (p Tuple) Less(key Key) bool {
	return p.a < key.(Tuple).a
}

type TupleSlice []Tuple

func (p TupleSlice) Len() int {
	return len(p)
}

func (p TupleSlice) Less(j, i int) bool {
	return p[j].a < p[i].a
}

func (p TupleSlice) Swap(j, i int) {
	p[j], p[i] = p[i], p[j]
}

// Min, max, abs.

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

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

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

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

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

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

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

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

func absFloat64(a float64) float64 {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

// Set Key interface implementations.

type Int int

func (p Int) Equals(key Key) bool {
	return int(p) == int(key.(Int))
}

func (p Int) Less(key Key) bool {
	return int(p) < int(key.(Int))
}

// Set.

type Key interface {
	Equals(key Key) bool
	Less(key Key) bool
}

type node struct {
	key   Key
	left  *node
	right *node
}

func newNode(key Key) *node {
	return &node{key, nil, nil}
}

type SplayTree struct {
	root *node
	tmp  *node
	len  int
}

func NewSplayTree() *SplayTree {
	return &SplayTree{nil, newNode(nil), 0}
}

func rotateLeft(x, p *node) {
	p.right = x.left
	x.left = p
}

func rotateRight(x, p *node) {
	p.left = x.right
	x.right = p
}

func (p *SplayTree) splay(x *node, key Key) *node {
	if x == nil {
		return nil
	}

	left := p.tmp
	right := p.tmp

	for {
		if key.Less(x.key) {
			y := x.left
			if y == nil {
				break
			}
			if key.Less(y.key) { // zig-zig
				rotateRight(y, x)
				x = y
				if x.left == nil {
					break
				}
			}
			// link right
			right.left = x
			right = x
			// move left
			x = x.left
		} else if x.key.Less(key) {
			y := x.right
			if y == nil {
				break
			}
			if y.key.Less(key) { // zig-zig
				rotateLeft(y, x)
				x = y
				if x.right == nil {
					break
				}
			}
			// link left
			left.right = x
			left = x
			// move right
			x = x.right
		} else {
			break
		}
	}

	left.right = x.left
	right.left = x.right
	x.left = p.tmp.right
	x.right = p.tmp.left

	return x
}

// left <= key < right
func (p *SplayTree) split(key Key) (left, right *node) {
	p.root = p.splay(p.root, key)
	if p.root.key.Equals(key) || p.root.key.Less(key) {
		right := p.root.right
		p.root.right = nil
		return p.root, right
	} else {
		left := p.root.left
		p.root.left = nil
		return left, p.root
	}
}

// keys from left tree must be less then keys from right tree
func (p *SplayTree) join(left, right *node) *node {
	if left == nil {
		return right
	} else if right == nil {
		return left
	}
	left = p.splay(left, right.key)
	left.right = right
	return left
}

type Set interface {
	Len() int
	Insert(key Key) error
	Find(key Key) bool
	Remove(key Key) error
}

func NewSet() Set {
	return Set(NewSplayTree())
}

func (p *SplayTree) Len() int {
	return p.len
}

func (p *SplayTree) Insert(key Key) error {
	if p.root == nil {
		p.root = newNode(key)
		p.len++
	} else {
		p.root = p.splay(p.root, key)
		if p.root.key.Equals(key) {
			return errors.New("Such key already exists")
		} else {
			left, right := p.split(key)
			p.root = newNode(key)
			p.root.left = left
			p.root.right = right
			p.len++
		}
	}
	return nil
}

func (p *SplayTree) Find(key Key) bool {
	if p.root == nil {
		return false
	}
	p.root = p.splay(p.root, key)
	return p.root.key.Equals(key)
}

func (p *SplayTree) Remove(key Key) error {
	p.root = p.splay(p.root, key)
	if p.root == nil || !p.root.key.Equals(key) {
		return errors.New("Such key doesn't exist")
	}
	p.root = p.join(p.split(key))
	return nil
}

// Copied scan.go
// Scanner provides a convenient interface for reading data such as
// a file of newline-delimited lines of text. Successive calls to
// the Scan method will step through the 'tokens' of a file, skipping
// the bytes between the tokens. The specification of a token is
// defined by a split function of type SplitFunc; the default split
// function breaks the input into lines with line termination stripped. Split
// functions are defined in this package for scanning a file into
// lines, bytes, UTF-8-encoded runes, and space-delimited words. The
// client may instead provide a custom split function.
//
// Scanning stops unrecoverably at EOF, the first I/O error, or a token too
// large to fit in the buffer. When a scan stops, the reader may have
// advanced arbitrarily far past the last token. Programs that need more
// control over error handling or large tokens, or must run sequential scans
// on a reader, should use bufio.Reader instead.
//
type Scanner struct {
	r            io.Reader // The reader provided by the client.
	split        SplitFunc // The function to split the tokens.
	maxTokenSize int       // Maximum size of a token; modified by tests.
	token        []byte    // Last token returned by split.
	buf          []byte    // Buffer used as argument to split.
	start        int       // First non-processed byte in buf.
	end          int       // End of data in buf.
	err          error     // Sticky error.
}

// SplitFunc is the signature of the split function used to tokenize the
// input. The arguments are an initial substring of the remaining unprocessed
// data and a flag, atEOF, that reports whether the Reader has no more data
// to give. The return values are the number of bytes to advance the input
// and the next token to return to the user, plus an error, if any. If the
// data does not yet hold a complete token, for instance if it has no newline
// while scanning lines, SplitFunc can return (0, nil, nil) to signal the
// Scanner to read more data into the slice and try again with a longer slice
// starting at the same point in the input.
//
// If the returned error is non-nil, scanning stops and the error
// is returned to the client.
//
// The function is never called with an empty data slice unless atEOF
// is true. If atEOF is true, however, data may be non-empty and,
// as always, holds unprocessed text.
type SplitFunc func(data []byte, atEOF bool) (advance int, token []byte, err error)

// Errors returned by Scanner.
var (
	ErrTooLong         = errors.New("bufio.Scanner: token too long")
	ErrNegativeAdvance = errors.New("bufio.Scanner: SplitFunc returns negative advance count")
	ErrAdvanceTooFar   = errors.New("bufio.Scanner: SplitFunc returns advance count beyond input")
)

const (
	// Maximum size used to buffer a token. The actual maximum token size
	// may be smaller as the buffer may need to include, for instance, a newline.
	MaxScanTokenSize = 1 << 20
)

// NewScanner returns a new Scanner to read from r.
// The split function defaults to ScanLines.
func NewScanner(r io.Reader) *Scanner {
	return &Scanner{
		r:            r,
		split:        ScanLines,
		maxTokenSize: MaxScanTokenSize,
		buf:          make([]byte, 4096), // Plausible starting size; needn't be large.
	}
}

// Err returns the first non-EOF error that was encountered by the Scanner.
func (s *Scanner) Err() error {
	if s.err == io.EOF {
		return nil
	}
	return s.err
}

// Bytes returns the most recent token generated by a call to Scan.
// The underlying array may point to data that will be overwritten
// by a subsequent call to Scan. It does no allocation.
func (s *Scanner) Bytes() []byte {
	return s.token
}

// Text returns the most recent token generated by a call to Scan
// as a newly allocated string holding its bytes.
func (s *Scanner) Text() string {
	return string(s.token)
}

// Scan advances the Scanner to the next token, which will then be
// available through the Bytes or Text method. It returns false when the
// scan stops, either by reaching the end of the input or an error.
// After Scan returns false, the Err method will return any error that
// occurred during scanning, except that if it was io.EOF, Err
// will return nil.
func (s *Scanner) Scan() bool {
	// Loop until we have a token.
	for {
		// See if we can get a token with what we already have.
		if s.end > s.start {
			advance, token, err := s.split(s.buf[s.start:s.end], s.err != nil)
			if err != nil {
				s.setErr(err)
				return false
			}
			if !s.advance(advance) {
				return false
			}
			s.token = token
			if token != nil {
				return true
			}
		}
		// We cannot generate a token with what we are holding.
		// If we've already hit EOF or an I/O error, we are done.
		if s.err != nil {
			// Shut it down.
			s.start = 0
			s.end = 0
			return false
		}
		// Must read more data.
		// First, shift data to beginning of buffer if there's lots of empty space
		// or space is neded.
		if s.start > 0 && (s.end == len(s.buf) || s.start > len(s.buf)/2) {
			copy(s.buf, s.buf[s.start:s.end])
			s.end -= s.start
			s.start = 0
		}
		// Is the buffer full? If so, resize.
		if s.end == len(s.buf) {
			if len(s.buf) >= s.maxTokenSize {
				s.setErr(ErrTooLong)
				return false
			}
			newSize := len(s.buf) * 2
			if newSize > s.maxTokenSize {
				newSize = s.maxTokenSize
			}
			newBuf := make([]byte, newSize)
			copy(newBuf, s.buf[s.start:s.end])
			s.buf = newBuf
			s.end -= s.start
			s.start = 0
			continue
		}
		// Finally we can read some input. Make sure we don't get stuck with
		// a misbehaving Reader. Officially we don't need to do this, but let's
		// be extra careful: Scanner is for safe, simple jobs.
		for loop := 0; ; {
			n, err := s.r.Read(s.buf[s.end:len(s.buf)])
			s.end += n
			if err != nil {
				s.setErr(err)
				break
			}
			if n > 0 {
				break
			}
			loop++
			if loop > 100 {
				s.setErr(io.ErrNoProgress)
				break
			}
		}
	}
}

// advance consumes n bytes of the buffer. It reports whether the advance was legal.
func (s *Scanner) advance(n int) bool {
	if n < 0 {
		s.setErr(ErrNegativeAdvance)
		return false
	}
	if n > s.end-s.start {
		s.setErr(ErrAdvanceTooFar)
		return false
	}
	s.start += n
	return true
}

// setErr records the first error encountered.
func (s *Scanner) setErr(err error) {
	if s.err == nil || s.err == io.EOF {
		s.err = err
	}
}

// Split sets the split function for the Scanner. If called, it must be
// called before Scan. The default split function is ScanLines.
func (s *Scanner) Split(split SplitFunc) {
	s.split = split
}

// Split functions

// ScanBytes is a split function for a Scanner that returns each byte as a token.
func ScanBytes(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	return 1, data[0:1], nil
}

var errorRune = []byte(string(utf8.RuneError))

// ScanRunes is a split function for a Scanner that returns each
// UTF-8-encoded rune as a token. The sequence of runes returned is
// equivalent to that from a range loop over the input as a string, which
// means that erroneous UTF-8 encodings translate to U+FFFD = "\xef\xbf\xbd".
// Because of the Scan interface, this makes it impossible for the client to
// distinguish correctly encoded replacement runes from encoding errors.
func ScanRunes(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}

	// Fast path 1: ASCII.
	if data[0] < utf8.RuneSelf {
		return 1, data[0:1], nil
	}

	// Fast path 2: Correct UTF-8 decode without error.
	_, width := utf8.DecodeRune(data)
	if width > 1 {
		// It's a valid encoding. Width cannot be one for a correctly encoded
		// non-ASCII rune.
		return width, data[0:width], nil
	}

	// We know it's an error: we have width==1 and implicitly r==utf8.RuneError.
	// Is the error because there wasn't a full rune to be decoded?
	// FullRune distinguishes correctly between erroneous and incomplete encodings.
	if !atEOF && !utf8.FullRune(data) {
		// Incomplete; get more bytes.
		return 0, nil, nil
	}

	// We have a real UTF-8 encoding error. Return a properly encoded error rune
	// but advance only one byte. This matches the behavior of a range loop over
	// an incorrectly encoded string.
	return 1, errorRune, nil
}

// dropCR drops a terminal \r from the data.
func dropCR(data []byte) []byte {
	if len(data) > 0 && data[len(data)-1] == '\r' {
		return data[0 : len(data)-1]
	}
	return data
}

// ScanLines is a split function for a Scanner that returns each line of
// text, stripped of any trailing end-of-line marker. The returned line may
// be empty. The end-of-line marker is one optional carriage return followed
// by one mandatory newline. In regular expression notation, it is `\r?\n`.
// The last non-empty line of input will be returned even if it has no
// newline.
func ScanLines(data []byte, atEOF bool) (advance int, token []byte, err error) {
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	if i := bytes.IndexByte(data, '\n'); i >= 0 {
		// We have a full newline-terminated line.
		return i + 1, dropCR(data[0:i]), nil
	}
	// If we're at EOF, we have a final, non-terminated line. Return it.
	if atEOF {
		return len(data), dropCR(data), nil
	}
	// Request more data.
	return 0, nil, nil
}

// isSpace reports whether the character is a Unicode white space character.
// We avoid dependency on the unicode package, but check validity of the implementation
// in the tests.
func isSpace(r rune) bool {
	if r <= '\u00FF' {
		// Obvious ASCII ones: \t through \r plus space. Plus two Latin-1 oddballs.
		switch r {
		case ' ', '\t', '\n', '\v', '\f', '\r':
			return true
		case '\u0085', '\u00A0':
			return true
		}
		return false
	}
	// High-valued ones.
	if '\u2000' <= r && r <= '\u200a' {
		return true
	}
	switch r {
	case '\u1680', '\u180e', '\u2028', '\u2029', '\u202f', '\u205f', '\u3000':
		return true
	}
	return false
}

// ScanWords is a split function for a Scanner that returns each
// space-separated word of text, with surrounding spaces deleted. It will
// never return an empty string. The definition of space is set by
// unicode.IsSpace.
func ScanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
	// Skip leading spaces.
	start := 0
	for width := 0; start < len(data); start += width {
		var r rune
		r, width = utf8.DecodeRune(data[start:])
		if !isSpace(r) {
			break
		}
	}
	if atEOF && len(data) == 0 {
		return 0, nil, nil
	}
	// Scan until space, marking end of word.
	for width, i := 0, start; i < len(data); i += width {
		var r rune
		r, width = utf8.DecodeRune(data[i:])
		if isSpace(r) {
			return i + width, data[start:i], nil
		}
	}
	// If we're at EOF, we have a final, non-empty, non-terminated word. Return it.
	if atEOF && len(data) > start {
		return len(data), data[start:], nil
	}
	// Request more data.
	return 0, nil, nil
}

package main

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

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

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

	n, k := nextInt(), nextInt()
	f := make([]int, 2001)
	lastFloor := 0
	second := 0

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

	for i := 2000; i >= 0; i-- {
		if f[i] != 0 {
			// println("i:", i," second:", second," f[i]:", f[i], " lastFloor:", lastFloor, " f[lastFloor]:", f[lastFloor])
			if f[i] + f[lastFloor] < k {
				f[i] += f[lastFloor]
			} else {
				if f[lastFloor] > 0 {
					f[i] -= k - f[lastFloor]
					second += lastFloor * 2
				}

				second += (f[i] / k) * i * 2
				f[i] %= k
			}

			lastFloor = i
			// println("i:", i," second:", second," f[i]:", f[i], " lastFloor:", lastFloor, " f[lastFloor]:", f[lastFloor])
		}
	}

	if f[lastFloor] > 0 {
		second += 2
	}

	println(second)
}

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

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

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

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

package main

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

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

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

	n, k := nextInt(), nextInt()
	f := make([]int, 2001)
	lastFloor := 0
	second := 0

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

	for i := 2000; i >= 0; i-- {
		if f[i] != 0 {
			println("i:", i," second:", second," f[i]:", f[i], " lastFloor:", lastFloor, " f[lastFloor]:", f[lastFloor])
			if f[i] + f[lastFloor] < k {
				if f[lastFloor] == 0 {
					lastFloor = i
				} else {
					f[lastFloor] += f[i]
				}

				println(i)
			} else {
				if f[lastFloor] > 0 {
					f[i] -= k - f[lastFloor]
					second += lastFloor * 2
					println(i, f[lastFloor])
				}

				second += (f[i] / k) * i * 2
				f[i] %= k
				lastFloor = i
			}

			println("i:", i," second:", second," f[i]:", f[i], " lastFloor:", lastFloor, " f[lastFloor]:", f[lastFloor])
		}
	}

	// if f[lastFloor] > 0 {
	// 	second += 2
	// }

	if f[lastFloor] > 0 {
		second += lastFloor * 2
	}

	println(second)
}

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

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

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

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

package main

import (
	"fmt"
	"sort"
)

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

	fn := make([]int, n, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&fn[i])
	}
	sort.Sort(sort.Reverse(sort.IntSlice(fn)))
	fmt.Println(fn)

	ans := 0
	for i := 0; i < n; i += k {
		ans += 2 * (fn[i] - 1)
	}

	fmt.Println(ans)
}


package main

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

type Seg struct {
	l int
	r int
	c int
	i int
}

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

func bsearch(a []Seg, l, r, v int) int {
	if (l == r) { return l }
	m := (l + r + 1) >> 1
	if a[m].l > v { return bsearch(a, l, m-1, v) }
	return bsearch(a, m, r, v)
}

func solve(a []Seg, dist *[]int) {
	c := make([][]Seg, len(a))

	for i, s := range a {
		if i == 0 {
			c[i] = []Seg{Seg{-2e10, -2e10, -1, -1}, s}
			continue
		}

		c[i] = []Seg{c[i-1][0], c[i-1][1]}
		same_clr := s.c != c[i][1].c
		if s.r >= c[i][1].r {
			if same_clr { c[i][0] = c[i][1] }
			c[i][1] = s
		} else if s.r >= c[i][0].r && same_clr {
			c[i][0] = s
		}
	}

	for _, s := range a {
		j := bsearch(a, 0, len(a)-1, s.r)
		i := 1
		if c[j][1].c == s.c { i = 0 }
		if s.l > c[j][i].r {
			(*dist)[s.i] = min((*dist)[s.i], s.l - c[j][i].r)
		} else {
			(*dist)[s.i] = 0
		}
	}
}

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

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {

		var n int
		fmt.Fscan(r, &n)

		a := make([]Seg, n)
		b := make([]Seg, n)
		dist := make([]int, n)

		for i := range a {
			var x, y, z int
			fmt.Fscan(r, &x, &y, &z)
			a[i] = Seg{x, y, z, i}
			b[i] = Seg{-y, -x, z, i}
			dist[i] = 1e10 + 7
		}

		sort.Slice(a, func(i, j int) bool { return a[i].l < a[j].l })
		sort.Slice(b, func(i, j int) bool { return b[i].l < b[j].l })

		solve(a, &dist)
		solve(b, &dist)

		for _, d := range dist {
			fmt.Fprintf(w, "%d ", d)
		}
		fmt.Fprintln(w, "")
	}

}

package main

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

type Seg struct {
	l int
	r int
	c int
	i int
}

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

func bsearch(a []Seg, l, r, v int) int {
	if (l == r) { return l }
	m := (l + r + 1) >> 1
	if a[m].l > v { return bsearch(a, l, m-1, v) }
	return bsearch(a, m, r, v)
}

func solve(a []Seg, dist *[]int) {
	c := make([][]Seg, len(a))

	for i, s := range a {
		if i == 0 {
			c[i] = []Seg{Seg{-2e10, -2e10, -1, -1}, s}
			// fmt.Println("&&&&&&&&&&& i, c ", i, c[i]) // ***
			continue
		}

		c[i] = []Seg{c[i-1][0], c[i-1][1]}
		same_clr := s.c != c[i][1].c
		if s.r >= c[i][1].r {
			if same_clr { c[i][0] = c[i][1] }
			c[i][1] = s
		} else if s.r >= c[i][0].r && same_clr {
			c[i][0] = s
		}
		// fmt.Println("&&&&&&&&&&& i, c ", i, c[i]) // ***
	}

	for _, s := range a {
		j := bsearch(a, 0, len(a)-1, s.r)
		i := 1
		if c[j][1].c == s.c { i = 0 }
		// fmt.Println("---------- c[j] ", c[j]) // ***
		// fmt.Println("---------- s ", s) // ***
		// fmt.Println("---------- j i s.l c[j][i].r ", j, i, s.l, c[j][i].r) // ***
		if s.l > c[j][i].r {
			(*dist)[s.i] = min((*dist)[s.i], s.l - c[j][i].r)
		} else {
			(*dist)[s.i] = 0
		}
	}
}

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

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {

		var n int
		fmt.Fscan(r, &n)

		a := make([]Seg, n)
		b := make([]Seg, n)
		dist := make([]int, n)

		for i := range a {
			var x, y, z int
			fmt.Fscan(r, &x, &y, &z)
			a[i] = Seg{x, y, z, i}
			b[i] = Seg{-y, -x, z, i}
			dist[i] = 1e10 + 7
		}

		sort.Slice(a, func(i, j int) bool { return a[i].l < a[j].l })
		sort.Slice(b, func(i, j int) bool { return b[i].l < b[j].l })

		/*
		fmt.Fprintln(w, "********** sorted a")
		for _, v := range a {
			fmt.Fprintln(w, "----------- ", v)
		}

		fmt.Fprintln(w, "********** sorted b")
		for _, v := range b {
			fmt.Fprintln(w, "----------- ", v)
		}
		*/

		solve(a, &dist)
		solve(b, &dist)

		for _, d := range dist {
			fmt.Fprintf(w, "%d ", d)
		}
		fmt.Fprintln(w, "")
	}

}

package main

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

type Seg struct {
	l int
	r int
	c int
	i int
}

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

func solve(a []Seg, dist *[]int) {
	c := make([]Seg, 2)
	c[0] = a[0]
	for _, s := range a {
		if s.c != c[0].c {
			c[1] = s
			break
		}
	}

	for _, s := range a {
		i := 1
		if s.c == c[1].c { i = 0 }

		if c[i].l <= s.r {
			if s.l > c[i].r {
				(*dist)[s.i] = min((*dist)[s.i], s.l - c[i].r)
			} else {
				(*dist)[s.i] = 0
			}

			if s.r >= c[1].r {
				if i == 1 { c[0] = c[1] }
				c[1] = s
			} else if s.r >= c[0].r && i == 1 {
				c[0] = s
			}
		}

		/*
		fmt.Println("@@@@@@@@@@ c ", c)
		fmt.Println("########## d ", *dist)
		*/
	}
}

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

	var T int
	for fmt.Fscan(r, &T); T > 0; T-- {

		var n int
		fmt.Fscan(r, &n)

		a := make([]Seg, n)
		b := make([]Seg, n)
		dist := make([]int, n)

		for i := range a {
			var x, y, z int
			fmt.Fscan(r, &x, &y, &z)
			a[i] = Seg{x, y, z, i}
			b[i] = Seg{-y, -x, z, i}
			dist[i] = 1e10 + 7
		}

		sort.Slice(a, func(i, j int) bool { return a[i].l < a[j].l })
		sort.Slice(b, func(i, j int) bool { return b[i].l < b[j].l })

		/*
		fmt.Fprintln(w, "********** sorted a")
		for _, v := range a {
			fmt.Fprintln(w, "----------- ", v)
		}

		fmt.Fprintln(w, "********** sorted b")
		for _, v := range b {
			fmt.Fprintln(w, "----------- ", v)
		}
		*/

		solve(a, &dist)
		solve(b, &dist)

		for _, d := range dist {
			fmt.Fprintf(w, "%d ", d)
		}
		fmt.Fprintln(w, "")
	}

}


package main

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

var N = big.NewInt(1000000007)
var Q = big.NewInt(4)
var D = big.NewInt(2)
var B0 = big.NewInt(0)
var B1 = big.NewInt(1)
var B2 = big.NewInt(2)
var B3 = big.NewInt(3)

// calculate the last number of the arithmetic progression
func c_li(f_i, n, d *big.Int) *big.Int {
	return new(big.Int).Add(f_i, new(big.Int).Mul(d, new(big.Int).Sub(n, B1)))
}

// calculate the first number of the arithmetic progression
func c_fi(l_i, n, d *big.Int) *big.Int {
	return new(big.Int).Sub(l_i, new(big.Int).Mul(d, new(big.Int).Sub(n, B1)))
}

// calculate the arithmetic progression sum
func APSum(f_i, l_i, d *big.Int) *big.Int {
	a := new(big.Int).Add(f_i, l_i)
	b := new(big.Int).Div(new(big.Int).Sub(l_i, f_i), d)
	b = new(big.Int).Add(b, B1)
	return new(big.Int).Div(new(big.Int).Mul(a, b), B2)
}

func seqSumEven(x *big.Int) (res *big.Int) {
	if x.Cmp(B1) == 0 {
		return B1
	}
	lx := big.NewInt(int64(math.Log2(float64(x.Int64()))))
	i2_u := new(big.Int).Sub(B2, new(big.Int).Mul(B2, new(big.Int).Exp(Q, lx.Div(lx, B2), nil)))
	i2_d := new(big.Int).Sub(B1, Q)
	i2 := new(big.Int).Mul(i2_u.Div(i2_u, i2_d), B2)
	if i2.Cmp(x) < 0 { // Section B
		n := new(big.Int).Sub(x, i2)
		i2a1 := new(big.Int).Add(i2, B1)
		l_i := c_li(i2a1, n, D)
		res = new(big.Int).Add(APSum(B1, i2, B1), APSum(i2a1, l_i, D))
	} else { // Section A
		n := new(big.Int).Sub(i2, x)
		i2s1 := new(big.Int).Sub(i2, B1)
		f_i := c_fi(i2s1, n, D)
		res = new(big.Int).Sub(APSum(B1, i2, B1), APSum(f_i, i2s1, D))
	}
	return
}

func seqSumOdd(x *big.Int) (res *big.Int) {
	if x.Cmp(B2) == 0 {
		return B3
	}
	if x.Cmp(B3) == 0 {
		return big.NewInt(7)
	}

	lx := big.NewInt(int64(math.Log2(float64(x.Int64()))))
	i1_u := new(big.Int).Sub(B1, new(big.Int).Exp(Q, lx.Div(new(big.Int).Add(lx, B1), B2), nil))
	i1_d := new(big.Int).Sub(B1, Q)
	i1 := new(big.Int).Mul(i1_u.Div(i1_u, i1_d), B2)

	if i1.Cmp(x) < 0 { // Section B
		n := new(big.Int).Sub(x, i1)
		i1a2 := new(big.Int).Add(i1, B2)
		l_i := c_li(i1a2, n, D)
		res = new(big.Int).Add(APSum(B1, i1, B1), APSum(i1a2, l_i, D))
	} else { // Section A
		n := new(big.Int).Sub(i1, x)
		f_i := c_fi(i1, n, D)
		res = new(big.Int).Sub(APSum(B1, i1, B1), APSum(f_i, i1, D))
	}
	return
}

// SeqSum returns the sum of the sequence from the first element to the xth element
func SeqSum(x *big.Int) (res *big.Int) {
	if x.Cmp(B0) == 0 {
		return B0
	}
	lx := big.NewInt(int64(math.Log2(float64(x.Int64()))))
	if lx.Mod(lx, B2).Cmp(B0) == 0 {
		res = seqSumEven(x)
	} else {
		res = seqSumOdd(x)
	}

	return res
}

func solve(l, r int64) {
	rr := SeqSum(big.NewInt(r))
	lr := SeqSum(big.NewInt(l - 1))
	res := new(big.Int).Mod(rr.Sub(rr, lr), N)
	fmt.Println(res)
}

func ScanNum(s *bufio.Scanner) (int64, error) {
	s.Scan()
	// old version atoi default set to int32 instead of int64
	return strconv.ParseInt(s.Text(), 10, 64)
}

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

	l, _ := ScanNum(s)
	r, _ := ScanNum(s)

	// l, _ := strconv.Atoi(os.Args[1])
	// r, _ := strconv.Atoi(os.Args[2])

	if l > r {
		panic(fmt.Errorf("Invalid range"))
	}
	solve(int64(l), int64(r))
}

package main

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

const (
	mod = uint64(1e9 + 7)
)

type slot struct {
	from uint64
	num  uint64
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	l, r := uint64(0), uint64(0)
	fmt.Fscanf(in, "%d %d\n", &l, &r)
	slots := make([]slot, 0)
	slots = append(slots, slot{1, 1})
	oddStart := uint64(3)
	evenStart := uint64(2)
	until := uint64(1)
	curNum := uint64(1)
	evenTurn := true
	for until < r {
		curNum *= 2
		until += curNum
		if evenTurn {
			evenEnd := evenStart + 2*(curNum-1)
			slots = append(slots, slot{evenStart, curNum})
			evenStart = evenEnd + 2
		} else {
			oddEnd := oddStart + 2*(curNum-1)
			slots = append(slots, slot{oddStart, curNum})
			oddStart = oddEnd + 2
		}
		evenTurn = !evenTurn
	}
	count := uint64(0)
	sum := uint64(0)
	//fmt.Println(slots)
	for i := 0; i < len(slots); i++ {
		// if count >= r {
		// 	fmt.Println("wtf")
		// 	break
		// }
		sumHere := uint64(0)
		// smallID := count + 1
		// bigID := count + slots[i].num
		// from := max(smallID, l)
		// to := min(bigID, r)
		// if from > to {
		// 	continue
		// }
		// num := to - from + 1
		// first := slots[i].from + 2*(from-smallID-1)
		// last := first + 2*(num-1)
		// last %= mod
		// sumd2 := (first + last) / 2
		// num %= mod
		// sumd2 *= num
		// sumd2 %= mod
		// sum += sumd2
		// sum %= mod
		if count+1 >= l {
			if count+slots[i].num <= r {
				first := slots[i].from
				end := first + 2*(slots[i].num-1)
				f1 := (first + end) / 2
				f1 %= mod
				f2 := slots[i].num
				f2 %= mod
				f1 *= f2
				f1 %= mod
				sumHere = f1
			} else {
				num := r - count
				first := slots[i].from
				end := first + 2*(num-1)
				f1 := (first + end) / 2
				f1 %= mod
				f2 := num
				f2 %= mod
				f1 *= f2
				f1 %= mod
				sumHere = f1
			}
		} else {
			if count+slots[i].num >= l {
				if count+slots[i].num <= r {
					num := count + slots[i].num - l + 1
					first := slots[i].from + 2*(l-count-1)
					end := first + 2*(num-1)
					f1 := (first + end) / 2
					f1 %= mod
					num %= mod
					f1 *= num
					f1 %= mod
					sumHere = f1
				} else {
					num := r - l + 1
					first := slots[i].from + 2*(l-count-1)
					end := first + 2*(num-1)
					f1 := (first + end) / 2
					f1 %= mod
					num %= mod
					f1 *= num
					f1 %= mod
					sumHere = f1
				}
			}
		}
		sum += sumHere
		sum %= mod
		count += slots[i].num
	}
	fmt.Fprintf(out, "%d\n", sum)
	return
}

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

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1151C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	const mod int64 = 1e9 + 7
	f := func(n int64) (res int64) {
		var s, o, e, st int64
		odd := true
		for i := int64(1); s < n; i <<= 1 {
			if odd {
				st = 2*o + 1
				o = (o + i) % mod
			} else {
				st = 2*e + 2
				e = (e + i) % mod
			}
			if s+i > n {
				i = n - s
			}
			s += i
			res += i % mod * (st + i%mod - 1) % mod
			odd = !odd
		}
		return
	}

	var l, r int64
	Fscan(in, &l, &r)
	Fprint(out, ((f(r)-f(l-1))%mod+mod)%mod)
}

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

package main

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

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

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

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

var debug = false

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

var mod = int64(1000000007)

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

type oenode struct {
	index int64
	first int64
	last  int64
}

func (e oenode) Len() int64 {
	return (e.last-e.first)/2 + 1
}

func (e oenode) Sum() int64 {
	return (((e.first + e.last) % (mod * 2)) * (e.Len() % (mod * 2)) / 2) % mod
}

func (e oenode) headSum(last int64) int64 {
	var t oenode
	t.first = e.first
	t.last = last
	return t.Sum()
}

func (e oenode) midSum(first, last int64) int64 {
	var t oenode
	t.first = first
	t.last = last
	return t.Sum()
}

func (e oenode) footSum(first int64) int64 {
	var t oenode
	t.first = first
	t.last = e.last
	return t.Sum()
}

func (e oenode) get(index int64) int64 {
	return e.first + index*2
}

var data = make([]oenode, 0)

func main() {
	defer writer.Flush()

	// init
	isOdd := true
	oddNow := int64(1)
	evenNow := int64(2)
	index := int64(1)
	for i := int64(1); i <= 1000000000000000000; i *= 2 {
		var t oenode
		if isOdd {
			t.first = oddNow
			oddNow += i * 2
			t.last = oddNow - 2
		} else {
			t.first = evenNow
			evenNow += i * 2
			t.last = evenNow - 2
		}
		t.index = index
		data = append(data, t)
		index += i
		isOdd = !isOdd
	}

	// input
	var n, m int64
	scanf("%d %d\n", &n, &m)

	// solve
	status := 0
	ans := int64(0)
	ok := false
	for i := 0; i < len(data) && !ok; i++ {
		t := data[i]
		switch status {
		case 0:
			if n < t.index+t.Len() {
				if m < t.index+t.Len() {
					ans = t.midSum(t.get(n-t.index), t.get(m-t.index))
					ok = true
					break
				}
				ans = add(ans, t.footSum(t.get(n-t.index)))
				status = 1
			}
		case 1:
			if m < t.index+t.Len() {
				ans = add(ans, t.headSum(t.get(m-t.index)))
				ok = true
				break
			}
			ans = add(ans, t.Sum())
		}
	}

	// output
	printf("%d\n", ans)
}

package main

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

const mod = int(1e9) + 7
var L int64
var R int64

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

func oddSum(X int64) int {
	var cnt = (X + 1) / 2
	cnt %= int64(mod)
	return int(cnt * cnt % int64(mod))

}

func evenSum(X int64) int {
	var cnt = X / 2
	var cntp = cnt + 1
	cnt %= int64(mod)
	cntp %= int64(mod)
	return int(cnt * cntp % int64(mod))
}

func oddRange(L int64, R int64) int {
	var tot = (oddSum(R) - oddSum(L - 1)) % mod
	if tot < 0 {
		tot += mod
	}
	return tot
}

func evenRange(L int64, R int64) int {
	var tot = (evenSum(R) - evenSum(L - 1)) % mod
	if tot < 0 {
		tot += mod
	}
	return tot
}

func comp(X int64) int {
	if X == 0 {
		return 0
	}

	var tot = 0
	var lastOdd = int64(-1)
	var lastEven = int64(0)

	var turn = 0

	var sz = int64(1)

	for true {
		sz = min(sz, X)
		X -= sz
		if turn == 0 {
			tot += oddRange(lastOdd + 2, lastOdd + 2 * sz)
			tot %= mod
			lastOdd += 2 * sz
		} else {
			tot += evenRange(lastEven + 2, lastEven + 2 * sz)
			tot %= mod
			lastEven += 2 * sz
		}
		turn = 1 - turn
		sz *= 2

		if X == 0 {
			break
		}
	}
	return tot
}

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

	fmt.Fscanf(reader, "%d %d\n", &L, &R)
	var ret = (comp(R) - comp(L - 1)) % mod
	if ret < 0 {
		ret += mod
	}
	fmt.Fprintf(writer, "%d", ret)
}

package main

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

const (
	mod = uint64(1e9 + 7)
)

type slot struct {
	from uint64
	num  uint64
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	l, r := uint64(0), uint64(0)
	fmt.Fscanf(in, "%d %d\n", &l, &r)
	slots := make([]slot, 0)
	slots = append(slots, slot{1, 1})
	oddStart := uint64(3)
	evenStart := uint64(2)
	until := uint64(1)
	curNum := uint64(1)
	evenTurn := true
	for until < r {
		curNum *= 2
		until += curNum
		if evenTurn {
			evenEnd := evenStart + 2*(curNum-1)
			slots = append(slots, slot{evenStart, curNum})
			evenStart = evenEnd + 2
		} else {
			oddEnd := oddStart + 2*(curNum-1)
			slots = append(slots, slot{oddStart, curNum})
			oddStart = oddEnd + 2
		}
		evenTurn = !evenTurn
	}
	count := uint64(0)
	sum := uint64(0)
	//fmt.Println(slots)
	for i := 0; i < len(slots); i++ {
		if count >= r {
			break
		}
		sumHere := uint64(0)
		if count+1 >= l {
			if count+slots[i].num <= r {
				first := slots[i].from
				end := first + 2*(slots[i].num-1)
				f1 := (first + end) / 2
				f1 %= mod
				f2 := slots[i].num
				f1 *= f2
				f1 %= mod
				sumHere = f1
			} else {
				num := r - count
				first := slots[i].from
				end := first + 2*(num-1)
				f1 := (first + end) / 2
				f1 %= mod
				f2 := num
				f1 *= f2
				f1 %= mod
				sumHere = f1
			}
		} else {
			if count+slots[i].num >= l {
				if count+slots[i].num <= r {
					num := count + slots[i].num - l + 1
					first := slots[i].from + 2*(l-count-1)
					end := first + 2*(num-1)
					f1 := (first + end) / 2
					f1 %= mod
					f1 *= num
					f1 %= mod
					sumHere = f1
				} else {
					num := r - l + 1
					first := slots[i].from + 2*(l-count-1)
					end := first + 2*(num-1)
					f1 := (first + end) / 2
					f1 %= mod
					f1 *= num
					f1 %= mod
					sumHere = f1
				}
			}
		}
		sum += sumHere
		sum %= mod
		count += slots[i].num
	}
	fmt.Fprintf(out, "%d\n", sum)
	return
}

package main

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

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

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

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

var debug = false

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

var mod = int64(1000000007)

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

type oenode struct {
	index int64
	first int64
	last  int64
}

func (e oenode) Len() int64 {
	return (e.last-e.first)/2 + 1
}

func (e oenode) Sum() int64 {
	return (((e.first + e.last) % (mod * 2)) * (e.Len() % (mod * 2)) / 2) % mod
}

func (e oenode) headSum(last int64) int64 {
	var t oenode
	t.first = e.first
	t.last = last
	return t.Sum()
}

func (e oenode) midSum(first, last int64) int64 {
	var t oenode
	t.first = first
	t.last = last
	return t.Sum()
}

func (e oenode) footSum(first int64) int64 {
	var t oenode
	t.first = first
	t.last = e.last
	return t.Sum()
}

func (e oenode) get(index int64) int64 {
	return e.first + index*2
}

var data = make([]oenode, 0)

func main() {
	defer writer.Flush()

	// init
	isOdd := true
	oddNow := int64(1)
	evenNow := int64(2)
	index := int64(1)
	for i := int64(1); i <= 1000000000000000000; i *= 2 {
		var t oenode
		if isOdd {
			t.first = oddNow
			oddNow += i * 2
			t.last = oddNow - 2
		} else {
			t.first = evenNow
			evenNow += i * 2
			t.last = evenNow - 2
		}
		t.index = index
		data = append(data, t)
		index += i
		isOdd = !isOdd
	}

	// input
	var n, m int64
	scanf("%d %d\n", &n, &m)

	// solve
	status := 0
	ans := int64(0)
	ok := false
	for i := 0; i < len(data) && !ok; i++ {
		t := data[i]
		switch status {
		case 0:
			if n <= t.index+t.Len() {
				if m <= t.index+t.Len() {
					ans = t.midSum(t.get(n-t.index), t.get(m-t.index))
					ok = true
					break
				}
				ans = add(ans, t.footSum(t.get(n-t.index)))
				status = 1
			}
		case 1:
			if m <= t.index+t.Len() {
				ans = add(ans, t.headSum(t.get(m-t.index)))
				ok = true
				break
			}
			ans = add(ans, t.Sum())
		}
	}

	// output
	printf("%d\n", ans)
}

package main

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

var N = big.NewInt(1000000007)
var Q = big.NewInt(4)
var D = big.NewInt(2)
var B0 = big.NewInt(0)
var B1 = big.NewInt(1)
var B2 = big.NewInt(2)
var B3 = big.NewInt(3)

// calculate the last number of the arithmetic progression
func c_li(f_i, n, d *big.Int) *big.Int {
	return new(big.Int).Add(f_i, new(big.Int).Mul(d, new(big.Int).Sub(n, B1)))
}

// calculate the first number of the arithmetic progression
func c_fi(l_i, n, d *big.Int) *big.Int {
	return new(big.Int).Sub(l_i, new(big.Int).Mul(d, new(big.Int).Sub(n, B1)))
}

// calculate the arithmetic progression sum
func APSum(f_i, l_i, d *big.Int) *big.Int {
	a := new(big.Int).Add(f_i, l_i)
	b := new(big.Int).Div(new(big.Int).Sub(l_i, f_i), d)
	b = new(big.Int).Add(b, B1)
	return new(big.Int).Div(new(big.Int).Mul(a, b), B2)
}

func seqSumEven(x *big.Int) (res *big.Int) {
	if x.Cmp(B1) == 0 {
		return B1
	}
	lx := big.NewInt(int64(math.Log2(float64(x.Int64()))))
	i2_u := new(big.Int).Sub(B2, new(big.Int).Mul(B2, new(big.Int).Exp(Q, lx.Div(lx, B2), nil)))
	i2_d := new(big.Int).Sub(B1, Q)
	i2 := new(big.Int).Mul(i2_u.Div(i2_u, i2_d), B2)
	if i2.Cmp(x) < 0 { // Section B
		n := new(big.Int).Sub(x, i2)
		i2a1 := new(big.Int).Add(i2, B1)
		l_i := c_li(i2a1, n, D)
		res = new(big.Int).Add(APSum(B1, i2, B1), APSum(i2a1, l_i, D))
	} else { // Section A
		n := new(big.Int).Sub(i2, x)
		i2s1 := new(big.Int).Sub(i2, B1)
		f_i := c_fi(i2s1, n, D)
		res = new(big.Int).Sub(APSum(B1, i2, B1), APSum(f_i, i2s1, D))
	}
	return
}

func seqSumOdd(x *big.Int) (res *big.Int) {
	if x.Cmp(B2) == 0 {
		return B3
	}
	if x.Cmp(B3) == 0 {
		return big.NewInt(7)
	}

	lx := big.NewInt(int64(math.Log2(float64(x.Int64()))))
	i1_u := new(big.Int).Sub(B1, new(big.Int).Exp(Q, lx.Div(new(big.Int).Add(lx, B1), B2), nil))
	i1_d := new(big.Int).Sub(B1, Q)
	i1 := new(big.Int).Mul(i1_u.Div(i1_u, i1_d), B2)

	if i1.Cmp(x) < 0 { // Section B
		n := new(big.Int).Sub(x, i1)
		i1a2 := new(big.Int).Add(i1, B2)
		l_i := c_li(i1a2, n, D)
		res = new(big.Int).Add(APSum(B1, i1, B1), APSum(i1a2, l_i, D))
	} else { // Section A
		n := new(big.Int).Sub(i1, x)
		f_i := c_fi(i1, n, D)
		res = new(big.Int).Sub(APSum(B1, i1, B1), APSum(f_i, i1, D))
	}
	return
}

// SeqSum returns the sum of the sequence from the first element to the xth element
func SeqSum(x *big.Int) (res *big.Int) {
	if x.Cmp(B0) == 0 {
		return B0
	}
	lx := big.NewInt(int64(math.Log2(float64(x.Int64()))))
	if lx.Mod(lx, B2).Cmp(B0) == 0 {
		res = seqSumEven(x)
	} else {
		res = seqSumOdd(x)
	}

	return res
}

func solve(l, r int64) {
	rr := SeqSum(big.NewInt(r))
	lr := SeqSum(big.NewInt(l - 1))
	res := new(big.Int).Mod(rr.Sub(rr, lr), N)
	fmt.Println(res)
}

func ScanNum(s *bufio.Scanner) (int, error) {
	s.Scan()
	return strconv.Atoi(s.Text())
}

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

	l, _ := ScanNum(s)
	r, _ := ScanNum(s)
	fmt.Printf("l:%d r:%d\n", l, r)

	// l, _ := strconv.Atoi(os.Args[1])
	// r, _ := strconv.Atoi(os.Args[2])

	if l > r {
		panic(fmt.Errorf("Invalid range"))
	}
	solve(int64(l), int64(r))
}

package main

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

var N = big.NewInt(1000000007)
var Q = big.NewInt(4)
var D = big.NewInt(2)
var B0 = big.NewInt(0)
var B1 = big.NewInt(1)
var B2 = big.NewInt(2)
var B3 = big.NewInt(3)

// calculate the last number of the arithmetic progression
func c_li(f_i, n, d *big.Int) *big.Int {
	return new(big.Int).Add(f_i, new(big.Int).Mul(d, new(big.Int).Sub(n, B1)))
}

// calculate the first number of the arithmetic progression
func c_fi(l_i, n, d *big.Int) *big.Int {
	return new(big.Int).Sub(l_i, new(big.Int).Mul(d, new(big.Int).Sub(n, B1)))
}

// calculate the arithmetic progression sum
func APSum(f_i, l_i, d *big.Int) *big.Int {
	a := new(big.Int).Add(f_i, l_i)
	b := new(big.Int).Div(new(big.Int).Sub(l_i, f_i), d)
	b = new(big.Int).Add(b, B1)
	return new(big.Int).Div(new(big.Int).Mul(a, b), B2)
}

func seqSumEven(x *big.Int) (res *big.Int) {
	if x.Cmp(B1) == 0 {
		return B1
	}
	lx := big.NewInt(int64(math.Log2(float64(x.Int64()))))
	i2_u := new(big.Int).Sub(B2, new(big.Int).Mul(B2, new(big.Int).Exp(Q, lx.Div(lx, B2), nil)))
	i2_d := new(big.Int).Sub(B1, Q)
	i2 := new(big.Int).Mul(i2_u.Div(i2_u, i2_d), B2)
	if i2.Cmp(x) < 0 { // Section B
		n := new(big.Int).Sub(x, i2)
		i2a1 := new(big.Int).Add(i2, B1)
		l_i := c_li(i2a1, n, D)
		res = new(big.Int).Add(APSum(B1, i2, B1), APSum(i2a1, l_i, D))
	} else { // Section A
		n := new(big.Int).Sub(i2, x)
		i2s1 := new(big.Int).Sub(i2, B1)
		f_i := c_fi(i2s1, n, D)
		res = new(big.Int).Sub(APSum(B1, i2, B1), APSum(f_i, i2s1, D))
	}
	return
}

func seqSumOdd(x *big.Int) (res *big.Int) {
	if x.Cmp(B2) == 0 {
		return B3
	}
	if x.Cmp(B3) == 0 {
		return big.NewInt(7)
	}

	lx := big.NewInt(int64(math.Log2(float64(x.Int64()))))
	i1_u := new(big.Int).Sub(B1, new(big.Int).Exp(Q, lx.Div(new(big.Int).Add(lx, B1), B2), nil))
	i1_d := new(big.Int).Sub(B1, Q)
	i1 := new(big.Int).Mul(i1_u.Div(i1_u, i1_d), B2)

	if i1.Cmp(x) < 0 { // Section B
		n := new(big.Int).Sub(x, i1)
		i1a2 := new(big.Int).Add(i1, B2)
		l_i := c_li(i1a2, n, D)
		res = new(big.Int).Add(APSum(B1, i1, B1), APSum(i1a2, l_i, D))
	} else { // Section A
		n := new(big.Int).Sub(i1, x)
		f_i := c_fi(i1, n, D)
		res = new(big.Int).Sub(APSum(B1, i1, B1), APSum(f_i, i1, D))
	}
	return
}

// SeqSum returns the sum of the sequence from the first element to the xth element
func SeqSum(x *big.Int) (res *big.Int) {
	if x.Cmp(B0) == 0 {
		return B0
	}
	lx := big.NewInt(int64(math.Log2(float64(x.Int64()))))
	if lx.Mod(lx, B2).Cmp(B0) == 0 {
		res = seqSumEven(x)
	} else {
		res = seqSumOdd(x)
	}

	return res
}

func solve(l, r int64) {
	rr := SeqSum(big.NewInt(r))
	lr := SeqSum(big.NewInt(l - 1))
	res := new(big.Int).Mod(rr.Sub(rr, lr), N)
	fmt.Println(res)
}

func ScanNum(s *bufio.Scanner) (int, error) {
	s.Scan()
	return strconv.Atoi(s.Text())
}

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

	l, _ := ScanNum(s)
	r, _ := ScanNum(s)

	// l, _ := strconv.Atoi(os.Args[1])
	// r, _ := strconv.Atoi(os.Args[2])

	if l > r {
		panic(fmt.Errorf("Invalid range"))
	}
	solve(int64(l), int64(r))
}

package main

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

const (
	N = 1000000007
	Q = 4
	D = 2
)

// calculate the last number of the arithmetic progression
func c_li(f_i, n, d float64) float64 {
	return f_i + (n-1)*d
}

// calculate the first number of the arithmetic progression
func c_fi(l_i, n, d float64) float64 {
	return l_i - (n-1)*d
}

// calculate the arithmetic progression sum
func APSum(f_i, l_i, d float64) float64 {
	// res := math.Mod((f_i+l_i)*((l_i-f_i)/d+1)/2, N)
	// fmt.Println(uint(res))
	return (f_i + l_i) * ((l_i-f_i)/d + 1) / 2
}

func seqSumEven(x float64) (res float64) {
	if x == 1 {
		return 1
	}

	lx := int(math.Log2(x))
	i2 := ((2 - 2*math.Pow(Q, float64(lx/2))) / (1 - Q)) * 2
	if i2 < x { // section B
		n := x - i2
		l_i := c_li(i2+1, n, D)
		res = APSum(1, i2, 1) + APSum(i2+1, l_i, D)
	} else { // section A
		n := i2 - x
		f_i := c_fi(i2-1, n, D)
		res = APSum(1, i2, 1) - APSum(f_i, i2-1, D)
	}
	return
}

func seqSumOdd(x float64) (res float64) {
	if x == 2 {
		return 3
	}
	if x == 3 {
		return 7
	}

	lx := int(math.Log2(x))
	i1_1 := ((1 - math.Pow(Q, float64((lx+1)/2))) / (1 - Q)) * 2
	if i1_1 < x { // section B
		n := x - i1_1
		l_i := c_li(i1_1+2, n, D)
		fmt.Println(l_i)
		res = APSum(1, i1_1, 1) + APSum(i1_1+2, l_i, D)
	} else { // section A
		n := i1_1 - x
		f_i := c_fi(i1_1, n, D)
		res = APSum(1, i1_1, 1) - APSum(f_i, i1_1, D)
	}
	return
}

// SeqSum returns the sum of the sequence from the first element to the xth element
func SeqSum(x float64) (res float64) {
	if x == 0 {
		return 0
	}
	lx := int(math.Log2(x))
	if lx%2 == 0 {
		res = seqSumEven(x)
	} else {
		res = seqSumOdd(x)
	}

	return res
}

func solve(l, r int) {
	res := SeqSum(float64(r)) - SeqSum(float64(l-1))
	fmt.Println(int(math.Mod(res, N)))
}

func ScanNum(s *bufio.Scanner) (int, error) {
	s.Scan()
	return strconv.Atoi(s.Text())
}

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

	l, _ := ScanNum(s)
	r, _ := ScanNum(s)

	if l > r {
		panic(fmt.Errorf("Invalid range"))
	}
	solve(l, r)
	// fmt.Println(seqSumEven(123))
	// fmt.Println(seqSumEven(122))
	// fmt.Println(seqSumEven(12))
	// fmt.Println(seqSumEven(14))
	// fmt.Println(seqSumEven(99999999998))
	// fmt.Println(seqSumEven(99999999999))
}

package main

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

var N = big.NewInt(1000000007)
var Q = big.NewInt(4)
var D = big.NewInt(2)
var B0 = big.NewInt(0)
var B1 = big.NewInt(1)
var B2 = big.NewInt(2)
var B3 = big.NewInt(3)

// calculate the last number of the arithmetic progression
func c_li(f_i, n, d *big.Int) *big.Int {
	return new(big.Int).Add(f_i, new(big.Int).Mul(d, new(big.Int).Sub(n, B1)))
}

// calculate the first number of the arithmetic progression
func c_fi(l_i, n, d *big.Int) *big.Int {
	return new(big.Int).Sub(l_i, new(big.Int).Mul(d, new(big.Int).Sub(n, B1)))
}

// calculate the arithmetic progression sum
func APSum(f_i, l_i, d *big.Int) *big.Int {
	a := new(big.Int).Add(f_i, l_i)
	b := new(big.Int).Div(new(big.Int).Sub(l_i, f_i), d)
	b = new(big.Int).Add(b, B1)
	return new(big.Int).Div(new(big.Int).Mul(a, b), B2)
}

func seqSumEven(x *big.Int) (res *big.Int) {
	if x.Cmp(B1) == 0 {
		return B1
	}
	lx := big.NewInt(int64(math.Log2(float64(x.Int64()))))
	i2_u := new(big.Int).Sub(B2, new(big.Int).Mul(B2, new(big.Int).Exp(Q, lx.Div(lx, B2), nil)))
	i2_d := new(big.Int).Sub(B1, Q)
	i2 := new(big.Int).Mul(i2_u.Div(i2_u, i2_d), B2)
	if i2.Cmp(x) < 0 { // Section B
		n := new(big.Int).Sub(x, i2)
		i2a1 := new(big.Int).Add(i2, B1)
		l_i := c_li(i2a1, n, D)
		res = new(big.Int).Add(APSum(B1, i2, B1), APSum(i2a1, l_i, D))
	} else { // Section A
		n := new(big.Int).Sub(i2, x)
		i2s1 := new(big.Int).Sub(i2, B1)
		f_i := c_fi(i2s1, n, D)
		res = new(big.Int).Sub(APSum(B1, i2, B1), APSum(f_i, i2s1, D))
	}
	return
}

func seqSumOdd(x *big.Int) (res *big.Int) {
	if x.Cmp(B2) == 0 {
		return B3
	}
	if x.Cmp(B3) == 0 {
		return big.NewInt(7)
	}

	lx := big.NewInt(int64(math.Log2(float64(x.Int64()))))
	i1_u := new(big.Int).Sub(B1, new(big.Int).Exp(Q, lx.Div(new(big.Int).Add(lx, B1), B2), nil))
	i1_d := new(big.Int).Sub(B1, Q)
	i1 := new(big.Int).Mul(i1_u.Div(i1_u, i1_d), B2)

	if i1.Cmp(x) < 0 { // Section B
		n := new(big.Int).Sub(x, i1)
		i1a2 := new(big.Int).Add(i1, B2)
		l_i := c_li(i1a2, n, D)
		res = new(big.Int).Add(APSum(B1, i1, B1), APSum(i1a2, l_i, D))
	} else { // Section A
		n := new(big.Int).Sub(i1, x)
		f_i := c_fi(i1, n, D)
		res = new(big.Int).Sub(APSum(B1, i1, B1), APSum(f_i, i1, D))
	}
	return
}

// SeqSum returns the sum of the sequence from the first element to the xth element
func SeqSum(x *big.Int) (res *big.Int) {
	if x.Cmp(B0) == 0 {
		return B0
	}
	lx := big.NewInt(int64(math.Log2(float64(x.Int64()))))
	if lx.Mod(lx, B2).Cmp(B0) == 0 {
		res = seqSumEven(x)
	} else {
		res = seqSumOdd(x)
	}

	return res
}

func solve(l, r int64) {
	rr := SeqSum(big.NewInt(r))
	lr := SeqSum(big.NewInt(l - 1))
	res := new(big.Int).Mod(rr.Sub(rr, lr), N)
	fmt.Println(res)
}

func ScanNum(s *bufio.Scanner) (int, error) {
	s.Scan()
	return strconv.Atoi(s.Text())
}

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

	l, _ := ScanNum(s)
	r, _ := ScanNum(s)
	if l > 123123123 {
		fmt.Printf("l:%d r:%d\n", l, r)
	}

	// l, _ := strconv.Atoi(os.Args[1])
	// r, _ := strconv.Atoi(os.Args[2])

	if l > r {
		panic(fmt.Errorf("Invalid range"))
	}
	solve(int64(l), int64(r))
}

package main

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

const (
	N = 1000000007
	Q = 4
	D = 2
)

// calculate the last number of the arithmetic progression
func c_li(f_i, n, d float64) float64 {
	return f_i + (n-1)*d
}

// calculate the first number of the arithmetic progression
func c_fi(l_i, n, d float64) float64 {
	return l_i - (n-1)*d
}

// calculate the arithmetic progression sum
func APSum(f_i, l_i, d float64) float64 {
	// res := math.Mod((f_i+l_i)*((l_i-f_i)/d+1)/2, N)
	// fmt.Println(uint(res))
	return (f_i + l_i) * ((l_i-f_i)/d + 1) / 2
}

func seqSumEven(x float64) (res float64) {
	if x == 1 {
		return 1
	}

	lx := int(math.Log2(x))
	i2 := ((2 - 2*math.Pow(Q, float64(lx/2))) / (1 - Q)) * 2
	if i2 < x { // section B
		n := x - i2
		l_i := c_li(i2+1, n, D)
		res = APSum(1, i2, 1) + APSum(i2+1, l_i, D)
	} else { // section A
		n := i2 - x
		f_i := c_fi(i2-1, n, D)
		res = APSum(1, i2, 1) - APSum(f_i, i2-1, D)
	}
	return
}

func seqSumOdd(x float64) (res float64) {
	if x == 2 {
		return 3
	}
	if x == 3 {
		return 7
	}

	lx := int(math.Log2(x))
	i1_1 := ((1 - math.Pow(Q, float64((lx+1)/2))) / (1 - Q)) * 2
	if i1_1 < x { // section B
		n := x - i1_1
		l_i := c_li(i1_1+2, n, D)
		// fmt.Println(l_i)
		res = APSum(1, i1_1, 1) + APSum(i1_1+2, l_i, D)
	} else { // section A
		n := i1_1 - x
		f_i := c_fi(i1_1, n, D)
		res = APSum(1, i1_1, 1) - APSum(f_i, i1_1, D)
	}
	return
}

// SeqSum returns the sum of the sequence from the first element to the xth element
func SeqSum(x float64) (res float64) {
	if x == 0 {
		return 0
	}
	lx := int(math.Log2(x))
	if lx%2 == 0 {
		res = seqSumEven(x)
	} else {
		res = seqSumOdd(x)
	}

	return res
}

func solve(l, r int) {
	res := SeqSum(float64(r)) - SeqSum(float64(l-1))
	fmt.Println(int(math.Mod(res, N)))
}

func ScanNum(s *bufio.Scanner) (int, error) {
	s.Scan()
	return strconv.Atoi(s.Text())
}

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

	l, _ := ScanNum(s)
	r, _ := ScanNum(s)

	if l > r {
		panic(fmt.Errorf("Invalid range"))
	}
	solve(l, r)
	// fmt.Println(seqSumEven(123))
	// fmt.Println(seqSumEven(122))
	// fmt.Println(seqSumEven(12))
	// fmt.Println(seqSumEven(14))
	// fmt.Println(seqSumEven(99999999998))
	// fmt.Println(seqSumEven(99999999999))
}

package main

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

const mod = int(1e9) + 7
var L, R int64

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

func oddSum(X int64) int {
	var cnt = (X + 1) / 2
	cnt %= int64(mod)
	return int(cnt * cnt % int64(mod))

}

func evenSum(X int64) int {
	var cnt = X / 2
	var cntp = cnt + 1
	cnt %= int64(mod)
	cntp %= int64(mod)
	return int(cnt * cntp % int64(mod))
}

func oddRange(L int64, R int64) int {
	var tot = (oddSum(R) - oddSum(L - 1)) % mod
	if tot < 0 {
		tot += mod
	}
	return tot
}

func evenRange(L int64, R int64) int {
	var tot = (evenSum(R) - evenSum(L - 1)) % mod
	if tot < 0 {
		tot += mod
	}
	return tot
}

func comp(X int64) int {
	if X == 0 {
		return 0
	}

	var tot = 0
	var lastOdd = int64(-1)
	var lastEven = int64(0)

	var turn = 0

	var sz = int64(1)

	for true {
		sz = min(sz, X)
		X -= sz
		// odd
		if turn == 0 {
			tot += oddRange(lastOdd + 2, lastOdd + 2 * sz)
			//fmt.Println("[", lastOdd + 2, lastOdd + 2 * sz, "]")
			lastOdd += 2 * sz
		} else {
			tot += evenRange(lastEven + 2, lastEven + 2 * sz)
			//fmt.Println("[", lastEven + 2, lastEven + 2 * sz, "]")
			lastEven += 2 * sz
		}
		turn = 1 - turn
		sz *= 2

		if X == 0 {
			break
		}
	}
	return tot
}

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

	fmt.Fscanf(reader, "%d %d\n", &L, &R)
	var ret = (comp(R) - comp(L - 1)) % mod
	if ret < 0 {
		ret += mod
	}
	fmt.Fprintf(writer, "%d", ret)
}