← Home
```go
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	// Read N
	if !scanner.Scan() {
		return
	}
	n, _ := strconv.Atoi(scanner.Text())

	// Read array elements
	a := make([]int, n)
	for i := 0; i < n; i++ {
		scanner.Scan()
		val, _ := strconv.Atoi(scanner.Text())
		a[i] = val
	}

	// Constants based on constraints (a_i <= 10^5)
	const MAX = 100005
	cost := make([]int, MAX)
	count := make([]int, MAX)
	visited := make([]int, MAX)

	// Process each chemical
	for i := 0; i < n; i++ {
		x := a[i]
		curOps := 0
		token := i + 1

		// Generate all reachable numbers by halving then doubling
		for x > 0 {
			t := x
			dOps := 0
			// Try doubling from the current halved value
			for t < MAX {
				if visited[t] != token {
					visited[t] = token
					count[t]++
					cost[t] += curOps + dOps
				}
				t <<= 1
				dOps++
			}
			x >>= 1
			curOps++
		}
	}

	// Find the minimum operations for a target volume reachable by all
	minOps := int(^uint(0) >> 1) // Max int
	for i := 1; i < MAX; i++ {
		if count[i] == n {
			if cost[i] < minOps {
				minOps = cost[i]
			}
		}
	}

	fmt.Println(minOps)
}
```