<?php
fscanf(STDIN,"%d",$n);
while ($n--)
{
	$typed=trim(fgets(STDIN));
    $printed=trim(fgets(STDIN));

	          $grp1=identicalSubstring($typed);
              $grp2=identicalSubstring($printed);
                     if(count($grp1)!=count($grp2))
                        {
                           $same=false;
                        }
                     else
                     {
                            $same=true;
                             for ($i=0; $i <count($grp1) ; $i++)
                            {
                                    if((strlen($grp1[$i])>strlen($grp2[$i]))||($grp1[$i][0]!=$grp2[$i][0]))
                                    {
                                        $same=false;
                                        break;
                                    }

                            }
                     }

  echo $same?"YES\n":"NO\n";
}
function identicalSubstring($str)
{
                $grp1=array();
                if(count(array_unique(str_split($str)))==1)
                  {
                    $grp1[0]=$str;
                    return $grp1;
                  }
                else
                 {
                        $i=0;
                        $k=0;
                        $str2="";
                        while($i<strlen($str)-1)
                        {

                                    if($str[$i]!=$str[$i+1])
                                    {
                                        $last=$i+1;
                                        $grp1[$k]=$str2.$str[$i];
                                        $k++;
                                        $str2="";
                                    }
                                    else
                                        $str2.=$str[$i];
                                 $i++;

                        }
                        $grp1[count($grp1)]=substr($str,$last);
                        return $grp1;

                    }

}

<?php

fscanf(STDIN,"%d",$n);
//$pair=$n*2;

while ($n--)
{
	$typed=trim(fgets(STDIN));

	$printed=trim(fgets(STDIN));

	          $grp1=identicalSubstring($typed);
             // print_r($grp1);
              $grp2=identicalSubstring($printed);
              //print_r($grp2);

                    if(count($grp1)!=count($grp2))
                    {
                        $same=false;
                        //echo "some";
                    }
                     else
                     {
                            $same=true;
                           //echo "hi\n";

                            for ($i=0; $i <count($grp1) ; $i++)
                            {
                                    if((strlen($grp1[$i])>strlen($grp2[$i]))||($grp1[$i][0]!=$grp2[$i][0]))
                                    {
                                        $same=false;
                                        break;
                                    }

                            }
                     }

  echo $same?"YES\n":"NO\n";
}
function identicalSubstring($str)
{

               $grp1=array();

                if(count(array_unique(str_split($str)))==1)
                {
                    $grp1[0]=$str;
                    return $grp1;
                }
                else
                 {
                    /*
                        $ara=array();
                        for ($i=0,$j=0; $i <strlen($str)-1 ; $i++)
                         {
                              if($str[$i]!=$str[$i+1])
                              {
                                 $ara[$j++]=$i;
                              }
                                //echo "$i\n";
                         }
                         //$start=0;
                         for ($i=0; $i <count($ara); $i++)
                         {
                                if($i==0)
                                  $grp1[$i]=substr($str,0,$ara[$i]+1);
                                else
                                {
                                  $diff=$ara[$i]-$ara[$i-1];
                                  $grp1[$i]=substr($str,$ara[$i-1]+1,$diff);
                                }
                              $grp1[$i+1]=substr($str,$ara[$i]+1);

                        }
                        return $grp1;
                        */
                        $i=0;
                        $k=0;
                        //$sbstr=array();
                        $str2="";
                        while($i<strlen($str)-1)
                        {

                            if($str[$i]!=$str[$i+1])
                            {
                                $last=$i+1;
                                //echo "$last\n";

                                $grp1[$k]=$str2.$str[$i];
                                $k++;
                                $str2="";
                            }
                            else
                                $str2.=$str[$i];
                         $i++;

                        }
                        $grp1[count($grp1)]=substr($str,$last);
                        return $grp1;

                    }

}

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     $b = str_split(trim(fgets(STDIN)));
     $c = str_split(trim(fgets(STDIN)));
     if(count($b) < count($c))
     {
          $b = array_unique($b);
          $c = array_unique($c);
          if(implode($b) == implode($c))
          {
               print "YES\n";
          }
          else
          {
               print "NO\n";
          }
     }
     elseif(count($b) == count($c))
     {
          if($b == $c)
          {
               print "YES\n";
          }
          else
          {
               print "NO\n";
          }
     }
     elseif(count($b) > count($c))
     {
          print "NO";
     }
}
?>

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     $b = str_split(trim(fgets(STDIN)));
     $c = str_split(trim(fgets(STDIN)));
     if(count($b) > count($c))
     {
          print "NO\n";
     }
     else
     {
          $b = array_unique($b);
          $c = array_unique($c);
          if(implode($b) == implode($c))
          {
               print "YES\n";
          }
          else
          {
               print "NO\n";
          }
     }
}
?>

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     $b = trim(fgets(STDIN));
     $c = trim(fgets(STDIN));
     if(strlen($b) < strlen($c))
     {
          $d = $b[0];
          for($y = 0; $y < strlen($b) - 1; $y++)
          {
               if($b[strlen($b) - 1] != $b[$y + 1])
               {
                    $d .= $b[$y + 1];
               }
          }
          $e = $c[0];
          for($y = 0; $y < strlen($c) - 1; $y++)
          {
               if($c[strlen($c) - 1] != $c[$y + 1])
               {
                    $e .= $c[$y + 1];
               }
          }
          if($d == $e)
          {
               print "YES\n";
          }
          else
          {
               print "NO\n";
          }
     }
     elseif(strlen($b) == strlen($c))
     {
          if($b == $c)
          {
               print "YES\n";
          }
          else
          {
               print "NO\n";
          }
     }
     elseif(strlen($b) > strlen($c))
     {
          print "NO\n";
     }
}
?>

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     $b = trim(fgets(STDIN));
     $c = trim(fgets(STDIN));
     if(strlen($b) < strlen($c))
     {
          $d = $b[0];
          for($y = 0; $y < strlen($b); $y++)
          {
               if($d[strlen($d) - 1] != $b[$y + 1])
               {
                    $d .= $b[$y + 1];
               }
          }
          $e = $c[0];
          for($y = 0; $y < strlen($c); $y++)
          {
               if($e[strlen($e) - 1] != $c[$y + 1])
               {
                    $e .= $c[$y + 1];
               }
          }
          if($d == $e)
          {
               print "YES\n";
          }
          else
          {
               print "NO\n";
          }
     }
     elseif(strlen($b) == strlen($c))
     {
          if($b == $c)
          {
               print "YES\n";
          }
          else
          {
               print "NO\n";
          }
     }
     elseif(strlen($b) > strlen($c))
     {
          print "NO\n";
     }
}
?>

<?php
$a = trim(fgets(STDIN));
for($x = 1; $x <= $a; $x++)
{
     $b = str_split(trim(fgets(STDIN)));
     $c = str_split(trim(fgets(STDIN)));
     if(count($b) < count($c))
     {
          $b = array_unique($b);
          $c = array_unique($c);
          if(implode($b) == implode($c))
          {
               print "YES\n";
          }
          else
          {
               print "NO\n";
          }
     }
     elseif(count($b) == count($c))
     {
          if($b == $c)
          {
               print "YES\n";
          }
          else
          {
               print "NO\n";
          }
     }
     elseif(count($b) > count($c))
     {
          print "NO\n";
     }
}
?>

<?php
fscanf(STDIN,"%d",$n);
//$pair=$n*2;
while ($n--)
{
	$typed=trim(fgets(STDIN));
	$typedSplit=str_split($typed);

	$printed=trim(fgets(STDIN));
	$printedSplit=str_split($printed,2);
	//print_r($printedSplit);
	$tLength=strlen($typed);
	$pLength=strlen($printed);

	$same=false;

    $tlstchar=$tLength-1;
    $plstchar=$pLength-1;
	if ($pLength>=$tLength&&$typed[0]==$printed[0]&&$typed[$tlstchar]==$printed[$plstchar])
	 {
	 	for ($i=0; $i <$tLength-1 ; $i++)
	 	{
	 	  $str1[$i]=substr($typed,$i,2);
	 	}
	 	for ($i=0; $i <$pLength-1 ; $i++)
	 	{
	 	  $str2[$i]=substr($printed,$i,2);
	 	}
	 	$count=0;
	 	for ($i=0; $i <count($str1) ; $i++)
	 	 {

                  $k=0;
	 		for ($j=0; $j <count($str2) ; $j++)
	 		{
	 			if($str1[$i]==$str2[$j])
	 			{
	 				$count++;
	 				$k=1;
	 				break;
	 			}
	 		}
	 		if($k==0)
	 			break;

	 	}

	 	//print_r($store1);

       if($count==$tLength-1)
	 	$same=true;

     }
    echo $same?"YES\n":"NO\n";
}

<?php

fscanf(STDIN,"%d",$n);
//$pair=$n*2;

while ($n--)
{
	$typed=trim(fgets(STDIN));
    $tLength=strlen($typed);
	//$typedSplit=str_split($typed);

	$printed=trim(fgets(STDIN));
    $pLength=strlen($printed);

	$same=false;

    $tlstchar=$tLength-1;
    $plstchar=$pLength-1;
     $count=0;
	if ($pLength>=$tLength&&$typed[0]==$printed[0]&&$typed[$tlstchar]==$printed[$plstchar])
	     {

                if(count(array_unique(str_split($typed)))==1)
                    $grp1[0]=$typed;
                else
                 {
                        $ara=array();
                        for ($i=0,$j=0; $i <strlen($typed)-1 ; $i++)
                         {
                              if($typed[$i]!=$typed[$i+1])
                              {
                                 $ara[$j++]=$i;
                              }
                                //echo "$i\n";
                         }
                         //$start=0;
                         $grp1=array();
                         for ($i=0; $i <count($ara); $i++)
                         {
                                if($i==0)
                                  $grp1[$i]=substr($typed,0,$ara[$i]+1);
                                else
                                {
                                  $diff=$ara[$i]-$ara[$i-1];
                                  $grp1[$i]=substr($typed,$ara[$i-1]+1,$diff);
                                }
                              $grp1[$i+1]=substr($typed,$ara[$i]+1);

                        }
                    }
                   // print_r($grp1)."\n";
                if(count(array_unique(str_split($printed)))==1)
                    $grp2[0]=$printed;
                else
                 {
                        $ara=array();
                        for ($i=0,$j=0; $i <strlen($printed)-1 ; $i++)
                         {
                              if($printed[$i]!=$printed[$i+1])
                              {
                                 $ara[$j++]=$i;
                              }
                                //echo "$i\n";
                         }
                         //$start=0;
                         $grp2=array();
                         for ($i=0; $i <count($ara); $i++)
                         {
                                if($i==0)
                                  $grp2[$i]=substr($printed,0,$ara[$i]+1);
                                else
                                {
                                  $diff=$ara[$i]-$ara[$i-1];
                                  $grp2[$i]=substr($printed,$ara[$i-1]+1,$diff);
                                }
                              $grp2[$i+1]=substr($printed,$ara[$i]+1);

                        }
                    }
                    if(count($grp1)!=count($grp2))
                        $same=false;
                     else
                     {
                       $same=true;

                        for ($i=0; $i <count($grp1) ; $i++)
                        {
                            if(strlen($grp1[$i])>strlen($grp2[$i]))
                            {
                                $same=false;
                                break;
                            }
                        }
                     }

        }

   echo $same?"YES\n":"NO\n";
}

<?php
fscanf(STDIN,"%d",$n);
//$pair=$n*2;
while ($n--)
{
	$typed=trim(fgets(STDIN));
	$typedSplit=str_split($typed);

	$printed=trim(fgets(STDIN));
	$printedSplit=str_split($printed,2);
	//print_r($printedSplit);
	$tLength=strlen($typed);
	$pLength=strlen($printed);

	$same=false;

    $tlstchar=$tLength-1;
    $plstchar=$pLength-1;
	if ($pLength>=$tLength&&$typed[0]==$printed[0]&&$typed[$tlstchar]==$printed[$plstchar])
	 {
	 	for ($i=0; $i <$tLength-1 ; $i++)
	 	{
	 	  $str1[$i]=substr($typed,$i,2);
	 	}
	 	for ($i=0; $i <$pLength-1 ; $i++)
	 	{
	 	  $str2[$i]=substr($printed,$i,2);
	 	}
	 	$count=0;
	 	for ($i=0; $i <count($str1) ; $i++)
	 	 {
	 		for ($j=0; $j <count($str2) ; $j++)
	 		{
	 			if($str1[$i]==$str2[$j])
	 				$count++;
	 		}
	 		if($count==0)
	 			break;
	 	}

	 	//print_r($store1);

       if($count==$tLength-1)
	 	$same=true;

     }
    echo $same?"YES\n":"NO\n";
}

<?php
fscanf(STDIN,"%d",$n);
//$pair=$n*2;
while ($n--)
{
	$typed=trim(fgets(STDIN));
	//$typedSplit=str_split($typed);

	$printed=trim(fgets(STDIN));
	//$printedSplit=str_split($printed,2);
	//print_r($printedSplit);
	$tLength=strlen($typed);
	$pLength=strlen($printed);

	$same=false;

    $tlstchar=$tLength-1;
    $plstchar=$pLength-1;
     $count=0;
	if ($pLength>=$tLength&&$typed[0]==$printed[0]&&$typed[$tlstchar]==$printed[$plstchar])
	 {

	      for ($i=0; $i <$pLength ; $i++)
	      {
	      	if($printed[$i]==$typed[$count])
	      	 {
	      		$count++;

	      		if($count==$tLength)
	      		{
	      			$same=true;
	      			break;
	      		}
	      	 }
	      	 //echo "$count\n";

	      }

     }
   echo $same?"YES\n":"NO\n";
}

<?php
fscanf(STDIN,"%d",$n);
//$pair=$n*2;
while ($n--)
{
	$typed=trim(fgets(STDIN));
	$typedSplit=str_split($typed);

	$printed=trim(fgets(STDIN));
	$printedSplit=str_split($printed,2);
	//print_r($printedSplit);
	$tLength=strlen($typed);
	$pLength=strlen($printed);

	$same=false;

    $tlstchar=$tLength-1;
    $plstchar=$pLength-1;
	if ($pLength>=$tLength&&$typed[0]==$printed[0]&&$typed[$tlstchar]==$printed[$plstchar])
	 {
	 	for ($i=0; $i <$tLength-1 ; $i++)
	 	{
	 	  $str1[$i]=substr($typed,$i,2);
	 	}
	 	for ($i=0; $i <$pLength-1 ; $i++)
	 	{
	 	  $str2[$i]=substr($printed,$i,2);
	 	}
	 	for ($i=0; $i <count($str1) ; $i++)
	 	 {
	 	$count=0;

	 		for ($j=0; $j <count($str2) ; $j++)
	 		{
	 			if($str1[$i]==$str2[$j])
	 				$count++;
	 		}
	 		if($count==0)
	 			break;
	 	}

	 	//print_r($store1);

       if($count==$tLength-1)
	 	$same=true;

     }
    echo $same?"YES\n":"NO\n";
}

<?php

fscanf(STDIN,"%d",$n);
//$pair=$n*2;

while ($n--)
{
	$typed=trim(fgets(STDIN));
    $tLength=strlen($typed);
	//$typedSplit=str_split($typed);

	$printed=trim(fgets(STDIN));
    $pLength=strlen($printed);

	$same=false;

    $tlstchar=$tLength-1;
    $plstchar=$pLength-1;
     $count=0;
	if ($pLength>=$tLength&&$typed[0]==$printed[0]&&$typed[$tlstchar]==$printed[$plstchar])
	     {

                $same=true;

                if(count(array_unique(str_split($typed)))==1)
                    $grp1[0]=$typed;
                else
                 {
                        $ara=array();
                        for ($i=0,$j=0; $i <strlen($typed)-1 ; $i++)
                         {
                              if($typed[$i]!=$typed[$i+1])
                              {
                                 $ara[$j++]=$i;
                              }
                                //echo "$i\n";
                         }
                         //$start=0;
                         $grp1=array();
                         for ($i=0; $i <count($ara); $i++)
                         {
                                if($i==0)
                                  $grp1[$i]=substr($typed,0,$ara[$i]+1);
                                else
                                {
                                  $diff=$ara[$i]-$ara[$i-1];
                                  $grp1[$i]=substr($typed,$ara[$i-1]+1,$diff);
                                }
                              $grp1[$i+1]=substr($typed,$ara[$i]+1);

                        }
                    }
                   // print_r($grp1)."\n";
                if(count(array_unique(str_split($printed)))==1)
                    $grp2[0]=$printed;
                else
                 {
                        $ara=array();
                        for ($i=0,$j=0; $i <strlen($printed)-1 ; $i++)
                         {
                              if($printed[$i]!=$printed[$i+1])
                              {
                                 $ara[$j++]=$i;
                              }
                                //echo "$i\n";
                         }
                         //$start=0;
                         $grp2=array();
                         for ($i=0; $i <count($ara); $i++)
                         {
                                if($i==0)
                                  $grp2[$i]=substr($printed,0,$ara[$i]+1);
                                else
                                {
                                  $diff=$ara[$i]-$ara[$i-1];
                                  $grp2[$i]=substr($printed,$ara[$i-1]+1,$diff);
                                }
                              $grp2[$i+1]=substr($printed,$ara[$i]+1);

                        }
                    }
                    if(count($grp1)!=count($grp2))
                        $same=false;
                     else
                     {
                        for ($i=0; $i <count($grp1) ; $i++)
                        {
                            if(strlen($grp1[$i])>strlen($grp2[$i]))
                            {
                                $same=false;
                                break;
                            }
                        }
                     }

        }

   echo $same?"YES\n":"NO\n";
}

<?php

fscanf(STDIN,"%d",$n);
//$pair=$n*2;

while ($n--)
{
	$typed=trim(fgets(STDIN));
    $tLength=strlen($typed);
	//$typedSplit=str_split($typed);

	$printed=trim(fgets(STDIN));
    $pLength=strlen($printed);

	$same=false;
       // echo "before\n";
    $tlstchar=$tLength-1;
    $plstchar=$pLength-1;
     $count=0;
	if ($pLength>=$tLength&&$typed[0]==$printed[0]&&$typed[$tlstchar]==$printed[$plstchar])
	     {

               $grp1=array();
               $grp2=array();

                if(count(array_unique(str_split($typed)))==1)
                    $grp1[0]=$typed;
                else
                 {
                        $ara=array();
                        for ($i=0,$j=0; $i <strlen($typed)-1 ; $i++)
                         {
                              if($typed[$i]!=$typed[$i+1])
                              {
                                 $ara[$j++]=$i;
                              }
                                //echo "$i\n";
                         }
                         //$start=0;
                         for ($i=0; $i <count($ara); $i++)
                         {
                                if($i==0)
                                  $grp1[$i]=substr($typed,0,$ara[$i]+1);
                                else
                                {
                                  $diff=$ara[$i]-$ara[$i-1];
                                  $grp1[$i]=substr($typed,$ara[$i-1]+1,$diff);
                                }
                              $grp1[$i+1]=substr($typed,$ara[$i]+1);

                        }
                    }
                   // print_r($grp1)."\n";
                if(count(array_unique(str_split($printed)))==1)
                    $grp2[0]=$printed;
                else
                 {
                        $ara=array();
                        for ($i=0,$j=0; $i <strlen($printed)-1 ; $i++)
                         {
                              if($printed[$i]!=$printed[$i+1])
                              {
                                 $ara[$j++]=$i;
                              }
                                //echo "$i\n";
                         }
                         //$start=0;
                         for ($i=0; $i <count($ara); $i++)
                         {
                                if($i==0)
                                  $grp2[$i]=substr($printed,0,$ara[$i]+1);
                                else
                                {
                                  $diff=$ara[$i]-$ara[$i-1];
                                  $grp2[$i]=substr($printed,$ara[$i-1]+1,$diff);
                                }
                              $grp2[$i+1]=substr($printed,$ara[$i]+1);

                        }
                    }
                   // print_r($grp2)."\n";
                    //echo count($grp1).count($grp2)."\n";
                    if(count($grp1)!=count($grp2))
                    {
                        $same=false;
                        //echo "some";
                    }
                     else
                     {
                        $same=true;
                       //echo "hi\n";

                        for ($i=0; $i <count($grp1) ; $i++)
                        {
                            if(strlen($grp1[$i])>strlen($grp2[$i]))
                            {
                                $same=false;
                                break;
                            }
                        }
                     }

        }

   echo $same?"YES\n":"NO\n";
}

<?php

fscanf(STDIN,"%d",$n);
//$pair=$n*2;

while ($n--)
{
	$typed=trim(fgets(STDIN));
    $tLength=strlen($typed);
	//$typedSplit=str_split($typed);

	$printed=trim(fgets(STDIN));
    $pLength=strlen($printed);

	$same=false;
       // echo "before\n";
    $tlstchar=$tLength-1;
    $plstchar=$pLength-1;
     $count=0;
	if ($pLength>=$tLength&&$typed[0]==$printed[0]&&$typed[$tlstchar]==$printed[$plstchar])
	     {

               $grp1=array();
               $grp2=array();

                if(count(array_unique(str_split($typed)))==1)
                    $grp1[0]=$typed;
                else
                 {
                        $ara=array();
                        for ($i=0,$j=0; $i <strlen($typed)-1 ; $i++)
                         {
                              if($typed[$i]!=$typed[$i+1])
                              {
                                 $ara[$j++]=$i;
                              }
                                //echo "$i\n";
                         }
                         //$start=0;
                         for ($i=0; $i <count($ara); $i++)
                         {
                                if($i==0)
                                  $grp1[$i]=substr($typed,0,$ara[$i]+1);
                                else
                                {
                                  $diff=$ara[$i]-$ara[$i-1];
                                  $grp1[$i]=substr($typed,$ara[$i-1]+1,$diff);
                                }
                              $grp1[$i+1]=substr($typed,$ara[$i]+1);

                        }
                    }
                   // print_r($grp1)."\n";
                if(count(array_unique(str_split($printed)))==1)
                    $grp2[0]=$printed;
                else
                 {
                        $ara=array();
                        for ($i=0,$j=0; $i <strlen($printed)-1 ; $i++)
                         {
                              if($printed[$i]!=$printed[$i+1])
                              {
                                 $ara[$j++]=$i;
                              }
                                //echo "$i\n";
                         }
                         //$start=0;
                         for ($i=0; $i <count($ara); $i++)
                         {
                                if($i==0)
                                  $grp2[$i]=substr($printed,0,$ara[$i]+1);
                                else
                                {
                                  $diff=$ara[$i]-$ara[$i-1];
                                  $grp2[$i]=substr($printed,$ara[$i-1]+1,$diff);
                                }
                              $grp2[$i+1]=substr($printed,$ara[$i]+1);

                        }
                    }
                   // print_r($grp2)."\n";
                    //echo count($grp1).count($grp2)."\n";
                    if(count($grp1)!=count($grp2))
                    {
                        $same=false;
                        //echo "some";
                    }
                     else
                     {
                        $same=true;
                       //echo "hi\n";

                        for ($i=0; $i <count($grp1) ; $i++)
                        {
                            if(strlen($grp1[$i])>strlen($grp2[$i]))
                            {
                                $same=false;
                                break;
                            }
                            //$count=0;
                            for ($j=0,$k=0; $j <strlen($grp2[$i]) ; $j++)
                            {
                                if($grp2[$i][$j]==$grp1[$i][$k])
                                {
                                       $k++;
                                       if($k==strlen($grp1[$i]))
                                       {
                                        $same=true;
                                        break;
                                       }
                                }
                                else
                                    $same=false;

                            }
                            if($same==true)
                                break;
                        }
                     }

        }

   echo $same?"YES\n":"NO\n";
}

<?php

fscanf(STDIN,"%d",$n);
//$pair=$n*2;

while ($n--)
{
	$typed=trim(fgets(STDIN));
    $tLength=strlen($typed);
	//$typedSplit=str_split($typed);

	$printed=trim(fgets(STDIN));
    $pLength=strlen($printed);

	$same=false;

    $tlstchar=$tLength-1;
    $plstchar=$pLength-1;
     $count=0;
	if ($pLength>=$tLength&&$typed[0]==$printed[0]&&$typed[$tlstchar]==$printed[$plstchar])
	     {

                $same=true;

                if(count(array_unique(str_split($typed)))==1)
                    $grp1[0]=$typed;
                else
                 {
                        $ara=array();
                        for ($i=0,$j=0; $i <strlen($typed)-1 ; $i++)
                         {
                              if($typed[$i]!=$typed[$i+1])
                              {
                                 $ara[$j++]=$i;
                              }
                                //echo "$i\n";
                         }
                         //$start=0;
                         $grp1=array();
                         for ($i=0; $i <count($ara); $i++)
                         {
                                if($i==0)
                                  $grp1[$i]=substr($typed,0,$ara[$i]+1);
                                else
                                {
                                  $diff=$ara[$i]-$ara[$i-1];
                                  $grp1[$i]=substr($typed,$ara[$i-1]+1,$diff);
                                }
                              $grp1[$i+1]=substr($typed,$ara[$i]+1);

                        }
                    }
                   // print_r($grp1)."\n";
                if(count(array_unique(str_split($printed)))==1)
                    $grp2[0]=$printed;
                else
                 {
                        $ara=array();
                        for ($i=0,$j=0; $i <strlen($printed)-1 ; $i++)
                         {
                              if($printed[$i]!=$printed[$i+1])
                              {
                                 $ara[$j++]=$i;
                              }
                                //echo "$i\n";
                         }
                         //$start=0;
                         $grp2=array();
                         for ($i=0; $i <count($ara); $i++)
                         {
                                if($i==0)
                                  $grp2[$i]=substr($printed,0,$ara[$i]+1);
                                else
                                {
                                  $diff=$ara[$i]-$ara[$i-1];
                                  $grp2[$i]=substr($printed,$ara[$i-1]+1,$diff);
                                }
                              $grp2[$i+1]=substr($printed,$ara[$i]+1);

                        }
                    }
                    if(count($grp1)!=count($grp2))
                        $same=false;
                     else
                     {
                        for ($i=0; $i <count($grp1) ; $i++)
                        {
                            if(array_unique(str_split($grp1[$i]))!=array_unique(str_split($grp2[$i])))
                            {
                                $same=false;
                                break;
                            }
                        }
                     }

        }

   echo $same?"YES\n":"NO\n";
}


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

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

    $maxCapacity = 0;
    $capacity = 0;
    for($i=0; $i<$n; $i++){
        fscanf($stdin, "%d%d\n", $a, $b);
        $tmp = $b - $a;
        $capacity += $tmp;
        if($capacity > $maxCapacity)
            $maxCapacity = $capacity;

    }

    echo $maxCapacity;

    fclose($stdin);
?>

<?php
$n = trim(fgets(STDIN));
$as = [];
$bs = [];

$cap = 0;
$cap_min = 0;
for($i = 0; $i<$n ; $i++){
  $input = fgets(STDIN);
  $array = array_map('intval', explode(' ', $input));
  array_push($as, $array[0]);
  array_push($bs, $array[1]);
}
for ($i = 0; $i<$n ; $i++){
  if($i == 0){
    $cap = $bs[$i];
    $cap_min = $cap;
  }else{
    $cap = $cap - $as[$i] + $bs[$i];
    if($cap > $cap_min){
      $cap_min = $cap;
    }
  }
}
echo $cap_min;

?>

<?php
$f = fopen('php://stdin', 'r');
//$f = fopen('5q.txt', 'r');
$n = trim(fgets($f));

$max = 0;
$cur = 0;

for ($i=0;$i<$n;$i++){
    $a = explode(" ",trim(fgets($f)));

    $cur-=$a[0];
    $cur+=$a[1];

    if ($cur>$max) $max = $cur;
}

echo $max;

<?php

fscanf(STDIN, "%d\n", $n);

$maxRiders = 0;
$currentRiders = 0;

for ($i = 0; $i < $n; $i++) {
    fscanf(STDIN, "%d %d\n", $a, $b);

    $currentRiders -= $a;
    $currentRiders += $b;
    $maxRiders = ($currentRiders > $maxRiders) ? $currentRiders : $maxRiders;
}

echo $maxRiders;

?>

<?php
fscanf(STDIN, "%d", $n);
$max_number = 0;
$max_array = array();
while($n--){
	fscanf(STDIN, "%s%s", $out, $in);
	$max_number = ($max_number - $out) + $in;
	$max_array[] = $max_number;
}
echo max($max_array);

<?php
$n = trim(fgets(STDIN));
$pass = 0;
$min = 0;
for ($i=0;$i<$n;$i++){
    $s = explode(' ', trim(fgets(STDIN)));
    $pass += -$s[0] + $s[1];
    if ($pass > $min)
        $min = $pass;
}
echo $min;
?>

<?php
    $f = fopen('php://stdin', 'r');
    $count = (int)fgets($f);
    $people = 0;
    $max = 0;

    for ($i = 0; $i < $count; $i++) {
        $arr = explode(' ', fgets($f));

        if (($people = $people - (int)$arr[0] + (int)$arr[1]) > $max) $max = $people;
    }

    echo $max;
?>

<?php
    $f = fopen('php://stdin', 'r');
    $count = (int)fgets($f);
    $people = 0;
    $max = 0;

    for ($i = 0; $i < $count; $i++) {
        $out = '';
        $in = '';

        while(is_numeric($char = fgetc($f))) {
            $out.= $char;
        }
        while(is_numeric($char = fgetc($f))) {
            $in.= $char;
        }
        fgets($f);

        if (($people = $people - $out + $in) > $max) $max = $people;
    }

    echo $max;
?>

<?php

$kol = trim(fgets(STDIN));

while ($str = fgets(STDIN))
{
    $mas[] = explode(' ', $str);
}
$n = 0;
for ($i = 0; $i < count($mas); $i++)
{
    $max[] = $n - $mas[$i][0] + $mas[$i][1];
    $n = $n - $mas[$i][0] + $mas[$i][1];
}
$vmestimost = max($max);
echo $vmestimost;

?>

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

while(fscanf(STDIN,"%d",$n)){
    $ans=0;
    $per=0;
    while($n-->0){
        fscanf(STDIN,"%d%d",$ex,$en);
        $per+=$en-$ex;
        if($ans<$per)$ans=$per;
    }
    fprintf(STDOUT,"%d\n",$ans);
}

<?php
// 116A Трамвай

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

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

$out = 0;
$col = 0;

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

    $input_line = fgets($in);

    list($a, $b) = split(" ", $input_line);
    $a = (int) $a;
    $b = (int) $b;

    $col += $b - $a;

    if ($col > $out) $out = $col;
}

echo $out;

?>

<?php
    $n = trim(fgets(STDIN));
    $count=0; $min=0;
    for ($i=1; $i<=$n; $i++){
        list($a,$b) = explode(' ',trim(fgets(STDIN)));
        $count=$count+$b-$a;
        if ($min<$count) $min=$count;
    }
    print($min);

?>

<?php
    fscanf(STDIN, "%d",$s);
    $c=0;
    $max=0;
    while (fscanf(STDIN, "%d %d", $out, $in)){
      $c = $c-$out+$in;
      $max=$c>$max?$c:$max;
    }
    echo $max;
?>

<?php

$count = (int) fgets(STDIN);

$passengers = 0;
$maxPassengers = 0;
for ($i = 0; $i < $count; $i++) {
    $rawQInfo = rtrim(fgets(STDIN));
    $rawInfo = explode(' ', $rawQInfo);

    $output = (int) $rawInfo[0];
    $input = (int) $rawInfo[1];

    $passengers += $input - $output;
    $maxPassengers = max($passengers, $maxPassengers);
}

echo $maxPassengers . PHP_EOL;

<?
$n=trim(fgets(STDIN));
for($i=0;$i<$n;$i++)
    $arr[]=explode(' ',trim(fgets(STDIN)));
$cur_peoples=0;
$max=0;
for($i=0;$i<$n;$i++){
    $cur_peoples-=$arr[$i][0];
    $cur_peoples+=$arr[$i][1];
    if($cur_peoples>$max) $max=$cur_peoples;
}
echo $max;
?>

<?php
fscanf(STDIN, '%d', $n);	// считываем кол-во остановок

$trainCounter = 0;
$total = array();

for($i = 0; $i < $n; $i++) {	// считываем количество выходящих и входящих
	fscanf(STDIN, '%d%d', $outcomers, $incomers);
	 //$trainCounter[$i] = $outcomers . '' . $outcomers;
	// $trainCounter[$i + 1] = $incomers;
	$trainCounter = $trainCounter - $outcomers;

	$trainCounter = $trainCounter + $incomers;
	array_push($total, $trainCounter);
}

printf(max($total));

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

$capacity = 0;
$max = 0;
for ($i = 0; $i < $n; $i++) {
    fscanf(STDIN, '%d %d', $wyj, $wej);
    $capacity = $capacity - $wyj + $wej;
    //echo $capacity."\n";
    if ($capacity > $max) $max = $capacity;
}

echo $max;

<?php

error_reporting(0);
$arr = [];
$testCase = (int) fgets(STDIN);

while ($testCase--) {
    list($n1, $n2) = explode(' ', fgets(STDIN));
    $current = $current - $n1;
    $current = $current + $n2;
    $arr[] = $current;
}
echo max($arr)."\n";

<?
$n=trim(fgets(STDIN));
$intram=0;$mx=0;
for($i=0;$i<$n;$i++)
    {
        $ex=explode(" ",trim(fgets(STDIN)));
        $intram-=$ex[0];
        $intram+=$ex[1];
        if($intram>$mx)$mx=$intram;
    }
   echo $mx;
?>

<?php
$n = trim(fgets(STDIN));

$c = 0;
$m = 0;
for($i=0;$i<$n;$i++){
 list($a, $b) = explode(' ',trim(fgets(STDIN)));
 $c -= $a - $b;
 if($m < $c) $m = $c;
}

print $m;
?>

<?
$fp=fopen('php://stdin', 'r');
$lines=stream_get_contents($fp);
$lines=trim($lines);
$lines=explode("\n", $lines);

$cur=0;
$max=0;
for($i=1; $i<count($lines); $i++)
{
    list($minus, $plus)=explode(" ", trim($lines[$i]));
    $cur=$cur-$minus+$plus;
    if ($cur>$max) $max=$cur;
}
echo $max;
?>

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

fprintf(STDOUT, $result);

<?php

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

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

$currentMax = 0;
$inTram = 0;

for($i = 0; $i < $n; $i++)
{
	list($out, $in) = fscanf($stdin, "%d %d");

	$inTram -= $out;
	$inTram += $in;
	if($inTram > $currentMax)
	{
		$currentMax = $inTram;
	}
}

echo $currentMax;

<?php
//116A: Tram
$n = trim(fgets(STDIN)); //$n = 4;
//$array = array("0 3", "2 5", "4 2", "4 0");
$capacities = array();
$ontram = 0;
for ($i = 0; $i < $n; $i++) {
    list($off, $on) = explode(" ", trim(fgets(STDIN)));
    //list($off, $on) = explode(" ", $array[$i]);
    $ontram = $ontram - $off;
    $ontram = $ontram + $on;
    $capacities[] = $ontram;
}
rsort($capacities);
echo $capacities[0];
?>

<?php

$m_capacity = $c_capacity = 0;

$s1 = fgets(STDIN);

while ($s = fgets(STDIN))
{
    $row = preg_split("/\s/", $s);
    $c_capacity = $c_capacity - $row[0] + $row[1];

    if ($c_capacity > $m_capacity)
        $m_capacity = $c_capacity;
}

echo $m_capacity;
exit;

<?php
	fgets(STDIN);
	$max = -1;
	$now = 0;
	$arr = [];
	while(fscanf(STDIN, '%d %d', $arr[0], $arr[1])){
		$now = $now - $arr[0] + $arr[1];
		if($now > $max) $max = $now;
	}
	echo $max;
?>

<?php
$a = trim(fgets(STDIN));
list($b, $c) = explode(" ", trim(fgets(STDIN)));
$d = array($c);
$e = $c;
for($x = 1; $x < $a; $x++)
{
    list($b, $c) = explode(" ", trim(fgets(STDIN)));
    $e = $e - $b + $c;
    array_push($d, $e);
}
rsort($d);
print $d[0];
?>

<?php
    $fp = fopen('php://stdin', 'r');
    $n = fgets($fp);
    $a = array();
    $b = array();
    while(!feof($fp))
        list($a[], $b[]) = explode(' ', rtrim(fgets($fp)));
    $max = $now = $b[0];
    for($i = 1; $i < $n; $i++) {
        $now = $now - $a[$i] + $b[$i];
        if($now > $max)
            $max = $now;
    }
    echo $max;
?>

<?php
	$cur = 0;
	$max = 0;
	$n = fgets(STDIN);
	for ($x = 0; $x < $n; $x++) {
		list($out,$in) = explode(' ',fgets(STDIN));
		$cur = $cur - (int)$out + (int)$in;
		if ($cur > $max) $max = $cur;
	}
	echo $max;

<?php

fscanf (STDIN, "%d",$n);
$num = 0;
$res = 0;
for ($i=0; $i < $n; $i++)
{
  fscanf (STDIN, "%d %d", $out, $in);
  $num -= $out;
  $num += $in;
  if ($num > $res) $res = $num;
}
echo $res;
?>

<?php

$n = readline();

$stationStatus = [];
for($i = 0; $i < $n; $i++){
    $stationStatus[] = explode(' ', readline());
}
$count = 0;
$max = 0;
foreach ($stationStatus as $key => $stationStatus) {
    $count -= $stationStatus[0];
    $count += $stationStatus[1];
    if($count > $max) $max = $count;
}
echo $max;

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

fscanf($input,"%d",$n);
$capacity = 0;
$totalPassengers = 0;
for($i=0; $i<$n; ++$i) {
    fscanf($input,"%d%d",$exited,$entered);
    $totalPassengers += $entered - $exited;
    if($totalPassengers > $capacity) {
        $capacity = $totalPassengers;
    }
}
fprintf($output,"%d",$capacity);

?>

<?php
/**
 * Created by PhpStorm.
 * User: kuangzhexi
 * Date: 13-11-11
 * Time: 下午12:07
 */

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

$n = trim(fgets($fp));

$max = 0;
$num = 0;
while ($n--) {
    $line = fgets($fp);
    list($a, $b) = explode(" ", trim($line));

    $num = $num - $a + $b;
    if ($num > $max) {
        $max = $num;
    }
}

print $max . "\n";

<?php
list($n)=explode(" ", trim(fgets(STDIN)));
$max=0;$s=0;
while ($n>0):
list($a,$b)=explode(" ", trim(fgets(STDIN)));
$s=$s-$a+$b;
if ($s>$max) $max=$s;
$n--;
endwhile;
print $max;
?>

<?php

$a = array();
fscanf(STDIN, "%d", $n);
$res = 0;
$cnt = 0;

for ($i = 0; $i < $n; $i++) {
	$cur = explode(" ", trim(fgets(STDIN)));
	$cnt = $cnt - $cur[0] + $cur[1];
	if ($cnt > $res)
	    $res = $cnt;
}

echo $res;

<?php
    $n = trim(fgets(STDIN));
    $m = 0; $c = 0;
    for($i = 0; $i < $n; $i++){
        $s = explode(" ",trim(fgets(STDIN)));
        $c=$c-$s[0]+$s[1];
        if($c > $m)$m = $c;
    }
    fwrite(STDOUT, $m);

<?php
	$i = 0;
	$min = 0;
	$x = 0;
	$stop = trim(fgets(STDIN));
	while($i<$stop)
	{
		$pass = explode(" ",trim(fgets(STDIN)));
		$x = $x - $pass[0] + $pass[1];
		if($min < $x)
			$min = $x;
		$i++;
	}
	echo $min;
?>

<?php
$stops = fgets(STDIN);
$num_pasengers = 0;$previous_enter=0;
for ($i=0; $i <$stops ; $i++) {
	$exit_enter = explode(' ', fgets(STDIN));
	$num_pasengers += $exit_enter[1]-$exit_enter[0];
	$max_num[$i] = $num_pasengers;
}
echo max($max_num);
?>

<?php
$n = fgets(STDIN);
$total=0;
$ans=0;
for($i=0;$i<$n;$i++){
list($a, $b) = explode(' ',trim(fgets(STDIN)));
 $total-=$a-$b;
 if($total>$ans){$ans=$total;}
}
echo $ans;
?>

<?php

$flag = 1; //must be not zero for STDIN
$in = 'php://stdin';
if (!$flag)
{
    $in = "input.txt";
}
$fd = fopen($in, "r");
fscanf($fd, "%d\n", $n);

$exit = array($n);
$enter = array($n);
for ($c = 0; $c < $n; $c++)
{
    fscanf($fd, "%d %d\n", $exit[$c], $enter[$c]);
}
fclose($fd);

for ($c = 0, $pass = 0, $max = 0; $c < $n; $c++)
{
    $pass+=$enter[$c];
    $pass-=$exit[$c];
    if ($max < $pass)
    {
        $max = $pass;
    }
}
print $max . "\n";
?>

<?php
$counter=0;
$max=0;
fscanf(STDIN, "%d",$n);
for ($i=0; $i < $n; $i++) {
	fscanf(STDIN,"%d %d",$out, $in);
	$counter-=($out-$in);
	if($max<$counter) $max=$counter;
}
echo $max;
?>

<?php
   $n = trim(fgets(STDIN));
   $sum = 0;
   $max = 0;
   for($i=0;$i<$n;$i++)
   {
       $pass = explode(' ',trim(fgets(STDIN)));
       $sum -= $pass[0];
       $sum += $pass[1];
       if($sum > $max) $max = $sum;
   }
   echo $max;
?>

<?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;

$r = 0;
$a = $b = [];
$max = 0;
$t = 0;

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

for ($i = 0; $i < $n; $i++) {
    list($a[$i], $b[$i]) = fscanf($input, "%d %d\n");

    $t -= $a[$i];
    $t += $b[$i];

    if ($t > $max) {
        $max = $t;
    }
}

fwrite($output, $max);

<?php

$n = fgets(STDIN);
$sum = 0;
$max = 0;
for ($i=1; $i <= $n; $i++) {
    list($a, $b) = explode(' ',trim(fgets(STDIN)));
    $sum -= (int) $a;
    $sum += (int) $b;
    if ($sum > $max) {
        $max = $sum;
    }
}

echo $max;

<?php
$max = 0;
$cur = 0;
$n = intval(fgets(STDIN));
for($i=0;$i<$n;$i++) {
    $in = explode(' ',trim(fgets(STDIN)));
    $cur -= $in[0];
    $cur += $in[1];
    if($cur > $max) {
        $max = $cur;
    }
}
echo( $max );

<?php
$n = trim(fgets(STDIN));
$station_list[] = array();
$max = 0;

for($i=0; $i<$n; $i++){
    $station_list[$i] = explode(' ',trim(fgets(STDIN)));
}

$count_passengers = array();
for( $i=0; $i<$n; $i++ ){
    for( $j=0; $j<1; $j++ ) {
        if( $i > 0 )
        {
            $in_bus = (($count_passengers[$i-1]) - $station_list[$i][$j]);
        }else{
            $in_bus = 0;
        }
        $count_passengers[$i] = $in_bus + $station_list[$i][++$j];
    }
}

for( $k=0; $k<sizeof($count_passengers); $k++  ){
    if( $max < $count_passengers[$k] )
    {
        $max = $count_passengers[$k];
    }
}
echo $max;

<?
$a = trim(fgets(STDIN));
$max = 0;
$curr = 0;
for($i = 0; $i < $a; $i++){
    list($out, $in) = explode(' ', trim(fgets(STDIN)));
    $curr -= $out;
    $curr += $in;
    if($max < $curr)
        $max = $curr;
}
echo $max;

<?php
$n = trim(fgets(STDIN));
$max=0;
$current=0;
for ($i=0;$i<$n;$i++)
{
    $player = explode(" ",fgets(STDIN));
    $current += $player[1]-$player[0];
    if ($max<$current)$max=$current;
}
echo $max;
?>

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

	$n = input();
	$result = 0;
	$now = 0;
	for ($i = 0; $i < $n; $i++)
	{
		$str = explode(" ", trim(fgets($stdin)));
		$now += $str[1] - $str[0];
		if ($now > $result)
		{
			$result = $now;
		}
	}
	echo $result;
?>

<?php
$f = fopen("php://stdin", "r");
fscanf($f, "%d", $n);

$res = 0;
$cur = 0;
while ($n--) {
    fscanf($f, "%d%d", $a, $b);
    $cur-=$a;
    $cur+=$b;
    $res = max($res, $cur);
}
echo $res;

?>

<?
$n=trim(fgets(STDIN));
$in=0;$max=0;
for($i=0;$i<$n;$i++)
    {
        $ex=explode(" ",trim(fgets(STDIN)));
        $in-=$ex[0];
        $in+=$ex[1];
        if($in>$max)$max=$in;
    }
   echo $max;
?>

<?php
  //$file = fopen("/home/py/PHPtraing/input.txt", "r");
  $file = STDIN;
  $n = (int) fgets($file);

  $now = 0;
  $ans = 0;
  for ($i=0; $i < $n; $i++) {
    $a = explode(" ",trim(fgets($file)));
    $now = $now - $a[0] + $a[1];
    $ans = max($ans,$now);
  }

  print $ans;

 fclose($file);

?>

<?php
// Open the file
$input = "C:\\xampp\\htdocs\\test\\test.txt";
if (@(ONLINE_JUDGE)) {
 $input = 'php://stdin';
}

// Add each line to an array

    $array = explode("\n", file_get_contents($input));
    array_shift($array);
    $array = array_values($array);
    $output = [];
    $max = 0;
    $id = 0;
    foreach ($array as $key => $value){
        $arr = explode(" ", $value);
        $id += -intval($arr[0]) + intval($arr[1]);

        if($id > $max) $max= $id;

    }
    echo $max;

<?php
$a = trim(fgets(STDIN));
list($b, $c) = explode(" ", trim(fgets(STDIN)));
$d = array();
$e = $c;
for($x = 1; $x < $a; $x++)
{
    list($b, $c) = explode(" ", trim(fgets(STDIN)));
    $e = $e - $b + $c;
    array_push($d, $e);
}
rsort($d);
print $d[0];
?>

<?php

fscanf (STDIN, "%d",$n);
$num = 0;
$res = 0;
for ($i=0; $i < $n; $i++)
{
  fscanf (STDIN, "%d %d", $o, $i);
  $num -= $o;
  $num += $i;
  if ($num > $res) $res = $num;
}
echo $res;
?>

<?php

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

$arr = explode(PHP_EOL, $input);
$sum = 0;
$max = 0;
for ($i=1; $i <= $arr[0]; $i++) {
    $sum -= (int) $arr[$i][0];
    $sum += (int) $arr[$i][2];
    if ($sum > $max) {
        $max = $sum;
    }
}

echo $max;

<?php
$n = trim(fgets(STDIN));
$max=0;
for ($i=0;$i<$n;$i++)
{
    $player = explode(" ",fgets($resource));
    if ($max<=$player[1]-$player[0])
    {
        $max+=$player[1]-$player[0];
    }
}
echo $max;
?>

<?php
$n = trim(fgets(STDIN));
$max=0;
$current=0;
for ($i=0;$i<$n;$i++)
{
    $player = explode(" ",fgets($resource));
    $current += $player[1]-$player[0];
    if ($max<$current)$max=$current;
}
echo $max;
?>

<?php
$n = trim(fgets(STDIN));
$max=0;
for ($i=0;$i<$n;$i++)
{
    $player = explode(" ",fgets(STDIN));
    if ($max<=$player[1]-$player[0])
    {
        $max+=$player[1]-$player[0];
    }
}
echo $max;
?>

<?php
// Open the file
//$input = "C:\\xampp\\htdocs\\test\\test.txt";
$input = 'php://stdin';

//$file = @fopen("C:\\xampp\\htdocs\\test\\test.txt", 'r');

$file = fopen($input, 'r');

// Add each line to an array
if ($file) {
    $array = explode("\n", file_get_contents($input));

    $array = array_values($array);
    $arr = [4, 7];
    var_dump($array);

    $output = [];
    $max = 0;
    $id = 0;
    foreach ($array as $key => $value) {
        $thisWordCodeVerdeeld = str_split($value);
        foreach ($thisWordCodeVerdeeld as $val) {
            $a = in_array(intval($val), $arr);
            if ($a == false) {
                echo 'NO';
                break;
            }
        }
//        $output[] = $str;
    }
    echo 'YES';
}
    fclose($file);

<?php
// Open the file
//$input = "C:\\xampp\\htdocs\\test\\test.txt";
$input = 'php://stdin';

//$file = @fopen("C:\\xampp\\htdocs\\test\\test.txt", 'r');

$file = fopen($input, 'r');

// Add each line to an array
if ($file) {
    $array = explode("\n", file_get_contents($input));

    array_shift($array);
    $array = array_values($array);
    $output = [];
    $max = 0;
    $id = 0;
    foreach ($array as $key => $value){
        $id += -intval($value[0]) + intval(substr($value,-1));
        if($id > $max) $max= $id;

//        $output[] = $str;
    }
    fclose($file);
    echo $max;
}

<?php
// Open the file
//$input = "C:\\xampp\\htdocs\\test\\test.txt";
$input = 'php://stdin';

//$file = @fopen("C:\\xampp\\htdocs\\test\\test.txt", 'r');

$file = fopen($input, 'r');

// Add each line to an array
if ($file) {
    $array = explode("\n", file_get_contents($input));

    array_shift($array);
    $array = array_values($array);
    $output = [];
    $max = 0;
    $id = 0;
    foreach ($array as $key => $value){
        $id += -intval($value[0]) + intval(substr($value,-1));
        if($id > $max) $max= $id;

    }
    echo $max;
    fclose($file);
}

<?php
// Open the file
//$input = "C:\\xampp\\htdocs\\test\\test.txt";
$input = 'php://stdin';

//$file = @fopen("C:\\xampp\\htdocs\\test\\test.txt", 'r');

$file = fopen($input, 'r');

// Add each line to an array
if ($file) {
    $array = explode("\n", file_get_contents($input));

    array_shift($array);
    $array = array_values($array);
    $output = [];
    $max = 0;
    $id = 0;
    foreach ($array as $key => $value){
        $id += -intval($value[0]) + intval(substr($value,-1));
        if($id > $max) $max= $id;

//        $output[] = $str;
    }
    echo $max;
    fclose($file);
}

<?php
$n = trim(fgets(STDIN));
$pass = 0;
$min = 0;
for ($i=0;$i<$n;$i++){
    $s = explode(' ', trim(fgets(STDIN)));
    $pass += $s[0] + $s[1];
    if ($pass > $min)
        $min = $pass;
}
echo $min;
?>

<?
$n=trim(fgets(STDIN));
for($i=0;$i<$n;$i++)
	$arr[]=explode(' ',trim(fgets(STDIN)));
print_r($arr);
$cur_peoples=0;
$max=0;
for($i=0;$i<$n;$i++){
	$cur_peoples-=$arr[$i][0];
	$cur_peoples+=$arr[$i][1];
	if($cur_peoples>$max) $max=$cur_peoples;
}
echo $max;
?>

<?php

error_reporting(0);
$std = fopen("php://stdin","r");
fscanf($std,"%d",$n);
$current = 0;
$arr = [];
for($i = 0; $i < $n; $i++)
{
    fscanf($std,"%d",$n1);
    fscanf($std,"%d",$n2);

    $current = $current - $n1;
    $current = $current + $n2;
    $arr[] = $current;
}
echo max($arr)."\n";

fclose($std);


<?php
/*****************************************/
class InputReader {protected $_fh;public function __construct($fileHandler = STDIN){$this->_fh = $fileHandler;}
	public function readInt() {$d = trim(fgets($this->_fh));return (int)$d;}
	public function readString() {$d = trim(fgets($this->_fh));return $d;}
	public function readArrayOfInt($size, $indexFrom = 0) {$a = [];$ind = $indexFrom;foreach (explode(' ', fgets($this->_fh)) as $item) {$a[$ind++] = (int)$item;}return $a;}
	public function readArrayOfString($size, $indexFrom = 0) {$a = [];$ind = $indexFrom;foreach (explode(' ', fgets($this->_fh)) as $item) {$a[$ind++] = $item;}return $a;}
}

/* Perform action N times. Can return values in array */
function ntimes($n, $func, $returnResults = false) {$a = [];for ($i=1; $i<=$n; $i++) {$result = $func();if ($returnResults) {$a[$i] = $result;}}return $a;}

/* Integral. Keys preserved. By reference. */
function cumsum(&$a){$sum = 0;foreach($a as $k=>$v) {$a[$k] += $sum;$sum = $a[$k];}}

/* Difference. Keys preserved. By reference. */
function diff(&$a){$prev = 0;foreach($a as $k=>$v) {$buf=$a[$k];$a[$k]-=$prev;$prev = $buf;}}

function bitCount($n){$cnt = 0;for ($j=$n; $j; $j>>=1){$cnt += $j&1;}return $cnt;}

class PrimeUtils {static protected $divisors = [1 => [1=>true],2 => [1=>true, 2=>true],];static protected $primes = [];
	static public function primes($limit){$a = str_repeat(chr(85), ($limit>>3) + 1);$a[0] = chr(83);for ($i=3; $i*$i < $limit; $i+=2) {if (ord($a[$i>>3]) & (1<<($i%8))) {;} else {for ($k=$i; $k*$i<$limit; $k++) {$n = $k*$i;$a[$n>>3] = chr(ord($a[$n>>3]) | (1<<($n%8)));}}}yield 2;for ($i=3; $i<$limit; $i+=2) {if (!(ord($a[$i>>3]) & (1<<($i%8)))) {yield $i;}}}
	static public function divisors($n, $lp = 2) {if (isset(self::$divisors[$n])) {return self::$divisors[$n];}if (empty(self::$primes)) {$primes = [];foreach (self::primes(1e3) as $prime) {$primes[$prime] = $prime;}self::$primes = $primes;}$r = [];foreach (self::$primes as $p) {if ($p>=$lp) {if ($n < $p*$p) {$r = [1=>true, $n=>true];break;} elseif ($n%$p==0) {foreach([1, $p] as $pre) {foreach(self::divisors(intdiv($n,$p), $p) as $nxt=>$v) {$r[$nxt*$pre] = true;}}break;}}}self::$divisors[$n] = $r;return self::$divisors[$n];}
}

/*****************************************/

$ir = new InputReader();

/* TASK */

$n = $ir->readInt();
$mas = [];

for ($i=1; $i<=$n; $i++) {
	$s = $ir->readString();
	if (!check($s)) {
		continue;
	}

	$chars = count_chars($s, 1);

	$d = ($chars[ord('(')]??0) - ($chars[ord(')')]??0);
	if (!isset($mas[$d])) {
		$mas[$d] = 0;
	}
	$mas[$d] += 1;
}

$cnt = 0;
foreach ($mas as $d=>$m) {
	if ($d>0) {
		$cnt += min([$m, $mas[-$d]??0]);
	}
}

echo $cnt+(($mas[0]??0)>>1);

function check ($s) {
	$stack = [];
	for ($i=0; $i<strlen($s); $i++) {
		end($stack);
		if ($s[$i]==')' and current($stack)=='(') {
			array_pop($stack);
		} else {
			$stack[] = $s[$i];
		}
	}

	if (count($stack)<=1) {
		return true;
	} else {
		return $stack[0]==$stack[count($stack)-1];
	}
}

<?php
$n = (int)trim(fgets(STDIN));
$store = [];
$result = 0;

for ($i = $n; $i > 0; $i--) {
    list($s, $error) = cCount(trim(fgets(STDIN)));
    if ($error) {continue;}
    $nS = -$s;
    if (array_key_exists($nS, $store) && $store[$nS] > 0) {
        $result++;
        $store[$nS]--;
    } else {
        $store[$s] = array_key_exists($s, $store) ? $store[$s] + 1 : 1;
    }
}

echo $result;

function cCount($s)
{
    $rs = 0;
    $min = 0;
    $arr = str_split($s);
    foreach ($arr as $r) {
        if ($r === '(') {
            $rs++;
        }
        if ($r === ')') {
            $rs--;
            $min = min($min, $rs);
        }
    }

    return [$rs, ($min < 0 && $min !== $rs)];
}

<?php
/*****************************************/
class InputReader {protected $_fh;public function __construct($fileHandler = STDIN){$this->_fh = $fileHandler;}
	public function readInt() {$d = trim(fgets($this->_fh));return (int)$d;}
	public function readString() {$d = trim(fgets($this->_fh));return $d;}
	public function readArrayOfInt($size, $indexFrom = 0) {$a = [];$ind = $indexFrom;foreach (explode(' ', fgets($this->_fh)) as $item) {$a[$ind++] = (int)$item;}return $a;}
	public function readArrayOfString($size, $indexFrom = 0) {$a = [];$ind = $indexFrom;foreach (explode(' ', fgets($this->_fh)) as $item) {$a[$ind++] = $item;}return $a;}
}

/* Perform action N times. Can return values in array */
function ntimes($n, $func, $returnResults = false) {$a = [];for ($i=1; $i<=$n; $i++) {$result = $func();if ($returnResults) {$a[$i] = $result;}}return $a;}

/* Integral. Keys preserved. By reference. */
function cumsum(&$a){$sum = 0;foreach($a as $k=>$v) {$a[$k] += $sum;$sum = $a[$k];}}

/* Difference. Keys preserved. By reference. */
function diff(&$a){$prev = 0;foreach($a as $k=>$v) {$buf=$a[$k];$a[$k]-=$prev;$prev = $buf;}}

function bitCount($n){$cnt = 0;for ($j=$n; $j; $j>>=1){$cnt += $j&1;}return $cnt;}

class PrimeUtils {static protected $divisors = [1 => [1=>true],2 => [1=>true, 2=>true],];static protected $primes = [];
	static public function primes($limit){$a = str_repeat(chr(85), ($limit>>3) + 1);$a[0] = chr(83);for ($i=3; $i*$i < $limit; $i+=2) {if (ord($a[$i>>3]) & (1<<($i%8))) {;} else {for ($k=$i; $k*$i<$limit; $k++) {$n = $k*$i;$a[$n>>3] = chr(ord($a[$n>>3]) | (1<<($n%8)));}}}yield 2;for ($i=3; $i<$limit; $i+=2) {if (!(ord($a[$i>>3]) & (1<<($i%8)))) {yield $i;}}}
	static public function divisors($n, $lp = 2) {if (isset(self::$divisors[$n])) {return self::$divisors[$n];}if (empty(self::$primes)) {$primes = [];foreach (self::primes(1e3) as $prime) {$primes[$prime] = $prime;}self::$primes = $primes;}$r = [];foreach (self::$primes as $p) {if ($p>=$lp) {if ($n < $p*$p) {$r = [1=>true, $n=>true];break;} elseif ($n%$p==0) {foreach([1, $p] as $pre) {foreach(self::divisors(intdiv($n,$p), $p) as $nxt=>$v) {$r[$nxt*$pre] = true;}}break;}}}self::$divisors[$n] = $r;return self::$divisors[$n];}
}

/*****************************************/

$ir = new InputReader();

/* TASK */

$n = $ir->readInt();
$mas = [];

for ($i=1; $i<=$n; $i++) {
	$s = $ir->readString();
	$chars = count_chars($s, 1);

	$d = ($chars[ord('(')]??0) - ($chars[ord(')')]??0);
	if (!isset($mas[$d])) {
		$mas[$d] = 0;
	}
	$mas[$d] += 1;
}

$cnt = 0;
foreach ($mas as $d=>$m) {
	if ($d>0)
		$cnt += min($m, $mas[-$d]??0);
}

echo $cnt+(($mas[0]??0)>>1);

<?php
$n = (int)trim(fgets(STDIN));
$store = [];
$result = 0;

for ($i = $n; $i > 0; $i--) {
    $s = cCount(trim(fgets(STDIN)));
    $nS = -$s;
    if (array_key_exists($nS, $store) && $store[$nS] > 0) {
        $result++;
        $store[$nS]--;
    } else {
        $store[$s] = array_key_exists($s, $store) ? $store[$s] + 1 : 1;
    }
}

echo $result;

function cCount($s)
{
    $rs = 0;
    $arr = str_split($s);
    foreach ($arr as $r) {
        if ($r === '(') {
            $rs++;
        }
        if ($r === ')') {
            $rs--;
        }
    }
    return $rs;
}

<?php
$n = (int)trim(fgets(STDIN));
$store = [];
$result = 0;

for ($i = $n; $i > 0; $i--) {
    $s = cCount(trim(fgets(STDIN)));
    if (array_key_exists($s, $store)) {
        $result++;
        unset($store[$s]);
    } else {
        $store[$s] = 1;
    }
}

echo $result;

function cCount($s)
{
    $rs = 0;
    $arr = str_split($s);
    foreach ($arr as $r) {
        if ($r === '(') {
            $rs++;
        }
        if ($r === ')') {
            $rs--;
        }
    }
    return $rs;
}


<?php

function next_char($cur_char)
{
	return chr((ord($cur_char) - ord("a") + 1) % 26 + ord("a"));
}

function different_char($first, $second)
{
	$cur_char = $first;
	while ($cur_char === $first || $cur_char === $second)
	{
		$cur_char = next_char($cur_char);
	}
	return $cur_char;
}

list($n_str, $t_str) = explode(" ", fgets(STDIN));
$n = (int) $n_str;
$t = (int) $t_str;
$first_string = fgets(STDIN);
$second_string = fgets(STDIN);

$different_letters = 0;
$result_string = "";
for ($i = 0; $i < $n; ++$i) {
	if ($first_string[$i] !== $second_string[$i]) {
		++$different_letters;
		$result_string .= "*";
	}
	else
	{
		$result_string .= $first_string[$i];
	}
}

if ($different_letters > 2 * $t)
{
	fwrite(STDOUT, ((str)-1)."\n");
}
else if ($different_letters <= $t) {
	for ($i = 0; $i < $n && $different_letters < $t; ++$i)
	{
		if ($result_string[$i] !== "*") {
			--$t;
			$result_string[$i] = next_char($result_string[$i]);
		}
	}

	for ($i = 0; $i < $n; ++$i)
	{
		if ($result_string[$i] === "*")
		{
			$result_string[$i] = different_char($first_string[$i], $second_string[$i]);
		}
	}

	fwrite(STDOUT, $result_string."\n");
}
else {
	$first_written = 0;
	for ($i = 0; $i < $n && $first_written < $t; ++$i) {
		if ($result_string[$i] === "*") {
			++$first_written;
			$result_string[$i] = $second_string[$i];
		}
	}

	$second_written = 0;
	for ($i = $n - 1; $i >= 0 && $second_written < $t; --$i) {
		if ($result_string[$i] === "*") {
			++$second_written;
			$result_string[$i] = $first_string[$i];
		}
		else if ($first_string[$i] !== $second_string[$i]) {
			++$second_written;
			$result_string[$i] = different_char($first_string[$i], $second_string[$i]);
		}
	}

	fwrite(STDOUT, $result_string."\n");
}

<?php

function next_char($cur_char)
{
	return chr((ord($cur_char) - ord("a") + 1) % 26 + ord("a"));
}

function different_char($first, $second)
{
	$cur_char = $first;
	while ($cur_char === $first || $cur_char === $second)
	{
		$cur_char = next_char($cur_char);
	}
	return $cur_char;
}

list($n, $t) = explode(" ", fgets(STDIN));
$first_string = fgets(STDIN);
$second_string = fgets(STDIN);

$different_letters = 0;
$result_string = "";
for ($i = 0; $i < $n; ++$i) {
	if ($first_string[$i] !== $second_string[$i]) {
		++$different_letters;
		$result_string .= "*";
	}
	else
	{
		$result_string .= $first_string[$i];
	}
}

if ($different_letters > 2 * $t)
{
	fwrite(STDOUT, ((str)-1)."\n");
}
else if ($different_letters <= $t) {
	for ($i = 0; $i < $n && $different_letters < $t; ++$i)
	{
		if ($result_string[$i] !== "*") {
			$result_string[$i] = next_char($result_string[$i]);
			--$t;
		}
	}

	for ($i = 0; $i < $n; ++$i)
	{
		if ($result_string[$i] === "*")
		{
			$result_string[$i] = different_char($first_string[$i], $second_string[$i]);
		}
	}

	fwrite(STDOUT, $result_string."\n");
}
else {
	$first_written = 0;
	for ($i = 0; $i < $n && $first_written < $t; ++$i) {
		if ($result_string[$i] === "*") {
			++$first_written;
			$result_string[$i] = $second_string[$i];
		}
	}

	$second_written = 0;
	for ($i = $n - 1; $i >= 0 && $second_written < $t; --$i) {
		if ($result_string[$i] === "*") {
			++$second_written;
			$result_string[$i] = $first_string[$i];
		}
		else if ($first_string[$i] !== $second_string[$i]) {
			++$second_written;
			$result_string[$i] = different_char($first_string[$i], $second_string[$i]);
		}
	}

	fwrite(STDOUT, $result_string."\n");
}


<?php
$a = trim(fgets(STDIN));
$b = explode(" ", trim(fgets(STDIN)));
$c = trim(fgets(STDIN));
$d = explode(" ", trim(fgets(STDIN)));
$e = array();
$f = 1;
for($x = 0; $x < $a; $x++)
{
     $h = array_fill($f, $b[$x], $x + 1);
     $f += $b[$x];
     $e += $h;
}
for($x = 0; $x < $c - 1; $x++)
{
     print $e[$d[$x]] . "\n";
}
print $e[$d[$x]];
?>

<?php
$count_of_stacks = trim(fgets(STDIN));
$arr_count_worms_in_stacks = explode(" ", trim(fgets(STDIN)));
$count_of_juicy_worms = trim(fgets(STDIN));
$arr_numbers_of_worws_in_stack = explode(" ", trim(fgets(STDIN)));

for ($i = 0; $i<$count_of_stacks; $i++) {
    for ($j = 0; $j<$arr_count_worms_in_stacks[$i]; $j++) {
        $arr[] = $i+1;
    }
}
for ($i = 0; $i<$count_of_juicy_worms; $i++) {
    echo $arr[$arr_numbers_of_worws_in_stack[$i]-1]."\n";
}
?>

<?php
$count_of_stacks = trim(fgets(STDIN));
$arr_count_worms_in_stacks = explode(' ', trim(fgets(STDIN)));
$count_of_juicy_worms = trim(fgets(STDIN));
$arr_numbers_of_worws_in_stack = explode(' ', trim(fgets(STDIN)));
$count_of_warms = array_sum($arr_count_worms_in_stacks);
foreach ($arr_numbers_of_worws_in_stack as $value) {
	$counter = 0;
	$worms = $arr_count_worms_in_stacks[0];
	while ($value > $worms) {
		$worms += $arr_count_worms_in_stacks[$counter+1];
		$counter++;
	}
	echo ($counter+1)."<br>";
}
?>

<?php
$count_of_stacks = trim(fgets(STDIN));
$arr_count_worms_in_stacks = explode(' ', trim(fgets(STDIN)));
$count_of_juicy_worms = trim(fgets(STDIN));
$arr_numbers_of_worws_in_stack = explode(' ', trim(fgets(STDIN)));

$count_of_warms = array_sum($arr_count_worms_in_stacks);
foreach ($arr_numbers_of_worws_in_stack as $value) {
	$counter = 0;
	$worms = $arr_count_worms_in_stacks[0];
	while ($value > $worms) {
		$worms += $arr_count_worms_in_stacks[$counter+1];
		$counter++;
	}
	echo $counter+1;
}
?>

<?php
$f = fopen('php://stdin', 'r');
//$f = fopen('test.txt', 'r');

$n = trim(fgets($f));

$s = trim(fgets($f));
$a = explode(" ",$s);

$m = trim(fgets($f));
$q = explode(" ",trim(fgets($f)));

$aux = array();
foreach($a as $item){
    $end = end($aux);
    $aux[] = $end+$item;
}

function n_binary(&$source_array, $search_value){
/*
        int a = Leftmost_possible;
		int b = Rightmost_possible;
		while( a <= b){
            int mid = (a+b)/2;
			if (possible(mid)){
                b = mid-1;
            }else{
                a = mid+1;
            }
		}
		return a;
*/
    $count = count($source_array);
    $start = 0;
    $end = $count;

/*    print_r($source_array);
    printf("val = $search_value \n");*/

    while(($end - $start)>1){

        $mid = $start + floor(($end-$start)/2);
        //printf("start = %s, end = %s, mid = %s \n",$start,$end,$mid);

        if ($source_array[$mid]>$search_value){
            $end = $mid;
        } else {
            $start = $mid;
        }
    }

    return $start;

}

/**
 * Функция бинарного поиска по упорядоченному массиву
 * @param array $source_array Упорядоченный по возрастанию массив целых чисел
 * @param int $search_value Искомая величина
 * @return bool|int
 */
function binary_search(&$source_array, $search_value) {
    $count = count($source_array);

        $start = 0;
        $end = $count - 1;

        while (true) {
            $len = $end - $start;
            if ($len > 2) {
                if ($len % 2 != 0) $len++;
                $mid = (int)($len / 2 + $start);
            } elseif ($len >= 0) {
                $mid = $start;
            } else {
                return false;
            }

            if ($source_array[$mid-1]<$search_value && $source_array[$mid]>=$search_value){
                return $mid;
            }

            if ($source_array[$mid] == $search_value) {
                return $mid;
            } elseif ($source_array[$mid] > $search_value) {
                $end = $mid - 1;
            } else {
                $start = $mid + 1;
            }
        }
}

foreach($q as $item){
    /*
    foreach ($aux as $k=>$x) {
        if ($item<=$x){
            break;
        }
    }
    */
    //$k = binary_search($aux,(int)$item);
    $k = n_binary($aux,(int)$item);
    echo ($k+1)."\n";
}

//var_dump(binary_search($aux,(int)11));
//print_r($aux);

<?php
$f = fopen('php://stdin', 'r');
//$f = fopen('test.txt', 'r');

$n = trim(fgets($f));

$s = trim(fgets($f));
$a = explode(" ",$s);

$m = trim(fgets($f));
$q = explode(" ",trim(fgets($f)));

$aux = array();
foreach($a as $item){
    $end = end($aux);
    $aux[] = $end+$item;
}

foreach($q as $item){
    foreach ($aux as $k=>$x) {
        if ($item<$x){
            break;
        }
    }
    echo(($k+1)."\n");
}

//print_r($aux);

<?php
$f = fopen('php://stdin', 'r');
//$f = fopen('test.txt', 'r');

$n = trim(fgets($f));

$s = trim(fgets($f));
$a = explode(" ",$s);

$m = trim(fgets($f));
$q = explode(" ",trim(fgets($f)));

$aux = array();
foreach($a as $item){
    $end = end($aux);
    $aux[] = $end+$item;
}

/**
 * Функция бинарного поиска по упорядоченному массиву
 * @param array $source_array Упорядоченный по возрастанию массив целых чисел
 * @param int $search_value Искомая величина
 * @return bool|int
 */
function binary_search(&$source_array, $search_value) {
    $count = count($source_array);
    if ($count < pow(2, 31) && is_int($search_value)) {
        $start = 0;
        $end = $count - 1;

        while (true) {
            $len = $end - $start;
            //var_dump($len);
            if ($len > 2) {
                if ($len % 2 != 0) $len++;
                $mid = (int)($len / 2 + $start);
            } elseif ($len >= 0) {
                $mid = $start;
            } else {
                return false;
            }

            if ($source_array[$mid-1]<=$search_value && $source_array[$mid]>=$search_value){
                return $mid;
            }

            if ($source_array[$mid] == $search_value) {
/*
                  while (($mid != 0) && ($source_array[$mid - 1] == $search_value))
                    $mid--;
*/
                return $mid;
            } elseif ($source_array[$mid] > $search_value) {
                $end = $mid - 1;
            } else {
                $start = $mid + 1;
            }
        }
    } else {
        return false;
    }
}

foreach($q as $item){
    /*
    foreach ($aux as $k=>$x) {
        if ($item<=$x){
            break;
        }
    }
    */
    $k = binary_search($aux,(int)$item);
    echo ($k+1)."\n";
}

//var_dump(binary_search($aux,(int)11));
//print_r($aux);


<?php

//გიორგი I (დ. 998 ან 1002 — გ. 16 აგვისტო. 1027) — საქართველოს მეფე 1014-იდან, ბაგრატ III-ის ძე.

// იცოდე ვისი გორისა ხარ

$giorgiPirveli = 0;

list($n,$x,$y) = explode(" ",trim(fgets(STDIN)));

$aga = explode("*",trim(fgets(STDIN)));

for($i = 0; $i < count($aga); $i++){
    if(count($aga[$i])){

        $k = strlen($aga[$i]);
        if($x < $y ){
            $g = $y;
            $y = $x;
            $x = $g;
        }

       // echo $x." ".$y."\n";

        $didi = $k - intval($k/2);
        $patara = intval($k/2);

        if($x>$didi){
            $x-=$didi;
            $giorgiPirveli+=$didi;
        }
        else{
            $giorgiPirveli+=$x;
            $x = 0;
        }

        if($y > $patara){
            $y-=$patara;
            $giorgiPirveli+=$patara;
        }
        else{
            $giorgiPirveli+=$y;
            $y=0;
        }

    }
}

echo $giorgiPirveli;
?>

<?php
$strings = [];

if (true) {
    $strings[0] = explode(' ', fgets(STDIN));
    $places = str_split(substr(fgets(STDIN), 0, $strings[0][0]));

    $s = $strings[0][1];
    $p = $strings[0][2];
} else {
    $places = str_split('*...*' . PHP_EOL . PHP_EOL);
    $s = 1;
    $p = 1;
}

echo max(
    check($places, $s, $p),
    check($places, $p, $s)
);

function check($places, $s, $p) {

    $s *= 1;
    $p *= 1;

    $i = 0;
    $busy = false;
    $progs = false;
    $skip = false;

    foreach ($places as $place) {
        echo $place, PHP_EOL;
        if ($place != '.'&& $place !== '*') {
            break;
        }
        if ($place !== '.') {
            $busy = true;
            continue;
        }

        if ($busy) {
            if ($p && $s) {
                if ($p > $s) {
                    $p--;
                } else {
                    $s--;
                }

                $i++;
            } elseif ($p) {
                $p--;
                $i++;
            } elseif ($s) {
                $s--;
                $i++;
            }
        } else {
            if ($p && $progs) {
                $p--;
                $progs = !$progs;
                $i++;
            } elseif ($s) {
                $s--;
                $progs = !$progs;
                $i++;
            } elseif ($skip) {
                if ($p) {
                    $i++;
                    $p--;
                    $skip = false;
                }
                if ($s) {
                    $i++;
                    $s--;
                    $skip = false;
                }
            } else {
                $skip = true;
            }
        }

        $busy = false;

    }

    return $i;
}

<?php
$strings = [];

$strings[0] = explode(' ', fgets(STDIN));
$strings[1] = str_split(fgets(STDIN));

echo max(
    check($strings[1], $strings[0][1], $strings[0][2]),
    check($strings[1], $strings[0][2], $strings[0][1])
);

function check($places, $s, $p) {
    $i = 0;
    $busy = false;
    $progs = false;
    $skip = false;

    foreach ($places as $place) {
        if ($place != '.'&& $place !== '*') {
            break;
        }
        if ($place !== '.') {
            $busy = true;
            continue;
        }

        if ($busy) {
            if ($p && $s) {
                if ($p > $s) {
                    $p--;
                } else {
                    $s--;
                }

                $i++;
            } elseif ($p) {
                $p--;
                $i++;
            } elseif ($s) {
                $s--;
                $i++;
            }
        } else {
            if ($p && $progs) {
                $p--;
                $progs = !$progs;
                $i++;
            } elseif ($s) {
                $s--;
                $progs = !$progs;
                $i++;
            } elseif ($skip) {
                if ($p) {
                    $i++;
                    $p--;
                    $skip = false;
                }
                if ($s) {
                    $i++;
                    $s--;
                    $skip = false;
                }
            } else {
                $skip = true;
            }
        }

        $busy = false;
        echo $s, ' | ', $p, PHP_EOL;
    }

    return $i;
}

<?php
$strings = [];

if (true) {
    $strings[0] = explode(' ', fgets(STDIN));
    $places = str_split(substr(fgets(STDIN), 0, $strings[0][0]));

    $s = $strings[0][1];
    $p = $strings[0][2];
} else {
    $places = str_split('*...*' . PHP_EOL . PHP_EOL);
    $s = 1;
    $p = 1;
}

echo max(
    check($places, $s, $p),
    check($places, $p, $s)
);

function check($places, $s, $p) {

    $s *= 1;
    $p *= 1;

    $i = 0;
    $busy = false;
    $progs = false;
    $skip = false;

    foreach ($places as $place) {
        if ($place != '.'&& $place !== '*') {
            break;
        }
        if ($place !== '.') {
            $busy = true;
            continue;
        }

        if ($busy) {
            if ($p && $s) {
                if ($p > $s) {
                    $p--;
                } else {
                    $s--;
                }

                $i++;
            } elseif ($p) {
                $p--;
                $i++;
            } elseif ($s) {
                $s--;
                $i++;
            }
        } else {
            if ($p && $progs) {
                $p--;
                $progs = !$progs;
                $i++;
            } elseif ($s) {
                $s--;
                $progs = !$progs;
                $i++;
            } elseif ($skip) {
                if ($p) {
                    $i++;
                    $p--;
                    $skip = false;
                }
                if ($s) {
                    $i++;
                    $s--;
                    $skip = false;
                }
            } else {
                $skip = true;
            }
        }

        $busy = false;

    }

    return $i;
}

<?php
$strings = [];

while($f = fgets(STDIN)) {
    $strings[] = str_split($f);

    if (count($strings) > 1) {
        break;
    }
}

$i = 0;

$first = 1;
$busy = false;
$progs = false;
$skip = false;

foreach ($strings[1] as $place) {
    if ($place !== '.' && $place !== '*') {
        break;
    }
    if ($place !== '.') {
        $busy = true;
        continue;
    } else {
        $busy = false;
    }

    if ($busy) {
        if ($strings[0][2] > 0) {
            $strings[0][2]--;
            $i++;
        } elseif ($strings[0][4]) {
            $strings[0][4]--;
            $i++;
        }
    } else {
        if ($strings[0][2] && $progs) {
            $strings[0][2]--;
            $progs = !$progs;
            $i++;
        } elseif ($strings[0][4]) {
            $strings[0][4]--;
            $progs = !$progs;
            $i++;
        } else {
            $skip = true;
        }
    }
}

echo $i;

<?php
$strings = [];

$strings[0] = explode(' ', fgets(STDIN));
$strings[1] = str_split(fgets(STDIN));

echo max(
    check($strings[1], $strings[0][2], $strings[0][4]),
    check($strings[1], $strings[0][4], $strings[0][2])
);

function check($places, $s, $p) {
    $i = 0;
    $busy = false;
    $progs = false;
    $skip = false;

    foreach ($places as $place) {
        if (!$place) {
            break;
        }
        if ($place !== '.') {
            $busy = true;
            continue;
        }

        if ($busy) {
            if ($p && $s) {
                if ($p > $s) {
                    $p--;
                } else {
                    $s--;
                }

                $i++;
            } elseif ($p) {
                $p--;
                $i++;
            } elseif ($s) {
                $s--;
                $i++;
            }
        } else {
            if ($p && $progs) {
                $p--;
                $progs = !$progs;
                $i++;
            } elseif ($s) {
                $s--;
                $progs = !$progs;
                $i++;
            } elseif ($skip) {
                if ($p) {
                    $i++;
                    $p--;
                    $skip = false;
                }
                if ($s) {
                    $i++;
                    $s--;
                    $skip = false;
                }
            } else {
                $skip = true;
            }
        }

        $busy = false;
//        echo $s, ' | ', $p, PHP_EOL;
    }

    return $i;
}

<?php
$strings = [];

if (true) {
    $strings[0] = explode(' ', fgets(STDIN));
    $places = str_split(substr(fgets(STDIN), 0, $strings[0][0]));

    $s = $strings[0][1];
    $p = $strings[0][2];
} else {
    $places = str_split('*...*' . PHP_EOL . PHP_EOL);
    $s = 1;
    $p = 1;
}

echo max(
    check($places, $s, $p),
    check($places, $p, $s)
);

function check($places, $s, $p) {

    $s *= 1;
    $p *= 1;

    $i = 0;
    $busy = false;
    $progs = false;
    $skip = false;

    foreach ($places as $place) {
        if ($place != '.'&& $place !== '*') {
            break;
        }
        if ($place !== '.') {
            $busy = true;
            continue;
        }

        if ($busy) {
            if ($p && $s) {
                if ($p > $s) {
                    $p--;
                } else {
                    $s--;
                }

                $i++;
            } elseif ($p) {
                $p--;
                $i++;
            } elseif ($s) {
                $s--;
                $i++;
            }
        } else {
            if ($p && $progs) {
                $p--;
                $progs = !$progs;
                $i++;
            } elseif ($s && !$progs) {
                $s--;
                $progs = !$progs;
                $i++;
            } elseif ($skip) {
                if ($p) {
                    $i++;
                    $p--;
                    $skip = false;
                }
                if ($s) {
                    $i++;
                    $s--;
                    $skip = false;
                }
            } else {
                $skip = true;
            }
        }

        $busy = false;

    }

    return $i;
}

<?php
$strings = [];

if (true) {
    $strings[0] = explode(' ', fgets(STDIN));
    $places = str_split(substr(fgets(STDIN), 0, $strings[0][0]));

    $s = $strings[0][1];
    $p = $strings[0][2];
} else {
    $places = str_split('*...*' . PHP_EOL . PHP_EOL);
    $s = 1;
    $p = 1;
}

echo max(
    check($places, $s, $p),
    check($places, $p, $s)
);

function check($places, $s, $p) {

    $s *= 1;
    $p *= 1;

    $i = 0;
    $busy = false;
    $progs = false;
    $skip = false;

    foreach ($places as $place) {
        if ($place != '.'&& $place !== '*') {
            break;
        }
        if ($place !== '.') {
            $busy = true;
            continue;
        }

        if ($busy) {
            if ($p && $s) {
                if ($p > $s) {
                    $p--;
                } else {
                    $s--;
                }

                $i++;
            } elseif ($p) {
                $p--;
                $i++;
            } elseif ($s) {
                $s--;
                $i++;
            }
        } else {
            if ($p && $progs) {
                $p--;
                $progs = !$progs;
                $i++;
            } elseif ($s && !$progs) {
                $s--;
                $progs = !$progs;
                $i++;
            } elseif ($skip) {
                if ($p && $s) {
                    if ($p) {
                        $p--;
                    } else {
                        $s--;
                    }

                    $i++;
                }
                if ($p) {
                    $i++;
                    $p--;
                    $skip = false;
                }
                if ($s) {
                    $i++;
                    $s--;
                    $skip = false;
                }
            } else {
                $skip = true;
            }
        }

        $busy = false;

    }

    return $i;
}


<?php
	$stdin = fopen("php://stdin","r");
	$stdout = fopen("php://stdout","w");
	$n = 0;
	$b = 0;
	$cur = array();
	fscanf($stdin,"%d%d",$n,$b);
	$total = (double) ($b);
	$str = fgets($stdin);
    $cur=	explode(" ",$str);
	for ($i=0;$i!=$n;++$i)
		$total+=(double)($cur[$i]);
	$everyone = $total / (double)$n;
	for ($i=0;$i!=$n;++$i)
	{
		$added[$i] = $everyone - (double)($cur[$i]);
		if ($added[$i]<0) die("-1\n");
	}
	for ($i=0;$i!=$n;++$i)
		fprintf($stdout,"%.6lf\n",$added[$i]);
?>

<?php
function main() {
  list($n, $b) = explode(' ' , trim(fgets(STDIN)));
  $as = explode(' ' , trim(fgets(STDIN)));
  $max = max($as);
  $count = count($as);
  $avg = array_sum($as) / $count;

  $c_sum = ($max - $avg) * $count;

  if ($c_sum > $b) {
    $res = array(-1);
  }
  else {
    $extra = 0;
    if ($b > $c_sum) {
      $extra = ($b - $c_sum) / $count;
    }

    $max += $extra;

    $res = array();
    foreach ($as as $a) {
      $res[] = number_format($max - $a, 6, '.', '');
    }
  }

  return $res;
}

$res = main();
print join("\n", $res) . "\n";

<?php

error_reporting(0);
ob_end_clean();

solve();

function solve(){
	$Scanner = new Scanner("php://stdin");
	//$Scanner = new Scanner("input.txt");

	$N = (int)$Scanner->Scan();
	$B = (int)$Scanner->Scan();

	for ($i = 0; $i < $N; $i++) {
		$C_array[] = (int)$Scanner->Scan();
	}
	$temp = $C_array;
	rsort($temp);
	$max = $temp[0];
	for ($i = 0; $i < $N; $i++) {
		$diff[] = $max - $C_array[$i];
	}
	$sum = array_sum($diff);
	if ($sum > $B) print(-1);
	else {
		$add = ($B - $sum) / $N;
		for ($i = 0; $i < $N; $i++) {
			printf("%.6f", $diff[$i] + $add);
			if ($i !== $N - 1) print("\n");
		}
	}

	$Scanner->Close();
}

class Scanner{
	private $Stream;
	private $Scanners = array();
	private $Id = 0;

	public function __construct($opend){
		$this->Stream = fopen($opend, 'r');
		$contents = stream_get_contents($this->Stream);
		$contents = str_replace(array("\r\n", "\r", "\n"), " ", $contents);
		$this->Scanners = explode(" ", $contents);
	}

	public function Scan(){
		return $this->Scanners[$this->Id++];
	}

	public function Close(){
		fclose($this->Stream);
	}
}

?>

<?php

class Companions{

    private $count;

    private $volume;

    private $poured = array();

    public $result;

    public function __construct(){
        $this->init();
    }
    // init params
    private function init()
    {
        fscanf(STDIN, "%d %d", $this->count, $this->volume);
        $this->poured = explode (" ", trim(fgets(STDIN)));

    }

    public function execute()
    {
        $maxVolume = $this->volume + array_sum($this->poured);
        $dose = $maxVolume/$this->count;
        if ($dose*$this->count == $maxVolume){

            $res = array();
            $all = 0;

            foreach($this->poured as $v){
                $res[] = number_format(($dose - $v), 6, '.', '');
                $all += abs($dose-$v);
            }

            $this->result = ((int)($this->volume - $all)) ? -1 : implode("\n", $res);

        } else {
            $this->result = -1;
        }
        return $this->result;
    }

}

$test = new Companions();
echo $test->execute();

?>

<?php

class Companions{

    private $count;

    private $volume;

    private $poured = array();

    public $result;

    public function __construct(){
        $this->init();
    }
    // init params
    private function init()
    {
        fscanf(STDIN, "%d %d", $this->count, $this->volume);
        $this->poured = explode (" ", trim(fgets(STDIN)));
    }

    public function execute()
    {
        $maxVolume = $this->volume + array_sum($this->poured);
        $dose = $maxVolume/$this->count;
        if ($dose*$this->count == $maxVolume){
            $res = array();
            foreach($this->poured as $k => $v){
                $res[] = number_format(($dose - $v), 6, '.', '');
            }
            $this->result = implode("\n", $res);
        } else {
            $this->result = -1;
        }
        return $this->result;
    }

}

$test = new Companions();

echo $test->execute();

?>

<?php

class Companions{

    private $count;

    private $volume;

    private $poured = array();

    public $result;

    public function __construct(){
        $this->init();
    }
    // init params
    private function init()
    {
        fscanf(STDIN, "%d %d", $this->count, $this->volume);
        $this->poured = explode (" ", trim(fgets(STDIN)));
    }

    public function execute()
    {
        $maxVolume = $this->volume + array_sum($this->poured);
        $dose = $maxVolume/$this->count;
        if (is_int($dose)){
            $res = array();
            foreach($this->poured as $k => $v){
                $res[] = number_format(($dose - $v), 6, '.', '');
            }
            $this->result = implode("\n", $res);
        } else {
            $this->result = -1;
        }
        return $this->result;
    }

}

$test = new Companions();

echo $test->execute();

?>

<?php

class Companions{

    private $count;

    private $volume;

    private $poured = array();

    public $result;

    public function __construct(){
        $this->init();
    }
    // init params
    private function init()
    {
        fscanf(STDIN, "%d %d", $this->count, $this->volume);
        $this->poured = explode (" ", trim(fgets(STDIN)));
    }

    public function execute()
    {
        $maxVolume = $this->volume + array_sum($this->poured);
        $dose = $maxVolume/$this->count;
        if ($dose*$this->count == $maxVolume and $this->volume > $dose){
            $res = array();
            foreach($this->poured as $k => $v){
                $res[] = number_format(($dose - $v), 6, '.', '');
            }
            $this->result = implode("\n", $res);
        } else {
            $this->result = -1;
        }
        return $this->result;
    }

}

$test = new Companions();
echo $test->execute();

?>

<?php

class Companions{

    private $count;

    private $volume;

    private $poured = array();

    public $result;

    public function __construct(){
        $this->init();
    }
    // init params
    private function init()
    {
        fscanf(STDIN, "%d %d", $this->count, $this->volume);
        $this->poured = explode (" ", trim(fgets(STDIN)));

    }

    public function execute()
    {
        $maxVolume = $this->volume + array_sum($this->poured);
        $dose = $maxVolume/$this->count;
        if ($dose*$this->count == $maxVolume and $this->volume >= $dose){
            $res = array();
            foreach($this->poured as $k => $v){
                $res[] = number_format(($dose - $v), 6, '.', '');
            }
            $this->result = implode("\n", $res);
        } else {
            $this->result = -1;
        }
        return $this->result;
    }

}

$test = new Companions();
echo $test->execute();

?>

<?php

class Companions{

    private $count;

    private $volume;

    private $poured = array();

    public $result;

    public function __construct(){
        $this->init();
    }
    // init params
    private function init()
    {
        fscanf(STDIN, "%d %d", $this->count, $this->volume);
        $this->poured = explode (" ", trim(fgets(STDIN)));

    }

    public function execute()
    {
        $maxVolume = $this->volume + array_sum($this->poured);
        $dose = $maxVolume/$this->count;
        if ($dose*$this->count == $maxVolume){
            $res = array();
            $all = 0;

            foreach($this->poured as $v){
                $res[] = number_format(($dose - $v), 6, '.', '');
                $all += abs($dose-$v);
            }
            $this->result = ($this->volume - $all) ? -1 : implode("\n", $res);

        } else {
            $this->result = -1;
        }
        return $this->result;
    }

}

$test = new Companions();
echo $test->execute();

?>

<?php

class Companions{

    private $count;

    private $volume;

    private $poured = array();

    public $result;

    public function __construct(){
        $this->init();
    }
    // init params
    private function init()
    {
        fscanf(STDIN, "%d %d", $this->count, $this->volume);
        $this->poured = explode (" ", trim(fgets(STDIN)));
    }

    public function execute()
    {
        $maxVolume = $this->volume + array_sum($this->poured);
        $dose = $maxVolume/$this->count;
        if (($dose*$this->count == $maxVolume) and ($dose <= $this->volume)){
            $res = array();
            foreach($this->poured as $k => $v){
                $res[] = number_format(($dose - $v), 6, '.', '');
            }
            $this->result = implode("\n", $res);
        } else {
            $this->result = -1;
        }
        return $this->result;
    }

}

$test = new Companions();

echo $test->execute();

?>

<?php
	$stdin = fopen("php://stdin","r");
	$stdout = fopen("php://stdout","w");
	$n = 0;
	$b = 0;
	$cur = array();
	fscanf($stdin,"%d%d",$n,$b);
	$total = (double) ($b);
	$str = fgets($stdin);
    $cur=	explode(" ",$str);
	for ($i=0;$i!=$n;++$i)
		$total+=(double)($cur[$i]);
	$everyone = $total / (double)$n;
	for ($i=0;$i!=$n;++$i)
	{
		$added[$i] = $everyone - (double)($cur[$i]);
		if ($added[$i]<0) die("-1\n");
	}
	for ($i=0;$i!=$n;++$i)
		fprintf($stdout,"%.2lf\n",$added[$i]);
?>

<?php
	$stdin = fopen("php://stdin","r");
	$stdout = fopen("php://stdout","w");
	$n = 0;
	$b = 0;
	$cur = array();
	fscanf($stdin,"%d",$n);
	fscanf($stdin,"%d",$b);
	$total = (double) ($b);
	for ($i=1;$i<=$n;++$i)
	{
		fscanf($stdin,"%d",$cur[$i]);
		$total+=(double)($cur[$i]);
	}
	$everyone = $total / (double)$n;
	for ($i=1;$i<=$n;++$i)
	{
		$added[$i] = $everyone - (double)($cur[$i]);
		if ($added[$i]<0) die("-1\n");
	}
	for ($i=1;$i<=$n;++$i)
		fprintf($stdout,"%.2lf\n",$added[$i]);
?>

<?php
	$stdin = fopen("php://stdin","r");
	$stdout = fopen("php://stdout","w");
	$n = 0;
	$b = 0;
	$cur = array();
	$str = fgets($stdin,2147483648);
	list($n,$b) = explode(" ",$str);
	$total = (double) ($b);
	$str = fgets($stdin,2147483648);
    $cur=	explode(" ",$str);
	for ($i=1;$i<=$n;++$i)
		$total+=(double)($cur[$i]);
	$everyone = $total / (double)$n;
	for ($i=1;$i<=$n;++$i)
	{
		$added[$i] = $everyone - (double)($cur[$i]);
		if ($added[$i]<0) die("-1\n");
	}
	for ($i=1;$i<=$n;++$i)
		fprintf($stdout,"%.2lf\n",$added[$i]);
?>


<?php
//$file = fopen('input.in', 'r');
$file = STDIN;
$n = trim(fgets($file));
$n *= 2;
$aArray = array();
for ($i = 2; $i <= $n; $i++) {
    $tArray = explode(" ", trim(fgets($file)));
    foreach ($tArray as $index => $value) {
        $aArray[$value] = array($i, $index + 1);
    }
}
krsort($aArray);

$result = array();
foreach ($aArray as $value => $c) {
    if (!isset($result[$c[0]]) && !isset($result[$c[1]])) {
        $result[$c[0]] = $c[1];
        $result[$c[1]] = $c[0];
    }
    if (count($result) == $n) {
        break;
    }
}
for ($i = 1; $i <= $n; $i++) {
    echo $result[$i] . " ";
}


<?php
/*****************************************/
class InputReader {protected $_fh;public function __construct($fileHandler = STDIN){$this->_fh = $fileHandler;}
	public function readInt() {$d = trim(fgets($this->_fh));return (int)$d;}
	public function readArrayOfInt($size, $indexFrom = 0) {$a = [];$ind = $indexFrom;foreach (explode(' ', fgets($this->_fh)) as $item) {$a[$ind++] = (int)$item;}return $a;}
	public function readArrayOfFloat($size, $indexFrom = 0) {$a = [];$ind = $indexFrom;foreach (explode(' ', fgets($this->_fh)) as $item) {$a[$ind++] = (float)$item;}return $a;}
	public function readArrayOfString($size, $indexFrom = 0) {$a = [];$ind = $indexFrom;foreach (explode(' ', fgets($this->_fh)) as $item) {$a[$ind++] = $item;}return $a;}
}

/* Perform action N times. Can return values in array */
function ntimes($n, $func, $returnResults = false) {$a = [];for ($i=1; $i<=$n; $i++) {$result = $func();if ($returnResults) {$a[$i] = $result;}}return $a;}

/* Integral. Keys preserved. By reference. */
function cumsum(&$a){$sum = 0;foreach($a as $k=>$v) {$a[$k] += $sum;$sum = $a[$k];}}

/* Difference. Keys preserved. By reference. */
function diff(&$a){$prev = 0;foreach($a as $k=>$v) {$buf=$a[$k];$a[$k]-=$prev;$prev = $buf;}}

function bitCount($n){$cnt = 0;for ($j=$n; $j; $j>>=1){$cnt += $j&1;}return $cnt;}
/*****************************************/

$ir = new InputReader();

/* TASK */

$tc = $ir->readInt();

$possibles = $ir->readArrayOfInt(0);
unset($possibles[0]);

if (count($possibles) > 1) {
	for ($i=2; $i<=$tc; $i++) {
		$ps = $ir->readArrayOfInt(0);
		unset($ps[0]);

		$possibles = array_intersect($possibles, $ps);
	}
}

echo implode(' ', $possibles);

<?php
const maxosts = 101;
$nall = intval(readline());
$res = array_fill(0, maxosts, 0);
for($i = 0; $i < $nall; $i++)
{
	$osts = explode(" ", readline());
	$nost = intval(array_shift($osts));
	for($j = 0; $j < $nost; $j++)
			$res[$osts[$j]]++;
}
for($i = 0; $i < maxosts; $i++)
	if($res[$i] == $nall)
		echo $i . " ";
?>

<?php
$a = trim(fgets(STDIN));
$b = array_splice(explode(" ", trim(fgets(STDIN))), 1);
for($x = 1; $x < $a; $x++)
{
     $c = array_splice(explode(" ", trim(fgets(STDIN))), 1);
     $b = array_intersect($b, $c);
}
sort($b);
print implode(" ", $b);
?>

<?php
$nall = intval(readline());
for($i = 0; $i < $nall; $i++)
{
	$osts = explode(" ", readline());
	$nost = intval(array_shift($osts));
	$new = array();
	if(empty($last))
		$new = $osts;
	else
		for($j = 0; $j < $nost; $j++)
			for($g = 0; $g < count($last); $g++)
				if($osts[$j] == $last[$g])
					$new[] = $last[$g];
	$last = $new;
}
for($i = 0; $i < count($last); $i++)
	echo $last[$i] . " ";
?>

<?php
$nall = intval(readline());
$res = array();
for($i = 0; $i < $nall; $i++)
{
	$osts = explode(" ", readline());
	$nost = intval(array_shift($osts));
	for($j = 0; $j < $nost; $j++)
	{
		if(empty($res[$osts[$j]]))
			$res[$osts[$j]] = 1;
		else
			$res[$osts[$j]]++;
	}
}
for($i = 0; $i < count($res); $i++)
	if(!empty($res[$i]) &&
	$res[$i] == $nall)
		echo $i . " ";
?>

<?php
$nall = intval(readline());
for($i = 0; $i < $nall; $i++)
{
	$osts = explode(" ", readline());
	$nost = intval(array_shift($osts));
	if(empty($last))
	{
		$last = $osts;
	}
	else
		$last = array_intersect($last, $osts);
}
for($i = 0; $i <= ($arrcount = (count($last) - 1)); $i++)
{
	echo $last[$i];
	if($i != $arrcount)
		echo " ";
}
?>


<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = array_slice($c, $b - 1);
$e = array_unique($d);
if(count(array_unique($c)) == 1)
{
    print "0";
}
else
{
    if(count($e) != 1)
    {
        print "-1";
    }
    else
    {
        for($x = $b - 1; $x > 0; $x--)
        {
            if($c[$x] != $c[$b - 1])
            {
                $g = $x;
                break;
            }
        }
        $f = array_slice($c, 0, $x + 1);
        print count($f);
    }
}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = 0;
$e = $b - 1;
$f = array_unique($c);
for($x = 0; $x < $a; $x++)
{
    array_push($c, $c[$e]);
    $c = array_slice($c, 1);
    $e = array_unique($c);
    if(count($e) == 1)
    {
        $d = $x + 1;
        break;
    }
}
if(count($f) == 1)
{
    print "0";
}
elseif($d == 0)
{
    print "-1";
}
else
{
    print $d;
}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = array_slice($c, $b - 1);
$e = array_unique($d);
if(count(array_unique($c)) == 1)
{
    print "0";
}
else
{
    if(count($e) != 1)
    {
        print "-1";
    }
    else
    {
        $f = array_slice($c, 0, $b - 1);
        print count($f);
    }
}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = 0;
for($x = 0; $x < $a; $x++)
{
    array_push($c, $c[$b - 1]);
    $c = array_slice($c, 1);
    $e = array_unique($c);
    if(count($e) == 1)
    {
        $d = 1;
        break;
    }
}
if($d == 0)
{
    print "-1";
}
else
{
    print $x + 1;
}
?>

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = 0;
$e = $b - 1;
$f = array_unique($c);
for($x = 0; $x < $a; $x++)
{
    array_push($c, $c[$g]);
    $c = array_slice($c, 1);
    $e = array_unique($c);
    if(count($e) == 1)
    {
        $d = $x + 1;
        break;
    }
}
if(count($f) == 1)
{
    print "0";
}
elseif($d == 0)
{
    print "-1";
}
else
{
    print $d;
}
?>


<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = array();
$e = array();
for($x = $a - 1; $x >= 0; $x--)
{
    $d[$c[$x]]++;
    $e[$x] = count($d);
}
$e = array_reverse($e);
for($x = 0; $x < $b; $x++)
{
    $f = trim(fgets(STDIN));
    print $e[$f - 1] . "\n";
}
$f = trim(fgets(STDIN));
print $e[$f - 1];
?>

<?php
$l=$n=$m=0;
$distinct=$visited=[];
$count=0;

fscanf(STDIN,"%d %d",$n,$m);
$arr=explode(' ',trim(fgets(STDIN)));

for ($i=$n-1;$i>=0;$i--){
    if(!isset($visited[$arr[$i]]))
        {
            $visited[$arr[$i]]=$count++;
        }
    $distinct[$i]=$count;
}

for($i=0;$i<$m;$i++){
    fscanf(STDIN,"%d",$l);
    echo $distinct[$l-1]."\n";
}

<?php
list($a, $b) = explode(" ", trim(fgets(STDIN)));
$c = explode(" ", trim(fgets(STDIN)));
$d = array_reverse($c);
$e = array_unique($d);
$f = 0;
$g = array();
for($x = 0; $x < $b; $x++)
{
    if($e[$x] != "")
    {
        $f++;
        array_unshift($g, $f);
    }
    else
    {
        array_unshift($g, $f);
    }
}
for($x = 0; $x < $b - 1; $x++)
{
    $h = trim(fgets(STDIN));
    print $g[$h - 1] . "\n";
}
$h = trim(fgets(STDIN));
print $g[$h - 1];
?>

<?php
$l=$n=$m=0;
$distinct=$visited=[];
$count=0;

fscanf(STDIN,"%d %d",$n,$m);
$arr=explode(" ",fgets(STDIN));

for ($i=$n-1;$i>=0;$i--){
    if(!isset($visited[$arr[$i]]))
        $visited[$arr[$i]]=$count++;
    $distinct[$i]=$count;
}

for($i=0;$i<$m;$i++){
    fscanf(STDIN,"%d",$l);
    echo $distinct[$l-1]."\n";
}