Use this to learn the idea, then write your own version.
1package main2 3import (4 "bufio"5 . "fmt"6 "io"7)8 910func CF1313B(_r io.Reader, _w io.Writer) {11 in := bufio.NewReader(_r)12 out := bufio.NewWriter(_w)13 defer out.Flush()14 15 solve := func() (ans1, ans2 int) {16 var n, x, y int17 Fscan(in, &n, &x, &y)18 if x > y {19 x, y = y, x20 }21 if y == 1 {22 return 1, 123 }24 25 if x >= n-1 {26 ans1 = y 27 } else {28 if x+y < n+1 {29 ans1 = 130 } else {31 remove := n - x - 132 ans1 = y - remove33 }34 }35 if x+y < n+1 {36 ans2 = x + y - 137 } else {38 ans2 = n39 }40 return41 }42 _ = solve43 44 solve2 := func() (ans1, ans2 int) {45 var n, x, y int46 Fscan(in, &n, &x, &y)47 if x+y <= n {48 return 1, x + y - 149 }50 if x+y < 2*n {51 return x + y - n + 1, n52 }53 return n, n54 }55 _ = solve256 57 var t int58 Fscan(in, &t)59 for _case := 1; _case <= t; _case++ {60 a, b := solve2()61 Fprintln(out, a, b)62 }63}64 656667686970717273747576777879808182838485868788899091func printTable(n int) {92 permutations := func(n, r int, do func(indexes []int)) {93 indexes := make([]int, n)94 for i := range indexes {95 indexes[i] = i + 196 }97 do(indexes[:r])98 cycles := make([]int, r)99 for i := range cycles {100 cycles[i] = n - i101 }102 for {103 i := r - 1104 for ; i >= 0; i-- {105 cycles[i]--106 if cycles[i] == 0 {107 tmp := indexes[i]108 copy(indexes[i:], indexes[i+1:])109 indexes[n-1] = tmp110 cycles[i] = n - i111 } else {112 j := cycles[i]113 indexes[i], indexes[n-j] = indexes[n-j], indexes[i]114 do(indexes[:r])115 break116 }117 }118 if i == -1 {119 return120 }121 }122 }123 min := func(a, b int) int {124 if a < b {125 return a126 }127 return b128 }129 max := func(a, b int) int {130 if a > b {131 return a132 }133 return b134 }135 136 getPlace := func(indexes1, indexes2 []int) (ans int) {137 score := indexes1[0] + indexes2[0]138 for i := 1; i < len(indexes1); i++ {139 if indexes1[i]+indexes2[i] <= score {140 ans++141 }142 }143 return ans + 1144 }145 146 for sum := 0; sum < 2*n-1; sum++ {147 for x := 0; x <= sum; x++ {148 y := sum - x149 xx, yy := x+1, y+1150 if xx > n || yy > n {151 continue152 }153 minPlace, maxPlace := int(1e9), 0154 permutations(n, n, func(indexes1 []int) {155 if indexes1[0] == xx {156 permutations(n, n, func(indexes2 []int) {157 if indexes2[0] == yy {158 p := getPlace(indexes1, indexes2)159 minPlace = min(minPlace, p)160 maxPlace = max(maxPlace, p)161 }162 })163 }164 })165 Println(xx+yy, xx, yy, minPlace, maxPlace)166 }167 }168}169 170171