package main

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

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)

	var s string

	fmt.Fscanf(reader, "%s", &s)
	l := len(s)
	b := make([]byte, l*2+1)
	plen := make([]int, l*2+1)
	dp := make([]int, l*2+1)
	for i := 0; i < l; i++ {
		b[i*2] = '#'
		b[i*2+1] = s[i]
	}
	b[2*l] = '#'
	farpos, midpos := 0, 0

	for i := 0; i < 2*l; i++ {
		plen[i] = 1
		if i < farpos {
			p := 2*midpos - i
			plen[i] = plen[p]
			if i+plen[i]-1 == farpos {
				for p := farpos + 1; p < 2*l+1 && 2*i-p >= 0; p++ {
					if b[2*i-p] == b[p] {
						farpos++
						midpos = i
						plen[i]++
					} else {
						break
					}
				}
			}
		} else {
			for p := i + 1; p < 2*l+1 && 2*i-p >= 0; p++ {
				if b[2*i-p] == b[p] {
					farpos = p
					midpos = i
					plen[i]++
				} else {
					break
				}
			}
		}
	}
	result := int64(1)
	dp[0] = 0
	dp[1] = 1
	for i := 2; i < 2*l; i++ {
		if plen[i] == i+1 {
			dp[i] = dp[i/2] + 1
			result += int64(dp[i])
		}
	}
	fmt.Printf("%d", result)

}

package main

import "fmt"

import "bytes"
import "io"
import "os"

//import "strings"

var dbg = false

var B int64 = 255
var P int64 = 982451653 // 1610612741 // 15487469 //

func hash1(h, s int64) int64 {
	return (h*B + s) % P
}

func hash2(h, s, B_n int64) (int64, int64) {
	r := (h + s*B_n) % P
	B_n = (B_n * B) % P
	return r, B_n
}

func palindrom_sum_degree(S string) int64 {
	K := make([]int64, len(S))
	//H1 := make([]int64, len(S))
	//H2 := make([]int64, len(S))

	var h1, h2, B_n int64 = 0, 0, 1
	var Sum int64 = 0

	for i := 0; i < len(S); i++ {

		h1 = hash1(h1, int64(S[i]))
		h2, B_n = hash2(h2, int64(S[i]), B_n)

		//H1[i] = h1
		//H2[i] = h2

		if h1 == h2 {
			if i == 0 {
				K[i] = 1
			} else {
				K[i] = K[(i+1)/2-1] + 1
			}
			Sum += K[i]
		}

	}

	if dbg && S[0:3] == "aba" {
		//fmt.Println(H1)
		//fmt.Println(H2)
		fmt.Println(K)
	}

	return Sum
}

func solve() {
	var input bytes.Buffer

	io.Copy(&input, os.Stdin)

	var s string
	fmt.Fscanf(&input, "%s", &s)
	//fmt.Fscanf(os.Stdin, "%s", &s)

	if dbg && s[0:3] == "aba" {
		fmt.Println("debug", s)
	}

	//buf := input.Bytes()

	//d := palindrom_sum_degree(buf[:len(buf)-1])
	d := palindrom_sum_degree(s)

	fmt.Println(d)
}

func main() {
	//test()
	// bala

	solve()
	//p := quick_pow_mod(int64(2), int64(20), B)
	//fmt.Print64ln(p)
}

package main

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

const b = 255
const p = 1610612741

func main() {
	s := readInput()

	var (
		hs  int64   = 0
		hr  int64   = 0
		bp  int64   = 1
		k   []int64 = make([]int64, len(s))
		sum int64   = 0
	)

	for i, c := range s {
		hs = (hs*b + int64(c)) % p
		hr = (hr + bp*int64(c)) % p
		bp = bp * b % p

		if hs == hr {
			idx := (i+1)/2 - 1

			if i == 0 {
				idx = 0
			}
			k[i] = k[idx] + 1
		}
		sum += k[i]
	}

	fmt.Println(sum)
}

func readInput() (s string) {
	in := bufio.NewReader(os.Stdin)
	var err error
	if s, err = in.ReadString(byte('\n')); err != nil {
		log.Fatal(err)
	}
	s = s[:len(s)-1]

	return s
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	s, _ := reader.ReadString('\n')
	var i int
	for i < len(s) && (s[i] >= 'a' && s[i] <= 'z' || s[i] >= 'A' && s[i] <= 'Z' || s[i] >= '0' && s[i] <= '9') {
		i++
	}
	fmt.Println(solve(s[:i]))
}

const P1 = 31

//const P2 = 41
const M1 = 1000000007

//const M2 = 1000000009

func solve(s string) int64 {
	n := len(s)
	var h1 int64
	//var h2 int64
	var h3 int64
	//var h4 int64
	var p1 int64 = 1
	//var p2 int64 = 1

	dp := make([]int64, n)
	var res int64
	for i := 0; i < n; i++ {
		x := int64(s[i]-'a') + 1
		h1 = (h1*P1 + x) % M1
		//h2 = (h2*P2 + x) % M2

		h3 = (h3 + (x*p1)%M1) % M1
		//h4 = (h4 + (x*p2)%M2) % M2

		p1 = (p1 * P1) % M1
		//p2 = (p2 * P2) % M2

		if h1 == h3 {
			dp[i] = 1
			if i > 0 {
				if i&2 == 1 {
					dp[i] += dp[i/2]
				} else {
					dp[i] += dp[(i-1)/2]
				}
			}
		}
		res += dp[i]
	}

	return res
}

func solve1(s string) int64 {
	p := manachers(s)

	n := len(s)

	dp := make([]int64, n)
	dp[0] = 1
	var res int64 = 1

	for i := 2; i <= n; i++ {
		if p[i-1] == 0 {
			dp[i-1] = 1
			//prefix s[0..i] is palindrome
			if p[i/2-1] == 0 {
				dp[i-1] += dp[i/2-1]
			}
			res += dp[i-1]
		}
	}

	return res
}

func manachers(s string) []int {
	ss := modify(s)
	n := len(ss)
	P := make([]int, n)
	var c, r int

	for i := 0; i < n; i++ {
		mirror := 2*c - r

		if i < r {
			P[i] = min(r-i, P[mirror])
		}
		a := i + 1 + P[i]
		b := i - (1 + P[i])
		for a < n && b >= 0 && ss[a] == ss[b] {
			P[i]++
			a++
			b--
		}

		if i+P[i] > r {
			r = i + P[i]
			c = i
		}
	}
	f := make([]int, len(s))
	for i := 0; i < len(s); i++ {
		f[i] = i
	}
	for i := 0; i < n; i++ {
		//l := P[i]
		// #a#a#b#
		a := i + P[i]
		b := i - P[i]
		a--
		b++
		if a > b || i%2 != 0 {
			f[a/2] = min(f[a/2], b/2)
		}
	}
	return f
}

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

func modify(s string) string {
	var buf bytes.Buffer

	for i := 0; i < len(s); i++ {
		buf.WriteByte('#')
		buf.WriteByte(s[i])
	}
	buf.WriteByte('#')
	return buf.String()
}

package main

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

const (
	p = 1610612741
)

func main() {
	var (
		err error
		s   string

		in = bufio.NewReader(os.Stdin)
	)

	if s, err = in.ReadString(byte('\n')); err != nil {
		log.Fatal(err)
	}

	s = s[:len(s)-1]

	var (
		l, r   int64
		n, res int
		b      int64 = 255
		base   int64 = 1
		k            = make([]int, len(s)+1)
	)

	for i, c := range s {
		n = i + 1
		l = (l*b + int64(c)) % p
		r = (r + int64(c)*base) % p

		if l == r {
			k[n] = k[n/2] + 1
		}

		res += k[n]
		base = (base * b) % p
	}

	fmt.Println(res)
}

package main

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

func main() {
	bs, _ := ioutil.ReadAll(os.Stdin)
	reader := bytes.NewBuffer(bs)

	var s string

	fmt.Fscanf(reader, "%s", &s)
	l := len(s)
	b := make([]byte, l*2+1)
	plen := make([]int, l*2+1)
	dp := make([]int, l*2+1)
	for i := 0; i < l; i++ {
		b[i*2] = '#'
		b[i*2+1] = s[i]
	}
	b[2*l] = '#'
	farpos, midpos := 0, 0

	for i := 0; i < 2*l; i++ {
		plen[i] = 1
		if i < farpos {
			p := 2*midpos - i
			plen[i] = plen[p]
			if i+plen[i] == farpos {
				for p := farpos + 1; p < 2*l+1 && 2*i-p >= 0; p++ {
					if b[2*i-p] == b[p] {
						farpos++
						midpos = i
						plen[i]++
					} else {
						break
					}
				}
			}
		} else {
			for p := i + 1; p < 2*l+1 && 2*i-p >= 0; p++ {
				if b[2*i-p] == b[p] {
					farpos = p
					midpos = i
					plen[i]++
				} else {
					break
				}
			}
		}
	}
	result := int64(1)
	dp[0] = 0
	dp[1] = 1
	for i := 2; i < 2*l; i++ {
		if plen[i] == i+1 && dp[i/2] != 0 {
			dp[i] = dp[i/2] + 1
			result += int64(dp[i])
		}
	}
	fmt.Printf("%d", result)

}

package main

import "fmt"

import "bytes"
import "io"
import "os"

//import "strings"

var dbg = false

func quick_pow_mod(b, e, m int) int {
	p := b
	r := int(1)
	for 0 < e {
		if e&1 == 1 {
			r = (r * p) % m
		}
		p = (p * p) % m
		e = e >> 1
	}
	return r
}

var A int = 0x1000000 - 1
var B int = 15487469

//var A int = 0x100000000 - 1
//var B int = 982451653

var A_ int = quick_pow_mod(A, B-2, B)

type Hash struct {
	h int
	n int
	a int
}

func hash_prepend(h Hash, c0 int) Hash {
	c := int(c0)
	h1 := Hash{
		h: (h.h*A + c*A) % B,
		n: h.n + 1,
		a: (h.a * A) % B,
	}
	return h1
}

func hash_shift(h Hash, c0 int) Hash {
	c := int(c0)
	var v int = (h.h - c*h.a) % B

	if v < 0 {
		v1 := v + B
		if dbg {
			fmt.Println("-", v, v1)
		}
		v = v1
	}

	h1 := Hash{
		h: v,
		n: h.n - 1,
		a: (h.a * A_) % B,
	}

	return h1
}

func init_prefix_hashes_lr(s []byte) []int {
	HH := make([]int, len(s))
	h := Hash{h: 0, n: 0, a: 1}
	for i := 0; i < len(s); i++ {
		h = hash_prepend(h, int(s[i]))
		HH[i] = int(h.h)
	}
	return HH
}

func init_prefix_hashes_rl(s []byte) []int {
	HH := make([]int, len(s))
	h := Hash{h: 0, n: 0, a: 1}
	l := len(s)
	for i := 0; i < len(s); i++ {
		h = hash_prepend(h, int(s[l-i-1]))
	}
	for i := 0; i < len(s); i++ {
		HH[l-i-1] = int(h.h)
		h = hash_shift(h, int(s[l-i-1]))
	}
	return HH
}

func palindrom_sum_degree(s []byte) int {

	LR := init_prefix_hashes_lr(s)
	RL := init_prefix_hashes_rl(s)

	S := 0
	for i := 0; i < len(s); i++ {
		P := 0
		end := i + 1

		for 0 < end {
			lr := LR[end-1]
			rl := RL[end-1]
			if lr != rl {
				break
			}
			P += 1
			end = end / 2
		}
		S += P
	}

	return S
}

func solve() {
	var input bytes.Buffer

	io.Copy(&input, os.Stdin)

	// var s string
	// fmt.Fscanf(&input, "%s", &s)
	// //s = strings.TrimSpace(s)

	// if dbg {
	// 	fmt.Println(s)
	// }

	d := palindrom_sum_degree(input.Bytes())

	fmt.Println(d)
}

func test() {
	h := Hash{h: 0, n: 0, a: 1}
	fmt.Println(h)
	h = hash_prepend(h, 'a')
	h = hash_prepend(h, 'b')
	h = hash_prepend(h, 'a')
	h = hash_prepend(h, 'a')
	fmt.Println(h)
	h = hash_shift(h, 'a')
	h = hash_shift(h, 'b')
	h = hash_shift(h, 'a')
	h = hash_shift(h, 'a')
	fmt.Println(h)
}

func test2() {
	fmt.Println(A, A_, A*A_)
}

func main() {
	//test()

	solve()
	//p := quick_pow_mod(int(2), int(20), B)
	//fmt.Println(p)
}

package main

import "fmt"

import "bytes"
import "io"
import "os"

//import "strings"

var dbg = false

var B = 255
var P = 982451653

func hash1(h, s int) int {
	return (h*B + s) % P
}

func hash2(h, s, B_n int) (int, int) {
	r := (h + s*B_n) % P
	B_n = (B_n * B) % P
	return r, B_n
}

func palindrom_sum_degree(S string) int {
	K := make([]int, len(S))
	h1, h2, B_n := 0, 0, 1
	Sum := 0

	for i := 0; i < len(S); i++ {

		h1 = hash1(h1, int(S[i]))
		h2, B_n = hash2(h2, int(S[i]), B_n)

		if h1 == h2 {
			if i == 0 {
				K[i] = 1
			} else {
				K[i] = K[(i+1)/2-1] + 1
			}
			Sum += K[i]
		}

	}
	return Sum
}

func solve() {
	var input bytes.Buffer

	io.Copy(&input, os.Stdin)

	var s string
	fmt.Fscanf(&input, "%s", &s)
	//fmt.Fscanf(os.Stdin, "%s", &s)

	if s[0:3] == "aba" {
		fmt.Println("debug", s)
	}

	//buf := input.Bytes()

	//d := palindrom_sum_degree(buf[:len(buf)-1])
	d := palindrom_sum_degree(s)

	fmt.Println(d)
}

func main() {
	//test()
	// bala

	solve()
	//p := quick_pow_mod(int(2), int(20), B)
	//fmt.Println(p)
}

package main

import "fmt"

import "bytes"
import "io"
import "os"

//import "strings"

var dbg = false

var B = 255
var P = 982451653

func hash1(h, s int) int {
	return (h*B + s) % P
}

func hash2(h, s, B_n int) (int, int) {
	r := (h + s*B_n) % P
	B_n = (B_n * B) % P
	return r, B_n
}

func palindrom_sum_degree(S []byte) int {
	K := make([]int, len(S))
	h1, h2, B_n := 0, 0, 1
	Sum := 0

	for i := 0; i < len(S); i++ {

		h1 = hash1(h1, int(S[i]))
		h2, B_n = hash2(h2, int(S[i]), B_n)

		if h1 == h2 {
			if i == 0 {
				K[i] = 1
			} else {
				K[i] = K[(i+1)/2-1] + 1
			}
			Sum += K[i]
		}

	}
	return Sum
}

func solve() {
	var input bytes.Buffer

	io.Copy(&input, os.Stdin)

	//var s string
	//fmt.Fscanf(&input, "%s", &s)
	//fmt.Fscanf(os.Stdin, "%s", &s)
	//s = strings.TrimSpace(s)

	buf := input.Bytes()

	d := palindrom_sum_degree(buf[:len(buf)-1])

	fmt.Println(d)
}

func main() {
	//test()

	solve()
	//p := quick_pow_mod(int(2), int(20), B)
	//fmt.Println(p)
}

package main

import "fmt"

import "bytes"
import "io"
import "os"

//import "strings"

var dbg = false

var B = 255
var P = 982451653

func hash1(h, s int) int {
	return (h*B + s) % P
}

func hash2(h, s, B_n int) (int, int) {
	r := (h + s*B_n) % P
	B_n = (B_n * B) % P
	return r, B_n
}

func palindrom_sum_degree(S string) int {
	K := make([]int, len(S))
	h1, h2, B_n := 0, 0, 1
	Sum := 0

	for i := 0; i < len(S); i++ {

		h1 = hash1(h1, int(S[i]))
		h2, B_n = hash2(h2, int(S[i]), B_n)

		if h1 == h2 {
			if i == 0 {
				K[i] = 1
			} else {
				K[i] = K[(i+1)/2-1] + 1
			}
			Sum += K[i]
		}

	}
	return Sum
}

func solve() {
	var input bytes.Buffer

	io.Copy(&input, os.Stdin)

	var s string
	fmt.Fscanf(&input, "%s", &s)
	//fmt.Fscanf(os.Stdin, "%s", &s)

	//buf := input.Bytes()

	//d := palindrom_sum_degree(buf[:len(buf)-1])
	d := palindrom_sum_degree(s)

	fmt.Println(d)
}

func main() {
	//test()
	// bala

	solve()
	//p := quick_pow_mod(int(2), int(20), B)
	//fmt.Println(p)
}

package main

import "fmt"

import "bytes"
import "io"
import "os"

//import "strings"

var dbg = false

var B = 127
var P = 15487469 //982451653

func hash1(h, s int) int {
	return (h*B + s) % P
}

func hash2(h, s, B_n int) (int, int) {
	r := (h + s*B_n) % P
	B_n = (B_n * B) % P
	return r, B_n
}

func palindrom_sum_degree(S string) int {
	K := make([]int, len(S))
	H1 := make([]int, len(S))
	H2 := make([]int, len(S))

	h1, h2, B_n := 0, 0, 1
	Sum := 0

	for i := 0; i < len(S); i++ {

		h1 = hash1(h1, int(S[i]))
		h2, B_n = hash2(h2, int(S[i]), B_n)

		H1[i] = h1
		H2[i] = h2

		if h1 == h2 {
			if i == 0 {
				K[i] = 1
			} else {
				K[i] = K[(i+1)/2-1] + 1
			}
			Sum += K[i]
		}

	}

	if S[0:3] == "aba" {
		fmt.Println(H1)
		fmt.Println(H2)
		fmt.Println(K)
	}

	return Sum
}

func solve() {
	var input bytes.Buffer

	io.Copy(&input, os.Stdin)

	var s string
	fmt.Fscanf(&input, "%s", &s)
	//fmt.Fscanf(os.Stdin, "%s", &s)

	if s[0:3] == "aba" {
		fmt.Println("debug", s)
	}

	//buf := input.Bytes()

	//d := palindrom_sum_degree(buf[:len(buf)-1])
	d := palindrom_sum_degree(s)

	fmt.Println(d)
}

func main() {
	//test()
	// bala

	solve()
	//p := quick_pow_mod(int(2), int(20), B)
	//fmt.Println(p)
}

package main

import "fmt"

import "bytes"
import "io"
import "os"

//import "strings"

var dbg = false

var B = 129
var P = 15487469 //982451653

func hash1(h, s int) int {
	return (h*B + s) % P
}

func hash2(h, s, B_n int) (int, int) {
	r := (h + s*B_n) % P
	B_n = (B_n * B) % P
	return r, B_n
}

func palindrom_sum_degree(S string) int {
	K := make([]int, len(S))
	H1 := make([]int, len(S))
	H2 := make([]int, len(S))

	h1, h2, B_n := 0, 0, 1
	Sum := 0

	for i := 0; i < len(S); i++ {

		h1 = hash1(h1, int(S[i]))
		h2, B_n = hash2(h2, int(S[i]), B_n)

		H1[i] = h1
		H2[i] = h2

		if h1 == h2 {
			if i == 0 {
				K[i] = 1
			} else {
				K[i] = K[(i+1)/2-1] + 1
			}
			Sum += K[i]
		}

	}

	if dbg && S[0:3] == "aba" {
		fmt.Println(H1)
		fmt.Println(H2)
		fmt.Println(K)
	}

	return Sum
}

func solve() {
	var input bytes.Buffer

	io.Copy(&input, os.Stdin)

	var s string
	fmt.Fscanf(&input, "%s", &s)
	//fmt.Fscanf(os.Stdin, "%s", &s)

	if dbg && s[0:3] == "aba" {
		fmt.Println("debug", s)
	}

	//buf := input.Bytes()

	//d := palindrom_sum_degree(buf[:len(buf)-1])
	d := palindrom_sum_degree(s)

	fmt.Println(d)
}

func main() {
	//test()
	// bala

	solve()
	//p := quick_pow_mod(int(2), int(20), B)
	//fmt.Println(p)
}

package main

import "fmt"

import "bytes"
import "io"
import "os"

//import "strings"

var dbg = false

func quick_pow_mod(b, e, m int) int {
	p := b
	r := int(1)
	for 0 < e {
		if e&1 == 1 {
			r = (r * p) % m
		}
		p = (p * p) % m
		e = e >> 1
	}
	return r
}

var A int = 0x1000000 - 1
var B int = 15487469

//var A int = 0x100000000 - 1
//var B int = 982451653

var A_ int = quick_pow_mod(A, B-2, B)

type Hash struct {
	h int
	n int
	a int
}

func hash_prepend(h Hash, c0 int) Hash {
	c := int(c0)
	h1 := Hash{
		h: (h.h*A + c*A) % B,
		n: h.n + 1,
		a: (h.a * A) % B,
	}
	return h1
}

func hash_shift(h Hash, c0 int) Hash {
	c := int(c0)
	var v int = (h.h - c*h.a) % B

	if v < 0 {
		v1 := v + B
		if dbg {
			fmt.Println("-", v, v1)
		}
		v = v1
	}

	h1 := Hash{
		h: v,
		n: h.n - 1,
		a: (h.a * A_) % B,
	}

	return h1
}

func init_prefix_hashes_lr(s []byte) []int {
	HH := make([]int, len(s))
	h := Hash{h: 0, n: 0, a: 1}
	for i := 0; i < len(s); i++ {
		h = hash_prepend(h, int(s[i]))
		HH[i] = int(h.h)
	}
	return HH
}

func init_prefix_hashes_rl(s []byte) []int {
	HH := make([]int, len(s))
	h := Hash{h: 0, n: 0, a: 1}
	l := len(s)
	for i := 0; i < len(s); i++ {
		h = hash_prepend(h, int(s[l-i-1]))
	}
	for i := 0; i < len(s); i++ {
		HH[l-i-1] = int(h.h)
		h = hash_shift(h, int(s[l-i-1]))
	}
	return HH
}

func palindrom_sum_degree(s []byte) int {

	LR := init_prefix_hashes_lr(s)
	RL := init_prefix_hashes_rl(s)

	S := 0
	for i := 0; i < len(s); i++ {
		P := 0
		end := i + 1

		for 0 < end {
			lr := LR[end-1]
			rl := RL[end-1]
			if lr != rl {
				break
			}
			P += 1
			end = end / 2
		}
		S += P
	}

	return S
}

func solve() {
	var input bytes.Buffer

	io.Copy(&input, os.Stdin)

	// var s string
	// fmt.Fscanf(&input, "%s", &s)
	// //s = strings.TrimSpace(s)

	// if dbg {
	// 	fmt.Println(s)
	// }

	d := palindrom_sum_degree(input.Bytes())

	fmt.Println(d)
}

func test() {
	h := Hash{h: 0, n: 0, a: 1}
	fmt.Println(h)
	h = hash_prepend(h, 'a')
	h = hash_prepend(h, 'b')
	h = hash_prepend(h, 'a')
	fmt.Println(h)
	h = hash_shift(h, 'a')
	h = hash_shift(h, 'b')
	h = hash_shift(h, 'a')
	fmt.Println(h)
}

func test2() {
	fmt.Println(A, A_, A*A_)
}

func main() {
	//test()

	solve()
	//p := quick_pow_mod(int(2), int(20), B)
	//fmt.Println(p)
}

package main

import "fmt"

import "bytes"
import "io"
import "os"

//import "strings"

var dbg = false

var B = 127
var P = 15487469 //982451653

func hash1(h, s int) int {
	return (h*B + s) % P
}

func hash2(h, s, B_n int) (int, int) {
	r := (h + s*B_n) % P
	B_n = (B_n * B) % P
	return r, B_n
}

func palindrom_sum_degree(S string) int {
	K := make([]int, len(S))
	H1 := make([]int, len(S))
	H2 := make([]int, len(S))

	h1, h2, B_n := 0, 0, 1
	Sum := 0

	for i := 0; i < len(S); i++ {

		h1 = hash1(h1, int(S[i]))
		h2, B_n = hash2(h2, int(S[i]), B_n)

		H1[i] = h1
		H2[i] = h2

		if h1 == h2 {
			if i == 0 {
				K[i] = 1
			} else {
				K[i] = K[(i+1)/2-1] + 1
			}
			Sum += K[i]
		}

	}

	if dbg && S[0:3] == "aba" {
		fmt.Println(H1)
		fmt.Println(H2)
		fmt.Println(K)
	}

	return Sum
}

func solve() {
	var input bytes.Buffer

	io.Copy(&input, os.Stdin)

	var s string
	fmt.Fscanf(&input, "%s", &s)
	//fmt.Fscanf(os.Stdin, "%s", &s)

	if dbg && s[0:3] == "aba" {
		fmt.Println("debug", s)
	}

	//buf := input.Bytes()

	//d := palindrom_sum_degree(buf[:len(buf)-1])
	d := palindrom_sum_degree(s)

	fmt.Println(d)
}

func main() {
	//test()
	// bala

	solve()
	//p := quick_pow_mod(int(2), int(20), B)
	//fmt.Println(p)
}

package main

import "fmt"

import "bytes"
import "io"
import "os"

//import "strings"

var dbg = false

var B = 255
var P = 982451653

func hash1(h, s int) int {
	return (h*B + s) % P
}

func hash2(h, s, B_n int) (int, int) {
	r := (h + s*B_n) % P
	B_n = (B_n * B) % P
	return r, B_n
}

func palindrom_sum_degree(S string) int {
	K := make([]int, len(S))
	H1 := make([]int, len(S))
	H2 := make([]int, len(S))

	h1, h2, B_n := 0, 0, 1
	Sum := 0

	for i := 0; i < len(S); i++ {

		h1 = hash1(h1, int(S[i]))
		h2, B_n = hash2(h2, int(S[i]), B_n)

		H1[i] = h1
		H2[i] = h2

		if h1 == h2 {
			if i == 0 {
				K[i] = 1
			} else {
				K[i] = K[(i+1)/2-1] + 1
			}
			Sum += K[i]
		}

	}

	if S[0:3] == "aba" {
		fmt.Println(H1)
		fmt.Println(H2)
		fmt.Println(K)
	}

	return Sum
}

func solve() {
	var input bytes.Buffer

	io.Copy(&input, os.Stdin)

	var s string
	fmt.Fscanf(&input, "%s", &s)
	//fmt.Fscanf(os.Stdin, "%s", &s)

	if s[0:3] == "aba" {
		fmt.Println("debug", s)
	}

	//buf := input.Bytes()

	//d := palindrom_sum_degree(buf[:len(buf)-1])
	d := palindrom_sum_degree(s)

	fmt.Println(d)
}

func main() {
	//test()
	// bala

	solve()
	//p := quick_pow_mod(int(2), int(20), B)
	//fmt.Println(p)
}

package main

import "fmt"

import "bytes"
import "io"
import "os"

//import "strings"

var dbg = false

var B = 255
var P = 982451653

func hash1(h, s int) int {
	return (h*B + s) % P
}

func hash2(h, s, B_n int) (int, int) {
	r := (h + s*B_n) % P
	B_n = (B_n * B) % P
	return r, B_n
}

func palindrom_sum_degree(S string) int {
	K := make([]int, len(S))
	h1, h2, B_n := 0, 0, 1
	Sum := 0

	for i := 0; i < len(S); i++ {

		h1 = hash1(h1, int(S[i]))
		h2, B_n = hash2(h2, int(S[i]), B_n)

		if h1 == h2 {
			if i == 0 {
				K[i] = 1
			} else {
				K[i] = K[(i+1)/2-1] + 1
			}
			Sum += K[i]
		}

	}
	return Sum
}

func solve() {
	var input bytes.Buffer

	io.Copy(&input, os.Stdin)

	var s string
	fmt.Fscanf(&input, "%s", &s)
	//fmt.Fscanf(os.Stdin, "%s", &s)

	//buf := input.Bytes()

	//d := palindrom_sum_degree(buf[:len(buf)-1])
	d := palindrom_sum_degree(s)

	fmt.Println(d)
}

func main() {
	//test()

	solve()
	//p := quick_pow_mod(int(2), int(20), B)
	//fmt.Println(p)
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	s, _ := reader.ReadString('\n')
	var i int
	for i < len(s) && (s[i] >= 'a' && s[i] <= 'z' || s[i] >= 'A' && s[i] <= 'Z' || s[i] >= '0' && s[i] <= '9') {
		i++
	}
	fmt.Println(solve(s[:i]))
}

func solve(s string) int64 {
	p := manachers(s)

	n := len(s)

	dp := make([]int64, n)
	dp[0] = 1
	for i := 2; i <= n; i++ {
		if p[i-1] == 0 && p[i/2-1] == 0 {
			//prefix s[0..i] is palindrome
			dp[i-1] = dp[i/2-1] + 1
		}
	}

	var res int64

	for i := 0; i < n; i++ {
		res = max(res, (1+dp[i])*(dp[i])/2)
	}

	return res
}

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

func manachers(s string) []int {
	ss := modify(s)
	n := len(ss)
	P := make([]int, n)
	var c, r int

	for i := 0; i < n; i++ {
		mirror := 2*c - r

		if i < r {
			P[i] = min(r-i, P[mirror])
		}
		a := i + 1 + P[i]
		b := i - (1 + P[i])
		for a < n && b >= 0 && ss[a] == ss[b] {
			P[i]++
			a++
			b--
		}

		if i+P[i] > r {
			r = i + P[i]
			c = i
		}
	}
	f := make([]int, len(s))
	for i := 0; i < len(s); i++ {
		f[i] = i
	}
	for i := 0; i < n; i++ {
		//l := P[i]
		// #a#a#b#
		a := i + P[i]
		b := i - P[i]
		a--
		b++
		if a > b || i%2 != 0 {
			f[a/2] = min(f[a/2], b/2)
		}
	}
	return f
}

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

func modify(s string) string {
	var buf bytes.Buffer

	for i := 0; i < len(s); i++ {
		buf.WriteByte('#')
		buf.WriteByte(s[i])
	}
	buf.WriteByte('#')
	return buf.String()
}

package main

import (
	"bufio"
	"bytes"
	"log"
	"os"
)

const (
	p = 1610612741
	b = 255
)

var (
	bases []int64
)

func main() {
	var (
		s       string
		ki, res int
		l, r    RollingHash

		in  = bufio.NewScanner(os.Stdin)
		buf = make([]byte, 6000000)
	)
	in.Buffer(buf, len(buf))
	in.Scan()

	if err := in.Err(); err != nil {
		log.Fatal(err)
	}

	s = in.Text()

	bases = make([]int64, len(s))
	bases[0] = 1
	bases[1] = b

	var bx int64 = b
	for i := 2; i < len(s); i++ {
		bx = bx * b % p
		bases[i] = bx
	}

	for i, c := range s {
		n := i + 1
		nm := n % 2

		r.Push(c)

		if n == 1 || (nm == 0 && n != 2) {
			l.Push(rune(s[i/2]))
		} else {
			r.Shift()
		}

		if l.Value() == r.Value() {
			ki += 1
			res += ki
		}
	}

	println(res)
}

type RollingHash struct {
	size  int
	value int64
	buf   bytes.Buffer
}

func NewRollingHash(s string) (h RollingHash) {
	for _, c := range s {
		h.Push(c)
	}
	return h
}

func (h *RollingHash) Push(c rune) {
	if _, err := h.buf.WriteRune(c); err != nil {
		log.Fatal(err)
	}
	h.value = (h.value*b + int64(c)) % p
	h.size += 1
}

func (h *RollingHash) Shift() {
	c, _, err := h.buf.ReadRune()
	if err != nil {
		log.Fatal(err)
	}
	h.value = (h.value - int64(c)*bases[h.size-1]) % p
	if h.value < 0 {
		h.value += p
	}
	h.size -= 1
}

func (h RollingHash) Len() int {
	return h.size
}

func (h RollingHash) Value() int64 {
	return h.value
}

func (h RollingHash) String() string {
	return h.buf.String()
}

package main

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

const (
	p = 1610612741
)

func main() {
	var (
		err error
		s   string

		in = bufio.NewReader(os.Stdin)
	)

	if s, err = in.ReadString(byte('\n')); err != nil {
		log.Fatal(err)
	}

	s = s[:len(s)-1]

	var (
		l, r   int64
		n, res int
		b      int64 = 255
		base   int64 = 1
		k            = make([]int, len(s)+1)
	)

	for i, c := range s {
		n = i + 1
		l = (l*b + int64(c)) % p
		r = (r + int64(c)*base) % p

		if l == r {
			k[n] = k[n/2] + 1
		}

		res += k[n]
		base = base * b
	}

	fmt.Println(res)
}

package main

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

const (
	p = 1610612741
)

func main() {
	var (
		err error
		s   string

		in = bufio.NewReader(os.Stdin)
	)

	if s, err = in.ReadString(byte('\n')); err != nil {
		log.Fatal(err)
	}

	s = s[:len(s)-1]

	var (
		l, r, n, res int
		b            = 255
		base         = 1
		k            = make([]int, len(s)+1)
	)

	for i, c := range s {
		n = i + 1
		l = (l*b + int(c)) % p
		r = (r + int(c)*base) % p

		if l == r {
			k[n] = k[n/2] + 1
		}

		res += k[n]
		base = (base * b) % p
	}

	fmt.Println(res)
}

package main

import (
	"bufio"
	"bytes"
	"log"
	"os"
)

const (
	p = 1610612741
	b = 255
)

// var (
// 	bases []int
// )

func main() {
	var (
		s       string
		ki, res int
		l, r    RollingHash

		in  = bufio.NewScanner(os.Stdin)
		buf = make([]byte, 6000000)
	)
	in.Buffer(buf, len(buf))
	in.Scan()

	if err := in.Err(); err != nil {
		log.Fatal(err)
	}

	s = in.Text()

	// bases = make([]int, len(s))
	// bases[0] = 1
	// bases[1] = b

	// var bx int = b
	// for i := 2; i < len(s); i++ {
	// 	bx = bx * b % p
	// 	bases[i] = bx
	// }

	for i, c := range s {
		n := i + 1
		nm := n % 2

		r.Push(c)

		if n == 1 || (nm == 0 && n != 2) {
			l.Push(rune(s[i/2]))
		} else {
			r.Shift()
		}

		if l.Value() == r.Value() {
			ki += 1
			res += ki
		}
	}

	println(res)
}

type RollingHash struct {
	size  int
	value int
	buf   bytes.Buffer
}

func NewRollingHash(s string) (h RollingHash) {
	return h
}

func (h *RollingHash) Push(c rune) {
}

func (h *RollingHash) Shift() {
}

func (h RollingHash) Len() int {
	return h.size
}

func (h RollingHash) Value() int {
	return h.value
}

func (h RollingHash) String() string {
	return h.buf.String()
}

// type RollingHash struct {
// 	size  int
// 	value int
// 	buf   bytes.Buffer
// }

// func NewRollingHash(s string) (h RollingHash) {
// 	for _, c := range s {
// 		h.Push(c)
// 	}
// 	return h
// }

// func (h *RollingHash) Push(c rune) {
// 	if _, err := h.buf.WriteRune(c); err != nil {
// 		log.Fatal(err)
// 	}
// 	h.value = (h.value*b + int(c)) % p
// 	h.size += 1
// }

// func (h *RollingHash) Shift() {
// 	c, _, err := h.buf.ReadRune()
// 	if err != nil {
// 		log.Fatal(err)
// 	}
// 	h.value = (h.value - int(c)*bases[h.size-1]) % p
// 	if h.value < 0 {
// 		h.value += p
// 	}
// 	h.size -= 1
// }

// func (h RollingHash) Len() int {
// 	return h.size
// }

// func (h RollingHash) Value() int {
// 	return h.value
// }

// func (h RollingHash) String() string {
// 	return h.buf.String()
// }

package main

import "fmt"

func main() {
	fmt.Println("1")
}

package main

import (
	"bufio"
	"bytes"
	"log"
	"os"
)

const (
	p = 1610612741
	b = 255
)

var (
	bases []int
)

func main() {
	var (
		s       string
		ki, res int
		l, r    RollingHash

		in  = bufio.NewScanner(os.Stdin)
		buf = make([]byte, 6000000)
	)
	in.Buffer(buf, len(buf))
	in.Scan()

	if err := in.Err(); err != nil {
		log.Fatal(err)
	}

	s = in.Text()

	bases = make([]int, len(s))
	bases[0] = 1
	bases[1] = b

	var bx int = b
	for i := 2; i < len(s); i++ {
		bx = bx * b % p
		bases[i] = bx
	}

	for i, c := range s {
		n := i + 1
		nm := n % 2

		r.Push(c)

		if n == 1 || (nm == 0 && n != 2) {
			l.Push(rune(s[i/2]))
		} else {
			r.Shift()
		}

		if l.Value() == r.Value() {
			ki += 1
			res += ki
		}
	}

	println(res)
}

type RollingHash struct {
	size  int
	value int
	buf   bytes.Buffer
}

func NewRollingHash(s string) (h RollingHash) {
	return h
}

func (h *RollingHash) Push(c rune) {
}

func (h *RollingHash) Shift() {
}

func (h RollingHash) Len() int {
	return h.size
}

func (h RollingHash) Value() int {
	return h.value
}

func (h RollingHash) String() string {
	return h.buf.String()
}

// type RollingHash struct {
// 	size  int
// 	value int
// 	buf   bytes.Buffer
// }

// func NewRollingHash(s string) (h RollingHash) {
// 	for _, c := range s {
// 		h.Push(c)
// 	}
// 	return h
// }

// func (h *RollingHash) Push(c rune) {
// 	if _, err := h.buf.WriteRune(c); err != nil {
// 		log.Fatal(err)
// 	}
// 	h.value = (h.value*b + int(c)) % p
// 	h.size += 1
// }

// func (h *RollingHash) Shift() {
// 	c, _, err := h.buf.ReadRune()
// 	if err != nil {
// 		log.Fatal(err)
// 	}
// 	h.value = (h.value - int(c)*bases[h.size-1]) % p
// 	if h.value < 0 {
// 		h.value += p
// 	}
// 	h.size -= 1
// }

// func (h RollingHash) Len() int {
// 	return h.size
// }

// func (h RollingHash) Value() int {
// 	return h.value
// }

// func (h RollingHash) String() string {
// 	return h.buf.String()
// }

package main

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

func main() {
	var (
		err error
		s   string

		in = bufio.NewReader(os.Stdin)
	)

	if s, err = in.ReadString(byte('\n')); err != nil {
		log.Fatal(err)
	}

	s = s[:len(s)-1]

	var (
		l, r, n, res int
		b            = 255
		base         = 1
		k            = make([]int, len(s)+1)
	)

	for i, c := range s {
		n = i + 1
		l = l*b + int(c)
		r = r + int(c)*base

		if l == r {
			k[n] = k[n/2] + 1
		}

		res += k[n]
		base = base * b
	}

	fmt.Println(res)
}

package main

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

const (
	p = 1610612741
	b = 255
)

var (
	bases []int64
)

func main() {
	var (
		err     error
		s       string
		ki, res int
		l, r    RollingHash

		in = bufio.NewReader(os.Stdin)
	)

	if s, err = in.ReadString(byte('\n')); err != nil {
		log.Fatal(err)
	}

	bases = make([]int64, len(s))
	bases[0] = 1
	bases[1] = b

	var bx int64 = b
	for i := 2; i < len(s); i++ {
		bx = bx * b % p
		bases[i] = bx
	}

	for i, c := range s {
		n := i + 1
		nm := n % 2

		r.Push(c)

		if n == 1 || (nm == 0 && n != 2) {
			l.Push(rune(s[i/2]))
		} else {
			r.Shift()
		}

		if l.Value() == r.Value() {
			ki += 1
			res += ki
		}
	}

	fmt.Println(res)
}

type RollingHash struct {
	size  int
	value int64
	buf   bytes.Buffer
}

func NewRollingHash(s string) (h RollingHash) {
	for _, c := range s {
		h.Push(c)
	}
	return h
}

func (h *RollingHash) Push(c rune) {
	if _, err := h.buf.WriteRune(c); err != nil {
		log.Fatal(err)
	}
	h.value = (h.value*b + int64(c)) % p
	h.size += 1
}

func (h *RollingHash) Shift() {
	c, _, err := h.buf.ReadRune()
	if err != nil {
		log.Fatal(err)
	}
	h.value = (h.value - int64(c)*bases[h.size-1]) % p
	if h.value < 0 {
		h.value += p
	}
	h.size -= 1
}

func (h RollingHash) Len() int {
	return h.size
}

func (h RollingHash) Value() int64 {
	return h.value
}

func (h RollingHash) String() string {
	return h.buf.String()
}

package main

import (
	"bufio"
	"bytes"
	"log"
	"os"
)

const (
	p = 1610612741
	b = 255
)

var (
	bases []int64
)

func main() {
	var (
		err     error
		s       string
		ki, res int
		l, r    RollingHash

		in = bufio.NewReader(os.Stdin)
	)
	if s, err = in.ReadString(byte('\n')); err != nil {
		log.Fatal(err)
	}

	bases = make([]int64, len(s))
	bases[0] = 1
	bases[1] = b

	var bx int64 = b
	for i := 2; i < len(s); i++ {
		bx = bx * b % p
		bases[i] = bx
	}

	for i, c := range s {
		n := i + 1
		nm := n % 2

		r.Push(c)

		if n == 1 || (nm == 0 && n != 2) {
			l.Push(rune(s[i/2]))
		} else {
			r.Shift()
		}

		if l.Value() == r.Value() {
			ki += 1
			res += ki
		}
	}

	println(res)
}

type RollingHash struct {
	size  int
	value int64
	buf   bytes.Buffer
}

func NewRollingHash(s string) (h RollingHash) {
	for _, c := range s {
		h.Push(c)
	}
	return h
}

func (h *RollingHash) Push(c rune) {
	if _, err := h.buf.WriteRune(c); err != nil {
		log.Fatal(err)
	}
	h.value = (h.value*b + int64(c)) % p
	h.size += 1
}

func (h *RollingHash) Shift() {
	c, _, err := h.buf.ReadRune()
	if err != nil {
		log.Fatal(err)
	}
	h.value = (h.value - int64(c)*bases[h.size-1]) % p
	if h.value < 0 {
		h.value += p
	}
	h.size -= 1
}

func (h RollingHash) Len() int {
	return h.size
}

func (h RollingHash) Value() int64 {
	return h.value
}

func (h RollingHash) String() string {
	return h.buf.String()
}

package main

import (
	"bufio"
	"bytes"
	"log"
	"os"
)

const (
	p = 1610612741
	b = 255
)

var (
	bases []int64
)

func main() {
	println("1")
}

func main2() {
	var (
		s       string
		ki, res int
		l, r    RollingHash

		in  = bufio.NewScanner(os.Stdin)
		buf = make([]byte, 6000000)
	)
	in.Buffer(buf, len(buf))
	in.Scan()

	if err := in.Err(); err != nil {
		log.Fatal(err)
	}

	s = in.Text()

	bases = make([]int64, len(s))
	bases[0] = 1
	bases[1] = b

	var bx int64 = b
	for i := 2; i < len(s); i++ {
		bx = bx * b % p
		bases[i] = bx
	}

	for i, c := range s {
		n := i + 1
		nm := n % 2

		r.Push(c)

		if n == 1 || (nm == 0 && n != 2) {
			l.Push(rune(s[i/2]))
		} else {
			r.Shift()
		}

		if l.Value() == r.Value() {
			ki += 1
			res += ki
		}
	}

	println(res)
}

type RollingHash struct {
	size  int
	value int64
	buf   bytes.Buffer
}

func NewRollingHash(s string) (h RollingHash) {
	for _, c := range s {
		h.Push(c)
	}
	return h
}

func (h *RollingHash) Push(c rune) {
	if _, err := h.buf.WriteRune(c); err != nil {
		log.Fatal(err)
	}
	h.value = (h.value*b + int64(c)) % p
	h.size += 1
}

func (h *RollingHash) Shift() {
	c, _, err := h.buf.ReadRune()
	if err != nil {
		log.Fatal(err)
	}
	h.value = (h.value - int64(c)*bases[h.size-1]) % p
	if h.value < 0 {
		h.value += p
	}
	h.size -= 1
}

func (h RollingHash) Len() int {
	return h.size
}

func (h RollingHash) Value() int64 {
	return h.value
}

func (h RollingHash) String() string {
	return h.buf.String()
}

package main

func main() {
	println("1")
}

package main

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

const (
	p = 1610612741
)

func main() {
	var (
		err error
		s   string

		in = bufio.NewReader(os.Stdin)
	)

	if s, err = in.ReadString(byte('\n')); err != nil {
		log.Fatal(err)
	}

	s = s[:len(s)-1]

	var (
		l, r, n, res int
		b            = 255
		base         = 1
		k            = make([]int, len(s)+1)
	)

	for i, c := range s {
		n = i + 1
		l = (l*b + int(c)) % p
		r = (r + int(c)*base) % p

		if l == r {
			k[n] = k[n/2] + 1
		}

		res += k[n]
		base = base * b
	}

	fmt.Println(res)
}

package main

import (
	"bufio"
	"bytes"
	"log"
	"os"
)

const (
	p = 1610612741
	b = 255
)

var (
	bases []int
)

func main() {
	var (
		s       string
		ki, res int
		l, r    RollingHash

		in  = bufio.NewScanner(os.Stdin)
		buf = make([]byte, 6000000)
	)
	in.Buffer(buf, len(buf))
	in.Scan()

	if err := in.Err(); err != nil {
		log.Fatal(err)
	}

	s = in.Text()

	bases = make([]int, len(s))
	bases[0] = 1
	bases[1] = b

	var bx int = b
	for i := 2; i < len(s); i++ {
		bx = bx * b % p
		bases[i] = bx
	}

	for i, c := range s {
		n := i + 1
		nm := n % 2

		r.Push(c)

		if n == 1 || (nm == 0 && n != 2) {
			l.Push(rune(s[i/2]))
		} else {
			r.Shift()
		}

		if l.Value() == r.Value() {
			ki += 1
			res += ki
		}
	}

	println(res)
}

type RollingHash struct {
	size  int
	value int
	buf   bytes.Buffer
}

func NewRollingHash(s string) (h RollingHash) {
	for _, c := range s {
		h.Push(c)
	}
	return h
}

func (h *RollingHash) Push(c rune) {
	if _, err := h.buf.WriteRune(c); err != nil {
		log.Fatal(err)
	}
	h.value = (h.value*b + int(c)) % p
	h.size += 1
}

func (h *RollingHash) Shift() {
	c, _, err := h.buf.ReadRune()
	if err != nil {
		log.Fatal(err)
	}
	h.value = (h.value - int(c)*bases[h.size-1]) % p
	if h.value < 0 {
		h.value += p
	}
	h.size -= 1
}

func (h RollingHash) Len() int {
	return h.size
}

func (h RollingHash) Value() int {
	return h.value
}

func (h RollingHash) String() string {
	return h.buf.String()
}


package main

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

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

	var n, m, p, q, l, r int
	Fscan(in, &n, &m)
	bad := make([]bool, m)
	var pre, cur string
	for Fscan(in, &pre); n > 1; n-- {
		Fscan(in, &cur)
		for j := 1; j < m; j++ {
			if cur[j-1] == 'X' && pre[j] == 'X' {
				bad[j] = true
			}
		}
		pre = cur
	}
	left := make([]int, m)
	for i, b := range bad {
		if b {
			p = i
		}
		left[i] = p
	}
	for Fscan(in, &q); q > 0; q-- {
		Fscan(in, &l, &r)
		if left[r-1] >= l {
			Fprintln(out, "NO")
		} else {
			Fprintln(out, "YES")
		}
	}
}

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

package main

import (
	"bufio"
	"fmt"
	"os"
)
func main() {
	var n, m int
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	fmt.Fscan(in,&n,&m)
	g := make([][]byte,n+5)
	for i:=0;i<=n;i++{
		g[i] = make([]byte,m+5)
	}
	f := make([][]int,n+5)
	for i:=0;i<=n;i++{
		f[i] = make([]int,m+5)
	}
	for i:=0;i<n;i++{
		fmt.Fscan(in, &g[i])
	}
	for i:=1;i<=n;i++{
		for j:=1;j<=m;j++{
			if i==1&&j==1{
				f[i][j] = 0
				continue
			}
			if j==1{
				f[i][j]=0
				continue
			}
			if i==1{
				f[i][j]=0
				continue
			}
			now := 0
			if g[i-2][j-1]=='X'&&g[i-1][j-2]=='X'{
				now = 1
			}
			f[i][j] = f[i-1][j]+f[i][j-1]-f[i-1][j-1] + now
		}
	}
	var q int
	fmt.Fscan(in,&q)
	for i:=1;i<=q;i++{
		var l, r int
		fmt.Fscan(in,&l,&r)
		if f[n][r]-f[n][l]==0{
			fmt.Fprintln(out,"YES")
		}else{
			fmt.Fprintln(out,"NO")
		}
	}
}

package main

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

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

	var n, m, p, q, l, r int
	var pre, cur string
	Fscan(in, &n, &m, &pre)
	bad := make([]bool, m)
	for ; n > 1; n-- {
		Fscan(in, &cur)
		for j := 1; j < m; j++ {
			if cur[j-1] == 'X' && pre[j] == 'X' {
				bad[j] = true
			}
		}
		pre = cur
	}
	left := make([]int, m)
	for i, b := range bad {
		if b {
			p = i
		}
		left[i] = p
	}
	for Fscan(in, &q); q > 0; q-- {
		Fscan(in, &l, &r)
		if left[r-1] >= l {
			Fprintln(out, "NO")
		} else {
			Fprintln(out, "YES")
		}
	}
}

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

package main

import (
	"bufio"
	"fmt"
	"os"
)
func main() {
	var n, m int
	in := bufio.NewReader(os.Stdin)
	out := os.Stdout
	fmt.Fscan(in,&n,&m)
	g := make([][]byte,n+5)
	for i:=0;i<=n;i++{
		g[i] = make([]byte,m+5)
	}
	f := make([][]int,n+5)
	for i:=0;i<=n;i++{
		f[i] = make([]int,m+5)
	}
	for i:=0;i<n;i++{
		fmt.Fscan(in, &g[i])
	}
	for i:=1;i<=n;i++{
		for j:=1;j<=m;j++{
			if i==1&&j==1{
				f[i][j] = 0
				continue
			}
			if j==1{
				f[i][j]=0
				continue
			}
			if i==1{
				f[i][j]=0
				continue
			}
			now := 0
			if g[i-1][j-1]=='.'&&g[i-2][j-1]=='X'&&g[i-1][j-2]=='X'{
				now = 1
			}
			f[i][j] = f[i-1][j]+f[i][j-1]-f[i-1][j-1] + now
		}
	}
	var q int
	fmt.Fscan(in,&q)
	for i:=1;i<=q;i++{
		var l, r int
		fmt.Fscan(in,&l,&r)
		if f[n][r]-f[n][l]==0{
			fmt.Fprintln(out,"YES")
		}else{
			fmt.Fprintln(out,"NO")
		}
	}
}


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

	solve := func() (ans int64) {
		var n, good, bad int64
		Fscan(in, &n, &good, &bad)
		s := good + bad

		half := (n-1)/2 + 1

		segCnt, left := n/s, n%s
		cntGood := segCnt * good
		if left > good {
			cntGood += good
		} else {
			cntGood += left
		}

		if cntGood >= half {
			return n
		}

		needFullGood,leftGood := half/good,half%good
		if leftGood == 0 {
			needFullGood--
			leftGood = good
		}
		leftBad := n-half
		leftBad = 0
		return needFullGood*s + leftGood-leftBad
	}

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

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

package main

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

func main() {
	defer Flush()

	t := readi()
	for i := 0; i < t; i++ {
		n := readll()
		g := readll()
		b := readll()
		println(solve(n, g, b))
	}
}

func solvex(n, g, b int64) int64 {
	ng := (n + 1) / 2
	nb := n - ng

	var d int64
	for 0 < ng || 0 < nb {
		e := minll(ng, g)
		ng -= e
		d += e

		if 0 == ng {
			d += nb
			break
		}
		nb = maxll(0, nb-b)
		d += b
	}
	return d
}

func solve(n, g, b int64) int64 {
	ng := (n + 1) / 2
	nb := n - ng

	k := ng / g
	if k == 0 {
		return n
	}
	d := k*g + (k-1)*b
	ng %= g
	nb = maxll(0, nb-(k-1)*b)
	if ng == 0 {
		return d + nb
	} else {
		if nb <= b {
			return d + ng + b
		} else {
			return d + ng + b + (nb - b)
		}
	}
}

// -----------------------------------------------------------------------------

// IO helper functions

// Returns next token from input.  It must be initialized by SetInput()
// before the first call.
var nextToken func() ([]byte, error)
var nextLine func() ([]byte, error)

// Holds a buffer for output.  It must be initialized by SetOutput().
// All IO fucntions (read*() and [e]print*()) should write to OutputWriter
// instead of this.
var OutputBuffer *bufio.Writer

// Holds an io.Writer.  It must be initialized by SetOutput()
var OutputWriter io.Writer

// Set IO functions for interactive input/output.
func SetInteractive(w io.Writer, r io.Reader) {
	SetUnbefferedInput(r)
	OutputBuffer = nil
	OutputWriter = w
}

// Setup OutputBuffer and OutputWriter.
func SetOutput(w io.Writer) {
	OutputBuffer = bufio.NewWriter(w)
	OutputWriter = OutputBuffer
}

// Flushes OutputBuffer
func Flush() {
	if OutputBuffer != nil {
		OutputBuffer.Flush()
	}
}

// Returns true if c is a white space
func IsSpace(c byte) bool {
	switch c {
	case '\t', '\n', '\v', '\f', '\r', ' ':
		return true
	}
	return false
}

func IsNewLine(c byte) bool {
	switch c {
	case '\n', '\r':
		return true
	}
	return false
}

// Setup nextToken with input buffer.
func SetInput(r io.Reader) {
	buf := new(bytes.Buffer)
	var b []byte

	var i int
	rest := func() ([]byte, error) {
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		return b[j:i], nil
	}
	initial := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextToken = rest
		return rest()
	}
	nextToken = initial

	restLn := func() ([]byte, error) {
		for i < len(b) && IsNewLine(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsNewLine(b[i]) {
			i++
		}
		return b[j:i], nil
	}

	initialLn := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextLine = restLn
		return restLn()
	}
	nextLine = initialLn
}

// Setup nextToken without input buffer.
func SetUnbefferedInput(r io.Reader) {
	buf := bufio.NewReader(r)
	var b []byte

	var i int
	nextToken = func() ([]byte, error) {
		var err error
		if i == len(b) {
			b, err = buf.ReadBytes('\n')
			if err != nil {
				return nil, err
			}
			i = 0
			j := len(b) - 1
			for 0 <= j && IsSpace(b[j]) {
				j--
			}
			b = b[0 : j+1]
		}
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		if i == j {
			return nil, io.ErrUnexpectedEOF
		}
		return b[j:i], nil
	}
}

// -----------------------------------------------------------------------------

// IO functions

// Reads next token and return it as []byte
func readb() []byte {
	b, err := nextToken()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

// Reads next token and return it as string
func reads() string {
	return string(readb())
}

// Read next line as []byte.  Trailing '\n' will not be included.
// See also comments on readb()
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

// Read next line as string
func readsln() string {
	return string(readbln())
}

// Reads next token and return it as int64
func readll() int64 {
	i, err := strconv.ParseInt(reads(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// Reads next token and return it as int
func readi() int {
	return int(readll())
}

// Reads next token and return it as float64
func readf() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// Write args to OutputWriter with the format f
func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(OutputWriter, f, args...)
}

// Write args to OutputWriter without format
func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(OutputWriter, args...)
}

// Write args to stderr with the format f
func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// Write args to stderr without format
func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// -----------------------------------------------------------------------------

// Utilities

func sumSlice(a []int) int {
	var res int
	for _, v := range a {
		res += v
	}
	return res
}

func sumSlicell(a []int64) int64 {
	var res int64
	for _, v := range a {
		res += v
	}
	return res
}

func readInts(N int) (int, []int) {
	if N == 0 {
		N = readi()
	}
	a := make([]int, N)
	for i := range a {
		a[i] = readi()
	}
	return N, a
}

func readIntsll(N int) (int, []int64) {
	if N == 0 {
		N = readi()
	}
	a := make([]int64, N)
	for i := range a {
		a[i] = readll()
	}
	return N, a
}

// reverse slice in place
func reverse(a []int) {
	for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
}

// areverse: allocating reverse
func areverse(a []int) []int {
	b := make([]int, len(a))
	for i := range a {
		b[i] = a[len(a)-i-1]
	}
	return b
}

// -----------------------------------------------------------------------------

// Simple math functions

const (
	// big prime
	INF  = 1000000007
	INF2 = 1000000009
	INF3 = 998244353
)

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

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

func minf(a, b float64) float64 {
	if a < b {
		return a
	}
	return b
}

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

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

func maxf(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

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

func absll(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func absf(a float64) float64 {
	if a < 0 {
		return -a
	}
	return a
}

// egcd(a, b) returns d, x, y:
//   d is gcd(a,b)
//   x, y are  integers that satisfy ax + by = d
func egcd(a, b int) (int, int, int) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcd(b, a%b)
	return d, y, x - a/b*y
}

func egcdll(a, b int64) (int64, int64, int64) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcdll(b, a%b)
	return d, y, x - a/b*y
}

func gcd(a, b int) int {
	d, _, _ := egcd(a, b)
	return d
}

func gcdll(a, b int64) int64 {
	d, _, _ := egcdll(a, b)
	return d
}

// set up IO functions
func init() {
	// for non-interactive
	SetInput(os.Stdin)
	SetOutput(os.Stdout)

	// Enable below when interactive.  Its ok to leave above intact.
	// SetInteractive(os.Stdout, os.Stdin)
}

package main

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

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

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

func main() {
  defer writer.Flush()
  var t int64
  scanf("%d\n", &t)
  var n, g, b int64
  for i := int64(0); i < t; i++ {
    scanf("%d %d %d\n", &n, &g, &b)
    solve(n, g, b)
  }
}

func solve(n, g, b int64) {
  if g >= b {
    printf("%d\n", n)
  } else {
    var gtarget int64 = n - n/2
    var rounds int64 = gtarget / g
    if gtarget%g == 0 {
      printf("%d\n", max(n, (rounds-1)*(g+b)+g))
    } else {
      printf("%d\n", max(n, rounds*(g+b)+gtarget%g))
    }
  }
}

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

package main

import (
    "fmt"
)

func main() {
    var tt int
    fmt.Scan(&tt)
    for xxx := 0; xxx < tt; xxx++ {
        var n, g, b int64
        fmt.Scan(&n)
        fmt.Scan(&g)
        fmt.Scan(&b)
        if g >= n {
            fmt.Println(n)
        } else {
            var cv int64 = (n + 1) / 2
            var ans int64 = cv + ((cv - 1) / g) * b
            if ans < n {
                ans = n
            }
            fmt.Println(ans)
        }
    }
}

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscanf(in, "%d\n", &t)
	for tt := 0; tt < t; tt++ {
		n, g, b := int64(0), int64(0), int64(0)
		fmt.Fscanf(in, "%d %d %d\n", &n, &g, &b)
		ans := int64(0)
		if b <= g || g >= (n+1)/2 {
			ans = n
		} else {
			totalNeeded := (n + 1) / 2
			n -= g
			totalNeeded -= g
			ans = g
			round := totalNeeded / g
			if totalNeeded%g != 0 {
				round++
			}
			days := round * (g + b)
			days -= min(round*g-totalNeeded, round*(g+b)-n)
			ans += days
		}
		fmt.Fprintf(out, "%d\n", ans)
	}
	return
}

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

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

/**
 * Copyright shopee
 * @Author : Yuxiang.Lei
 * @MailBox: Yuxiang.Lei@shopee.com
 * @Date : 2020-02-12
 * @Version: v2.4
 **/

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	numStr := scanner.Text()
	num, _ := strconv.ParseInt(numStr, 10, 64)
	for i := int64(0); i < num; i++ {
		scanner.Scan()
		numsstr := scanner.Text()
		nums := strings.Split(numsstr, " ")
		n, _ := strconv.ParseInt(nums[0], 10, 64)
		g, _ := strconv.ParseInt(nums[1], 10, 64)
		b, _ := strconv.ParseInt(nums[2], 10, 64)
		goodMax := int64(0)
		if n % 2 == 1 {
			goodMax = n / 2 + 1
		} else {
			goodMax = n / 2
		}
		circle := goodMax / g - 1
		if circle < 0 {
			circle = 0
		}
		leftgoods := goodMax - g * circle
		result := (g + b) * circle
		if leftgoods <= g {
			result += leftgoods
		} else {
			result += leftgoods + b
		}
		if result < n {
			result = n
		}
		fmt.Println(result)
	}

}

package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string { sc.Scan(); return sc.Text() }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

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

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

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1000000)

	tests := scanInt()
	for t := 0; t < tests; t++ {
		n := scanInt64()
		g := scanInt64()
		b := scanInt64()

		ans := int64(0)
		if (n+1)/2 <= g || b <= g {
			fmt.Println(n)
			continue
		}

		ans += (n+1)/2
		ans += ((n+1)/2-g+g-1)/g*b

		if ans < n {
			ans = n
		}

		fmt.Println(ans)
	}
}

package main

import "fmt"
import "os"
import "bufio"
import "strings"
import "strconv"

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Scan()
    line := scanner.Text()
    t, _ := strconv.Atoi(line)
    for i := 0; i < t; i++ {
        scanner.Scan()
        line = scanner.Text()
        parts := strings.Split(line, " ")
        _n, _ := strconv.Atoi(parts[0])
        _g, _ := strconv.Atoi(parts[1])
        _b, _ := strconv.Atoi(parts[2])

        n := uint64(_n)
        g := uint64(_g)
        b := uint64(_b)
        //~ fmt.Println(n, g, b)

        min_good := n / 2 + (n % 2) // ceil n/2
        cycles, rem_good := min_good / g, min_good % g
        if rem_good == 0  && cycles > 0 {
            cycles--
            rem_good += g
        }
        days := cycles * (g + b) + rem_good
        if days < n {
            days = n
        }
        //~ fmt.Println(min_good, cycles, rem_good, days)
        fmt.Println(days)
    }
}

package main

import "fmt"

var t, n, g, d int64

func main() {
	fmt.Scan(&t)
	for ; t > 0; t-- {
		fmt.Scan(&n, &g, &d)
		if g >= d {
			fmt.Println(n)
			continue
		}
		gdays := (n + 1) >> 1
		ddays := n - gdays
		gtimes := (gdays - 1) / g
		dtimes := (ddays - 1) / d + 1
		if(gtimes >= dtimes) {
			ans := gtimes * (g + d) + gdays % g
			if gdays % g == 0 {
				ans += g
			}
			fmt.Println(ans)
			continue
		}
		fmt.Println(n)
	}
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1303B(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	searchRange := func(l, r int64, f func(int64) bool) int64 {
		i, j := l, r
		for i < j {
			h := (i + j) >> 1
			if f(h) {
				j = h
			} else {
				i = h + 1
			}
		}
		return i
	}

	solve := func() (ans int64) {
		var n, g, b int64
		Fscan(in, &n, &g, &b)
		sum := g + b
		half := (n-1)/2 + 1
		return searchRange(n, 1e18, func(days int64) bool {
			seg, left := days/sum, days%sum
			if left > g {
				left = g
			}
			return seg*g+left >= half
		})
	}
	var t int
	for Fscan(in, &t); t > 0; t-- {
		Fprintln(out, solve())
	}
}

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscanf(in, "%d\n", &t)
	for tt := 0; tt < t; tt++ {
		n, g, b := int64(0), int64(0), int64(0)
		fmt.Fscanf(in, "%d %d %d\n", &n, &g, &b)
		ans := int64(0)
		if b <= g || g >= n {
			ans = n
		} else {
			totalNeeded := (n + 1) / 2
			n -= g
			totalNeeded -= g
			ans = g
			round := totalNeeded / g
			if totalNeeded%g != 0 {
				round++
			}
			days := round * (g + b)
			days -= min(round*g-totalNeeded, round*(g+b)-n)
			ans += days
		}
		fmt.Fprintf(out, "%d\n", ans)
	}
	return
}

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

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

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := 0
	fmt.Fscanf(in, "%d\n", &t)
	for tt := 0; tt < t; tt++ {
		n, g, b := int64(0), int64(0), int64(0)
		fmt.Fscanf(in, "%d %d %d\n", &n, &g, &b)
		ans := int64(0)
		if b <= g {
			ans = n
		} else {
			totalNeeded := (n + 1) / 2
			n -= g
			totalNeeded -= g
			ans = g
			round := totalNeeded / g
			if totalNeeded%g != 0 {
				round++
			}
			days := round * (g + b)
			days -= min(round*g-totalNeeded, round*(g+b)-n)
			ans += days
		}
		fmt.Fprintf(out, "%d\n", ans)
	}
	return
}

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

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

/**
 * Copyright shopee
 * @Author : Yuxiang.Lei
 * @MailBox: Yuxiang.Lei@shopee.com
 * @Date : 2020-02-12
 * @Version: v2.4
 **/

package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	numStr := scanner.Text()
	num, _ := strconv.ParseInt(numStr, 10, 64)
	for i := int64(0); i < num; i++ {
		scanner.Scan()
		numsstr := scanner.Text()
		nums := strings.Split(numsstr, " ")
		n, _ := strconv.Atoi(nums[0])
		g, _ := strconv.Atoi(nums[1])
		b, _ := strconv.Atoi(nums[2])
		goodMax := 0
		if n % 2 == 1 {
			goodMax = n / 2 + 1
		} else {
			goodMax = n / 2
		}
		circle := goodMax / g - 1
		if circle < 0 {
			circle = 0
		}
		leftgoods := goodMax - g * circle
		result := (g + b) * circle
		if leftgoods <= g {
			result += leftgoods
		} else {
			result += leftgoods + b
		}
		if result < n {
			result = n
		}
		fmt.Println(result)
	}

}

package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string { sc.Scan(); return sc.Text() }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

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

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

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1000000)

	tests := scanInt()
	for t := 0; t < tests; t++ {
		n := scanInt64()
		g := scanInt64()
		b := scanInt64()

		ans := int64(0)
		if n <= g {
			fmt.Println(n)
			continue
		}

		if b > g {
			c := ((n+1)/2-g)
			ans += g
			ans += (c+g-1)/g*b + c
		} else {
			ans = n
		}

		fmt.Println(ans)
	}
}

package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string { sc.Scan(); return sc.Text() }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

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

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

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1000000)

	tests := scanInt()
	for t := 0; t < tests; t++ {
		n := scanInt64()
		g := scanInt64()
		b := scanInt64()

		ans := int64(0)
		if (n+1)/2 <= g || b <= g {
			fmt.Println(n)
			continue
		}

		ans += (n+1)/2
		ans += ((n+1)/2-g+g-1)/g*b

		fmt.Println(ans)
	}
}

package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string { sc.Scan(); return sc.Text() }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

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

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

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1000000)

	tests := scanInt()
	for t := 0; t < tests; t++ {
		n := scanInt64()
		g := scanInt64()
		b := scanInt64()

		c := int64(0)
		ans := int64(0)
		c = n - g
		ans += g
		if c<0 {
			ans += c
			c = 0
		}

		c = ((n+1)/2-ans)
		ans += c/g*(b+g) + (c%g)

		fmt.Println(ans)
	}
}

package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string { sc.Scan(); return sc.Text() }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

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

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

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1000000)

	tests := scanInt()
	for t := 0; t < tests; t++ {
		n := scanInt64()
		g := scanInt64()
		b := scanInt64()

		ans := int64(0)
		if n <= g || b <= g {
			fmt.Println(n)
			continue
		}

		c := (n-g+1)/2
		ans += (n+1)/2
		ans += (c+g-1)/g*b

		fmt.Println(ans)
	}
}

package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string { sc.Scan(); return sc.Text() }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

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

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

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1000000)

	tests := scanInt()
	for t := 0; t < tests; t++ {
		n := scanInt64()
		g := scanInt64()
		b := scanInt64()

		c := int64(0)
		ans := int64(0)
		c = n - g
		ans += g
		if c<0 {
			ans += c
			fmt.Println(ans)
			continue
		}

		c = ((n+1)/2-ans)
		ans += c/g*(b+g) + (c%g)

		fmt.Println(ans)
	}
}

package main

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

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string { sc.Scan(); return sc.Text() }
func scanInt() int { a,_ := strconv.Atoi(scanString()); return a }
func scanInt64() int64 { a,_ := strconv.ParseInt(scanString(),10,64); return a }
func scanFloat64() float64 { a,_ := strconv.ParseFloat(scanString(),64); return a }

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

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

//•*¨*•.¸¸♪Main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1000000)

	tests := scanInt()
	for t := 0; t < tests; t++ {
		n := scanInt64()
		g := scanInt64()
		b := scanInt64()

		ans := int64(0)
		if n <= g {
			fmt.Println(n)
			continue
		}

		if b >= g {
			c := ((n+1)/2-g)
			ans += g
			ans += c/g*(b+g) + (c%g)
		} else {
			ans = n
		}

		fmt.Println(ans)
	}
}

package main

import "fmt"
import "os"
import "bufio"
import "strings"
import "strconv"

func main() {
    scanner := bufio.NewScanner(os.Stdin)
    scanner.Scan()
    line := scanner.Text()
    t, _ := strconv.Atoi(line)
    for i := 0; i < t; i++ {
        scanner.Scan()
        line = scanner.Text()
        parts := strings.Split(line, " ")
        n, _ := strconv.Atoi(parts[0])
        g, _ := strconv.Atoi(parts[1])
        b, _ := strconv.Atoi(parts[2])
        //~ fmt.Println(n, g, b)

        min_good := n / 2 + (n % 2) // ceil n/2
        cycles, rem_good := min_good / g, min_good % g
        if rem_good == 0  && cycles > 0 {
            cycles--
            rem_good += g
        }
        days := cycles * (g + b) + rem_good
        if days < n {
            days = n
        }
        //~ fmt.Println(min_good, cycles, rem_good, days)
        fmt.Println(days)
    }
}

package main

import "fmt"

var t, n, g, d int64

func main() {
	fmt.Scan(&t)
	for ; t > 0; t-- {
		fmt.Scan(&n, &g, &d)
		if g >= d {
			fmt.Println(n)
		} else {
			half := (n + 1) >> 1
			times := half / g
			half = half % g
			ans := (g+d) * times + half
			if half == 0 {
				ans -= d
			}
			fmt.Println(ans)
		}
	}
}

package main

import "fmt"

var t, n, g, d int

func main() {
	fmt.Scan(&t)
	for cas:=0; cas < t; cas++ {
		fmt.Scan(&n, &g, &d)
		if g >= d {
			fmt.Println(n)
		} else {
			half := (n + 1) >> 1
			times := half / g
			half = half % g
			ans := (g+d) * times + half
			if half == 0 {
				ans -= d
			}
			fmt.Println(ans)
		}
	}
}

package main

import "fmt"

var t, n, g, d int64

func main() {
	fmt.Scan(&t)
	for ; t > 0; t-- {
		fmt.Scan(&n, &g, &d)
		if g >= d {
			fmt.Println(n)
			continue
		}
		gdays := (n + 1) >> 1
		ddays := n - gdays
		gtimes := (gdays - 1) / g
		dtimes := (ddays - 1) / d + 1
		if(gtimes >= dtimes) {
			fmt.Println(gtimes * (g + d) + gdays % g)
			continue
		}
		fmt.Println(n)
	}
}

package main

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

func main() {
	defer Flush()

	t := readi()
	for i := 0; i < t; i++ {
		n := readll()
		g := readll()
		b := readll()
		println(solve(n, g, b))
	}
}

func solve(n, g, b int64) int64 {
	ng := (n + 1) / 2
	nb := n - ng

	k := ng / g
	if k == 0 {
		return n
	}
	var d int64
	if ng%k == 0 {
		d = (k-1)*(g+b) + g
		d += maxll(0, nb-(k-1)*b)
	} else {
		d = k*(g+b) + ng%k + maxll(0, nb-k*b)
	}
	return d
}

// -----------------------------------------------------------------------------

// IO helper functions

// Returns next token from input.  It must be initialized by SetInput()
// before the first call.
var nextToken func() ([]byte, error)
var nextLine func() ([]byte, error)

// Holds a buffer for output.  It must be initialized by SetOutput().
// All IO fucntions (read*() and [e]print*()) should write to OutputWriter
// instead of this.
var OutputBuffer *bufio.Writer

// Holds an io.Writer.  It must be initialized by SetOutput()
var OutputWriter io.Writer

// Set IO functions for interactive input/output.
func SetInteractive(w io.Writer, r io.Reader) {
	SetUnbefferedInput(r)
	OutputBuffer = nil
	OutputWriter = w
}

// Setup OutputBuffer and OutputWriter.
func SetOutput(w io.Writer) {
	OutputBuffer = bufio.NewWriter(w)
	OutputWriter = OutputBuffer
}

// Flushes OutputBuffer
func Flush() {
	if OutputBuffer != nil {
		OutputBuffer.Flush()
	}
}

// Returns true if c is a white space
func IsSpace(c byte) bool {
	switch c {
	case '\t', '\n', '\v', '\f', '\r', ' ':
		return true
	}
	return false
}

func IsNewLine(c byte) bool {
	switch c {
	case '\n', '\r':
		return true
	}
	return false
}

// Setup nextToken with input buffer.
func SetInput(r io.Reader) {
	buf := new(bytes.Buffer)
	var b []byte

	var i int
	rest := func() ([]byte, error) {
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		return b[j:i], nil
	}
	initial := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextToken = rest
		return rest()
	}
	nextToken = initial

	restLn := func() ([]byte, error) {
		for i < len(b) && IsNewLine(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsNewLine(b[i]) {
			i++
		}
		return b[j:i], nil
	}

	initialLn := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextLine = restLn
		return restLn()
	}
	nextLine = initialLn
}

// Setup nextToken without input buffer.
func SetUnbefferedInput(r io.Reader) {
	buf := bufio.NewReader(r)
	var b []byte

	var i int
	nextToken = func() ([]byte, error) {
		var err error
		if i == len(b) {
			b, err = buf.ReadBytes('\n')
			if err != nil {
				return nil, err
			}
			i = 0
			j := len(b) - 1
			for 0 <= j && IsSpace(b[j]) {
				j--
			}
			b = b[0 : j+1]
		}
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		if i == j {
			return nil, io.ErrUnexpectedEOF
		}
		return b[j:i], nil
	}
}

// -----------------------------------------------------------------------------

// IO functions

// Reads next token and return it as []byte
func readb() []byte {
	b, err := nextToken()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

// Reads next token and return it as string
func reads() string {
	return string(readb())
}

// Read next line as []byte.  Trailing '\n' will not be included.
// See also comments on readb()
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

// Read next line as string
func readsln() string {
	return string(readbln())
}

// Reads next token and return it as int64
func readll() int64 {
	i, err := strconv.ParseInt(reads(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// Reads next token and return it as int
func readi() int {
	return int(readll())
}

// Reads next token and return it as float64
func readf() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// Write args to OutputWriter with the format f
func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(OutputWriter, f, args...)
}

// Write args to OutputWriter without format
func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(OutputWriter, args...)
}

// Write args to stderr with the format f
func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// Write args to stderr without format
func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// -----------------------------------------------------------------------------

// Utilities

func sumSlice(a []int) int {
	var res int
	for _, v := range a {
		res += v
	}
	return res
}

func sumSlicell(a []int64) int64 {
	var res int64
	for _, v := range a {
		res += v
	}
	return res
}

func readInts(N int) (int, []int) {
	if N == 0 {
		N = readi()
	}
	a := make([]int, N)
	for i := range a {
		a[i] = readi()
	}
	return N, a
}

func readIntsll(N int) (int, []int64) {
	if N == 0 {
		N = readi()
	}
	a := make([]int64, N)
	for i := range a {
		a[i] = readll()
	}
	return N, a
}

// reverse slice in place
func reverse(a []int) {
	for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
}

// areverse: allocating reverse
func areverse(a []int) []int {
	b := make([]int, len(a))
	for i := range a {
		b[i] = a[len(a)-i-1]
	}
	return b
}

// -----------------------------------------------------------------------------

// Simple math functions

const (
	// big prime
	INF  = 1000000007
	INF2 = 1000000009
	INF3 = 998244353
)

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

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

func minf(a, b float64) float64 {
	if a < b {
		return a
	}
	return b
}

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

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

func maxf(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

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

func absll(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func absf(a float64) float64 {
	if a < 0 {
		return -a
	}
	return a
}

// egcd(a, b) returns d, x, y:
//   d is gcd(a,b)
//   x, y are  integers that satisfy ax + by = d
func egcd(a, b int) (int, int, int) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcd(b, a%b)
	return d, y, x - a/b*y
}

func egcdll(a, b int64) (int64, int64, int64) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcdll(b, a%b)
	return d, y, x - a/b*y
}

func gcd(a, b int) int {
	d, _, _ := egcd(a, b)
	return d
}

func gcdll(a, b int64) int64 {
	d, _, _ := egcdll(a, b)
	return d
}

// set up IO functions
func init() {
	// for non-interactive
	SetInput(os.Stdin)
	SetOutput(os.Stdout)

	// Enable below when interactive.  Its ok to leave above intact.
	// SetInteractive(os.Stdout, os.Stdin)
}

package main

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

func main() {
	defer Flush()

	t := readi()
	for i := 0; i < t; i++ {
		n := readll()
		g := readll()
		b := readll()
		println(solve(n, g, b))
	}
}

func solve(n, g, b int64) int64 {
	ng := (n + 1) / 2
	nb := n - ng

	k := ng / g
	if k == 0 {
		return n
	}
	d := k*(g+b) - b
	ng %= g
	nb = maxll(0, nb-(k-1)*b)
	if ng == 0 {
		return d + nb
	} else {
		return d + ng + b
	}
}

// -----------------------------------------------------------------------------

// IO helper functions

// Returns next token from input.  It must be initialized by SetInput()
// before the first call.
var nextToken func() ([]byte, error)
var nextLine func() ([]byte, error)

// Holds a buffer for output.  It must be initialized by SetOutput().
// All IO fucntions (read*() and [e]print*()) should write to OutputWriter
// instead of this.
var OutputBuffer *bufio.Writer

// Holds an io.Writer.  It must be initialized by SetOutput()
var OutputWriter io.Writer

// Set IO functions for interactive input/output.
func SetInteractive(w io.Writer, r io.Reader) {
	SetUnbefferedInput(r)
	OutputBuffer = nil
	OutputWriter = w
}

// Setup OutputBuffer and OutputWriter.
func SetOutput(w io.Writer) {
	OutputBuffer = bufio.NewWriter(w)
	OutputWriter = OutputBuffer
}

// Flushes OutputBuffer
func Flush() {
	if OutputBuffer != nil {
		OutputBuffer.Flush()
	}
}

// Returns true if c is a white space
func IsSpace(c byte) bool {
	switch c {
	case '\t', '\n', '\v', '\f', '\r', ' ':
		return true
	}
	return false
}

func IsNewLine(c byte) bool {
	switch c {
	case '\n', '\r':
		return true
	}
	return false
}

// Setup nextToken with input buffer.
func SetInput(r io.Reader) {
	buf := new(bytes.Buffer)
	var b []byte

	var i int
	rest := func() ([]byte, error) {
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		return b[j:i], nil
	}
	initial := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextToken = rest
		return rest()
	}
	nextToken = initial

	restLn := func() ([]byte, error) {
		for i < len(b) && IsNewLine(b[i]) {
			i++
		}
		if i == len(b) {
			return nil, io.ErrUnexpectedEOF
		}
		j := i
		for i < len(b) && !IsNewLine(b[i]) {
			i++
		}
		return b[j:i], nil
	}

	initialLn := func() ([]byte, error) {
		io.Copy(buf, r)
		b = buf.Bytes()
		nextLine = restLn
		return restLn()
	}
	nextLine = initialLn
}

// Setup nextToken without input buffer.
func SetUnbefferedInput(r io.Reader) {
	buf := bufio.NewReader(r)
	var b []byte

	var i int
	nextToken = func() ([]byte, error) {
		var err error
		if i == len(b) {
			b, err = buf.ReadBytes('\n')
			if err != nil {
				return nil, err
			}
			i = 0
			j := len(b) - 1
			for 0 <= j && IsSpace(b[j]) {
				j--
			}
			b = b[0 : j+1]
		}
		for i < len(b) && IsSpace(b[i]) {
			i++
		}
		j := i
		for i < len(b) && !IsSpace(b[i]) {
			i++
		}
		if i == j {
			return nil, io.ErrUnexpectedEOF
		}
		return b[j:i], nil
	}
}

// -----------------------------------------------------------------------------

// IO functions

// Reads next token and return it as []byte
func readb() []byte {
	b, err := nextToken()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

// Reads next token and return it as string
func reads() string {
	return string(readb())
}

// Read next line as []byte.  Trailing '\n' will not be included.
// See also comments on readb()
func readbln() []byte {
	b, err := nextLine()
	if err != nil {
		panic(err)
	}
	return b[:len(b):len(b)]
}

// Read next line as string
func readsln() string {
	return string(readbln())
}

// Reads next token and return it as int64
func readll() int64 {
	i, err := strconv.ParseInt(reads(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// Reads next token and return it as int
func readi() int {
	return int(readll())
}

// Reads next token and return it as float64
func readf() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// Write args to OutputWriter with the format f
func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(OutputWriter, f, args...)
}

// Write args to OutputWriter without format
func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(OutputWriter, args...)
}

// Write args to stderr with the format f
func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// Write args to stderr without format
func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// -----------------------------------------------------------------------------

// Utilities

func sumSlice(a []int) int {
	var res int
	for _, v := range a {
		res += v
	}
	return res
}

func sumSlicell(a []int64) int64 {
	var res int64
	for _, v := range a {
		res += v
	}
	return res
}

func readInts(N int) (int, []int) {
	if N == 0 {
		N = readi()
	}
	a := make([]int, N)
	for i := range a {
		a[i] = readi()
	}
	return N, a
}

func readIntsll(N int) (int, []int64) {
	if N == 0 {
		N = readi()
	}
	a := make([]int64, N)
	for i := range a {
		a[i] = readll()
	}
	return N, a
}

// reverse slice in place
func reverse(a []int) {
	for i, j := 0, len(a)-1; i < j; i, j = i+1, j-1 {
		a[i], a[j] = a[j], a[i]
	}
}

// areverse: allocating reverse
func areverse(a []int) []int {
	b := make([]int, len(a))
	for i := range a {
		b[i] = a[len(a)-i-1]
	}
	return b
}

// -----------------------------------------------------------------------------

// Simple math functions

const (
	// big prime
	INF  = 1000000007
	INF2 = 1000000009
	INF3 = 998244353
)

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

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

func minf(a, b float64) float64 {
	if a < b {
		return a
	}
	return b
}

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

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

func maxf(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

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

func absll(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func absf(a float64) float64 {
	if a < 0 {
		return -a
	}
	return a
}

// egcd(a, b) returns d, x, y:
//   d is gcd(a,b)
//   x, y are  integers that satisfy ax + by = d
func egcd(a, b int) (int, int, int) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcd(b, a%b)
	return d, y, x - a/b*y
}

func egcdll(a, b int64) (int64, int64, int64) {
	if b == 0 {
		return a, 1, 0
	}
	d, x, y := egcdll(b, a%b)
	return d, y, x - a/b*y
}

func gcd(a, b int) int {
	d, _, _ := egcd(a, b)
	return d
}

func gcdll(a, b int64) int64 {
	d, _, _ := egcdll(a, b)
	return d
}

// set up IO functions
func init() {
	// for non-interactive
	SetInput(os.Stdin)
	SetOutput(os.Stdout)

	// Enable below when interactive.  Its ok to leave above intact.
	// SetInteractive(os.Stdout, os.Stdin)
}

package main

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

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

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

func main() {
  defer writer.Flush()
  var t int
  scanf("%d\n", &t)
  var n, g, b int
  for i := 0; i < t; i++ {
    scanf("%d %d %d\n", &n, &g, &b)
    solve(n, g, b)
  }
}

func solve(n, g, b int) {
  if g >= b {
    printf("%d\n", n)
  } else {
    gtarget := n - n/2
    rounds := gtarget / g
    if gtarget%g == 0 {
      printf("%d\n", (rounds-1)*(g+b)+g)
    } else {
      printf("%d\n", rounds*(g+b)+gtarget%g)
    }
  }
}

package main

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

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

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

func main() {
  defer writer.Flush()
  var t int64
  scanf("%d\n", &t)
  var n, g, b int64
  for i := int64(0); i < t; i++ {
    scanf("%d %d %d\n", &n, &g, &b)
    solve(n, g, b)
  }
}

func solve(n, g, b int64) {
  if g >= b {
    printf("%d\n", n)
  } else {
    var gtarget int64 = n - n/2
    var rounds int64 = gtarget / g
    if gtarget%g == 0 {
      printf("%d\n", (rounds-1)*(g+b)+g)
    } else {
      printf("%d\n", rounds*(g+b)+gtarget%g)
    }
  }
}

package main

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

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

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

func main() {
  defer writer.Flush()
  var t int64
  scanf("%d\n", &t)
  var n, g, b int64
  for i := int64(0); i < t; i++ {
    scanf("%d %d %d\n", &n, &g, &b)
    solve(n, g, b)
  }
}

func solve(n, g, b int64) {
  if g >= b {
    printf("%d\n", n)
  } else {
    var gtarget int64 = n - n/2
    var rounds int64 = gtarget / g
    if gtarget%g == 0 {
      printf("%d\n", max(n, (rounds-1)*(g+b)+g))
    } else {
      printf("%d\n", rounds*(g+b)+gtarget%g)
    }
  }
}

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


// For each layer i , it can connect items in level (i + 1) + 2n,
// 	one should notice that for the layer i + 1, some nodes are
// 	already connected.
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	adjList := map[int][]int{}

	for i := 0; i < n; i++ {
		scanner.Scan()
		e1, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		e2, _ := strconv.Atoi(scanner.Text())
		if adjList[e1] == nil {
			adjList[e1] = []int{}
		}
		if adjList[e2] == nil {
			adjList[e2] = []int{}
		}
		adjList[e1] = append(adjList[e1], e2)
		adjList[e2] = append(adjList[e2], e1)
	}

	// BFS to build the layer map
	v, q := map[int]bool{1: true}, []int{1}
	layerCount, layerMap, maxLayer := map[int]int{}, map[int]int{1: 0}, 0
	for len(q) > 0 {
		task := q[0]
		q = q[1:]
		layerCount[layerMap[task]]++

		for _, item := range adjList[task] {
			if v[item] {
				continue
			}
			layerMap[item] = layerMap[task] + 1
			if layerMap[item] > maxLayer {
				maxLayer = layerMap[item]
			}
			v[item] = true
			q = append(q, item)
		}
	}

	// Use eMap, oMap so that the next step does not need nesting loop.
	eMap, oMap := map[int]int64{}, map[int]int64{}
	for i := 0; i <= maxLayer; i++ {
		if i%2 == 1 {
			oMap[i] = oMap[i-2]
			oMap[i] += int64(layerCount[i])
			oMap[i+1] = oMap[i]
		} else {
			eMap[i] = eMap[i-2]
			eMap[i] += int64(layerCount[i])
			eMap[i+1] = eMap[i]
			// fmt.Println(i, eMap[i], i+1, eMap[i+1])
		}
	}
	// fmt.Println(oMap, eMap)

	sum := int64(0)
	for i := 0; i < maxLayer; i++ {
		sum += int64(layerCount[i]-1) * int64(layerCount[i+1])
		if i%2 == 0 {
			sum += int64(layerCount[i]) * (oMap[maxLayer] - oMap[i+1])
		} else {
			sum += int64(layerCount[i]) * (eMap[maxLayer] - eMap[i+1])
		}
	}
	fmt.Println(sum)
}

package main

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

var g [][]int
var color []int

func solve() {
	n := readInt()
	g = make([][]int, n)
	color = make([]int, n)
	for i := 0; i < n; i++ {
		color[i] = -1
	}
	for i := 0; i < n-1; i++ {
		u := readInt() - 1
		v := readInt() - 1
		g[u] = append(g[u], v)
		g[v] = append(g[v], u)
	}
	dfs(0, 1)
	cnt1 := 0
	for i := 0; i < n; i++ {
		if color[i] != 1 {
			cnt1++
		}
	}
	res := int64(0)
	for i := 0; i < n; i++ {
		if color[i] == 1 {
			res += int64(cnt1 - len(g[i]))
		}
	}
	fmt.Println(res)
}

func dfs(v int, c int) {
	color[v] = c
	for i := 0; i < len(g[v]); i++ {
		next := g[v][i]
		if color[next] == -1 {
			dfs(next, ^c)
		}
	}
}

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

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

var scanner *bufio.Scanner

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

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

// IO

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

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

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

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

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

// For each layer i , it can connect items in level (i + 1) + 2n,
// 	one should notice that for the layer i + 1, some nodes are
// 	already connected.
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	adjList := map[int][]int{}

	for i := 0; i < n; i++ {
		scanner.Scan()
		e1, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		e2, _ := strconv.Atoi(scanner.Text())
		if adjList[e1] == nil {
			adjList[e1] = []int{}
		}
		if adjList[e2] == nil {
			adjList[e2] = []int{}
		}
		adjList[e1] = append(adjList[e1], e2)
		adjList[e2] = append(adjList[e2], e1)
	}

	// BFS to build the layer map
	v, q := map[int]bool{1: true}, []int{1}
	layerCount, layerMap, maxLayer := map[int]int{}, map[int]int{1: 0}, 0
	for len(q) > 0 {
		task := q[0]
		q = q[1:]
		layerCount[layerMap[task]]++

		for _, item := range adjList[task] {
			if v[item] {
				continue
			}
			layerMap[item] = layerMap[task] + 1
			if layerMap[item] > maxLayer {
				maxLayer = layerMap[item]
			}
			v[item] = true
			q = append(q, item)
		}
	}

	eMap, oMap := map[int]int64{}, map[int]int64{}
	for i := 0; i <= maxLayer; i++ {
		oMap[i] = oMap[i-2]
		eMap[i] = eMap[i-2]
		if i%2 == 1 {
			oMap[i] += int64(layerCount[i])
			oMap[i-1] = oMap[i]
		} else {
			eMap[i] += int64(layerCount[i])
			eMap[i+1] = eMap[i]
		}
	}

	sum := int64(0)
	for i := 0; i < maxLayer; i++ {
		sum += int64(layerCount[i]-1) * int64(layerCount[i+1])
		if i%2 == 0 {
			sum += int64(layerCount[i]) * (oMap[maxLayer] - oMap[i+1])
		} else {
			sum += int64(layerCount[i]) * (eMap[maxLayer] - eMap[i+1])
		}
	}
	fmt.Println(sum)
}

// For each layer i , it can connect items in level (i + 1) + 2n,
// 	one should notice that for the layer i + 1, some nodes are
// 	already connected.
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())
	adjList := map[int][]int{}

	for i := 0; i < n; i++ {
		scanner.Scan()
		e1, _ := strconv.Atoi(scanner.Text())
		scanner.Scan()
		e2, _ := strconv.Atoi(scanner.Text())
		if adjList[e1] == nil {
			adjList[e1] = []int{}
		}
		if adjList[e2] == nil {
			adjList[e2] = []int{}
		}
		adjList[e1] = append(adjList[e1], e2)
		adjList[e2] = append(adjList[e2], e1)
	}

	// BFS to build the layer map
	v, q := map[int]bool{1: true}, []int{1}
	layerCount, layerMap, maxLayer := map[int]int{}, map[int]int{1: 0}, 0
	for len(q) > 0 {
		task := q[0]
		q = q[1:]
		layerCount[layerMap[task]]++

		for _, item := range adjList[task] {
			if v[item] {
				continue
			}
			layerMap[item] = layerMap[task] + 1
			if layerMap[item] > maxLayer {
				maxLayer = layerMap[item]
			}
			v[item] = true
			q = append(q, item)
		}
	}

	// Use eMap, oMap so that the next step does not need nesting loop.
	eMap, oMap := map[int]int64{}, map[int]int64{}
	for i := 0; i <= maxLayer; i++ {
		if i%2 == 1 {
			oMap[i] = oMap[i-2]
			oMap[i] += int64(layerCount[i])
			oMap[i-1] = oMap[i]
		} else {
			eMap[i] = eMap[i-2]
			eMap[i] += int64(layerCount[i])
			eMap[i+1] = eMap[i]
			// fmt.Println(i, eMap[i], i+1, eMap[i+1])
		}
	}
	// fmt.Println(oMap, eMap)

	sum := int64(0)
	for i := 0; i < maxLayer; i++ {
		sum += int64(layerCount[i]-1) * int64(layerCount[i+1])
		if i%2 == 0 {
			sum += int64(layerCount[i]) * (oMap[maxLayer] - oMap[i+1])
		} else {
			sum += int64(layerCount[i]) * (eMap[maxLayer] - eMap[i+1])
		}
	}
	fmt.Println(sum)
}