#!/usr/bin/env ruby input = $stdin.readlines.map(&:to_i) lf = 0 freq = [0] loop do input.each do |i| lf += i if freq.include?(lf) puts lf exit end freq << lf end end