package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	N := nextInt()
	An := make([]int, N)
	for i := range An {
		An[i] = nextInt()
		if An[i] == 0 {
			fmt.Println(0)
			return
		}
	}
	ans := 1
	for i := 0; i < N; i++ {
		// An[i]*ans <= int(1e18)を変形
		if An[i] <= int(1e18)/ans {
			ans *= An[i]
		} else {
			fmt.Println(-1)
			return
		}
	}
	fmt.Println(ans)
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

func pow(p, q int) int {
	res := p
	if q == 0 {
		return 1
	}
	for i := 0; i < q-1; i++ {
		res *= p
	}
	return res
}

func MinOf(vars ...int) int {
	min := vars[0]
	for _, i := range vars {
		if min > i {
			min = i
		}
	}
	return min
}

func MaxOf(vars ...int) int {
	max := vars[0]
	for _, i := range vars {
		if max < i {
			max = i
		}
	}
	return max
}

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

func lcmof2numbers(a int, b int) int {
	return a / gcdof2numbers(a, b) * b
}

// マイナスの場合は考慮していない
func fuctorial(a int) int {
	if a == 1 || a == 0 {
		return 1
	} else {
		return fuctorial(a-1) * a
	}
}

func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

// 素因数分解したmapを返す
func primeFuctorize(n int) map[int]int {
	pf := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			pf[i]++
			n /= i
		}
	}
	if n != 1 {
		pf[n]++
	}
	return pf
}


package main

import (
	"fmt"
)

func main() {
	var n int
	var result uint64
	fmt.Scan(&n)
	arr := make([]uint64, n)
	for i:=0; i<n; i++ {
		fmt.Scan(&arr[i])
		// 0が一個でも存在したら積は0になる。先に全部チェックしてしまうことで、無駄な計算量を減らす
		if arr[i] == 0 {
			fmt.Printf("%d", 0)
			return
		}
	}
	result = 1
	for _,value := range arr {
		// result * value はオーバーフローしてしまう
		// オーバーフローする可能性のある積を比較するのは積→割り算に変換する
		// TODO: これは正確には result * value > 1e18とは違う。割り算は切り捨てられるため。しかしこれで必要十分な理由を述べよ。
		if result > 1e18/value {
			fmt.Print(-1)
			return
		}
		result *= value
	}
	fmt.Printf("%d", result)
}

Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.

Score : 200 points

Problem Statement

Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N.

However, if the result exceeds 10^{18}, print -1 instead.

Constraints

2 \leq N \leq 10^5

0 \leq A_i \leq 10^{18}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 ... A_N

Output

Print the value A_1 \times ... \times A_N as an integer, or -1 if the value exceeds 10^{18}.

Sample Input 1

2
1000000000 1000000000

Sample Output 1

1000000000000000000

We have 1000000000 \times 1000000000 = 1000000000000000000.

Sample Input 2

3
101 9901 999999000001

Sample Output 2

-1

We have 101 \times 9901 \times 999999000001 = 1000000000000000001, which exceeds 10^{18}, so we should print -1 instead.

Sample Input 3

31
4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 0

Sample Output 3

0

Submitted source-code file size, in bytes.

Execution CPU time reported by official Project CodeNet metadata, in milliseconds.

Peak memory usage reported by official Project CodeNet metadata, in kilobytes.


package main

import (
	"bufio"
	"fmt"
	"log"
	"math/big"
	"os"
	"strconv"
)

func main() {
	n := readInt64()
	a := readInt64Slice(n)

	answer := big.NewInt(1)
	max := big.NewInt(10).Exp(big.NewInt(10), big.NewInt(18), nil)
	for _, v := range a {
		if v == 0 {
			fmt.Println(0)
			return
		}
		answer.Mul(answer, big.NewInt(v))
		if answer.Cmp(max) > 0 {
			fmt.Println(-1)
			return
		}
	}
	if answer.Cmp(max) > 0 {
		fmt.Println(-1)
		return
	}
	fmt.Println(answer)
}

var (
	scanner *bufio.Scanner
)

func init() {
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
}

func readInt64() int64 {
	var t string

	if scanner.Scan() {
		t = scanner.Text()
	}

	n, err := strconv.ParseInt(t, 10, 64)
	if err != nil {
		log.Fatal(err)
	}

	return n

}

func readInt64Slice(n int64) []int64 {
	s := make([]int64, n)
	var t string

	for i := 0; i < int(n); i++ {
		if scanner.Scan() {
			t = scanner.Text()
		}

		num, err := strconv.ParseInt(t, 10, 64)
		if err != nil {
			log.Fatal(err)
		}
		s[i] = num
	}

	return s
}


package main

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

func main() {
	var t string
	var s = bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)

	if s.Scan() {
		t = s.Text()
	}

	N, err := strconv.Atoi(t)
	if err != nil {
		return
	}

	var answer uint64
	answer = 1

	for i := 0; i < N; i++ {
		if s.Scan() {
			t = s.Text()
		}

		v, err := strconv.ParseUint(t, 10, 64)
		if err != nil {
			fmt.Println(err)
			return
		}
		if v == 0 {
			fmt.Println(0)
			return
		}

		answer *= v
	}

	if answer > uint64(math.Pow10(18)) {
		fmt.Println(-1)
		return
	}
	fmt.Println(answer)
}


package main

import (
	"bufio"
	"fmt"
	"io"
	"math/big"
	"os"
	"strconv"
)

func main() {
	sc := NewBufScanner(os.Stdin)
	n := int(sc.Int())

	var a int64
	sum := big.NewInt(1)

	upper := big.NewInt(1e18)
	as := make([]int64, n)
	for i := 0; i < n; i++ {
		as[i] = sc.Int()
		if a == 0 {
			fmt.Println(0)
			return
		}
	}
	for i, v := range  as {
		if i == 0 {
			sum = big.NewInt(v)
			continue
		}
		sum.Mul(sum, big.NewInt(v))
		if sum.Cmp(upper) >0 {
			fmt.Println("-1")
			return
		}
	}
	fmt.Println(sum.Int64())
}

type BufScanner struct {
	*bufio.Scanner
}

func NewBufScanner(r io.Reader) *BufScanner {
	s := bufio.NewScanner(r)
	s.Split(bufio.ScanWords)
	// s.Split(scanWords)
	return &BufScanner{s}
}

func scanWords(data []byte, atEOF bool) (advance int, token []byte, err error) {
	start := 0
	for isSpace(data[start]) {
		start++
	}
	for i := start; i < len(data); i++ {
		if isSpace(data[i]) {
			return i+1, data[start:i], nil
		}
	}
	if atEOF && len(data) > start {
		return len(data), data[start:], nil
	}
	return start, nil, nil
}
func isSpace(b byte) bool {
	return b == ' ' || b == '\n' || b == '\r' || b == '\t'
}

func (s *BufScanner) String() string {
	s.Scan()
	return s.Text()
}

func (s *BufScanner) Int() int64 {
	return int64(s.UInt())
}

func (s *BufScanner) UInt() uint64 {
	s.Scan()
	i, e := strconv.ParseUint(s.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}


package main

import (
	"fmt"
)

func main() {
	var n int
	var result uint64
	fmt.Scanf("%d", &n)
	arr := make([]uint64, n)
	for i:=0; i<n; i++ {
		fmt.Scanf("%d", &arr[i])
	}
	result = 1
	toobig := false
	for _,value := range arr {
		result *= value
		if value == 0 {
			fmt.Printf("%d", result)
			return
		}
		if result >= 1e18 {
			toobig = true
		}
	}
	if toobig || result > 1e18 {
		fmt.Printf("-1")
	} else {
		fmt.Printf("%d", result)
	}
}


package main

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

func main() {
	var n int
	fmt.Scan(&n)
	stdin := bufio.NewScanner(os.Stdin)
	stdin.Scan()
	s := stdin.Text()

	is := strings.Split(s, " ")
	inputs := stringsToInts(is)

	for _, v := range inputs {
		if v == 0 {
			fmt.Println(0)
			return
		}
	}

	for _, v := range inputs {
		if v >= int64(math.Pow(10, 18)) {
			fmt.Println(-1)
			return
		}
	}

	var ans int64 = 1
	for _, v := range inputs {
		if ans*v >= int64(math.Pow(10, 18)) {
			fmt.Println(-1)
			return
		}
		ans *= v
	}
	fmt.Println(ans)
}

func stringsToInts(s []string) []int64 {
	arr := make([]int64, len(s))
	for i, v := range s {
		arr[i], _ = strconv.ParseInt(v, 10, 64)
	}
	return arr
}


package main

import (
	"fmt"
	"math"
	"math/big"
	"strconv"
)

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

	sum := big.NewInt(1)
	var fuck string
	for i:=0; i<n; i++ {
		var a int64
		fmt.Scan(&a)
		if a == 0 {
			fmt.Println(0)
			return
		}
		b := big.NewInt(a)
		sum = new(big.Int).Mul(sum, b)
		fuck=sum.String()
		q := new(big.Int).Sub(sum, big.NewInt(int64(math.Pow10(18)))).String()
		w, _ := strconv.Atoi(q)
		if w > 0 {
			fmt.Println(-1)
			return
		}
		t, _ := strconv.Atoi(fuck)
		sum = big.NewInt(int64(t))
	}
	c := new(big.Int).Sub(sum, big.NewInt(int64(math.Pow10(18)))).String()
	d, _ := strconv.Atoi(c)
	if d > 0 {
		fmt.Println(-1)
	} else {
		fmt.Println(fuck)
	}
}


package main

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

func main() {
	n := readi()
	a := make([]uint64, n)
	for i := 0; i < n; i++ {
		a[i] = readui64()
	}

	var ans uint64 = 1
	for i := 0; i < n; i++ {
		ans = ans * a[i]
	}

	var e1018 uint64 = 1000000000000000000
	if ans > e1018 {
		fmt.Println("-1")
		return
	}
	fmt.Println(ans)
}

func readui64() uint64 {
	i, err := strconv.ParseUint(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

/*-------------------utilities-------------------*/

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

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

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

func chmin(x *int, y int) bool {
	if *x > y {
		*x = y
		return true
	}
	return false
}

func chmax(x *int, y int) bool {
	if *x < y {
		*x = y
		return true
	}
	return false
}

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

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

func permutations(arr []int) [][]int {
	var helper func([]int, int)
	res := [][]int{}

	helper = func(arr []int, n int) {
		if n == 1 {
			tmp := make([]int, len(arr))
			copy(tmp, arr)
			res = append(res, tmp)
		} else {
			for i := 0; i < n; i++ {
				helper(arr, n-1)
				if n%2 == 1 {
					tmp := arr[i]
					arr[i] = arr[n-1]
					arr[n-1] = tmp
				} else {
					tmp := arr[0]
					arr[0] = arr[n-1]
					arr[n-1] = tmp
				}
			}
		}
	}
	helper(arr, len(arr))
	return res
}

func isPrime(n int) bool {
	if n == 1 {
		return false
	}
	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			return false
		}
	}
	return true
}

func divisor(n int) (res []int) {
	for i := 1; i*i <= n; i++ {
		if n%i == 0 {
			res = append(res, i)
			if i*i != n {
				res = append(res, n/i)
			}
		}
	}
	sort.Ints(res)
	return
}

/*-------------------init-------------------*/

const (
	INF = 1000000000000000000
	MOD = 1e9 + 7
)

var (
	readString func() string
)

func init() {
	readString = newReadString(os.Stdin)
}

/*-------------------inputs-------------------*/

func readi() int {
	return int(readi64())
}

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

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

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

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


package main

import (
	"fmt"
	"math"
)

func main() {
	var n int
	var result uint64
	fmt.Scanf("%d", &n)
	arr := make([]uint64, n)
	for i:=0; i<n; i++ {
		fmt.Scanf("%d", &arr[i])
	}
	result = 1
	toobig := false
	containzero := false
	for _,value := range arr {
		result *= value
		if value == 0 {
			containzero = true
			break
		}
		if result >= uint64(math.Pow(10, 18)) {
			toobig = true
		}
	}
	if containzero {
		fmt.Printf("%d", result)
	} else if toobig || result > uint64(math.Pow(10, 18)) {
		fmt.Printf("-1")
	} else {
		fmt.Printf("%d", result)
	}
}


package main

import (
	"fmt"
	"os"
)

func main() {
	var N, A int64
	fmt.Scan(&N)
	As := make([]int64, N)

	var res int64
	res = 1
	for i := 0; i < int(N); i++ {
		fmt.Scan(&A)
		As[i] = A
		if A == 0 {
			fmt.Println(0)
			os.Exit(0)
		}
	}

	for i := 0; i < int(N); i++ {
		n := As[i]
		res = add(res, n)
		if res == -1 {
			break;
		}
		if res > 1000000000000000000 || res < 0 {
			res = -1
			break;
		}

	}

	fmt.Println(res)

}

func add(a,b int64) (res int64) {

    defer func() {
        err := recover()
        if err != nil {
            res = -1
		}
    }()

	res = a*b
	return res
}


package main

import (
	"fmt"
	"math"
)

func main() {
	var N uint64
	fmt.Scan(&N)

	var ans uint64 = 1
	for i := uint64(0); i < N; i++ {
		var A uint64
		fmt.Scan(&A)

		ans *= A
	}

	if ans > uint64(math.Pow10(18)) {
		fmt.Println("-1")
	} else {
		fmt.Println(ans)
	}
}


package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	prod := big.NewInt(nextInt64())
	cons := big.NewInt(1000000000000000000)

	//alist := make([]int, n)
	for i := 0; i < n-1; i++ {
		prod.Mul(prod, big.NewInt(nextInt64()))
		//prod *= nextInt()
		//alist[i] = nextInt()
		//fmt.Printf("[%d] %d\n", i, prod)
	}
	compares := prod.Cmp(cons)
	if compares == 1 {
		fmt.Println(-1)
	} else {
		fmt.Printf("%d\n", prod)
	}
}

// ---- readfunc
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return int(i)
}
func nextInt64() int64 {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return int64(i)
}
func nextBigInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextF() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


package main

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

func main() {
	var t string
	var s = bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)

	if s.Scan() {
		t = s.Text()
	}

	N, err := strconv.Atoi(t)
	if err != nil {
		return
	}

	// var answer int64
	// answer = 1

	// for i := 0; i < N; i++ {

	// 	if s.Scan() {
	// 		t = s.Text()
	// 	}

	// 	v, err := strconv.ParseInt(t, 10, 64)
	// 	if err != nil {
	// 		return
	// 	}
	// 	if v == 0 {
	// 		fmt.Println(0)
	// 		return
	// 	} else {
	// 		answer = answer * int64(v)
	// 	}
	// }

	// if answer > int64(math.Pow10(18)) {
	// 	fmt.Println(-1)
	// 	return
	// }
	// fmt.Println(answer)

	var arr []int64
	for i := 0; i < N; i++ {
		if s.Scan() {
			t = s.Text()
		}

		v, err := strconv.ParseInt(t, 10, 64)
		if err != nil {
			fmt.Println(err)
			return
		}
		if v == 0 {
			fmt.Println(0)
			return
		} else {
			arr = append(arr, v)
		}
	}

	var answer int64
	answer = 1
	for _, v := range arr {
		// if v > int64(math.Pow10(18)) {
		// 	fmt.Println(-1)
		// 	return
		// }
		answer = int64(answer * v)
		if answer < 0 {
			fmt.Println(-1)
			return
		}
	}

	if answer > int64(math.Pow10(18)) {
		fmt.Println(-1)
		return
	}
	if answer < 0 {
		fmt.Println(-1)
		return
	}
	fmt.Println(answer)

}


package main

import "fmt"

func main() {
	var n, a int
	ans := 1

	fmt.Scan(&n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a)
		ans *= a
	}
	if ans > 1000000000000000000 {
		fmt.Println(-1)
	} else {
		fmt.Println(ans)
	}
}


package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	ft := 1

	for i := 0; i < n; i++ {
		var t int
		fmt.Scan(&t)
		ft *= t
		if ft > 1000000000000000000 {
			fmt.Println(-1)
			return
		}
	}
	fmt.Println(ft)
}


package main

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

func main() {
	parseProblem(os.Stdin)
}

func parseProblem(r io.Reader) {
	const (
		initialBufSize = 100000
		maxBufSize     = 1000000
	)
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines

	n := scanInt(sc)
	var limit uint64 = 1
	for i := 0; i < 18; i++ {
		limit *= 10
	}
	var res uint64 = 1
	over := false
	for i := 0; i < n; i++ {
		c := scanUint(sc)
		if c == 0 {
			fmt.Println("0")
			return
		}
		if c > limit {
			over = true
		}
		res *= c
		if res > limit {
			over = true
			res = 1
		}
	}
	if over {
		fmt.Println("-1")
		return
	}
	fmt.Println(res)
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanUint(sc *bufio.Scanner) uint64 {
	sc.Scan()
	u, _ := strconv.ParseUint(sc.Text(), 10, 64)
	return u
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()

	var i int64
	var ret int64 = 1
	for i = 1; i <= n; i++ {
		a := nextInt()
		ret = ret * a
	}
	if ret > 1000000000000000000 || ret < 0 {
		fmt.Println(-1)
	} else {
		fmt.Println(ret)
	}

}

func nextInt() int64 {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return int64(i)
}


package main

import (
	"fmt"
	"math/big"
)

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

	mul := big.NewInt(1)
	a := new(big.Int)
	MAX := big.NewInt(1000000000000000000)
	for i := 0; i < N; i++ {
		var s string
		fmt.Scanf("%s", &s)
		a, _ = a.SetString(s, 10)

		mul = mul.Mul(mul, a)
		if mul.Cmp(MAX) == 1 {
			fmt.Println("-1")
			return
		}
	}
	fmt.Println(mul)
}


// +build ignore
package main

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

func solve(sc *scanner, wr *bufio.Writer) int {
	N := sc.i()
	A := make([]uint64, N)
	for i := 0; i < N; i++ {
		A[i] = uint64(sc.i())
	}
	sort.Slice(A, func(i, j int) bool {
		return A[i] < A[j]
	})
	if A[0] == 0 {
		fmt.Println("0")
		return 0
	}
	sort.Slice(A, func(i, j int) bool {
		return A[i] > A[j]
	})
	sum := uint64(1)
	for i := 0; i < N; i++ {
		sum *= A[i]
		if sum > uint64(1000000000000000000) {
			fmt.Println("-1")
			return 0
		}
	}

	fmt.Println(sum)

	return 0
}

func main() {
	sc := newScanner(os.Stdin)
	wr := bufio.NewWriter(os.Stdout)
	ret := solve(sc, wr)
	wr.Flush()
	os.Exit(ret)
}

// I/O
type scanner struct {
	sc *bufio.Scanner
}

func newScanner(input io.Reader) *scanner {
	sc := bufio.NewScanner(input)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &scanner{sc}
}

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

func (s *scanner) i() int {
	i, e := strconv.Atoi(s.s())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *scanner) f() float64 {
	f, e := strconv.ParseFloat(s.s(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *scanner) bs() []byte {
	return []byte(s.s())
}

func (s *scanner) is(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.i()
	}
	return res
}

func (s *scanner) fs(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.f()
	}
	return res
}


package main

import (
	"fmt"
)

// github.com/EndlessCheng/codeforces-go

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

  A := make([]int, N)
  for i := range A{
    fmt.Scan(&A[i])
    if A[i] == 0 {
      fmt.Print(0)
      return
    }
  }

  retval := 1

  for i := range A{
    retval *= A[i]
    if retval > 1000000000000000000 {
      fmt.Print(-1)
      return
    }
  }
  fmt.Print(retval)
}


package main

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

func main() {
	var t string
	var s = bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)

	if s.Scan() {
		t = s.Text()
	}

	N, err := strconv.Atoi(t)
	if err != nil {
		return
	}

	var answer int64
	answer = 1
	for i := 0; i < N; i++ {
		if s.Scan() {
			t = s.Text()
		}

		N, err := strconv.ParseInt(t, 10, 64)
		if err != nil {
			return
		}
		if N == 0 {
			fmt.Println(0)
			return
		} else if answer*int64(N) > int64(math.Pow10(18)) {
			fmt.Println(-1)
			return
		} else {
			answer = answer * int64(N)
		}
	}
	fmt.Println(answer)
}


package main

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

var mod = 1000000007
var maxv int = 1000000000000000000

func main() {
	r := bufio.NewReader(os.Stdin)
	var n int
	fmt.Fscan(r, &n)

	ans := int(1)
	var a int
	as := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(r, &a)
		as[i] = a

		ans *= a
		if ans > maxv {
			ans = -1
			break
		}
	}

	for i := 0; i < n; i++ {
		if as[i] == 0 {
			ans = 0
			break
		}
	}

	fmt.Println(ans)

}

// Union-Find
type unionFind struct {
	d []int
}

func newUnionFind(n int) *unionFind {
	uf := new(unionFind)
	uf.d = make([]int, n)
	for i := 0; i < n; i++ {
		uf.d[i] = -1
	}
	return uf
}

func (uf *unionFind) find(x int) int {
	if uf.d[x] < 0 {
		return x
	}
	uf.d[x] = uf.find(uf.d[x])
	return uf.d[x]
}

func (uf *unionFind) unite(x, y int) bool {
	rootX := uf.find(x)
	rootY := uf.find(y)
	if rootX == rootY {
		return false
	}

	if uf.d[rootX] < uf.d[rootY] {
		uf.d[rootX] += uf.d[rootY]
		uf.d[rootY] = rootX
	} else {
		uf.d[rootY] += uf.d[rootX]
		uf.d[rootX] = rootY
	}

	return true
}

func (uf *unionFind) same(x, y int) bool {
	return uf.find(x) == uf.find(y)
}

func (uf *unionFind) size(x int) int {
	return -uf.d[uf.find(x)]
}

// mod
func modpow(a, n, mod int) int {
	res := 1
	for n > 0 {
		if n%2 != 0 {
			res = res * a % mod
		}
		a = a * a % mod
		n = n / 2
	}
	return res
}

func modinv(n, mod int) int {
	return modpow(n, mod-2, mod)
}

func modcomb(n, a, mod int) int {
	x := 1
	y := 1
	for i := 0; i < a; i++ {
		x = x * (n - i)
		x %= mod
		y = y * (i + 1)
		y %= mod
	}
	return x * modpow(y, mod-2, mod) % mod
}

func modfactorial(n, mod int) int {
	result := 1
	for i := 1; i <= n; i++ {
		result = (result * i) % mod
	}
	return result
}

// Combination ...
type Combination struct {
	facts, invs []int
	mod         int
}

// NewCombination ...
func NewCombination(n, mod int) Combination {
	return Combination{
		facts: make([]int, n+1),
		invs:  make([]int, n+1),
		mod:   mod,
	}
}

func (cmb *Combination) calc(n, k int) int {
	ret := cmb.facts[n] * cmb.invs[k]
	ret %= cmb.mod
	ret = ret * cmb.invs[n-k]
	ret %= cmb.mod
	return ret
}

func (cmb *Combination) init(n int) {
	cmb.facts[0] = 1
	// 階乗を算出
	for i := 1; i <= n; i++ {
		cmb.facts[i] = cmb.facts[i-1] * i % cmb.mod
	}
	// 逆元を算出
	cmb.invs[n] = modinv(cmb.facts[n], cmb.mod)
	for i := n - 1; i >= 0; i-- {
		cmb.invs[i] = cmb.invs[i+1] * (i + 1) % cmb.mod
	}
}

// Utility
func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

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

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

func primeFactor(x int) map[int]int {
	res := make(map[int]int)
	for i := 2; i*i <= x; i++ {
		for x%i == 0 {
			res[i]++
			x = x / i
		}
	}
	if x != 1 {
		res[x] = 1
	}
	return res
}

func divisor(x int) []int {
	res := make([]int, 0)
	for i := 1; i*i <= x; i++ {
		if x%i == 0 {
			res = append(res, i)
			if i != x/i {
				res = append(res, x/i)
			}
		}
	}
	return res
}

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func lcm(x, y int) int {
	return x / gcd(x, y) * y
}

func reverseString(s string) string {
	r := []rune(s)
	for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
		r[i], r[j] = r[j], r[i]
	}
	return string(r)
}

// Queue ...
type Queue []int

// pop ...
func (q *Queue) empty() bool {
	return len(*q) == 0
}

// push ...
func (q *Queue) push(i int) {
	*q = append(*q, i)
}

// pop ...
func (q *Queue) pop() (int, bool) {
	if q.empty() {
		return 0, false
	} else {
		res := (*q)[0]
		*q = (*q)[1:]
		return res, true
	}
}

// Stack ...
type Stack []int

// pop ...
func (s *Stack) empty() bool {
	return len(*s) == 0
}

// push ...
func (s *Stack) push(i int) {
	*s = append(*s, i)
}

// pop ...
func (s *Stack) pop() (int, bool) {
	if s.empty() {
		return 0, false
	} else {
		index := len(*s) - 1
		res := (*s)[index]
		*s = (*s)[:index]
		return res, true
	}
}

// priority_queue
type intHeap []int

func (h intHeap) Len() int           { return len(h) }
func (h intHeap) Less(i, j int) bool { return h[i] > h[j] }
func (h intHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }
func (h *intHeap) Push(x interface{}) {
	*h = append(*h, x.(int))
}
func (h *intHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}

// sortable points
type point struct {
	x int
	y int
}

type points []point

func (p points) Len() int {
	return len(p)
}

func (p points) Less(i, j int) bool {
	return p[i].x < p[j].x
}

func (p points) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}


package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"reflect"
	"sort"
	"strconv"
	"strings"
	// "regexp"
)

/* sort */
type pair struct {
	index  int64
	p1, p2 interface{}
}
type pairs []pair

func (slice pairs) Len() int {
	return len(slice)
}

func (slice pairs) Less(i, j int) bool {
	return slice[i].index < slice[j].index
}

func (slice pairs) Swap(i, j int) {
	slice[i], slice[j] = slice[j], slice[i]
}

/* sort */
type Int64Slice []int64

func (slice Int64Slice) Len() int {
	return len(slice)
}

func (slice Int64Slice) Less(i, j int) bool {
	return slice[i] < slice[j]
}

func (slice Int64Slice) Swap(i, j int) {
	slice[i], slice[j] = slice[j], slice[i]
}
func Int64s(a []int64)                    { sort.Sort(Int64Slice(a)) }
func Int64sSliceAreSorted(a []int64) bool { return sort.IsSorted(Int64Slice(a)) }

const (
	initialBufSize = 1e4
	maxBufSize     = 1e8
	INF            = 1e8
)

var (
	scanner = bufio.NewScanner(os.Stdin)
	writer  = bufio.NewWriter(os.Stdout)
	di      = []int64{-1, 0, 1, 0}
	dj      = []int64{0, -1, 0, 1}
	di8     = []int64{-1, -1, 0, 1, 1, 1, 0, -1}
	dj8     = []int64{0, -1, -1, -1, 0, 1, 1, 1}
)

func main() {
	buf := make([]byte, initialBufSize)
	scanner.Buffer(buf, maxBufSize)
	scanner.Split(bufio.ScanWords)
	N := readInt()
	A := make([]int64, N)
	var prod int64
	prod = 1
	zero := false
	for i := int64(0); i < N; i++ {
		A[i] = readInt()
		if A[i] == 0 {
			zero = true
		}
	}
	if zero {
		fmt.Println(0)
		return
	}
	for i := int64(0); i < N; i++ {
		if keta(prod)+keta(A[i]) >= 18 {
			if prod*A[i] != int64(1e18) {
				fmt.Println(-1)
				return
			}
		}
		prod *= A[i]
	}
	fmt.Println(prod)
}

func keta(a int64) int64 {
	return int64(len(i2s(a)))
}

/*==========================================
 *             Library
 *==========================================*/
func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}
func doubleAry(h int64, w int64, init int64) (res [][]int64) {
	res = make([][]int64, h)
	for i := int64(0); i < h; i++ {
		res[i] = make([]int64, w)
		for j := int64(0); j < w; j++ {
			res[i][j] = init
		}
	}
	return
}

func aryEq(a []int64, b []int64) bool {
	return reflect.DeepEqual(a, b)
}

func clone(n []int64) (r []int64) {
	r = make([]int64, len(n))
	for i := 0; i < len(n); i++ {
		r[i] = n[i]
	}
	return
}
func write(s string) {
	writer.WriteString(s)
}

func print() {
	writer.Flush()
}

// scanner.Split(bufio.ScanWords) をコメントアウトしないと使用不可
func readLine() (s string) {
	if scanner.Scan() {
		s = scanner.Text()
	}
	return s
}

func readInt() (read int64) {
	scanner.Scan()
	read, err := strconv.ParseInt(scanner.Text(), 10, 64)
	if err != nil {
		panic(err)
	}
	return
}

func readFloat() (read float64) {
	scanner.Scan()
	read, err := strconv.ParseFloat(scanner.Text(), 64)
	if err != nil {
		panic(err)
	}
	return
}

func readRunes() (read []rune) {
	scanner.Scan()
	for _, v := range scanner.Text() {
		read = append(read, v)
	}
	return
}

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

func readStrings() (read []string) {
	scanner.Scan()
	for _, v := range scanner.Text() {
		read = append(read, string(v))
	}
	return
}

func s2i(s string) int64 {
	var intVal, e = strconv.ParseInt(s, 10, 64)
	if e != nil {
		panic(e)
	}
	return intVal
}

func i2s(i int64) string {
	var strVal = strconv.FormatInt(i, 10)
	return strVal
}

func s2f(s string) float64 {
	var floatVal, e = strconv.ParseFloat(s, 64)
	if e != nil {
		panic(e)
	}
	return floatVal
}

func abs(i int64) int64 {
	return int64(math.Abs(float64(i)))
}

func max(a ...int64) int64 {
	ans := int64(0)
	for i, v := range a {
		if i == 0 {
			ans = v
		}
		if ans < v {
			ans = v
		}
	}
	return ans
}
func min(a ...int64) int64 {
	ans := int64(0)
	for i, v := range a {
		if i == 0 {
			ans = v
		}
		if ans > v {
			ans = v
		}
	}
	return ans
}

func sum(i []int64) int64 {
	sum := int64(0)
	for _, val := range i {
		sum += val
	}
	return sum
}

func split(s string) []string {
	return strings.Fields(s)
}

func strAry2intAry(strs []string) []int64 {
	var ret = make([]int64, 0, len(strs))
	for _, str := range strs {
		var intVal = s2i(str)
		ret = append(ret, intVal)
	}
	return ret
}

func intAry2strAry(nums []int64) []string {
	var ret = make([]string, 0, len(nums))
	for _, num := range nums {
		var strVal = i2s(num)
		ret = append(ret, strVal)
	}
	return ret
}

func ary2str(strs []string) string {
	return strings.Join(strs, " ")
}

func reverse(res []int64) []int64 {
	for i, j := 0, len(res)-1; i < j; i, j = i+1, j-1 {
		res[i], res[j] = res[j], res[i]
	}
	return res
}
func reverseStr(res []string) []string {
	for i, j := 0, len(res)-1; i < j; i, j = i+1, j-1 {
		res[i], res[j] = res[j], res[i]
	}
	return res
}

func ini(res []int, init int) {
	if len(res) == 0 {
		return
	}
	res[0] = init
	for i := 0; i < len(res); i++ {
		copy(res[i:], res[:i])
	}
}

//
// func regexpExample() {
//     // Your code here!
//     var str = "13:20"
//     r := regexp.MustCompile(`(\d+):(\d+)`)
//     fmt.Println(r.FindStringSubmatch(str))
// }

// type Country struct {
//     gold int
//     silver int
//     blonze int
// }

// // 複数ソートのサンプル
// func stableSortExample() []Country{
//     var country = []Country {
//         {gold:1, silver:2, blonze:3},
//         {gold:1, silver:2, blonze:3},
//         {gold:1, silver:3, blonze:2},
//         {gold:1, silver:3, blonze:3},
//     }
//     sort.SliceStable(country, func(i, j int) bool { return country[i].blonze > country[j].blonze })
//     sort.SliceStable(country, func(i, j int) bool { return country[i].silver > country[j].silver })
//     sort.SliceStable(country, func(i, j int) bool { return country[i].gold > country[j].gold })
//     return country
// }


package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		num = nextInt()
		nums = append(nums, num)
	}
	return
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	a := scanNums(n)
	var sum int64
	sum = 1
	for i := 0; i < n; i++ {
		sum *= int64(a[i])
	}
	if sum > int64(math.Pow(10, 18)) {
		fmt.Println(-1)
	} else {
		fmt.Println(int64(sum))
	}
}


package main

import "fmt"

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

	nums := make([]int, a)

	for i := range nums {
		fmt.Scan(&nums[i])
	}
	ans := 1
	for i := range nums {
		ans *= nums[i]
	}

	if ans > 1000000000000000000 {
		fmt.Print(-1)
	} else {
		fmt.Print(ans)
	}

}


package main

import (
	"bufio"
	"fmt"
	"math/big"
	"os"
	"sort"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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

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

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

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()
	sum := big.NewInt(1)

	over := big.NewInt(1000000000)
	over.Mul(over, over)

	a := make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = getInt()
		if a[i] == 0 {
			out(0)
			return
		}
	}
	for i := 0; i < N; i++ {
		b := big.NewInt(int64(a[i]))
		sum.Mul(sum, b)
		if sum.Cmp(over) > 0 {
			out(-1)
			return
		}
	}
	out(sum)
}


package main

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

var stdInScanner = bufio.NewScanner(os.Stdin)

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

func main() {
	stdInScanner.Split(bufio.ScanWords)

	N := nextInt()
	anser := nextInt()

	for i := 0; i < N-1; i++ {
		anser *= nextInt()
		if 1000000000000000000 < anser {
			anser = -1
			break
		}
	}
	fmt.Println(anser)
}


package main

import "fmt"

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

	max := int64(1e18)
	ans := int64(1)
	for i := 0; i < n; i++ {
		if a[i] == 0 {
			ans = 0
			break
		}
		if ans > max/a[i] {
			ans = -1
			break
		}
		ans *= a[i]
		if ans > max {
			ans = -1
			break
		}
	}
	fmt.Println(ans)
}


package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		num = nextInt()
		nums = append(nums, num)
	}
	return
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	a := scanNums(n)
	sum := 1
	for i := 0; i < n; i++ {
		sum *= a[i]
	}
	if sum > int(math.Pow(10, 18)) {
		fmt.Println(-1)
	} else {
		fmt.Println(sum)
	}
}


package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	a  := nextInt()
	max  := int(math.Pow(10, 18))

	ans := 0
	for i := 0; i < a; i++ {
		ans *= a
		if ans > max {
			fmt.Println(-1)
		}
	}
	fmt.Println(ans)
}

func isPrime(n int) bool {
	for i := 2.0; i <= math.Sqrt(float64(n)); i++ {
		if n%int(i) == 0 {
			return false
		}
	}
	return true
}

func slicePrint(s []int) {
	for i, v := range s {
		if i != 0 {
			fmt.Printf(" ")
		}
		fmt.Printf("%v", v)
	}
	fmt.Println("")
}

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


package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	num, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return num
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func getMin(x ...int) int {
	min := math.MaxInt64
	for i := 0; i < len(x); i++ {
		if x[i] < min {
			min = x[i]
		}
	}
	return min
}

func getMax(x ...int) int {
	max := math.MinInt64
	for i := 0; i < len(x); i++ {
		if x[i] > max {
			max = x[i]
		}
	}
	return max
}

func pow(x, pow int) int {
	ans := x
	for i := 1; i < pow; i++ {
		ans = ans * x
	}
	return ans
}

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

func main() {
	// sc.Buffer([]byte{}, math.MaxInt64)
	sc.Split(bufio.ScanWords)

	// w := bufio.NewWriter(os.Stdout)
	// defer w.Flush()

	bar := 1000000000000000000

	n := nextInt()
	ans := func() int {
		total := 1
		flag := false
		for i := 0; i < n; i++ {
			a := nextInt()
			if a == 0 {
				return 0
			}
			total = total * a
			if total > bar {
				flag = true
				total = 1
			}
		}

		if flag {
			return -1
		}
		return total
	}()

	fmt.Println(ans)
}


package main

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

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

	var n int
	Fscan(in, &n)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
		if a[i] == 0 {
			Fprintln(out, 0)

			return
		}
	}
	s := big.NewInt(1)
	upper := big.NewInt(1e18)
	for _, v := range a {

		s.Mul(s,big.NewInt(int64(v)))
		if s.Cmp( upper)>0 {
			Fprintln(out, -1)
			return
		}
	}
	Fprintln(out, s.Int64())
}

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


package main

import "fmt"

func main() {
	var A, B float64
	fmt.Scan(&A, &B)
	a := int(A)
	b := int(B * 100)
	fmt.Println(int(a * b / 100))
}

Score : 300 points

Problem Statement

Compute A \times B, truncate its fractional part, and print the result as an integer.

Constraints

0 \leq A \leq 10^{15}

0 \leq B < 10

A is an integer.

B is a number with two digits after the decimal point.

Input

Input is given from Standard Input in the following format:

A B

Output

Print the answer as an integer.

Sample Input 1

198 1.10

Sample Output 1

217

We have 198 \times 1.10 = 217.8. After truncating the fractional part, we have the answer: 217.

Sample Input 2

1 0.01

Sample Output 2

0

Sample Input 3

1000000000000000 9.99

Sample Output 3

9990000000000000


package main

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

func main() {
	var a int
	var b float64
	fmt.Scanf("%d %f", &a, &b)

	intB := int(math.Floor(b * 100))
	fmt.Printf("%d\n", (a*intB)/100)
}

func scanLongIntSlices(lines int, maxBufSize int) ([][]int, error) {

	res := [][]int{}

	sc := bufio.NewScanner(os.Stdin)
	buf := make([]byte, bufio.MaxScanTokenSize)
	sc.Buffer(buf, maxBufSize)

	for sc.Scan() {
		line := sc.Text()
		strs := strings.Split(line, " ")
		ints := make([]int, len(strs))
		for i, c := range strs {
			n, err := strconv.Atoi(c)
			if err != nil {
				return nil, err
			}
			ints[i] = n
		}
		res = append(res, ints)
	}

	if err := sc.Err(); err != nil {
		return nil, err
	}

	return res, nil
}


package main

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

func main() {
	list := getStdinArr()
	N, _ := strconv.Atoi(list[0])
	M, _ := strconv.ParseFloat(list[1], 64)
	n := N
	m := int(math.Round(M * 100))
	fmt.Printf("%d\n", (n*m)/100)
}

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*1)

func getStdin() string {
	return readLine()
}
func getStdinArr() []string {
	str := getStdin()
	list := strings.Split(str, " ")
	return list
}
func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, _ := sc.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


package main

import (
	"bufio"
	"fmt"
	"io"
	"math/big"
	"os"
	"sort"
	"strconv"
)

func main() {
	a := readi64()
	b := readf()
	// https://twitter.com/kyopro_friends/status/1267095064804638720
	// 誤差が出たら嫌な問題はできるだけ整数の範囲で計算するのがよくて、
	// 今回はA×(B×100)/100みたいに計算すればいいんだけど、B×100を整数に変換するときの誤差にも気をつけないとダメだね。
	// 例えばB=2.51のとき、B×100=250.999999999999971…になるよー
	B := big.NewInt(int64(b*100 + 0.001))

	A := big.NewInt(a)
	A.Mul(A, B)
	A.Div(A, big.NewInt(100))
	fmt.Println(A)
}

/*-------------------utilities-------------------*/

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

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

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

func chmin(x *int, y int) bool {
	if *x > y {
		*x = y
		return true
	}
	return false
}

func chmax(x *int, y int) bool {
	if *x < y {
		*x = y
		return true
	}
	return false
}

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

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

func permutations(arr []int) [][]int {
	var helper func([]int, int)
	res := [][]int{}

	helper = func(arr []int, n int) {
		if n == 1 {
			tmp := make([]int, len(arr))
			copy(tmp, arr)
			res = append(res, tmp)
		} else {
			for i := 0; i < n; i++ {
				helper(arr, n-1)
				if n%2 == 1 {
					tmp := arr[i]
					arr[i] = arr[n-1]
					arr[n-1] = tmp
				} else {
					tmp := arr[0]
					arr[0] = arr[n-1]
					arr[n-1] = tmp
				}
			}
		}
	}
	helper(arr, len(arr))
	return res
}

func isPrime(n int) bool {
	if n == 1 {
		return false
	}
	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			return false
		}
	}
	return true
}

func divisor(n int) (res []int) {
	for i := 1; i*i <= n; i++ {
		if n%i == 0 {
			res = append(res, i)
			if i*i != n {
				res = append(res, n/i)
			}
		}
	}
	sort.Ints(res)
	return
}

// func searchInts(a []int, k int) int {
// 	return binarySearch(len(a), func(i int) bool {
// 		return a[i] >= k
// 	})
// }

func binarySearch(n int, f func(int) bool) int {
	i, j := 0, n
	for i < j {
		h := int(uint(i+j) >> 1)
		if !f(h) {
			i = h + 1
		} else {
			j = h
		}
	}
	return i
}

/*-------------------init-------------------*/

const (
	INF = 1000000000000000000
	MOD = 1e9 + 7
)

var (
	readString func() string
)

func init() {
	readString = newReadString(os.Stdin)
}

/*-------------------inputs-------------------*/

func readi() int {
	return int(readi64())
}

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

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

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

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


package main

import (
	"fmt"
	"math"
)

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

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func main() {
	var a,b float64
	fmt.Scan(&a,&b)

	fmt.Println(int(a*b))

}


package main

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

)

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

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

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

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	a, bs := r.nextInt(), r.nextString()
	b, _ := strconv.ParseFloat(bs, 64)

	fmt.Fprintf(stdout, "%.0f\n", math.Floor(float64(a)*math.Floor(b*100)/100))
}


package main

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

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

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

func scanFloat64() float64 {
	sc.Scan()
	i, _ := strconv.ParseFloat(sc.Text(), 64)
	return i
}

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

func scanInts64(n int) []int64 {
	res := make([]int64, n)
	for i := range res {
		res[i] = scanInt64()
	}
	return res
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	a, b := scanInt64(), scanFloat64()

	fmt.Println((a * int64(math.Round(b*100))) / 100)
}


package main

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

func main() {
	// a := big.NewInt(readInt64())
	// b := big.NewInt(int64(readFloat64() * 100))

	// ans := big.NewInt(1)
	// ans.Mul(a, b)
	// ans.Div(ans, big.NewInt(100))
	// fmt.Println(ans)

	a := readInt64()
	b := int64(readFloat64() * 100)

	fmt.Println((a * b) / 100)

}

var (
	scanner *bufio.Scanner
)

func init() {
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
}

func readInt64() int64 {
	var t string

	if scanner.Scan() {
		t = scanner.Text()
	}

	n, err := strconv.ParseInt(t, 10, 64)
	if err != nil {
		log.Fatal(err)
	}

	return n

}

func readFloat64() float64 {
	var t string

	if scanner.Scan() {
		t = scanner.Text()
	}

	n, err := strconv.ParseFloat(t, 64)
	if err != nil {
		log.Fatal(err)
	}

	return n
}


package main

import "fmt"

func main() {
	var a int
	var b float64
	fmt.Scan(&a, &b)

	fmt.Println((a * int(b*100)) / 100)
}


package main

import "fmt"

func main() {
	var a int
	var b float64
	fmt.Scan(&a, &b)
	fmt.Println((a * int(100.0*b)) / 100)
}


package main

import "fmt"

func main() {
	var a int
	var b float64

	fmt.Scan(&a, &b)

	bsec := int(b * 100.0)

	ansint := a * bsec
	ans := ansint / 100

	fmt.Println(ans)
}


package main

import (
	"fmt"
)

func main() {
	var a int
	var b float64
	fmt.Scan(&a, &b)
	// fmt.Println(b * 100)
	r := ((a * int(b*100)) / 100)
	fmt.Println(r)
}


package main

import (
	"fmt"
)

func main() {
	var a int
	var b float64
	fmt.Scan(&a, &b)
	// fmt.Println(b * 100)
	r := int((float64(a) * (b * 100)) / 100)
	fmt.Println(r)
}


package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"math/big"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var buff []byte

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buff, bufio.MaxScanTokenSize*1024)
	log.SetFlags(log.Lshortfile)
}

func main() {
	solveBigFloat()
	// eps := 0.000000000001
	// A := nextInt()
	// B := nextFloat64()
	// log.Println(A, B)
	// ans := 0
	// for i := 0.0; i+eps < B; i += 0.01 {
	// 	ans += A
	// }
	// fmt.Println(ans / 100)
}

func solveBigFloat() {
	A := nextString()
	B := nextString()
	var a, b big.Float
	a.SetString(A)
	b.SetString(B)
	u, _ := a.Mul(&a, &b).Uint64()
	fmt.Println(u)
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextFloat64() float64 {
	sc.Scan()
	f, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return f
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func nextInts(n int) (r []int) {
	r = make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


package main

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

var (
	finv, inv, fac [MAX]int
)

func COM(n, k int) int {
	if n < k {
		return 0
	}
	if n < 0 || k < 0 {
		return 0
	}
	return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD
}

func init() {
	fac[0] = 1
	fac[1] = 1
	finv[0] = 1
	finv[1] = 1
	inv[1] = 1
	for i := 2; i < MAX; i++ {
		fac[i] = fac[i-1] * i % MOD
		inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD
		finv[i] = finv[i-1] * inv[i] % MOD
	}
	//sc.Split(bufio.ScanLines)
	sc.Split(bufio.ScanWords)
	//sc.Buffer([]byte{}, 100100)
}

const (
	MOD = 1000000007
	MAX = 510000
)

func ModAdd(a, b int64) int64 {
	return (a + b) % MOD
}

func ModMul(a, b int64) int64 {
	return a * b % MOD
}

func ModSub(a, b int64) int64 {
	r := (a%MOD - b%MOD) % MOD
	if r < 0 {
		r += MOD
	}
	return r
}

func ModDiv(a, b int64) int64 {
	return a % MOD * ModInv(b) % MOD
}

func ModPow(a, n int64) int64 {
	var r int64 = 1
	for n > 0 {
		if n&1 == 1 {
			r = r * a % MOD
		}
		a = a * a % MOD
		n >>= 1
	}
	return r
}

func ModInv(a int64) int64 {
	var b, u, v int64 = MOD, 1, 0
	for b > 0 {
		t := a / b
		a -= t * b
		a, b = b, a
		u -= t * v
		u, v = v, u
	}
	u %= MOD
	if u < 0 {
		u += MOD
	}
	return u
}

type Q struct {
	value int
	index int
	A, B  int
}

type QS []*Q

func (p QS) Len() int           { return len(p) }
func (p QS) Less(i, j int) bool { return p[i].value > p[j].value }
func (pq QS) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *QS) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Q)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *QS) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

func IsPrime(num int) bool {
	m := map[int]int{}
	return factor(m, num, 2)
}

func factor(result map[int]int, num, pnum int) bool {
	if pnum*pnum > num {
		if num != 1 {
			if result[num] > 0 {
				return false
			}
			result[num] += 1
		}
		return len(result) == 1
	}

	if num%pnum == 0 {
		num /= pnum
		if result[pnum] > 0 {
			return false
		}
		result[pnum]++
		if len(result) > 1 {
			return false
		}
	} else {
		pnum++
	}
	return factor(result, num, pnum)
}

func GCD(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return GCD(b, a%b)
}

func LCM(a, b int64) int64 {
	return a * b / GCD(a, b)
}

type UnionFind struct {
	par  []int
	size []int
}

func NewUnionFind(size int) *UnionFind {
	return new(UnionFind).init(size)
}

func (uf *UnionFind) init(size int) *UnionFind {
	uf.par = make([]int, size)
	uf.size = make([]int, size)

	for i := 0; i < size; i++ {
		uf.par[i] = i
		uf.size[i] = 1
	}
	return uf
}

func (uf *UnionFind) Unite(p int, q int) {
	rp := uf.Root(p)
	rq := uf.Root(q)
	if rp == rq {
		return
	}
	if uf.size[rp] < uf.size[rq] {
		uf.par[rp] = uf.par[rq]
		uf.size[rq] += uf.size[rp]
	} else {
		uf.par[rq] = uf.par[rp]
		uf.size[rp] += uf.size[rq]
	}
}

func (uf *UnionFind) Root(p int) int {
	for uf.par[p] == p {
		return p
	}
	uf.par[p] = uf.Root(uf.par[p])
	return uf.par[p]
}

func (uf *UnionFind) Size(p int) int {
	return uf.size[uf.Root(p)]
}

func (uf *UnionFind) Same(p int, q int) bool {
	return uf.Root(p) == uf.Root(q)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	n, _ := strconv.Atoi(getStr())
	return n
}

func getStr() string {
	sc.Scan()
	return sc.Text()
}

type T struct {
	A interface{} `json:"a"`
}

func main() {
	A, S := getInt(), getStr()
	B, _ := strconv.ParseFloat(S, 64)
	if A%100 == 0 {
		A /= 100
		fmt.Println(uint64(A) * uint64(B*100))
		return
	}
	fmt.Println(uint64(float64(A) * B))
}

type IntHeap []int

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] < h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *IntHeap) Push(x interface{}) {
	// Push and Pop use pointer receivers because they modify the slice's length,
	// not just its contents.
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}


package main

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

var (
	finv, inv, fac [MAX]int
)

func COM(n, k int) int {
	if n < k {
		return 0
	}
	if n < 0 || k < 0 {
		return 0
	}
	return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD
}

func init() {
	fac[0] = 1
	fac[1] = 1
	finv[0] = 1
	finv[1] = 1
	inv[1] = 1
	for i := 2; i < MAX; i++ {
		fac[i] = fac[i-1] * i % MOD
		inv[i] = MOD - inv[MOD%i]*(MOD/i)%MOD
		finv[i] = finv[i-1] * inv[i] % MOD
	}
	//sc.Split(bufio.ScanLines)
	sc.Split(bufio.ScanWords)
	//sc.Buffer([]byte{}, 100100)
}

const (
	MOD = 1000000007
	MAX = 510000
)

func ModAdd(a, b int64) int64 {
	return (a + b) % MOD
}

func ModMul(a, b int64) int64 {
	return a * b % MOD
}

func ModSub(a, b int64) int64 {
	r := (a%MOD - b%MOD) % MOD
	if r < 0 {
		r += MOD
	}
	return r
}

func ModDiv(a, b int64) int64 {
	return a % MOD * ModInv(b) % MOD
}

func ModPow(a, n int64) int64 {
	var r int64 = 1
	for n > 0 {
		if n&1 == 1 {
			r = r * a % MOD
		}
		a = a * a % MOD
		n >>= 1
	}
	return r
}

func ModInv(a int64) int64 {
	var b, u, v int64 = MOD, 1, 0
	for b > 0 {
		t := a / b
		a -= t * b
		a, b = b, a
		u -= t * v
		u, v = v, u
	}
	u %= MOD
	if u < 0 {
		u += MOD
	}
	return u
}

type Q struct {
	value int
	index int
	A, B  int
}

type QS []*Q

func (p QS) Len() int           { return len(p) }
func (p QS) Less(i, j int) bool { return p[i].value > p[j].value }
func (pq QS) Swap(i, j int) {
	pq[i], pq[j] = pq[j], pq[i]
	pq[i].index = i
	pq[j].index = j
}

func (pq *QS) Push(x interface{}) {
	n := len(*pq)
	item := x.(*Q)
	item.index = n
	*pq = append(*pq, item)
}

func (pq *QS) Pop() interface{} {
	old := *pq
	n := len(old)
	item := old[n-1]
	old[n-1] = nil  // avoid memory leak
	item.index = -1 // for safety
	*pq = old[0 : n-1]
	return item
}

func IsPrime(num int) bool {
	m := map[int]int{}
	return factor(m, num, 2)
}

func factor(result map[int]int, num, pnum int) bool {
	if pnum*pnum > num {
		if num != 1 {
			if result[num] > 0 {
				return false
			}
			result[num] += 1
		}
		return len(result) == 1
	}

	if num%pnum == 0 {
		num /= pnum
		if result[pnum] > 0 {
			return false
		}
		result[pnum]++
		if len(result) > 1 {
			return false
		}
	} else {
		pnum++
	}
	return factor(result, num, pnum)
}

func GCD(a, b int64) int64 {
	if b == 0 {
		return a
	}
	return GCD(b, a%b)
}

func LCM(a, b int64) int64 {
	return a * b / GCD(a, b)
}

type UnionFind struct {
	par  []int
	size []int
}

func NewUnionFind(size int) *UnionFind {
	return new(UnionFind).init(size)
}

func (uf *UnionFind) init(size int) *UnionFind {
	uf.par = make([]int, size)
	uf.size = make([]int, size)

	for i := 0; i < size; i++ {
		uf.par[i] = i
		uf.size[i] = 1
	}
	return uf
}

func (uf *UnionFind) Unite(p int, q int) {
	rp := uf.Root(p)
	rq := uf.Root(q)
	if rp == rq {
		return
	}
	if uf.size[rp] < uf.size[rq] {
		uf.par[rp] = uf.par[rq]
		uf.size[rq] += uf.size[rp]
	} else {
		uf.par[rq] = uf.par[rp]
		uf.size[rp] += uf.size[rq]
	}
}

func (uf *UnionFind) Root(p int) int {
	for uf.par[p] == p {
		return p
	}
	uf.par[p] = uf.Root(uf.par[p])
	return uf.par[p]
}

func (uf *UnionFind) Size(p int) int {
	return uf.size[uf.Root(p)]
}

func (uf *UnionFind) Same(p int, q int) bool {
	return uf.Root(p) == uf.Root(q)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	n, _ := strconv.Atoi(getStr())
	return n
}

func getStr() string {
	sc.Scan()
	return sc.Text()
}

type T struct {
	A interface{} `json:"a"`
}

func main() {
	A, S := getInt(), getStr()
	B, _ := strconv.ParseFloat(S, 64)
	fmt.Println(uint64(float64(A) * B))
}

type IntHeap []int

func (h IntHeap) Len() int           { return len(h) }
func (h IntHeap) Less(i, j int) bool { return h[i] < h[j] }
func (h IntHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }

func (h *IntHeap) Push(x interface{}) {
	// Push and Pop use pointer receivers because they modify the slice's length,
	// not just its contents.
	*h = append(*h, x.(int))
}

func (h *IntHeap) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}


package main

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

func main() {
	a := readInt()
	b := int(math.Round(readFloat64() * 100))
	fmt.Println(a * b / 100)
}

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

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

func readInt() int {
	return int(readInt64())
}

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

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
}

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

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


package main

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

func main() {
	a := readInt()
	b := int(readFloat64() * 100)
	fmt.Println(a * b / 100)
}

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

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

func readInt() int {
	return int(readInt64())
}

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

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
}

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

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


package main

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

func main() {
	fmt.Println(int(readFloat64() * readFloat64()))
}

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	log.SetFlags(log.Lshortfile)
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

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

func readInt() int {
	return int(readInt64())
}

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

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
}

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

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

// こちらを参考にした
// https://drken1215.hatenablog.com/

func main() {
	var A int
	var B float64
	fmt.Scan(&A, &B)
	B100 := int(B*100 + 0.001)
	ans := (A * B100) / 100
	fmt.Println(ans)
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

func pow(p, q int) int {
	res := p
	if q == 0 {
		return 1
	}
	for i := 0; i < q-1; i++ {
		res *= p
	}
	return res
}

func MinOf(vars ...int) int {
	min := vars[0]
	for _, i := range vars {
		if min > i {
			min = i
		}
	}
	return min
}

func MaxOf(vars ...int) int {
	max := vars[0]
	for _, i := range vars {
		if max < i {
			max = i
		}
	}
	return max
}

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

func lcmof2numbers(a int, b int) int {
	return a / gcdof2numbers(a, b) * b
}

// マイナスの場合は考慮していない
func fuctorial(a int) int {
	if a == 1 || a == 0 {
		return 1
	} else {
		return fuctorial(a-1) * a
	}
}

func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

// 素因数分解したmapを返す
func primeFuctorize(n int) map[int]int {
	pf := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			pf[i]++
			n /= i
		}
	}
	if n != 1 {
		pf[n]++
	}
	return pf
}


package main

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

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

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

func readInt64() int64 {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return int64(i)
}

func readfloat64() float64 {
	sc.Scan()
	i, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return float64(i)
}

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

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

const Mod = 1000000007

func ModComb(n, k int) int {
	if k == 0 {
		return 1
	}
	x, y := n, k
	for i := 1; i < k; i++ {
		x = x * (n - i) % Mod
		y = y * (k - i) % Mod
	}
	inv := ModInv(y)
	return x * inv % Mod
}

func ModFact(x int) int {
	fact := 1
	for i := 1; i <= x; i++ {
		fact = fact * i % Mod
	}
	return fact
}

func ModInv(x int) int {
	return ModPow(x, Mod-2)
}

func ModPow(a, n int) int {
	res := 1
	for n > 0 {
		if n%2 != 0 {
			res = res * a % Mod
		}
		a = a * a % Mod
		n /= 2
	}
	return res
}

func pow(a, n int) int {
	if n == 0 {
		return 1
	}

	ans := 0
	if n%2 == 0 {
		ans = pow(a*a, n/2)
	} else {
		ans = a * pow(a*a, (n-1)/2)
	}
	return ans
}

func intSliceReverse(slice []int) []int {
	for i, j := 0, len(slice)-1; i < j; i, j = i+1, j-1 {
		slice[i], slice[j] = slice[j], slice[i]
	}
	return slice
}

func stringReverse(str string) string {
	runes := []rune(str)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func main() {
	sc.Split(bufio.ScanWords)

	a, b := readInt(), readfloat64()

	ans := (uint64(a) * uint64(b*100)) / 100
	fmt.Printf("%d\n", ans)
}


package main

import "fmt"

func main() {
	var (
		a uint64
		b float32
	)

	fmt.Scanln(&a, &b)

	if a == 0 {
		fmt.Println(0)
		return
	}

	fmt.Println((a * uint64(b*100+0.5)) / 100)
}


package main

import "fmt"

func main() {
	var (
		a uint64
		b float32
	)

	fmt.Scanln(&a, &b)

	b2 := uint64(b * 100)

	fmt.Println((a * b2) / 100)
}


package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var a int
	var b string

	fmt.Scan(&a, &b)
	bInt, _ := strconv.Atoi(strings.Replace(b, ".", "", -1))
	fmt.Println(a * bInt / 100)
}


package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var a int
	var b string
	fmt.Scan(&a, &b)
	bInt, _ := strconv.Atoi(strings.Replace(b, ".", "", -1))
	fmt.Println(a * bInt  / 100)
}


package main

import (
	"fmt"
)

func main() {
	var a, b float64
	fmt.Scan(&a, &b)
	b = b*100

	fmt.Println(int(a*b/100))

}


package main

import (
        "fmt"
        "strconv"
)

func solution(a int, b string) int {
        x := make([]byte, 0, len(b))
        for i := range b {
                if b[i] != '.' {
                        x = append(x, b[i])
                }
        }
        bn, _ := strconv.Atoi(string(x))

        return a * bn / 100
}

func main() {
        var a int
        var b string
        fmt.Scan(&a, &b)
        fmt.Println(solution(a, b))
}


package main

import (
	"fmt"
	"math"
)

func main() {
	var a, b float64
	fmt.Scan(&a, &b)

	fmt.Println(math.Round(a * b))
}


package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Scan()
	ss := strings.Fields(sc.Text())

	A, _ := strconv.ParseUint(ss[0], 10, 64)
	B, _ := strconv.ParseFloat(ss[1], 64)
	BB := uint64(B * 100)

	result := A * BB / 100

	fmt.Print(result)
}


package main

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

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

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

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

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

//Main
var sc = bufio.NewScanner(os.Stdin)

const MAX = 1000000000000000000

var A, B string

func main() {
	sc.Split(bufio.ScanWords)
	A, B = nextStr(), nextStr()

	if A == "0" || B == "0.00" {
		fmt.Println(0)
		return
	}

	var ans, b, c int64
	a, _ := strconv.ParseInt(A, 10, 64)
	ans = 0
	b = 100
	for i := 3; i >= 0; i-- {
		if i == 1 {
			continue
		}
		c, _ = strconv.ParseInt(string(B[i]), 10, 64)
		if c != 0 {
			ans += int64(a/b) * c
		}
		b /= 10
	}

	fmt.Println(ans)

}


package main

import (
	"fmt"
	"math"
)

func main() {
	var A int64
	var B float64
	fmt.Scan(&A, &B)

	fmt.Println(int(math.Floor(float64(A) * B)))
}


package main

import "fmt"

func main() {
	var a int
	var b float64

	fmt.Scanf("%d %f", &a, &b)
	var out float64
	out = float64(a) * b
	fmt.Println(int(out))

}


package main

import "fmt"

func main(){
	var a, b float64
	fmt.Scan(&a, &b)
	fmt.Println(int64(a*b))
}


package main

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

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*10)

func main() {
	list := getStdinArr()
	N, _ := strconv.Atoi(list[0])
	M, _ := strconv.ParseFloat(list[1], 64)
	ans := float64(N) * M
	i := int(roundDown(ans, 0))
	fmt.Printf("%d\n", i)
}

// RoundDown 切り捨て

func roundDown(num, places float64) float64 {
	shift := math.Pow(10, places)

	return math.Trunc(num*shift) / shift

}

func getStdin() string {
	return readLine()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}

func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}

func getStdinArr() []string {
	str := getStdin()
	list := strings.Split(str, " ")
	return list
}

func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, e := sc.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


package main

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

const (
	initialBufSize = 10000
	maxBufSize = 1000000
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextFloat() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	buf := make([]byte, initialBufSize)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
	a, b := nextFloat(), nextFloat()

	fmt.Println(int(math.Floor(a*b)))
}

func isPrime(n int) bool {
	for i := 2.0; i <= math.Sqrt(float64(n)); i++ {
		if n%int(i) == 0 {
			return false
		}
	}
	return true
}

func slicePrint(s []int) {
	for i, v := range s {
		if i != 0 {
			fmt.Printf(" ")
		}
		fmt.Printf("%v", v)
	}
	fmt.Println("")
}

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


package main

import (
	"fmt"
	"math"
)

func main() {
	var a int64
	var b float64
	fmt.Scan(&a, &b)
	af := float64(a)

	ans := af * b
	ansi := int(math.Floor(ans))
	fmt.Println(ansi)
}


package main

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

// go run ./main.go < in

func main() {
	sc := bufio.NewScanner(os.Stdin)
	for i := 0; i <= 0; i++ {
		sc.Scan()
		inputs := strings.Split(sc.Text(), " ")
		a, _ := strconv.ParseFloat(inputs[0], 64)
		b, _ := strconv.ParseFloat(inputs[1], 64)

		fmt.Println(int(math.Floor(a * b)))

	}

}


package main

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

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

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

func readInt64() int64 {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return int64(i)
}

func readfloat64() float64 {
	sc.Scan()
	i, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return float64(i)
}

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

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

const Mod = 1000000007

func ModComb(n, k int) int {
	if k == 0 {
		return 1
	}
	x, y := n, k
	for i := 1; i < k; i++ {
		x = x * (n - i) % Mod
		y = y * (k - i) % Mod
	}
	inv := ModInv(y)
	return x * inv % Mod
}

func ModFact(x int) int {
	fact := 1
	for i := 1; i <= x; i++ {
		fact = fact * i % Mod
	}
	return fact
}

func ModInv(x int) int {
	return ModPow(x, Mod-2)
}

func ModPow(a, n int) int {
	res := 1
	for n > 0 {
		if n%2 != 0 {
			res = res * a % Mod
		}
		a = a * a % Mod
		n /= 2
	}
	return res
}

func pow(a, n int) int {
	if n == 0 {
		return 1
	}

	ans := 0
	if n%2 == 0 {
		ans = pow(a*a, n/2)
	} else {
		ans = a * pow(a*a, (n-1)/2)
	}
	return ans
}

func intSliceReverse(slice []int) []int {
	for i, j := 0, len(slice)-1; i < j; i, j = i+1, j-1 {
		slice[i], slice[j] = slice[j], slice[i]
	}
	return slice
}

func stringReverse(str string) string {
	runes := []rune(str)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func main() {
	sc.Split(bufio.ScanWords)

	a, b := readfloat64(), readfloat64()

	fmt.Printf("%d", int(math.Trunc(a*b)))
}


package main

import (
	"fmt"
)

func main() {
	var (
		a int
		b float64
	)
	fmt.Scan(&a, &b)
	ib := int(b * 100)

	fmt.Println(a * ib / 100)
}


package main

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

func main() {
	a := readi()
	b := readf()

	fmt.Println(int(float64(a) * b))
}

/*-------------------utilities-------------------*/

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

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

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

func chmin(x *int, y int) bool {
	if *x > y {
		*x = y
		return true
	}
	return false
}

func chmax(x *int, y int) bool {
	if *x < y {
		*x = y
		return true
	}
	return false
}

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

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

func permutations(arr []int) [][]int {
	var helper func([]int, int)
	res := [][]int{}

	helper = func(arr []int, n int) {
		if n == 1 {
			tmp := make([]int, len(arr))
			copy(tmp, arr)
			res = append(res, tmp)
		} else {
			for i := 0; i < n; i++ {
				helper(arr, n-1)
				if n%2 == 1 {
					tmp := arr[i]
					arr[i] = arr[n-1]
					arr[n-1] = tmp
				} else {
					tmp := arr[0]
					arr[0] = arr[n-1]
					arr[n-1] = tmp
				}
			}
		}
	}
	helper(arr, len(arr))
	return res
}

func isPrime(n int) bool {
	if n == 1 {
		return false
	}
	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			return false
		}
	}
	return true
}

func divisor(n int) (res []int) {
	for i := 1; i*i <= n; i++ {
		if n%i == 0 {
			res = append(res, i)
			if i*i != n {
				res = append(res, n/i)
			}
		}
	}
	sort.Ints(res)
	return
}

/*-------------------init-------------------*/

const (
	INF = 1000000000000000000
	MOD = 1e9 + 7
)

var (
	readString func() string
)

func init() {
	readString = newReadString(os.Stdin)
}

/*-------------------inputs-------------------*/

func readi() int {
	return int(readi64())
}

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

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

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

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


package main

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

func main() {
	N, K := ReadInt(), ReadInt()
	A := ReadInts(N)

	maxI := int(math.Ceil(math.Log2(float64(K))))
	next := make([][]int, maxI+1)
	for k := 0; k < maxI+1; k++ {
		next[k] = make([]int, N)
	}
	for i := 0; i < N; i++ {
		next[0][i] = A[i] - 1
	}
	for k := 0; k < maxI; k++ {
		for i := 0; i < N; i++ {
			next[k+1][i] = next[k][next[k][i]]
		}
	}

	ans := 0
	k := 0
	for K > 0 {
		if K&1 == 1 {
			ans = next[k][ans]
		}
		K >>= 1
		k++
	}
	fmt.Println(ans + 1)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}

Score: 400 points

Problem Statement

The Kingdom of Takahashi has N towns, numbered 1 through N.

There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i.

Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there.

Help the king by writing a program that answers this question.

Constraints

2 \leq N \leq 2 \times 10^5

1 \leq A_i \leq N

1 \leq K \leq 10^{18}

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \dots A_N

Output

Print the integer representing the town the king will be in if he starts at Town 1 and uses a teleporter exactly K times from there.

Sample Input 1

4 5
3 2 4 1

Sample Output 1

4

If we start at Town 1 and use the teleporter 5 times, our travel will be as follows: 1 \to 3 \to 4 \to 1 \to 3 \to 4.

Sample Input 2

6 727202214173249351
6 5 2 5 3 2

Sample Output 2

2


package main

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

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

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

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

func scanInts64(n int) []int64 {
	res := make([]int64, n)
	for i := range res {
		res[i] = scanInt64()
	}
	return res
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	n, k := scanInt(), scanInt()
	// a := make([]int, n)
	// for i := range a {
	// 	a[i] = scanInt() - 1
	// }
	a := []int{0}
	a = append(a, scanInts(n)...)

	fg := []int{1}
	for i := 0; i < n+n+100; i++ {
		fg = append(fg, a[fg[len(fg)-1]])
	}

	if k < n+1 {
		fmt.Println(fg[k])
		return
	}

	loopEnd := n
	loopStart := n - 1
	for fg[loopEnd] != fg[loopStart] {
		loopStart--
	}
	loopLen := loopEnd-loopStart

	k %= loopLen
	if k < n {
		k += loopLen
	}

	fmt.Println(fg[k])
}


package main

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

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

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

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

func scanInts64(n int) []int64 {
	res := make([]int64, n)
	for i := range res {
		res[i] = scanInt64()
	}
	return res
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	n, k := scanInt(), scanInt()
	a := make([]int, n)
	for i := range a {
		a[i] = scanInt() - 1
	}
	fg := []int{a[0]}
	for i := 0; i < n+100; i++ {
		fg = append(fg, a[fg[len(fg)-1]])
	}

	if k <= n {
		fmt.Println(fg[k-1])
	}

	loopEnd := n - 1
	loopStart := n - 2
	loopLen := 0
	for i := 0; i < n; i++ {
		if fg[loopEnd] == fg[loopStart] {
			loopLen = loopEnd - loopStart
			break
		}
		loopStart--
	}

	k %= loopLen
	if k < n {
		k += loopLen
	}

	fmt.Println(fg[k-1] + 1)
}


package main

import (
	"fmt"
)

func main() {
	var N, K int
	fmt.Scanf("%d %d", &N, &K)
	A := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &A[i])
	}

	next := A[0]
	pattern := []int{1}
	counter := make([]int, N)
	for i := 0; i < N; i++ {
		counter[i] = 0
	}
	counter[0]++
	for {
		pattern = append(pattern, next)
		counter[next-1]++
		if counter[next-1] > 1 {
			break
		}
		next = A[next-1]
	}
	patternFastIndex := next
	var patternA, patternB []int
	if patternFastIndex == 1 {
		patternA = pattern[:patternFastIndex-1]
		patternB = pattern[patternFastIndex-1 : len(pattern)-1]
	} else {
		patternA = pattern[:patternFastIndex]
		patternB = pattern[patternFastIndex : len(pattern)-1]
	}
	if K >= len(patternA) {
		fmt.Println(patternB[(K-len(patternA))%len(patternB)])
	} else {
		fmt.Println(patternA[K%len(patternA)])
	}
}


package main

import (
	"fmt"
)

func main() {
	var N, K int
	fmt.Scanf("%d %d", &N, &K)
	A := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &A[i])
	}

	next := A[0]
	pattern := []int{1}
	counter := make([]int, N)
	for i := 0; i < N; i++ {
		counter[i] = 0
	}
	counter[0]++
	for {
		pattern = append(pattern, next)
		counter[next-1]++
		next = A[next-1]
		breakFlag := false
		for i := 0; i < N; i++ {
			if counter[i] > 1 {
				breakFlag = true
				break
			}
		}
		if breakFlag {
			break
		}
	}
	patternFastIndex := -1
	for i := 0; i < N; i++ {
		if counter[i] == 2 {
			patternFastIndex = i + 1
			break
		}
	}
	// fmt.Println(patternFastIndex)
	var patternA, patternB []int
	if patternFastIndex == 1 {
		patternA = pattern[:patternFastIndex-1]
		patternB = pattern[patternFastIndex-1 : len(pattern)-1]
	} else {
		patternA = pattern[:patternFastIndex]
		patternB = pattern[patternFastIndex : len(pattern)-1]
	}
	if K >= len(patternA) {
		fmt.Println(patternB[(K-len(patternA))%len(patternB)])
	} else {
		fmt.Println(patternA[K])
	}
}


package main

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

const (
	maxBufsize = 1000000
)

func inputs(lines int, rdr *bufio.Reader) []string {
	var strSlice []string

	//rdr := bufio.NewReaderSize(os.Stdin, maxBufsize)

	for i := 0; i < lines; i++ {

		line := ReadLine(rdr)
		strSlice = append(strSlice, line)

	}

	return strSlice
}

// ReadLine is to read long line
func ReadLine(rdr *bufio.Reader) string {
	buf := make([]byte, 0, maxBufsize)
	for {
		l, p, e := rdr.ReadLine()

		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}

	return string(buf)
}

//DivideConvertInt is to divide and convert
func DivideConvertInt(line string, num int) []int {
	tmp := strings.Split(line, " ")

	intSlice := make([]int, num)

	for i := 0; i < num; i++ {
		intTmp, _ := strconv.Atoi(tmp[i])
		intSlice[i] = intTmp
	}

	return intSlice
}

func main() {
	rdr := bufio.NewReaderSize(os.Stdin, maxBufsize)
	line0 := inputs(1, rdr)

	line0Int := DivideConvertInt(line0[0], 2)

	N := line0Int[0]
	K := line0Int[1]

	line1 := inputs(1, rdr)

	A := DivideConvertInt(line1[0], N)

	check := []int{}
	ord := make([]int, N+1)

	for i := 0; i < N+1; i++ {
		ord[i] = -1
	}

	i := 1

	for {
		if ord[i] == -1 {
			ord[i] = len(check)
			check = append(check, i)
			i = A[i-1]
		} else {
			break
		}
	}

	cycle := len(check) - ord[i]

	l := ord[i]

	if K < l {
		fmt.Println(check[K])
	} else {
		K -= l
		K %= cycle
		fmt.Println(check[l+K])
	}

}


package main

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

var startval int

func solve() {
	n := scanInt()
	k := scanInt()
	a := make([]int, n)
	seen := map[int]bool{}
	trace := []int{0}
	for i := 0; i < n; i++ {
		a[i] = scanInt()
	}
	for i := 0; i < k; i++ {
		next := a[trace[i]] - 1
		_, ok := seen[next]
		if ok {
			startval = next
			break
		}
		trace = append(trace, next)
		seen[next] = true
	}
	var start int
	for i := 0; i < k; i++ {
		if trace[i] == startval {
			start = i
			break
		}
	}
	repetition := trace[start:]
	fmt.Println(repetition[(k-start)%(len(repetition))] + 1)
	return
}

var sc = bufio.NewScanner(os.Stdin)

func scanString() string {
	sc.Scan()
	return sc.Text()
}
func scanInt() int {
	sc.Scan()
	a, err := strconv.Atoi(sc.Text())
	if err != nil {
		fmt.Println(err)
	}
	return a
}
func scanFloat64() float64 {
	f, _ := strconv.ParseFloat(scanString(), 64)
	return f
}
func Permute(nums []int) [][]int {
	n := factorial(len(nums))
	ret := make([][]int, 0, n)
	permute(nums, &ret)
	return ret
}
func permute(nums []int, ret *[][]int) {
	*ret = append(*ret, makeCopy(nums))

	n := len(nums)
	var i, j int
	for {
		for i = n - 2; i >= 0; i-- {
			if nums[i] < nums[i+1] {
				break
			}
		}
		if i < 0 {
			return
		}
		for j = n - 1; ; j-- {
			if nums[j] > nums[i] {
				break
			}
		}
		nums[i], nums[j] = nums[j], nums[i]
		for k, l := i+1, n-1; k < l; {
			nums[k], nums[l] = nums[l], nums[k]
			k++
			l--
		}
		*ret = append(*ret, makeCopy(nums))
	}
}

func factorial(n int) int {
	ret := 1
	for i := 2; i <= n; i++ {
		ret *= i
	}
	return ret
}
func makeCopy(nums []int) []int {
	return append([]int{}, nums...)
}
func gcd(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}
func main() {
	sc.Split(bufio.ScanWords)
	solve()
}


package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)
var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

// https://atcoder.jp/contests/abc167/tasks/abc167_d
var hashMap map[int]int
var history map[int]int
var muraCount int
func main() {

	firstLine := strings.Split(readLine(), " ")
	secondLine := strings.Split(readLine(), " ")

	// line 1 N札 M個 目標値
	// line over 2 値段 アルゴ理解度......
	muraCount, _ = strconv.Atoi(firstLine[0])
	jumpNum, _ := strconv.Atoi(firstLine[1])

	hashMap = make(map[int]int, muraCount)
	history = make(map[int]int, muraCount)
	for i, v := range secondLine {
		n, _ := strconv.Atoi(v)
		hashMap[i+1] = n
	}

	jump(jumpNum, 1, 0)

}

func jump(k int, index int, cnt int) {

	if cnt == k {
		fmt.Println(index)
		os.Exit(0)
	}

	for i, v := range history {
		if v == index {
			// ループしたことになる 現在 cnt - i 分移動すると また香り高い街に移動する。
			// 残りの移動量は k - cnt となり、 (k-cnt) % (cnt - i) 分移動すれば答えとなる。
			nokori := (k - cnt) % (cnt - i)
			history = make(map[int]int, muraCount)
			jump(nokori, index, 0)
		}
	}
	history[cnt] = index

	jump(k, hashMap[index], cnt+1)

}

func readLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


package main

import (
	"fmt"
	"strconv"

	// Reader
	"bufio"
	"os"
	"strings"
)

const BUFF_LIMIT = 1000000

func main() {
	var i Input
	i.Init(BUFF_LIMIT)
	d := i.NextLine()

	townCount, _ := strconv.Atoi(d[0])
	numK, _ := strconv.Atoi(d[1])

	tl := i.NextLine()
	lines := make([]int, townCount)
	for n := 0; n < townCount; n++ {
		ti, _ := strconv.Atoi(tl[n])
		lines[n] = ti
	}

	path, before, loop := parseLines(lines)
	//fmt.Println(path)
	//fmt.Println(before)
	//fmt.Println(loop)
	loopPos := (numK - before) % loop
	townPos := path[before + loopPos]
	//fmt.Println(townPos)

	fmt.Printf("%d \n", townPos + 1)
}

func parseLines(lines []int) ([]int, int, int) {
	var path []int
	from := 0
	path = append(path, 0)
	for {
		to := lines[from] - 1
		pos := contains(path, to)
		if pos == -1 {
			// 無いとき
			path = append(path, to)
			from = to
			continue
		}

		// ある時 (どこかでloop してる
		beforeCount := pos
		loopCount := len(path) - pos
		return path, beforeCount, loopCount
	}
}

// Checker
func contains(s []int, e int) int {
	for k, v := range s {
		if e == v {
			return k
		}
	}
	return -1
}

// InputReader
type Input struct {
	limit int
	reader *bufio.Reader
}

func (i *Input) Init(l int) {
	i.limit = l
	i.reader = bufio.NewReaderSize(os.Stdin, i.limit)
}

func (i *Input) NextLine() []string {
	return i.parseLine(i.readLine())
}

func (i *Input) readLine() string {
	buf := make([]byte, 0, i.limit)
	for {
		l, p, e := i.reader.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func (i *Input) parseLine(s string) []string {
	slice := strings.Split(s, " ")
	return slice
}


package main

import (
	"fmt"
	"strconv"

	// Reader
	"bufio"
	"os"
	"strings"
)

const BUFF_LIMIT = 1000

func main() {
	var i Input
	i.Init(BUFF_LIMIT)
	d := i.NextLine()

	townCount, _ := strconv.Atoi(d[0])
	numK, _ := strconv.Atoi(d[1])

	tl := i.NextLine()
	lines := make([]int, townCount)
	for n := 0; n < townCount; n++ {
		ti, _ := strconv.Atoi(tl[n])
		lines[n] = ti
	}

	path, before, loop := parseLines(lines)

	loopPos := (numK - before) % loop
	townPos := path[before + loopPos]

	fmt.Printf("%d \n", townPos + 1)
}

func parseLines(lines []int) ([]int, int, int) {
	var path []int
	from := 0
	path = append(path, 0)
	for {
		to := lines[from] - 1
		pos := contains(path, to)
		if pos == -1 {
			// 無いとき
			path = append(path, to)
			from = to
			continue
		}

		// ある時 (どこかでloop してる
		beforeCount := pos
		loopCount := len(path) - pos
		return path, beforeCount, loopCount
	}
}

// Checker
func contains(s []int, e int) int {
	for k, v := range s {
		if e == v {
			return k
		}
	}
	return -1
}

// InputReader
type Input struct {
	limit int
	reader *bufio.Reader
}

func (i *Input) Init(l int) {
	i.limit = l
	i.reader = bufio.NewReaderSize(os.Stdin, i.limit)
}

func (i *Input) NextLine() []string {
	return i.parseLine(i.readLine())
}

func (i *Input) readLine() string {
	buf := make([]byte, 0, i.limit)
	for {
		l, p, e := i.reader.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func (i *Input) parseLine(s string) []string {
	slice := strings.Split(s, " ")
	return slice
}


// +build ignore
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []byte {
	return []byte(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

func gcd(x, y int) int {
	if x%y != 0 {
		return gcd(y, x%y)
	}
	return y
}

const D = 60

func run(input io.Reader, output io.Writer) int {
	sc := NewScanner()
	N := sc.nextInt()
	K := sc.nextInt()
	A := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = sc.nextInt() - 1
	}

	T := make([][]int, D)
	T[0] = make([]int, N)
	for i := 0; i < N; i++ {
		T[0][i] = A[i]
	}

	for i := 1; i < D; i++ {
		T[i] = make([]int, N)
		for j := 0; j < N; j++ {
			T[i][j] = T[i-1][T[i-1][j]]
		}
	}

	p := 0
	for i := D; i >= 0; i-- {
		if K&(1<<i) != 0 {
			p = T[i][p]
		}
	}

	fmt.Println(p + 1)

	return 0
}

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


package main

import (
        "fmt"
)

func solution(n, k int, a []int) int {
        visit := make([]int, 0)
        hop := make([]int, n+1)
        for i := range hop {
                hop[i] = -1
        }

        cur := 1
        c := 1
        l := 0
        for hop[cur] == -1 {
                hop[cur] = len(visit)
                visit = append(visit, cur)
                cur = a[cur-1]
        }

        c = len(visit) - hop[cur]
        l = hop[cur]
        ans := 0
        if k < l {
                ans = visit[k]
        } else {
                k -= l
                k %= c
                ans = visit[l+k]
        }
        return ans
}

func main() {
        var n, k int
        fmt.Scan(&n, &k)
        a := make([]int, 0, n)
        for i := 0; i < n; i++ {
                tmp := 0
                fmt.Scan(&tmp)
                a = append(a, tmp)
        }
        fmt.Println(solution(n, k, a))
}


package main

import (
	"fmt"
	"math/big"
	"strconv"
)

var N int
var Kstr string
var K = big.NewInt(0)
var cycleStartAt, cycleStart int
var cycle []int

func main() {
	fmt.Scan(&N, &Kstr)
	ctr := int64(0)
	ten := big.NewInt(10)
	for i := len(Kstr) - 1; i >= 0; i-- {
		val, _ := strconv.Atoi(string(Kstr[i]))
		K = new(big.Int).Add(K, new(big.Int).Mul(big.NewInt(int64(val)), new(big.Int).Exp(ten, big.NewInt(ctr), nil)))
		ctr++
	}
	towns := make([]*town, N+1)
	towns[0] = &town{
		next: 1,
		came: false,
	}
	for i := 1; i <= N; i++ {
		var next int
		fmt.Scan(&next)
		towns[i] = &town{
			next: next,
			came: false,
		}
	}
	s := 1
	cur := 1
	for {
		if towns[cur].came {
			cycleStartAt = cur
			cycleStart = s
			break
		}
		towns[cur].came = true
		cur = towns[cur].next
		s++
	}
	cur = 0
	for i := 0; i <= N; i++ {
		if towns[cur].next == cycleStartAt {
			t := towns[cur]
			for {
				cycle = append(cycle, t.next)
				t = towns[t.next]
				if t.next == cycleStartAt {
					break
				}
			}
			break
		}
		cur = towns[cur].next
	}
	step := big.NewInt(0)
	cur = 1
	if K.Int64() <= int64(cycleStart) {
		for i := int64(1); i <= K.Int64(); i++ {
			cur = towns[cur].next
		}
		fmt.Println(cur)
		return
	}
	for {
		step = new(big.Int).Add(step, big.NewInt(1))
		currentTown := towns[cur]
		if currentTown.next == cycleStartAt {
			addr := new(big.Int).Mod(new(big.Int).Sub(K, step), big.NewInt(int64(len(cycle))))
			fmt.Print(cycle[addr.Int64()])
			return
		}
		cur = currentTown.next
	}
}

type town struct {
	next int
	came bool
}


package main

import "fmt"

func main() {
	var n, k int
	start := 0
	fmt.Scan(&n, &k)
	a := make([]int, n)
	state := make([]int, n)
	tmp := make([]int, 1000000)
	tmp[0] = 0
	loopLength := 0

	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	for i := 0; i < k; i++ {
		start = a[start] - 1
		tmp[i+1] = start
		if state[start] == 1 {
			for j := 0; j < len(tmp); j++ {
				if tmp[j] == start {
					tmp = tmp[j : i+1]
					loopLength = len(tmp)
					break
				}
			}
			fmt.Println(tmp[(k-i-1)%loopLength] + 1)
			return
		} else {
			state[start] = 1
		}
	}
	fmt.Println(start + 1)
}


package main

import "fmt"

func main() {
	var n, k int
	start := 1
	fmt.Scan(&n, &k)
	a := make([]int, n+1)
	state := make([]int, n+1)
	tmp := make([]int, 5000000)
	tmp[0] = 1
	state[1] = 1
	loopLength := 0

	for i := 0; i < n; i++ {
		fmt.Scan(&a[i+1])
	}

	for i := 0; i < k; i++ {
		start = a[start]
		tmp[i+1] = start
		if state[start] == 1 {
			for j := 0; j < i+1; j++ {
				if tmp[j] == start {
					tmp = tmp[j : i+1]
					loopLength = len(tmp)
					break
				}
			}
			// fmt.Println(tmp)
			fmt.Println(tmp[(k-i-1)%loopLength])
			return
		} else {
			state[start] = 1
		}
	}
	println(start)
}


package main

import "fmt"

func main() {
	var n, k int
	start := 1
	fmt.Scan(&n, &k)
	a := make([]int, n+1)
	state := make([]int, n+1)
	tmp := make([]int, 5000000)
	tmp[0] = 1
	state[1] = 1
	loopLength := 0

	for i := 0; i < n; i++ {
		fmt.Scan(&a[i+1])
	}

	for i := 0; i < k; i++ {
		start = a[start]
		tmp[i+1] = start
		if state[start] == 1 {
			for j := 0; j < len(tmp); j++ {
				if tmp[j] == start {
					tmp = tmp[j : i+1]
					loopLength = len(tmp)
					break
				}
			}
			// fmt.Println(tmp)
			fmt.Println(tmp[(k-i-1)%loopLength])
			return
		} else {
			state[start] = 1
		}
	}
	println(start)
}


package main

import (
	"fmt"
)

func findCircuit(array []int) (int, int) {
	for i := 0; i < len(array); i++ {
		var target = array[i]
		for j := i+1; j < len(array); j++ {
			if array[j] == target {
				return i, j
			}
		}
	}
	return -1, -1
}

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

	fmt.Printf("%d %d", n, k)

	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	b := make([]int, n + 2)
	b[0] = 1
	for i := 0; i < n; i++ {
		b[i+1] = a[b[i] - 1]
	}
	// fmt.Printf("%d", b)
	var start, end = findCircuit(b)
	var duration = end - start
	// fmt.Printf("%d %d %d", start, end, duration)

	if start >= k {
		now := 0
		for i := 0; i < k; i++ {
			now = a[now] - 1
		}
		fmt.Printf("%d", now)
	} else {
		k = k - start
		k = k % duration
		// fmt.Printf("k=%d", k)
		fmt.Printf("%d", b[start + k])
	}
}


package main

import "fmt"

func main() {
	k, a := input()
	ans := run(k, a)
	output(ans)
}

func run(k int, a []int) int {
	town := 0
	// trajectory := []int{}
	trajectory := make(map[int]int)
	var begin, end int
	var ok bool
	var i int
	for i = 0; i < k; i++ {
		begin, ok = trajectory[town]
		// begin = firstAppearance(town, trajectory)
		if ok {
			end = i
			break
		}
		trajectory[town] = i
		// trajectory = append(trajectory, town)
		town = a[town]
	}
	if i == k {
		return town + 1
	}
	t := (k - begin) % (end - begin)
	// fmt.Println(begin, end)
	// fmt.Println(trajectory)
	arr := make([]int, end-begin, end-begin)
	for i, v := range trajectory {
		if begin <= v && v < end {
			arr[v-begin] = i
		}
	}
	// fmt.Println(arr)
	// arr := trajectory[begin:end]
	return arr[t] + 1
	// return -1
}

func firstAppearance(x int, t map[int]int) int {
	for i, v := range t {
		if x == v {
			return i
		}
	}
	return -1
}

func output(a int) {
	fmt.Println(a)
}

func input() (int, []int) {
	var n, k int
	fmt.Scan(&n, &k)
	a := make([]int, n, n)
	var t int
	for i := range a {
		fmt.Scan(&t)
		a[i] = t - 1
	}
	return k, a
}


package main

import "fmt"

func main() {
	var n, k int

	fmt.Scanf("%d %d", &n, &k)

	a := make([]int, n+1)
	for i := 1; i <= n; i++ {
		fmt.Scanf("%d", &a[i])
	}

	pos := 1
	prev := pos
	memo := []int{1}
	var i int

	for i = 0; i < k; i++ {
		prev = pos
		pos = a[pos]
		a[prev] = -(i + 1)
		if pos < 0 {
			break
		}
		memo = append(memo, pos)
	}

	if i == k {
		fmt.Println(pos)
	} else {
		j := -pos
		k1 := k - j
		l := len(memo) - j
		mod := k1 % l
		fmt.Println(memo[j+mod])
	}
}


package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n, k := scanInt(), scanInt()
	a := make([]int, n+1)
	for i := 1; i <= n; i++ {
		a[i] = scanInt()
	}

	p := 1
	ans := make([]int, n+1)
	ans[0] = p
	passed := make([]int, n+1)
	for i := range passed {
		passed[i] = -1
	}
	passed[1] = 0
	var r int
	for i := 1; i <= n; i++ {
		p = a[p]
		if passed[p] != -1 {
			k -= passed[p]
			r = i - passed[p] - 1
			break
		}

		passed[p] = i
		ans[i] = p
		if i == k {
			fmt.Println(p)
			return
		}
	}

	k %= r
	fmt.Println(ans[k+1])
}


package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n, k := scanInt(), scanInt()
	a := make([]int, n+1)
	for i := 1; i <= n; i++ {
		a[i] = scanInt()
	}

	p := 1
	ans := make([]int, n+1)
	ans[0] = p
	passed := make(map[int]int)
	passed[p] = 0
	var r int
	for i := 1; i <= n; i++ {
		p = a[p]
		if _, ok := passed[p]; ok {
			k -= passed[p]
			r = i - passed[p] - 1
			break
		}

		passed[p] = i
		ans[i] = p
		if i == k {
			fmt.Println(p)
			return
		}
	}

	k %= r
	fmt.Println(ans[k+1])
}