require 'prime'
max = 10000
arr = (1 .. max).select{|i|Prime.instance.prime?(i)}
array = Array.new(max + 2){0}
for i in 0 ... arr.size
    if (arr[i] + arr[i] <= max + 1)
        array[arr[i] * 2] += 1
    end
    for j in (i + 1) ... arr.size
        if (arr[j] + arr[i] > max + 1)
            break
        else
            array[arr[j] + arr[i]] += 2
        end
    end
end
while (n = gets)
    puts array[n.to_i + 1]
end
