Due to the coronavirus pandemic, city authorities obligated citizens to keep a social distance. The mayor of the city Semyon wants to light up Gluharniki park so that people could see each other even at night to keep the social distance.The park is a rectangular table with $$$n$$$ rows and $$$m$$$ columns, where the cells of the table are squares, and the boundaries between the cells are streets. External borders are also streets. Every street has length $$$1$$$. For example, park with $$$n=m=2$$$ has $$$12$$$ streets.You were assigned to develop a plan for lighting the park. You can put lanterns in the middle of the streets. The lamp lights two squares near it (or only one square if it stands on the border of the park).    The park sizes are: $$$n=4$$$, $$$m=5$$$. The lighted squares are marked yellow. Please note that all streets have length $$$1$$$. Lanterns are placed in the middle of the streets. In the picture not all the squares are lit. Semyon wants to spend the least possible amount of money on lighting but also wants people throughout the park to keep a social distance. So he asks you to find the minimum number of lanterns that are required to light all the squares.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case is a line containing two integers $$$n$$$, $$$m$$$ ($$$1 \le n, m \le 10^4$$$) — park sizes.

Print $$$t$$$ answers to the test cases. Each answer must be a single integer — the minimum number of lanterns that are required to light all the squares.

NotePossible optimal arrangement of the lanterns for the $$$2$$$-nd test case of input data example: Possible optimal arrangement of the lanterns for the $$$3$$$-rd test case of input data example:

package main

import "fmt"

func main() {
	var T int
	fmt.Scan(&T)
	var answers = make([]int, T)

	for i := 0; i < T; i++ {
		var rows, columns int
		fmt.Scan(&rows)
		fmt.Scan(&columns)
		answers[i] = findLightCount(rows, columns)
	}

	for _, ans := range answers {
		fmt.Println(ans)
	}
}

func findLightCount(rows, columns int) int {
	if (rows*columns)%2 == 0 {
		return (rows * columns) / 2
	}
	return ((rows*columns)/2 + 1)
}

package main

import "fmt"

func main() {
	var testCases int
	var m int
	var n int
	var result int

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

	for i := 0; i < testCases; i++ {
		fmt.Scanf("%d%d\n", &m, &n)
		if (m*n)%2 == 0 {
			result = m*n/2
			fmt.Printf("%d\n", result)
		} else {
			result = n*m/2 + 1
			fmt.Printf("%d\n", result)
		}
	}
}

package main

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

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

	var t, n, m int
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m)
		Fprintln(out, (n*m+1)/2)
	}
}

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

package main

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

func main() {
	defer out.Flush()
	for t := ScanInt(); t > 0; t-- {
		P(solve())
	}
}

func solve() int {
	n, m := ScanInt(), ScanInt()
	sq := n * m
	return (sq / 2) + (sq % 2)
}

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

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

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

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

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

		}
		out.WriteString(str + seperator)
	}
}

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

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

package main

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

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

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

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

package main
import "fmt"
func main(){
    var t, n, m, ans int
    fmt.Scan(&t)
    for ; t > 0; t-- {
        fmt.Scan(&n, &m)
        if m == 1 {
            ans = (n+1)/2
        }else if n == 1 {
            ans = (m+1)/2
        }else if m % 2 == 0 {
            ans = (m / 2) * n
        }else {
            ans = ((m-1)/2)*n + ((n+1)/2)
        }
        fmt.Println(ans)
    }
}

package main

import "fmt"

func CountLamps(n, m int) int {
	if m > n {
		n, m = m, n
	}
	return n/2 * m + (n % 2) * (m / 2 + m%2)
}

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

	for i := 0; i < t; i++ {
		var n, m int
		fmt.Scan(&n, &m)
		fmt.Println(CountLamps(n, m))
	}
}

package main

import (
	"fmt"
)

func main(){
	var T int
	fmt.Scan(&T)
	for t := 0; t < T; t++ {
		var n, m int
		fmt.Scan(&n, &m)
		if n%2 == 0 || m%2 == 0 {
			ans := (n*m) >> 1
			fmt.Println(ans)
		} else {
			ans := (n*m + 1) >> 1
			fmt.Println(ans)
		}
	}
}

package main

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

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

	var t int
	fmt.Fscan(r, &t)

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

		fmt.Fprintln(w, p/2+p%2)
	}
}

package main

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

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

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

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

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

type WordScanner interface {
	Int64() int64
	UInt64() uint64
	String() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) Int64() int64 {
	impl.Scan()
	bb := impl.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 (impl *wordScannerImpl) UInt64() uint64 {
	impl.Scan()
	bb := impl.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) String() string {
	impl.Scan()
	return impl.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
}

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

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

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

func sol(n, m int64) int64 {
	if n * m % 2 == 0 {
		return n * m / 2
	}
	return n * m / 2 + 1
}

package main

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

func main() {
	var t, n, m int
	in := bufio.NewReader(os.Stdin)
	fmt.Fscan(in, &t)
	for i := 0; i < t; i++ {
		fmt.Fscan(in, &n, &m)
		ans := n / 2 * m
		if n%2 == 1 {
			ans += m / 2
			if m%2 == 1 {
				ans++
			}
		}
		fmt.Println(ans)
	}
}

package main

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

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

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n, m := readTwoNums(reader)
		fmt.Println(solve(n, m))
	}
}

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, m int) int64 {
	if n%2 == 0 || m%2 == 0 {
		return int64(m) * int64(n) / 2
	}
	res := int64(n-1) * int64(m) / 2
	res += int64(m) / 2
	res++

	return res
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(1)
	fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		n, m := int64(0), int64(0)
		fmt.Fscanf(in, "%d %d\n", &n, &m)
		fmt.Fprintf(out, "%d\n", (n*m+1)/2)
	}
	return
}

func minDigit(a int64) int64 {
	ans := a % 10
	for a > 0 {
		ans = min(ans, a%10)
		a /= 10
	}
	return ans
}

func maxDigit(a int64) int64 {
	ans := a % 10
	for a > 0 {
		ans = max(ans, a%10)
		a /= 10
	}
	return ans
}

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

func main() {
	s := NewScanner()
	t := s.NextInt()

	for i := 0; i < t; i++ {
		n, m := s.NextInt(), s.NextInt()

		if n%2 == 0 || m%2 == 0 {
			fmt.Println(m * n / 2)
			continue
		}

		if n%2 == 1 {
			fmt.Println(m*(n/2) + (m+1)/2)
			continue
		}

		if m%2 == 1 {
			fmt.Println(n*(m/2) + (n+1)/2)
		}
	}
}

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

type scanner struct {
	*bufio.Scanner
}

func NewScanner() *scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	return &scanner{s}
}

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

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

func (s *scanner) NextString() string {
	s.Scan()
	return s.Text()
}

// https://codeforces.com/contest/1355/problem/A
package main

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

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

func main() {
	var (
		T int
	)

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

func solver() {
	var n, m int
	fmt.Fscan(input, &n, &m)
	if m & 1 == 0 {
	  fmt.Println(m/2*n)
	} else {
	  fmt.Println(m/2*n + (n + 1)/2)
	}

}

package main

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

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

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

func sol(a,b int) int {
	if(a==1){
		return (b+1)/2
	}
	if(b==1){
		return (a+1)/2
	}
	if(a==2){
		return b
	}
 	if(b==2){
 		return a
 	}
 	if(b%2==0 && a%2==0){
 		return (a/2)*b
 	}
 	if(b%2==1 && a%2==1){
 		x,y:=MnMx(a,b)
 		return (sol(y-1,x)+sol(1,x))
 	}
 	x,y:=oddeven(a,b)
 	return x*(y/2)
}

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

func oddeven(a,b int)(int,int) {
	if(a%2==1){
		return a,b
	}
	return b,a
}

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

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

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

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

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

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

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

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

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.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 (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}
/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int) (int, int) {
	minVal, maxVal := int(math.MaxInt32), int(math.MinInt32)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
// func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
// func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
// func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
// func GCD(a, b int64) int64 {
// 	if a == 0 {
// 		return b
// 	}
// 	return GCD(b%a, a)
// }
// func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
// func abs(x int64) int64 {
// 	if x < 0 {
// 		return -x
// 	}
// 	return x
// }

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

package main

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

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

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

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

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

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

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

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

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

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

var (
	t    int
	n, m int
)

func main() {
	t = ReadInt()
	for i := 0; i < t; i++ {
		n, m = ReadInt2()
		solve(n, m)
	}
}

func solve(n, m int) {
	num := n * m

	ans := num/2 + num%2
	fmt.Println(ans)
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

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

var nTest, n, m int

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

	fmt.Fscan(in, &nTest)
	for t := 0; t < nTest; t++ {
		fmt.Fscan(in, &m, &n)

		res := (n*m + 1) / 2

		fmt.Fprintln(out, res)
	}

	out.Flush()
}

package main

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

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

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

func sol(a,b int) int {
	if(a==1){
		return (b+1)/2
	}
	if(b==1){
		return (a+1)/2
	}
	if(a==2){
		return b
	}
 	if(b==2){
 		return a
 	}
 	if(b%2==0 && a%2==0){
 		return (a/2)*b
 	}
 	if(b%2==1 && a%2==1){
 		x:=max(a,b)
 		return x+ (x+1)/2
 	}
 	x,y:=oddeven(a,b)
 	return x*(y/2)
}

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

func oddeven(a,b int)(int,int) {
	if(a%2==1){
		return a,b
	}
	return b,a
}

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

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

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

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

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

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

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

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

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.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 (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}
/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

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

func sol(a,b int) int {
	if(a==1){
		return (b+1)/2
	}
	if(b==1){
		return (a+1)/2
	}
	if(a==2){
		return b
	}
 	if(b==2){
 		return a
 	}
 	if(b%2==0 && a%2==0){
 		return a+b
 	}
 	if(b%2==1 && a%2==1){
 		x:=max(a,b)
 		return x+ (x+1)/2
 	}
 	y:=even(a,b)
 	return y+y/2
}

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

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

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

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

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

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

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

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

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

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

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.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 (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}
/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}

package main

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

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

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

func sol(a,b int) int {
	if(a==1){
		return (b+1)/2
	}
	if(b==1){
		return (a+1)/2
	}
	if(a==2){
		return b
	}
 	if(b==2){
 		return a
 	}
 	if(b%2==0 && a%2==0){
 		return a+b
 	}
 	if(b%2==1 && a%2==1){
 		x:=max(a,b)
 		return x+ (x+1)/2
 	}
 	x,y:=oddeven(a,b)
 	return x*(y/2)
}

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

func oddeven(a,b int)(int,int) {
	if(a%2==1){
		return a,b
	}
	return b,a
}

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

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

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

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

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

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

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

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

func (impl *wordScannerImpl) NextInt64() int64 {
	impl.Scan()
	bb := impl.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 (impl *wordScannerImpl) NextString() string {
	impl.Scan()
	return impl.Text()
}
/*********************** Utils ***********************/

func S(v interface{}) string { return fmt.Sprintf("%v", v) }
func SArr(a []int) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.Itoa(a[i]) + " ")
	}
	return sb.String()
}
func SArr64(a []int64) string {
	sb := strings.Builder{}
	sb.Grow(len(a) * 9)
	for i := range a {
		sb.WriteString(strconv.FormatInt(a[i], 10) + " ")
	}
	return sb.String()
}
func MnMx(args ...int64) (int64, int64) {
	minVal, maxVal := int64(math.MaxInt64), int64(math.MinInt64)
	for _, v := range args {
		if v < minVal {
			minVal = v
		}
		if v > maxVal {
			maxVal = v
		}
	}
	return minVal, maxVal
}
func Mn(args ...int64) int64 { mn, _ := MnMx(args...); return mn }
func Mx(args ...int64) int64 { _, mx := MnMx(args...); return mx }
func LCM(a, b int64) int64   { return a / GCD(a, b) * b }
func GCD(a, b int64) int64 {
	if a == 0 {
		return b
	}
	return GCD(b%a, a)
}
func sortInt64Slice(a []int64) { sort.Slice(a, func(i, j int) bool { return a[i] < a[j] }) }
func abs(x int64) int64 {
	if x < 0 {
		return -x
	}
	return x
}


Gennady is one of the best child dentists in Berland. Today n children got an appointment with him, they lined up in front of his office.All children love to cry loudly at the reception at the dentist. We enumerate the children with integers from 1 to n in the order they go in the line. Every child is associated with the value of his cofidence pi. The children take turns one after another to come into the office; each time the child that is the first in the line goes to the doctor.While Gennady treats the teeth of the i-th child, the child is crying with the volume of vi. At that the confidence of the first child in the line is reduced by the amount of vi, the second one — by value vi - 1, and so on. The children in the queue after the vi-th child almost do not hear the crying, so their confidence remains unchanged.If at any point in time the confidence of the j-th child is less than zero, he begins to cry with the volume of dj and leaves the line, running towards the exit, without going to the doctor's office. At this the confidence of all the children after the j-th one in the line is reduced by the amount of dj.All these events occur immediately one after the other in some order. Some cries may lead to other cries, causing a chain reaction. Once in the hallway it is quiet, the child, who is first in the line, goes into the doctor's office.Help Gennady the Dentist to determine the numbers of kids, whose teeth he will cure. Print their numbers in the chronological order.

The first line of the input contains a positive integer n (1 ≤ n ≤ 4000) — the number of kids in the line.  Next n lines contain three integers each vi, di, pi (1 ≤ vi, di, pi ≤ 106) — the volume of the cry in the doctor's office, the volume of the cry in the hall and the confidence of the i-th child.

In the first line print number k — the number of children whose teeth Gennady will cure. In the second line print k integers — the numbers of the children who will make it to the end of the line in the increasing order.

NoteIn the first example, Gennady first treats the teeth of the first child who will cry with volume 4. The confidences of the remaining children will get equal to  - 2, 1, 3, 1, respectively. Thus, the second child also cries at the volume of 1 and run to the exit. The confidence of the remaining children will be equal to 0, 2, 0. Then the third child will go to the office, and cry with volume 5. The other children won't bear this, and with a loud cry they will run to the exit.In the second sample, first the first child goes into the office, he will cry with volume 4. The confidence of the remaining children will be equal to 5,  - 1, 6, 8. Thus, the third child will cry with the volume of 1 and run to the exit. The confidence of the remaining children will be equal to 5, 5, 7. After that, the second child goes to the office and cry with the volume of 5. The confidences of the remaining children will be equal to 0, 3. Then the fourth child will go into the office and cry with the volume of 2. Because of this the confidence of the fifth child will be 1, and he will go into the office last.

package main

import (
    "fmt"
)

const MAXN int = 4010

func main() {
    var n int
    fmt.Scan(&n)
    v := make([]int64, n)
    d := make([]int64, n)
    p := make([]int64, n)
    c := make([]bool, n)
    for i := 0; i < n; i++ {
        fmt.Scan(&v[i],&d[i],&p[i])
    }

    st := make([]int,0)

    for i := 0; i < n; i++ {
        if !c[i] {
            st = append(st,i+1)
            c[i] = true
            for j, vi := i+1, v[i]; j < n && vi > 0; j++ {
                if !c[j] {
                    p[j] -= vi
                    vi--
                }
            }
        }
        for {
             idx := func() int {
                for i := 0; i < n; i++ {
                    if !c[i] && p[i] < 0 {
                        return i
                    }
                }
                return -1;
                } ()
             if idx == -1 { break }
             c[idx] = true
             for j := idx+1; j < n; j++ {
                p[j] -= d[idx]
             }
        }
    }

    fmt.Println(len(st))
    for i := 0; i < len(st); i++ {
        if i == len(st)-1 {
            fmt.Println(st[i])
        } else {
            fmt.Print(st[i]," ")
        }
    }

}

package main
import (
	"fmt"
)

func main(){
	var n int
	var a []int64
	var b []int64
	var c []int64
	var rez []int
	fmt.Scanf("%d\n",&n)
	for i:=0;i<n;i++{
		var v,d,p int64
		fmt.Scanf("%d %d %d\n",&v,&d,&p)
		a=append(a,v)
		b=append(b,d)
		c=append(c,p)
	}
	for i:=0;i<n;i++{
		if c[i]>=0{
			rez=append(rez,i+1)
			var pl int64
			for j:=i+1;j<n;j++{
				if c[j]<0{
					continue
				}
				c[j]-=pl+a[i]
				if c[j]<0{
					pl+=b[j]
				}
				if a[i]>0{
					a[i]-=1
				}
			}
		}
	}
	fmt.Println(len(rez))
	for i:=0;i<len(rez);i++{
		fmt.Print(rez[i]," ")
	}

}

package main

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

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

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

	n := nextInt()
	v, d, p := make([]int, n), make([]int, n), make([]int, n)
	isLeaves := make([]bool, n)
	kid := make([]int, 0)

	for i := range v {
		v[i], d[i], p[i] = nextInt(), nextInt(), nextInt()
	}

	for i := range isLeaves {
		if !isLeaves[i] {
			reduced := 0

			for j := i + 1; j < n; j++ {
				if isLeaves[j] {
					continue
				}

				p[j] -= v[i] + reduced

				if v[i] > 0 {
					v[i]--
				}

				if p[j] < 0 {
					isLeaves[j] = true

					if reduced < 1000000 {
						reduced += d[j]
					}
				}
			}

			kid = append(kid, i+1)
		}
	}

	println(len(kid))

	for i := range kid {
		print(kid[i], " ")
	}

	println()
}

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

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

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

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

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

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

package main

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

var scanner *bufio.Scanner

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

type Child struct {
  InsideCry, OutsideCry, Confidence int64
  Departed bool
}

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

  n := getI()
  children := make([]*Child, n)
  for i := range children {
    children[i] = &Child{ getI64(), getI64(), getI64(), false }
  }
  treated := []int{}

  for pos, child := range children {
    if child.Departed {
      continue
    }
    treated = append(treated, pos + 1)
    insideCry := child.InsideCry
    for i := pos + 1; i < n; i++ {
      if !children[i].Departed {
        children[i].Confidence -= insideCry
        insideCry--
        if insideCry == 0 {
          break
        }
      }
    }
    outsideCry := int64(0)
    for i := pos + 1; i < n; i++ {
      if children[i].Departed {
        continue
      }
      children[i].Confidence -= outsideCry
      if children[i].Confidence < 0 {
        children[i].Departed = true
        outsideCry += children[i].OutsideCry
      }
    }
  }

  writer.WriteString(fmt.Sprintf("%d\n%d", len(treated), treated[0]))
  for i := 1; i < len(treated); i++ {
    writer.WriteString(fmt.Sprintf(" %d", treated[i]))
  }
  writer.WriteString("\n")
}

package main

import "fmt"

func main() {
    var n int
    var v, d, p []int
    fmt.Scanf("%d\n", &n)
    for i := 0; i < n; i++ {
        var vi, di, pi int
        fmt.Scanf("%d %d %d\n", &vi, &di, &pi)
        v = append(v, vi)
        d = append(d, di)
        p = append(p, pi)
    }
    var ans []int
    for i := 0; i < n; i++ {
        if p[i] >= 0 {
            ans = append(ans, i+1)
            var cry int
            for j := i + 1; j < n; j++ {
                if p[j] < 0 { // already left
                    continue
                }
                p[j] -= cry + v[i]
                if p[j] < 0 && cry < int(1e7) {
                    cry += d[j]
                }
                if v[i] > 0 {
                    v[i]--
                }
            }
        }
    }

    fmt.Println(len(ans))
    fmt.Printf("%d", ans[0])
    for _, x := range ans[1:] {
        fmt.Printf(" %d", x)
    }
}

package main

import "fmt"

func main() {
	var n int
	var v, d, p []int64
	fmt.Scanf("%d\n", &n)
	for i := 0; i < n; i++ {
		var vi, di, pi int64
		fmt.Scanf("%d %d %d\n", &vi, &di, &pi)
		v = append(v, vi)
		d = append(d, di)
		p = append(p, pi)
	}
	var ans []int
	for i := 0; i < n; i++ {
		if p[i] >= 0 {
			ans = append(ans, i+1)
			var cry int64
			for j := i + 1; j < n; j++ {
				if p[j] < 0 { // already left
					continue
				}
				p[j] -= cry + v[i]
				if p[j] < 0 && cry < int64(1e7) {
					cry += d[j]
				}
				if v[i] > 0 {
					v[i]--
				}
			}
		}
	}

	fmt.Println(len(ans))
	fmt.Printf("%d", ans[0])
	for _, x := range ans[1:] {
		fmt.Printf(" %d", x)
	}
	fmt.Println()
}

package main

import (
    "fmt"
)

const MAXN int = 4010

func main() {
    var n int
    fmt.Scan(&n)
    v := make([]int, n)
    d := make([]int, n)
    p := make([]int, n)
    for i := 0; i < n; i++ {
        fmt.Scan(&v[i],&d[i],&p[i])
    }

    st := make([]int,0)

    dec := 0
    for i, pi := range p {
        pi -= dec
        if pi >= 0 {
            st = append(st,i+1)
            for j, vj := i+1, v[i]; j < n && vj > 0; j, vj = j+1, vj-1 {
                p[j] -= vj
            }
        } else {
            dec += d[i]
        }
    }

    fmt.Println(len(st))
    for i := 0; i < len(st); i++ {
        if i == len(st)-1 {
            fmt.Println(st[i])
        } else {
            fmt.Print(st[i]," ")
        }
    }

}

package main

import (
    "fmt"
)

const MAXN int = 4010

func main() {
    var n int
    fmt.Scan(&n)
    v := make([]int64, n)
    d := make([]int64, n)
    p := make([]int64, n)
    for i := 0; i < n; i++ {
        fmt.Scan(&v[i],&d[i],&p[i])
    }

    st := make([]int,0)

    dec := int64(0)
    for i, pi := range p {
        pi -= dec
        if pi >= 0 {
            st = append(st,i+1)
            for j, vj := i+1, v[i]; j < n && vj > 0; j, vj = j+1, vj-1 {
                p[j] -= vj
            }
        } else {
            dec += d[i]
        }
    }

    fmt.Println(len(st))
    for i := 0; i < len(st); i++ {
        if i == len(st)-1 {
            fmt.Println(st[i])
        } else {
            fmt.Print(st[i]," ")
        }
    }

}

package main

import (
    "fmt"
)

const MAXN int = 4010

func main() {
    var n int
    fmt.Scan(&n)
    v := make([]int, n)
    d := make([]int, n)
    p := make([]int, n)
    for i := 0; i < n; i++ {
        fmt.Scan(&v[i],&d[i],&p[i])
    }

    st := make([]int,0)

    dec := 0
    for i, pi := range p {
        pi -= dec
        if pi > 0 {
            st = append(st,i+1)
            for j, vj := i+1, v[i]; j < n && vj > 0; j, vj = j+1, vj-1 {
                p[j] -= vj
            }
        } else {
            dec += d[i]
        }
    }

    fmt.Println(len(st))
    for i := 0; i < len(st); i++ {
        if i == len(st)-1 {
            fmt.Println(st[i])
        } else {
            fmt.Print(st[i]," ")
        }
    }

}

package main

import (
    "fmt"
)

const MAXN int = 4010

func main() {
    var n int
    fmt.Scan(&n)
    v := make([]int, n)
    d := make([]int, n)
    p := make([]int, n)
    for i := 0; i < n; i++ {
        fmt.Scan(&v[i],&d[i],&p[i])
    }

    st := make([]int,0)

    dec := 0
    for i, pi := range p {
        pi -= dec
        if pi > 0 {
            st = append(st,i)
            for j, vj := i+1, v[i]; j < n && vj > 0; j, vj = j+1, vj-1 {
                p[j] -= vj
            }
        } else {
            dec += d[i]
        }
    }

    fmt.Println(len(st))
    for i := 0; i < len(st); i++ {
        if i == len(st)-1 {
            fmt.Println(st[i])
        } else {
            fmt.Print(st[i]," ")
        }
    }

}

package main

import (
    "fmt"
)

const MAXN int = 4010

func main() {
    var n int
    fmt.Scan(&n)
    v := make([]int64, n)
    d := make([]int64, n)
    p := make([]int64, n)
    for i := 0; i < n; i++ {
        fmt.Scan(&v[i],&d[i],&p[i])
    }

    st := make([]int,0)

    dec := int64(0)
    for i, pi := range p {
        pi -= dec
        if pi >= 0 {
            st = append(st,i+1)
            for j, vj := i+1, v[i]; j < n && vj > 0; j, vj = j+1, vj-1 {
                if p[j] < 0 {
                    vj++
                } else {
                    p[j] -= vj
                }
            }
        } else {
            dec += d[i]
        }
    }

    fmt.Println(len(st))
    for i := 0; i < len(st); i++ {
        if i == len(st)-1 {
            fmt.Println(st[i])
        } else {
            fmt.Print(st[i]," ")
        }
    }

}

package main
import (
	"fmt"
)

func main(){
	var n int
	var a []int
	var b []int
	var c []int
	var rez []int
	fmt.Scanf("%d\n",&n)
	for i:=0;i<n;i++{
		var v,d,p int
		fmt.Scanf("%d %d %d\n",&v,&d,&p)
		a=append(a,v)
		b=append(b,d)
		c=append(c,p)
	}
	for i:=0;i<n;i++{
		if c[i]>=0{
			rez=append(rez,i+1)
			var pl int
			for j:=i+1;j<n;j++{
				if c[j]<0{
					continue
				}
				c[j]-=pl+a[i]
				if c[j]<0{
					pl+=b[j]
				}
				if a[i]>0{
					a[i]-=1
				}
			}
		}
	}
	fmt.Println(len(rez))
	for i:=0;i<len(rez);i++{
		fmt.Print(rez[i]," ")
	}

}

package main
import (
	"fmt"
)

func main(){
	var n int
	var a []int
	var b []int
	var c []int
	var pl int
	var rez []int
	fmt.Scanf("%d\n",&n)
	for i:=0;i<n;i++{
		var v,d,p int
		fmt.Scanf("%d %d %d\n",&v,&d,&p)
		a=append(a,v)
		b=append(b,d)
		c=append(c,p)
	}
	for i:=0;i<n;i++{
		if c[i]>=0{
			rez=append(rez,i+1)
			for j:=i+1;j<n;j++{
				if c[j]<0{
					continue
				}
				c[j]-=pl+a[i]
				if c[j]<0{
					pl+=b[j]
				}
				if a[i]>0{
					a[i]-=1
				}
			}
		}
	}
	fmt.Println(len(rez))
	for i:=0;i<len(rez);i++{
		fmt.Print(rez[i]," ")
	}

}

package main

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

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

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

	n := nextInt()
	v, d, p := make([]int, n), make([]int, n), make([]int, n)
	isLeaves := make([]bool, n)
	haveChild := true
	kid := make([]int, 0)

	for i := range v {
		v[i], d[i], p[i] = nextInt(), nextInt(), nextInt()
	}

	for haveChild {
		haveChild = false

		for i := range isLeaves {
			if !isLeaves[i] {
				haveChild = true
				isLeaves[i] = true
				reduced := 0

				for j := i + 1; j < n; j++ {
					if v[i] > 0 {
						v[i]--
					}

					if isLeaves[j] {
						continue
					}

					p[j] -= v[i] + reduced

					if p[j] < 0 {
						isLeaves[j] = true
						reduced += d[j]
					}
				}

				kid = append(kid, i+1)
				break
			}
		}
	}

	println(len(kid))

	for i := range kid {
		print(kid[i], " ")
	}

	println()
}

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

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

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

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

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

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

package main

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

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

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

	n := nextInt()
	v, d, p := make([]int, n), make([]int, n), make([]int, n)
	isLeaves := make([]bool, n)
	haveChild := true
	kid := make([]int, 0)

	for i := range v {
		v[i], d[i], p[i] = nextInt(), nextInt(), nextInt()
	}

	for haveChild {
		haveChild = false

		for i := range isLeaves {
			if !isLeaves[i] {
				haveChild = true
				isLeaves[i] = true
				reduced := 0

				for j := i + 1; j < n; j++ {
					if isLeaves[j] {
						continue
					}

					p[j] -= v[i] + reduced

					if v[i] > 0 {
						v[i]--
					}

					if p[j] < 0 {
						isLeaves[j] = true
						reduced += d[j]
					}
				}

				kid = append(kid, i+1)
				break
			}
		}
	}

	println(len(kid))

	for i := range kid {
		print(kid[i], " ")
	}

	println()
}

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

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

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

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

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

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

package main

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

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

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

	n := nextInt()
	v, d, p := make([]int, n), make([]int, n), make([]int, n)
	isLeaves := make([]bool, n)
	haveChild := true
	kid := make([]int, 0)

	for i := range v {
		v[i], d[i], p[i] = nextInt(), nextInt(), nextInt()
	}

	for haveChild {
		haveChild = false

		for i := range isLeaves {
			if !isLeaves[i] {
				haveChild = true
				isLeaves[i] = true
				reduced := 0

				for j := i + 1; j < n; j++ {
					p[j] -= v[i] + reduced

					if v[i] > 0 {
						v[i]--
					}

					if isLeaves[j] {
						continue
					}

					if p[j] < 0 {
						isLeaves[j] = true
						reduced += d[j]
					}
				}

				kid = append(kid, i+1)
				break
			}
		}
	}

	println(len(kid))

	for i := range kid {
		print(kid[i], " ")
	}

	println()
}

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

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

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

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

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

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

package main

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

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

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

	n := nextInt()
	v, d, p := make([]int, n), make([]int, n), make([]int, n)
	isLeaves := make([]bool, n)
	haveChild := true
	kid := make([]int, 0)

	for i := range v {
		v[i], d[i], p[i] = nextInt(), nextInt(), nextInt()
	}

	for haveChild {
		haveChild = false

		for i := range isLeaves {
			if !isLeaves[i] {
				haveChild = true
				isLeaves[i] = true
				reduced := 0

				for j := i + 1; j < n; j++ {
					p[j] -= v[i] + reduced

					if v[i] > 0 {
						v[i]--
					}

					if p[j] < 0 {
						isLeaves[j] = true
						reduced += d[j]
					}
				}

				kid = append(kid, i+1)
				break
			}
		}
	}

	println(len(kid))

	for i := range kid {
		print(kid[i], " ")
	}

	println()
}

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

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

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

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

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

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

package main

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

var scanner *bufio.Scanner

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

type Child struct {
  InsideCry, OutsideCry, Confidence int
  Departed bool
}

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

  n := getI()
  children := make([]*Child, n)
  for i := range children {
    children[i] = &Child{ getI(), getI(), getI(), false }
  }
  treated := []int{}

  for pos, child := range children {
    if child.Departed {
      continue
    }
    treated = append(treated, pos + 1)
    insideCry := child.InsideCry
    for i := pos + 1; i < n; i++ {
      if !children[i].Departed {
        children[i].Confidence -= insideCry
        insideCry--
        if insideCry == 0 {
          break
        }
      }
    }
    outsideCry := 0
    for i := pos + 1; i < n; i++ {
      if children[i].Departed {
        continue
      }
      children[i].Confidence -= outsideCry
      if children[i].Confidence < 0 {
        children[i].Departed = true
        outsideCry += children[i].OutsideCry
      }
    }
  }

  writer.WriteString(fmt.Sprintf("%d\n%d", len(treated), treated[0]))
  for i := 1; i < len(treated); i++ {
    writer.WriteString(fmt.Sprintf(" %d", treated[i]))
  }
  writer.WriteString("\n")
}

package main

import "fmt"

func main() {
	var n int
	var v, d, p []int
	fmt.Scanf("%d", &n)
	for i := 0; i < n; i++ {
		var vi, di, pi int
		fmt.Scanf("%d %d %d", &vi, &di, &pi)
		v = append(v, vi)
		d = append(d, di)
		p = append(p, pi)
	}
	var ans []int
	for i := 0; i < n; i++ {
		if p[i] >= 0 {
			ans = append(ans, i+1)
			var cry int
			for j := i + 1; j < n; j++ {
				if p[j] < 0 { // already left
					continue
				}
				p[j] -= cry + v[i]
				if p[j] < 0 && cry < int(1e7) {
					cry += d[j]
				}
				if v[i] > 0 {
					v[i]--
				}
			}
		}
	}

	fmt.Println(len(ans))
	fmt.Printf("%d", ans[0])
	for _, x := range ans[1:] {
		fmt.Printf(" %d", x)
	}
}


There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that1. 1 ≤ i, j ≤ N2. S[i] = S[j], that is the i-th symbol of string S is equal to the j-th.

// B. Choosing Symbol Pairs
/*
There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that

1. 1 ≤ i, j ≤ N

2. S[i] = S[j], that is the i-th symbol of string S is equal to the j-th.

Input
The single input line contains S, consisting of lowercase Latin letters and digits. It is guaranteed that string S in not empty and its length does not exceed 105.

Output
Print a single number which represents the number of pairs i and j with the needed property. Pairs (x, y) and (y, x) should be considered different, i.e. the ordered pairs count.

Examples
Input
great10

Output
7

Input
aaaaaaaaaa

Output
100
*/
package main

import (
	"fmt"
)

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

	aMap := make(map[byte]int, len(s))
	for i := 0; i < len(s); i++ {
		aMap[s[i]]++
	}

	var total int64
	for i := 0; i < len(s); i++ {
		total += int64(aMap[s[i]])
	}
	fmt.Print(total)
}

// B. Choosing Symbol Pairs
/*
There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that

1. 1 ≤ i, j ≤ N

2. S[i] = S[j], that is the i-th symbol of string S is equal to the j-th.

Input
The single input line contains S, consisting of lowercase Latin letters and digits. It is guaranteed that string S in not empty and its length does not exceed 105.

Output
Print a single number which represents the number of pairs i and j with the needed property. Pairs (x, y) and (y, x) should be considered different, i.e. the ordered pairs count.

Examples
Input
great10

Output
7

Input
aaaaaaaaaa

Output
100
*/
package main

import (
	"fmt"
)

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

	aMap := make(map[byte]int64, len(s))
	for i := 0; i < len(s); i++ {
		aMap[s[i]]++
	}

	var total int64
	for i := 0; i < len(s); i++ {
		total += aMap[s[i]]
	}
	fmt.Print(total)
}

// B. Choosing Symbol Pairs
/*
There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that

1. 1 ≤ i, j ≤ N

2. S[i] = S[j], that is the i-th symbol of string S is equal to the j-th.

Input
The single input line contains S, consisting of lowercase Latin letters and digits. It is guaranteed that string S in not empty and its length does not exceed 105.

Output
Print a single number which represents the number of pairs i and j with the needed property. Pairs (x, y) and (y, x) should be considered different, i.e. the ordered pairs count.

Examples
Input
great10

Output
7

Input
aaaaaaaaaa

Output
100
*/
package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	s, _ := reader.ReadString('\n')
	s = strings.TrimSpace(s)
	l := len(s)
	aMap := make(map[byte]int, l)
	for i := 0; i < len(s); i++ {
		aMap[s[i]]++
	}

	var total int64
	for i := 0; i < l; i++ {
		total += int64(aMap[s[i]])
	}
	fmt.Print(total)
}

// B. Choosing Symbol Pairs
/*
There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that

1. 1 ≤ i, j ≤ N

2. S[i] = S[j], that is the i-th symbol of string S is equal to the j-th.

Input
The single input line contains S, consisting of lowercase Latin letters and digits. It is guaranteed that string S in not empty and its length does not exceed 105.

Output
Print a single number which represents the number of pairs i and j with the needed property. Pairs (x, y) and (y, x) should be considered different, i.e. the ordered pairs count.

Examples
Input
great10

Output
7

Input
aaaaaaaaaa

Output
100
*/
package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	s, _ := reader.ReadString('\n')
	s = strings.TrimSpace(s)
	aMap := make(map[byte]int, len(s))
	for i := 0; i < len(s); i++ {
		aMap[s[i]]++
	}

	var total int64
	for i := 0; i < len(s); i++ {
		total += int64(aMap[s[i]])
	}
	fmt.Print(total)
}

package main

import (
	"fmt"
)

func main() {
	var (
		i, lw int32
		wi    byte
		w     string
		frek  [26 + 26 + 10]int32
		ans   int64
	)

	fmt.Scan(&w)
	lw = int32(len(w))
	for i = 0; i < lw; i++ {
		wi = w[i]
		switch {
		case 'a' <= wi && wi <= 'z':
			frek[wi-'a']++
			//			println(int32(wi-'a'), wi)
		case 'A' <= wi && wi <= 'Z':
			frek[wi+26-'A']++
			//			println(int32(wi+26-'A'), wi)

		case '0' <= wi && wi <= '9':
			frek[wi+26+26-'0']++
			//			println(int32(wi+26+26-'A'), wi)

		}
	}
	for i = 0; i < 26+26+10; i++ {
		ans += int64(frek[i]) * int64(frek[i])
	}
	fmt.Println(ans)
}

package main

import (
	"fmt"
)

func main() {
	var (
		i    int32
		w    string
		frek [26 + 26 + 10]int32
		ans  int64
	)

	fmt.Scan(&w)
	for _, wi := range w {
		switch {
		case 'a' <= wi && wi <= 'z':
			frek[wi-'a']++
			//			println(int32(wi-'a'), wi)
		case 'A' <= wi && wi <= 'Z':
			frek[wi+26-'A']++
			//			println(int32(wi+26-'A'), wi)

		case '0' <= wi && wi <= '9':
			frek[wi+26+26-'0']++
			//			println(int32(wi+26+26-'A'), wi)

		}
	}
	for i = 0; i < 26+26+10; i++ {
		ans += int64(frek[i]) * int64(frek[i])
	}
	fmt.Println(ans)
}

//  URL: http://codeforces.com/contest/50/problem/B
//  PROBLEM RESTATEMENT
//      Given string s of length N, and 1 <= i, j <= N, count number of pairs
//      s.t s[i] == s[j]. i can equal j, and order matters (i, j) != (j, i).
//  APPROACH
//      1. Brute force approach is O(n^2), n can be an array of size 10^5, so
//         we need to find an analytical approach.
//      2. Let's say that a character appears in s `n` times.
//      3. How many ways can we pick two elements from a set of size `n`?
//             - There are n choose 2 ways of picking two elements from a set.
//             - There are 2! ways of re-ordering each pair.
//             - So, n C 2 * 2!. We can simplify n!/n-2!2! * 2! to n!/n-2!
//               which is n * (n - 1)
//      4. So we have n * (n - 1), for a given character. Because i can equal
//         j, we have to add n, so n * (n - 1) + n = n * n.
//      4. Our approach is now simple. Create a map of type [rune, int64].
//         Iterate through the map, and add value + value.

package main

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

func solve(s string) int64 {
	var count int64 = 0
	m := make(map[rune]int64, 0)
	for _, elem := range s {
		m[elem] += 1
	}
	for _, value := range m {
		count += value*value
	}
	return count
}

func main() {
	reader, writer := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var s string
	fmt.Fscanf(reader, "%s\n", &s)
	fmt.Fprintf(writer, "%d\n", solve(s))
}

// B. Choosing Symbol Pairs
/*
There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that

1. 1 ≤ i, j ≤ N

2. S[i] = S[j], that is the i-th symbol of string S is equal to the j-th.

Input
The single input line contains S, consisting of lowercase Latin letters and digits. It is guaranteed that string S in not empty and its length does not exceed 105.

Output
Print a single number which represents the number of pairs i and j with the needed property. Pairs (x, y) and (y, x) should be considered different, i.e. the ordered pairs count.

Examples
Input
great10

Output
7

Input
aaaaaaaaaa

Output
100
*/
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scanf("%v ", &s)

	aMap := make(map[byte]int, len(s))
	for i := 0; i < len(s); i++ {
		aMap[s[i]]++
	}

	total := 0
	for _, v := range aMap {
		total += v * v
	}
	fmt.Print(total)
}

// B. Choosing Symbol Pairs
/*
There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that

1. 1 ≤ i, j ≤ N

2. S[i] = S[j], that is the i-th symbol of string S is equal to the j-th.

Input
The single input line contains S, consisting of lowercase Latin letters and digits. It is guaranteed that string S in not empty and its length does not exceed 105.

Output
Print a single number which represents the number of pairs i and j with the needed property. Pairs (x, y) and (y, x) should be considered different, i.e. the ordered pairs count.

Examples
Input
great10

Output
7

Input
aaaaaaaaaa

Output
100
*/
package main

import (
	"fmt"
)

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

	aMap := make(map[byte]int, len(s))
	for i := 0; i < len(s); i++ {
		aMap[s[i]]++
	}

	total := 0
	for i := 0; i < len(s); i++ {
		total += aMap[s[i]]
	}
	fmt.Print(total)
}

//  URL: http://codeforces.com/contest/50/problem/B
//  Time: 4:11PM
//  PROBLEM RESTATEMENT
//      Given string s of length N, and 1 <= i, j <= N, count number of pairs
//      s.t s[i] == s[j]. i can equal j, and order matters (i, j) != (j, i).
//  APPROACH
//      1. Brute force approach is O(n^2), n can be an array of size 10^5, so
//         we need to find an analytical approach.
//      2. Let's say that a character appears in s `n` times.
//      3. How many ways can we pick two elements from a set of size `n`?
//             There are n choose 2 ways of picking two elements from a set.
//             Then, there are 2! ways of re-ordering each pair.
//             So, n C 2 * 2!. We can simplify n!/n-2!2! * 2! to n!/n-2! which
//             is n * (n - 1).
//             Since we can also set i == j, we need to add n to the answer.
//      4. Our approach is now simple. Create a map of type [rune, int].
//         Iterate through the map, and add value + value * (value - 1).

package main

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

func solve(s string) int {
	count := 0
	m := make(map[rune]int, 0)
	for _, elem := range s {
		m[elem] += 1
	}
	for _, value := range m {
		count += value + value*(value-1)
	}
	return count
}

func main() {
	reader, writer := bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	var s string
	fmt.Fscanf(reader, "%s\n", &s)
	fmt.Fprintf(writer, "%d\n", solve(s))
}