const M = 7717; DIST = 17; MAX_N = 101010; var a: array[1..MAX_N] of integer; cntL, cntR: array[0..M-1] of integer; f: text; begin Assign(f, '27-140b.txt'); reset(f); var N: integer; readln(f, N); for var i := 1 to N do begin readln(f, a[i]); a[i] := a[i] mod M; if i > DIST then cntR[a[i]] += 1; end; var ans: int64 = 0; for var i := 1 to N do begin if i > DIST then cntL[a[i - DIST]] += 1; for var x := 0 to M - 1 do begin var y := (2 * M - x - a[i]) mod M; ans += cntL[x] * cntR[y]; end; if i + DIST <= N then cntR[a[i + DIST]] -= 1; end; writeln(ans); end.