package main
import (
"bufio"
"fmt"
"os"
"sort"
"strconv"
"strings"
)
type Team struct {
name string
pts, gf, ga int
games int
}
type Stat struct {
name string
pts, gf, ga int
}
func cmp(a, b Stat) int {
if a.pts != b.pts {
if a.pts > b.pts {
return 1
}
return -1
}
gda := a.gf - a.ga
gdb := b.gf - b.ga
if gda != gdb {
if gda > gdb {
return 1
}
return -1
}
if a.gf != b.gf {
if a.gf > b.gf {
return 1
}
return -1
}
if a.name < b.name {
return 1
}
return -1
}
func main() {
in := bufio.NewReader(os.Stdin)
teams := map[string]*Team{}
getTeam := func(name string) *Team {
if t, ok := teams[name]; ok {
return t
}
t := &Team{name: name}
teams[name] = t
return t
}
for i := 0; i < 5; i++ {
var a, b, s string
if _, err := fmt.Fscan(in, &a, &b, &s); err != nil {
return
}
parts := strings.SplitN(s, ":", 2)
g1, _ := strconv.Atoi(parts[0])
g2, _ := strconv.Atoi(parts[1])
ta := getTeam(a)
tb := getTeam(b)
ta.games++
tb.games++
ta.gf += g1
ta.ga += g2
tb.gf += g2
tb.ga += g1
if g1 > g2 {
ta.pts += 3
} else if g1 < g2 {
tb.pts += 3
} else {
ta.pts++
tb.pts++
}
}
ber, ok := teams["BERLAND"]
if !ok {
fmt.Print("IMPOSSIBLE")
return
}
var opp *Team
var fixed []*Team
var allOther []*Team
for _, t := range teams {
if t.name == "BERLAND" {
continue
}
allOther = append(allOther, t)
if t.games == 2 {
opp = t
} else {
fixed = append(fixed, t)
}
}
if opp == nil {
fmt.Print("IMPOSSIBLE")
return
}
bgd0 := ber.gf - ber.ga
found := false
ansX, ansY := 0, 0
for d := 1; d <= 1000 && !found; d++ {
candMap := map[int]struct{}{0: {}}
pB := ber.pts + 3
gdB := bgd0 + d
for _, t := range fixed {
if pB == t.pts && gdB == t.gf-t.ga {
reqGF := t.gf
if !(ber.name < t.name) {
reqGF++
}
thr := reqGF - (ber.gf + d)
if thr > 0 {
candMap[thr] = struct{}{}
}
}
}
cands := make([]int, 0, len(candMap))
for y := range candMap {
cands = append(cands, y)
}
sort.Ints(cands)
for _, y := range cands {
bs := Stat{
name: ber.name,
pts: ber.pts + 3,
gf: ber.gf + y + d,
ga: ber.ga + y,
}
ahead := 0
for _, t := range allOther {
var ts Stat
if t.name == opp.name {
ts = Stat{
name: t.name,
pts: t.pts,
gf: t.gf + y,
ga: t.ga + y + d,
}
} else {
ts = Stat{
name: t.name,
pts: t.pts,
gf: t.gf,
ga: t.ga,
}
}
if cmp(ts, bs) == 1 {
ahead++
}
}
if ahead <= 1 {
ansX = y + d
ansY = y
found = true
break
}
}
}
if !found {
fmt.Print("IMPOSSIBLE")
return
}
fmt.Printf("%d:%d", ansX, ansY)
}