X, Y = gets.split.map(&:to_i) S = Math.sqrt(X).ceil if X == Y L = S else L = Math.sqrt(Y).ceil end counter = Hash.new(0) S.upto(L) do |x| v = x ** 2 next if v < X next if Y < v counter[v] += 1 end L.times do |y| dy = y ** 2 L.times do |x| dx = x ** 2 v = dy + dx next if v < X next if Y < v counter[v] += 1 end end if counter.values.empty? puts 0 else puts counter.values.max * 4 end