← Home
For problem statement at 0-999/500-599/540-549/546/problemC.txt this is a correct solution, but verifier at 0-999/500-599/540-549/546/verifierC.go ends with All tests passed can you fix the verifier? ```go
package main

import (
	"fmt"
)

func main() {
	var n, k1, k2, val int
	fmt.Scan(&n)

	fmt.Scan(&k1)
	d1 := make([]byte, 0, n)
	for i := 0; i < k1; i++ {
		fmt.Scan(&val)
		d1 = append(d1, byte(val))
	}

	fmt.Scan(&k2)
	d2 := make([]byte, 0, n)
	for i := 0; i < k2; i++ {
		fmt.Scan(&val)
		d2 = append(d2, byte(val))
	}

	seen := make(map[string]bool)
	fights := 0

	for {
		if len(d1) == 0 {
			fmt.Println(fights, 2)
			return
		}
		if len(d2) == 0 {
			fmt.Println(fights, 1)
			return
		}

		// State representation for cycle detection
		state := string(d1) + string(byte(0)) + string(d2)
		if seen[state] {
			fmt.Println("-1")
			return
		}
		seen[state] = true

		// Safety break for extremely long games (though map handles cycles)
		if fights > 1000000 {
			fmt.Println("-1")
			return
		}

		c1 := d1[0]
		d1 = d1[1:]
		c2 := d2[0]
		d2 = d2[1:]

		if c1 > c2 {
			d1 = append(d1, c2, c1)
		} else {
			d2 = append(d2, c1, c2)
		}
		fights++
	}
}
```