Problem:
Score : 100 points

Problem Statement

You are given an integer N that has exactly four digits in base ten.
How many times does 2 occur in the base-ten representation of N?

Constraints

1000 \leq N \leq 9999

Input

Input is given from Standard Input in the following format:

N

Output

Print the answer.

Sample Input 1

1222

Sample Output 1

3

2 occurs three times in 1222. By the way, this contest is held on December 22 (JST).

Sample Input 2

3456

Sample Output 2

0

Sample Input 3

9592

Sample Output 3

1

Solution in Go (1.6) (judge verdict: Runtime Error)

package main

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

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

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

func scanTextArray(n int) []string {
	out := make([]string, n)
	for i, v := range(strings.Split(scanText(), "")) {
		out[i] = v
	}
	return out
}

func scanInt() int {
	out, e := strconv.Atoi(scanText())
	if e != nil {
        panic(e)
    }
	return out
}

func scanIntArray(n int) []int {
	out := make([]int, n)
	for i, v := range(strings.Split(scanText(), " ")) {
		num, e := strconv.Atoi(v)
		if e != nil {
			panic(e)
		}
		out[i] = num
	}
	return out
}
func pow(x, n int) int{
	ans := 1
	for i:=0; i<n; i++ {
		ans *= x
	}
	return ans
}

func is_p_num(x int, arr []int) bool{
	for _, v := range arr {
		if x%v == 0 {
			return false
		}
	}
	return true
}
//  template end

func main() {
	sc.Buffer(buf, 10000)
	np := scanIntArray(2)
	N, P := np[0], np[1]
	ans := 1
	if N == 1 {
		ans = P
	} else if P == 1 {
		ans = 1
	} else {
		// p_nums := make([]int, 0)
		x := 2
		for {
			// if !is_p_num(x, p_nums) {
			// 	x++
			// 	continue
			// } else {
			// 	p_nums = append(p_nums, x)
			// }
			x_pow := pow(x, N)
			// fmt.Println(x, N, x_pow, P)
			if P < x_pow {
				break
			} else {
				for {
					if P % x_pow == 0 {
						ans *= x
						P /= x_pow
					} else {
						break
					}
				}
			}
			// fmt.Println(x, p_nums)
			x++
		}
	}
	fmt.Println(ans)
}