Polycarp plays "Game 23". Initially he has a number $$$n$$$ and his goal is to transform it to $$$m$$$. In one move, he can multiply $$$n$$$ by $$$2$$$ or multiply $$$n$$$ by $$$3$$$. He can perform any number of moves.Print the number of moves needed to transform $$$n$$$ to $$$m$$$. Print -1 if it is impossible to do so.It is easy to prove that any way to transform $$$n$$$ to $$$m$$$ contains the same number of moves (i.e. number of moves doesn't depend on the way of transformation).

The only line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le m \le 5\cdot10^8$$$).

Print the number of moves to transform $$$n$$$ to $$$m$$$, or -1 if there is no solution.

NoteIn the first example, the possible sequence of moves is: $$$120 \rightarrow 240 \rightarrow 720 \rightarrow 1440 \rightarrow 4320 \rightarrow 12960 \rightarrow 25920 \rightarrow 51840.$$$ The are $$$7$$$ steps in total.In the second example, no moves are needed. Thus, the answer is $$$0$$$.In the third example, it is impossible to transform $$$48$$$ to $$$72$$$.

package main

import "fmt"

func main() {
	var n, m int64
	fmt.Scan(&n, &m)
	if m%n != 0 {
		fmt.Println(-1)
		return
	}
	m /= n
	cnt := 0
	for ; m%2 == 0; m /= 2 {
		cnt += 1
	}
	for ; m%3 == 0; m /= 3 {
		cnt += 1
	}
	if m > 1 {
		fmt.Println(-1)
		return
	}
	fmt.Println(cnt)
}

package main

import (
	"fmt"
)

func rec(a, b, cnt int) int {
	if a > b {
		return -1
	}
	if a == b {
		// fmt.Printf("%d\n", cnt)
		return cnt
	}
	if rec(a*2, b, cnt+1) != -1 {
		return rec(a*2, b, cnt+1)
	}
	if rec(a*3, b, cnt+1) != -1 {
		return rec(a*3, b, cnt+1)
	}
	return -1
}

func main() {
	var a, b int
	fmt.Scanf("%d %d\n", &a, &b)
	fmt.Printf("%d\n", rec(a, b, 0))
}

package main

import "fmt"

func recurs(a, b int) int {
	if a > b {
		return -1
	}
	if a == b {
		// fmt.Printf("%d\n", cnt)
		return 0
	}
	if recurs(a*2, b) != -1 {
		return 1 + recurs(a*2, b)
	}
	if recurs(a*3, b) != -1 {
		return 1 + recurs(a*3, b)
	}
	return -1
}

func main() {
	var a, b int
	fmt.Scanf("%d %d\n", &a, &b)
	fmt.Printf("%d\n", recurs(a, b))
}

package main

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

func main() {
	buf := bufio.NewReader(os.Stdin)

	var n, m int
	fmt.Fscanf(buf, "%d %d\n", &n, &m)
	if m%n != 0 {
		fmt.Printf("-1\n")
		return
	}
	ans := 0
	m /= n
	for m > 1 {
		if m%2 == 0 {
			m /= 2
			ans++
		} else if m%3 == 0 {
			m /= 3
			ans++
		} else {
			fmt.Printf("-1\n")
			return
		}
	}
	fmt.Printf("%d\n", ans)

}

package main

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

func main()  {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var n,m int
	fmt.Fscan(in,&n)
	fmt.Fscan(in,&m)
	if(m == n){
		fmt.Fprint(out,0)
		return
	}
	temp := m / n;
	cnt := -1
	if(temp * n == m){

	for temp % 2 == 0{
		if(cnt == -1){
			cnt = 0
		}
		cnt++
		temp /= 2
	}

	for temp % 3 == 0{
		if(cnt == -1){
			cnt = 0
		}
		cnt ++
		temp /= 3
	}

	if(temp == 1){
		fmt.Fprint(out,cnt)
		return
	}

	}
	if(temp == 1){
		fmt.Fprint(out,cnt)
	}else{
		fmt.Fprint(out,-1)
	}

}

func max(i int, i2 int) int {
	if(i < i2){
		return i2
	}else{
		return i
	}
}
func min(i int , i2 int)  int {
	if(i < i2){
		return i
	}else{
		return i2
	}

}

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

func main() {
    reader := bufio.NewReader(os.Stdin)

    input, _ := reader.ReadString('\n')
    input = strings.Trim(input, "\r\n")
    splitted := strings.Split(input, " ")

    n, _ := strconv.Atoi(splitted[0])
    m, _ := strconv.Atoi(splitted[1])

    if n == m {
        fmt.Println("0")
        os.Exit(0)
    } else if m % n != 0 {
        fmt.Println("-1")
        os.Exit(0)
    }

    div := m / n
    if div % 2 != 0 && div % 3 != 0 {
        fmt.Println("-1")
        os.Exit(0)
    }

    divisors := [3] int {6, 3, 2}
    ans := 0

    for i := 0; i < 3; i++ {
        for div % divisors[i] == 0 {
            if i == 0 {
                ans += 2
            } else {
                ans++
            }
            div /= divisors[i]
        }
    }

    if div == 1 {
        fmt.Println(ans)
    } else {
        fmt.Println("-1")
    }
}

/*package main

import (
	"fmt"
)

func main() {
	var n int
	d:=0
	var s string
	fmt.Scan(&n)
	fmt.Scan(&s)
	for i:=0; i<n ; i++{
		if s[i]%2==0{
			d=d+i+1
		}
	}
	fmt.Printf("%d", d)

}*/
package main

import (
	"fmt"
)

func main() {
	var n,m int
	d:=0
	fmt.Scan(&n)
	fmt.Scan(&m)
	if m%n!=0{
	    fmt.Printf("%d", -1)
	}
	if m%n==0{
	    x:=m/n
	    for (x%2==0||x%3==0)&&x>1{
	        if x%2==0{
	            x=x/2
	            d+=1
	        }
	        if x%3==0{
	            x=x/3
	            d+=1
	        }
	    }
	    if x==1{
	        fmt.Printf("%d", d)
	    }
	    if x!=1{
	        fmt.Printf("%d", -1)
	    }
	}

}

package main

import "fmt"

func main () {
	var n, m int
	fmt.Scanln(&n, &m)

	twoCount1 := 0
	threeCount1 := 0
	twoCount2 := 0
	threeCount2 := 0

	for n%2==0 {
		twoCount1 += 1
		n /= 2
	}
	for m%2==0 {
		twoCount2 += 1
		m /= 2
	}
	for n%3==0 {
		threeCount1 += 1
		n /= 3
	}
	for m%3==0 {
		threeCount2 += 1
		m /= 3
	}

	if m != n || twoCount1 > twoCount2 || threeCount1 > threeCount2 {
		fmt.Println("-1")
		return
	} else {
		fmt.Println(twoCount2 - twoCount1 + threeCount2 - threeCount1)
	}

}

package main

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

type Cin struct {
	scanner *bufio.Scanner
}

func (c *Cin) NextInt() int {
	c.scanner.Scan()
	line := c.scanner.Text()
	return c.convertInt(line)
}

func (c *Cin) NextIntSlice() []int {
	c.scanner.Scan()
	line := strings.Split(c.scanner.Text(), " ")
	var ret []int
	for _, s := range line {
		ret = append(ret, c.convertInt(s))
	}
	return ret
}

func (c *Cin) NextTwoInt() (int, int) {
	line := c.NextIntSlice()
	return line[0], line[1]
}

func (c *Cin) convertInt(data string) int {
	i, _ := strconv.Atoi(data)
	return i
}

var cin = &Cin{
	scanner: bufio.NewScanner(os.Stdin),
}

type element struct {
	value int
	step  int
	next  *element
	last  *element
}

func newElement(value, step int) *element {
	return &element{value: value, step: step}
}

type queue struct {
	head *element
	tail *element
}

func (q *queue) push(value, step int) {
	item := newElement(value, step)
	if q.isEmpty() {
		q.head = item
		q.tail = q.head
		return
	}
	item.last = q.tail
	q.tail.next = item
	q.tail = item
}

func (q *queue) isEmpty() bool {
	return q.head == nil
}

func (q *queue) pop() *element {
	if q.isEmpty() {
		panic("pop from empty queue")
	}
	item := q.head
	q.head = q.head.next
	return item
}

func newQueue() *queue {
	return &queue{}
}

func handle(n, m int) int {
	q := newQueue()
	q.push(n, 0)
	set := map[int]int{n: 0}
	for !q.isEmpty() {
		ele := q.pop()
		if ele.value == m {
			return ele.step
		}
		if ele.value > m {
			continue
		}
		if _, ok := set[ele.value*2]; !ok {
			set[ele.value*2] = ele.step + 1
			// fmt.Printf("val=[%v],step=[%v]\n", ele.value*2, ele.step+1)
			q.push(ele.value*2, ele.step+1)
		}
		if _, ok := set[ele.value*3]; !ok {
			set[ele.value*3] = ele.step + 1
			// fmt.Printf("val=[%v],step=[%v]\n", ele.value*3, ele.step+1)
			q.push(ele.value*3, ele.step+1)
		}
	}
	return -1
}

func main() {
	n, m := cin.NextTwoInt()
	fmt.Printf("%d\n", handle(n, m))
}

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 a, b int
  scanf("%d %d\n", &a, &b)

  if b % a !=  0 {
    printf("%d\n", -1)
    return
  }

  div := b / a
  count := 0

  for div > 1 {
    if div % 2 == 0 {
      div /= 2
      count += 1
    } else if div % 3 == 0 {
      div /= 3
      count += 1
    } else {
      break
    }
  }

  if div == 1 {
    printf("%d\n", count)
  } else {
    printf("%d\n", -1)
  }
  return
}

package main

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

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

func p(a ...interface{})                { fmt.Fprint(writer, a...) }
func pln(a ...interface{})              { fmt.Fprintln(writer, a...) }
func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }

func scan(a ...interface{})             { fmt.Fscan(reader, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func main() {
  defer writer.Flush()

  var a, b int
  scan(&a, &b)

  if b % a !=  0 {
    pln(-1)
    return
  }

  div := b / a
  count := 0

  for div > 1 {
    if div % 2 == 0 {
      div /= 2
      count += 1
    } else if div % 3 == 0 {
      div /= 3
      count += 1
    } else {
      break
    }
  }

  if div == 1 {
    pln(count)
  } else {
    pln(-1)
  }
  return
}

package main

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

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

	var vl int

	if ok := m % n; ok == 0 {
		vl = m / n
	} else {
		fmt.Println(-1)
		return
	}

	var count int
	for vl > 1 {
		if vl%3 == 0 {
			vl /= 3
			count++
		} else if vl%2 == 0 {
			vl /= 2
			count++
		} else {
			fmt.Println(-1)
			return
		}
	}

	fmt.Println(count)
}

package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	if m%n != 0 {
		fmt.Print("-1")
	} else {
		var div int = m / n
		var count int = 0
		for div%2 == 0 {
			count++
			div /= 2
		}
		for div%3 == 0 {
			count++
			div /= 3
		}
		if div != 1 {
			fmt.Printf("-1")
		} else {
			fmt.Printf("%v", count)
		}
	}
}

package main

import "fmt"

func main() {
	var n, m, fact, step int64
	fmt.Scanf("%d %d", &n, &m)
	if m != n {
		if m%n == 0 {
			fact = m / n
			for fact%3 == 0 {
				fact /= 3
				step++
			}
			for fact%2 == 0 {
				fact /= 2
				step++
			}
		}
		if fact != 1 {
			step = -1
		}
	}

	fmt.Println(step)
}

// Author: sighduck
// URL: https://codeforces.com/contest/1141/problem/A

package main

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

func reduceDivisor(divisor int, moves int) int {
	if divisor == 1 {
		return moves
	} else if divisor%2 == 0 {
		return reduceDivisor(divisor/2, moves+1)
	} else if divisor%3 == 0 {
		return reduceDivisor(divisor/3, moves+1)
	}
	return -1
}

func Solve(n int, m int) int {
	if m%n != 0 || m < n {
		return -1
	}
	return reduceDivisor(m/n, 0)
}

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

	var n, m int
	fmt.Fscanf(reader, "%d %d\n", &n, &m)

	fmt.Fprintf(writer, "%d\n", Solve(n, m))
}

package main

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

func main()  {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var n,m int
	fmt.Fscan(in,&n)
	fmt.Fscan(in,&m)
	cnt := -1
	if m % n == 0{
	temp := m / n
	for temp % 2 == 0{
		temp /= 2
		if(cnt == -1){
			cnt = 0
		}
		cnt ++
	}
	for temp % 3 == 0{
		temp /= 3
		if(cnt == -1){
			cnt = 0
		}
		cnt++
	}
	}else{
		cnt = -1
	}
	fmt.Fprint(out,cnt)
}

func max(i int, i2 int) int {
	if(i < i2){
		return i2
	}else{
		return i
	}
}
func min(i int , i2 int)  int {
	if(i < i2){
		return i
	}else{
		return i2
	}

}

package main

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

func main()  {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var n,m int
	fmt.Fscan(in,&n)
	fmt.Fscan(in,&m)
	if(n == m){
		fmt.Fprint(out,0)
		return
	}
	cnt := -1
	if m % n == 0{
	temp := m / n
	for temp % 2 == 0{
		temp /= 2
		if(cnt == -1){
			cnt = 0
		}
		cnt ++
	}
	for temp % 3 == 0{
		temp /= 3
		if(cnt == -1){
			cnt = 0
		}
		cnt++
	}
	}else{
		cnt = -1
	}
	fmt.Fprint(out,cnt)
}

func max(i int, i2 int) int {
	if(i < i2){
		return i2
	}else{
		return i
	}
}
func min(i int , i2 int)  int {
	if(i < i2){
		return i
	}else{
		return i2
	}

}

package main

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

func main()  {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	var n,m int
	fmt.Fscan(in,&n)
	fmt.Fscan(in,&m)
	cnt := 0
	if m % n == 0{
	temp := m / n
	for temp % 2 == 0{
		temp /= 2
		cnt ++
	}
	for temp % 3 == 0{
		temp /= 3
		cnt++
	}
	}else{
		cnt = -1
	}
	fmt.Fprint(out,cnt)
}

func max(i int, i2 int) int {
	if(i < i2){
		return i2
	}else{
		return i
	}
}
func min(i int , i2 int)  int {
	if(i < i2){
		return i
	}else{
		return i2
	}

}

package main

import "fmt"

func main () {
	var n, m int
	fmt.Scanln(&n, &m)

	twoCount1 := 0
	threeCount1 := 0
	twoCount2 := 0
	threeCount2 := 0

	for n%2==0 {
		twoCount1 += 1
		n /= 2
	}
	for m%2==0 {
		twoCount2 += 1
		m /= 2
	}
	for n%3==0 {
		threeCount1 += 1
		n /= 3
	}
	for m%3==0 {
		threeCount2 += 1
		m /= 3
	}

	if m != n || twoCount1 > twoCount2 || threeCount1 > threeCount2 {
		println("-1")
		return
	} else {
		println(twoCount2 - twoCount1 + threeCount2 - threeCount1)
	}

}

package main

import "fmt"

func main() {
	var x, y, z, a, b, c int32
	fmt.Scan(&x, &y, &z, &a, &b, &c)
	var answer string = "YES"
	if a -= x; a < 0 {
		answer = "NO"
	}
	if b = a + b - y; b < 0 {
		answer = "NO"
	}
	if c = b + c - z; c < 0 {
		answer = "NO"
	}
	fmt.Printf("%v", answer)
}

package main

import "fmt"

func main() {
	var n, m, fact, step int64
	fmt.Scanf("%d %d", &n, &m)
	if m != n {
		if m%n == 0 {
			fact = m / n
			fmt.Println(fact)
			for fact%3 == 0 {
				fact /= 3
				step++
			}
			fmt.Println(fact)
			for fact%2 == 0 {
				fact /= 2
				step++
			}
			fmt.Println(fact)
		}
		if fact != 1 {
			step = -1
		}
	}

	fmt.Println(step)
}

package main

import "fmt"

func main() {
	var n, m, step int
	fmt.Scanf("%d %d", &n, &m)
	if m != n {
		if m%n == 0 {
			var fact = m / n
			for fact%3 == 0 {
				fact /= 3
				step++
			}
			for fact%2 == 0 {
				fact /= 2
				step++
			}
		} else {
			step = -1
		}
	}

	fmt.Println(step)
}

package main

import "fmt"

func main() {
	var n, m, fact, step int64
	fmt.Scanf("%d %d", &n, &m)
	if m != n {
		if m%n == 0 {
			fact = m / n
			for fact%3 == 0 {
				fact /= 3
				step++
			}
			for fact%2 == 0 {
				fact /= 2
				step++
			}
		}
		if fact != 1 {
			step = -1
		}
		step = -1
	}

	fmt.Println(step)
}

package main

import "fmt"

func main() {
	var n, m, step int
	fmt.Scanf("%d %d", &n, &m)
	if m != n {
		if m%n == 0 {
			var fact = m / n
			for fact%3 == 0 {
				fact /= 3
				step++
			}
			for fact%2 == 0 {
				fact /= 2
				step++
			}
			if step == 0 {
				step = -1
			}
		} else {
			step = -1
		}
	}

	fmt.Println(step)
}

package main

import "fmt"

func main() {
	var n, m, step uint
	fmt.Scanf("%d %d", &n, &m)
	if m%n == 0 {
		var fact = m / n
		for fact%3 == 0 {
			fact /= 3
			step++
		}
		for fact%2 == 0 {
			fact /= 2
			step++
		}
	}
	fmt.Println(step)
}


Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Let next(x) be the minimum lucky number which is larger than or equals x. Petya is interested what is the value of the expression next(l) + next(l + 1) + ... + next(r - 1) + next(r). Help him solve this problem.

The single line contains two integers l and r (1 ≤ l ≤ r ≤ 109) — the left and right interval limits.

In the single line print the only number — the sum next(l) + next(l + 1) + ... + next(r - 1) + next(r). Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator.

NoteIn the first sample: next(2) + next(3) + next(4) + next(5) + next(6) + next(7) = 4 + 4 + 4 + 7 + 7 + 7 = 33In the second sample: next(7) = 7

// 121A
package main

import (
	"fmt"
)

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

func main() {
	var a [15]int64
	var i, l, r, x, j, n1, n2 int64
	x, j = 0, 1
	fmt.Scan(&l, &r)
	for i = 0; i <= 10; i++ {
		a[i] = 0
	}
	for j <= r {
		i = 10
		a[i]++
		for a[i] > 2 {
			a[i] = 0
			i--
			a[i]++
		}
		j = 0
		for i = 1; i <= 10; i++ {
			if j > 0 && a[i] == 0 {
				break
			}
			if a[i] == 1 {
				n1 = 4
			} else {
				n1 = 0
			}
			if a[i] == 2 {
				n2 = 7
			} else {
				n2 = 0
			}
			j = j*10 + n1 + n2
		}
		if x == 0 && j >= l {
			x += j
		}
		if i <= 10 {
			continue
		}
		if j >= l {
			x += (min(j, r) - l) * j
			l = j
		}
	}
	fmt.Print(x)
}

package main

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

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

func getNext(x int64) int64 {
  //fmt.Fprintf(os.Stderr, "in: %d\n", x)
  digits := []int64{}
  for x != 0 {
    digits = append(digits, x%10)
    x /= 10
  }
  carry := int64(0)
  resetIndex := -1
  for i, digit := range digits {
    if carry == 1 {
      digit++
      carry = 0
    }
    if digit <= 4 {
      if digit < 4 {
        resetIndex = i-1
      }
      digits[i] = 4
    } else if digit <= 7 {
      if digit < 7 {
        resetIndex = i-1
      }
      digits[i] = 7
    } else {
      digits[i] = 4
      resetIndex = i
      carry = 1
    }
  }
  if carry == 1 {
    digits = append(digits, 4)
  }
  for i := 0; i <= resetIndex; i++ {
    digits[i] = 4
  }
  base := int64(1)
  for _, digit := range digits {
    x += base*digit
    base *= 10
  }
  //fmt.Fprintf(os.Stderr, " -> %d\n", x)
  return x
}

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

  left, right := getI64(), getI64()
  total := int64(0)
  max := getNext(right)
  current := left-1
  for {
    next := getNext(current+1)
    if next == max {
      total += (right-current)*next
      break
    }
    total += (next-current)*next
    current = next
  }
  writer.WriteString(fmt.Sprintf("%d\n", total))
}

package main

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

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

func getNext(x int64) int64 {
  digits := []int64{}
  for x != 0 {
    digits = append(digits, x%10)
    x /= 10
  }
  carry := int64(0)
  for i, digit := range digits {
    digit += carry
    carry = 0
    if digit <= 4 {
      digits[i] = 4
    } else if digit <= 7 {
      digits[i] = 7
    } else {
      digits[i] = 4
      carry = 1
    }
  }
  if carry == 1 {
    digits = append(digits, 4)
  }
  base := int64(1)
  for _, digit := range digits {
    x += base*digit
    base *= 10
  }
  return x
}

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

  left, right := getI64(), getI64()
  total := int64(0)
  max := getNext(right)
  current := left-1
  for {
    next := getNext(current+1)
    if next == max {
      total += (right-current)*next
      break
    }
    total += (next-current)*next
    current = next
  }
  writer.WriteString(fmt.Sprintf("%d\n", total))
}

package main

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

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

func getNext(x int64) int64 {
  //fmt.Fprintf(os.Stderr, "in: %d\n", x)
  digits := []int64{}
  for x != 0 {
    digits = append(digits, x%10)
    x /= 10
  }
  carry := int64(0)
  carryIndex := -1
  for i, digit := range digits {
    if carry == 1 {
      digit++
      carry = 0
    }
    if digit <= 4 {
      digits[i] = 4
    } else if digit <= 7 {
      digits[i] = 7
    } else {
      digits[i] = 4
      carry = 1
      carryIndex = i
    }
  }
  if carry == 1 {
    digits = append(digits, 4)
  }
  for i := 0; i <= carryIndex; i++ {
    digits[i] = 4
  }
  base := int64(1)
  for _, digit := range digits {
    x += base*digit
    base *= 10
  }
  //fmt.Fprintf(os.Stderr, " -> %d\n", x)
  return x
}

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

  left, right := getI64(), getI64()
  total := int64(0)
  max := getNext(right)
  current := left-1
  for {
    next := getNext(current+1)
    if next == max {
      total += (right-current)*next
      break
    }
    total += (next-current)*next
    current = next
  }
  writer.WriteString(fmt.Sprintf("%d\n", total))
}

package main

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

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

func getNext(x int64) int64 {
  fmt.Fprintf(os.Stderr, "%d ->", x)
  digits := []int64{}
  for x != 0 {
    digits = append(digits, x%10)
    x /= 10
  }
  carry := int64(0)
  for i, digit := range digits {
    digit += carry
    carry = 0
    if digit <= 4 {
      digits[i] = 4
    } else if digit <= 7 {
      digits[i] = 7
    } else {
      digits[i] = 4
      carry = 1
    }
  }
  if carry == 1 {
    digits = append(digits, 4)
  }
  base := int64(1)
  for _, digit := range digits {
    x += base*digit
    base *= 10
  }
  fmt.Fprintf(os.Stderr, " %d\n", x)
  return x
}

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

  span := int64(0)
  left, right := getI64(), getI64()
  total := uint64(0)
  max := getNext(right)
  current := left-1
  for current != max {
    next := getNext(current+1)
    total += uint64(next-current)*uint64(next)
    span += next-current
    fmt.Fprintf(os.Stderr, "(%d - %d = %d) * %d\n", next, current,
        next-current, next)
    if next < current {
      fmt.Fprintf(os.Stderr, "%d < %d\n", next, current)
      break
    }
    current = next
    fmt.Fprintf(os.Stderr, "  %d\n", total)
  }
  fmt.Fprintf(os.Stderr, "span = %d, right-left+1 = %d\n", span, right-left+1)
  writer.WriteString(fmt.Sprintf("%d\n", total))
}


Mancala is a game famous in the Middle East. It is played on a board that consists of 14 holes.   Initially, each hole has $$$a_i$$$ stones. When a player makes a move, he chooses a hole which contains a positive number of stones. He takes all the stones inside it and then redistributes these stones one by one in the next holes in a counter-clockwise direction.Note that the counter-clockwise order means if the player takes the stones from hole $$$i$$$, he will put one stone in the $$$(i+1)$$$-th hole, then in the $$$(i+2)$$$-th, etc. If he puts a stone in the $$$14$$$-th hole, the next one will be put in the first hole.After the move, the player collects all the stones from holes that contain even number of stones. The number of stones collected by player is the score, according to Resli.Resli is a famous Mancala player. He wants to know the maximum score he can obtain after one move.

The only line contains 14 integers $$$a_1, a_2, \ldots, a_{14}$$$ ($$$0 \leq a_i \leq 10^9$$$) — the number of stones in each hole. It is guaranteed that for any $$$i$$$ ($$$1\leq i \leq 14$$$) $$$a_i$$$ is either zero or odd, and there is at least one stone in the board.

Output one integer, the maximum possible score after one move.

NoteIn the first test case the board after the move from the hole with $$$7$$$ stones will look like 1 2 2 0 0 0 0 0 0 0 1 1 1 1. Then the player collects the even numbers and ends up with a score equal to $$$4$$$.

package main

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

func main() {
	var line string
	var max int64
	var start [14]int64
	var end [14]int64
	reader := bufio.NewReader(os.Stdin)
	line, _ = reader.ReadString('\n')
	arrStartStrings := strings.Split(strings.TrimSpace(line), " ")
	for i, v := range arrStartStrings {
		start[i], _ = strconv.ParseInt(v, 10, 0)
	}
	for i := 0; i < 14; i++ {
		end[i] = igra(start, i)
	}
	for i := 0; i < 14; i++ {
		if max < end[i]{
			max=end[i]
		}
	}
	fmt.Println(max)
}

func igra(start [14]int64, i int) int64 {
	var n, addToAll, result int64
	n = start[i]
	start[i] = 0
	if n == 0 {
		return 0
	}
	addToAll = n / 14
	n = n % 14
	for i := 0; i < 14; i++ {
		start[i] += addToAll
	}
	for n != 0 {
		if i+1 == 14 {
			i = 0
		} else {
			i++
		}
		start[i]++
		n--
	}
	for i := 0; i < 14; i++ {
		if start[i]%2==0{
			result+=start[i]
		}
	}
	return result
}

package main

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

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 scanSlice(n int) []int64 {
	a := make([]int64, n)
	l, _ := reader.ReadString('\n')
	s := strings.Split(strings.TrimSpace(l), " ")
	for i := 0; i < n; i++ {
		a[i], _ = strconv.ParseInt(s[i], 10, 0)
	}
	return a
}

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

func main() {
	defer writer.Flush()

	a := scanSlice(14)

	maxcount := int64(0)
	for i := range a {
		if a[i] == 0 {
			continue
		}
		count, k := int64(0), a[i]
		a[i] = 0
		for j := range a {
			n := a[(i+j)%14] + k/14
			if (int64(j)-1+14)%14 < k%14 {
				n++
			}
			if n%2 == 0 {
				count += n
			}
		}
		maxcount, a[i] = max(maxcount, count), k
	}
	printF("%d", maxcount)
}

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 scanInt(a interface{})             { fmt.Fscanf(reader, "%d", a) }
func scanlnInt(a interface{})           { fmt.Fscanf(reader, "%d\n", a) }
func scanChar(a interface{})            { fmt.Fscanf(reader, "%c", a) }
func scanString(a interface{})          { fmt.Fscanf(reader, "%s", a) }

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

func main() {
	defer writer.Flush()

	a := make([]int64, 14)
	for i := range a {
		scanInt(&a[i])
	}
	maxcount := int64(0)
	for i := int64(0); i < 14; i++ {
		count, k := int64(0), a[i]
		a[i] = 0
		for j := int64(0); j < 14; j++ {
			n := a[(i+j)%14] + k/14
			if (j-1+14)%14 < k%14 {
				n++
			}
			if n%2 == 0 {
				count += n
			}
		}
		maxcount, a[i] = max(maxcount, count), k
	}
	printf("%d", maxcount)
}

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 scanInt(a interface{})             { fmt.Fscanf(reader, "%d", a) }
func scanlnInt(a interface{})           { fmt.Fscanf(reader, "%d\n", a) }
func scanChar(a interface{})            { fmt.Fscanf(reader, "%c", a) }
func scanString(a interface{})          { fmt.Fscanf(reader, "%s", a) }

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

func main() {
	defer writer.Flush()

	a := make([]int, 14)
	for i := range a {
		scanInt(&a[i])
	}
	maxcount := 0
	for i := range a {
		count, k := 0, a[i]
		a[i] = 0
		for j := range a {
			n := a[(i+j)%14] + k/14
			if (j-1+14)%14 < k%14 {
				n++
			}
			if n%2 == 0 {
				count += n
			}
		}
		maxcount, a[i] = max(maxcount, count), k
	}
	printf("%d", maxcount)
}

package main

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

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 scanSlice(n int) []int {
	a := make([]int, n)
	l, _ := reader.ReadString('\n')
	s := strings.Split(strings.TrimSpace(l), " ")
	for i := 0; i < n; i++ {
		a[i], _ = strconv.Atoi(s[i])
	}
	return a
}

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

func main() {
	defer writer.Flush()

	a := scanSlice(14)

	maxcount := 0
	for i := range a {
		if a[i] == 0 {
			continue
		}
		count, k := 0, a[i]
		a[i] = 0
		for j := range a {
			n := a[(i+j)%14] + k/14
			if (j-1+14)%14 < k%14 {
				n++
			}
			if n%2 == 0 {
				count += n
			}
		}
		maxcount, a[i] = max(maxcount, count), k
	}
	printF("%d", maxcount)
}

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 scanInt(a interface{})             { fmt.Fscanf(reader, "%d", a) }
func scanlnInt(a interface{})           { fmt.Fscanf(reader, "%d\n", a) }
func scanlnSInt(n int) []int {
	s := make([]int, n)
	for i := 0; i < n-1; i++ {
		fmt.Fscanf(reader, "%d ", &s[i])
	}
	fmt.Fscanf(reader, "%d\n", &s[n-1])
	return s
}
func scanChar(a interface{})   { fmt.Fscanf(reader, "%c", a) }
func scanString(a interface{}) { fmt.Fscanf(reader, "%s", a) }

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

func main() {
	defer writer.Flush()

	a := scanlnSInt(14)

	maxcount := 0
	for i := range a {
		if a[i] == 0 {
			continue
		}
		count, k := 0, a[i]
		a[i] = 0
		for j := range a {
			n := a[(i+j)%14] + k/14
			if (j-1+14)%14 < k%14 {
				n++
			}
			if n%2 == 0 {
				count += n
			}
		}
		maxcount, a[i] = max(maxcount, count), k
	}
	printf("%d", maxcount)
}

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 scanInt(a interface{})             { fmt.Fscanf(reader, "%d", a) }
func scanlnInt(a interface{})           { fmt.Fscanf(reader, "%d\n", a) }
func scanChar(a interface{})            { fmt.Fscanf(reader, "%c", a) }
func scanString(a interface{})          { fmt.Fscanf(reader, "%s", a) }

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

func main() {
	defer writer.Flush()

	a := make([]int, 14)
	for i := range a {
		scanInt(&a[i])
	}
	maxcount := 0
	for i := range a {
		if a[i] == 0 {
			continue
		}
		count, k := 0, a[i]
		a[i] = 0
		for j := range a {
			n := a[(i+j)%14] + k/14
			if (j-1+14)%14 < k%14 {
				n++
			}
			if n%2 == 0 {
				count += n
			}
		}
		maxcount, a[i] = max(maxcount, count), k
	}
	printf("%d", maxcount)
}

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 scanInt(a interface{})             { fmt.Fscanf(reader, "%d", a) }
func scanlnInt(a interface{})           { fmt.Fscanf(reader, "%d\n", a) }
func scanlnSInt(n int) []int {
	s := make([]int, n)
	for i := 0; i < n-1; i++ {
		fmt.Fscanf(reader, "%d", &s[i])
	}
	fmt.Fscanf(reader, "%d\n", &s[n-1])
	return s
}
func scanChar(a interface{})   { fmt.Fscanf(reader, "%c", a) }
func scanString(a interface{}) { fmt.Fscanf(reader, "%s", a) }

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

func main() {
	defer writer.Flush()

	a := scanlnSInt(14)

	maxcount := 0
	for i := range a {
		if a[i] == 0 {
			continue
		}
		count, k := 0, a[i]
		a[i] = 0
		for j := range a {
			n := a[(i+j)%14] + k/14
			if (j-1+14)%14 < k%14 {
				n++
			}
			if n%2 == 0 {
				count += n
			}
		}
		maxcount, a[i] = max(maxcount, count), k
	}
	printf("%d", maxcount)
}


Luba is surfing the Internet. She currently has n opened tabs in her browser, indexed from 1 to n from left to right. The mouse cursor is currently located at the pos-th tab. Luba needs to use the tabs with indices from l to r (inclusive) for her studies, and she wants to close all the tabs that don't belong to this segment as fast as possible.Each second Luba can either try moving the cursor to the left or to the right (if the cursor is currently at the tab i, then she can move it to the tab max(i - 1, a) or to the tab min(i + 1, b)) or try closing all the tabs to the left or to the right of the cursor (if the cursor is currently at the tab i, she can close all the tabs with indices from segment [a, i - 1] or from segment [i + 1, b]). In the aforementioned expressions a and b denote the minimum and maximum index of an unclosed tab, respectively. For example, if there were 7 tabs initially and tabs 1, 2 and 7 are closed, then a = 3, b = 6.What is the minimum number of seconds Luba has to spend in order to leave only the tabs with initial indices from l to r inclusive opened?

The only line of input contains four integer numbers n, pos, l, r (1 ≤ n ≤ 100, 1 ≤ pos ≤ n, 1 ≤ l ≤ r ≤ n) — the number of the tabs, the cursor position and the segment which Luba needs to leave opened.

Print one integer equal to the minimum number of seconds required to close all the tabs outside the segment [l, r].

NoteIn the first test Luba can do the following operations: shift the mouse cursor to the tab 2, close all the tabs to the left of it, shift the mouse cursor to the tab 3, then to the tab 4, and then close all the tabs to the right of it.In the second test she only needs to close all the tabs to the right of the current position of the cursor.In the third test Luba doesn't need to do anything.

package main

import (
	"fmt"
	// "os"
	)

const INF = 0x3f3f3f3f

var n, m, tot int

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

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

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

func main() {
	// fd, _ := os.Open("in.txt")
	// os.Stdin = fd
	var T int = 1
	// fmt.Scanf("%d", &T)
	for ci:=1; ci<=T; ci++ {
		var l, r int
		fmt.Scanf("%d %d %d %d\n", &n, &m, &l, &r)
		// fmt.Printf("Case #%d: ", ci)
		if l==1 && r==n {
			fmt.Println(0)
		} else if l==1 {
			if m<=r {
				fmt.Println(1+r-m)
			} else {
				fmt.Println(1-r+m)
			}
		} else if r==n {
			if m<l {
				fmt.Println(1+l-m)
			} else {
				fmt.Println(1-l+m)
			}
		} else {
			mid := (l+r)>>1
			if m<=mid {
				fmt.Println(r+2-l+abs(m-l))
			} else {
				fmt.Println(r+2-l+abs(r-m))
			}
		}
	}
}

// http://codeforces.com/contest/915/problem/B
package main

import "fmt"

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

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

// comentar que nem gente
func main() {
	var n, pos, l, r int
	fmt.Scanf("%d %d %d %d\n", &n, &pos, &l, &r)
	if l == 1 && r == n {
		fmt.Printf("0\n")
	} else if l == 1 {
		fmt.Printf("%d\n", abs(r - pos) + 1)
	} else if r == n {
		fmt.Printf("%d\n", abs(l - pos) + 1)
	} else {
		if abs(l - pos) < abs(r - pos) {
			fmt.Printf("%d\n", abs(l - pos) + r - l + 2)
		} else {
			fmt.Printf("%d\n", abs(r - pos) + r - l + 2)
		}
	}
}

package main

import (
    "fmt"
    "math"
)

func main() {
    var n, pos, l, r int
    fmt.Scan(&n, &pos, &l, &r)
    var ans int
    if l == 1 {
        if r == n {
            ans = 0
        } else {
            ans = int(math.Abs(float64(pos - r))) + 1
        }
    } else if r == n {
        ans = int(math.Abs(float64(pos - l))) + 1
    } else {
        var diff int = int(math.Abs(float64(l - r)))
        var ans1 int = int(math.Abs(float64(pos - l))) + diff + 2
        var ans2 int = int(math.Abs(float64(pos - r))) + diff + 2
        if ans1 < ans2 {
            ans = ans1
        } else {
            ans = ans2
        }
    }
    fmt.Println(ans)
}

package main

/*
	If we breakdown the problem, we will found 3 cases:
	- if non-studies tabs exist both in left & right of studies tabs: 1, [2, 3, 4, 5], 6
	- if non-studies tabs exist only in right of studies tabs: [1, 2, 3], 4, 5, 6
	- if non-studies tabs exist only in left of studies tabs: 1, 2, 3, [4, 5, 6]

	For the first case the minimum number of seconds would be:
		min(abs(pos-l), abs(pos-r)) + 1 + abs(l-r) + 1
	In the second case:
		abs(pos-r) + 1
	In the third case:
		abs(pos-l) + 1
*/

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

func main() {
	var n, pos, l, r int
	stdin := bufio.NewReader(os.Stdin)
	fmt.Fscanf(stdin, "%d %d %d %d", &n, &pos, &l, &r)
	fmt.Println(solve(n, pos, l, r))
}

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

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

func solve(n, pos, l, r int) int {
	isLeftExist := abs(1-l) > 0
	isRightExist := abs(r-n) > 0
	if isLeftExist && isRightExist {
		return min(abs(pos-l), abs(pos-r)) + 1 + abs(l-r) + 1
	} else if isRightExist {
		return abs(pos-r) + 1
	} else if isLeftExist {
		return abs(pos-l) + 1
	}
	return 0
}

package main

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

func main() {
	var n, pos, l, r int
	stdin := bufio.NewReader(os.Stdin)
	fmt.Fscanf(stdin, "%d %d %d %d", &n, &pos, &l, &r)
	fmt.Println(solve(n, pos, l, r))
}

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

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

func solve(n, pos, l, r int) int {
	isLeftExist := abs(1-l) > 0
	isRightExist := abs(r-n) > 0
	if isLeftExist && isRightExist {
		return min(abs(pos-l), abs(pos-r)) + 1 + abs(l-r) + 1
	} else if isRightExist {
		return abs(pos-r) + 1
	} else if isLeftExist {
		return abs(pos-l) + 1
	}
	return 0
}

package main

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

func solve() {
	n := readInt()
	pos := readInt()
	l := readInt()
	r := readInt()
	if l == 1 && r == n {
		fmt.Println(0)
	} else if l == 1 {
		fmt.Println(abs(r-pos) + 1)
	} else if r == n {
		fmt.Println(abs(pos-l) + 1)
	} else {
		fmt.Println(min(abs(pos-l)+1+r-l+1, abs(r-pos)+1+r-l+1))
	}
}

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

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

var scanner *bufio.Scanner

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

// 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 abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func min(i, j int) int {
	if i < j {
		return i
	}
	return j
}

func main() {
	var n, pos, l, r int
	fmt.Scan(&n, &pos, &l, &r)

	goright := abs(r - pos)
	goleft := abs(l - pos)
	if l == 1 && r == n {
		fmt.Println(0)
	} else if l == 1 {
		fmt.Println(goright + 1)
	} else if r == n {
		fmt.Println(goleft + 1)
	} else {
		if pos < l {
			fmt.Println(goright + 2)
		} else if pos > r {
			fmt.Println(goleft + 2)
		} else {
			fmt.Println(min(goleft, goright) + r - l + 2)
		}
	}
}

//	URL: http://codeforces.com/contest/915/problem/B
//	PROBLEM RESTATEMENT
//		Let x be an array 1 ... n.
//		Given an integer pos in the range [1, n]
//		Two operations: move, and close.
//		The move operation either increment or decrements pos in range [1, n]
//		Close operator removes either (pos, n] or [1, pos) from the set.
//		Determine minimum number of operations needed to remove all elements
//		from x except for [l, r].
//	SETUP
//		There are three cases:
//			1) l = 1 and r = n.
//			2) l = 1 and r != n, by symmetry, also: l != 1 and r = n.
//			3) l != 1 and r != n.
//	CASES
//		1) We terminate in 0 operations - solved state.
//		2) Need to fix one interval: either (r, n] or [1, l). This cost is
//		   the distance from pos to r or pos to l, and one close() operation.
//		3) Need to fix both of the aforementioned intervals. We traverse to
//		   whichever interval is closer (r or l), close(), move r - l to the
//		   other interval, and close() again.

package main

import "fmt"

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

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

func solve(n int, pos int, l int, r int) int {
	if l == 1 && r == n {
		return 0
	} else if l == 1 && r != n {
		return abs(r-pos) + 1
	} else if l != 1 && r == n {
		return abs(l-pos) + 1
	} else {
		return r - l + min(abs(l-pos), abs(r-pos)) + 2
	}
}

func main() {
	var n, pos, l, r int
	fmt.Scan(&n, &pos, &l, &r)
	fmt.Println(solve(n, pos, l, r))
}

package main

import (
	"fmt"
	// "os"
	)

const INF = 0x3f3f3f3f

var n, m, tot int

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

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

func main() {
	// fd, _ := os.Open("in.txt")
	// os.Stdin = fd
	var T int = 1
	// fmt.Scanf("%d", &T)
	for ci:=1; ci<=T; ci++ {
		var l, r int
		fmt.Scanf("%d %d %d %d\n", &n, &m, &l, &r)
		// fmt.Printf("Case #%d: ", ci)
		if l==1 && r==n {
			fmt.Println(0)
		} else if l==1 {
			if m<=r {
				fmt.Println(1+r-m)
			} else {
				fmt.Println(1-r+m)
			}
		} else if r==n {
			if m<l {
				fmt.Println(1+l-m)
			} else {
				fmt.Println(1-l+m)
			}
		} else {
			mid := (l+r)>>1
			if m<=mid {
				fmt.Println(r+2-l+m-l)
			} else {
				fmt.Println(r+2-l+r-m)
			}
		}
	}
}

package main

import (
	"fmt"
	// "os"
	)

const INF = 0x3f3f3f3f

var n, m, tot int

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

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

func main() {
	// fd, _ := os.Open("in.txt")
	// os.Stdin = fd
	var T int = 1
	// fmt.Scanf("%d", &T)
	for ci:=1; ci<=T; ci++ {
		var l, r int
		fmt.Scanf("%d %d %d %d\n", &n, &m, &l, &r)
		// fmt.Printf("Case #%d: ", ci)
		if l==1 && r==n {
			fmt.Println(0)
		} else if l==1 {
			if m<=r {
				fmt.Println(1+r-m)
			} else {
				fmt.Println(1-r+m)
			}
		} else if r==n {
			if m<l {
				fmt.Println(1+l-m)
			} else {
				fmt.Println(1-l+m)
			}
		} else {
			mid := l+r>>1
			if m<=mid {
				fmt.Println(r+2-l+m-l)
			} else {
				fmt.Println(r+2-l+r-m)
			}
		}
	}
}

// http://codeforces.com/contest/915/problem/B
package main

import "fmt"

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

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

// comentar que nem gente
func main() {
	var n, pos, l, r int
	fmt.Scanf("%d %d %d %d\n", &n, &pos, &l, &r)
	if l == 1 && r == n {
		fmt.Printf("0\n")
	} else if l == 1 {
		fmt.Printf("%d\n", abs(r - pos) + 1)
	} else if r == n {
		fmt.Printf("%d\n", abs(l - pos) + 2)
	} else {
		if abs(l - pos) < abs(r - pos) {
			fmt.Printf("%d\n", abs(l - pos) + r - l + 2)
		} else {
			fmt.Printf("%d\n", abs(r - pos) + r - l + 2)
		}
	}
}

package main

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

func solve() {
	n := readInt()
	pos := readInt()
	l := readInt()
	r := readInt()
	if l == 1 && r == n {
		fmt.Println(0)
	} else if l == 1 {
		fmt.Println(r - pos + 1)
	} else if r == n {
		fmt.Println(pos - l + 1)
	} else {
		fmt.Println(min(pos-l+1+r-l+1, r-pos+1+r-l+1))
	}
}

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

var scanner *bufio.Scanner

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

// 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
}


Tonight is brain dinner night and all zombies will gather together to scarf down some delicious brains. The artful Heidi plans to crash the party, incognito, disguised as one of them. Her objective is to get away with at least one brain, so she can analyze the zombies' mindset back home and gain a strategic advantage.They will be N guests tonight: N - 1 real zombies and a fake one, our Heidi. The living-dead love hierarchies as much as they love brains: each one has a unique rank in the range 1 to N - 1, and Heidi, who still appears slightly different from the others, is attributed the highest rank, N. Tonight there will be a chest with brains on display and every attendee sees how many there are. These will then be split among the attendees according to the following procedure:The zombie of the highest rank makes a suggestion on who gets how many brains (every brain is an indivisible entity). A vote follows. If at least half of the attendees accept the offer, the brains are shared in the suggested way and the feast begins. But if majority is not reached, then the highest-ranked zombie is killed, and the next zombie in hierarchy has to make a suggestion. If he is killed too, then the third highest-ranked makes one, etc. (It's enough to have exactly half of the votes – in case of a tie, the vote of the highest-ranked alive zombie counts twice, and he will of course vote in favor of his own suggestion in order to stay alive.)You should know that zombies are very greedy and sly, and they know this too – basically all zombie brains are alike. Consequently, a zombie will never accept an offer which is suboptimal for him. That is, if an offer is not strictly better than a potential later offer, he will vote against it. And make no mistake: while zombies may normally seem rather dull, tonight their intellects are perfect. Each zombie's priorities for tonight are, in descending order:   survive the event (they experienced death already once and know it is no fun),  get as many brains as possible. Heidi goes first and must make an offer which at least half of the attendees will accept, and which allocates at least one brain for Heidi herself.What is the smallest number of brains that have to be in the chest for this to be possible?

The only line of input contains one integer: N, the number of attendees (1 ≤ N ≤ 109).

Output one integer: the smallest number of brains in the chest which allows Heidi to take one brain home.

package main

import "fmt"

func main(){
	var n int
	fmt.Scanf("%d", &n)
	if n & 1 == 1 {
		fmt.Printf("%d", (n + 1) >> 1)
	}else{
		fmt.Printf("%d", n >> 1)
	}
}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')
	text = strings.TrimRight(text, "\r\n")
	s := strings.Split(text, " ")

	c, _ := strconv.Atoi(s[0])
	if (c % 2) == 1 {
		c += 1
	}
	fmt.Println(c / 2)
	//x, _ := strconv.ParseInt(s[1], 10, 64)

}

package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	text, _ := reader.ReadString('\n')
	text = strings.TrimRight(text, "\r\n")
	s := strings.Split(text, " ")

	c, _ := strconv.Atoi(s[0])
	fmt.Println(math.Ceil(float64(c) / 2.0))
	//x, _ := strconv.ParseInt(s[1], 10, 64)

}


Not so long ago company R2 bought company R1 and consequently, all its developments in the field of multicore processors. Now the R2 laboratory is testing one of the R1 processors.The testing goes in n steps, at each step the processor gets some instructions, and then its temperature is measured. The head engineer in R2 is keeping a report record on the work of the processor: he writes down the minimum and the maximum measured temperature in his notebook. His assistant had to write down all temperatures into his notebook, but (for unknown reasons) he recorded only m.The next day, the engineer's assistant filed in a report with all the m temperatures. However, the chief engineer doubts that the assistant wrote down everything correctly (naturally, the chief engineer doesn't doubt his notes). So he asked you to help him. Given numbers n, m, min, max and the list of m temperatures determine whether you can upgrade the set of m temperatures to the set of n temperatures (that is add n - m temperatures), so that the minimum temperature was min and the maximum one was max.

The first line contains four integers n, m, min, max (1 ≤ m < n ≤ 100; 1 ≤ min < max ≤ 100). The second line contains m space-separated integers ti (1 ≤ ti ≤ 100) — the temperatures reported by the assistant. Note, that the reported temperatures, and the temperatures you want to add can contain equal temperatures.

If the data is consistent, print 'Correct' (without the quotes). Otherwise, print 'Incorrect' (without the quotes).

NoteIn the first test sample one of the possible initial configurations of temperatures is [1, 2].In the second test sample one of the possible initial configurations of temperatures is [2, 1, 3].In the third test sample it is impossible to add one temperature to obtain the minimum equal to 1 and the maximum equal to 3.

package main

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

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

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

  total, found, min, max := getI(), getI(), getI(), getI()
  foundMin, foundMax := false, false
  for i := 0; i < found; i++ {
    x := getI()
    if x < min || x > max {
      writer.WriteString("Incorrect\n")
      return
    }
    if x == min {
      foundMin = true
    } else if x == max {
      foundMax = true
    }
  }
  result := "Correct"
  if !foundMin && !foundMax && total-found == 1 {
    result = "Incorrect"
  }
  writer.WriteString(fmt.Sprintf("%s\n", result))
}

package main

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

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

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

  total, found, min, max := getI(), getI(), getI(), getI()
  foundMin, foundMax := false, false
  for i := 0; i < found; i++ {
    x := getI()
    if x == min {
      foundMin = true
    } else if x == max {
      foundMax = true
    }
  }
  result := "Correct"
  if !foundMin && !foundMax && total-found == 1 {
    result = "Incorrect"
  }
  writer.WriteString(fmt.Sprintf("%s\n", result))
}


Iahub is training for the IOI. What is a better way to train than playing a Zuma-like game? There are n balls put in a row. Each ball is colored in one of k colors. Initially the row doesn't contain three or more contiguous balls with the same color. Iahub has a single ball of color x. He can insert his ball at any position in the row (probably, between two other balls). If at any moment there are three or more contiguous balls of the same color in the row, they are destroyed immediately. This rule is applied multiple times, until there are no more sets of 3 or more contiguous balls of the same color. For example, if Iahub has the row of balls [black, black, white, white, black, black] and a white ball, he can insert the ball between two white balls. Thus three white balls are destroyed, and then four black balls become contiguous, so all four balls are destroyed. The row will not contain any ball in the end, so Iahub can destroy all 6 balls.Iahub wants to destroy as many balls as possible. You are given the description of the row of balls, and the color of Iahub's ball. Help Iahub train for the IOI by telling him the maximum number of balls from the row he can destroy.

The first line of input contains three integers: n (1 ≤ n ≤ 100), k (1 ≤ k ≤ 100) and x (1 ≤ x ≤ k). The next line contains n space-separated integers c1, c2, ..., cn (1 ≤ ci ≤ k). Number ci means that the i-th ball in the row has color ci. It is guaranteed that the initial row of balls will never contain three or more contiguous balls of the same color.

Print a single integer — the maximum number of balls Iahub can destroy.

package main

import (
	"bufio"
	"errors"
	"flag"
	"fmt"
	"log"
	"os"
	"strconv"
	"time"
)

// ******************************** CODE STARTS ********************************

var ()

func getAns(array []int) int {
	// logln("lol")
	// logln(array)
	n := len(array)
	res := 0
	for {
		count := 0
		left := -1
		sum := -1

		for i := 0; i < n; i++ {
			if array[i] == -1 {
				continue
			}

			left = i
			sum = 1
			break
		}

		if left != -1 {
			for j := left + 1; j < n; j++ {
				if array[j] == -1 {
					continue
				}

				if array[left] == array[j] {
					sum++
				} else {
					if sum >= 3 {
						for i := left; i < j; i++ {
							array[i] = -1
						}
						count = sum
						sum = 0
						break
					}

					left = j
					sum = 1
				}
				// logln(array)
			}

			if sum >= 3 {
				for i := left; i < n; i++ {
					array[i] = -1
				}
				count = sum
			}
			// logln(array)
		}

		if count == 0 {
			break
		}
		res += count
		count = 0
	}
	return res - 1
}

func solve() {
	n := readInt()
	_ = readInt()
	x := readInt()
	array := make([]int, n)
	for i := 0; i < n; i++ {
		array[i] = readInt()
	}

	best := 0
	for j := 0; j <= n; j++ {
		var newArray []int
		if j > 0 {
			newArray = append(newArray, array[:j]...)
		}
		newArray = append(newArray, x)
		if j < n {
			newArray = append(newArray, array[j:]...)
		}
		best = maxInt(best, getAns(newArray))
	}
	printInt(best)
	printLine()
}

// ********************************* CODE ENDS *********************************

// IO.

var (
	scanner *bufio.Scanner
	writer  *bufio.Writer
	logger  *log.Logger
)

func main() {
	local := flag.Bool("local", false, "Equals true, if run is local.")
	flag.Parse()

	var (
		input  *os.File
		output *os.File
	)

	if *local {
		startTime := time.Now()
		defer func() {
			println(fmt.Sprintf("Time: %.5fs", time.Since(startTime).Seconds()))
		}()
		input, _ = os.Open("/home/outside/coding/workspace/go/io/input.txt")
		output, _ = os.Create("/home/outside/coding/workspace/go/io/output.txt")
		logger = log.New(output, "log: ", 0)
	} else {
		input = os.Stdin
		output = os.Stdout
		// input, _ = os.Open("")
		// output, _ = os.Create("")
	}
	defer input.Close()
	defer output.Close()

	scanner = bufio.NewScanner(input)
	scanner.Split(bufio.ScanWords)

	writer = bufio.NewWriter(output)
	defer writer.Flush()

	solve()
}

// Read.

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

func readLine() string {
	scanner.Split(bufio.ScanLines)
	defer scanner.Split(bufio.ScanWords)
	return readString()
}

func readInt() int {
	ans, _ := strconv.ParseInt(readString(), 10, 0)
	return int(ans)
}

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

func readFloat64() float64 {
	ans, _ := strconv.ParseFloat(readString(), 64)
	return ans
}

// Write.

func printString(value string) {
	writer.WriteString(value)
}

func printLine() {
	printString("\n")
}

func printInt(value int) {
	printString(strconv.FormatInt(int64(value), 10))
}

func printInt64(value int64) {
	printString(strconv.FormatInt(value, 10))
}

func printFLoat64(value float64) {
	printString(strconv.FormatFloat(value, 'f', 20, 64))
}

// Log.

func logln(value ...interface{}) {
	writer.Flush()
	logger.Println(value...)
}
func logf(format string, value ...interface{}) {
	writer.Flush()
	logger.Printf(format, value...)
}

// Tuple

type Tuple struct {
	a, b int
}

func (p Tuple) Equals(key Key) bool {
	return p.a == key.(Tuple).a
}

func (p Tuple) Less(key Key) bool {
	return p.a < key.(Tuple).a
}

type TupleSlice []Tuple

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

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

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

// Min, max, abs.

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

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

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

func maxInt64(a, b int64) int64 {
	if a > b {
		return a
	} else {
		return b
	}
}

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

func absInt64(a int64) int64 {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

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

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

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

// Set Key interface implementations.

type Int int

func (p Int) Equals(key Key) bool {
	return int(p) == int(key.(Int))
}

func (p Int) Less(key Key) bool {
	return int(p) < int(key.(Int))
}

// Set.

type Key interface {
	Equals(key Key) bool
	Less(key Key) bool
}

type node struct {
	key   Key
	left  *node
	right *node
}

func newNode(key Key) *node {
	return &node{key, nil, nil}
}

type SplayTree struct {
	root *node
	tmp  *node
	len  int
}

func NewSplayTree() *SplayTree {
	return &SplayTree{nil, newNode(nil), 0}
}

func rotateLeft(x, p *node) {
	p.right = x.left
	x.left = p
}

func rotateRight(x, p *node) {
	p.left = x.right
	x.right = p
}

func (p *SplayTree) splay(x *node, key Key) *node {
	if x == nil {
		return nil
	}

	left := p.tmp
	right := p.tmp

	for {
		if key.Less(x.key) {
			y := x.left
			if y == nil {
				break
			}
			if key.Less(y.key) { // zig-zig
				rotateRight(y, x)
				x = y
				if x.left == nil {
					break
				}
			}
			// link right
			right.left = x
			right = x
			// move left
			x = x.left
		} else if x.key.Less(key) {
			y := x.right
			if y == nil {
				break
			}
			if y.key.Less(key) { // zig-zig
				rotateLeft(y, x)
				x = y
				if x.right == nil {
					break
				}
			}
			// link left
			left.right = x
			left = x
			// move right
			x = x.right
		} else {
			break
		}
	}

	left.right = x.left
	right.left = x.right
	x.left = p.tmp.right
	x.right = p.tmp.left

	return x
}

// left <= key < right
func (p *SplayTree) split(key Key) (left, right *node) {
	p.root = p.splay(p.root, key)
	if p.root.key.Equals(key) || p.root.key.Less(key) {
		right := p.root.right
		p.root.right = nil
		return p.root, right
	} else {
		left := p.root.left
		p.root.left = nil
		return left, p.root
	}
}

// keys from left tree must be less then keys from right tree
func (p *SplayTree) join(left, right *node) *node {
	if left == nil {
		return right
	} else if right == nil {
		return left
	}
	left = p.splay(left, right.key)
	left.right = right
	return left
}

type Set interface {
	Len() int
	Insert(key Key) error
	Find(key Key) bool
	Remove(key Key) error
}

func NewSet() Set {
	return Set(NewSplayTree())
}

func (p *SplayTree) Len() int {
	return p.len
}

func (p *SplayTree) Insert(key Key) error {
	if p.root == nil {
		p.root = newNode(key)
		p.len++
	} else {
		p.root = p.splay(p.root, key)
		if p.root.key.Equals(key) {
			return errors.New("Such key already exists")
		} else {
			left, right := p.split(key)
			p.root = newNode(key)
			p.root.left = left
			p.root.right = right
			p.len++
		}
	}
	return nil
}

func (p *SplayTree) Find(key Key) bool {
	if p.root == nil {
		return false
	}
	p.root = p.splay(p.root, key)
	return p.root.key.Equals(key)
}

func (p *SplayTree) Remove(key Key) error {
	p.root = p.splay(p.root, key)
	if p.root == nil || !p.root.key.Equals(key) {
		return errors.New("Such key doesn't exist")
	}
	p.root = p.join(p.split(key))
	return nil
}

package main

import "fmt"

// Retorna slice de slices com as duplas retiradas.
func possiveisJogadas(row []int, num int, x int) [][]int {
	duplas := make([][2]int, 0)

	for i := 0; i+1 <= num-1; i++ {
		if row[i] == x && row[i] == row[i+1] {
			duplas = append(duplas, [2]int{i, i + 1})
		}
	}

	possibilidades := make([][]int, len(duplas))

	for i, v := range duplas {
		copia := make([]int, num)
		copy(copia, row)
		x, y := v[0], v[1]

		possibilidades[i] = append(copia[:x], copia[y+1:]...)

	}

	return possibilidades
}

// Remove um range de um array. [x, y] != [x, y)
func removerElementos(row *[]int, x, y int) {
	*row = append((*row)[:x], (*row)[y+1:]...)
}

func limparRow(row []int) []int {
	i := 1
	grupo := 1
	grupoAchado := false
	for {
		if i >= len(row) {
			if grupo >= 3 {
				removerElementos(&row, i-grupo, i-1)
			}
			break
		}

		if row[i] == row[i-1] {
			grupo++
			if grupo >= 3 {
				grupoAchado = true
			}
		} else {
			if grupoAchado {
				removerElementos(&row, i-grupo, i-1)
				i = 0
				grupoAchado = false

			}
			grupo = 1
		}

		i++
	}

	return row
}

func main() {
	// len(row), num de cores, cor escolhida pelo player.
	var num, k, x int
	fmt.Scan(&num, &k, &x)

	// Criar slice que representa a row.
	row := make([]int, num)
	for i := 0; i < num; i++ {
		fmt.Scan(&row[i])
	}

	// Copia e algoritmos.
	jogadas := possiveisJogadas(row, num, x)

	maior := 0
	for _, jogada := range jogadas {
		cont := num - len(limparRow(jogada))
		if cont > maior {
			maior = cont
		}
	}
	fmt.Println(maior)
}

package main

import "fmt"

// Retorna slice de slices com as duplas retiradas.
func possiveisJogadas(row []int, num int, x int) [][]int {
	duplas := make([][2]int, 0)

	for i := 0; i+1 <= num-1; i++ {
		if row[i] == x && row[i] == row[i+1] {
			duplas = append(duplas, [2]int{i, i + 1})
		}
	}

	possibilidades := make([][]int, len(duplas))

	for i, v := range duplas {
		copia := make([]int, num)
		copy(copia, row)
		x, y := v[0], v[1]

		possibilidades[i] = append(copia[:x], copia[y+1:]...)

	}

	return possibilidades
}

// Remove um range de um array. [x, y] != [x, y)
func removerElementos(row *[]int, x, y int) {
	*row = append((*row)[:x], (*row)[y+1:]...)
}

func limparRow(row []int) []int {
	i := 1
	grupo := 1
	grupoAchado := false
	for {
		if i >= len(row) {
			if grupo >= 3 {
				removerElementos(&row, i-grupo, i-1)
			}
			break
		}

		if row[i] == row[i-1] {
			grupo++
			if grupo >= 3 {
				grupoAchado = true
			}
		} else {
			if grupoAchado {
				removerElementos(&row, i-grupo, i-1)
				i = 0
				grupoAchado = false

			}
			grupo = 1
		}

		i++
	}

	return row
}

func main() {
	// len(row), num de cores, cor escolhida pelo player.
	var num, k, x int
	fmt.Scan(&num, &k, &x)

	// Criar slice que representa a row.
	row := make([]int, num)
	for i := 0; i < num; i++ {
		fmt.Scan(&row[i])
	}

	// Copia e algoritmos.
	jogadas := possiveisJogadas(row, num, x)
	if len(jogadas) == 0 {
		fmt.Println(0)
	}

	maior := 0
	for _, jogada := range jogadas {
		cont := num - len(limparRow(jogada))
		if cont > maior {
			maior = cont
		}
	}
	fmt.Println(maior)
}


Igor K. always used to trust his favorite Kashpirovsky Antivirus. That is why he didn't hesitate to download the link one of his groupmates sent him via QIP Infinium. The link was said to contain "some real funny stuff about swine influenza". The antivirus had no objections and Igor K. run the flash application he had downloaded. Immediately his QIP Infinium said: "invalid login/password".Igor K. entered the ISQ from his additional account and looked at the info of his main one. His name and surname changed to "H1N1" and "Infected" correspondingly, and the "Additional Information" field contained a strange-looking binary code 80 characters in length, consisting of zeroes and ones. "I've been hacked" — thought Igor K. and run the Internet Exploiter browser to quickly type his favourite search engine's address.Soon he learned that it really was a virus that changed ISQ users' passwords. Fortunately, he soon found out that the binary code was actually the encrypted password where each group of 10 characters stood for one decimal digit. Accordingly, the original password consisted of 8 decimal digits.Help Igor K. restore his ISQ account by the encrypted password and encryption specification.

The input data contains 11 lines. The first line represents the binary code 80 characters in length. That is the code written in Igor K.'s ISQ account's info. Next 10 lines contain pairwise distinct binary codes 10 characters in length, corresponding to numbers 0, 1, ..., 9.

Print one line containing 8 characters — The password to Igor K.'s ISQ account. It is guaranteed that the solution exists.

package main

import "fmt"

func main() {
    var pass,code string
    fmt.Scan(&pass)
    digit := make(map[string]int)
    for i := 0; i < 10; i++ {
        fmt.Scan(&code)
        digit[code] = i
    }
    for i := 0; i < 8; i++ {
        a := pass[i*10:(i+1)*10]
        fmt.Print(digit[a])
    }
    fmt.Println()
}

package main

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

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()
  scanner.Scan()
  code := scanner.Text()
  digits := map[string]int{}
  for i := 0; i < 10; i++ {
    scanner.Scan()
    digits[scanner.Text()] = i
  }
  for i := 0; i < 8; i++ {
    digit := digits[code[10*i:10*(i+1)]]
    writer.WriteString(fmt.Sprintf("%d", digit))
  }
  writer.WriteString("\n")
}