package main

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

const (
	SCANNER_BUF_SIZE = 2 << 20

	INF = int64(math.MaxInt64)
	MOD = 1e9 + 7
)

var (
	writer  *bufio.Writer
	scanner *bufio.Scanner
)

func init() {
	writer = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, SCANNER_BUF_SIZE), SCANNER_BUF_SIZE)
}

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

func sint64() int64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func suint64() uint64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

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

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

func main() {
	defer writer.Flush()
	t := sint64()
	for ; t > 0; t-- {
		res := solve(sint64())
		for _, d := range res {
			printf("%d ", d)
		}
		printf("\n")
	}
}

func solve(n int64) []int64 {
	ret := []int64{}
	for ; n > 0; n-- {
		ret = append(ret, 1)
	}
	return ret
}

package main

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

var (
	t int8
	n int8
)

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

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

		for ; n > 0; n-- {
			if n == 1 {
				fmt.Printf("1\n")
			} else {
				fmt.Printf("1 ")
			}
		}
	}
}

// Written by : Syed Mujtaba
// Seek knowledge from the cradle to the grave
package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }

func main() {
  defer writer.Flush()
  var t int
  scanf("%d\n", &t)

  for i := 0; i < t; i++ {
  	var n int
  	scanf("%d\n", &n)
  	for j := 0; j < n; j++ {
  		printf("1 ")
  	}
  	printf("\n")
  }
}

package main

import "fmt"

func main () {
	var t int64
	fmt.Scan(&t)
	for ; t > 0; t-- {
		var a int64
		fmt.Scan(&a)
		for ; a > 0; a-- {
			fmt.Print("1 ")
		}
		fmt.Println()
	}
}

package main

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

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

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

func solveA() {
	n := 0
	scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		printf("1 ")
	}
	printf("\n")
}

func solveB() {
	n := 0
	scanf("%d\n", &n)
	d := make(map[int]int)
	ans := "NO"
	for k, i := 0, 0; i < n; i++ {
		scanf("%d ", &k)
		d[k]++
		if d[k] > 1 {
			ans = "YES"
		}
	}
	printf(ans + "\n")
}

func main() {
	defer writer.Flush()
	var t int
	scanf("%d\n", &t)
	for ; t > 0; t-- {
		solveA()
	}
}

/*
URL:
https://codeforces.com/contest/1438/problem/A
*/

package main

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

var (
	t int

	n int
)

func main() {
	defer stdout.Flush()

	t = readi()
	for tc := 0; tc < t; tc++ {
		n = readi()

		solve()
	}
}

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

	printf("%s\n", PrintIntsLine(A...))
}

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

/********** common constants **********/

const (
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPH_N  = 26
	INF_I64 = math.MaxInt64
	INF_B60 = 1 << 60
	INF_I32 = math.MaxInt32
	INF_B30 = 1 << 30
	NIL     = -1
	EPS     = 1e-10
)

/********** bufio setting **********/

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

// mod can calculate a right residual whether value is positive or negative.
func mod(val, m int) int {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

// min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// chmin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func chmin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// chmax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func chmax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// sum returns multiple integers sum.
func sum(integers ...int) int {
	var s int
	s = 0

	for _, i := range integers {
		s += i
	}

	return s
}

// abs is integer version of math.Abs
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// pow is integer version of math.Pow
// pow calculate a power by Binary Power (二分累乗法(O(log e))).
func pow(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}

	if e == 0 {
		return 1
	}

	if e%2 == 0 {
		halfE := e / 2
		half := pow(a, halfE)
		return half * half
	}

	return a * pow(a, e-1)
}

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

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

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

//str := reads()
//i := readi()
//X := readis(n)
//S := readrs()
//a := readf()
//A := readfs(n)

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

/*********** Input ***********/

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

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

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

// readi returns an integer.
func readi() int {
	return int(_readInt64())
}
func readi2() (int, int) {
	return int(_readInt64()), int(_readInt64())
}
func readi3() (int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64())
}
func readi4() (int, int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64()), int(_readInt64())
}

// readll returns as integer as int64.
func readll() int64 {
	return _readInt64()
}
func readll2() (int64, int64) {
	return _readInt64(), _readInt64()
}
func readll3() (int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64()
}
func readll4() (int64, int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64(), _readInt64()
}

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

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

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

// readf returns an float64.
func readf() float64 {
	return float64(_readFloat64())
}

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

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

// readrs returns a rune slice.
func readrs() []rune {
	return []rune(reads())
}

/*********** Output ***********/

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

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

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

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

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

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

	return res
}

package main

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

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

	solve := func(Case int) {
		var n int
		Fscan(in, &n)
		for i := 0; i < n; i++ {
			Fprint(out, "1 ")
		}
		Fprintln(out)
	}

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

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

package main

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

var t int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)

	fmt.Fscan(input, &t)

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

		for i := 0; i < n; i++ {
			fmt.Printf("1 ")
		}

		fmt.Println()
	}
}

package main

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

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

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

	for ; t > 0; t-- {
		fmt.Fscan(in, &n)
		result := ""
		for i := 0; i < n; i++ {
			result += "1 "
		}
		fmt.Println(result)
	}
}

package main

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

var reader = bufio.NewReader(os.Stdin)

func main() {
	var t int
	fmt.Fscan(reader, &t)

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

		for j := 0; j < n; j++ {
			fmt.Print("1 ")
		}
		fmt.Println()
	}
}

package main

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

func main() {
	var t, n, c0, c1, h int
	var s string

	reader := bufio.NewReader(os.Stdin)

	fmt.Fscan(reader, &t)

	for ; t > 0; t-- {
		fmt.Fscan(reader, &n, &c0, &c1, &h)
		fmt.Fscan(reader, &s)

		fmt.Println(cal(n, c0, c1, h, s))
	}
}

func cal(n int, c0 int, c1 int, h int, s string) int {

	buyD := 0
	buyC := 0

	for i := range s {
		if s[i] == '0' {
			buyD += c0
		}
		if s[i] == '1' {
			buyD += c1
		}
	}

	for i := range s {
		if s[i] == '0' {
			if c0 > c1 {
				buyC += h
				buyC += c1
			} else {
				buyC += c0
			}
		}

		if s[i] == '1' {
			if c1 > c0 {
				buyC += h
				buyC += c0
			} else {
				buyC += c1
			}
		}
	}

	if buyC >= buyD {
		return buyD
	} else {
		return buyC
	}

}


package main

import (
	"fmt"
)

func main() {
	var n int
	var arr [120005]int
	var pows [33]int64
	mp := make(map[int64]int)

	for i := 1; i <= 31; i++ {
		pows[i] = 1 << uint(i)
	}

	fmt.Scan(&n)
	for i := 1; i <= n; i++ {
		fmt.Scan(&arr[i])
		mp[int64(arr[i])]++
	}

	var cnt int = 0
	for i := 1; i <= n; i++ {
		for j := 1; j <= 31; j++ {
			tmp := pows[j] - int64(arr[i])
			if tmp <= 0 {
				continue
			} else if mp[tmp] <= 0 {
				continue
			}

			if (tmp == int64(arr[i]) && mp[tmp] > 1) || (tmp != int64(arr[i]) && mp[tmp] > 0) {
				cnt++
				break
			}
		}
	}

	fmt.Println(n - cnt)
}

package main

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

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

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

	twos := make([]int, 32)
	for i := range twos {
		twos[i] = 1 << uint(i)
	}

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

	cnt := 0
	for i := range set {
		if set[i] == 0 {
			continue
		}

		found := false
		for _, two := range twos {
			if two < i {
				continue
			}

			diff := two - i
			if (diff != i && set[diff] > 0) || (diff == i && set[diff] > 1) {
				found = true
				break
			}
		}

		if !found {
			cnt += set[i]
		}
	}

	fmt.Println(cnt)
}

package main

import (
	"fmt"
	"sort"
)

func main() {
	var (
		n, ans int
		a []int
	)

	fmt.Scan(&n)
	ans = n;
	a = make([]int, n)
	for i := range a {
		fmt.Scan(&a[i])
	}
	sort.Ints(a)

	for i, val := range a {
		var found bool
		for j := 0; !found && j < 31; j++ {
			p := 1 << uint(j)
			req := p - val
			if req < 0 {
				continue
			}

			ind := sort.Search(n, func(ind int) bool {
				return a[ind] > req
			})
			found = ind - 1 >= 0 && a[ind-1] == req && ind-1 != i

			ind = sort.Search(n, func(ind int) bool {
				return a[ind] >= req
			})
			found = found || (ind < n && a[ind] == req && ind != i)
		}

		if found {
			ans--
		}
	}

	fmt.Println(ans)
}

package main

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

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

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

	twos := make([]int, 32)
	for i := range twos {
		twos[i] = 1 << uint(i)
	}

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

	cnt := 0
	for i := 1; i <= 120000; i++ {
		if set[i] == 0 {
			continue
		}

		found := false
		for _, two := range twos {
			if two < i {
				continue
			}

			diff := two - i
			if (diff != i && set[diff] > 0) || (diff == i && set[diff] > 1) {
				found = true
				break
			}
		}

		if !found {
			cnt += set[i]
		}
	}

	fmt.Println(cnt)
}

package main

import (
	"fmt"
)

func main() {
	var n int
	var arr [120005]int
	var pows [33]int64
	mp := make(map[int64]int)

	for i := 1; i <= 31; i++ {
		pows[i] = 2 << uint(i)
	}

	fmt.Scan(&n)
	for i := 1; i <= n; i++ {
		fmt.Scan(&arr[i])
		mp[int64(arr[i])]++
	}

	var cnt int = 0
	for i := 1; i <= n; i++ {
		for j := 1; j <= 31; j++ {
			tmp := pows[j] - int64(arr[i])
			if tmp <= 0 {
				continue
			} else if mp[tmp] <= 0 {
				continue
			}

			if (tmp == int64(arr[i]) && mp[tmp] > 1) || (tmp != int64(arr[i]) && mp[tmp] > 0) {
				cnt++
				break
			}
		}
	}

	fmt.Println(n - cnt)
}


package main

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

func main() {
	var n, k, min, summ int64
	var tmp int
	min = 1000000001
	var line string
	var arr []int64
	var arrS []string
	reader := bufio.NewReader(os.Stdin)
	fmt.Scanf("%d %d\n", &n, &k)
	line, _ = reader.ReadString('\n')
	arrS = strings.Split(strings.TrimSpace(line), " ")
	for j := range arrS {
		tmp, _ = strconv.Atoi(arrS[j])
		if int64(tmp) < min {
			min = int64(tmp)
		}
		arr = append(arr, int64(tmp))
	}
	for i := 0; i < len(arr); i++ {
		if (arr[i]-min)%k != 0 {
			fmt.Println("-1")
			os.Exit(0)
		} else {
			summ = summ + ((arr[i] - min) / k)
		}
	}
	fmt.Println(summ)
}

package main

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

var in = bufio.NewScanner(os.Stdin)

func readInt() int64 {
	if !in.Scan() {
		panic(in.Err())
	}
	res := int64(0)
	mul := int64(1)
	for _, b := range in.Bytes() {
		if b == '-' {
			mul *= -1
			continue
		}
		res = res*10 + int64(b-'0')
	}
	return mul * res
}
func main() {
	in.Split(bufio.ScanWords)

	n := readInt()
	k := readInt()
	a := make([]int64, n)
	min := int64(1e9)
	for i := range a {
		a[i] = readInt()
		if min > a[i] {
			min = a[i]
		}
		if i > 0 {
			if (a[i]-a[i-1])%k != 0 {
				fmt.Println(-1)
				return
			}
		}
	}
	var res int64
	for _, a := range a {
		res += (a - min) / k
	}
	fmt.Println(res)
}

package main

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

func I(i ...interface{}) error {
	_, err := fmt.Fscan(r, i...)
	return err
}

func O(o ...interface{}) {
	fmt.Fprint(w, o...)
}

var (
	r *bufio.Reader
	w *bufio.Writer
)

func init() {
	if f, err := os.Open("in.goC"); err == nil {
		r = bufio.NewReader(f)
	} else {
		r = bufio.NewReader(os.Stdin)
	}
	w = bufio.NewWriter(os.Stdout)
}

func main() {
	defer w.Flush()
	var n, k int
	for I(&n, &k) == nil {
		solve(n, k)
	}
}

func solve(n, k int) {
	in := make(arr, n)
	for i := range in {
		I(&in[i])
	}
	if len(in) == 1 {
		O("0\n")
		return
	}
	sort.Sort(in)
	var ans int64 = 0
	for i := range in {
		if i != n-1 {
			if (in[i]-in[i+1])%int64(k) != 0 {
				O("-1\n")
				return
			}
		}
		ans += (in[i] - in[n-1]) / int64(k)
	}
	O(ans, "\n")
}

type arr []int64

func (a arr) Len() int           { return len(a) }
func (a arr) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a arr) Less(i, j int) bool { return a[i] > a[j] }

package main

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

func solve() {
	n := readInt()
	k := readInt64()
	a := make([]int, n)
	m := math.MaxInt32
	for i := 0; i < n; i++ {
		a[i] = readInt()
		m = min(m, a[i])
	}
	var total int64
	for i := 0; i < n; i++ {
		d := int64(a[i] - m)
		if d%k != 0 {
			fmt.Println(-1)
			return
		}
		total += d / k
	}

	fmt.Println(total)
}

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

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 abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a int, b int) int {
	if a < b {
		return a
	}
	return b
}

// IO

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
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

package main

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

func solve() {
	n := readInt()
	k := readInt()
	a := make([]int, n)
	m := math.MaxInt32
	for i := 0; i < n; i++ {
		a[i] = readInt()
		m = min(m, a[i])
	}
	var total int
	for i := 0; i < n; i++ {
		d := a[i] - m
		if d%k != 0 {
			fmt.Println(-1)
			return
		}
		total += d / k
	}

	fmt.Println(total)
}

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

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 abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a int, b int) int {
	if a < b {
		return a
	}
	return b
}

// IO

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
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

package main

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

func main() {
	var n, k, tmp, min, summ int
	min = 1000000001
	var line string
	var arr []int
	var arrS []string
	reader := bufio.NewReader(os.Stdin)
	fmt.Scanf("%d %d\n", &n, &k)
	line, _ = reader.ReadString('\n')
	arrS = strings.Split(strings.TrimSpace(line), " ")
	for j := range arrS {
		tmp, _ = strconv.Atoi(arrS[j])
		if tmp < min {
			min = tmp
		}
		arr = append(arr, tmp)
	}
	for i := 0; i < len(arr); i++ {
		if (arr[i]-min)%k != 0 {
			fmt.Println("-1")
			os.Exit(0)
		} else {
			summ = summ + ((arr[i] - min) / k)
		}
	}
	fmt.Println(summ)
}

package main

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

func main() {
	var k, tmp, min, summ int
	min = 1000000001
	var line string
	var arr []int
	var arrS []string
	reader := bufio.NewReader(os.Stdin)
	line, _ = reader.ReadString('\n')
	arrS = strings.Split(strings.TrimSpace(line), " ")
	for j := range arrS {
		tmp, _ = strconv.Atoi(arrS[j])
		arr = append(arr, tmp)
	}
	k = arr[1]
	arr = []int{}
	line, _ = reader.ReadString('\n')
	arrS = strings.Split(strings.TrimSpace(line), " ")
	for j := range arrS {
		tmp, _ = strconv.Atoi(arrS[j])
		if tmp < min {
			min = tmp
		}
		arr = append(arr, tmp)
	}
	for i := 0; i < len(arr); i++ {
		if (arr[i]-min)%k != 0 {
			fmt.Println("-1")
			os.Exit(0)
		} else {
			summ = summ + ((arr[i] - min) / k)
		}
	}
	fmt.Println(summ)
}


package main

import (
	"fmt"
)

func loadData() string {
	var s string = ""
	fmt.Scanf("%s", &s)
	return s
}

func main() {
	var i, j, k, flag, ln int
	answer := make([]uint64, 30)
	tmp := make([]int, 30)
	for index, _ := range tmp {
		tmp[index] = -1
	}
	add := make([]int, 30)

	str := loadData()

	ln = len(str)
	for i = 0; i < ln; i++ {
		// fmt.Println(str[i])
		if tmp[str[i]-'a'+1] == -1 {
			for j = 26; j > 0; j-- {
				add[j] = add[j-1]
			}
			add[1]++
		} else {
			k = i - tmp[str[i]-'a'+1] - 1
			for flag = 1; k > 0; flag++ {
				k -= add[flag]
			}
			add[flag] += add[flag-1]
			for j = flag - 1; j > 0; j-- {
				add[j] = add[j-1]
			}
			add[1]++
		}
		tmp[str[i]-'a'+1] = i
		for j = 26; j > 0; j-- {
			answer[j] += uint64(add[j])
		}
	}
	for j = 26; j > 0; j-- {
		if answer[j] > 0 {
			fmt.Printf("%d\n", j)
			break
		}
	}
	for i = 1; i <= j; i++ {
		fmt.Printf("%d\n", answer[i])
	}
}

package main

import (
	"fmt"
)

func loadData() string {
	var s string = ""
	fmt.Scanf("%s", &s)
	return s
}

func main() {
	var i, j, k, flag, ln int
	answer := make([]uint64, 30)
	tmp := make([]int, 30)
	for index, _ := range tmp {
		tmp[index] = -1
	}
	add := make([]int, 30)

	str := loadData()

	ln = len(str)
	for i = 0; i < ln; i++ {
		if tmp[str[i]-'a'+1] == -1 {
			for j = 26; j > 0; j-- {
				add[j] = add[j-1]
			}
			add[1]++
		} else {
			k = i - tmp[str[i]-'a'+1] - 1
			for flag = 1; k > 0; flag++ {
				k -= add[flag]
			}
			add[flag] += add[flag-1]
			for j = flag - 1; j > 0; j-- {
				add[j] = add[j-1]
			}
			add[1]++
		}
		tmp[str[i]-'a'+1] = i
		for j = 26; j > 0; j-- {
			answer[j] += uint64(add[j])
		}
	}
	for j = 26; j > 0; j-- {
		if answer[j] > 0 {
			fmt.Printf("%d\n", j)
			break
		}
	}
	for i = 1; i <= j; i++ {
		fmt.Printf("%d\n", answer[i])
	}
}

package main

// http://codeforces.ru/problemset/status/386/problem/C/page/1?order=BY_PROGRAM_LENGTH_ASC
import (
	"fmt"
)

func loadData() string {
	var s string = ""
	fmt.Scanf("%s", &s)
	return s
}

func S(s string, i int, j int) int {
	tmp := make([]int, 26)
	ans := 0
	for t := i; t <= j; t++ {
		if tmp[s[t]-'a'] == 0 {
			tmp[s[t]-'a'] = 1
			ans++
		}
	}
	return ans
}

func main() {
	var ln int
	answer := make([]int, 30)

	tmp := make([]int, 30)
	for index, _ := range tmp {
		tmp[index] = -1
	}

	str := loadData()
	fmt.Println(str)

	ln = len(str)
	var d int = S(str, 0, ln-1)
	for i := 0; i < ln; i++ {
		for j := i; j < ln; j++ {
			t := S(str, i, j)
			//fmt.Printf("i=%d; j=%d; t=%d\n", i, j, t)
			answer[t]++

		}
	}

	fmt.Printf("%d\n", d)
	for i := 1; i <= d; i++ {
		fmt.Printf("%d ", answer[i])
	}
}

package main

import (
	"fmt"
)

func loadData() string {
	var s string = ""
	fmt.Scanf("%s", &s)
	return s
}

func main() {
	var i, j, k, flag, ln int
	answer := make([]uint32, 30)
	tmp := make([]int, 30)
	for index, _ := range tmp {
		tmp[index] = -1
	}
	add := make([]int, 30)

	str := loadData()

	ln = len(str)
	for i = 0; i < ln; i++ {
		// fmt.Println(str[i])
		if tmp[str[i]-'a'+1] == -1 {
			for j = 26; j > 0; j-- {
				add[j] = add[j-1]
			}
			add[1]++
		} else {
			k = i - tmp[str[i]-'a'+1] - 1
			for flag = 1; k > 0; flag++ {
				k -= add[flag]
			}
			add[flag] += add[flag-1]
			for j = flag - 1; j > 0; j-- {
				add[j] = add[j-1]
			}
			add[1]++
		}
		tmp[str[i]-'a'+1] = i
		for j = 26; j > 0; j-- {
			answer[j] += uint32(add[j])
		}
	}
	for j = 26; j > 0; j-- {
		if answer[j] > 0 {
			fmt.Printf("%d\n", j)
			break
		}
	}
	for i = 1; i <= j; i++ {
		fmt.Printf("%d\n", answer[i])
	}
}

package main

import (
	"fmt"
)

func loadData() string {
	var s string = ""
	fmt.Scanf("%s", &s)
	return s
}

func main() {
	var i, j, k, flag, ln int
	answer := make([]int, 30)
	tmp := make([]int, 30)
	for index, _ := range tmp {
		tmp[index] = -1
	}
	add := make([]int, 30)

	str := loadData()
	fmt.Println(str)

	ln = len(str)
	for i = 0; i < ln; i++ {
		// fmt.Println(str[i])
		if tmp[str[i]-'a'+1] == -1 {
			for j = 26; j > 0; j-- {
				add[j] = add[j-1]
			}
			add[1]++
		} else {
			k = i - tmp[str[i]-'a'+1] - 1
			for flag = 1; k > 0; flag++ {
				k -= add[flag]
			}
			add[flag] += add[flag-1]
			for j = flag - 1; j > 0; j-- {
				add[j] = add[j-1]
			}
			add[1]++
		}
		tmp[str[i]-'a'+1] = i
		for j = 26; j > 0; j-- {
			answer[j] += add[j]
		}
	}
	for j = 26; j > 0; j-- {
		if answer[j] > 0 {
			fmt.Printf("%d\n", j)
			break
		}
	}
	for i = 1; i <= j; i++ {
		fmt.Printf("%d\n", answer[i])
	}
}

package main

// http://codeforces.ru/problemset/status/386/problem/C/page/1?order=BY_PROGRAM_LENGTH_ASC
import (
	"fmt"
)

func loadData() string {
	var s string = ""
	fmt.Scanf("%s", &s)
	return s
}

func S(s string, i int, j int) int {
	tmp := make([]int, 26)
	ans := 0
	for t := i; t <= j; t++ {
		if tmp[s[t]-'a'] == 0 {
			tmp[s[t]-'a'] = 1
			ans++
		}
	}
	return ans
}

func main() {
	var ln int
	answer := make([]int, 30)

	tmp := make([]int, 30)
	for index, _ := range tmp {
		tmp[index] = -1
	}

	str := loadData()
	fmt.Println(str)

	ln = len(str)
	var d int = S(str, 0, ln-1)
	for i := 0; i < ln; i++ {
		for j := i; j < ln; j++ {
			t := S(str, i, j)
			//fmt.Printf("i=%d; j=%d; t=%d\n", i, j, t)
			answer[t]++

		}
	}

	fmt.Printf("%d\n", d)
	for i := 1; i <= d; i++ {
		fmt.Printf("%d\n", answer[i])
	}
}

package main

import (
	"fmt"
)

func loadData() string {
	var s string = ""
	fmt.Scanf("%s", &s)
	return s
}

func main() {
	var i, j, k, flag, ln int
	answer := make([]int, 30)
	tmp := make([]int, 30)
	for index, _ := range tmp {
		tmp[index] = -1
	}
	add := make([]int, 30)

	str := loadData()

	ln = len(str)
	for i = 0; i < ln; i++ {
		// fmt.Println(str[i])
		if tmp[str[i]-'a'+1] == -1 {
			for j = 26; j > 0; j-- {
				add[j] = add[j-1]
			}
			add[1]++
		} else {
			k = i - tmp[str[i]-'a'+1] - 1
			for flag = 1; k > 0; flag++ {
				k -= add[flag]
			}
			add[flag] += add[flag-1]
			for j = flag - 1; j > 0; j-- {
				add[j] = add[j-1]
			}
			add[1]++
		}
		tmp[str[i]-'a'+1] = i
		for j = 26; j > 0; j-- {
			answer[j] += add[j]
		}
	}
	for j = 26; j > 0; j-- {
		if answer[j] > 0 {
			fmt.Printf("%d\n", j)
			break
		}
	}
	for i = 1; i <= j; i++ {
		fmt.Printf("%d\n", answer[i])
	}
}

package main

import (
	"fmt"
)

func loadData() string {
	var s string = ""
	fmt.Scanf("%s", &s)
	return s
}

func main() {
	var i, j, k, flag, ln int
	answer := make([]int, 30)
	tmp := make([]int, 30)
	for index, _ := range tmp {
		tmp[index] = -1
	}
	add := make([]int, 30)

	str := loadData()
	fmt.Println(str)

	ln = len(str)
	for i = 0; i < ln; i++ {
		// fmt.Println(str[i])
		if tmp[str[i]-'a'+1] == -1 {
			for j = 26; j > 0; j-- {
				add[j] = add[j-1]
			}
			add[1]++
		} else {
			k = i - tmp[str[i]-'a'+1] - 1
			for flag = 1; k > 0; flag++ {
				k -= add[flag]
			}
			add[flag] += add[flag-1]
			for j = flag - 1; j > 0; j-- {
				add[j] = add[j-1]
			}
			add[1]++
		}
		tmp[str[i]-'a'+1] = i
		for j = 26; j > 0; j-- {
			answer[j] += add[j]
		}
	}
	for j = 26; j > 0; j-- {
		if answer[j] > 0 {
			fmt.Printf("%d\n", j)
			break
		}
	}
	for i = 1; i <= j; i++ {
		fmt.Printf("%d ", answer[i])
	}
}


package main

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

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

	for t := io.NextInt(); t > 0; t-- {
		n, m := io.NextInt(), io.NextInt()
		g := make([][]int, n+1)
		for i := 0; i < m; i++ {
			u, v := io.NextInt(), io.NextInt()
			g[u] = append(g[u], v)
			g[v] = append(g[v], u)
		}

		vis := make([]bool, n+1)
		par := make([]int, n+1)
		deep, dep := 0, 0
		var pairs [][]int
		cur := make([]int, n+1)

		var dfs func(int, int)
		dfs = func(u, d int) {
			vis[u] = true
			for _, v := range g[u] {
				if !vis[v] {
					par[v] = u
					if d > dep {
						deep, dep = v, d
					}
					if cur[d] == 0 {
						cur[d] = v
					} else {
						pairs = append(pairs, []int{cur[d], v})
						cur[d] = 0
					}
					dfs(v, d+1)
				}
			}
		}
		dfs(1, 1)

		if dep >= (n+1)/2 {
			var path []int
			cur := deep
			for cur != 0 {
				path = append(path, cur)
				cur = par[cur]
			}
			io.Println("PATH")
			io.Println(len(path))
			io.PrintlnInts(path...)
		} else {
			io.Println("PAIRING")
			io.Println(len(pairs))
			for _, p := range pairs {
				io.PrintlnInts(p...)
			}
		}
	}
}

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

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

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

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

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

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

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

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

package main

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

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

	for t := io.NextInt(); t > 0; t-- {
		n, m := io.NextInt(), io.NextInt()
		g := make([][]int, n+1)
		for i := 0; i < m; i++ {
			u, v := io.NextInt(), io.NextInt()
			g[u] = append(g[u], v)
			g[v] = append(g[v], u)
		}

		vis := make([]bool, n+1)
		par, dep := make([]int, n+1), make([]int, n+1)
		deep := 0
		var pairs [][2]int
		cur := make([]int, n+1)
		var dfs func(int)
		dfs = func(u int) {
			vis[u] = true
			for _, v := range g[u] {
				if !vis[v] {
					par[v] = u
					dep[v] = dep[u] + 1
					if dep[v] > dep[deep] {
						deep = v
					}
					if cur[dep[v]] == 0 {
						cur[dep[v]] = v
					} else {
						pairs = append(pairs, [2]int{cur[dep[v]], v})
						cur[dep[v]] = 0
					}
					dfs(v)
				}
			}
		}
		dfs(1)

		if dep[deep] >= (n+1)/2 {
			var path []int
			cur := deep
			for cur != 0 {
				path = append(path, cur)
				cur = par[cur]
			}
			io.Println("PATH")
			io.Println(len(path))
			io.PrintlnInts(path...)
		} else {
			io.Println("PAIRING")
			io.Println(len(pairs))
			for _, p := range pairs {
				io.PrintlnInts(p[0], p[1])
			}
		}
	}
}

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

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

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

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

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

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

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

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

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

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

package main

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

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

	for t := io.NextInt(); t > 0; t-- {
		n, m := io.NextInt(), io.NextInt()
		g := make([][]int, n+1)
		for i := 0; i < m; i++ {
			u, v := io.NextInt(), io.NextInt()
			g[u] = append(g[u], v)
			g[v] = append(g[v], u)
		}

		vis := make([]bool, n+1)
		par, dep := make([]int, n+1), make([]int, n+1)
		deep := 0
		var pairs [][2]int
		cur := make([]int, n+1)
		var dfs func(int)
		dfs = func(u int) {
			vis[u] = true
			for _, v := range g[u] {
				if !vis[v] {
					par[v] = u
					dep[v] = dep[u] + 1
					if dep[v] > dep[deep] {
						deep = v
					}
					if cur[dep[v]] == 0 {
						cur[dep[v]] = v
					} else {
						pairs = append(pairs, [2]int{cur[dep[v]], v})
						cur[dep[v]] = 0
					}
					dfs(v)
				}
			}
		}
		dfs(1)

		if dep[deep] >= (n+1)/2 {
			var path []int
			cur := deep
			for cur != 0 {
				path = append(path, cur)
				cur = par[cur]
			}
			io.Println("PATH")
			io.Println(len(path))
			io.PrintlnInts(path...)
		} else {
			io.Println("PAIRING")
			io.Println(len(pairs))
			for _, p := range pairs {
				io.PrintlnInts(p[0], p[1])
			}
		}
	}
}

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

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

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

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

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

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

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

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

package main

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

var in *bufio.Reader
var out *bufio.Writer

func printf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fprintf(out, x, a...)
}

func scanf(x string, a ...interface{}) (n int, err error) {
	return fmt.Fscanf(in, x, a...)
}

type priorityQueue [][2]int

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

func (pq priorityQueue) Less(i, j int) bool {
	return pq[i][1] > pq[j][1]
}

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

func (pq *priorityQueue) Push(x interface{}) {
	*pq = append(*pq, x.([2]int))
}

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

var err error

func next() (n string) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return ""
		}
	}
}

func nextInt() (n int) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func nextLong() (n int64) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func nextDouble() (n float64) {
	for {
		_, err = scanf("%v", &n)
		if err == nil {
			return n
		}
		if err.Error() == "EOF" {
			return 0
		}
	}
}

func Fill(a []int, v int) {
	for i := range a {
		a[i] = v
	}
}

func FillB(a []bool, v bool) {
	for i := range a {
		a[i] = v
	}
}

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

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

var (
	dx [4]int = [4]int{-1, 0, 1, 0}
	dy [4]int = [4]int{0, 1, 0, -1}
)

const (
	mod = 1000000007
)

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

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

var (
	adj   [][]int
	par   []int
	depth []int
	vis   []bool
)

func solve() {
	n, m := nextInt(), nextInt()
	adj = make([][]int, n)
	for i := 0; i < m; i++ {
		u, v := nextInt()-1, nextInt()-1
		adj[u] = append(adj[u], v)
		adj[v] = append(adj[v], u)
	}
	par = make([]int, n)
	depth = make([]int, n)
	vis = make([]bool, n)
	par[0] = -1
	depth[0] = 1
	dfs(0)
	for i, v := range depth {
		if v >= (n+1)/2 {
			printf("PATH\n%d\n", v)
			for i != 0 {
				printf("%d ", i+1)
				i = par[i]
			}
			printf("1\n")
			return
		}
	}
	printf("PAIRING\n")
	res := [][2]int{}
	prev := make([]int, n+1)
	Fill(prev, -1)
	for i, v := range depth {
		if prev[v] == -1 {
			prev[v] = i
		} else {
			res = append(res, [2]int{i, prev[v]})
			prev[v] = -1
		}
	}
	printf("%d\n", len(res))
	for _, v := range res {
		printf("%d %d\n", v[0]+1, v[1]+1)
	}
}

func dfs(i int) {
	vis[i] = true
	for _, e := range adj[i] {
		if !vis[e] {
			par[e] = i
			depth[e] = depth[i] + 1
			dfs(e)
		}
	}
}

func main() {
	in = bufio.NewReaderSize(os.Stdin, 8192)
	out = bufio.NewWriterSize(os.Stdout, 8192)
	if false {
		name := "in"
		file1, err := os.Open(name + ".in")
		if err != nil {
			log.Fatal(err)
		}
		// file2, err := os.Create(name + ".out")
		// if err != nil {
		// 	log.Fatal(err)
		// }
		in = bufio.NewReaderSize(file1, 8192)
		// out = bufio.NewWriterSize(file2, 8192)
	}
	defer out.Flush()

	for t := nextInt(); t > 0; t-- {
		solve()
	}
}


package main

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

// github.com/EndlessCheng/codeforces-go
func CF877B(in io.Reader, out io.Writer) {
	var s []byte
	Fscan(bufio.NewReader(in), &s)
	n := len(s)
	sum := make([]int, n+1)
	for i, b := range s {
		sum[i+1] = sum[i]
		if b == 'a' {
			sum[i+1]++
		}
	}
	ans := sum[n]
	for i, b := range s {
		if b != 'b' {
			continue
		}
		for j := i; j < n; j++ {
			if s[j] != 'b' {
				continue
			}
			if s := sum[n] + j + 1 - i - 2*(sum[j+1]-sum[i]); s > ans {
				ans = s
			}
		}
	}
	Fprint(out, ans)
}

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

package main

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

func main() {
	do()
}

func do() {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	s.Scan()
	xs := s.Text()
	n := len(xs)

	sumA := prefixSums(xs, n, 'a')
	sumB := prefixSums(xs, n, 'b')

	maxLen := -1
	for i := 0; i <= n-1; i++ {
		for j := i; j <= n; j++ {
			t := max(0, i, sumA) + max(i, j, sumB) + max(j, n, sumA)
			if t > maxLen {
				maxLen = t
			}
		}
	}
	fmt.Println(maxLen)
}

func prefixSums(xs string, n int, x byte) []int {
	ss := make([]int, n+1)
	c := 0
	for i := 0; i < n; i++ {
		if xs[i] == x {
			c++
		}
		ss[i+1] = c
	}
	return ss
}

func max(i, j int, sum []int) int {
	return sum[j] - sum[i]
}

// Try Codeforces
// author: Leonardone @ NEETSDKASU
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)
	size := len(s)
	acnt := make([]int, size+2)
	bcnt := make([]int, size+2)
	for i, c := range s {
		if c == 'a' {
			acnt[i+1] = acnt[i] + 1
			bcnt[i+1] = bcnt[i]
		} else {
			acnt[i+1] = acnt[i]
			bcnt[i+1] = bcnt[i] + 1
		}
	}
	ans := 0
	for i := 0; i <= size; i++ {
		for j := i; j <= size; j++ {
			a1 := acnt[i] - acnt[0]
			b1 := bcnt[j] - bcnt[i]
			a2 := acnt[size] - acnt[j]
			c := a1 + b1 + a2
			if c > ans {
				ans = c
			}
		}
	}
	fmt.Println(ans)
}

package main

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

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

func main() {
    //io
    scanner := bufio.NewReader(os.Stdin)
    writer := bufio.NewWriter(os.Stdout)
    //---
    var s string
    fmt.Fscan(scanner, &s)
    frst := strings.Index(s, "b")
    scnd := strings.LastIndex(s, "b")

    if(frst == -1) {
        writer.WriteString(strconv.Itoa(len(s)))
        writer.Flush()
        os.Exit(0)
    }

    t := s[frst:scnd+1]
    ans := -1
    n := len(t)
    a, b := make([]int, n+1), make([]int, n+1)

    for i := 0; i < n; i++ {
        a[i+1], b[i+1] = a[i], b[i]
        if(t[i] == 'a') {
            a[i+1]++
        } else {
            b[i+1]++
        }
    }

    for i := 0; i <= n; i++ {
        for j := i; j <= n; j++ {
            x := a[i]
            y := b[j] - b[i]
            z := a[n] - a[j]
            ans = max(ans, x + y + z)
        }
    }

    writer.WriteString(strconv.Itoa(ans + len(s) - len(t)))
    writer.Flush()
}

package main

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

func main() {
    //io
    scanner := bufio.NewReader(os.Stdin)
    writer := bufio.NewWriter(os.Stdout)
    //---
    var s string
    fmt.Fscan(scanner, &s)
    frst := strings.Index(s, "b")
    scnd := strings.LastIndex(s, "b")
    if(frst == -1) {
        writer.WriteString(strconv.Itoa(len(s)))
        writer.Flush()
        os.Exit(0)
    }
    //x := s[:frst]
    y := s[frst:scnd+1]
    //z := s[scnd+1:]
    ans := strings.Count(y, "a")
    ans2 := strings.Count(y, "b")
    if(ans < ans2) {
        writer.WriteString(strconv.Itoa(len(s) - ans))
    } else {
        writer.WriteString(strconv.Itoa(len(s) - ans2))
    }

    writer.Flush()
}

package main

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

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

func main() {
    //io
    scanner := bufio.NewReader(os.Stdin)
    writer := bufio.NewWriter(os.Stdout)
    //---
    var s string
    fmt.Fscan(scanner, &s)
    t := s
    _ = t
    frst := strings.Index(s, "b")
    scnd := strings.LastIndex(s, "b")

    if(frst == -1) {
        writer.WriteString(strconv.Itoa(len(s)))
        writer.Flush()
        os.Exit(0)
    }
    cnt := 0
    sz := len(s)
    ans := 9999999
    for frst != -1 {
        y := ""
        if len(s) > len(t) {
            y = t[frst:scnd+1]
        } else {
            y = s[frst:scnd+1]
        }
        ans = min(ans, min(strings.Count(y, "a"), strings.Count(y, "b")) + cnt)
        s = s[frst+1:scnd+1]
        t = t[frst:scnd]
        frst = strings.Index(s, "b")
        scnd = strings.LastIndex(s, "b")
        cnt++
    }

    writer.WriteString(strconv.Itoa(sz - ans))
    writer.Flush()
}

package main

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

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

func main() {
    //io
    scanner := bufio.NewReader(os.Stdin)
    writer := bufio.NewWriter(os.Stdout)
    //---
    var s string
    fmt.Fscan(scanner, &s)
    t := s
    _ = t
    frst := strings.Index(s, "b")
    scnd := strings.LastIndex(s, "b")

    if(frst == -1) {
        writer.WriteString(strconv.Itoa(len(s)))
        writer.Flush()
        os.Exit(0)
    }
    cnt := 0
    sz := len(s)
    ans := 9999999
    for frst != -1 {
        y := s[frst:scnd+1]
        ans = min(ans, min(strings.Count(y, "a"), strings.Count(y, "b")) + cnt)
        s = s[frst+1:scnd+1]
        frst = strings.Index(s, "b")
        scnd = strings.LastIndex(s, "b")
        cnt++
    }

    writer.WriteString(strconv.Itoa(sz - ans))
    writer.Flush()
}

package main

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

func main() {
	do()
}

func do() {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	s.Scan()
	xs := s.Text()
	n := len(xs)

	sumA := prefixSums(xs, n, 'a')
	sumB := prefixSums(xs, n, 'b')

	maxLen := -1
	for i := 0; i < n-1; i++ {
		for j := i; j <= n; j++ {
			t := max(0, i, sumA) + max(i, j, sumB) + max(j, n, sumA)
			if t > maxLen {
				maxLen = t
			}
		}
	}
	fmt.Println(maxLen)
}

func prefixSums(xs string, n int, x byte) []int {
	ss := make([]int, n+1)
	c := 0
	for i := 0; i < n; i++ {
		if xs[i] == x {
			c++
		}
		ss[i+1] = c
	}
	return ss
}

func max(i, j int, sum []int) int {
	return sum[j] - sum[i]
}

package main

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

func main() {
	do()
}

func do() {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	s.Scan()
	xs := s.Text()
	n := len(xs)

	maxLen := -1
	for i := 0; i < n-1; i++ {
		for j := i + 1; j <= n; j++ {
			if isBeautiful(xs[i:j]) && j-i > maxLen {
				maxLen = j - i
			}
		}
	}
	fmt.Println(maxLen)
}

func isBeautiful(xs string) bool {
	state := 0
	for i := 0; i < len(xs); i++ {
		switch {
		case state == 0 && xs[i] == 'a':
		case state == 0 && xs[i] == 'b':
			state = 1
		case state == 1 && xs[i] == 'a':
			state = 2
		case state == 1 && xs[i] == 'b':
		case state == 2 && xs[i] == 'a':
		case state == 2 && xs[i] == 'b':
			return false
		}
	}
	return state == 2
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF877B(in io.Reader, out io.Writer) {
	var s string
	Fscan(bufio.NewReader(in), &s)
	a := []int{}
	if s[0] == 'b' {
		a = append(a, 0)
	}
	for i, n := 0, len(s); i < n; {
		st := i
		for ; i < n && s[i] == s[st]; i++ {
		}
		a = append(a, i-st)
	}
	a = append(a, 0)
	ans := 0
	for i := 1; i < len(a); i += 2 {
		s := a[i-1] + a[i]
		if i+1 < len(a) {
			s += a[i+1]
		}
		if s > ans {
			ans = s
		}
	}
	Fprint(out, ans)
}

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


package main

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

// github.com/EndlessCheng/codeforces-go
func CF962F(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}
	type edge struct{ v, w, eid int }
	type nei struct{ to, eid int }

	var n, m, v, w int
	Fscan(in, &n, &m)
	g := make([][]nei, n)
	for i := 1; i <= m; i++ {
		Fscan(in, &v, &w)
		v--
		w--
		g[v] = append(g[v], nei{w, i})
		g[w] = append(g[w], nei{v, i})
	}

	ok := make([]bool, m+1)
	bccIDs := make([]int, n)
	idCnt := 0
	dfn := make([]int, n)
	dfsClock := 0
	stack := []edge{}
	var f func(v, fa int) int
	f = func(v, fa int) int {
		dfsClock++
		dfn[v] = dfsClock
		lowV := dfsClock
		for _, ne := range g[v] {
			w := ne.to
			e := edge{v, w, ne.eid}
			if dfn[w] == 0 {
				stack = append(stack, e)
				lowW := f(w, v)
				if lowW >= dfn[v] {
					idCnt++
					comp := []int{}
					eids := []int{}
					for {
						e, stack = stack[len(stack)-1], stack[:len(stack)-1]
						if bccIDs[e.v] != idCnt {
							bccIDs[e.v] = idCnt
							comp = append(comp, e.v)
						}
						if bccIDs[e.w] != idCnt {
							bccIDs[e.w] = idCnt
							comp = append(comp, e.w)
						}
						eids = append(eids, e.eid)
						if e.v == v && e.w == w {
							break
						}
					}
					if len(comp) == len(eids) {
						for _, eid := range eids {
							ok[eid] = true
						}
					}
				}
				lowV = min(lowV, lowW)
			} else if w != fa && dfn[w] < dfn[v] {
				stack = append(stack, e)
				lowV = min(lowV, dfn[w])
			}
		}
		return lowV
	}
	for v, ts := range dfn {
		if ts == 0 && len(g[v]) > 0 {
			f(v, -1)
		}
	}

	ans := []interface{}{}
	for i, b := range ok {
		if b {
			ans = append(ans, i)
		}
	}
	Fprintln(out, len(ans))
	Fprint(out, ans...)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF962F(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}
	type edge struct{ v, w, eid int }
	type nei struct{ to, eid int }

	var n, m, v, w int
	Fscan(in, &n, &m)
	g := make([][]nei, n)
	for i := 1; i <= m; i++ {
		Fscan(in, &v, &w)
		v--
		w--
		g[v] = append(g[v], nei{w, i})
		g[w] = append(g[w], nei{v, i})
	}

	comps := [][2][]int{}
	bccIDs := make([]int, n)
	idCnt := 0
	isCut := make([]bool, n)

	dfn := make([]int, n)
	dfsClock := 0
	stack := []edge{}
	var f func(v, fa int) int
	f = func(v, fa int) int {
		dfsClock++
		dfn[v] = dfsClock
		lowV := dfsClock
		childCnt := 0
		for _, ne := range g[v] {
			w := ne.to
			e := edge{v, w, ne.eid}
			if dfn[w] == 0 {
				stack = append(stack, e)
				childCnt++
				lowW := f(w, v)
				if lowW >= dfn[v] {
					isCut[v] = true
					idCnt++
					comp := []int{}
					eids := []int{}
					for {
						e, stack = stack[len(stack)-1], stack[:len(stack)-1]
						if bccIDs[e.v] != idCnt {
							bccIDs[e.v] = idCnt
							comp = append(comp, e.v)
						}
						if bccIDs[e.w] != idCnt {
							bccIDs[e.w] = idCnt
							comp = append(comp, e.w)
						}
						eids = append(eids, e.eid)
						if e.v == v && e.w == w {
							break
						}
					}
					comps = append(comps, [2][]int{comp, eids})
				}
				lowV = min(lowV, lowW)
			} else if w != fa && dfn[w] < dfn[v] {
				stack = append(stack, e)
				lowV = min(lowV, dfn[w])
			}
		}
		if fa == -1 && childCnt == 1 {
			isCut[v] = false
		}
		return lowV
	}
	for v, timestamp := range dfn {
		if timestamp == 0 && len(g[v]) > 0 {
			f(v, -1)
		}
	}

	ok := make([]bool, m+1)
	for _, p := range comps {
		if eids := p[1]; len(eids) == len(p[0]) {
			for _, eid := range eids {
				ok[eid] = true
			}
		}
	}
	ans := []interface{}{}
	for i, b := range ok {
		if b {
			ans = append(ans, i)
		}
	}
	Fprintln(out, len(ans))
	Fprint(out, ans...)
}

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

package main

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

const (
	HOUSTON = false
)

type caseInput struct {
	n, m uint32
	ac   *EdgeList
}

func readCaseInput(scanner *bufio.Scanner) caseInput {
	n := uint32(readInt(scanner))
	m := uint32(readInt(scanner))

	el := EdgeListNew(n + 1)
	for label := uint32(1); label <= m; label++ {
		source := uint32(readInt(scanner))
		target := uint32(readInt(scanner))
		el.AddEdge(source, target, label)
	}

	return caseInput{n, m, el}
}

type caseOutput struct {
	simpleCycleLabels []uint32
}

func writeCaseOutput(writer *bufio.Writer, out caseOutput) {
	writef(writer, "%d\n", len(out.simpleCycleLabels))
	for _, l := range out.simpleCycleLabels {
		writef(writer, "%d ", l)
	}
}

//noinspection GoBoolExpressions
func solveCase(in caseInput) caseOutput {
	cycleLabelUF := UnionFindNew(in.m + 1) //	which cycles intersect

	dfsLevels := make([]uint32, in.n+1)
	cycleTops := make([]uint32, in.m+1)
	dfsEdges := make([]*Edge, in.n+1)

	vertexQ := make([]*Edge, 0, in.n)
	cycleEdges := make([]*Edge, 0, in.m)
	dfsStart := uint32(1)
	for dfsStart <= in.n {
		if dfsEdges[dfsStart] != nil {
			dfsStart += 1
			continue
		}

		vertexQ = append(vertexQ[:0], &Edge{0, dfsStart, 0, 0, nil})
		cycleEdges = cycleEdges[:0]
		dfsLevels[dfsStart] = 1

		for len(vertexQ) > 0 {
			edgeToSource := vertexQ[len(vertexQ)-1]
			source := edgeToSource.Target
			sourceLevel := dfsLevels[source]
			vertexQ = vertexQ[:len(vertexQ)-1]

			if HOUSTON {
				fmt.Printf("edgesFor %d (%d)\n", source, len(in.ac.EdgesFor(source)))
			}
			for _, e := range in.ac.EdgesFor(source) {

				if e.Target == edgeToSource.Source {
					if HOUSTON {
						fmt.Printf("\tBACKSTOP\t%d -> %d\t%d\t%d\n", e.Source, e.Target, e.Label, e.CycleLabel)
					}
					continue // same link we used for DFS, but seen from the other side
				}

				if dfsLevels[e.Target] == 0 {
					if HOUSTON {
						fmt.Printf("\tPROPAGATE\t%d -> %d\t%d\t%d\n", e.Source, e.Target, e.Label, e.CycleLabel)
					}
					//	add all new vertexes to spanning tree
					vertexQ = append(vertexQ, e)
					dfsEdges[e.Target] = e
					dfsLevels[e.Target] = sourceLevel + 1
				} else {
					if e.Source < e.Target {
						if HOUSTON {
							fmt.Printf("\tCYCLE\t%d -> %d\t%d\t%d\n", e.Source, e.Target, e.Label, e.CycleLabel)
						}
						//	this edge forms a cycle
						cycleEdges = append(cycleEdges, e)
					} else {
						//	do nothing, we'll see this edge from the other side
						if HOUSTON {
							fmt.Printf("\tCYCLE DUPE\t%d -> %d\t%d\t%d\n", e.Source, e.Target, e.Label, e.CycleLabel)
						}
					}
				}
			}
		}

		if HOUSTON {
			fmt.Printf("dfsLevels = %v\n", dfsLevels)
			fmt.Printf("cycleEdges (%d)\n", len(cycleEdges))
			for _, e := range cycleEdges {
				fmt.Printf("%d -> %d\t%d\t%d\n", e.Source, e.Target, e.Label, e.CycleLabel)
			}
			fmt.Printf("dfsEdges\n")
			for i, e := range dfsEdges {
				if e != nil {
					fmt.Printf("\t%d %d -> %d\t%d\t%d\n", i, e.Source, e.Target, e.Label, e.CycleLabel)
				} else {
					fmt.Printf("\t%d NIL\n", i)
				}
			}
		}

		for _, ce := range cycleEdges {
			cycleLabel := ce.Label
			ce.CycleLabel = cycleLabel
			ce.Reverse.CycleLabel = cycleLabel
			s := ce.Source
			t := ce.Target
			if HOUSTON {
				fmt.Printf(
					"cycleEdge\t%d -> %d\t%d\t%d\n",
					ce.Source, ce.Target, ce.Label, ce.CycleLabel,
				)
			}

			for s != t {
				if dfsLevels[s] >= dfsLevels[t] {
					if HOUSTON {
						fmt.Printf(
							"\tdfsEdges[s=%d at level %d]\t%d -> %d\t%d\t%d\n",
							s, dfsLevels[s], dfsEdges[s].Source, dfsEdges[s].Target, dfsEdges[s].Label, dfsEdges[s].CycleLabel,
						)
					}
					if dfsEdges[s].CycleLabel == cycleLabel {
						panic(fmt.Sprintf("seen same cycle with label %d", cycleLabel))
					} else if dfsEdges[s].CycleLabel > 0 {
						if HOUSTON {
							fmt.Printf("\t\tUNION %d with %d\n", cycleLabel, dfsEdges[s].CycleLabel)
							fmt.Printf("\t\ts <== %d\n", cycleTops[dfsEdges[s].CycleLabel])
						}
						cycleLabelUF.Union(dfsEdges[s].CycleLabel, cycleLabel)
						s = cycleTops[dfsEdges[s].CycleLabel]
					} else {
						if HOUSTON {
							fmt.Printf("\t\tLABEL with %d\n", cycleLabel)
							fmt.Printf("\t\ts <== %d\n", dfsEdges[s].Source)
						}
						dfsEdges[s].CycleLabel = cycleLabel
						dfsEdges[s].Reverse.CycleLabel = cycleLabel
						s = dfsEdges[s].Source
					}
				} else {
					if HOUSTON {
						fmt.Printf(
							"\tdfsEdges[t=%d at level %d]\t%d -> %d\t%d\t%d\n",
							t, dfsLevels[t], dfsEdges[t].Source, dfsEdges[t].Target, dfsEdges[t].Label, dfsEdges[t].CycleLabel,
						)
					}
					if dfsEdges[t].CycleLabel == cycleLabel {
						panic(fmt.Sprintf("seen same cycle with label %d", cycleLabel))
					} else if dfsEdges[t].CycleLabel > 0 {
						if HOUSTON {
							fmt.Printf("\t\tUNION %d with %d\n", cycleLabel, dfsEdges[t].CycleLabel)
							fmt.Printf("\t\tt = %d\n", cycleTops[dfsEdges[t].CycleLabel])
						}
						cycleLabelUF.Union(dfsEdges[t].CycleLabel, cycleLabel)
						t = cycleTops[dfsEdges[t].CycleLabel]
					} else {
						if HOUSTON {
							fmt.Printf("\t\tLABEL with %d\n", cycleLabel)
							fmt.Printf("\t\tt = %d\n", dfsEdges[t].Source)
						}
						dfsEdges[t].CycleLabel = cycleLabel
						dfsEdges[t].Reverse.CycleLabel = cycleLabel
						t = dfsEdges[t].Source
					}
				}
			}
			cycleTops[cycleLabel] = s
		}

		dfsStart += 1
	}

	simpleCycleLabels := make([]uint32, 0, in.m)

	if HOUSTON {
		fmt.Printf("Final edge filter\n")
	}
	for _, e := range in.ac.Added {
		if HOUSTON {
			fmt.Printf(
				"\t%d -> %d\t%d\t%d\n",
				e.Source, e.Target, e.Label, e.CycleLabel,
			)
		}

		if e.CycleLabel > 0 {
			ufSize := cycleLabelUF.Size(e.CycleLabel)
			if HOUSTON {
				fmt.Printf(
					"\t\tnumber of intersecting cycles: %d\n",
					ufSize,
				)
			}
			if ufSize == 1 {
				simpleCycleLabels = append(simpleCycleLabels, e.Label)
			}
		}
	}

	// sort.Sort(Uint32Sort(simpleCycleLabels))

	return caseOutput{simpleCycleLabels}
}

//type Uint32Sort []uint32
//
//func (s Uint32Sort) Len() int           { return len(s) }
//func (s Uint32Sort) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
//func (s Uint32Sort) Less(i, j int) bool { return s[i] < s[j] }

func main() {
	var scanner *bufio.Scanner
	if len(os.Args) > 1 {
		reader, err := os.Open(os.Args[1])
		if err != nil {
			panic(err)
		}
		defer reader.Close()
		scanner = bufio.NewScanner(reader)
	} else {
		scanner = bufio.NewScanner(os.Stdin)
	}
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 0, 1024*1024), 1024*1024)

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

	writeCaseOutput(writer, solveCase(readCaseInput(scanner)))
}

func readInt64(sc *bufio.Scanner) int64 {
	if !sc.Scan() {
		panic("failed to scan next token")
	}

	res, err := strconv.ParseInt(sc.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}

func readInt(sc *bufio.Scanner) int {
	return int(readInt64(sc))
}

func writef(writer *bufio.Writer, formatStr string, values ...interface{}) {
	out := fmt.Sprintf(formatStr, values...)
	_, err := writer.WriteString(out)
	if err != nil {
		panic(err)
	}
}

type Edge struct {
	Source, Target uint32
	Label          uint32
	CycleLabel     uint32
	Reverse        *Edge
}

type EdgeList struct {
	Added []*Edge
	Edges [][]*Edge
}

func EdgeListNew(
	numNodes uint32,
) *EdgeList {
	edges := make([][]*Edge, numNodes+1, numNodes+1)
	added := make([]*Edge, 0, numNodes+1)
	for i := range edges {
		edges[i] = make([]*Edge, 0, 32)
	}
	return &EdgeList{
		added,
		edges,
	}
}

func (el *EdgeList) AddEdge(source, target uint32, label uint32) {
	added := &Edge{source, target, label, 0, nil}
	reverse := &Edge{target, source, label, 0, nil}

	added.Reverse = reverse
	reverse.Reverse = added

	el.Added = append(el.Added, added)
	el.Edges[source] = append(el.Edges[source], added)
	el.Edges[target] = append(el.Edges[target], reverse)
}

func (el *EdgeList) EdgesFor(source uint32) []*Edge {
	return el.Edges[source]
}

type UnionFind struct {
	parent []uint32
	size   []uint32
	count  uint32
}

func UnionFindNew(count uint32) *UnionFind {
	parent := make([]uint32, count, count)
	size := make([]uint32, count, count)
	lim := uint32(count)
	for i := uint32(0); i < lim; i++ {
		parent[i], size[i] = i, 1
	}
	return &UnionFind{parent, size, lim}
}

func (ufp *UnionFind) Reset() {
	lim := uint32(len(ufp.parent))
	for i := uint32(0); i < lim; i++ {
		ufp.parent[i], ufp.size[i] = i, 1
	}
	ufp.count = lim
}

func (ufp *UnionFind) validate(p uint32) {
	n := uint32(len(ufp.parent))
	if p >= n {
		panic(fmt.Sprintf("index %d is not between 0 and %d", p, n-1))
	}
}

func (ufp *UnionFind) Count() uint32 {
	return ufp.count
}

func (ufp *UnionFind) Find(p uint32) uint32 {
	ufp.validate(p)

	root := p
	for root != ufp.parent[root] {
		root = ufp.parent[root]
	}
	for p != root {
		newp := ufp.parent[p]
		ufp.parent[p] = root
		p = newp
	}

	return root
}

func (ufp *UnionFind) Size(p uint32) uint32 {
	return ufp.size[ufp.Find(p)]
}

func (ufp *UnionFind) Connected(p, q uint32) bool {
	return ufp.Find(p) == ufp.Find(q)
}

func (ufp *UnionFind) Union(p, q uint32) {
	rootP := ufp.Find(p)
	rootQ := ufp.Find(q)

	if rootP == rootQ {
		return
	}

	if ufp.size[rootP] < ufp.size[rootQ] {
		ufp.parent[rootP] = rootQ
		ufp.size[rootQ] += ufp.size[rootP]
	} else {
		ufp.parent[rootQ] = rootP
		ufp.size[rootP] += ufp.size[rootQ]
	}

	ufp.count -= 1
}

package main

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

const (
	HOUSTON = false
)

type caseInput struct {
	n, m uint32
	ac   *EdgeList
}

func readCaseInput(scanner *bufio.Scanner) caseInput {
	n := uint32(readInt(scanner))
	m := uint32(readInt(scanner))

	el := EdgeListNew(n + 1)
	for label := uint32(1); label <= m; label++ {
		source := uint32(readInt(scanner))
		target := uint32(readInt(scanner))
		el.AddEdge(source, target, label)
	}

	return caseInput{n, m, el}
}

type caseOutput struct {
	simpleCycleLabels []uint32
}

func writeCaseOutput(writer *bufio.Writer, out caseOutput) {
	writef(writer, "%d\n", len(out.simpleCycleLabels))
	for _, l := range out.simpleCycleLabels {
		writef(writer, "%d ", l)
	}
}

//noinspection GoBoolExpressions
func solveCase(in caseInput) caseOutput {
	cycleLabelUF := UnionFindNew(in.m + 1) //	which cycles intersect

	dfsLevels := make([]uint32, in.n+1)
	dfsEdges := make([]*Edge, in.n+1)

	vertexQ := make([]*Edge, 0, in.n)
	cycleEdges := make([]*Edge, 0, in.m)
	dfsStart := uint32(1)
	for dfsStart <= in.n {
		if dfsEdges[dfsStart] != nil {
			dfsStart += 1
			continue
		}

		vertexQ = append(vertexQ[:0], &Edge{0, dfsStart, 0, 0, nil})
		cycleEdges = cycleEdges[:0]
		dfsLevels[dfsStart] = 1

		for len(vertexQ) > 0 {
			edgeToSource := vertexQ[len(vertexQ)-1]
			source := edgeToSource.Target
			sourceLevel := dfsLevels[source]
			vertexQ = vertexQ[:len(vertexQ)-1]

			if HOUSTON {
				fmt.Printf("edgesFor %d (%d)\n", source, len(in.ac.EdgesFor(source)))
			}
			for _, e := range in.ac.EdgesFor(source) {

				if e.Target == edgeToSource.Source {
					if HOUSTON {
						fmt.Printf("\tBACKSTOP\t%d -> %d\t%d\t%d\n", e.Source, e.Target, e.Label, e.CycleLabel)
					}
					continue // same link we used for DFS, but seen from the other side
				}

				if dfsLevels[e.Target] == 0 {
					if HOUSTON {
						fmt.Printf("\tPROPAGATE\t%d -> %d\t%d\t%d\n", e.Source, e.Target, e.Label, e.CycleLabel)
					}
					//	add all new vertexes to spanning tree
					vertexQ = append(vertexQ, e)
					dfsEdges[e.Target] = e
					dfsLevels[e.Target] = sourceLevel + 1
				} else {
					if e.Source < e.Target {
						if HOUSTON {
							fmt.Printf("\tCYCLE\t%d -> %d\t%d\t%d\n", e.Source, e.Target, e.Label, e.CycleLabel)
						}
						//	this edge forms a cycle
						cycleEdges = append(cycleEdges, e)
					} else {
						//	do nothing, we'll see this edge from the other side
						if HOUSTON {
							fmt.Printf("\tCYCLE DUPE\t%d -> %d\t%d\t%d\n", e.Source, e.Target, e.Label, e.CycleLabel)
						}
					}
				}
			}
		}

		if HOUSTON {
			fmt.Printf("dfsLevels = %v\n", dfsLevels)
			fmt.Printf("cycleEdges (%d)\n", len(cycleEdges))
			for _, e := range cycleEdges {
				fmt.Printf("%d -> %d\t%d\t%d\n", e.Source, e.Target, e.Label, e.CycleLabel)
			}
			fmt.Printf("dfsEdges\n")
			for i, e := range dfsEdges {
				if e != nil {
					fmt.Printf("\t%d %d -> %d\t%d\t%d\n", i, e.Source, e.Target, e.Label, e.CycleLabel)
				} else {
					fmt.Printf("\t%d NIL\n", i)
				}
			}
		}

		for _, ce := range cycleEdges {
			cycleLabel := ce.Label
			ce.CycleLabel = cycleLabel
			ce.Reverse.CycleLabel = cycleLabel
			s := ce.Source
			t := ce.Target
			if HOUSTON {
				fmt.Printf(
					"cycleEdge\t%d -> %d\t%d\t%d\n",
					ce.Source, ce.Target, ce.Label, ce.CycleLabel,
				)
			}

			sPathUnique := true
			tPathUnique := true
			for s != t && (sPathUnique || tPathUnique) {
				if dfsLevels[s] >= dfsLevels[t] {
					if HOUSTON {
						fmt.Printf(
							"\tdfsEdges[s=%d at level %d]\t%d -> %d\t%d\t%d\n",
							s, dfsLevels[s], dfsEdges[s].Source, dfsEdges[s].Target, dfsEdges[s].Label, dfsEdges[s].CycleLabel,
						)
					}
					if dfsEdges[s].CycleLabel > 0 {
						if HOUSTON {
							fmt.Printf("\t\tUNION %d with %d\n", cycleLabel, dfsEdges[s].CycleLabel)
						}
						cycleLabelUF.Union(dfsEdges[s].CycleLabel, cycleLabel)
						sPathUnique = false;
					} else {
						if HOUSTON {
							fmt.Printf("\t\tLABEL with %d\n", cycleLabel)
						}
						dfsEdges[s].CycleLabel = cycleLabel
						dfsEdges[s].Reverse.CycleLabel = cycleLabel
					}
					if HOUSTON {
						fmt.Printf("\t\ts <== %d\n", dfsEdges[s].Source)
					}
					s = dfsEdges[s].Source
				} else {
					if HOUSTON {
						fmt.Printf(
							"\tdfsEdges[t=%d at level %d]\t%d -> %d\t%d\t%d\n",
							t, dfsLevels[t], dfsEdges[t].Source, dfsEdges[t].Target, dfsEdges[t].Label, dfsEdges[t].CycleLabel,
						)
					}
					if dfsEdges[t].CycleLabel > 0 {
						if HOUSTON {
							fmt.Printf("\t\tUNION %d with %d\n", cycleLabel, dfsEdges[t].CycleLabel)
						}
						cycleLabelUF.Union(dfsEdges[t].CycleLabel, cycleLabel)
						tPathUnique = false
					} else {
						if HOUSTON {
							fmt.Printf("\t\tLABEL with %d\n", cycleLabel)
						}
						dfsEdges[t].CycleLabel = cycleLabel
						dfsEdges[t].Reverse.CycleLabel = cycleLabel
					}
					if HOUSTON {
						fmt.Printf("\t\tt = %d\n", dfsEdges[t].Source)
					}
					t = dfsEdges[t].Source
				}
			}
		}

		dfsStart += 1
	}

	simpleCycleLabels := make([]uint32, 0, in.m)

	if HOUSTON {
		fmt.Printf("Final edge filter\n")
	}
	for _, e := range in.ac.Added {
		if HOUSTON {
			fmt.Printf(
				"\t%d -> %d\t%d\t%d\n",
				e.Source, e.Target, e.Label, e.CycleLabel,
			)
		}

		if e.CycleLabel > 0 {
			ufSize := cycleLabelUF.Size(e.CycleLabel)
			if HOUSTON {
				fmt.Printf(
					"\t\tnumber of intersecting cycles: %d\n",
					ufSize,
				)
			}
			if ufSize == 1 {
				simpleCycleLabels = append(simpleCycleLabels, e.Label)
			}
		}
	}

	// sort.Sort(Uint32Sort(simpleCycleLabels))

	return caseOutput{simpleCycleLabels}
}

//type Uint32Sort []uint32
//
//func (s Uint32Sort) Len() int           { return len(s) }
//func (s Uint32Sort) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
//func (s Uint32Sort) Less(i, j int) bool { return s[i] < s[j] }

func main() {
	var scanner *bufio.Scanner
	if len(os.Args) > 1 {
		reader, err := os.Open(os.Args[1])
		if err != nil {
			panic(err)
		}
		defer reader.Close()
		scanner = bufio.NewScanner(reader)
	} else {
		scanner = bufio.NewScanner(os.Stdin)
	}
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 0, 1024*1024), 1024*1024)

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

	writeCaseOutput(writer, solveCase(readCaseInput(scanner)))
}

func readInt64(sc *bufio.Scanner) int64 {
	if !sc.Scan() {
		panic("failed to scan next token")
	}

	res, err := strconv.ParseInt(sc.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}

func readInt(sc *bufio.Scanner) int {
	return int(readInt64(sc))
}

func writef(writer *bufio.Writer, formatStr string, values ...interface{}) {
	out := fmt.Sprintf(formatStr, values...)
	_, err := writer.WriteString(out)
	if err != nil {
		panic(err)
	}
}

type Edge struct {
	Source, Target uint32
	Label          uint32
	CycleLabel     uint32
	Reverse        *Edge
}

type EdgeList struct {
	Added []*Edge
	Edges [][]*Edge
}

func EdgeListNew(
	numNodes uint32,
) *EdgeList {
	edges := make([][]*Edge, numNodes+1, numNodes+1)
	added := make([]*Edge, 0, numNodes+1)
	for i := range edges {
		edges[i] = make([]*Edge, 0, 32)
	}
	return &EdgeList{
		added,
		edges,
	}
}

func (el *EdgeList) AddEdge(source, target uint32, label uint32) {
	added := &Edge{source, target, label, 0, nil}
	reverse := &Edge{target, source, label, 0, nil}

	added.Reverse = reverse
	reverse.Reverse = added

	el.Added = append(el.Added, added)
	el.Edges[source] = append(el.Edges[source], added)
	el.Edges[target] = append(el.Edges[target], reverse)
}

func (el *EdgeList) EdgesFor(source uint32) []*Edge {
	return el.Edges[source]
}

type UnionFind struct {
	parent []uint32
	size   []uint32
	count  uint32
}

func UnionFindNew(count uint32) *UnionFind {
	parent := make([]uint32, count, count)
	size := make([]uint32, count, count)
	lim := uint32(count)
	for i := uint32(0); i < lim; i++ {
		parent[i], size[i] = i, 1
	}
	return &UnionFind{parent, size, lim}
}

func (ufp *UnionFind) Reset() {
	lim := uint32(len(ufp.parent))
	for i := uint32(0); i < lim; i++ {
		ufp.parent[i], ufp.size[i] = i, 1
	}
	ufp.count = lim
}

func (ufp *UnionFind) validate(p uint32) {
	n := uint32(len(ufp.parent))
	if p >= n {
		panic(fmt.Sprintf("index %d is not between 0 and %d", p, n-1))
	}
}

func (ufp *UnionFind) Count() uint32 {
	return ufp.count
}

func (ufp *UnionFind) Find(p uint32) uint32 {
	ufp.validate(p)

	root := p
	for root != ufp.parent[root] {
		root = ufp.parent[root]
	}
	for p != root {
		newp := ufp.parent[p]
		ufp.parent[p] = root
		p = newp
	}

	return root
}

func (ufp *UnionFind) Size(p uint32) uint32 {
	return ufp.size[ufp.Find(p)]
}

func (ufp *UnionFind) Connected(p, q uint32) bool {
	return ufp.Find(p) == ufp.Find(q)
}

func (ufp *UnionFind) Union(p, q uint32) {
	rootP := ufp.Find(p)
	rootQ := ufp.Find(q)

	if rootP == rootQ {
		return
	}

	if ufp.size[rootP] < ufp.size[rootQ] {
		ufp.parent[rootP] = rootQ
		ufp.size[rootQ] += ufp.size[rootP]
	} else {
		ufp.parent[rootQ] = rootP
		ufp.size[rootP] += ufp.size[rootQ]
	}

	ufp.count -= 1
}

package main

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

const (
	HOUSTON = false
)

type caseInput struct {
	n, m uint32
	ac   *EdgeList
}

func readCaseInput(scanner *bufio.Scanner) caseInput {
	n := uint32(readInt(scanner))
	m := uint32(readInt(scanner))

	el := EdgeListNew(n + 1)
	for label := uint32(1); label <= m; label++ {
		source := uint32(readInt(scanner))
		target := uint32(readInt(scanner))
		el.AddEdge(source, target, label)
	}

	return caseInput{n, m, el}
}

type caseOutput struct {
	simpleCycleLabels []uint32
}

func writeCaseOutput(writer *bufio.Writer, out caseOutput) {
	writef(writer, "%d\n", len(out.simpleCycleLabels))
	for _, l := range out.simpleCycleLabels {
		writef(writer, "%d ", l)
	}
}

//noinspection GoBoolExpressions
func solveCase(in caseInput) caseOutput {
	cycleLabelUF := UnionFindNew(in.m + 1) //	which cycles intersect

	dfsLevels := make([]uint32, in.n+1)
	dfsEdges := make([]*Edge, in.n+1)

	vertexQ := make([]*Edge, 0, in.n)
	cycleEdges := make([]*Edge, 0, in.m)
	dfsStart := uint32(1)
	for dfsStart <= in.n {
		if dfsEdges[dfsStart] != nil {
			dfsStart += 1
			continue
		}

		vertexQ = append(vertexQ[:0], &Edge{0, dfsStart, 0, 0, nil})
		cycleEdges = cycleEdges[:0]
		dfsLevels[dfsStart] = 1

		for len(vertexQ) > 0 {
			edgeToSource := vertexQ[len(vertexQ)-1]
			source := edgeToSource.Target
			sourceLevel := dfsLevels[source]
			vertexQ = vertexQ[:len(vertexQ)-1]

			if HOUSTON {
				fmt.Printf("edgesFor %d (%d)\n", source, len(in.ac.EdgesFor(source)))
			}
			for _, e := range in.ac.EdgesFor(source) {

				if e.Target == edgeToSource.Source {
					if HOUSTON {
						fmt.Printf("\tBACKSTOP\t%d -> %d\t%d\t%d\n", e.Source, e.Target, e.Label, e.CycleLabel)
					}
					continue // same link we used for DFS, but seen from the other side
				}

				if dfsLevels[e.Target] == 0 {
					if HOUSTON {
						fmt.Printf("\tPROPAGATE\t%d -> %d\t%d\t%d\n", e.Source, e.Target, e.Label, e.CycleLabel)
					}
					//	add all new vertexes to spanning tree
					vertexQ = append(vertexQ, e)
					dfsEdges[e.Target] = e
					dfsLevels[e.Target] = sourceLevel + 1
				} else {
					if e.Source < e.Target {
						if HOUSTON {
							fmt.Printf("\tCYCLE\t%d -> %d\t%d\t%d\n", e.Source, e.Target, e.Label, e.CycleLabel)
						}
						//	this edge forms a cycle
						cycleEdges = append(cycleEdges, e)
					} else {
						//	do nothing, we'll see this edge from the other side
						if HOUSTON {
							fmt.Printf("\tCYCLE DUPE\t%d -> %d\t%d\t%d\n", e.Source, e.Target, e.Label, e.CycleLabel)
						}
					}
				}
			}
		}

		if HOUSTON {
			fmt.Printf("dfsLevels = %v\n", dfsLevels)
			fmt.Printf("cycleEdges (%d)\n", len(cycleEdges))
			for _, e := range cycleEdges {
				fmt.Printf("%d -> %d\t%d\t%d\n", e.Source, e.Target, e.Label, e.CycleLabel)
			}
			fmt.Printf("dfsEdges\n")
			for i, e := range dfsEdges {
				if e != nil {
					fmt.Printf("\t%d %d -> %d\t%d\t%d\n", i, e.Source, e.Target, e.Label, e.CycleLabel)
				} else {
					fmt.Printf("\t%d NIL\n", i)
				}
			}
		}

		for _, ce := range cycleEdges {
			cycleLabel := ce.Label
			ce.CycleLabel = cycleLabel
			ce.Reverse.CycleLabel = cycleLabel
			s := ce.Source
			t := ce.Target
			if HOUSTON {
				fmt.Printf(
					"cycleEdge\t%d -> %d\t%d\t%d\n",
					ce.Source, ce.Target, ce.Label, ce.CycleLabel,
				)
			}

			for s != t {
				if dfsLevels[s] >= dfsLevels[t] {
					if HOUSTON {
						fmt.Printf(
							"\tdfsEdges[s=%d at level %d]\t%d -> %d\t%d\t%d\n",
							s, dfsLevels[s], dfsEdges[s].Source, dfsEdges[s].Target, dfsEdges[s].Label, dfsEdges[s].CycleLabel,
						)
					}
					if dfsEdges[s].CycleLabel > 0 {
						if HOUSTON {
							fmt.Printf("\t\tUNION %d with %d\n", cycleLabel, dfsEdges[s].CycleLabel)
						}
						cycleLabelUF.Union(dfsEdges[s].CycleLabel, cycleLabel)
						break;
					} else {
						if HOUSTON {
							fmt.Printf("\t\tLABEL with %d\n", cycleLabel)
						}
						dfsEdges[s].CycleLabel = cycleLabel
						dfsEdges[s].Reverse.CycleLabel = cycleLabel
					}
					if HOUSTON {
						fmt.Printf("\t\ts <== %d\n", dfsEdges[s].Source)
					}
					s = dfsEdges[s].Source
				} else {
					if HOUSTON {
						fmt.Printf(
							"\tdfsEdges[t=%d at level %d]\t%d -> %d\t%d\t%d\n",
							t, dfsLevels[t], dfsEdges[t].Source, dfsEdges[t].Target, dfsEdges[t].Label, dfsEdges[t].CycleLabel,
						)
					}
					if dfsEdges[t].CycleLabel > 0 {
						if HOUSTON {
							fmt.Printf("\t\tUNION %d with %d\n", cycleLabel, dfsEdges[t].CycleLabel)
						}
						cycleLabelUF.Union(dfsEdges[t].CycleLabel, cycleLabel)
						break
					} else {
						if HOUSTON {
							fmt.Printf("\t\tLABEL with %d\n", cycleLabel)
						}
						dfsEdges[t].CycleLabel = cycleLabel
						dfsEdges[t].Reverse.CycleLabel = cycleLabel
					}
					if HOUSTON {
						fmt.Printf("\t\tt = %d\n", dfsEdges[t].Source)
					}
					t = dfsEdges[t].Source
				}
			}
		}

		dfsStart += 1
	}

	simpleCycleLabels := make([]uint32, 0, in.m)

	if HOUSTON {
		fmt.Printf("Final edge filter\n")
	}
	for _, e := range in.ac.Added {
		if HOUSTON {
			fmt.Printf(
				"\t%d -> %d\t%d\t%d\n",
				e.Source, e.Target, e.Label, e.CycleLabel,
			)
		}

		if e.CycleLabel > 0 {
			ufSize := cycleLabelUF.Size(e.CycleLabel)
			if HOUSTON {
				fmt.Printf(
					"\t\tnumber of intersecting cycles: %d\n",
					ufSize,
				)
			}
			if ufSize == 1 {
				simpleCycleLabels = append(simpleCycleLabels, e.Label)
			}
		}
	}

	// sort.Sort(Uint32Sort(simpleCycleLabels))

	return caseOutput{simpleCycleLabels}
}

//type Uint32Sort []uint32
//
//func (s Uint32Sort) Len() int           { return len(s) }
//func (s Uint32Sort) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
//func (s Uint32Sort) Less(i, j int) bool { return s[i] < s[j] }

func main() {
	var scanner *bufio.Scanner
	if len(os.Args) > 1 {
		reader, err := os.Open(os.Args[1])
		if err != nil {
			panic(err)
		}
		defer reader.Close()
		scanner = bufio.NewScanner(reader)
	} else {
		scanner = bufio.NewScanner(os.Stdin)
	}
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 0, 1024*1024), 1024*1024)

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

	writeCaseOutput(writer, solveCase(readCaseInput(scanner)))
}

func readInt64(sc *bufio.Scanner) int64 {
	if !sc.Scan() {
		panic("failed to scan next token")
	}

	res, err := strconv.ParseInt(sc.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return res
}

func readInt(sc *bufio.Scanner) int {
	return int(readInt64(sc))
}

func writef(writer *bufio.Writer, formatStr string, values ...interface{}) {
	out := fmt.Sprintf(formatStr, values...)
	_, err := writer.WriteString(out)
	if err != nil {
		panic(err)
	}
}

type Edge struct {
	Source, Target uint32
	Label          uint32
	CycleLabel     uint32
	Reverse        *Edge
}

type EdgeList struct {
	Added []*Edge
	Edges [][]*Edge
}

func EdgeListNew(
	numNodes uint32,
) *EdgeList {
	edges := make([][]*Edge, numNodes+1, numNodes+1)
	added := make([]*Edge, 0, numNodes+1)
	for i := range edges {
		edges[i] = make([]*Edge, 0, 32)
	}
	return &EdgeList{
		added,
		edges,
	}
}

func (el *EdgeList) AddEdge(source, target uint32, label uint32) {
	added := &Edge{source, target, label, 0, nil}
	reverse := &Edge{target, source, label, 0, nil}

	added.Reverse = reverse
	reverse.Reverse = added

	el.Added = append(el.Added, added)
	el.Edges[source] = append(el.Edges[source], added)
	el.Edges[target] = append(el.Edges[target], reverse)
}

func (el *EdgeList) EdgesFor(source uint32) []*Edge {
	return el.Edges[source]
}

type UnionFind struct {
	parent []uint32
	size   []uint32
	count  uint32
}

func UnionFindNew(count uint32) *UnionFind {
	parent := make([]uint32, count, count)
	size := make([]uint32, count, count)
	lim := uint32(count)
	for i := uint32(0); i < lim; i++ {
		parent[i], size[i] = i, 1
	}
	return &UnionFind{parent, size, lim}
}

func (ufp *UnionFind) Reset() {
	lim := uint32(len(ufp.parent))
	for i := uint32(0); i < lim; i++ {
		ufp.parent[i], ufp.size[i] = i, 1
	}
	ufp.count = lim
}

func (ufp *UnionFind) validate(p uint32) {
	n := uint32(len(ufp.parent))
	if p >= n {
		panic(fmt.Sprintf("index %d is not between 0 and %d", p, n-1))
	}
}

func (ufp *UnionFind) Count() uint32 {
	return ufp.count
}

func (ufp *UnionFind) Find(p uint32) uint32 {
	ufp.validate(p)

	root := p
	for root != ufp.parent[root] {
		root = ufp.parent[root]
	}
	for p != root {
		newp := ufp.parent[p]
		ufp.parent[p] = root
		p = newp
	}

	return root
}

func (ufp *UnionFind) Size(p uint32) uint32 {
	return ufp.size[ufp.Find(p)]
}

func (ufp *UnionFind) Connected(p, q uint32) bool {
	return ufp.Find(p) == ufp.Find(q)
}

func (ufp *UnionFind) Union(p, q uint32) {
	rootP := ufp.Find(p)
	rootQ := ufp.Find(q)

	if rootP == rootQ {
		return
	}

	if ufp.size[rootP] < ufp.size[rootQ] {
		ufp.parent[rootP] = rootQ
		ufp.size[rootQ] += ufp.size[rootP]
	} else {
		ufp.parent[rootQ] = rootP
		ufp.size[rootP] += ufp.size[rootQ]
	}

	ufp.count -= 1
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF962F(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}
	type nei struct{ to, eid int }
	type edge struct{ v, w int }

	var n, m, v, w int
	Fscan(in, &n, &m)
	g := make([][]nei, n)
	for i := 1; i <= m; i++ {
		Fscan(in, &v, &w)
		v--
		w--
		g[v] = append(g[v], nei{w, i})
		g[w] = append(g[w], nei{v, i})
	}

	comps := [][]int{}
	bccIDs := make([]int, n)
	idCnt := 0
	isCut := make([]bool, n)

	dfn := make([]int, n)
	dfsClock := 0
	stack := []edge{}
	var f func(v, fa int) int
	f = func(v, fa int) int {
		dfsClock++
		dfn[v] = dfsClock
		lowV := dfsClock
		childCnt := 0
		for _, ne := range g[v] {
			w := ne.to
			e := edge{v, w}
			if dfn[w] == 0 {
				stack = append(stack, e)
				childCnt++
				lowW := f(w, v)
				if lowW >= dfn[v] {
					isCut[v] = true
					idCnt++
					comp := []int{}
					for {
						e, stack = stack[len(stack)-1], stack[:len(stack)-1]
						if bccIDs[e.v] != idCnt {
							bccIDs[e.v] = idCnt
							comp = append(comp, e.v)
						}
						if bccIDs[e.w] != idCnt {
							bccIDs[e.w] = idCnt
							comp = append(comp, e.w)
						}
						if e.v == v && e.w == w {
							break
						}
					}
					comps = append(comps, comp)
				}
				lowV = min(lowV, lowW)
			} else if w != fa && dfn[w] < dfn[v] {
				stack = append(stack, e)
				lowV = min(lowV, dfn[w])
			}
		}
		if fa == -1 && childCnt == 1 {
			isCut[v] = false
		}
		return lowV
	}
	for v, timestamp := range dfn {
		if timestamp == 0 && len(g[v]) > 0 {
			f(v, -1)
		}
	}

	ok := make([]bool, m+1)
	for _, vs := range comps {
		bad := false
		for _, v := range vs {
			if !isCut[v] && len(g[v]) != 2 {
				bad = true
				break
			}
		}
		if !bad {
			for _, v := range vs {
				if !isCut[v] {
					ok[g[v][0].eid] = true
					ok[g[v][1].eid] = true
				}
			}
		}
	}
	ans := []interface{}{}
	for i, b := range ok {
		if b {
			ans = append(ans, i)
		}
	}
	Fprintln(out, len(ans))
	Fprint(out, ans...)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF962F(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}
	type edge struct{ v, w,eid int }
	type nei struct{ to, eid int }

	var n, m, v, w int
	Fscan(in, &n, &m)
	g := make([][]nei, n)
	for i := 1; i <= m; i++ {
		Fscan(in, &v, &w)
		v--
		w--
		g[v] = append(g[v], nei{w,i})
		g[w] = append(g[w], nei{v,i})
	}

	comps := [][2][]int{}
	bccIDs := make([]int, n)
	idCnt := 0
	isCut := make([]bool, n)

	dfn := make([]int, n)
	dfsClock := 0
	stack := []edge{}
	var f func(v, fa int) int
	f = func(v, fa int) int {
		dfsClock++
		dfn[v] = dfsClock
		lowV := dfsClock
		childCnt := 0
		for _, ne := range g[v] {
			w := ne.to
			e := edge{v, w,ne.eid}
			if dfn[w] == 0 {
				stack = append(stack, e)
				childCnt++
				lowW := f(w, v)
				if lowW >= dfn[v] {
					isCut[v] = true
					idCnt++
					comp := []int{}
					eids := []int{}
					for {
						e, stack = stack[len(stack)-1], stack[:len(stack)-1]
						if bccIDs[e.v] != idCnt {
							bccIDs[e.v] = idCnt
							comp = append(comp, e.v)
						}
						if bccIDs[e.w] != idCnt {
							bccIDs[e.w] = idCnt
							comp = append(comp, e.w)
						}
						eids = append(eids,e.eid )
						if e.v == v && e.w == w {
							break
						}
					}
					comps = append(comps, [2][]int{comp,eids})
				}
				lowV = min(lowV, lowW)
			} else if w != fa && dfn[w] < dfn[v] {
				stack = append(stack, e)
				lowV = min(lowV, dfn[w])
			}
		}
		if fa == -1 && childCnt == 1 {
			isCut[v] = false
		}
		return lowV
	}
	for v, timestamp := range dfn {
		if timestamp == 0 && len(g[v]) > 0 {
			f(v, -1)
		}
	}

	ok := make([]bool, m+1)
	for _, p := range comps {
		vs, eids := p[0],p[1]
		if len(vs) < 3 {
			continue
		}
		bad := false
		for _, v := range vs {
			if !isCut[v] && len(g[v]) != 2 {
				bad = true
				break
			}
		}
		if !bad {
			for _, eid := range eids {
				ok[eid]=true
			}
		}
	}
	ans := []interface{}{}
	for i, b := range ok {
		if b {
			ans = append(ans, i)
		}
	}
	Fprintln(out, len(ans))
	Fprint(out, ans...)
}

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

package main

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

// github.com/EndlessCheng/codeforces-go
func CF962F(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	min := func(a, b int) int {
		if a < b {
			return a
		}
		return b
	}
	type edge struct{ v, w int }

	var n, m, v, w int
	Fscan(in, &n, &m)
	g := make([][]int, n)
	idMap := map[[2]int]int{}
	for i := 1; i <= m; i++ {
		Fscan(in, &v, &w)
		v--
		w--
		g[v] = append(g[v], w)
		g[w] = append(g[w], v)
		if v > w {
			v, w = w, v
		}
		idMap[[2]int{v, w}] = i
	}

	comps := [][]int{}
	bccIDs := make([]int, n)
	idCnt := 0
	isCut := make([]bool, n)

	dfn := make([]int, n)
	dfsClock := 0
	stack := []edge{}
	var f func(v, fa int) int
	f = func(v, fa int) int {
		dfsClock++
		dfn[v] = dfsClock
		lowV := dfsClock
		childCnt := 0
		for _, w := range g[v] {
			e := edge{v, w}
			if dfn[w] == 0 {
				stack = append(stack, e)
				childCnt++
				lowW := f(w, v)
				if lowW >= dfn[v] {
					isCut[v] = true
					idCnt++
					comp := []int{}
					for {
						e, stack = stack[len(stack)-1], stack[:len(stack)-1]
						if bccIDs[e.v] != idCnt {
							bccIDs[e.v] = idCnt
							comp = append(comp, e.v)
						}
						if bccIDs[e.w] != idCnt {
							bccIDs[e.w] = idCnt
							comp = append(comp, e.w)
						}
						if e.v == v && e.w == w {
							break
						}
					}
					comps = append(comps, comp)
				}
				lowV = min(lowV, lowW)
			} else if w != fa && dfn[w] < dfn[v] {
				stack = append(stack, e)
				lowV = min(lowV, dfn[w])
			}
		}
		if fa == -1 && childCnt == 1 {
			isCut[v] = false
		}
		return lowV
	}
	for v, timestamp := range dfn {
		if timestamp == 0 && len(g[v]) > 0 {
			f(v, -1)
		}
	}

	ok := make([]bool, m+1)
	for _, vs := range comps {
		if len(vs) < 3 {
			continue
		}
		bad := false
		for _, v := range vs {
			if !isCut[v] && len(g[v]) != 2 {
				bad = true
				break
			}
		}
		if !bad {
			vs = append(vs, vs[0])
			for i := 0; i < len(vs)-1; i++ {
				v, w := vs[i], vs[i+1]
				if v > w {
					v, w = w, v
				}
				ok[idMap[[2]int{v, w}]] = true
			}
		}
	}
	ans := []interface{}{}
	for i, b := range ok {
		if b {
			ans = append(ans, i)
		}
	}
	Fprintln(out, len(ans))
	Fprint(out, ans...)
}

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