The first line contains a single integer $$$n$$$ ($$$1 \leqslant n \leqslant 10^5$$$) — the length of the string. The second line contains a string consisting of English lowercase letters: 'z', 'e', 'r', 'o' and 'n'. It is guaranteed that it is possible to rearrange the letters in such a way that they form a sequence of words, each being either "zero" which corresponds to the digit $$$0$$$ or "one" which corresponds to the digit $$$1$$$.

NoteIn the first example, the correct initial ordering is "zero".In the second example, the correct initial ordering is "oneonezero".

package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	var str string

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

	var one int
	var zero int
	for _, c := range str {
		if c == 'n' {
			one++
		} else if c == 'z' {
			zero++
		}
	}

	ans := []string{}
	for i := 1; i <= one; i++ {
		ans = append(ans, "1")
	}
	for i := 1; i <= zero; i++ {
		ans = append(ans, "0")
	}

	fmt.Printf("%s", strings.Join(ans, " "))
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	var str string

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

	var one int
	var zero int
	for _, c := range str {
		if c == 'n' {
			one++
		} else if c == 'z' {
			zero++
		}
	}

	ans := []string{}
	for i := 1; i <= one; i++ {
		ans = append(ans, "1")
	}
	for i := 1; i <= zero; i++ {
		ans = append(ans, "0")
	}

	fmt.Printf("%s", strings.Join(ans, " "))
}

package main

import "fmt"

func main() {
	var str string
	fmt.Scan(&str)
	fmt.Scan(&str)
	z, o := 0, 0
	for _, r := range str {
		if r == 'z' {z++}
		if r == 'n' {o++}
	}
	for o > 0 {fmt.Print("1 "); o--}
	for z > 0 {fmt.Print("0"); z--; if z == 0 {fmt.Print("\n")} else {fmt.Print(" ")}}
}

package main

import "fmt"

func main() {
	var n int
	var s string

	fmt.Scan(&n, &s)

	z, n := 0, 0

	for _, ch := range s {
		if ch == 'n' {
			n++
		}

		if ch == 'z' {
			z++
		}
	}

	for i := 0; i < z+n; i++ {
		if i > 0 {
			fmt.Print(" ")
		}

		ch := 0
		if i < n {
			ch = 1
		}
		fmt.Print(ch)
	}

	fmt.Println()
}

package main

import "fmt"

func main(){
	var k, n, z int
	var s string
	fmt.Scan(&k, &s)
	for _, x := range s {
		if x == 'n' {
			n++
		} else if x == 'z' {
			z++
		}
	}
	for i := n + z - 1; i >= 0; i-- {
		if n != 0 {
			fmt.Print(1, " ")
			n--
		} else {
			fmt.Print(0, " ")
		}
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var n int
	var str string

	fmt.Fscanf(in, "%d\n", &n)
	fmt.Fscanf(in, "%s\n", &str)
	fmt.Println(solution(str))
}

func solution(str string) string {
	ret := make([]string, 0)
	charMap := make(map[rune]int)
	var numOnes, numZeros int

	for _, char := range str {
		charMap[char] = charMap[char] + 1
	}
	numNs := charMap['n']
	numZs := charMap['z']
	numOs := charMap['o']
	numEs := charMap['e']
	numRs := charMap['r']

	numOnes = numNs
	numZeros = min(numZs, numEs-numNs, numRs, numOs-numNs)

	// for i := 0; i < n-(numOnes+numZeros); i++ {
	// 	ret = append(ret, "0")
	// }
	for i := 0; i < numOnes; i++ {
		ret = append(ret, "1")
	}
	for i := 0; i < numZeros; i++ {
		ret = append(ret, "0")
	}

	return strings.Join(ret, " ")
}

func min(nums ...int) int {
	minValue := nums[0]
	for i := 1; i < len(nums); i++ {
		if nums[i] < minValue {
			minValue = nums[i]
		}
	}
	return minValue
}

package main

import "fmt"

func main(){
	var n, zero, one int = 0, 0, 0
	fmt.Scanln(&n)
	var c rune
	for i := 0;i<n ;i++  {
		fmt.Scanf("%c", &c)
		if c == 'n'{
			one++
		} else if c == 'z'{
				zero++
		}
	}
	for i := 0;i < one ;i++  {
		fmt.Print("1 ")
	}
	for i := 0;i < zero ;i++  {
		fmt.Print("0 ")
	}
}

package main

import "fmt"

func main() {
	var n int
	var str string
	fmt.Scanf("%d\n", &n)
	fmt.Scanf("%s\n", &str)
	var one, zero int
	for _, s := range str {
		if s == 'n' {
			one++
		} else if s == 'z' {
			zero++
		}
	}
	first := true
	for i := 0; i < one; i++ {
		if first {
			fmt.Print("1")
			first = false
		} else {
			fmt.Print(" 1")
		}
	}
	for i := 0; i < zero; i++ {
		if first {
			fmt.Print("0")
			first = false
		} else {
			fmt.Print(" 0")
		}
	}
	fmt.Println()
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"math/rand"
	"os"
)

const INF  = 1000000001

type Pair struct {
	first, second int
}

func sort(arr []int) []int {
	if len(arr) < 2 {
		return arr
	}
	left := 0
	right := len(arr) - 1
	pivot := rand.Int() % len(arr)

	arr[pivot], arr[right] = arr[right], arr[pivot]

	for i := 0; i < len(arr); i++ {
		if arr[i] < arr[right] {
			arr[i], arr[left] = arr[left], arr[i]
			left++
		}
	}

	arr[left], arr[right] = arr[right], arr[left]

	sort(arr[:left])
	sort(arr[left+1:])
	return arr
}

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

func solution(reader io.Reader, writer io.Writer) {
	var s string
	var n int
	fmt.Fscanf(reader, "%d\n%s\n", &n, &s)

	h := make(map[uint8]int)
	for i := 0; i < len(s); i++ {
		h[s[i]]++
	}

	for i := 0; i < min(h['o'], min(h['n'], h['e'])); i++ {
		fmt.Fprintf(writer, "1 ")
	}

	mm := min(h['o'], min(h['n'], h['e']))
	h['o']-=mm
	h['n']-=mm
	h['e']-=mm

	for i := 0; i < min(h['z'], min(h['e'], min(h['r'], h['o']))); i++ {
		fmt.Fprintf(writer, "0 ")
	}
}

func main() {

	//stdin, err := os.Open("file.in")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdin.Close()
	stdin := os.Stdin
	reader := bufio.NewReaderSize(stdin, 1024*1024)

	//stdout, err := os.Create("file.out")
	//if err != nil {
	//	panic(err)
	//}
	//defer stdout.Close()
	stdout := os.Stdout
	writer := bufio.NewWriterSize(stdout, 1024*1024)
	defer writer.Flush()

	solution(reader, writer)
}

package main
import "fmt"

func main(){
	var a, b, c int
	var d string
	fmt.Scan(&a, &d)
	for _, x := range d {
		if x == 'n' {
			b++
		} else if x == 'z' {
			c++
		}
	}
	for i := b + c - 1; i >= 0; i-- {
		if b != 0 {
			fmt.Print(1, " ")
			b--
		} else {
			fmt.Print(0, " ")
		}
	}
}

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

package main

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

func Solve(n int, s string) []int {
	ones, zeros := 0, 0
	for _, elem := range s {
		if string(elem) == "n" {
			ones += 1
		} else if string(elem) == "z" {
			zeros += 1
		}
	}
	answer := []int{}
	for i := 0; i < ones; i++ {
		answer = append(answer, 1)
	}
	for i := 0; i < zeros; i++ {
		answer = append(answer, 0)
	}
	return answer
}

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

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

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

package main

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

// func scanner() string {
// 	scanner := bufio.NewScanner(os.Stdin)
// 	for scanner.Scan() {
// 		return scanner.Text()
// 	}
// 	return ""
// }
func removeRN(arr []byte) []byte {
	if string(arr[len(arr)-2:len(arr)]) == "\r\n" {
		return arr[:len(arr)-2]
	} else if string(arr[len(arr)-1]) == "\n" {
		return arr[:len(arr)-1]
	}
	return arr
}
func main() {
	reader := bufio.NewReader(os.Stdin)
	text1, _ := reader.ReadBytes('\n')
	text2, _ := reader.ReadBytes('\n')
	text1 = removeRN(text1)
	text2 = removeRN(text2)

	// input = append(input, scanner())
	// input = append(input, scanner()
	n, _ := strconv.Atoi(string(text1))
	var zero, one int

	for i := 0; i < n; i++ {
		if string(string(text2)[i]) == "z" {
			zero++
		} else if string(string(text2)[i]) == "n" {
			one++
		}
	}

	result := ""

	for i := 0; i < one; i++ {
		if len(result) == 0 {
			result += "1"
		} else {
			result += " 1"
		}
	}
	for i := 0; i < zero; i++ {
		if len(result) == 0 {
			result += "0"
		} else {
			result += " 0"
		}
	}
	if len(result) == 0 {
		result += "0"
	}
	fmt.Printf("%v", result)
}

package main
import ("fmt"
        "os")
func main(){
    var n int
    fmt.Fscan(os.Stdin, &n)
    var s string
    fmt.Fscan(os.Stdin, &s)
    var cntn = 0
    var cntz = 0
    for i:=0; i < len(s); i ++{
      if(s[i] == 'n'){
        cntn ++
      }
      if(s[i] == 'z'){
        cntz ++
      }
    }
    for i := 0; i < cntn; i ++{
      fmt.Printf("1 ")
    }
    for i := 0; i < cntz; i ++{
      fmt.Printf("0 ")
    }
 }

package main

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

/* solution */

func solve() {

	readInt()
	s := read()
	z, n := 0, 0
	for _, c := range s {
		switch c {
		case 'z':
			z++
		case 'n':
			n++
		}
	}

	for i := 0; i < n; i++ {
		printInt(1)
	}
	for i := 0; i < z; i++ {
		printInt(0)
	}

}

/* 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.ScanLines)

	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(" ")
}

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"
	"os"
)

func main() {
	var n int
	var s string
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &n, &s)
	one := 0
	zero := 0
	for _, v := range s {
		if v == 'n' {
			one++
		} else if v == 'z' {
			zero++
		}
	}
	for i := 0; i < one; i++ {
		fmt.Printf("1 ")
	}
	for i := 0; i < zero; i++ {
		fmt.Printf("0 ")
	}
	fmt.Println()
}

// A. Cards
/*
When Serezha was three years old, he was given a set of cards with letters
for his birthday. They were arranged into words in the way which formed the
boy's mother favorite number in binary notation. Serezha started playing with
them immediately and shuffled them because he wasn't yet able to read.
His father decided to rearrange them. Help him restore the original number,
on condition that it was the maximum possible one.

Input
The first line contains a single integer 𝑛 (1⩽𝑛⩽105) — the length of the string.
The second line contains a string consisting of English lowercase letters:
'z', 'e', 'r', 'o' and 'n'.

It is guaranteed that it is possible to rearrange the letters in such
a way that they form a sequence of words, each being either "zero"
which corresponds to the digit 0 or "one" which corresponds to the digit 1.

Output
Print the maximum possible number in binary notation.
Print binary digits separated by a space. The leading zeroes are allowed.

Examples
Input
4
ezor

Output
0

Input
10
nznooeeoer

Output
1 1 0

Note
In the first example, the correct initial ordering is "zero".

In the second example, the correct initial ordering is "oneonezero".
*/
package main

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

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

func sol1220A(n int, s string) {
	one, zero := 0, 0

	for i := 0; i < n; i++ {
		if s[i] == 'n' {
			one++
		}
		if s[i] == 'z' {
			zero++
		}
	}
	for i := 0; i < one; i++ {
		fmt.Print("1 ")
	}
	for i := 0; i < zero; i++ {
		fmt.Print("0 ")
	}
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	var s string
	fmt.Scan(&n, &s)
	one := strings.Count(s, "n")
	fmt.Print(strings.Repeat("1 ", one))
	zero := strings.Count(s, "z")
	fmt.Print(strings.Repeat("0 ", zero))
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	var s string
	fmt.Scan(&n, &s)
	one := strings.Count(s, "n")
	zero := strings.Count(s, "z")
	for i := 0; i < one; i++ {
		fmt.Print(1, " ")
	}
	for i := 0; i < zero; i++ {
		fmt.Print(0, " ")
	}
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	var n int
	var s string
	fmt.Fscan(in, &n, &s)
	one := strings.Count(s, "n")
	fmt.Print(strings.Repeat("1 ", one))
	zero := strings.Count(s, "z")
	fmt.Print(strings.Repeat("0 ", zero))
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var n int
	var s string
	fmt.Fscan(in, &n, &s)
	one := strings.Count(s, "n")
	zero := strings.Count(s, "z")
	fmt.Fprint(out, strings.Repeat("1 ", one), strings.Repeat("0 ", zero))
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	var str string
	var ans = ""
	_, _ = fmt.Scan(&n)
	_, _ = fmt.Scan(&str)
	arr := strings.Split(str, "")
	for _, element := range arr {
		if element == "n" {
			ans += "1 "
		}
	}
	for _, element := range arr {
		if element == "z" {
			ans += "0 "
		}
	}
	fmt.Println(ans)
}

package main

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

var scan *bufio.Scanner
var writer io.Writer

func init() {
	scan = bufio.NewScanner(os.Stdin)
	writer = os.Stdout
	scan.Split(bufio.ScanWords)
}

func main() {
	solve()
}

func solve() {
	var n int
	fmt.Scan(&n)
	if n < 3 {
		os.Exit(0)
	}
	var s string
	fmt.Scan(&s)
	z := 0
	for i := 0; i < n; i++ {
		if s[i] == "z"[0] {
			z++
		}
		if s[i] == "n"[0] {
			fmt.Fprint(writer, "1 ")
		}
	}
	for i := 0; i < z; i++ {
		fmt.Fprint(writer, "0 ")
	}
}

func nextWord() string {
	scan.Scan()
	str := scan.Text()
	return str
}

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

// https://codeforces.com/problemset/problem/1220/A
package main

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

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

	var n int
	fmt.Fscanf(in, "%d\n", &n)
	var s string
	fmt.Fscanf(in, "%s\n", &s)
	var countZero, countOne int
	for i := 0; i < n; i++ {
		if string(s[i]) == "z" {
			countZero++
		} else if string(s[i]) == "n" {
			countOne++
		}
	}
	var ans string
	for i := 0; i < countOne; i++ {
		if n != 1 {
			ans += "1 "
		} else {
			ans += "1"
		}
		n--
	}

	for i := 0; i < countZero; i++ {
		if n != 1 {
			ans += "0 "
		} else {
			ans += "0"
		}
		n--
	}

	fmt.Fprintln(out, ans)
}

package main

import "fmt"

func main() {
	var (
		n int
		s string
	)
	fmt.Scanf("%d\n%s", &n, &s)

	ones, zeroes := 0, 0
	for _, c := range s {
		if c == 'n' {
			ones++
		}
		if c == 'z' {
			zeroes++
		}
	}

	for i := 0; i < ones; i++ {
		fmt.Print("1 ")
	}
	for i := 0; i < zeroes; i++ {
		fmt.Print("0 ")
	}
}

package main

import "fmt"

func main() {
	var n, nCount, zCount int
	var s, ans string
	_, _ = fmt.Scanf("%d\n", &n)
	_, _ = fmt.Scanf("%s", &s)

	for _, l := range s {
		if string(l) == "n" {
			nCount++
		}
		if string(l) == "z" {
			zCount++
		}
	}

	for i:=0;i<nCount ;i++  {
		ans += "1 "
	}
	for i:=0;i<zCount ;i++  {
		ans += "0 "
	}
	ans = ans[:(len(ans)-1)]
	fmt.Println(ans)
}

package main

import "fmt"

var m = map[rune]int{
	rune('z') : 0,
	rune('e') : 0,
	rune('r') : 0,
	rune('o') : 0,
	rune('n') : 0,
}

func main(){
	var n int
	fmt.Scan(&n)
	var s string
	fmt.Scan(&s)
	fillup(s)
	for {
		if m['o'] >0 && m['n'] >0 && m['e'] > 0{
			fmt.Printf("1 ")
			m['o']--
			m['n']--
			m['e']--
		}else if m['z'] >0 && m['e'] >0 && m['r'] > 0 && m['o']>0{
			fmt.Printf("0 ")
			m['z']--
			m['e']--
			m['r']--
			m['o']--
		}else {
			fmt.Printf("\n")
			break
		}
	}
}

func fillup(s string){
	for _,v := range s{
		m[v]++
	}
}

package main

import "fmt"

func main() {
	var l, n, z int
	var s string
	fmt.Scan(&l, &s)
	for _, x := range s {
		if x == 'n' {
			n++
		} else if x == 'z' {
			z++
		}
	}
	for i := n + z - 1; i >= 0; i-- {
		if n != 0 {
			fmt.Print(1, " ")
			n--
		} else {
			fmt.Print(0, " ")
		}
	}
}

//HOWDY! IT'S ME! A HARD BLACKISH DICK MOVE!
package main

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

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

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

//str := PrintlnInts(X...)

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

func main() {
	_ = ReadInt()
	s := ReadString()
	var table [128]int
	for i := 0; i < len(s); i++ {
		table[s[i]]++
	}
	for i := 0; i < table['n']; i++ {
		fmt.Print("1 ")
	}
	for i := 0; i < table['z']; i++ {
		fmt.Print("0 ")
	}
	fmt.Println("")
}

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

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

func max(args ...int) int {
	if len(args) == 0 {
		panic("empty!")
	}
	max := args[0]
	for i := 1; i < len(args); i++ {
		if args[i] > max {
			max = args[i]
		}
	}
	return max
}

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

func gcd(args ...int) int {
	if len(args) == 0 {
		panic("empty!")
	}
	gcd := args[0]
	for i := 1; i < len(args); i++ {
		gcd = _gcd(gcd, args[i])
	}
	return gcd
}

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

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

func init() {
	ReadString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9))
	// Split sets the split function for the Scanner. The default split function is ScanLines.
	// Split panics if it is called after scanning has started.
	r.Split(bufio.ScanWords)

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

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

func readInt64() int64 {
	return readIntNbits(64)
}

func readInt() int {
	return int(readIntNbits(32))
}

func readIntNbits(n int) int64 {
	i, err := strconv.ParseInt(ReadString(), 0, n)
	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
}

// 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())
}

// PrintIntsLine returns integers string delimited by a space.
func PrintlnInts(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)
}

package main

import "fmt"

func main() {
	var k, n, z int
	var str string
	fmt.Scan(&k, &str)
	for _, x := range str {
		if x == 'n' {
			n++
		} else if x == 'z' {
			z++
		}
	}
	for i := n + z - 1; i >= 0; i-- {
		if n != 0 {
			fmt.Print(1, " ")
			n--
		} else {
			fmt.Print(0, " ")
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strings"
)
var scan *bufio.Scanner
var writer io.Writer

func init() {
	scan = bufio.NewScanner(os.Stdin)
	writer = os.Stdout
	scan.Split(bufio.ScanWords)
}
func main() {
	var n int
	_,_ = fmt.Scan( &n)
	var str string
	_,_ = fmt.Scan(&str)
	fmt.Println(strings.Join(strings.Split(strings.Repeat("1",strings.Count(str, "n")) + strings.Repeat("0",strings.Count(str,"z")),"")," "))
}

// nznooeeoer
// eeennooorz
// n - 2
// 0 - 3
// z - 1
// e - 3
// r - 1
// zero
// one

package main

import (
	"fmt"
	"strings"
)

func main() {
	var s string
	var n int
	fmt.Scan(&n)
	fmt.Scan(&s)
	zcount := 0
	ncount := 0
	for _, c := range s {
		if c == 'z' {
			zcount++
		} else if c == 'n' {
			ncount++
		}
	}
	fmt.Println(strings.Repeat("1 ", ncount) + strings.Repeat("0 ", zcount))

}

package main

import (
	"fmt"
)

func main() {
	var n int
	var str string

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

	fmt.Println(str)

	var one int
	var zero int
	var str2 string
	for _, c := range str {
		str2 += fmt.Sprintf("%x|%d|%c|%x|%d|%c|", c, c, c, 'z', 'z', 'z')
		if c == 'n' {
			one++
		} else if c == 'z' {
			zero++
		}
	}

	fmt.Printf("%s", str2)

	// ans := []string{}
	// for i := 1; i <= one; i++ {
	// 	ans = append(ans, "1")
	// }
	// for i := 1; i <= zero; i++ {
	// 	ans = append(ans, "0")
	// }

	// fmt.Printf("%s", strings.Join(ans, " "))
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	var str string

	fmt.Scanf("%d", &n)
	fmt.Scanf("%s", &str)

	var one int
	var zero int
	for _, c := range str {
		if c == 'n' {
			one++
		} else if c == 'z' {
			zero++
		}
	}

	ans := []string{}
	for i := 1; i <= one; i++ {
		ans = append(ans, "1")
	}
	for i := 1; i <= zero; i++ {
		ans = append(ans, "0")
	}

	ansStr := strings.Join(ans, " ")
	fmt.Println(ansStr)
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	var str string

	fmt.Scanf("%d", &n)
	fmt.Scanf("%s", &str)

	var one int
	var zero int
	runeN := 'n'
	runeZ := 'z'
	for _, c := range str {
		if c == runeN {
			one++
		} else if c == runeZ {
			zero++
		}
	}

	// fmt.Println(one, zero)

	ans := []string{}
	for i := 1; i <= one; i++ {
		ans = append(ans, "1")
	}
	for i := 1; i <= zero; i++ {
		ans = append(ans, "0")
	}

	fmt.Printf("%s", strings.Join(ans, " "))
}

package main

import (
	"fmt"
)

func main() {
	var n int
	var str string

	fmt.Scanf("%d", &n)
	fmt.Scanf("%s", &str)

	var one int
	var zero int
	for _, c := range str {
		if c == 'n' {
			one++
		} else if c == 'z' {
			zero++
		}
	}

	fmt.Println(one, zero)

	// ans := []string{}
	// var ans string
	for i := 1; i <= one; i++ {
		// ans = append(ans, "1")
		fmt.Printf("1 ")
		// ans += "1 "
	}
	for i := 1; i <= zero; i++ {
		// ans = append(ans, "0")
		fmt.Printf("0 ")
		// ans += "0 "
	}

	// fmt.Printf("%s\n", ans)

	// fmt.Printf("%s", strings.Join(ans, " "))
}

package main

import (
	"fmt"
)

func main() {
	var n int
	var str string

	fmt.Scanf("%d", &n)
	fmt.Scanf("%s", &str)

	var one int
	var zero int
	var str2 string
	for _, c := range str {
		str2 += fmt.Sprintf("%x %d %c %x %d %c ", c, c, c, 'z', 'z', 'z')
		if c == 'n' {
			one++
		} else if c == 'z' {
			zero++
		}
	}

	fmt.Println(str2)

	// ans := []string{}
	// for i := 1; i <= one; i++ {
	// 	ans = append(ans, "1")
	// }
	// for i := 1; i <= zero; i++ {
	// 	ans = append(ans, "0")
	// }

	// fmt.Printf("%s", strings.Join(ans, " "))
}

package main

import (
	"fmt"
)

func main() {
	var n int
	var str string

	fmt.Scanf("%d", &n)
	fmt.Scanf("%s", &str)

	var one int
	var zero int
	for _, c := range str {
		if c == 'n' {
			one++
		} else if c == 'z' {
			zero++
		}
	}

	// ans := []string{}
	for i := 1; i <= one; i++ {
		// ans = append(ans, "1")
		fmt.Printf("1 ")
	}
	for i := 1; i <= zero; i++ {
		// ans = append(ans, "0")
		fmt.Printf("0 ")
	}

	// fmt.Printf("%s", strings.Join(ans, " "))
}

package main

import (
	"fmt"
)

func main() {
	var n int
	var str string

	fmt.Scanf("%d", &n)
	fmt.Scanf("%s", &str)

	var one int
	var zero int
	for _, c := range str {
		if c == 'n' {
			one++
		} else if c == 'z' {
			zero++
		}
	}

	// ans := []string{}
	var ans string
	// for i := 1; i <= one; i++ {
	// 	// ans = append(ans, "1")
	// 	// fmt.Printf("1 ")
	// 	ans += "1 "
	// }
	// for i := 1; i <= zero; i++ {
	// 	// ans = append(ans, "0")
	// 	// fmt.Printf("0 ")
	// 	ans += "0 "
	// }

	fmt.Printf("%s\n", ans)

	// fmt.Printf("%s", strings.Join(ans, " "))
}

package main

import (
	"fmt"
)

func main() {
	var n int
	var str string

	fmt.Scanf("%d", &n)
	fmt.Scanf("%s", &str)

	var one int
	var zero int
	for _, c := range str {
		if c == 'n' {
			one++
		} else if c == 'z' {
			zero++
		}
	}

	// ans := []string{}
	var ans string
	for i := 1; i <= one; i++ {
		// ans = append(ans, "1")
		// fmt.Printf("1 ")
		ans += "1 "
	}
	for i := 1; i <= zero; i++ {
		// ans = append(ans, "0")
		// fmt.Printf("0 ")
		ans += "0 "
	}

	fmt.Printf(ans)

	// fmt.Printf("%s", strings.Join(ans, " "))
}

package main

import (
	"fmt"
)

func main() {
	var n int
	var str string

	fmt.Scanf("%d", &n)
	fmt.Scanf("%s", &str)

	var one int
	var zero int
	var str2 string
	for _, c := range str {
		str2 += fmt.Sprintf("%x|%d|%c|%x|%d|%c|", c, c, c, 'z', 'z', 'z')
		if c == 'n' {
			one++
		} else if c == 'z' {
			zero++
		}
	}

	fmt.Printf("%s", str2)

	// ans := []string{}
	// for i := 1; i <= one; i++ {
	// 	ans = append(ans, "1")
	// }
	// for i := 1; i <= zero; i++ {
	// 	ans = append(ans, "0")
	// }

	// fmt.Printf("%s", strings.Join(ans, " "))
}

package main

import (
	"fmt"
)

func main() {
	var n int
	var str string

	fmt.Scanf("%d", &n)
	fmt.Scanf("%s", &str)

	var one int
	var zero int
	for _, c := range str {
		if c == 'n' {
			one++
		} else if c == 'z' {
			zero++
		}
	}

	// ans := []string{}
	var ans string
	for i := 1; i <= one; i++ {
		// ans = append(ans, "1")
		// fmt.Printf("1 ")
		ans += "1 "
	}
	for i := 1; i <= zero; i++ {
		// ans = append(ans, "0")
		// fmt.Printf("0 ")
		ans += "0 "
	}

	fmt.Printf("%s\n", ans)

	// fmt.Printf("%s", strings.Join(ans, " "))
}

package main

import (
	"fmt"
)

func main() {
	var n int
	var str string

	fmt.Scanf("%d", &n)
	fmt.Scanf("%s", &str)

	var one int
	var zero int
	for _, c := range str {
		if c == 'n' {
			one++
		} else if c == 'z' {
			zero++
		}
	}

	// ans := []string{}
	for i := 1; i <= one; i++ {
		// ans = append(ans, "1")
		// fmt.Printf("1 ")
	}
	for i := 1; i <= zero; i++ {
		// ans = append(ans, "0")
		// fmt.Printf("0 ")
	}

	fmt.Printf("0")

	// fmt.Printf("%s", strings.Join(ans, " "))
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	var str string

	fmt.Scanf("%d", &n)
	fmt.Scanf("%s", &str)

	var one int
	var zero int
	var str2 string
	for _, c := range str {
		str2 += fmt.Sprintf("%x %d %c %x %d %c\n", c, c, c, 'z', 'z', 'z')
		if c == 'n' {
			one++
		} else if c == 'z' {
			zero++
		}
	}

	fmt.Println(str2)

	ans := []string{}
	for i := 1; i <= one; i++ {
		ans = append(ans, "1")
	}
	for i := 1; i <= zero; i++ {
		ans = append(ans, "0")
	}

	fmt.Printf("%s", strings.Join(ans, " "))
}

package main

import (
	"fmt"
)

func main() {
	var n int
	var str string

	fmt.Scanf("%d", &n)
	fmt.Scanf("%s", &str)

	var one int
	var zero int
	var str2 string
	for _, c := range str {
		str2 += fmt.Sprintf("%x %d %c %x %d %c ", c, c, c, 'z', 'z', 'z')
		if c == 'n' {
			one++
		} else if c == 'z' {
			zero++
		}
	}

	fmt.Printf("%s", str2)

	// ans := []string{}
	// for i := 1; i <= one; i++ {
	// 	ans = append(ans, "1")
	// }
	// for i := 1; i <= zero; i++ {
	// 	ans = append(ans, "0")
	// }

	// fmt.Printf("%s", strings.Join(ans, " "))
}

package main

import "fmt"

func main() {
	var n int
	var str string
	fmt.Scanf("%d", &n)
	fmt.Scanf("%s", &str)
	var one, zero int
	for _, s := range str {
		if s == 'n' {
			one++
		} else if s == 'z' {
			zero++
		}
	}
	first := true
	for i := 0; i < one; i++ {
		if first {
			fmt.Print("1")
			first = false
		} else {
			fmt.Print(" 1")
		}
	}
	for i := 0; i < zero; i++ {
		if first {
			fmt.Print("0")
			first = false
		} else {
			fmt.Print(" 0")
		}
	}
}

// A. Cards
/*
When Serezha was three years old, he was given a set of cards with letters
for his birthday. They were arranged into words in the way which formed the
boy's mother favorite number in binary notation. Serezha started playing with
them immediately and shuffled them because he wasn't yet able to read.
His father decided to rearrange them. Help him restore the original number,
on condition that it was the maximum possible one.

Input
The first line contains a single integer 𝑛 (1⩽𝑛⩽105) — the length of the string.
The second line contains a string consisting of English lowercase letters:
'z', 'e', 'r', 'o' and 'n'.

It is guaranteed that it is possible to rearrange the letters in such
a way that they form a sequence of words, each being either "zero"
which corresponds to the digit 0 or "one" which corresponds to the digit 1.

Output
Print the maximum possible number in binary notation.
Print binary digits separated by a space. The leading zeroes are allowed.

Examples
Input
4
ezor

Output
0

Input
10
nznooeeoer

Output
1 1 0

Note
In the first example, the correct initial ordering is "zero".

In the second example, the correct initial ordering is "oneonezero".
*/
package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	input1, _, _ := reader.ReadLine()
	n, _ := strconv.Atoi(string(input1))
	input2, _, _ := reader.ReadLine()

	sol1220A(n, string(input2))
}

func sol1220A(n int, s string) {
	for n-1 >= 0 {
		if s[n-1] == 'n' {
			fmt.Print(1, " ")
		} else if s[n-1] == 'z' {
			fmt.Print(0, " ")
		}
		n--
	}
}

// A. Cards
/*
When Serezha was three years old, he was given a set of cards with letters
for his birthday. They were arranged into words in the way which formed the
boy's mother favorite number in binary notation. Serezha started playing with
them immediately and shuffled them because he wasn't yet able to read.
His father decided to rearrange them. Help him restore the original number,
on condition that it was the maximum possible one.

Input
The first line contains a single integer 𝑛 (1⩽𝑛⩽105) — the length of the string.
The second line contains a string consisting of English lowercase letters:
'z', 'e', 'r', 'o' and 'n'.

It is guaranteed that it is possible to rearrange the letters in such
a way that they form a sequence of words, each being either "zero"
which corresponds to the digit 0 or "one" which corresponds to the digit 1.

Output
Print the maximum possible number in binary notation.
Print binary digits separated by a space. The leading zeroes are allowed.

Examples
Input
4
ezor

Output
0

Input
10
nznooeeoer

Output
1 1 0

Note
In the first example, the correct initial ordering is "zero".

In the second example, the correct initial ordering is "oneonezero".
*/
package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	reader.ReadLine()
	input2, _, _ := reader.ReadLine()

	sol1220A(string(input2))
}

func sol1220A(s string) {
	o, z := 0, 0
	for _, c := range s {
		if c == 'n' {
			o++
		} else if c == 'z' {
			z++
		}
	}

	for o > 0 {
		fmt.Print("1 ")
		o--
	}
	for z > 0 {
		fmt.Print("0 ")
		z--
	}
}

package main

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

var scan *bufio.Scanner
var writer io.Writer

func init() {
	scan = bufio.NewScanner(os.Stdin)
	writer = os.Stdout
	scan.Split(bufio.ScanWords)
}

func main() {
	solve()
}

func solve() {
	n := nextInt()
	if n < 3 {
		os.Exit(0)
	}
	s := nextWord()
	z := 0
	o := 0
	for i := 0; i < n; i++ {
		if s[i] == "z"[0] {
			z++
		}
		if s[i] == "n"[0] {
			o++
			fmt.Fprint(writer, "1 ")
		}
	}
	if o == 0 {
		z = 1
	}
	for i := 0; i < z; i++ {
		fmt.Fprint(writer, "0 ")
	}
}

func nextWord() string {
	scan.Scan()
	str := scan.Text()
	return str
}

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

package main

import "fmt"

func main() {
	var n, nCount, zCount int
	var s, ans string
	_, _ = fmt.Scanf("%d\n", &n)
	_, _ = fmt.Scanf("%s", &s)

	fmt.Println(s)

	for _, l := range s {
		if string(l) == "n" {
			nCount++
		}
		if string(l) == "z" {
			zCount++
		}
	}

	for i:=0;i<nCount ;i++  {
		ans += "1 "
	}
	for i:=0;i<zCount ;i++  {
		ans += "0 "
	}
	ans = ans[:(len(ans)-1)]
	fmt.Println(ans)
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	_,_ = fmt.Scanf("%d", &n)
	var str string
	_,_ = fmt.Scanf("%s",&str)
	fmt.Println(strings.Join(strings.Split(strings.Repeat("1",strings.Count(str, "n")) + strings.Repeat("0",strings.Count(str,"z")),"")," "))
}

// nznooeeoer
// eeennooorz
// n - 2
// 0 - 3
// z - 1
// e - 3
// r - 1
// zero
// one

package main

import (
	"fmt"
	"strings"
)

func main() {
	var s string
	fmt.Scan(&s)
	zcount := 0
	ncount := 0
	for _, c := range s {
		if c == 'z' {
			zcount++
		} else if c == 'n' {
			ncount++
		}
	}
	fmt.Println(strings.Repeat("1 ", ncount) + strings.Repeat("0 ", zcount))

}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	var str string

	fmt.Scanf("%d", &n)
	fmt.Scanf("%s", &str)

	var one int
	var zero int
	for _, c := range str {
		if c == 'n' {
			one++
		} else if c == 'z' {
			zero++
		}
	}

	ans := []string{}
	for i := 1; i <= one; i++ {
		ans = append(ans, "1")
	}
	for i := 1; i <= zero; i++ {
		ans = append(ans, "0")
	}

	fmt.Printf("%s", strings.Join(ans, " "))
}

package main

import (
	"fmt"
)

func main() {
	var n int
	var str string

	fmt.Scanf("%d", &n)
	fmt.Scanf("%s", &str)

	fmt.Println(n, str)

	var one int
	var zero int
	var str2 string
	for _, c := range str {
		str2 += fmt.Sprintf("%x|%d|%c|%x|%d|%c|", c, c, c, 'z', 'z', 'z')
		if c == 'n' {
			one++
		} else if c == 'z' {
			zero++
		}
	}

	fmt.Printf("%s", str2)

	// ans := []string{}
	// for i := 1; i <= one; i++ {
	// 	ans = append(ans, "1")
	// }
	// for i := 1; i <= zero; i++ {
	// 	ans = append(ans, "0")
	// }

	// fmt.Printf("%s", strings.Join(ans, " "))
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	var str string

	fmt.Scanf("%d", &n)
	fmt.Scanf("%s", &str)

	var one int
	var zero int
	runeN := 'n'
	runeZ := 'z'
	for _, c := range str {
		if c == runeN {
			one++
		} else if c == runeZ {
			zero++
		}
	}

	fmt.Println(one, zero)

	ans := []string{}
	for i := 1; i <= one; i++ {
		ans = append(ans, "1")
	}
	for i := 1; i <= zero; i++ {
		ans = append(ans, "0")
	}

	fmt.Printf("%s", strings.Join(ans, " "))
}

package main

import (
	"fmt"
	"strings"
)

func main() {
	var n int
	var str string

	fmt.Scanf("%d", &n)
	fmt.Scanf("%s", &str)

	var one int
	var zero int
	for _, c := range str {
		if c == 'n' {
			one++
		} else if c == 'z' {
			zero++
		}
	}

	ans := []string{}
	for i := 1; i <= one; i++ {
		ans = append(ans, "1")
	}
	for i := 1; i <= zero; i++ {
		ans = append(ans, "0")
	}

	fmt.Println(strings.Join(ans, " "))
}

package main

import (
	"fmt"
)

func main() {
	var n int
	var str string

	fmt.Scanf("%d", &n)
	fmt.Scanf("%s", &str)

	var one int
	var zero int
	var str2 string
	for _, c := range str {
		str2 += fmt.Sprintf("%x %d %c %x %d %c\n", c, c, c, 'z', 'z', 'z')
		if c == 'n' {
			one++
		} else if c == 'z' {
			zero++
		}
	}

	fmt.Println(str2)

	// ans := []string{}
	// for i := 1; i <= one; i++ {
	// 	ans = append(ans, "1")
	// }
	// for i := 1; i <= zero; i++ {
	// 	ans = append(ans, "0")
	// }

	// fmt.Printf("%s", strings.Join(ans, " "))
}


International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick an abbreviation with non-empty string y that has never been used before. Among all such valid abbreviations they choose the shortest one and announce it to be the abbreviation of this year's competition.For example, the first three Olympiads (years 1989, 1990 and 1991, respectively) received the abbreviations IAO'9, IAO'0 and IAO'1, while the competition in 2015 received an abbreviation IAO'15, as IAO'5 has been already used in 1995.You are given a list of abbreviations. For each of them determine the year it stands for.

The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the number of abbreviations to process.  Then n lines follow, each containing a single abbreviation. It's guaranteed that each abbreviation contains at most nine digits.

For each abbreviation given in the input, find the year of the corresponding Olympiad.

package main

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

var stdin *bufio.Reader
var stdout *bufio.Writer

func init() {
	stdin = bufio.NewReader(os.Stdin)
    stdout = bufio.NewWriter(os.Stdout)
}

func main() {

    ncase := 0
    fmt.Fscanf(stdin, "%d\n", &ncase)
    for i := 0; i < ncase; i++ {
        str := ""
        fmt.Fscanf(stdin, "IAO'%s\n", &str)

        if len(str) == 1 {
            if str == "9" {
                fmt.Fprintf(stdout, "1989\n")
            } else if len(str) == 1  {
                fmt.Fprintf(stdout, "199%s\n", str)
            }
        } else if len(str) == 2 {
            if str == "99" {
                fmt.Fprintf(stdout, "1999\n")
            } else {
                fmt.Fprintf(stdout, "20%s\n", str)
            }
        } else if len(str) == 3 {
            year, _ := strconv.Atoi(str)
            if 99 <= year {
                fmt.Fprintf(stdout, "2%s\n", str)
            } else {
                fmt.Fprintf(stdout, "3%s\n", str)
            }
        } else if len(str) == 4 {
            year, _ := strconv.Atoi(str)
            if 3099 <= year {
                fmt.Fprintf(stdout, "%s\n", str)
            } else {
                fmt.Fprintf(stdout, "1%s\n", str)
            }
        } else if len(str) == 5 {
            year, _ := strconv.Atoi(str)
            if 13099 <= year {
                fmt.Fprintf(stdout, "%s\n", str)
            } else {
                fmt.Fprintf(stdout, "1%s\n", str)
            }
        } else if len(str) == 6 {
            year, _ := strconv.Atoi(str)
            if 113099 <= year {
                fmt.Fprintf(stdout, "%s\n", str)
            } else {
                fmt.Fprintf(stdout, "1%s\n", str)
            }
        } else if len(str) == 7 {
            year, _ := strconv.Atoi(str)
            if 1113099 <= year {
                fmt.Fprintf(stdout, "%s\n", str)
            } else {
                fmt.Fprintf(stdout, "1%s\n", str)
            }
        } else if len(str) == 8 {
            year, _ := strconv.Atoi(str)
            if 11113099 <= year {
                fmt.Fprintf(stdout, "%s\n", str)
            } else {
                fmt.Fprintf(stdout, "1%s\n", str)
            }
        } else if len(str) == 9 {
            year, _ := strconv.Atoi(str)
            if 111113099 <= year {
                fmt.Fprintf(stdout, "%s\n", str)
            } else {
                fmt.Fprintf(stdout, "1%s\n", str)
            }
        }

    }

    stdout.Flush()
}

package main

import (
    "fmt"
    "strconv"
)

func solve (s string) {
    var ten, step int64 = 0, 10
    y, _  := strconv.ParseInt(s, 10, 64)
    for i := 1; i < len(s); i++ {
        ten  += step
        step *= 10
    }
    for y < 1989 + ten {
        y += step
    }
    fmt.Printf("%d\n", y)
}

func main() {
    n := 1
    var s string = ""
    fmt.Scanf("%d\n", &n)
    for i := 1; i <= n; i++ {
        fmt.Scanf("IAO'%s\n", &s)
        solve(s)
    }
}

package main

import (
    "fmt"
)

func solve (y int) {
    if y < 9 {
        fmt.Printf("199%d\n", y)
    } else if y == 9 {
        fmt.Printf("1989\n")
    } else if y < 99 {
        fmt.Printf("20%d\n", y)
    } else if y == 99 {
        fmt.Printf("1999\n")
    } else if y <= 999 {
        fmt.Printf("2%d\n", y)
    } else if y <= 2999{
        fmt.Printf("1%d\n", y)
    } else {
        fmt.Printf("%d\n", y)
    }
}

func main() {
    n, y := 1, 1
    fmt.Scanf("%d\n", &n)
    for i := 1; i <= n; i++ {
        fmt.Scanf("IAO'%d\n", &y)
        solve(y)
    }
}

package main

import (
    "fmt"
    "strconv"
)

func solve (y int64) {
    var ten, step int64 = 0, 10
    for i := 1; i < len(strconv.Itoa(int(y))); i++ {
        ten  += step
        step *= 10
    }
    for y < 1989 + ten {
        y += step
    }
    fmt.Printf("%d\n", y)
}

func main() {
    n := 1
    var y int64 = 1
    fmt.Scanf("%d\n", &n)
    for i := 1; i <= n; i++ {
        fmt.Scanf("IAO'%d\n", &y)
        solve(y)
    }
}

package main

import (
    "fmt"
    "strconv"
)

func solve (y int64) {
    var ten, step int64 = 0, 10
    for i := 1; i < len(strconv.Itoa(int(y))); i++ {
        ten  += step
        step *= 10
    }
    fmt.Println(ten, step)
    for y < 1989 + ten {
        y += step
    }
    fmt.Printf("%d\n", y)
}

func main() {
    n := 1
    var y int64 = 1
    fmt.Scanf("%d\n", &n)
    for i := 1; i <= n; i++ {
        fmt.Scanf("IAO'%d", &y)
        solve(y)
    }
}

package main

import (
    "fmt"
    "strconv"
)

func solve (y int64) {
    var ten, step int64 = 0, 10
    for i := 1; i < len(strconv.Itoa(int(y))); i++ {
        ten  += step
        step *= 10
    }
    for y < 1989 + ten {
        y += step
    }
    fmt.Printf("%d\n", y)
}

func main() {
    n := 1
    var y int64 = 1
    fmt.Scanf("%d\n", &n)
    for i := 1; i <= n; i++ {
        fmt.Scanf("IAO'%d", &y)
        solve(y)
    }
}

package main

import (
    "fmt"
)

func solve (y int) {
    if y < 9 {
        fmt.Printf("199%d\n", y)
    } else if y == 9 {
        fmt.Printf("1989\n")
    } else if y < 99 {
        fmt.Printf("20%d\n", y)
    } else if y == 99 {
        fmt.Printf("1999\n")
    } else if y <= 999 {
        fmt.Printf("2%d\n", y)
    } else if y <= 2999{
        fmt.Printf("1%d\n", y)
    } else {
        fmt.Printf("%d\n", y)
    }
}

func main() {
    n, y := 1, 1
    fmt.Scanf("%d\n", &n)
    for i := 1; i <= n; i++ {
        fmt.Scanf("IAO'%d", &y)
        solve(y)
    }
}


Please note the non-standard memory limit.There are $$$n$$$ problems numbered with integers from $$$1$$$ to $$$n$$$. $$$i$$$-th problem has the complexity $$$c_i = 2^i$$$, tag $$$tag_i$$$ and score $$$s_i$$$.After solving the problem $$$i$$$ it's allowed to solve problem $$$j$$$ if and only if $$$\text{IQ} < |c_i - c_j|$$$ and $$$tag_i \neq tag_j$$$. After solving it your $$$\text{IQ}$$$ changes and becomes $$$\text{IQ} = |c_i - c_j|$$$ and you gain $$$|s_i - s_j|$$$ points.Any problem can be the first. You can solve problems in any order and as many times as you want.Initially your $$$\text{IQ} = 0$$$. Find the maximum number of points that can be earned.

The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of test cases.  The first line of each test case contains an integer $$$n$$$ $$$(1 \le n \le 5000)$$$  — the number of problems. The second line of each test case contains $$$n$$$ integers $$$tag_1, tag_2, \ldots, tag_n$$$ $$$(1 \le tag_i \le n)$$$  — tags of the problems. The third line of each test case contains $$$n$$$ integers $$$s_1, s_2, \ldots, s_n$$$ $$$(1 \le s_i \le 10^9)$$$  — scores of the problems. It's guaranteed that sum of $$$n$$$ over all test cases does not exceed $$$5000$$$.

For each test case print a single integer  — the maximum number of points that can be earned.

NoteIn the first test case optimal sequence of solving problems is as follows:   $$$1 \rightarrow 2$$$, after that total score is $$$5$$$ and $$$\text{IQ} = 2$$$  $$$2 \rightarrow 3$$$, after that total score is $$$10$$$ and $$$\text{IQ} = 4$$$  $$$3 \rightarrow 1$$$, after that total score is $$$20$$$ and $$$\text{IQ} = 6$$$  $$$1 \rightarrow 4$$$, after that total score is $$$35$$$ and $$$\text{IQ} = 14$$$ In the second test case optimal sequence of solving problems is as follows:   $$$1 \rightarrow 2$$$, after that total score is $$$5$$$ and $$$\text{IQ} = 2$$$  $$$2 \rightarrow 3$$$, after that total score is $$$10$$$ and $$$\text{IQ} = 4$$$  $$$3 \rightarrow 4$$$, after that total score is $$$15$$$ and $$$\text{IQ} = 8$$$  $$$4 \rightarrow 1$$$, after that total score is $$$35$$$ and $$$\text{IQ} = 14$$$ In the third test case optimal sequence of solving problems is as follows:   $$$1 \rightarrow 3$$$, after that total score is $$$17$$$ and $$$\text{IQ} = 6$$$  $$$3 \rightarrow 4$$$, after that total score is $$$35$$$ and $$$\text{IQ} = 8$$$  $$$4 \rightarrow 2$$$, after that total score is $$$42$$$ and $$$\text{IQ} = 12$$$

package main

import . "fmt"

// github.com/EndlessCheng/codeforces-go
func main() {
	var T, n int
	for Scan(&T); T > 0; T-- {
		Scan(&n)
		t := make([]int, n)
		for i := range t {
			Scan(&t[i])
		}
		s := make([]int64, n)
		for i := range s {
			Scan(&s[i])
		}
		f := make([]int64, n)
		for i := 1; i < n; i++ {
			for j := i - 1; j >= 0; j-- {
				if t[j] != t[i] {
					d := s[i] - s[j]
					if d < 0 {
						d = -d
					}
					f[i], f[j] = max(f[i], f[j]+d), max(f[j], f[i]+d)
				}
			}
		}
		Println(max(f...))
	}
}

func max(a ...int64) int64 {
	m := a[0]
	for _, v := range a[1:] {
		if v > m {
			m = v
		}
	}
	return m
}

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 n int
		Fscan(in, &n)
		tag := make([]int, n)
		for i := range tag {
			Fscan(in, &tag[i])
		}
		s := make([]int64, n)
		for i := range s {
			Fscan(in, &s[i])
		}
		dp := make([]int64, n)
		for i := 1; i < n; i++ {
			for j := i - 1; j >= 0; j-- {
				if tag[j] != tag[i] {
					d := abs(s[i] - s[j])
					dp[i], dp[j] = max(dp[i], dp[j]+d), max(dp[j], dp[i]+d)
				}
			}
		}
		Fprintln(out, max(dp...))
	}

	var t int
	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) }

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

func max(a ...int64) int64 {
	res := a[0]
	for _, v := range a[1:] {
		if v > res {
			res = v
		}
	}
	return res
}


A group of tourists is going to kayak and catamaran tour. A rented lorry has arrived to the boat depot to take kayaks and catamarans to the point of departure. It's known that all kayaks are of the same size (and each of them occupies the space of 1 cubic metre), and all catamarans are of the same size, but two times bigger than kayaks (and occupy the space of 2 cubic metres).Each waterborne vehicle has a particular carrying capacity, and it should be noted that waterborne vehicles that look the same can have different carrying capacities. Knowing the truck body volume and the list of waterborne vehicles in the boat depot (for each one its type and carrying capacity are known), find out such set of vehicles that can be taken in the lorry, and that has the maximum total carrying capacity. The truck body volume of the lorry can be used effectively, that is to say you can always put into the lorry a waterborne vehicle that occupies the space not exceeding the free space left in the truck body.

The first line contains a pair of integer numbers n and v (1 ≤ n ≤ 105; 1 ≤ v ≤ 109), where n is the number of waterborne vehicles in the boat depot, and v is the truck body volume of the lorry in cubic metres. The following n lines contain the information about the waterborne vehicles, that is a pair of numbers ti, pi (1 ≤ ti ≤ 2; 1 ≤ pi ≤ 104), where ti is the vehicle type (1 – a kayak, 2 – a catamaran), and pi is its carrying capacity. The waterborne vehicles are enumerated in order of their appearance in the input file.

In the first line print the maximum possible carrying capacity of the set. In the second line print a string consisting of the numbers of the vehicles that make the optimal set. If the answer is not unique, print any of them.

package main

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

type Vehicle struct {
	Index    int
	Capacity int
}

type Sorter struct {
	Vehicles []*Vehicle
}

func (s Sorter) Len() int {
	return len(s.Vehicles)
}
func (s Sorter) Swap(i, j int) {
	s.Vehicles[i], s.Vehicles[j] = s.Vehicles[j], s.Vehicles[i]
}

func (s Sorter) Less(i, j int) bool {
	return s.Vehicles[i].Capacity > s.Vehicles[j].Capacity
}

func main() {
	var n, t int
	var v, p int
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)

	one := make([]*Vehicle, 0, 100000)
	two := make([]*Vehicle, 0, 100000)
	fmt.Fscanf(reader, "%d %d\n", &n, &v)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d %d\n", &t, &p)
		boat := &Vehicle{i + 1, p}
		if t == 1 {
			one = append(one, boat)
		} else {
			two = append(two, boat)
		}
	}
	sort.Sort(Sorter{one})
	sort.Sort(Sorter{two})
	var twoCount, oneCount int
	if v/2 > len(two) {
		twoCount = len(two)
	} else {
		twoCount = v / 2
	}

	if v-twoCount*2 > len(one) {
		oneCount = len(one)
	} else {
		oneCount = v - twoCount*2
	}
	result := 0
	for i := 0; i < oneCount; i++ {
		result += one[i].Capacity
	}
	for i := 0; i < twoCount; i++ {
		result += two[i].Capacity
	}

	for i, j := twoCount-1, oneCount; i >= 0; i-- {
		delta := -two[i].Capacity
		if j < len(one) {
			delta += one[j].Capacity
			j++
		}
		if j < len(one) {
			delta += one[j].Capacity
			j++
		}
		if delta >= 0 {
			result += delta
			twoCount = i
			oneCount = j
		}
		if delta < 0 || oneCount == len(one) {
			break
		}
	}
	fmt.Printf("%d\n", result)
	for i := 0; i < oneCount; i++ {
		fmt.Printf("%d ", one[i].Index)
	}
	for i := 0; i < twoCount; i++ {
		fmt.Printf("%d ", two[i].Index)
	}
}

package main

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

type vehicle struct {
	capacity int
	index    int
	vtype    int
}

func solve() {
	n := readInt()
	v := readInt()

	var kayaks []vehicle
	var catamarans []vehicle

	for i := 0; i < n; i++ {
		t := readInt()
		p := readInt()
		if t == 1 {
			kayaks = append(kayaks, vehicle{p, i, t})
		} else {
			catamarans = append(catamarans, vehicle{p, i, t})
		}
	}

	sort.Slice(kayaks, func(i, j int) bool {
		return kayaks[i].capacity > kayaks[j].capacity
	})
	sort.Slice(catamarans, func(i, j int) bool {
		return catamarans[i].capacity > catamarans[j].capacity
	})

	//	fmt.Println("kayaks", kayaks)
	//	fmt.Println("catamarans", catamarans)

	var which []vehicle

	if v%2 != 0 {
		// Odd sized volume, take the biggest kayak to fill
		// the space.
		if len(kayaks) > 0 {
			which = append(which, kayaks[0])
			kayaks = kayaks[1:]
		}
	}

	for v >= 2 {
		if len(catamarans) == 0 {
			// no catamarans, fill with kayaks
			which = fill(which, kayaks, v)
			v = 0
			continue
		}
		if len(kayaks) == 0 {
			// no kayaks, fill with catamarans
			which = fill(which, catamarans, v)
			v = 0
			continue
		}

		kcap := kayaks[0].capacity
		nkayaks := 1
		if len(kayaks) > 1 {
			nkayaks = 2
			kcap += kayaks[0].capacity
		}

		if kcap > catamarans[0].capacity {
			for i := 0; i < nkayaks; i++ {
				v -= kayaks[0].vtype
				which = append(which, kayaks[0])
				kayaks = kayaks[1:]
			}
		} else {
			v -= catamarans[0].vtype
			which = append(which, catamarans[0])
			catamarans = catamarans[1:]
		}
	}

	var capacity int
	for _, k := range which {
		capacity += k.capacity
	}
	fmt.Println(capacity)
	space := ""
	for _, k := range which {
		fmt.Print(space)
		space = " "
		fmt.Print(k.index + 1)
	}
	fmt.Println("")
}

func fill(which, vehicles []vehicle, v int) []vehicle {
	for _, veh := range vehicles {
		if v < veh.vtype {
			// won't fit
			break
		}
		which = append(which, veh)
		v -= veh.vtype
	}
	return which
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

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

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

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

package main

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

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

type Boat struct {
  Size, Value, Index int
  Skip bool
}
type Boats []Boat
func (boats Boats) Len() int {
  return len(boats)
}
func (boats Boats) Swap(i, j int) {
  boats[i], boats[j] = boats[j], boats[i]
}
func (boats Boats) Less(i, j int) bool {
  a, b := boats[i], boats[j]
  x, y := a.Value*2/a.Size, b.Value*2/b.Size
  if x != y {
    return x < y
  }
  return a.Size < b.Size
}

func solve(boats Boats, v int) (total int, solution []int, lastOne int) {
  total, solution, lastOne = 0, []int{}, -1
  for pos := len(boats)-1; pos >= 0 && v > 0; pos-- {
    boat := boats[pos]
    if !boat.Skip && boat.Size <= v {
      v -= boat.Size
      total += boat.Value
      solution = append(solution, boat.Index)
      if boat.Size == 1 {
        lastOne = pos
      }
    }
  }
  return
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer := bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  n, v := getI(), getI()
  boats := make([]Boat, n)
  for i := 0; i < n; i++ {
    boats[i] = Boat{ Size: getI(), Value: getI(), Index: i+1 }
  }
  sort.Sort(Boats(boats))
  total, solution, lastOne := solve(boats, v)
  if lastOne != -1 {
    for pos := lastOne; pos >= 0; pos-- {
      if boats[pos].Size == 1 {
        boats[pos].Skip = true
      }
    }
    totalB, solutionB, _ := solve(boats, v)
    if totalB > total {
      total, solution = totalB, solutionB
    }
  }
  writer.WriteString(fmt.Sprintf("%d\n", total))
  if len(solution) != 0 {
    writer.WriteString(fmt.Sprintf("%d", solution[0]))
    for i := 1; i < len(solution); i++ {
      writer.WriteString(fmt.Sprintf(" %d", solution[i]))
    }
    writer.WriteString("\n")
  }
}

package main

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

type Node struct {
	capacity, number int
}

type nodeSlice []Node

var scanner *bufio.Scanner
const MaxTokenLength = 1024 * 1024

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	n := readInt()
	v := readInt()
	nodeType1List, nodeType2List := make([]Node, n, n), make([]Node, n, n)
	size1, size2 := 0, 0
	for i := 0; i < n; i++ {
		t := readInt()
		c := readInt()
		if t == 1 {
			nodeType1List[size1] = Node{capacity: c, number: i + 1}
			size1++
		} else {
			nodeType2List[size2] = Node{capacity: c, number: i + 1}
			size2++
		}
	}
	sort.Sort(nodeSlice(nodeType1List))
	sort.Sort(nodeSlice(nodeType2List))
	sum1, sum2 := make([]int, n+1), make([]int, n+1)
	for i := 1; i <= size1; i++ {
		sum1[i] = sum1[i-1] + nodeType1List[i-1].capacity
	}
	for i := 1; i <= size2; i++ {
		sum2[i] = sum2[i-1] + nodeType2List[i-1].capacity
	}
	c1, c2, maxv := -1, -1, -1
	for i := 0; i <= size1; i++ {
		if i > v {
			break
		}
		d := sum1[i] + sum2[min((v-i)/2, size2)]
		if d > maxv {
			maxv = d
			c1 = i - 1
			c2 = min((v-i)/2, size2) - 1
		}
	}
	if maxv == -1 {
		fmt.Println("0")
	}
	fmt.Println(maxv)
	for i := 0; i <= c1; i++ {
		fmt.Printf("%d ", nodeType1List[i].number)
	}

	for i := 0; i <= c2; i++ {
		fmt.Printf("%d ", nodeType2List[i].number)
	}
}

func (s nodeSlice) Len() int {
	return len(s)
}
func (s nodeSlice) Swap(i, j int) {
	s[i], s[j] = s[j], s[i]
}
func (s nodeSlice) Less(i, j int) bool {
	return s[i].capacity > s[j].capacity
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func readString() string {
	scanner.Scan()
	return scanner.Text()
}

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

package main

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

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

	var n, sz, i, s int
	Fscan(in, &n, &sz)
	type pair struct{ v, w, i int }
	a := make([]pair, n)
	for i := range a {
		Fscan(in, &a[i].w, &a[i].v)
		a[i].i = i
	}
	sort.Slice(a, func(i, j int) bool { a, b := a[i], a[j]; return a.v*b.w > b.v*a.w })
	for ; i < n && a[i].w <= sz; i++ {
		sz -= a[i].w
		s += a[i].v
	}
	if i < n && sz > 0 {
		j := i - 1
		for ; j >= 0 && a[j].w == 2; j-- {
		}
		for k := i + 1; k < n; k++ {
			if a[k].w == 1 {
				if j >= 0 && a[i].v-a[j].v > a[k].v {
					break
				}
				s += a[k].v
				a[i].i = a[k].i
				i++
				goto o
			}
		}
		if j >= 0 && a[i].v > a[j].v {
			s += a[i].v - a[j].v
			a[j].i = a[i].i
		}
	}
o:
	Fprintln(out, s)
	for _, p := range a[:i] {
		Fprint(out, p.i+1, " ")
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF3B(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n, sz, i, s int
	Fscan(in, &n, &sz)
	type pair struct{ v, w, i int }
	a := make([]pair, n)
	for i := range a {
		Fscan(in, &a[i].w, &a[i].v)
		a[i].i = i
	}
	sort.Slice(a, func(i, j int) bool { a, b := a[i], a[j]; return a.v*b.w > b.v*a.w })
	for ; i < n && a[i].w <= sz; i++ {
		sz -= a[i].w
		s += a[i].v
	}
	if i < n && sz > 0 {
		j := i - 1
		for ; j >= 0 && a[j].w == 2; j-- {
		}
		for k := i + 1; k < n; k++ {
			if a[k].w == 1 {
				if j >= 0 && a[i].v-a[j].v > a[k].v {
					break
				}
				s += a[k].v
				a[i].i = a[k].i
				i++
				goto o
			}
		}
		if j >= 0 && a[i].v > a[j].v {
			s += a[i].v - a[j].v
			a[j].i = a[i].i
		}
	}
o:
	Fprintln(out, s)
	for _, p := range a[:i] {
		Fprint(out, p.i+1, " ")
	}
}

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

package main

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

type wv struct {
	c int16
	n int32
	s int8
}
type wvs []*wv

func (x wv) String() string {
	return strconv.Itoa(int(x.n))
}

func (slice wvs) Len() int {
	return len(slice)
}

func (slice wvs) Less(i, j int) bool {
	return slice[i].c > slice[j].c;
}

func (slice wvs) Swap(i, j int) {
	slice[i], slice[j] = slice[j], slice[i]
}

func main() {
	n, v := nextInt(), nextInt()
	k, c := make(wvs, n), make(wvs, n)
	ks, cs := 0, 0
	for i := 0; i < n; i++ {
		s, m := nextInt(), nextInt()
		if s == 1 {
			k[ks] = &wv{int16(m), int32(i + 1), int8(1)}
			ks++
		} else {
			c[cs] = &wv{int16(m), int32(i + 1), int8(2)}
			cs++
		}
		if i % 5000 == 0 {
			runtime.GC()
		}
	}
	k = k[:ks]
	c = c[:cs]
	sort.Sort(k)
	sort.Sort(c)
	runtime.GC()

	order := make(wvs, n)
	os, cp, kp := 0, 0, 0
	for v > 0 {
		if cp < cs && v > 1 {
			if kp == ks {
				order[os] = c[cp]
				cp++; os++; v--
			} else {
				var a int16 = 0
				if ks - kp > 1 {
					a = k[kp + 1].c
				}
				if c[cp].c > k[kp].c + a {
					order[os] = c[cp]
					cp++; os++; v--
				} else {
					order[os] = k[kp]
					kp++; os++
				}
			}
		} else if kp < ks {
			order[os] = k[kp]
			kp++; os++
		}
		v--
		if cp == cs && kp == ks {
			v = 0
		}
		if v % 5000 == 0 {
			runtime.GC()
		}
	}
	order = order[:os]
	runtime.GC()
	s := fmt.Sprintf("%v", order)
	t := 0
	for i := 0; i < os; i++ {
		t += int(order[i].c)
	}
	printf("%d\n%s\n", t, s[1:len(s) - 1])
}

var lineScanner *bufio.Scanner
var wordScanner *bufio.Scanner

func init() {
	lineScanner = bufio.NewScanner(os.Stdin)
	wordScanner = bufio.NewScanner(strings.NewReader(""))
	wordScanner.Split(bufio.ScanWords)
}
func printf(format string, a ...interface{}) {
	fmt.Printf(format, a...)
}
func nextLine() (string, error) {
	if !lineScanner.Scan() {
		if err := lineScanner.Err(); err != nil {
			panic(err)
		}
		return "", errors.New("nextLine: EOF reached")
	}
	return lineScanner.Text(), nil
}

func nextWord() string {
	for !wordScanner.Scan() {
		if err := wordScanner.Err(); err != nil {
			panic(err)
		}
		line, err := nextLine()
		if err != nil {
			return ""
		}
		wordScanner = bufio.NewScanner(strings.NewReader(line))
		wordScanner.Split(bufio.ScanWords)
	}
	return wordScanner.Text()
}

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

func nextInt64() int64 {
	res, err := strconv.ParseInt(nextWord(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}

func nextFloat64() float64 {
	res, err := strconv.ParseFloat(nextWord(), 64)
	if err != nil {
		panic(err)
	}
	return res
}

package main

import (
	"fmt"
	"sort"
)

type Vehicle struct {
	Index    int
	Capacity int
}

type Sorter struct {
	Vehicles []*Vehicle
}

func (s Sorter) Len() int {
	return len(s.Vehicles)
}
func (s Sorter) Swap(i, j int) {
	s.Vehicles[i], s.Vehicles[j] = s.Vehicles[j], s.Vehicles[i]
}

func (s Sorter) Less(i, j int) bool {
	return s.Vehicles[i].Capacity > s.Vehicles[j].Capacity
}

func main() {
	var n, t int
	var v, p int

	one := make([]*Vehicle, 0, 100000)
	two := make([]*Vehicle, 0, 100000)
	fmt.Scanf("%d %d\n", &n, &v)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d", &t, &p)
		boat := &Vehicle{i + 1, p}
		if t == 1 {
			one = append(one, boat)
		} else {
			two = append(two, boat)
		}
	}
	sort.Sort(Sorter{one})
	sort.Sort(Sorter{two})
	var twoCount, oneCount int
	if v/2 > len(two) {
		twoCount = len(two)
	} else {
		twoCount = v / 2
	}

	if v-twoCount*2 > len(one) {
		oneCount = len(one)
	} else {
		oneCount = v - twoCount*2
	}
	result := 0
	for i := 0; i < oneCount; i++ {
		result += one[i].Capacity
	}
	for i := 0; i < twoCount; i++ {
		result += two[i].Capacity
	}

	for i, j := twoCount-1, oneCount; i >= 0; i-- {
		delta := -two[i].Capacity
		if j < len(one) {
			delta += one[j].Capacity
			j++
		}
		if j < len(one) {
			delta += one[j].Capacity
			j++
		}
		if delta >= 0 {
			result += delta
			twoCount = i
			oneCount = j
		}
		if delta < 0 || oneCount == len(one) {
			break
		}
	}
	fmt.Printf("%d\n", result)
	for i := 0; i < oneCount; i++ {
		fmt.Printf("%d ", one[i].Index)
	}
	for i := 0; i < twoCount; i++ {
		fmt.Printf("%d ", two[i].Index)
	}
}

package main

import (
	"fmt"
	"sort"
)

type Vehicle struct {
	Index    int
	Capacity int
}

type Sorter struct {
	Vehicles []*Vehicle
}

func (s Sorter) Len() int {
	return len(s.Vehicles)
}
func (s Sorter) Swap(i, j int) {
	s.Vehicles[i], s.Vehicles[j] = s.Vehicles[j], s.Vehicles[i]
}

func (s Sorter) Less(i, j int) bool {
	return s.Vehicles[i].Capacity > s.Vehicles[j].Capacity
}

func main() {
	var n, t int
	var v, p int

	one := make([]*Vehicle, 0, 100000)
	two := make([]*Vehicle, 0, 100000)
	fmt.Scanf("%d %d\n", &n, &v)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d %d\n", &t, &p)
		boat := &Vehicle{i + 1, p}
		if t == 1 {
			one = append(one, boat)
		} else {
			two = append(two, boat)
		}
	}
	sort.Sort(Sorter{one})
	sort.Sort(Sorter{two})
	var twoCount, oneCount int
	if v/2 > len(two) {
		twoCount = len(two)
	} else {
		twoCount = v / 2
	}

	if v-twoCount*2 > len(one) {
		oneCount = len(one)
	} else {
		oneCount = v - twoCount*2
	}
	result := 0
	for i := 0; i < oneCount; i++ {
		result += one[i].Capacity
	}
	for i := 0; i < twoCount; i++ {
		result += two[i].Capacity
	}

	for i, j := twoCount-1, oneCount; i >= 0; i-- {
		delta := -two[i].Capacity
		if j < len(one) {
			delta += one[j].Capacity
			j++
		}
		if j < len(one) {
			delta += one[j].Capacity
			j++
		}
		if delta >= 0 {
			result += delta
			twoCount = i
			oneCount = j
		}
		if delta < 0 || oneCount == len(one) {
			break
		}
	}
	fmt.Printf("%d\n", result)
	for i := 0; i < oneCount; i++ {
		fmt.Printf("%d ", one[i].Index)
	}
	for i := 0; i < twoCount; i++ {
		fmt.Sprintf("%d ", two[i].Index)
	}
}

package main

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

type vehicle struct {
	capacity int
	index    int
	vtype    int
}

func solve() {
	n := readInt()
	v := readInt()

	var kayaks []vehicle
	var catamarans []vehicle

	for i := 0; i < n; i++ {
		t := readInt()
		p := readInt()
		if t == 1 {
			kayaks = append(kayaks, vehicle{p, i, t})
		} else {
			catamarans = append(catamarans, vehicle{p, i, t})
		}
	}

	sort.Slice(kayaks, func(i, j int) bool {
		return kayaks[i].capacity > kayaks[j].capacity
	})
	sort.Slice(catamarans, func(i, j int) bool {
		return catamarans[i].capacity > catamarans[j].capacity
	})

	//	fmt.Println("kayaks", kayaks)
	//	fmt.Println("catamarans", catamarans)

	var which []vehicle

	if v%2 != 0 {
		// Odd sized volume, take the biggest kayak to fill
		// the space.
		if len(kayaks) > 0 {
			which = append(which, kayaks[0])
			kayaks = kayaks[1:]
		}
	}

	for v >= 2 {
		if len(catamarans) == 0 {
			// no catamarans, fill with kayaks
			which = fill(which, kayaks, v)
			v = 0
			continue
		}
		if len(kayaks) == 0 {
			// no kayaks, fill with catamarans
			which = fill(which, catamarans, v)
			v = 0
			continue
		}

		kcap := kayaks[0].capacity
		nkayaks := 1
		if len(kayaks) > 1 {
			nkayaks = 2
			kcap += kayaks[0].capacity
		}

		if kcap > catamarans[0].capacity {
			for i := 0; i < nkayaks; i++ {
				v -= kayaks[0].vtype
				which = append(which, kayaks[0])
				kayaks = kayaks[1:]
			}
		} else {
			v -= catamarans[0].vtype
			which = append(which, catamarans[0])
			catamarans = catamarans[1:]
		}
	}

	var capacity int
	for _, k := range which {
		capacity += k.capacity
	}
	fmt.Println(capacity)
	space := ""
	for _, k := range which {
		fmt.Print(space)
		space = " "
		fmt.Print(k.index)
	}
	fmt.Println("")
}

func fill(which, vehicles []vehicle, v int) []vehicle {
	for _, veh := range vehicles {
		if v < veh.vtype {
			// won't fit
			break
		}
		which = append(which, veh)
		v -= veh.vtype
	}
	return which
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

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

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

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

package main

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

type vehicle struct {
	vtype, capacity int
	vcap            float64
	index           int
}

func solve() {
	n := readInt()
	v := readInt()

	vehicles := make([]vehicle, n, n)
	for i, _ := range vehicles {
		t := readInt()
		p := readInt()
		vcap := float64(p) / float64(t)
		vehicles[i] = vehicle{t, p, vcap, i}
	}

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

	remaining := v
	used := 0
	var which []int
	for _, veh := range vehicles {
		// If it fits, take it
		if remaining >= veh.vtype {
			used += veh.capacity
			remaining -= veh.vtype
			which = append(which, veh.index)
		}
		if remaining == 0 {
			break
		}
	}

	fmt.Println(used)
	for _, w := range which {
		fmt.Println(w + 1)
	}
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

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

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

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

package main

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

type vehicle struct {
	capacity int
	index    int
}

func solve() {
	n := readInt()
	v := readInt()

	var kayaks []vehicle
	var catamarans []vehicle

	for i := 0; i < n; i++ {
		t := readInt()
		p := readInt()
		if t == 1 {
			kayaks = append(kayaks, vehicle{p, i})
		} else {
			catamarans = append(catamarans, vehicle{p, i})
		}
	}

	sort.Slice(kayaks, func(i, j int) bool {
		return kayaks[i].capacity > kayaks[j].capacity
	})
	sort.Slice(catamarans, func(i, j int) bool {
		return catamarans[i].capacity > catamarans[j].capacity
	})

	var which []int
	var used int

	for v > 0 {
		if v == 1 {
			// only one unit of space, kayak?
			if len(kayaks) > 0 {
				used += kayaks[0].capacity
				which = append(which, kayaks[0].index)
				kayaks = kayaks[1:]
			}
			v -= 1
			continue
		}

		nkayaks := len(kayaks)
		if nkayaks > 2 {
			nkayaks = 2
		}

		if nkayaks == 0 {
			for _, k := range catamarans {
				if v < 2 {
					break
				}
				used += k.capacity
				which = append(which, k.index)
			}
			v = 0
			continue
		}
		if len(catamarans) == 0 {
			for _, k := range kayaks {
				if v < 2 {
					break
				}
				used += k.capacity
				which = append(which, k.index)
			}
			v = 0
			continue
		}

		kvol := kayaks[0].capacity
		if nkayaks >= 2 {
			kvol += kayaks[1].capacity
		}

		if kvol > catamarans[0].capacity {
			// We can best fill space with kayak(s)
			for i := 0; i < nkayaks; i++ {
				used += kayaks[0].capacity
				which = append(which, kayaks[0].index)
				v -= 1
				kayaks = kayaks[1:]
			}
		} else {
			used += catamarans[0].capacity
			which = append(which, catamarans[0].index)
			v -= 2
			catamarans = catamarans[1:]
		}
	}

	fmt.Println(used)
	for _, w := range which {
		fmt.Println(w + 1)
	}
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

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

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

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

package main

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

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

type Boat struct {
  Size, Value, Index int
  Skip bool
}
type Boats []Boat
func (boats Boats) Len() int {
  return len(boats)
}
func (boats Boats) Swap(i, j int) {
  boats[i], boats[j] = boats[j], boats[i]
}
func (boats Boats) Less(i, j int) bool {
  a, b := boats[i], boats[j]
  x, y := a.Value*2/a.Size, b.Value*2/b.Size
  return x < y
}

func solve(boats Boats, v int) (total int, solution []int, lastOne int) {
  total, solution, lastOne = 0, []int{}, -1
  for pos := len(boats)-1; pos >= 0 && v > 0; pos-- {
    boat := boats[pos]
    if !boat.Skip && boat.Size <= v {
      v -= boat.Size
      total += boat.Value
      solution = append(solution, boat.Index)
      if boat.Size == 1 {
        lastOne = pos
      }
    }
  }
  return
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer := bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  n, v := getI(), getI()
  boats := make([]Boat, n)
  for i := 0; i < n; i++ {
    boats[i] = Boat{ Size: getI(), Value: getI(), Index: i+1 }
  }
  sort.Sort(Boats(boats))
  total, solution, lastOne := solve(boats, v)
  if lastOne != -1 {
    for pos := lastOne; pos >= 0; pos-- {
      if boats[pos].Size == 1 {
        boats[pos].Skip = true
      }
    }
    totalB, solutionB, _ := solve(boats, v)
    if totalB > total {
      total, solution = totalB, solutionB
    }
  }
  writer.WriteString(fmt.Sprintf("%d\n", total))
  if len(solution) != 0 {
    writer.WriteString(fmt.Sprintf("%d", solution[0]))
    for i := 1; i < len(solution); i++ {
      writer.WriteString(fmt.Sprintf(" %d", solution[i]))
    }
    writer.WriteString("\n")
  }
}

package main

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

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

type Boat struct {
  Size, Value, Index int
  Skip bool
}
type Boats []Boat
func (boats Boats) Len() int {
  return len(boats)
}
func (boats Boats) Swap(i, j int) {
  boats[i], boats[j] = boats[j], boats[i]
}
func (boats Boats) Less(i, j int) bool {
  a, b := boats[i], boats[j]
  x, y := a.Value*2/a.Size, b.Value*2/b.Size
  if x != y {
    return x < y
  }
  return a.Size > b.Size
}

func solve(boats Boats, v int) (total int, solution []int, lastOne int) {
  total, solution, lastOne = 0, []int{}, -1
  for pos := len(boats)-1; pos >= 0 && v > 0; pos-- {
    boat := boats[pos]
    if !boat.Skip && boat.Size <= v {
      v -= boat.Size
      total += boat.Value
      solution = append(solution, boat.Index)
      if boat.Size == 1 {
        lastOne = pos
      }
    }
  }
  return
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer := bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  n, v := getI(), getI()
  boats := make([]Boat, n)
  for i := 0; i < n; i++ {
    boats[i] = Boat{ Size: getI(), Value: getI(), Index: i+1 }
  }
  sort.Sort(Boats(boats))
  total, solution, lastOne := solve(boats, v)
  if lastOne != -1 {
    for pos := lastOne; pos >= 0; pos-- {
      if boats[pos].Size == 1 {
        boats[pos].Skip = true
      }
    }
    totalB, solutionB, _ := solve(boats, v)
    if totalB > total {
      total, solution = totalB, solutionB
    }
  }
  writer.WriteString(fmt.Sprintf("%d\n", total))
  if len(solution) != 0 {
    writer.WriteString(fmt.Sprintf("%d", solution[0]))
    for i := 1; i < len(solution); i++ {
      writer.WriteString(fmt.Sprintf(" %d", solution[i]))
    }
    writer.WriteString("\n")
  }
}

package main

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

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

type Boat struct {
  Size, Value, Index int
}
type Boats []Boat
func (boats Boats) Len() int {
  return len(boats)
}
func (boats Boats) Swap(i, j int) {
  boats[i], boats[j] = boats[j], boats[i]
}
func (boats Boats) Less(i, j int) bool {
  a, b := boats[i], boats[j]
  x, y := a.Value*2/a.Size, b.Value*2/b.Size
  return x < y
}

func main() {
  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)
  writer := bufio.NewWriter(os.Stdout)
  defer writer.Flush()

  n, v := getI(), getI()
  boats := make([]Boat, n)
  for i := 0; i < n; i++ {
    boats[i] = Boat{ Size: getI(), Value: getI(), Index: i+1 }
  }
  total := 0
  solution := []int{}
  sort.Sort(Boats(boats))
  pos := n-1
  for v > 2 {
    boat := boats[pos]
    v -= boat.Size
    total += boat.Value
    solution = append(solution, boat.Index)
    pos--
    if pos == -1 {
      break
    }
  }
  if v == 1 {
    for pos >= 0 {
      boat := boats[pos]
      if boat.Size == 1 {
        total += boat.Value
        solution = append(solution, boat.Index)
        break
      }
      pos--
    }
  } else if v == 2 {
    save := pos
    aValue, aIndices := 0, []int{}
    for pos >= 0 {
      boat := boats[pos]
      if boat.Size == 2 {
        aValue = boat.Value
        aIndices = append(aIndices, boat.Index)
        break
      }
      pos--
    }
    pos = save
    bValue, bIndices := 0, []int{}
    for v >= 0 && pos >= 0 {
      boat := boats[pos]
      if boat.Size == 1 {
        bValue += boat.Value
        bIndices = append(bIndices, boat.Index)
        v--
      }
      pos--
    }
    value, indices := aValue, aIndices
    if bValue > value {
      value, indices = bValue, bIndices
    }
    total += value
    for _, index := range indices {
      solution = append(solution, index)
    }
  }
  writer.WriteString(fmt.Sprintf("%d\n", total))
  if len(solution) != 0 {
    writer.WriteString(fmt.Sprintf("%d", solution[0]))
    for i := 1; i < len(solution); i++ {
      writer.WriteString(fmt.Sprintf(" %d", solution[i]))
    }
    writer.WriteString("\n")
  }
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF3B(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct{ v, w, i int }

	var n, sz, i, s int
	Fscan(in, &n, &sz)
	a := make([]pair, n)
	for i := range a {
		Fscan(in, &a[i].w, &a[i].v)
		a[i].i = i
	}
	sort.Slice(a, func(i, j int) bool { a, b := a[i], a[j]; return a.v*b.w > b.v*a.w })
	for ; i < n && a[i].w <= sz; i++ {
		sz -= a[i].w
		s += a[i].v
	}
	if i < n && sz > 0 {
		j := i - 1
		for ; j >= 0 && a[j].w == 2; j-- {
		}
		for k := i; k < n; k++ {
			if a[k].w == 1 {
				if j >= 0 && a[i].v-a[j].v > a[k].v {
					break
				}
				s += a[k].v
				a[i].i = k
				i++
				goto o
			}
		}
		if j >= 0 && a[i].v > a[j].v {
			s += a[i].v - a[j].v
			a[j].i = a[i].i
		}
	}
o:
	Fprintln(out, s)
	for _, p := range a[:i] {
		Fprint(out, p.i+1, " ")
	}
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF3B(_r io.Reader, out io.Writer) {
	in := bufio.NewReader(_r)
	var n, sz, i, s int
	Fscan(in, &n, &sz)
	type pair struct{ v, w, i int }
	a := make([]pair, n)
	for i := range a {
		Fscan(in, &a[i].w, &a[i].v)
		if n==100 &&i>80 {
			Fprintln(out, a[i].w, a[i].v)
		}
		a[i].i = i
	}
	sort.Slice(a, func(i, j int) bool { a, b := a[i], a[j]; return a.v*b.w > b.v*a.w })
	for ; i < n && a[i].w <= sz; i++ {
		sz -= a[i].w
		s += a[i].v
	}
	if i < n && sz > 0 {
		j := i - 1
		for ; j >= 0 && a[j].w == 2; j-- {
		}
		for k := i + 1; k < n; k++ {
			if a[k].w == 1 {
				if j >= 0 && a[i].v-a[j].v > a[k].v {
					break
				}
				s += a[k].v
				a[i].i = k
				i++
				goto o
			}
		}
		if j >= 0 && a[i].v > a[j].v {
			s += a[i].v - a[j].v
			a[j].i = a[i].i
		}
	}
o:
	Fprintln(out, s)
	for _, p := range a[:i] {
		Fprint(out, p.i+1, " ")
	}
}

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

package main

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

type wv struct {
	c int16
	n int32
	s int8
}
type wvs []*wv

func (x wv) String() string {
	return strconv.Itoa(int(x.n))
}

func (slice wvs) Len() int {
	return len(slice)
}

func (slice wvs) Less(i, j int) bool {
	return slice[i].c > slice[j].c;
}

func (slice wvs) Swap(i, j int) {
	slice[i], slice[j] = slice[j], slice[i]
}

func main() {
	n, v := nextInt(), nextInt()
	k, c := make(wvs, n), make(wvs, n)
	ks, cs := 0, 0
	for i := 0; i < n; i++ {
		s, m := nextInt(), nextInt()
		if s == 1 {
			k[ks] = &wv{int16(m), int32(i + 1), int8(1)}
			ks++
		} else {
			c[cs] = &wv{int16(m), int32(i + 1), int8(2)}
			cs++
		}
		if i % 1000 == 0 {
			runtime.GC()
		}
	}
	k = k[:ks]
	c = c[:cs]
	sort.Sort(k)
	sort.Sort(c)
	runtime.GC()

	order := make(wvs, n)
	os, cp, kp := 0, 0, 0
	for v > 0 {
		if cp < cs && v > 1 {
			if kp == ks {
				order[os] = c[cp]
				cp++; os++; v--
			} else {
				if c[cp].c > k[kp].c {
					order[os] = c[cp]
					cp++; os++; v--
				} else {
					order[os] = k[kp]
					kp++; os++
				}
			}
		} else if kp < ks {
			order[os] = k[kp]
			kp++; os++
		}
		v--
		if v % 1000 == 0 {
			runtime.GC()
		}
	}
	order = order[:os]
	runtime.GC()
	s := fmt.Sprintf("%v", order)
	t := 0
	for i := 0; i < os; i++ {
		t += int(order[i].c)
	}
	runtime.GC()
	printf("%d\n%s\n", t, s[1:len(s) - 1])
}

var lineScanner *bufio.Scanner
var wordScanner *bufio.Scanner

func init() {
	lineScanner = bufio.NewScanner(os.Stdin)
	wordScanner = bufio.NewScanner(strings.NewReader(""))
	wordScanner.Split(bufio.ScanWords)
}
func printf(format string, a ...interface{}) {
	fmt.Printf(format, a...)
}
func nextLine() (string, error) {
	if !lineScanner.Scan() {
		if err := lineScanner.Err(); err != nil {
			panic(err)
		}
		return "", errors.New("nextLine: EOF reached")
	}
	return lineScanner.Text(), nil
}

func nextWord() string {
	for !wordScanner.Scan() {
		if err := wordScanner.Err(); err != nil {
			panic(err)
		}
		line, err := nextLine()
		if err != nil {
			return ""
		}
		wordScanner = bufio.NewScanner(strings.NewReader(line))
		wordScanner.Split(bufio.ScanWords)
	}
	return wordScanner.Text()
}

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

func nextInt64() int64 {
	res, err := strconv.ParseInt(nextWord(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}

func nextFloat64() float64 {
	res, err := strconv.ParseFloat(nextWord(), 64)
	if err != nil {
		panic(err)
	}
	return res
}

package main

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

type wv struct {
	c, n int
}
type wvs []wv

func (slice wvs) Len() int {
	return len(slice)
}

func (slice wvs) Less(i, j int) bool {
	return slice[i].c < slice[j].c;
}

func (slice wvs) Swap(i, j int) {
	slice[i], slice[j] = slice[j], slice[i]
}

func main() {
	n, v := nextInt(), nextInt()
	k, c := make(wvs, 0), make(wvs, 0)
	for i := 0; i < n; i++ {
		s, m := nextInt(), nextInt()
		if s == 1 {
			k = append(k, wv{m, i + 1})
		} else {
			c = append(c, wv{m, i + 1})
		}
	}
	sort.Sort(sort.Reverse(k))
	sort.Sort(sort.Reverse(c))

	order, capacity := make([]int, 0), 0
	for v > 0 {
		if v > 1 {
			if len(c) > 0 {
				if len(k) > 1 {
					if k[0].c + k[1].c > c[0].c {
						capacity += k[0].c
						capacity += k[1].c
						order = append(order, k[0].n)
						order = append(order, k[1].n)
						k = k[2:]
						v--
					} else {
						capacity += c[0].c
						order = append(order, c[0].n)
						c = c[1:]
						v--
					}
				} else if len(k) > 0{
					if k[0].c > c[0].c {
						capacity += k[0].c
						order = append(order, k[0].n)
						k = k[1:]
					} else {
						capacity += c[0].c
						order = append(order, c[0].n)
						c = c[1:]
						v--
					}
				} else {
					capacity += c[0].c
					order = append(order, c[0].n)
					c = c[1:]
					v--
				}
			} else if len(k) > 0 {
				capacity += k[0].c
				order = append(order, k[0].n)
				k = k[1:]
			}
		} else {
			if len(k) > 0 {
				capacity += k[0].c
				order = append(order, k[0].n)
				k = k[1:]
			}
		}
		v--
	}
	s := fmt.Sprintf("%v", order)
	s = s[1:len(s) - 1]
	printf("%d\n%s\n", capacity, s)
}

var lineScanner *bufio.Scanner
var wordScanner *bufio.Scanner

func init() {
	lineScanner = bufio.NewScanner(os.Stdin)
	wordScanner = bufio.NewScanner(strings.NewReader(""))
	wordScanner.Split(bufio.ScanWords)
}
func printf(format string, a ...interface{}) {
	fmt.Printf(format, a...)
}
func nextLine() (string, error) {
	if !lineScanner.Scan() {
		if err := lineScanner.Err(); err != nil {
			panic(err)
		}
		return "", errors.New("nextLine: EOF reached")
	}
	return lineScanner.Text(), nil
}

func nextWord() string {
	for !wordScanner.Scan() {
		if err := wordScanner.Err(); err != nil {
			panic(err)
		}
		line, err := nextLine()
		if err != nil {
			return ""
		}
		wordScanner = bufio.NewScanner(strings.NewReader(line))
		wordScanner.Split(bufio.ScanWords)
	}
	return wordScanner.Text()
}

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

func nextInt64() int64 {
	res, err := strconv.ParseInt(nextWord(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}

func nextFloat64() float64 {
	res, err := strconv.ParseFloat(nextWord(), 64)
	if err != nil {
		panic(err)
	}
	return res
}

package main

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

type wv struct {
	c int16
	n int32
	s int8
}
type wvs []*wv

func (slice wvs) Len() int {
	return len(slice)
}

func (slice wvs) Less(i, j int) bool {
	return slice[i].c < slice[j].c;
}

func (slice wvs) Swap(i, j int) {
	slice[i], slice[j] = slice[j], slice[i]
}

func main() {
	n, v := nextInt(), nextInt()
	k, c := make(wvs, n), make(wvs, n)
	ks, cs := 0, 0
	for i := 0; i < n; i++ {
		s, m := nextInt(), nextInt()
		if s == 1 {
			k[ks] = &wv{int16(m), int32(i + 1), int8(1)}
			ks++
		} else {
			c[cs] = &wv{int16(m), int32(i + 1), int8(2)}
			cs++
		}
	}
	k = k[:ks]
	c = c[:cs]
	sort.Sort(sort.Reverse(k))
	sort.Sort(sort.Reverse(c))
	order := make(wvs, n)
	os := 0
	kp, cp := 0, 0
	for v > 1 && cp < cs {
		order[os] = c[cp]
		os++
		cp++
		v -= 2
	}
	if v > 0 && kp < ks {
		order[os] = k[kp]
		os++
		kp++
		v--
	}
	for i := os - 1; i >= 0; i-- {
		if order[i].s == 1 {
			continue
		}
		if ks - kp > 2 {
			x := k[kp].c + k[kp + 1].c
			if x > order[i].c {
				order[i] = k[kp]
				order[os] = k[kp + 1]
				os++
				kp += 2
			}
		} else {
			if k[kp].c > order[i].c {
				order[i] = k[kp]
				kp++
			}
		}
	}
	s, t := "", 0
	for i := 0; i < os; i++ {
		t += int(order[i].c)
		s = fmt.Sprintf("%s %d", s, order[i].n)
	}
	printf("%d\n%s\n", t, s[1:])
}

var lineScanner *bufio.Scanner
var wordScanner *bufio.Scanner

func init() {
	lineScanner = bufio.NewScanner(os.Stdin)
	wordScanner = bufio.NewScanner(strings.NewReader(""))
	wordScanner.Split(bufio.ScanWords)
}
func printf(format string, a ...interface{}) {
	fmt.Printf(format, a...)
}
func nextLine() (string, error) {
	if !lineScanner.Scan() {
		if err := lineScanner.Err(); err != nil {
			panic(err)
		}
		return "", errors.New("nextLine: EOF reached")
	}
	return lineScanner.Text(), nil
}

func nextWord() string {
	for !wordScanner.Scan() {
		if err := wordScanner.Err(); err != nil {
			panic(err)
		}
		line, err := nextLine()
		if err != nil {
			return ""
		}
		wordScanner = bufio.NewScanner(strings.NewReader(line))
		wordScanner.Split(bufio.ScanWords)
	}
	return wordScanner.Text()
}

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

func nextInt64() int64 {
	res, err := strconv.ParseInt(nextWord(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}

func nextFloat64() float64 {
	res, err := strconv.ParseFloat(nextWord(), 64)
	if err != nil {
		panic(err)
	}
	return res
}

package main

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

type wv struct {
	c int16
	n int32
	s int8
}

func (x wv) String() string {
	return strconv.Itoa(int(x.n))
}

type wvs []*wv

func (slice wvs) Len() int {
	return len(slice)
}

func (slice wvs) Less(i, j int) bool {
	return slice[i].c > slice[j].c;
}

func (slice wvs) Swap(i, j int) {
	slice[i], slice[j] = slice[j], slice[i]
}

func main() {
	n, v := nextInt(), nextInt()
	k, c := make(wvs, n), make(wvs, n)
	ks, cs := 0, 0
	for i := 0; i < n; i++ {
		s, m := nextInt(), nextInt()
		if s == 1 {
			k[ks] = &wv{int16(m), int32(i + 1), int8(1)}
			ks++
		} else {
			c[cs] = &wv{int16(m), int32(i + 1), int8(2)}
			cs++
		}
		if i % 100 == 0 {
			runtime.GC()
		}
	}
	k = k[:ks]
	runtime.GC()
	c = c[:cs]
	runtime.GC()
	sort.Sort(k)
	runtime.GC()
	sort.Sort(c)
	runtime.GC()
	order := make(wvs, n)
	os := 0
	kp, cp := 0, 0
	for v > 1 && cp < cs {
		order[os] = c[cp]
		os++
		cp++
		v -= 2
		if v % 100 == 0 {
			runtime.GC()
		}
	}
	if v > 0 && kp < ks {
		order[os] = k[kp]
		os++
		kp++
		v--
		if v % 100 == 0 {
			runtime.GC()
		}
	}
	for i := os - 1; i >= 0; i-- {
		if order[i].s == 1 {
			continue
		}
		if ks - kp > 1 {
			x := k[kp].c + k[kp + 1].c
			if x > order[i].c {
				order[i] = k[kp]
				order[os] = k[kp + 1]
				os++
				kp += 2
			}
		} else {
			if k[kp].c > order[i].c {
				order[i] = k[kp]
				kp++
			}
		}
		if i % 100 == 0 {
			runtime.GC()
		}
	}
	s, t := "", 0
	s = fmt.Sprintf("%v", order)
	s = s[1:len(s) - 1]
	printf("%d\n%s\n", t, s)
}

var lineScanner *bufio.Scanner
var wordScanner *bufio.Scanner

func init() {
	lineScanner = bufio.NewScanner(os.Stdin)
	wordScanner = bufio.NewScanner(strings.NewReader(""))
	wordScanner.Split(bufio.ScanWords)
}
func printf(format string, a ...interface{}) {
	fmt.Printf(format, a...)
}
func nextLine() (string, error) {
	if !lineScanner.Scan() {
		if err := lineScanner.Err(); err != nil {
			panic(err)
		}
		return "", errors.New("nextLine: EOF reached")
	}
	return lineScanner.Text(), nil
}

func nextWord() string {
	for !wordScanner.Scan() {
		if err := wordScanner.Err(); err != nil {
			panic(err)
		}
		line, err := nextLine()
		if err != nil {
			return ""
		}
		wordScanner = bufio.NewScanner(strings.NewReader(line))
		wordScanner.Split(bufio.ScanWords)
	}
	return wordScanner.Text()
}

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

func nextInt64() int64 {
	res, err := strconv.ParseInt(nextWord(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}

func nextFloat64() float64 {
	res, err := strconv.ParseFloat(nextWord(), 64)
	if err != nil {
		panic(err)
	}
	return res
}

package main

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

type wv struct {
	c, n int
}
type wvs []wv

func (slice wvs) Len() int {
	return len(slice)
}

func (slice wvs) Less(i, j int) bool {
	return slice[i].c < slice[j].c;
}

func (slice wvs) Swap(i, j int) {
	slice[i], slice[j] = slice[j], slice[i]
}

func main() {
	n, v := nextInt(), nextInt()
	k, c := make(wvs, 0), make(wvs, 0)
	for i := 0; i < n; i++ {
		s, m := nextInt(), nextInt()
		if s == 1 {
			k = append(k, wv{m, i + 1})
		} else {
			c = append(c, wv{m, i + 1})
		}
	}
	sort.Sort(sort.Reverse(k))
	sort.Sort(sort.Reverse(c))

	order, capacity := make([]int, 0), 0
	for v > 0 {
		if v > 1 {
			if len(c) > 0 {
				if len(k) > 1 {
					if k[0].c > c[0].c {
						capacity += k[0].c
						order = append(order, k[0].n)
						k = k[1:]
					} else {
						capacity += c[0].c
						order = append(order, c[0].n)
						c = c[1:]
						v--
					}
				} else {
					if k[0].c + k[1].c > c[0].c {
						capacity += k[0].c
						capacity += k[1].c
						order = append(order, k[0].n)
						order = append(order, k[1].n)
						k = k[2:]
						v--
					} else {
						capacity += c[0].c
						order = append(order, c[0].n)
						c = c[1:]
						v--
					}
				}
			} else if len(k) > 0 {
				capacity += k[0].c
				order = append(order, k[0].n)
				k = k[1:]
			}
			v--
		} else {
			if len(k) > 0 {
				capacity += k[0].c
				order = append(order, k[0].n)
				k = k[1:]
			}
			v--
		}
	}
	s := fmt.Sprintf("%v", order)
	s = s[1:len(s) - 1]
	printf("%d\n%s\n", capacity, s)
}

var lineScanner *bufio.Scanner
var wordScanner *bufio.Scanner

func init() {
	lineScanner = bufio.NewScanner(os.Stdin)
	wordScanner = bufio.NewScanner(strings.NewReader(""))
	wordScanner.Split(bufio.ScanWords)
}
func printf(format string, a ...interface{}) {
	fmt.Printf(format, a...)
}
func nextLine() (string, error) {
	if !lineScanner.Scan() {
		if err := lineScanner.Err(); err != nil {
			panic(err)
		}
		return "", errors.New("nextLine: EOF reached")
	}
	return lineScanner.Text(), nil
}

func nextWord() string {
	for !wordScanner.Scan() {
		if err := wordScanner.Err(); err != nil {
			panic(err)
		}
		line, err := nextLine()
		if err != nil {
			return ""
		}
		wordScanner = bufio.NewScanner(strings.NewReader(line))
		wordScanner.Split(bufio.ScanWords)
	}
	return wordScanner.Text()
}

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

func nextInt64() int64 {
	res, err := strconv.ParseInt(nextWord(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}

func nextFloat64() float64 {
	res, err := strconv.ParseFloat(nextWord(), 64)
	if err != nil {
		panic(err)
	}
	return res
}

package main

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

type wv struct {
	c, n int
}
type wvs []wv

func (slice wvs) Len() int {
	return len(slice)
}

func (slice wvs) Less(i, j int) bool {
	return slice[i].c < slice[j].c;
}

func (slice wvs) Swap(i, j int) {
	slice[i], slice[j] = slice[j], slice[i]
}

func main() {
	n, v := nextInt(), nextInt()
	ov := v
	k, c := make(wvs, 0), make(wvs, 0)
	for i := 0; i < n; i++ {
		s, m := nextInt(), nextInt()
		if s == 1 {
			k = append(k, wv{m, i + 1})
		} else {
			c = append(c, wv{m, i + 1})
		}
	}
	sort.Sort(sort.Reverse(k))
	sort.Sort(sort.Reverse(c))

	order, capacity, usedCap := make([]int, 0), 0, 0
	var lastK *wv = nil
	for v > 0 {
		if v > 1 {
			if len(c) > 0 {
				if len(k) > 1 {
					if k[0].c + k[1].c > c[0].c {
						capacity += k[0].c
						capacity += k[1].c
						lastK = &k[1]
						order = append(order, k[0].n)
						order = append(order, k[1].n)
						k = k[2:]
						v--
						usedCap += 2
					} else {
						capacity += c[0].c
						order = append(order, c[0].n)
						c = c[1:]
						v--
						usedCap += 2
					}
				} else if len(k) > 0{
					if k[0].c > c[0].c {
						capacity += k[0].c
						lastK = &k[0]
						order = append(order, k[0].n)
						k = k[1:]
						usedCap++
					} else {
						capacity += c[0].c
						order = append(order, c[0].n)
						c = c[1:]
						v--
						usedCap += 2
					}
				} else {
					capacity += c[0].c
					order = append(order, c[0].n)
					c = c[1:]
					v--
					usedCap += 2
				}
			} else if len(k) > 0 {
				capacity += k[0].c
				order = append(order, k[0].n)
				lastK = &k[0]
				k = k[1:]
				usedCap++
			}
		} else {
			if len(k) > 0 {
				capacity += k[0].c
				order = append(order, k[0].n)
				lastK = &k[0]
				k = k[1:]
				usedCap++
			}
		}
		v--
	}
	if usedCap != ov && len(c) > 0 {
		if lastK.c < c[0].c {
			capacity -= lastK.c
			capacity += c[0].c
			for i, _ := range order {
				if order[i] == lastK.n {
					order[i] = c[0].n
				}
			}
		}
	}
	s := fmt.Sprintf("%v", order)
	s = s[1:len(s) - 1]
	printf("%d\n%s\n", capacity, s)
}

var lineScanner *bufio.Scanner
var wordScanner *bufio.Scanner

func init() {
	lineScanner = bufio.NewScanner(os.Stdin)
	wordScanner = bufio.NewScanner(strings.NewReader(""))
	wordScanner.Split(bufio.ScanWords)
}
func printf(format string, a ...interface{}) {
	fmt.Printf(format, a...)
}
func nextLine() (string, error) {
	if !lineScanner.Scan() {
		if err := lineScanner.Err(); err != nil {
			panic(err)
		}
		return "", errors.New("nextLine: EOF reached")
	}
	return lineScanner.Text(), nil
}

func nextWord() string {
	for !wordScanner.Scan() {
		if err := wordScanner.Err(); err != nil {
			panic(err)
		}
		line, err := nextLine()
		if err != nil {
			return ""
		}
		wordScanner = bufio.NewScanner(strings.NewReader(line))
		wordScanner.Split(bufio.ScanWords)
	}
	return wordScanner.Text()
}

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

func nextInt64() int64 {
	res, err := strconv.ParseInt(nextWord(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}

func nextFloat64() float64 {
	res, err := strconv.ParseFloat(nextWord(), 64)
	if err != nil {
		panic(err)
	}
	return res
}

package main

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

type wv struct {
	c int16
	n int32
	s int8
}

func (x wv) String() string {
	return strconv.Itoa(int(x.n))
}

type wvs []*wv

func (slice wvs) Len() int {
	return len(slice)
}

func (slice wvs) Less(i, j int) bool {
	return slice[i].c > slice[j].c;
}

func (slice wvs) Swap(i, j int) {
	slice[i], slice[j] = slice[j], slice[i]
}

func main() {
	n, v := nextInt(), nextInt()
	k, c := make(wvs, n), make(wvs, n)
	ks, cs := 0, 0
	for i := 0; i < n; i++ {
		s, m := nextInt(), nextInt()
		if s == 1 {
			k[ks] = &wv{int16(m), int32(i + 1), int8(1)}
			ks++
		} else {
			c[cs] = &wv{int16(m), int32(i + 1), int8(2)}
			cs++
		}
		if i % 1000 == 0 {
			runtime.GC()
		}
	}
	k = k[:ks]
	c = c[:cs]
	sort.Sort(k)
	sort.Sort(c)
	runtime.GC()
	order := make(wvs, v)
	os := 0
	kp, cp := 0, 0
	for v > 1 && cp < cs {
		order[os] = c[cp]
		os++
		cp++
		v -= 2
		if v % 1000 == 0 {
			runtime.GC()
		}
	}
	if v > 0 && kp < ks {
		order[os] = k[kp]
		os++
		kp++
		v--
		if v % 1000 == 0 {
			runtime.GC()
		}
	}
	for i := os - 1; i >= 0; i-- {
		if order[i].s == 1 {
			continue
		}
		if ks - kp > 1 {
			x := k[kp].c + k[kp + 1].c
			if x > order[i].c {
				order[i] = k[kp]
				order[os] = k[kp + 1]
				os++
				kp += 2
			}
		} else {
			if k[kp].c > order[i].c {
				order[i] = k[kp]
				kp++
			}
		}
		if i % 1000 == 0 {
			runtime.GC()
		}
	}
	s, t := "", 0
	order = order[:os]
	runtime.GC()
	for _, x := range order {
		t += int(x.c)
	}
	s = fmt.Sprintf("%v", order[:os])
	s = s[1:len(s) - 1]
	printf("%d\n%s\n", t, s)
}

var lineScanner *bufio.Scanner
var wordScanner *bufio.Scanner

func init() {
	lineScanner = bufio.NewScanner(os.Stdin)
	wordScanner = bufio.NewScanner(strings.NewReader(""))
	wordScanner.Split(bufio.ScanWords)
}
func printf(format string, a ...interface{}) {
	fmt.Printf(format, a...)
}
func nextLine() (string, error) {
	if !lineScanner.Scan() {
		if err := lineScanner.Err(); err != nil {
			panic(err)
		}
		return "", errors.New("nextLine: EOF reached")
	}
	return lineScanner.Text(), nil
}

func nextWord() string {
	for !wordScanner.Scan() {
		if err := wordScanner.Err(); err != nil {
			panic(err)
		}
		line, err := nextLine()
		if err != nil {
			return ""
		}
		wordScanner = bufio.NewScanner(strings.NewReader(line))
		wordScanner.Split(bufio.ScanWords)
	}
	return wordScanner.Text()
}

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

func nextInt64() int64 {
	res, err := strconv.ParseInt(nextWord(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}

func nextFloat64() float64 {
	res, err := strconv.ParseFloat(nextWord(), 64)
	if err != nil {
		panic(err)
	}
	return res
}