package main

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

var lineDelim = byte('\r')
var reader *bufio.Reader = bufio.NewReader(os.Stdin)

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

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

func ReadInt() int64 {
    str, _ := reader.ReadString(lineDelim)
    str = str[:len(str)-1]
    n, _ := strconv.Atoi(str)

    return int64(n)
}

func ReadString() string {
    str, _ := reader.ReadString(lineDelim)
    str = str[:len(str)-1]

    return str
}

func main() {
	nTestCases := ReadInt()
	for nTestCases != 0 {
		input := ReadString()
		input += "R"
		inputAsRunes := []rune(input)
		length := len(inputAsRunes)
		d := 0
		last := -1
		for i := 0; i < length; i++ {
			input := inputAsRunes[i]
			if input == 'L' {
				continue
			}
			diff := i - last
			last = i
			if d < diff {
				d = diff
			}
		}
		fmt.Println(d)
		nTestCases -= 1
	}
}

package main

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

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

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

	var n int
	fmt.Fscan(r, &n)
	for i := 0; i < n; i++ {
		var s string
		fmt.Fscan(r, &s)
		pos, res := -1, 0
		for l := 0; l < len(s); l++{
			if s[l] == 'R' {
				res = max(res, l-pos)
				pos = l
			}
		}
		if pos == -1{
			res = len(s) + 1
		}else {
			res = max(res, len(s) - pos)
		}
		fmt.Fprint(w, res, "\n")
	}

}

package main

import "fmt"

func Max(x int,y int) int{
	if x >= y {
		return x
	} else{
		return y
	}
}

func main() {
	var t int
	var s string
	fmt.Scan(&t)
	for T := 0 ; T < t ; T ++ {
		fmt.Scan(&s)
		q := -1
		output := 0
		for i := 0 ; i < len(s) ; i ++ {
			if s[i] == 'R' {
				output = Max( output , i - q)
				q = i
			}
		}
		output = Max(output , len(s) - q)
		fmt.Println(output)
	}
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	var cases int
	fmt.Scanf("%d\n", &cases)
	for i := 0; i < cases; i++ {
		line := readLine(reader)
		max := 0
		for i := len(line) - 1; i >= 0; {
			temp := 1
			for i>=0 && line[i] != 'R' {
				temp++
				i--
			}
			if temp > max {
				max = temp
			}
			i--
		}
		fmt.Println(max)
	}
}

func readLine(reader *bufio.Reader) []byte {
	result := make([]byte, 0)
	for {
		s, isPrefix, err := reader.ReadLine()
		if err != nil {
			fmt.Printf("error=%+v\n", err)
			break
		}
		result = append(result, s...)
		if !isPrefix {
			break
		}
	}
	return result
}

package main

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

func max(a int, b int, args ...int) int {
	mx := a
	if b > mx {
		mx = b
	}
	for _, val := range args {
		if val > mx {
			mx = val
		}
	}
	return mx
}

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

	var t int
	fmt.Fscanf(in, "%d\n", &t)
	for tc := 1; tc <= t; tc++ {
		var s string
		fmt.Fscanf(in, "%s\n", &s)
		s = "R" + s + "R"
		length := len(s)

		var pos []int
		for i := 0; i < length; i++ {
			cur := s[i : i+1]
			if cur == "R" {
				pos = append(pos, i)
			}
		}
		mx := 0
		for i := 0; i < len(pos)-1; i++ {
			mx = max(mx, pos[i+1]-pos[i])
		}
		fmt.Printf("%d\n", mx)
	}
}

package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	var t int
	fmt.Fscan(r, &t)
	for tc := 0; tc < t; tc++ {
		var s string
		fmt.Fscan(r, &s)
		rls := solve(s)
		fmt.Println(rls)
	}
}

func solve(s string) int {
	s = "R" + s + "R"
	cur, rls := 0, 0
	for i, ch := range s {
		if ch == 'R' {
			if i-cur > rls {
				rls = i - cur
			}
			cur = i
		}
	}
	return rls
}

package main

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

var (
	reader Reader = NewReader()
	writer Writer = NewWriter()
)

type Reader interface {
    Scanf(format string, a ...interface{})
}

type Writer interface {
	Printf(format string, a ...interface{})
	Flush()
}

type readerImpl struct {
	*bufio.Reader
}

func NewReader() Reader {
	return &readerImpl{Reader: bufio.NewReader(os.Stdin)}
}

func (i *readerImpl) Scanf(f string, a ...interface{}) {
    fmt.Fscanf(i.Reader, f, a...)
}

type writerImpl struct {
	*bufio.Writer
}

func NewWriter() Writer {
	return &writerImpl{Writer: bufio.NewWriter(os.Stdout)}
}

func (i *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(i.Writer, f, a...)
}

func (i *writerImpl) Flush() {
	i.Writer.Flush()
}

func main() {
	defer writer.Flush()
    var t int64
    reader.Scanf("%d\n", &t)
	for ; t > 0; t-- {
        var s string
		reader.Scanf("%s\n", &s)
		writer.Printf("%d\n", sol(s))
	}
}

func sol(s string) int {
	fmt.Scan()
	maxSoFar := 0
	prev := -1
	for i, c := range s + "R" {
		if c == 'R' {
			maxSoFar = max(maxSoFar, i-prev)
			prev = i
		}
	}
	return maxSoFar
}

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

package main

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

var (
	reader Reader = NewReader()
	writer Writer = NewWriter()
)

type Reader interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type Writer interface {
	Printf(format string, a ...interface{})
	Flush()
}

type readerImpl struct {
	*bufio.Scanner
}

func NewReader() Reader {
	s := bufio.NewScanner(os.Stdin)
	size := 2 << 22
	buf := make([]byte, size)
	s.Buffer(buf, size)
	s.Split(bufio.ScanWords)
	return &readerImpl{Scanner: s}
}

func (i *readerImpl) NextInt() int {
	i.Scan()
	ret, _ := strconv.Atoi(i.Text())
	return ret
}

func (i *readerImpl) NextInt64() int64 {
	i.Scan()
	ret, _ := strconv.ParseInt(i.Text(), 10, 64)
	return ret
}

func (i *readerImpl) NextString() string {
	i.Scan()
	return i.Text()
}

type writerImpl struct {
	*bufio.Writer
}

func NewWriter() Writer {
	return &writerImpl{Writer: bufio.NewWriter(os.Stdout)}
}

func (i *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(i.Writer, f, a...)
}

func (i *writerImpl) Flush() {
	i.Writer.Flush()
}

func main() {
	defer writer.Flush()
	t := reader.NextInt()
	for ; t > 0; t-- {
		s := reader.NextString()
		writer.Printf("%d\n", sol(s))
	}
}

func sol(s string) int {
	maxSoFar := 0
	prev := -1
	for i, c := range s + "R" {
		if c == 'R' {
			maxSoFar = max(maxSoFar, i-prev)
			prev = i
		}
	}
	return maxSoFar
}

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

package main

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

var (
	reader Reader = NewReader()
	writer Writer = NewWriter()
)

type Reader interface {
	Int() int
	Int64() int64
	String() string
	IntSlice(size int) []int
	Int64Slice(size int) []int64
	StringSlice(size int) []string
}

type Writer interface {
	Printf(format string, a ...interface{})
	Flush()
}

type readerImpl struct {
	*bufio.Reader
}

func NewReader() Reader {
	return &readerImpl{Reader: bufio.NewReader(os.Stdin)}
}

func (impl *readerImpl) scanf(f string, a ...interface{}) {
	fmt.Fscanf(impl.Reader, f, a...)
}

func (impl *readerImpl) Int() int {
	var ret int
	impl.scanf("%d\n", &ret)
	return ret
}

func (impl *readerImpl) Int64() int64 {
	var ret int64
	impl.scanf("%d\n", &ret)
	return ret
}

func (impl *readerImpl) String() string {
	var ret string
	impl.scanf("%s\n", &ret)
	return ret
}

func (impl *readerImpl) IntSlice(size int) []int {
	ret := make([]int, size)
	for i := 0; i < size-1; i++ {
		impl.scanf("%d ", &ret[i])
	}
	impl.scanf("%d\n", &ret[size-1])
	return ret
}

func (impl *readerImpl) Int64Slice(size int) []int64 {
	ret := make([]int64, size)
	for i := 0; i < size-1; i++ {
		impl.scanf("%d ", &ret[i])
	}
	impl.scanf("%d\n", &ret[size-1])
	return ret
}

func (impl *readerImpl) StringSlice(size int) []string {
	ret := make([]string, size)
	for i := 0; i < size-1; i++ {
		impl.scanf("%s ", &ret[i])
	}
	impl.scanf("%s\n", &ret[size-1])
	return ret
}

type writerImpl struct {
	*bufio.Writer
}

func NewWriter() Writer {
	return &writerImpl{Writer: bufio.NewWriter(os.Stdout)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

func main() {
	defer writer.Flush()
    t := reader.Int()
	for ; t > 0; t-- {
        s := reader.String()
		writer.Printf("%d\n", sol(s))
	}
}

func sol(s string) int {
	maxSoFar := 0
	prev := -1
	for i, c := range s + "R" {
		if c == 'R' {
			maxSoFar = max(maxSoFar, i-prev)
			prev = i
		}
	}
	return maxSoFar
}

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

package main

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

var lineDelim = byte('\r')
var reader *bufio.Reader = bufio.NewReader(os.Stdin)

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

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

func ReadInt() int64 {
    str, _ := reader.ReadString(lineDelim)
    str = str[:len(str)-1]
    n, _ := strconv.Atoi(str)

    return int64(n)
}

func ReadString() string {
    str, _ := reader.ReadString(lineDelim)
    str = str[:len(str)-1]

    return str
}

func main() {
	nTestCases := ReadInt()
	var inputArray []string
	for nTestCases != 0 {
		input := ReadString()
		inputArray = append(inputArray, input)
		nTestCases -= 1
	}
	for i, input := range inputArray {
		newInput := "R" + input
		inputArray[i] = newInput
	}
	var possibleSolutions []int
	for _, input := range inputArray {
		inputAsRunes := []rune(input)
		var d int = 1
		var i int = 0
		inputLen := len(input)
		maxJumps := inputLen - 1
		curJumps := 0
		for i < inputLen {
			if inputAsRunes[i] == 'L' {
				i = Max(Max(0, i - d), i - 1)
			} else {
				i = Max(i + 1, Min(inputLen + 1, i + d))
			}
			curJumps += 1
			if curJumps == maxJumps {
				i = 0
				curJumps = 0
			}
			if i == 0 {
				d += 1
			}
		}
		possibleSolutions = append(possibleSolutions, d)
	}
	for _, solution := range possibleSolutions {
		fmt.Println(solution)
	}
}

package main

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

var lineDelim = byte('\n')
var reader *bufio.Reader = bufio.NewReader(os.Stdin)

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

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

func ReadInt() int64 {
    str, _ := reader.ReadString(lineDelim)
    str = str[:len(str)-1]
    n, _ := strconv.Atoi(str)

    return int64(n)
}

func ReadString() string {
    str, _ := reader.ReadString(lineDelim)
    str = str[:len(str)-1]

    return str
}

func main() {
	nTestCases := ReadInt()
	for nTestCases != 0 {
		input := ReadString()
		input += "R"
		inputAsRunes := []rune(input)
		length := len(inputAsRunes)
		d := 0
		last := -1
		for i := 0; i < length; i++ {
			input := inputAsRunes[i]
			if input == 'L' {
				continue
			}
			diff := i - last
			last = i
			if d < diff {
				d = diff
			}
		}
		fmt.Println(d)
		nTestCases -= 1
	}
}

package main

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

func ReadStdin() string {
	reader := bufio.NewReader(os.Stdin)
	input, _ := reader.ReadString('\n')
	return strings.TrimSpace(input)
}

func StringToInt64(str string) int64 {
	integer, err := strconv.ParseInt(str, 10, 16)
	if err != nil {
		panic(err)
	}
	return integer
}

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

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

func main() {
	nTestCases := StringToInt64(ReadStdin())
	var inputArray []string
	for nTestCases != 0 {
		inputArray = append(inputArray, ReadStdin())
		nTestCases = nTestCases - 1
	}
	for i, input := range inputArray {
		newInput := "R" + input
		inputArray[i] = newInput
	}
	var possibleSolutions []int
	for _, input := range inputArray {
		inputAsRunes := []rune(input)
		var d int = 1
		var i int = 0
		inputLen := len(input)
		maxJumps := inputLen - 1
		curJumps := 0
		for i < inputLen {
			if inputAsRunes[i] == 'L' {
				i = Max(Max(0, i - d), i - 1)
			} else {
				i = Max(i + 1, Min(inputLen + 1, i + d))
			}
			curJumps += 1
			if curJumps == maxJumps {
				i = 0
				curJumps = 0
			}
			if i == 0 {
				d += 1
			}
		}
		possibleSolutions = append(possibleSolutions, d)
	}
	for _, solution := range possibleSolutions {
		fmt.Println(solution)
	}
}

package main

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

var lineDelim = byte('\r')
var reader *bufio.Reader = bufio.NewReader(os.Stdin)

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

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

func ReadInt() int64 {
    str, _ := reader.ReadString(lineDelim)
    str = str[:len(str)-1]
    n, _ := strconv.Atoi(str)

    return int64(n)
}

func ReadString() string {
    str, _ := reader.ReadString(lineDelim)
    str = str[:len(str)-1]

    return str
}

func main() {
	nTestCases := ReadInt()
	var inputArray []string
	for nTestCases != 0 {
		inputArray = append(inputArray, ReadString())
		nTestCases -= 1
	}
	for i, input := range inputArray {
		newInput := "R" + input
		inputArray[i] = newInput
	}
	for _, input := range inputArray {
		inputAsRunes := []rune(input)
		existsR := false
		inputLen := len(input)
		for i := 1; i < inputLen; i++ {
			if inputAsRunes[i] == 'R' {
				existsR = true
				break
			}
		}
		if !existsR {
			fmt.Println(inputLen)
			continue
		}
		var d int = 1
		var i int = 0
		var curJumps int = 0
		curMaxJumps := inputLen
		for i < inputLen {
			if inputAsRunes[i] == 'L' {
				i = Max(Max(0, i - d), i - 1)
			} else {
				i = Max(i + 1, Min(inputLen + 1, i + d))
			}
			if i >= inputLen {
				break
			}
			curJumps += 1
			if curJumps == curMaxJumps {
				d += 1
				curJumps = 0
				i += d
				curMaxJumps -= i
			}
		}
		fmt.Println(d)
	}
}

package main

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

func ReadStdin() string {
	reader := bufio.NewReader(os.Stdin)
	input, _ := reader.ReadString('\n')
	return strings.TrimSpace(input)
}

func StringToInt64(str string) int64 {
	integer, err := strconv.ParseInt(str, 10, 16)
	if err != nil {
		panic(err)
	}
	return integer
}

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

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

func main() {
	nTestCases := StringToInt64(ReadStdin())
	var inputArray []string
	for nTestCases != 0 {
		inputArray = append(inputArray, ReadStdin())
		nTestCases = nTestCases - 1
	}
	fmt.Println(inputArray)
	for i, input := range inputArray {
		newInput := "R" + input
		inputArray[i] = newInput
	}
	fmt.Println(inputArray)
	var possibleSolutions []int
	for _, input := range inputArray {
		inputAsRunes := []rune(input)
		var d int = 1
		var i int = 0
		inputLen := len(input)
		maxJumps := inputLen - 1
		curJumps := 0
		for i < inputLen {
			if inputAsRunes[i] == 'L' {
				i = Max(Max(0, i - d), i - 1)
			} else {
				i = Max(i + 1, Min(inputLen + 1, i + d))
			}
			curJumps += 1
			if curJumps == maxJumps {
				i = 0
				curJumps = 0
			}
			if i == 0 {
				d += 1
			}
		}
		possibleSolutions = append(possibleSolutions, d)
	}
	fmt.Println(possibleSolutions)
	for _, solution := range possibleSolutions {
		fmt.Println(solution)
	}
}

package main

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

func ReadStdin() string {
	reader := bufio.NewReader(os.Stdin)
	input, _ := reader.ReadString('\n')
	return strings.TrimSpace(input)
}

func StringToInt64(str string) int64 {
	integer, err := strconv.ParseInt(str, 10, 16)
	if err != nil {
		log.Panic(err)
	}
	return integer
}

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

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

func main() {
	nTestCases := StringToInt64(ReadStdin())
	var inputArray []string
	for nTestCases != 0 {
		inputArray = append(inputArray, ReadStdin())
		nTestCases = nTestCases - 1
	}
	for i, input := range inputArray {
		newInput := "R" + input
		inputArray[i] = newInput
	}
	var possibleSolutions []int
	for _, input := range inputArray {
		inputAsRunes := []rune(input)
		var d int = 1
		var i int = 0
		inputLen := len(input)
		maxJumps := inputLen - 1
		curJumps := 0
		for i < inputLen {
			if inputAsRunes[i] == 'L' {
				i = Max(Max(0, i - d), i - 1)
			} else {
				i = Max(i + 1, Min(inputLen + 1, i + d))
			}
			curJumps += 1
			if curJumps == maxJumps {
				i = 0
				curJumps = 0
			}
			if i == 0 {
				d += 1
			}
		}
		possibleSolutions = append(possibleSolutions, d)
	}
	for _, solution := range possibleSolutions {
		log.Println(solution)
	}
}

package main

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

var lineDelim = byte('\r')
var reader *bufio.Reader = bufio.NewReader(os.Stdin)

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

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

func ReadInt() int64 {
    str, _ := reader.ReadString(lineDelim)
    str = str[:len(str)-1]
    n, _ := strconv.Atoi(str)

    return int64(n)
}

func ReadString() string {
    str, _ := reader.ReadString(lineDelim)
    str = str[:len(str)-1]

    return str
}

func main() {
	nTestCases := ReadInt()
	var inputArray []string
	for nTestCases != 0 {
		inputArray = append(inputArray, ReadString())
		nTestCases -= 1
	}
	var onlyLInputs []int
	for i, input := range inputArray {
		existsR := false
		runes := []rune(input)
		for _, r := range runes {
			if r == 'R' {
				existsR = true
				break
			}
		}
		if !existsR {
			onlyLInputs = append(onlyLInputs, i)
		}
	}
	for i, input := range inputArray {
		newInput := "R" + input
		inputArray[i] = newInput
	}
	for inputIndex, input := range inputArray {
		inputLen := len(input)
		skip := false
		for _, onlyLIndex := range onlyLInputs {
			if onlyLIndex == inputIndex {
				fmt.Println(inputLen)
				skip = true
			}
		}
		if skip {
			continue
		}
		inputAsRunes := []rune(input)
		var d int = 1
		var i int = 0
		var curJumps int = 0
		for i < inputLen {
			if inputAsRunes[i] == 'L' {
				i = Max(Max(0, i - d), i - 1)
			} else {
				i = Max(i + 1, Min(inputLen + 1, i + d))
			}
			if i >= inputLen {
				break
			}
			curJumps += 1
			if curJumps == inputLen {
				d += 1
				curJumps = 0
				i = d
			}
		}
		fmt.Println(d)
	}
}

package main

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

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

	var T, n, e int
	fmt.Fscan(r, &T)
	for t := 0; t < T; t++ {
		fmt.Fscan(r, &n)
		m := make(map[int]int)
		suc := false
		for i := 0; i < n; i++{
			fmt.Fscan(r, &e)
			v, ok := m[e]
			if ok && i-v > 1 {
				suc = true
			}
			if !ok {
				m[e] = i
			}
		}
		if suc {
			fmt.Fprint(w, "YES\n")
		}else {
			fmt.Fprint(w, "NO\n")
		}
	}

}

package main

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

var (
	reader Reader = NewReader()
	writer Writer = NewWriter()
)

type Reader interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type Writer interface {
	Printf(format string, a ...interface{})
	Flush()
}

type readerImpl struct {
	*bufio.Scanner
}

func NewReader() Reader {
	s := bufio.NewScanner(os.Stdin)
	maxStrLen := 20000
	buf := make([]byte, maxStrLen+1)
	s.Buffer(buf, maxStrLen+1)
	s.Split(bufio.ScanWords)
	return &readerImpl{Scanner: s}
}

func (i *readerImpl) NextInt() int {
	i.Scan()
	ret, _ := strconv.Atoi(i.Text())
	return ret
}

func (i *readerImpl) NextInt64() int64 {
	i.Scan()
	ret, _ := strconv.ParseInt(i.Text(), 10, 64)
	return ret
}

func (i *readerImpl) NextString() string {
	i.Scan()
	return i.Text()
}

type writerImpl struct {
	*bufio.Writer
}

func NewWriter() Writer {
	return &writerImpl{Writer: bufio.NewWriter(os.Stdout)}
}

func (i *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(i.Writer, f, a...)
}

func (i *writerImpl) Flush() {
	i.Writer.Flush()
}

func main() {
	defer writer.Flush()
	t := reader.NextInt()
	for ; t > 0; t-- {
		s := reader.NextString()
		writer.Printf("%d\n", sol(s))
	}
}

func sol(s string) int {
	maxSoFar := 0
	prev := -1
	for i, c := range s + "R" {
		if c == 'R' {
			maxSoFar = max(maxSoFar, i-prev)
			prev = i
		}
	}
	return maxSoFar
}

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

package main

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

var (
	reader Reader = NewReader()
	writer Writer = NewWriter()
)

type Reader interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type Writer interface {
	Printf(format string, a ...interface{})
	Flush()
}

type readerImpl struct {
	*bufio.Scanner
}

func NewReader() Reader {
	s := bufio.NewScanner(os.Stdin)
	maxStrLen := 20000
	buf := make([]byte, maxStrLen+1)
	s.Buffer(buf, maxStrLen+1)
	s.Split(bufio.ScanWords)
	return &readerImpl{Scanner: s}
}

func (i *readerImpl) NextInt() int {
	i.Scan()
	ret, _ := strconv.Atoi(i.Text())
	return ret
}

func (i *readerImpl) NextInt64() int64 {
	i.Scan()
	ret, _ := strconv.ParseInt(i.Text(), 10, 64)
	return ret
}

func (i *readerImpl) NextString() string {
	i.Scan()
	return i.Text()
}

type writerImpl struct {
	*bufio.Writer
}

func NewWriter() Writer {
	return &writerImpl{Writer: bufio.NewWriter(os.Stdout)}
}

func (i *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(i.Writer, f, a...)
}

func (i *writerImpl) Flush() {
	i.Writer.Flush()
}

func main() {
	defer writer.Flush()
	t := reader.NextInt()
	for ; t > 0; t-- {
		s := reader.NextString()
		writer.Printf("%d\n", sol(s))
	}
}

func sol(s string) int {
	writer.Printf("Received %s\n", s)
	maxSoFar := 0
	prev := -1
	for i, c := range s + "R" {
		if c == 'R' {
			maxSoFar = max(maxSoFar, i-prev)
			prev = i
		}
	}
	return maxSoFar
}

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

package main

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

var (
	reader Reader = NewReader()
	writer Writer = NewWriter()
)

type Reader interface {
	NextInt(delim byte) int
	NextInt64(delim byte) int64
	NextString(delim byte) string
}

type Writer interface {
	Printf(format string, a ...interface{})
	Flush()
}

type readerImpl struct {
	*bufio.Reader
}

func NewReader() Reader {
	return &readerImpl{Reader: bufio.NewReader(os.Stdin)}
}

func (i *readerImpl) NextInt(delim byte) int {
	ret, _ := strconv.Atoi(i.NextString(delim))
	return ret
}

func (i *readerImpl) NextInt64(delim byte) int64 {
	ret, _ := strconv.ParseInt(i.NextString(delim), 10, 64)
	return ret
}

func (i *readerImpl) NextString(delim byte) string {
	s, _ := i.ReadBytes(delim)
	return string(s[:len(s)-1])
}

type writerImpl struct {
	*bufio.Writer
}

func NewWriter() Writer {
	return &writerImpl{Writer: bufio.NewWriter(os.Stdout)}
}

func (i *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(i.Writer, f, a...)
}

func (i *writerImpl) Flush() {
	i.Writer.Flush()
}

func main() {
	defer writer.Flush()
	t := reader.NextInt('\n')
	for ; t > 0; t-- {
		s := reader.NextString('\n')
		writer.Printf("%d\n", sol(s))
	}
}

func sol(s string) int {
	maxSoFar := 0
	prev := -1
	for i, c := range s + "R" {
		if c == 'R' {
			maxSoFar = max(maxSoFar, i-prev)
			prev = i
		}
	}
	return maxSoFar
}

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

package main

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

var (
	reader Reader = NewReader()
	writer Writer = NewWriter()
)

type Reader interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type Writer interface {
	Printf(format string, a ...interface{})
	Flush()
}

type readerImpl struct {
	*bufio.Scanner
}

func NewReader() Reader {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	return &readerImpl{Scanner: s}
}

func (i *readerImpl) NextInt() int {
	i.Scan()
	ret, _ := strconv.Atoi(i.Text())
	return ret
}

func (i *readerImpl) NextInt64() int64 {
	i.Scan()
	ret, _ := strconv.ParseInt(i.Text(), 10, 64)
	return ret
}

func (i *readerImpl) NextString() string {
	i.Scan()
	return i.Text()
}

type writerImpl struct {
	*bufio.Writer
}

func NewWriter() Writer {
	return &writerImpl{Writer: bufio.NewWriter(os.Stdout)}
}

func (i *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(i.Writer, f, a...)
}

func (i *writerImpl) Flush() {
	i.Writer.Flush()
}

func main() {
	defer writer.Flush()
	t := reader.NextInt()
	for ; t > 0; t-- {
		s := reader.NextString()
		writer.Printf("%d\n", sol(s))
	}
}

func sol(s string) int {
	maxSoFar := 0
	prev := -1
	for i, c := range s + "R" {
		if c == 'R' {
			maxSoFar = max(maxSoFar, i-prev)
			prev = i
		}
	}
	return maxSoFar
}

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

package main

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

var (
	reader Reader = NewReader()
	writer Writer = NewWriter()
)

type Reader interface {
	NextInt() int
	NextInt64() int64
	NextString() string
}

type Writer interface {
	Printf(format string, a ...interface{})
	Flush()
}

type readerImpl struct {
	*bufio.Scanner
}

func NewReader() Reader {
	s := bufio.NewScanner(os.Stdin)
    c := 200000 // random large-enough number
	buf := make([]byte, c)
	s.Buffer(buf, c)
	s.Split(bufio.ScanWords)
	return &readerImpl{Scanner: s}
}

func (i *readerImpl) NextInt() int {
	i.Scan()
	ret, _ := strconv.Atoi(i.Text())
	return ret
}

func (i *readerImpl) NextInt64() int64 {
	i.Scan()
	ret, _ := strconv.ParseInt(i.Text(), 10, 64)
	return ret
}

func (i *readerImpl) NextString() string {
	i.Scan()
	return i.Text()
}

type writerImpl struct {
	*bufio.Writer
}

func NewWriter() Writer {
	return &writerImpl{Writer: bufio.NewWriter(os.Stdout)}
}

func (i *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(i.Writer, f, a...)
}

func (i *writerImpl) Flush() {
	i.Writer.Flush()
}

func main() {
	defer writer.Flush()
	t := reader.NextInt()
	for ; t > 0; t-- {
		s := reader.NextString()
		writer.Printf("%d\n", sol(s))
	}
}

func sol(s string) int {
	maxSoFar := 0
	prev := -1
	for i, c := range s + "R" {
		if c == 'R' {
			maxSoFar = max(maxSoFar, i-prev)
			prev = i
		}
	}
	return maxSoFar
}

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


package main
import (
	"fmt"
	//"sort"
	//"unicode/utf8"
)
var f [101]int
var a [101][101]int

func fungsi(n int) int{
	if f[n]!=n {
		f[n]=fungsi(f[n])
	} else {
		return f[n]
	}
	return f[n]
}
func main() {
	var n1,m1,t,l int
	flag,no:=0,0
	b:=make([]int,101)
	fmt.Scan(&n1,&m1)
	for i:=1;i<=n1;i++ {
		f[i]=i
		fmt.Scan(&t)
		for j:=1;j<=t;j++ {
			flag=1
			fmt.Scan(&l)
			if b[l]==0 {
				b[l]=i
			} else {
				f[fungsi(b[l])]=i
			}
		}
	}
	for i:=1;i<=n1;i++ {
		if f[i]==i {
			no++
		}
	}
	fmt.Println(no-flag)
}

package main

import "fmt"

//disjoint union set

const  MAX_N=101
var par [MAX_N]int //父亲
var rank [MAX_N]int //树的高度
var visited [MAX_N]bool //whether the language is needed

func initialize(n int) {
	for i := 1; i <= n; i++{
		par[i]=i
		rank[i]=0
	}
}

func find(x int) int{
	if par[x] == x {
		return x
	}else {
		par[x] = find(par[x])
		return par[x]
	}
}

func unite(x, y int) {
	x=find(x)
	y=find(y)
	if(x == y) {return}
	if rank[x] < rank[y]{
		par[x]=y
	}else{
		par[y]=x;
		if rank[x] == rank[y] {rank[x]++}
	}
}

func same(x, y int) bool{
	return find(x) == find(y);
}

func main() {
	var n,m int
	fmt.Scan(&n,&m)
	initialize(m)
	var dumb int //know nothing
	for i := 0; i < n; i++ {
		var l int
		fmt.Scan(&l)
		arr := make([]int,l)
		if l == 0 {
			dumb++
			continue
		}
		for j := 0; j < l; j++ {
			fmt.Scan(&arr[j])
			visited[arr[j]] = true
		}
		for j := 1; j < l; j++ { //union
			unite(arr[0],arr[j])
		}
	}
	stmap := make(map[int]int)
	for i := 1; i <= m; i++ {
		if visited[i] {
			stmap[find(i)]++
		}
	}
	if len(stmap) == 0{
		fmt.Println(dumb)
	}else {
		res := len(stmap) + dumb - 1
		fmt.Println(res)
	}
}

package main

import "fmt"

type Set struct {
    pset []int
    count int
}

func (s *Set) initSet(n int) {
    s.pset = make([]int,n)
    for i := 0; i < n; i++ { s.pset[i] = i }
    s.count = n
}

func (s *Set) findSet(i int) int {
    if s.pset[i] != i { s.pset[i] = s.findSet(s.pset[i]) }
    return s.pset[i]
}

func (s *Set) isSameSet(i, j int) bool {
    return s.findSet(i) == s.findSet(j)
}

func (s *Set) unionSet(i, j int) {
    s.pset[s.findSet(i)] = s.findSet(j)
    s.count--
}

func main() {
    var n,m,k,a int
    var x Set
    p := make(map[int]int)
    fmt.Scan(&n,&m)
    x.initSet(n)
    zero := true
    for i := 0; i < n; i++ {
        fmt.Scan(&k)
        if k != 0 { zero = false }
        for j := 0; j < k; j++ {
            fmt.Scan(&a)
            if _, ok := p[a]; !ok {
                p[a] = i
            } else {
                if !x.isSameSet(p[a],i) {
                    x.unionSet(p[a],i)
                }
            }
        }
    }
    if zero { fmt.Println(x.count) } else { fmt.Println(x.count-1) }
}

package main

import "fmt"

var a [210][210]int
var n, m int
var w [210]int

func q(v int) {
    w[v] = 1
    for i := 0; i < n+m; i++ {
        if a[v][i] == 1 && w[i] == 0 {
            q(i)
        }
    }
}

func main() {
    fmt.Scan(&n, &m)
    cou := 0

    for i := 0; i < n; i++ {
        var k int
        fmt.Scan(&k)
        cou += k
        for j := 0; j < k; j++ {
            var x int
            fmt.Scan(&x)
            x--
            a[i][n+x] = 1
            a[n+x][i] = 1
        }
    }
    ans := 0
    for i := 0; i < n; i++ {
        if w[i] == 0 {
            q(i)
            ans++
        }
    }
    if cou == 0 {
        fmt.Println(n)
    } else {
        fmt.Println(ans - 1)
    }
}

package main

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

func dsuGet(p []int, v int) int {
	if v == p[v] {
		return v
	}
	p[v] = dsuGet(p, p[v])
	return p[v]
}

func dsuUnite(p []int, a, b int) {
	a = dsuGet(p, a)
	b = dsuGet(p, b)

	if rand.Int() & 1 == 1 {
		a, b = b, a
	}
	if a != b {
		p[a] = b
	}
}

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)

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

	a := make([][]int, m)
	for i := 0; i < m; i++ {
		a[i] = make([]int, 0)
	}

	var sk int

	for i := 0; i < n; i++ {
		var k, b int
		fmt.Fscanf(reader, "%d", &k)
		sk += k
		for j := 0; j < k; j++ {
			fmt.Fscanf(reader, "%d", &b)
			b--
			a[b] = append(a[b], i)
		}
		fmt.Fscanf(reader, "\n")
	}

	p := make([]int, n)
	for i := 0; i < n; i++ {
		p[i] = i
	}

	var res int

	for i := 0; i < m; i++ {
		if len(a[i]) > 0 {
			for j := 0; j < len(a[i]); j++ {
				if dsuGet(p, a[i][0]) != dsuGet(p, a[i][j]) {
					dsuUnite(p, a[i][0], a[i][j])
				}
			}
		}
	}

	for i := 1; i < n; i++ {
		if dsuGet(p, 0) != dsuGet(p, i) {
			res++
			dsuUnite(p, 0, i)
		}
	}

	if sk == 0 {
		fmt.Fprintf(writer, "%d\n", n)
	} else {
		fmt.Fprintf(writer, "%d\n", res)
	}

	writer.Flush()
}

package main

import "fmt"

var emp [][]int
var g [][]int
var used []bool

func dfs(vertex int) {
	used[vertex] = true
	for _, to := range g[vertex] {
		if !used[to] {
			dfs(to)
		}
	}
}

func check(x, y []int) bool {
	for _, xVal := range x {
		for _, yVal := range y {
			if xVal == yVal {
				return true
			}
		}
	}
	return false
}

func buildGraph(n int) {
	g = make([][]int, n)
	used = make([]bool, n)

	for from := 0; from < n; from++ {
		for to := 0; to < n; to++ {
			if to != from && check(emp[from], emp[to]) {
				g[from] = append(g[from], to)
			}
		}
	}
}

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

	emp = make([][]int, n)

	marker := false

	for i := 0; i < n; i++ {
		var k int
		fmt.Scanf("%d", &k)
		marker = marker || k > 0
		for j := 0; j < k; j++ {
			var id int
			fmt.Scanf("%d", &id)
			emp[i] = append(emp[i], id-1)
		}
		fmt.Scanf("\n")
	}

	buildGraph(n)

	counter := 0

	for i := 0; i < n; i++ {
		if !used[i] {
			dfs(i)
			counter++
		}
	}

	if marker {
	    counter--
	}

	fmt.Printf("%d\n", counter)
}

package main

import "fmt"

//disjoint union set

const  MAX_N=101
var par [MAX_N]int //父亲
var rank [MAX_N]int //树的高度
var visited [MAX_N]bool //whether the language is needed

func initialize(n int) {
	for i := 1; i <= n; i++{
		par[i]=i
		rank[i]=0
	}
}

func find(x int) int{
	if par[x] == x {
		return x
	}else {
		par[x] = find(par[x])
		return par[x]
	}
}

func unite(x, y int) {
	x=find(x)
	y=find(y)
	if(x == y) {return}
	if rank[x] < rank[y]{
		par[x]=y
	}else{
		par[y]=x;
		if rank[x] == rank[y] {rank[x]++}
	}
}

func same(x, y int) bool{
	return find(x) == find(y);
}

func main() {
	var n,m int
	fmt.Scan(&n,&m)
	initialize(m)
	var dumb int //know nothing
	for i := 0; i < n; i++ {
		var l int
		fmt.Scan(&l)
		arr := make([]int,l)
		if l == 0 {
			dumb++
			continue
		}
		for j := 0; j < l; j++ {
			fmt.Scan(&arr[j])
			visited[arr[j]] = true
		}
		for j := 1; j < l; j++ { //union
			unite(arr[0],arr[j])
		}
	}
	stmap := make(map[int]int)
	for i := 1; i <= m; i++ {
		if visited[i] {
			stmap[find(i)]++
		}
	}
	res := len(stmap) + dumb - 1
	fmt.Println(res)
}

package main

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

func dsuGet(p []int, v int) int {
	if v == p[v] {
		return v
	}
	p[v] = dsuGet(p, p[v])
	return p[v]
}

func dsuUnite(p []int, a, b int) {
	a = dsuGet(p, a)
	b = dsuGet(p, b)

	if rand.Int() & 1 == 1 {
		a, b = b, a
	}
	if a != b {
		p[a] = b
	}
}

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)

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

	a := make([][]int, m)
	for i := 0; i < m; i++ {
		a[i] = make([]int, 0)
	}

	for i := 0; i < n; i++ {
		var k, b int
		fmt.Fscanf(reader, "%d", &k)
		for j := 0; j < k; j++ {
			fmt.Fscanf(reader, "%d", &b)
			b--
			a[b] = append(a[b], i)
		}
		fmt.Fscanf(reader, "\n")
	}

	p := make([]int, n)
	for i := 0; i < n; i++ {
		p[i] = i
	}

	var res int

	for i := 0; i < m; i++ {
		if len(a[i]) > 0 {
			for j := 0; j < len(a[i]); j++ {
				if dsuGet(p, a[i][0]) != dsuGet(p, a[i][j]) {
					dsuUnite(p, a[i][0], a[i][j])
				}
			}
		}
	}

	for i := 1; i < n; i++ {
		if dsuGet(p, 0) != dsuGet(p, i) {
			res++
			dsuUnite(p, 0, i)
		}
	}

	fmt.Fprintf(writer, "%d\n", res)

	writer.Flush()
}

package main

import (
	"fmt"
)

var emp [][]int
var g [][]int
var used []bool

func dfs(vertex int) int {
	used[vertex] = true
	counter := 1
	for _, to := range g[vertex] {
		if !used[to] {
			counter += dfs(to)
		}
	}
	return counter
}

func check(x, y []int) bool {
	for _, xVal := range x {
		for _, yVal := range y {
			if xVal == yVal {
				return true
			}
		}
	}
	return false
}

func buildGraph(n int) {
	g = make([][]int, n)
	used = make([]bool, n)

	for from := 0; from < n; from++ {
		for to := 0; to < n; to++ {
			if to != from && check(emp[from], emp[to]) {
				g[from] = append(g[from], to)
			}
		}
	}
}

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

	emp = make([][]int, n)
	bad := make([]bool, n)

	for i := 0; i < n; i++ {
		var k int
		fmt.Scanf("%d", &k)
		if k == 0 {
			bad[i] = true
		}
		for j := 0; j < k; j++ {
			var id int
			fmt.Scanf("%d", &id)
			emp[i] = append(emp[i], id-1)
		}
	}

	buildGraph(n)

	compSize := 0

	for i := 0; i < n; i++ {
		if !used[i] && !bad[i] {
			curSize := dfs(i)
			if curSize > compSize {
				compSize = curSize
			}
		}
	}

	fmt.Printf("%d\n", n-compSize)
}

package main

import "fmt"

var emp [][]int
var g [][]int
var used []bool

func dfs(vertex int) {
	used[vertex] = true
	for _, to := range g[vertex] {
		if !used[to] {
			dfs(to)
		}
	}
}

func check(x, y []int) bool {
	for _, xVal := range x {
		for _, yVal := range y {
			if xVal == yVal {
				return true
			}
		}
	}
	return false
}

func buildGraph(n int) {
	g = make([][]int, n)
	used = make([]bool, n)

	for from := 0; from < n; from++ {
		for to := 0; to < n; to++ {
			if to != from && check(emp[from], emp[to]) {
				g[from] = append(g[from], to)
			}
		}
	}
}

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

	emp = make([][]int, n)

	marker := false

	for i := 0; i < n; i++ {
		var k int
		fmt.Scanf("%d", &k)
		marker = k > 0
		for j := 0; j < k; j++ {
			var id int
			fmt.Scanf("%d", &id)
			emp[i] = append(emp[i], id-1)
		}
		fmt.Scanf("\n")
	}

	buildGraph(n)

	counter := 0

	for i := 0; i < n; i++ {
		if !used[i] {
			dfs(i)
			counter++
		}
	}

	if marker {
	    counter--
	}

	fmt.Printf("%d\n", counter)
}

package main

import "fmt"

var emp [][]int
var g [][]int
var used []bool

func dfs(vertex int) {
	used[vertex] = true
	for _, to := range g[vertex] {
		if !used[to] {
			dfs(to)
		}
	}
}

func check(x, y []int) bool {
	for _, xVal := range x {
		for _, yVal := range y {
			if xVal == yVal {
				return true
			}
		}
	}
	return false
}

func buildGraph(n int) {
	g = make([][]int, n)
	used = make([]bool, n)

	for from := 0; from < n; from++ {
		for to := 0; to < n; to++ {
			if to != from && check(emp[from], emp[to]) {
				g[from] = append(g[from], to)
			}
		}
	}
}

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

	emp = make([][]int, n)

	for i := 0; i < n; i++ {
		var k int
		fmt.Scanf("%d", &k)
		for j := 0; j < k; j++ {
			var id int
			fmt.Scanf("%d", &id)
			emp[i] = append(emp[i], id-1)
		}
	}

	buildGraph(n)

	counter := 0

	for i := 0; i < n; i++ {
		if !used[i] {
			dfs(i)
			counter++
		}
	}

	fmt.Printf("%d\n", counter-1)
}

package main

import "fmt"

var emp [][]int
var g [][]int
var used []bool

func dfs(vertex int) {
	used[vertex] = true
	for _, to := range g[vertex] {
		if !used[to] {
			dfs(to)
		}
	}
}

func check(x, y []int) bool {
	for _, xVal := range x {
		for _, yVal := range y {
			if xVal == yVal {
				return true
			}
		}
	}
	return false
}

func buildGraph(n int) {
	g = make([][]int, n)
	used = make([]bool, n)

	for from := 0; from < n; from++ {
		for to := 0; to < n; to++ {
			if to != from && check(emp[from], emp[to]) {
				g[from] = append(g[from], to)
			}
		}
	}
}

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

	emp = make([][]int, n)

	for i := 0; i < n; i++ {
		var k int
		fmt.Scanf("%d", &k)
		for j := 0; j < k; j++ {
			var id int
			fmt.Scanf("%d", &id)
			emp[i] = append(emp[i], id-1)
		}
		fmt.Scanf("\n")
	}

	buildGraph(n)

	counter := 0

	for i := 0; i < n; i++ {
		if !used[i] {
			dfs(i)
			counter++
		}
	}

	fmt.Printf("%d\n", counter-1)
}


package main

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

// github.com/EndlessCheng/codeforces-go
type vec struct{ x, y float64 }
type line struct{ p1, p2 vec }

func (a vec) sub(b vec) vec     { return vec{a.x - b.x, a.y - b.y} }
func (a vec) det(b vec) float64 { return a.x*b.y - a.y*b.x }
func (a line) vec() vec         { return a.p2.sub(a.p1) }

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

	solve := func(Case int) {
		var x, y, a, b int64
		Fscan(in, &x, &y, &a, &b)
		r := min(x/a, y/b)
		ans := max(r, min(x/b, y/a))

		if a == b {
			Fprintln(out, ans)
			return
		}

		i := func() int64 {
			x, y, a, b := float64(x), float64(y), float64(a), float64(b)
			l1 := line{vec{x / a, 0}, vec{0, x / b}}
			l2 := line{vec{y / b, 0}, vec{0, y / a}}

			va := l1.vec()
			d1 := va.det(l2.p1.sub(l1.p1))
			d2 := va.det(l2.p2.sub(l1.p1))

			d :=d2-d1
			i := int64(l2.p1.x/d*d2-l2.p2.x/d*d1)
			return i
		}()
		for k1 := i - 10; k1 < i+10 && k1 <= r; k1++ {
			if k1 < 0 {
				continue
			}
			k2 := min((x-k1*a)/b, (y-k1*b)/a)
			ans = max(ans, k1+k2)
		}

		Fprintln(out, ans)
	}

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

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

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

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

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

package main

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

// Binary Search
// Math

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

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

	var x, y, a, b int64
	for ; t > 0; t-- {
		fmt.Fscanf(reader, "%d%d%d%d\n", &x, &y, &a, &b)
		fmt.Println(giftSet(x, y, a, b))
	}
}

func giftSet(x, y, a, b int64) int64 {
	if a == b {
		return Min(x, y) / a
	}

	if a < b {
		a, b = b, a
	}

	out := int64(0)
	l, r := int64(0), int64(1e9)
	for l <= r {
		m := l + (r-l)>>1
		if isValid(x, y, a, b, m) {
			out = m
			l = m + 1
		} else {
			r = m - 1
		}
	}
	return out
}

func isValid(x, y, a, b, m int64) bool {
	l := math.Max(math.Ceil(float64(y-a*m)/float64(b-a)), 0)
	r := math.Min(math.Floor(float64(x-b*m)/float64(a-b)), float64(m))
	return l <= r
}

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

package main

import (
	"fmt"
	"math"
)

func main() {
	var t int64
	fmt.Scanln(&t)

	var x, y, a, b int64
	for ; t > 0; t-- {
		fmt.Scanln(&x, &y, &a, &b)
		fmt.Println(giftSet(x, y, a, b))
	}
}

func giftSet(x, y, a, b int64) int64 {
	if a == b {
		return Min(x, y) / a
	}

	if a < b {
		a, b = b, a
	}

	out := int64(0)
	l, r := int64(0), int64(1e9)
	for l <= r {
		m := l + (r-l)>>1
		if isValid(x, y, a, b, m) {
			out = m
			l = m + 1
		} else {
			r = m - 1
		}
	}
	return out
}

func isValid(x, y, a, b, m int64) bool {
	l := math.Max(math.Ceil(float64(y-a*m)/float64(b-a)), 0)
	r := math.Min(math.Floor(float64(x-b*m)/float64(a-b)), float64(m))
	return l <= r
}

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

package main

import (
	"fmt"
	"math"
)

func main() {
	var t int64
	fmt.Scanf("%d\n", &t)

	for ; t > 0; t-- {
		var x, y, a, b int64
		fmt.Scanf("%d%d%d%d\n", &x, &y, &a, &b)
		fmt.Println(giftSet(x, y, a, b))
	}
}

func giftSet(x, y, a, b int64) int64 {
	if a == b {
		return Min(x, y) / a
	}

	if a < b {
		a, b = b, a
	}

	out := int64(0)
	l, r := int64(0), int64(1e9)
	for l <= r {
		m := l + (r-l)>>1
		if isValid(x, y, a, b, m) {
			out = m
			l = m + 1
		} else {
			r = m - 1
		}
	}
	return out
}

func isValid(x, y, a, b, m int64) bool {
	l := math.Max(math.Ceil(float64(y-a*m)/float64(b-a)), 0)
	r := math.Min(math.Floor(float64(x-b*m)/float64(a-b)), float64(m))
	return l <= r
}

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

package main

import (
	"fmt"
	"math"
)

func main() {
	var t int64
	fmt.Scanf("%d\n", &t)

	// res := make([]int64, 0, t)
	for ; t > 0; t-- {
		var x, y, a, b int64
		fmt.Scanf("%d%d%d%d\n", &x, &y, &a, &b)
		fmt.Println(giftSet(x, y, a, b))
		// res = append(res, giftSet(x, y, a, b))
	}

	// for _, num := range res {
	// 	fmt.Println(num)
	// }
}

func giftSet(x, y, a, b int64) int64 {
	if a == b {
		return Min(x, y) / a
	}

	if a < b {
		a, b = b, a
	}

	out := int64(0)
	l, r := int64(0), int64(1e9+1)
	for l < r {
		m := l + (r-l+1)>>1
		if isValid(x, y, a, b, m) {
			out = m
			l = m
		} else {
			r = m - 1
		}
	}
	return out
}

func isValid(x, y, a, b, m int64) bool {
	return math.Max(math.Ceil(float64(y-a*m)/float64(b-a)), 0) <=
		math.Min(math.Floor(float64(x-b*m)/float64(a-b)), float64(m))
}

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

package main

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

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

	type pair struct {
		x, y int
	}
	var t int
	for Fscan(in, &t); t > 0; t-- {
		var x, y, a, b int
		Fscan(in, &x, &y, &a, &b)

		if a == b {
			Fprintln(out, min(x, y) / a)
			continue
		}
		if a < b {
			a, b = b, a
		}

		left, right := 0, (x + y) / (a + b)
		for left < right {
			mid := left + ((right - left + 1) >> 1)
			lower := int(math.Ceil(float64(y - a * mid) / float64(b - a)))
			upper := int(math.Floor(float64(x - b * mid) / float64(a - b)))
			if max(0, lower) <= min(upper, mid) {
				left = mid
			} else {
				right = mid - 1
			}
		}
		Fprintln(out, left)
	}
}

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

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

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

package main

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

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

	type pair struct {
		x, y int
	}
	var t int
	for Fscan(in, &t); t > 0; t-- {
		var x, y, a, b int
		Fscan(in, &x, &y, &a, &b)

		if a == b {
			Fprintln(out, min(x, y) / a)
			continue
		}
		if a < b {
			a, b = b, a
		}

		left, right := 0, (x + y) / (a + b)
		for left < right {
			mid := left + ((right - left + 1) >> 1)
			l := max(0, (mid * a - y + a - b - 1) / (a - b))
			r := min(mid, (x - mid * b + a - b) / (a - b) - 1)
			if l <= r {
				left = mid
			} else {
				right = mid - 1
			}
		}
		Fprintln(out, left)
	}
}

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

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

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

package main

import "fmt"

func main() {
	var t int64
	fmt.Scanf("%d\n", &t)

	// res := make([]int64, 0, t)
	for ; t > 0; t-- {
		var x, y, a, b int64
		fmt.Scanf("%d%d%d%d\n", &x, &y, &a, &b)
		fmt.Println(giftSet(x, y, a, b))
		// res = append(res, giftSet(x, y, a, b))
	}

	// for _, num := range res {
	// 	fmt.Println(num)
	// }
}

func giftSet(x, y, a, b int64) int64 {
	if Min(x/a, y/b) < Min(x/b, y/a) {
		a, b = b, a
	}
	i := Min(x/a, y/b)
	if i == 0 || a*i > x || b*i > y {
		return 0
	}

	out := i + Min((x-a*i)/b, (y-b*i)/a)
	if a == b {
		return out
	}

	for i--; i >= 0; i-- {
		res := i + Min((x-a*i)/b, (y-b*i)/a)
		if res <= out {
			break
		}
		out = res
	}
	return out
}

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

package main

import "fmt"

func main() {
	var t int64
	fmt.Scanf("%d\n", &t)

	res := make([]int64, 0, t)
	for ; t > 0; t-- {
		var x, y, a, b int64
		fmt.Scanf("%d%d%d%d\n", &x, &y, &a, &b)
		res = append(res, giftSet(x, y, a, b))
	}

	for _, num := range res {
		fmt.Println(num)
	}
}

func giftSet(x, y, a, b int64) int64 {
	if Min(x/a, y/b) < Min(x/b, y/a) {
		a, b = b, a
	}
	i := Min(x/a, y/b)
	if i == 0 || a*i > x || b*i > y {
		return 0
	}
	return Max(i+Min((x-a*i)/b, (y-b*i)/a), i-1+Min((x-a*(i-1))/b, (y-b*(i-1))/a))
}

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

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

package main

import "fmt"

func main() {
	var t int64
	fmt.Scanf("%d\n", &t)

	res := make([]int64, 0, t)
	for ; t > 0; t-- {
		var x, y, a, b int64
		fmt.Scanf("%d%d%d%d\n", &x, &y, &a, &b)
		res = append(res, giftSet(x, y, a, b))
	}

	for _, num := range res {
		fmt.Println(num)
	}
}

func giftSet(x, y, a, b int64) int64 {
	out := int64(0)
	l, r := int64(1), int64(1)+x/a
	for l < r {
		m := l + (r-l)>>1
		val, ok := isValid(x, y, a, b, m)
		if ok {
			out = Max(out, val)
			l = m + 1
		} else {
			r = m
		}
	}
	if val, ok := isValid(x, y, a, b, l); ok {
		out = Max(out, val)
	}
	l, r = 1, 1+x/b
	for l < r {
		m := l + (r-l)>>1
		val, ok := isValid(x, y, b, a, m)
		if ok {
			out = Max(out, val)
			l = m + 1
		} else {
			r = m
		}
	}
	if val, ok := isValid(x, y, a, b, l); ok {
		out = Max(out, val)
	}
	return out
}

func isValid(x, y, a, b, i int64) (int64, bool) {
	if a*i > x || b*i > y {
		return -1, false
	}
	return i + Min((x-a*i)/b, (y-b*i)/a), true
}

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

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

package main

import "fmt"

func main() {
	var t int64
	fmt.Scanf("%d\n", &t)

	res := make([]int64, 0, t)
	for ; t > 0; t-- {
		var x, y, a, b int64
		fmt.Scanf("%d%d%d%d\n", &x, &y, &a, &b)
		res = append(res, giftSet(x, y, a, b))
	}

	for _, num := range res {
		fmt.Println(num)
	}
}

func giftSet(x, y, a, b int64) int64 {
	out := int64(0)
	l, r := int64(1), int64(1)+int64(x/a)
	for l < r {
		m := l + (r-l)>>1
		val, ok := isValid(x, y, a, b, m)
		if ok {
			out = Max(out, val)
			l = m + 1
		} else {
			r = m
		}
	}
	l, r = 1, 1+x/b
	for l < r {
		m := l + (r-l)>>1
		val, ok := isValid(x, y, b, a, m)
		if ok {
			out = Max(out, val)
			l = m + 1
		} else {
			r = m
		}
	}
	return out
}

func isValid(x, y, a, b, i int64) (int64, bool) {
	if a*i > x || b*i > y {
		return -1, false
	}
	return i + Min((x-a*i)/b, (y-b*i)/a), true
}

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

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

package main

import "fmt"

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

	res := make([]int, 0, t)
	for ; t > 0; t-- {
		var x, y, a, b int
		fmt.Scanf("%d%d%d%d\n", &x, &y, &a, &b)
		res = append(res, giftSet(x, y, a, b))
	}

	for _, num := range res {
		fmt.Println(num)
	}
}

func giftSet(x, y, a, b int) int {
	out := 0
	l, r := 1, 1+x/a
	for l < r {
		m := l + (r-l)>>1
		val, ok := isValid(x, y, a, b, m)
		if ok {
			out = Max(out, val)
			l = m + 1
		} else {
			r = m
		}
	}
	l, r = 1, 1+x/b
	for l < r {
		m := l + (r-l)>>1
		val, ok := isValid(x, y, b, a, m)
		if ok {
			out = Max(out, val)
			l = m + 1
		} else {
			r = m
		}
	}
	return out
}

func isValid(x, y, a, b, i int) (int, bool) {
	if a*i > x || b*i > y {
		return -1, false
	}
	return i + Min((x-a*i)/b, (y-b*i)/a), true
}

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

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

package main

import (
	"bufio"
	. "fmt"
	"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()
	ternarySearchInt := func(l, r int64, f func(x int64) int64) int64 {
		for r-l > 10 {
			m1 := l + (r-l)/3
			m2 := r - (r-l)/3
			v1, v2 := f(m1), f(m2)
			if v1 < v2 {
				l = m1
			} else {
				r = m2
			}
		}
		mx := f(l)
		for i := l + 1; i <= r; i++ {
			if v := f(i); v > mx {
				mx = v
			}
		}
		return mx
	}
	_ = ternarySearchInt

	solve := func(Case int) {
		var x, y, a, b int64
		Fscan(in, &x, &y, &a, &b)
		r := min(x/a, y/b)
		ans := r
		ans = max(ans, min(x/b, y/a))

		res := ternarySearchInt(0, r, func(k1 int64) int64 {
			k2 := min((x-k1*a)/b, (y-k1*b)/a)
			return k1 + k2
		})
		ans = max(ans, res)

		Fprintln(out, ans)
	}

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

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

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

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

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


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

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

var scn = bufio.NewScanner(os.Stdin)

func gets() string {
	scn.Scan()
	return scn.Text()
}

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

func main() {
	n := atoi(gets())
	ans := 0
	next := 1
	a := make([]int, 0, n*2)
	for i := 0; i < 2*n; i++ {
		s := gets()
		if s != "remove" {
			sp := strings.Split(s, " ")
			x := atoi(sp[1])
			a = append(a, x)
		} else {
			sz := len(a)
			if sz > 0 {
				if a[sz-1] != next {
					a = a[:0]
					ans++
				} else {
					a = a[:sz-1]
				}
			}
			next++
		}
	}
	fmt.Println(ans)
}

package main

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

const N = 300007

var stack [N]int
var size = 0

func push(x int) {
	stack[size] = x
	size++
}

func top() int {
	return stack[size-1]
}

func pop() {
	size--
}

func clear() {
	size = 0
}

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 main() {
	var n, x int
	var c string
	fmt.Fscanln(reader, &n)
	ans := 0
	cur := 0
	balanced := make(map[int]bool)
	for i := 0; i < n*2; i++ {
		fmt.Fscan(reader, &c)
		if c == "add" {
			fmt.Fscan(reader, &x)
			push(x)
		} else {
			cur++
			if size > 0 && top() == cur {
				pop()
			} else if !balanced[cur] || (size > 0 && !balanced[top()]) {
				ans++
				for j := 0; j < size; j++ {
					balanced[stack[j]] = true
				}
				clear()
			}
		}
	}
	fmt.Println(ans)
}

package main

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

var fileName = ""
var sc *Scanner = getScanner()
var w *bufio.Writer = bufio.NewWriter(os.Stdout)

func getScanner() *Scanner {
	if len(fileName) <= 0 {
		return NewScanner(os.Stdin)
	}
	var file, err = os.Open(fileName)
	if err != nil {
		panic(err)
	}
	return NewScanner(bufio.NewReader(file))
}

type Scanner struct {
	r            io.Reader
	split        bufio.SplitFunc
	maxTokenSize int
	token, buf   []byte
	start, end   int
}

func NewScanner(r io.Reader) *Scanner {
	return &Scanner{
		r:            r,
		split:        bufio.ScanWords,
		maxTokenSize: 16777216,
		buf:          make([]byte, 4096),
	}
}

func (s *Scanner) advance(n int) bool {
	if n < 0 || n > s.end-s.start {
		return false
	}
	s.start += n
	return true
}

func (s *Scanner) Text() string {
	return string(s.token)
}

func (s *Scanner) Scan() bool {
	for {
		if s.end > s.start {
			advance, token, err := s.split(s.buf[s.start:s.end], false)
			if err != nil || !s.advance(advance) {
				return false
			}
			s.token = token
			if token != nil {
				return true
			}
		}
		if s.start > 0 && (s.end == len(s.buf) || s.start > len(s.buf)/2) {
			copy(s.buf, s.buf[s.start:s.end])
			s.end -= s.start
			s.start = 0
		}
		if s.end == len(s.buf) {
			if len(s.buf) >= s.maxTokenSize {
				return false
			}
			newSize := len(s.buf) * 2
			if newSize > s.maxTokenSize {
				newSize = s.maxTokenSize
			}
			newBuf := make([]byte, newSize)
			copy(newBuf, s.buf[s.start:s.end])
			s.buf = newBuf
			s.end -= s.start
			s.start = 0
			continue
		}
		for loop := 0; ; {
			n, _ := s.r.Read(s.buf[s.end:len(s.buf)])
			s.end += n
			if n > 0 {
				break
			}
			loop++
			if loop > 100 {
				break
			}
		}
	}
}

func (s *Scanner) Split(split bufio.SplitFunc) {
	s.split = split
}

func printSpace() { w.WriteByte(' ') }
func println()    { w.WriteByte('\n') }

func nextToken() string { sc.Scan(); return sc.Text() }

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

func nextInt64() int64 {
	sc.Scan()
	n, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return n
}

func printInt(i ...int) {
	for _, ii := range i {
		w.WriteString(strconv.Itoa(ii))
		printSpace()
	}
}

func printInt64(i ...int64) {
	for _, ii := range i {
		w.WriteString(strconv.FormatInt(ii, 10))
		printSpace()
	}
}

func print(s ...string) {
	for _, ss := range s {
		w.WriteString(ss)
		printSpace()
	}
}

func min(i, j int) int {
	if i < j {
		return i
	}
	return j
}

func max(i, j int) int {
	if i > j {
		return i
	}
	return j
}

func min64(i, j int64) int64 {
	if i < j {
		return i
	}
	return j
}

func max64(i, j int64) int64 {
	if i > j {
		return i
	}
	return j
}

func main() {
	defer w.Flush()

	n := nextInt()
	a := make([]int, n)
	r := make([]bool, n)
	sz := 0
	ans := 0
	numR := 0
	for k := 0; k < 2 * n; k++ {
		cmd := nextToken()
		if cmd == "add" {
			num := nextInt()
			a[sz] = num
			r[sz] = false
			sz++
		} else {
			numR++
			good := r[sz - 1] || a[sz - 1] == numR
			if !good {
				r[sz - 1] = true
				ans++
			}
			sz--
			if sz > 0 {
				r[sz-1] = r[sz-1] || r[sz]
			}
		}
	}
	printInt(ans)
}

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

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)
	ans := 0
	next := 1
	a := []int{}
	for i := 0; i < 2*n; i++ {
		var s string
		fmt.Scan(&s)
		if s == "add" {
			var x int
			fmt.Scan(&x)
			a = append(a, x)
		} else {
			sz := len(a) - 1
			p := a[sz]
			if p != next {
				fmt.Println(p, next)
				sort.Sort(sort.Reverse(sort.IntSlice(a)))
				ans++
			}
			a = a[:sz]
			next++
		}
	}
	fmt.Println(ans)
}

package main

import "fmt"

const N = 300007

var stack [N]int
var size = 0

func push(x int) {
	stack[size] = x
	size++
}

func top() int {
	return stack[size-1]
}

func pop() {
	size--
}

func clear() {
	size = 0
}

func main() {
	var n, x int
	var c string
	fmt.Scanln(&n)
	ans := 0
	cur := 0
	balanced := make(map[int]bool)
	for i := 0; i < n*2; i++ {
		fmt.Scan(&c)
		if c == "add" {
			fmt.Scan(&x)
			push(x)
		} else {
			cur++
			if size > 0 && top() == cur {
				pop()
			} else if !balanced[cur] {
				ans++
				for j := 0; j < size; j++ {
					balanced[stack[j]] = true
				}
				clear()
			}
		}
	}
	fmt.Println(ans)
}


package main

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

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

func solve(a []int64) []int64 {
	n := int64(len(a))
	sum := int64(0)
	for _, v := range a {
		sum += v
	}
	x := (sum - n*(n-1)/2)/n
	y := int64(0)

	ans := make([]int64, n)
	for i := range ans {
		ans[i] = x + int64(i)
		y += ans[i]
	}
	for i := range ans {
		if y < sum {
			ans[i]++
			y++
		}
	}
	return ans
}

func main() {
	// ioutil.WriteFile("input.txt", []byte(generateInput()), os.ModeExclusive)

	debug := 1
	filename := "input.txt"
	if  debug != 0 && len(os.Args)>1 && os.Args[1] == "debug" {
		file, _ := os.Open(filename)
		reader = bufio.NewReader(file)
	} else {
		reader = bufio.NewReader(os.Stdin)
	}
	writer = bufio.NewWriter(os.Stdout)
	//file, _ := os.OpenFile("output.txt", os.O_CREATE|os.O_WRONLY, 0644)
	//writer = bufio.NewWriter(file)

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
	}
	ans := solve(a)
	for _, v := range ans {
		fmt.Fprintf(writer, "%d ", v)
	}

	writer.Flush()
}

func readInts() []int64 {
	line := readLine()
	fields := strings.Fields(line)
	res := make([]int64, len(fields))
	for i := range fields {
		v, _ := strconv.ParseInt(fields[i], 10, 64)
		res[i] = int64(v)
	}
	return res
}

func readInt() int {
	line := readLine()
	n, _ := strconv.ParseInt(line, 10, 64)
	return int(n)
}

func readLine() string {
	str, err := reader.ReadString('\n')
	if err == bufio.ErrBufferFull {
		panic(err)
	}

	return strings.TrimRight(str, "\r\n")
}

package main

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

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

	n := readNum(reader)

	H := make([]int64, n)
	s, _ := reader.ReadBytes('\n')
	var pos int
	for i := 0; i < n; i++ {
		var x uint64
		pos = readUint64(s, pos, &x) + 1
		H[i] = int64(x)
	}

	res := solve(n, H)

	var buf bytes.Buffer

	for i := 0; i < n; i++ {
		buf.WriteString(fmt.Sprintf("%d ", res[i]))
	}
	buf.WriteByte('\n')
	fmt.Print(buf.String())
}

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

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

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

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

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

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

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

	return i
}
func solve(n int, H []int64) []int64 {
	if n == 1 {
		return H
	}
	var sum int64
	for i := 0; i < n; i++ {
		sum += H[i]
	}
	// if (a + a + n - 1) * n / 2 == sum
	// (2 * a + n - 1) = 2 * sum / n
	N := int64(n)
	if 2*sum%N == 0 {
		m := 2 * sum / N
		m += 1 - N
		if m > 0 && m%2 == 0 {
			a := m / 2
			for i := 0; i < n; i++ {
				H[i] = a + int64(i)
			}
			return H
		}
	}

	// then there should be one adjacent pair that H[i] == H[i+1] in the result.
	// (a + a + n - 2) * (n - 1) / 2 + H[k] = sum
	// where k is the same pair index
	// H[k] = a + k
	// (2 * a + n - 2) * (n - 1) / 2 + a + k == sum
	// (2 * a + n - 2) * (n - 1) + 2 * a  + 2 * k == 2 * sum
	sum *= 2
	// 2 * a * (n - 1) + 2 * a + (n - 2) * (n - 1) + 2 * k == 2 * sum
	sum -= (N - 2) * (N - 1)
	// 2 * a * n + 2 * k == 2 * sum - (N - 2) * (N - 1)
	for k := 0; k < n-1; k++ {
		// if k == i
		tmp := sum - 2*int64(k)
		if tmp%(2*N) == 0 {
			// found
			a := tmp / (2 * N)
			//a := m / 2
			for i := 0; i < n; i++ {
				H[i] = a + int64(i)
				if i >= k + 1 {
					H[i]--
				}
			}

			break
		}
	}
	return H
}

package main

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

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

func solve(a []int64) []int64 {
	n := int64(len(a))
	sum := int64(0)
	for _, v := range a {
		sum += v
	}
	x := (sum - n*(n-1)/2)/n
	y := int64(0)

	ans := make([]int64, n)
	for i := range ans {
		ans[i] = x + int64(i)
		y += ans[i]
	}
	for i := range ans {
		if y < sum {
			ans[i]++
			y++
		}
	}
	return ans
}

func main() {
	// ioutil.WriteFile("input.txt", []byte(generateInput()), os.ModeExclusive)

	debug := 1
	filename := "input.txt"
	if  debug != 0 && len(os.Args)>1 && os.Args[1] == "debug" {
		file, _ := os.Open(filename)
		reader = bufio.NewReader(file)
	} else {
		reader = bufio.NewReader(os.Stdin)
	}
	writer = bufio.NewWriter(os.Stdout)
	//file, _ := os.OpenFile("output.txt", os.O_CREATE|os.O_WRONLY, 0644)
	//writer = bufio.NewWriter(file)

	_ = readInt()
	a := readInts()
	ans := solve(a)
	str := fmt.Sprint(ans)
	str = str[1:len(str)-1]
	writer.WriteString(str)
	writer.Flush()
}

func readInts() []int64 {
	line := readLine()
	fields := strings.Fields(line)
	res := make([]int64, len(fields))
	for i := range fields {
		v, _ := strconv.ParseInt(fields[i], 10, 64)
		res[i] = int64(v)
	}
	return res
}

func readInt() int {
	line := readLine()
	n, _ := strconv.ParseInt(line, 10, 64)
	return int(n)
}

func readLine() string {
	str, err := reader.ReadString('\n')
	if err == bufio.ErrBufferFull {
		panic(err)
	}

	return strings.TrimRight(str, "\r\n")
}

package main

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

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

func solve(a []int64) []int64 {
	n := int64(len(a))
	sum := int64(0)
	for _, v := range a {
		sum += v
	}
	x := (sum - n*(n-1)/2)/n
	y := int64(0)

	ans := make([]int64, n)
	for i := range ans {
		ans[i] = x + int64(i)
		y += ans[i]
	}
	for i := range ans {
		if y < sum {
			ans[i]++
			y++
		}
	}
	return ans
}

func main() {
	// ioutil.WriteFile("input.txt", []byte(generateInput()), os.ModeExclusive)

	debug := 1
	filename := "input.txt"
	if  debug != 0 && len(os.Args)>1 && os.Args[1] == "debug" {
		file, _ := os.Open(filename)
		reader = bufio.NewReaderSize(file, 1024*1024)
	} else {
		reader = bufio.NewReaderSize(os.Stdin, 1024*1024)
	}
	writer = bufio.NewWriterSize(os.Stdout, 1024 * 1024)
	//file, _ := os.OpenFile("output.txt", os.O_CREATE|os.O_WRONLY, 0644)
	//writer = bufio.NewWriter(file)

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
	}
	ans := solve(a)
	str := fmt.Sprint(ans)
	str = str[1:len(str)-1]
	fmt.Fprintln(writer, str)

	writer.Flush()
}

func readInts() []int64 {
	line := readLine()
	fields := strings.Fields(line)
	res := make([]int64, len(fields))
	for i := range fields {
		v, _ := strconv.ParseInt(fields[i], 10, 64)
		res[i] = int64(v)
	}
	return res
}

func readInt() int {
	line := readLine()
	n, _ := strconv.ParseInt(line, 10, 64)
	return int(n)
}

func readLine() string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

package main

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

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

func solve(a []int64) []int64 {
	n := int64(len(a))
	sum := int64(0)
	for _, v := range a {
		sum += v
	}
	x := (sum - n*(n-1)/2)/n
	y := int64(0)

	ans := make([]int64, n)
	for i := range ans {
		ans[i] = x + int64(i)
		y += ans[i]
	}
	for i := range ans {
		if y < sum {
			ans[i]++
			y++
		}
	}
	return ans
}

func main() {
	// ioutil.WriteFile("input.txt", []byte(generateInput()), os.ModeExclusive)

	debug := 1
	filename := "input.txt"
	var scanner *bufio.Scanner
	if  debug != 0 && len(os.Args)>1 && os.Args[1] == "debug" {
		file, _ := os.Open(filename)
		reader = bufio.NewReader(file)
		scanner = bufio.NewScanner(file)
	} else {
		reader = bufio.NewReader(os.Stdin)
		scanner = bufio.NewScanner(os.Stdin)
	}
	writer = bufio.NewWriter(os.Stdout)
	//file, _ := os.OpenFile("output.txt", os.O_CREATE|os.O_WRONLY, 0644)
	//writer = bufio.NewWriter(file)
	scanner.Split(bufio.ScanWords)

	//_ = readInt()
	//a := readInts()
	scanner.Scan()
	text := scanner.Text()
	n, _ := strconv.ParseInt(text, 10, 64)
	a := make([]int64, n)
	for i := range a {
		scanner.Scan()
		text := scanner.Text()
		a[i], _ = strconv.ParseInt(text, 10, 64)
	}
	ans := solve(a)
	str := fmt.Sprint(ans)
	str = str[1:len(str)-1]
	writer.WriteString(str)
	writer.Flush()
}

func readInts() []int64 {
	line := readLine()
	fields := strings.Fields(line)
	res := make([]int64, len(fields))
	for i := range fields {
		v, _ := strconv.ParseInt(fields[i], 10, 64)
		res[i] = int64(v)
	}
	return res
}

func readInt() int {
	line := readLine()
	n, _ := strconv.ParseInt(line, 10, 64)
	return int(n)
}

func readLine() string {
	str, err := reader.ReadString('\n')
	if err != io.EOF {
		panic(err)
	}

	return strings.TrimRight(str, "\r\n")
}

package main

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

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

func solve(a []int64) []int64 {
	n := int64(len(a))
	sum := int64(0)
	for _, v := range a {
		sum += v
	}
	x := (sum - n*(n-1)/2)/n
	y := int64(0)

	ans := make([]int64, n)
	for i := range ans {
		ans[i] = x + int64(i)
		y += ans[i]
	}
	for i := range ans {
		if y < sum {
			ans[i]++
			y++
		}
	}
	return ans
}

func main() {
	// ioutil.WriteFile("input.txt", []byte(generateInput()), os.ModeExclusive)

	debug := 1
	filename := "input.txt"
	if  debug != 0 && len(os.Args)>1 && os.Args[1] == "debug" {
		file, _ := os.Open(filename)
		reader = bufio.NewReaderSize(file, 1024*1024)
	} else {
		reader = bufio.NewReaderSize(os.Stdin, 1024*1024)
	}
	writer = bufio.NewWriterSize(os.Stdout, 1024 * 1024)
	//file, _ := os.OpenFile("output.txt", os.O_CREATE|os.O_WRONLY, 0644)
	//writer = bufio.NewWriter(file)

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
	}
	ans := solve(a)
	for _, v := range ans {
		fmt.Fprintf(writer, "%d ", v)
	}

	writer.Flush()
}

func readInts() []int64 {
	line := readLine()
	fields := strings.Fields(line)
	res := make([]int64, len(fields))
	for i := range fields {
		v, _ := strconv.ParseInt(fields[i], 10, 64)
		res[i] = int64(v)
	}
	return res
}

func readInt() int {
	line := readLine()
	n, _ := strconv.ParseInt(line, 10, 64)
	return int(n)
}

func readLine() string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

package main

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

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

	n := readNum(reader)

	H := make([]int64, n)
	s, _ := reader.ReadBytes('\n')
	var pos int
	for i := 0; i < n; i++ {
		var x uint64
		pos = readUint64(s, pos, &x) + 1
		H[i] = int64(x)
	}

	res := solve(n, H)

	var buf bytes.Buffer

	for i := 0; i < n; i++ {
		buf.WriteString(fmt.Sprintf("%d ", res[i]))
	}
	buf.WriteByte('\n')
	fmt.Print(buf.String())
}

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

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

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

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

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

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

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

	return i
}
func solve(n int, H []int64) []int64 {

	var sum int64

	for i := 0; i < n; i++ {
		sum += H[i]
	}

	check := func(h0 int64) bool {
		// if h[0] = h0
		var need = h0 - H[0]
		var prev = h0

		for i := 1; i < n; i++ {
			cur := prev
			diff := H[i] - H[i-1]

			cur += diff & 1

			if cur >= H[i] {
				need += cur - H[i]
			} else {
				need -= H[i] - cur
			}
			if need < 0 {
				return false
			}
			prev = cur
		}
		return need <= 0
	}

	var left = H[0]
	var right = H[n-1] + 1

	for left < right {
		mid := left + (right-left)/2
		if !check(mid) {
			right = mid
		} else {
			left = mid + 1
		}
	}

	X := make([]int64, n)
	X[0] = right - 1

	for i := 1; i < n; i++ {
		X[i] = X[i-1] + (H[i]-H[i-1])&1
	}

	return X
}

package main

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

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

func solve(a []int64) []int64 {
	n := int64(len(a))
	sum := int64(0)
	for _, v := range a {
		sum += v
	}
	tmp := sum - n*(n-1)/2
	a1 := tmp / n
	i := tmp - a1*n

	ans := make([]int64, n)
	for j := int64(0); j < i; j++ {
		ans[j] = a1+j+1
	}
	for j := i; j < n; j++ {
		ans[j] = a1+j
	}
	return ans
}

func main() {
	//ioutil.WriteFile("input.txt", []byte(generateInput()), os.ModeExclusive)

	debug := 1
	filename := "input.txt"
	if  debug != 0 && len(os.Args)>1 && os.Args[1] == "debug" {
		file, _ := os.Open(filename)
		reader = bufio.NewReaderSize(file, 1024*1024)
	} else {
		reader = bufio.NewReaderSize(os.Stdin, 1024*1024)
	}
	writer = bufio.NewWriterSize(os.Stdout, 1024 * 1024)

	_ = readInt()
	a := readInts()
	ans := solve(a)
	str := fmt.Sprint(ans)
	str = str[1:len(str)-1]
	fmt.Fprintln(writer, str)

	writer.Flush()
}

func readInts() []int64 {
	line := readLine()
	fields := strings.Fields(line)
	res := make([]int64, len(fields))
	for i := range fields {
		v, _ := strconv.ParseInt(fields[i], 10, 64)
		res[i] = int64(v)
	}
	return res
}

func readInt() int {
	line := readLine()
	n, _ := strconv.ParseInt(line, 10, 64)
	return int(n)
}

func readLine() string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

package main

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

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

func solve(a []int64) []int64 {
	n := int64(len(a))
	sum := int64(0)
	for _, v := range a {
		sum += v
	}
	x := (sum - n*(n-1)/2)/n
	y := int64(0)

	ans := make([]int64, n)
	for i := range ans {
		ans[i] = x + int64(i)
		y += ans[i]
	}
	for i := range ans {
		if y < sum {
			ans[i]++
			y++
		}
	}
	return ans
}

func main() {
	//ioutil.WriteFile("input.txt", []byte(generateInput()), os.ModeExclusive)

	debug := 1
	filename := "input.txt"
	if  debug != 0 && len(os.Args)>1 && os.Args[1] == "debug" {
		file, _ := os.Open(filename)
		reader = bufio.NewReaderSize(file, 1024*1024)
	} else {
		reader = bufio.NewReaderSize(os.Stdin, 1024*1024)
	}
	writer = bufio.NewWriterSize(os.Stdout, 1024 * 1024)

	_ = readInt()
	a := readInts()
	ans := solve(a)
	str := fmt.Sprint(ans)
	str = str[1:len(str)-1]
	fmt.Fprintln(writer, str)

	writer.Flush()
}

func readInts() []int64 {
	line := readLine()
	fields := strings.Fields(line)
	res := make([]int64, len(fields))
	for i := range fields {
		v, _ := strconv.ParseInt(fields[i], 10, 64)
		res[i] = int64(v)
	}
	return res
}

func readInt() int {
	line := readLine()
	n, _ := strconv.ParseInt(line, 10, 64)
	return int(n)
}

func readLine() string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

package main

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

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

func solve(a []int64) []int64 {
	n := int64(len(a))
	sum := int64(0)
	for _, v := range a {
		sum += v
		if sum < 0 {
			panic("sum")
		}
	}
	if n*(n-1) < 0 {
		panic("n*(n-1)")
	}
	tmp := sum - n*(n-1)/2
	if tmp < 0 {
		panic("tmp")
	}
	a1 := tmp / n
	i := int64(0)
	if a1 * n < tmp {
		a1++
		i = n - (a1*n - tmp)
	}
	if i < 0 {
		panic("i")
	}

	ans := make([]int64, n)
	if i == 0 {
		for j := range ans {
			ans[j] = a1 + int64(j)
		}
	} else {
		i--
		for j := int64(0); j <= i; j++ {
			ans[j] = a1+j
		}
		for j := i; j < n-1; j++ {
			ans[j+1] = a1+j
		}
	}
	return ans
}

func main() {
	//ioutil.WriteFile("input.txt", []byte(generateInput()), os.ModeExclusive)

	debug := 1
	filename := "input.txt"
	if  debug != 0 && len(os.Args)>1 && os.Args[1] == "debug" {
		file, _ := os.Open(filename)
		reader = bufio.NewReaderSize(file, 1024*1024)
	} else {
		reader = bufio.NewReaderSize(os.Stdin, 1024*1024)
	}
	writer = bufio.NewWriterSize(os.Stdout, 1024 * 1024)

	_ = readInt()
	a := readInts()
	ans := solve(a)
	str := fmt.Sprint(ans)
	str = str[1:len(str)-1]
	fmt.Fprintln(writer, str)

	writer.Flush()
}

func readInts() []int64 {
	line := readLine()
	fields := strings.Fields(line)
	res := make([]int64, len(fields))
	for i := range fields {
		v, _ := strconv.ParseInt(fields[i], 10, 64)
		res[i] = int64(v)
	}
	return res
}

func readInt() int {
	line := readLine()
	n, _ := strconv.ParseInt(line, 10, 64)
	return int(n)
}

func readLine() string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

package main

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

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

func solve(a []int) []int {
	n := len(a)
	sum := 0
	for _, v := range a {
		sum += v
	}
	tmp := sum - n*(n-1)/2
	a1 := tmp / n
	i := 0
	if a1 * n < tmp {
		a1++
		i = n - (a1*n - tmp)
	}

	ans := make([]int, n)
	if i == 0 {
		for j := range ans {
			ans[j] = a1+j
		}
	} else {
		i--
		for j := 0; j <= i; j++ {
			ans[j] = a1+j
		}
		for j := i; j < n-1; j++ {
			ans[j+1] = a1+j
		}
	}
	return ans
}

func main() {
	//ioutil.WriteFile("input.txt", []byte(generateInput()), os.ModeExclusive)

	debug := 1
	filename := "input.txt"
	if  debug != 0 && len(os.Args)>1 && os.Args[1] == "debug" {
		file, _ := os.Open(filename)
		reader = bufio.NewReaderSize(file, 1024*1024)
	} else {
		reader = bufio.NewReaderSize(os.Stdin, 1024*1024)
	}
	writer = bufio.NewWriterSize(os.Stdout, 1024 * 1024)

	_ = readInt()
	a := readInts()
	ans := solve(a)
	str := fmt.Sprint(ans)
	str = str[1:len(str)-1]
	fmt.Fprintln(writer, str)

	writer.Flush()
}

func readInts() []int {
	line := readLine()
	fields := strings.Fields(line)
	res := make([]int, len(fields))
	for i := range fields {
		v, _ := strconv.ParseInt(fields[i], 10, 64)
		res[i] = int(v)
	}
	return res
}

func readInt() int {
	line := readLine()
	n, _ := strconv.ParseInt(line, 10, 64)
	return int(n)
}

func readLine() string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

package main

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

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

func solve(a []int64) []int64 {
	n := int64(len(a))
	sum := int64(0)
	for _, v := range a {
		sum += v
	}
	x := (sum - n*(n-1)/2)/n
	y := int64(0)

	ans := make([]int64, n)
	for i := range ans {
		ans[i] = x + int64(i)
		y += ans[i]
	}
	for i := range ans {
		if y < sum {
			ans[i]++
			y++
		}
	}
	return ans
}

func main() {
	// ioutil.WriteFile("input.txt", []byte(generateInput()), os.ModeExclusive)

	debug := 1
	filename := "input.txt"
	if  debug != 0 && len(os.Args)>1 && os.Args[1] == "debug" {
		file, _ := os.Open(filename)
		reader = bufio.NewReaderSize(file, 1024*1024)
	} else {
		reader = bufio.NewReaderSize(os.Stdin, 1024*1024)
	}
	//writer = bufio.NewWriterSize(os.Stdout, 1024 * 1024)
	file, _ := os.OpenFile("output.txt", os.O_CREATE|os.O_WRONLY, 0644)
	writer = bufio.NewWriter(file)

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%d", &a[i])
	}
	ans := solve(a)
	str := fmt.Sprint(ans)
	str = str[1:len(str)-1]
	fmt.Fprintln(writer, str)

	writer.Flush()
}

func readInts() []int64 {
	line := readLine()
	fields := strings.Fields(line)
	res := make([]int64, len(fields))
	for i := range fields {
		v, _ := strconv.ParseInt(fields[i], 10, 64)
		res[i] = int64(v)
	}
	return res
}

func readInt() int {
	line := readLine()
	n, _ := strconv.ParseInt(line, 10, 64)
	return int(n)
}

func readLine() string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

package main

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

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

func solve(a []int) []int {
	n := len(a)
	sum := 0
	for _, v := range a {
		sum += v
	}
	tmp := sum - n*(n-1)/2
	a1 := tmp / n
	i := 0
	if a1 * n < tmp {
		a1++
		i = n - (a1*n - tmp)
	}

	ans := make([]int, n)
	if i == 0 {
		for j := range ans {
			ans[j] = a1+j
		}
	} else {
		i--
		for j := 0; j <= i; j++ {
			ans[j] = a1+j
		}
		for j := i; j < n-1; j++ {
			ans[j+1] = a1+j
		}
	}
	return ans
}

func main() {
	//ioutil.WriteFile("input.txt", []byte(generateInput()), os.ModeExclusive)

	debug := 1
	filename := "input.txt"
	if  debug != 0 && len(os.Args)>1 && os.Args[1] == "debug" {
		file, _ := os.Open(filename)
		reader = bufio.NewReaderSize(file, 1024*1024)
	} else {
		reader = bufio.NewReaderSize(os.Stdin, 1024*1024)
	}
	writer = bufio.NewWriterSize(os.Stdout, 1024 * 1024)

	_ = readInt()
	a := readInts()
	ans := solve(a)
	fmt.Fprintln(writer, ans)

	writer.Flush()
}

func readInts() []int {
	line := readLine()
	fields := strings.Fields(line)
	res := make([]int, len(fields))
	for i := range fields {
		v, _ := strconv.ParseInt(fields[i], 10, 64)
		res[i] = int(v)
	}
	return res
}

func readInt() int {
	line := readLine()
	n, _ := strconv.ParseInt(line, 10, 64)
	return int(n)
}

func readLine() string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}

package main

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

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

func solve(a []int64) []int64 {
	n := int64(len(a))
	sum := int64(0)
	for _, v := range a {
		sum += v
	}
	tmp := sum - n*(n-1)/2
	a1 := tmp / n
	i := int64(0)
	if a1 * n < tmp {
		a1++
		i = n - (a1*n - tmp)
	}

	ans := make([]int64, n)
	if i == 0 {
		for j := range ans {
			ans[j] = a1+ int64(j)
		}
	} else {
		i--
		for j := int64(0); j <= i; j++ {
			ans[j] = a1+j
		}
		for j := i; j < n-1; j++ {
			ans[j+1] = a1+j
		}
	}
	return ans
}

func main() {
	//ioutil.WriteFile("input.txt", []byte(generateInput()), os.ModeExclusive)

	debug := 1
	filename := "input.txt"
	if  debug != 0 && len(os.Args)>1 && os.Args[1] == "debug" {
		file, _ := os.Open(filename)
		reader = bufio.NewReaderSize(file, 1024*1024)
	} else {
		reader = bufio.NewReaderSize(os.Stdin, 1024*1024)
	}
	writer = bufio.NewWriterSize(os.Stdout, 1024 * 1024)

	_ = readInt()
	a := readInts()
	ans := solve(a)
	str := fmt.Sprint(ans)
	str = str[1:len(str)-1]
	fmt.Fprintln(writer, str)

	writer.Flush()
}

func readInts() []int64 {
	line := readLine()
	fields := strings.Fields(line)
	res := make([]int64, len(fields))
	for i := range fields {
		v, _ := strconv.ParseInt(fields[i], 10, 64)
		res[i] = int64(v)
	}
	return res
}

func readInt() int {
	line := readLine()
	n, _ := strconv.ParseInt(line, 10, 64)
	return int(n)
}

func readLine() string {
	str, _, err := reader.ReadLine()
	if err == io.EOF {
		return ""
	}

	return strings.TrimRight(string(str), "\r\n")
}