forked from EndlessCheng/codeforces-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path988D.go
52 lines (48 loc) · 871 Bytes
/
988D.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"bufio"
. "fmt"
"io"
"sort"
)
// github.com/EndlessCheng/codeforces-go
func CF988D(_r io.Reader, _w io.Writer) {
in := bufio.NewReader(_r)
out := bufio.NewWriter(_w)
defer out.Flush()
var n int
Fscan(in, &n)
a := make([]int, n)
for i := range a {
Fscan(in, &a[i])
a[i] += 1e9
}
sort.Ints(a)
var ans []interface{}
o:
for i := 0; i < 31; i++ {
d := 1 << i
g := map[int][]int{}
for _, x := range a {
g[x%d] = append(g[x%d], x)
}
for _, xs := range g {
for j := 0; j < len(xs); {
b := []interface{}{}
for j0 := j; j < len(xs) && xs[j] == xs[j0]+(j-j0)*d; j++ {
b = append(b, xs[j]-1e9)
if len(b) == 3 {
ans = b
break o
}
}
if len(b) > len(ans) {
ans = b
}
}
}
}
Fprintln(out, len(ans))
Fprint(out, ans...)
}
//func main() { CF988D(os.Stdin, os.Stdout) }