# frozen_string_literal: true class Array # rubocop:todo Style/Documentation def solve # rubocop:todo Metrics/AbcSize a = each_with_object({}) do |item, result| result[item[0]] ||= [] result[item[1]] ||= [] result[item[0]] << item[1] result[item[1]] << item[0] end a.map { |_k, v| [v.size - 2, 0].max }.sum end end N = gets.to_i A = (N - 1).times.map { gets.chomp.split.map(&:to_i) } RESULT = A.solve puts RESULT