local ffi = require("ffi") local C = ffi.C ffi.cdef[[ long long atoll(const char*); ]] local function lltonumber(str) return C.atoll(str) end local n = io.read("*n", "*l") local s = io.read() local a = {} for w in s:gmatch("%d+") do table.insert(a, lltonumber(w)) end table.sort(a) local len = {} for i = 1, n do len[i] = 0 end for i = n - 1, 1, -1 do if a[i] + 2LL == a[i + 1] then len[i] = len[i + 1] + 1 elseif i + 2 <= n and a[i] + 2LL == a[i + 2] then len[i] = len[i + 2] + 1 else len[i] = 0 end end local ret = n for i = 1, n - 1 do if a[i] + 1LL == a[i + 1] then ret = ret + 1 + len[i + 1] end end print(ret)