In the popular spreadsheets systems (for example, in Excel) the following numeration of columns is used. The first column has number A, the second — number B, etc. till column 26 that is marked by Z. Then there are two-letter numbers: column 27 has number AA, 28 — AB, column 52 is marked by AZ. After ZZ there follow three-letter numbers, etc.The rows are marked by integer numbers starting with 1. The cell name is the concatenation of the column and the row numbers. For example, BC23 is the name for the cell that is in column 55, row 23. Sometimes another numeration system is used: RXCY, where X and Y are integer numbers, showing the column and the row numbers respectfully. For instance, R23C55 is the cell from the previous example.Your task is to write a program that reads the given sequence of cell coordinates and produce each item written according to the rules of another numeration system.

The first line of the input contains integer number n (1 ≤ n ≤ 105), the number of coordinates in the test. Then there follow n lines, each of them contains coordinates. All the coordinates are correct, there are no cells with the column and/or the row numbers larger than 106 .

Write n lines, each line should contain a cell coordinates in the other numeration system.

use strict;
use warnings;

use 5.012;

my $num_inputs = <>;
my @inputs;

for ( 1 .. $num_inputs ) {
  my $input = <>;
  chomp $input;
  if ( $input =~ /\AR(\d+)C(\d+)\z/ ) {
    printf "%s%s\n", row_num_to_letter($2), $1;
  }
  else {
    $input =~ /\A([A-Z]+)(\d+)\z/;
    printf "R%sC%s\n", $2, row_letter_to_num( $1 );
  }
}

sub row_num_to_letter {
  my ( $num ) = @_;
  my $str = '';
  while ( $num > 0 ) {
    if ( my $left = $num % 26 ) {
      $str = chr( $left + 64 ) . $str;
      $num = int( $num / 26 );
    } else {
      $str = 'Z' . $str;
      $num = int( $num / 26 ) - 1;
    }
  }
  return $str;
}

sub row_letter_to_num {
  my ( @letters ) = split //,  $_[0];
  my $num = 0;
  my $scale = 0;
  while ( @letters ) {
    my $letter = pop(@letters);
    my $nvalue = ord($letter) - 64;
    $num = $num + ( $nvalue * ( 26 ** $scale ) );
    $scale ++;
  }
  return $num;
}

#!/usr/bin/perl

use strict;
use warnings;

my $n = <STDIN>;
chomp $n;

while ($n--) {
    my $line = <STDIN>;
    chomp $line;
    print trans($line), "\n";
}

sub trans
{
    my $x = shift @_;
    my $res = "";

    if ($x =~ m/R(\d+)C(\d+)/) {
        my $r = $1;
        my $c = $2;

#        print "$r $c\n";
        while ($c > 0) {
            $res = chr(ord('A') + ($c + 25)%26).$res;
            if ($c % 26) {
                $c = int($c/26);
            } else {
                $c = $c/26 - 1;
            }
        }
        $res .= $r;
    } else {
        $x =~ m/([A-Z]+)(\d+)/;
        my $r = $2;

#        print "$1 $2\n";
        my $c = 0;
        my $pow = 0;
        my $len = length($1);
        foreach (split "", $1) {
#            print "$_\n";
            $pow += 1;
            $c += (ord($_) - ord('A') + 1)*(26**($len-$pow));
#            print "$len $pow $_ $c\n";
        }

        $res = "R".$r."C".$c;
    }

    return $res;
}

sub RC_to_CR {
	my $rc = shift;
	$rc =~ /^R(\d+)C(\d+)/;
	my $row = $1;
	my $col = $2;
	my $ret = '';
#	my $p = 1;
#	print "col = $col\n";
	while($col > 26) {
		my $tmp = int($col / 26);
		my $v = $col - $tmp * 26;
#		print "col = $col, p = $p, tmp = $tmp, v = $v\n";
		if($v==0) { $v = 26; $col -= 26; }
		$ret .= chr(64+$v);
		$col = int($col/26);
#		$p++;
	}
	$ret .= chr(64+$col);
	$ret = scalar reverse $ret;
	$ret .= $row;
	return $ret;
}

sub CR_to_RC {
	my $cr = shift;
	$cr =~ /([A-Z]+)(\d+)/;
	my $col = $1;
	my $row = $2;
	my $ret = 'R'.$row."C";
	my $l = length($col)-1;
	my $c = 0;
	my $p = $l;
	foreach my $ltr (split //, $col) {
		my $v = (ord($ltr)-64);
		$c += ($v * 26**$p);
		$p--;
	}
	$ret .= $c;
	return $ret;
}

my $num = <STDIN>;
chomp($num);
while($num-- > 0) {
	chomp($row = <STDIN>);
	if($row =~ /^R\d+C\d+/) {
		print RC_to_CR($row)."\n";
	} else {
		print CR_to_RC($row)."\n";
	}
}

#!usr/bin/perl
use warnings;
no warnings 'recursion';
use strict;

sub ltn{
    my @k=split//,shift;my $ln=shift;
    if(@k==1){return $$ln{$k[0]};}
    else{
	my $h=pop @k;my $f=join "",@k;
	return ($$ln{$h}+26*ltn($f,$ln));
    }
}
sub ntl{
    my $t=shift;my $ln=shift;
    if($t>26){return ((($t%26==0)?ntl(int($t/26-1),$ln):ntl(int($t/26),$ln)).$$ln{$t%26});}
    else{return $$ln{$t%26};}
}

my $row_n;my %ln;$ln{0}="Z";$ln{"Z"}=26;my $l="A";
for my $j(1..25){
    $ln{$j}=$l;
    $ln{$l}=$j;
    ++$l;
}my $g=\%ln;
my $n=<STDIN>;
my @final_list;
foreach my $i (1..$n){
    my $sr=<STDIN>;
    chomp($sr);
    if($sr=~/^R([0-9]+)C([0-9]+)$/){
	my $p=($2>26)?ntl($2,$g):$ln{$2%26};
	push @final_list,"$p"."$1\n";
    }
    elsif($sr=~/([A-Z]+)([0-9]+)/){
	my $col=ltn($1,$g);
	$row_n=$2;
	push @final_list,"R$row_n"."C$col\n";
    }
}
print @final_list;

#!/usr/bin/perl

%num2char = map { ($_ + 1) => chr(ord('A') + $_) } (0..25) ;
%char2num = reverse %num2char;

#map { print "$_ $num2char{$_}\n" } sort { $a <=> $b } keys %num2char;
#map { print "$_ $char2num{$_}\n" } sort keys %char2num;

$n = <>;

for (1..$n) {
    $input = <>;
    if ($input =~ /^R(\d+)C(\d+)$/) {
        $row = $1;
        $col = $2;
        $new_char = undef;
        while ($col > 0) {
            $new_char = ($col % 26 == 0 ? $num2char{26} : $num2char{$col % 26}) . $new_char;
            if ($col % 26 == 0) { $col--; }
            $col = int($col / 26);
        }
        $col = $new_char;
        print "$col$row\n";
    }
    elsif ($input =~ /^([A-Z]+)(\d+)$/) {
        $row = $2;
        $col = $1;
        $count = 0;
        $sum = 0;
        for $c (reverse split //,$col) {
            $sum += (26 ** $count++) * $char2num{$c};
        }
        $col = $sum;
        print "R$row" . "C$col\n";
    }
}

use strict;
use warnings;

my $totalNum =  <STDIN>;

my @inputs;
for(my $i = 0; $i < $totalNum; $i++){
    my $input = <STDIN>;
    push @inputs, $input;
}

foreach my $input (@inputs){
#    print $input . "\n";
    if ( $input =~ /^R([0-9]+)C([0-9]+)$/){
        print convert26($2) . "$1" . "\n";
    }
    if ($input =~ /^([A-Z]+)(\d+)$/ ){
        print "R$2" . "C" . iconvert26($1) . "\n";
    }
}

#
#foreach my $i (1..250){
#    print convert26($i), " ";
#}
#
#print "\n";
#

#foreach my $i ('AA'..'AZ'){
#    print iconvert26($i), "  ";
#}

#===================================================================
sub convert26
{
	my ($input) = @_;
	my $base = 26;
	my @elements = ( 'A'..'Z');
	my @ret=();
	do{
	    unshift @ret, $elements[($input)%$base -1];
	    $input = int(($input-1) /$base);
	}while($input);
	return join('', @ret);
}

sub iconvert26
{
    my ($input) = @_;
    my $base = 26;
    my @elements = ('', 'A'..'Z');
    my @inputs = reverse (split("", $input));
    my $ret = 0;
    my $pos = 0;
    foreach my $in (@inputs){
        my $index = 0;
        foreach my $elem (@elements){

            if($elem eq $in){
                last;
            }
            $index ++;
        }
        $ret += $index  * $base ** $pos;
        $index = 0;
        $pos++;
    }
    return $ret;
}

#!/usr/local/bin/perl
$n = <>;
for ( 1 .. $n ) {
    $line = <>;

    if ( $line =~ /(\D+)(\d+)(\D+)(\d+)/ ) {
        print makeNormal($2,$4)."\n";

    }
    elsif($line =~ /(\D+)(\d+)/ ){
        print makeRC($1 , $2)."\n";
    }

}
    sub makeNormal {
        use integer;
        my $row = $_[0];
        my $col = $_[1];
        my @alph = (A..Z);

        $result = $row;
        do{
            my $r, $letter;
            $col -= 1;
            $r = $col % 26;
            $col = $col / 26;
            $result = @alph[$r].$result;
        } while ($col);
        return $result;
    }

    sub makeRC {
        use integer;
        my $row = $_[1];
        my $col = $_[0];
        my $resCol = 0;
        my $n = 1;
        my $A = ord("A");
        foreach $ch (reverse split (// , $col)){
            $resCol+= (ord($ch) - $A +1) * $n;
            $n *= 26;
        }
        return "R".$row."C".$resCol;

    }

my $num = <STDIN>;
for (1..$num) {
    my $input = <STDIN>;
    chomp $input;
    if ($input =~ /R(\d+)C(\d+)/) {
        my ($row, $col) = ($1, $2);
        my @col;
        while ($col > 26) {
            my $r = $col % 26;
            $r = 26 if !$r;
            push @col, $r;
            $col = int (($col-$r)/26);
        }
        push @col, $col;
        @col = reverse @col;
        my $str;
        $str .= ('A'..'Z')[$_-1] foreach @col;
        $str .= $row;
        print $str, "\n";
    } else {
        $input =~ /([A-Z]+)(\d+)/;
        my ($col_str, $row) = ($1, $2);
        my $col = 0;
        foreach (map { ord($_) - 64 } split //, $col_str) {
            $col *= 26;
            $col += $_;
        }
        print "R", $row, "C", $col, "\n";
    }
}

#!/usr/bin/perl

main();

sub main {
    my $n = int <>;
    for(1..$n) {
        my $line = <>;
        if ($line =~ /(\D+)(\d+)(\D+)(\d+)/) {
            print convertToSymbols($4)."$2\n";
            next;
        }
        if ($line =~ /(\D+)(\d+)/) {
            print "R".$2."C".convertFromSymbols($1)."\n";
        }
    }
}

sub convertToSymbols {
    my $cur = shift;
    my $result = "";
    while ($cur > 0) {
        my $tmp = $cur % 26;
        $tmp = 26 if ($tmp==0);
        my $c = chr(ord("A") + $tmp - 1);
        $result = $result.$c;
        $cur = ($cur - $tmp) / 26;
    }
    return reverse $result;
}

sub convertFromSymbols {
    my $s = shift;
    my @arr = split //, $s;
    my $result = 0;
    foreach(@arr) {
        $result = $result * 26 + ord($_) - ord("A") + 1;
    }
    return $result;
}

use strict;
use warnings;

use 5.012;

my $num_inputs = <>;
my @inputs;

for ( 1 .. $num_inputs ) {
  my $input = <>;
  chomp $input;
  if ( $input =~ /\AR(\d+)C(\d+)\z/ ) {
    printf "%s%s\n", row_num_to_letter($2), $1;
  }
  else {
    $input =~ /\A([A-Z]+)(\d+)\z/;
    printf "R%sC%s\n", $2, row_letter_to_num( $1 );
  }
}

sub row_num_to_letter {
  my ( $num ) = @_;
  my $str = '';
  while ( $num > 26 ) {
    my $left = $num % 26;
    $str = chr( $left + 64 ) . $str;
    $num = int( $num / 26 );
  }
  return chr( $num + 64 ) . $str;
}
sub row_letter_to_num {
  my ( @letters ) = split //,  $_[0];
  my $num = 0;
  my $scale = 0;
  while ( @letters ) {
    my $letter = pop(@letters);
    my $nvalue = ord($letter) - 64;
    $num = $num + ( $nvalue * ( 26 ** $scale ) );
    $scale ++;
  }
  return $num;
}

#!/usr/bin/perl

use strict;
use warnings;

my $n = <STDIN>;
chomp $n;

while ($n--) {
    my $line = <STDIN>;
    chomp $line;
    print trans($line), "\n";
}

sub trans
{
    my $x = shift @_;
    my $res = "";

    if ($x =~ m/R(\d+)C(\d+)/) {
        my $r = $1;
        my $c = $2;

#        print "$r $c\n";
        while ($c > 0) {
            $res = chr(ord('A') - 1 + $c%26).$res;
            $c = int($c/26);
#            $c -= 1;
        }
        $res .= $r;
    } else {
        $x =~ m/([A-Z]+)(\d+)/;
        my $r = $2;

#        print "$1 $2\n";
        my $c = 0;
        my $pow = 0;
        my $len = length($1);
        foreach (split "", $1) {
#            print "$_\n";
            $pow += 1;
            $c += (ord($_) - ord('A') + 1)*(26**($len-$pow));
#            print "$len $pow $_ $c\n";
        }

        $res = "R".$r."C".$c;
    }

    return $res;
}

#!/usr/bin/perl

use strict;
use warnings;

my $n = <STDIN>;
chomp $n;

while ($n--) {
    my $line = <STDIN>;
    chomp $line;
    print trans($line), "\n";
}

sub trans
{
    my $x = shift @_;
    my $res = "";

    if ($x =~ m/R(\d+)C(\d+)/) {
        my $r = $1;
        my $c = $2;

#        print "$r $c\n";
        $c -= 1;
        while ($c > 0) {
            $res = chr(ord('A') + $c%26).$res;
            $c = int($c/26);
            $c -= 1;
        }
        $res .= $r;
    } else {
        $x =~ m/([A-Z]+)(\d+)/;
        my $r = $2;

#        print "$1 $2\n";
        my $c = 0;
        my $pow = 0;
        my $len = length($1);
        foreach (split "", $1) {
#            print "$_\n";
            $pow += 1;
            $c += (ord($_) - ord('A') + 1)*(26**($len-$pow));
#            print "$len $pow $_ $c\n";
        }

        $res = "R".$r."C".$c;
    }

    return $res;
}

#!/usr/bin/perl

use strict;
use warnings;

my $n = <STDIN>;
chomp $n;

while ($n--) {
    my $line = <STDIN>;
    chomp $line;
    print trans($line), "\n";
}

sub trans
{
    my $x = shift @_;
    my $res = "";

    if ($x =~ m/R(\d+)C(\d+)/) {
        my $r = $1;
        my $c = $2;

#        print "$r $c\n";
        $c -= 1;
        while ($c > 0) {
            $res = chr(ord('A') + $c%26).$res;
            $c = int($c/26);
            $c -= 1;
        }
        $res .= $r;
    } else {
        $x =~ m/([A-Z]+)(\d+)/;
        my $r = $2;

#        print "$1 $2\n";
        my $c = 0;
        foreach (split "", $1) {
#            print "$_\n";
            $c *= 26;
            $c += ord($_) - ord('A') + 1;
        }

        $res = "R".$r."C".$c;
    }

    return $res;
}

#!/usr/bin/perl

use strict;
use warnings;

my $n = <STDIN>;
chomp $n;

while ($n--) {
    my $line = <STDIN>;
    chomp $line;
    print trans($line), "\n";
}

sub trans
{
    my $x = shift @_;
    my $res = "";

    if ($x =~ m/R(\d+)C(\d+)/) {
        my $r = $1;
        my $c = $2;

#        print "$r $c\n";
        $c -= 1;
        while ($c > 0) {
            $res = chr(ord('A') + $c%26).$res;
            $c = int($c/26);
            $c -= 1;
        }
        $res .= $r;
    } else {
        $x =~ m/([A-Z]+)(\d+)/;
        my $r = $2;

#        print "$1 $2\n";
        my $c = 0;
        foreach (split "", $1) {
            print "$_\n";
            $c *= 26;
            $c += ord($_) - ord('A') + 1;
        }

        $res = "R".$r."C".$c;
    }

    return $res;
}

sub RC_to_CR {
	my $rc = shift;
	$rc =~ /^R(\d+)C(\d+)/;
	my $row = $1;
	my $col = $2;
	my $ret = '';
	while($col > 26) {
		$ret .= chr(64+($col % 26));
		$col /= 26;
	}
	$ret .= chr(64+$col);
	$ret = scalar reverse $ret;
	$ret .= $row;
	return $ret;
}

sub CR_to_RC {
	my $cr = shift;
	$cr =~ /([A-Z]+)(\d+)/;
	my $col = $1;
	my $row = $2;
	my $ret = 'R'.$row."C";
	my $p = length($col)-1;
	my $c = 0;
	foreach my $ltr (split //, $col) {
		my $v = (ord($ltr)-64);
		$c += ($v * 26**$p);
		$p--;
	}
	$ret .= $c;
	return $ret;
}

my $num = <STDIN>;
chomp($num);
while($num-- > 0) {
	chomp($row = <STDIN>);
	if($row =~ /^R\d+C\d+/) {
		print RC_to_CR($row)."\n";
	} else {
		print CR_to_RC($row)."\n";
	}
}

sub RC_to_CR {
	my $rc = shift;
	$rc =~ /^R(\d+)C(\d+)/;
	my $row = $1;
	my $col = $2;
	my $ret = '';
	my $p = 1;
	while($col > 26) {
		if($col % 26**$p == 0) {
			$ret .= "Z";
			$col -= 26**$p;
		} else {
			my $tmp = int($col / 26);
#		$tmp = 1 if($tmp == 0);
			my $v = $col - $tmp * 26;
#			print "Got $v, it turns into ".chr(64+$v)."\n";
			$ret .= chr(64+$v);
		}
		$col = int($col/26);
		$p++;
	}

	$ret .= chr(64+$col);
	$ret = scalar reverse $ret;
	$ret .= $row;
	return $ret;
}

sub CR_to_RC {
	my $cr = shift;
	$cr =~ /([A-Z]+)(\d+)/;
	my $col = $1;
	my $row = $2;
	my $ret = 'R'.$row."C";
	my $l = length($col)-1;
	my $c = 0;
	my $p = $l;
	foreach my $ltr (split //, $col) {
		my $v = (ord($ltr)-64);
		$c += ($v * 26**$p);
		$p--;
	}
	$ret .= $c;
	return $ret;
}

my $num = <STDIN>;
chomp($num);
while($num-- > 0) {
	chomp($row = <STDIN>);
	if($row =~ /^R\d+C\d+/) {
		print RC_to_CR($row)."\n";
	} else {
		print CR_to_RC($row)."\n";
	}
}

sub RC_to_CR {
	my $rc = shift;
	$rc =~ /^R(\d+)C(\d+)/;
	my $row = $1;
	my $col = $2;
	my $ret = '';
	while($col > 26) {
		$ret .= chr(64+($col % 26));
		$col /= 26;
	}
	$ret .= chr(64+$col);
	$ret = scalar reverse $ret;
	$ret .= $row;
	return $ret;
}

sub CR_to_RC {
	my $cr = shift;
	$cr =~ /([A-Z]+)(\d+)/;
	my $col = $1;
	my $row = $2;
	my $ret = 'R'.$row."C";
	my $l = length($col)-1;
	my $c = 0;
	for(my $p=$l;$p>=0;$p--) {
		my $ltr = substr($col,($p-$l), 1);
		my $v = (ord($ltr)-64);
		$c += ($v * 26**$p);
	}
	$ret .= $c;
	return $ret;
}

my $num = <STDIN>;
chomp($num);
while($num-- > 0) {
	chomp($row = <STDIN>);
	if($row =~ /^R\d+C\d+/) {
		print RC_to_CR($row)."\n";
	} else {
		print CR_to_RC($row)."\n";
	}
}

sub RC_to_CR {
	my $rc = shift;
	$rc =~ /^R(\d+)C(\d+)/;
	my $row = $1;
	my $col = $2;
	my $ret = '';
	my $p = 1;
	while($col > 26) {
		if($col % 26**$p == 0) {
			$ret .= "Z";
			$col /= 26;
		} else {
			my $tmp = int($col / 26);
			my $v = $col - $tmp * 26;
			$ret .= chr(64+$v);
			$col /= 26;
		}
		$p++;
	}
	$ret .= chr(64+$col);
	$ret = scalar reverse $ret;
	$ret .= $row;
	return $ret;
}

sub CR_to_RC {
	my $cr = shift;
	$cr =~ /([A-Z]+)(\d+)/;
	my $col = $1;
	my $row = $2;
	my $ret = 'R'.$row."C";
	my $l = length($col)-1;
	my $c = 0;
	my $p = $l;
	foreach my $ltr (split //, $col) {
		my $v = (ord($ltr)-64);
		$c += ($v * 26**$p);
		$p--;
	}
	$ret .= $c;
	return $ret;
}

my $num = <STDIN>;
chomp($num);
while($num-- > 0) {
	chomp($row = <STDIN>);
	if($row =~ /^R\d+C\d+/) {
		print RC_to_CR($row)."\n";
	} else {
		print CR_to_RC($row)."\n";
	}
}

sub RC_to_CR {
	my $rc = shift;
	$rc =~ /^R(\d+)C(\d+)/;
	my $row = $1;
	my $col = $2;
	my $ret = '';
	my $p = 1;
	while($col > 26) {
		if($col % 26**$p == 0) {
			$ret .= "Z";
$col -= 26**$p;
			$col /= 26;
		} else {
			my $tmp = int($col / 26);
			my $v = $col - $tmp * 26;
			$ret .= chr(64+$v);
			$col /= 26;
		}
		$p++;
	}
	$ret .= chr(64+$col);
	$ret = scalar reverse $ret;
	$ret .= $row;
	return $ret;
}

sub CR_to_RC {
	my $cr = shift;
	$cr =~ /([A-Z]+)(\d+)/;
	my $col = $1;
	my $row = $2;
	my $ret = 'R'.$row."C";
	my $l = length($col)-1;
	my $c = 0;
	my $p = $l;
	foreach my $ltr (split //, $col) {
		my $v = (ord($ltr)-64);
		$c += ($v * 26**$p);
		$p--;
	}
	$ret .= $c;
	return $ret;
}

my $num = <STDIN>;
chomp($num);
while($num-- > 0) {
	chomp($row = <STDIN>);
	if($row =~ /^R\d+C\d+/) {
		print RC_to_CR($row)."\n";
	} else {
		print CR_to_RC($row)."\n";
	}
}

#!/bin/perl -w
use strict;
use warnings;

sub ntos {
# Slow, but should be OK
    my $n = shift;
    my $s = 'A';
    for (1 .. $n - 1) { $s++; }
    return $s;
}

sub ston {
    my $s = shift;
    my %hash;
    @hash{('A'..'Z')} = (1 .. 26);
    my $n = 0;
    for (split //, $s) {
	$n *= 26;
	$n += $hash{$_};
    }
    return $n;
}

sub main {
    my $n = int <>;
    for (1 .. $n) {
	my $s = <>;
	if ($s =~ /^R([\d]*)C([\d]*)$/) {
	    print ntos($2) . "$1\n";
	} elsif ($s =~ /^([\D]*)([\d]*)$/) {
	    print "R$2C" . (ston $1) . "\n";
	} else {
	    exit(-1);
	}
    }
}

main();

#!usr/bin/perl
use warnings;
no warnings 'recursion';
use strict;

sub ltn{
    my @k=split//,shift;my $ln=shift;
    if(@k==1){return $$ln{$k[0]};}
    else{
	my $h=pop @k;my $f=join "",@k;
	return ($$ln{$h}+26*ltn($f,$ln));
    }
}
sub ntl{
    my $t=shift;my $ln=shift;
    if($t>=26){return ((($t%26==0)?ntl(int($t/26-1),$ln):ntl(int($t/26),$ln)).$$ln{$t%26});}
    else{return $$ln{$t};}
}

my $row_n;my %ln;$ln{0}="Z";$ln{"Z"}=26;my $l="A";
for my $j(1..25){
    $ln{$j}=$l;
    $ln{$l}=$j;
    ++$l;
}my $g=\%ln;
my $n=<STDIN>;
my @final_list;
foreach my $i (1..$n){
    my $sr=<STDIN>;
    chomp($sr);
    if($sr=~/^R([0-9]+)C([0-9]+)$/){
	my $p=($2>26)?ntl($2,$g):$ln{$2%26};
	push @final_list,"$p"."$1\n";
    }
    elsif($sr=~/([A-Z]+)([0-9]+)/){
	my $col=ltn($1,$g);
	$row_n=$2;
	push @final_list,"R$row_n"."C$col\n";
    }
}
print @final_list;

#!usr/bin/perl
use warnings;
no warnings 'recursion';
use strict;

sub ltn{
    my @k=split//,shift;my $ln=shift;
    if(@k==1){return $$ln{$k[0]};}
    else{
	my $h=pop @k;my $f=join "",@k;
	return ($$ln{$h}+26*ltn($f,$ln));
    }
}
sub ntl{
    my $t=shift;my $ln=shift;
    if($t==0){return "";}
    elsif($t>26){return (($t%26==0)?ntl(int($t/26-1),$ln):ntl(int($t/26)),$ln).$$ln{$t%26};}
    else{return $$ln{$t};}
}

my $row_n;my %ln;$ln{0}="Z";$ln{"Z"}=26;my $l="A";
for my $j(1..25){
    $ln{$j}=$l;
    $ln{$l}=$j;
    ++$l;
}my $g=\%ln;
my $n=<STDIN>;
my @final_list;
foreach my $i (1..$n){
    my $sr=<STDIN>;
    chomp($sr);
    if($sr=~/^R([0-9]+)C([0-9]+)$/){
	my $p=ntl($2,$g);
	push @final_list,"$p"."$1\n";
    }
    elsif($sr=~/([A-Z]+)([0-9]+)/){
	my $col=ltn($1,$g);
	$row_n=$2;
	push @final_list,"R$row_n"."C$col\n";
    }
}
print @final_list;

#!usr/bin/perl
use warnings;
no warnings 'recursion';
use strict;

sub ltn{
    my @k=split//,shift;my $ln=shift;
    if(@k==1){return $$ln{$k[0]};}
    else{
	my $h=pop @k;my $f=join "",@k;
	return ($$ln{$h}+26*ltn($f,$ln));
    }
}
sub ntl{
    my $t=shift;my $ln=shift;
    if($t==0){return "";}
    elsif($t>26){return ((($t%26==0)?ntl(int($t/26-1),$ln):ntl(int($t/26),$ln)).$$ln{$t%26});}
    else{return $$ln{$t};}
}

my $row_n;my %ln;$ln{0}="Z";$ln{"Z"}=26;my $l="A";
for my $j(1..25){
    $ln{$j}=$l;
    $ln{$l}=$j;
    ++$l;
}my $g=\%ln;
my $n=<STDIN>;
my @final_list;
foreach my $i (1..$n){
    my $sr=<STDIN>;
    chomp($sr);
    if($sr=~/^R([0-9]+)C([0-9]+)$/){
	my $p=ntl($2,$g);
	push @final_list,"$p"."$1\n";
    }
    elsif($sr=~/([A-Z]+)([0-9]+)/){
	my $col=ltn($1,$g);
	$row_n=$2;
	push @final_list,"R$row_n"."C$col\n";
    }
}
print @final_list;

#!usr/bin/perl
use warnings;
no warnings 'recursion';
use strict;

sub ltn{
    my @k=split//,shift;my $ln=shift;
    if(@k==1){return $$ln{$k[0]};}
    else{
	my $h=pop @k;my $f=join "",@k;
	return ($$ln{$h}+26*ltn($f,$ln));
    }
}
sub ntl{
    my $t=shift;my $ln=shift;
    if($t==0){return "";}
    elsif($t==1){return "A";}
    elsif($t>26){return ntl(int($t/26),$ln).$$ln{$t%26};}
    else{return $$ln{$t-1};}
}

my $row_n;my %ln;$ln{0}="Z";$ln{"Z"}=26;my $l="A";
for my $j(1..25){
    $ln{$j}=$l;
    $ln{$l}=$j;
    ++$l;
}my $g=\%ln;
my $n=<STDIN>;
my @final_list;
foreach my $i (1..$n){
    my $sr=<STDIN>;
    chomp($sr);
    if($sr=~/^R([0-9]+)C([0-9]+)$/){
	my $p=ntl($2,$g);
	push @final_list,"$p"."$1\n";
    }
    elsif($sr=~/([A-Z]+)([0-9]+)/){
	my $col=ltn($1,$g);
	$row_n=$2;
	push @final_list,"R$row_n"."C$col\n";
    }
}
print @final_list;

#!usr/bin/perl
use warnings;
no warnings 'recursion';
use strict;

sub ltn{
    my @k=split//,shift;my $ln=shift;
    if(@k==1){return $$ln{$k[0]};}
    else{
	my $h=pop @k;my $f=join "",@k;
	return ($$ln{$h}+26*ltn($f,$ln));
    }
}
sub ntl{
    my $t=shift;my $ln=shift;
    if($t==0){return "";}
    elsif($t>26){return (($t%26)?ntl(int($t/26-1),$ln):ntl(int($t/26)),$ln).$$ln{$t%26};}
    else{return $$ln{$t};}
}

my $row_n;my %ln;$ln{0}="Z";$ln{"Z"}=26;my $l="A";
for my $j(1..25){
    $ln{$j}=$l;
    $ln{$l}=$j;
    ++$l;
}my $g=\%ln;
my $n=<STDIN>;
my @final_list;
foreach my $i (1..$n){
    my $sr=<STDIN>;
    chomp($sr);
    if($sr=~/^R([0-9]+)C([0-9]+)$/){
	my $p=ntl($2,$g);
	push @final_list,"$p"."$1\n";
    }
    elsif($sr=~/([A-Z]+)([0-9]+)/){
	my $col=ltn($1,$g);
	$row_n=$2;
	push @final_list,"R$row_n"."C$col\n";
    }
}
print @final_list;

#!usr/bin/perl
use warnings;
no warnings 'recursion';
use strict;

sub ltn{
    my @k=split//,shift;my $ln=shift;
    if(@k==1){return $$ln{$k[0]};}
    else{
	my $h=pop @k;my $f=join "",@k;
	return ($$ln{$h}+26*ltn($f,$ln));
    }
}
sub ntl{
    my $t=shift;my $ln=shift;
    if($t==0){return "";}
    elsif($t>26){return ntl(int($t/26),$ln).$$ln{$t%26};}
    else{return $$ln{$t};}
}

my $row_n;my %ln;$ln{0}="Z";$ln{"Z"}=26;my $l="A";
for my $j(1..25){
    $ln{$j}=$l;
    $ln{$l}=$j;
    ++$l;
}my $g=\%ln;
my $n=<STDIN>;
my @final_list;
foreach my $i (1..$n){
    my $sr=<STDIN>;
    chomp($sr);
    if($sr=~/^R([0-9]+)C([0-9]+)$/){
	my $p=ntl($2,$g);
	push @final_list,"$p"."$1\n";
    }
    elsif($sr=~/([A-Z]+)([0-9]+)/){
	my $col=ltn($1,$g);
	$row_n=$2;
	push @final_list,"R$row_n"."C$col\n";
    }
}
print @final_list;

#!usr/bin/perl
use warnings;
no warnings 'recursion';
use strict;

sub ltn{
    my @k=split//,shift;my $ln=shift;
    if(@k==1){return $$ln{$k[0]};}
    else{
	my $h=pop @k;my $f=join "",@k;
	return ($$ln{$h}+26*ltn($f,$ln));
    }
}
sub ntl{
    my $t=shift;my $ln=shift;
    if($t>26){return ((($t%26==0)?ntl(int($t/26-1),$ln):ntl(int($t/26),$ln)).$$ln{$t%26});}
    else{return $$ln{$t};}
}

my $row_n;my %ln;$ln{0}="Z";$ln{"Z"}=26;my $l="A";
for my $j(1..25){
    $ln{$j}=$l;
    $ln{$l}=$j;
    ++$l;
}my $g=\%ln;
my $n=<STDIN>;
my @final_list;
foreach my $i (1..$n){
    my $sr=<STDIN>;
    chomp($sr);
    if($sr=~/^R([0-9]+)C([0-9]+)$/){
	my $p=($2>26)?ntl($2,$g):$ln{$2%26};
	push @final_list,"$p"."$1\n";
    }
    elsif($sr=~/([A-Z]+)([0-9]+)/){
	my $col=ltn($1,$g);
	$row_n=$2;
	push @final_list,"R$row_n"."C$col\n";
    }
}
print @final_list;

#!/usr/bin/perl

%num2char = map { ($_ + 1) => chr(ord('A') + $_) } (0..25) ;
%char2num = reverse %num2char;

#map { print "$_ $num2char{$_}\n" } sort { $a <=> $b } keys %num2char;
#map { print "$_ $char2num{$_}\n" } sort keys %char2num;

$n = <>;

for (1..$n) {
    $input = <>;
    if ($input =~ /^R(\d+)C(\d+)$/) {
        #print "Row-column to column-row\n";
        $row = $1;
        $col = $2;
        $new_char = undef;
        while ($col > 0) {
            $new_char = $num2char{$col % 26} . $new_char;
            $col = int($col / 26);
        }
        $col = $new_char;
        print "$col$row\n";
    }
    elsif ($input =~ /^([A-Z]+)(\d+)$/) {
        #print "Column-row to row-column $1, $2\n";
        $row = $2;
        $col = $1;
        $count = 0;
        $sum = 0;
        for $c (reverse split //,$col) {
            $sum += (26 ** $count++) * $char2num{$c};
        }
        $col = $sum;
        print "R$row" . "C$col\n";
    }
}

#!/usr/bin/perl

%num2char = map { ($_ + 1) => chr(ord('A') + $_) } (0..25) ;
%char2num = reverse %num2char;

#map { print "$_ $num2char{$_}\n" } sort { $a <=> $b } keys %num2char;
#map { print "$_ $char2num{$_}\n" } sort keys %char2num;

$n = <>;

for (1..$n) {
    $input = <>;
    if ($input =~ /^R(\d+)C(\d+)$/) {
        #print "Row-column to column-row\n";
        $row = $1;
        $col = $2;
        $new_char = undef;
        while ($col > 1) {
            $new_char = ($col % 26 == 0 ? $num2char{26} : $num2char{$col % 26}) . $new_char;
            $col = int($col / 26);
        }
        $col = $new_char;
        print "$col$row\n";
    }
    elsif ($input =~ /^([A-Z]+)(\d+)$/) {
        #print "Column-row to row-column $1, $2\n";
        $row = $2;
        $col = $1;
        $count = 0;
        $sum = 0;
        for $c (reverse split //,$col) {
            $sum += (26 ** $count++) * $char2num{$c};
        }
        $col = $sum;
        print "R$row" . "C$col\n";
    }
}

#!/usr/local/bin/perl
$n = <>;
for ( 1 .. $n ) {
    $line = <>;

    if ( $line =~ /(\D+)(\d+)(\D+)(\d+)/ ) {
        print makeNormal($2,$4);

    }
    elsif($line =~ /(\D+)(\d+)/ ){
        print makeRC($1 , $2);
    }

}
    sub makeNormal {
        use integer;
        my $row = $_[0];
        my $col = $_[1];
        my @alph = (A..Z);

        $result = $row;
        do{
            my $r, $letter;
            $col -= 1;
            $r = $col % 26;
            $col = $col / 26;
            $result = @alph[$r].$result;
        } while ($col);
        return $result;
    }

    sub makeRC {
        use integer;
        my $row = $_[1];
        my $col = $_[0];
        my $resCol = 0;
        my $n = 1;
        my $A = ord("A");
        foreach $ch (reverse split (// , $col)){
            $resCol+= (ord($ch) - $A +1) * $n;
            $n *= 26;
        }
        return "R".$row."C".$resCol;

    }

my $num = <STDIN>;
for (1..$num) {
    my $input = <STDIN>;
    chomp $input;
    if ($input =~ /R(\d+)C(\d+)/) {
        my ($row, $col) = ($1, $2);
        my @col;
        while ($col >= 26) {
            push @col, $col % 26;
            $col = int ($col/26);
        }
        push @col, $col;
        @col = reverse @col;
        my $str;
        $str .= ('A'..'Z')[$_-1] foreach @col;
        $str .= $row;
        print $str, "\n";
    } else {
        $input =~ /([A-Z]+)(\d+)/;
        my ($col_str, $row) = ($1, $2);
        my $col = 0;
        foreach (map { ord($_) - 64 } split //, $col_str) {
            $col *= 26;
            $col += $_;
        }
        print "R", $row, "C", $col, "\n";
    }
}

my $num = <STDIN>;
for (1..$num) {
    my $input = <STDIN>;
    chomp $input;
    if ($input =~ /R(\d+)C(\d+)/) {
        my ($row, $col) = ($1, $2);
        my @col;
        while ($col >= 26) {
            push @col, $col % 26;
            $col = int (($col-1)/26);
        }
        push @col, $col;
        @col = reverse @col;
        my $str;
        $str .= ('A'..'Z')[$_-1] foreach @col;
        $str .= $row;
        print $str, "\n";
    } else {
        $input =~ /([A-Z]+)(\d+)/;
        my ($col_str, $row) = ($1, $2);
        my $col = 0;
        foreach (map { ord($_) - 64 } split //, $col_str) {
            $col *= 26;
            $col += $_;
        }
        print "R", $row, "C", $col, "\n";
    }
}

#!/usr/bin/perl

use 5.006;
use strict;
use warnings;

main();

sub main {
    my $n = int <>;
    for(1..$n) {
        my $line = <>;
        if ($line =~ /R[0-9]+C[0-9]+/) {
            my $row = $line;
            $row =~ s/R//g;
            $row =~ s/C[0-9]+//g;
            my $col = $line;
            $col =~ s/^R[0-9]+C//g;
            print convertToSymbols($col)."$row\n";
        } else {
            my $row = $line;
            $row =~ s/[A-Z]+//g;
            my $col = $line;
            $col =~ s/[0-9]+//g;
            print "R".$row."C".convertFromSymbols($col)."\n";
        }
    }
}

sub convertToSymbols {
    my $cur = shift;
    my $result = "";
    while ($cur > 0) {
        my $c = chr(ord("A") + $cur % 26 - 1);
        $result = $result.$c;
        $cur = ($cur - $cur % 26) / 26;
    }
    return reverse $result;
}

sub convertFromSymbols {
    my $s = shift;
    my @arr = split //, $s;
    my $result = 0;
    foreach(@arr) {
        $result = $result * 26 + ord($_) - ord("A") + 1;
    }
    return $result;
}

#!/usr/bin/perl

main();

sub main {
    my $n = int <>;
    for(1..$n) {
        my $line = <>;
        if ($line =~ /(\D+)(\d+)(\D+)(\d+)/) {
            print convertToSymbols($4)."$2\n";
            next;
        }
        if ($line =~ /(\D+)(\d+)/) {
            print "R".$2."C".convertFromSymbols($1)."\n";
        }
    }
}

sub convertToSymbols {
    my $cur = shift;
    my $result = "";
    while ($cur > 0) {
        my $c = chr(ord("A") + $cur % 26 - 1);
        $result = $result.$c;
        $cur = ($cur - $cur % 26) / 26;
    }
    return reverse $result;
}

sub convertFromSymbols {
    my $s = shift;
    my @arr = split //, $s;
    my $result = 0;
    foreach(@arr) {
        $result = $result * 26 + ord($_) - ord("A") + 1;
    }
    return $result;
}

#!/usr/bin/perl

main();

sub main {
    my $n = int <>;
    for(1..$n) {
        my $line = <>;
        if ($line =~ /(\D+)(\d+)(\D+)(\d+)/) {
            print convertToSymbols($4)."$2\n";
            next;
        }
        if ($line =~ /(\D+)(\d+)/) {
            print "R".$2."C".convertFromSymbols($1)."\n";
        }
    }
}

sub convertToSymbols {
    my $cur = shift;
    my $result = "";
    while ($cur > 0) {
        my $c = chr(ord("A") + ($cur - 1) % 26);
        $result = $result.$c;
        $cur = ($cur - $cur % 26) / 26;
    }
    return reverse $result;
}

sub convertFromSymbols {
    my $s = shift;
    my @arr = split //, $s;
    my $result = 0;
    foreach(@arr) {
        $result = $result * 26 + ord($_) - ord("A") + 1;
    }
    return $result;
}

#!/usr/bin/perl

use 5.006;
use strict;
use warnings;

main();

sub main {
    my $n = int <>;
    for(1..$n) {
        my $line = <>;
        if ($line =~ /R[0-9]+C[0-9]+/) {
            my $row = $line;
            $row =~ s/R//g;
            $row =~ s/C[0-9]+//g;
            my $col = $line;
            $col =~ s/^R[0-9]+C//g;
            print convertToSymbols($col)."$row";
        } else {
            my $row = $line;
            $row =~ s/[A-Z]+//g;
            my $col = $line;
            $col =~ s/[0-9]+//g;
            print "R".$row."C".convertFromSymbols($col);
        }
    }
}

sub convertToSymbols {
    my $cur = shift;
    my $result = "";
    while ($cur > 0) {
        my $c = chr(ord("A") + $cur % 26 - 1);
        $result = $result.$c;
        $cur = ($cur - $cur % 26) / 26;
    }
    return reverse $result;
}

sub convertFromSymbols {
    my $s = shift;
    my @arr = split //, $s;
    my $result = 0;
    foreach(@arr) {
        $result = $result * 26 + ord($_) - ord("A") + 1;
    }
    return $result;
}

#!/usr/bin/perl

use 5.006;
use strict;
use warnings;

main();

sub main {
    my $n = int <>;
    for(1..$n) {
        my $line = <>;
        if ($line =~ /R[0-9]+C[0-9]+/) {
            my $row = $line;
            $row =~ s/R//g;
            $row =~ s/C[0-9]+//g;
            my $col = $line;
            $col =~ s/^R[0-9]+C//g;
            print convertToSymbols($col)."$row";
        } else {
            my $row = $line;
            $row =~ s/[A-Z]+//g;
            my $col = $line;
            $col =~ s/[0-9]+//g;
            print "R".convertFromSymbols($col)."C$row";
        }
    }
}

sub convertToSymbols {
    my $cur = shift;
    my $result = "";
    while ($cur > 0) {
        my $c = chr(ord("A") + $cur % 26 - 1);
        $result = $result.$c;
        $cur = ($cur - $cur % 26) / 26;
    }
    return reverse $result;
}

sub convertFromSymbols {
    my $s = shift;
    my @arr = split //, $s;
    my $result = 0;
    foreach(@arr) {
        $result = $result * 26 + ord($_) - ord("A") + 1;
    }
    return $result;
}


Many computer strategy games require building cities, recruiting army, conquering tribes, collecting resources. Sometimes it leads to interesting problems. Let's suppose that your task is to build a square city. The world map uses the Cartesian coordinates. The sides of the city should be parallel to coordinate axes. The map contains mines with valuable resources, located at some points with integer coordinates. The sizes of mines are relatively small, i.e. they can be treated as points. The city should be built in such a way that all the mines are inside or on the border of the city square. Building a city takes large amount of money depending on the size of the city, so you have to build the city with the minimum area. Given the positions of the mines find the minimum possible area of the city.

The first line of the input contains number n — the number of mines on the map (2 ≤ n ≤ 1000). Each of the next n lines contains a pair of integers xi and yi — the coordinates of the corresponding mine ( - 109 ≤ xi, yi ≤ 109). All points are pairwise distinct.

Print the minimum area of the city that can cover all the mines with valuable resources.


You are given an undirected graph consisting of $$$n$$$ vertices and $$$m$$$ edges. Your task is to find the number of connected components which are cycles.Here are some definitions of graph theory.An undirected graph consists of two sets: set of nodes (called vertices) and set of edges. Each edge connects a pair of vertices. All edges are bidirectional (i.e. if a vertex $$$a$$$ is connected with a vertex $$$b$$$, a vertex $$$b$$$ is also connected with a vertex $$$a$$$). An edge can't connect vertex with itself, there is at most one edge between a pair of vertices.Two vertices $$$u$$$ and $$$v$$$ belong to the same connected component if and only if there is at least one path along edges connecting $$$u$$$ and $$$v$$$.A connected component is a cycle if and only if its vertices can be reordered in such a way that:  the first vertex is connected with the second vertex by an edge,  the second vertex is connected with the third vertex by an edge,  ...  the last vertex is connected with the first vertex by an edge,  all the described edges of a cycle are distinct. A cycle doesn't contain any other edges except described above. By definition any cycle contains three or more vertices.    There are $$$6$$$ connected components, $$$2$$$ of them are cycles: $$$[7, 10, 16]$$$ and $$$[5, 11, 9, 15]$$$.

The first line contains two integer numbers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 2 \cdot 10^5$$$, $$$0 \le m \le 2 \cdot 10^5$$$) — number of vertices and edges. The following $$$m$$$ lines contains edges: edge $$$i$$$ is given as a pair of vertices $$$v_i$$$, $$$u_i$$$ ($$$1 \le v_i, u_i \le n$$$, $$$u_i \ne v_i$$$). There is no multiple edges in the given graph, i.e. for each pair ($$$v_i, u_i$$$) there no other pairs ($$$v_i, u_i$$$) and ($$$u_i, v_i$$$) in the list of edges.

Print one integer — the number of connected components which are also cycles.

NoteIn the first example only component $$$[3, 4, 5]$$$ is also a cycle.The illustration above corresponds to the second example.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;
my $debug = 0;

while(<>){
	my( $n, $m ) = split;

	my %h;

	map {
		my( $u, $v ) = split ' ', <>;
		$h{ $u }{ $v } ++;
		$h{ $v }{ $u } ++;
		} 1 .. $m;

	my @u = keys %h;

	my $cnt = 0;

	for my $u ( @u ){
		next if not exists $h{ $u };
		my @try = $u;

		my %fract;

		while( @try ){
			my $try = shift @try;
			my @adj = keys %{ $h{ $try } };
			$fract{ 0 + @adj } ++;
			push @try, @adj;
		##	delete $h{ $try }{ $_ } for @adj;
			delete $h{ $try };
			}

		$debug and print map "[$_]", join ' ', sort keys %fract;

		$cnt ++ if 2 >= ( keys %fract ) and '0 2' eq join ' ', sort keys %fract;
		}

	print $cnt;

	$debug and print '-' x 10;
	}


Heidi has finally found the mythical Tree of Life – a legendary combinatorial structure which is said to contain a prophecy crucially needed to defeat the undead armies.On the surface, the Tree of Life is just a regular undirected tree well-known from computer science. This means that it is a collection of n points (called vertices), some of which are connected using n - 1 line segments (edges) so that each pair of vertices is connected by a path (a sequence of one or more edges).To decipher the prophecy, Heidi needs to perform a number of steps. The first is counting the number of lifelines in the tree – these are paths of length 2, i.e., consisting of two edges. Help her!

The first line of the input contains a single integer n – the number of vertices in the tree (1 ≤ n ≤ 10000). The vertices are labeled with the numbers from 1 to n. Then n - 1 lines follow, each describing one edge using two space-separated numbers a b – the labels of the vertices connected by the edge (1 ≤ a < b ≤ n). It is guaranteed that the input represents a tree.

Print one integer – the number of lifelines in the tree.

NoteIn the second sample, there are four lifelines: paths between vertices 1 and 3, 2 and 4, 2 and 5, and 4 and 5.


PizzaForces is Petya's favorite pizzeria. PizzaForces makes and sells pizzas of three sizes: small pizzas consist of $$$6$$$ slices, medium ones consist of $$$8$$$ slices, and large pizzas consist of $$$10$$$ slices each. Baking them takes $$$15$$$, $$$20$$$ and $$$25$$$ minutes, respectively.Petya's birthday is today, and $$$n$$$ of his friends will come, so he decided to make an order from his favorite pizzeria. Petya wants to order so much pizza that each of his friends gets at least one slice of pizza. The cooking time of the order is the total baking time of all the pizzas in the order.Your task is to determine the minimum number of minutes that is needed to make pizzas containing at least $$$n$$$ slices in total. For example:   if $$$12$$$ friends come to Petya's birthday, he has to order pizzas containing at least $$$12$$$ slices in total. He can order two small pizzas, containing exactly $$$12$$$ slices, and the time to bake them is $$$30$$$ minutes;  if $$$15$$$ friends come to Petya's birthday, he has to order pizzas containing at least $$$15$$$ slices in total. He can order a small pizza and a large pizza, containing $$$16$$$ slices, and the time to bake them is $$$40$$$ minutes;  if $$$300$$$ friends come to Petya's birthday, he has to order pizzas containing at least $$$300$$$ slices in total. He can order $$$15$$$ small pizzas, $$$10$$$ medium pizzas and $$$13$$$ large pizzas, in total they contain $$$15 \cdot 6 + 10 \cdot 8 + 13 \cdot 10 = 300$$$ slices, and the total time to bake them is $$$15 \cdot 15 + 10 \cdot 20 + 13 \cdot 25 = 750$$$ minutes;  if only one friend comes to Petya's birthday, he can order a small pizza, and the time to bake it is $$$15$$$ minutes.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of testcases. Each testcase consists of a single line that contains a single integer $$$n$$$ ($$$1 \le n \le 10^{16}$$$) — the number of Petya's friends.

For each testcase, print one integer — the minimum number of minutes that is needed to bake pizzas containing at least $$$n$$$ slices in total.


Polycarp is a great fan of television.He wrote down all the TV programs he is interested in for today. His list contains n shows, i-th of them starts at moment li and ends at moment ri.Polycarp owns two TVs. He can watch two different shows simultaneously with two TVs but he can only watch one show at any given moment on a single TV. If one show ends at the same moment some other show starts then you can't watch them on a single TV.Polycarp wants to check out all n shows. Are two TVs enough to do so?

The first line contains one integer n (1 ≤ n ≤ 2·105) — the number of shows. Each of the next n lines contains two integers li and ri (0 ≤ li < ri ≤ 109) — starting and ending time of i-th show.

If Polycarp is able to check out all the shows using only two TVs then print "YES" (without quotes). Otherwise, print "NO" (without quotes).

# declare two tv arrays
my @arr;

# read n
my $f = <STDIN>;
chomp ( $f );

my $g;
my $s, $e;
# read show intervals
for ( my $i = 0; $i < $f ; $i += 1 ) {
    $g = <STDIN>;
    chomp ( $g );
    ($s, $e) = split m/ /, $g;
    push @arr, [ ($s, $e) ];
}

# # debugging
# for ( my $i = 0; $i < @arr; $i += 1 ) {
#     print $arr[ $i ][ 0 ];
#     print "  ";
#     print $arr[ $i ][ 1 ];
#     print "\n";
# }
# print "\n\n\n";

# sort the array by start time
my @arr_two = sort { ${ $a }[0] <=> ${ $b }[0] } @arr;

# # debugging
# for ( my $i = 0; $i < @arr_two; $i += 1 ) {
#     print $arr_two[$i][0];
#     print "  ";
#     print $arr_two[$i][1];
#     print "\n";
# }

# value represents whether we can schedule
# n shows on two tvs, without overlap
my $works = 1;

# keeps track of latest show end
my $tv_one = -1;
my $tv_two = -1;

# use for iterating through array, temporary variable
my $beg, $end;

# iterate through the array, assigning shows to tvs one and two
while ( (@arr_two > 0) and $works ) {

    # remove one slice from array
    # one slice is one show
    my $ref;
    $ref = shift @arr_two;
    $beg = ${ $ref }[0];
    $end = ${ $ref }[1];

    # assign a show to a tv if it begins after
    # the last one ended
    if ( $beg > $tv_one ) {
	$tv_one = $end; }
    elsif ( $beg > $tv_two ) {
	$tv_two = $end; }
    else {
	$works = 0;}
    # if it can't fit on either tv
    # then we will print NO

}

# print answer
if ( $works ) {
    print "YES\n";}
else {
    print "NO\n"; }

# declare two tv arrays
my @arr;

# read n
my $f = <STDIN>;
chomp ( $f );

my $s, $e;
# read show intervals
for (1..$f) {
    $f = <STDIN>;
    chomp ( $f );
    ($s, $e) = split m/ /, $f;
    push @arr, [ ($s, $e) ];
}

# sort the array by start time
my @arr_two = sort { $a[0] <=> $b[0] } @arr;

# value represents whether we can schedule
# n shows on two tvs, without overlap
my $works = 1;

# keeps track of latest show end
my $tv_one = -1;
my $tv_two = -1;

# use for iterating through array, temporary variable
my $beg, $end;

# iterate through the array, assigning shows to tvs one and two
while ( (@arr_two > 0) and $works ) {

    # remove one slice from array
    # one slice is one show
    my $ref;
    $ref = shift @arr_two;
    $beg = ${ $ref }[0];
    $end = ${ $ref }[1];

    # assign a show to a tv if it begins after
    # the last one ended
    if ( $beg > $tv_one ) {
	$tv_one = $end; }
    elsif ( $beg > $tv_two ) {
	$tv_two = $end; }
    else {
	$works = 0;}
    # if it can't fit on either tv
    # then we will print NO

}

# print answer
if ( $works ) {
    print "YES\n";}
else {
    print "NO\n"; }


There are two popular keyboard layouts in Berland, they differ only in letters positions. All the other keys are the same. In Berland they use alphabet with 26 letters which coincides with English alphabet.You are given two strings consisting of 26 distinct letters each: all keys of the first and the second layouts in the same order. You are also given some text consisting of small and capital English letters and digits. It is known that it was typed in the first layout, but the writer intended to type it in the second layout. Print the text if the same keys were pressed in the second layout.Since all keys but letters are the same in both layouts, the capitalization of the letters should remain the same, as well as all other characters.

The first line contains a string of length 26 consisting of distinct lowercase English letters. This is the first layout. The second line contains a string of length 26 consisting of distinct lowercase English letters. This is the second layout. The third line contains a non-empty string s consisting of lowercase and uppercase English letters and digits. This is the text typed in the first layout. The length of s does not exceed 1000.


IA has so many colorful magnets on her fridge! Exactly one letter is written on each magnet, 'a' or 'b'. She loves to play with them, placing all magnets in a row. However, the girl is quickly bored and usually thinks how to make her entertainment more interesting.Today, when IA looked at the fridge, she noticed that the word formed by magnets is really messy. "It would look much better when I'll swap some of them!" — thought the girl — "but how to do it?". After a while, she got an idea. IA will look at all prefixes with lengths from $$$1$$$ to the length of the word and for each prefix she will either reverse this prefix or leave it as it is. She will consider the prefixes in the fixed order: from the shortest to the largest. She wants to get the lexicographically smallest possible word after she considers all prefixes. Can you help her, telling which prefixes should be chosen for reversing?A string $$$a$$$ is lexicographically smaller than a string $$$b$$$ if and only if one of the following holds: $$$a$$$ is a prefix of $$$b$$$, but $$$a \ne b$$$; in the first position where $$$a$$$ and $$$b$$$ differ, the string $$$a$$$ has a letter that appears earlier in the alphabet than the corresponding letter in $$$b$$$.

The first and the only line contains a string $$$s$$$ ($$$1 \le |s| \le 1000$$$), describing the initial string formed by magnets. The string $$$s$$$ consists only of characters 'a' and 'b'.

Output exactly $$$|s|$$$ integers. If IA should reverse the $$$i$$$-th prefix (that is, the substring from $$$1$$$ to $$$i$$$), the $$$i$$$-th integer should be equal to $$$1$$$, and it should be equal to $$$0$$$ otherwise. If there are multiple possible sequences leading to the optimal answer, print any of them.

NoteIn the first example, IA can reverse the second and the third prefix and get a string "abbb". She cannot get better result, since it is also lexicographically smallest string obtainable by permuting characters of the initial string.In the second example, she can reverse any subset of prefixes — all letters are 'a'.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

while(<>){
	chomp;

	my $length = length;

	$debug and print '-' x 15;
	$debug and print;

	my @ans;

	my $len = 0;

	s/^a*b+(?=a)// and do {
		$len += length $&;
		push @ans, $len;
		};

	while( /a/ ){
		s/a+// and do {
			$len += length $&;
			push @ans, $len;
			};

		s/b+(?=a)// and do {
			$len += length $&;
			push @ans, $len;
			};
		}

	$debug and print "@ans";

	my @ANS = ( 0 ) x $length;

	for( @ans ){
		$ANS[ $_ - 1 ] = 1;
		}

	print "@ANS";
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

while(<>){
	chomp;

	@_ = ();

	my $q = 0;

	while( 1 < length ){
		my $ch = chop;
		my $front = substr $_, 0, 1;

		if( 0 ){ ; }
		elsif( $front eq 'b' and $ch eq 'b' ){
			push @_, 0;
			}
		elsif( $front eq 'a' and $ch eq 'b' ){
			if( $q ){
				push @_, 1;
				$_ = reverse( $_ . $ch );
				chop;
				$q = 0;
				}
			else{
				push @_, 0;
				}
			}
		elsif( $front eq 'b' and $ch eq 'a' ){
			push @_, 1;
			$_ = reverse( $_ . $ch );
			chop;
			}
		elsif( $front eq 'a' and $ch eq 'a' ){
			push @_, $q ? 0 : '?';
			$q ||= 1;
			}
		}

	my $last = $_;

	push @_, 0;
	@_ = reverse @_;
#%	print "@_";

	my $one = 0;

	for( @_ ){
		/\?/ and $one and do {
			$_ = 1;
			};
		/\?/ and $one = 1;
		}

	for( @_ ){
		/\?/ and do {
			$_ = $last eq 'b' ? 1 : 0;
			last;
			};
		}

	print "@_";
	}


Arseniy is already grown-up and independent. His mother decided to leave him alone for m days and left on a vacation. She have prepared a lot of food, left some money and washed all Arseniy's clothes. Ten minutes before her leave she realized that it would be also useful to prepare instruction of which particular clothes to wear on each of the days she will be absent. Arseniy's family is a bit weird so all the clothes is enumerated. For example, each of Arseniy's n socks is assigned a unique integer from 1 to n. Thus, the only thing his mother had to do was to write down two integers li and ri for each of the days — the indices of socks to wear on the day i (obviously, li stands for the left foot and ri for the right). Each sock is painted in one of k colors.When mother already left Arseniy noticed that according to instruction he would wear the socks of different colors on some days. Of course, that is a terrible mistake cause by a rush. Arseniy is a smart boy, and, by some magical coincidence, he posses k jars with the paint — one for each of k colors.Arseniy wants to repaint some of the socks in such a way, that for each of m days he can follow the mother's instructions and wear the socks of the same color. As he is going to be very busy these days he will have no time to change the colors of any socks so he has to finalize the colors now.The new computer game Bota-3 was just realised and Arseniy can't wait to play it. What is the minimum number of socks that need their color to be changed in order to make it possible to follow mother's instructions and wear the socks of the same color during each of m days.

The first line of input contains three integers n, m and k (2 ≤ n ≤ 200 000, 0 ≤ m ≤ 200 000, 1 ≤ k ≤ 200 000) — the number of socks, the number of days and the number of available colors respectively. The second line contain n integers c1, c2, ..., cn (1 ≤ ci ≤ k) — current colors of Arseniy's socks. Each of the following m lines contains two integers li and ri (1 ≤ li, ri ≤ n, li ≠ ri) — indices of socks which Arseniy should wear during the i-th day.

Print one integer — the minimum number of socks that should have their colors changed in order to be able to obey the instructions and not make people laugh from watching the socks of different colors.

NoteIn the first sample, Arseniy can repaint the first and the third socks to the second color.In the second sample, there is no need to change any colors.

#use strict;
#use warnings;
#use Data::Dumper;
$,=" ";
my ($n,$m,$k)=split / /,<>;
chomp($n,$m,$k);
my @c=split / /,<>;
chomp(@c);
my %socks;
my %visited;
my %cc;
while($m--)
{
$_=<>;
chomp;
my @t=split / /;
chomp(@t);
push(@{$socks{$t[0]}},$t[1]);
push(@{$socks{$t[1]}},$t[0]);
}

my $ans=0;
for my $key (keys %socks)
{
  if(!$visited{$key})
  {
  %cc=();
  DFS($key);
  #print Dumper(\%cc) . "\n";
  my $i=1;
    for my $tv (sort {$cc{$b} <=>  $cc{$a}} keys %cc)
    {
      if($i)
      {
        $i--;
        next;
      }
      $ans+=$cc{$tv};
    }
  }

}

print $ans . "\n";

sub DFS
{
  my $v=shift;
  if(!$visited{$v})
  {
      $visited{$v}=1;
      $cc{$c[$v-1]}++;

  }
  for my $tt (@{$socks{$v}})
  {
    if(!$visited{$tt})
    {
      DFS($tt);
    }
  }
}

$,=" ";
my ($n,$m,$k)=split / /,<>;
chomp($n,$m,$k);
my @c=split / /,<>;
chomp(@c);
my %socks;
my %counts;
while($m--)
{
$_=<>;
chomp;
my @t=split / /;
chomp(@t);
@t=map {$c[$_-1]} @t;
push(@{$socks{$t[0]}},$t[1]);
$counts{$t[0]}++;
$counts{$t[1]}++;
}
my %color=map {$_ => $_ } @c;
my $count=0;
for my $key (sort { $counts{$a} <=> $counts{$b} } keys %counts)
{
  if(defined $socks{$key})
  {
    for(my $i=0;$i<scalar(@{$socks{$key}});$i++)
    {
      if($color{$socks{$key}->[$i]} == $color{$key})
      {
        next;
      }
      else
      {
        $count++;
        $color{$socks{$key}->[$i]}=$color{$key};
      }
    }
  }
}

print $count . "\n";

#use strict;
#use warnings;
#use Data::Dumper;
$,=" ";
my ($n,$m,$k)=split / /,<>;
chomp($n,$m,$k);
my @c=split / /,<>;
chomp(@c);
my %socks;
my %counts;
while($m--)
{
$_=<>;
chomp;
my @t=split / /;
chomp(@t);
#@t=map {$c[$_-1]} @t;
push(@{$socks{$t[0]}},$t[1]);
$counts{$t[0]}++;
$counts{$t[1]}++;
}
#print Dumper(\%counts) . "\n";
#print Dumper(\%socks) . "\n";
my $count=0;
for my $key (sort { $counts{$a} <=> $counts{$b} } keys %counts)
{
  if(defined $socks{$key})
  {
    for(my $i=0;$i<scalar(@{$socks{$key}});$i++)
    {
      my $fc=$c[$socks{$key}->[$i]-1];
      my $sc=$c[$key-1];
      if($fc == $sc)
      {
        next;
      }
      else
      {
        if($counts{$fc}>$counts{$sc})
        {
          $c[$key-1]=$c[$socks{$key}->[$i]-1];
          $counts{$fc}++;
        }
        else
        {
          $c[$socks{$key}->[$i]-1]=$c[$key-1];
          $counts{$sc}++;
        }
        $count++;
      }
    }
  }
}

print $count . "\n";

#use strict;
#use warnings;
#use Data::Dumper;
$,=" ";
my ($n,$m,$k)=split / /,<>;
chomp($n,$m,$k);
my @c=split / /,<>;
chomp(@c);
my %socks;
my %counts;
while($m--)
{
$_=<>;
chomp;
my @t=split / /;
chomp(@t);
#@t=map {$c[$_-1]} @t;
push(@{$socks{$t[0]}},$t[1]);
$counts{$t[0]}++;
$counts{$t[1]}++;
}
#print Dumper(\%counts) . "\n";
#print Dumper(\%socks) . "\n";
my $count=0;
for my $key (sort { $counts{$a} <=> $counts{$b} } keys %counts)
{
  if(defined $socks{$key})
  {
    for(my $i=0;$i<scalar(@{$socks{$key}});$i++)
    {
      if($c[$socks{$key}->[$i]-1] == $c[$key-1])
      {
        next;
      }
      else
      {
        $c[$socks{$key}->[$i]-1] = $c[$key-1];
        $count++;
      }
    }
  }
}

print $count . "\n";

#use strict;
#use warnings;
#use Data::Dumper;
$,=" ";
my ($n,$m,$k)=split / /,<>;
chomp($n,$m,$k);
my @c=split / /,<>;
chomp(@c);
my %socks;
my %counts;
while($m--)
{
$_=<>;
chomp;
my @t=split / /;
chomp(@t);
@t=map {$c[$_-1]} @t;
push(@{$socks{$t[0]}},$t[1]);
$counts{$t[0]}++;
$counts{$t[1]}++;
}
#print Dumper(\%counts) . "\n";
#print Dumper(\%socks) . "\n";
my $count=0;
for my $key (sort { $counts{$a} <=> $counts{$b} } keys %counts)
{
  if(defined $socks{$key})
  {
    for(my $i=0;$i<scalar(@{$socks{$key}});$i++)
    {
      if($socks{$key}->[$i] == $key)
      {
        next;
      }
      else
      {
        $count++;
      }
    }
  }
}

print $count . "\n";

#use strict;
#use warnings;
#use Data::Dumper;
$,=" ";
my ($n,$m,$k)=split / /,<>;
chomp($n,$m,$k);
my @c=split / /,<>;
chomp(@c);
my %socks;
my %counts;
while($m--)
{
$_=<>;
chomp;
my @t=split / /;
chomp(@t);
#@t=map {$c[$_-1]} @t;
push(@{$socks{$t[0]}},$t[1]);
$counts{$t[0]}++;
$counts{$t[1]}++;
}
#print Dumper(\%counts) . "\n";
#print Dumper(\%socks) . "\n";
my $count=0;
for my $key (sort { $counts{$a} <=> $counts{$b} } keys %counts)
{
  if(defined $socks{$key})
  {
    for(my $i=0;$i<scalar(@{$socks{$key}});$i++)
    {
      if($c[$socks{$key}->[$i]-1] == $c[$key-1])
      {
        next;
      }
      else
      {
        $c[$socks{$key}->[$i]-1] = $c[$key-1-0];
        $count++;
      }
    }
  }
}

print $count . "\n";


Polycarp wants to assemble his own keyboard. Layouts with multiple rows are too complicated for him — his keyboard will consist of only one row, where all $$$26$$$ lowercase Latin letters will be arranged in some order.Polycarp uses the same password $$$s$$$ on all websites where he is registered (it is bad, but he doesn't care). He wants to assemble a keyboard that will allow to type this password very easily. He doesn't like to move his fingers while typing the password, so, for each pair of adjacent characters in $$$s$$$, they should be adjacent on the keyboard. For example, if the password is abacaba, then the layout cabdefghi... is perfect, since characters a and c are adjacent on the keyboard, and a and b are adjacent on the keyboard. It is guaranteed that there are no two adjacent equal characters in $$$s$$$, so, for example, the password cannot be password (two characters s are adjacent).Can you help Polycarp with choosing the perfect layout of the keyboard, if it is possible?

The first line contains one integer $$$T$$$ ($$$1 \le T \le 1000$$$) — the number of test cases. Then $$$T$$$ lines follow, each containing one string $$$s$$$ ($$$1 \le |s| \le 200$$$) representing the test case. $$$s$$$ consists of lowercase Latin letters only. There are no two adjacent equal characters in $$$s$$$.

For each test case, do the following:   if it is impossible to assemble a perfect keyboard, print NO (in upper case, it matters in this problem);  otherwise, print YES (in upper case), and then a string consisting of $$$26$$$ lowercase Latin letters — the perfect layout. Each Latin letter should appear in this string exactly once. If there are multiple answers, print any of them.

5
ababa
codedoca
abcda
zxzytyz
abcdefghijklmnopqrstuvwxyza

YES
bacdefghijklmnopqrstuvwxyz
YES
edocabfghijklmnpqrstuvwxyz
NO
YES
xzytabcdefghijklmnopqrsuvw
NO

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

<>;

while(<>){
	$debug and print '-' x 15;

	chomp;

	if( 1 == length ){
		print for "YES", join '', 'a' .. 'z';
		next;
		}

	my %h;

	/
		(.)
		(?=(.))
		(?{ $h{ join '', sort $1, $2 } ++ })
		(*FAIL)
		/x;

	$debug and print ":$_ --> [$h{ $_ }]" for sort keys %h;

	@_ = map { [ split '' ] } sort keys %h;

	my $alphabet = join '', @{ shift @_ };

	my %alphabet;

	$alphabet{ $_ } = 0 for 'a' .. 'z';

	map { $alphabet{ $_ } ++ } split '', $alphabet;

	my $j = 26 ** 1 + 2;

	while( @_ ){
		$j -- < 0 and last;

		my $try = shift @_;

		if( 1 != $alphabet{ $try->[ 0 ] } + $alphabet{ $try->[ 1 ] } ){
			push @_, $try;
			next;
			}

		my $fail = 0;

		if( 0 ){ ; }
		elsif( $alphabet =~ /^$try->[ 0 ]/ ){
			$alphabet = $try->[ 1 ] . $alphabet;
			$alphabet{ $try->[ 1 ] } ++;
			}
		elsif( $alphabet =~ /^$try->[ 1 ]/ ){
			$alphabet = $try->[ 0 ] . $alphabet;
			$alphabet{ $try->[ 0 ] } ++;
			}
		elsif( $alphabet =~ /$try->[ 0 ]$/ ){
			$alphabet .= $try->[ 1 ];
			$alphabet{ $try->[ 1 ] } ++;
			}
		elsif( $alphabet =~ /$try->[ 1 ]$/ ){
			$alphabet .= $try->[ 0 ];
			$alphabet{ $try->[ 0 ] } ++;
			}
		else{
			$fail = 1;
			}

		if( $fail ){
			push @_, $try;
			}
		}

	$debug and print "alphabet:[$alphabet]|\@_:[@_]|j:[$j]";

	if( $j == -2 ){
		print "NO";
		}
	else{
		print for "YES", $alphabet . ( join '', 'a' .. 'z' ) =~ s/[$alphabet]//gr;
		}
	}

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

<>;

while(<>){
	$debug and print '-' x 15;

	chomp;

	if( 1 == length ){
		print for "YES", join '', 'a' .. 'z';
		next;
		}

	my %h;

	/
		(.)
		(?=(.))
		(?{ $h{ join '', sort $1, $2 } ++ })
		(*FAIL)
		/x;

	$debug and print ":$_ --> [$h{ $_ }]" for sort keys %h;

	@_ = map { [ split '' ] } sort keys %h;

	my $alphabet = join '', @{ shift @_ };

	my %alphabet;

	$alphabet{ $_ } = 0 for 'a' .. 'z';

	map { $alphabet{ $_ } ++ } split '', $alphabet;

	my $j = 26 ** 1 + 2;

	while( @_ ){
		$j -- < 0 and last;

		my $try = shift @_;

		if( 2 == $alphabet{ $try->[ 0 ] } + $alphabet{ $try->[ 1 ] } ){
			$j = -2;
			last;
			}

		if( 0 == $alphabet{ $try->[ 0 ] } + $alphabet{ $try->[ 1 ] } ){
			push @_, $try;
			next;
			}

		my $fail = 0;

		if( 0 ){ ; }
		elsif( $alphabet =~ /^$try->[ 0 ]/ ){
			$alphabet = $try->[ 1 ] . $alphabet;
			$alphabet{ $try->[ 1 ] } ++;
			}
		elsif( $alphabet =~ /^$try->[ 1 ]/ ){
			$alphabet = $try->[ 0 ] . $alphabet;
			$alphabet{ $try->[ 0 ] } ++;
			}
		elsif( $alphabet =~ /$try->[ 0 ]$/ ){
			$alphabet .= $try->[ 1 ];
			$alphabet{ $try->[ 1 ] } ++;
			}
		elsif( $alphabet =~ /$try->[ 1 ]$/ ){
			$alphabet .= $try->[ 0 ];
			$alphabet{ $try->[ 0 ] } ++;
			}
		else{
			$fail = 1;
			}

		if( $fail ){
			push @_, $try;
			}
		}

	$debug and print "alphabet:[$alphabet]|\@_:[@_]|j:[$j]";

	if( $j == -2 ){
		print "NO";
		}
	else{
		print for "YES", $alphabet . ( join '', 'a' .. 'z' ) =~ s/[$alphabet]//gr;
		}
	}


You are given string s. Let's call word any largest sequence of consecutive symbols without symbols ',' (comma) and ';' (semicolon). For example, there are four words in string "aba,123;1a;0": "aba", "123", "1a", "0". A word can be empty: for example, the string s=";;" contains three empty words separated by ';'.You should find all words in the given string that are nonnegative INTEGER numbers without leading zeroes and build by them new string a. String a should contain all words that are numbers separating them by ',' (the order of numbers should remain the same as in the string s). By all other words you should build string b in the same way (the order of numbers should remain the same as in the string s).Here strings "101", "0" are INTEGER numbers, but "01" and "1.0" are not.For example, for the string aba,123;1a;0 the string a would be equal to "123,0" and string b would be equal to "aba,1a".

The only line of input contains the string s (1 ≤ |s| ≤ 105). The string contains only symbols '.' (ASCII 46), ',' (ASCII 44), ';' (ASCII 59), digits, lowercase and uppercase latin letters.

Print the string a to the first line and string b to the second line. Each string should be surrounded by quotes (ASCII 34). If there are no words that are numbers print dash (ASCII 45) on the first line. If all words are numbers print dash on the second line.

NoteIn the second example the string s contains five words: "1", "", "01", "a0", "".

#!perl
$\ = "\n";

$line = <>;
chomp $line;

@letters = split //, $line;

$filler = "~";
push @letters, $filler if @letters[$#letters] eq "," or @letters[$#letters] eq ";";
@letters = ($filler, @letters) if @letters[0] eq "," or @letters[0] eq ";";

for (my $i = 0; $i <= $#letters; $i++)
{
    my $word = "";
    my $char_flag = 0;
    my $zero_flag = 0;

    $zero_flag = 1 if @letters[$i] eq '0';

    while ($i <= $#letters and ',' ne @letters[$i] and ';' ne @letters[$i])
    {
        $char_flag = 1 if @letters[$i] gt '9' or @letters[$i] eq '.';
        $word .= @letters[$i];
        $i++;
    }

    if($char_flag == 1 or $word eq "" or $zero_flag == 1 and length $word > 1)
    {
        $b .= $word.',';
    }
    else
    {
        $a .= $word.',';
    }
}

chop $a;
chop $b;

$a = '-' if $a eq "";
$b = '-' if $b eq "";

$b =~ s/$filler//g;

print $a eq "-" ? '-' : qq("$a");
print $b eq "-" ? '-' : qq("$b");

#!perl
$\ = "\n";

$line = <>;
chomp $line;

@letters = split //, $line;

$end_filler = "~";
push @letters, $end_filler if @letters[$#letters] eq "," or @letters[$#letters] eq ";";

for (my $i = 0; $i <= $#letters; $i++)
{
    my $word = "";
    my $char_flag = 0;
    my $zero_flag = 0;

    $zero_flag = 1 if @letters[$i] eq '0';

    while ($i <= $#letters and ',' ne @letters[$i] and ';' ne @letters[$i])
    {
        $char_flag = 1 if @letters[$i] gt '9' or @letters[$i] eq '.';
        $word .= @letters[$i];
        $i++;
    }

    if($char_flag == 1 or $word eq "" or $zero_flag == 1 and length $word > 1)
    {
        $b .= $word.',';
    }
    else
    {
        $a .= $word.',';
    }
}

chop $a;
chop $b;

print $a eq "" ? '-' : qq("$a");
print $b eq "" ? '-' : $b =~ m/(.*)$end_filler$/ ? qq("$1") : qq("$b");

#!perl
$\ = "\n";

$line = <>;
chomp $line;

@words = split /;|,/, $line;

for my $word (@words)
{
    if($word =~ m/^(([1-9]+\d*)|0)$/)
    {
        push @as, $word;
    }
    else
    {
        push @bs, $word;
    }
}

push @bs, "" if $line =~ m/^.*,$/;

$a = scalar @as > 0 ? join ',', @as : '-';
$b = scalar @bs > 0 ? join ',', @bs : '-';

print $a;
print $b;

#!perl
$\ = "\n";

$line = <>;
chomp $line;

@words = split /;|,/, $line;

for my $word (@words)
{
    if($word =~ m/^(([1-9]+\d*)|0)$/)
    {
        push @as, $word;
    }
    else
    {
        push @bs, $word;
    }
}

push @bs, "" if $line =~ m/^.*,$/;

$a = scalar @as > 0 ? join ',', @as : '-';
$b = scalar @bs > 0 ? join ',', @bs : '-';

$a eq '-' ? print '-' : print "\"$a\"";
$b eq '-' ? print '-' : print "\"$b\"";

#!perl
$\ = "\n";

$line = <>;
chomp $line;

@letters = split //, $line;

for (my $i = 0; $i <= $#letters; $i++)
{
    my $word = "";
    my $char_flag = 0;
    my $zero_flag = 0;

    $zero_flag = 1 if @letters[$i] eq '0';

    while ($i <= $#letters and ',' ne @letters[$i] and ';' ne @letters[$i])
    {
        $char_flag = 1 if @letters[$i] gt '9' or @letters[$i] eq '.';
        $word .= @letters[$i];
        $i++;
    }

    if($char_flag == 1 or $word eq "" or $zero_flag == 1 and length $word > 1)
    {
        $b .= $word.',';
    }
    else
    {
        $a .= $word.',';
    }
}

chop $a;
chop $b;

$b .= "," if @letters[$#letters] eq "," or @letters[$#letters] eq ";";

print $a eq "" ? '-' : qq("$a");
print $b eq "" ? '-' : $b eq "," ? qq("") : qq("$b");

#!perl
$\ = "\n";

$line = <>;
chomp $line;

@letters = split //, $line;

for (my $i = 0; $i <= $#letters; $i++)
{
    my $word = "";
    my $char_flag = 0;
    my $zero_flag = 0;

    $zero_flag = 1 if @letters[$i] eq '0';

    while ($i <= $#letters and ',' ne @letters[$i] and ';' ne @letters[$i])
    {
        $char_flag = 1 if @letters[$i] gt '9' or @letters[$i] eq '.';
        $word .= @letters[$i];
        $i++;
    }

    if($char_flag == 1 or $word eq "" or $zero_flag == 1 and length $word > 1)
    {
        $b .= $word.',';
    }
    else
    {
        $a .= $word.',';
    }
}

chop $a;
chop $b;

$b .= "," if @letters[$#letters] eq "," or @letters[$#letters] eq ";";

print $a eq "" ? '-' : qq("$a");
print $b eq "" ? '-' : qq("$b");

#!perl
$\ = "\n";

$line = <>;
chomp $line;

@words = split /;|,/, $line;

for my $word (@words)
{
    if($word =~ m/^(([1-9]+\d*)|0)$/)
    {
        push @as, $word;
    }
    else
    {
        push @bs, $word;
    }
}

push @bs, "" if $line =~ m/^.*,$/;

$a = scalar @as > 0 ? join ',', @as : '-';
$b = scalar @bs > 0 ? join ',', @bs : '-';

print "\"$a\"";
print "\"$b\"";

#!perl
$\ = "\n";

$line = <>;
chomp $line;

@letters = split //, $line;

for (my $i = 0; $i <= $#letters; $i++)
{
    my $word = "";
    my $char_flag = 0;

    $zero_flag = 1 if @letters[$i] eq '0';

    while ($i <= $#letters and ',' ne @letters[$i] and ';' ne @letters[$i])
    {
        $char_flag = 1 if @letters[$i] gt '9' or @letters[$i] eq '.';
        $word .= @letters[$i];
        $i++;
    }

    if($char_flag == 1 or $word eq "" or $zero_flag == 1 and length $word > 1)
    {
        $b .= $word.',';
    }
    else
    {
        $a .= $word.',';
    }
}

chop $a;
chop $b;

$b .= "," if @letters[$#letters] eq "," or @letters[$#letters] eq ";";

print $a eq "" ? '-' : qq("$a");
print $b eq "" ? '-' : qq("$b");

#!perl
$\ = "\n";

$line = <>;
chomp $line;

@letters = split //, $line;

for (my $i = 0; $i <= $#letters; $i++)
{
    my $word = "";
    my $char_flag = 0;

    $zero_flag = 1 if @letters[$i] eq '0';

    while ($i <= $#letters and ',' ne @letters[$i] and ';' ne @letters[$i])
    {
        $char_flag = 1 if @letters[$i] gt '9';
        $word .= @letters[$i];
        $i++;
    }

    if($char_flag == 1 or $word eq "" or $zero_flag == 1 and length $word > 1)
    {
        $b .= $word.',';
    }
    else
    {
        $a .= $word.',';
    }
}

chop $a;
chop $b;

$b .= "," if @letters[$#letters] eq "," or @letters[$#letters] eq ";";

print $a eq "" ? '-' : qq("$a");
print $b eq "" ? '-' : qq("$b");


There is a field divided into $$$n$$$ rows and $$$m$$$ columns. Some cells are empty (denoted as E), other cells contain robots (denoted as R).You can send a command to all robots at the same time. The command can be of one of the four types:  move up;  move right;  move down;  move left. When you send a command, all robots at the same time attempt to take one step in the direction you picked. If a robot tries to move outside the field, it explodes; otherwise, every robot moves to an adjacent cell in the chosen direction.You can send as many commands as you want (possibly, zero), in any order. Your goal is to make at least one robot reach the upper left corner of the field. Can you do this without forcing any of the robots to explode?

The first line contains one integer $$$t$$$ ($$$1 \le t \le 5000$$$) — the number of test cases. Each test case starts with a line containing two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 5$$$) — the number of rows and the number of columns, respectively. Then $$$n$$$ lines follow; each of them contains a string of $$$m$$$ characters. Each character is either E (empty cell} or R (robot). Additional constraint on the input: in each test case, there is at least one robot on the field.

If it is possible to make at least one robot reach the upper left corner of the field so that no robot explodes, print YES. Otherwise, print NO.

6

1 3

ERR

2 2

ER

RE

2 2

ER

ER

1 1

R

4 3

EEE

EEE

ERR

EER

3 3

EEE

EER

REE

NoteExplanations for test cases of the example:  in the first test case, it is enough to send a command to move left.  in the second test case, if you try to send any command, at least one robot explodes.  in the third test case, it is enough to send a command to move left.  in the fourth test case, there is already a robot in the upper left corner.  in the fifth test case, the sequence "move up, move left, move up" leads one robot to the upper left corner;  in the sixth test case, if you try to move any robot to the upper left corner, at least one other robot explodes.

#!/usr/bin/perl
use Data::Dumper;
use integer;   ### important!
my $mod = 10 ** 9 + 7;
# my $mod = 998244353;

my ($testcase) = map { $_ - 0 } split(/\s+/,<STDIN>);

while( $testcase -- > 0 ){

  my ($n,$m) = map { $_ - 0 } split(/\s+/,<STDIN>);

  my $t = $n+1; my $l = $m+1;
  my @s = ();
  for(my $i=0;$i<$n;$i++){
    ( my $s1 = <STDIN> ) =~ s/[\x00-\x20]+$//ios;
    for(my $j=0;$j<$m;$j++){
      my $c1 = substr($s1,$j,1);
      if( $c1 eq 'R' ){
        $t = &min($t,$i);
        $l = &min($l,$j);
      }
    }
    push(@s,$s1);
  }
  if( $t >= $n || $l >= $m ){
    print "NO\n"; next;
  }
  if( substr($s[$t],$l,1) eq 'R' ){
    print "YES\n";
  } else {
    print "NO\n";
  }
}

exit(0);

sub max {
  my $r = undef;
  foreach my $e (@_){  $r = $e if !defined($r) or $e > $r;  }
  return $r;
}
sub min {
  my $r = undef;
  foreach my $e (@_){  $r = $e if !defined($r) or $e < $r;  }
  return $r;
}
sub sum {
  my $r = 0;
  foreach my $e (@_){ $r += $e; }
  return $r;
}
sub ruisum {   # my @rui = (0); &ruisum(\@rui,\@array);
  my $r = shift; my $ar = shift;
  $#{$r} = 1+$#{$ar}; $r->[0] = 0; my $rr = 0;
  for(my $i=0;$i<=$#ar;$i++){
    $rr += $ar->[$i];
    $r->[1+$i] = $rr;
  }
}


You are given an array $$$a$$$ consisting of $$$n$$$ integers.In one move, you can choose two indices $$$1 \le i, j \le n$$$ such that $$$i \ne j$$$ and set $$$a_i := a_j$$$. You can perform such moves any number of times (possibly, zero). You can choose different indices in different operations. The operation := is the operation of assignment (i.e. you choose $$$i$$$ and $$$j$$$ and replace $$$a_i$$$ with $$$a_j$$$).Your task is to say if it is possible to obtain an array with an odd (not divisible by $$$2$$$) sum of elements.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2000$$$) — the number of test cases. The next $$$2t$$$ lines describe test cases. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 2000$$$) — the number of elements in $$$a$$$. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 2000$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2000$$$ ($$$\sum n \le 2000$$$).

For each test case, print the answer on it — "YES" (without quotes) if it is possible to obtain the array with an odd sum of elements, and "NO" otherwise.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

while(<>){
	@_ = split ' ', <>;

	print qw( NO YES )[ ( grep $_ % 2, @_ ) and @_ % 2 || 0 + grep !( $_ % 2 ), @_ ];
	}


Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y), (x–1, y), (x, y + 1) and (x, y–1).Iahub wants to know how many Coders can be placed on an n × n chessboard, so that no Coder attacks any other Coder.

The first line contains an integer n (1 ≤ n ≤ 1000).

On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next n lines print n characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any.