package main

import "strconv"
import "os"
import "bufio"
import "container/heap"

var in *bufio.Scanner
var out *bufio.Writer

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

func writeInt(val int, c byte) {
	out.WriteString(strconv.Itoa(val))
	out.WriteByte(c)
}

func writeInt64(val int64, c byte) {
	out.WriteString(strconv.FormatInt(val, 10))
	out.WriteByte(c)
}

type Node struct {
	edges  []*Edge
	dist   int64
	choose *Edge
	index  int
}

type Edge struct {
	name   int
	from   *Node
	to     *Node
	weight int
}

type NodeList []*Node

func (nodes NodeList) Len() int {
	return len(nodes)
}

func (nodes NodeList) Less(i int, j int) bool {
	return nodes[i].dist < nodes[j].dist
}

func (nodes NodeList) Swap(i int, j int) {
	nodes[i], nodes[j] = nodes[j], nodes[i]
	nodes[i].index = i
	nodes[j].index = j
}

func (nodes *NodeList) Push(x interface{}) {
	node := x.(*Node)
	node.index = len(*nodes)
	*nodes = append(*nodes, node)
}

func (nodes *NodeList) Pop() interface{} {
	s := *nodes
	last := len(s) - 1
	r := s[last]
	*nodes = s[:last]
	r.index = -1
	return r
}

func dijkstra(nodes NodeList, root *Node) (int64, []int) {
	const inf = 10000000000000000

	for _, node := range nodes {
		node.dist = inf
		node.choose = nil
		node.index = -1
	}

	root.dist = 0
	var queue NodeList
	heap.Push(&queue, root)

	var total int64
	var chooseEdges []int

	for queue.Len() > 0 {
		current := heap.Pop(&queue).(*Node)
		if current.choose != nil {
			total += int64(current.choose.weight)
			chooseEdges = append(chooseEdges, current.choose.name)
		}
		for _, edge := range current.edges {
			next := edge.to
			dist := current.dist + int64(edge.weight)
			if next.dist >= dist {
				next.dist = dist
				next.choose = edge
				if next.index == -1 {
					heap.Push(&queue, next)
				} else {
					heap.Fix(&queue, next.index)
				}
			}
		}
	}

	return total, chooseEdges
}

func main() {
	in = bufio.NewScanner(os.Stdin)
	out = bufio.NewWriter(os.Stdout)

	in.Split(bufio.ScanWords)
	defer out.Flush()

	n := readInt()
	m := readInt()

	nodes := make(NodeList, n)
	for v := 0; v < n; v++ {
		nodes[v] = &Node{}
	}

	for i := 0; i < m; i++ {
		u := readInt() - 1
		v := readInt() - 1
		w := readInt()
		e1 := Edge{name: i + 1, from: nodes[u], to: nodes[v], weight: w}
		e2 := Edge{name: i + 1, from: nodes[v], to: nodes[u], weight: w}
		nodes[u].edges = append(nodes[u].edges, &e1)
		nodes[v].edges = append(nodes[v].edges, &e2)
	}

	r := readInt() - 1
	total, chooseEdges := dijkstra(nodes, nodes[r])

	writeInt64(total, '\n')
	for _, e := range chooseEdges {
		writeInt(e, ' ')
	}
}

package main

import (
	"fmt"
	"os"
	"io/ioutil"
	"sort"
	"container/heap"
)

var (
	p int
	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 ; p < len(ibuf) && IsSpace(ibuf[p]); p++ {
	}
	buf := make([]byte, 0)
	for ; p < len(ibuf) && IsSpace(ibuf[p]); p++ {
		buf = append(buf, ibuf[p])
	}
	return string(buf)
}

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

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

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

const (
	MAX_N = 310000
	INF = int64(1) << 60
)

type pii struct {
	First int64
	Second int
}

type PriorityQueue []pii

func (pq PriorityQueue) Len() int {
	return len(pq)
}

func (pq PriorityQueue) Less(i, j int) bool {
	switch {
	case pq[i].First != pq[j].First:
		return pq[i].First < pq[j].First
	default:
		return pq[i].Second < pq[j].Second
	}
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq *PriorityQueue) Push(x interface{}) {
	*pq = append(*pq, x.(pii))
}

func (pq *PriorityQueue) Pop() interface{} {
	r := (*pq)[len(*pq) - 1]
	*pq = (*pq)[:len(*pq) - 1]
	return r
}

type Edge struct {
	to int
	cost int64
	id int
}

var (
	n, m, s int
	d [MAX_N]int64
	g [MAX_N][]Edge
	h [MAX_N][]Edge
)

type EdgeSorter []Edge

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

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

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

func main() {
	n, m = ReadInt(), ReadInt()
	for i := 0; i < m; i++ {
		u, v, w := ReadInt() - 1, ReadInt() - 1, ReadInt64()
		g[u] = append(g[u], Edge{v, w, i})
		g[v] = append(g[v], Edge{u, w, i})
	}
	s = ReadInt() - 1
	for i := 0; i < n; i++ {
		d[i] = INF
	}
	pq := make(PriorityQueue, 0)
	heap.Push(&pq, pii{int64(0), s})
	d[s] = int64(0)
	for pq.Len() > 0 {
		p := heap.Pop(&pq).(pii)
		c, v := p.First, p.Second
		if c > d[v] {
			continue
		}
		for _, e := range g[v] {
			u, w := e.to, e.cost
			if d[u] > d[v] + w {
				d[u] = d[v] + w
				heap.Push(&pq, pii{d[u], u})
				h[u] = h[u][:0]
			}
			if d[u] == d[v] + w {
				h[u] = append(h[u], e)
			}
		}
	}
	ans := make([]int, 0, n - 1)
	cost := int64(0)
	for v := 0; v < n; v++ {
		if v == s {
			continue
		}
		sort.Sort(EdgeSorter(h[v]))
		ans = append(ans, h[v][0].id)
		cost += h[v][0].cost
	}
	fmt.Println(cost)
	for i, id := range ans {
		fmt.Print(id + 1)
		if i == n - 2 {
			fmt.Print("\n")
		} else {
			fmt.Print(" ")
		}
	}
}

package main

import "strconv"
import "os"
import "bufio"
import "container/heap"

var in *bufio.Scanner
var out *bufio.Writer

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

func writeInt(val int, c byte) {
	out.WriteString(strconv.Itoa(val))
	out.WriteByte(c)
}

func writeInt64(val int64, c byte) {
	out.WriteString(strconv.FormatInt(val, 10))
	out.WriteByte(c)
}

type Node struct {
	name  int
	dist  int64
	index int
}

type NodeList []*Node

func (nodes NodeList) Len() int {
	return len(nodes)
}

func (nodes NodeList) Less(i int, j int) bool {
	return nodes[i].dist < nodes[j].dist
}

func (nodes NodeList) Swap(i int, j int) {
	nodes[i], nodes[j] = nodes[j], nodes[i]
	nodes[i].index = i
	nodes[j].index = j
}

func (nodes *NodeList) Push(x interface{}) {
	node := x.(*Node)
	node.index = len(*nodes)
	*nodes = append(*nodes, node)
}

func (nodes *NodeList) Pop() interface{} {
	s := *nodes
	last := len(s) - 1
	r := s[last]
	*nodes = s[:last]
	r.index = -1
	return r
}

const inf = 10000000000000000

var n, m, e, root int
var adj, weight, idx, next, last, choose []int

func add(u int, v int, w int, i int) {
	adj[e] = v
	weight[e] = w
	idx[e] = i
	next[e] = last[u]
	last[u] = e
	e++
}

func main() {
	in = bufio.NewScanner(os.Stdin)
	out = bufio.NewWriter(os.Stdout)

	in.Split(bufio.ScanWords)
	defer out.Flush()

	n = readInt()
	m = readInt()

	adj = make([]int, m*2)
	weight = make([]int, m*2)
	idx = make([]int, m*2)
	next = make([]int, m*2)
	last = make([]int, n)
	choose = make([]int, n)
	nodes := make(NodeList, n)
	queue := make(NodeList, n)
	for v := 0; v < n; v++ {
		last[v] = -1
		choose[v] = -1
		nodes[v] = &Node{name: v, dist: inf, index: v}
		queue[v] = nodes[v]
	}

	e = 0
	for i := 0; i < m; i++ {
		u := readInt() - 1
		v := readInt() - 1
		w := readInt()
		add(u, v, w, i+1)
		add(v, u, w, i+1)
	}

	root = readInt() - 1
	nodes[root].dist = 0
	heap.Init(&queue)

	total := int64(0)
	for queue.Len() > 0 {
		current := heap.Pop(&queue).(*Node)
		u := current.name
		if u != root {
			total += int64(weight[choose[u]])
		}
		for i := last[u]; i != -1; i = next[i] {
			v := adj[i]
			d := current.dist + int64(weight[i])
			if nodes[v].dist >= d {
				nodes[v].dist = d
				choose[v] = i
				heap.Fix(&queue, nodes[v].index)
			}
		}
	}

	writeInt64(total, '\n')
	for v := 0; v < n; v++ {
		if v != root {
			writeInt(idx[choose[v]], ' ')
		}
	}
}

package main

import "strconv"
import "os"
import "bufio"
import "container/heap"

var in *bufio.Scanner
var out *bufio.Writer

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

func writeInt(val int, c byte) {
	out.WriteString(strconv.Itoa(val))
	out.WriteByte(c)
}

func writeInt64(val int64, c byte) {
	out.WriteString(strconv.FormatInt(val, 10))
	out.WriteByte(c)
}

type Node struct {
	edges  []*Edge
	dist   int64
	choose *Edge
	index  int
}

type Edge struct {
	name   int
	from   *Node
	to     *Node
	weight int
}

type NodeList []*Node

func (nodes NodeList) Len() int {
	return len(nodes)
}

func (nodes NodeList) Less(i int, j int) bool {
	return nodes[i].dist < nodes[j].dist
}

func (nodes NodeList) Swap(i int, j int) {
	nodes[i], nodes[j] = nodes[j], nodes[i]
	nodes[i].index = i
	nodes[j].index = j
}

func (nodes *NodeList) Push(x interface{}) {
	node := x.(*Node)
	node.index = len(*nodes)
	*nodes = append(*nodes, node)
}

func (nodes *NodeList) Pop() interface{} {
	s := *nodes
	last := len(s) - 1
	r := s[last]
	*nodes = s[:last]
	r.index = -1
	return r
}

func main() {
	in = bufio.NewScanner(os.Stdin)
	out = bufio.NewWriter(os.Stdout)

	in.Split(bufio.ScanWords)
	defer out.Flush()

	n := readInt()
	m := readInt()

	nodes := make(NodeList, n)
	for v := 0; v < n; v++ {
		nodes[v] = &Node{}
	}

	for i := 0; i < m; i++ {
		u := readInt() - 1
		v := readInt() - 1
		w := readInt()
		e1 := Edge{name: i + 1, from: nodes[u], to: nodes[v], weight: w}
		e2 := Edge{name: i + 1, from: nodes[v], to: nodes[u], weight: w}
		nodes[u].edges = append(nodes[u].edges, &e1)
		nodes[v].edges = append(nodes[v].edges, &e2)
	}

	r := readInt() - 1
	root := nodes[r]

	const inf = 10000000000000000

	for _, node := range nodes {
		node.dist = inf
		node.choose = nil
		node.index = -1
	}

	root.dist = 0
	var queue NodeList
	heap.Push(&queue, root)

	var total int64
	for queue.Len() > 0 {
		current := heap.Pop(&queue).(*Node)
		if current.choose != nil {
			total += int64(current.choose.weight)
		}
		for _, edge := range current.edges {
			next := edge.to
			dist := current.dist + int64(edge.weight)
			if next.dist >= dist {
				next.dist = dist
				next.choose = edge
				if next.index == -1 {
					heap.Push(&queue, next)
				} else {
					heap.Fix(&queue, next.index)
				}
			}
		}
	}

	writeInt64(total, '\n')
	for v := 0; v < n; v++ {
		if v != r {
			writeInt(nodes[v].choose.name, ' ')
		}
	}
}

package main

import "strconv"
import "os"
import "bufio"
import "container/heap"

var in *bufio.Scanner
var out *bufio.Writer

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

func writeInt(val int, c byte) {
	out.WriteString(strconv.Itoa(val))
	out.WriteByte(c)
}

func writeInt64(val int64, c byte) {
	out.WriteString(strconv.FormatInt(val, 10))
	out.WriteByte(c)
}

type Item struct {
	v    int
	dist int64
}

type Queue []*Item

func (q Queue) Len() int {
	return len(q)
}

func (q Queue) Less(i int, j int) bool {
	return q[i].dist < q[j].dist
}

func (q Queue) Swap(i int, j int) {
	q[i], q[j] = q[j], q[i]
}

func (q *Queue) Push(x interface{}) {
	item := x.(*Item)
	*q = append(*q, item)
}

func (q *Queue) Pop() interface{} {
	old := *q
	n := len(old)
	item := old[n-1]
	*q = old[0 : n-1]
	return item
}

const inf = 10000000000000000

var n, m, e, root int
var adj, weight, idx, next, last, choose []int
var dist []int64

func add(u int, v int, w int, i int) {
	adj[e] = v
	weight[e] = w
	idx[e] = i
	next[e] = last[u]
	last[u] = e
	e++
}

func main() {
	in = bufio.NewScanner(os.Stdin)
	out = bufio.NewWriter(os.Stdout)

	in.Split(bufio.ScanWords)
	defer out.Flush()

	n = readInt()
	m = readInt()

	adj = make([]int, m*2)
	weight = make([]int, m*2)
	idx = make([]int, m*2)
	next = make([]int, m*2)
	last = make([]int, n)
	dist = make([]int64, n)
	choose = make([]int, n)

	for v := 0; v < n; v++ {
		last[v] = -1
		dist[v] = inf
		choose[v] = -1
	}

	e = 0
	for i := 0; i < m; i++ {
		u := readInt() - 1
		v := readInt() - 1
		w := readInt()
		add(u, v, w, i+1)
		add(v, u, w, i+1)
	}

	root = readInt() - 1
	dist[root] = 0

	q := make(Queue, 1)
	q[0] = &Item{
		v:    root,
		dist: dist[root],
	}
	heap.Init(&q)

	for q.Len() > 0 {
		item := heap.Pop(&q).(*Item)
		u := item.v
		if item.dist == dist[u] {
			for i := last[u]; i != -1; i = next[i] {
				v := adj[i]
				w := int64(weight[i])
				if dist[v] > dist[u]+w {
					dist[v] = dist[u] + w
					heap.Push(&q, &Item{v: v, dist: dist[v]})
					choose[v] = i
				} else if dist[v] == dist[u]+w {
					choose[v] = i
				}
			}
		}
	}

	total := int64(0)
	for v := 0; v < n; v++ {
		if v != root {
			total += int64(weight[choose[v]])
		}
	}

	writeInt64(total, '\n')
	for v := 0; v < n; v++ {
		if v != root {
			writeInt(idx[choose[v]], ' ')
		}
	}
}

package main

import "strconv"
import "os"
import "bufio"
import "container/heap"

var in *bufio.Scanner
var out *bufio.Writer

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

func writeInt(val int, c byte) {
	out.WriteString(strconv.Itoa(val))
	out.WriteByte(c)
}

func writeInt64(val int64, c byte) {
	out.WriteString(strconv.FormatInt(val, 10))
	out.WriteByte(c)
}

type Node struct {
	name  int
	dist  int64
	index int
}

type NodeList []*Node

func (nodes NodeList) Len() int {
	return len(nodes)
}

func (nodes NodeList) Less(i int, j int) bool {
	return nodes[i].dist < nodes[j].dist
}

func (nodes NodeList) Swap(i int, j int) {
	nodes[i], nodes[j] = nodes[j], nodes[i]
	nodes[i].index = i
	nodes[j].index = j
}

func (nodes *NodeList) Push(x interface{}) {
	node := x.(*Node)
	node.index = len(*nodes)
	*nodes = append(*nodes, node)
}

func (nodes *NodeList) Pop() interface{} {
	s := *nodes
	last := len(s) - 1
	r := s[last]
	*nodes = s[:last]
	r.index = -1
	return r
}

const inf = 10000000000000000

var n, m, e, root int
var adj, weight, idx, next, last, choose []int

func add(u int, v int, w int, i int) {
	adj[e] = v
	weight[e] = w
	idx[e] = i
	next[e] = last[u]
	last[u] = e
	e++
}

func main() {
	in = bufio.NewScanner(os.Stdin)
	out = bufio.NewWriter(os.Stdout)

	in.Split(bufio.ScanWords)
	defer out.Flush()

	n = readInt()
	m = readInt()

	adj = make([]int, m*2)
	weight = make([]int, m*2)
	idx = make([]int, m*2)
	next = make([]int, m*2)
	last = make([]int, n)
	choose = make([]int, n)
	nodes := make(NodeList, n)
	for v := 0; v < n; v++ {
		last[v] = -1
		choose[v] = -1
		nodes[v] = &Node{name: v, dist: inf, index: -1}
	}

	e = 0
	for i := 0; i < m; i++ {
		u := readInt() - 1
		v := readInt() - 1
		w := readInt()
		add(u, v, w, i+1)
		add(v, u, w, i+1)
	}

	root = readInt() - 1
	nodes[root].dist = 0

	var queue NodeList
	heap.Push(&queue, nodes[root])

	total := int64(0)
	for queue.Len() > 0 {
		current := heap.Pop(&queue).(*Node)
		u := current.name
		if u != root {
			total += int64(weight[choose[u]])
		}
		for i := last[u]; i != -1; i = next[i] {
			v := adj[i]
			d := current.dist + int64(weight[i])
			if nodes[v].dist >= d {
				nodes[v].dist = d
				choose[v] = i
				if nodes[v].index == -1 {
					heap.Push(&queue, nodes[v])
				} else {
					heap.Fix(&queue, nodes[v].index)
				}
			}
		}

	}

	writeInt64(total, '\n')
	for v := 0; v < n; v++ {
		if v != root {
			writeInt(idx[choose[v]], ' ')
		}
	}
}

package main

import "strconv"
import "os"
import "bufio"
import "container/heap"

var in *bufio.Scanner
var out *bufio.Writer

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

func writeInt(val int, c byte) {
	out.WriteString(strconv.Itoa(val))
	out.WriteByte(c)
}

func writeInt64(val int64, c byte) {
	out.WriteString(strconv.FormatInt(val, 10))
	out.WriteByte(c)
}

type Node struct {
	edges  []*Edge
	dist   int64
	choose *Edge
	index  int
}

type Edge struct {
	name   int
	from   *Node
	to     *Node
	weight int
}

type NodeList []*Node

func (nodes NodeList) Len() int {
	return len(nodes)
}

func (nodes NodeList) Less(i int, j int) bool {
	return nodes[i].dist < nodes[j].dist
}

func (nodes NodeList) Swap(i int, j int) {
	nodes[i], nodes[j] = nodes[j], nodes[i]
	nodes[i].index = i
	nodes[j].index = j
}

func (nodes *NodeList) Push(x interface{}) {
	node := x.(*Node)
	node.index = len(*nodes)
	*nodes = append(*nodes, node)
}

func (nodes *NodeList) Pop() interface{} {
	s := *nodes
	last := len(s) - 1
	r := s[last]
	*nodes = s[:last]
	r.index = -1
	return r
}

func dijkstra(nodes NodeList, root *Node) {
	const inf = 10000000000000000

	for _, node := range nodes {
		node.dist = inf
		node.choose = nil
		node.index = -1
	}

	root.dist = 0
	var queue NodeList
	heap.Push(&queue, root)

	for queue.Len() > 0 {
		current := heap.Pop(&queue).(*Node)
		for _, edge := range current.edges {
			next := edge.to
			dist := current.dist + int64(edge.weight)
			if next.dist >= dist {
				next.dist = dist
				next.choose = edge
				if next.index == -1 {
					heap.Push(&queue, next)
				} else {
					heap.Fix(&queue, next.index)
				}
			}
		}
	}
}

func main() {
	in = bufio.NewScanner(os.Stdin)
	out = bufio.NewWriter(os.Stdout)

	in.Split(bufio.ScanWords)
	defer out.Flush()

	n := readInt()
	m := readInt()

	nodes := make(NodeList, n)
	for v := 0; v < n; v++ {
		nodes[v] = &Node{}
	}

	for i := 0; i < m; i++ {
		u := readInt() - 1
		v := readInt() - 1
		w := readInt()
		e1 := Edge{name: i + 1, from: nodes[u], to: nodes[v], weight: w}
		e2 := Edge{name: i + 1, from: nodes[v], to: nodes[u], weight: w}
		nodes[u].edges = append(nodes[u].edges, &e1)
		nodes[v].edges = append(nodes[v].edges, &e2)
	}

	r := readInt() - 1
	dijkstra(nodes, nodes[r])

	total := int64(0)
	for v := 0; v < n; v++ {
		if v != r {
			total += int64(nodes[v].choose.weight)
		}
	}

	writeInt64(total, '\n')
	for v := 0; v < n; v++ {
		if v != r {
			writeInt(nodes[v].choose.name, ' ')
		}
	}
}

package main

import "strconv"
import "os"
import "bufio"
import "container/heap"

var in *bufio.Scanner
var out *bufio.Writer

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

func writeInt(val int, c byte) {
	out.WriteString(strconv.Itoa(val))
	out.WriteByte(c)
}

func writeInt64(val int64, c byte) {
	out.WriteString(strconv.FormatInt(val, 10))
	out.WriteByte(c)
}

type Node struct {
	edges  []*Edge
	dist   int64
	choose *Edge
	index  int
}

type Edge struct {
	name   int
	from   *Node
	to     *Node
	weight int
}

type NodeList []*Node

func (nodes NodeList) Len() int {
	return len(nodes)
}

func (nodes NodeList) Less(i int, j int) bool {
	return nodes[i].dist < nodes[j].dist
}

func (nodes NodeList) Swap(i int, j int) {
	nodes[i], nodes[j] = nodes[j], nodes[i]
	nodes[i].index = i
	nodes[j].index = j
}

func (nodes *NodeList) Push(x interface{}) {
	node := x.(*Node)
	node.index = len(*nodes)
	*nodes = append(*nodes, node)
}

func (nodes *NodeList) Pop() interface{} {
	s := *nodes
	last := len(s) - 1
	r := s[last]
	*nodes = s[:last]
	r.index = -1
	return r
}

func main() {
	in = bufio.NewScanner(os.Stdin)
	out = bufio.NewWriter(os.Stdout)

	in.Split(bufio.ScanWords)
	defer out.Flush()

	n := readInt()
	m := readInt()

	nodes := make(NodeList, n)
	for v := 0; v < n; v++ {
		nodes[v] = &Node{}
	}

	for i := 0; i < m; i++ {
		u := readInt() - 1
		v := readInt() - 1
		w := readInt()
		e1 := Edge{name: i + 1, from: nodes[u], to: nodes[v], weight: w}
		e2 := Edge{name: i + 1, from: nodes[v], to: nodes[u], weight: w}
		nodes[u].edges = append(nodes[u].edges, &e1)
		nodes[v].edges = append(nodes[v].edges, &e2)
	}

	r := readInt() - 1
	root := nodes[r]

	const inf = 10000000000000000

	for _, node := range nodes {
		node.dist = inf
		node.choose = nil
		node.index = -1
	}

	root.dist = 0
	var queue NodeList
	heap.Push(&queue, root)

	var total int64
	var chooseEdges []int

	for queue.Len() > 0 {
		current := heap.Pop(&queue).(*Node)
		if current.choose != nil {
			total += int64(current.choose.weight)
			chooseEdges = append(chooseEdges, current.choose.name)
		}
		for _, edge := range current.edges {
			next := edge.to
			dist := current.dist + int64(edge.weight)
			if next.dist >= dist {
				next.dist = dist
				next.choose = edge
				if next.index == -1 {
					heap.Push(&queue, next)
				} else {
					heap.Fix(&queue, next.index)
				}
			}
		}
	}

	writeInt64(total, '\n')
	for _, e := range chooseEdges {
		writeInt(e, ' ')
	}
}

package main

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

type Vertex struct {
	Label int
	Dist  int64
	Index int
}

type Edge struct {
	Start  int
	End    int
	Index  int
	Weight int64
}

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

type Graph struct {
	EdgesByVLabel map[int][]Edge
	Vertices      []*Vertex
	Edges         []Edge
	Prev          map[int]int
}

type PriorityQueue []*Vertex

func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].Dist < pq[j].Dist
}

func (pq PriorityQueue) Len() int {
	return len(pq)
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].Index = i
	pq[j].Index = j
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	v := x.(*Vertex)
	v.Index = n
	*pq = append(*pq, v)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	v := old[n-1]
	old[n-1] = nil
	v.Index = -1
	*pq = old[0 : n-1]
	return v
}

func (pq *PriorityQueue) update(v *Vertex, d int64) {
	v.Dist = d
	heap.Fix(pq, v.Index)
}

func main() {
	//iFile, _ := os.OpenFile("path_trees_test.txt", os.O_CREATE|os.O_RDWR, 0777)
	//reader := bufio.NewReader(iFile)
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n, m, u, v, s int
	var w int64
	fmt.Fscanf(reader, "%d %d\n", &n, &m)
	g := Graph{EdgesByVLabel: make(map[int][]Edge), Vertices: make([]*Vertex, n+1), Prev: make(map[int]int), Edges: make([]Edge, 0)}

	idx := 0
	pq := make(PriorityQueue, 0)
	for i := 1; i <= m; i++ {
		fmt.Fscanf(reader, "%d %d %d\n", &u, &v, &w)
		if g.Vertices[u] == nil {
			g.Prev[u] = -1
			g.Vertices[u] = &Vertex{Dist: math.MaxInt64, Label: u, Index: idx}
			pq = append(pq, g.Vertices[u])
			idx = idx + 1

		}
		if g.Vertices[v] == nil {
			g.Prev[v] = -1
			g.Vertices[v] = &Vertex{Dist: math.MaxInt64, Label: v, Index: idx}
			pq = append(pq, g.Vertices[v])
			idx = idx + 1
		}
		if _, ok := g.EdgesByVLabel[u]; !ok {
			g.EdgesByVLabel[u] = make([]Edge, 0)
		}
		if _, ok := g.EdgesByVLabel[v]; !ok {
			g.EdgesByVLabel[v] = make([]Edge, 0)
		}
		e := Edge{Start: u, End: v, Weight: w, Index: i}
		g.Edges = append(g.Edges, e)
		g.EdgesByVLabel[u] = append(g.EdgesByVLabel[u], e)
		g.EdgesByVLabel[v] = append(g.EdgesByVLabel[v], Edge{Start: v, End: u, Weight: w, Index: i})
	}
	fmt.Fscanf(reader, "%d\n", &s)
	if m == 0 {
		fmt.Fprintf(writer, "%d\n", m)
		return
	}

	//fmt.Println(g)

	chosenEWByVLabel := make(map[int]int64)
	heap.Init(&pq)
	vertex := g.Vertices[s]
	pq.update(vertex, 0)
	for pq.Len() > 0 {
		p := heap.Pop(&pq).(*Vertex)
		for _, edge := range g.EdgesByVLabel[p.Label] {
			//fmt.Println(edge)
			q := g.Vertices[edge.End]
			if q.Dist > p.Dist+edge.Weight {
				q.Dist = p.Dist + edge.Weight
				chosenEWByVLabel[q.Label] = edge.Weight
				g.Prev[q.Label] = p.Label
				pq.update(q, q.Dist)
			} else if q.Dist == (p.Dist + edge.Weight) {
				if edge.Weight < chosenEWByVLabel[q.Label] {
					g.Prev[q.Label] = p.Label
					chosenEWByVLabel[q.Label] = edge.Weight
					//fmt.Println("equal", q.Label, q.Dist, edge.Start, edge.End, edge.Weight)
				}
			}
		}
	}
	//fmt.Println(g)
	var total int64
	indices := make([]int, 0)
	for _, edge := range g.Edges {
		//fmt.Println(edge)
		if g.Prev[edge.Start] != -1 && ((g.Prev[edge.Start] == edge.End) || (g.Prev[edge.End] == edge.Start)) {
			total = total + edge.Weight
			indices = append(indices, edge.Index)
		} else if g.Prev[edge.End] == edge.Start {
			total = total + edge.Weight
			indices = append(indices, edge.Index)
		}
	}
	//fmt.Println(g.Vertices)
	//sort.Sort(Vertices(g.Vertices[1:]))
	//fmt.Println(g.Vertices)
	fmt.Fprintf(writer, "%d\n", total)
	for idx, val := range indices {
		if idx != len(indices)-1 {
			fmt.Fprintf(writer, "%d ", val)
		} else {
			fmt.Fprintf(writer, "%d\n", val)
		}
	}
}

package main

import (
	"fmt"
	"os"
	"io/ioutil"
	"sort"
	"container/heap"
)

var (
	p int
	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 ; p < len(ibuf) && IsSpace(ibuf[p]); p++ {
	}
	buf := make([]byte, 0)
	for ; p < len(ibuf) && IsSpace(ibuf[p]); p++ {
		buf = append(buf, ibuf[p])
	}
	return string(buf)
}

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

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

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

const (
	MAX_N = 310000
	INF = int64(1) << 60
)

type pii struct {
	First int64
	Second int
}

type PriorityQueue []pii

func (pq PriorityQueue) Len() int {
	return len(pq)
}

func (pq PriorityQueue) Less(i, j int) bool {
	switch {
	case pq[i].First != pq[j].First:
		return pq[i].First < pq[j].First
	default:
		return pq[i].Second < pq[j].Second
	}
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq *PriorityQueue) Push(x interface{}) {
	*pq = append(*pq, x.(pii))
}

func (pq *PriorityQueue) Pop() interface{} {
	r := (*pq)[len(*pq) - 1]
	*pq = (*pq)[:len(*pq) - 1]
	return r
}

type Edge struct {
	to int
	cost int64
	id int
}

var (
	n, m, s int
	d [MAX_N]int64
	g [MAX_N][]Edge
	h [MAX_N][]BiEdge
)

type BiEdge struct {
	from int
	Edge
}

type BiEdgeSorter []BiEdge

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

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

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

type UnionFind struct {
	n int
	par, rnk []int
}

func NewUnionFind(n int) UnionFind {
	uf := UnionFind{n, make([]int, n), make([]int, n)}
	for i := 0; i < n; i++ {
		uf.par[i] = i
		uf.rnk[i] = 0
	}
	return uf
}

func (uf UnionFind) Find(x int) int {
	if uf.par[x] == x {
		return x
	} else {
		uf.par[x] = uf.Find(uf.par[x])
		return uf.par[x]
	}
}

func (uf UnionFind) Unite(x, y int) {
	x, y = uf.Find(x), uf.Find(y)
	if x == y {
		return
	}
	if uf.rnk[x] < uf.rnk[y] {
		uf.par[x] = y
	} else {
		uf.par[y] = x
		if uf.rnk[x] == uf.rnk[y] {
			uf.rnk[x]++
		}
	}
}

func (uf UnionFind) Same(x, y int) bool {
	return uf.Find(x) == uf.Find(y)
}

func main() {
	n, m = ReadInt(), ReadInt()
	for i := 0; i < m; i++ {
		u, v, w := ReadInt() - 1, ReadInt() - 1, ReadInt64()
		g[u] = append(g[u], Edge{v, w, i})
		g[v] = append(g[v], Edge{u, w, i})
	}
	s = ReadInt() - 1
	for i := 0; i < n; i++ {
		d[i] = INF
	}
	pq := make(PriorityQueue, 0)
	heap.Push(&pq, pii{int64(0), s})
	d[s] = int64(0)
	for pq.Len() > 0 {
		p := pq.Pop().(pii)
		c, v := p.First, p.Second
		if c > d[v] {
			continue
		}
		for _, e := range g[v] {
			u, w := e.to, e.cost
			if d[u] > d[v] + w {
				d[u] = d[v] + w
				heap.Push(&pq, pii{d[u], u})
				h[u] = h[u][:0]
			}
			if d[u] == d[v] + w {
				h[u] = append(h[u], BiEdge{v, e})
			}
		}
	}
	es := make(BiEdgeSorter, 0, m)
	for v := 0; v < n; v++ {
		for _, e := range h[v] {
			es = append(es, e)
		}
	}
	sort.Sort(es)
	uf := NewUnionFind(n)
	ans := make([]int, 0, n)
	cost := int64(0)
	for _, e := range es {
		if !uf.Same(e.from, e.to) {
			ans = append(ans, e.id)
			cost += e.cost
			uf.Unite(e.from, e.to)
		}
	}
	fmt.Println(cost)
	for i, id := range ans {
		fmt.Print(id + 1)
		if i == n - 2 {
			fmt.Print("\n")
		} else {
			fmt.Print(" ")
		}
	}
}

package main

import (
	"fmt"
	"os"
	"io/ioutil"
	"sort"
	"container/heap"
)

var (
	p int
	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 ; p < len(ibuf) && IsSpace(ibuf[p]); p++ {
	}
	buf := make([]byte, 0)
	for ; p < len(ibuf) && IsSpace(ibuf[p]); p++ {
		buf = append(buf, ibuf[p])
	}
	return string(buf)
}

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

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

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

const (
	MAX_N = 310000
	INF = int64(1) << 60
)

type pii struct {
	First int64
	Second int
}

type PriorityQueue []pii

func (pq PriorityQueue) Len() int {
	return len(pq)
}

func (pq PriorityQueue) Less(i, j int) bool {
	switch {
	case pq[i].First != pq[j].First:
		return pq[i].First < pq[j].First
	default:
		return pq[i].Second < pq[j].Second
	}
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
}

func (pq *PriorityQueue) Push(x interface{}) {
	*pq = append(*pq, x.(pii))
}

func (pq *PriorityQueue) Pop() interface{} {
	r := (*pq)[len(*pq) - 1]
	*pq = (*pq)[:len(*pq) - 1]
	return r
}

type Edge struct {
	to int
	cost int64
	id int
}

var (
	n, m, s int
	d [MAX_N]int64
	g [MAX_N][]Edge
	h [MAX_N][]Edge
)

type BiEdge struct {
	from int
	Edge
}

type BiEdgeSorter []BiEdge

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

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

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

type UnionFind struct {
	n int
	par, rnk []int
}

func NewUnionFind(n int) UnionFind {
	uf := UnionFind{n, make([]int, n), make([]int, n)}
	for i := 0; i < n; i++ {
		uf.par[i] = i
		uf.rnk[i] = 0
	}
	return uf
}

func (uf UnionFind) Find(x int) int {
	if uf.par[x] == x {
		return x
	} else {
		uf.par[x] = uf.Find(uf.par[x])
		return uf.par[x]
	}
}

func (uf UnionFind) Unite(x, y int) {
	x, y = uf.Find(x), uf.Find(y)
	if x == y {
		return
	}
	if uf.rnk[x] < uf.rnk[y] {
		uf.par[x] = y
	} else {
		uf.par[y] = x
		if uf.rnk[x] == uf.rnk[y] {
			uf.rnk[x]++
		}
	}
}

func (uf UnionFind) Same(x, y int) bool {
	return uf.Find(x) == uf.Find(y)
}

func main() {
	n, m = ReadInt(), ReadInt()
	for i := 0; i < m; i++ {
		u, v, w := ReadInt() - 1, ReadInt() - 1, ReadInt64()
		g[u] = append(g[u], Edge{v, w, i})
	}
	s = ReadInt()
	for i := 0; i < n; i++ {
		d[i] = INF
	}
	pq := make(PriorityQueue, 0)
	heap.Push(&pq, pii{int64(0), s})
	for pq.Len() > 0 {
		p := pq.Pop().(pii)
		c, v := p.First, p.Second
		if c > d[v] {
			continue
		}
		for _, e := range g[v] {
			u, w := e.to, e.cost
			if d[u] > d[v] + w {
				d[u] = d[v] + w
				heap.Push(&pq, pii{d[u], u})
				h[u] = h[u][:0]
			}
			if d[u] == d[v] + w {
				h[u] = append(h[u], e)
			}
		}
	}
	es := make(BiEdgeSorter, 0, m)
	for v := 0; v < n; v++ {
		for _, e := range g[v] {
			es = append(es, BiEdge{v, e})
		}
	}
	sort.Sort(es)
	uf := NewUnionFind(n)
	ans := make([]int, 0, n)
	cost := int64(0)
	for _, e := range es {
		if !uf.Same(e.from, e.to) {
			ans = append(ans, e.id)
			cost += e.cost
			uf.Unite(e.from, e.to)
		}
	}
	fmt.Println(cost)
	for i, id := range ans {
		fmt.Print(id + 1)
		if i == n - 2 {
			fmt.Print("\n")
		} else {
			fmt.Print(" ")
		}
	}
}

package main

import "strconv"
import "os"
import "bufio"
import "container/heap"

var in *bufio.Scanner
var out *bufio.Writer

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

func writeInt(val int, c byte) {
	out.WriteString(strconv.Itoa(val))
	out.WriteByte(c)
}

func writeInt64(val int64, c byte) {
	out.WriteString(strconv.FormatInt(val, 10))
	out.WriteByte(c)
}

type Item struct {
	v    int
	dist int64
	pos  int
}

type Queue []*Item

func (q Queue) Len() int {
	return len(q)
}

func (q Queue) Less(i int, j int) bool {
	return q[i].dist < q[j].dist
}

func (q Queue) Swap(i int, j int) {
	q[i], q[j] = q[j], q[i]
	q[i].pos = i
	q[j].pos = j
}

func (q *Queue) Push(x interface{}) {
	n := len(*q)
	item := x.(*Item)
	item.pos = n
	*q = append(*q, item)
}

func (q *Queue) Pop() interface{} {
	old := *q
	n := len(old)
	item := old[n-1]
	item.pos = -1
	*q = old[0 : n-1]
	return item
}

func (q *Queue) update(item *Item, dist int64) {
	item.dist = dist
	heap.Fix(q, item.pos)
}

const inf = 10000000000000000

var n, m, e, root int
var adj, weight, idx, next, last, choose []int
var dist []int64

func add(u int, v int, w int, i int) {
	adj[e] = v
	weight[e] = w
	idx[e] = i
	next[e] = last[u]
	last[u] = e
	e++
}

func main() {
	in = bufio.NewScanner(os.Stdin)
	out = bufio.NewWriter(os.Stdout)

	in.Split(bufio.ScanWords)
	defer out.Flush()

	n = readInt()
	m = readInt()

	adj = make([]int, m*2)
	weight = make([]int, m*2)
	idx = make([]int, m*2)
	next = make([]int, m*2)
	last = make([]int, n)
	dist = make([]int64, n)
	choose = make([]int, n)

	for v := 0; v < n; v++ {
		last[v] = -1
		dist[v] = inf
		choose[v] = -1

	}

	e = 0
	for i := 0; i < m; i++ {
		u := readInt() - 1
		v := readInt() - 1
		w := readInt()
		add(u, v, w, i+1)
		add(v, u, w, i+1)
	}

	root = readInt() - 1
	dist[root] = 0

	items := make([]Item, n)
	q := make(Queue, n)
	for v := 0; v < n; v++ {
		items[v] = Item{v: v, dist: dist[v]}
		q[v] = &items[v]
	}

	heap.Init(&q)

	for q.Len() > 0 {
		item := heap.Pop(&q).(*Item)
		u := item.v
		for i := last[u]; i != -1; i = next[i] {
			v := adj[i]
			w := int64(weight[i])
			if dist[v] > dist[u]+w {
				dist[v] = dist[u] + w
				q.update(&items[v], dist[v])
				choose[v] = i
			} else if dist[v] == dist[u]+w {
				choose[v] = i
			}
		}
	}

	total := int64(0)
	for v := 0; v < n; v++ {
		if v != root {
			total += int64(weight[choose[v]])
		}
	}

	writeInt64(total, '\n')
	for v := 0; v < n; v++ {
		if v != root {
			writeInt(idx[choose[v]], ' ')
		}
	}
}

package main

import "strconv"
import "os"
import "bufio"
import "container/heap"

var in *bufio.Scanner
var out *bufio.Writer

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

func writeInt(val int, c byte) {
	out.WriteString(strconv.Itoa(val))
	out.WriteByte(c)
}

func writeInt64(val int64, c byte) {
	out.WriteString(strconv.FormatInt(val, 10))
	out.WriteByte(c)
}

type Item struct {
	v    int
	dist int64
	pos  int
}

type Queue []*Item

func (q Queue) Len() int {
	return len(q)
}

func (q Queue) Less(i int, j int) bool {
	return q[i].dist < q[j].dist
}

func (q Queue) Swap(i int, j int) {
	q[i], q[j] = q[j], q[i]
	q[i].pos = i
	q[j].pos = j
}

func (q *Queue) Push(x interface{}) {
	n := len(*q)
	item := x.(*Item)
	item.pos = n
	*q = append(*q, item)
}

func (q *Queue) Pop() interface{} {
	old := *q
	n := len(old)
	item := old[n-1]
	item.pos = -1
	*q = old[0 : n-1]
	return item
}

func (q *Queue) update(item *Item, dist int64) {
	item.dist = dist
	heap.Fix(q, item.pos)
}

const inf = 10000000000000000

var n, m, e, root int
var adj, weight, idx, next, last, choose []int
var dist []int64

func add(u int, v int, w int, i int) {
	adj[e] = v
	weight[e] = w
	idx[e] = i
	next[e] = last[u]
	last[u] = e
	e++
}

func main() {
	in = bufio.NewScanner(os.Stdin)
	out = bufio.NewWriter(os.Stdout)

	in.Split(bufio.ScanWords)
	defer out.Flush()

	n = readInt()
	m = readInt()

	adj = make([]int, m*2)
	weight = make([]int, m*2)
	idx = make([]int, m*2)
	next = make([]int, m*2)
	last = make([]int, n)
	dist = make([]int64, n)
	choose = make([]int, n)

	for v := 0; v < n; v++ {
		last[v] = -1
		dist[v] = inf
		choose[v] = -1

	}

	e = 0
	for i := 0; i < m; i++ {
		u := readInt() - 1
		v := readInt() - 1
		w := readInt()
		add(u, v, w, i+1)
		add(v, u, w, i+1)
	}

	root = readInt() - 1
	dist[root] = 0

	items := make(Queue, n)
	q := make(Queue, n)
	for v := 0; v < n; v++ {
		items[v] = &Item{v: v, dist: dist[v]}
		q[v] = items[v]
	}

	heap.Init(&q)

	for q.Len() > 0 {
		item := heap.Pop(&q).(*Item)
		u := item.v
		if item.dist == dist[u] {
			for i := last[u]; i != -1; i = next[i] {
				v := adj[i]
				w := int64(weight[i])
				if dist[v] > dist[u]+w {
					dist[v] = dist[u] + w
					q.update(items[v], dist[v])
					choose[v] = i
				} else if dist[v] == dist[u]+w {
					choose[v] = i
				}
			}
		}
	}

	total := int64(0)
	for v := 0; v < n; v++ {
		if v != root {
			total += int64(weight[choose[v]])
		}
	}

	writeInt64(total, '\n')
	for v := 0; v < n; v++ {
		if v != root {
			writeInt(idx[choose[v]], ' ')
		}
	}
}

package main

import "strconv"
import "os"
import "bufio"
import "container/heap"

var in *bufio.Scanner
var out *bufio.Writer

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

func writeInt(val int, c byte) {
	out.WriteString(strconv.Itoa(val))
	out.WriteByte(c)
}

func writeInt64(val int64, c byte) {
	out.WriteString(strconv.FormatInt(val, 10))
	out.WriteByte(c)
}

type Node struct {
	name  int
	dist  int64
	index int
}

type NodeList []*Node

func (nodes NodeList) Len() int {
	return len(nodes)
}

func (nodes NodeList) Less(i int, j int) bool {
	return nodes[i].dist < nodes[j].dist
}

func (nodes NodeList) Swap(i int, j int) {
	nodes[i], nodes[j] = nodes[j], nodes[i]
	nodes[i].index = i
	nodes[j].index = j
}

func (nodes *NodeList) Push(x interface{}) {
	node := x.(*Node)
	node.index = len(*nodes)
	*nodes = append(*nodes, node)
}

func (nodes *NodeList) Pop() interface{} {
	s := *nodes
	last := len(s) - 1
	r := s[last]
	*nodes = s[:last]
	r.index = -1
	return r
}

const inf = 10000000000000000

var n, m, e, root int
var adj, weight, idx, next, last, choose []int

func add(u int, v int, w int, i int) {
	adj[e] = v
	weight[e] = w
	idx[e] = i
	next[e] = last[u]
	last[u] = e
	e++
}

func main() {
	in = bufio.NewScanner(os.Stdin)
	out = bufio.NewWriter(os.Stdout)

	in.Split(bufio.ScanWords)
	defer out.Flush()

	n = readInt()
	m = readInt()

	adj = make([]int, m*2)
	weight = make([]int, m*2)
	idx = make([]int, m*2)
	next = make([]int, m*2)
	last = make([]int, n)
	choose = make([]int, n)
	nodes := make(NodeList, n)
	for v := 0; v < n; v++ {
		last[v] = -1
		choose[v] = -1
		nodes[v] = &Node{name: v, dist: inf, index: -1}
	}

	e = 0
	for i := 0; i < m; i++ {
		u := readInt() - 1
		v := readInt() - 1
		w := readInt()
		add(u, v, w, i+1)
		add(v, u, w, i+1)
	}

	root = readInt() - 1
	nodes[root].dist = 0

	var queue NodeList
	heap.Push(&queue, nodes[root])

	total := int64(0)
	for queue.Len() > 0 {
		current := heap.Pop(&queue).(*Node)
		u := current.name
		if u != root {
			writeInt(u+1, ' ')
			writeInt(choose[u], ' ')
			writeInt(weight[choose[u]], '\n')
			total += int64(weight[choose[u]])
		}
		for i := last[u]; i != -1; i = next[i] {
			v := adj[i]
			d := current.dist + int64(weight[i])
			if nodes[v].dist >= d {
				nodes[v].dist = d
				choose[v] = i
				if nodes[v].index == -1 {
					heap.Push(&queue, nodes[v])
				} else {
					heap.Fix(&queue, nodes[v].index)
				}
			}
		}

	}

	writeInt64(total, '\n')
	for v := 0; v < n; v++ {
		if v != root {
			writeInt(idx[choose[v]], ' ')
		}
	}
}

package main

import "strconv"
import "os"
import "bufio"
import "container/heap"

var in *bufio.Scanner
var out *bufio.Writer

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

func writeInt(val int, c byte) {
	out.WriteString(strconv.Itoa(val))
	out.WriteByte(c)
}

func writeInt64(val int64, c byte) {
	out.WriteString(strconv.FormatInt(val, 10))
	out.WriteByte(c)
}

type Node struct {
	name  int
	dist  int64
	index int
}

type NodeList []*Node

func (nodes NodeList) Len() int {
	return len(nodes)
}

func (nodes NodeList) Less(i int, j int) bool {
	return nodes[i].dist < nodes[j].dist
}

func (nodes NodeList) Swap(i int, j int) {
	nodes[i], nodes[j] = nodes[j], nodes[i]
	nodes[i].index = i
	nodes[j].index = j
}

func (nodes *NodeList) Push(x interface{}) {
	node := x.(*Node)
	node.index = len(*nodes)
	*nodes = append(*nodes, node)
}

func (nodes *NodeList) Pop() interface{} {
	s := *nodes
	last := len(s) - 1
	r := s[last]
	*nodes = s[:last]
	r.index = -1
	return r
}

const inf = 10000000000000000

var n, m, e, root int
var adj, weight, idx, next, last, choose []int

func add(u int, v int, w int, i int) {
	adj[e] = v
	weight[e] = w
	idx[e] = i
	next[e] = last[u]
	last[u] = e
	e++
}

func main() {
	in = bufio.NewScanner(os.Stdin)
	out = bufio.NewWriter(os.Stdout)

	in.Split(bufio.ScanWords)
	defer out.Flush()

	n = readInt()
	m = readInt()

	adj = make([]int, m*2)
	weight = make([]int, m*2)
	idx = make([]int, m*2)
	next = make([]int, m*2)
	last = make([]int, n)
	choose = make([]int, n)
	nodes := make(NodeList, n)
	queue := make(NodeList, n)

	for v := 0; v < n; v++ {
		last[v] = -1
		choose[v] = -1
		nodes[v] = &Node{name: v, dist: inf, index: -1}
		queue[v] = nodes[v]
	}

	e = 0
	for i := 0; i < m; i++ {
		u := readInt() - 1
		v := readInt() - 1
		w := readInt()
		add(u, v, w, i+1)
		add(v, u, w, i+1)
	}

	root = readInt() - 1
	nodes[root].dist = 0
	heap.Init(&queue)

	total := int64(0)
	for queue.Len() > 0 {
		current := heap.Pop(&queue).(*Node)
		u := current.name
		if u != root {
			total += int64(weight[choose[u]])
		}
		for i := last[u]; i != -1; i = next[i] {
			v := adj[i]
			d := current.dist + int64(weight[i])
			if nodes[v].dist >= d {
				nodes[v].dist = d
				choose[v] = i
				heap.Fix(&queue, nodes[v].index)
			}
		}
	}

	writeInt64(total, '\n')
	for v := 0; v < n; v++ {
		if v != root {
			writeInt(idx[choose[v]], ' ')
		}
	}
}

package main

import "strconv"
import "os"
import "bufio"
import "container/heap"

var in *bufio.Scanner
var out *bufio.Writer

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

func writeInt(val int, c byte) {
	out.WriteString(strconv.Itoa(val))
	out.WriteByte(c)
}

func writeInt64(val int64, c byte) {
	out.WriteString(strconv.FormatInt(val, 10))
	out.WriteByte(c)
}

type Item struct {
	v    int
	dist int64
	pos  int
}

type Queue []*Item

func (q Queue) Len() int {
	return len(q)
}

func (q Queue) Less(i int, j int) bool {
	return q[i].dist < q[j].dist
}

func (q Queue) Swap(i int, j int) {
	q[i], q[j] = q[j], q[i]
	q[i].pos = i
	q[j].pos = j
}

func (q *Queue) Push(x interface{}) {
	n := len(*q)
	item := x.(*Item)
	item.pos = n
	*q = append(*q, item)
}

func (q *Queue) Pop() interface{} {
	old := *q
	n := len(old)
	item := old[n-1]
	item.pos = -1
	*q = old[0 : n-1]
	return item
}

func (q *Queue) update(item *Item, dist int64) {
	item.dist = dist
	heap.Fix(q, item.pos)
}

const inf = 10000000000000000

var n, m, e, root int
var adj, weight, idx, next, last, choose []int
var dist []int64

func add(u int, v int, w int, i int) {
	adj[e] = v
	weight[e] = w
	idx[e] = i
	next[e] = last[u]
	last[u] = e
	e++
}

func main() {
	in = bufio.NewScanner(os.Stdin)
	out = bufio.NewWriter(os.Stdout)

	in.Split(bufio.ScanWords)
	defer out.Flush()

	n = readInt()
	m = readInt()

	adj = make([]int, m*2)
	weight = make([]int, m*2)
	idx = make([]int, m*2)
	next = make([]int, m*2)
	last = make([]int, n)
	dist = make([]int64, n)
	choose = make([]int, n)

	for v := 0; v < n; v++ {
		last[v] = -1
		dist[v] = inf
		choose[v] = -1

	}

	e = 0
	for i := 0; i < m; i++ {
		u := readInt() - 1
		v := readInt() - 1
		w := readInt()
		add(u, v, w, i+1)
		add(v, u, w, i+1)
	}

	root = readInt() - 1
	dist[root] = 0

	items := make([]Item, n)
	q := make(Queue, n)
	for v := 0; v < n; v++ {
		items[v] = Item{v: v, dist: dist[v]}
		q[v] = &items[v]
	}

	heap.Init(&q)

	for q.Len() > 0 {
		item := heap.Pop(&q).(*Item)
		u := item.v
		if item.dist == dist[u] {
			for i := last[u]; i != -1; i = next[i] {
				v := adj[i]
				w := int64(weight[i])
				if dist[v] > dist[u]+w {
					dist[v] = dist[u] + w
					q.update(&items[v], dist[v])
					choose[v] = i
				} else if dist[v] == dist[u]+w {
					choose[v] = i
				}
			}
		}
	}

	total := int64(0)
	for v := 0; v < n; v++ {
		if v != root {
			total += int64(weight[choose[v]])
		}
	}

	writeInt64(total, '\n')
	for v := 0; v < n; v++ {
		if v != root {
			writeInt(idx[choose[v]], ' ')
		}
	}
}

package main

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

type Vertex struct {
	Label int
	Dist  int64
	Index int
}

type Edge struct {
	Start  int
	End    int
	Index  int
	Weight int64
}

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

type Graph struct {
	EdgesByVLabel map[int][]Edge
	Vertices      []*Vertex
	Edges         []Edge
	Prev          map[int]int
}

type PriorityQueue []*Vertex

func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].Dist < pq[j].Dist
}

func (pq PriorityQueue) Len() int {
	return len(pq)
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].Index = i
	pq[j].Index = j
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	v := x.(*Vertex)
	v.Index = n
	*pq = append(*pq, v)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	v := old[n-1]
	old[n-1] = nil
	v.Index = -1
	*pq = old[0 : n-1]
	return v
}

func (pq *PriorityQueue) update(v *Vertex, d int64) {
	v.Dist = d
	heap.Fix(pq, v.Index)
}

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

	var n, m, u, v, s int
	var w int64
	fmt.Fscanf(reader, "%d %d\n", &n, &m)
	g := Graph{EdgesByVLabel: make(map[int][]Edge), Vertices: make([]*Vertex, n+1), Prev: make(map[int]int), Edges: make([]Edge, 0)}

	idx := 0
	pq := make(PriorityQueue, 0)
	for i := 1; i <= m; i++ {
		fmt.Fscanf(reader, "%d %d %d\n", &u, &v, &w)
		if g.Vertices[u] == nil {
			g.Prev[u] = -1
			g.Vertices[u] = &Vertex{Dist: math.MaxInt32, Label: u, Index: idx}
			pq = append(pq, g.Vertices[u])
			idx = idx + 1

		}
		if g.Vertices[v] == nil {
			g.Prev[v] = -1
			g.Vertices[v] = &Vertex{Dist: math.MaxInt32, Label: v, Index: idx}
			pq = append(pq, g.Vertices[v])
			idx = idx + 1
		}
		if _, ok := g.EdgesByVLabel[u]; !ok {
			g.EdgesByVLabel[u] = make([]Edge, 0)
		}
		if _, ok := g.EdgesByVLabel[v]; !ok {
			g.EdgesByVLabel[v] = make([]Edge, 0)
		}
		e := Edge{Start: u, End: v, Weight: w, Index: i}
		g.Edges = append(g.Edges, e)
		g.EdgesByVLabel[u] = append(g.EdgesByVLabel[u], e)
		g.EdgesByVLabel[v] = append(g.EdgesByVLabel[v], Edge{Start: v, End: u, Weight: w, Index: i})
	}
	fmt.Fscanf(reader, "%d\n", &s)
	if m == 0 {
		fmt.Fprintf(writer, "%d\n", m)
		return
	}

	//fmt.Println(g)

	chosenEWByVLabel := make(map[int]int64)
	heap.Init(&pq)
	vertex := g.Vertices[s]
	pq.update(vertex, 0)
	for pq.Len() > 0 {
		p := heap.Pop(&pq).(*Vertex)
		for _, edge := range g.EdgesByVLabel[p.Label] {
			//fmt.Println(edge)
			q := g.Vertices[edge.End]
			if q.Dist > p.Dist+edge.Weight {
				q.Dist = p.Dist + edge.Weight
				chosenEWByVLabel[q.Label] = edge.Weight
				g.Prev[q.Label] = p.Label
				pq.update(q, q.Dist)
			} else if q.Dist == (p.Dist + edge.Weight) {
				if edge.Weight < chosenEWByVLabel[q.Label] {
					g.Prev[q.Label] = p.Label
					chosenEWByVLabel[q.Label] = edge.Weight
					//fmt.Println("equal", q.Label, q.Dist, edge.Start, edge.End, edge.Weight)
				}
			}
		}
	}
	//fmt.Println(g.Prev)
	var total int64
	indices := make([]int, 0)
	for _, edge := range g.Edges {
		//fmt.Println(edge)
		if g.Prev[edge.Start] != -1 && ((g.Prev[edge.Start] == edge.End) || (g.Prev[edge.End] == edge.Start)) {
			total = total + edge.Weight
			indices = append(indices, edge.Index)
		} else if g.Prev[edge.End] == edge.Start {
			total = total + edge.Weight
			indices = append(indices, edge.Index)
		}
	}
	//fmt.Println(g.Vertices)
	//sort.Sort(Vertices(g.Vertices[1:]))
	//fmt.Println(g.Vertices)
	fmt.Fprintf(writer, "%d\n", total)
	for idx, val := range indices {
		if idx != len(indices)-1 {
			fmt.Fprintf(writer, "%d ", val)
		} else {
			fmt.Fprintf(writer, "%d\n", val)
		}
	}
}

package main

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

type Vertex struct {
	Label int
	Dist  int64
	Index int
}

type Edge struct {
	Start  int
	End    int
	Index  int
	Weight int64
}

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

type Graph struct {
	EdgesByVLabel map[int][]Edge
	Vertices      []*Vertex
	Edges         []Edge
	Prev          map[int]int
}

type PriorityQueue []*Vertex

func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].Dist < pq[j].Dist
}

func (pq PriorityQueue) Len() int {
	return len(pq)
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].Index = i
	pq[j].Index = j
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	v := x.(*Vertex)
	v.Index = n
	*pq = append(*pq, v)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	v := old[n-1]
	old[n-1] = nil
	v.Index = -1
	*pq = old[0 : n-1]
	return v
}

func (pq *PriorityQueue) update(v *Vertex, d int64) {
	v.Dist = d
	heap.Fix(pq, v.Index)
}

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

	var n, m, u, v, s int
	var w int64
	fmt.Fscanf(reader, "%d %d\n", &n, &m)
	if m == 0 {
		fmt.Fprintf(writer, "%d\n", m)
		return
	}
	g := Graph{EdgesByVLabel: make(map[int][]Edge), Vertices: make([]*Vertex, n+1), Prev: make(map[int]int), Edges: make([]Edge, 0)}

	idx := 0
	pq := make(PriorityQueue, 0)
	for i := 1; i <= m; i++ {
		fmt.Fscanf(reader, "%d %d %d\n", &u, &v, &w)
		if g.Vertices[u] == nil {
			g.Prev[u] = -1
			g.Vertices[u] = &Vertex{Dist: math.MaxInt32, Label: u, Index: idx}
			pq = append(pq, g.Vertices[u])
			idx = idx + 1

		}
		if g.Vertices[v] == nil {
			g.Prev[v] = -1
			g.Vertices[v] = &Vertex{Dist: math.MaxInt32, Label: v, Index: idx}
			pq = append(pq, g.Vertices[v])
			idx = idx + 1
		}
		if _, ok := g.EdgesByVLabel[u]; !ok {
			g.EdgesByVLabel[u] = make([]Edge, 0)
		}
		if _, ok := g.EdgesByVLabel[v]; !ok {
			g.EdgesByVLabel[v] = make([]Edge, 0)
		}
		e := Edge{Start: u, End: v, Weight: w, Index: i}
		g.Edges = append(g.Edges, e)
		g.EdgesByVLabel[u] = append(g.EdgesByVLabel[u], e)
		g.EdgesByVLabel[v] = append(g.EdgesByVLabel[v], Edge{Start: v, End: u, Weight: w, Index: i})
	}
	fmt.Fscanf(reader, "%d\n", &s)
	//fmt.Println(g)

	chosenEWByVLabel := make(map[int]int64)
	heap.Init(&pq)
	vertex := g.Vertices[s]
	pq.update(vertex, 0)
	for pq.Len() > 0 {
		p := heap.Pop(&pq).(*Vertex)
		for _, edge := range g.EdgesByVLabel[p.Label] {
			//fmt.Println(edge)
			q := g.Vertices[edge.End]
			if q.Dist > p.Dist+edge.Weight {
				q.Dist = p.Dist + edge.Weight
				chosenEWByVLabel[q.Label] = edge.Weight
				g.Prev[q.Label] = p.Label
				pq.update(q, q.Dist)
			} else if q.Dist == (p.Dist + edge.Weight) {
				if edge.Weight < chosenEWByVLabel[q.Label] {
					g.Prev[q.Label] = p.Label
					chosenEWByVLabel[q.Label] = edge.Weight
					//fmt.Println("equal", q.Label, q.Dist, edge.Start, edge.End, edge.Weight)
				}
			}
		}
	}
	//fmt.Println(g.Prev)
	var total int64
	indices := make([]int, 0)
	for _, edge := range g.Edges {
		if g.Prev[edge.Start] == edge.End || g.Prev[edge.End] == edge.Start {
			total = total + edge.Weight
			indices = append(indices, edge.Index)
		}
	}
	fmt.Fprintf(writer, "%d\n", total)
	for idx, val := range indices {
		if idx != len(indices)-1 {
			fmt.Fprintf(writer, "%d ", val)
		} else {
			fmt.Fprintf(writer, "%d\n", val)
		}
	}
}

package main

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

type Vertex struct {
	Label int
	Dist  int
	Index int
}

type Edge struct {
	Start  int
	End    int
	Index  int
	Weight int
}

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

type Graph struct {
	EdgesByVLabel map[int][]Edge
	Vertices      []*Vertex
	Edges         []Edge
	Prev          map[int]int
}

type PriorityQueue []*Vertex

func (pq PriorityQueue) Less(i, j int) bool {
	return pq[i].Dist < pq[j].Dist
}

func (pq PriorityQueue) Len() int {
	return len(pq)
}

func (pq PriorityQueue) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].Index = i
	pq[j].Index = j
}

func (pq *PriorityQueue) Push(x interface{}) {
	n := len(*pq)
	v := x.(*Vertex)
	v.Index = n
	*pq = append(*pq, v)
}

func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	v := old[n-1]
	old[n-1] = nil
	v.Index = -1
	*pq = old[0 : n-1]
	return v
}

func (pq *PriorityQueue) update(v *Vertex, d int) {
	v.Dist = d
	heap.Fix(pq, v.Index)
}

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

	var n, m, u, v, w, s int
	fmt.Fscanf(reader, "%d %d\n", &n, &m)
	if m == 0 {
		fmt.Fprintf(writer, "%d\n", m)
		return
	}
	g := Graph{EdgesByVLabel: make(map[int][]Edge), Vertices: make([]*Vertex, n+1), Prev: make(map[int]int), Edges: make([]Edge, 0)}

	idx := 0
	pq := make(PriorityQueue, 0)
	for i := 1; i <= m; i++ {
		fmt.Fscanf(reader, "%d %d %d\n", &u, &v, &w)
		if g.Vertices[u] == nil {
			g.Prev[u] = -1
			g.Vertices[u] = &Vertex{Dist: math.MaxInt32, Label: u, Index: idx}
			pq = append(pq, g.Vertices[u])
			idx = idx + 1

		}
		if g.Vertices[v] == nil {
			g.Prev[v] = -1
			g.Vertices[v] = &Vertex{Dist: math.MaxInt32, Label: v, Index: idx}
			pq = append(pq, g.Vertices[v])
			idx = idx + 1
		}
		if _, ok := g.EdgesByVLabel[u]; !ok {
			g.EdgesByVLabel[u] = make([]Edge, 0)
		}
		if _, ok := g.EdgesByVLabel[v]; !ok {
			g.EdgesByVLabel[v] = make([]Edge, 0)
		}
		e := Edge{Start: u, End: v, Weight: w, Index: i}
		g.Edges = append(g.Edges, e)
		g.EdgesByVLabel[u] = append(g.EdgesByVLabel[u], e)
		g.EdgesByVLabel[v] = append(g.EdgesByVLabel[v], Edge{Start: v, End: u, Weight: w, Index: i})
	}
	fmt.Fscanf(reader, "%d\n", &s)
	//fmt.Println(g)

	chosenEWByVLabel := make(map[int]int)
	heap.Init(&pq)
	vertex := g.Vertices[s]
	pq.update(vertex, 0)
	for pq.Len() > 0 {
		p := heap.Pop(&pq).(*Vertex)
		for _, edge := range g.EdgesByVLabel[p.Label] {
			//fmt.Println(edge)
			q := g.Vertices[edge.End]
			if q.Dist > p.Dist+edge.Weight {
				q.Dist = p.Dist + edge.Weight
				chosenEWByVLabel[q.Label] = edge.Weight
				g.Prev[q.Label] = p.Label
				pq.update(q, q.Dist)
			} else if q.Dist == (p.Dist + edge.Weight) {
				if edge.Weight < chosenEWByVLabel[q.Label] {
					g.Prev[q.Label] = p.Label
					chosenEWByVLabel[q.Label] = edge.Weight
					//fmt.Println("equal", q.Label, q.Dist, edge.Start, edge.End, edge.Weight)
				}
			}
		}
	}
	//fmt.Println(g.Prev)
	total := 0
	indices := make([]int, 0)
	for _, edge := range g.Edges {
		if g.Prev[edge.Start] == edge.End || g.Prev[edge.End] == edge.Start {
			total = total + edge.Weight
			indices = append(indices, edge.Index)
		}
	}
	fmt.Fprintf(writer, "%d\n", total)
	for idx, val := range indices {
		if idx != len(indices)-1 {
			fmt.Fprintf(writer, "%d ", val)
		} else {
			fmt.Fprintf(writer, "%d\n", val)
		}
	}
}


package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	n := 0;
	fmt.Fscanf(in, "%d\n", &n);
	var s string;
	fmt.Fscanf(in, "%s\n", &s);
	var a int64 = 0;
	for i:=0; i < n; i++ {
		if s[i] % 2 == 0  {
			a += int64(i + 1);
		}
	}
	fmt.Println(a);
}

package main

import (
	"fmt"
)

func main() {
	var n, sum int
	var s string
	fmt.Scanln(&n)
	fmt.Scanln(&s)
	for ind, val := range s{
		ii := int(val - '0')
		if ii%2 == 0{
			sum += ind+1
		}
	}
	fmt.Println(sum)
}

package main

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

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

	var n int
	fmt.Fscanf(in, "%d\n", &n)

	counter := 0
	for i := 1; i <= n; i++ {
		c, _, _ := in.ReadRune()
		if c % 2 == 0 {
			counter += i
		}
	}

	fmt.Println(counter)
}

package main

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

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

	var n int
	var str string

	fmt.Fscan(reader, &n)
	fmt.Fscan(reader, &str)

	var count int
	for in, vl := range str {
		if ok, _ := strconv.Atoi(string(vl)); ok%2 == 0 {
			count += in + 1
		}
	}

	fmt.Println(count)
}

package main

import "fmt"

func main() {
    var n int
    var a string
    fmt.Scan(&n)
    sum := 0
	//for i := 0; i < n; i++ {
		fmt.Scan(&a)
	//}
	for i:=0; i< n ;i++{
	    if(a[i]%2==0){
	        sum+=(i+1)
	    }
	}
	fmt.Println(sum)
}

// A. Even Substrings
/*
You are given a string 𝑠=𝑠1𝑠2…𝑠𝑛 of length 𝑛, which only contains digits 1, 2, ..., 9.

A substring 𝑠[𝑙…𝑟] of 𝑠 is a string 𝑠𝑙𝑠𝑙+1𝑠𝑙+2…𝑠𝑟. A substring 𝑠[𝑙…𝑟] of 𝑠 is called even if the number represented by it is even.

Find the number of even substrings of 𝑠. Note, that even if some substrings are equal as strings, but have different 𝑙 and 𝑟, they are counted as different substrings.

Input
The first line contains an integer 𝑛 (1≤𝑛≤65000) — the length of the string 𝑠.

The second line contains a string 𝑠 of length 𝑛. The string 𝑠 consists only of digits 1, 2, ..., 9.

Output
Print the number of even substrings of 𝑠.

Examples
Input
4
1234

Output
6

Input
4
2244

Output
10

Note
In the first example, the [𝑙,𝑟] pairs corresponding to even substrings are:

    𝑠[1…2]
	 	𝑠[2…2]
	 	𝑠[1…4]
	 	𝑠[2…4]
	 	𝑠[3…4]
	 	𝑠[4…4]

In the second example, all 10 substrings of 𝑠 are even substrings. Note, that while substrings 𝑠[1…1] and 𝑠[2…2] both define the substring "2", they are still counted as different substrings.
*/
package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	input1, _ := reader.ReadString('\n')
	n, _ := strconv.Atoi(strings.TrimSpace(input1))

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

	ans := 0
	for i := 0; i < n; i++ {
		v, _ := strconv.Atoi(string(s[i]))

		if v%2 == 0 {
			ans += i + 1
		}
	}
	fmt.Print(ans)
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var n, res int
	var s string
	fmt.Fscan(in, &n, &s)
	for i, ch := range s {
		if ch%2 == 0 {
			res += i + 1
		}
	}
	fmt.Print(res)
}

package main

import "fmt"

func main() {
	var n, res int
	var s string
	fmt.Scan(&n, &s)
	for i, ch := range s {
		if ch%2 == 0 {
			res += i + 1
		}
	}
	fmt.Print(res)
}

package main

import "fmt"

func main() {
	var n, s string
	fmt.Scan(&n, &s)
	res := 0
	for i, ch := range s{
		if (ch - 48) % 2 == 0 {
			res += i + 1
		}
	}
	fmt.Print(res)
}

package main

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

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

	var n int

	fmt.Fscanf(buf, "%d\n", &n)
	str := make([]byte,n+1)
	fmt.Fscanf(buf, "%s\n", &str)
	var ans int64 = 0
	for i:=0;i < n;i++{
		if 0==((str[i]-'0')&1){
			ans += int64(i+1)
		}
	}
	fmt.Printf("%d\n", ans)

}

package main

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

func main()  {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var n int
	var s string
	fmt.Fscanln(in,&n)
	fmt.Fscan(in,&s)
	cnt := 0
	for i := 0 ;i < len(s);i++{
		if(s[i] - 48) % 2 == 0{
			cnt ++
		}
	}
	ans := 0
	for i := 0 ;i < len(s);i++{
		if(s[i] - 48) % 2 == 0{
			ans += cnt
			cnt --
		}else{
				ans += cnt
		}
	}
	fmt.Fprint(out,ans)

}

package main

import (
	"fmt"
)

func main() {
	var n int
	d:=0
	var s string
	fmt.Scan(&n)
	fmt.Scan(&s)
	for i:=0; i<n ; i++{
		if s[i]%2==0{
			d=d+i+1
		}
	}
	fmt.Printf("%d", d)

}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n := 0
	fmt.Fscanf(in, "%d\n", &n)
	s := ""
	fmt.Fscanf(in, "%s", &s)
	ans := 0
	for i := 0; i < n; i++ {
		if (s[i]-'0')%2 == 0 {
			ans += (i + 1)
		}
	}
	fmt.Fprintf(out, "%d\n", ans)
	return
}

package main

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

var even = map[string]bool{
	"0": true,
	"2": true,
	"4": true,
	"6": true,
	"8": true,
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	_, _ = reader.ReadString('\n')
	s, _ := reader.ReadString('\n')

	evenQuantity := 0

	for i := 0; i < len(s) - 1; i++ {
		if even[string(s[i])] {
			evenQuantity += 1 + i
		}
	}

	fmt.Println(evenQuantity)
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var n, total int
	fmt.Scanln(&n)
	var s string
	digits := "2468"
	fmt.Scanln(&s)
	for ind, ch := range s{
		if strings.ContainsRune(digits, ch){
			total += ind+1
		}
	}
	fmt.Println(total)
}

package main

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

var even = map[string]bool{
	"0": true,
	"2": true,
	"4": true,
	"6": true,
	"8": true,
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	nString, _ := reader.ReadString('\n')
	s, _ := reader.ReadString('\n')

	n, _ := strconv.Atoi(nString[:len(nString)-1])

	evenQuantity := 0

	for i := 0; i < n; i++ {
		for j := i; j < n + 1; j++ {
			if i == j {
				continue
			}
			buf := s[i:j]
			if even[string(buf[len(buf) - 1])] {
				evenQuantity++
			}
		}
	}

	fmt.Println(evenQuantity)
}

package main

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

var even = map[string]bool{
	"0": true,
	"2": true,
	"4": true,
	"6": true,
	"8": true,
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	s, _ := reader.ReadString('\n')

	evenQuantity := 0

	for i := 0; i < len(s) - 1; i++ {
		for j := i; j < len(s); j++ {
			if i == j {
				continue
			}
			buf := s[i:j]
			if even[string(buf[len(buf) - 1])] {
				evenQuantity++
			}
		}
	}

	fmt.Println(evenQuantity)
}

package main

import "fmt"

func main() {
    var n int
    var a [30]int
    fmt.Scan(&n)
    sum := 0
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	for i:=0; i< n ;i++{
	    if(a[i]%2==0){
	        sum+=(i+1)
	    }
	}
	fmt.Println(sum)
}


package main

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

func minimum(n int32, arr []int32) int32 {
	mini := int32(100)
	for _, value := range arr {
		if value < mini {
			mini = value
		}
	}
	return mini
}

func solve(n int32, arr []int32) int32 {
	mini := minimum(n, arr)
	output := int32(0)
	for _, value := range arr {
		if value == mini {
			output++
		}
	}
	return n - output
}

func arrayScanf(in *bufio.Reader, n int32, arr *[]int32) {
	m := int32(0)
	for i := int32(0); i < n; i++ {
		if i > 0 {
			fmt.Fscanf(in, " ")
		}
		fmt.Fscanf(in, "%d", &m)
		*arr = append(*arr, m)
	}
	fmt.Fscanf(in, "\n")
}

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

	tt := int32(0)
	fmt.Fscanf(in, "%d\n", &tt)
	for tt > 0 {
		n := int32(0)
		arr := []int32{}
		fmt.Fscanf(in, "%d\n", &n)
		arrayScanf(in, n, &arr)
		fmt.Fprintf(out, "%d\n", solve(n, arr))
		tt--
	}
	out.Flush()
}

package main

import (
	"fmt"
)

func calculate(a []int) int {
	n := len(a)
	res := 0
	sum := 0
	for i:=0; i < n; i++ {
		sum += a[i]
	}

	for i:=0; i < n; i++ {
		if a[i]*n > sum {
			res++
		}
	}

	m := n - res
	if m == 0 || m == n {
		return res
	}

	b:= make([]int, m)
	for i :=0; i < n; i++ {
		if a[i]*n <= sum {
			m--
			b[m] = a[i]
		}
	}

	return res + calculate(b)
}

func main() {
	t:=0
	fmt.Scanf("%d\n", &t)

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

		res := calculate(a)
		fmt.Printf("%d\n", res)
	}
}

package main

import (
	"fmt"
	"math"
)

func solve() {
	var n int
	fmt.Scan(&n)
	mi := math.MaxInt32
	cnt := 0
	for i := 0; i < n; i++ {
		var x int
		fmt.Scan(&x)
		if x < mi {
			mi, cnt = x, 1
		} else if x == mi {
			cnt++
		}
	}
	fmt.Printf("%d\n", n-cnt)
}

func main() {
	var T int
	fmt.Scan(&T)
	for i := 0; i < T; i++ {
		solve()
	}
}

package main

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

func CF1529A(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, N, A int
	for fmt.Fscan(in, &T); T > 0; T-- {
		min, cnt := 101, 0
		fmt.Fscan(in, &N)
		for i := 0; i < N; i++ {
			fmt.Fscan(in, &A)
			if A < min {
				min = A
				cnt = 1
			} else if A == min {
				cnt++
			}
		}
		fmt.Fprintln(out, N-cnt)
	}
}

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

package main

import (
	"fmt"
)

func main() {
	var a [100]int
	var t,n,num,res,avg int

	fmt.Scan(&t)

	for j:=0;j<t;j++{
		res =0
		avg = 9999999
		fmt.Scan(&n)

		for i:=0;i<n;i++ {
			fmt.Scan(&num)
			a[i]=num
			if num < avg{
			avg = num
			}
		}
		for i:=0;i<n;i++ {
			if avg != a[i]{
				res++
			}
		}
			fmt.Println(res)
		}

}

package main
import(
    "fmt"
    "sort"
)
func main() {
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var n int
		fmt.Scan(&n)
		var list []int = make([]int,n)
		for j:=0;j<n;j++{
			fmt.Scan(&list[j])
		}
		sort.Ints(list)
		for j:=0;j<len(list);j++{
			// fmt.Println(list)
			// fmt.Println(j, list[j], list[len(list)-1])
			// fmt.Println()
			if list[j] < list[len(list)-1] {
				avg:= (list[j] + list[len(list)-2] + list[len(list)-1])/3
				for k:=len(list)-2;k<len(list);k++{
					if list[k] > avg {
						list= list[:k]
						j--
						break
					}
				}
			} else {
				fmt.Println(n - len(list))
				break
			}
		}
	}
}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	t, n   int
)

func solve(a []int) int {
	min, c := 101, 0
	for _, x := range a {
		if x < min {
			min = x
		}
	}
	for _, x := range a {
		if x > min {
			c++
		}
	}
	return c
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		fmt.Println(solve(a))
	}
}

package main

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

type CF1529A struct {
	sc        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *CF1529A) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1529A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *CF1529A) NextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *CF1529A) NextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *CF1529A) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

/**
Run solve the problem CF1529A
Date: 11/10/21
User: epradere
URL: https://codeforces.com/problemset/problem/1529/A
Problem: CF1529A
**/
func (in *CF1529A) Run() {
	t := in.NextInt()
	for ; t > 0; t-- {
		n := in.NextInt()
		m := map[int]int{}
		sum := 0
		for i := 0; i < n; i++ {
			num := in.NextInt()
			sum += num
			if _, ok := m[num]; !ok {
				m[num] = 0
			}
			m[num]++
		}
		sol := 0
		avg := sum / n
		for {
			deleted := 0
			for i, value := range m {
				if i > avg {
					sum -= i * value
					n -= value
					deleted += value
					sol += value
					delete(m, i)
				}
			}
			if deleted > 0 {
				avg = sum / n
			} else {
				break
			}

		}
		fmt.Println(sol)
	}
}

func NewCF1529A(r *bufio.Reader) *CF1529A {
	return &CF1529A{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

func main() {
	NewCF1529A(bufio.NewReader(os.Stdin)).Run()
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var cases, n int
	var array []int
	fmt.Scan(&cases)
	for ; cases > 0; cases-- {
		fmt.Scan(&n)
		array = make([]int, n)
		for k := 0; k < n; k++ {
			fmt.Scan(&array[k])
		}
		sort.Ints(array)
		i := 1
		for ; i < n && array[i] == array[i-1]; i++ {
		}
		fmt.Printf("%d\n", n-i)
	}
}

package main

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

func main() {
	var t, n int

	reader := bufio.NewReader(os.Stdin)
	fmt.Fscan(reader, &t)

	for i := 0; i < t; i++ {
		m := map[int]int{}

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

		min := arr[0]
		for _, v := range arr {
			m[v]++
			if v < min {
				min = v
			}
		}
		fmt.Println(len(arr) - m[min])
	}
}

package main

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

func main() {
	var testCases int

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

	defer writer.Flush()

	fmt.Fscan(reader, &testCases)
	for testCase := 0; testCase < testCases; testCase++ {
		var n int

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

		output := solve(&arr, n)

		fmt.Fprintln(writer, output)
	}
}

func solve(arr *[]int, n int) int {
	smallest2 := [2]int{100, 100}

	for i := 0; i < n; i++ {
		if (*arr)[i] < smallest2[1] {
			smallest2[1] = (*arr)[i]
		}
		if smallest2[1] < smallest2[0] {
			smallest2[0] = smallest2[1]
		}
	}
	avg := int(math.Round(float64((smallest2[0] + smallest2[1]) / 2)))

	cnt := 0
	for i := 0; i < n; i++ {
		if (*arr)[i] > avg {
			cnt++
		}
	}

	return cnt
}

package main

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

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

	for test := parseInt(getString(reader)); test > 0; test-- {
		_ = getString(reader)
		A := getIntln(reader)
		min := A[0]
		for _, v := range A {
			if v < min {
				min = v
			}
		}
		var removes int
		for _, v := range A {
			if v^min > 0 {
				removes++
			}
		}
		writer.WriteString(fmt.Sprintln(removes))
	}
	writer.Flush()
}

func getString(in *bufio.Reader) string {
	res, _ := in.ReadString('\n')
	res = strings.ReplaceAll(res, "\n", "")
	res = strings.ReplaceAll(res, "\r", "")
	res = strings.TrimSpace(res)
	return res
}

func parseInt(str string) int {
	var res int
	size := len(str)
	for i := 0; i < size; i++ {
		digit := int(str[i] - '0')
		for j := (i + 1); j < size; j++ {
			digit = digit<<3 + digit<<1
		}
		res += digit
	}
	return res
}

func getIntln(in *bufio.Reader) []int {
	b := strings.Split(getString(in), " ")
	res := make([]int, len(b))
	for k, v := range b {
		res[k] = parseInt(v)
	}
	return res
}

package main

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

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

	var T, n, v int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		c, s := [101]int{}, 0
		for i := 0; i < n; i++ {
			Fscan(in, &v)
			c[v]++
			s += v
		}
		ans := 0
		for i := 100; i*n > s; i-- {
			ans += c[i]
			n -= c[i]
			s -= i * c[i]
		}
		Fprintln(out, ans)
	}
}

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

package main

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

var cin = bufio.NewReader(os.Stdin)
var cout = bufio.NewWriter(os.Stdout)

const N = 105

var n, t int
var A [N]int

func main() {
	defer cout.Flush()
	fmt.Fscan(cin, &t)
	for ti := 0; ti < t; ti++ {
		fmt.Fscan(cin, &n)
		mn := N
		cnt := 0
		for i := 0; i < n; i++ {
			fmt.Fscan(cin, &A[i])
			if A[i] < mn {
				mn = A[i]
				cnt = 0
			}
			if A[i] == mn {
				cnt++
			}
		}
		fmt.Fprintln(cout, n-cnt)
	}
}

package main

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

const (
	MOD int = int(1e9 + 7)
)

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

	var t int
	fmt.Fscan(_r, &t)

	for i := 0; i < t; i++ {
		var n int
		fmt.Fscan(_r, &n)
		a := make([]int, n)
		min := math.MaxInt32
		for j := 0; j < n; j++ {
			fmt.Fscan(_r, &a[j])
			if min > a[j] {
				min = a[j]
			}
		}
		cnt := 0
		for j := 0; j < n; j++ {
			if a[j] == min {
				cnt++
			}
		}
		fmt.Fprintf(_w, "%d\n", n-cnt)

	}

	// fmt.Fscan(_r, &h, &w)
}

package main

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

)

func run(r io.Reader ,w io.Writer){

	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)

	defer out.Flush()

	solve := func(){

		var n int

		fmt.Fscan(in , &n)

		arr := make([]int , n)
		Freq := make([]int ,101)

		for i := 0 ; i < n ; i++{
			fmt.Fscan(in , &arr[i])
			Freq[arr[i]]++

		}

		for i := range Freq{

			if Freq[i]>0{
				fmt.Fprintln(out,n - Freq[i])
				break
			}
		}

	}

	T := 1

	fmt.Fscan(in ,&T)

	for o := 0 ; o < T ; o++{
		solve()
	}

}

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

package main

import "fmt"

func main() {
    var t int
    _, err := fmt.Scan(&t)
	if err != nil {
		panic(err)
	}

    var a = make([]int, 102)

    for ;t > 0; t-- {
        var n int
        fmt.Scan(&n);

        for i := 0; i < 101; i++ {
            a[i] = 0
        }

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

        i := 0
        for ; a[i] == 0; i++ {
        }

        fmt.Printf("%d\n", n - a[i]);
    }
}

package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string { sc.Scan(); return sc.Text() }
func scanInt() int       { a, _ := strconv.Atoi(scanString()); return a }

const maxn = int(2e6) + 10

func solve() {
	n := scanInt()
	a := make([]int, 0)
	for i := 0; i < n; i++ {
		a = append(a, scanInt())
	}

	sort.Slice(a, func(i, j int) bool {
		return a[i] < a[j]
	})
	ans := n
	for _, x := range a {
		if x == a[0] {
			ans--
		}
	}
	fmt.Println(ans)
}

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1000000)
}

func main() {
	T := scanInt()
	for Case := 0; Case < T; Case++ {
		solve()
	}
}

package main

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

// var m []int
// err = json.Unmarshal([]byte(r.FormValue("example")), &m)

// for i := 0; i < len(m); i++ {
// 	fmt.Println(m[i])
// }

// sort.Slice(arr, func(i, j int) bool {
// 	return arr[i] > arr[j]
// })

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

func MKO(x, y int64) int64 {
	if x < y {
		return 0
	} else {
		return x - y + 1
	}
}

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

func LCM(x, y int) int {
	if x >= y {
		initial := x
		for i := 1; i < y+2; i++ {
			if initial%y == 0 {
				break
			} else {
				initial = initial + x
			}

		}
		return initial
	} else {
		initial := y
		for i := 1; i < x+2; i++ {
			if initial%x == 0 {
				break
			} else {
				initial = initial + y
			}

		}
		return initial
	}
}

func GCD(x, y int64) int64 {
	var l, q int64
	l = MAX(x, y)
	q = MIN(x, y)
	var m int64
	for l*q > 0 {
		a := l % q
		b := l - a
		cc := int64(b / q)
		remain := l - cc*q
		l = MAX(remain, q)
		q = MIN(remain, q)
		if l*q == 0 {
			m = l + q
			break
		}

	}
	return m

}

func IsItPrime(x int) bool {
	if x < 10 {
		if x == 2 || x == 3 || x == 5 || x == 7 {
			return true
		} else {
			return false
		}
	} else {
		j := 0
		k := math.Sqrt(float64(x))
		for m := 3; m <= int(k); {
			if x%m == 0 {
				j = 1
				break
			}
			m = m + 2
		}
		if j == 1 {
			return false
		} else {
			return true
		}
	}

}

func LITTLE(x int) int64 {
	var answer int64
	answer = answer + int64((x*x*x*x-x*x)/4) + int64(x*x*(x-1)*(x-1)/8) - int64(x*(x-1)*(x+x+1)*(x+x-1)/12)
	return answer
}

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &t)
	for o := 0; o < t; o++ {

		var n int
		fmt.Fscan(input, &n)
		ARRAY := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(input, &ARRAY[i])
		}

		sort.Ints(ARRAY)
		var ind int
		for i := 1; i < n; i++ {
			if ARRAY[i] > ARRAY[i-1] {
				ind = i
				break
			}
		}
		if ind > 0 {
			fmt.Println(n - ind)
		} else {
			fmt.Println(0)
		}
	}
}

package main

import (
	"fmt"
	"sort"
)

func main() {

	var T, n int
	fmt.Scan(&T)
	for i := 0; i < T; i++ {
		fmt.Scan(&n)
		var a [110]int
		var mp = make(map[int]int)
		for j := 0; j < n; j++ {
			fmt.Scan(&a[j])
			mp[a[j]]++
		}
		var result = n
		var keys = make([]int, len(mp))
		j := 0
		for key, _ := range mp {
			keys[j] = key
			j++
		}
		sort.Ints(keys)
		result -= mp[keys[0]]
		fmt.Println(result)
	}
}

package main

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

/*
*/
func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Scan()
    var number_test_case int
    fmt.Sscan(scanner.Text(), &number_test_case)
    for i:=0; i < number_test_case; i++ {
        var number_elements uint64
        scanner.Scan()
        fmt.Sscan(scanner.Text(), &number_elements)
        scanner.Scan()
        array := make([]int, number_elements)
        for i, v := range strings.Split(scanner.Text(), " ") {
            array[i], _ = strconv.Atoi(v)
        }
        fmt.Println(max_removed(array))
    }
}

func max_removed(a []int) int {
    n := len(a)
    for i:=0; i < n; i++ { // brute force it max itereation is the len of a
        a = filter(a)
    }
    return n - len(a)
}

func filter(a []int) []int {
    av := average_uniques(a)
    var na []int
    for _, v := range a {
        if v <= av {
            na = append(na, v)
        }
    }
    return na
}

func average_uniques(a []int) int {
    s := 0
    u := make(map[int]bool)
    n := 0
    for _, v := range a{
        if !u[v] {
            s += v
            n ++
            u[v] = true
        }
    }
    return s / n
}

package main

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

func main() {
	var tcs int
	in := bufio.NewReader(os.Stdin)
	_, _ = fmt.Fscan(in, &tcs)

	for tc := 0; tc < tcs; tc++ {
		var n int
		_, _ = fmt.Fscan(in, &n)

		arr := make([]int, n)
		num := make([]int, 101)

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

		for i := 1; i <= 100; i++ {
			if num[i] > 0 {
				fmt.Println(n - num[i])
				break
			}
		}
	}
}

package main

import (
	"fmt"
)

func main() {
	t:=0
	fmt.Scanf("%d\n", &t)

	for w:=1; w <= t; w++ {
		n := 0
		fmt.Scanf("%d\n", &n)
		a := make([]int, n)
		sum := 0
		for i:=0; i < n; i++ {
			fmt.Scanf("%d", &a[i])
			sum += a[i]
		}
		fmt.Scanf("\n")
		res := 0
		for i:=0; i < n; i++ {
			if a[i]*n > sum {
				res++
			}
		}
		fmt.Printf("%d\n", res)
	}
}

package main

import (
	"fmt"
)

func main() {
	t:=0
	fmt.Scanf("%d\n", &t)

	for w:=1; w <= t; w++ {
		n := 0
		fmt.Scanf("%d", &n)
		a := make([]int, n)
		sum := 0
		for i:=0; i < n; i++ {
			fmt.Scanf("%d", &a[i])
			sum += a[i]
		}
		res := 0
		for i:=0; i < n; i++ {
			if a[i]*n > sum {
				res++
			}
		}
		fmt.Printf("%d\n", res)
	}
}

package main

import (
	"fmt"
)

func main() {
	t:=0
	fmt.Scanf("%d\n", &t)

	for w:=1; w <= t; w++ {
		n := 0
		fmt.Scanf("%d\n", &n)
		a := make([]int, n)
		sum := 0
		for i:=0; i < n; i++ {
			fmt.Scanf("%d", &a[i])
			sum += a[i]
		}
		res := 0
		for i:=0; i < n; i++ {
			if a[i]*n > sum {
				res++
			}
		}
		fmt.Printf("%d", res)
	}
}

package main

import (
	"fmt"
)

func main() {
	t:=0
	fmt.Scanf("%d\n", &t)

	for w:=1; w <= t; w++ {
		n := 0
		fmt.Scanf("%d\n", &n)
		a := make([]int, n)
		sum := 0
		for i:=0; i < n; i++ {
			fmt.Scanf("%d", &a[i])
			sum += a[i]
		}
		res := 0
		for i:=0; i < n; i++ {
			if a[i]*n > sum {
				res++
			}
		}
		fmt.Printf("%d\n", res)
	}
}

package main

import (
	"fmt"
)

func main() {
	t:=0
	fmt.Scanf("%d", &t)

	for w:=1; w <= t; w++ {
		n := 0
		fmt.Scanf("%d", &n)
		a := make([]int, n)
		sum := 0
		for i:=0; i < n; i++ {
			fmt.Scanf("%d", &a[i])
			sum += a[i]
		}
		res := 0
		for i:=0; i < n; i++ {
			if a[i]*n > sum {
				res++
			}
		}
		fmt.Printf("%d\n", res)
	}
}

package main

import (
	"fmt"
)

func main() {
	t:=0
	fmt.Scanf("%d", &t)

	for w:=1; w <= t; w++ {
		n := 0
		fmt.Scanf("%d", &n)
		a := make([]int, n)
		sum := 0
		for i:=0; i < n; i++ {
			fmt.Scanf("%d", &a[i])
			sum += a[i]
		}
		res := 0
		for i:=0; i < n; i++ {
			if a[i]*n > sum {
				res++
			}
		}
		fmt.Printf("%d", res)
	}
}

package main

import (
	"fmt"
)

func main() {
	t:=0
	fmt.Scanf("%d\n", &t)

	for w:=1; w <= t; w++ {
		n := 0
		fmt.Scanf("%d\n", &n)
		a := make([]int, n)
		sum := 0
		for i:=0; i < n; i++ {
			fmt.Scanf("%d", &a[i])
			sum += a[i]
		}
		res := 0
		for i:=0; i < n; i++ {
			if a[i]*n > sum {
				res++
			}
		}
		fmt.Println(res)
	}
}

package main

import (
	"fmt"
	"math"
)

func solve() {
	var n int
	fmt.Scanf("%d\n", &n)
	mi := math.MaxInt32
	cnt := 0
	for i := 0; i < n; i++ {
		var x int
		fmt.Scanf("%d ", &x)
		if x < mi {
			mi, cnt = x, 1
		} else if x == mi {
			cnt++
		}
	}
	fmt.Printf("%d\n", n-cnt)
}

func main() {
	var T int
	fmt.Scanf("%d\n", &T)
	for i := 0; i < T; i++ {
		solve()
	}
}

package main

import (
	"fmt"
	"math"
)

func solve() {
	var n int
	fmt.Scanf("%d\n", &n)
	mi := math.MaxInt32
	cnt := 0
	for i := 0; i < n; i++ {
		var x int
		fmt.Scanf("%d\n", &x)
		if x < mi {
			mi, cnt = x, 1
		} else if x == mi {
			cnt++
		}
	}
	fmt.Printf("%d\n", n-cnt)
}

func main() {
	var T int
	fmt.Scanf("%d\n", &T)
	for i := 0; i < T; i++ {
		solve()
	}
}

package main

import (
	"fmt"
	"math"
)

func solve() {
	var n int
	fmt.Scanf("%d\n", &n)
	mi := math.MaxInt32
	cnt := 0
	for i := 0; i < n; i++ {
		var x int
		fmt.Scanf("%d", &x)
		if x < mi {
			mi, cnt = x, 1
		} else if x == mi {
			cnt++
		}
	}
	fmt.Printf("%d\n", n-cnt)
}

func main() {
	var T int
	fmt.Scanf("%d\n", &T)
	for i := 0; i < T; i++ {
		solve()
	}
}

package main

import (
	"fmt"
	"math"
)

func solve() {
	var n int
	fmt.Scanf("%d", &n)
	mi := math.MaxInt32
	cnt := 0
	for i := 0; i < n; i++ {
		var x int
		fmt.Scanf("%d", &x)
		if x < mi {
			mi, cnt = x, 1
		} else if x == mi {
			cnt++
		}
	}
	fmt.Printf("%d\n", n-cnt)
}

func main() {
	var T int
	fmt.Scanf("%d", &T)
	for i := 0; i < T; i++ {
		solve()
	}
}

package main

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

func CF1529A(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, N, A int
	for fmt.Fscan(in, &T); T > 0; T-- {
		min, cnt := 101, 0
		fmt.Fscan(in, &N)
		for ; N > 0; N-- {
			fmt.Fscan(in, &A)
			if A < min {
				min = A
				cnt = 1
			} else if A == min {
				cnt++
			}
		}
		fmt.Fprintln(out, N-cnt)
	}
}

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

package main

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

func CF1529A(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, N, A int
	for fmt.Fscan(in, &T); T > 0; T-- {
		min, cnt := 101, 0
		for fmt.Fscan(in, &N); N > 0; N-- {
			fmt.Fscan(in, &A)
			if A < min {
				min = A
				cnt = 1
			} else if A == min {
				cnt++
			}
		}
		fmt.Fprintln(out, N-cnt)
	}
}

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

package main

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

func CF1529A(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, N, A int
	for fmt.Fscan(in, &T); T > 0; T-- {
		min, cnt := 101, 0
		for fmt.Fscan(in, &N); N > 0; N-- {
			fmt.Fscan(in, &A)
			if A < min {
				min = A
				cnt = 1
			} else if A == min {
				cnt++
			}
		}
		fmt.Fprintln(out, cnt)
	}
}

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

package main

import (
	"fmt"
)

func main() {
	var a [100]int
	var t,n,num,res,avg int
	avg = 9999999
	fmt.Scan(&t)

	for j:=0;j<t;j++{
		fmt.Scan(&n)

		for i:=0;i<n;i++ {
			fmt.Scan(&num)
			a[i]=num
			if num < avg{
			avg = num
			}
		}

		for i:=0;i<n;i++ {
			if avg != a[i]{
				res++
			}
		}
			fmt.Println(res)
		}

}

package main

import (
	"fmt"
	"math"
)

func main() {
	var a [100]int
	var t,n, res int
	var avg,nAvg float64
	flag := true

	fmt.Scan(&t)

	for j:=0;j<t;j++{
		fmt.Scan(&n)
		nAvg=0
		avg=0
		flag=true
		res = 0
		for i:=0;i<n;i++{
			fmt.Scan(&a[i])
			avg+=float64(a[i])/float64(n)
		}
		for flag{
			for i:=0;i<n;i++{
			if float64(a[i])>math.Round(avg) {
				a[i]=0
				res++
			} else {
				nAvg+=float64(a[i])
			}
		}
		if avg*(float64(n)-float64(res)) == nAvg || res == 0{
			flag = false
		} else {
			avg=nAvg/(float64(n)-float64(res))
			nAvg=0
		}

		}
		fmt.Println(res)
		}

}

package main
import(
    "fmt"
)
func main() {
	var t int
	fmt.Scan(&t)
	for i:=0;i<t;i++{
		var n int
		fmt.Scan(&n)
		var list []int = make([]int,n)
		sum:=0
		for j:=0;j<n;j++{
			fmt.Scan(&list[j])
			sum+=list[j]
		}
		counter:=0
		for j:=0;j<n;j++{
			if list[j] > (sum/n) {
				//list= append(list[:j],list[j+1:]...)
				counter++
			}
		}
		fmt.Println(counter)
	}
}

package main

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

var (
	reader = bufio.NewReader(os.Stdin)
	t, n   int
)

func solve(a []int) int {
	min, c := 101, 0
	for _, x := range a {
		if x < min {
			min = x
		}
	}
	for _, x := range a {
		if x == min {
			c++
		}
	}
	return c
}

func main() {
	fmt.Fscan(reader, &t)
	for ; t > 0; t-- {
		fmt.Fscan(reader, &n)
		a := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(reader, &a[i])
		}
		fmt.Println(solve(a))
	}
}

package main

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

type CF1529A struct {
	sc        *bufio.Reader
	split     []string
	index     int
	separator string
}

func (in *CF1529A) GetLine() string {
	line, err := in.sc.ReadString('\n')
	if err != nil {
		fmt.Println("error line:", line, " err: ", err)
	}
	in.split = []string{}
	in.index = 0
	return line
}
func (in *CF1529A) load() {
	if len(in.split) <= in.index {
		in.split = strings.Split(in.GetLine(), in.separator)
		in.index = 0
	}
}

func (in *CF1529A) NextInt() int {
	in.load()
	val, _ := strconv.Atoi(strings.TrimSpace(in.split[in.index]))
	in.index++
	return val
}

func (in *CF1529A) NextInt64() int64 {
	in.load()
	val, _ := strconv.ParseInt(strings.TrimSpace(in.split[in.index]), 10, 64)
	in.index++
	return val
}

func (in *CF1529A) NextString() string {
	in.load()
	val := strings.TrimSpace(in.split[in.index])
	in.index++
	return val
}

/**
 Run solve the problem CF1529A
 Date: 21/08/21
 User: pepradere
 URL: https://codeforces.com/problemset/problem/1529/A
 Problem: CF1529A
**/
func (in *CF1529A) Run() {
	t := in.NextInt()
	for ;t>0;t--{
		n := in.NextInt()
		arr := make([]int, 101)
		max := 0
		posMax :=0
		maxNum := -1
		for i:=0;i<n;i++{
			num := in.NextInt()
			if num > maxNum {
				maxNum = num
			}
			arr[num]++
			if arr[num] >= max {
				if arr[num] == max {
					if num > posMax {
						posMax = num
					}
				} else {
					posMax = num
				}
				max = arr[num]
			}
		}

		ans := 0
		for i:=100;i>posMax;i--{
			if arr[i] > 0 {
				ans+=arr[i]
			}
		}

		fmt.Println(ans)

	}

}

func NewCF1529A(r *bufio.Reader) *CF1529A {
	return &CF1529A{
		sc:        r,
		split:     []string{},
		index:     0,
		separator: " ",
	}
}

func main() {
	NewCF1529A(bufio.NewReader(os.Stdin)).Run()
}

package main

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

func average(n int32, arr []int32) int32 {
	total := int32(0)
	for _, value := range arr {
		total += value
	}
	return total / n
}

func solve(n int32, arr []int32) int32 {
	avg := average(n, arr)
	output := int32(0)
	for _, value := range arr {
		if value > avg {
			output++
		}
	}
	return output
}

func arrayScanf(in *bufio.Reader, n int32, arr *[]int32) {
	m := int32(0)
	for i := int32(0); i < n; i++ {
		if i > 0 {
			fmt.Fscanf(in, " ")
		}
		fmt.Fscanf(in, "%d", &m)
		*arr = append(*arr, m)
	}
	fmt.Fscanf(in, "\n")
}

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

	tt := int32(0)
	fmt.Fscanf(in, "%d\n", &tt)
	for tt > 0 {
		n := int32(0)
		arr := []int32{}
		fmt.Fscanf(in, "%d\n", &n)
		arrayScanf(in, n, &arr)
		fmt.Fprintf(out, "%d\n", solve(n, arr))
		tt--
	}
	out.Flush()
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var cases, n int
	fmt.Scanf("%d\n", &cases)
	for ; cases > 0; cases-- {
		fmt.Scanf("%d\n", &n)
		array := make([]int, n)
		for k := 0; k < n; k++ {
			fmt.Scanf("%d", &array[k])
		}
		// fmt.Scanln()
		sort.Ints(array)
		i := 1
		for ; i < n && array[i] == array[i-1]; i++ {
		}
		fmt.Printf("%d\n", n-i)
	}
}

package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var t int
	var a []int

	t = string2Int(scanElement())

	for i := 0; i < t; i++ {
		m := map[int]int{}

		// scan n
		string2Int(scanElement())

		// scan array
		a = arrString2ArrInt(scanArray())
		min := a[0]

		for _, v := range a {
			m[v]++
			if v < min {
				min = v
			}
		}
		fmt.Println(len(a) - m[min])
	}
}

func scanElement() string {
	var input string
	fmt.Scanln(&input)
	return input
}

func scanArray() []string {
	var input string
	fmt.Scanln(&input)
	return strings.Split(input, " ")
}

func string2Int(s string) int {
	i, _ := strconv.Atoi(s)
	return i
}

func arrString2ArrInt(arr []string) []int {
	result := []int{}
	for _, s := range arr {
		i, _ := strconv.Atoi(s)
		result = append(result, i)
	}
	return result
}


package main

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

// github.com/EndlessCheng/codeforces-go
func main() {
	in := bufio.NewReader(os.Stdin)
	n := 0
	Fscan(in, &n)
	a := make([]int64, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	b := make([]int64, n)
	for i := range b {
		Fscan(in, &b[i])
	}

	p := int64(0)
	s := []byte{}
	if n == 1 {
		if a[0] != b[0] {
			Print("IMPOSSIBLE")
		} else {
			Print("SMALL\n0")
		}
		return
	}
	x, y := a[0], a[1]
	if x > y {
		x,y=y,x
	}
	for !eq(b, a) {
		ok := true
		for i := 0; i < n; i++ {
			ok = ok && b[i] == a[n-1-i]
			if b[i] < 1 {
				Print("IMPOSSIBLE")
				return
			}
		}
		if ok {
			s = append(s, 'R')
			break
		}
		if b[0] > b[1] {
			for i, j := 0, n-1; i < j; i++ {
				b[i],b[j]=b[j],b[i]
				j--
			}
			s = append(s, 'R')
		}
		if n == 2 {
			c := b[1] / b[0]
			if b[0] == x {
				if (b[1]-y)%x != 0 {
					Print("IMPOSSIBLE")
					return
				}
				c = (b[1]-y)/x
				b[1] = y
			} else {
				b[1] %= b[0]
			}
			p += c
			if p <= 2e5 {
				s = append(s, bytes.Repeat([]byte{'P'}, int(c))...)
			}
			continue
		}
		for i := len(b) - 1; i > 0; i-- {
			b[i] -= b[i-1]
		}
		p++
		if p <= 2e5 {
			s = append(s, 'P')
		}
	}
	if p > 2e5 {
		Println("BIG")
		Print(p)
		return
	}
	for i, j := 0, len(s)-1; i < j; i++ {
		s[i],s[j]=s[j],s[i]
		j--
	}
	Println("SMALL")
	Println(len(s))
	Print(string(s))
}

func eq(a, b []int64) bool {
	for i, v := range a {
		if v != b[i] {
			return false
		}
	}
	return true
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1358F(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	eq := func(a, b []int64) bool {
		for i, v := range a {
			if v != b[i] {
				return false
			}
		}
		return true
	}
	eqR := func(a, b []int64) bool {
		for i, v := range a {
			if v != b[len(a)-1-i] {
				return false
			}
		}
		return true
	}

	var n int
	Fscan(in, &n)
	a := make([]int64, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	b := make([]int64, n)
	for i := range b {
		Fscan(in, &b[i])
	}

	cntP := int64(0)
	ans := []byte{}
	if n == 1 {
		if a[0] != b[0] {
			Fprint(out, "IMPOSSIBLE")
		} else {
			Fprint(out, "SMALL\n0")
		}
		return
	}
	x, y := a[0], a[1]
	if x > y {
		x, y = y, x
	}
	for !eq(b, a) {
		for _, v := range b {
			if v < 1 {
				Fprint(out, "IMPOSSIBLE")
				return
			}
		}
		if eqR(b, a) {
			ans = append(ans, 'R')
			break
		}
		if b[0] > b[1] {
			for i, j := 0, n-1; i < j; i++ {
				b[i], b[j] = b[j], b[i]
				j--
			}
			ans = append(ans, 'R')
		}
		if n == 2 {
			c := b[1] / b[0]
			if b[0] == x {
				if (b[1]-y)%x != 0 {
					Fprint(out, "IMPOSSIBLE")
					return
				}
				c = (b[1] - y) / x
				b[1] = y
			} else {
				b[1] %= b[0]
			}
			cntP += c
			if cntP <= 2e5 {
				ans = append(ans, bytes.Repeat([]byte{'P'}, int(c))...)
			}
			continue
		}
		for i := len(b) - 1; i > 0; i-- {
			b[i] -= b[i-1]
		}
		cntP++
		if cntP <= 2e5 {
			ans = append(ans, 'P')
		}
	}
	if cntP > 2e5 {
		Fprintln(out, "BIG")
		Fprint(out, cntP)
		return
	}
	for i, j := 0, len(ans)-1; i < j; i++ {
		ans[i], ans[j] = ans[j], ans[i]
		j--
	}
	Fprintln(out, "SMALL")
	Fprintln(out, len(ans))
	Fprint(out, string(ans))
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1358F(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	eq := func(a, b []int64) bool {
		for i, v := range a {
			if v != b[i] {
				return false
			}
		}
		return true
	}
	eqR := func(a, b []int64) bool {
		for i, v := range a {
			if v != b[len(a)-1-i] {
				return false
			}
		}
		return true
	}

	var n int
	Fscan(in, &n)
	a := make([]int64, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	b := make([]int64, n)
	for i := range b {
		Fscan(in, &b[i])
	}

	cntP := int64(0)
	ans := []byte{}
	if n == 1 {
		if a[0] != b[0] {
			Fprint(out, "IMPOSSIBLE")
		} else {
			Fprint(out, "SMALL\n0")
		}
		return
	}
	x, y := a[0], a[1]
	if x > y {
		x, y = y, x
	}
	for !eq(b, a) {
		if b[0] < 1 {
			Fprint(out, "IMPOSSIBLE")
			return
		}
		if eqR(b, a) {
			ans = append(ans, 'R')
			break
		}
		if sort.SliceIsSorted(b, func(i, j int) bool { return b[i] >= b[j] }) {
			for i, j := 0, n-1; i < j; i++ {
				b[i], b[j] = b[j], b[i]
				j--
			}
			ans = append(ans, 'R')
		} else if sort.SliceIsSorted(b, func(i, j int) bool { return b[i] <= b[j] }) {
			if n == 2 {
				c := b[1] / b[0]
				if b[0] == x {
					if (b[1]-y)%x != 0 {
						Fprint(out, "IMPOSSIBLE")
						return
					}
					c = (b[1] - y) / x
					b[1] = y
				} else {
					b[1] %= b[0]
				}
				cntP += c
				if cntP <= 2e5 {
					ans = append(ans, bytes.Repeat([]byte{'P'}, int(c))...)
				}
				continue
			}
			for i := len(b) - 1; i > 0; i-- {
				b[i] -= b[i-1]
			}
			cntP++
			if cntP <= 2e5 {
				ans = append(ans, 'P')
			}
		} else {
			Fprint(out, "IMPOSSIBLE")
			return
		}
	}
	if cntP > 2e5 {
		Fprintln(out, "BIG")
		Fprint(out, cntP)
		return
	}
	for i, j := 0, len(ans)-1; i < j; i++ {
		ans[i], ans[j] = ans[j], ans[i]
		j--
	}
	Fprintln(out, "SMALL")
	Fprintln(out, len(ans))
	Fprint(out, string(ans))
}

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


package main

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

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

	var T int
	fmt.Fscan(in, &T)

	for t := 0; t < T; t++ {
		var n, x int
		fmt.Fscan(in, &n, &x)

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

		z := make([]int, n)
		copy(z, arr)
		sort.Ints(z)

		f := true
		for i := 0; i < n; i++ {
			if z[i] != arr[i] && i-x < 0 && i+x >= n {
				f = false
				break
			}
		}

		if !f {
			fmt.Fprintln(out, "NO")
		} else {
			fmt.Fprintln(out, "YES")
		}
	}
}

package main

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

/*
1 6 3 4 2 5 0
1 6 3 0 2 5 4
1 6 3 4 2 0 5

5 1 2 3 4
::: 3 1 2 5 4
::: 2 1 (3) 5 4
::: 4 1 (3) 5 2
::: 4 (2) (3) 5 1
::: 5 (2) (3) (4) 1
::: (1) (2) (3) (4) (5)
*/

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

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

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

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(input, &t)

	for i := 0; i < t; i++ {
		var n, x int
		fmt.Fscan(input, &n, &x)
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(input, &arr[i])
		}
		arrCopy := make([]int, n)
		copy(arrCopy, arr)
		sort.Ints(arrCopy)
		possible := true
		for i := n - x; i < x; i++ {
			if arrCopy[i] != arr[i] {
				possible = false
				break
			}
		}
		if possible {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}

	}
}

package main

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

func CF1592B(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var t int
	var n, x int
	arr := make([]int, 2e5+10)
Outer:
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &x)
		s := make([]int, n)
		for i := 0; i < n; i++ {
			Fscan(in, &arr[i])
			s[i] = arr[i]
		}
		sort.Ints(s)
		for i, j := n-x, x-1; i <= j; i++ {
			if arr[i] != s[i] {
				Fprintln(out, "NO")
				continue Outer
			}
		}
		Fprintln(out, "YES")
	}
}

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

package main

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

/*
1 6 3 4 2 5 0
1 6 3 0 2 5 4
1 6 3 4 2 0 5

5 1 2 3 4
::: 3 1 2 5 4
::: 2 1 (3) 5 4
::: 4 1 (3) 5 2
::: 4 (2) (3) 5 1
::: 5 (2) (3) (4) 1
::: (1) (2) (3) (4) (5)
*/

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

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

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

func isSameSlice(arr1 []int, arr2 []int) bool {
	for i := 0; i < len(arr1)-1; i++ {
		if arr1[i] != arr2[i] {
			return false
		}
	}
	return true
}

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(input, &t)

	for i := 0; i < t; i++ {
		var n, x int
		fmt.Fscan(input, &n, &x)
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(input, &arr[i])
		}
		arrCopy := make([]int, n)
		copy(arrCopy, arr)
		sort.Ints(arrCopy)
		if n-x <= n-(n-x) {
			checkSlice1 := arr[n-x : n-(n-x)]
			checkSlice2 := arrCopy[n-x : n-(n-x)]
			// fmt.Println(checkSlice1, checkSlice2)
			if !isSameSlice(checkSlice1, checkSlice2) {
				fmt.Println("NO")
			} else {
				fmt.Println("YES")
			}
		} else {
			fmt.Println("YES")
		}

	}
}

package main

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

/*
1 6 3 4 2 5 0
1 6 3 0 2 5 4
1 6 3 4 2 0 5

5 1 2 3 4
::: 3 1 2 5 4
::: 2 1 (3) 5 4
::: 4 1 (3) 5 2
::: 4 (2) (3) 5 1
::: 5 (2) (3) (4) 1
::: (1) (2) (3) (4) (5)
*/

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

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

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

func isSameSlice(arr1 []int, arr2 []int) bool {
	for i := 0; i < len(arr1)-1; i++ {
		if arr1[i] != arr2[i] {
			return false
		}
	}
	return true
}

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(input, &t)

	for i := 0; i < t; i++ {
		var n, x int
		fmt.Fscan(input, &n, &x)
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(input, &arr[i])
		}
		arrCopy := make([]int, n)
		copy(arrCopy, arr)
		sort.Ints(arrCopy)
		if n-x < n-(n-x) {
			checkSlice1 := arr[n-x : n-(n-x)]
			checkSlice2 := arrCopy[n-x : n-(n-x)]
			// fmt.Println(checkSlice1, checkSlice2)
			if !isSameSlice(checkSlice1, checkSlice2) {
				fmt.Println("NO")
			} else {
				fmt.Println("YES")
			}
		} else {
			fmt.Println("YES")
		}

	}
}

package main

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

/*
1 6 3 4 2 5 0
1 6 3 0 2 5 4
1 6 3 4 2 0 5

5 1 2 3 4
::: 3 1 2 5 4
::: 2 1 (3) 5 4
::: 4 1 (3) 5 2
::: 4 (2) (3) 5 1
::: 5 (2) (3) (4) 1
::: (1) (2) (3) (4) (5)
*/

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

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

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

func isSorted(arr []int) bool {
	for i := 0; i < len(arr)-1; i++ {
		if arr[i] > arr[i+1] {
			return false
		}
	}
	return true
}

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(input, &t)

	for i := 0; i < t; i++ {
		var n, x int
		fmt.Fscan(input, &n, &x)
		arr := make([]int, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(input, &arr[i])
		}
		if n-x < n-(n-x) {
			checkSlice := arr[n-x : n-(n-x)]
			if !isSorted(checkSlice) {
				fmt.Println("NO")
			} else {
				fmt.Println("YES")
			}
		} else {
			fmt.Println("YES")
		}

	}
}