For problem statement at 2000-2999/2000-2099/2040-2049/2045/problemF.txt this is a correct solution, but verifier at 2000-2999/2000-2099/2040-2049/2045/verifierF.go ends with can you fix the verifier? ```go
package main
import (
"bufio"
"fmt"
"os"
"sort"
)
func solve() {
in := bufio.NewReader(os.Stdin)
out := bufio.NewWriter(os.Stdout)
defer out.Flush()
var T int
fmt.Fscan(in, &T)
for t := 0; t < T; t++ {
var N int64
var M, K int
fmt.Fscan(in, &N, &M, &K)
// Map to store A_i sums per row
rowSums := make(map[int64]int64)
for i := 0; i < M; i++ {
var r, c, a int64
fmt.Fscan(in, &r, &c, &a)
rowSums[r] += a
}
// Identify active rows
// An active row is one where sum(A_i) % (K+1) != 0
var activeRows []int64
mod := int64(K + 1)
for r, s := range rowSums {
if s%mod != 0 {
activeRows = append(activeRows, r)
}
}
sort.Slice(activeRows, func(i, j int) bool {
return activeRows[i] < activeRows[j]
})
if len(activeRows) == 0 {
fmt.Fprintln(out, "Kamu")
continue
}
// Collect events
// Events are P_j and P_j - K - 1
eventSet := make(map[int64]bool)
for _, p := range activeRows {
eventSet[p] = true
val := p - int64(K) - 1
if val >= 1 {
eventSet[val] = true
}
}
var events []int64
for e := range eventSet {
events = append(events, e)
}
sort.Slice(events, func(i, j int) bool {
return events[i] > events[j] // Descending
})
// Map to store F values of active rows
fVals := make(map[int64]int) // 1 for Win, 0 for Lose
lastZero := int64(-1) // -1 represents infinity
// Helper to find target
// Target is F[smallest active row > u + K]
// Since we iterate u downwards, we can maintain a pointer or use binary search
// Given M is small (2e5), binary search is fast enough
getTarget := func(u int64) int {
limit := u + int64(K)
// Find smallest active > limit
// activeRows is sorted ascending
idx := sort.Search(len(activeRows), func(i int) bool {
return activeRows[i] > limit
})
if idx < len(activeRows) {
p := activeRows[idx]
return fVals[p]
}
return 0 // No active row > limit means target is "End" -> 0 (Losing for opponent)
}
for k := 0; k < len(events); k++ {
curr := events[k]
// 1. Process point curr
target := getTarget(curr)
// F[curr] logic
var fCurr int
hasZeroInRange := false
if lastZero != -1 && lastZero <= curr+int64(K) {
hasZeroInRange = true
}
if hasZeroInRange {
fCurr = 1
} else {
if target == 0 {
fCurr = 1
} else {
fCurr = 0
}
}
if fCurr == 0 {
lastZero = curr
}
// If curr is an active row, store its F value
// We can check using binary search or map. Since activeRows is sorted, bs is ok.
idx := sort.Search(len(activeRows), func(i int) bool {
return activeRows[i] >= curr
})
if idx < len(activeRows) && activeRows[idx] == curr {
fVals[curr] = fCurr
}
// 2. Process interval (next, curr)
if k+1 < len(events) {
next := events[k+1]
low := next + 1
high := curr - 1
if low <= high {
// In this interval, target is constant
// Target is determined by looking at any point in range, e.g., high
// Actually, the events are constructed such that target is constant.
// Let's verify with high.
tInt := getTarget(high)
if tInt == 1 {
// We generate zeros
// First zero needed at z = min(high, lastZero - K - 1)
// If lastZero is -1 (infinity), then z = high.
var z int64
if lastZero == -1 {
z = high
} else {
req := lastZero - int64(K) - 1
if high < req {
z = high
} else {
z = req
}
}
if z >= low {
// We can plant at least one zero
// Number of zeros
count := (z - low) / int64(K+1)
newLast := z - count*int64(K+1)
lastZero = newLast
}
}
// If tInt == 0, f is always 1, lastZero doesn't change position (effectively moves further away)
}
}
}
// The answer is determined by the highest active row (P_1)
// activeRows is sorted ascending, so P_1 is activeRows[0]
// Wait, activeRows is sorted ascending? Yes.
// Wait, my event processing sorted events descending.
// The highest row is activeRows[0].
// We computed fVals[activeRows[0]].
// If 1 -> Anda wins. Else Kamu.
p1 := activeRows[0]
if fVals[p1] == 1 {
fmt.Fprintln(out, "Anda")
} else {
fmt.Fprintln(out, "Kamu")
}
}
}
func main() {
solve()
}
```