<?php

error_reporting(0);
ob_end_clean();

solve();

function solve(){
/*
	//$handle = fopen("php://stdin");
	$handle = @fopen("input.txt", "r");

	$line = fgets($handle);
	while ($line !== false) {
		$lines[] = $line;
		$line = fgets($handle);
	}
*/
	$flag = 0;
	$STDIN = @fopen("php://stdin", 'r');
	while ($line = fgets($STDIN)) {
		$line = rtrim($line, "\r\n");
		$text = ltrim($line);
		if ($text[0] === "#") {
			if ($flag === 1) {
				print($replaceds."\n");
				$replaceds = "";
			}
			print($line."\n");
			$flag = 0;
		} else {
			$replaceds .= str_replace(" ", "", $text);
			$flag = 1;
		}
	}
	if ($flag === 1) {
		print($replaceds."\n");
	}
	fclose($STDIN);
}
?>

<?php

error_reporting(0);
ob_end_clean();

solve();

function solve(){
/*
	//$handle = fopen("php://stdin");
	$handle = @fopen("input.txt", "r");

	$line = fgets($handle);
	while ($line !== false) {
		$lines[] = $line;
		$line = fgets($handle);
	}
*/
	$flag = 0;
	//$fp = @fopen("input.txt", "r");
	//while (!feof($fp)) {
		//$line = rtrim(fgets($fp), "\r\n");
	while ($line = fgets(STDIN)) {
		$line = rtrim($line, "\r\n");
		$text = ltrim($line);
		if ($text[0] === "#") {
			if ($flag === 1) {
				print($replaceds."\n");
				$replaceds = "";
			}
			print($line."\n");
			$flag = 0;
		} else {
			$replaceds .= str_replace(" ", "", $text);
			$flag = 1;
		}
	}
	if ($flag === 1) {
		print($replaceds."\n");
	}
}
?>

<?php

error_reporting(0);
ob_end_clean();

solve();

function solve(){
/*
	//$handle = fopen("php://stdin");
	$handle = @fopen("input.txt", "r");

	$line = fgets($handle);
	while ($line !== false) {
		$lines[] = $line;
		$line = fgets($handle);
	}
*/
	$flag = 0;
	//$fp = @fopen("input.txt", "r");
	//while (!feof($fp)) {
		//$line = rtrim(fgets($fp), "\r\n");
	$STDIN = @fopen('php://stdin', 'r');
	while ($line = fgets($STDIN)) {
		$line = rtrim($line, "\r\n");
		$text = ltrim($line);
		if ($text[0] === "#") {
			if ($flag === 1) {
				print($replaceds."\n");
				$replaceds = "";
			}
			print($line."\n");
			$flag = 0;
		} else {
			$replaceds .= str_replace(" ", "", $text);
			$flag = 1;
		}
	}
	if ($flag === 1) {
		print($replaceds."\n");
	}
	fclose($STDIN);
}
?>

<?php

error_reporting(0);
ob_end_clean();

solve();

function solve(){

	$flag = 0;
	$fp = @fopen("input.txt", 'r');
	//file has eof,but stdin not.
	//while (!feof($fp)) {
		//$line = rtrim(fgets($fp), "\r\n");

	//STDIN is opened, so this is not needed
	//$STDIN = @fopen("php://stdin", 'r');
	while ($line = fgets(STDIN)) {
		$line = rtrim($line, "\r\n");
		$text = ltrim($line);
		if ($text[0] === "#") {
			if ($flag === 1) {
				print($replaceds."\n");
				$replaceds = "";
			}
			print($line."\n");
			$flag = 0;
		} else {
			$replaceds .= str_replace(" ", "", $text);
			$flag = 1;
		}
	}
	if ($flag === 1) {
		print($replaceds."\n");
	}
	fclose($STDIN);
}
?>

<?php

error_reporting(0);
ob_end_clean();

define("PowerSpell", 1);
define("Space" ,0);
define("Normal" ,-1);

solve();

function solve(){

	//$handle = fopen("php://stdin");
	$handle = @fopen("input.txt", "r");

	$line = fgets($handle);
	while ($line !== false) {
		$lines[] = $line;
		$line = fgets($handle);
	}

	//EOF is red ⇒ \n is needed ?
	//while($line = fgets(STDIN)) $lines[] = $line;

	//TLE EOF is not
	//$fp = fopen("php://stdin");
	//while (!feof($fp)) {
	//	$lines[] = fgets($fp);
	//}

	$len = count($lines);
	//$ispower = false;
	$ispower = true;
	$newlines = array();
	$normalline = "";
	$spaces = array();
	for ($i = 0; $i < $len; $i++) {
		$type = linetype($lines[$i]);
		if ($type === PowerSpell) {
			if ($normalline !== "") {
				$newlines[] = $normalline."\n";
				$normalline = "";
			}

			if (!$ispower) $ispower = true;
			else {
				if (count($spaces) !== 0) {
					foreach ($spaces as $as_space) {
						$newlines[] = $as_space;
					}
					$spaces = array();
				}

			}
			$powerspell = rtrim(str_replace("\r\n", "\n", $lines[$i]), "\n");
			$newlines[] = $powerspell."\n";
		} elseif ($type === Normal) {
			$line = rtrim(str_replace("\r\n", "\n", $lines[$i]), "\n");
			$normalline .= str_replace(" ", "", $line);
			$spaces = array();
			$ispower = false;
		} elseif ($type === Space) {
			//first spaces + powersell line# ⇒ this spaces is not deleteed
			//if ($ispower) $spaces[] = $lines[$i];
			$spaces[] = $lines[$i];
		}
	}

	if ($normalline !== "") {
		//$newlines[] = $normalline;
		$newlines[] = $normalline."\n";
	}

	$len = count($newlines);
	for ($i = 0; $i < $len; $i++) print($newlines[$i]);
		//if ($i !== $len - 1) print($newlines[$i]);
		//elseif ($i === $len - 1 && $newlines[$i] !== "") print(rtrim($newlines[$i]));	}
}

function linetype($line){
	//empty line = "(\n)" or "   (\n)" and "            (\n)".so not only "(\n)"
	$line = str_replace(" ", "", $line);
	$line = str_replace("\r\n", "\n", $line);
	$line = rtrim($line, "\n");

	if ($line === "") return 0;

	$elemets = str_split($line);
	$len = count($elemets);
	for ($i = 0; $i < $len; $i++) {
		if ($elemets[$i] === " ") continue;
		else {
			$first = $elemets[$i];
			break;
		}
	}
	if ($first === "#") return 1;

	return -1;
}
?>

<?php

error_reporting(0);
ob_end_clean();

define("PowerSpell", 1);
define("Space" ,0);
define("Normal" ,-1);

solve();

function solve(){

/*
	//$handle = fopen("php://stdin");
	$handle = @fopen("input.txt", "r");

	$line = fgets($handle);
	while ($line !== false) {
		$lines[] = $line;
		$line = fgets($handle);
	}
*/
	//EOF is red ⇒ \n is needed ?
	while($line = fgets(STDIN)) $lines[] = $line;

	//TLE EOF is not
	//$fp = fopen("php://stdin");
	//while (!feof($fp)) {
	//	$lines[] = fgets($fp);
	//}

	$len = count($lines);
	$ispower = false;
	$newlines = array();
	$normalline = "";
	$spaces = array();
	for ($i = 0; $i < $len; $i++) {
		$type = linetype($lines[$i]);
		if ($type === PowerSpell) {
			if ($normalline !== "") {
				$newlines[] = $normalline."\n";
				$normalline = "";
			}

			if (!$ispower) $ispower = true;
			else {
				if (count($spaces) !== 0) {
					foreach ($spaces as $as_space) {
						$newlines[] = $as_space;
					}
					$spaces = array();
				}

			}
			$newlines[] = $lines[$i];
		} elseif ($type === Normal) {
			$line = rtrim(str_replace("\r\n", "\n", $lines[$i]), "\n");
			$normalline .= str_replace(" ", "", $line);
			$spaces = array();
			$ispower = false;
		} elseif ($type === Space) {
			if ($ispower) $spaces[] = $lines[$i];
		}
	}

	if ($normalline !== "") {
		//$newlines[] = $normalline;
		$newlines[] = $normalline."\n";
	}

	$len = count($newlines);
	for ($i = 0; $i < $len; $i++) print($newlines[$i]);
		//if ($i !== $len - 1) print($newlines[$i]);
		//elseif ($i === $len - 1 && $newlines[$i] !== "") print(rtrim($newlines[$i]));	}
}

function linetype($line){
	$line = str_replace("\r\n", "\n", $line);
	$line = rtrim($line, "\n");

	if ($line === "") return 0;

	$elemets = str_split($line);
	$len = count($elemets);
	for ($i = 0; $i < $len; $i++) {
		if ($elemets[$i] === " ") continue;
		else {
			$first = $elemets[$i];
			break;
		}
	}
	if ($first === "#") return 1;

	return -1;
}
?>

<?php

error_reporting(0);
ob_end_clean();

define("PowerSpell", 1);
define("Space" ,0);
define("Normal" ,-1);

solve();

function solve(){
/*
	//$handle = fopen("php://stdin");
	$handle = @fopen("input.txt", "r");

	$line = fgets($handle);
	while ($line !== false) {
		$lines[] = $line;
		$line = fgets($handle);
	}
*/
	//EOF is red ⇒ \n is needed ?
	while($line = fgets(STDIN)) $lines[] = $line;

	//TLE EOF is not
	//$fp = fopen("php://stdin");
	//while (!feof($fp)) {
	//	$lines[] = fgets($fp);
	//}

	$len = count($lines);
	//$ispower = false;
	$ispower = true;
	$newlines = array();
	$normalline = "";
	$spaces = array();
	for ($i = 0; $i < $len; $i++) {
		$type = linetype($lines[$i]);
		if ($type === PowerSpell) {
			if ($normalline !== "") {
				$newlines[] = $normalline."\n";
				$normalline = "";
			}

			if (!$ispower) $ispower = true;
			else {
				if (count($spaces) === 5) $newlines[] = "\n";
				elseif (count($spaces) !== 0) {
					foreach ($spaces as $as_space) {
						$newlines[] = $as_space;
					}
				}
				$spaces = array();
			}
			$powerspell = rtrim(str_replace("\r\n", "\n", $lines[$i]), "\n");
			$newlines[] = $powerspell."\n";
		} elseif ($type === Normal) {
			$line = rtrim(str_replace("\r\n", "\n", $lines[$i]), "\n");
			$normalline .= str_replace(" ", "", $line);
			$spaces = array();
			$ispower = false;
		} elseif ($type === Space) {
			//first spaces + powersell line# ⇒ this spaces is not deleteed
			//if ($ispower) $spaces[] = $lines[$i];
			//$spaces[] = $lines[$i];
			if ($ispower) $spaces[] = "\n";
		}
	}
	if (count($spaces) === 4) $newlines[] = "\n";
	elseif (count($spaces) !== 6 && count($spaces) !== 0 && count($newlines) !== 0) {		for ($j = 0; $j < $len; $j++) $newlines[] = $spaces[$j];
	} elseif (count($spaces) !== 0 && count($newlines) === 0) $newlines[] = "\n";

	if ($normalline !== "") {
		//$newlines[] = $normalline;
		$newlines[] = $normalline."\n";
	}

	$len = count($newlines);
	for ($i = 0; $i < $len; $i++) print($newlines[$i]);
		//if ($i !== $len - 1) print($newlines[$i]);
		//elseif ($i === $len - 1 && $newlines[$i] !== "") print(rtrim($newlines[$i]));	}
}

function linetype($line){
	//empty line = "(\n)" or "   (\n)" and "            (\n)".so not only "(\n)"
	$line = str_replace(" ", "", $line);
	$line = str_replace("\r\n", "\n", $line);
	$line = rtrim($line, "\n");

	if ($line === "") return 0;

	$elemets = str_split($line);
	$len = count($elemets);
	for ($i = 0; $i < $len; $i++) {
		if ($elemets[$i] === " ") continue;
		else {
			$first = $elemets[$i];
			break;
		}
	}
	if ($first === "#") return 1;

	return -1;
}
?>

<?php

error_reporting(0);
ob_end_clean();

define("PowerSpell", 1);
define("Space" ,0);
define("Normal" ,-1);

solve();

function solve(){
/*
	//$handle = fopen("php://stdin");
	$handle = @fopen("input.txt", "r");

	$line = fgets($handle);
	while ($line !== false) {
		$lines[] = $line;
		$line = fgets($handle);
	}
*/
	//EOF is red ⇒ \n is needed ?
	while($line = fgets(STDIN)) $lines[] = $line;

	//TLE EOF is not
	//$fp = fopen("php://stdin");
	//while (!feof($fp)) {
	//	$lines[] = fgets($fp);
	//}

	$len = count($lines);
	//$ispower = false;
	$ispower = true;
	$newlines = array();
	$normalline = "";
	$spaces = array();
	for ($i = 0; $i < $len; $i++) {
		$type = linetype($lines[$i]);
		if ($type === PowerSpell) {
			if ($normalline !== "") {
				$newlines[] = $normalline."\n";
				$normalline = "";
			}

			if (!$ispower) $ispower = true;
			else {
				if (count($spaces) !== 0) {
					foreach ($spaces as $as_space) {
						$newlines[] = $as_space;
					}
					$spaces = array();
				}

			}
			$powerspell = rtrim(str_replace("\r\n", "\n", $lines[$i]), "\n");
			$newlines[] = $powerspell."\n";
		} elseif ($type === Normal) {
			$line = rtrim(str_replace("\r\n", "\n", $lines[$i]), "\n");
			$normalline .= str_replace(" ", "", $line);
			$spaces = array();
			$ispower = false;
		} elseif ($type === Space) {
			//first spaces + powersell line# ⇒ this spaces is not deleteed
			//if ($ispower) $spaces[] = $lines[$i];
			//$spaces[] = $lines[$i];
			$spaces[] = "\n";
		}
	}

	if ($normalline !== "") {
		//$newlines[] = $normalline;
		$newlines[] = $normalline."\n";
	}

	$len = count($newlines);
	for ($i = 0; $i < $len; $i++) print($newlines[$i]);
		//if ($i !== $len - 1) print($newlines[$i]);
		//elseif ($i === $len - 1 && $newlines[$i] !== "") print(rtrim($newlines[$i]));	}
}

function linetype($line){
	//empty line = "(\n)" or "   (\n)" and "            (\n)".so not only "(\n)"
	$line = str_replace(" ", "", $line);
	$line = str_replace("\r\n", "\n", $line);
	$line = rtrim($line, "\n");

	if ($line === "") return 0;

	$elemets = str_split($line);
	$len = count($elemets);
	for ($i = 0; $i < $len; $i++) {
		if ($elemets[$i] === " ") continue;
		else {
			$first = $elemets[$i];
			break;
		}
	}
	if ($first === "#") return 1;

	return -1;
}
?>

<?php

error_reporting(0);
ob_end_clean();

define("PowerSpell", 1);
define("Space" ,0);
define("Normal" ,-1);

solve();

function solve(){
/*
	$handle = fopen("php://stdin");
	//$handle = @fopen("input.txt", "r");

	$line = fgets($handle);
	while ($line !== false) {

		$line = fgets($handle);
	}
*/
	while($line = fgets(STDIN)) $lines[] = $line;

	$len = count($lines);
	$ispower = false;
	$newlines = array();
	$normalline = "";
	$spaces = array();
	for ($i = 0; $i < $len; $i++) {
		$type = linetype($lines[$i]);
		if ($type === PowerSpell) {
			if ($normalline !== "") {
				$newlines[] = $normalline."\n";
				$normalline = "";
			}

			if (!$ispower) $ispower = true;
			else {
				if (count($spaces) !== 0) {
					foreach ($spaces as $as_space) {
						$newlines[] = $as_space;
					}
					$spaces = array();
				}

			}
			$newlines[] = $lines[$i];
		} elseif ($type === Normal) {
			$line = rtrim(str_replace("\r\n", "\n", $lines[$i]), "\n");
			$normalline .= str_replace(" ", "", $line);
			$spaces = array();
			$ispower = false;
		} elseif ($type === Space) {
			if ($ispower) $spaces[] = $lines[$i];
		}
	}

	if ($normalline !== "") {
		$newlines[] = $normalline;
	}

	$len = count($newlines);
	for ($i = 0; $i < $len; $i++) {
		if ($i !== $len - 1) print($newlines[$i]);
		elseif ($i === $len - 1 && $newlines[$i] !== "") print(rtrim($newlines[$i]));	}
}

function linetype($line){
	$line = str_replace("\r\n", "\n", $line);
	$line = rtrim($line, "\n");

	if ($line === "") return 0;

	$elemets = str_split($line);
	$len = count($elemets);
	for ($i = 0; $i < $len; $i++) {
		if ($elemets[$i] === " ") continue;
		else {
			$first = $elemets[$i];
			break;
		}
	}
	if ($first === "#") return 1;

	return -1;
}
?>

<?php

error_reporting(0);
ob_end_clean();

define("PowerSpell", 1);
define("Space" ,0);
define("Normal" ,-1);

solve();

function solve(){
/*
	//$handle = fopen("php://stdin");
	$handle = @fopen("input.txt", "r");

	$line = fgets($handle);
	while ($line !== false) {
		$lines[] = $line;
		$line = fgets($handle);
	}
*/
	//EOF is red ⇒ \n is needed ?
	while($line = fgets(STDIN)) $lines[] = $line;

	//TLE EOF is not
	//$fp = fopen("php://stdin");
	//while (!feof($fp)) {
	//	$lines[] = fgets($fp);
	//}

	$len = count($lines);
	//$ispower = false;
	$ispower = true;
	$newlines = array();
	$normalline = "";
	$spaces = array();
	for ($i = 0; $i < $len; $i++) {
		$type = linetype($lines[$i]);
		if ($type === PowerSpell) {
			if ($normalline !== "") {
				$newlines[] = $normalline."\n";
				$normalline = "";
			}

			if (!$ispower) $ispower = true;
			else {
				if (count($spaces) !== 0) {
					foreach ($spaces as $as_space) {
						$newlines[] = $as_space;
					}
					$spaces = array();
				}

			}
			$powerspell = rtrim(str_replace("\r\n", "\n", $lines[$i]), "\n");
			$newlines[] = $powerspell."\n";
		} elseif ($type === Normal) {
			$line = rtrim(str_replace("\r\n", "\n", $lines[$i]), "\n");
			$normalline .= str_replace(" ", "", $line);
			$spaces = array();
			$ispower = false;
		} elseif ($type === Space) {
			//first spaces + powersell line# ⇒ this spaces is not deleteed
			//if ($ispower) $spaces[] = $lines[$i];
			$spaces[] = $lines[$i];
		}
	}

	if ($normalline !== "") {
		//$newlines[] = $normalline;
		$newlines[] = $normalline."\n";
	}

	$len = count($newlines);
	for ($i = 0; $i < $len; $i++) print($newlines[$i]);
		//if ($i !== $len - 1) print($newlines[$i]);
		//elseif ($i === $len - 1 && $newlines[$i] !== "") print(rtrim($newlines[$i]));	}
}

function linetype($line){
	//empty line = "(\n)" or "   (\n)" and "            (\n)".so not only "(\n)"
	$line = str_replace(" ", "", $line);
	$line = str_replace("\r\n", "\n", $line);
	$line = rtrim($line, "\n");

	if ($line === "") return 0;

	$elemets = str_split($line);
	$len = count($elemets);
	for ($i = 0; $i < $len; $i++) {
		if ($elemets[$i] === " ") continue;
		else {
			$first = $elemets[$i];
			break;
		}
	}
	if ($first === "#") return 1;

	return -1;
}
?>

<?php

error_reporting(0);
ob_end_clean();

define("PowerSpell", 1);
define("Space" ,0);
define("Normal" ,-1);

solve();

function solve(){
/*
	//$handle = fopen("php://stdin");
	$handle = @fopen("input.txt", "r");

	$line = fgets($handle);
	while ($line !== false) {
		$lines[] = $line;
		$line = fgets($handle);
	}
*/
	//EOF is red ⇒ \n is needed ?
	while($line = fgets(STDIN)) $lines[] = $line;

	//TLE EOF is not
	//$fp = fopen("php://stdin");
	//while (!feof($fp)) {
	//	$lines[] = fgets($fp);
	//}

	$len = count($lines);
	//$ispower = false;
	$ispower = true;
	$newlines = array();
	$normalline = "";
	$spaces = array();
	for ($i = 0; $i < $len; $i++) {
		$type = linetype($lines[$i]);
		if ($type === PowerSpell) {
			if ($normalline !== "") {
				$newlines[] = $normalline."\n";
				$normalline = "";
			}

			if (!$ispower) $ispower = true;
			else {
				if (count($spaces) !== 0) {
					foreach ($spaces as $as_space) {
						$newlines[] = $as_space;
					}
					$spaces = array();
				}
			}
			$powerspell = rtrim(str_replace("\r\n", "\n", $lines[$i]), "\n");
			$newlines[] = $powerspell."\n";
		} elseif ($type === Normal) {
			$line = rtrim(str_replace("\r\n", "\n", $lines[$i]), "\n");
			$normalline .= str_replace(" ", "", $line);
			$spaces = array();
			$ispower = false;
		} elseif ($type === Space) {
			//first spaces + powersell line# ⇒ this spaces is not deleteed
			//if ($ispower) $spaces[] = $lines[$i];
			//$spaces[] = $lines[$i];
			if ($ispower) $spaces[] = "\n";
		}
	}
	if (count($spaces) !== 0) {
		for ($j = 0; $j < $len; $j++) {
			if ($j !== $len - 1) $newlines[] = $spaces[$j];
			else $newlines[] = $spaces[$j];
		}
	}

	if ($normalline !== "") {
		//$newlines[] = $normalline;
		$newlines[] = $normalline."\n";
	}

	$len = count($newlines);
	for ($i = 0; $i < $len; $i++) print($newlines[$i]);
		//if ($i !== $len - 1) print($newlines[$i]);
		//elseif ($i === $len - 1 && $newlines[$i] !== "") print(rtrim($newlines[$i]));	}
}

function linetype($line){
	//empty line = "(\n)" or "   (\n)" and "            (\n)".so not only "(\n)"
	$line = str_replace(" ", "", $line);
	$line = str_replace("\r\n", "\n", $line);
	$line = rtrim($line, "\n");

	if ($line === "") return 0;

	$elemets = str_split($line);
	$len = count($elemets);
	for ($i = 0; $i < $len; $i++) {
		if ($elemets[$i] === " ") continue;
		else {
			$first = $elemets[$i];
			break;
		}
	}
	if ($first === "#") return 1;

	return -1;
}
?>

<?php

error_reporting(0);
ob_end_clean();

solve();

function solve(){
/*
	//$handle = fopen("php://stdin");
	$handle = @fopen("input.txt", "r");

	$line = fgets($handle);
	while ($line !== false) {
		$lines[] = $line;
		$line = fgets($handle);
	}
*/
	$flag = 0;
	//$fp = @fopen("input.txt", "r");
	//while (!feof($fp)) {
		//$line = rtrim(fgets($fp), "\r\n");
	while ($line = rtrim(fgets(STDIN), "\r\n")) {
		$text = ltrim($line);
		if ($text[0] === "#") {
			if ($flag === 1) {
				print($replaceds."\n");
				$replaceds = "";
			}
			print($line."\n");
			$flag = 0;
		} else {
			$replaceds .= str_replace(" ", "", $text);
			$flag = 1;
		}
	}
	if ($flag === 1) {
		print($replaceds."\n");
	}
}
?>

<?php

error_reporting(0);
ob_end_clean();

define("PowerSpell", 1);
define("Space" ,0);
define("Normal" ,-1);

solve();

function solve(){
/*
	//$handle = fopen("php://stdin");
	$handle = @fopen("input.txt", "r");

	$line = fgets($handle);
	while ($line !== false) {
		$lines[] = $line;
		$line = fgets($handle);
	}
*/
	//EOF is red ⇒ \n is needed ?
	while($line = fgets(STDIN)) $lines[] = $line;

	//TLE EOF is not
	//$fp = fopen("php://stdin");
	//while (!feof($fp)) {
	//	$lines[] = fgets($fp);
	//}

	$len = count($lines);
	//$ispower = false;
	$ispower = true;
	$newlines = array();
	$normalline = "";
	$spaces = array();
	for ($i = 0; $i < $len; $i++) {
		$type = linetype($lines[$i]);
		if ($type === PowerSpell) {
			if ($normalline !== "") {
				$newlines[] = $normalline."\n";
				$normalline = "";
			}

			if (!$ispower) $ispower = true;
			else {
				if (count($spaces) !== 0) {
					foreach ($spaces as $as_space) {
						$newlines[] = $as_space;
					}
					$spaces = array();
				}

			}
			$powerspell = rtrim(str_replace("\r\n", "\n", $lines[$i]), "\n");
			$newlines[] = $powerspell."\r\n";
		} elseif ($type === Normal) {
			$line = rtrim(str_replace("\r\n", "\n", $lines[$i]), "\n");
			$normalline .= str_replace(" ", "", $line);
			$spaces = array();
			$ispower = false;
		} elseif ($type === Space) {
			//first spaces + powersell line# ⇒ this spaces is not deleteed
			//if ($ispower) $spaces[] = $lines[$i];
			$spaces[] = $lines[$i];
		}
	}

	if ($normalline !== "") {
		//$newlines[] = $normalline;
		$newlines[] = $normalline."\n";
	}

	$len = count($newlines);
	for ($i = 0; $i < $len; $i++) print($newlines[$i]);
		//if ($i !== $len - 1) print($newlines[$i]);
		//elseif ($i === $len - 1 && $newlines[$i] !== "") print(rtrim($newlines[$i]));	}
}

function linetype($line){
	//empty line = "(\n)" or "   (\n)" and "            (\n)".so not only "(\n)"
	$line = str_replace(" ", "", $line);
	$line = str_replace("\r\n", "\n", $line);
	$line = rtrim($line, "\n");

	if ($line === "") return 0;

	$elemets = str_split($line);
	$len = count($elemets);
	for ($i = 0; $i < $len; $i++) {
		if ($elemets[$i] === " ") continue;
		else {
			$first = $elemets[$i];
			break;
		}
	}
	if ($first === "#") return 1;

	return -1;
}
?>

<?php

error_reporting(0);
ob_end_clean();

define("PowerSpell", 1);
define("Space" ,0);
define("Normal" ,-1);

solve();

function solve(){
/*
	//$handle = fopen("php://stdin");
	$handle = @fopen("input.txt", "r");

	$line = fgets($handle);
	while ($line !== false) {
		$lines[] = $line;
		$line = fgets($handle);
	}
*/
	//EOF is red ⇒ \n is needed ?
	while($line = fgets(STDIN)) $lines[] = $line;

	//TLE EOF is not
	//$fp = fopen("php://stdin");
	//while (!feof($fp)) {
	//	$lines[] = fgets($fp);
	//}

	$len = count($lines);
	//$ispower = false;
	$ispower = true;
	$newlines = array();
	$normalline = "";
	$spaces = array();
	for ($i = 0; $i < $len; $i++) {
		$type = linetype($lines[$i]);
		if ($type === PowerSpell) {
			if ($normalline !== "") {
				$newlines[] = $normalline."\n";
				$normalline = "";
			}

			if (!$ispower) $ispower = true;
			else {
				if (count($spaces) !== 0) {
					foreach ($spaces as $as_space) {
						$newlines[] = $as_space;
					}
					$spaces = array();
				}
			}
			$powerspell = rtrim(str_replace("\r\n", "\n", $lines[$i]), "\n");
			$newlines[] = $powerspell."\n";
		} elseif ($type === Normal) {
			$line = rtrim(str_replace("\r\n", "\n", $lines[$i]), "\n");
			$normalline .= str_replace(" ", "", $line);
			$spaces = array();
			$ispower = false;
		} elseif ($type === Space) {
			//first spaces + powersell line# ⇒ this spaces is not deleteed
			//if ($ispower) $spaces[] = $lines[$i];
			//$spaces[] = $lines[$i];
			if ($ispower) $spaces[] = "\n";
		}
	}
	if (count($spaces) !== 0 && count($newlines) !== 0) {
		for ($j = 0; $j < $len; $j++) {
			if ($j !== $len - 1) $newlines[] = $spaces[$j];
			else $newlines[] = $spaces[$j];
		}
	}

	if ($normalline !== "") {
		//$newlines[] = $normalline;
		$newlines[] = $normalline."\n";
	}

	$len = count($newlines);
	for ($i = 0; $i < $len; $i++) print($newlines[$i]);
		//if ($i !== $len - 1) print($newlines[$i]);
		//elseif ($i === $len - 1 && $newlines[$i] !== "") print(rtrim($newlines[$i]));	}
}

function linetype($line){
	//empty line = "(\n)" or "   (\n)" and "            (\n)".so not only "(\n)"
	$line = str_replace(" ", "", $line);
	$line = str_replace("\r\n", "\n", $line);
	$line = rtrim($line, "\n");

	if ($line === "") return 0;

	$elemets = str_split($line);
	$len = count($elemets);
	for ($i = 0; $i < $len; $i++) {
		if ($elemets[$i] === " ") continue;
		else {
			$first = $elemets[$i];
			break;
		}
	}
	if ($first === "#") return 1;

	return -1;
}
?>

<?php

error_reporting(0);
ob_end_clean();

define("PowerSpell", 1);
define("Space" ,0);
define("Normal" ,-1);

solve();

function solve(){
/*
	//$handle = fopen("php://stdin");
	$handle = @fopen("input.txt", "r");

	$line = fgets($handle);
	while ($line !== false) {
		$lines[] = $line;
		$line = fgets($handle);
	}
*/
	//EOF is red ⇒ \n is needed ?
	while($line = fgets(STDIN)) $lines[] = $line;

	//TLE EOF is not
	//$fp = fopen("php://stdin");
	//while (!feof($fp)) {
	//	$lines[] = fgets($fp);
	//}

	$len = count($lines);
	//$ispower = false;
	$ispower = true;
	$newlines = array();
	$normalline = "";
	$spaces = array();
	for ($i = 0; $i < $len; $i++) {
		$type = linetype($lines[$i]);
		if ($type === PowerSpell) {
			if ($normalline !== "") {
				$newlines[] = $normalline."\n";
				$normalline = "";
			}

			if (!$ispower) $ispower = true;
			else {
				if (count($spaces) !== 0) {
					foreach ($spaces as $as_space) {
						$newlines[] = $as_space;
					}
					$spaces = array();
				}
			}
			$powerspell = rtrim(str_replace("\r\n", "\n", $lines[$i]), "\n");
			$newlines[] = $powerspell."\n";
		} elseif ($type === Normal) {
			$line = rtrim(str_replace("\r\n", "\n", $lines[$i]), "\n");
			$normalline .= str_replace(" ", "", $line);
			$spaces = array();
			$ispower = false;
		} elseif ($type === Space) {
			//first spaces + powersell line# ⇒ this spaces is not deleteed
			//if ($ispower) $spaces[] = $lines[$i];
			//$spaces[] = $lines[$i];
			if ($ispower) $spaces[] = "\n";
		}
	}
	if (count($spaces) === 4) $newlines[] = "\n";
	elseif (count($spaces) !== 6 && count($spaces) !== 0 && count($newlines) !== 0) {		for ($j = 0; $j < $len; $j++) $newlines[] = $spaces[$j];
	} elseif (count($spaces) !== 0 && count($newlines) === 0) $newlines[] = "\n";

	if ($normalline !== "") {
		//$newlines[] = $normalline;
		$newlines[] = $normalline."\n";
	}

	$len = count($newlines);
	for ($i = 0; $i < $len; $i++) print($newlines[$i]);
		//if ($i !== $len - 1) print($newlines[$i]);
		//elseif ($i === $len - 1 && $newlines[$i] !== "") print(rtrim($newlines[$i]));	}
}

function linetype($line){
	//empty line = "(\n)" or "   (\n)" and "            (\n)".so not only "(\n)"
	$line = str_replace(" ", "", $line);
	$line = str_replace("\r\n", "\n", $line);
	$line = rtrim($line, "\n");

	if ($line === "") return 0;

	$elemets = str_split($line);
	$len = count($elemets);
	for ($i = 0; $i < $len; $i++) {
		if ($elemets[$i] === " ") continue;
		else {
			$first = $elemets[$i];
			break;
		}
	}
	if ($first === "#") return 1;

	return -1;
}
?>

<?php

error_reporting(0);
ob_end_clean();

define("PowerSpell", 1);
define("Space" ,0);
define("Normal" ,-1);

solve();

function solve(){
	//$handle = fopen("php://stdin");
	$handle = fopen(STDIN);
	//$handle = @fopen("input.txt", "r");

	$line = fgets($handle);
	while ($line !== false) {
		$lines[] = $line;
		$line = fgets($handle);
	}

	$len = count($lines);
	$ispower = false;
	$newlines = array();
	$normalline = "";
	$spaces = array();
	for ($i = 0; $i < $len; $i++) {
		$type = linetype($lines[$i]);
		if ($type === PowerSpell) {
			if ($normalline !== "") {
				$newlines[] = $normalline."\n";
				$normalline = "";
			}

			if (!$ispower) $ispower = true;
			else {
				if (count($spaces) !== 0) {
					foreach ($spaces as $as_space) {
						$newlines[] = $as_space;
					}
					$spaces = array();
				}

			}
			$newlines[] = $lines[$i];
		} elseif ($type === Normal) {
			$line = rtrim(str_replace("\r\n", "\n", $lines[$i]), "\n");
			$normalline .= str_replace(" ", "", $line);
			$spaces = array();
			$ispower = false;
		} elseif ($type === Space) {
			if ($ispower) $spaces[] = $lines[$i];
		}
	}

	if ($normalline !== "") {
		$newlines[] = $normalline;
	}

	$len = count($newlines);
	for ($i = 0; $i < $len; $i++) {
		if ($i !== $len - 1) print($newlines[$i]);
		elseif ($i === $len - 1 && $newlines[$i] !== "") print(rtrim($newlines[$i]));	}
}

function linetype($line){
	$line = str_replace("\r\n", "\n", $line);
	$line = rtrim($line, "\n");

	if ($line === "") return 0;

	$elemets = str_split($line);
	$len = count($elemets);
	for ($i = 0; $i < $len; $i++) {
		if ($elemets[$i] === " ") continue;
		else {
			$first = $elemets[$i];
			break;
		}
	}
	if ($first === "#") return 1;

	return -1;
}
?>

<?php

error_reporting(0);
ob_end_clean();

define("PowerSpell", 1);
define("Space" ,0);
define("Normal" ,-1);

solve();

function solve(){
	$handle = fopen("php://stdin");
	//$handle = @fopen("input.txt", "r");

	$line = fgets($handle);
	while ($line !== false) {
		$lines[] = $line;
		$line = fgets($handle);
	}

	$len = count($lines);
	$ispower = false;
	$newlines = array();
	for ($i = 0; $i < $len; $i++) {
		$type = linetype($lines[$i]);
		if ($type === PowerSpell) {
			if ($normalline !== "") {
				$newlines[] = $normalline."\n";
				$normalline = "";
			}

			if (!$ispower) $ispower = true;
			else {
				if (count(spaces) !== 0) {
					foreach ($spaces as $as_space) {
						$newlines[] = $as_space;
					}
				}
				$spaces = array();
			}
			$newlines[] = $lines[$i];
		} elseif ($type === Normal) {
			$normalline .= str_replace(" ", "", rtrim($lines[$i]));
			$spaces = array();
			$ispower = false;
		} elseif ($type === Space) {
			if ($ispower) $spaces[] = $lines[$i];
		}
	}

	if ($normalline !== "") {
		$newlines[] = $normalline;
	}

	$len = count($newlines);
	for ($i = 0; $i < $len; $i++) {
		if ($i !== $len - 1) print($newlines[$i]);
		elseif ($i === $len - 1 && $newlines[$i] !== "") print(rtrim($newlines[$i]));	}
}

function linetype($line){
	$line = str_replace("\r\n", "\n", $line);
	$line = rtrim($line, "\n");

	if ($line === "") return 0;

	$elemets = str_split($line);
	$len = count($elemets);
	for ($i = 0; $i < $len; $i++) {
		if ($elemets[$i] === " ") continue;
		else {
			$first = $elemets[$i];
			break;
		}
	}
	if ($first === "#") return 1;

	return -1;
}
?>

<?php

error_reporting(0);
ob_end_clean();

define("PowerSpell", 1);
define("Space" ,0);
define("Normal" ,-1);

solve();

function solve(){

/*??
	//$handle = fopen("php://stdin");
	$handle = @fopen("input.txt", "r");

	$line = fgets($handle);
	while ($line !== false) {
		$lines[] = $line;
		$line = fgets($handle);
	}
*/
	//EOF is red ⇒ \n is needed ?
	while($line = fgets(STDIN)) $lines[] = $line;

	//TLE EOF is not
	//$fp = fopen("php://stdin");
	//while (!feof($fp)) {
	//	$lines[] = fgets($fp);
	//}

	$len = count($lines);
	//$ispower = false;
	$ispower = true;
	$newlines = array();
	$normalline = "";
	$spaces = array();
	for ($i = 0; $i < $len; $i++) {
		$type = linetype($lines[$i]);
		if ($type === PowerSpell) {
			if ($normalline !== "") {
				$newlines[] = $normalline."\n";
				$normalline = "";
			}

			if (!$ispower) $ispower = true;
			else {
				if (count($spaces) !== 0) {
					foreach ($spaces as $as_space) {
						$newlines[] = $as_space;
					}
					$spaces = array();
				}

			}
			$newlines[] = $lines[$i];
		} elseif ($type === Normal) {
			$line = rtrim(str_replace("\r\n", "\n", $lines[$i]), "\n");
			$normalline .= str_replace(" ", "", $line);
			$spaces = array();
			$ispower = false;
		} elseif ($type === Space) {
			//first spaces + powersell line# ⇒ this spaces is not deleteed
			//if ($ispower) $spaces[] = $lines[$i];
			$spaces[] = $lines[$i];
		}
	}

	if ($normalline !== "") {
		//$newlines[] = $normalline;
		$newlines[] = $normalline."\n";
	}

	$len = count($newlines);
	for ($i = 0; $i < $len; $i++) print($newlines[$i]);
		//if ($i !== $len - 1) print($newlines[$i]);
		//elseif ($i === $len - 1 && $newlines[$i] !== "") print(rtrim($newlines[$i]));	}
}

function linetype($line){
	$line = str_replace(" ", "", $line);
	$line = str_replace("\r\n", "\n", $line);
	$line = rtrim($line, "\n");

	if ($line === "") return 0;

	$elemets = str_split($line);
	$len = count($elemets);
	for ($i = 0; $i < $len; $i++) {
		if ($elemets[$i] === " ") continue;
		else {
			$first = $elemets[$i];
			break;
		}
	}
	if ($first === "#") return 1;

	return -1;
}
?>

<?php

error_reporting(0);
ob_end_clean();

define("PowerSpell", 1);
define("Space" ,0);
define("Normal" ,-1);

solve();

function solve(){

/*??
	//$handle = fopen("php://stdin");
	$handle = @fopen("input.txt", "r");

	$line = fgets($handle);
	while ($line !== false) {
		$lines[] = $line;
		$line = fgets($handle);
	}
*/
	//EOF is red ⇒ \n is needed ?
	while($line = fgets(STDIN)) $lines[] = $line;

	//TLE EOF is not
	//$fp = fopen("php://stdin");
	//while (!feof($fp)) {
	//	$lines[] = fgets($fp);
	//}

	$len = count($lines);
	//$ispower = false;
	$ispower = true;
	$newlines = array();
	$normalline = "";
	$spaces = array();
	for ($i = 0; $i < $len; $i++) {
		$type = linetype($lines[$i]);
		if ($type === PowerSpell) {
			if ($normalline !== "") {
				$newlines[] = $normalline."\n";
				$normalline = "";
			}

			if (!$ispower) $ispower = true;
			else {
				if (count($spaces) !== 0) {
					foreach ($spaces as $as_space) {
						$newlines[] = $as_space;
					}
					$spaces = array();
				}

			}
			$newlines[] = $lines[$i];
		} elseif ($type === Normal) {
			$line = rtrim(str_replace("\r\n", "\n", $lines[$i]), "\n");
			$normalline .= str_replace(" ", "", $line);
			$spaces = array();
			$ispower = false;
		} elseif ($type === Space) {
			//first spaces + powersell line# ⇒ this spaces is not deleteed
			//if ($ispower) $spaces[] = $lines[$i];
			$spaces[] = $lines[$i];
		}
	}

	if ($normalline !== "") {
		//$newlines[] = $normalline;
		$newlines[] = $normalline."\n";
	}

	$len = count($newlines);
	for ($i = 0; $i < $len; $i++) print($newlines[$i]);
		//if ($i !== $len - 1) print($newlines[$i]);
		//elseif ($i === $len - 1 && $newlines[$i] !== "") print(rtrim($newlines[$i]));	}
}

function linetype($line){
	$line = str_replace("\r\n", "\n", $line);
	$line = rtrim($line, "\n");

	if ($line === "") return 0;

	$elemets = str_split($line);
	$len = count($elemets);
	for ($i = 0; $i < $len; $i++) {
		if ($elemets[$i] === " ") continue;
		else {
			$first = $elemets[$i];
			break;
		}
	}
	if ($first === "#") return 1;

	return -1;
}
?>

<?php

error_reporting(0);
ob_end_clean();

define("PowerSpell", 1);
define("Space" ,0);
define("Normal" ,-1);

solve();

function solve(){

/*??
	//$handle = fopen("php://stdin");
	$handle = @fopen("input.txt", "r");

	$line = fgets($handle);
	while ($line !== false) {
		$lines[] = $line;
		$line = fgets($handle);
	}
*/
	//EOF is red ⇒ \n is needed ?
	while($line = fgets(STDIN)) $lines[] = $line;

	//TLE EOF is not
	//$fp = fopen("php://stdin");
	//while (!feof($fp)) {
	//	$lines[] = fgets($fp);
	//}

	$len = count($lines);
	//$ispower = false;
	$ispower = true;
	$newlines = array();
	$normalline = "";
	$spaces = array();
	for ($i = 0; $i < $len; $i++) {
		$type = linetype($lines[$i]);
		if ($type === PowerSpell) {
			if ($normalline !== "") {
				$newlines[] = $normalline."\n";
				$normalline = "";
			}

			if (!$ispower) $ispower = true;
			else {
				if (count($spaces) !== 0) {
					foreach ($spaces as $as_space) {
						$newlines[] = $as_space;
					}
					$spaces = array();
				}

			}
			$newlines[] = rtrim(str_replace("\r\n", "\n", $lines[$i]), "\n")."\n";
		} elseif ($type === Normal) {
			$line = rtrim(str_replace("\r\n", "\n", $lines[$i]), "\n");
			$normalline .= str_replace(" ", "", $line);
			$spaces = array();
			$ispower = false;
		} elseif ($type === Space) {
			//first spaces + powersell line# ⇒ this spaces is not deleteed
			//if ($ispower) $spaces[] = $lines[$i];
			$spaces[] = $lines[$i];
		}
	}

	if ($normalline !== "") {
		//$newlines[] = $normalline;
		$newlines[] = $normalline."\n";
	}

	$len = count($newlines);
	for ($i = 0; $i < $len; $i++) print($newlines[$i]);
		//if ($i !== $len - 1) print($newlines[$i]);
		//elseif ($i === $len - 1 && $newlines[$i] !== "") print(rtrim($newlines[$i]));	}
}

function linetype($line){
	//empty line = "(\n)" or "   (\n)" and "            (\n)".so not only "(\n)"
	$line = str_replace(" ", "", $line);
	$line = str_replace("\r\n", "\n", $line);
	$line = rtrim($line, "\n");

	if ($line === "") return 0;

	$elemets = str_split($line);
	$len = count($elemets);
	for ($i = 0; $i < $len; $i++) {
		if ($elemets[$i] === " ") continue;
		else {
			$first = $elemets[$i];
			break;
		}
	}
	if ($first === "#") return 1;

	return -1;
}
?>

<?php

error_reporting(0);
ob_end_clean();

define("PowerSpell", 1);
define("Space" ,0);
define("Normal" ,-1);

solve();

function solve(){
	$handle = fopen("php://stdin");
	//$handle = @fopen("input.txt", "r");

	$line = fgets($handle);
	while ($line !== false) {
		$lines[] = $line;
		$line = fgets($handle);
	}

	$len = count($lines);
	$ispower = false;
	$newlines = array();
	$normalline = "";
	$spaces = array();
	for ($i = 0; $i < $len; $i++) {
		$type = linetype($lines[$i]);
		if ($type === PowerSpell) {
			if ($normalline !== "") {

				$newlines[] = $normalline."\n";
				$normalline = "";
			}

			if (!$ispower) $ispower = true;
			else {
				if (count($spaces) !== 0) {
					foreach ($spaces as $as_space) {
						$newlines[] = $as_space;
					}
				}
				$spaces = array();
			}
			$newlines[] = $lines[$i];
		} elseif ($type === Normal) {
			$line = rtrim(str_replace("\r\n", "\n", $lines[$i]), "\n");
			$normalline .= str_replace(" ", "", $line);
			$spaces = array();
			$ispower = false;
		} elseif ($type === Space) {
			if ($ispower) $spaces[] = $lines[$i];
		}
	}

	if ($normalline !== "") {
		$newlines[] = $normalline;
	}

	$len = count($newlines);
	for ($i = 0; $i < $len; $i++) {
		if ($i !== $len - 1) print($newlines[$i]);
		elseif ($i === $len - 1 && $newlines[$i] !== "") print(rtrim($newlines[$i]));	}
}

function linetype($line){
	$line = str_replace("\r\n", "\n", $line);
	$line = rtrim($line, "\n");

	if ($line === "") return 0;

	$elemets = str_split($line);
	$len = count($elemets);
	for ($i = 0; $i < $len; $i++) {
		if ($elemets[$i] === " ") continue;
		else {
			$first = $elemets[$i];
			break;
		}
	}
	if ($first === "#") return 1;

	return -1;
}
?>

<?php

error_reporting(0);
ob_end_clean();

solve();

function solve(){
/*
	//$handle = fopen("php://stdin");
	$handle = @fopen("input.txt", "r");

	$line = fgets($handle);
	while ($line !== false) {
		$lines[] = $line;
		$line = fgets($handle);
	}
*/
	$flag = 0;
	//$fp = @fopen("input.txt", "r");
	//while (!feof($fp)) {
		//$line = rtrim(fgets($fp), "\r\n");
	$fp = @fopen("php://stdin");
	while ($line = fgets($fp)) {
		$line = rtrim($line, "\r\n");
		$text = ltrim($line);
		if ($text[0] === "#") {
			if ($flag === 1) {
				print($replaceds."\n");
				$replaceds = "";
			}
			print($line."\n");
			$flag = 0;
		} else {
			$replaceds .= str_replace(" ", "", $text);
			$flag = 1;
		}
	}
	if ($flag === 1) {
		print($replaceds."\n");
	}
	fclose($fp);
}
?>

<?php

error_reporting(0);
ob_end_clean();

define("PowerSpell", 1);
define("Space" ,0);
define("Normal" ,-1);

solve();

function solve(){

/*?
	$handle = fopen("php://stdin");
	//$handle = @fopen("input.txt", "r");

	$line = fgets($handle);
	while ($line !== false) {
		$lines[] = $line;
		$line = fgets($handle);
	}
*/
	//EOF is red ⇒ \n is needed ?
	while($line = fgets(STDIN)) $lines[] = $line;

	//TLE EOF is not
	//$fp = fopen("php://stdin");
	//while (!feof($fp)) {
	//	$lines[] = fgets($fp);
	//}

	$len = count($lines);
	$ispower = false;
	$newlines = array();
	$normalline = "";
	$spaces = array();
	for ($i = 0; $i < $len; $i++) {
		$type = linetype($lines[$i]);
		if ($type === PowerSpell) {
			if ($normalline !== "") {
				$newlines[] = $normalline."\n";
				$normalline = "";
			}

			if (!$ispower) $ispower = true;
			else {
				if (count($spaces) !== 0) {
					foreach ($spaces as $as_space) {
						$newlines[] = $as_space;
					}
					$spaces = array();
				}

			}
			$newlines[] = $lines[$i];
		} elseif ($type === Normal) {
			$line = rtrim(str_replace("\r\n", "\n", $lines[$i]), "\n");
			$normalline .= str_replace(" ", "", $line);
			$spaces = array();
			$ispower = false;
		} elseif ($type === Space) {
			if ($ispower) $spaces[] = $lines[$i];
		}
	}

	if ($normalline !== "") {
		$newlines[] = $normalline;
	}

	$len = count($newlines);
	for ($i = 0; $i < $len; $i++) print($newlines[$i]);
		//if ($i !== $len - 1) print($newlines[$i]);
		//elseif ($i === $len - 1 && $newlines[$i] !== "") print(rtrim($newlines[$i]));	}
}

function linetype($line){
	$line = str_replace("\r\n", "\n", $line);
	$line = rtrim($line, "\n");

	if ($line === "") return 0;

	$elemets = str_split($line);
	$len = count($elemets);
	for ($i = 0; $i < $len; $i++) {
		if ($elemets[$i] === " ") continue;
		else {
			$first = $elemets[$i];
			break;
		}
	}
	if ($first === "#") return 1;

	return -1;
}
?>

<?php

error_reporting(0);
ob_end_clean();

define("PowerSpell", 1);
define("Space" ,0);
define("Normal" ,-1);

solve();

function solve(){
/*
	//$handle = fopen("php://stdin");
	$handle = @fopen("input.txt", "r");

	$line = fgets($handle);
	while ($line !== false) {
		$lines[] = $line;
		$line = fgets($handle);
	}
*/
	//EOF is red ⇒ \n is needed ?
	while($line = fgets(STDIN)) $lines[] = $line;

	//TLE EOF is not
	//$fp = fopen("php://stdin");
	//while (!feof($fp)) {
	//	$lines[] = fgets($fp);
	//}

	$len = count($lines);
	//$ispower = false;
	$ispower = true;
	$newlines = array();
	$normalline = "";
	$spaces = array();
	for ($i = 0; $i < $len; $i++) {
		$type = linetype($lines[$i]);
		if ($type === PowerSpell) {
			if ($normalline !== "") {
				$newlines[] = $normalline."\n";
				$normalline = "";
			}

			if (!$ispower) $ispower = true;
			else {
				if (count($spaces) !== 0) {
					foreach ($spaces as $as_space) {
						$newlines[] = $as_space;
					}
					$spaces = array();
				}
			}
			$powerspell = rtrim(str_replace("\r\n", "\n", $lines[$i]), "\n");
			$newlines[] = $powerspell."\n";
		} elseif ($type === Normal) {
			$line = rtrim(str_replace("\r\n", "\n", $lines[$i]), "\n");
			$normalline .= str_replace(" ", "", $line);
			$spaces = array();
			$ispower = false;
		} elseif ($type === Space) {
			//first spaces + powersell line# ⇒ this spaces is not deleteed
			//if ($ispower) $spaces[] = $lines[$i];
			//$spaces[] = $lines[$i];
			if ($ispower) $spaces[] = "\n";
		}
	}
	if (count($spaces) === 6) $newlines[] = "\n";
	elseif (count($spaces) !== 6 && count($spaces) !== 0 && count($newlines) !== 0) {		for ($j = 0; $j < $len; $j++) $newlines[] = $spaces[$j];
	} elseif (count($spaces) !== 0 && count($newlines) === 0) $newlines[] = "\n";

	if ($normalline !== "") {
		//$newlines[] = $normalline;
		$newlines[] = $normalline."\n";
	}

	$len = count($newlines);
	for ($i = 0; $i < $len; $i++) print($newlines[$i]);
		//if ($i !== $len - 1) print($newlines[$i]);
		//elseif ($i === $len - 1 && $newlines[$i] !== "") print(rtrim($newlines[$i]));	}
}

function linetype($line){
	//empty line = "(\n)" or "   (\n)" and "            (\n)".so not only "(\n)"
	$line = str_replace(" ", "", $line);
	$line = str_replace("\r\n", "\n", $line);
	$line = rtrim($line, "\n");

	if ($line === "") return 0;

	$elemets = str_split($line);
	$len = count($elemets);
	for ($i = 0; $i < $len; $i++) {
		if ($elemets[$i] === " ") continue;
		else {
			$first = $elemets[$i];
			break;
		}
	}
	if ($first === "#") return 1;

	return -1;
}
?>

<?php

error_reporting(0);
ob_end_clean();

define("PowerSpell", 1);
define("Space" ,0);
define("Normal" ,-1);

solve();

function solve(){
/*
	//$handle = fopen("php://stdin");
	$handle = @fopen("input.txt", "r");

	$line = fgets($handle);
	while ($line !== false) {
		$lines[] = $line;
		$line = fgets($handle);
	}
*/
	//EOF is red ⇒ \n is needed ?
	while($line = fgets(STDIN)) $lines[] = $line;

	//TLE EOF is not
	//$fp = fopen("php://stdin");
	//while (!feof($fp)) {
	//	$lines[] = fgets($fp);
	//}

	$len = count($lines);
	//$ispower = false;
	$ispower = true;
	$newlines = array();
	$normalline = "";
	$spaces = array();
	for ($i = 0; $i < $len; $i++) {
		$type = linetype($lines[$i]);
		if ($type === PowerSpell) {
			if ($normalline !== "") {
				$newlines[] = $normalline."\n";
				$normalline = "";
			}

			if (!$ispower) $ispower = true;
			else {
				if (count($spaces) !== 0) {
					foreach ($spaces as $as_space) {
						$newlines[] = $as_space;
					}
					$spaces = array();
				}
			}
			$powerspell = rtrim(str_replace("\r\n", "\n", $lines[$i]), "\n");
			$newlines[] = $powerspell."\n";
		} elseif ($type === Normal) {
			$line = rtrim(str_replace("\r\n", "\n", $lines[$i]), "\n");
			$normalline .= str_replace(" ", "", $line);
			$spaces = array();
			$ispower = false;
		} elseif ($type === Space) {
			//first spaces + powersell line# ⇒ this spaces is not deleteed
			//if ($ispower) $spaces[] = $lines[$i];
			//$spaces[] = $lines[$i];
			if ($ispower) $spaces[] = "\n";
		}
	}
	if (count($spaces) === 5) $newlines[] = "\n";
	elseif (count($spaces) !== 6 && count($spaces) !== 0 && count($newlines) !== 0) {		for ($j = 0; $j < $len; $j++) $newlines[] = $spaces[$j];
	} elseif (count($spaces) !== 0 && count($newlines) === 0) $newlines[] = "\n";

	if ($normalline !== "") {
		//$newlines[] = $normalline;
		$newlines[] = $normalline."\n";
	}

	$len = count($newlines);
	for ($i = 0; $i < $len; $i++) print($newlines[$i]);
		//if ($i !== $len - 1) print($newlines[$i]);
		//elseif ($i === $len - 1 && $newlines[$i] !== "") print(rtrim($newlines[$i]));	}
}

function linetype($line){
	//empty line = "(\n)" or "   (\n)" and "            (\n)".so not only "(\n)"
	$line = str_replace(" ", "", $line);
	$line = str_replace("\r\n", "\n", $line);
	$line = rtrim($line, "\n");

	if ($line === "") return 0;

	$elemets = str_split($line);
	$len = count($elemets);
	for ($i = 0; $i < $len; $i++) {
		if ($elemets[$i] === " ") continue;
		else {
			$first = $elemets[$i];
			break;
		}
	}
	if ($first === "#") return 1;

	return -1;
}
?>

<?php

error_reporting(0);
ob_end_clean();

define("PowerSpell", 1);
define("Space" ,0);
define("Normal" ,-1);

solve();

function solve(){
/*
	//$handle = fopen("php://stdin");
	$handle = @fopen("input.txt", "r");

	$line = fgets($handle);
	while ($line !== false) {
		$lines[] = $line;
		$line = fgets($handle);
	}
*/
	//EOF is red ⇒ \n is needed ?
	while($line = fgets(STDIN)) $lines[] = $line;

	//TLE EOF is not
	//$fp = fopen("php://stdin");
	//while (!feof($fp)) {
	//	$lines[] = fgets($fp);
	//}

	$len = count($lines);
	//$ispower = false;
	$ispower = true;
	$newlines = array();
	$normalline = "";
	$spaces = array();
	for ($i = 0; $i < $len; $i++) {
		$type = linetype($lines[$i]);
		if ($type === PowerSpell) {
			if ($normalline !== "") {
				$newlines[] = $normalline."\n";
				$normalline = "";
			}

			if (!$ispower) $ispower = true;
			else {
				if (count($spaces) !== 0) {
					foreach ($spaces as $as_space) {
						$newlines[] = $as_space;
					}
					$spaces = array();
				}
			}
			$powerspell = rtrim(str_replace("\r\n", "\n", $lines[$i]), "\n");
			$newlines[] = $powerspell."\n";
		} elseif ($type === Normal) {
			$line = rtrim(str_replace("\r\n", "\n", $lines[$i]), "\n");
			$normalline .= str_replace(" ", "", $line);
			$spaces = array();
			$ispower = false;
		} elseif ($type === Space) {
			//first spaces + powersell line# ⇒ this spaces is not deleteed
			//if ($ispower) $spaces[] = $lines[$i];
			//$spaces[] = $lines[$i];
			if ($ispower) $spaces[] = "\n";
		}
	}
	if (count($spaces) !== 0 && count($newlines) !== 0) {
		for ($j = 0; $j < $len; $j++) {
			if ($j !== $len - 1) $newlines[] = $spaces[$j];
			else $newlines[] = $spaces[$j];
		}
	} elseif (count($spaces) !== 0 && count($newlines) === 0) $newlines[] = "\n";

	if ($normalline !== "") {
		//$newlines[] = $normalline;
		$newlines[] = $normalline."\n";
	}

	$len = count($newlines);
	for ($i = 0; $i < $len; $i++) print($newlines[$i]);
		//if ($i !== $len - 1) print($newlines[$i]);
		//elseif ($i === $len - 1 && $newlines[$i] !== "") print(rtrim($newlines[$i]));	}
}

function linetype($line){
	//empty line = "(\n)" or "   (\n)" and "            (\n)".so not only "(\n)"
	$line = str_replace(" ", "", $line);
	$line = str_replace("\r\n", "\n", $line);
	$line = rtrim($line, "\n");

	if ($line === "") return 0;

	$elemets = str_split($line);
	$len = count($elemets);
	for ($i = 0; $i < $len; $i++) {
		if ($elemets[$i] === " ") continue;
		else {
			$first = $elemets[$i];
			break;
		}
	}
	if ($first === "#") return 1;

	return -1;
}
?>

<?php

error_reporting(0);
ob_end_clean();

define("PowerSpell", 1);
define("Space" ,0);
define("Normal" ,-1);

solve();

function solve(){
/*
	//$handle = fopen("php://stdin");
	$handle = @fopen("input.txt", "r");

	$line = fgets($handle);
	while ($line !== false) {
		$lines[] = $line;
		$line = fgets($handle);
	}
*/
	//EOF is red ⇒ \n is needed ?
	while($line = fgets(STDIN)) $lines[] = $line;

	//TLE EOF is not
	//$fp = fopen("php://stdin");
	//while (!feof($fp)) {
	//	$lines[] = fgets($fp);
	//}

	$len = count($lines);
	//$ispower = false;
	$ispower = true;
	$newlines = array();
	$normalline = "";
	$spaces = array();
	for ($i = 0; $i < $len; $i++) {
		$type = linetype($lines[$i]);
		if ($type === PowerSpell) {
			if ($normalline !== "") {
				$newlines[] = $normalline."\n";
				$normalline = "";
			}

			if (!$ispower) $ispower = true;
			else {
				if (count($spaces) !== 0) {
					foreach ($spaces as $as_space) {
						$newlines[] = $as_space;
					}
					$spaces = array();
				}
			}
			$powerspell = rtrim(str_replace("\r\n", "\n", $lines[$i]), "\n");
			$newlines[] = $powerspell."\n";
		} elseif ($type === Normal) {
			$line = rtrim(str_replace("\r\n", "\n", $lines[$i]), "\n");
			$normalline .= str_replace(" ", "", $line);
			$spaces = array();
			$ispower = false;
		} elseif ($type === Space) {
			//first spaces + powersell line# ⇒ this spaces is not deleteed
			//if ($ispower) $spaces[] = $lines[$i];
			//$spaces[] = $lines[$i];
			if ($ispower) $spaces[] = "\n";
		}
	}
	if (count($spaces) !== 0) {
		for ($j = 0; $j < $len; $j++) {
			if ($j !== $len - 1) $newlines[] = $spaces[$j];
			else $newlines[] = $spaces[$j]. "\n";
		}
	}

	if ($normalline !== "") {
		//$newlines[] = $normalline;
		$newlines[] = $normalline."\n";
	}

	$len = count($newlines);
	for ($i = 0; $i < $len; $i++) print($newlines[$i]);
		//if ($i !== $len - 1) print($newlines[$i]);
		//elseif ($i === $len - 1 && $newlines[$i] !== "") print(rtrim($newlines[$i]));	}
}

function linetype($line){
	//empty line = "(\n)" or "   (\n)" and "            (\n)".so not only "(\n)"
	$line = str_replace(" ", "", $line);
	$line = str_replace("\r\n", "\n", $line);
	$line = rtrim($line, "\n");

	if ($line === "") return 0;

	$elemets = str_split($line);
	$len = count($elemets);
	for ($i = 0; $i < $len; $i++) {
		if ($elemets[$i] === " ") continue;
		else {
			$first = $elemets[$i];
			break;
		}
	}
	if ($first === "#") return 1;

	return -1;
}
?>

<?php

error_reporting(0);
ob_end_clean();

define("PowerSpell", 1);
define("Space" ,0);
define("Normal" ,-1);

solve();

function solve(){
/*
	//$handle = fopen("php://stdin");
	$handle = @fopen("input.txt", "r");

	$line = fgets($handle);
	while ($line !== false) {
		$lines[] = $line;
		$line = fgets($handle);
	}
*/
	//EOF is red ⇒ \n is needed ?
	while($line = fgets(STDIN)) $lines[] = $line;

	//TLE EOF is not
	//$fp = fopen("php://stdin");
	//while (!feof($fp)) {
	//	$lines[] = fgets($fp);
	//}

	$len = count($lines);
	//$ispower = false;
	$ispower = true;
	$newlines = array();
	$normalline = "";
	$spaces = array();
	for ($i = 0; $i < $len; $i++) {
		$type = linetype($lines[$i]);
		if ($type === PowerSpell) {
			if ($normalline !== "") {
				$newlines[] = $normalline."\n";
				$normalline = "";
			}

			if (!$ispower) $ispower = true;
			else {
				if (count($spaces) !== 0) {
					foreach ($spaces as $as_space) {
						$newlines[] = $as_space;
					}
					$spaces = array();
				}

			}
			$powerspell = rtrim(str_replace("\r\n", "\n", $lines[$i]), "\n");
			$newlines[] = $powerspell."\n";
		} elseif ($type === Normal) {
			$line = rtrim(str_replace("\r\n", "\n", $lines[$i]), "\n");
			$normalline .= str_replace(" ", "", $line);
			$spaces = array();
			$ispower = false;
		} elseif ($type === Space) {
			//first spaces + powersell line# ⇒ this spaces is not deleteed
			//if ($ispower) $spaces[] = $lines[$i];
			//$spaces[] = $lines[$i];
			if ($ispower) $spaces[] = "\n";
		}
	}

	if ($normalline !== "") {
		//$newlines[] = $normalline;
		$newlines[] = $normalline."\n";
	}

	$len = count($newlines);
	for ($i = 0; $i < $len; $i++) print($newlines[$i]);
		//if ($i !== $len - 1) print($newlines[$i]);
		//elseif ($i === $len - 1 && $newlines[$i] !== "") print(rtrim($newlines[$i]));	}
}

function linetype($line){
	//empty line = "(\n)" or "   (\n)" and "            (\n)".so not only "(\n)"
	$line = str_replace(" ", "", $line);
	$line = str_replace("\r\n", "\n", $line);
	$line = rtrim($line, "\n");

	if ($line === "") return 0;

	$elemets = str_split($line);
	$len = count($elemets);
	for ($i = 0; $i < $len; $i++) {
		if ($elemets[$i] === " ") continue;
		else {
			$first = $elemets[$i];
			break;
		}
	}
	if ($first === "#") return 1;

	return -1;
}
?>

<?php

error_reporting(0);
ob_end_clean();

define("PowerSpell", 1);
define("Space" ,0);
define("Normal" ,-1);

solve();

function solve(){

	//$handle = fopen("php://stdin");
	$handle = @fopen("input.txt", "r");

	$line = fgets($handle);
	while ($line !== false) {
		$lines[] = $line;
		$line = fgets($handle);
	}

	//EOF is red ⇒ \n is needed ?
	//while($line = fgets(STDIN)) $lines[] = $line;

	//TLE EOF is not
	//$fp = fopen("php://stdin");
	//while (!feof($fp)) {
	//	$lines[] = fgets($fp);
	//}

	$len = count($lines);
	$ispower = false;
	$newlines = array();
	$normalline = "";
	$spaces = array();
	for ($i = 0; $i < $len; $i++) {
		$type = linetype($lines[$i]);
		if ($type === PowerSpell) {
			if ($normalline !== "") {
				$newlines[] = $normalline."\n";
				$normalline = "";
			}

			if (!$ispower) $ispower = true;
			else {
				if (count($spaces) !== 0) {
					foreach ($spaces as $as_space) {
						$newlines[] = $as_space;
					}
					$spaces = array();
				}

			}
			$newlines[] = $lines[$i];
		} elseif ($type === Normal) {
			$line = rtrim(str_replace("\r\n", "\n", $lines[$i]), "\n");
			$normalline .= str_replace(" ", "", $line);
			$spaces = array();
			$ispower = false;
		} elseif ($type === Space) {
			if ($ispower) $spaces[] = $lines[$i];
		}
	}

	if ($normalline !== "") {
		//$newlines[] = $normalline;
		$newlines[] = $normalline;
	}

	$len = count($newlines);
	for ($i = 0; $i < $len; $i++) print($newlines[$i]);
		//if ($i !== $len - 1) print($newlines[$i]);
		//elseif ($i === $len - 1 && $newlines[$i] !== "") print(rtrim($newlines[$i]));	}
}

function linetype($line){
	$line = str_replace("\r\n", "\n", $line);
	$line = rtrim($line, "\n");

	if ($line === "") return 0;

	$elemets = str_split($line);
	$len = count($elemets);
	for ($i = 0; $i < $len; $i++) {
		if ($elemets[$i] === " ") continue;
		else {
			$first = $elemets[$i];
			break;
		}
	}
	if ($first === "#") return 1;

	return -1;
}
?>

<?php

error_reporting(0);
ob_end_clean();

define("PowerSpell", 1);
define("Space" ,0);
define("Normal" ,-1);

solve();

function solve(){
	//$handle = fopen("php://stdin");
	//$handle = @fopen("input.txt", "r");

	//$line = fgets($handle);
	$line = fgets("php://stdin");
	while ($line !== false) {
		$lines[] = $line;
		$line = fgets("php://stdin");
	}

	$len = count($lines);
	$ispower = false;
	$newlines = array();
	$normalline = "";
	$spaces = array();
	for ($i = 0; $i < $len; $i++) {
		$type = linetype($lines[$i]);
		if ($type === PowerSpell) {
			if ($normalline !== "") {

				$newlines[] = $normalline."\n";
				$normalline = "";
			}

			if (!$ispower) $ispower = true;
			else {
				if (count($spaces) !== 0) {
					foreach ($spaces as $as_space) {
						$newlines[] = $as_space;
					}
				}
				$spaces = array();
			}
			$newlines[] = $lines[$i];
		} elseif ($type === Normal) {
			$line = rtrim(str_replace("\r\n", "\n", $lines[$i]), "\n");
			$normalline .= str_replace(" ", "", $line);
			$spaces = array();
			$ispower = false;
		} elseif ($type === Space) {
			if ($ispower) $spaces[] = $lines[$i];
		}
	}

	if ($normalline !== "") {
		$newlines[] = $normalline;
	}

	$len = count($newlines);
	for ($i = 0; $i < $len; $i++) {
		if ($i !== $len - 1) print($newlines[$i]);
		elseif ($i === $len - 1 && $newlines[$i] !== "") print(rtrim($newlines[$i]));	}
}

function linetype($line){
	$line = str_replace("\r\n", "\n", $line);
	$line = rtrim($line, "\n");

	if ($line === "") return 0;

	$elemets = str_split($line);
	$len = count($elemets);
	for ($i = 0; $i < $len; $i++) {
		if ($elemets[$i] === " ") continue;
		else {
			$first = $elemets[$i];
			break;
		}
	}
	if ($first === "#") return 1;

	return -1;
}
?>

<?php

error_reporting(0);
ob_end_clean();

solve();

function solve(){
/*
	//$handle = fopen("php://stdin");
	$handle = @fopen("input.txt", "r");

	$line = fgets($handle);
	while ($line !== false) {
		$lines[] = $line;
		$line = fgets($handle);
	}
*/
	$flag = 0;
	//$fp = @fopen("input.txt", "r");
	//while (!feof($fp)) {
		//$line = rtrim(fgets($fp), "\r\n");
	$fp = @fopen(STDIN);
	while ($line = fgets($fp)) {
		$line = rtrim($line, "\r\n");
		$text = ltrim($line);
		if ($text[0] === "#") {
			if ($flag === 1) {
				print($replaceds."\n");
				$replaceds = "";
			}
			print($line."\n");
			$flag = 0;
		} else {
			$replaceds .= str_replace(" ", "", $text);
			$flag = 1;
		}
	}
	if ($flag === 1) {
		print($replaceds."\n");
	}
	fclose($fp);
}
?>


<?php
$n = 0;
$colOper = trim(fgets(STDIN));
for ($i=0;$i<$colOper;$i++) {
    $operand = trim(fgets(STDIN));
    if ($operand == '++X') {
        ++$n;
    }
    elseif ($operand == 'X++') {
        $n++;
    }
    elseif ($operand == '--X') {
        --$n;
    }
    elseif ($operand == 'X--') {
        $n--;
    }
}
echo $n;

<?php

$stdin = fopen('php://stdin','r');
$n = trim(fgets($stdin));

$a=0;
for ($i=0;$i<$n;$i++)
{
    $s = trim(fgets($stdin));
    if ($s[1]=='+') {$a++;} else {$a--;}
}
fclose($stdin);

echo $a;
?>

<?php
$r=0;
$stmt= array();
fscanf(STDIN, "%d",$n);
for($i=0;$i<$n;$i++){
    fscanf(STDIN, "%s",$stmt[$i]);
}
for($i=0;$i<$n;$i++){
    if(strtolower($stmt[$i])== "++x"|strtolower($stmt[$i])== "x++")
    $r++;
    else
    $r--;
}
echo $r;

<?php
    $fp = fopen('php://stdin', 'r');
    $n = rtrim(fgets($fp));
    $operators = array();
    while(!feof($fp)) {
        $operators[] = rtrim(fgets($fp));
    }
    $x = 0;
    for($i=0; $i < $n; $i++)
        if(strpos($operators[$i], '++') !== false)
            $x++;
        else
            $x--;
    echo $x;
?>

<?php
	$total = 0;
	$n = fgets(STDIN);
	for ($x = 0; $x < $n; $x++) {
		$in = fgets(STDIN);
		if (substr_count($in, '++')) {
			$total++;
		} elseif (substr_count($in, '--')) {
			$total--;
		}
	}
	echo $total;
?>

<?php
while($str = fgets(STDIN)) $arr[] = explode(' ', trim($str));
if(!isset($arr)) {
    $arr[] = explode(' ', '2');
    $arr[] = explode(' ', 'X++');
    $arr[] = explode(' ', '--X');
}
$out = 0;
for($i=1; $i<sizeof($arr); $i++) {
    if(strpos($arr[$i][0], '++')!==false) $out++;
    elseif(strpos($arr[$i][0], '--')!==false) $out--;
}
echo $out;
?>

<?  fscanf(STDIN,"%d",$x);$x=0;
    while(fscanf(STDIN,"%s",$s)){
        eval(str_replace("X","\$x",$s).";");
    }
    echo $x; ?>

<?  fscanf(STDIN,"%d",$x);$x=0;
    while(fscanf(STDIN,"%s",$s)){
        $s=str_replace("X","\$x",$s);
        eval($s.";");
    }
    fprintf(STDOUT,"%d",$x); ?>

<?php
$input = STDIN;
$output = STDOUT;

fscanf($input,"%d",$n);
$x = 0;
for($i=0; $i<$n; ++$i) {
    fscanf($input,"%s",$xstr);
    switch($xstr[1]) {
        case '+':
            ++$x;
            break;
        case '-':
            --$x;
            break;
    }
}
fprintf($output,"%d",$x);

?>

<?php

$x = 0;
$n = (int) readline();

for ( $i = 0; $i < $n; $i++ ) {
	$str = readline();
	$x = $x + substr_count($str, '++');
	$x = $x - substr_count($str, '--');
}

echo $x;

<?
$num = (int) trim(fgets(STDIN));

$x = 0;
for($i = 0; $i < $num; $i++){
    if(strpos(fgets(STDIN), '--') !== false){
        $x--;
    }else{
        $x++;
    }
}
echo $x;

<?php
$n = (int)readline();
$output = 0;
for($i = 0; $i < $n; $i++) {
    $input = readline();
    $input[1] == '+' ? $output++ : $output--;
}
echo $output;

<?php
    $n = trim(fgets(STDIN));
    $result = 0;
    for($i = 0; $i < $n; $i++){
        $args[$i] = trim(fgets(STDIN));
        if(strpos($args[$i],"++") === false) $result--;
        else $result++;
    }
    fwrite(STDOUT, $result);

<?php
while($s = fgets(STDIN))
{
    $input .= $s;
}

$input = explode("\n", $input);
unset($input[0]);
$x = 0;

foreach($input as $line)
{
    $line = str_replace(array('x', 'X'), '', trim($line));
    if ($line == '--')
    {
        $x--;
    }

    if ($line == '++')
    {
        $x++;
    }
}

echo $x;

<?php
	 // Check Examples

 //php 7.3.0

 	$f = fopen( 'php://stdin', 'r' );
 	$sum = 0;

while( $line = fgets( $f ) ) {

  if (stripos($line, '+') !== false) $sum++;
  if (stripos($line, '-') !== false) $sum--;
}

fclose( $f );
echo $sum;
 ?>

<?php
//Codeforces Round #173 (Div. 2)
//13 Mar 2013

// Retrieve input
$stdin = fopen('php://stdin', 'r');
function input()
{
	global $stdin;
	$ashar = explode(" ", trim(fgets($stdin)));
	return $ashar[0];
}

$N = input();
$risan = 0;

while ($N-- > 0)
{
	$s = input();
	if ($s == "++X" || $s == "X++") ++$risan;
	else --$risan;
}

echo $risan;
echo "\n";

?>

<?php
$num_str = fgets(STDIN);
$result = 0;
for ($i = 1; $i <= $num_str; $i++) {
    $cur_str = fgets(STDIN);
    if ($cur_str[1] == "+") {
        $result++;
    } else {
        $result--;
    }
}
echo $result;
?>

<?php
	$stdin = fopen('php://stdin', 'r');
	function input()
	{
		global $stdin;
		$ashar = explode(" ", trim(fgets($stdin)));
		return $ashar[0];
	}

	$n = input();
	$result = 0;
	for ($i = 0; $i < $n; $i++)
	{
		$str = input();
		if ($str[1] == '-')
		{
			$result--;
		}
		else
		{
			$result++;
		}
	}
	echo $result;
?>

<?php
$input = file('php://stdin', FILE_IGNORE_NEW_LINES);
array_shift($input);
$x = 0;
foreach ($input as $command) {
    if (strpos($command, '+') !== false) {
       $x ++;
    } else {
        $x --;
    }
}
echo $x;

<?php
$X = 0;
fscanf(STDIN, "%d", $n);
while($n--) {
	fscanf(STDIN, "%s", $s);
	if(strpos($s, "++") !== false) {
		++$X;
	}
	else {
		--$X;
	}
}
echo $X;

<?php
$input = trim(fgets(STDIN));
$noOfInputs = (int)$input;
$x = 0;
for($counter = 0 ; $counter < $noOfInputs; $counter++){
    $input = trim(fgets(STDIN));
    if($input == "--X" || $input == "X--"){
        $x--;
    }else{
        $x++;
    }
}
echo $x;
?>

<?php
$n = trim(fgets(STDIN));
$nilai = 0;
while($n--){
	$s = trim(fgets(STDIN));
	eval(str_replace("X", "\$nilai", $s) . ";");
/*	if (substr_count($s, "++"))
		$nilai++;
	else if ($substr_count($s, "--"))
		$nilai--; */
}
print $nilai;
?>

<?php
    $f = fopen('php://stdin', 'r');
    $cnt = (int)fgets($f);
    $ount = 0;
    for ($i = 0; $i < $cnt; $i++) {
        $out+= strpos(fgets($f), '+') === FALSE ? -1 : 1;
    }
    echo $out;
?>

<?php
/**
 * Created by IntelliJ IDEA.
 * User: 低调的程序员
 * Date: 2015/4/25
 * Time: 1:17
 */

while(fscanf(STDIN,"%d",$n)){
    $ans=0;
    while($n-->0){
        $str=stream_get_line(STDIN,10,"\n");
        $h=substr($str,0,2);
        $t=substr($str,1,2);
        if($h=="++" or $t=="++")$ans++;
        else $ans--;
    }
    fprintf(STDOUT,"%d\n",$ans);
}

<?php

//First Get The Input.
$input = file_get_contents("php://stdin");

//Get The Number Of Statements.
$n = (int)explode("\n",$input)[0];

//Then Loop Throw The Statements To Apply Them On ( x ).
$int = 0;

for($i = 0;$i < $n;$i++) {

    $current_statement = (string)explode("\n",$input)[$i + 1];

    $current_statement = trim($current_statement,"\r\n");

    if(in_array($current_statement,array("X++","++X"))) {

        $int++;

    }elseif(in_array($current_statement,array("X--","--X"))) {

        $int--;

    }

}

//return ( x ).
echo $int;

?>

<?php

/**
 * @return int
 */
function getInt() {
    return (int) trim(fgets(STDIN));
}

/**
 * @return string
 */
function getStr() {
    return (string) trim(fgets(STDIN));
}

/**
 * @return array
 */
function getRow($len) {
    return array_slice(explode(' ', trim(fgets(STDIN))), 0, $len);
}

const N = "\n";

/*** SOLVING */

$x = 0;
$n = getInt();

while ($n--) {
    $str = getStr();
    if ($str == 'X++' OR $str == '++X') {
        $x++;
    } else if ($str == 'X--' OR $str == '--X') {
        $x--;
    } else if ($str == 'X++' OR $str == '++X') {
        $x = -$x;
    }
}

echo $x;

<?php
$x=0;
$i=0;
$b=fgets(STDIN);
while ($i<$b) {
	$a=str_replace("X","",trim(fgets(STDIN)));
	if($a=="--")
		$x--;
	else
		$x++;
	$i++;
}
echo $x;
?>

<?php
// 282A 	Bit++

$in = fopen("php://stdin", 'r');

$input_line = fgets($in);
$n = (int) $input_line;

$out = 0;

for ($i=1; $i <= $n; $i++) {

    $input_line = fgets($in);

    if (substr($input_line, 1, 1) == '+') {
        $out++;
    } else {
        $out--;
    }
}

echo $out;

?>

<?php

class Solution
{
    public function solve()
    {
        fscanf(STDIN, '%d', $n);

        $x = 0;
        while ($n--) {
            fscanf(STDIN, '%s', $s);
            $x += strpos($s, '-') !== false ? -1 : 1;
        }

        echo $x . PHP_EOL;
    }
}

$sol = new Solution();
$sol->solve();

<?php

$inputString = fgets(STDIN);

$n = (int) $inputString;

$answer = 0;
for ($i = 1; $i <= $n; $i++) {
    $inputString = rtrim(fgets(STDIN));
    if ($inputString[0] == '+' || $inputString[1] == '+' || $inputString[2] == '+') {
        $answer++;
    } else {
        $answer--;
    }
}

echo  $answer . PHP_EOL;

<?php
fscanf(STDIN, '%d\n', $n);
$lines = array();
$x = 0;

for($i = 0; $i < $n; $i++) {	// считываем n строк
	$lines[$i] = fgets(STDIN);

}

	foreach($lines as $line) {
		$line = trim($line);		// хз почему, но это как-то сработало.
	if(($line == '++X') | ($line == 'X++')){
			$x++;
		} else {
			$x--;
		}

	 }

	printf($x);

<?php
/*$in = fopen('php://stdin', 'r');
$result = 0;
$num_str = (int)(fgets($in));
$cur_str = trim(fgets($in));
if ($cur_str == "++x") {
    $result = $result + 1;
}
echo $result;*/
$num_str = (int)(fgets(STDIN));
$result = 0;
for ($i = 1; $i <= $num_str; $i++) {
    $cur_str = fgets(STDIN);
    if ($cur_str[1] == "+") {
        $result++;
    } else {
        $result--;
    }
}
echo $result;
?>

<?php
fscanf(STDIN, '%d', $n);

function oper($string) {
    for ($i = 0; $i < strlen($string); $i++) {
       if ($string[$i] == '+') return true;
    }

    return false;
}

$wynik = 0;
while($n--) {
    fscanf(STDIN, '%s', $string);
    if (oper($string)) $wynik++;
    else $wynik--;
}

echo $wynik;

<?php
$x=0;
fscanf(STDIN, "%d",$n);
for ($i=0; $i < $n; $i++) {
	fscanf(STDIN,"%s",$operator);

	if ($operator==="++X" || $operator==="X++") $x++;
	else $x--;
}
echo $x;
?>

<?php

function dd(...$args)
{
    var_dump(...$args);
    die;
}

define('TXTIN', fopen('input.txt', 'r'));
define('TXTOUT', fopen('output.txt', 'w'));

//$input = TXTIN;
$input = STDIN;

//$output = TXTOUT;
$output = STDOUT;

function foo($x)
{
    return $x === '++X' || $x === 'X++';
}

$r = 0;

list($n) = fscanf($input, "%d\n");

for ($i = 0; $i < $n; ++$i) {
    list($x) = fscanf($input, "%s\n");

    $r = foo($x) ? $r + 1 : $r - 1;
}

fwrite($output, $r);

<?
$n=trim(fgets(STDIN));
$x=0;
for($i=0;$i<$n;$i++)
    {
        $op=trim(fgets(STDIN));
        if(strpos($op,'+')!== False)++$x;
        else --$x;
    }
   echo $x;
?>

<?php
$a = array();
fscanf(STDIN, "%d", $n);
for ($i = 0; $i < $n; $i++) {
	$a[] = trim(fgets(STDIN));
}
$result = 0;
foreach ($a as $task) {
	if ($task == '++X' || $task == 'X++')
		$result++;
	else
		$result--;
}

fprintf(STDOUT, $result);

<?php
// http://codeforces.com/problemset/problem/282/A

// Input
// The first line contains a single integer n (1 ≤ n ≤ 150) — the number of statements in the programme.
$n = fgets(STDIN);

// The language is that peculiar as it has exactly one variable, called x.
$x = 0;

// Next n lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable x (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order.
for ($i=0; $i < $n; $i++)
{
	$operation = rtrim(fgets(STDIN));

	if (false !== strpos($operation, '++'))
		$x++;
	else
		$x--;
}

echo $x;

?>

<?php
    $x = trim(fgets(STDIN));
    $ret = 0;

    for ($i=0; $i<$x; $i++)
    {
        $s = trim(fgets(STDIN));
        if (strpos($s,"++") === false)
            $ret--;
        else
            $ret++;

    }
    echo $ret;
?>

<?php

$stdin = fopen('php://stdin', 'r');

fscanf($stdin, "%d", $n);

$res = 0;
for($i = 0; $i < $n; $i++)
{
	fscanf($stdin, "%s", $com);
	if(preg_match('/\+/', $com))
	{
		$res++;
	}
	else
	{
		$res--;
	}
}

echo $res;

<?php

fscanf(STDIN, "%d\n", $number);
$i = 0;
$counter = 0;

while($i<$number && $line = trim(fgets(STDIN))){

    if($line == '++X' || $line == 'X++') $counter++ ;
	else $counter-- ;
}

fwrite(STDOUT, $counter."\n");

<?php

while($item = trim(fgets(STDIN))) {
    $data[] = $item;
}
$count = array_shift($data);
$result = 0;
for ($i = 0; $i <=$count; $i++) {
    if($data[$i][1] === '+') {
        $result++;
    } elseif($data[$i][1] === '-') {
        $result--;
    }
}

echo $result;

<?php
$n = trim(fgets(STDIN));
$operation = array();
for( $i=0; $i<$n; $i++ ){
    $operation[$i] = preg_replace('/x/i','',trim(fgets(STDIN)));
}

$output = 0;
for( $i=0; $i<$n; $i++ ){
    if( $operation[$i] == '++' ){
        $output++;
    }elseif( $operation[$i] == '--' )
    {
        $output--;
    }
}
echo $output;

<?php
//282A: Bit++
$n = trim(fgets(STDIN));
$x = 0;
for ($i = 0; $i < $n; $i++) {
    $explode = str_split(trim(fgets(STDIN)));
    sort($explode);
    if ($explode[0] == "+") {
        $x++;
    } else {
        $x--;
    }
}
echo $x;
?>

<?php

$is_first = true;
$x = 0;
while ($row = fgets(STDIN)) {
    if ($is_first === true) {
        $is_first = false;
        continue;
    }
    if (strpos($row, '++') !== false) {
        $x++;
    }
    if (strpos($row, '--') !== false) {
        $x--;
    }
}
echo $x;

<?php
	fscanf(STDIN, '%d', $num);
	$res = 0;
	while (fscanf(STDIN, '%s', $input)){
		if(strpos($input, '++') !== false) $res++;
		if(strpos($input, '--') !== false) $res--;
	}
	echo $res;
?>

<?php
$n=fgets(STDIN);
$k = 0;
for ($i=0; $i < $n; $i++) {
	$a=fgets(STDIN);
	if (strripos($a, '+')) $k++;
	else $k--;
}
print($k);
?>

<?  fscanf(STDIN,"%d",$x);$x=0;
    while(fscanf(STDIN,"%s",$s)){
        eval(str_replace("X","\$x",$s).";");
    }
    echo $x; ?>

<?php
$n = trim(fgets(STDIN));
$counter = 0;
for ($i = 1; $i <= $n; $i++)
{
   // list($a, $b, $c) = explode(' ', trim(fgets(STDIN)));
   $str = trim(fgets(STDIN));
   $str = str_replace("X", "", $str);
   if ($str == '++')
        $counter++;
    else
        $counter--;
   //if (($a+$b+$c) > 1) $counter++;
}

echo $counter;

<?php

$x = 0;

$n = readline();

for($i = 0; $i < $n; $i++) {
    $line = readline();
    $len = 3;

    for($k = 0; $k < $len; $k++) {
        switch($line[$k]) {
            case '+':
                $x++;
                continue 3;
            case '-':
                $x--;
                continue 3;
            case 'X':
                continue 2;
        }
    }

}

echo $x;

<?php
$n = (fgets(STDIN));
$result=0;
for ($i=0;$i<$n;$i++)
{
    $line = fgets(STDIN);
    if (strripos($line,"++")!==false)
    {
        $result++;
    }
    else
    {
        $result--;
    }
}
echo $result;
?>

<?php

function getStdIn(bool $asInt = false): array
{
    $stdIn = explode(' ', trim(fgets(STDIN)));

    if ($asInt) {
        foreach ($stdIn as $key => $value) {
            $stdIn[$key] = (int)$value;
        }
    }

    return $stdIn;
}

function stdOut($output)
{
    fwrite(STDOUT, $output);
}

function solve(): void
{
    [$n] = getStdIn(true);
    $x = 0;

    for ($i = 0; $i < $n; $i++) {
        [$operation] = getStdIn();
        if (strpos($operation, '++') !== false) {
            $x++;
        } elseif (strpos($operation, '--') !== false) {
            $x--;
        }
    }

    stdOut($x);
}

solve();

<?php
    $fp = fopen('php://stdin', 'r');
    $n = rtrim(fgets($fp));
    $operations = array();
    while(!feof($fp)) {
        $operations[] = rtrim(fgets($fp));
    }
    $x = 0;
    foreach($operations as $o) {
        if(strpos($o, '++')!==false)
            $x++;
        else
            $x--;
    }
    echo $x;
?>

<?php
    $fp = fopen('php://stdin', 'r');
    $n = rtrim(fgets($fp));
    $operations = array();
    while(!feof($fp)) {
        $operations[] = rtrim(fgets($fp));
    }
    $x = 0;
    foreach($operations as $o) {
        if(strpos($o, '++'))
            $x++;
        else
            $x--;
    }
    echo $x;
?>

<?php
	$total = 0;
	$n = fgets(STDIN);
	for ($x = 0; $x < $n; $x++) {
		if (substr_count(fgets(STDIN), '++')) {
			$total++;
		} elseif (substr_count(fgets(STDIN), '++')) {
			$total--;
		}
	}
	echo $total;
?>

<?php
	$total = 0;
	$n = fgets(STDIN);
	for ($x = 0; $x < $n; $x++) {
		if (substr_count(fgets(STDIN), '++')) {
			$total++;
		} elseif (substr_count(fgets(STDIN), '--')) {
			$total--;
		}
	}
	echo $total;
?>

<?php
while($str = fgets(STDIN)) $arr[] = explode(' ', trim($str));
if(!isset($arr)) {
    $arr[] = explode(' ', '2 4');
}
$out = 0;
for($i=1; $i<sizeof($arr); $i++) {
    if(strpos($arr[$i], '++')!==false) $out++;
    elseif(strpos($arr[$i], '--')!==false) $out--;
}
echo $out;
?>

<?
$num = (int) trim(fgets(STDIN));

$x = 0;
for($i = 0; $i < $num; $i++){
    if(strpos('--', fgets(STDIN)) !== false){
        $x--;
    }else{
        $x++;
    }
}
echo $x;

<?php
while($s = fgets(STDIN))
{
    $input .= $s;
}

$input = explode("\n", $input);
unset($input[0]);
$x = 0;

foreach($input as $line)
{
    $line = str_replace('X', '', trim($line));
    if ($line == '--') {
        $x--;
    } else {
        $x++;
    }
}

echo $x;

<?php
while($s = fgets(STDIN))
{
    $input .= $s;
}

$input = explode("\n", $input);
unset($input[0]);
$x = 0;

foreach($input as $line)
{
    $line = str_replace(array('x', 'X'), '', trim($line));
    if ($line == '--') {
        $x--;
    } else {
        $x++;
    }
}

echo $x;

<?php
while($s = fgets(STDIN))
{
    $input .= $s;
}

$input = explode("\r\n", $input);
unset($input[0]);
$x = 0;

foreach($input as $line)
{
    $line = str_replace('X', '', trim($line));
    if ($line == '--') {
        $x--;
    } else {
        $x++;
    }
}

echo $x;

<?php
$in = fopen('php://stdin', 'r');
$result = 0;
$num_str = (int)(fgets($in));
$cur_str = fgets($in);
settype($cur_str, "string");
if ($cur_str == "++x" || $cur_str == "++X") $result++;

echo $result;
?>

<?php
$in = fopen('php://stdin', 'r');
$result = 0;
$num_str = (int)(fgets($in));
$cur_str = fgets($in);
if ($cur_str == '++x') $result++;

echo $result;
?>

<?php
$in = fopen('php://stdin', 'r');
$result = 0;
$num_str = (int)(fgets($in));
for ($i = 1; $i <= $num_str; $i++) {
    $cur_str = fgets($in);
    if ($cur_str == "++x" || $cur_str == "x++") $result++;
    if ($cur_str == "--x" || $cur_str == "x--") $result--;
}
echo $result;
?>

<?php
$in = fopen('php://stdin', 'r');
$result = 0;
$num_str = (int)(fgets($in));
$cur_str = fgets($in);
settype($cur_str, "string");
if ($cur_str == "++x") $result++;

echo $result;
?>

<?php
/*$in = fopen('php://stdin', 'r');
$result = 0;
$num_str = (int)(fgets($in));
$cur_str = trim(fgets($in));
if ($cur_str == "++x") {
    $result = $result + 1;
}
echo $result;*/
$num_str = (int)(fgets(STDIN));
$result = 0;
for ($i = 1; $i <= $num_str; $i++) {
    $cur_str = fgets(STDIN);
    if ($cur_str == "++x" || $cur_str == "x++") {
        $result++;
    } else {
        $result--;
    }
}
echo $result;
?>

<?php
$in = fopen('php://stdin', 'r');
$result = 0;
$num_str = (int)(fgets($in));
for ($i = 1; $i <= $num_str; $i++) {
    $cur_str = fgets($in);
    settype($cur_str, "string");
    if ($cur_str == "++x" || $cur_str == "x++") $result++;
    if ($cur_str == "--x" || $cur_str == "x--") $result--;
}
echo $result;
?>

<?php
$in = fopen('php://stdin', 'r');
$result = 0;
$num_str = (int)(fgets($in));
$cur_str = fgets($in);
if ($cur_str == "++x") $result = 10;

echo $result;
?>

<?php
$in = fopen('php://stdin', 'r');
$result = 0;
$num_str = (int)(fgets($in));
$cur_str = fgets($in);
settype($cur_str, "string");
if ($cur_str == "++x" || $cur_str == "++X") {
    $result = $result + 1;
}
echo $result;
?>

<?php
/*$in = fopen('php://stdin', 'r');
$result = 0;
$num_str = (int)(fgets($in));
$cur_str = trim(fgets($in));
if ($cur_str == "++x") {
    $result = $result + 1;
}
echo $result;*/
$num_str = (int)(fgets(STDIN));
$result = 0;
for ($i = 1; $i <= $num_str; $i++) {
    $cur_str = fgetc(STDIN);
    if ($cur_str == "+") {
        $result++;
    } else {
        $result--;
    }
}
echo $result;
?>

<?php
$number_string = fgets(STDIN);
$result = 0;
for ($counter = 1; $counter <= $number_string; $counter++) {
    $current_string = fgets(STDIN);
    if (($current_string == "x++") || ($current_string == "++x")) {
        $result = $result + 1;
    } else {
        $result = $result - 1;
    }
}
echo $result;
?>

<?php
$in = fopen('php://stdin', 'r');
$cur_str = fgets($in);
$next_str = fgets($in);
//$result = 0;
//while (! feof($in)) {
/*    $cur_str = fgets($in);
    if ($cur_str == "++x" || $cur_str == "x++") {
        $result = $result + 1;
    } elseif ($cur_str == "--x" || $cur_str == "x--") {
        $result = $result - 1;
    }*/
    //$result = $result + 1;
//}
echo $next_str;
?>

<?php
$in = fopen("php://stdin", "r");
$result = 0;
while (!feof($in)) {
    $cur_str = fgets($in);
    if ($cur_str == "++x" or $cur_str == "x++") {
        $result = $result + 1;
    } else if ($cur_str == "--x" or $cur_str == "x--") {
        $result = $result - 1;
    }
}
echo $result;
?>

<?php
$number_string = fgets(STDIN);
$result = 0;
for ($counter = 1; $counter <= $number_string; $counter++) {
    $current_string = fgets(STDIN);
    if ($current_string == "x++" || $current_string == "++x") {
        $result = $result + 1;
    } else {
        $result = $result - 1;
    }
}
echo $result;
?>

<?php
$number_string = fgetc(STDIN);
$result = 0;
for ($counter = 1; $counter <= $number_string; $counter++) {
    $current_string = fgetc(STDIN);
    if (($current_string == "x++") || ($current_string == "++x")) {
        $result = $result + 1;
    } else {
        $result = $result - 1;
    }
}
echo $result;
?>

<?php
$number_string = (int)(fgetc(STDIN));
$result = 0;
for ($counter = 0; $counter <= $number_string; $counter++) {
    $current_string = fgetc(STDIN);
    if (($current_string == "x++") || ($current_string == "++x")) {
        $result = $result + 1;
    } else {
        $result = $result - 1;
    }
}
echo $result;
?>

<?php
$in = fopen('php://stdin', 'r');
$result = 0;
while (!feof($in)) {
    $cur_str = fgets($in);
    if ($cur_str == "++x" || $cur_str == "x++") {
        $result = $result + 1;
    } elseif ($cur_str == "--x" || $cur_str == "x--") {
        $result = $result - 1;
    }
}
echo $result;
?>

<?php
$in = fopen('php://stdin', 'r');
$cur_str = fgets($in);
//$result = 0;
//while (! feof($in)) {
/*    $cur_str = fgets($in);
    if ($cur_str == "++x" || $cur_str == "x++") {
        $result = $result + 1;
    } elseif ($cur_str == "--x" || $cur_str == "x--") {
        $result = $result - 1;
    }*/
    //$result = $result + 1;
//}
echo $cur_str;
?>

<?php
$in = fopen('php://stdin', 'r');
$result = 20;
$num_str = (int)(fgets($in));
$cur_str = fgets($in);
if ($cur_str == "\+\+x") $result = 10;

echo $result;
?>

<?php
$number_string = (int)(fgetc(STDIN));
$result = 0;
for ($counter = 1; $counter <= $number_string; $counter++) {
    $current_string = fgetc(STDIN);
    if (($current_string == "x++") || ($current_string == "++x")) {
        $result = $result + 1;
    } else {
        $result = $result - 1;
    }
}
echo $result;
?>

<?php
$in = fopen("php://stdin", "r");
$result = 0;
while (!feof($in)) {
    $cur_str = fgets($in);
    if ($cur_str == "++x" or $cur_str == "x++") {
        $result = $result + 1;
    } else if ($cur_str == "--x" or $cur_str == "x--") {
        $result = $result - 1;
    } else break;
}
echo $result;
?>

<?php
$in = fopen('php://stdin', 'r');
$result = 20;
$num_str = (int)(fgets($in));
$cur_str = fgets($in);
if ($cur_str == "\+\+x") $result = 10;

echo $cur_str;
?>

<?php
$in = fopen('php://stdin', 'r');
$result = 0;
$num_str = (int)(fgets($in));
$cur_str = fgets($in);
if ($cur_str == "\+\+x") $result = 10;

echo $result;
?>

<?php
/*$in = fopen('php://stdin', 'r');
$result = 0;
$num_str = (int)(fgets($in));
$cur_str = trim(fgets($in));
if ($cur_str == "++x") {
    $result = $result + 1;
}
echo $result;*/
$num_str = (int)(fgets(STDIN));
echo $num_str;
?>

<?php
$in = fopen('php://stdin', 'r');
$result = 0;
$num_str = (int)(fgets($in));
$cur_str = trim(fgets($in));
if ($cur_str == "++x") {
    $result = $result + 1;
}
echo $result;
?>

<?php
/*$in = fopen('php://stdin', 'r');
$result = 0;
$num_str = (int)(fgets($in));
$cur_str = trim(fgets($in));
if ($cur_str == "++x") {
    $result = $result + 1;
}
echo $result;*/
$num_str = (int)(fgets(STDIN));
$result = 0;
for ($i = 1; $i <= $num_str; $i++) {
    $cur_str = fgetc(STDIN);
    if ($cur_str == "++x" || $cur_str == "x++") {
        $result++;
    } else {
        $result--;
    }
}
echo $result;
?>

<?php
$in = fopen('php://stdin', 'r');
$result = 0;
$num_str = (int)(fgets($in));
$cur_str = fgets($in);
if ($cur_str == "++X") $result++;

echo $result;
?>

<?php
$dir = fopen("php://stdin", 'r');
$input = stream_get_contents($dir);

$arr = explode(PHP_EOL, $input);
$x = 0;
for($i=1;$i<count($arr);$i++){
  if($arr[$i][1] == '+')
    $x++;
  else
    $x--;
}
echo $x."\n";

<?php
$dir = fopen("php://stdin", 'r');
$input = stream_get_contents($dir);
// $input="2
// ++x
// ++x";

$arr = explode(PHP_EOL, $input);

$x = 0;
for($i=1;$i<count($arr);$i++){
  if($arr[$i][1] == '+')
    $x++;
  else
    $x--;
}
echo $x ."\n";
?>

<?php
$dir = fopen("php://stdin", 'r');
$input = stream_get_contents($dir);
// $input="1
// ++X";

$arr = explode(PHP_EOL, $input);

$x = 0;
for($i=1;$i<count($arr);$i++){
  if($arr[$i][1] == '+')
    $x++;
  else
    $x--;
}
echo $x ."\n";

<?php
$dir = fopen("php://stdin", 'r');
$input = stream_get_contents($dir);

$arr = explode(PHP_EOL, $input);

$x = 0;
for($i=1;$i<count($arr);$i++){
  if($arr[$i][1] == '+')
    $x++;
  else
    $x--;
}
echo $x ."\n";

<?php
// http://codeforces.com/problemset/problem/282/A

// Input
// The first line contains a single integer n (1 ≤ n ≤ 150) — the number of statements in the programme.
$n = fgets(STDIN);

// The language is that peculiar as it has exactly one variable, called x.
$x = 0;

// Next n lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable x (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order.
for ($i=0; $i < $n; $i++)
{
	$operation = rtrim(fgets(STDIN));

	if (false == strpos($operation, '++'))
		$x++;
	else
		$x--;
}

echo $x;

?>

<?php
// http://codeforces.com/problemset/problem/282/A

// Input
// The first line contains a single integer n (1 ≤ n ≤ 150) — the number of statements in the programme.
$n = fgets(STDIN);

// The language is that peculiar as it has exactly one variable, called x.
$x = 0;

// Next n lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable x (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order.
for ($i=0; $i < $n; $i++)
{
	$operation = rtrim(fgets(STDIN));

	if (false != strpos($operation, '++'))
		$x++;
	else
		$x--;
}

echo $x;

?>

<?php
    $x = trim(fgets(STDIN));
    $ret = 0;

    for ($i=0; $i<$x; $i++)
    {
        $s = trim(fgets(STDIN));
        if (strpos($s, "++")>=0)
            $ret++;
        else
            $ret--;

    }
    echo $ret;
?>

<?php
fscanf(STDIN, "%d", $x);

while (fscanf(STDIN, "%s", $s)) {
    eval(str_replace("X", "\$x", $s) . ";");
}
echo $x;
?>

<?php
$n = (fgets(STDIN));
$result=0;
for ($i=0;$i<$n;$i++)
{
    $line = fgets(STDIN);
    if (strripos($line,"++"))
    {
        $result++;
    }
    elseif (strripos($line,"--"))
    {
        $result--;
    }
}
echo $result;
?>

<?php
$n = (fgets(STDIN));
$summSolution=0;
for ($i=0;$i<$n;$i++)
{
    $peopleVote = explode(" ",fgets(STDIN));
    if (($peopleVote[0]+$peopleVote[1]+$peopleVote[2])>=2)
    {
        $summSolution++;
    }
}
echo $summSolution;
?>

<?php

function getStdIn(bool $asInt = false): array
{
    $stdIn = explode(' ', trim(fgets(STDIN)));

    if ($asInt) {
        foreach ($stdIn as $key => $value) {
            $stdIn[$key] = (int)$value;
        }
    }

    return $stdIn;
}

function stdOut($output)
{
    fwrite(STDOUT, $output);
}

function solve(): void
{
    [$n] = getStdIn(true);
    $x = 0;

    for ($i = 0; $i < $n; $i++) {
        [$operation] = getStdIn();
        var_dump($operation);
        if (strpos($operation, '++') !== false) {
            $x++;
        } elseif (strpos($operation, '--') !== false) {
            $x--;
        }
    }

    stdOut($x);
}

solve();

<?php
$input = trim(fgets(STDIN));
$noOfInputs = (int)$input;
$x = 0;
for($counter = 0 ; $counter < $noOfInputs; $counter++){
    $input = trim(fgets(STDIN));
    if(strpos($input, "--")){
        $x--;
    }else{
        $x++;
    }
}
echo $x;
?>

<?php

//First Get The Input.
$input = file_get_contents("php://stdin");

//Get The Number Of Statements.
$n = explode("\n",$input)[0];

//Then Loop Throw The Statements To Apply Them On ( x ).
$x = 0;
for($i = 1;$i <= $n;$i++) {

    $current_statement = explode("\n",$input)[$i];

    if(in_array($current_statement,array("++x","x++"))) {

        $x++;

    }else {

        $x--;

    }

}

//return ( x ).
echo $x;

<?php

//First Get The Input.
$input = file_get_contents("php://stdin");

//Get The Number Of Statements.
$n = (int)explode("\n",$input)[0];

//Then Loop Throw The Statements To Apply Them On ( x ).
$int = 0;

for($i = 0;$i < $n;$i++) {

    $current_statement = (string)explode("\n",$input)[$i + 1];

    $current_statement = trim($current_statement,"\r\n");

    if(in_array($current_statement,array("x++","++x"))) {

        $int++;

    }elseif(in_array($current_statement,array("x--","--x"))) {

        $int--;

    }

}

//return ( x ).
echo $int;

?>

<?php
fscanf(STDIN, '%d\n', $n);
$lines = array();
$x = 0;

for($i = 0; $i < $n; $i++) {	// считываем n строк
	$lines[$i] = fgets(STDIN);
	$lines = explode(' ', $lines[$i]); // теперь $lines - двумерный массив c выражениями
	}

for($i = 0; $i < $n; $i++) {
	// if($lines[$i] == "++X" || "X++") {
	// 	$x = 1;
	// } elseif($lines[$i] == "X--" || "--X") {
	// 	$x = 0;
	// }
	if($lines[$i][2] == "X--" || "--X"){
		$x = 0;
	} else {
		$x = 1;
	}
}

printf($x);

<?php
$a = array();
fscanf(STDIN, "%d", $n);
for ($i = 0; $i < $n; $i++) {
	$a[] = trim(fgets(STDIN));
}
$result = 0;
foreach ($a as $task) {
	if ($task == '++X')
		$result++;
	else
		$result--;
}

fprintf(STDOUT, $result);

<?php
$a = array();
fscanf(STDIN, "%d", $n);
for ($i = 0; $i < $n; $i++) {
	$a[] = explode(" ", trim(fgets(STDIN)));
}
$result = 0;
foreach ($a as $task) {
	if ($task == '++X')
		$result++;
	else
		$result--;
}

fprintf(STDOUT, $result);


<?php
$no = 'NO';
$yes = 'YES';
$mod = 1000000007;
$alph = 'abcdefghijklmnopqrstuvwxyz';
$inter = "\n";

  $t = getT();
//   $point = ord('a') + ord('b') ;

  for($q=0; $q <$t; $q++) {
      $ans = 0;
      list($l1, $r1, $l2, $r2) = getA();

      if($r1 >= $l2 && $l1 <= $r2) {
          $ans = getMaxValue($l2, $l1);
      } else {
          $ans = $l1 + $l2;
      }

          pr($ans);

  }
// bcadd — Add two arbitrary precision numbers
// bccomp — Compare two arbitrary precision numbers
// bcdiv — Divide two arbitrary precision numbers
// bcmod — Get modulus of an arbitrary precision number
// bcmul — Multiply two arbitrary precision numbers
// bcpow — Raise an arbitrary precision number to another
// bcpowmod — Raise an arbitrary precision number to another, reduced by a specified modulus
// bcscale — Set or get default scale parameter for all bc math functions
// bcsqrt — Get the square root of an arbitrary precision number
// bcsub — Subtract one arbitrary precision number from another
function getDar($n) {
    $dar = [2];
    for($i=0; $i<$n; $i++) {
        $dar[] = $dar[$i] * 2;
    }
    return $dar;
}
function getDar2($n, $k) {
    if($k == 0) {
        return 1;
    }
    return bcmul($n, getDar2($n, $k-1));
}

  function getT() {
      return trim(fgets(STDIN));
  }
  function getA() {
      return explode(' ', trim(fgets(STDIN)));
  }

  function is_prime($n) {
    $d = 2;
        while ($n % $d != 0) {
        	 $d += 1;
        }

        return $d == $n;
    }
function getMinValue($x, $y) {
        return $x > $y ? $y : $x;
    }
    function getMaxValue($x, $y) {
        return $x > $y ? $x : $y;
    }

    function getMaxValueBc($x, $y) {
        return bccomp($x, $y) == 1 ? $x : $y;
    }
    function getRotate($a, $s, $e, $ind) {
 		$ar = [];
        for ($i= $s; $i<=$e; $i++) {
        	$ar[$i] = $a[$i];
        	$j = $i + $ind > $e ? $i + $ind - $e - 1 : $i + $ind;
        	// echo $i, ' ', $j, ' ', $j < $i ? $ar[$j] : $a[$j] , "\n";
        	$a[$i] = $j < $i ? $ar[$j] : $a[$j];
        }
        return $a;
    }
    function pr($s) {
        if(is_array($s)) {
            echo implode( ' ', $s), PHP_EOL;
        } else {
            echo $s, PHP_EOL;
        }
    }
    function fab2($n, $a) {
        if($n <= 1) {
            return $a[$n];
        }
       for($i=2; $i<=$n; $i++) {
           $a[$i] = $a[$i-1] + $a[$i-2];
       }

        return $a[$n];
    }

    function mergeSort($aArray) {
    if(count($aArray) <= 1) {
        return $aArray;
    }
    $aLeft = [];
    $aRight = [];
    $n =floor(count($aArray) / 2);
    for($i = 0; $i <$n; $i++) {
       $aLeft[] = $aArray[$i];
    }
    for($i = $n; $i <count($aArray); $i++) {
       $aRight[] = $aArray[$i];
    }

    return merge(mergeSort($aLeft), mergeSort($aRight));
}

function merge($aLeft, $aRight) {
    $aResult = [];
    $iL = 0;
    $iR = 0;

    while($iL < count($aLeft) && $iR < count($aRight)) {
        if($aLeft[$iL] >= $aRight[$iR]) {
            $aResult[] = $aLeft[$iL];
            $iL++;
        } else {
            $aResult[] = $aRight[$iR];
            $iR++;
        }
    }

    while($iL < count($aLeft)) {
        $aResult[] = $aLeft[$iL];
        $iL++;
    }
    while($iR < count($aRight)) {
        $aResult[] = $aRight[$iR];
        $iR++;
    }

    return $aResult;

}


<?php
//[$n,$m] = array_map('intval', explode(' ', trim(fgets(STDIN))));
[$n] = array_map('intval', explode(' ', trim(fgets(STDIN))));
//$a = array_map('intval', explode(' ', trim(fgets(STDIN))));
//[$s,$t] = explode(' ', trim(fgets(STDIN)));
//[$s] = explode(' ', trim(fgets(STDIN)));
//$s = explode(' ', trim(fgets(STDIN)));
//function decr($v){return --$v;}
//$alpha='abcdefghijklmnopqrstuvwxyz';
//$mod=1000000009;
//$mod=1000000007;
//$mod=998244353;
//$a=[];
//$b=[];
for($i=0;$i<$n;$i++){
    [$m] = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $a = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $suma = array_sum($a);
    $f = 0;
    $cnt = 0;
    $min = $m;
    for($j=0;$j<$m-1;$j++){
        $f += $a[$j];
        $cnt++;
        if($suma % $f == 0){
            $max = $cnt;
            //echo ">>>>>>".$max." ".$f.PHP_EOL;
            $s = 0;
            $cnt1 = 0;
            $ok = true;
            for($k=$j+1;$k<$m;$k++){
                $s += $a[$k];
                //echo ">>>>".$s.PHP_EOL;
                $cnt1++;
                if($k==$m-1){
                    if($f == $s){
                        $max = max($max,$cnt1);
                    }else{
                        $ok=false;
                        break;
                    }
                }else{
                    if($f < $s){
                        $ok=false;
                        break;
                    }else if($f == $s){
                        $max = max($max, $cnt1);
                        //echo ">>".$max." ".$cnt.PHP_EOL;
                        $cnt1 = 0;
                        $s = 0;
                    }
                }
            }
            if($ok){
                $min = min($min, $max);
            }
        }
    }
    $ans[] = $min;
}
echo implode(PHP_EOL,$ans);

<?php
$mod = 1000000007;
$intMaxValue = 2147483646; //2147483647

$loop = true;
$t = $loop ? IO::get() : 1;
while($t--) {
    solve();
}
function solve()
{
   $n = IO::get();
   $a = IO::getArray();
   $z = false;
   $ans = $n;
   $t = [];
   $tt = 0;
   $tols = 0;
   $e = [];
   $cnt = array_sum($a);
   for($j=0; $j<$n; $j++) {
        $tols = $j+1;
        $tt += $a[$j];
        $t[$j][] = $tt;
        $temp = 0;
        $rr = 0;
     for($i=$j+1; $i<$n; $i++) {
          $rr++;
         $temp += $a[$i];
         if($temp == $tt) {
          //    IO::pr('rr => ' . $rr . ' ' . $tols);
              $tols = $tols > $rr ? $tols : $rr;
            $t[$j][] = $tt;
            $temp = 0;
            $rr = 0;
         }
     }
     if(array_sum($t[$j]) == $cnt) {
         $e[$j] = $tols;
     } else {
          $e[$j] = $n;
     }

   }
   $min = $n;
   foreach($t as $key=>$value) {

        if(count($value) > 1 ) {
            $min = $min > count($value) ? count($value) : $min;
            $ans = $ans > $e[$key] ? $e[$key] : $ans;
        }
   }

   IO::pr($ans);
}

class IO {
    public static function get()
    {
        return trim(fgets(STDIN));
    }

    public static function getArray()
    {
        return explode(' ', trim(fgets(STDIN)));
    }
    public static function pr($s)
    {
        echo $s, PHP_EOL;
    }
    public static function prArray($s)
    {
        echo implode( ' ', $s), PHP_EOL;
    }
    public static function getMinValue($x, $y) {
        return $x > $y ? $y : $x;
    }
    public static function getMaxValue($x, $y) {
        return $x > $y ? $x : $y;
    }
}

<?php
$mod = 1000000007;
$intMaxValue = 2147483646; //2147483647

$loop = true;
$t = $loop ? IO::get() : 1;
while($t--) {
    solve();
}
function solve()
{
   $n = IO::get();
   $a = IO::getArray();
   $z = false;
   $ans = $n;
   $t = [];
   $tt = 0;
   $tols = 0;
   $e = [];
   for($j=0; $j<$n; $j++) {
        $tols = $j+1;
        $tt += $a[$j];
        $t[$j][] = $tt;
        $temp = 0;
        $rr = 0;
     for($i=$j+1; $i<$n; $i++) {
          $rr++;
         $temp += $a[$i];
         if($temp == $tt) {
          //    IO::pr('rr => ' . $rr . ' ' . $tols);
              $tols = $tols > $rr ? $tols : $rr;
            $t[$j][] = $tt;
            $temp = 0;
            $rr = 0;
         }
     }
     $e[$j] = $tols;
   }
   $min = $n;
   foreach($t as $key=>$value) {

        if(count($value) > 1 ) {
            $min = $min > count($value) ? count($value) : $min;
            $ans = $ans > $e[$key] ? $e[$key] : $ans;
        }
   }

   IO::pr($ans);
}

class IO {
    public static function get()
    {
        return trim(fgets(STDIN));
    }

    public static function getArray()
    {
        return explode(' ', trim(fgets(STDIN)));
    }
    public static function pr($s)
    {
        echo $s, PHP_EOL;
    }
    public static function prArray($s)
    {
        echo implode( ' ', $s), PHP_EOL;
    }
    public static function getMinValue($x, $y) {
        return $x > $y ? $y : $x;
    }
    public static function getMaxValue($x, $y) {
        return $x > $y ? $x : $y;
    }
}

<?php
$mod = 1000000007;
$intMaxValue = 2147483646; //2147483647

$loop = true;
$t = $loop ? IO::get() : 1;
while($t--) {
    solve();
}
function solve()
{
   $n = IO::get();
   $a = IO::getArray();
   $z = false;
   $ans = $n;
   $t = [];
   $tt = 0;
   for($j=0; $j<$n; $j++) {
        $tt += $a[$j];
        $t[$j][] = $tt;
        $temp = 0;
     for($i=$j+1; $i<$n; $i++) {
         $temp += $a[$i];
         if($temp == $tt) {
            $t[$j][] = $tt;
            $temp = 0;
         }
     }
   }
   $min = $n;
   foreach($t as $key=>$value) {
     //    IO::pr($key . ' ' . count($value));
     //    IO::prArray($value);
        if(count($value) > 1 ) {
            $ans = $ans > count($value) ? count($value) : $ans;
        }
   }

   IO::pr($ans);
}

class IO {
    public static function get()
    {
        return trim(fgets(STDIN));
    }

    public static function getArray()
    {
        return explode(' ', trim(fgets(STDIN)));
    }
    public static function pr($s)
    {
        echo $s, PHP_EOL;
    }
    public static function prArray($s)
    {
        echo implode( ' ', $s), PHP_EOL;
    }
    public static function getMinValue($x, $y) {
        return $x > $y ? $y : $x;
    }
    public static function getMaxValue($x, $y) {
        return $x > $y ? $x : $y;
    }
}

<?php
//[$n,$m] = array_map('intval', explode(' ', trim(fgets(STDIN))));
[$n] = array_map('intval', explode(' ', trim(fgets(STDIN))));
//$a = array_map('intval', explode(' ', trim(fgets(STDIN))));
//[$s,$t] = explode(' ', trim(fgets(STDIN)));
//[$s] = explode(' ', trim(fgets(STDIN)));
//$s = explode(' ', trim(fgets(STDIN)));
//function decr($v){return --$v;}
//$alpha='abcdefghijklmnopqrstuvwxyz';
//$mod=1000000009;
//$mod=1000000007;
//$mod=998244353;
//$a=[];
//$b=[];
for($i=0;$i<$n;$i++){
    [$m] = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $a = array_map('intval', explode(' ', trim(fgets(STDIN))));
    $suma = array_sum($a);
    $f = 0;
    $cnt = 0;
    $min = $m;
    for($j=0;$j<$m;$j++){
        $f += $a[$j];
        $cnt++;
        if($suma % $f == 0){
            $max = $cnt;
            $s = 0;
            $cnt = 0;
            $ok = true;
            for($k=$j+1;$k<$m;$k++){
                $s += $a[$k];
                //echo ">>>>".$s.PHP_EOL;
                $cnt++;
                if($k==$m-1){
                    if($f == $s){
                        $max = max($max,$cnt);
                    }else{
                        $ok=false;
                        break;
                    }
                }else{
                    if($f < $s){
                        $ok=false;
                        break;
                    }else if($f == $s){
                        $max = max($max, $cnt);
                        //echo ">>".$max." ".$cnt.PHP_EOL;
                        $cnt = 0;
                        $s = 0;
                    }
                }
            }
            if($ok){
                $min = min($min, $max);
            }
        }
    }
    $ans[] = $min;
}
echo implode(PHP_EOL,$ans);