for ($y = $this->_startY; $y <= $this->_endY; $y++) { (yield ["x" => $x, "y" => $y]); } } } } function getFieldProperties($fieldNum) { for ($i = 0; $i < $fieldNum; $i++) { (yield new Field_Property(fgets(STDIN))); } } function getUniqueCellProperties($fieldNum) { $fieldProperties = getFieldProperties($fieldNum); $cellProperties = []; foreach ($fieldProperties as $fieldProperty) { foreach ($fieldProperty->getCellProperties() as $cellProperty) { array_push($cellProperties, $cellProperty); } } return array_unique($cellProperties, SORT_REGULAR); } $inputParameter = explode(" ", fgets(STDIN)); $table = new Table(intval($inputParameter[0]), intval($inputParameter[1])); $cellProperties = getUniqueCellProperties(intval($inputParameter[2])); $sum = 0; foreach ($table->getFieldValues($cellProperties) as $cellValue) { $sum += $cellValue; } echo $sum;