```go
package main
import "fmt"
func main() {
var n, a, b, c int64
fmt.Scan(&n, &a, &b, &c)
remainder := n % 4
if remainder == 0 {
fmt.Println(0)
return
}
need := 4 - remainder // need to buy 'need' more copybooks (1, 2, or 3)
// We can buy any combination of packs (1, 2, 3) to total exactly need, need+4, need+8, ...
// But since costs can vary, we try all combinations for buying exactly need mod 4 copybooks.
// We need to buy some number of copybooks k where k % 4 == need.
// k = x*1 + y*2 + z*3, and k % 4 == need.
// Since we want minimum cost, and packs are 1,2,3, we can try all combinations up to buying 3 of each type (since 4 of any type can be replaced optimally).
// Actually, let's think: the cheapest way to buy 4 copybooks is min(4a, 2b, a+c, b+a+a... etc).
// Cost of 4 copybooks: min(4*a, 2*b, a+c, b+a+a is 2a+b... wait let me enumerate)
// For 4: combinations: 4×1=4a, 2×2=2b, 1×1+1×3=a+c, 2×2... that's it? Also 1×1+1×1+1×2=2a+b, 1×2+1×2=2b (same), etc.
// Actually min cost for 4: min(4a, 2b, a+c, 2a+b)
// Simpler approach: try buying i copies of pack1, j copies of pack2, k copies of pack3
// where i+2j+3k ≡ need (mod 4) and i+2j+3k >= need
// We only need to try i,j,k from 0 to 3 each (since 4 of any can be "absorbed").
// Wait, but we also need to consider that buying more than 3 of something might still be optimal.
// Actually no: if we buy 4 single packs, that's 4a. We could instead buy 0 and save if 4a > alternatives.
// The key insight: we only need up to 3 of each pack type, because any multiple of 4 copybooks
// can be bought using the cheapest "4-copybook" combination.
// Let's just brute force: for i=0..3, j=0..3, k=0..3, if (i + 2j + 3k) % 4 == need,
// compute cost = i*a + j*b + k*c, take minimum.
var minCost int64 = 1<<62
for i := int64(0); i <= 3; i++ {
for j := int64(0); j <= 3; j++ {
for k := int64(0); k <= 3; k++ {
total := i + 2*j + 3*k
if total%4 == int64(need) {
cost := i*a + j*b + k*c
if cost < minCost {
minCost = cost
}
}
}
}
}
fmt.Println(minCost)
}
```