Alexander is learning how to convert numbers from the decimal system to any other, however, he doesn't know English letters, so he writes any number only as a decimal number, it means that instead of the letter A he will write the number 10. Thus, by converting the number 475 from decimal to hexadecimal system, he gets 11311 (475 = 1·162 + 13·161 + 11·160). Alexander lived calmly until he tried to convert the number back to the decimal number system.Alexander remembers that he worked with little numbers so he asks to find the minimum decimal number so that by converting it to the system with the base n he will get the number k.

The first line contains the integer n (2 ≤ n ≤ 109). The second line contains the integer k (0 ≤ k < 1060), it is guaranteed that the number k contains no more than 60 symbols. All digits in the second line are strictly less than n. Alexander guarantees that the answer exists and does not exceed 1018. The number k doesn't contain leading zeros.

Print the number x (0 ≤ x ≤ 1018) — the answer to the problem.

NoteIn the first example 12 could be obtained by converting two numbers to the system with base 13: 12 = 12·130 or 15 = 1·131 + 2·130.

package main

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

func solve() {
	n := readInt64()
	k := readString()
	values := make([]int, 0)
	for len(k) > 0 {
		var maxValue int
		var maxIndex int
		for i := len(k) - 1; i >= 0; i-- {
			value, err := strconv.ParseInt(k[i:], 10, 64)
			if err == nil {
				if value < n {
					maxValue = int(value)
					maxIndex = i
				} else {
					break
				}
			} else {
				break
			}
		}
		if maxIndex+1 < len(k) {
			if maxValue != 0 {
				for maxIndex < len(k) && k[maxIndex] == '0' {
					maxIndex++
				}
			} else if maxValue == 0 {
				maxIndex = len(k) - 1
			}
		}
		k = k[:maxIndex]
		values = append(values, maxValue)
	}
	var res int64
	for i := len(values) - 1; i >= 0; i-- {
		res *= n
		res += int64(values[i])
	}
	fmt.Println(res)
}

var scanner *bufio.Scanner

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

// IO

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

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

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

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

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

package main

import (
	"fmt"
	"log"
	"sort"
)

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}
func find_last_le_idx(a []int, target int )int {
	//if not exist rturn -1

	s := 0
	e := len(a)
	for ;s < e;{
		mid := s +(e- s)/2
		if a[mid ] <= target{
			s = mid + 1
		}else {
			e = mid
		}
	}
	return s - 1
}

func find_first_ge_idx(a []int, target int )int {
	//if not exist rturn -1

	s := 0
	e := len(a)
	for ;s < e;{
		mid := s +(e- s)/2
		if a[mid ] < target{
			s = mid + 1
		}else {
			e = mid
		}
	}

	return s
}

func maxSumSubmatrix(a [][]int, target int) int {
	row := len(a)
	if row == 0{
		return 0
	}
	col := len(a[0])

	pre_sum := make([][]int, row)
	for i := range pre_sum{
		pre_sum[i] = make([]int ,col)
	}

	for i := 0;i < row; i ++{
		for j :=0;j < col; j ++{
			if j == 0 {
				pre_sum[i][j] = a[i][j]
			}else {
				pre_sum[i][j] = pre_sum[i][j-1] + a[i][j]
			}
		}
	}

	near := -100000000
	for i := 0; i < col ; i ++{
		for j :=i ;j <col; j ++{
			tmp := []int {0}
			cur := 0
			for k := 0;k < row; k++{

				if i == j {
					cur += a[k][i]
				}else if i == 0{
					cur += pre_sum[k][j]
				}else {
					cur += pre_sum[k][j] - pre_sum[k][i-1]
				}
				idx := find_first_ge_idx(tmp, cur  - target)
				if idx != len(tmp){
					near = max(near, cur -tmp[idx] )
				}
				iid := find_first_ge_idx(tmp, cur )
				q := tmp[iid:]
				tmp = append(tmp[:iid], cur)
				tmp = append(tmp ,q...)

				//if k == 0{
				//	if cur ==target || (cur < target&& cur > near) {
				//		near = cur
				//	}
				//	tmp = append(tmp, cur)
				//}
			}

		}
	}
	return near
}

func q(matrix [][]int, k int) int {
	row := len(matrix)
	col := len(matrix[0])
	near := -1000000
	for left := 0; left < col ; left ++{
	// 以left为左边界，每行的总和
		_sum :=make([]int, row)
	//for right in range(left, col):
		for right :=left ;right <col; right ++ {

			for j := 0; j < row; j++ {
				_sum[j] += matrix[j][right]
			}
			// 在left，right为边界下的矩阵，求不超过K的最大数值和
			tmp := []int{0}
			cur := 0
			for _, tmpp := range _sum {
				cur += tmpp

				//# 二分法
				idx := find_first_ge_idx(tmp, cur-k)
				if idx != len(tmp) {
					near = max(near, cur-tmp[idx])
				}
				iid := find_first_ge_idx(tmp, cur)
				q := []int{}

				q= append(q, tmp[iid:]...)
				ee := []int{}
				ee = append(ee,tmp[:iid]...)
				ee = append(ee, cur)
				tmp = append(ee, q...)
			}
		}
		}

	return near
}

func qeqw(a int, aa int) int{

	caa := "asas"
	log.Println(caa)
	return 23
}

func m(a []int, b[]int){
	 //q := map[[2]int]bool{}

}
var ori [1000001]int
var record [1000001]int

var energy [1000001]int
var counter [1000001]int

//}
func p(){
	var n int
	var k int
	var target int
	//var n,k int
	fmt.Scan(&n)
	fmt.Scan(&k)
	for i := 0;i < n; i ++{
		fmt.Scan(&record[i])
	}
	idx := -1
	left := 0
	min_l := 1000000000
	m_l := 0
	m_r := 0
	for ;left < n &&idx < n;{
		if target == k {
			//if counter[record[left]] > 1 {
			if idx - left +1 < min_l{
				min_l = idx - left + 1
				m_l = left
				m_r = idx
			}
			counter[record[left]] --

			//}else {
			//
			//}
			if counter[record[left]] == 0 {
				target --
			}
			left ++
		}else{
				idx ++
			counter[record[idx]] ++
			if counter[record[idx]] == 1{
				target ++
			}
			//idx++
		}
	}
	fmt.Println(m_l + 1, m_r + 1)
}

func ini(){
	var n int
	//var k int
	fmt.Scan(&n)
	//fmt.Scan(&k)
	for i := 0;i < n; i ++{
		fmt.Scan(&ori[i])
		fmt.Scan(&energy[i])
	}
	R := -1
	L := 0
	for i :=0; i < n; i ++{
		//if record[L] == i - k{
		//	L ++
		//}
		for ;R >= L &&ori[i] >ori[record[R]];R--{
			counter[i]	+= energy[record[R]]
		}
		tmp := energy[i]
		for ;R >= L &&ori[i] ==ori[record[R]];R--{
			tmp += energy[i]
		}
		R ++
		record[R] = i
		if R != 0  {
			counter[record[R - 1]] += tmp
		}
	}
	m := -1
	for i :=0; i <n;i ++{
		if counter[i] > m{
			m = counter[i]
		}
	}
	fmt.Println(m)
}
type S struct {
	Idx int
	Time int

}
type intSlice []S

func (p intSlice) Len() int           { return len(p) }
func (p intSlice) Less(i, j int) bool { return p[i].Time > p[j].Time }
func (p intSlice) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }

var roww [1000]int
var coll [1000]int
func inii(){
	var m,n,k,l,d int
	//var k int
	row := make(intSlice, 10000)
	col := make(intSlice, 10000)
	fmt.Scan(&m, &n, &k, &l,&d)
	//fmt.Scan(&k)
	for i := 0;i < d; i ++{
		var x1,y1,x2,y2 int
		fmt.Scan(&x1,&y1,&x2,&y2)
		if x1 == x2 {
			if y1 > y2 {
				y1,y2 = y2,y1
			}
			col[y1].Idx = y1
			col[y1].Time ++
		}else{
				if x1 > x2{
					x1,x2 = x2,x1
				}
				row[x1].Idx = x1
			row[x1].Time ++
		}
		//fmt.Scan(&energy[i])
	}
	//row = row[:m+1]
	//col = col[:n + 1]
	sort.Sort(row)
	sort.Sort(col)
	row = row[:k+1]
	col = col[:l + 1]
	sort.Sort(row)
	sort.Sort(col)
	for i := 0;i < k-1;i ++ {
		fmt.Print(row[i].Idx," ")
	}
	fmt.Print(row[k -1 ].Idx,"\n")
	for i := 0;i < l-1;i ++ {
		fmt.Print(col[i].Idx," ")
	}
	fmt.Print(col[l -1 ].Idx,"\n")

}

func next_per(){
	var n int
	var m int
	fmt.Scan(&n,&m)
	a :=make([]int, n)
	for i:=0;i <n;i++{
		fmt.Scan(&a[i])
	}
	for ;m > 0;m--{
		i := 0
		for i = n-2;i >=0;i --{
			if a[i] < a[i + 1]{
				break
			}

		}
		//t := a[i+1]
		j := 0
		for j = i + 1;j < n;j ++{
			if a[j] <= a[i]{
					break
			}
		}
		a[i],a[j-1] = a[j-1],a[i]
		sort.Ints(a[i + 1:])

	}
	fmt.Println(a)

}
var s string
var n,ans,length,carry int64
//var ans int
//var length int
//var carry int
//func max(x,y int)int{
//	if x > y{
//		return x
//	}
//	return y
//}
func maxf(x, y int64)int64{
	if x > y {
		return x
	}
	return y
}
func get(k int)int{
	var x int64
	var t int64 = 1
	i := k
	for ;i  >= 0; i -- {
		if x + maxf(int64(1), (int64)(s[i]-'0')) * int64(t) >=n{
			break
		}
		x += int64(s[i]-'0') * t
		t *= 10
	}
	for ;s[i+ 1] == '0'&& i < k-1;i ++{

	}
	ans += x * carry
	return i
}
func qq(){

	carry = 1
	fmt.Scan(&n, &s)
	i := len(s) - 1
	for ;i >=0;{
		i = get(i)
		carry *=n
	}
	fmt.Println( ans)

}

func main(){
	//a := [][]int{{28,4,-19,18,-7,-10,27,19,1,16,0,10,-17,11,11,27,-1,10,12,-1},
	//	{-2,-19,17,4,25,-20,4,3,4,28,-10,7,16,-14,-3,-19,6,17,-4,-7},
	//	{2,8,18,-17,-2,10,-6,-5,11,10,22,-6,19,-16,6,-4,18,5,22,-17},
	//	{-14,-7,-20,13,-19,-20,-15,21,-11,-10,-8,-9,10,13,6,-10,15,9,-15,-2},
	//	{-18,26,12,8,2,16,-17,12,0,-5,9,-3,-12,-11,3,-6,-18,16,-7,-14},
	//	{5,29,25,22,11,-3,-2,-15,4,13,-17,-2,0,-2,20,10,-18,6,25,-20},
	//	{5,-7,8,5,15,22,8,-5,22,-18,-5,-14,23,2,-8,12,-16,-18,12,-12},
	//	{27,18,4,11,-3,12,-4,-8,-3,25,-9,24,-14,5,11,-9,-17,0,25,-15},
	//	{26,-7,18,4,4,18,-17,9,-19,-9,-19,-8,-4,-13,10,-11,6,-16,-12,12},
	//	{28,22,7,11,-6,13,8,22,7,-14,17,14,10,29,16,9,-3,18,-9,10},
	//	{27,19,-10,-9,1,3,14,1,7,3,-3,16,-2,9,14,-7,-19,-5,23,19},
	//	{-17,7,-20,8,-5,-6,-2,25,29,16,23,4,4,27,16,17,9,20,-6,22},
	//	{2,9,-13,1,-18,25,4,7,25,26,-4,8,-19,18,6,-7,-5,7,21,-8},
	//	{-2,11,1,29,6,-16,-8,3,7,11,10,-2,-1,-20,20,4,19,5,29,-7},
	//	{29,-12,-3,17,6,19,23,12,-19,13,19,5,27,22,-17,27,10,-12,12,23},
	//	{24,16,4,25,15,13,24,-19,1,-7,-19,13,-13,14,13,26,9,18,-9,-18},
	//	{-17,4,-18,-18,-19,3,-13,12,23,-17,-10,-20,14,2,18,21,-12,27,-3,4},
	//	{27,13,12,14,16,-9,-2,-15,-20,8,-2,24,18,15,26,21,27,17,-15,-3},
	//	{25,-8,17,-10,-16,13,26,-11,-15,6,-5,-13,23,2,24,-4,5,8,-15,-1},
	//	{15,-12,18,5,-3,7,5,11,-4,-13,28,20,0,-4,-13,-5,-13,-8,-16,3}}

	//log.Println(find_last_le_idx(a, 3))
	//log.Println(q(a, -123))

	//aa := []int{2,3,1,3,4,6,1,2}
	//mm(aa, 1)
	//ini()
//inii()
	//next_per()
	qq()
}

package main

import (
	"fmt"
	"log"
	"sort"
)

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}
func find_last_le_idx(a []int, target int )int {
	//if not exist rturn -1

	s := 0
	e := len(a)
	for ;s < e;{
		mid := s +(e- s)/2
		if a[mid ] <= target{
			s = mid + 1
		}else {
			e = mid
		}
	}
	return s - 1
}

func find_first_ge_idx(a []int, target int )int {
	//if not exist rturn -1

	s := 0
	e := len(a)
	for ;s < e;{
		mid := s +(e- s)/2
		if a[mid ] < target{
			s = mid + 1
		}else {
			e = mid
		}
	}

	return s
}

func maxSumSubmatrix(a [][]int, target int) int {
	row := len(a)
	if row == 0{
		return 0
	}
	col := len(a[0])

	pre_sum := make([][]int, row)
	for i := range pre_sum{
		pre_sum[i] = make([]int ,col)
	}

	for i := 0;i < row; i ++{
		for j :=0;j < col; j ++{
			if j == 0 {
				pre_sum[i][j] = a[i][j]
			}else {
				pre_sum[i][j] = pre_sum[i][j-1] + a[i][j]
			}
		}
	}

	near := -100000000
	for i := 0; i < col ; i ++{
		for j :=i ;j <col; j ++{
			tmp := []int {0}
			cur := 0
			for k := 0;k < row; k++{

				if i == j {
					cur += a[k][i]
				}else if i == 0{
					cur += pre_sum[k][j]
				}else {
					cur += pre_sum[k][j] - pre_sum[k][i-1]
				}
				idx := find_first_ge_idx(tmp, cur  - target)
				if idx != len(tmp){
					near = max(near, cur -tmp[idx] )
				}
				iid := find_first_ge_idx(tmp, cur )
				q := tmp[iid:]
				tmp = append(tmp[:iid], cur)
				tmp = append(tmp ,q...)

				//if k == 0{
				//	if cur ==target || (cur < target&& cur > near) {
				//		near = cur
				//	}
				//	tmp = append(tmp, cur)
				//}
			}

		}
	}
	return near
}

func q(matrix [][]int, k int) int {
	row := len(matrix)
	col := len(matrix[0])
	near := -1000000
	for left := 0; left < col ; left ++{
	// 以left为左边界，每行的总和
		_sum :=make([]int, row)
	//for right in range(left, col):
		for right :=left ;right <col; right ++ {

			for j := 0; j < row; j++ {
				_sum[j] += matrix[j][right]
			}
			// 在left，right为边界下的矩阵，求不超过K的最大数值和
			tmp := []int{0}
			cur := 0
			for _, tmpp := range _sum {
				cur += tmpp

				//# 二分法
				idx := find_first_ge_idx(tmp, cur-k)
				if idx != len(tmp) {
					near = max(near, cur-tmp[idx])
				}
				iid := find_first_ge_idx(tmp, cur)
				q := []int{}

				q= append(q, tmp[iid:]...)
				ee := []int{}
				ee = append(ee,tmp[:iid]...)
				ee = append(ee, cur)
				tmp = append(ee, q...)
			}
		}
		}

	return near
}

func qeqw(a int, aa int) int{

	caa := "asas"
	log.Println(caa)
	return 23
}

func m(a []int, b[]int){
	 //q := map[[2]int]bool{}

}
var ori [1000001]int
var record [1000001]int

var energy [1000001]int
var counter [1000001]int

//}
func p(){
	var n int
	var k int
	var target int
	//var n,k int
	fmt.Scan(&n)
	fmt.Scan(&k)
	for i := 0;i < n; i ++{
		fmt.Scan(&record[i])
	}
	idx := -1
	left := 0
	min_l := 1000000000
	m_l := 0
	m_r := 0
	for ;left < n &&idx < n;{
		if target == k {
			//if counter[record[left]] > 1 {
			if idx - left +1 < min_l{
				min_l = idx - left + 1
				m_l = left
				m_r = idx
			}
			counter[record[left]] --

			//}else {
			//
			//}
			if counter[record[left]] == 0 {
				target --
			}
			left ++
		}else{
				idx ++
			counter[record[idx]] ++
			if counter[record[idx]] == 1{
				target ++
			}
			//idx++
		}
	}
	fmt.Println(m_l + 1, m_r + 1)
}

func ini(){
	var n int
	//var k int
	fmt.Scan(&n)
	//fmt.Scan(&k)
	for i := 0;i < n; i ++{
		fmt.Scan(&ori[i])
		fmt.Scan(&energy[i])
	}
	R := -1
	L := 0
	for i :=0; i < n; i ++{
		//if record[L] == i - k{
		//	L ++
		//}
		for ;R >= L &&ori[i] >ori[record[R]];R--{
			counter[i]	+= energy[record[R]]
		}
		tmp := energy[i]
		for ;R >= L &&ori[i] ==ori[record[R]];R--{
			tmp += energy[i]
		}
		R ++
		record[R] = i
		if R != 0  {
			counter[record[R - 1]] += tmp
		}
	}
	m := -1
	for i :=0; i <n;i ++{
		if counter[i] > m{
			m = counter[i]
		}
	}
	fmt.Println(m)
}
type S struct {
	Idx int
	Time int

}
type intSlice []S

func (p intSlice) Len() int           { return len(p) }
func (p intSlice) Less(i, j int) bool { return p[i].Time > p[j].Time }
func (p intSlice) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }

var roww [1000]int
var coll [1000]int
func inii(){
	var m,n,k,l,d int
	//var k int
	row := make(intSlice, 10000)
	col := make(intSlice, 10000)
	fmt.Scan(&m, &n, &k, &l,&d)
	//fmt.Scan(&k)
	for i := 0;i < d; i ++{
		var x1,y1,x2,y2 int
		fmt.Scan(&x1,&y1,&x2,&y2)
		if x1 == x2 {
			if y1 > y2 {
				y1,y2 = y2,y1
			}
			col[y1].Idx = y1
			col[y1].Time ++
		}else{
				if x1 > x2{
					x1,x2 = x2,x1
				}
				row[x1].Idx = x1
			row[x1].Time ++
		}
		//fmt.Scan(&energy[i])
	}
	//row = row[:m+1]
	//col = col[:n + 1]
	sort.Sort(row)
	sort.Sort(col)
	row = row[:k+1]
	col = col[:l + 1]
	sort.Sort(row)
	sort.Sort(col)
	for i := 0;i < k-1;i ++ {
		fmt.Print(row[i].Idx," ")
	}
	fmt.Print(row[k -1 ].Idx,"\n")
	for i := 0;i < l-1;i ++ {
		fmt.Print(col[i].Idx," ")
	}
	fmt.Print(col[l -1 ].Idx,"\n")

}

func next_per(){
	var n int
	var m int
	fmt.Scan(&n,&m)
	a :=make([]int, n)
	for i:=0;i <n;i++{
		fmt.Scan(&a[i])
	}
	for ;m > 0;m--{
		i := 0
		for i = n-2;i >=0;i --{
			if a[i] < a[i + 1]{
				break
			}

		}
		//t := a[i+1]
		j := 0
		for j = i + 1;j < n;j ++{
			if a[j] <= a[i]{
					break
			}
		}
		a[i],a[j-1] = a[j-1],a[i]
		sort.Ints(a[i + 1:])

	}
	fmt.Println(a)

}
var s string
var n,ans,length,carry int
//var ans int
//var length int
//var carry int
//func max(x,y int)int{
//	if x > y{
//		return x
//	}
//	return y
//}
func maxf(x, y int)int{
	if x > y {
		return x
	}
	return y
}
func get(k int)int{
	var x int
	var t int = 1
	i := k
	for ;i  >= 0; i -- {
		if x + maxf(int(1), (int)(s[i]-'0')) * int(t) >=n{
			break
		}
		x += int(s[i]-'0') * t
		t *= 10
	}
	for ;s[i+ 1] == '0'&& i < k-1;i ++{

	}
	ans += x * carry
	return i
}
func qq(){

	carry = 1
	fmt.Scan(&n, &s)
	i := len(s) - 1
	for ;i >=0;{
		i = get(i)
		carry *=n
	}
	fmt.Println( ans)

}

func main(){
	//a := [][]int{{28,4,-19,18,-7,-10,27,19,1,16,0,10,-17,11,11,27,-1,10,12,-1},
	//	{-2,-19,17,4,25,-20,4,3,4,28,-10,7,16,-14,-3,-19,6,17,-4,-7},
	//	{2,8,18,-17,-2,10,-6,-5,11,10,22,-6,19,-16,6,-4,18,5,22,-17},
	//	{-14,-7,-20,13,-19,-20,-15,21,-11,-10,-8,-9,10,13,6,-10,15,9,-15,-2},
	//	{-18,26,12,8,2,16,-17,12,0,-5,9,-3,-12,-11,3,-6,-18,16,-7,-14},
	//	{5,29,25,22,11,-3,-2,-15,4,13,-17,-2,0,-2,20,10,-18,6,25,-20},
	//	{5,-7,8,5,15,22,8,-5,22,-18,-5,-14,23,2,-8,12,-16,-18,12,-12},
	//	{27,18,4,11,-3,12,-4,-8,-3,25,-9,24,-14,5,11,-9,-17,0,25,-15},
	//	{26,-7,18,4,4,18,-17,9,-19,-9,-19,-8,-4,-13,10,-11,6,-16,-12,12},
	//	{28,22,7,11,-6,13,8,22,7,-14,17,14,10,29,16,9,-3,18,-9,10},
	//	{27,19,-10,-9,1,3,14,1,7,3,-3,16,-2,9,14,-7,-19,-5,23,19},
	//	{-17,7,-20,8,-5,-6,-2,25,29,16,23,4,4,27,16,17,9,20,-6,22},
	//	{2,9,-13,1,-18,25,4,7,25,26,-4,8,-19,18,6,-7,-5,7,21,-8},
	//	{-2,11,1,29,6,-16,-8,3,7,11,10,-2,-1,-20,20,4,19,5,29,-7},
	//	{29,-12,-3,17,6,19,23,12,-19,13,19,5,27,22,-17,27,10,-12,12,23},
	//	{24,16,4,25,15,13,24,-19,1,-7,-19,13,-13,14,13,26,9,18,-9,-18},
	//	{-17,4,-18,-18,-19,3,-13,12,23,-17,-10,-20,14,2,18,21,-12,27,-3,4},
	//	{27,13,12,14,16,-9,-2,-15,-20,8,-2,24,18,15,26,21,27,17,-15,-3},
	//	{25,-8,17,-10,-16,13,26,-11,-15,6,-5,-13,23,2,24,-4,5,8,-15,-1},
	//	{15,-12,18,5,-3,7,5,11,-4,-13,28,20,0,-4,-13,-5,-13,-8,-16,3}}

	//log.Println(find_last_le_idx(a, 3))
	//log.Println(q(a, -123))

	//aa := []int{2,3,1,3,4,6,1,2}
	//mm(aa, 1)
	//ini()
//inii()
	//next_per()
	qq()
}

package main

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

func solve() {
	n := readInt64()
	k := readString()
	values := make([]int, 0)
	for len(k) > 0 {
		var maxValue int
		var maxIndex int
		for i := len(k) - 1; i >= 0; i-- {
			value, err := strconv.ParseInt(k[i:], 10, 32)
			if err == nil {
				if value <= n {
					maxValue = int(value)
					maxIndex = i
				}
			} else {
				panic(err)
			}
		}
		if maxIndex+1 < len(k) {
			for maxIndex < len(k) && k[maxIndex] == '0' {
				maxIndex++
			}
		}
		k = k[:maxIndex]
		values = append(values, maxValue)
	}
	var res int64
	for i := len(values) - 1; i >= 0; i-- {
		res *= n
		res += int64(values[i])
	}
	fmt.Println(res)
}

var scanner *bufio.Scanner

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

// IO

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

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

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

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

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

package main

import (
	"fmt"
	"log"
	"sort"
)

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}
func find_last_le_idx(a []int, target int )int {
	//if not exist rturn -1

	s := 0
	e := len(a)
	for ;s < e;{
		mid := s +(e- s)/2
		if a[mid ] <= target{
			s = mid + 1
		}else {
			e = mid
		}
	}
	return s - 1
}

func find_first_ge_idx(a []int, target int )int {
	//if not exist rturn -1

	s := 0
	e := len(a)
	for ;s < e;{
		mid := s +(e- s)/2
		if a[mid ] < target{
			s = mid + 1
		}else {
			e = mid
		}
	}

	return s
}

func maxSumSubmatrix(a [][]int, target int) int {
	row := len(a)
	if row == 0{
		return 0
	}
	col := len(a[0])

	pre_sum := make([][]int, row)
	for i := range pre_sum{
		pre_sum[i] = make([]int ,col)
	}

	for i := 0;i < row; i ++{
		for j :=0;j < col; j ++{
			if j == 0 {
				pre_sum[i][j] = a[i][j]
			}else {
				pre_sum[i][j] = pre_sum[i][j-1] + a[i][j]
			}
		}
	}

	near := -100000000
	for i := 0; i < col ; i ++{
		for j :=i ;j <col; j ++{
			tmp := []int {0}
			cur := 0
			for k := 0;k < row; k++{

				if i == j {
					cur += a[k][i]
				}else if i == 0{
					cur += pre_sum[k][j]
				}else {
					cur += pre_sum[k][j] - pre_sum[k][i-1]
				}
				idx := find_first_ge_idx(tmp, cur  - target)
				if idx != len(tmp){
					near = max(near, cur -tmp[idx] )
				}
				iid := find_first_ge_idx(tmp, cur )
				q := tmp[iid:]
				tmp = append(tmp[:iid], cur)
				tmp = append(tmp ,q...)

				//if k == 0{
				//	if cur ==target || (cur < target&& cur > near) {
				//		near = cur
				//	}
				//	tmp = append(tmp, cur)
				//}
			}

		}
	}
	return near
}

func q(matrix [][]int, k int) int {
	row := len(matrix)
	col := len(matrix[0])
	near := -1000000
	for left := 0; left < col ; left ++{
	// 以left为左边界，每行的总和
		_sum :=make([]int, row)
	//for right in range(left, col):
		for right :=left ;right <col; right ++ {

			for j := 0; j < row; j++ {
				_sum[j] += matrix[j][right]
			}
			// 在left，right为边界下的矩阵，求不超过K的最大数值和
			tmp := []int{0}
			cur := 0
			for _, tmpp := range _sum {
				cur += tmpp

				//# 二分法
				idx := find_first_ge_idx(tmp, cur-k)
				if idx != len(tmp) {
					near = max(near, cur-tmp[idx])
				}
				iid := find_first_ge_idx(tmp, cur)
				q := []int{}

				q= append(q, tmp[iid:]...)
				ee := []int{}
				ee = append(ee,tmp[:iid]...)
				ee = append(ee, cur)
				tmp = append(ee, q...)
			}
		}
		}

	return near
}

func qeqw(a int, aa int) int{

	caa := "asas"
	log.Println(caa)
	return 23
}

func m(a []int, b[]int){
	 //q := map[[2]int]bool{}

}
var ori [1000001]int
var record [1000001]int

var energy [1000001]int
var counter [1000001]int

//}
func p(){
	var n int
	var k int
	var target int
	//var n,k int
	fmt.Scan(&n)
	fmt.Scan(&k)
	for i := 0;i < n; i ++{
		fmt.Scan(&record[i])
	}
	idx := -1
	left := 0
	min_l := 1000000000
	m_l := 0
	m_r := 0
	for ;left < n &&idx < n;{
		if target == k {
			//if counter[record[left]] > 1 {
			if idx - left +1 < min_l{
				min_l = idx - left + 1
				m_l = left
				m_r = idx
			}
			counter[record[left]] --

			//}else {
			//
			//}
			if counter[record[left]] == 0 {
				target --
			}
			left ++
		}else{
				idx ++
			counter[record[idx]] ++
			if counter[record[idx]] == 1{
				target ++
			}
			//idx++
		}
	}
	fmt.Println(m_l + 1, m_r + 1)
}

func ini(){
	var n int
	//var k int
	fmt.Scan(&n)
	//fmt.Scan(&k)
	for i := 0;i < n; i ++{
		fmt.Scan(&ori[i])
		fmt.Scan(&energy[i])
	}
	R := -1
	L := 0
	for i :=0; i < n; i ++{
		//if record[L] == i - k{
		//	L ++
		//}
		for ;R >= L &&ori[i] >ori[record[R]];R--{
			counter[i]	+= energy[record[R]]
		}
		tmp := energy[i]
		for ;R >= L &&ori[i] ==ori[record[R]];R--{
			tmp += energy[i]
		}
		R ++
		record[R] = i
		if R != 0  {
			counter[record[R - 1]] += tmp
		}
	}
	m := -1
	for i :=0; i <n;i ++{
		if counter[i] > m{
			m = counter[i]
		}
	}
	fmt.Println(m)
}
type S struct {
	Idx int
	Time int

}
type intSlice []S

func (p intSlice) Len() int           { return len(p) }
func (p intSlice) Less(i, j int) bool { return p[i].Time > p[j].Time }
func (p intSlice) Swap(i, j int)      { p[i], p[j] = p[j], p[i] }

var roww [1000]int
var coll [1000]int
func inii(){
	var m,n,k,l,d int
	//var k int
	row := make(intSlice, 10000)
	col := make(intSlice, 10000)
	fmt.Scan(&m, &n, &k, &l,&d)
	//fmt.Scan(&k)
	for i := 0;i < d; i ++{
		var x1,y1,x2,y2 int
		fmt.Scan(&x1,&y1,&x2,&y2)
		if x1 == x2 {
			if y1 > y2 {
				y1,y2 = y2,y1
			}
			col[y1].Idx = y1
			col[y1].Time ++
		}else{
				if x1 > x2{
					x1,x2 = x2,x1
				}
				row[x1].Idx = x1
			row[x1].Time ++
		}
		//fmt.Scan(&energy[i])
	}
	//row = row[:m+1]
	//col = col[:n + 1]
	sort.Sort(row)
	sort.Sort(col)
	row = row[:k+1]
	col = col[:l + 1]
	sort.Sort(row)
	sort.Sort(col)
	for i := 0;i < k-1;i ++ {
		fmt.Print(row[i].Idx," ")
	}
	fmt.Print(row[k -1 ].Idx,"\n")
	for i := 0;i < l-1;i ++ {
		fmt.Print(col[i].Idx," ")
	}
	fmt.Print(col[l -1 ].Idx,"\n")

}

func next_per(){
	var n int
	var m int
	fmt.Scan(&n,&m)
	a :=make([]int, n)
	for i:=0;i <n;i++{
		fmt.Scan(&a[i])
	}
	for ;m > 0;m--{
		i := 0
		for i = n-2;i >=0;i --{
			if a[i] < a[i + 1]{
				break
			}

		}
		//t := a[i+1]
		j := 0
		for j = i + 1;j < n;j ++{
			if a[j] <= a[i]{
					break
			}
		}
		a[i],a[j-1] = a[j-1],a[i]
		sort.Ints(a[i + 1:])

	}
	fmt.Println(a)

}
var s string
var n,ans,length,carry float64
//var ans int
//var length int
//var carry int
//func max(x,y int)int{
//	if x > y{
//		return x
//	}
//	return y
//}
func maxf(x, y float64)float64{
	if x > y {
		return x
	}
	return y
}
func get(k int)int{
	var x float64
	var t float64 = 1
	i := k
	for ;i  >= 0; i -- {
		if x + maxf(float64(1), (float64)(s[i]-'0')) * float64(t) >=n{
			break
		}
		x += float64(s[i]-'0') * t
		t *= 10
	}
	for ;s[i+ 1] == '0'&& i < k-1;i ++{

	}
	ans += x * carry
	return i
}
func qq(){

	carry = 1
	fmt.Scan(&n, &s)
	i := len(s) - 1
	for ;i >=0;{
		i = get(i)
		carry *=n
	}
	fmt.Println(ans)

}

func main(){
	//a := [][]int{{28,4,-19,18,-7,-10,27,19,1,16,0,10,-17,11,11,27,-1,10,12,-1},
	//	{-2,-19,17,4,25,-20,4,3,4,28,-10,7,16,-14,-3,-19,6,17,-4,-7},
	//	{2,8,18,-17,-2,10,-6,-5,11,10,22,-6,19,-16,6,-4,18,5,22,-17},
	//	{-14,-7,-20,13,-19,-20,-15,21,-11,-10,-8,-9,10,13,6,-10,15,9,-15,-2},
	//	{-18,26,12,8,2,16,-17,12,0,-5,9,-3,-12,-11,3,-6,-18,16,-7,-14},
	//	{5,29,25,22,11,-3,-2,-15,4,13,-17,-2,0,-2,20,10,-18,6,25,-20},
	//	{5,-7,8,5,15,22,8,-5,22,-18,-5,-14,23,2,-8,12,-16,-18,12,-12},
	//	{27,18,4,11,-3,12,-4,-8,-3,25,-9,24,-14,5,11,-9,-17,0,25,-15},
	//	{26,-7,18,4,4,18,-17,9,-19,-9,-19,-8,-4,-13,10,-11,6,-16,-12,12},
	//	{28,22,7,11,-6,13,8,22,7,-14,17,14,10,29,16,9,-3,18,-9,10},
	//	{27,19,-10,-9,1,3,14,1,7,3,-3,16,-2,9,14,-7,-19,-5,23,19},
	//	{-17,7,-20,8,-5,-6,-2,25,29,16,23,4,4,27,16,17,9,20,-6,22},
	//	{2,9,-13,1,-18,25,4,7,25,26,-4,8,-19,18,6,-7,-5,7,21,-8},
	//	{-2,11,1,29,6,-16,-8,3,7,11,10,-2,-1,-20,20,4,19,5,29,-7},
	//	{29,-12,-3,17,6,19,23,12,-19,13,19,5,27,22,-17,27,10,-12,12,23},
	//	{24,16,4,25,15,13,24,-19,1,-7,-19,13,-13,14,13,26,9,18,-9,-18},
	//	{-17,4,-18,-18,-19,3,-13,12,23,-17,-10,-20,14,2,18,21,-12,27,-3,4},
	//	{27,13,12,14,16,-9,-2,-15,-20,8,-2,24,18,15,26,21,27,17,-15,-3},
	//	{25,-8,17,-10,-16,13,26,-11,-15,6,-5,-13,23,2,24,-4,5,8,-15,-1},
	//	{15,-12,18,5,-3,7,5,11,-4,-13,28,20,0,-4,-13,-5,-13,-8,-16,3}}

	//log.Println(find_last_le_idx(a, 3))
	//log.Println(q(a, -123))

	//aa := []int{2,3,1,3,4,6,1,2}
	//mm(aa, 1)
	//ini()
//inii()
	//next_per()
	qq()
}


The final round of Bayan Programming Contest will be held in Tehran, and the participants will be carried around with a yellow bus. The bus has 34 passenger seats: 4 seats in the last row and 3 seats in remaining rows.   The event coordinator has a list of k participants who should be picked up at the airport. When a participant gets on the bus, he will sit in the last row with an empty seat. If there is more than one empty seat in that row, he will take the leftmost one. In order to keep track of the people who are on the bus, the event coordinator needs a figure showing which seats are going to be taken by k participants. Your task is to draw the figure representing occupied seats.

The only line of input contains integer k, (0 ≤ k ≤ 34), denoting the number of participants.

Print the figure of a bus with k passengers as described in sample tests. Character '#' denotes an empty seat, while 'O' denotes a taken seat. 'D' is the bus driver and other characters in the output are for the purpose of beautifying the figure. Strictly follow the sample test cases output format. Print exactly six lines. Do not output extra space or other characters.

package main

import (
	"fmt"
	"strings"
)

func main() {
	var k int
	fmt.Scanf("%d", &k)
	rows := []int{0,0,0,0}
	if k <= 4 {
		for i := 0; i < k; i++ {
			rows[i] = 1
		}
	} else {
		rows[2] = 1
		q := (k - 4) / 3
		r := (k - 4) % 3
		rows[0], rows[1], rows[3] = q + 1, q + 1, q + 1
		if r >= 1 {
			rows[0]++
		}
		if r >= 2 {
			rows[1]++
		}
	}
	fmt.Println("+------------------------+")
	fmt.Printf("|%s%s|D|)\n", strings.Repeat("O.", rows[0]), strings.Repeat("#.", 11 - rows[0]))
	fmt.Printf("|%s%s|.|\n", strings.Repeat("O.", rows[1]), strings.Repeat("#.", 11 - rows[1]))
	if rows[2] > 0 {
		fmt.Printf("|%s%s..|\n", strings.Repeat("O.", rows[2]), strings.Repeat("..", 11 - rows[2]))
	} else {
		fmt.Printf("|%s%s..|\n", strings.Repeat("#.", 1), strings.Repeat("..", 10))
	}
	fmt.Printf("|%s%s|.|)\n", strings.Repeat("O.", rows[3]), strings.Repeat("#.", 11 - rows[3]))
	fmt.Println("+------------------------+")
}

package main

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

var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func ReadInt32() int {
    scanner.Scan()
    ans, _ := strconv.Atoi(scanner.Text())
    return ans
}

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

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

    n := ReadInt32()
    s := make([]string, 4)

    s[1] = "|#.#.#.#.#.#.#.#.#.#.#.|D|)\n"
    s[2] = "|#.#.#.#.#.#.#.#.#.#.#.|.|\n"
    s[0] = "|#.#.#.#.#.#.#.#.#.#.#.|.|)\n"

    if n >= 3 {
        s[3] = "|O.......................|\n"
        n--
    } else {
        s[3] = "|#.......................|\n"
    }

    for i := 1; i <= n; i++ {
        s[i%3] = strings.Replace(s[i%3], "#", "O", 1)
    }

    writer.WriteString("+------------------------+\n")
    writer.WriteString(s[1])
    writer.WriteString(s[2])
    writer.WriteString(s[3])
    writer.WriteString(s[0])
    writer.WriteString("+------------------------+\n")
}


Nothing is eternal in the world, Kostya understood it on the 7-th of January when he saw partially dead four-color garland.Now he has a goal to replace dead light bulbs, however he doesn't know how many light bulbs for each color are required. It is guaranteed that for each of four colors at least one light is working.It is known that the garland contains light bulbs of four colors: red, blue, yellow and green. The garland is made as follows: if you take any four consecutive light bulbs then there will not be light bulbs with the same color among them. For example, the garland can look like "RYBGRYBGRY", "YBGRYBGRYBG", "BGRYB", but can not look like "BGRYG", "YBGRYBYGR" or "BGYBGY". Letters denote colors: 'R' — red, 'B' — blue, 'Y' — yellow, 'G' — green.Using the information that for each color at least one light bulb still works count the number of dead light bulbs of each four colors.

The first and the only line contains the string s (4 ≤ |s| ≤ 100), which describes the garland, the i-th symbol of which describes the color of the i-th light bulb in the order from the beginning of garland:    'R' — the light bulb is red,  'B' — the light bulb is blue,  'Y' — the light bulb is yellow,  'G' — the light bulb is green,  '!' — the light bulb is dead.  The string s can not contain other symbols except those five which were described.  It is guaranteed that in the given string at least once there is each of four letters 'R', 'B', 'Y' and 'G'.  It is guaranteed that the string s is correct garland with some blown light bulbs, it means that for example the line "GRBY!!!B" can not be in the input data.

In the only line print four integers kr, kb, ky, kg — the number of dead light bulbs of red, blue, yellow and green colors accordingly.

NoteIn the first example there are no dead light bulbs.In the second example it is obvious that one blue bulb is blown, because it could not be light bulbs of other colors on its place according to the statements.

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	re := regexp.MustCompile(`\r?\n`)
	if garland, err := reader.ReadString('\n'); err != nil {
		if err != io.EOF {
			return
		}
	} else {
		garland = re.ReplaceAllString(garland, "")

		needs := make([]int, 4)
		color_idx := make([]int, 4) // Index of RBYG

		for i := 0; i < len(garland); i++ {
			k := i % 4
			if 'R' == garland[i] {
				color_idx[0] = k
			} else if 'B' == garland[i] {
				color_idx[1] = k
			} else if 'Y' == garland[i] {
				color_idx[2] = k
			} else if 'G' == garland[i] {
				color_idx[3] = k
			} else if '!' == garland[i] {
				needs[k]++
			} else {
				fmt.Println("Error")
				return
			}
		}

		for i := 0; i < 4; i++ {
			fmt.Printf("%d ", needs[color_idx[i]])
		}
		fmt.Println()
	}
}

package main

import (
	"fmt"
	)

func main() {
	var input string
	fmt.Scanln(&input)
	d := map[string]int{
		"R":0,
		"B":1,
		"Y":2,
		"G":3,
	}
	cnt := []int{0, 0, 0, 0}
	mod := []int{-1, -1, -1, -1}
	for i, s := range(input) {
		if string(s) == "!" {
			continue
		}
		x := d[string(s)]
		cnt[x]++
		mod[x] = i % 4
	}
	for i := 0; i < 4; i++ {
		val := len(input) / 4
		if len(input) % 4 > mod[i] {
			val++
		}
		fmt.Printf("%d ", val - cnt[i])
	}
}

package main

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

func solve() {
	str1 := readString()
	a := []byte(str1)
	res := make([]int, 4)
	dfs(a, 0, res)
	for i := 0; i < len(res); i++ {
		if i > 0 {
			fmt.Printf(" %d", res[i])
		} else {
			fmt.Printf("%d", res[i])
		}
	}
	fmt.Println()
}

func dfs(a []byte, pos int, res []int) bool {
	if pos == len(a) {
		return true
	}
	if a[pos] != '!' {
		if dfs(a, pos+1, res) {
			return true
		}
	} else {
		for j, v := range "RBYG" {
			ch := byte(v)
			ok := true
			for j := 0; j < 3; j++ {
				k := pos - j - 1
				if k >= 0 && a[k] == ch {
					ok = false
					break
				}
				k = pos + j + 1
				if k < len(a) && a[k] == ch {
					ok = false
					break
				}
			}
			if ok {
				a[pos] = ch
				if dfs(a, pos+1, res) {
					res[j]++
					return true
				}
				a[pos] = '!'
			}
		}
	}
	return false
}

var scanner *bufio.Scanner

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

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

// IO

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

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

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

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

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

package main
import (
	"fmt"
)

func main() {
	var bulbs string
	fmt.Scanln(&bulbs)

	r, b, y, g := 0, 0, 0, 0

	len_bulbs := len(bulbs)

	for i := 0; i < len_bulbs; i++ {
		if bulbs[i] == '!' {
			for j := i % 4; j < len_bulbs; j = j + 4 {
				c := bulbs[j]
				if c == 'R' {
					r++
					break
				} else if c == 'B' {
					b++
					break
				} else if c == 'Y' {
					y++
					break
				} else if c == 'G' {
					g++
					break
				}
			}
		}
	}

	fmt.Println(r, b, y, g)
}

package main

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

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}

	S := io.NextLine()

	dead := make([]int, 4)
	index := make([]int, 256)
	for i, c := range S {
		if c == '!' {
			dead[i % 4]++
		} else {
			index[c] = i % 4
		}
	}
	io.Printf("%d %d %d %d\n", dead[index['R']], dead[index['B']], dead[index['Y']], dead[index['G']])

	io.FlushOutput()
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if (c == '-') {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if (c == '-') {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

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

package main

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

func main() {
	sc := NewScanner()
	S := sc.NextLine()
	color := map[int]rune{}

	for i, v := range S {
		if v == '!' {
			continue
		}
		color[i % 4] = v
	}
	ans := map[rune]int{}

	for i, v := range S {
		if v == '!' {
			ans[color[i % 4]]++
		}
	}
	fmt.Println(ans['R'], ans['B'], ans['Y'], ans['G'])

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r:rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf) + 1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf) + 1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

package main
import (
	"fmt"
)

func main() {
	var bulbs string
	fmt.Scanln(&bulbs)

	r, b, y, g := 0, 0, 0, 0

	len_bulbs := len(bulbs)

	for i := 0; i < len_bulbs; i++ {
		if bulbs[i] == '!' {
			for j := i % 4; j < len_bulbs; j = j + 4 {
				switch bulbs[j] {
					case 'R':
						r++
						break
					case 'B':
						b++
						break
					case 'Y':
						y++
						break
					case 'G':
						g++
						break
				}
			}
		}
	}

	fmt.Println(r, b, y, g)
}


You are given an array a consisting of n integers, and additionally an integer m. You have to choose some sequence of indices b1, b2, ..., bk (1 ≤ b1 < b2 < ... < bk ≤ n) in such a way that the value of  is maximized. Chosen sequence can be empty.Print the maximum possible value of .

The first line contains two integers n and m (1 ≤ n ≤ 35, 1 ≤ m ≤ 109). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109).

NoteIn the first example you can choose a sequence b = {1, 2}, so the sum  is equal to 7 (and that's 3 after taking it modulo 4).In the second example you can choose a sequence b = {3}.

package main

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

// github.com/EndlessCheng/codeforces-go
func CF888E(_r io.Reader, out io.Writer) {
	max := func(a, b int) int {
		if a > b {
			return a
		}
		return b
	}
	in := bufio.NewReader(_r)
	var n, m, ans int
	Fscan(in, &n, &m)
	a := make([]int64, n)
	for i := range a {
		Fscan(in, &a[i])
	}

	b := a[:(n+1)/2]
	f := func(i int) int {
		s := int64(0)
		for j, v := range b {
			if i>>j&1 > 0 {
				s += v
			}
		}
		return int(s % int64(m))
	}
	x := []int{}
	for i := 0; i < 1<<len(b); i++ {
		s := f(i)
		ans = max(ans, s)
		x = append(x, s)
	}
	sort.Ints(x)
	b = a[(n+1)/2:]
	for i := 0; i < 1<<len(b); i++ {
		s := f(i)
		ans = max(ans, s)
		if j := sort.SearchInts(x, m-s); j > 0 {
			ans = max(ans, s+x[j-1])
		}
	}
	Fprint(out, ans)
}

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


The only difference between the easy and the hard versions is constraints.A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between them. For example, for the string "abaca" the following strings are subsequences: "abaca", "aba", "aaa", "a" and "" (empty string). But the following strings are not subsequences: "aabaca", "cb" and "bcaa".You are given a string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters.In one move you can take any subsequence $$$t$$$ of the given string and add it to the set $$$S$$$. The set $$$S$$$ can't contain duplicates. This move costs $$$n - |t|$$$, where $$$|t|$$$ is the length of the added subsequence (i.e. the price equals to the number of the deleted characters).Your task is to find out the minimum possible total cost to obtain a set $$$S$$$ of size $$$k$$$ or report that it is impossible to do so.

The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 100$$$) — the length of the string and the size of the set, correspondingly. The second line of the input contains a string $$$s$$$ consisting of $$$n$$$ lowercase Latin letters.

Print one integer — if it is impossible to obtain the set $$$S$$$ of size $$$k$$$, print -1. Otherwise, print the minimum possible total cost to do it.

NoteIn the first example we can generate $$$S$$$ = { "asdf", "asd", "adf", "asf", "sdf" }. The cost of the first element in $$$S$$$ is $$$0$$$ and the cost of the others is $$$1$$$. So the total cost of $$$S$$$ is $$$4$$$.

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1183H(_r io.Reader, _w io.Writer) {
	var n int
	var k, ans int64
	var s []byte
	Fscan(bufio.NewReader(_r), &n, &k, &s)
	prev := [26]int{}
	dp := make([][]int64, n+1)
	for i := range dp {
		dp[i] = make([]int64, n+1)
	}
	dp[0][0] = 1
	for i := 1; i <= n; i++ {
		c := s[i-1] - 'a'
		dp[i][0] = 1
		for j := 1; j <= i; j++ {
			dp[i][j] = dp[i-1][j] + dp[i-1][j-1]
			if p := prev[c]; p > 0 {
				dp[i][j] -= dp[p-1][j-1]
			}
		}
		prev[c] = i
	}
	k--
	for l := n - 1; l >= 0; l-- {
		cnt := dp[n][l]
		if cnt > k {
			ans += int64(n-l) * k
			k = 0
			break
		}
		k -= cnt
		ans += int64(n-l) * cnt
	}
	if k > 0 {
		ans = -1
	}
	Fprint(_w, ans)
}

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


You are given an array of positive integers a1, a2, ..., an × T of length n × T. We know that for any i > n it is true that ai = ai - n. Find the length of the longest non-decreasing sequence of the given array.

The first line contains two space-separated integers: n, T (1 ≤ n ≤ 100, 1 ≤ T ≤ 107). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 300).

Print a single number — the length of a sought sequence.

NoteThe array given in the sample looks like that: 3, 1, 4, 2, 3, 1, 4, 2, 3, 1, 4, 2. The elements in bold form the largest non-decreasing subsequence.

package main

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

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

	var n, t, d int
	Fscan(in, &n, &t)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	dp := []int{}
	for i := 0; i < 110 && t > 0; i++ {
		t--
		cur := len(dp)
		for _, v := range a {
			if p := sort.SearchInts(dp, v+1); p < len(dp) {
				dp[p] = v
			} else {
				dp = append(dp, v)
			}
		}
		d = len(dp) - cur
		cur = len(dp)
	}
	if t == 0 {
		Fprint(out, len(dp))
		return
	}
	Fprintln(out, len(dp)+t*d)
}

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

package main

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

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

	var n, t, d int
	Fscan(in, &n, &t)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	dp := []int{}
	for i := 0; i < n+10 && t > 0; i++ {
		t--
		cur := len(dp)
		for _, v := range a {
			if p := sort.SearchInts(dp, v+1); p < len(dp) {
				dp[p] = v
			} else {
				dp = append(dp, v)
			}
		}
		d = len(dp) - cur
		cur = len(dp)
	}
	if t == 0 {
		Fprint(out, len(dp))
		return
	}
	Fprintln(out, len(dp)+t*d)
}

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

package main

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

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

	var n, t, d int
	Fscan(in, &n, &t)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	dp := []int{}
	for i := 0; i < 310 && t > 0; i++ {
		t--
		cur := len(dp)
		for _, v := range a {
			if p := sort.SearchInts(dp, v+1); p < len(dp) {
				dp[p] = v
			} else {
				dp = append(dp, v)
			}
		}
		d = len(dp) - cur
		cur = len(dp)
	}
	if t == 0 {
		Fprint(out, len(dp))
		return
	}
	Fprintln(out, len(dp)+t*d)
}

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

package main

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

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

	var n, t int
	Fscan(in, &n, &t)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	dp := []int{}
	f := func() {
		for _, v := range a {
			if i := sort.SearchInts(dp, v+1); i < len(dp) {
				dp[i] = v
			} else {
				dp = append(dp, v)
			}
		}
	}
	f()
	if t == 1 {
		Fprint(out, len(dp))
		return
	}
	f()
	Fprint(out, len(dp)+t-2)
}

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

package main

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

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

	var n, t, d int
	Fscan(in, &n, &t)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	dp := []int{}
	f := func() {
		for _, v := range a {
			if i := sort.SearchInts(dp, v+1); i < len(dp) {
				dp[i] = v
			} else {
				dp = append(dp, v)
			}
		}
	}
	for i := 0; i < 5 && t > 0; i++ {
		t--
		cur := len(dp)
		f()
		d = len(dp) - cur
		cur = len(dp)
	}
	if t == 0 {
		Fprint(out, len(dp))
		return
	}
	Fprintln(out, len(dp)+t*d)
}

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


Given 2 integers $$$u$$$ and $$$v$$$, find the shortest array such that bitwise-xor of its elements is $$$u$$$, and the sum of its elements is $$$v$$$.

The only line contains 2 integers $$$u$$$ and $$$v$$$ $$$(0 \le u,v \le 10^{18})$$$.

If there's no array that satisfies the condition, print "-1". Otherwise: The first line should contain one integer, $$$n$$$, representing the length of the desired array. The next line should contain $$$n$$$ positive integers, the array itself. If there are multiple possible answers, print any.

NoteIn the first sample, $$$3\oplus 1 = 2$$$ and $$$3 + 1 = 4$$$. There is no valid array of smaller length.Notice that in the fourth sample the array is empty.

package main

import "fmt"

func main() {
	var u, v uint64
	fmt.Scanf("%d %d", &u, &v)
	res, found := solve(u, v)
	if !found {
		fmt.Println(-1)
	} else {
		fmt.Println(len(res))
		for i := 0; i < len(res); i++ {
			fmt.Printf("%d ", res[i])
		}
	}
}

func solve(u uint64, v uint64) ([]uint64, bool) {
	if u > v || u&1 != v&1 {
		return nil, false
	}

	if u == 0 && v == 0 {
		return nil, true
	}

	if u == v {
		return []uint64{u}, true
	}

	x := (v - u) >> 1
	// u, x, x is an answer with length 3
	for i := 0; i < 63; i++ {
		if (x>>i)&1 == 1 {
			if (u>>i)&1 == 1 {
				// can' be true
				return []uint64{u, x, x}, true
			}
		}
	}

	return []uint64{u + x, x}, true
}

package main

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

var reader io.Reader
var scanner *bufio.Scanner

func Init(io io.Reader, max_token_size int) {
	reader = bufio.NewReader(io)
	scanner = bufio.NewScanner(reader)
	// max token size
	scanner.Split(bufio.ScanWords)
	scanner.Buffer([]byte{}, max_token_size)
}

func stderr(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
}

func die(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
	os.Exit(1)
}

func NextInt() int {
	bytes := NextBytes()
	i, err := Atoi(bytes)
	if err != nil {
		die(err)
	}
	return i
}
func NextInt64() int64 {
	bytes := NextBytes()
	i, err := Atoi64(bytes)
	if err != nil {
		die(err)
	}
	return i
}

func NextBytes() []byte {
	if !scanner.Scan() {
		die(scanner.Err())
	}
	bytes := scanner.Bytes()
	copied := make([]byte, len(bytes))
	copy(copied, bytes)
	return copied
}

func Atoi(b []byte) (int, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func Atoi64(b []byte) (int64, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	var n int64
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int64(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func ExtendByteArray(a []byte, size int) []byte {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]byte, size-len(a))...)
	}
}

func ExtendIntArray(a []int, size int) []int {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]int, size-len(a))...)
	}
}

func reverseInts(a []int) {
	for l, r := 0, len(a)-1; l < r; l, r = l+1, r-1 {
		a[l], a[r] = a[r], a[l]
	}
}

func unique(a []int) int {
	newLen := 0
	n := len(a)
	for i := 0; i < n; i++ {
		if newLen == 0 || a[i] != a[newLen-1] {
			a[newLen] = a[i]
			newLen++
		}
	}
	return newLen
}

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 main() {
	inf := os.Stdin
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	// inf, err := os.Open("a.in")
	// if err != nil {
	// 	die(err)
	// }
	// out, err := os.Create("a.out")
	// if err != nil {
	// 	die(err)
	// }
	// defer out.Close()
	Init(inf, 1000010)

	u := NextInt64()
	v := NextInt64()
	MAXP := 63
	MAXC := 100
	a := make([]int, MAXP)
	b := make([]int, MAXP)

	// u = 1000000000000000000
	// v = 1000000000000000000

	for i := 0; i < MAXP; i++ {
		a[i] = int(u & 1)
		b[i] = int(v & 1)
		u >>= 1
		v >>= 1
	}

	dp := make([][]int, MAXP)
	p := make([][][3]int, MAXP)
	for i := 0; i < MAXP; i++ {
		dp[i] = make([]int, MAXC)
		p[i] = make([][3]int, MAXC)
		for j := 0; j < MAXC; j++ {
			dp[i][j] = -1
		}
	}

	MAXINT := 1000000000

	var f func(i, carry int) int
	f = func(i, carry int) int {

		if i == -1 {
			if carry == 0 {
				return 0
			} else {
				return MAXINT
			}
		}

		if dp[i][carry] != -1 {
			return dp[i][carry]
		}

		res := MAXINT
		resk1, resc := -1, -1

		for k1 := 0; k1 < MAXC*2; k1++ {
			if (k1 >> 1) > carry {
				break
			}
			if (k1 & 1) != a[i] {
				continue
			}
			for ncarry := 0; ncarry < MAXC; ncarry++ {
				if ((k1 + ncarry) >> 1) > carry {
					break
				}
				if ((k1+ncarry)>>1) == carry && ((k1+ncarry)&1) == b[i] {
					t := max(k1, f(i-1, ncarry))
					if t < res {
						res = t
						resk1 = k1
						resc = ncarry
					}
				}
			}
		}
		dp[i][carry] = res
		p[i][carry][1] = resk1
		p[i][carry][2] = resc
		return res
	}

	res := f(MAXP-1, 0)
	if res == MAXINT {
		fmt.Fprintln(out, -1)
		return
	}

	fmt.Fprintln(out, res)

	ans := make([]int64, res)

	for i, carry, j := MAXP-1, 0, 0; i >= 0; i-- {
		ncarry := p[i][carry][2]
		k1 := p[i][carry][1]
		for k1 > 0 {
			ans[j] |= (int64(1) << uint(i))
			j++
			if j == res {
				j = 0
			}
			k1--
		}
		carry = ncarry
	}

	for i := 0; i < res; i++ {
		fmt.Fprint(out, ans[i], " ")
	}
}

package main

import (
	"bufio"
	"fmt"
)

func main() {
	var u,v int64
	fmt.Scanf("%d %d\n", &u, &v)
	if u > v {
		fmt.Println(-1)
		return
	}
	if u == v {
		if u == 0 {
			fmt.Println(0)
			return
		} else {
			fmt.Println(1)
			fmt.Println(u)
			return
		}
	}
	if (v - u) % 2 != 0 {
		fmt.Println(-1)
		return
	}
	c1 := u
	c2 := (v - u) / 2
	if (c1 + c2) ^ c2 == u {
		fmt.Println(2)
		fmt.Println(c2, c1+c2)
	} else {
		fmt.Println(3)
		fmt.Println(c2, c2, c1)
	}
}

func readLine(reader *bufio.Reader) []byte {
	result := make([]byte, 0)
	for {
		s, isPrefix, err := reader.ReadLine()
		if err != nil {
			fmt.Printf("error=%+v\n", err)
			break
		}
		result = append(result, s...)
		if !isPrefix {
			break
		}
	}
	return result
}

/*
URL:
https://codeforces.com/problemset/problem/1325/D
*/

package main

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

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

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

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

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

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

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

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

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

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

var (
	u, v int64
)

func main() {
	u, v = ReadInt64_2()

	if u == v && u == 0 {
		fmt.Println(0)
		return
	}

	if u == v {
		fmt.Println(1)
		fmt.Println(u)
		return
	}

	if u > v {
		fmt.Println(-1)
		return
	}

	if u%2 != v%2 {
		fmt.Println(-1)
		return
	}

	x := (v - u) / 2
	if x&u == 0 {
		fmt.Println(2)
		fmt.Println(u+x, x)
	} else {
		fmt.Println(3)
		fmt.Println(u, x, x)
	}
}

// NthBit returns nth bit value of an argument.
// n starts from 0.
func NthBit(num int64, nth int) int64 {
	return num >> uint(nth) & 1
}

// OnBit returns the integer that has nth ON bit.
// If an argument has nth ON bit, OnBit returns the argument.
func OnBit(num int64, nth int) int64 {
	return num | (1 << uint(nth))
}

// OffBit returns the integer that has nth OFF bit.
// If an argument has nth OFF bit, OffBit returns the argument.
func OffBit(num int64, nth int) int64 {
	return num & ^(1 << uint(nth))
}

// PopCount returns the number of ON bit of an argument.
func PopCount(num int64) int {
	res := 0

	for i := 0; i < 70; i++ {
		if ((num >> uint(i)) & 1) == 1 {
			res++
		}
	}

	return res
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	return res
}

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

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

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

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

	return string(res)
}

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

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

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

	return string(res)
}

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

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

package main

import (
	"fmt"
	"strconv"
)

func main() {
	var u, v int64
	var a [4]int64
	var times int
	var ll1 int64 = 1
	var out string
	fmt.Scan(&u)
	fmt.Scan(&v)
	//u = 0
	//v = 0

	if u > v || ((u ^ v) & 1) != 0 {
		fmt.Println(-1)
		return
	}

	for i := 0; i < 63; i++ {
		times = 0
		if (u & (ll1 << i)) != 0 {
			times += 1
			u ^= ll1 << i
			v -= ll1 << i
		}
		if (u & (ll1 << (i + 1))) != (v & (ll1 << (i + 1))) {
			times += 2
			v -= ll1 << (i + 1)
		}

		for j := 0; j < times; j++ {
			a[j] ^= ll1 << i
		}
	}

	for i := 0; i < 4; i++ {
		if a[i] == 0 {
			out = strconv.Itoa(i) + "\n" + out
			break
		}
		out += fmt.Sprintf("%v ", a[i])
	}
	fmt.Println(out)

	return
}

package main

import (
	"fmt"
)

func main() {
	var u, v uint64
	fmt.Scanf("%d %d", &u, &v)

	if !can(u, v) {
		fmt.Println("-1")
		return
	}

	if u == 0 && v == 0 {
		fmt.Println("0")
		return
	}

	d := v - u
	comp := d / 2

	if comp == 0 {
		fmt.Println("1")
		fmt.Println(u)
	} else if (u & comp) == 0 {
		fmt.Println("2")
		fmt.Printf("%d %d\n", u|comp, comp)
	} else {
		fmt.Println("3")
		fmt.Printf("%d %d %d\n", u, comp, comp)
	}
}

func can(u, v uint64) bool {
	if (u > v) || ((v-u)%2) == 1 {
		return false
	}
	return true
}

package main

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

// github.com/EndlessCheng/codeforces-go
func CF1325D(in io.Reader, out io.Writer) {
	var xor, sum int64
	Fscan(in, &xor, &sum)
	if xor > sum || (sum-xor)&1 > 0 {
		Fprint(out, -1)
	} else if xor == sum {
		if xor == 0 {
			Fprint(out, 0)
		} else {
			Fprint(out, "1\n", xor)
		}
	} else if and := (sum - xor) / 2; and&xor > 0 {
		Fprint(out, "3\n", xor, and, and)
	} else {
		Fprint(out, "2\n", xor|and, and)
	}
}

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

package main

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

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

type writerImpl struct {
    *bufio.Writer
}

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

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

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

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

type wordScannerImpl struct {
    *bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
    s := bufio.NewScanner(reader)
    s.Split(bufio.ScanWords)
    return &wordScannerImpl{Scanner: s}
}

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

func (impl *wordScannerImpl) NextInt64() int64 {
    impl.Scan()
    bb := impl.Bytes()
    i := int64(0)
    for _, b := range bb {
        i *= 10
        i += int64(b - '0')
    }
    return i
}

func (impl *wordScannerImpl) NextString() string {
    impl.Scan()
    return impl.Text()
}

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

func main() {
    defer writer.Flush()
    u, v := reader.NextInt64(), reader.NextInt64()
    if u > v {
        writer.Printf("-1\n")
        return
    }
    if u == v {
        if u == 0 {
            writer.Printf("0\n")
        } else {
            writer.Printf("1\n%d\n", u)
        }
        return
    }
    diff := v - u
    if diff % 2 == 1 {
        writer.Printf("-1\n")
        return
    }
    num := diff / 2
    if num & u == 0 {
        writer.Printf("2\n%d %d\n", u | num, num)
    } else {
        writer.Printf("3\n%d %d %d\n", u, num, num)
    }
}

package main

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

var reader io.Reader
var scanner *bufio.Scanner

func Init(io io.Reader, max_token_size int) {
	reader = bufio.NewReader(io)
	scanner = bufio.NewScanner(reader)
	// max token size
	scanner.Split(bufio.ScanWords)
	scanner.Buffer([]byte{}, max_token_size)
}

func stderr(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
}

func die(v ...interface{}) {
	fmt.Fprintln(os.Stderr, v...)
	os.Exit(1)
}

func NextInt() int {
	bytes := NextBytes()
	i, err := Atoi(bytes)
	if err != nil {
		die(err)
	}
	return i
}
func NextInt64() int64 {
	bytes := NextBytes()
	i, err := Atoi64(bytes)
	if err != nil {
		die(err)
	}
	return i
}

func NextBytes() []byte {
	if !scanner.Scan() {
		die(scanner.Err())
	}
	bytes := scanner.Bytes()
	copied := make([]byte, len(bytes))
	copy(copied, bytes)
	return copied
}

func Atoi(b []byte) (int, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	n := 0
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func Atoi64(b []byte) (int64, error) {
	neg := false
	if b[0] == '+' {
		b = b[1:]
	} else if b[0] == '-' {
		neg = true
		b = b[1:]
	}
	var n int64
	for _, v := range b {
		if v < '0' || v > '9' {
			return 0, strconv.ErrSyntax
		}
		n = n*10 + int64(v-'0')
	}
	if neg {
		return -n, nil
	}
	return n, nil
}

func ExtendByteArray(a []byte, size int) []byte {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]byte, size-len(a))...)
	}
}

func ExtendIntArray(a []int, size int) []int {
	if size <= len(a) {
		return a
	} else {
		return append(a, make([]int, size-len(a))...)
	}
}

func reverseInts(a []int) {
	for l, r := 0, len(a)-1; l < r; l, r = l+1, r-1 {
		a[l], a[r] = a[r], a[l]
	}
}

func unique(a []int) int {
	newLen := 0
	n := len(a)
	for i := 0; i < n; i++ {
		if newLen == 0 || a[i] != a[newLen-1] {
			a[newLen] = a[i]
			newLen++
		}
	}
	return newLen
}

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 main() {
	inf := os.Stdin
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	// inf, err := os.Open("a.in")
	// if err != nil {
	// 	die(err)
	// }
	// out, err := os.Create("a.out")
	// if err != nil {
	// 	die(err)
	// }
	// defer out.Close()
	Init(inf, 1000010)

	u := NextInt64()
	v := NextInt64()
	MAXP := 63
	MAXC := 4
	a := make([]int, MAXP)
	b := make([]int, MAXP)

	for i := 0; i < MAXP; i++ {
		a[i] = int(u & 1)
		b[i] = int(v & 1)
		u >>= 1
		v >>= 1
	}

	dp := make([][]int, MAXP)
	p := make([][][3]int, MAXP)
	for i := 0; i < MAXP; i++ {
		dp[i] = make([]int, MAXC)
		p[i] = make([][3]int, MAXC)
		for j := 0; j < MAXC; j++ {
			dp[i][j] = -1
		}
	}

	MAXINT := 1000000000

	var f func(i, carry int) int
	f = func(i, carry int) int {

		if i == -1 {
			if carry == 0 {
				return 0
			} else {
				return MAXINT
			}
		}

		if dp[i][carry] != -1 {
			return dp[i][carry]
		}

		res := MAXINT
		resk1, resc := -1, -1

		for k1 := 0; k1 < MAXP*2; k1++ {
			if (k1 >> 1) > carry {
				break
			}
			if (k1 & 1) != a[i] {
				continue
			}
			for ncarry := 0; ncarry < MAXC; ncarry++ {
				if ((k1 + ncarry) >> 1) > carry {
					break
				}
				if ((k1+ncarry)>>1) == carry && ((k1+ncarry)&1) == b[i] {
					t := max(k1, f(i-1, ncarry))
					if t < res {
						res = t
						resk1 = k1
						resc = ncarry
					}
				}
			}
		}
		dp[i][carry] = res
		p[i][carry][1] = resk1
		p[i][carry][2] = resc
		return res
	}

	res := f(MAXP-1, 0)
	if res == MAXINT {
		fmt.Fprintln(out, -1)
		return
	}

	fmt.Fprintln(out, res)

	ans := make([]int, res)

	for i, carry, j := MAXP-1, 0, 0; i >= 0; i-- {
		ncarry := p[i][carry][2]
		k1 := p[i][carry][1]
		for k1 > 0 {
			ans[j] |= (1 << uint(i))
			j++
			if j == res {
				j = 0
			}
			k1--
		}
		carry = ncarry
	}

	for i := 0; i < res; i++ {
		fmt.Fprint(out, ans[i], " ")
	}
}

package main

import (
	"bufio"
	"fmt"
)

func main() {
	var u,v int64
	fmt.Scanf("%d %d\n", &u, &v)
	if u > v {
		fmt.Println(-1)
		return
	}
	if u == v {
		if u == 0 {
			fmt.Println(0)
			return
		} else {
			fmt.Println(1)
			fmt.Println(u)
		}
	}
	if (v - u) % 2 != 0 {
		fmt.Println(-1)
		return
	}
	c1 := u
	c2 := (v - u) / 2
	if (c1 + c2) ^ c2 == u {
		fmt.Println(2)
		fmt.Println(c2, c1+c2)
	} else {
		fmt.Println(3)
		fmt.Println(c1, c2, c2)
	}
}

func readLine(reader *bufio.Reader) []byte {
	result := make([]byte, 0)
	for {
		s, isPrefix, err := reader.ReadLine()
		if err != nil {
			fmt.Printf("error=%+v\n", err)
			break
		}
		result = append(result, s...)
		if !isPrefix {
			break
		}
	}
	return result
}

package main

import (
	"fmt"
	"log"
)

func main() {
	var u, v int64
	var a []int64
	var ll1 int64 = 1
	fmt.Scan(&u)
	fmt.Scan(&v)

	if u > v || ((u ^ v) & 1) != 0 {
		fmt.Println(-1)
		return
	}
	if u == 0 && v == 0 {
		fmt.Println(0)
		return
	}

	for i := 0; i < 63; i++ {
		log.Printf("%v %v", u, v)
		if (u & (ll1 << i)) != 0 {
			a = append(a, ll1 << i)
			u ^= ll1 << i
			v -= ll1 << i
		}
		if (u & (ll1 << (i + 1))) != (v & (ll1 << (i + 1))) {
			a = append(a, ll1 << i)
			a = append(a, ll1 << i)
			v -= ll1 << (i + 1)
		}
	}

	fmt.Println(len(a))
	for i := 0; i < len(a); i++ {
		fmt.Printf("%v ", a[i])
	}

	return
}

package main

import (
	"fmt"
)

func main() {
	var u, v uint64
	fmt.Scanf("%d %d", &u, &v)

	if !can(u, v) {
		fmt.Println("-1")
		return
	}

	d := v - u
	comp := uint64(0)
	for i := 0; i <= 64; i++ {
		if d%2 == 1 {
			comp += uint64(1) << uint64(i-1)
		}
		d /= 2
	}

	if comp == 0 {
		fmt.Println("1")
		fmt.Println(u)
	} else if (u & comp) == 0 {
		fmt.Println("2")
		fmt.Printf("%d %d\n", u|comp, comp)
	} else {
		fmt.Println("3")
		fmt.Printf("%d %d %d\n", u, comp, comp)
	}
}

func can(u, v uint64) bool {
	if (u > v) || ((v-u)%2) == 1 {
		return false
	}
	return true
}


As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where k is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers.A well-known hipster Andrew adores everything funky and cool but unfortunately, he isn't good at maths. Given number n, help him define whether this number can be represented by a sum of two triangular numbers (not necessarily different)!

The first input line contains an integer n (1 ≤ n ≤ 109).

Print "YES" (without the quotes), if n can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes).

NoteIn the first sample number .In the second sample number 512 can not be represented as a sum of two triangular numbers.

package main

import "os"
import "bufio"
import "math"
import "strconv"

func main(){
	var n float64
	r := bufio.NewScanner(os.Stdin)
	r.Split(bufio.ScanWords)
	w := bufio.NewWriter(os.Stdout)
	r.Scan()
	n, _ = strconv.ParseFloat(r.Text(), 64)
	a := (-1+math.Sqrt(8*n-7))/2
	var b float64
	var j int64
	for i:=1; float64(i)<=a; i++ {
		b = (math.Sqrt(1+8*n-4*float64(i)-4*float64(i)*float64(i))-1)/2
		j = int64(b)
		if float64(j) == b && j != 0 {
			w.WriteString("YES\n")
			w.Flush()
			return
		}
	}
	w.WriteString("NO\n")
	w.Flush()
	return
}

package main

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

func scanInt(scanner *bufio.Scanner) int {
  scanner.Scan()
  x, _ := strconv.Atoi(scanner.Text())
  return x
}

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

  triangular := map[int64]bool{}
  k := int64(0)
  for {
    k++
    x := k*(k+1)/2
    if x > 1000000000 {
      break
    }
    triangular[x] = true
  }

  n := int64(scanInt(scanner))
  for x := range triangular {
    _, found := triangular[n-x]
    if found {
      writer.WriteString("YES\n")
      return
    }
  }
  writer.WriteString("NO\n")
}

// 192A-ahalim,dikai,eric
package main

import (
	"fmt"
	"math"
)

func main() {
	var i,n,m,k,l,p int64
	fmt.Scan(&n)
	if n==1 {
		fmt.Println("NO")
		return
	}
	l = int64(math.Sqrt(float64(n*2)))
	m = 0
	for i=1;i<=l;i++{
		p = n-i*(i+1)/2
		k = int64((math.Sqrt(float64(8*p+1))-1)/2)
		if k > 0 {
			if k*(k+1)+i*(i+1)== 2*n{
				m =1
				fmt.Println("YES")
				break
			}
		}
	}
	if m == 0{
		fmt.Println("NO")
	}
}

//rextester.com:1.6.2--codeforces.com:1.7.3
package main
import("fmt";"math")
func main(){
    var a float64;fmt.Scan(&a);a*=2;b:=false
    for i:=1;i<int(math.Sqrt(a));i++{
        c:=int(a)-i*i-i;d:=int(math.Sqrt(float64(c)))
        if(d*(d+1)==c){b=true}
    }
    if(b){fmt.Print("YES")}else{fmt.Print("NO")}
}

// 192A
package main

import (
	"fmt"
	"math"
)

func main() {
	var n, i, j float64
	fmt.Scan(&n)
	for i = 1; i*(i+1)/2 <= n; i++ {
		j = math.Sqrt(n*2 - i*(i+1))
		x := int64(j)
		if x > 0 && x*(x+1)+int64(i)*(int64(i)+1) == int64(n)*2 {
			fmt.Print("YES")
			return
		}
	}
	fmt.Print("NO")
	return
}

// 192A-mic
package main

import (
	"fmt"
	"math"
)

func main() {
	var n, i, diff, f, c, sq float64
	flag := false
	fmt.Scan(&n)
	for i = 1; (i * (i + 1)) < 2*n; i++ {
		diff = 2*n - (i * (i + 1))
		sq = math.Sqrt(diff)
		f = math.Floor(sq)
		c = math.Ceil(sq)
		if f != c && f*c == diff {
			flag = true
			break
		}
	}
	if flag {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

// 192A
package main

import (
	"fmt"
	"math"
)

func main() {
	var n, i, j float64
	fmt.Scan(&n)
	for i = 1; i*(i+1)/2 <= n; i++ {
		j = math.Sqrt(n*2 - i*(i+1))
		if j > 0 && j*(j+1)+i*(i+1) == n*2 {
			fmt.Print("YES")
			return
		}
	}
	fmt.Print("NO")
	return
}


Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him.

The input data contain four lines. Each of these lines contains four integers x1, y1, x2, y2 ( - 109 ≤ x1, y1, x2, y2 ≤ 109) — coordinates of segment's beginning and end positions. The given segments can degenerate into points.

Output the word «YES», if the given four segments form the required rectangle, otherwise output «NO».

package main

import . "fmt"

type vec struct {
	x, y int64
}

func (a vec) less(b vec) bool                 { return a.x < b.x || a.x == b.x && a.y < b.y }
func (a vec) sub(b vec) vec                   { return vec{a.x - b.x, a.y - b.y} }
func (a vec) dot(b vec) int64                 { return a.x*b.x + a.y*b.y }
func isOrthogonal(a, b, c vec) bool           { return a.sub(b).dot(c.sub(b)) == 0 }
func isRectangle(a, b, c, d vec) bool         { return isOrthogonal(a, b, c) && isOrthogonal(b, c, d) && isOrthogonal(c, d, a) }
func isRectangleAnyOrder(a, b, c, d vec) bool { return isRectangle(a, b, c, d) || isRectangle(a, b, d, c) || isRectangle(a, c, b, d) }

// github.com/EndlessCheng/codeforces-go
func main() {
	mp := map[vec]int{}
	shown := map[vec]int{}
	for i := 0; i < 4; i++ {
		var x, y int64
		Scan(&x, &y)
		p0 := vec{x, y}
		Scan(&x, &y)
		p1 := vec{x, y}
		if v := p1.sub(p0); v.x != 0 && v.y != 0 {
			Print("NO")
			return
		}
		mp[p0]++
		mp[p1]++
		if p1.less(p0) {
			p0, p1 = p1, p0
		}
		shown[p1.sub(p0)]++
	}
	for _, v := range shown {
		if v != 2 {
			Print("NO")
			return
		}
	}
	arr := []vec{}
	for vec, v := range mp {
		if v != 2 {
			Print("NO")
			return
		}
		arr = append(arr, vec)
	}
	if isRectangleAnyOrder(arr[0], arr[1], arr[2], arr[3]) {
		Print("YES")
	} else {
		Print("NO")
	}
}

package main

import . "fmt"

type vec struct {
	x, y int64
}

func (a vec) sub(b vec) vec                   { return vec{a.x - b.x, a.y - b.y} }
func (a vec) dot(b vec) int64                 { return a.x*b.x + a.y*b.y }
func isOrthogonal(a, b, c vec) bool           { return a.sub(b).dot(c.sub(b)) == 0 }
func isRectangle(a, b, c, d vec) bool         { return isOrthogonal(a, b, c) && isOrthogonal(b, c, d) && isOrthogonal(c, d, a) }
func isRectangleAnyOrder(a, b, c, d vec) bool { return isRectangle(a, b, c, d) || isRectangle(a, b, d, c) || isRectangle(a, c, b, d) }

// github.com/EndlessCheng/codeforces-go
func main() {
	mp := map[vec]int{}
	for i := 0; i < 4; i++ {
		var x, y int64
		Scan(&x, &y)
		p0 := vec{x, y}
		Scan(&x, &y)
		p1 := vec{x, y}
		v := p1.sub(p0)
		if v.x != 0 && v.y != 0 {
			Print("NO")
			return
		}
		mp[p0]++
		mp[p1]++
	}
	arr := []vec{}
	for vec, v := range mp {
		if v != 2 {
			Print("NO")
			return
		}
		arr = append(arr, vec)
	}
	if isRectangleAnyOrder(arr[0], arr[1], arr[2], arr[3]) {
		Print("YES")
	} else {
		Print("NO")
	}
}

package main

import . "fmt"

type vec struct {
	x, y int64
}

func (a vec) sub(b vec) vec                   { return vec{a.x - b.x, a.y - b.y} }
func (a vec) dot(b vec) int64                 { return a.x*b.x + a.y*b.y }
func isOrthogonal(a, b, c vec) bool           { return a.sub(b).dot(c.sub(b)) == 0 }
func isRectangle(a, b, c, d vec) bool         { return isOrthogonal(a, b, c) && isOrthogonal(b, c, d) && isOrthogonal(c, d, a) }
func isRectangleAnyOrder(a, b, c, d vec) bool { return isRectangle(a, b, c, d) || isRectangle(a, b, d, c) || isRectangle(a, c, b, d) }

// github.com/EndlessCheng/codeforces-go
func main() {
	mp := map[vec]int{}
	for i := 0; i < 4; i++ {
		var x, y int64
		Scan(&x, &y)
		p0 := vec{x, y}
		Scan(&x, &y)
		p1 := vec{x, y}
		mp[p0]++
		mp[p1]++
	}
	arr := []vec{}
	for vec, v := range mp {
		if v != 2 {
			Print("NO")
			return
		}
		arr = append(arr, vec)
	}
	if isRectangleAnyOrder(arr[0], arr[1], arr[2], arr[3]) {
		Print("YES")
	} else {
		Print("NO")
	}
}


Vasya has a pile, that consists of some number of stones. $$$n$$$ times he either took one stone from the pile or added one stone to the pile. The pile was non-empty before each operation of taking one stone from the pile.You are given $$$n$$$ operations which Vasya has made. Find the minimal possible number of stones that can be in the pile after making these operations.

The first line contains one positive integer $$$n$$$ — the number of operations, that have been made by Vasya ($$$1 \leq n \leq 100$$$). The next line contains the string $$$s$$$, consisting of $$$n$$$ symbols, equal to "-" (without quotes) or "+" (without quotes). If Vasya took the stone on $$$i$$$-th operation, $$$s_i$$$ is equal to "-" (without quotes), if added, $$$s_i$$$ is equal to "+" (without quotes).

Print one integer — the minimal possible number of stones that can be in the pile after these $$$n$$$ operations.

NoteIn the first test, if Vasya had $$$3$$$ stones in the pile at the beginning, after making operations the number of stones will be equal to $$$0$$$. It is impossible to have less number of piles, so the answer is $$$0$$$. Please notice, that the number of stones at the beginning can't be less, than $$$3$$$, because in this case, Vasya won't be able to take a stone on some operation (the pile will be empty).In the second test, if Vasya had $$$0$$$ stones in the pile at the beginning, after making operations the number of stones will be equal to $$$4$$$. It is impossible to have less number of piles because after making $$$4$$$ operations the number of stones in the pile increases on $$$4$$$ stones. So, the answer is $$$4$$$.In the third test, if Vasya had $$$1$$$ stone in the pile at the beginning, after making operations the number of stones will be equal to $$$1$$$. It can be proved, that it is impossible to have less number of stones after making the operations.In the fourth test, if Vasya had $$$0$$$ stones in the pile at the beginning, after making operations the number of stones will be equal to $$$3$$$.

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
func ReadStr() string{
	scanner.Scan()
	return scanner.Text()
}

func ReadInt(x int) (res int)  {
	scanner.Scan()

	n,err := strconv.Atoi(scanner.Text())
	res = n
	if err != nil{
		panic(err)
	}
	return
}

type building struct
{
	a , b ,c int
}

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

func main()  {
	var n int
	fmt.Scan(&n)
	var s string
	fmt.Scan(&s)
	ans := 100
	for i := 0 ;i <= 100 ;i ++{
		t := i
		check := true
	for index,_ := range s{
		if(string(s[index]) == "+"){
			t ++
		}else{
				t --;
				if(t <= -1){
				check = false
				break;
				}
		}
	}
	if(check){

		ans = min(t,ans)
	}
	}
	fmt.Print(ans)

}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
func ReadStr() string{
	scanner.Scan()
	return scanner.Text()
}

func ReadInt(x int) (res int)  {
	scanner.Scan()

	n,err := strconv.Atoi(scanner.Text())
	res = n
	if err != nil{
		panic(err)
	}
	return
}

type building struct
{
	a , b ,c int
}

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

func main()  {
	var n int
	fmt.Scan(&n)
	var s string
	fmt.Scan(&s)
	ans := 0
	for i,_ := range s{
			if(string(s[i]) == "+"){
				ans ++
			}else{
					if(ans >= 1){
						ans --
					}
			}
	}
	fmt.Println(ans)

}

package main

import "fmt"

func main() {
	var n int32
	var str string
	fmt.Scanf("%d\n",&n)
	fmt.Scanf("%s\n",&str)
	ans:=0
	for _,c:=range str{
		if c=='+'{
			ans++
		}else if c=='-'{
			if ans>0{
				ans--
			}
		}
	}
	fmt.Println(ans)
}

package main

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

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

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

func main() {
	defer writer.Flush()
	var d int
	scanf("%d\n", &d)
	var s string
	scanf("%s", &s)
	sa := []byte(s)
	cur := 0
	for _, c := range sa {
		if c == '-' {
			cur--
		} else {
			cur++
		}
		if cur < 0 {
			cur = 0
		}
	}

	printf("%d", cur)
}

package main

import (
	"fmt"
	"strconv"
)

func main() {
	var nStr string
	fmt.Scanln(&nStr)
	n, _ := strconv.Atoi(nStr)

	var pattern string
	fmt.Scanln(&pattern)

	ct := 0
	minSeen := 0
	for i := 0; i < n; i++ {
		if pattern[i] == '+' {
			ct++
		} else if pattern[i] == '-' {
			ct--
		}
		if ct < minSeen {
			minSeen = ct
		}
	}
	fmt.Println(ct - minSeen)
}

package main

import (
	"fmt"
)
func main() {
	n := 0
	fmt.Scan(&n)
	s := ""
	fmt.Scan(&s)
	ans := 0
	for _, char := range(s) {
		if char == rune('+') {
			ans = ans + 1
		} else if char == rune('-') {
			if ans != 0 {
				ans = ans - 1
			}
		}
	}
	fmt.Println(ans)
}

package main

import (
	"bufio"
	"os"
	"fmt"
)
var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{}) { fmt.Fscanf(reader, f, a...) }
func readLine()(string,error) 			{ return reader.ReadString('\n') }

func main() {
	defer writer.Flush()
	var t,s string
	scanf("%s\n%s", &t, &s);
	c := 0
	for _, i := range s {
		if i == '-' {
			if c > 0 {
				c--
			}
		}
		if i == '+' {
			c++
		}
	}
	fmt.Println(c)
}

package main

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

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

func Solve(n int, s string) int {
	rollingSum := 0
	lowestRollingSum := 0
	for _, elem := range s {
		if string(elem) == "-" {
			rollingSum -= 1
		} else if string(elem) == "+" {
			rollingSum += 1
		}
		lowestRollingSum = min(lowestRollingSum, rollingSum)
	}
	return -1*lowestRollingSum + rollingSum
}

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

	var n int
	var s string
	fmt.Fscanf(reader, "%d\n", &n)
	fmt.Fscanf(reader, "%s\n", &s)
	fmt.Fprintf(writer, "%d\n", Solve(n, s))
}

package main

import (
	"fmt"
)

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

func main(){
	var n int
	fmt.Scan(&n)
	var s string
	fmt.Scan(&s)
	ans := n
	var i int
	var temp int

	for i = 0 ; i <= 100;i++{
		temp = i
		for _, char := range (s){
			if(char =='+'){
				temp ++
			}
			if(char =='-'){
				temp --
				if(temp <= -1){
				temp = -1
				break;
				}
			}
		}
		if(temp >= 0){
			ans = min(ans,temp)
		}
	}
	fmt.Print(ans)

}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
func ReadStr() string{
	scanner.Scan()
	return scanner.Text()
}

func ReadInt(x int) (res int)  {
	scanner.Scan()

	n,err := strconv.Atoi(scanner.Text())
	res = n
	if err != nil{
		panic(err)
	}
	return
}

type building struct
{
	a , b ,c int
}

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

func main()  {
	var n int
	fmt.Scan(&n)
	s := ReadStr()
	ans := 0
	for index,_ := range s{
		if(string(s[index]) == "+"){
			ans ++
		}else{
				ans --;
		}

	}
	fmt.Print(max(ans,0))

}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
func ReadStr() string{
	scanner.Scan()
	return scanner.Text()
}

func ReadInt(x int) (res int)  {
	scanner.Scan()

	n,err := strconv.Atoi(scanner.Text())
	res = n
	if err != nil{
		panic(err)
	}
	return
}

type building struct
{
	a , b ,c int
}

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

func main()  {
	var n int
	fmt.Scan(&n)
	var s string
	fmt.Scan(&s)
	var ans int
	for index,_ := range s{
		if(string(s[index]) == "+"){
			ans ++
		}else{
				ans --;
		}

	}
	fmt.Print(max(ans,0))

}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
func ReadStr() string{
	scanner.Scan()
	return scanner.Text()
}

func ReadInt(x int) (res int)  {
	scanner.Scan()

	n,err := strconv.Atoi(scanner.Text())
	res = n
	if err != nil{
		panic(err)
	}
	return
}

type building struct
{
	a , b ,c int
}

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

func main()  {
	var n int
	fmt.Scan(&n)
	s := ReadStr()
	ans := 0
	for _,i := range s{
		if(string(i) == "+"){
			ans ++
		}else{
				ans --;
		}

	}
	fmt.Println(max(ans,0))

}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
var scanner *bufio.Scanner = bufio.NewScanner(os.Stdin)
func ReadStr() string{
	scanner.Scan()
	return scanner.Text()
}

func ReadInt(x int) (res int)  {
	scanner.Scan()

	n,err := strconv.Atoi(scanner.Text())
	res = n
	if err != nil{
		panic(err)
	}
	return
}

type building struct
{
	a , b ,c int
}

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

func main()  {
	var n int
	fmt.Scan(&n)
	s := ReadStr()
	ans := 100
	for i := 0 ; i <= 100;i++{
		t := i
		yes := true
		for _,i := range s{
			if(string(i) == "-"){
				t --;
				if(t <= -1){
					yes = false
					break;
				}
			}else{
				t ++
			}
		}
		if(yes){
			ans = min(ans,t)
		}
	}
	fmt.Println(ans)

}

package main

import "fmt"

func main() {
	var n int32
	var str string
	fmt.Scanf("%d\n",&n)
	fmt.Scanf("%s\n",&str)
	fmt.Println(n)
	fmt.Println(str)
	ans:=0
	for _,c:=range str{
		if c=='+'{
			ans++
		}else if c=='-'{
			if ans>0{
				ans--
			}
		}
	}
	fmt.Println(ans)
}

package main

import "fmt"

func main() {
	var n int32
	var str string
	fmt.Scanf("%d",&n)
	fmt.Scanf("%s",&str)
	ans:=0
	for _,c:=range str{
		if c=='+'{
			ans++
		}else if c=='-'{
			if ans>0{
				ans--
			}
		}
	}
	fmt.Println(ans)
}

package main

import "fmt"

func main() {
	var n int32
	var str string
	fmt.Scanf("%d",&n)
	fmt.Scanf("%s",&str)
	fmt.Println(n)
	fmt.Println(str)
	ans:=0
	for _,c:=range str{
		if c=='+'{
			ans++
		}else if c=='-'{
			if ans>0{
				ans--
			}
		}
	}
	fmt.Println(ans)
}

package main

import "fmt"

func main() {
	var n int64
	var str string
	fmt.Scanf("%d",&n)
	fmt.Scanf("%s",&str)
	ans:=0
	for _,c:=range str{
		if c=='+'{
			ans++
		}else{
			if ans>0{
				ans--
			}
		}
	}
	fmt.Println(ans)
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	nStr, _ := reader.ReadString('\n')
	nStr = strings.TrimSuffix(nStr, "\n")
	n, _ := strconv.Atoi(nStr)
	pattern, _ := reader.ReadString('\n')

	ct := 0
	minSeen := 0
	for i := 0; i < n; i++ {
		if pattern[i] == '+' {
			ct++
		} else if pattern[i] == '-' {
			ct--
		}
		if minSeen > ct {
			minSeen = ct
		}
	}

	fmt.Println(ct - minSeen)
}

package main

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

func readline(reader *bufio.Reader) string {
	str, _ := reader.ReadString('\n')
	return strings.TrimSuffix(str, "\n")
}

func readInt(reader *bufio.Reader) int {
	str := readline(reader)
	n, _ := strconv.Atoi(str)
	return n
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	n := readInt(reader)
	pattern := readline(reader)

	ct := 0
	minSeen := 0
	for i := 0; i < n; i++ {
		if pattern[i] == '+' {
			ct++
		} else if pattern[i] == '-' {
			ct--
		}
		if ct < minSeen {
			minSeen = ct
		}
	}
	fmt.Println(ct, minSeen)
	fmt.Println(ct - minSeen)
}

package main

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

func readline(reader *bufio.Reader) string {
	str, _ := reader.ReadString('\n')
	return strings.TrimSuffix(str, "\n")
}

func readInt(reader *bufio.Reader) int {
	str := readline(reader)
	n, _ := strconv.Atoi(str)
	return n
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	n := readInt(reader)
	pattern := readline(reader)

	ct := 0
	minSeen := 0
	for i := 0; i < n; i++ {
		if pattern[i] == '+' {
			ct++
		} else if pattern[i] == '-' {
			ct--
		}
		if ct < minSeen {
			minSeen = ct
		}
	}
	fmt.Println(ct - minSeen)
}

package main

import (
	"fmt"
)

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

func main(){
	var n int
	fmt.Scanf("%d",&n)
	var s string
	fmt.Scanf("%s",&s)
	ans := n
	var i , j int
	for i = 0 ; i <= 100;i++{
		temp := i
		for j = 0 ; j < len(s); j ++{
			if(s[j] =='+'){
				temp ++
			}
			if(s[j] =='-'){
				temp --
				if(temp <= -1){
				temp = -1
				break;
				}
			}
		}
		if(temp >= 0){
			ans = min(ans,temp)
		}
	}
	fmt.Print(ans)

}

package main

import (
	"fmt"
)

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

func main(){
	var n int
	fmt.Scanf("%d",&n)
	var s string
	fmt.Scanf("%s",&s)
	ans := 100
	var i , j int
	for i = 0 ; i <= 100;i++{
		temp := i
		for j = 0 ; j < len(s); j ++{
			if(s[j] =='+'){
				temp ++
			}
			if(s[j] =='-'){
				temp --
				if(temp <= -1){
				temp = -1
				}
			}
		}
		if(temp >= 0){
			ans = min(ans,temp)
		}
	}
	fmt.Print(ans)

}

package main

import (
	"fmt"
)

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

func main(){
	var n int
	fmt.Scan(&n)
	var s string
	fmt.Scan(&s)
	ans := n
	var i int
	var temp int

	for i = 0 ; i <= 10;i++{
		temp = i
		for _, char := range (s){
			if(char =='+'){
				temp ++
			}
			if(char =='-'){
				temp --
				if(temp <= -1){
				temp = -1
				break;
				}
			}
		}
		if(temp >= 0){
			ans = min(ans,temp)
		}
	}
	fmt.Print(ans)

}


Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one.In school, where Noora is studying, teachers are putting down marks to the online class register, which are integers from 1 to k. The worst mark is 1, the best is k. Mark that is going to the certificate, is calculated as an average of all the marks, rounded to the closest integer. If several answers are possible, rounding up is produced. For example, 7.3 is rounded to 7, but 7.5 and 7.8784 — to 8. For instance, if Noora has marks [8, 9], then the mark to the certificate is 9, because the average is equal to 8.5 and rounded to 9, but if the marks are [8, 8, 9], Noora will have graduation certificate with 8.To graduate with «A» certificate, Noora has to have mark k.Noora got n marks in register this year. However, she is afraid that her marks are not enough to get final mark k. Noora decided to ask for help in the internet, where hacker Leha immediately responded to her request. He is ready to hack class register for Noora and to add Noora any number of additional marks from 1 to k. At the same time, Leha want his hack be unseen to everyone, so he decided to add as less as possible additional marks. Please help Leha to calculate the minimal number of marks he has to add, so that final Noora's mark will become equal to k.

The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 100) denoting the number of marks, received by Noora and the value of highest possible mark. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ k) denoting marks received by Noora before Leha's hack.

Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to k.

NoteConsider the first example testcase.Maximal mark is 10, Noora received two marks — 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10, 10, 10, 10] (4 marks in total) to the registry, achieving Noora having average mark equal to . Consequently, new final mark is 10. Less number of marks won't fix the situation.In the second example Leha can add [5, 5, 5] to the registry, so that making average mark equal to 4.5, which is enough to have 5 in the certificate.

package main

import (
	"fmt"
	"os"
)

var n int
var m int
var tmp int

func main() {
	fmt.Scan(&n)
	fmt.Scan(&m)
	suma := 0
	for i := 0; i < n; i++ {
		fmt.Scan(&tmp)
		suma += tmp
	}

	ansa := 0
	for {
		if float64(m)-float64(suma)/float64((ansa+n)) <= float64(0.5) {
			fmt.Println(ansa)
			os.Exit(0)
		}
		suma += m
		ansa++

	}

}

package main

import "fmt"

func main() {
    var n int
    var k int
    fmt.Scanf("%d %d\n", &n, &k)
    sum := 0
    for i := 0; i < n; i++ {
    	var x int
    	fmt.Scanf("%d", &x)
    	sum += x
    }
    ret := 0
    for 2 * sum < (ret + n) * (2 * k - 1) {
    	/*
    	sum / (ret + n) >= (k - 0.5)
    	2 * sum / (ret + n) >= 2 * k - 1
    	2 * sum >= (ret + n) * (2 * k - 1)
    	*/
    	sum += k
    	ret += 1
    }
    fmt.Printf("%d\n", ret)
}

package main

import "fmt"

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

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

	for passed(a, k) == false {
		a = append(a, k)
	}

	fmt.Printf("%d", len(a)-n)
}

func passed(a []int, k int) bool {
	avg := calcAvg(a)
	if avg+0.5 >= float64(k) {
		return true
	}
	return false
}

func calcAvg(a []int) float64 {
	total := 0
	for _, value := range a {
		total += value
	}
	return float64(total) / float64(len(a))
}