package main

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

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

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

	var T int
	var n int
	var x int

	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)

		a := make([]int, n)
		for i := 0; i < n; i++ {
			Fscan(in, &x)
			a[i] = x-1
		}

		ans := 0
		for i, v := range a {
			for j := i +1; j < n;j++ {
				if a[j] < v {
					ans++
				}
			}
		}
		m := map[int]int{}
		for _,  v := range a {
			m[v]++
		}
		for _, v := range m {
			if v > 1 {
				ans +=  v * (v-1)/2
			}
		}

		Fprintln(out, ans)
	}
}

package main

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

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

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

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

		var tot int
		for i := 0; i < n-1; i++ {
			for j := i + 1; j < n; j++ {
				if arr[j] <= arr[i] {
					tot++
				}
			}
		}
		fmt.Fprintln(out, tot)
	}
}

package main

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

var in *In
var out *Out

const N = 2e5 + 10

var a, b [N]int

func lowbit(x int) int {
	return x & (-x)
}

func add(x, k int) {
	for i := x; i < N; i += lowbit(i) {
		b[i] += k
	}
}

func get(x int) int {
	ans := 0
	for i := x; i > 0; i -= lowbit(i) {
		ans += b[i]
	}
	return ans
}

func problem_solver() {
	T := in.NextInt()
	for T > 0 {
		T--
		n := in.NextInt()
		var ans int64 = 0
		for i := 1; i <= n; i++ {
			a[i] = in.NextInt()
			a[i] = n - a[i] + 1
			ans += int64(get(a[i]))
			add(a[i], 1)
		}
		for i := 1; i <= n; i++ {
			add(a[i], -1)
		}
		out.Println(ans)

	}
}

func main() {

	in, out = InitIo(true)
	defer out.Flush()

	problem_solver()

}

func debug(args ...interface{}) {
	fmt.Fprintln(os.Stderr, args...)
}

// ==================================================
// 入出力操作
// ==================================================
type In struct {
	// NextString は 次の入力を文字列として読み込んで返します。
	NextString func() string
}

type Out struct {
	writer io.Writer
	Flush  func()
}

// InitIo は inとoutを初期化します。
func InitIo(buffer bool) (*In, *Out) {
	bufsize := 4 * 1024 * 1024 // 4MB

	// 入力はずっとバッファーでいいらしい。ほんとう？
	// TODO バッファなしfmt.Fscanf(os.Stdin)だとTLEだった。要調査
	_in := bufio.NewScanner(os.Stdin)
	_in.Split(bufio.ScanWords)
	_in.Buffer(make([]byte, bufsize), bufsize)
	in := func() string {
		_in.Scan()
		return _in.Text()
	}

	// 出力はバッファon/offが必要
	var out io.Writer
	var flush func()

	if buffer {
		_out := bufio.NewWriterSize(os.Stdout, bufsize)
		out = _out
		flush = func() {
			_out.Flush()
		}
	} else {
		out = os.Stdout
		flush = func() {}
	}

	return &In{in}, &Out{out, flush}
}

// NextBytes は 次の入力をbyteの配列として読み込んで返します。
// 遅いから極力使わない。
func (in *In) NextBytes() []byte {
	return []byte(in.NextString())
}

// NextInt は 次の入力を数値として読み込んで返します。
func (in *In) NextInt() int {
	i, _ := strconv.Atoi(in.NextString())
	return i
}

// NextInt2 は 次の2つの入力を数値として読み込んで返します。
func (in *In) NextInt2() (int, int) {
	return in.NextInt(), in.NextInt()
}

// NextInt2d は 次の2つの入力を数値n1,n2として読み込んで、n1+d1, n2+d2を返します。
func (in *In) NextInt2d(d1, d2 int) (int, int) {
	return in.NextInt() + d1, in.NextInt() + d2
}

// NextInt3 は 次の3つの入力を数値として読み込んで返します。
func (in *In) NextInt3() (int, int, int) {
	return in.NextInt(), in.NextInt(), in.NextInt()
}

// NextInt2d は 次の3つの入力を数値n1,n2,n3として読み込んで、n1+d1, n2+d2, n3+d3を返します。
func (in *In) NextInt3d(d1, d2, d3 int) (int, int, int) {
	return in.NextInt() + d1, in.NextInt() + d2, in.NextInt() + d3
}

// NextInt4 は 次の4つの入力を数値として読み込んで返します。
func (in *In) NextInt4() (int, int, int, int) {
	return in.NextInt(), in.NextInt(), in.NextInt(), in.NextInt()
}

// NextInts は 次のn個の入力を数値として読み込んで、配列として返します。
func (in *In) NextInts(n int) sort.IntSlice {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = in.NextInt()
	}
	return sort.IntSlice(a)
}

// NextLongIntAsArray は 次の入力を数値として読み込み、各桁を要素とした配列を返します。
func (in *In) NextLongIntAsArray() []int {
	s := in.NextString()
	l := len(s)
	arr := make([]int, l)
	for i := 0; i < l; i++ {
		arr[i] = int(s[i] - '0')
	}

	return arr
}

// NextFloat は 次の入力を実数値として読み込み、値を返します。
func (in *In) NextFloat() float64 {
	f, _ := strconv.ParseFloat(in.NextString(), 64)
	return f
}

// NextFloatAsInt は次の入力を実数rとして読み込み、r * 10^base の値を返します。
func (in *In) NextFloatAsInt(base int) int {
	if base%10 == 0 {
		panic("baseは小数点の最大桁数を指定する")
	}

	s := in.NextString()
	index := strings.IndexByte(s, '.')

	// 小数点がなければそのまま返す
	if index == -1 {
		n, _ := strconv.Atoi(s)
		return n * pow(10, base)
	}

	// 末尾の0を消しておく
	for s[len(s)-1] == '0' {
		s = s[:len(s)-1]
	}

	// 整数部分 * 10^base + 小数部分 * 10^(足りない分)
	s1, s2 := s[:index], s[index+1:]
	n, _ := strconv.Atoi(s1)
	m, _ := strconv.Atoi(s2)

	return n*pow(10, base) + m*pow(10, base-len(s2))
}

// Println は引数をスペース区切りで出力し、最後に改行を出力します。
func (out *Out) Println(a ...interface{}) {
	fmt.Fprintln(out.writer, a...)
}

// Printf はformatにしたがってaを整形して出力します。
func (out *Out) Printf(format string, a ...interface{}) {
	fmt.Fprintf(out.writer, format, a...)
}

// PrintStringsln は文字列配列の各要素をスペース区切りで出力し、最後に改行を出力します。
func (out *Out) PrintStringsln(a []string) {
	out.Println(strings.Join(a, " "))
}

// PrintIntsLn は整数配列の各要素をスペース区切りで出力し、最後に改行を出力します。
func (out *Out) PrintIntsLn(a []int) {
	b := make([]string, len(a))
	for i, v := range a {
		b[i] = fmt.Sprint(v)
	}
	out.Println(strings.Join(b, " "))
}

func (out *Out) PrintLenAndIntsLn(a []int) {
	b := make([]string, len(a)+1)
	b[0] = fmt.Sprint(len(a))
	for i, v := range a {
		b[i+1] = fmt.Sprint(v)
	}
	out.Println(strings.Join(b, " "))
}

// YesNo は condが真ならYes, 偽ならNoを出力します。
func (out *Out) YesNo(cond bool) {
	if cond {
		out.Println("Yes")
	} else {
		out.Println("No")
	}
}

func (out *Out) YESNO(cond bool) {
	if cond {
		out.Println("YES")
	} else {
		out.Println("NO")
	}
}

// ==================================================
// 数値操作
// ==================================================

// max は aとbのうち大きい方を返します。
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

// min は aとbのうち小さい方を返します。
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

// abs は aの絶対値を返します。
func abs(a int) int {
	if a > 0 {
		return a
	}
	return -a
}

// pow は aのb乗を返します。
func pow(a, b int) int {
	ans := 1
	for b > 0 {
		if b%2 == 1 {
			ans *= a
		}
		a, b = a*a, b/2
	}
	return ans
}

// divceil は a/b の結果を正の無限大に近づけるように丸めて返します。
func divceil(a, b int) int {
	if a%b == 0 || a/b < 0 {
		return a / b
	}
	return (a + b - 1) / b
}

// divfloor は a/b の結果を負の無限大に近づけるように丸めて返します。
func divfloor(a, b int) int {
	if a%b == 0 || a/b > 0 {
		return a / b
	}
	if b < 0 {
		a, b = -a, -b
	}
	return (a - b + 1) / b
}

// powmod は (x^n) mod m を返します。
func powmod(x, n, m int) int {
	x = x % m
	if x == 0 {
		return 0
	}

	ans := 1
	for n > 0 {
		if n%2 == 1 {
			ans = (ans * x) % m
		}
		x = (x * x) % m
		n /= 2
	}
	return ans
}

// ch は condがtrueのときok, falseのときngを返します。
func ch(cond bool, ok, ng int) int {
	if cond {
		return ok
	}
	return ng
}

// ==================================================
// ビット操作
// ==================================================

// nthbit はaのn番目のビットを返します。
func nthbit(a int, n int) int { return int((a >> uint(n)) & 1) }

// popcount はaのうち立っているビットを数えて返します。
func popcount(a int) int {
	return bits.OnesCount(uint(a))
}

func xor(a, b bool) bool { return a != b }

// ==================================================
// 文字列操作
// ==================================================

// toLowerCase は sをすべて小文字にした文字列を返します。
func toLowerCase(s string) string {
	return strings.ToLower(s)
}

// toUpperCase は sをすべて大文字にした文字列を返します。
func toUpperCase(s string) string {
	return strings.ToUpper(s)
}

// isLower はbが小文字かどうかを判定します
func isLower(b byte) bool {
	return 'a' <= b && b <= 'z'
}

// isUpper はbが大文字かどうかを判定します
func isUpper(b byte) bool {
	return 'A' <= b && b <= 'Z'
}

// ==================================================
// 配列
// ==================================================
// NewIntInt は数値の二次元配列を作成します。
func NewIntInt(rows, cols, val int) [][]int {
	a := make([][]int, rows)
	for i := 0; i < rows; i++ {
		a[i] = make([]int, cols)

		for j := 0; j < cols; j++ {
			a[i][j] = val
		}
	}

	return a
}

func reverse(arr *[]interface{}) {
	for i, j := 0, len(*arr)-1; i < j; i, j = i+1, j-1 {
		(*arr)[i], (*arr)[j] = (*arr)[j], (*arr)[i]
	}
}

func reverseInt(arr *[]int) {
	for i, j := 0, len(*arr)-1; i < j; i, j = i+1, j-1 {
		(*arr)[i], (*arr)[j] = (*arr)[j], (*arr)[i]
	}
}

func uniqueInt(arr []int) []int {
	hist := map[int]bool{}
	j := 0
	for i := 0; i < len(arr); i++ {
		if hist[arr[i]] {
			continue
		}

		a := arr[i]
		arr[j] = a
		hist[a] = true
		j++
	}
	return arr[:j]
}

// ==================================================
// 構造体
// ==================================================

// Point は 座標を表す構造体です。
type Point struct {
	x int
	y int
}

type Geo struct {
}

// NextPointは入力から2点読み込んで座標として返します。
func (g *Geo) NextPoint() *Point {
	return &Point{in.NextInt(), in.NextInt()}
}

// x2areaは3点で囲まれる面積の2倍を返します。
func (g *Geo) x2area(p1 *Point, p2 *Point, p3 *Point) int {
	return abs(p1.x*p2.y + p2.x*p3.y + p3.x*p1.y - p1.y*p2.x - p2.y*p3.x - p3.y*p1.x)
}

package main

import "fmt"

const N = 2e5 + 10

var a, b [N]int

func lowbit(x int) int {
	return x & (-x)
}

func add(x, k int) {
	for i := x; i < N; i += lowbit(i) {
		b[i] += k
	}
}

func get(x int) int {
	ans := 0
	for i := x; i >0 ; i -= lowbit(i) {
		ans += b[i]
	}
	return ans
}

func main() {
	var T int
	fmt.Scan(&T)
	for T > 0 {
		T--
		var n int
		fmt.Scan(&n)
		ans := 0
		for i := 1; i <= n; i++ {
			fmt.Scan(&a[i])
			a[i] = n - a[i] + 1
			ans += get(a[i])
			add(a[i], 1)
		}
		for i := 1; i <= n; i++ {
			add(a[i], -1)
		}
		fmt.Println(ans)

	}
}

package main

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

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

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

type Key struct {
	n int
	k int
}

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var niter int
	fmt.Fscan(in, &niter)
	for iiter := 0; iiter < niter; iiter++ {
		var n int
		fmt.Fscan(in, &n)
		m := make(map[int]int, n)
		res := 0
		for i := 0; i < n; i++ {
			var el int
			fmt.Fscan(in, &el)
			for key, val := range m {
				if key >= el {
					res += val
				}
			}
			m[el] += 1
		}
		fmt.Fprintln(out, res)
	}
}

package main

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

var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

func slove() {
	var n int
	fmt.Fscan(r, &n)
	nums := make([]int, n)
	cnt := make(map[int]int)
	for i:=0;i<n;i++ {
		fmt.Fscan(r, &nums[i])
		cnt[nums[i]]++
	}
	f := newFenwick(2e5+5)
	var ans int64
	for i := range nums {
		ans += int64(f.query(nums[i]+1, 2e5+2))
		f.add(nums[i], 1)
	}
	for _, v := range cnt {
		ans += int64((v-1))*int64(v)/2
	}
	fmt.Fprintln(w, ans)
}

func main() {
	defer w.Flush()
	var n int
	fmt.Fscan(r, &n)
	for i:=1;i<=n;i++ {
		slove()
	}
}

type fenwick struct {tree []int}
func newFenwick(n int) fenwick {return fenwick{make([]int, n+1)}}
func (f fenwick) add(i int, val int) {for ; i < len(f.tree); i += i & -i {f.tree[i] += val}}
func (f fenwick) sum(i int) (res int) {for ; i > 0; i -= i & -i {res += f.tree[i]}; return}
func (f fenwick) query(l, r int) int {return f.sum(r) - f.sum(l-1)}

package main

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

// github.com/EndlessCheng/codeforces-go
type fenwick struct {
	tree []int
}

func newFenwickTree(n int) fenwick {
	return fenwick{make([]int, n+1)}
}
func (f fenwick) add(i int, val int) {
    //i++
	for ; i < len(f.tree); i += i & -i {
		f.tree[i] += val
	}
}
func (f fenwick) sum(i int) (res int) {
    //i++
	for ; i > 0; i &= i - 1 {
		res += f.tree[i]
	}
	return
}
func (f fenwick) query(l, r int) (res int) { // [l,r]
	return f.sum(r) - f.sum(l-1)
}

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

	solve := func(curCase int) {
		var n int
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		f := newFenwickTree(n+1)
		ans := int64(0)
		for _, v := range a {
			s := f.query(v,n)
			ans+= int64(s)
			f.add(v,1)
		}
		Fprintln(out, ans)
	}

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

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

}

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

package main

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

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

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

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

		var tot int
		for i := 0; i < n-1; i++ {
			if i > arr[i] {
				continue
			}

			for j := i + 1; j < n; j++ {
				if arr[i] >= arr[j] {
					tot++
				}
			}
		}
		fmt.Fprintln(out, tot)
	}
}

package main

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

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

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

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

		var tot int
		for i := 0; i < n-1; i++ {
			if i+1 > arr[i] {
				continue
			}

			for j := i + 1; j < n; j++ {
				if arr[i] >= arr[j] {
					tot++
				}
			}
		}
		fmt.Fprintln(out, tot)
	}
}


package main

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

func main() {
	re := regexp.MustCompile(`\r?\n`)
	strs := make([]string, 2)

	reader := bufio.NewReader(os.Stdin)
	for i := 0; i < 2; i++ {
		if s, err := reader.ReadString('\n'); err != nil {
			if err == io.EOF {
				break
			} else {
				return
			}
		} else {
			strs[i] = re.ReplaceAllString(s, "")
		}
	}
	out_str := make([]byte, len(strs[0]))

	follow := 0
	for i := 0; i < len(strs[0]); i++ {
		if strs[0][i] == strs[1][i] {
			out_str[i] = strs[0][i]
		} else {
			out_str[i] = strs[follow][i]
			follow = (follow + 1) % 2
		}
	}

	if follow == 1 {
		fmt.Println("impossible")
	} else {
		fmt.Printf("%s\n", out_str)
	}
}

// Codeforces 911 C done
package main

import (
	"bufio"
	"fmt"
	"strings"
	"strconv"
	"os"
)
var in *bufio.Reader

func readFive() (int,int,int,int,int) {
	var a [5]int
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("first read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	for i:=0; i<len(ss); i++ {
		a[i], err = strconv.Atoi(ss[i])
		if err != nil {
			fmt.Println("n atoi failure", err)
			panic(err)
		}
	}
	return a[0],a[1],a[2],a[3],a[4]
}

func readLineNumbs(n int) []int {
	a := make([]int, n)
	s, err := in.ReadString('\n')
	if err != nil {
		fmt.Println("read failure", err)
		panic(err)
	}
	ss := strings.Split(strings.Trim(s, " \n\r"), " ")
	for j:=0; j<n; j++ {
		aa,err := strconv.Atoi(ss[j])
		if err != nil {
			fmt.Println("aa conv failed", err)
			panic(err)
		}
		a[j] = aa
	}
	return a
}

const BAD_BYTE = 99
var s []byte
var t []byte
var res []byte

func readData() {
	in = bufio.NewReader(os.Stdin)
	str,_ := in.ReadString('\n')
	s = []byte(str)
	str,_ = in.ReadString('\n')
	t = []byte(str)
}

func solve() {
	ndiff := 0
	n := len(s)
	for i:=0; i<n; i++ {
		if s[i] != t[i] {
			ndiff++
		}
	}
	res = make([]byte, n)
	if (ndiff % 2) == 1 {
		res[0] = BAD_BYTE
		return
	}
	nd2 := ndiff/2
	dcnt := 0
	for i:=0; i<n; i++ {
		if s[i] == t[i] {
			res[i] = s[i]
		} else {
			if dcnt < nd2 {
				res[i] = s[i]
			} else {
				res[i] = t[i]
			}
			dcnt++
		}
	}
}

func printRes() {
	if res[0] == BAD_BYTE {
		fmt.Println("impossible")
	} else {
		fmt.Println(string(res))
	}
}

func main() {
	readData()
	solve()
	printRes()
}

package main

import (
	"fmt"
)

func main() {
	var s, t string
	fmt.Scan(&s, &t)

	p := make([]byte, len(s), len(s))

	dis := 0
	cur := 0
	for i := 0; i < len(s); i++ {
		if s[i] != t[i] {
			dis++
			if cur%2 == 0 {
				p[i] = s[i]
			} else {
				p[i] = t[i]
			}
			cur++
		} else {
			p[i] = s[i]
		}
	}

	if dis%2 == 0 {
		fmt.Println(string(p))
	} else {
		fmt.Println("impossible")
	}
}

package main

import (
	"fmt"
)

var (
	s, t string
	C = [2]string{"0", "1"}
)

func main() {
	fmt.Scan(&s, &t)
	ct := 0
	buf := make([]uint8, 0)
	for i := 0; i < len(s); i++ {
		if s[i] != t[i] {
			if ct % 2 == 0 {
				buf = append(buf, s[i])
			} else {
				buf = append(buf, t[i])
			}
			ct++
		} else {
			buf = append(buf, s[i])
		}
	}
	if ct % 2 == 1 {
		fmt.Println("impossible")
	} else {
		fmt.Println(string(buf))
	}
}

package main

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

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

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

	var s, t string

	scan(&s, &t)

	n, dif := len(s), 0

	for i := 0; i < n; i++ {
		if s[i] != t[i] {
			dif++
		}
	}
	if dif%2 == 0 {
		cnt := 0

		for i := 0; i < n; i++ {
			if s[i] == t[i] {
				printf("%c", s[i])
			} else {
				if cnt < dif/2 {
					if s[i] == '1' {
						print(0)
					} else {
						print(1)
					}
				} else {
					if s[i] == '1' {
						print(1)
					} else {
						print(0)
					}
				}
				cnt++
			}
		}
		println()
	} else {
		println("impossible")
	}
}

func scan(a ...interface{}) {
	fmt.Fscan(reader, a...)
}

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

func nextInt64() int64 {
	n, _ := strconv.ParseInt(next(), 0, 64)
	return n
}

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

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

func println(a ...interface{})               { fmt.Fprintln(writer, a...) }
func print(a ...interface{})                 { fmt.Fprint(writer, a...) }
func printf(format string, a ...interface{}) { fmt.Fprintf(writer, format, a...) }

package main

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

var reader *bufio.Reader
var writer *bufio.Writer

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

  line, _ := reader.ReadString('\n')
  s := strings.TrimSpace(line)
  line, _ = reader.ReadString('\n')
  t := strings.TrimSpace(line)
  n := len(s)
  count := 0
  p := make([]byte, n)
  for i := 0; i < n; i++ {
    if s[i] == t[i] {
      p[i] = s[i]
    } else {
      count++
      if count%2 == 0 {
        p[i] = s[i]
      } else {
        p[i] = t[i]
      }
    }
  }
  if count%2 == 1 {
    writer.WriteString("impossible\n")
  } else {
    writer.WriteString(fmt.Sprintf("%s\n", p))
  }
}

package main

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

var reader *bufio.Reader
var writer *bufio.Writer

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

  line, _ := reader.ReadString('\n')
  s := strings.TrimSpace(line)
  line, _ = reader.ReadString('\n')
  t := strings.TrimSpace(line)
  n := len(s)
  count := 0
  p := make([]byte, n)
  for i := 0; i < n; i++ {
    if s[i] == t[i] {
      p[i] = s[i]
    } else {
      count++
      if count%2 == 0 {
        p[i] = '0'
      } else {
        p[i] = '1'
      }
    }
  }
  if count%2 == 1 {
    writer.WriteString("impossible\n")
  } else {
    writer.WriteString(fmt.Sprintf("%s\n", p))
  }
}


package main

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

var sc *bufio.Scanner = bufio.NewScanner(os.Stdin)
var w *bufio.Writer = bufio.NewWriter(os.Stdout)

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

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

func pri(n int)    { w.WriteString(strconv.Itoa(n)) }
func prll(n int64) { w.WriteString(strconv.FormatInt(n, 10)) }
func sp()          { w.WriteByte(' ') }
func endl()        { w.WriteByte('\n') }

func main() {
  sc.Split(bufio.ScanWords)
  n := ni()
  a, b := make([]int, n), make([]int, n+1)
  for i := 0; i < n; i++ {
    a[i] = ni()
  }
  for i := 0; i < n; i++ {
    b[ni()] = i
  }
  ii := 1
  for ; ii < n && b[a[ii]] > b[a[ii-1]]; ii++ {
  }
  pri(n - ii)
  endl()
  w.Flush()
}

package main

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

var sc *bufio.Scanner = bufio.NewScanner(os.Stdin)
var w *bufio.Writer = bufio.NewWriter(os.Stdout)

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

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

func pri(n int)    { w.WriteString(strconv.Itoa(n)) }
func prll(n int64) { w.WriteString(strconv.FormatInt(n, 10)) }
func sp()          { w.WriteByte(' ') }
func endl()        { w.WriteByte('\n') }

func main() {
  sc.Split(bufio.ScanWords)
  n := ni()
  a, b := make([]int, n), make(map[int]int)
  for i := 0; i < n; i++ {
    a[i] = ni()
  }
  for i := 0; i < n; i++ {
    b[ni()] = i
  }
  ii := 1
  for ; ii < n && b[a[ii]] > b[a[ii-1]]; ii++ {
  }
  pri(n - ii)
  endl()
  w.Flush()
}


//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 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 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 "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, " ")
		}
	}
}

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

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

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


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

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


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
}

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
}