A sequence of $$$n$$$ non-negative integers ($$$n \ge 2$$$) $$$a_1, a_2, \dots, a_n$$$ is called good if for all $$$i$$$ from $$$1$$$ to $$$n-1$$$ the following condition holds true: $$$$$$a_1 \: \& \: a_2 \: \& \: \dots \: \& \: a_i = a_{i+1} \: \& \: a_{i+2} \: \& \: \dots \: \& \: a_n,$$$$$$ where $$$\&$$$ denotes the bitwise AND operation.You are given an array $$$a$$$ of size $$$n$$$ ($$$n \geq 2$$$). Find the number of permutations $$$p$$$ of numbers ranging from $$$1$$$ to $$$n$$$, for which the sequence $$$a_{p_1}$$$, $$$a_{p_2}$$$, ... ,$$$a_{p_n}$$$ is good. Since this number can be large, output it modulo $$$10^9+7$$$.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^4$$$), denoting the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the size of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$2 \cdot 10^5$$$.

Output $$$t$$$ lines, where the $$$i$$$-th line contains the number of good permutations in the $$$i$$$-th test case modulo $$$10^9 + 7$$$.

NoteIn the first test case, since all the numbers are equal, whatever permutation we take, the sequence is good. There are a total of $$$6$$$ permutations possible with numbers from $$$1$$$ to $$$3$$$: $$$[1,2,3]$$$, $$$[1,3,2]$$$, $$$[2,1,3]$$$, $$$[2,3,1]$$$, $$$[3,1,2]$$$, $$$[3,2,1]$$$.In the second test case, it can be proved that no permutation exists for which the sequence is good.In the third test case, there are a total of $$$36$$$ permutations for which the sequence is good. One of them is the permutation $$$[1,5,4,2,3]$$$ which results in the sequence $$$s=[0,0,3,2,0]$$$. This is a good sequence because   $$$ s_1 = s_2 \: \& \: s_3 \: \& \: s_4 \: \& \: s_5 = 0$$$,  $$$ s_1 \: \& \: s_2 = s_3 \: \& \: s_4 \: \& \: s_5 = 0$$$,  $$$ s_1 \: \& \: s_2 \: \& \: s_3 = s_4 \: \& \: s_5 = 0$$$,  $$$ s_1 \: \& \: s_2 \: \& \: s_3 \: \& \: s_4 = s_5 = 0$$$.

package main

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

func Readln(r *bufio.Reader) (string, error) {
	var (
		isPrefix bool  = true
		err      error = nil
		line, ln []byte
	)
	for isPrefix && err == nil {
		line, isPrefix, err = r.ReadLine()
		ln = append(ln, line...)
	}
	return string(ln), err
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	pk, _ := Readln(reader)
	k, _ := strconv.Atoi(string(pk))

	mainloop: for outi := 0 ; outi<k; outi++ {
		Readln(reader)
		ln,_ := Readln(reader)
		lnx := strings.Split(ln," ")
		l := make([] int, len(lnx))
		for i := range lnx {
			l[i], _ = strconv.Atoi(lnx[i])
		}
		mn := math.MaxInt32

		m := make(map [int] int)
		for _, val := range l {
			if val < mn {
				mn = val
			}
			m[val] ++
		}

		if m[mn] < 2 {

			fmt.Println("0")
			continue
		}

		for _, val := range l {
			if val&mn != mn {
			    fmt.Println("0")
			    continue mainloop
			}
		}
		p:= int64(1000000007)
		var res int64
		res = int64(1)

		num0 := m[mn]
		//num1 := m[1]
		others := len(l) - 2
		res = (res* int64(num0)) % p
		res = (res* int64(num0-1)) % p

		for i:=2; i<=others; i++ {
			res = (res* int64(i)) % p
		}
		ans := res % p
		if ans <0 {
			fmt.Println(-ans)
		} else {
			fmt.Println(ans)
		}

	}

}

package main

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

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

	const mx int = 3e5
	f := [mx]int64{1}
	for i := 1; i < mx; i++ {
		f[i] = f[i-1] * int64(i) % mod
	}

	solve := func(Case int) {
		var n,  c int
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		s := a[0]
		for _, v := range a {
			s &= v
		}
		for _, v := range a {
			if v == s {
				c++
			}
		}
		if c < 2 {
			Fprintln(out, 0)
			return
		}

		ans := int64(c) * int64(c-1) % mod
		ans = ans * f[n-2] % mod

		Fprintln(out, ans)
	}

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

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

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

package main

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

func Readln(r *bufio.Reader) (string, error) {
	var (
		isPrefix bool  = true
		err      error = nil
		line, ln []byte
	)
	for isPrefix && err == nil {
		line, isPrefix, err = r.ReadLine()
		ln = append(ln, line...)
	}
	return string(ln), err
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	pk, _ := Readln(reader)
	k, _ := strconv.Atoi(string(pk))

	for outi := 0 ; outi<k; outi++ {
		Readln(reader)
		ln,_ := Readln(reader)
		lnx := strings.Split(ln," ")
		l := make([] int, len(lnx))
		for i := range lnx {
			l[i], _ = strconv.Atoi(lnx[i])
		}
		mn := math.MaxInt32
		tryagain:
		m := make(map [int] int)
		for _, val := range l {
			if val < mn && val >= 1 {
				mn = val
			}
			m[val] ++
		}

		if m[0] < 2 {
			if m[0] ==0 {
				for i := range l{
					l[i] -= mn
				}

				//fmt.Println(l)
				goto tryagain

			}

			fmt.Println("0")
			continue
		}
		p:= int64(1000000007)
		var res int64
		res = int64(1)

		num0 := m[0]
		//num1 := m[1]
		others := len(l) - 2
		for i:=num0-1; i<=num0; i++ {
			if i==0 {
				i=1
			}
			res = (res* int64(i)) % p
		}
		//for i:=num1-1; i<=num1; i++ {
		//	if i==0 {
		//		i=1
		//	}
		//	res = (res* int64(i)) % p
		//}
		for i:=2; i<=others; i++ {
			res = (res* int64(i)) % p
		}
		ans := res % p
		if ans <0 {
			fmt.Println(-ans)
		} else {
			fmt.Println(ans)
		}

	}

}

package main

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

func Readln(r *bufio.Reader) (string, error) {
	var (
		isPrefix bool  = true
		err      error = nil
		line, ln []byte
	)
	for isPrefix && err == nil {
		line, isPrefix, err = r.ReadLine()
		ln = append(ln, line...)
	}
	return string(ln), err
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	pk, _ := Readln(reader)
	k, _ := strconv.Atoi(string(pk))

	for outi := 0 ; outi<k; outi++ {
		Readln(reader)
		ln,_ := Readln(reader)
		lnx := strings.Split(ln," ")
		l := make([] int, len(lnx))
		for i := range lnx {
			l[i], _ = strconv.Atoi(lnx[i])
		}
		mn := math.MaxInt32
		tryagain:
		m := make(map [int] int)
		for _, val := range l {
			if val < mn && val >1 {
				mn = val
			}
			m[val] ++
		}

		if m[0] < 2 && m[1] < 2 {
			if m[0] ==0 && m[1] == 0 {
				for i := range l{
					l[i] -= mn-1
				}

				//fmt.Println(l)
				goto tryagain
			}

			fmt.Println("0")
			continue
		}
		p:= int64(1000000007)
		var res int64
		res = int64(1)

		num0 := m[0]
		num1 := m[1]
		others := len(l) - 2
		for i:=num0-1; i<=num0; i++ {
			if i==0 {
				i=1
			}
			res = (res* int64(i)) % p
		}
		for i:=num1-1; i<=num1; i++ {
			if i==0 {
				i=1
			}
			res = (res* int64(i)) % p
		}
		for i:=2; i<=others; i++ {
			res = (res* int64(i)) % p
		}
		ans := res % p
		if ans <0 {
			fmt.Println(-ans)
		} else {
			fmt.Println(ans)
		}

	}

}

package main

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

func Readln(r *bufio.Reader) (string, error) {
	var (
		isPrefix bool  = true
		err      error = nil
		line, ln []byte
	)
	for isPrefix && err == nil {
		line, isPrefix, err = r.ReadLine()
		ln = append(ln, line...)
	}
	return string(ln), err
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	pk, _ := Readln(reader)
	k, _ := strconv.Atoi(string(pk))

	for outi := 0 ; outi<k; outi++ {
		Readln(reader)
		ln,_ := Readln(reader)
		lnx := strings.Split(ln," ")
		l := make([] int, len(lnx))
		for i := range lnx {
			l[i], _ = strconv.Atoi(lnx[i])
		}
		mn := math.MaxInt32
		tryagain:
		m := make(map [int] int)
		for _, val := range l {
			if val < mn && val >1 {
				mn = val
			}
			m[val] ++
		}

		if m[0] < 2 && m[1] < 2 {
			if m[0] ==0 && m[1] == 0 {
				for i := range l{
					l[i] -= mn-1
				}

				//fmt.Println(l)
				goto tryagain
			}

			fmt.Println("0")
			continue
		}
		p:= 1000000007
		res:= 1

		num0 := m[0]
		num1 := m[1]
		others := len(l) - 2
		for i:=num0-1; i<=num0; i++ {
			if i==0 {
				i=1
			}
			res = (res*i) % p
		}
		for i:=num1-1; i<=num1; i++ {
			if i==0 {
				i=1
			}
			res = (res*i) % p
		}
		for i:=2; i<=others; i++ {
			res = (res*i) % p
		}
		ans := res % p
		if ans <0 {
			fmt.Println(-ans)
		} else {
			fmt.Println(ans)
		}

	}

}

package main

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

func Readln(r *bufio.Reader) (string, error) {
	var (
		isPrefix bool  = true
		err      error = nil
		line, ln []byte
	)
	for isPrefix && err == nil {
		line, isPrefix, err = r.ReadLine()
		ln = append(ln, line...)
	}
	return string(ln), err
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	pk, _ := Readln(reader)
	k, _ := strconv.Atoi(string(pk))

	for outi := 0 ; outi<k; outi++ {
		Readln(reader)
		ln,_ := Readln(reader)
		lnx := strings.Split(ln," ")
		l := make([] int, len(lnx))
		for i := range lnx {
			l[i], _ = strconv.Atoi(lnx[i])
		}

		m := make(map [int] int)
		for _, val := range l {
			m[val] ++
		}

		if m[0] < 2 && m[1] < 2 {
			fmt.Println("0")
			continue
		}
		p:= 1000000007
		res:= 1
		//fmt.Println(len(l), m)
		num0 := m[0]
		num1 := m[1]
		others := len(l) - 2
		for i:=2; i<=num0; i++ {
			res = (res*i) % p
		}
		for i:=2; i<=num1; i++ {
			res = (res*i) % p
		}
		for i:=2; i<=others; i++ {
			res = (res*i) % p
		}
		fmt.Println(res)

	}

}


String s of length n is called k-palindrome, if it is a palindrome itself, and its prefix and suffix of length  are (k - 1)-palindromes. By definition, any string (even empty) is 0-palindrome.Let's call the palindrome degree of string s such a maximum number k, for which s is k-palindrome. For example, "abaaba" has degree equals to 3.You are given a string. Your task is to find the sum of the palindrome degrees of all its prefixes.

The first line of the input data contains a non-empty string, consisting of Latin letters and digits. The length of the string does not exceed 5·106. The string is case-sensitive.

Output the only number — the sum of the polindrome degrees of all the string's prefixes.

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


The problem statement looms below, filling you with determination.Consider a grid in which some cells are empty and some cells are filled. Call a cell in this grid exitable if, starting at that cell, you can exit the grid by moving up and left through only empty cells. This includes the cell itself, so all filled in cells are not exitable. Note that you can exit the grid from any leftmost empty cell (cell in the first column) by going left, and from any topmost empty cell (cell in the first row) by going up.Let's call a grid determinable if, given only which cells are exitable, we can exactly determine which cells are filled in and which aren't.You are given a grid $$$a$$$ of dimensions $$$n \times m$$$ , i. e. a grid with $$$n$$$ rows and $$$m$$$ columns. You need to answer $$$q$$$ queries ($$$1 \leq q \leq 2 \cdot 10^5$$$). Each query gives two integers $$$x_1, x_2$$$ ($$$1 \leq x_1 \leq x_2 \leq m$$$) and asks whether the subgrid of $$$a$$$ consisting of the columns $$$x_1, x_1 + 1, \ldots, x_2 - 1, x_2$$$ is determinable.

The first line contains two integers $$$n, m$$$ ($$$1 \leq n, m \leq 10^6$$$, $$$nm \leq 10^6$$$)  — the dimensions of the grid $$$a$$$. $$$n$$$ lines follow. The $$$y$$$-th line contains $$$m$$$ characters, the $$$x$$$-th of which is 'X' if the cell on the intersection of the the $$$y$$$-th row and $$$x$$$-th column is filled and "." if it is empty. The next line contains a single integer $$$q$$$ ($$$1 \leq q \leq 2 \cdot 10^5$$$)  — the number of queries. $$$q$$$ lines follow. Each line contains two integers $$$x_1$$$ and $$$x_2$$$ ($$$1 \leq x_1 \leq x_2 \leq m$$$), representing a query asking whether the subgrid of $$$a$$$ containing the columns $$$x_1, x_1 + 1, \ldots, x_2 - 1, x_2$$$ is determinable.

For each query, output one line containing "YES" if the subgrid specified by the query is determinable and "NO" otherwise. The output is case insensitive (so "yEs" and "No" will also be accepted).

NoteFor each query of the example, the corresponding subgrid is displayed twice below: first in its input format, then with each cell marked as "E" if it is exitable and "N" otherwise.For the first query: ..X EEN... EEE... EEE... EEEFor the second query: X N. E. E. ENote that you can exit the grid by going left from any leftmost cell (or up from any topmost cell); you do not need to reach the top left corner cell to exit the grid.For the third query: XX NNX. NNX. NNX. NNThis subgrid cannot be determined only from whether each cell is exitable, because the below grid produces the above "exitability grid" as well: XXXXXXXXFor the fourth query: X N. E. E. EFor the fifth query: ..XXX EENNN...X. EEENN...X. EEENN...X. EEENNThis query is simply the entire grid. It cannot be determined only from whether each cell is exitable because the below grid produces the above "exitability grid" as well: ..XXX...XX...XX...XX

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


Your company was appointed to lay new asphalt on the highway of length $$$n$$$. You know that every day you can either repair one unit of the highway (lay new asphalt over one unit of the highway) or skip repairing.Skipping the repair is necessary because of the climate. The climate in your region is periodical: there are $$$g$$$ days when the weather is good and if you lay new asphalt these days it becomes high-quality pavement; after that, the weather during the next $$$b$$$ days is bad, and if you lay new asphalt these days it becomes low-quality pavement; again $$$g$$$ good days, $$$b$$$ bad days and so on.You can be sure that you start repairing at the start of a good season, in other words, days $$$1, 2, \dots, g$$$ are good.You don't really care about the quality of the highway, you just want to make sure that at least half of the highway will have high-quality pavement. For example, if the $$$n = 5$$$ then at least $$$3$$$ units of the highway should have high quality; if $$$n = 4$$$ then at least $$$2$$$ units should have high quality.What is the minimum number of days is needed to finish the repair of the whole highway?

The first line contains a single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of test cases. Next $$$T$$$ lines contain test cases — one per line. Each line contains three integers $$$n$$$, $$$g$$$ and $$$b$$$ ($$$1 \le n, g, b \le 10^9$$$) — the length of the highway and the number of good and bad days respectively.

Print $$$T$$$ integers — one per test case. For each test case, print the minimum number of days required to repair the whole highway if at least half of it should have high quality.

NoteIn the first test case, you can just lay new asphalt each day, since days $$$1, 3, 5$$$ are good.In the second test case, you can also lay new asphalt each day, since days $$$1$$$-$$$8$$$ are good.

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

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"
	. "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"
	"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 {
			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
}