Devu is a dumb guy, his learning curve is very slow. You are supposed to teach him n subjects, the ith subject has ci chapters. When you teach him, you are supposed to teach all the chapters of a subject continuously.Let us say that his initial per chapter learning power of a subject is x hours. In other words he can learn a chapter of a particular subject in x hours.Well Devu is not complete dumb, there is a good thing about him too. If you teach him a subject, then time required to teach any chapter of the next subject will require exactly 1 hour less than previously required (see the examples to understand it more clearly). Note that his per chapter learning power can not be less than 1 hour.You can teach him the n subjects in any possible order. Find out minimum amount of time (in hours) Devu will take to understand all the subjects and you will be free to do some enjoying task rather than teaching a dumb guy.Please be careful that answer might not fit in 32 bit data type.

The first line will contain two space separated integers n, x (1 ≤ n, x ≤ 105). The next line will contain n space separated integers: c1, c2, ..., cn (1 ≤ ci ≤ 105).

Output a single integer representing the answer to the problem.

NoteLook at the first example. Consider the order of subjects: 1, 2. When you teach Devu the first subject, it will take him 3 hours per chapter, so it will take 12 hours to teach first subject. After teaching first subject, his per chapter learning time will be 2 hours. Now teaching him second subject will take 2 × 1 = 2 hours. Hence you will need to spend 12 + 2 = 14 hours.Consider the order of subjects: 2, 1. When you teach Devu the second subject, then it will take him 3 hours per chapter, so it will take 3 × 1 = 3 hours to teach the second subject. After teaching the second subject, his per chapter learning time will be 2 hours. Now teaching him the first subject will take 2 × 4 = 8 hours. Hence you will need to spend 11 hours.So overall, minimum of both the cases is 11 hours.Look at the third example. The order in this example doesn't matter. When you teach Devu the first subject, it will take him 3 hours per chapter. When you teach Devu the second subject, it will take him 2 hours per chapter. When you teach Devu the third subject, it will take him 1 hours per chapter. In total it takes 6 hours.

package main

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

func solve(n int, t int, arr []int) int64 {
	sort.Slice(arr, func(i int, j int) bool { return arr[i] < arr[j] })
	total := int64(0)

	for i := range arr {
		total += int64(arr[i]) * int64(t)
		if t > 1 {
			t--
		}
	}
	return total
}

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

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

	arr := make([]int, n)

	for i := range arr {
		fmt.Fscanf(r, "%d", &arr[i])
	}

	fmt.Fprintf(os.Stdout, "%d\n", solve(n, t, arr))
}

package main

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

func solve(n int64, t int64, arr []int64) int64 {
	sort.Slice(arr, func(i int, j int) bool { return arr[i] < arr[j] })
	total := int64(0)

	for i := range arr {
		total += arr[i] * t
		if t > 1 {
			t--
		}
	}
	return total
}

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

	var n, t int64
	fmt.Fscanf(r, "%d %d\n", &n, &t)

	arr := make([]int64, n)

	for i := range arr {
		fmt.Fscanf(r, "%d", &arr[i])
	}

	fmt.Fprintf(os.Stdout, "%d\n", solve(n, t, arr))
}

package main

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

func main() {
	reader := NewStdReader(os.Stdin)
	n, x := reader.ReadInt(), reader.ReadInt()
	c := make([]int, n)
	for i := 0; i < n; i++ {
		c[i] = reader.ReadInt()
	}
	sort.Ints(c)

	time := int64(0)
	for i := 0; i < n; i++ {
		time += int64(x) * int64(c[i])
		if x > 1 {
			x--
		}
	}

	fmt.Print(time)
}

type StdReader struct {
	buf *bufio.Reader
}

func NewStdReader(reader io.Reader) *StdReader {
	return &StdReader{bufio.NewReaderSize(reader, 20*1024*1024)}
}

func (std *StdReader) ReadInt() int {

	r := 0
	sign := 1
	ok := false

	for {
		b, e := std.buf.ReadByte()

		if e != nil {
			break
		}
		if b >= '0' && b <= '9' {
			r = r*10 + int(b-'0')
			ok = true
		} else {
			if ok {
				break
			} else {
				if b == '-' {
					sign = -sign
				}
			}
		}
	}

	return sign * r
}

package main

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

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Split(bufio.ScanWords)
    var n,x int
    fmt.Scan(&n,&x)
    a := make([]int,n)
    for i := 0; i < n; i++ {
        scanner.Scan()
        a[i], _ = strconv.Atoi(scanner.Text())
    }
    sort.Ints(a)
    var ans int64 = 0
    for i := 0; i < n; i++ {
        ans += int64(a[i])*int64(x)
        if x != 1 { x-- }
    }
    fmt.Println(ans)
}

package main

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

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

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

	n, x := nextInt(), nextInt()
	c := make([]int, n)

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

	sort.Ints(c)

	totalHours := int64(0)

	for i:=0; i<n; i++ {
		totalHours += int64(c[i]) * int64(x)

		if x > 1 {
			x--
		}
	}

	println(totalHours)
}

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

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

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

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

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

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

package main

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

func main() {
	var n int
	var k int64
	input := bufio.NewScanner(os.Stdin)
    	input.Split(bufio.ScanWords)
    	fmt.Scan(&n,&k)
	a:=make([]int,n)

	for i:=0;i<n;i++ {
		input.Scan()
       		aa, _ := strconv.Atoi(input.Text())
		a[i]=aa
	}
	sort.Ints(a)
	//for _,v =range a {
		//fmt.Println(v)
	//}
	var no,c int64
	no = k
	c=0
	for i:=0;i<n;i++ {
		if no<1 {
			no=1
		}
		c += no* int64(a[i])
		no--
	}
	fmt.Println(c)
}

package main

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

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

	//var n int64
	var x int64
	var c []int64

	inputLine1, _ := reader.ReadString('\n')
	tmp := strings.Split(strings.TrimSpace(inputLine1), " ")
	//n, _ = strconv.ParseInt(string(tmp[0]), 10, 64)
	x, _ = strconv.ParseInt(string(tmp[1]), 10, 64)

	inputLine2, _ := reader.ReadString('\n')
	tmpArray := strings.Split(strings.TrimSpace(inputLine2), " ")

	c = convertStringToInt64(tmpArray)

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

	var time int64 = 0
	for _, value := range c {
		time += value * x
		if x > 1 {
			x -= 1
		}
	}
	fmt.Println(time)
}

func convertStringToInt64(minutes []string) []int64 {
	var result []int64
	for _, string := range minutes {
		if string == "" {
			continue
		}
		value, err := strconv.ParseInt(string, 10, 64)
		if err != nil {
			fmt.Println(err)
		}
		result = append(result, value)
	}
	return result
}

package main

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

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

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

	merge_sort(c, 0, n-1)

	time := int64(0)
	xx := int64(x)
	for i := 0; i < n; i++ {
		time += int64(c[i]) * xx
		if xx > 1 {
			xx -= 1
		}
	}
	fmt.Println(time)
}

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

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

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

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

package main

import (
	"bufio"
	"bytes"
	"errors"
	"flag"
	"fmt"
	"io"
	"log"
	"os"
	"sort"
	"strconv"
	"time"
	"unicode/utf8"
)

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

var ()

func solve() {
	n := readInt()
	time := readInt()
	mas := make([]int, n)
	for i := 0; i < n; i++ {
		mas[i] = readInt()
	}

	sort.Ints(mas)
	res := int64(0)
	for i := 0; i < n; i++ {
		res += int64(time) * int64(mas[i])
		if time > 1 {
			time--
		}
	}
	printInt64(res)
}

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

// IO.

var (
	scanner *Scanner
	writer  *bufio.Writer
	logger  *log.Logger
)

func main() {
	local := flag.Bool("local", false, "Equals true, if run is local.")
	flag.Parse()

	var (
		input  *os.File
		output *os.File
	)

	if *local {
		startTime := time.Now()
		defer func() {
			println(fmt.Sprintf("Time: %.5fs", time.Since(startTime).Seconds()))
		}()
		input, _ = os.Open("/home/outside/coding/workspace/go/io/input.txt")
		output, _ = os.Create("/home/outside/coding/workspace/go/io/output.txt")
		logger = log.New(output, "log: ", 0)
	} else {
		input = os.Stdin
		output = os.Stdout
		// input, _ = os.Open("")
		// output, _ = os.Create("")
	}
	defer input.Close()
	defer output.Close()

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

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

	solve()
}

// Read.

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

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

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

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

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

// Write.

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

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

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

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

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

// Log.

func logln(value ...interface{}) {
	writer.Flush()
	logger.Println(value...)
}
func logf(format string, value ...interface{}) {
	writer.Flush()
	logger.Printf(format, value...)
}

// Tuple

type Tuple struct {
	a, b int
}

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

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

type TupleSlice []Tuple

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

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

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

// Min, max, abs.

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

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

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

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

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

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

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

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

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

// Set Key interface implementations.

type Int int

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

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

// Set.

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

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

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

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

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

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

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

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

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

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

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

	return x
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// Split functions

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

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

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

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

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

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

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

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

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

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

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

package main

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

func solve(n int, t int, arr []int) int64 {
	sort.Slice(arr, func(i int, j int) bool { return arr[i] < arr[j] })
	total := int64(0)

	for i := range arr {
		total += int64(arr[i] * t)
		if t > 1 {
			t--
		}
	}
	return total
}

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

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

	arr := make([]int, n)

	for i := range arr {
		fmt.Fscanf(r, "%d", &arr[i])
	}

	fmt.Fprintf(os.Stdout, "%d\n", solve(n, t, arr))
}

package main

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

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

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

	n, x := nextInt(), nextInt()
	c := make([]int, n)

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

	sort.Ints(c)

	totalHours := 0

	for i:=0; i<n; i++ {
		totalHours += c[i] * x

		if x > 1 {
			x--
		}
	}

	println(totalHours)
}

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

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

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

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

func print(a ...interface{}) {
	fmt.Fprint(writer, a...)
}

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

package main

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

func solve(n int, t int, arr []int) int {
	sort.Slice(arr, func(i int, j int) bool { return arr[i] < arr[j] })
	total := 0

	for i := range arr {
		total += arr[i] * t
		if t > 1 {
			t--
		}
	}
	return total
}

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

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

	arr := make([]int, n)

	for i := range arr {
		fmt.Fscanf(r, "%d", &arr[i])
	}

	fmt.Fprintf(os.Stdout, "%d\n", solve(n, t, arr))
}


The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills.The boy is now looking at the ratings of consecutive participants written in a binary system. He thinks that the more such ratings differ, the more unfair is that such people are next to each other. He defines the difference between two numbers as the number of bit positions, where one number has zero, and another has one (we suppose that numbers are padded with leading zeros to the same length). For example, the difference of $$$5 = 101_2$$$ and $$$14 = 1110_2$$$ equals to $$$3$$$, since $$$0101$$$ and $$$1110$$$ differ in $$$3$$$ positions. Johnny defines the unfairness of the contest as the sum of such differences counted for neighboring participants.Johnny has just sent you the rating sequence and wants you to find the unfairness of the competition. You have noticed that you've got a sequence of consecutive integers from $$$0$$$ to $$$n$$$. That's strange, but the boy stubbornly says that everything is right. So help him and find the desired unfairness for received numbers.

The input consists of multiple test cases. The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 10\,000$$$) — the number of test cases. The following $$$t$$$ lines contain a description of test cases. The first and only line in each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^{18})$$$.

Output $$$t$$$ lines. For each test case, you should output a single line with one integer — the unfairness of the contest if the rating sequence equals to $$$0$$$, $$$1$$$, ..., $$$n - 1$$$, $$$n$$$.

NoteFor $$$n = 5$$$ we calculate unfairness of the following sequence (numbers from $$$0$$$ to $$$5$$$ written in binary with extra leading zeroes, so they all have the same length):   $$$000$$$  $$$001$$$  $$$010$$$  $$$011$$$  $$$100$$$  $$$101$$$ The differences are equal to $$$1$$$, $$$2$$$, $$$1$$$, $$$3$$$, $$$1$$$ respectively, so unfairness is equal to $$$1 + 2 + 1 + 3 + 1 = 8$$$.

package main

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

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

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

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

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

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

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

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

	return i
}

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

	tc := readNum(reader)

	for tc > 0 {
		tc--
		var num uint64
		s, _ := reader.ReadBytes('\n')
		readUint64(s, 0, &num)

		fmt.Println(solve(num))
	}
}

const N = 64

var dp []uint64

func init() {
	dp = make([]uint64, N)
	dp[0] = 1

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

func solve(num uint64) uint64 {
	var res uint64

	for i := N - 1; i > 0; i-- {
		if (num>>i)&1 == 1 {
			res += dp[i-1] + uint64(i+1)
		}
	}

	if num&1 == 1 {
		res++
	}

	return res
}

package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)
var input io.Reader

func main() {
	var (
		T int
	)

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input = bufio.NewReader(os.Stdin)
	fmt.Fscan(input, &T)
	for i := 0; i < T; i++ {
		solver()
	}
}

func solver() {
	var n int64
	fmt.Fscan(input, &n)
	ans := int64(0)
	g := int64(2)
	n++
	for k := n / g; k > 0; k = n / g {

		ans += 2*k - 1
		r := n % g
		if r > 0 {ans++}
		if r > g>>1 {ans++}
		g <<= 1
	}
	r := n % g
	if r > g>>1 {ans++}
	fmt.Println(ans)
}

package main

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

func main() {
	t := int(nextInt())
	for i := 0; i < t; i++ {
		fmt.Println(solve(nextInt()))
	}
}

func solve(n int64) int64 {
	var answer int64
	for n > 0 {
		answer += n
		n /= 2
	}
	return answer
}

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer(make([]byte, 256), 1e9)
	sc.Split(bufio.ScanWords)
}

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

func nextInt() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

/*
URL:
https://codeforces.com/contest/1362/problem/C
*/

package main

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

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	t int
	n int64

	dp [100]int64
)

func main() {
	dp[0] = 1
	for i := int64(1); i <= 60; i++ {
		var d int64
		d = 1 << uint(i)
		dp[i] = dp[i-1] + d
	}
	// PrintfDebug("%v\n", dp)

	t = ReadInt()
	for i := 0; i < t; i++ {
		n = ReadInt64()

		solve()
	}
}

func solve() {
	// for i := int64(1); i <= n; i++ {
	// 	PrintfDebug("%v\n", calcDiff(i, i-1))
	// }
	// PrintfDebug("\n")

	// for i := 0; i <= int(n); i++ {
	// 	PrintfDebug("%2d: %s\n", i, string(ZeroPaddingRuneSlice(i, 10)))
	// }
	// PrintfDebug("\n")

	// sum := int64(0)
	// for i := int64(1); i <= n; i++ {
	// 	sum += calcDiff(i, i-1)
	// 	if PopCount(i) == 1 {
	// 		PrintfDebug("%2d: %d\n", i, sum)
	// 	}
	// }
	// PrintfDebug("\n")

	ans := int64(0)
	for i := 0; i <= 60; i++ {
		if NthBit(n, i) == 1 {
			ans += dp[i]
		}
	}
	fmt.Println(ans)
}

func calcDiff(a, b int64) int64 {
	res := int64(0)

	for i := 0; i < 61; i++ {
		if NthBit(a, i) != NthBit(b, i) {
			res++
		}
	}

	return res
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num int64, nth int) int64 {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num int64, nth int) int64 {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num int64, nth int) int64 {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int64) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

/*******************************************************************/

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

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

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

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

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

package main

import "fmt"

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

	for t := 0; t < nTest; t++ {
		var x, res int64
		fmt.Scan(&x)

		for i := 0; x != 0; i++ {
			if x%2 != 0 {
				res += (1 << (i + 1)) - 1
			}

			x /= 2
		}

		fmt.Println(res)
	}
}

package main

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

func main() {
	defer out.Flush()
	for t := ScanInt(); t > 0; t-- {
		n := ScanInt64()

		c := &big.Int{}
		for n > 0 {
			c = c.Add(c, big.NewInt(n))
			n /= 2
		}
		P(c.String())
	}

}

func length(n int64) int {
	i := 0
	for n > 0 {
		i++
		n = n >> 1
	}
	return i
}

/*********************** I/O ***********************/
var in *bufio.Scanner
var out *bufio.Writer

func init() {
	in = bufio.NewScanner(os.Stdin)
	in.Buffer(make([]byte, 1024), int(1e+9))
	in.Split(bufio.ScanWords)
	out = bufio.NewWriter(os.Stdout)
}

func P(args ...interface{}) {
	print("\n", args...)
}

func PS(args ...interface{}) {
	print(" ", args...)
	print("\n", nil)
}

func print(seperator string, args ...interface{}) {
	for _, arg := range args {
		str := ""
		switch v := arg.(type) {
		case byte:
			str = string(v)
		case rune:
			str = string(v)
		case int:
			str = strconv.Itoa(v)
		case []int:
			sb := strings.Builder{}
			for i := 0; i < len(v); i++ {
				sb.WriteString(strconv.Itoa(v[i]) + " ")
			}
			str = sb.String()
		case int64:
			str = strconv.FormatInt(v, 10)
		case []int64:
			sb := strings.Builder{}
			for i := 0; i < len(v); i++ {
				sb.WriteString(strconv.FormatInt(v[i], 10) + " ")
			}
			str = sb.String()
		case string:
			str = v
		default:
			panic("invalid print arg: " + fmt.Sprintf("%v", arg))

		}
		out.WriteString(str + seperator)
	}
}

func ScanWord() string { in.Scan(); return in.Text() }
func ScanWords(n int) []string {
	s := make([]string, n)
	for i := 0; i < n; i++ {
		s[i] = ScanWord()
	}
	return s
}
func ScanInt() int { i, _ := strconv.Atoi(ScanWord()); return i }
func ScanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = ScanInt()
	}
	return a
}
func ScanInt64() int64 { i, _ := strconv.ParseInt(ScanWord(), 10, 64); return i }
func ScanInt64s(n int) []int64 {
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = ScanInt64()
	}
	return a
}

/*********************** Utils int64 ***********************/
func MnMx64(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn64(args ...int64) int64 { mn, _ := MnMx64(args...); return mn }
func Mx64(args ...int64) int64 { _, mx := MnMx64(args...); return mx }
func LCM64(a, b int64) int64   { return a / GCD64(a, b) * b }
func GCD64(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD64(b%a, a)
}
func SortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func Abs64(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

/*********************** Utils int ***********************/
func MnMx(args ...int) (int, int) {
	minVal, maxVal := math.MaxInt32, math.MinInt32
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int) int { mn, _ := MnMx(args...); return mn }
func Mx(args ...int) int { _, mx := MnMx(args...); return mx }
func LCM(a, b int) int   { return a / GCD(a, b) * b }
func GCD(a, b int) int {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func Abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

func min(a, b int) int {
	return int(math.Min(float64(a), float64(b)))
}

func max(a, b int) int {
	return int(math.Max(float64(a), float64(b)))
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var t int
	fmt.Fscanf(in, "%v\n", &t)
	for now := 0; now < t;now++{
		var n, ans int64
		fmt.Fscanf(in, "%v\n", &n)
		for n > 0 {
			ans += n
			n /= 2
		}
		fmt.Fprintln(out, ans)
	}
	return
}

package main

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

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

func main() {
	defer out.Flush()
	inn.Buffer([]byte{}, 10000000)
	inn.Split(bufio.ScanWords)

	for tt := rd(); tt > 0; tt-- {
		n := rdll()
		Fprintln(out, solve(n))
	}
}

func solve(n int64) int64 {
	if n == 1 {
		return 1
	}
	return solve(n/2) + n
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func rd() (x int) {
	inn.Scan()
	data := inn.Bytes()
	x, _ = strconv.Atoi(string(data))
	return x
}
func rdll() (x int64) {
	inn.Scan()
	data := inn.Bytes()
	x, _ = strconv.ParseInt(string(data), 10, 64)
	return x
}
func rds() string {
	inn.Scan()
	return string(inn.Bytes())
}

package main

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

func getUnfairness(n int64) int64 {
	var res int64
	for d := int64(1); d <= n; d *= 2 {
		res += n / d
	}
	return res
}

func main() {
	defer out.Flush()

	var t int
	for scan(&t); t > 0; t-- {
		var n int64
		scan(&n)
		println(getUnfairness(n))
	}
}

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

func scan(a ...interface{}) {
	fmt.Fscan(in, a...)
}
func println(a ...interface{}) {
	fmt.Fprintln(out, a...)
}


Monocarp and Polycarp are learning new programming techniques. Now they decided to try pair programming.It's known that they have worked together on the same file for $$$n + m$$$ minutes. Every minute exactly one of them made one change to the file. Before they started, there were already $$$k$$$ lines written in the file.Every minute exactly one of them does one of two actions: adds a new line to the end of the file or changes one of its lines.Monocarp worked in total for $$$n$$$ minutes and performed the sequence of actions $$$[a_1, a_2, \dots, a_n]$$$. If $$$a_i = 0$$$, then he adds a new line to the end of the file. If $$$a_i > 0$$$, then he changes the line with the number $$$a_i$$$. Monocarp performed actions strictly in this order: $$$a_1$$$, then $$$a_2$$$, ..., $$$a_n$$$.Polycarp worked in total for $$$m$$$ minutes and performed the sequence of actions $$$[b_1, b_2, \dots, b_m]$$$. If $$$b_j = 0$$$, then he adds a new line to the end of the file. If $$$b_j > 0$$$, then he changes the line with the number $$$b_j$$$. Polycarp performed actions strictly in this order: $$$b_1$$$, then $$$b_2$$$, ..., $$$b_m$$$.Restore their common sequence of actions of length $$$n + m$$$ such that all actions would be correct — there should be no changes to lines that do not yet exist. Keep in mind that in the common sequence Monocarp's actions should form the subsequence $$$[a_1, a_2, \dots, a_n]$$$ and Polycarp's — subsequence $$$[b_1, b_2, \dots, b_m]$$$. They can replace each other at the computer any number of times.Let's look at an example. Suppose $$$k = 3$$$. Monocarp first changed the line with the number $$$2$$$ and then added a new line (thus, $$$n = 2, \: a = [2, 0]$$$). Polycarp first added a new line and then changed the line with the number $$$5$$$ (thus, $$$m = 2, \: b = [0, 5]$$$).Since the initial length of the file was $$$3$$$, in order for Polycarp to change line number $$$5$$$ two new lines must be added beforehand. Examples of correct sequences of changes, in this case, would be $$$[0, 2, 0, 5]$$$ and $$$[2, 0, 0, 5]$$$. Changes $$$[0, 0, 5, 2]$$$ (wrong order of actions) and $$$[0, 5, 2, 0]$$$ (line $$$5$$$ cannot be edited yet) are not correct.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$). Then $$$t$$$ test cases follow. Before each test case, there is an empty line. Each test case contains three lines. The first line contains three integers $$$k$$$, $$$n$$$, $$$m$$$ ($$$0 \le k \le 100$$$, $$$1 \le n, m \le 100$$$) — the initial number of lines in file and lengths of Monocarp's and Polycarp's sequences of changes respectively. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 300$$$). The third line contains $$$m$$$ integers $$$b_1, b_2, \dots, b_m$$$ ($$$0 \le b_j \le 300$$$).

For each test case print any correct common sequence of Monocarp's and Polycarp's actions of length $$$n + m$$$ or -1 if such sequence doesn't exist.

package main

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

func run(r io.Reader, w io.Writer) {
	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)
	defer out.Flush()

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var k, n, m int
		Fscan(in, &k, &n, &m)
		mono, poly, ans := make([]int, n), make([]int, m), make([]int,n+m)

		for i, _ := range mono {
			Fscan(in, &mono[i])
		}
		for i, _ := range poly {
			Fscan(in, &poly[i])
		}

		left, right, ans := 0, 0, []int{}
		for left < n || right < m {
			flag := false
			if left < n {
				if mono[left] == 0 {
					ans = append(ans, mono[left])
					left++; k++
					flag = true

				} else if mono[left] <= k {
					ans = append(ans, mono[left])
					left++; flag = true

				}
			}
			if right < m {
				if poly[right] == 0 {
					ans = append(ans, poly[right])
					right++; k++; flag = true

				} else if poly[right] <= k {
					ans = append(ans, poly[right])
					right++; flag = true

				}
			}
			if !flag {
				goto error
			}
		}
		for _, val := range ans {
			Fprint(out, val, " ")
		}
		Fprintln(out)
		continue
		error:
			Fprintln(out, -1)
	}

}

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

package main

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

func run(r io.Reader, w io.Writer) {
	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)
	defer out.Flush()

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var k, n, m int
		Fscan(in, &k, &n, &m)
		mono, poly, ans := make([]int, n), make([]int, m), make([]int,n+m)

		for i := 0; i < n; i++ {
			Fscan(in, &mono[i])
		}
		for i := 0; i < m; i++ {
			Fscan(in, &poly[i])
		}

		left, right, ans := 0, 0, []int{}
		for left < n || right < m {
			flag := false
			if left < n {
				if mono[left] == 0 {
					ans = append(ans, mono[left])
					left++; k++
					flag = true

				} else if mono[left] <= k {
					ans = append(ans, mono[left])
					left++; flag = true

				}
			}
			if right < m {
				if poly[right] == 0 {
					ans = append(ans, poly[right])
					right++; k++; flag = true

				} else if poly[right] <= k {
					ans = append(ans, poly[right])
					right++; flag = true

				}
			}
			if !flag {
				goto error
			}
		}
		for _, val := range ans {
			Fprint(out, val, " ")
		}
		Fprintln(out)
		continue
		error:
			Fprintln(out, -1)
	}

}

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

package main

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

func run(r io.Reader, w io.Writer) {
	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)
	defer out.Flush()

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var k, n, m int
		Fscan(in, &k, &n, &m)
		mono, poly, ans := make([]int, n), make([]int, m), make([]int,n+m)

		for i := 0; i < n; i++ {
			Fscan(in, &mono[i])
		}
		for i := 0; i < m; i++ {
			Fscan(in, &poly[i])
		}

		left, right, curr := 0, 0, 0
		for left < n && right < m {
			flag := false
			if mono[left] == 0 {
				ans[curr] = 0
				left++; curr++; k++

			} else if mono[left] <= k {
				ans[curr] = mono[left]
				curr++; left++;

			} else {
				flag = true
			}
			if poly[right] == 0 {
				ans[curr] = 0
				curr++; right++; k++

			} else if poly[right] <= k {
				ans[curr] = poly[right]
				curr++; right++

			} else if flag {
				goto error
			}
		}

		for i := left; i < n; i++ {
			if mono[i] == 0 {
				ans[curr] = mono[i]
				curr++; k++

			} else if mono[i] <= k {
				ans[curr] = mono[i]
				curr++

			} else {
				goto error
			}
		}

		for i := right; i < m; i++ {
			if poly[i] == 0 {
				ans[curr] = poly[i]
				curr++; k++

			} else if poly[i] <= k {
				ans[curr] = poly[i]
				curr++

			} else {
				goto error
			}
		}
		for _, val := range ans {
			Fprint(out, val, " ")
		}
		goto routine
	error:
		Fprintln(out, -1)
		continue
	routine:
		Fprintln(out)
	}

}

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

package main

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

func run(r io.Reader, w io.Writer) {
	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)
	defer out.Flush()

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var k, n, m int
		Fscan(in, &k, &n, &m)
		mono, poly, ans := make([]int, n), make([]int, m), make([]int,n+m)

		for i := 0; i < n; i++ {
			Fscan(in, &mono[i])
		}
		for i := 0; i < m; i++ {
			Fscan(in, &poly[i])
		}

		solve := func() {
			left, right, curr := 0, 0, 0
			for left < n || right < m {
				flag := false
				if left < n {
					if mono[left] == 0 {
						ans[curr], flag = 0, true
						left++; curr++; k++

					} else if mono[left] <= k {
						ans[curr], flag = mono[left], true
						curr++; left++
					}
				}
				if right < m {
					if poly[right] == 0 {
						ans[curr], flag = 0, true
						curr++; right++; k++

					} else if poly[right] <= k {
						ans[curr], flag = poly[right], true
						curr++; right++;
					}
				}
				if !flag {
					Fprintln(out, -1)
					return
				}
			}
			for _, val := range ans {
				Fprint(out, val, " ")
			}
			Fprintln(out)
		}
		solve()
	}

}

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

package main

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

const N int = 300 + 10

var a, b [N]int
var ans [N * 2]int
var len, sum int

func check(arr *[N]int, idx *int, length *int) bool {
	change := false
	for *idx <= *length {
		if arr[*idx] == 0 {
			sum++
			ans[sum] = arr[*idx]
			len++
			*idx++
			change = true
		} else if arr[*idx] > len {
			break
		} else {
			sum++
			ans[sum] = arr[*idx]
			*idx++
		}
	}
	return change
}

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

	solve := func(Case int) {
		var k, n, m int
		Fscan(in, &k, &n, &m)
		for i := 1; i <= n; i++ {
			Fscan(in, &a[i])
		}
		for i := 1; i <= m; i++ {
			Fscan(in, &b[i])
		}

		ia, ib := 1, 1
		len, sum = k, 0
		for {
			if !check(&a, &ia, &n) && !check(&b, &ib, &m) {
				break
			}
		}

		if ia <= n || ib <= m {
			Fprintln(out, -1)
		} else {
			for i := 1; i < sum; i++ {
				Fprint(out, ans[i], " ")
			}
			Fprintln(out, ans[sum])
		}

	}

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

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

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	var caseNum int
	fmt.Fscan(r, &caseNum)
	for c := 0; c < caseNum; c++ {
		var k, n, m int
		fmt.Fscan(r, &k, &n, &m)
		opeMono, opePoly := make([]int, n), make([]int, m)
		for i := 0; i < n; i++ {
			fmt.Fscan(r, &opeMono[i])
		}
		for i := 0; i < m; i++ {
			fmt.Fscan(r, &opePoly[i])
		}
		solve1547C(k, opeMono, opePoly)
	}
}
func solve1547C(k int, opeMono, opePoly []int) {
	n, m := len(opeMono), len(opePoly)
	p1, p2, p3 := 0, 0, 0
	ope := make([]int, n+m)
	for p1 < n || p2 < m {
		var isAppend bool = false
		for p1 < n && (opeMono[p1] == 0 || opeMono[p1] <= k) {
			isAppend = true
			ope[p3] = opeMono[p1]
			p3++
			if opeMono[p1] == 0 {
				k++
			}
			p1++
		}
		for p2 < m && (opePoly[p2] == 0 || opePoly[p2] <= k) {
			isAppend = true
			ope[p3] = opePoly[p2]
			p3++
			if opePoly[p2] == 0 {
				k++
			}
			p2++
		}
		if !isAppend {
			fmt.Println("-1")
			return
		}
	}
	w := bufio.NewWriter(os.Stdout)
	for i := 0; i < len(ope); i++ {
		fmt.Fprint(w, ope[i], " ")
	}
	fmt.Fprintln(w)
	w.Flush()
}

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	var caseNum int
	fmt.Fscan(r, &caseNum)
	for c := 0; c < caseNum; c++ {
		var k, n, m int
		fmt.Fscan(r, &k, &n, &m)
		opeMono, opePoly := make([]int, n), make([]int, m)
		for i := 0; i < n; i++ {
			fmt.Fscan(r, &opeMono[i])
		}
		for i := 0; i < m; i++ {
			fmt.Fscan(r, &opePoly[i])
		}
		solve1547C(k, opeMono, opePoly)
	}
}
func solve1547C(k int, opeMono, opePoly []int) {
	n, m := len(opeMono), len(opePoly)
	p1, p2 := 0, 0
	ope:=[]int{}
	for p1 < n || p2 < m {
		var isAppend bool = false
		for p1 < n && (opeMono[p1] == 0 || opeMono[p1] <= k) {
			isAppend = true
			ope=append(ope,opeMono[p1])
			if opeMono[p1] == 0 {
				k++
			}
			p1++
		}
		for p2 < m && (opePoly[p2] == 0 || opePoly[p2] <= k) {
			isAppend = true
			ope=append(ope,opePoly[p2])
			if opePoly[p2] == 0 {
				k++
			}
			p2++
		}
		if !isAppend {
			fmt.Println("-1")
			return
		}
	}
	for i := 0; i < len(ope); i++ {
		fmt.Printf("%d ", ope[i])
	}
	fmt.Printf("\n")
}

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	var caseNum int
	fmt.Fscan(r, &caseNum)
	for c := 0; c < caseNum; c++ {
		var k, n, m int
		fmt.Fscan(r, &k, &n, &m)
		opeMono, opePoly := make([]int, n), make([]int, m)
		for i := 0; i < n; i++ {
			fmt.Fscan(r, &opeMono[i])
		}
		for i := 0; i < m; i++ {
			fmt.Fscan(r, &opePoly[i])
		}
		solve1547C(k, opeMono, opePoly)
	}
}
func solve1547C(k int, opeMono, opePoly []int) {
	n, m := len(opeMono), len(opePoly)
	p1, p2, p3 := 0, 0, 0
	ope := make([]int, n+m)
	for p1 < n || p2 < m {
		var isAppend bool = false
		for p1 < n && (opeMono[p1] == 0 || opeMono[p1] <= k) {
			isAppend = true
			ope[p3] = opeMono[p1]
			p3++
			if opeMono[p1] == 0 {
				k++
			}
			p1++
		}
		for p2 < m && (opePoly[p2] == 0 || opePoly[p2] <= k) {
			isAppend = true
			ope[p3] = opePoly[p2]
			p3++
			if opePoly[p2] == 0 {
				k++
			}
			p2++
		}
		if !isAppend {
			fmt.Println("-1")
			return
		}
	}
	for i := 0; i < len(ope); i++ {
		fmt.Printf("%d ", ope[i])
	}
	fmt.Printf("\n")
}

package main

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

type IO struct {
	in  io.Reader
	out io.Writer
}

func NewIO(in io.Reader, out io.Writer) *IO {
	return &IO{in: bufio.NewReader(in), out: out}
}

func (io *IO) ReadInt() int {
	var res int
	fmt.Fscanf(io.in, "%d\n", &res)
	return res
}

func (io *IO) ReadInts() (int, int, int) {
	var a, b, c int
	fmt.Fscanf(io.in, "%d %d %d\n", &a, &b, &c)
	return a, b, c
}

func (io *IO) ReadPairInt() (int, int) {
	var a, b int
	fmt.Fscanf(io.in, "%d %d\n", &a, &b)
	return a, b
}

func (io *IO) ReadString() string {
	var res string
	fmt.Fscanf(io.in, "%s\n", &res)
	return res
}

func (io *IO) ReadIntSlice(n int) sort.IntSlice {
	var t int
	res := make(sort.IntSlice, 0, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(io.in, "%d", &t)
		res = append(res, t)
	}
	fmt.Fscanf(io.in, "\n")
	return res
}

func (io *IO) Println(v ...interface{}) {
	fmt.Fprintln(io.out, v...)
}

func (io *IO) Print(v ...interface{}) {
	fmt.Fprint(io.out, v...)
}

func (io *IO) Printf(format string, v ...interface{}) {
	fmt.Fprintf(io.out, format, v...)
}

func (io *IO) PrintIntSlice(s sort.IntSlice) {
	for _, v := range s {
		io.Printf("%d ", v)
	}
}

func (io *IO) PrintlnIntSlice(s sort.IntSlice) {
	io.PrintIntSlice(s)
	io.Printf("\n")
}

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

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

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

func main() {
	io := NewIO(os.Stdin, os.Stdout)
	some: for t := io.ReadInt(); t > 0; t-- {
		io.ReadString()
		k, n, m := io.ReadInts()
		a := io.ReadIntSlice(n)
		b := io.ReadIntSlice(m)

		i, j := 0, 0
		ans := ""
		for {
			if i < n && a[i] <= k {
				if a[i] == 0 {
					k++
				}
				ans += strconv.Itoa(a[i]) + " "
				i++
			} else if j < m && b[j] <= k {
				if b[j] == 0 {
					k++
				}
				ans += strconv.Itoa(b[j]) + " "
				j++
			} else if i == n && j == m {
				io.Println(ans)
				break
			} else {
				io.Println(-1)
				continue some
			}
		}
	}
}

package main

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

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 k, n, m int
		fmt.Fscan(in, &k, &n, &m)

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

		var p1, p2 int
		z := make([]int, n+m)
		f := true
		for p1 < n && p2 < m {
			if a[p1] <= b[p2] {
				z[p1+p2] = a[p1]
				p1++
			} else {
				z[p1+p2] = b[p2]
				p2++
			}

			if z[p1+p2-1] == 0 {
				k++
			} else if z[p1+p2-1] > k {
				f = false
				break
			}
		}

		for p1 < n {
			z[p1+p2] = a[p1]
			if a[p1] == 0 {
				k++
			} else if a[p1] > k {
				f = false
				break
			}
			p1++
		}

		for p2 < m {
			z[p1+p2] = b[p2]
			if b[p2] == 0 {
				k++
			} else if b[p2] > k {
				f = false
				break
			}
			p2++
		}

		if !f {
			fmt.Fprintln(out, -1)
		} else {
			for _, v := range z {
				fmt.Fprintf(out, "%d ", v)
			}
			fmt.Fprintln(out)
		}
	}
}

package main

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

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

	var tcs int
	_, _ = fmt.Fscan(in, &tcs)

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

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

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

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

		ans := make([]int, 0, n+m)

		i, j := 0, 0
		for i < n || j < m {
			if j == m {
				if a[i] == 0 {
					k++
				}

				if a[i] > k {
					break
				}

				ans = append(ans, a[i])
				i++
				continue
			}

			if i == n {
				if b[j] == 0 {
					k++
				}

				if b[j] > k {
					break
				}

				ans = append(ans, b[j])
				j++
				continue
			}

			if a[i] < b[j] {
				if a[i] == 0 {
					k++
				}

				if a[i] > k {
					break
				}

				ans = append(ans, a[i])
				i++
			} else {
				if b[j] == 0 {
					k++
				}

				if b[j] > k {
					break
				}

				ans = append(ans, b[j])
				j++
			}
		}

		if len(ans) == n+m {
			for _, v := range ans {
				_, _ = fmt.Fprintf(out, "%d ", v)
			}

			_, _ = fmt.Fprintln(out)
		} else {
			_, _ = fmt.Fprintln(out, "-1")
		}
	}

	_ = out.Flush()
}

func abs(n int) int {
	if n < 0 {
		n = -n
	}

	return n
}

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

	return b
}

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

	return b
}

package main

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

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

func init() {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 4096), 1e9)
}

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

func sint64() int64 {
	s := sstring()
	i := int64(0)
	if s[0] == '-' {
		for _, r := range s[1:] {
			i *= 10
			i -= int64(r - '0')
		}
		return i
	}
	for _, r := range s {
		i *= 10
		i += int64(r - '0')
	}
	return i
}

func sint64s(n int64) []int64 {
	a := make([]int64, n)
	for i := range a {
		a[i] = sint64()
	}
	return a
}

func sstring() string {
	if !scanner.Scan() {
		panic(scanner.Err())
	}
	return scanner.Text()
}

func main() {
	defer writer.Flush()
	for t := sint64(); t > 0; t-- {
		k := sint64()
		n := sint64()
		m := sint64()
		a := sint64s(n)
		b := sint64s(m)
		res := sol(k, n, m, a, b)
		if res == nil {
			printf("-1\n")
		} else {
			for _, r := range res {
				printf("%d ", r)
			}
			printf("\n")
		}
	}
}

func sol(k, n, m int64, a, b []int64) []int64 {
	ai, bi := int64(0), int64(0)
	ret := []int64{}
	for ai < n && bi < m {
		if a[ai] == 0 {
			ret = append(ret, a[ai])
			ai++
			k++
			continue
		}
		if b[bi] == 0 {
			ret = append(ret, b[bi])
			bi++
			k++
			continue
		}
		if a[ai] < b[bi] {
			if a[ai] > k {
				return nil
			}
			ret = append(ret, a[ai])
			ai++
		} else {
			if b[bi] > k {
				return nil
			}
			ret = append(ret, b[bi])
			bi++
		}
	}

	for ai < n {
		if a[ai] == 0 {
			ret = append(ret, a[ai])
			ai++
			k++
			continue
		}
		if a[ai] > k {
			return nil
		}
		ret = append(ret, a[ai])
		ai++
	}

	for bi < m {
		if b[bi] == 0 {
			ret = append(ret, b[bi])
			bi++
			k++
			continue
		}
		if b[bi] > k {
			return nil
		}
		ret = append(ret, b[bi])
		bi++
	}

	return ret
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"io/ioutil"
	"os"
	"strings"
)

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

	solve := func(Case int) {
		var cur, n, m int
		Fscan(in, &cur, &n, &m)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		b := make([]int, m)
		for i := range b {
			Fscan(in, &b[i])
		}

		ans :=[]int{}
		i,j := 0,0
		for i<n||j<m {
			ok := false
			if i < n {
				if a[i] == 0 {
					cur++
					ok=true
					ans = append(ans, a[i])
					i++
				} else {
					if a[i] <= cur {
						ok=true
						ans = append(ans, a[i])
						i++
					}
				}
			}
			if j < m {
				if b[j] == 0 {
					cur++
					ok=true
					ans = append(ans, b[j])
					j++
				} else {
					if b[j] <= cur {
						ok=true
						ans = append(ans, b[j])
						j++
					}
				}
			}
			if !ok {
				Fprintln(out, -1)
				return
			}
		}
		for _, v := range ans {
			Fprint(out, v, " ")
		}
		Fprintln(out)
	}

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

	_leftData, _ := ioutil.ReadAll(in)
	if _s := strings.TrimSpace(string(_leftData)); _s != "" {
		panic("有未读入的数据：\n" + _s)
	}
}

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

package main

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

func run(r io.Reader, w io.Writer) {
	in := bufio.NewReader(r)
	out := bufio.NewWriter(w)
	defer out.Flush()

	var t int
	for Fscan(in, &t); t > 0; t-- {
		var k, n, m int
		Fscan(in, &k, &n, &m)
		mono, poly, ans := make([]int, n), make([]int, m), make([]int,n+m)

		for i := 0; i < n; i++ {
			Fscan(in, &mono[i])
		}
		for i := 0; i < m; i++ {
			Fscan(in, &poly[i])
		}

		left, right, curr := 0, 0, 0
		for left < n && right < m {
			flag := false
			if mono[left] == 0 {
				ans[curr] = 0
				left++; curr++; k++

			} else if mono[left] <= k {
				ans[curr] = mono[left]
				curr++; left++;

			} else {
				flag = true
			}
			if poly[right] == 0 {
				ans[curr] = 0
				curr++; right++; k++

			} else if poly[right] <= k {
				ans[curr] = poly[right]
				curr++; right++

			} else if flag {
				goto error
			}
		}

		for i := left; i < n; i++ {
			if mono[i] == 0 {
				ans[curr] = mono[i]
				curr++

			} else if mono[i] <= k {
				ans[curr] = mono[i]
				curr++

			} else {
				goto error
			}
		}

		for i := right; i < m; i++ {
			if poly[i] == 0 {
				ans[curr] = poly[i]
				curr++

			} else if poly[i] <= k {
				ans[curr] = poly[i]
				curr++

			} else {
				goto error
			}
		}
		for _, val := range ans {
			Fprint(out, val, " ")
		}
		goto routine
		error:
			Fprintln(out, -1)
			continue
		routine:
			Fprintln(out)
	}

}

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

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

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

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

package main

import (
	"fmt"
)

const N int = 300 + 10

var a, b [N]int
var ans [N * 2]int
var len, sum int

func solve(arr *[N]int, idx *int, length *int) bool {
	change := false
	for *idx <= *length {
		if arr[*idx] == 0 {
			sum++
			ans[sum] = arr[*idx]
			len++
			*idx++
			change = true
		} else if arr[*idx] > len {
			break
		} else {
			sum++
			ans[sum] = arr[*idx]
			*idx++
		}
	}
	return change
}

func main() {
	T := 0
	fmt.Scanf("%d\n", &T)
	for ; T > 0; T-- {
		var k, n, m int
		fmt.Scanf("\n%d%d%d\n", &k, &n, &m)
		for i := 1; i <= n; i++ {
			fmt.Scanf("%d", &a[i])
		}
		fmt.Scanf("\n")
		for i := 1; i <= m; i++ {
			fmt.Scanf("%d", &b[i])
		}
		fmt.Scanf("\n")

		ia, ib := 1, 1
		len, sum = k, 0
		for {
			if !solve(&a, &ia, &n) && !solve(&b, &ib, &m) {
				break
			}
		}

		if ia <= n || ib <= m {
			fmt.Println(-1)
		} else {
			for i := 1; i < sum; i++ {
				fmt.Printf("%d ", a[i])
			}
			fmt.Println(a[sum])
		}
	}
}

package main

import (
	"fmt"
)

const N int = 300 + 10

var a, b [N]int
var ans [N * 3]int
var len int

func solve(arr *[N]int, idx *int, length *int) bool {
	change := false
	for *idx <= *length {
		if arr[*idx] == 0 {
			len++
			*idx++
			change = true
		} else if arr[*idx] > len {
			break
		} else {
			ans[1] = a[*idx]
			*idx++
		}
	}
	return change
}

func main() {
	T := 0
	fmt.Scanf("%d\n", &T)
	for ; T > 0; T-- {
		var k, n, m int
		fmt.Scanf("\n%d%d%d\n", &k, &n, &m)
		for i := 1; i <= n; i++ {
			fmt.Scanf("%d", &a[i])
		}
		fmt.Scanf("\n")
		for i := 1; i <= m; i++ {
			fmt.Scanf("%d", &b[i])
		}
		fmt.Scanf("\n")

		ia, ib := 1, 1
		len = k
		for {
			if !solve(&a, &ia, &n) && !solve(&b, &ib, &m) {
				break
			}
		}

		if ia <= n || ib <= m {
			fmt.Println(-1)
		} else {
			for i := 1; i < len; i++ {
				fmt.Printf("%d ", a[i])
			}
			fmt.Println(a[len])
		}
	}
}

package main

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

type IO struct {
	in  io.Reader
	out io.Writer
}

func NewIO(in io.Reader, out io.Writer) *IO {
	return &IO{in: bufio.NewReader(in), out: out}
}

func (io *IO) ReadInt() int {
	var res int
	fmt.Fscanf(io.in, "%d\n", &res)
	return res
}

func (io *IO) ReadInts() (int, int, int) {
	var a, b, c int
	fmt.Fscanf(io.in, "%d %d %d\n", &a, &b, &c)
	return a, b, c
}

func (io *IO) ReadPairInt() (int, int) {
	var a, b int
	fmt.Fscanf(io.in, "%d %d\n", &a, &b)
	return a, b
}

func (io *IO) ReadString() string {
	var res string
	fmt.Fscanf(io.in, "%s\n", &res)
	return res
}

func (io *IO) ReadIntSlice(n int) sort.IntSlice {
	var t int
	res := make(sort.IntSlice, 0, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(io.in, "%d", &t)
		res = append(res, t)
	}
	fmt.Fscanf(io.in, "\n")
	return res
}

func (io *IO) Println(v ...interface{}) {
	fmt.Fprintln(io.out, v...)
}

func (io *IO) Print(v ...interface{}) {
	fmt.Fprint(io.out, v...)
}

func (io *IO) Printf(format string, v ...interface{}) {
	fmt.Fprintf(io.out, format, v...)
}

func (io *IO) PrintIntSlice(s sort.IntSlice) {
	for _, v := range s {
		io.Printf("%d ", v)
	}
}

func (io *IO) PrintlnIntSlice(s sort.IntSlice) {
	io.PrintIntSlice(s)
	io.Printf("\n")
}

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

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

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

func main() {
	io := NewIO(os.Stdin, os.Stdout)
	some: for t := io.ReadInt(); t > 0; t-- {
		io.ReadString()
		k, n, m := io.ReadInts()
		a := io.ReadIntSlice(n)
		b := io.ReadIntSlice(m)

		i, j := 0, 0
		ans := ""
		for {
			if i < n && a[i] <= k {
				if a[i] == 0 {
					k++
				}
				ans += strconv.Itoa(a[i])
				i++
			} else if j < m && b[j] <= k {
				if b[j] == 0 {
					k++
				}
				ans += strconv.Itoa(b[j])
				j++
			} else if i == n && j == m {
				io.Println(ans)
				break
			} else {
				io.Println(-1)
				continue some
			}
		}
	}
}


Mike and Ann are sitting in the classroom. The lesson is boring, so they decided to play an interesting game. Fortunately, all they need to play this game is a string $$$s$$$ and a number $$$k$$$ ($$$0 \le k < |s|$$$).At the beginning of the game, players are given a substring of $$$s$$$ with left border $$$l$$$ and right border $$$r$$$, both equal to $$$k$$$ (i.e. initially $$$l=r=k$$$). Then players start to make moves one by one, according to the following rules: A player chooses $$$l^{\prime}$$$ and $$$r^{\prime}$$$ so that $$$l^{\prime} \le l$$$, $$$r^{\prime} \ge r$$$ and $$$s[l^{\prime}, r^{\prime}]$$$ is lexicographically less than $$$s[l, r]$$$. Then the player changes $$$l$$$ and $$$r$$$ in this way: $$$l := l^{\prime}$$$, $$$r := r^{\prime}$$$. Ann moves first. The player, that can't make a move loses.Recall that a substring $$$s[l, r]$$$ ($$$l \le r$$$) of a string $$$s$$$ is a continuous segment of letters from s that starts at position $$$l$$$ and ends at position $$$r$$$. For example, "ehn" is a substring ($$$s[3, 5]$$$) of "aaaehnsvz" and "ahz" is not.Mike and Ann were playing so enthusiastically that they did not notice the teacher approached them. Surprisingly, the teacher didn't scold them, instead of that he said, that he can figure out the winner of the game before it starts, even if he knows only $$$s$$$ and $$$k$$$.Unfortunately, Mike and Ann are not so keen in the game theory, so they ask you to write a program, that takes $$$s$$$ and determines the winner for all possible $$$k$$$.

The first line of the input contains a single string $$$s$$$ ($$$1 \leq |s| \leq 5 \cdot 10^5$$$) consisting of lowercase English letters.

Print $$$|s|$$$ lines. In the line $$$i$$$ write the name of the winner (print Mike or Ann) in the game with string $$$s$$$ and $$$k = i$$$, if both play optimally

package main

import (
	"bufio"
	"os"
	"runtime"
	"strconv"
)

/* solution */

func solve() {

	s := read()

	min := 'z'
	for _, c := range s {
		if min < c {
			print("Ann")
		} else {
			print("Mike")
			min = c
		}
	}

}

/* stubs */

func main() {

	var f *os.File
	if runtime.GOROOT() == "C:\\Soft\\Go" {
		f, _ = os.Open("input.txt")
		defer f.Close()
	} else {
		f = os.Stdin
	}

	writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	reader = bufio.NewScanner(f)

	const maxCapacity = 1024 * 1024
	buf := make([]byte, maxCapacity)
	reader.Buffer(buf, maxCapacity)

	reader.Split(bufio.ScanWords)

	solve()

}

var reader *bufio.Scanner
var writer *bufio.Writer

func read() string {
	reader.Scan()
	return reader.Text()
}

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

func print(s string) {
	writer.WriteString(s)
	writer.WriteString("\n")
}

func printInt(i int) {
	print(strconv.Itoa(i))
}

func printInt64(i int64) {
	print(strconv.FormatInt(i, 10))
}

func readInt64() int64 {
	reader.Scan()
	ret, _ := strconv.ParseInt(reader.Text(), 10, 64)
	return ret
}

package main

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

func main() {
	io := NewFastIO(os.Stdin, os.Stdout)
	defer io.Flush()

	s := io.Next()
	n := len(s)
	mn := int(1e9)

	for i := 0; i < n; i++ {
		a := int(s[i] - 'a')
		mn = min(mn, a)
		if mn < a {
			io.Println("Ann")
		} else {
			io.Println("Mike")
		}
	}
}

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

type FastIO struct {
	*bufio.Reader
	*bufio.Writer
	c [1]byte
}

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

func (f *FastIO) readC() byte {
	f.Read(f.c[:])
	return f.c[0]
}

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

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

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

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

func (f *FastIO) Print(a ...interface{}) {
	fmt.Fprint(f.Writer, a...)
}

func (f *FastIO) PrintInts(a ...int) {
	if len(a) > 0 {
		f.Print(a[0])
		for _, x := range a[1:] {
			f.Print(" ", x)
		}
	}
}

func (f *FastIO) PrintlnInts(a ...int) {
	f.PrintInts(a...)
	f.Println()
}

package main

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

func main() {
	defer Flush()

	s := readb()
	for _, v := range solve(s) {
		if v == 0 {
			println("Ann")
		} else {
			println("Mike")
		}
	}

}

func solve(s []byte) []int {
	n := len(s)
	a := make([]int, n)
	for i := range a {
		a[i] = int(s[i] - 'a')
	}

	res := make([]int, n)
	minv := 27
	for k, v := range a {
		if v <= minv {
			res[k] = 1
			minv = v
		} else {
			res[k] = 0
		}
	}

	return res
}

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

// IO helper functions

// Returns next token from input.  It must be initialized by SetInput()
// before the first call.
var nextToken func() ([]byte, error)
var nextLine func() ([]byte, error)

// Holds a buffer for output.  It must be initialized by SetOutput().
// All IO fucntions (read*() and [e]print*()) should write to OutputWriter
// instead of this.
var OutputBuffer *bufio.Writer

// Holds an io.Writer.  It must be initialized by SetOutput()
var OutputWriter io.Writer

// Set IO functions for interactive input/output.
func SetInteractive(w io.Writer, r io.Reader) {
	SetUnbefferedInput(r)
	OutputBuffer = nil
	OutputWriter = w
}

// Setup OutputBuffer and OutputWriter.
func SetOutput(w io.Writer) {
	OutputBuffer = bufio.NewWriter(w)
	OutputWriter = OutputBuffer
}

// Flushes OutputBuffer
func Flush() {
	if OutputBuffer != nil {
		OutputBuffer.Flush()
	}
}

// Returns true if c is a white space
func IsSpace(c byte) bool {
	switch c {
	case '\t', '\n', '\v', '\f', '\r', ' ':
		return true
	}
	return false
}

func IsNewLine(c byte) bool {
	switch c {
	case '\n', '\r':
		return true
	}
	return false
}

// Setup nextToken with input buffer.
func SetInput(r io.Reader) {
	buf := new(bytes.Buffer)
	var b []byte

	var i int
	rest := func() ([]byte, error) {
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		return b[j:i], nil
	}
	initial := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextToken = rest
		return rest()
	}
	nextToken = initial

	restLn := func() ([]byte, error) {
		for i < len(b) && IsNewLine(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsNewLine(b[i]) {
			i++
		}
		return b[j:i], nil
	}

	initialLn := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextLine = restLn
		return restLn()
	}
	nextLine = initialLn
}

// Setup nextToken without input buffer.
func SetUnbefferedInput(r io.Reader) {
	buf := bufio.NewReader(r)
	var b []byte

	var i int
	nextToken = func() ([]byte, error) {
		var err error
		if i == len(b) {
			b, err = buf.ReadBytes('\n')
			if err != nil {
				return nil, err
			}
			i = 0
			j := len(b) - 1
			for 0 <= j && IsSpace(b[j]) {
				j--
			}
			b = b[0 : j+1]
		}
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		if i == j {
			return nil, io.ErrUnexpectedEOF
		}
		return b[j:i], nil
	}
}

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

// IO functions

// Reads next token and return it as []byte
func readb() []byte {
	b, err := nextToken()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

// Reads next token and return it as string
func reads() string {
	return string(readb())
}

// Read next line as []byte.  Trailing '\n' will not be included.
// See also comments on readb()
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

// Read next line as string
func readsln() string {
	return string(readbln())
}

// Reads next token and return it as int64
func readll() int64 {
	i, err := strconv.ParseInt(reads(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// Reads next token and return it as int
func readi() int {
	return int(readll())
}

// Reads next token and return it as float64
func readf() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// Write args to OutputWriter with the format f
func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(OutputWriter, f, args...)
}

// Write args to OutputWriter without format
func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(OutputWriter, args...)
}

// Write args to stderr with the format f
func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// Write args to stderr without format
func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

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

// Utilities

func sumSlice(a []int) int {
	var res int
	for _, v := range a {
		res += v
	}
	return res
}

func sumSlicell(a []int64) int64 {
	var res int64
	for _, v := range a {
		res += v
	}
	return res
}

func readInts(N int) (int, []int) {
	if N == 0 {
		N = readi()
	}
	a := make([]int, N)
	for i := range a {
		a[i] = readi()
	}
	return N, a
}

func readIntsll(N int) (int, []int64) {
	if N == 0 {
		N = readi()
	}
	a := make([]int64, N)
	for i := range a {
		a[i] = readll()
	}
	return N, a
}

// reverse slice in place
func reverse(a []int) {
	for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
}

// areverse: allocating reverse
func areverse(a []int) []int {
	b := make([]int, len(a))
	for i := range a {
		b[i] = a[len(a)-i-1]
	}
	return b
}

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

// Simple math functions

const (
	// big prime
	INF  = 1000000007
	INF2 = 1000000009
	INF3 = 998244353
)

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

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

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

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

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

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

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

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

func absf(a float64) float64 {
	if a < 0 {
		return -a
	}
	return a
}

// egcd(a, b) returns d, x, y:
//   d is gcd(a,b)
//   x, y are  integers that satisfy ax + by = d
func egcd(a, b int) (int, int, int) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcd(b, a%b)
	return d, y, x - a/b*y
}

func egcdll(a, b int64) (int64, int64, int64) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcdll(b, a%b)
	return d, y, x - a/b*y
}

func gcd(a, b int) int {
	d, _, _ := egcd(a, b)
	return d
}

func gcdll(a, b int64) int64 {
	d, _, _ := egcdll(a, b)
	return d
}

// set up IO functions
func init() {
	// for non-interactive
	SetInput(os.Stdin)
	SetOutput(os.Stdout)

	// Enable below when interactive.  Its ok to leave above intact.
	// SetInteractive(os.Stdout, os.Stdin)
}

// Author: sighduck
// URL: https://codeforces.com/contest/1220/problem/C

package main

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

func createSmallestLetterExistsArray(s string) []bool {
	smallerLetterExists := make([]bool, len(s))
	smallestLetter := string(s[0])
	for i := 1; i < len(s); i++ {
		l := string(s[i])
		if smallestLetter < l {
			smallerLetterExists[i] = true
		}
		if l < smallestLetter {
			smallestLetter = l
		}
	}
	return smallerLetterExists
}

func Solve(s string) []string {
	winners := make([]string, len(s))
	for i, annWins := range createSmallestLetterExistsArray(s) {
		if annWins {
			winners[i] = "Ann"
		} else {
			winners[i] = "Mike"
		}
	}
	return winners
}

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

	var s string
	fmt.Fscanf(reader, "%s\n", &s)

	for _, elem := range Solve(s) {
		fmt.Fprintf(writer, "%s\n", elem)
	}
}

// Author: sighduck
// URL: https://codeforces.com/contest/1220/problem/C

package main

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

func Solve(s string) []string {
	winners := make([]string, len(s))
	minLetter := "z"
	for i, si := range s {
		currentLetter := string(si)
		if minLetter < currentLetter {
			winners[i] = "Ann"
		} else {
			winners[i] = "Mike"
			minLetter = currentLetter
		}
	}
	return winners
}

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

	var s string
	fmt.Fscanf(reader, "%s\n", &s)

	for _, elem := range Solve(s) {
		fmt.Fprintf(writer, "%s\n", elem)
	}
}


Maxim wants to buy some games at the local game shop. There are $$$n$$$ games in the shop, the $$$i$$$-th game costs $$$c_i$$$.Maxim has a wallet which can be represented as an array of integers. His wallet contains $$$m$$$ bills, the $$$j$$$-th bill has value $$$a_j$$$.Games in the shop are ordered from left to right, Maxim tries to buy every game in that order.When Maxim stands at the position $$$i$$$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $$$i$$$-th game using this bill. After Maxim tried to buy the $$$n$$$-th game, he leaves the shop.Maxim buys the $$$i$$$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $$$i$$$-th game. If he successfully buys the $$$i$$$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game.For example, for array $$$c = [2, 4, 5, 2, 4]$$$ and array $$$a = [5, 3, 4, 6]$$$ the following process takes place: Maxim buys the first game using the first bill (its value is $$$5$$$), the bill disappears, after that the second bill (with value $$$3$$$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $$$c_2 > a_2$$$, the same with the third game, then he buys the fourth game using the bill of value $$$a_2$$$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $$$a_3$$$.Your task is to get the number of games Maxim will buy.

The first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 1000$$$) — the number of games and the number of bills in Maxim's wallet. The second line of the input contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le 1000$$$), where $$$c_i$$$ is the cost of the $$$i$$$-th game. The third line of the input contains $$$m$$$ integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_j \le 1000$$$), where $$$a_j$$$ is the value of the $$$j$$$-th bill from the Maxim's wallet.

Print a single integer — the number of games Maxim will buy.

NoteThe first example is described in the problem statement.In the second example Maxim cannot buy any game because the value of the first bill in his wallet is smaller than the cost of any game in the shop.In the third example the values of the bills in Maxim's wallet are large enough to buy any game he encounter until he runs out of bills in his wallet.

package main

import (
	"bufio"
	"os"
)

func main() {
	defer out.Flush()

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

	c:=make([]int,n)
	for i:=range c {
		c[i]=readInt()
	}
	ans:=0
	for i,j:=0,0;i<m;i++ {
		x := readInt()
		for j<n && c[j]>x { j++ }
		if j==n {
			break
		}
		ans++
		j++
	}
	writeInt(ans)
	out.WriteByte('\n')
}

var in, out = io()

func io() (*bufio.Scanner, *bufio.Writer) {
	in := bufio.NewScanner(os.Stdin)
	in.Split(bufio.ScanWords)
	return in, bufio.NewWriter(os.Stdout)
}

func readInt() int {
	if !in.Scan() {
		panic("Input error")
	}

	b := in.Bytes()

	x := int(0)

	for _, v := range b {
		x = x*10 + int(v-'0')
	}

	return x
}

const (
	INTLEN = 22
)

func writeInt(x int) {
	var neg bool
	if x < 0 {
		neg = true
		x = -x
	}

	var b [INTLEN + 1]byte //negative
	i := INTLEN+1
	for x >= 10 {
		q := x / 10
		i--
		b[i] = byte(x-q*10) + '0'
		x = q
	}
	i--
	b[i] = byte(x) + '0'

	if neg {
		i--
		b[i] = '-'
	}
	out.Write(b[i:])
}

package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	// scan first line
	sc.Scan()
	//mn := getArrInt(sc.Text())
	// scan second line
	sc.Scan()
	games := getArrInt(sc.Text())
	// scan third line
	sc.Scan()
	wallet := getArrInt(sc.Text())

	boughtGames := 0
	billIdx := 0
	for _, game := range games {
		currentBill := wallet[billIdx]
		if currentBill >= game {
			boughtGames++
			billIdx++
			// catch condition where there are much more games than bill
			if billIdx >= len(wallet) {
				break
			}
		}
	}
	fmt.Println(boughtGames)
}

func getArrInt(arrStr string) (arr []int) {
	tokens := strings.Split(arrStr, " ")
	for _, token := range tokens {
		x, _ := strconv.Atoi(token)
		arr = append(arr, x)
	}
	return
}

package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	var c, a []int
	for i := 0; i < n; i++ {
		var t int
		fmt.Scan(&t)
		c = append(c, t)
	}
	for i := 0; i < m; i++ {
		var t int
		fmt.Scan(&t)
		a = append(a, t)
	}
	ret := 0
	for i, j := 0, 0; i < n && j < m; {
		if c[i] <= a[j] {
			ret++
			i++
			j++
		} else {
			i++
		}
	}
	fmt.Println(ret)
}

package main

import (
	"fmt"
)
const (
	maxn = 1000 + 10
)
func main() {
	var n, m int
	fmt.Scan(&n, &m)
	var c, a [maxn]int
	for i := 0; i < n; i++ {
		fmt.Scan(&c[i])
	}
	for i := 0; i < m; i++ {
		fmt.Scan(&a[i])
	}
	ret := 0
	for i, j := 0, 0; i < n && j < m; {
		if c[i] <= a[j] {
			ret++
			i++
			j++
		} else {
			i++
		}
	}
	fmt.Println(ret)
}

package main

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

func main() {
	sc := NewScanner()
	N, M := sc.NextInt(), sc.NextInt()
	c := sc.NextIntArray()
	a := sc.NextIntArray()

	p := 0
	ans := 0
	for i := 0; i < N && p < M; i++ {
		if c[i] <= a[p] {
			p++
			ans++
		}
	}
	fmt.Println(ans)

}

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

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

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

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

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

	return mp
}

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

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)

func readInt() int {
	var ch byte
	var err error
	for {
		ch, err = reader.ReadByte()
		if err != nil {
			return 0
		}
		if unicode.IsDigit(rune(ch)) {
			break
		}
	}
	result := int(ch & 0xf)
	for {
		ch, err = reader.ReadByte()
		if err != nil || !unicode.IsDigit(rune(ch)) {
			return result
		}
		result = result*10 + int(ch&0xf)
	}
	return result
}

const M int = 1005

var (
	n, m, ans int
	c, a [M]int
)

func main() {
	n, m = readInt(), readInt()
	for i := 0; i < n; i++ {
		c[i] = readInt()
	}
	for i := 0; i < m; i++ {
		a[i] = readInt()
	}
	cl, al := c[:n], a[:m]
	for ; len(cl)!=0 && len(al)!=0; {
		if al[0] >= cl[0] {
			ans += 1
			cl = cl[1:]
			al = al[1:]
		} else {
			cl = cl[1:]
		}
	}
	fmt.Println(ans)
	return
}

package main
import "fmt"
func main() {
  var hehe int
  var n, m int
  fmt.Scanf("%d", &n)
  fmt.Scanf("%d", &m)
  fmt.Scanf("%d", &hehe)
  var c []int
  var a []int

  for i:=0; i<n; i++ {
    var tmp int
    fmt.Scanf("%d", &tmp)
    c = append(c, tmp)
  }
  fmt.Scanf("%d", &hehe)
  for i:=0; i<m; i++ {
    var tmp int
    fmt.Scanf("%d", &tmp)
    a = append(a, tmp)
  }
  fmt.Scanf("%d", &hehe)

  aindex := 0
  cindex := 0
  counter := 0
  for cindex<n && aindex<m {
    if c[cindex] <= a[aindex] {
      cindex++
      aindex++
      counter++
    } else {
      cindex++
    }
  }
  fmt.Println(counter)
}

package main

import "fmt"

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

package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	c := make([]int, n)
	a := make([]int, m)
	for i := 0; i < n; i++ {
		fmt.Scan(&c[i])
	}
	for i := 0; i < m; i++ {
		fmt.Scan(&a[i])
	}
	var result, i, j int
	for i < n && j < m {
		if c[i] <= a[j] {
			result++
			i++
			j++
		} else {
			i++
		}
	}
	fmt.Println(result)
}

package main

import (
	"fmt"
)

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

	for i := 0; i < m; i++ {
		var t int
		fmt.Scan(&t)
		a = append(a, t)
	}
	fmt.Println(n, m, c, a)
	ret := 0
	for i, j := 0, 0; i < n && j < m; {
		fmt.Println(i, j, ret, c[i], a[j])
		if c[i] <= a[j] {
			ret++
			i++
			j++
		} else {
			i++
		}
	}
	fmt.Println(ret)
}

package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	var c, a []int
	for i := 0; i < n; i++ {
		var t int
		fmt.Scan(&t)
		c = append(c, t)
	}
	for i := 0; i < m; i++ {
		var t int
		fmt.Scan(&t)
		a = append(a, t)
	}
	ret := 0
	for i, j := 0, 0; i < n && j < m; {
		if c[i] <= a[j] {
			ret++
			i++
			j++
		} else {
			j++
		}
	}
	fmt.Println(ret)
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)

func readInt() int {
	var ch byte
	var err error
	for {
		ch, err = reader.ReadByte()
		if err != nil {
			return 0
		}
		if unicode.IsDigit(rune(ch)) {
			break
		}
	}
	result := int(ch & 0xf)
	for {
		ch, err = reader.ReadByte()
		if err != nil || !unicode.IsDigit(rune(ch)) {
			return result
		}
		result = result*10 + int(ch&0xf)
	}
	return result
}

const M int = 1005

var (
	n, m, ans int
	c, a [M]int
)

func main() {
	n, m = readInt(), readInt()
	for i := 0; i < n; i++ {
		c[i] = readInt()
	}
	for i := 0; i < m; i++ {
		a[i] = readInt()
	}
	cl, al := c[:n], a[:m]
	for ; len(cl)!=0 && len(al)!=0; {
		if al[0] >= cl[0] {
			ans += 1
			cl = cl[1:]
			al = al[1:]
		} else {
			al = al[1:]
		}
	}
	fmt.Println(ans)
	return
}

package main
import "fmt"
func main() {
  var n, m int
  fmt.Scanf("%d %d", &n, &m)
  var c []int
  var a []int

  for i:=0; i<n; i++ {
    var tmp int
    fmt.Scanf("%d", &tmp)
    c = append(c, tmp)
  }
  for i:=0; i<m; i++ {
    var tmp int
    fmt.Scanf("%d", &tmp)
    a = append(a, tmp)
  }

  aindex := 0
  cindex := 0
  counter := 0
  for cindex<n && aindex<m {
    if c[cindex] <= a[aindex] {
      cindex++
      aindex++
      counter++
    } else {
      cindex++
    }
  }
  fmt.Println(counter)
}

package main
import "fmt"
func main() {
  var n, m int
  fmt.Scanf("%d %d", &n, &m)
  var c []int
  var a []int

  for i:=0; i<n; i++ {
    var tmp int
    fmt.Scanf("%d", &tmp)
    c = append(c, tmp)
  }
  for i:=0; i<m; i++ {
    var tmp int
    fmt.Scanf("%d", &tmp)
    a = append(a, tmp)
  }

  aindex := 0
  cindex := 0
  counter := 0
  fmt.Println(a)
  fmt.Println(c)
  for cindex<n && aindex<m {
    if c[cindex] <= a[aindex] {
      cindex++
      aindex++
      counter++
    } else {
      cindex++
    }
  }
  fmt.Println(counter)
}

package main

import (
	"bufio"
	"os"
)

func main() {
	defer out.Flush()

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

	c:=make([]int,n)
	for i:=range c {
		c[i]=readInt()
	}
	ans:=0
	for i,j:=0,0;i<m;i++ {
		x := readInt()
		for j<n && c[j]>x { j++ }
		if j==n {
			break
		}
		ans++
		j++
	}
	writeInt(ans)
	out.WriteByte('\n')
}

var in, out = io()

func io() (*bufio.Scanner, *bufio.Writer) {
	in := bufio.NewScanner(os.Stdin)
	in.Split(bufio.ScanWords)
	return in, bufio.NewWriter(os.Stdout)
}

func readInt() int {
	if !in.Scan() {
		panic("Input error")
	}

	b := in.Bytes()

	x := int(0)

	for _, v := range b {
		x = x*10 + int(v-'0')
	}

	return x
}

const (
	INTLEN = 22
)

func writeInt(x int) {
	var neg bool
	if x < 0 {
		neg = true
		x = -x
	}

	var b [INTLEN + 1]byte //negative
	i := INTLEN
	for x >= 10 {
		q := x / 10
		i--
		b[i] = byte(x-q*10) + '0'
		x = q
	}
	i--
	b[i] = byte(x) + '0'

	if neg {
		i--
		b[i] = '-'
	}
	out.Write(b[i:])
}