Winters are just damn freezing cold in Nvodsk! That's why a group of n friends prefers to take a taxi, order a pizza and call girls. The phone numbers in the city consist of three pairs of digits (for example, 12-34-56). Each friend has a phonebook of size si (that's the number of phone numbers). We know that taxi numbers consist of six identical digits (for example, 22-22-22), the numbers of pizza deliveries should necessarily be decreasing sequences of six different digits (for example, 98-73-21), all other numbers are the girls' numbers.You are given your friends' phone books. Calculate which friend is best to go to when you are interested in each of those things (who has maximal number of phone numbers of each type). If the phone book of one person contains some number two times, you should count it twice. That is, each number should be taken into consideration the number of times it occurs in the phone book.

The first line contains an integer n (1 ≤ n ≤ 100) — the number of friends.  Then follow n data blocks that describe each friend's phone books. Each block is presented in the following form: first goes the line that contains integer si and string namei (0 ≤ si ≤ 100) — the number of phone numbers in the phone book of the i-th friend and the name of the i-th friend. The name is a non-empty sequence of uppercase and lowercase Latin letters, containing no more than 20 characters. Next si lines contain numbers as "XX-XX-XX", where X is arbitrary digits from 0 to 9.

In the first line print the phrase "If you want to call a taxi, you should call: ". Then print names of all friends whose phone books contain maximal number of taxi phone numbers.  In the second line print the phrase "If you want to order a pizza, you should call: ". Then print names of all friends who have maximal number of pizza phone numbers.  In the third line print the phrase "If you want to go to a cafe with a wonderful girl, you should call: ". Then print names of all friends who have maximal number of girls' phone numbers.  Print the names in the order in which they are given in the input data. Separate two consecutive names with a comma and a space. Each line should end with exactly one point. For clarifications concerning the output form, see sample tests. It is necessary that you follow the output form strictly. Extra spaces are not allowed.

If you want to call a taxi, you should call: Rogulenko.
If you want to order a pizza, you should call: Fedorov, Rogulenko, Kaluzhin.
If you want to go to a cafe with a wonderful girl, you should call: Melnikov.

If you want to call a taxi, you should call: Gleb.
If you want to order a pizza, you should call: Gleb, Serega.
If you want to go to a cafe with a wonderful girl, you should call: Melnik.

If you want to call a taxi, you should call: Pachocki.
If you want to order a pizza, you should call: Kulczynski, Pachocki.
If you want to go to a cafe with a wonderful girl, you should call: Kulczynski.

NoteIn the first sample you are given four friends. Fedorov's phone book contains one taxi number and one pizza delivery number, Melnikov's phone book only has 3 numbers of girls, Rogulenko's one has 6 taxi numbers and one pizza delivery number, Kaluzhin's one contains 2 taxi numbers and one pizza delivery number.Thus, if you need to order a taxi, you should obviously call Rogulenko, if you need to order a pizza you should call anybody of the following: Rogulenko, Fedorov, Kaluzhin (each of them has one number). Melnikov has maximal number of phone numbers of girls.

#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

#    <>=~/ /;
#    <>=~/ (\d+) /;
#    <>=~/ (\d+) (\d+) /;

@_=<>;
chomp @_;
shift @_;

s/-//g for @_;

for (@_){
	if (/^\d{6}$/){
		@n=split//;
		$f=shift @n;
		$nT=$nP=0;
		for $i(@n){
			$f!=$i and $nT++;
			$i>=$f and $nP++;
			$f=$i;
			}
		$nT && $nP and $_=3;
		$nT && !$nP and $_=2;
		!$nT && $nP and $_=1;
		}

	}

# print "@_\n";

for (@_){
	s/^\d+ / /;
	}

$_=join"",@_;
# print; n();

while (/31|21|32/){
s/31|21|32/reverse $&/eg;
}

$j=0;
for $i(1..100){
	/1{$i}/ and $j++;
	}
s/([a-z]+)(\d*?1{$j})/(push @T,$1) and "$1"."$2"/ieg;
# print; n();
# print "@T\n";

$j=0;
for $i(1..100){
	/2{$i}/ and $j++;
	}
s/([a-z]+)(\d*?2{$j})/(push @P,$1) and "$1"."$2"/ieg;
# print; n();
# print "@P\n";

$j=0;
for $i(1..100){
	/3{$i}/ and $j++;
	}
s/([a-z]+)(\d*?3{$j})/(push @M,$1) and "$1"."$2"/ieg;
# print; n();
# print "@M\n";

print "If you want to call a taxi, you should call: ",(join", ",@T),".\n";
print "If you want to order a pizza, you should call: ",(join", ",@P),".\n";
print "If you want to go to a cafe with a wonderful girl, you should call: ",(join", ",@M),".\n";

#***********SUBS************

sub num {$a <=> $b}
sub num_rev {$b <=> $a}
sub rev {$b cmp $a}

sub p{print}
sub n{print "\n"}
sub pn{p,n}
sub pn_mas {pn for @_}

# Transpose "charbox"
sub transpose{
    $i=@m=@_;
    chomp @m;
    while ($i--){
        $t[$i]=~s/$/chop/e for @m
    }
return @t
}

# Transpose "value sets"
sub transpose_space{
    my @t;
    for (@_){
        my $j=0;
        s/\d+/($t[$j++].="$& ")?$&:$&/eg;
        }
    chop @t;
return @t
}

sub div{
    my ($n, $k)=@_;
return ($n - $n % $k) / $k
}

sub uniq{
    my @m=sort @_;
    push @u, my $i=shift @m;
    for (@m){
        $i eq $_ or push @u, $_;
        $i=$_;
        }
return @u
}

sub max{
    my $max=shift;
    $max<$_ and $max=$_ for @_;
return $max
}

sub min{
    my $min=shift;
    $min>$_ and $min=$_ for @_;
return $min
}

# count (kas_ieskoma, masyvas)
sub count{
    my $i=0;
    $_ eq $_[0] and $i++ for @_;
return --$i
}

#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

#    <>=~/ /;
#    <>=~/ (\d+) /;
#    <>=~/ (\d+) (\d+) /;

@_=<>;
chomp @_;
shift @_;

s/-//g for @_;

for (@_){
	if (/^\d{6}$/){
		@n=split//;
		$f=shift @n;
		$nT=$nP=0;
		for $i(@n){
			$f!=$i and $nT++;
			$i>=$f and $nP++;
			$f=$i;
			}
		$nT && $nP and $_=3;
		$nT && !$nP and $_=2;
		!$nT && $nP and $_=1;
		}

	}

# print "@_\n";

for (@_){
	s/^\d+ / /;
	}

$_=join"",@_;
# print; n();

s#\d+#join"",(sort (split//,$&))#eg;
# print; n();
$j=0;
for $i(1..100){
	/1{$i}/ and $j++;
	}
s/([a-z]+)(\d*?1{$j})/(push @T,$1) and "$1"."$2"/ieg;
# print; n();
# print "@T\n";

$j=0;
for $i(1..100){
	/2{$i}/ and $j++;
	}
s/([a-z]+)(\d*?2{$j})/(push @P,$1) and "$1"."$2"/ieg;
# print; n();
# print "@P\n";

$j=0;
for $i(1..100){
	/3{$i}/ and $j++;
	}
s/([a-z]+)(\d*?3{$j})/(push @M,$1) and "$1"."$2"/ieg;
# print; n();
# print "@M\n";

print "If you want to call a taxi, you should call: ",(join", ",@T),".\n";
print "If you want to order a pizza, you should call: ",(join", ",@P),".\n";
print "If you want to go to a cafe with a wonderful girl, you should call: ",(join", ",@M),".\n";

#***********SUBS************

sub num {$a <=> $b}
sub num_rev {$b <=> $a}
sub rev {$b cmp $a}

sub p{print}
sub n{print "\n"}
sub pn{p,n}
sub pn_mas {pn for @_}

# Transpose "charbox"
sub transpose{
    $i=@m=@_;
    chomp @m;
    while ($i--){
        $t[$i]=~s/$/chop/e for @m
    }
return @t
}

# Transpose "value sets"
sub transpose_space{
    my @t;
    for (@_){
        my $j=0;
        s/\d+/($t[$j++].="$& ")?$&:$&/eg;
        }
    chop @t;
return @t
}

sub div{
    my ($n, $k)=@_;
return ($n - $n % $k) / $k
}

sub uniq{
    my @m=sort @_;
    push @u, my $i=shift @m;
    for (@m){
        $i eq $_ or push @u, $_;
        $i=$_;
        }
return @u
}

sub max{
    my $max=shift;
    $max<$_ and $max=$_ for @_;
return $max
}

sub min{
    my $min=shift;
    $min>$_ and $min=$_ for @_;
return $min
}

# count (kas_ieskoma, masyvas)
sub count{
    my $i=0;
    $_ eq $_[0] and $i++ for @_;
return --$i
}

#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

#    <>=~/ /;
#    <>=~/ (\d+) /;
#    <>=~/ (\d+) (\d+) /;

@_=<>;
chomp @_;
shift @_;

s/-//g for @_;

for (@_){
	if (/^\d{6}$/){
		@n=split//;
		$f=shift @n;
		$nT=$nP=0;
		for $i(@n){
			$f!=$i and $nT++;
			$i>=$f and $nP++;
			$f=$i;
			}
		$nT && $nP and $_=3;
		$nT && !$nP and $_=2;
		!$nT && $nP and $_=1;
		}

	}

# print "@_\n";

for (@_){
	s/^\d+ / /;
	}

$_=join"",@_;
# print; n();

while (/31|21|32/){
s/31/13/g;
s/21/12/g;
s/32/23/g;
}

$j=0;
for $i(1..100){
	/1{$i}/ and $j++;
	}
s/([a-z]+)(\d*?1{$j})/(push @T,$1) and "$1"."$2"/ieg;
# print; n();
# print "@T\n";

$j=0;
for $i(1..100){
	/2{$i}/ and $j++;
	}
s/([a-z]+)(\d*?2{$j})/(push @P,$1) and "$1"."$2"/ieg;
# print; n();
# print "@P\n";

$j=0;
for $i(1..100){
	/3{$i}/ and $j++;
	}
s/([a-z]+)(\d*?3{$j})/(push @M,$1) and "$1"."$2"/ieg;
# print; n();
# print "@M\n";

print "If you want to call a taxi, you should call: ",(join", ",@T),".\n";
print "If you want to order a pizza, you should call: ",(join", ",@P),".\n";
print "If you want to go to a cafe with a wonderful girl, you should call: ",(join", ",@M),".\n";

#***********SUBS************

sub num {$a <=> $b}
sub num_rev {$b <=> $a}
sub rev {$b cmp $a}

sub p{print}
sub n{print "\n"}
sub pn{p,n}
sub pn_mas {pn for @_}

# Transpose "charbox"
sub transpose{
    $i=@m=@_;
    chomp @m;
    while ($i--){
        $t[$i]=~s/$/chop/e for @m
    }
return @t
}

# Transpose "value sets"
sub transpose_space{
    my @t;
    for (@_){
        my $j=0;
        s/\d+/($t[$j++].="$& ")?$&:$&/eg;
        }
    chop @t;
return @t
}

sub div{
    my ($n, $k)=@_;
return ($n - $n % $k) / $k
}

sub uniq{
    my @m=sort @_;
    push @u, my $i=shift @m;
    for (@m){
        $i eq $_ or push @u, $_;
        $i=$_;
        }
return @u
}

sub max{
    my $max=shift;
    $max<$_ and $max=$_ for @_;
return $max
}

sub min{
    my $min=shift;
    $min>$_ and $min=$_ for @_;
return $min
}

# count (kas_ieskoma, masyvas)
sub count{
    my $i=0;
    $_ eq $_[0] and $i++ for @_;
return --$i
}

#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

#    <>=~/ /;
#    <>=~/ (\d+) /;
#    <>=~/ (\d+) (\d+) /;

@_=<>;
chomp @_;
shift @_;

s/-//g for @_;

for (@_){
	if (/^\d{6}$/){
		@n=split//;
		$f=shift @n;
		$nT=$nP=0;
		for $i(@n){
			$f!=$i and $nT++;
			$i>=$f and $nP++;
			$f=$i;
			}
		$nT && $nP and $_=3;
		$nT && !$nP and $_=2;
		!$nT && $nP and $_=1;
		}

	}

# print "@_\n";

for (@_){
	s/^\d+ / /;
	}

$_=join"",@_;
# print; n();

s#\d+#join"",(sort (split//,$&))#eg;
# print; n();
$j=0;
for $i(1..100){
	/1{$i}/ and $j++;
	}
s/([a-z]+)(1{$j})/(push @T,$1) and "$1"/ieg;
# print; n();
# print "@T\n";
s/1//g;

$j=0;
for $i(1..100){
	/2{$i}/ and $j++;
	}
s/([a-z]+)(2{$j})/(push @P,$1) and "$1"/ieg;
# print; n();
# print "@P\n";
s/2//g;

$j=0;
for $i(1..100){
	/3{$i}/ and $j++;
	}
s/([a-z]+)(3{$j})/(push @M,$1) and "$1"/ieg;
# print; n();
# print "@M\n";
s/3//g;

print "If you want to call a taxi, you should call: ",(join", ",@T),".\n";
print "If you want to order a pizza, you should call: ",(join", ",@P),".\n";
print "If you want to go to a cafe with a wonderful girl, you should call: ",(join", ",@M),".\n";

#***********SUBS************

sub num {$a <=> $b}
sub num_rev {$b <=> $a}
sub rev {$b cmp $a}

sub p{print}
sub n{print "\n"}
sub pn{p,n}
sub pn_mas {pn for @_}

# Transpose "charbox"
sub transpose{
    $i=@m=@_;
    chomp @m;
    while ($i--){
        $t[$i]=~s/$/chop/e for @m
    }
return @t
}

# Transpose "value sets"
sub transpose_space{
    my @t;
    for (@_){
        my $j=0;
        s/\d+/($t[$j++].="$& ")?$&:$&/eg;
        }
    chop @t;
return @t
}

sub div{
    my ($n, $k)=@_;
return ($n - $n % $k) / $k
}

sub uniq{
    my @m=sort @_;
    push @u, my $i=shift @m;
    for (@m){
        $i eq $_ or push @u, $_;
        $i=$_;
        }
return @u
}

sub max{
    my $max=shift;
    $max<$_ and $max=$_ for @_;
return $max
}

sub min{
    my $min=shift;
    $min>$_ and $min=$_ for @_;
return $min
}

# count (kas_ieskoma, masyvas)
sub count{
    my $i=0;
    $_ eq $_[0] and $i++ for @_;
return --$i
}

#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

#    <>=~/ /;
#    <>=~/ (\d+) /;
#    <>=~/ (\d+) (\d+) /;

@_=<>;
chomp @_;
shift @_;

s/-//g for @_;

for (@_){
	if (/^\d{6}$/){
		@n=split//;
		$f=shift @n;
		$nT=$nP=0;
		for $i(@n){
			$f!=$i and $nT++;
			$i>=$f and $nP++;
			$f=$i;
			}
		$nT && $nP and $_=3;
		$nT && !$nP and $_=2;
		!$nT && $nP and $_=1;
		}

	}

# print "@_\n";

for (@_){
	s/^\d+ / /;
	}

$_=join"",@_;
# print; n();

$j=0;
for $i(1..100){
	/1{$i}/ and $j++;
	}
s/([a-z]+)(\d*?1{$j})/(push @T,$1) and "$1"."$2"/ieg;
# print; n();
# print "@T\n";

$j=0;
for $i(1..100){
	/2{$i}/ and $j++;
	}
s/([a-z]+)(\d*?2{$j})/(push @P,$1) and "$1"."$2"/ieg;
# print; n();
# print "@P\n";

$j=0;
for $i(1..100){
	/3{$i}/ and $j++;
	}
s/([a-z]+)(\d*?3{$j})/(push @M,$1) and "$1"."$2"/ieg;
# print; n();
# print "@M\n";

print "If you want to call a taxi, you should call: ",(join", ",@T),".\n";
print "If you want to order a pizza, you should call: ",(join", ",@P),".\n";
print "If you want to go to a cafe with a wonderful girl, you should call: ",(join", ",@M),".\n";

#***********SUBS************

sub num {$a <=> $b}
sub num_rev {$b <=> $a}
sub rev {$b cmp $a}

sub p{print}
sub n{print "\n"}
sub pn{p,n}
sub pn_mas {pn for @_}

# Transpose "charbox"
sub transpose{
    $i=@m=@_;
    chomp @m;
    while ($i--){
        $t[$i]=~s/$/chop/e for @m
    }
return @t
}

# Transpose "value sets"
sub transpose_space{
    my @t;
    for (@_){
        my $j=0;
        s/\d+/($t[$j++].="$& ")?$&:$&/eg;
        }
    chop @t;
return @t
}

sub div{
    my ($n, $k)=@_;
return ($n - $n % $k) / $k
}

sub uniq{
    my @m=sort @_;
    push @u, my $i=shift @m;
    for (@m){
        $i eq $_ or push @u, $_;
        $i=$_;
        }
return @u
}

sub max{
    my $max=shift;
    $max<$_ and $max=$_ for @_;
return $max
}

sub min{
    my $min=shift;
    $min>$_ and $min=$_ for @_;
return $min
}

# count (kas_ieskoma, masyvas)
sub count{
    my $i=0;
    $_ eq $_[0] and $i++ for @_;
return --$i
}

#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

#    <>=~/ /;
#    <>=~/ (\d+) /;
#    <>=~/ (\d+) (\d+) /;

@_=<>;
chomp @_;
shift @_;

s/-//g for @_;

for (@_){
	if (/^\d{6}$/){
		@n=split//;
		$f=shift @n;
		$nT=$nP=0;
		for $i(@n){
			$f!=$i and $nT++;
			$i>=$f and $nP++;
			$f=$i;
			}
		$nT && $nP and $_=3;
		$nT && !$nP and $_=2;
		!$nT && $nP and $_=1;
		}

	}

# print "@_\n";

for (@_){
	s/^\d+ / /;
	}

$_=join"",@_;
# print; n();

s#\d+#join"",(sort (split//,$&))#eg;
# print; n();
$j=0;
for $i(1..100){
	/1{$i}/ and $j++;
	}
s/([a-z]+)(1{$j})/(push @T,$1) and "$1"/ieg;
# print; n();
# print "@T\n";

$j=0;
for $i(1..100){
	/2{$i}/ and $j++;
	}
s/([a-z]+)(2{$j})/(push @P,$1) and "$1"/ieg;
# print; n();
# print "@P\n";

$j=0;
for $i(1..100){
	/3{$i}/ and $j++;
	}
s/([a-z]+)(3{$j})/(push @M,$1) and "$1"/ieg;
# print; n();
# print "@M\n";

print "If you want to call a taxi, you should call: ",(join", ",@T),".\n";
print "If you want to order a pizza, you should call: ",(join", ",@P),".\n";
print "If you want to go to a cafe with a wonderful girl, you should call: ",(join", ",@M),".\n";

#***********SUBS************

sub num {$a <=> $b}
sub num_rev {$b <=> $a}
sub rev {$b cmp $a}

sub p{print}
sub n{print "\n"}
sub pn{p,n}
sub pn_mas {pn for @_}

# Transpose "charbox"
sub transpose{
    $i=@m=@_;
    chomp @m;
    while ($i--){
        $t[$i]=~s/$/chop/e for @m
    }
return @t
}

# Transpose "value sets"
sub transpose_space{
    my @t;
    for (@_){
        my $j=0;
        s/\d+/($t[$j++].="$& ")?$&:$&/eg;
        }
    chop @t;
return @t
}

sub div{
    my ($n, $k)=@_;
return ($n - $n % $k) / $k
}

sub uniq{
    my @m=sort @_;
    push @u, my $i=shift @m;
    for (@m){
        $i eq $_ or push @u, $_;
        $i=$_;
        }
return @u
}

sub max{
    my $max=shift;
    $max<$_ and $max=$_ for @_;
return $max
}

sub min{
    my $min=shift;
    $min>$_ and $min=$_ for @_;
return $min
}

# count (kas_ieskoma, masyvas)
sub count{
    my $i=0;
    $_ eq $_[0] and $i++ for @_;
return --$i
}

#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

#    <>=~/ /;
#    <>=~/ (\d+) /;
#    <>=~/ (\d+) (\d+) /;

@_=<>;
chomp @_;
shift @_;

s/-//g for @_;

for (@_){
	if (/^\d{6}$/){
		@n=split//;
		$f=shift @n;
		$nT=$nP=0;
		for $i(@n){
			$f!=$i and $nT++;
			$i>=$f and $nP++;
			$f=$i;
			}
		$nT && $nP and $_=3;
		$nT && !$nP and $_=2;
		!$nT && $nP and $_=1;
		}

	}

# print "@_\n";

for (@_){
	s/^\d+ //;
	}

$_=join"",@_;
# print; n();

$j=0;
for $i(1..100){
	/1{$i}/ and $j++;
	}
s/([a-z]+)(\d*?1{$j})/(push @T,$1) and "$1"."$2"/ieg;
# print; n();
# print "@T\n";

$j=0;
for $i(1..100){
	/2{$i}/ and $j++;
	}
s/([a-z]+)(\d*?2{$j})/(push @P,$1) and "$1"."$2"/ieg;
# print; n();
# print "@P\n";

$j=0;
for $i(1..100){
	/3{$i}/ and $j++;
	}
s/([a-z]+)(\d*?3{$j})/(push @M,$1) and "$1"."$2"/ieg;
# print; n();
# print "@M\n";

print "If you want to call a taxi, you should call: ",(join", ",@T),".\n";
print "If you want to order a pizza, you should call: ",(join", ",@P),".\n";
print "If you want to go to a cafe with a wonderful girl, you should call: ",(join", ",@M),".\n";

#***********SUBS************

sub num {$a <=> $b}
sub num_rev {$b <=> $a}
sub rev {$b cmp $a}

sub p{print}
sub n{print "\n"}
sub pn{p,n}
sub pn_mas {pn for @_}

# Transpose "charbox"
sub transpose{
    $i=@m=@_;
    chomp @m;
    while ($i--){
        $t[$i]=~s/$/chop/e for @m
    }
return @t
}

# Transpose "value sets"
sub transpose_space{
    my @t;
    for (@_){
        my $j=0;
        s/\d+/($t[$j++].="$& ")?$&:$&/eg;
        }
    chop @t;
return @t
}

sub div{
    my ($n, $k)=@_;
return ($n - $n % $k) / $k
}

sub uniq{
    my @m=sort @_;
    push @u, my $i=shift @m;
    for (@m){
        $i eq $_ or push @u, $_;
        $i=$_;
        }
return @u
}

sub max{
    my $max=shift;
    $max<$_ and $max=$_ for @_;
return $max
}

sub min{
    my $min=shift;
    $min>$_ and $min=$_ for @_;
return $min
}

# count (kas_ieskoma, masyvas)
sub count{
    my $i=0;
    $_ eq $_[0] and $i++ for @_;
return --$i
}


A number $$$a_2$$$ is said to be the arithmetic mean of two numbers $$$a_1$$$ and $$$a_3$$$, if the following condition holds: $$$a_1 + a_3 = 2\cdot a_2$$$. We define an arithmetic mean deviation of three numbers $$$a_1$$$, $$$a_2$$$ and $$$a_3$$$ as follows: $$$d(a_1, a_2, a_3) = |a_1 + a_3 - 2 \cdot a_2|$$$.Arithmetic means a lot to Jeevan. He has three numbers $$$a_1$$$, $$$a_2$$$ and $$$a_3$$$ and he wants to minimize the arithmetic mean deviation $$$d(a_1, a_2, a_3)$$$. To do so, he can perform the following operation any number of times (possibly zero):  Choose $$$i, j$$$ from $$$\{1, 2, 3\}$$$ such that $$$i \ne j$$$ and increment $$$a_i$$$ by $$$1$$$ and decrement $$$a_j$$$ by $$$1$$$ Help Jeevan find out the minimum value of $$$d(a_1, a_2, a_3)$$$ that can be obtained after applying the operation any number of times.

The first line contains a single integer $$$t$$$ $$$(1 \le t \le 5000)$$$  — the number of test cases. The first and only line of each test case contains three integers $$$a_1$$$, $$$a_2$$$ and $$$a_3$$$ $$$(1 \le a_1, a_2, a_3 \le 10^{8})$$$.

For each test case, output the minimum value of $$$d(a_1, a_2, a_3)$$$ that can be obtained after applying the operation any number of times.

NoteNote that after applying a few operations, the values of $$$a_1$$$, $$$a_2$$$ and $$$a_3$$$ may become negative.In the first test case, $$$4$$$ is already the Arithmetic Mean of $$$3$$$ and $$$5$$$.$$$d(3, 4, 5) = |3 + 5 - 2 \cdot 4| = 0$$$In the second test case, we can apply the following operation:$$$(2, 2, 6)$$$ $$$\xrightarrow[\text{increment $$$a_2$$$}]{\text{decrement $$$a_1$$$}}$$$ $$$(1, 3, 6)$$$$$$d(1, 3, 6) = |1 + 6 - 2 \cdot 3| = 1$$$It can be proven that answer can not be improved any further.In the third test case, we can apply the following operations:$$$(1, 6, 5)$$$ $$$\xrightarrow[\text{increment $$$a_3$$$}]{\text{decrement $$$a_2$$$}}$$$ $$$(1, 5, 6)$$$ $$$\xrightarrow[\text{increment $$$a_1$$$}]{\text{decrement $$$a_2$$$}}$$$ $$$(2, 4, 6)$$$$$$d(2, 4, 6) = |2 + 6 - 2 \cdot 4| = 0$$$


A string t is called an anagram of the string s, if it is possible to rearrange letters in t so that it is identical to the string s. For example, the string "aab" is an anagram of the string "aba" and the string "aaa" is not.The string t is called a substring of the string s if it can be read starting from some position in the string s. For example, the string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba".You are given a string s, consisting of lowercase Latin letters and characters "?". You are also given a string p, consisting of lowercase Latin letters only. Let's assume that a string is good if you can obtain an anagram of the string p from it, replacing the "?" characters by Latin letters. Each "?" can be replaced by exactly one character of the Latin alphabet. For example, if the string p = «aba», then the string "a??" is good, and the string «?bc» is not. Your task is to find the number of good substrings of the string s (identical substrings must be counted in the answer several times).

The first line is non-empty string s, consisting of no more than 105 lowercase Latin letters and characters "?". The second line is non-empty string p, consisting of no more than 105 lowercase Latin letters. Please note that the length of the string p can exceed the length of the string s.

Print the single number representing the number of good substrings of string s. Two substrings are considered different in their positions of occurrence are different. Thus, if some string occurs several times, then it should be counted the same number of times.

NoteConsider the first sample test. Here the string s has two good substrings: "b??" (after we replace the question marks we get "baa"), "???" (after we replace the question marks we get "baa").Let's consider the second sample test. Here the string s has two good substrings: "ab?" ("?" can be replaced by "c"), "b?c" ("?" can be replaced by "a").

#!/bin/bash/perl
$input=<>;
@input1=split(" ",$input);
$refer=$input1[0];
$input=<>;
@input1=split(" ",$input);
$main=$input1[0];

if(length($refer)<length($main)){
	print "0";
}

else{
	@mainarr=split("",$main);
	@mainarr=sort(@mainarr);

	#now create hash for main string for later
	#occurence checking
	%mainhash=NULL;
	for($i=0;$i<@mainarr;++$i){
		if($mainhash{$mainarr[$i]}==NULL){
			#then add it
			$mainhash{$mainarr[$i]}=1;
		}
		else{
			#then increase its value
			++$mainhash{$mainarr[$i]};
		}
	} #O_n

	#now take a substring of length of main string
	#and hash it. make changes to hash and keep continuing
	@newsubstr=split("",$refer);
	@substr1=split("",substr($refer,0,@mainarr));
	$ques=0; $tot=0; $match=0;
	%hash=NULL;
	for($i=0;$i<@substr1;++$i){
		$temp=$hash{$substr1[$i]};
		if($temp==NULL){ #entry not present
			#check if its a '?'
			if($substr1[$i] eq '?'){
				++$ques;
			}
			#else add its entry
			else{
				$hash{$substr1[$i]}=1;
			}
		}
		else{ #entry present
			++$hash{$substr1[$i]};
		}
	} #init for ends

	#match with initial hash created and increment things
	%outerhash=%hash;
	for($i=0;$i<@mainarr;++$i){
		$temp=$hash{$mainarr[$i]};
		if($temp!=NULL && $temp>0){
			--$hash{$mainarr[$i]};
			++$match;
		}
	}

	if($ques+$match == @mainarr){
		++$tot;
	}

	#reset hash value
	%hash = %outerhash;

	for($i=1;$i<=length($refer)-@mainarr;++$i){
		#first reset outer values

		#remove previous entry of index $i-1
		$previous=$i-1;

		if($newsubstr[$previous] eq '?'){ #if its '?' then remove entry
			--$ques;
		}
		else{ #then it has to have an entry in hash, remove it
			--$hash{$newsubstr[$previous]};
		}

		#add new index in hash or '?' entry for index $i+@mainarr-1

		if($newsubstr[$i+@mainarr-1] eq '?'){
			#add entry for '?'
			++$ques;
		}
		else{
			#then add entry in hash
			$temp = $hash{$newsubstr[$i+@mainarr-1]};
			if($temp==NULL){
				$hash{$newsubstr[$i+@mainarr-1]}=1;
			}
			else{
				++$hash{$newsubstr[$i+@mainarr-1]};
			}
		}

		$match=0;
		#now compare with entries in mainhash

		if($ques < @mainarr){
			for($alpha='a';$alpha ne'aa' &&($match+$ques < @mainarr);++$alpha){
				$temp=$mainhash{$alpha};
				$temp1=$hash{$alpha};
				if(($temp!=NULL) && ($temp>0)){
					if($temp1!=NULL && $temp1>0){
						if($temp == $temp1){
							$match=$match+$temp;
						}
						elsif($temp < $temp1){
							#more residue inside, will always clash with
							#some cases, hence exit
							$alpha='z';
						}
						else{
							$match = $match+$temp1;
						}
					}
					else{
						if($ques<=0){
							#req shall not be met in future
							$alpha='z';
						}
					}
				}
				elsif($temp1 != NULL && $temp1 >0){
					#some residual value is there, that shall
					#always reduce chances of being selected
					#hence exit
					$alpha='z';
				}

			}#O_(1)
		}

		if($match+$ques == @mainarr){
				++$tot;
			}
	}#O_26n

	print "$tot";

}#else all other cases

#!/bin/bash/perl
$input=<>;
@input1=split(" ",$input);
$refer=$input1[0];
$input=<>;
@input1=split(" ",$input);
$main=$input1[0];

if(length($refer)<length($main)){
	print "0";
}

else{
	@mainarr=split("",$main);
	@mainarr=sort(@mainarr);

	#now create hash for main string for later
	#occurence checking
	%mainhash=NULL;
	for($i=0;$i<@mainarr;++$i){
		if($mainhash{$mainarr[$i]}==NULL){
			#then add it
			$mainhash{$mainarr[$i]}=1;
		}
		else{
			#then increase its value
			++$mainhash{$mainarr[$i]};
		}
	} #O_n

	#now take a substring of length of main string
	#and hash it. make changes to hash and keep continuing
	@newsubstr=split("",$refer);
	@substr1=split("",substr($refer,0,@mainarr));
	$ques=0; $tot=0; $match=0;
	%hash=NULL;
	for($i=0;$i<@substr1;++$i){
		$temp=$hash{$substr1[$i]};
		if($temp==NULL){ #entry not present
			#check if its a '?'
			if($substr1[$i] eq '?'){
				++$ques;
			}
			#else add its entry
			else{
				$hash{$substr1[$i]}=1;
			}
		}
		else{ #entry present
			++$hash{$substr1[$i]};
		}
	} #init for ends

	#match with initial hash created and increment things
	%outerhash=%hash;
	for($i=0;$i<@mainarr;++$i){
		$temp=$hash{$mainarr[$i]};
		if($temp!=NULL && $temp>0){
			--$hash{$mainarr[$i]};
			++$match;
		}
	}

	if($ques+$match == @mainarr){
		++$tot;
	}

	#reset hash value
	%hash = %outerhash;

	for($i=1;$i<=length($refer)-@mainarr;++$i){
		#first reset outer values

		#remove previous entry of index $i-1
		$previous=$i-1;

		if($newsubstr[$previous] eq '?'){ #if its '?' then remove entry
			--$ques;
		}
		else{ #then it has to have an entry in hash, remove it
			--$hash{$newsubstr[$previous]};
		}

		#add new index in hash or '?' entry for index $i+@mainarr-1

		if($newsubstr[$i+@mainarr-1] eq '?'){
			#add entry for '?'
			++$ques;
		}
		else{
			#then add entry in hash
			$temp = $hash{$newsubstr[$i+@mainarr-1]};
			if($temp==NULL){
				$hash{$newsubstr[$i+@mainarr-1]}=1;
			}
			else{
				++$hash{$newsubstr[$i+@mainarr-1]};
			}
		}

		$match=0;
		#now compare with entries in mainhash

		if($ques < @mainarr){
			for($alpha='a';$alpha ne'aa';++$alpha){
				$temp=$mainhash{$alpha};
				$temp1=$hash{$alpha};
				if(($temp!=NULL) && ($temp>0)){
					if($temp1!=NULL && $temp1>0){
						if($temp <= $temp1){
							$match=$match+$temp;
						}
						else{
							$match = $match+$temp1;
						}
					}
					else{
						if($ques<=0){
							#req shall not be met in future
							$alpha='z';
						}
					}
				}
				elsif($temp1 != NULL && $temp1 >0){
					#some residual value is there, that shall
					#always reduce chances of being selected
					#hence exit
					$alpha='z';
				}

			}#O_(1)
		}
		else{
			print "sufficient ?\n";
		}
		if($match+$ques == @mainarr){
				++$tot;
			}
	}#O_26n

	print "$tot";

}#else all other cases


You are given a rectangular grid of lattice points from (0, 0) to (n, m) inclusive. You have to choose exactly 4 different points to build a polyline possibly with self-intersections and self-touching. This polyline should be as long as possible.A polyline defined by points p1, p2, p3, p4 consists of the line segments p1 p2, p2 p3, p3 p4, and its length is the sum of the lengths of the individual line segments.

The only line of the input contains two integers n and m (0 ≤ n, m ≤ 1000). It is guaranteed that grid contains at least 4 different points.

Print 4 lines with two integers per line separated by space — coordinates of points p1, p2, p3, p4 in order which represent the longest possible polyline. Judge program compares your answer and jury's answer with 10 - 6 precision.


There is a right triangle with legs of length a and b. Your task is to determine whether it is possible to locate the triangle on the plane in such a way that none of its sides is parallel to the coordinate axes. All the vertices must have integer coordinates. If there exists such a location, you have to output the appropriate coordinates of vertices.

The first line contains two integers a, b (1 ≤ a, b ≤ 1000), separated by a single space.

In the first line print either "YES" or "NO" (without the quotes) depending on whether the required location exists. If it does, print in the next three lines three pairs of integers — the coordinates of the triangle vertices, one pair per line. The coordinates must be integers, not exceeding 109 in their absolute value.


DZY loves chessboard, and he enjoys playing with it.He has a chessboard of n rows and m columns. Some cells of the chessboard are bad, others are good. For every good cell, DZY wants to put a chessman on it. Each chessman is either white or black. After putting all chessmen, DZY wants that no two chessmen with the same color are on two adjacent cells. Two cells are adjacent if and only if they share a common edge.You task is to find any suitable placement of chessmen on the given chessboard.

The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 100). Each of the next n lines contains a string of m characters: the j-th character of the i-th string is either "." or "-". A "." means that the corresponding cell (in the i-th row and the j-th column) is good, while a "-" means it is bad.

Output must contain n lines, each line must contain a string of m characters. The j-th character of the i-th string should be either "W", "B" or "-". Character "W" means the chessman on the cell is white, "B" means it is black, "-" means the cell is a bad cell. If multiple answers exist, print any of them. It is guaranteed that at least one answer exists.

NoteIn the first sample, DZY puts a single black chessman. Of course putting a white one is also OK.In the second sample, all 4 cells are good. No two same chessmen share an edge in the sample output.In the third sample, no good cells are adjacent. So you can just put 3 chessmen, no matter what their colors are.


Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divides into four triangle plants: three of them will be directed in the same direction as the parent plant, and one of them will be directed in the opposite direction. Then each year the process repeats. The figure below illustrates this process.  Help the dwarfs find out how many triangle plants that point "upwards" will be in n years.

The first line contains a single integer n (0 ≤ n ≤ 1018) — the number of full years when the plant grew. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.

Print a single integer — the remainder of dividing the number of plants that will point "upwards" in n years by 1000000007 (109 + 7).

NoteThe first test sample corresponds to the second triangle on the figure in the statement. The second test sample corresponds to the third one.

#!/usr/bin/perl
use strict;
use warnings;
use bigint; # Hope for the best! Yeah, it's rather slow :-(

main();

sub main {
    my $years = <>;
    if ($years == 0) {
        print 1;
        goto end;
    }
    my $mod = 1000000007;
    my $h_amount = mpow(2, $years-1, $mod);
    my $last = ($h_amount * 2) % $mod;
    my $result = ((1 + $last) * $h_amount) % $mod;
    print $result;
end:
}

sub mpow {
    my ($x, $n, $mod) = @_;
    my $b = 1;
    while ($n > 0) {
        if ($n % 2) {
            $n--;
            $b *= $x;
            $b = $b % $mod;
        } else {
            $n /= 2;
            $x *= $x;
            $x = $x % $mod;
        }
    }
    return $b % $mod;
}

#!/usr/bin/perl
use strict;
use warnings;
use bigint; # Hope for the best! Yeah, it's rather slow :-(

main();

sub main {
    my $years = <>;
    if (! $years) {
        print 1;
        goto end;
    }
    my $mod = 1000000007;
    my $h_amount = mpow(2, $years-1, $mod);
    my $last = ($h_amount * 2) % $mod;
    my $result = ((1 + $last) * $h_amount) % $mod;
    print $result;
end:
}

sub mpow {
    my ($x, $n, $mod) = @_;
    my $b = 1;
    while ($n > 0) {
        if ($n % 2) {
            $n--;
            $b *= $x;
            $b = $b % $mod;
        } else {
            $n /= 2;
            $x *= $x;
            $x = $x % $mod;
        }
    }
    return $b % $mod;
}


There are $$$n$$$ trees in a park, numbered from $$$1$$$ to $$$n$$$. The initial height of the $$$i$$$-th tree is $$$h_i$$$.You want to water these trees, so they all grow to the same height.The watering process goes as follows. You start watering trees at day $$$1$$$. During the $$$j$$$-th day you can:   Choose a tree and water it. If the day is odd (e.g. $$$1, 3, 5, 7, \dots$$$), then the height of the tree increases by $$$1$$$. If the day is even (e.g. $$$2, 4, 6, 8, \dots$$$), then the height of the tree increases by $$$2$$$.  Or skip a day without watering any tree. Note that you can't water more than one tree in a day. Your task is to determine the minimum number of days required to water the trees so they grow to the same height.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 2 \cdot 10^4$$$) — the number of test cases. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 3 \cdot 10^5$$$) — the number of trees. The second line of the test case contains $$$n$$$ integers $$$h_1, h_2, \ldots, h_n$$$ ($$$1 \le h_i \le 10^9$$$), where $$$h_i$$$ is the height of the $$$i$$$-th tree. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$ ($$$\sum n \le 3 \cdot 10^5$$$).

For each test case, print one integer — the minimum number of days required to water the trees, so they grow to the same height.

NoteConsider the first test case of the example. The initial state of the trees is $$$[1, 2, 4]$$$.  During the first day, let's water the first tree, so the sequence of heights becomes $$$[2, 2, 4]$$$;  during the second day, let's water the second tree, so the sequence of heights becomes $$$[2, 4, 4]$$$;  let's skip the third day;  during the fourth day, let's water the first tree, so the sequence of heights becomes $$$[4, 4, 4]$$$. Thus, the answer is $$$4$$$.

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

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

my @h;

while( $testcase -- > 0 ){
  my ($n) = map { $_ - 0 } split(/\s+/,<STDIN>);
  @h = map { $_ - 0 } split(/\s+/,<STDIN>);
  my $maxh = &max(@h);
  my $r = &min( &calc($maxh,$n) , &calc($maxh+1,$n) );
  $r = &min( $r, &calc($maxh+2,$n) );
  print "$r\n";
}

exit(0);

sub calc {
  my $mh = shift;
  my $n = shift;
  my $l1 = 0; my $l2 = 0;
  for(my $i=0;$i<$n;$i++){
    my $v = $mh - $h[$i];
    $l1 += ($v % 2);
    $l2 += ($v / 2);
  }
  my $days = &max((2*$l1-1),$l2*2);
  return $days if $l1 >= $l2;
  my $x = ($l2 - $l1)/3;
  for(my $j=$x-2;$j<=$x+2;$j++){
    next if $j<0;
    my $l2_ = $l2 - $j;
    my $l1_ = $l1 + 2*$j;
    next if $l2_ < 0;
    my $minv = &max( $l2_*2 , $l1_*2-1);
    $days = &min($days, $minv);
  }
  return $days;
}

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

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

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

my @h;

while( $testcase -- > 0 ){
  my ($n) = map { $_ - 0 } split(/\s+/,<STDIN>);
  @h = map { $_ - 0 } split(/\s+/,<STDIN>);
  my $maxh = &max(@h);
  my $r = &min( &calc($maxh,$n) , &calc($maxh+1,$n) );
  $r = &min( $r, &calc($maxh+2,$n) );
  print "$r\n";
}

exit(0);

sub calc {
  my $mh = shift;
  my $n = shift;
  my $l1 = 0; my $l2 = 0;
  for(my $i=0;$i<$n;$i++){
    my $v = $mh - $h[$i];
    $l1 += ($v % 2);
    $l2 += ($v / 2);
  }
  my $days = &max((2*$l1-1),$l2*2);
  if( $l2 - 1 > $l1 ){
    my $x = ($l2 - $l1)/3;
    for(my $j=$x-2;$j<=$x+2;$j++){
      next if $j<0;
      my $l2_ = $l2 - $x;
      my $l1_ = $l1 + 2*$x;
      next if $l2_ < 1;
      my $minv = &max( $l2_*2 , $l1_*2-1);
      $days = &min($days, $minv);
    }
  } elsif( $l1 == $l2 ){
    $days = &min($days,($l1+$l2));
  } elsif( $l1 > $l2 ){
    $days = &min($days,(2*$l1-1));
  } else {
    $days = &min($days,(2*$l2));
  }
  return $days;
}

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

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

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

my @h;

while( $testcase -- > 0 ){
  my ($n) = map { $_ - 0 } split(/\s+/,<STDIN>);
  @h = map { $_ - 0 } split(/\s+/,<STDIN>);
  my $maxh = &max(@h);
  my $r = &min( &calc($maxh,$n) , &calc($maxh+1,$n) );
  $r = &min( $r, &calc($maxh+2,$n) );
  print "$r\n";
}

exit(0);

sub calc {
  my $mh = shift;
  my $n = shift;
  my $l1 = 0; my $l2 = 0;
  for(my $i=0;$i<$n;$i++){
    my $v = $mh - $h[$i];
    $l1 += ($v % 2);
    $l2 += ($v / 2);
  }
  my $days = &max((2*$l1-1),$l2*2);
  if( $l2 - 1 > $l1 ){
    my $x = ($l2 - $l1)/3;
    for(my $j=$x-2;$j<=$x+2;$j++){
      next if $j<0;
      my $l2_ = $l2 - $x;
      my $l1_ = $l1 + 2*$x;
      next if $l2 < 1;
      my $minv = &max( $l2_*2 , $l1_*2-1);
      $days = &min($days, $minv);
    }
  } elsif( $l1 == $l2 ){
    $days = &min($days,($l1+$l2));
  } elsif( $l1 > $l2 ){
    $days = &min($days,(2*$l1-1));
  } else {
    $days = &min($days,(2*$l2));
  }
  return $days;
}

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

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

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

my @h;

while( $testcase -- > 0 ){
  my ($n) = map { $_ - 0 } split(/\s+/,<STDIN>);
  @h = map { $_ - 0 } split(/\s+/,<STDIN>);
  my $maxh = &max(@h);
  my $r = &min( &calc($maxh,$n) , &calc($maxh+1,$n) );
  print "$r\n";
}

exit(0);

sub calc {
  my $mh = shift;
  my $n = shift;
  my $l1 = 0; my $l2 = 0;
  for(my $i=0;$i<$n;$i++){
    my $v = $mh - $h[$i];
    $l1 += ($v % 2);
    $l2 += ($v / 2);
  }
  my $days = &max((2*$l1-1),$l2*2);
  if( $l2 - 1 > $l1 ){
    my $x = (2*$l2 - 2*$l1 + 1)/6;
    for(my $j=$x-1;$j<=$x+1;$j++){
      next if $x<0;
      my $l2_ = $l2 - $x;
      my $l1_ = $l1 + 2*$x;
      next if $l2 < 1;
      my $minv = &max( $l2_*2 , $l1_*2-1);
      $days = &min($dats, $minv);
    }
  } elsif( $l1 == $l2 ){
    $days = &min($days,($l1+$l2));
  } elsif( $l1 > $l2 ){
    $days = &min($days,(2*$l1-1));
  } else {
    $days = &min($days,(2*$l2));
  }
  return $days;
}

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


Ilya plays a card game by the following rules.A player has several cards. Each card contains two non-negative integers inscribed, one at the top of the card and one at the bottom. At the beginning of the round the player chooses one of his cards to play it. If the top of the card contains number ai, and the bottom contains number bi, then when the player is playing the card, he gets ai points and also gets the opportunity to play additional bi cards. After the playing the card is discarded.More formally: let's say that there is a counter of the cards that can be played. At the beginning of the round the counter equals one. When a card is played, the counter decreases by one for the played card and increases by the number bi, which is written at the bottom of the card. Then the played card is discarded. If after that the counter is not equal to zero, the player gets the opportunity to play another card from the remaining cards. The round ends when the counter reaches zero or the player runs out of cards.Of course, Ilya wants to get as many points as possible. Can you determine the maximum number of points he can score provided that you know his cards?

The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of cards Ilya has. Each of the next n lines contains two non-negative space-separated integers — ai and bi (0 ≤ ai, bi ≤ 104) — the numbers, written at the top and the bottom of the i-th card correspondingly.

Print the single number — the maximum number of points you can score in one round by the described rules.

NoteIn the first sample none of two cards brings extra moves, so you should play the one that will bring more points.In the second sample you should first play the third card that doesn't bring any points but lets you play both remaining cards.

#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

#    <>=~/ /;
#    <>=~/ (\d+) /;
#    <>=~/ (\d+) (\d+) /;

$ats=0; $i=1;
<>;
while(<>){
	chomp;
	($a,$b)=split/ /;
	$b? ($ats+=$a,$i+=$b-1):(push @_,$a);
	}
@_=sort num @_;
while ($i--){$ats+=pop@_}
print $ats;

#***********SUBS************

sub num {$a <=> $b}
sub num_rev {$b <=> $a}
sub rev {$b cmp $a}

sub p{print}
sub n{print "\n"}
sub pn{p,n}
sub pn_mas {pn for @_}

# Transpose "charbox"
sub transpose{
    $i=@m=@_;
    chomp @m;
    while ($i--){
        $t[$i]=~s/$/chop/e for @m
    }
return @t
}

# Transpose "value sets"
sub transpose_space{
    my @t;
    for (@_){
        my $j=0;
        s/\d+/($t[$j++].="$& ")?$&:$&/eg;
        }
    chop @t;
return @t
}

sub div{
    my ($n, $k)=@_;
return ($n - $n % $k) / $k
}

sub uniq{
    my @m=sort @_;
    push @u, my $i=shift @m;
    for (@m){
        $i eq $_ or push @u, $_;
        $i=$_;
        }
return @u
}

sub max{
    my $max=shift;
    $max<$_ and $max=$_ for @_;
return $max
}

sub min{
    my $min=shift;
    $min>$_ and $min=$_ for @_;
return $min
}

# count (kas_ieskoma, masyvas)
sub count{
    my $i=0;
    $_ eq $_[0] and $i++ for @_;
return --$i
}

#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

#    <>=~/ /;
#    <>=~/ (\d+) /;
#    <>=~/ (\d+) (\d+) /;

$ats=0; $i=1;
<>;
while(<>){
	chomp;
	($a,$b)=split/ /;
	$b or push @_,$a;
	$b and ($ats+=$a,$i+=$b-1);
	}
@_=sort num @_;
while ($i--){$ats+=pop@_}
print $ats;

#***********SUBS************

sub num {$a <=> $b}
sub num_rev {$b <=> $a}
sub rev {$b cmp $a}

sub p{print}
sub n{print "\n"}
sub pn{p,n}
sub pn_mas {pn for @_}

# Transpose "charbox"
sub transpose{
    $i=@m=@_;
    chomp @m;
    while ($i--){
        $t[$i]=~s/$/chop/e for @m
    }
return @t
}

# Transpose "value sets"
sub transpose_space{
    my @t;
    for (@_){
        my $j=0;
        s/\d+/($t[$j++].="$& ")?$&:$&/eg;
        }
    chop @t;
return @t
}

sub div{
    my ($n, $k)=@_;
return ($n - $n % $k) / $k
}

sub uniq{
    my @m=sort @_;
    push @u, my $i=shift @m;
    for (@m){
        $i eq $_ or push @u, $_;
        $i=$_;
        }
return @u
}

sub max{
    my $max=shift;
    $max<$_ and $max=$_ for @_;
return $max
}

sub min{
    my $min=shift;
    $min>$_ and $min=$_ for @_;
return $min
}

# count (kas_ieskoma, masyvas)
sub count{
    my $i=0;
    $_ eq $_[0] and $i++ for @_;
return --$i
}

#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

#    <>=~/ /;
#    <>=~/ (\d+) /;
#    <>=~/ (\d+) (\d+) /;

$ats=0; $i=1;
<>;
while(<>=~/ /){
	$'+0 or push @_,$`;
	$'+0 and ($ats+=$`,$i+=$'-1);
	}
@_=sort num @_;
while ($i--){$ats+=pop@_}
print $ats;

#***********SUBS************

sub num {$a <=> $b}
sub num_rev {$b <=> $a}
sub rev {$b cmp $a}

sub p{print}
sub n{print "\n"}
sub pn{p,n}
sub pn_mas {pn for @_}

# Transpose "charbox"
sub transpose{
    $i=@m=@_;
    chomp @m;
    while ($i--){
        $t[$i]=~s/$/chop/e for @m
    }
return @t
}

# Transpose "value sets"
sub transpose_space{
    my @t;
    for (@_){
        my $j=0;
        s/\d+/($t[$j++].="$& ")?$&:$&/eg;
        }
    chop @t;
return @t
}

sub div{
    my ($n, $k)=@_;
return ($n - $n % $k) / $k
}

sub uniq{
    my @m=sort @_;
    push @u, my $i=shift @m;
    for (@m){
        $i eq $_ or push @u, $_;
        $i=$_;
        }
return @u
}

sub max{
    my $max=shift;
    $max<$_ and $max=$_ for @_;
return $max
}

sub min{
    my $min=shift;
    $min>$_ and $min=$_ for @_;
return $min
}

# count (kas_ieskoma, masyvas)
sub count{
    my $i=0;
    $_ eq $_[0] and $i++ for @_;
return --$i
}

#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

#    <>=~/ /;
#    <>=~/ (\d+) /;
#    <>=~/ (\d+) (\d+) /;

$ats=0; $i=1;
<>;
while(<>){
	chomp;
	($a,$b)=split/ /;
	$b? ($ats+=$a,$i+=$b-1):(push @_,$a);
	}
@_=sort {$a <=> $b} @_;
while ($i--){$ats+=pop@_}
print $ats;

#***********SUBS************

sub num {$a <=> $b}
sub num_rev {$b <=> $a}
sub rev {$b cmp $a}

sub p{print}
sub n{print "\n"}
sub pn{p,n}
sub pn_mas {pn for @_}

# Transpose "charbox"
sub transpose{
    $i=@m=@_;
    chomp @m;
    while ($i--){
        $t[$i]=~s/$/chop/e for @m
    }
return @t
}

# Transpose "value sets"
sub transpose_space{
    my @t;
    for (@_){
        my $j=0;
        s/\d+/($t[$j++].="$& ")?$&:$&/eg;
        }
    chop @t;
return @t
}

sub div{
    my ($n, $k)=@_;
return ($n - $n % $k) / $k
}

sub uniq{
    my @m=sort @_;
    push @u, my $i=shift @m;
    for (@m){
        $i eq $_ or push @u, $_;
        $i=$_;
        }
return @u
}

sub max{
    my $max=shift;
    $max<$_ and $max=$_ for @_;
return $max
}

sub min{
    my $min=shift;
    $min>$_ and $min=$_ for @_;
return $min
}

# count (kas_ieskoma, masyvas)
sub count{
    my $i=0;
    $_ eq $_[0] and $i++ for @_;
return --$i
}

#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

#    <>=~/ /;
#    <>=~/ (\d+) /;
#    <>=~/ (\d+) (\d+) /;

$ats=0; $i=1;
<>;
while(<>=~/ /){
	$'+0 or push @_,$`;
	$'+0 and ($ats+=$`,$i+=$');
	}
@_=sort num @_;
while ($i--){$ats+=pop@_}
print $ats;

#***********SUBS************

sub num {$a <=> $b}
sub num_rev {$b <=> $a}
sub rev {$b cmp $a}

sub p{print}
sub n{print "\n"}
sub pn{p,n}
sub pn_mas {pn for @_}

# Transpose "charbox"
sub transpose{
    $i=@m=@_;
    chomp @m;
    while ($i--){
        $t[$i]=~s/$/chop/e for @m
    }
return @t
}

# Transpose "value sets"
sub transpose_space{
    my @t;
    for (@_){
        my $j=0;
        s/\d+/($t[$j++].="$& ")?$&:$&/eg;
        }
    chop @t;
return @t
}

sub div{
    my ($n, $k)=@_;
return ($n - $n % $k) / $k
}

sub uniq{
    my @m=sort @_;
    push @u, my $i=shift @m;
    for (@m){
        $i eq $_ or push @u, $_;
        $i=$_;
        }
return @u
}

sub max{
    my $max=shift;
    $max<$_ and $max=$_ for @_;
return $max
}

sub min{
    my $min=shift;
    $min>$_ and $min=$_ for @_;
return $min
}

# count (kas_ieskoma, masyvas)
sub count{
    my $i=0;
    $_ eq $_[0] and $i++ for @_;
return --$i
}

#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

#    <>=~/ /;
#    <>=~/ (\d+) /;
#    <>=~/ (\d+) (\d+) /;

$ats=0;
<>;
while(<>=~/ /){
	$'+0 or push @_,$`;
	$'+0 and ($ats+=$`,$i+=$');
	}
@_=sort num @_;
$i or $i++;
while ($i--){$ats+=pop@_}
print $ats;

#***********SUBS************

sub num {$a <=> $b}
sub num_rev {$b <=> $a}
sub rev {$b cmp $a}

sub p{print}
sub n{print "\n"}
sub pn{p,n}
sub pn_mas {pn for @_}

# Transpose "charbox"
sub transpose{
    $i=@m=@_;
    chomp @m;
    while ($i--){
        $t[$i]=~s/$/chop/e for @m
    }
return @t
}

# Transpose "value sets"
sub transpose_space{
    my @t;
    for (@_){
        my $j=0;
        s/\d+/($t[$j++].="$& ")?$&:$&/eg;
        }
    chop @t;
return @t
}

sub div{
    my ($n, $k)=@_;
return ($n - $n % $k) / $k
}

sub uniq{
    my @m=sort @_;
    push @u, my $i=shift @m;
    for (@m){
        $i eq $_ or push @u, $_;
        $i=$_;
        }
return @u
}

sub max{
    my $max=shift;
    $max<$_ and $max=$_ for @_;
return $max
}

sub min{
    my $min=shift;
    $min>$_ and $min=$_ for @_;
return $min
}

# count (kas_ieskoma, masyvas)
sub count{
    my $i=0;
    $_ eq $_[0] and $i++ for @_;
return --$i
}

#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

#    <>=~/ /;
#    <>=~/ (\d+) /;
#    <>=~/ (\d+) (\d+) /;

<>;
while(<>=~/ /){
	$'+0 or push @_,$`;
	$'+0 and ($ats+=$`,$i+=$');
	}
@_=sort num @_;
while ($i--){$ats+=pop@_}
print $ats;

#***********SUBS************

sub num {$a <=> $b}
sub num_rev {$b <=> $a}
sub rev {$b cmp $a}

sub p{print}
sub n{print "\n"}
sub pn{p,n}
sub pn_mas {pn for @_}

# Transpose "charbox"
sub transpose{
    $i=@m=@_;
    chomp @m;
    while ($i--){
        $t[$i]=~s/$/chop/e for @m
    }
return @t
}

# Transpose "value sets"
sub transpose_space{
    my @t;
    for (@_){
        my $j=0;
        s/\d+/($t[$j++].="$& ")?$&:$&/eg;
        }
    chop @t;
return @t
}

sub div{
    my ($n, $k)=@_;
return ($n - $n % $k) / $k
}

sub uniq{
    my @m=sort @_;
    push @u, my $i=shift @m;
    for (@m){
        $i eq $_ or push @u, $_;
        $i=$_;
        }
return @u
}

sub max{
    my $max=shift;
    $max<$_ and $max=$_ for @_;
return $max
}

sub min{
    my $min=shift;
    $min>$_ and $min=$_ for @_;
return $min
}

# count (kas_ieskoma, masyvas)
sub count{
    my $i=0;
    $_ eq $_[0] and $i++ for @_;
return --$i
}


Chouti and his classmates are going to the university soon. To say goodbye to each other, the class has planned a big farewell party in which classmates, teachers and parents sang and danced.Chouti remembered that $$$n$$$ persons took part in that party. To make the party funnier, each person wore one hat among $$$n$$$ kinds of weird hats numbered $$$1, 2, \ldots n$$$. It is possible that several persons wore hats of the same kind. Some kinds of hats can remain unclaimed by anyone.After the party, the $$$i$$$-th person said that there were $$$a_i$$$ persons wearing a hat differing from his own.It has been some days, so Chouti forgot all about others' hats, but he is curious about that. Let $$$b_i$$$ be the number of hat type the $$$i$$$-th person was wearing, Chouti wants you to find any possible $$$b_1, b_2, \ldots, b_n$$$ that doesn't contradict with any person's statement. Because some persons might have a poor memory, there could be no solution at all.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$), the number of persons in the party. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le n-1$$$), the statements of people.

If there is no solution, print a single line "Impossible". Otherwise, print "Possible" and then $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le n$$$). If there are multiple answers, print any of them.

NoteIn the answer to the first example, all hats are the same, so every person will say that there were no persons wearing a hat different from kind $$$1$$$.In the answer to the second example, the first and the second person wore the hat with type $$$1$$$ and all other wore a hat of type $$$2$$$.So the first two persons will say there were three persons with hats differing from their own. Similarly, three last persons will say there were two persons wearing a hat different from their own.In the third example, it can be shown that no solution exists.In the first and the second example, other possible configurations are possible.


Sereja has got an array, consisting of n integers, a1, a2, ..., an. Sereja is an active boy, so he is now going to complete m operations. Each operation will have one of the three forms:  Make vi-th array element equal to xi. In other words, perform the assignment avi = xi.  Increase each array element by yi. In other words, perform n assignments ai = ai + yi (1 ≤ i ≤ n).  Take a piece of paper and write out the qi-th array element. That is, the element aqi. Help Sereja, complete all his operations.

The first line contains integers n, m (1 ≤ n, m ≤ 105). The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the original array. Next m lines describe operations, the i-th line describes the i-th operation. The first number in the i-th line is integer ti (1 ≤ ti ≤ 3) that represents the operation type. If ti = 1, then it is followed by two integers vi and xi, (1 ≤ vi ≤ n, 1 ≤ xi ≤ 109). If ti = 2, then it is followed by integer yi (1 ≤ yi ≤ 104). And if ti = 3, then it is followed by integer qi (1 ≤ qi ≤ n).

For each third type operation print value aqi. Print the values in the order, in which the corresponding queries follow in the input.


You are given two integers $$$n$$$ and $$$k$$$. You are asked to choose maximum number of distinct integers from $$$1$$$ to $$$n$$$ so that there is no subset of chosen numbers with sum equal to $$$k$$$.A subset of a set is a set that can be obtained from initial one by removing some (possibly all or none) elements of it.

The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 100$$$). Each of the next $$$T$$$ lines contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 1000$$$) — the description of test cases.

For each test case output two lines. In the first line output a single integer $$$m$$$ — the number of chosen integers. In the second line output $$$m$$$ distinct integers from $$$1$$$ to $$$n$$$ — the chosen numbers. If there are multiple answers, print any. You can print the numbers in any order.


Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations: Move from the list of letters to the content of any single letter. Return to the list of letters from single letter viewing mode. In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.The program cannot delete the letters from the list or rearrange them.Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?

The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of letters in the mailbox. The second line contains n space-separated integers (zeros and ones) — the state of the letter list. The i-th number equals either 1, if the i-th number is unread, or 0, if the i-th letter is read.

Print a single number — the minimum number of operations needed to make all the letters read.

NoteIn the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.In the third sample all letters are already read.

chomp($n=<>);
chomp($_=<>);
@a = split / /;
foreach (@a) {
	if ($_) {
		++$ans && !$flag && ++$ans;
		$flag = 1;
	} else {
		$flag = 0;
	}
}
print "0\n" if !$ans;
print $ans-1,"\n" if $ans;

#!/usr/bin/perl

my $n = <>;

my @mail = split / /, <>;

my $ans = 0;
my $reading = 0;
for $i (@mail) {
	if (($i == 1) || ($reading)) {
		$ans++;
	}
	$reading = $i;
};

if (($mail[-1] == 0) && ($ans > 0)) {
	$ans--;
};

print $ans;


It's now 260 AD. Shapur, being extremely smart, became the King of Persia. He is now called Shapur, His majesty King of kings of Iran and Aniran.Recently the Romans declared war on Persia. They dreamed to occupy Armenia. In the recent war, the Romans were badly defeated. Now their senior army general, Philip is captured by Shapur and Shapur is now going to capture Valerian, the Roman emperor.Being defeated, the cowardly Valerian hid in a room at the top of one of his castles. To capture him, Shapur has to open many doors. Fortunately Valerian was too scared to make impenetrable locks for the doors.Each door has 4 parts. The first part is an integer number a. The second part is either an integer number b or some really odd sign which looks like R. The third one is an integer c and the fourth part is empty! As if it was laid for writing something. Being extremely gifted, after opening the first few doors, Shapur found out the secret behind the locks.c is an integer written in base a, to open the door we should write it in base b. The only bad news is that this R is some sort of special numbering system that is used only in Roman empire, so opening the doors is not just a piece of cake!Here's an explanation of this really weird number system that even doesn't have zero:Roman numerals are based on seven symbols: a stroke (identified with the letter I) for a unit, a chevron (identified with the letter V) for a five, a cross-stroke (identified with the letter X) for a ten, a C (identified as an abbreviation of Centum) for a hundred, etc.: I=1 V=5 X=10 L=50 C=100 D=500 M=1000Symbols are iterated to produce multiples of the decimal (1, 10, 100, 1, 000) values, with V, L, D substituted for a multiple of five, and the iteration continuing: I 1, II 2, III 3, V 5, VI 6, VII 7, etc., and the same for other bases: X 10, XX 20, XXX 30, L 50, LXXX 80; CC 200, DCC 700, etc. At the fourth and ninth iteration, a subtractive principle must be employed, with the base placed before the higher base: IV 4, IX 9, XL 40, XC 90, CD 400, CM 900.Also in bases greater than 10 we use A for 10, B for 11, etc.Help Shapur capture Valerian and bring peace back to Persia, especially Armenia.

The first line contains two integers a and b (2 ≤ a, b ≤ 25). Only b may be replaced by an R which indicates Roman numbering system. The next line contains a single non-negative integer c in base a which may contain leading zeros but its length doesn't exceed 103.  It is guaranteed that if we have Roman numerals included the number would be less than or equal to 300010 and it won't be 0. In any other case the number won't be greater than 101510.

Write a single line that contains integer c in base b. You must omit leading zeros.

NoteYou can find more information about roman numerals here: http://en.wikipedia.org/wiki/Roman_numerals

use strict;

our @rule = qw(1 11 111 12 2 21 211 2111 13);
our @char = qw(IVX XLC CDM M);

sub convert_R {
	my $s = shift;
	my $r;
	my $p = length $s;
	if ($p) {
		my ($d, $d2) = split //, $s, 2;
		if ($d) {
	        	$r = $rule[$d - 1];
	        	my @c = split //, $char[$p - 1];
        		$r =~ s{ (.) }{ $c[$1 - 1] }gxe;
		}
		$r .= convert_R ($d2);
	}
	$r;
}

sub convert_10 {
	my ($number, $base) = @_;
	my $r;
	$number =~ s/^0+//;
	$number = reverse $number;
	for (my $i = 0; $i < length $number; $i++) {
		my $digit = substr $number, $i, 1;
		$digit =~ tr [0-9A-Z] [\00-\11\12-\43];
		$r += ord($digit) * $base ** $i;
	}
	$r;
}

sub convert_B {
	my ($n, $base) = @_;
	my $r;
	while ($n) {
		my $digit = chr $n % $base;
		$digit =~ tr [\00-\11\12-\43] [0-9A-Z];
		$r .= $digit;
		$n = int $n/$base;
	}
	$r ||= 0;
	scalar reverse $r;
}

$/ = ""; $_ = <>; my ($a, $b, $c) = split;
my $n = convert_10($c, $a);
my $r = $b eq "R"? convert_R($n): convert_B($n, $b);
print $r;

use strict;

our @rule = qw(1 11 111 12 2 21 211 2111 13);
our @char = qw(IVX XLC CDM M);

sub convert_R {
	my $s = shift;
	my $r;
	my $p = length $s;
	if ($p) {
		my ($d, $d2) = split //, $s, 2;
		if ($d) {
	        	$r = $rule[$d - 1];
	        	my @c = split //, $char[$p - 1];
        		$r =~ s{ (.) }{ $c[$1 - 1] }gxe;
		}
		$r .= convert_R ($d2);
	}
	$r;
}

sub convert_10 {
	my ($number, $base) = @_;
	my $r;
	$number = reverse $number;
	for (my $i = 0; $i < length $number; $i++) {
		my $digit = substr $number, $i, 1;
		$digit =~ tr [0-9A-Z] [\00-\11\12-\43];
		$r += ord($digit) * $base ** $i;
	}
	$r;
}

sub convert_B {
	my ($n, $base) = @_;
	my $r = 0;
	while ($n) {
		my $digit = chr $n % $base;
		$digit =~ tr [\00-\11\12-\43] [0-9A-Z];
		$r .= $digit;
		$n = int $n/$base;
	}
	scalar reverse $r;
}

$/ = ""; $_ = <>; my ($a, $b, $c) = split;
my $n = convert_10($c, $a);
my $r = $b eq "R"? convert_R($n): convert_B($n, $b);
print $r;

use strict;

our @rule = qw(1 11 111 12 2 21 211 2111 13);
our @char = qw(IVX XLC CDM M);

sub convert_R {
	my $s = shift;
	my $r;
	my $p = length $s;
	if ($p) {
		my ($d, $d2) = split //, $s, 2;
		if ($d) {
	        	$r = $rule[$d - 1];
	        	my @c = split //, $char[$p - 1];
        		$r =~ s{ (.) }{ $c[$1 - 1] }gxe;
		}
		$r .= convert_R ($d2);
	}
	$r;
}

sub convert_10 {
	my ($number, $base) = @_;
	my $r;
	$number = reverse $number;
	for (my $i = 0; $i < length $number; $i++) {
		my $digit = substr $number, $i, 1;
		$digit =~ tr [0-9A-Z] [\00-\11\12-\43];
		$r += ord($digit) * $base ** $i;
	}
	$r;
}

sub convert_B {
	my ($n, $base) = @_;
	my $r;
	while ($n) {
		my $digit = chr $n % $base;
		$digit =~ tr [\00-\11\12-\43] [0-9A-Z];
		$r .= $digit;
		$n = int $n/$base;
	}
	scalar reverse $r;
}

$/ = ""; $_ = <>; my ($a, $b, $c) = split;
my $n = convert_10($c, $a);
my $r = $b eq "R"? convert_R($n): convert_B($n, $b);
print $r;


A penguin Rocher has $$$n$$$ sticks. He has exactly one stick with length $$$i$$$ for all $$$1 \le i \le n$$$.He can connect some sticks. If he connects two sticks that have lengths $$$a$$$ and $$$b$$$, he gets one stick with length $$$a + b$$$. Two sticks, that were used in the operation disappear from his set and the new connected stick appears in his set and can be used for the next connections.He wants to create the maximum number of sticks that have the same length. It is not necessary to make all sticks have the same length, some sticks can have the other length. How many sticks with the equal length he can create?

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Next $$$t$$$ lines contain descriptions of test cases. For each test case, the only line contains a single integer $$$n$$$ ($$$1 \le n \le 10^{9}$$$).

For each test case, print a single integer  — the answer to the problem.

NoteIn the third case, he can connect two sticks with lengths $$$1$$$ and $$$2$$$ and he will get one stick with length $$$3$$$. So, he will have two sticks with lengths $$$3$$$.In the fourth case, he can connect two sticks with lengths $$$1$$$ and $$$3$$$ and he will get one stick with length $$$4$$$. After that, he will have three sticks with lengths $$$\{2, 4, 4\}$$$, so two sticks have the same length, and one stick has the other length.

use strict;

use integer;

my $try = <>;

while($try > 0){
    my $cnt = <>;
    $cnt = $cnt / 2 + $cnt % 2;
    print "$cnt\n";
    $try -= 1;
}


You went to the store, selling $$$n$$$ types of chocolates. There are $$$a_i$$$ chocolates of type $$$i$$$ in stock.You have unlimited amount of cash (so you are not restricted by any prices) and want to buy as many chocolates as possible. However if you buy $$$x_i$$$ chocolates of type $$$i$$$ (clearly, $$$0 \le x_i \le a_i$$$), then for all $$$1 \le j < i$$$ at least one of the following must hold:  $$$x_j = 0$$$ (you bought zero chocolates of type $$$j$$$) $$$x_j < x_i$$$ (you bought less chocolates of type $$$j$$$ than of type $$$i$$$) For example, the array $$$x = [0, 0, 1, 2, 10]$$$ satisfies the requirement above (assuming that all $$$a_i \ge x_i$$$), while arrays $$$x = [0, 1, 0]$$$, $$$x = [5, 5]$$$ and $$$x = [3, 2]$$$ don't.Calculate the maximum number of chocolates you can buy.

The first line contains an integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$), denoting the number of types of chocolate. The next line contains $$$n$$$ integers $$$a_i$$$ ($$$1 \le a_i \le 10^9$$$), denoting the number of chocolates of each type.

Print the maximum number of chocolates you can buy.

NoteIn the first example, it is optimal to buy: $$$0 + 0 + 1 + 3 + 6$$$ chocolates.In the second example, it is optimal to buy: $$$1 + 2 + 3 + 4 + 10$$$ chocolates.In the third example, it is optimal to buy: $$$0 + 0 + 0 + 1$$$ chocolates.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

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

	my $r = 1e10;
	my $sum = 0;

	for( @_ ){
		if( $_ < $r ){
			$sum += $_;
			$r = $_;
			}
		else{
			$r and $r --;
			$sum += $r;
			}
		}

	print $sum;
	}


A new pack of n t-shirts came to a shop. Each of the t-shirts is characterized by three integers pi, ai and bi, where pi is the price of the i-th t-shirt, ai is front color of the i-th t-shirt and bi is back color of the i-th t-shirt. All values pi are distinct, and values ai and bi are integers from 1 to 3.m buyers will come to the shop. Each of them wants to buy exactly one t-shirt. For the j-th buyer we know his favorite color cj.A buyer agrees to buy a t-shirt, if at least one side (front or back) is painted in his favorite color. Among all t-shirts that have colors acceptable to this buyer he will choose the cheapest one. If there are no such t-shirts, the buyer won't buy anything. Assume that the buyers come one by one, and each buyer is served only after the previous one is served.You are to compute the prices each buyer will pay for t-shirts.

The first line contains single integer n (1 ≤ n ≤ 200 000) — the number of t-shirts. The following line contains sequence of integers p1, p2, ..., pn (1 ≤ pi ≤ 1 000 000 000), where pi equals to the price of the i-th t-shirt. The following line contains sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 3), where ai equals to the front color of the i-th t-shirt. The following line contains sequence of integers b1, b2, ..., bn (1 ≤ bi ≤ 3), where bi equals to the back color of the i-th t-shirt. The next line contains single integer m (1 ≤ m ≤ 200 000) — the number of buyers.  The following line contains sequence c1, c2, ..., cm (1 ≤ cj ≤ 3), where cj equals to the favorite color of the j-th buyer. The buyers will come to the shop in the order they are given in the input. Each buyer is served only after the previous one is served.

Print to the first line m integers — the j-th integer should be equal to the price of the t-shirt which the j-th buyer will buy. If the j-th buyer won't buy anything, print -1.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

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

	my %h;
	my $i;

	for ( 0 .. 1 ){
		$i = -1;
		map { $i ++; $h{ $_ }{ $_[ $i ] } ++ } split ' ', <>;
		}

	<>;

	my %g;
	my %i;

	for my $color ( 1 .. 3 ){
		@{ $g{ $color } } = sort { $a <=> $b } keys %{ $h{ $color } };
		$debug and print "@{ $g{ $color } }";
		for my $clr ( 1 .. 3 ){
			$i{ $color }{ $clr } = 0;
			}
		}

	my @ans;
	my $ans;

	for my $color ( split ' ', <> ){

		while( $g{ $color }->[ $i{ $color }{ $color } ] and
			$g{ $color }->[ $i{ $color }{ $color } ] =~ / / ){
			$i{ $color }{ $color } ++;
			}

		if( $g{ $color }->[ $i{ $color }{ $color } ] ){
			push @ans, $ans = $g{ $color }->[ $i{ $color }{ $color } ];
			$g{ $color }->[ $i{ $color }{ $color } ] .= ' ';
			$i{ $color }{ $color } ++;

			for my $clr ( 1 .. 3 ){
				next if $clr == $color;

				while( $g{ $clr }->[ $i{ $color }{ $clr } ] and
					$g{ $clr }->[ $i{ $color }{ $clr } ] < $ans ){
					$i{ $color }{ $clr } ++;
					}

				if( $g{ $clr }->[ $i{ $color }{ $clr } ] and
					$g{ $clr }->[ $i{ $color }{ $clr } ] == $ans ){
					$g{ $clr }->[ $i{ $color }{ $clr } ] .= ' ';
					$i{ $color }{ $clr } ++;
					last;
					}

				}

			}
		else {
			push @ans, -1;
			}

		}

	print "@ans";
	}


You are given a matrix $$$a$$$ consisting of positive integers. It has $$$n$$$ rows and $$$m$$$ columns.Construct a matrix $$$b$$$ consisting of positive integers. It should have the same size as $$$a$$$, and the following conditions should be met:   $$$1 \le b_{i,j} \le 10^6$$$;  $$$b_{i,j}$$$ is a multiple of $$$a_{i,j}$$$;  the absolute value of the difference between numbers in any adjacent pair of cells (two cells that share the same side) in $$$b$$$ is equal to $$$k^4$$$ for some integer $$$k \ge 1$$$ ($$$k$$$ is not necessarily the same for all pairs, it is own for each pair). We can show that the answer always exists.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n,m \le 500$$$). Each of the following $$$n$$$ lines contains $$$m$$$ integers. The $$$j$$$-th integer in the $$$i$$$-th line is $$$a_{i,j}$$$ ($$$1 \le a_{i,j} \le 16$$$).

The output should contain $$$n$$$ lines each containing $$$m$$$ integers. The $$$j$$$-th integer in the $$$i$$$-th line should be $$$b_{i,j}$$$.

NoteIn the first example, the matrix $$$a$$$ can be used as the matrix $$$b$$$, because the absolute value of the difference between numbers in any adjacent pair of cells is $$$1 = 1^4$$$.In the third example:   $$$327$$$ is a multiple of $$$3$$$, $$$583$$$ is a multiple of $$$11$$$, $$$408$$$ is a multiple of $$$12$$$, $$$664$$$ is a multiple of $$$8$$$;  $$$|408 - 327| = 3^4$$$, $$$|583 - 327| = 4^4$$$, $$$|664 - 408| = 4^4$$$, $$$|664 - 583| = 3^4$$$.


Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two ships, however, the ships can touch each other.Galya doesn't know the ships location. She can shoot to some cells and after each shot she is told if that cell was a part of some ship (this case is called "hit") or not (this case is called "miss").Galya has already made k shots, all of them were misses.Your task is to calculate the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship.It is guaranteed that there is at least one valid ships placement.

The first line contains four positive integers n, a, b, k (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ n, 0 ≤ k ≤ n - 1) — the length of the grid, the number of ships on the grid, the length of each ship and the number of shots Galya has already made. The second line contains a string of length n, consisting of zeros and ones. If the i-th character is one, Galya has already made a shot to this cell. Otherwise, she hasn't. It is guaranteed that there are exactly k ones in this string.

In the first line print the minimum number of cells such that if Galya shoot at all of them, she would hit at least one ship. In the second line print the cells Galya should shoot at. Each cell should be printed exactly once. You can print the cells in arbitrary order. The cells are numbered from 1 to n, starting from the left. If there are multiple answers, you can print any of them.

NoteThere is one ship in the first sample. It can be either to the left or to the right from the shot Galya has already made (the "1" character). So, it is necessary to make two shots: one at the left part, and one at the right part.

#!perl
use strict;
use warnings;
use v5.18;
while (<>) {
	my ($n, $a, $b, $k) = split;
	my $s = <>; chomp $s;
	$s = '1' . $s . '1';
	my @str = split '', $s;
	my @positions;
	my $q;
	for ( my $i = 0; $i < $#str; $i = $q ) {
		my $j = $i;
		while ($j < $#str && 1 == $str[$j]) { $j++; }
		$q = $j;
		while ($q < $#str && 0 == $str[$q]) { $q++; }
		for (my $pos = $j - 1 + $b; $pos < $q; $pos += $b) {
			if ($a == 1) { push @positions, $pos }
			else { $a--; }
		}
	}
	say scalar @positions;
	say join ' ', @positions;
}

#!perl
use v5.20;
use strict;
use warnings;
use Class::Struct;
struct (
  Interval => [
    length => '$',
    cntShip => '$',
    endPos => '$'
  ]
);
while (<>) {
  my ($n, $aa, $bb, $k) = split ' ';
  my ($s, @str);
  chomp($s = <>);
  @str = split '', $s;
  my ($cnt, $i, @room);
  $cnt = 0;
  for $i ( 0..$#str ) {
    if (!$str[$i]) {
      ++$cnt;
    }
    else {
      if ($cnt) {
        push @room, Interval->new(
          length => $cnt,
          cntShip => int($cnt/$bb),
          endPos => $i-1
          );
      }
      $cnt = 0;
    }
  }
  if ($cnt) {
      push @room, Interval->new(
        length => $cnt,
        cntShip => int($cnt/$bb),
        endPos => $#str
        );
  }
  @room = sort { $a->length <=> $b->length } @room;

  #for $i ( 0..$#room ) {
  #  say '(', $room[$i]->length,
  #  ' ', $room[$i]->cntShip,
  #  ' ', $room[$i]->endPos, ')';
  #}

  my ($result, @postSum, $sum);
  $sum = 0;
  for ($i = $#room; $i >= 0; --$i) {
    $sum += $room[$i]->cntShip;
    $postSum[$i] = $sum;
  }
  my (@positions);
  for $i ( 0..$#room ) {
    if ($i != $#room && $postSum[$i+1] >= $aa) {
    #// remaining is enough.
      my $start = $room[$i]->endPos - ($room[$i]->length - 1);
      my $pos = $room[$i]->endPos;
      while ($pos >= $start + $bb - 1) {
      #say "start= ", $start, " pos= ", $pos;
        $pos -= ($bb - 1);
        push @positions, $pos+1;
        $pos--;
      }
    }
    elsif ($i != $#room && $postSum[$i+1] < $aa) {
    #// remaining is not enough, current interval is the last.
      my $remaining = $aa - $postSum[$i+1];
      my $cnt = $room[$i]->cntShip - $remaining + 1;
      my $pos = $room[$i]->endPos;
      while ($cnt--) {
        $pos -= ($bb - 1);
        push @positions, $pos+1;
        $pos--;
      }
      last;
    }
    else {
      my $cnt = $room[$i]->cntShip - $aa + 1;
      my $pos = $room[$i]->endPos;
      while ($cnt--) {
        $pos -= ($bb - 1);
        push @positions, $pos+1;
        $pos--;
      }
    }
  }
  say scalar @positions;
  say join ' ', @positions;
}

#!perl
use v5.20;
use strict;
use warnings;
use Class::Struct;
struct (
  Interval => [
    length => '$',
    cntShip => '$',
    endPos => '$'
  ]
);
while (<>) {
  my ($n, $aa, $bb, $k) = split ' ';
  my ($s, @str);
  chomp($s = <>);
  @str = split '', $s;
  my ($cnt, $i, @room);
  $cnt = 0;
  for $i ( 0..$#str ) {
    if (!$str[$i]) {
      ++$cnt;
    }
    else {
      if ($cnt) {
        push @room, Interval->new(
          length => $cnt,
          cntShip => int($cnt/$bb),
          endPos => $i-1
          );
      }
      $cnt = 0;
    }
  }
  if ($cnt) {
      push @room, Interval->new(
        length => $cnt,
        cntShip => int($cnt/$bb),
        endPos => $#str
        );
  }
  @room = sort { $a->length <=> $b->length } @room;

  #for $i ( 0..$#room ) {
  #  say '(', $room[$i]->length,
  #  ' ', $room[$i]->cntShip,
  #  ' ', $room[$i]->endPos, ')';
  #}

  my ($result, @postSum, $sum);
  $sum = 0;
  for ($i = $#room; $i >= 0; --$i) {
    $sum += $room[$i]->cntShip;
    $postSum[$i] = $sum;
  }
  my (@positions);
  for $i ( 0..$#room ) {
    if ($i != $#room && $postSum[$i+1] >= $aa) {
    #// remaining is enough.
      my $start = $room[$i]->endPos - ($room[$i]->length - 1);
      my $pos = $room[$i]->endPos;
      while ($pos >= $start + $bb - 1) {
      #say "start= ", $start, " pos= ", $pos;
        $pos -= ($bb - 1);
        push @positions, $pos+1;
        $pos--;
      }
    }
    elsif ($i != $#room && $postSum[$i+1] < $aa) {
    #// remaining is not enough, current interval is the last.
      my $remaining = $aa - $postSum[$i+1];
      my $cnt = $room[$i]->cntShip - $remaining + 1;
      my $pos = $room[$i]->endPos;
      while ($cnt--) {
        $pos -= ($bb - 1);
        push @positions, $pos+1;
      }
      last;
    }
    else {
      my $cnt = $room[$i]->cntShip - $aa + 1;
      my $pos = $room[$i]->endPos;
      while ($cnt--) {
        $pos -= ($bb - 1);
        push @positions, $pos+1;
      }
    }
  }
  say scalar @positions;
  say join ' ', @positions;
}


You are given a n × m field consisting only of periods ('.') and asterisks ('*'). Your task is to count all right triangles with two sides parallel to the square sides, whose vertices are in the centers of '*'-cells. A right triangle is a triangle in which one angle is a right angle (that is, a 90 degree angle).

The first line contains two positive integer numbers n and m (1 ≤ n, m ≤ 1000). The following n lines consist of m characters each, describing the field. Only '.' and '*' are allowed.

Output a single number — total number of square triangles in the field. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d).


Three swimmers decided to organize a party in the swimming pool! At noon, they started to swim from the left side of the pool.It takes the first swimmer exactly $$$a$$$ minutes to swim across the entire pool and come back, exactly $$$b$$$ minutes for the second swimmer and $$$c$$$ minutes for the third. Hence, the first swimmer will be on the left side of the pool after $$$0$$$, $$$a$$$, $$$2a$$$, $$$3a$$$, ... minutes after the start time, the second one will be at $$$0$$$, $$$b$$$, $$$2b$$$, $$$3b$$$, ... minutes, and the third one will be on the left side of the pool after $$$0$$$, $$$c$$$, $$$2c$$$, $$$3c$$$, ... minutes.You came to the left side of the pool exactly $$$p$$$ minutes after they started swimming. Determine how long you have to wait before one of the swimmers arrives at the left side of the pool.

The first line of the input contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. Next $$$t$$$ lines contains test case descriptions, one per line. Each line contains four integers $$$p$$$, $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \leq p, a, b, c \leq 10^{18}$$$), time in minutes after the start, when you came to the pool and times in minutes it take the swimmers to cross the entire pool and come back.

For each test case, output one integer — how long you have to wait (in minutes) before one of the swimmers arrives at the left side of the pool.

NoteIn the first test case, the first swimmer is on the left side in $$$0, 5, 10, 15, \ldots$$$ minutes after the start time, the second swimmer is on the left side in $$$0, 4, 8, 12, \ldots$$$ minutes after the start time, and the third swimmer is on the left side in $$$0, 8, 16, 24, \ldots$$$ minutes after the start time. You arrived at the pool in $$$9$$$ minutes after the start time and in a minute you will meet the first swimmer on the left side.In the second test case, the first swimmer is on the left side in $$$0, 6, 12, 18, \ldots$$$ minutes after the start time, the second swimmer is on the left side in $$$0, 10, 20, 30, \ldots$$$ minutes after the start time, and the third swimmer is on the left side in $$$0, 9, 18, 27, \ldots$$$ minutes after the start time. You arrived at the pool $$$2$$$ minutes after the start time and after $$$4$$$ minutes meet the first swimmer on the left side.In the third test case, you came to the pool $$$10$$$ minutes after the start time. At the same time, all three swimmers are on the left side. A rare stroke of luck!In the fourth test case, all swimmers are located on the left side in $$$0, 9, 18, 27, \ldots$$$ minutes after the start time. You arrived at the pool $$$10$$$ minutes after the start time and after $$$8$$$ minutes meet all three swimmers on the left side.

#!/usr/bin/perl

use warnings;
use strict;
use bigint;

$\ = $/;

<>;

while(<>){
	my( $p, @A ) = split;

	my @cand;

	for( @A ){
		my $mod = $p % $_;
		$mod == 0 and push @cand, 0;
		push @cand, $_ - $mod;
		}

	print +( sort { $a <=> $b } @cand )[ 0 ];
	}


Woken up by the alarm clock Igor the financial analyst hurried up to the work. He ate his breakfast and sat in his car. Sadly, when he opened his GPS navigator, he found that some of the roads in Bankopolis, the city where he lives, are closed due to road works. Moreover, Igor has some problems with the steering wheel, so he can make no more than two turns on his way to his office in bank.Bankopolis looks like a grid of n rows and m columns. Igor should find a way from his home to the bank that has no more than two turns and doesn't contain cells with road works, or determine that it is impossible and he should work from home. A turn is a change in movement direction. Igor's car can only move to the left, to the right, upwards and downwards. Initially Igor can choose any direction. Igor is still sleepy, so you should help him.

The first line contains two integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and the number of columns in the grid. Each of the next n lines contains m characters denoting the corresponding row of the grid. The following characters can occur:    "." — an empty cell;  "*" — a cell with road works;  "S" — the cell where Igor's home is located;  "T" — the cell where Igor's office is located.  It is guaranteed that "S" and "T" appear exactly once each.

In the only line print "YES" if there is a path between Igor's home and Igor's office with no more than two turns, and "NO" otherwise.

NoteThe first sample is shown on the following picture:  In the second sample it is impossible to reach Igor's office using less that 4 turns, thus there exists no path using no more than 2 turns. The path using exactly 4 turns is shown on this picture:


You're given a list of n strings a1, a2, ..., an. You'd like to concatenate them together in some order such that the resulting string would be lexicographically smallest.Given the list of strings, output the lexicographically smallest concatenation.

The first line contains integer n — the number of strings (1 ≤ n ≤ 5·104). Each of the next n lines contains one string ai (1 ≤ |ai| ≤ 50) consisting of only lowercase English letters. The sum of string lengths will not exceed 5·104.

Print the only string a — the lexicographically smallest string concatenation.

<>;

print sort { $a . $b cmp $b . $a } map s/\n//r, <>

<>;

print sort {
		($A, $B) = ($a, $b);
		$max = length $A > length $B ? $A : $B;
		map { $_ x= 50; substr $_, 0, $max } $A, $B;
		$A cmp $B
	} map s/\n//r, <>;

<>;

print join '+', sort {
		($A, $B) = ($a, $b);
		$max = length $A > length $B ? $A : $B;
		map { $_ x= 50; substr $_, 0, $max } $A, $B;
		$A cmp $B
	} map s/\n//r, <>;

<>;

%h = map { chomp; $_ => 1 } @_ = <>;

for (sort map $_ .= (chop) x (52 - length), @_){
	for $i (reverse 1 .. 50){
		$s = substr $_, 0, $i;
		$h{ $s } and do { $_ = $s ; delete $h{ $s }; last }
		}
	print
	}

<>;

print map y/~//dr, sort map s/\n//r . '~', <>;


There are some websites that are accessible through several different addresses. For example, for a long time Codeforces was accessible with two hostnames codeforces.com and codeforces.ru.You are given a list of page addresses being queried. For simplicity we consider all addresses to have the form http://<hostname>[/<path>], where:  <hostname> — server name (consists of words and maybe some dots separating them),  /<path> — optional part, where <path> consists of words separated by slashes. We consider two <hostname> to correspond to one website if for each query to the first <hostname> there will be exactly the same query to the second one and vice versa — for each query to the second <hostname> there will be the same query to the first one. Take a look at the samples for further clarifications.Your goal is to determine the groups of server names that correspond to one website. Ignore groups consisting of the only server name.Please note, that according to the above definition queries http://<hostname> and http://<hostname>/ are different.

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of page queries. Then follow n lines each containing exactly one address. Each address is of the form http://<hostname>[/<path>], where:   <hostname> consists of lowercase English letters and dots, there are no two consecutive dots, <hostname> doesn't start or finish with a dot. The length of <hostname> is positive and doesn't exceed 20.  <path> consists of lowercase English letters, dots and slashes. There are no two consecutive slashes, <path> doesn't start with a slash and its length doesn't exceed 20.  Addresses are not guaranteed to be distinct.

First print k — the number of groups of server names that correspond to one website. You should count only groups of size greater than one. Next k lines should contain the description of groups, one group per line. For each group print all server names separated by a single space. You are allowed to print both groups and names inside any group in arbitrary order.

10
http://abacaba.ru/test
http://abacaba.ru/
http://abacaba.com
http://abacaba.com/test
http://abacaba.de/
http://abacaba.ru/test
http://abacaba.de/test
http://abacaba.com/
http://abacaba.com/t
http://abacaba.com/test

14
http://c
http://ccc.bbbb/aba..b
http://cba.com
http://a.c/aba..b/a
http://abc/
http://a.c/
http://ccc.bbbb
http://ab.ac.bc.aa/
http://a.a.a/
http://ccc.bbbb/
http://cba.com/
http://cba.com/aba..b
http://a.a.a/aba..b/a
http://abc/aba..b/a

2
http://cba.com http://ccc.bbbb
http://a.a.a http://a.c http://abc

#!/usr/bin/env perl

use strict;
use warnings;
no warnings 'uninitialized';

my $N = <> + 0;

my $npaths = 0;
my %map_paths = ();

my %host_paths = ();

for (my $i = 0; $i < $N; ++$i) {
   my $url = <>;
   chomp $url;
   $url =~ m{http://([.a-z]+)(.*)};
   my ($hostname, $path) = ($1, $2);
   #print $hostname, ' ', $path, "\n";

   my $id;
   if ( not exists $map_paths{ $path } ) {
      $id = $map_paths{ $path } = $npaths++
   }
   else {
      $id = $map_paths{ $path }
   }
   $host_paths{ $hostname }{$id} = 1
}

my %paths_hosts = ();
while (my ($key, $path_set) = each %host_paths) {
   my $paths = join(':', sort keys %$path_set);
   #print $key, ' ', $paths, "\n";
   push( @{$paths_hosts{ $paths }}, $key )
}

my @res;
while (my ($key, $list) = each %paths_hosts) {
   next if @$list <= 1;
   push(@res, join(' ', map('http://' . $_, @$list)))
}

print scalar @res, "\n";
print join("\n", @res), "\n"

use warnings;
use strict;

my %host2path;
my %path2host;

my $n = <>;
chomp $n;
$n += 0;

for (my $i = 0; $i < $n; $i++){
    my $url = <>;
    $url =~ m!^(http://[\w\.]+)(/[\w\./]*)?\n$! or die "bad url";
    my $host = $1;
    my $path = $2 || '';
    #print STDERR "host = \'$host\' path = \'$path\'\n";
    if ($host2path{$host}) {
        ${$host2path{$host}}{$path} = undef;
        }
    else {
        $host2path{$host} = { $path => undef };
        }
    }

while (my ($host, $pathes) = each %host2path){
    my $ppp = join '#', sort keys %$pathes;
    #print STDERR "ppp = \'$ppp\' host = \'$host\'\n";
    if ($path2host{$ppp}){
        push @{$path2host{$ppp}}, $host;
        }
    else {
        $path2host{$ppp} = [ $host ]
        }
    }

my @res = ();
while (my ($ppp, $hosts) = each %path2host){
    push @res, $hosts if (scalar(@$hosts) > 1);
    }

print scalar(@res), "\n";
print join(' ', @$_), "\n" foreach (@res);

exit(0);

$_ = <>, chomp, m!http://[\w.]+!, undef $h{ $& }{ $' } for 1 .. <>;

push @{ $g{ join ' ', sort keys %{ $h{ $_ } }  } }, $_ for keys %h;
push @ans, grep / /, join ' ', @{ $g{ $_ } } for keys %g;

print join $/, ~~ @ans, @ans

#!/usr/bin/env perl

use strict;
use warnings;
no warnings 'uninitialized';

my $N = <> + 0;

my $npaths = 0;
my %map_paths = ();

my %host_paths = ();

for (my $i = 0; $i < $N; ++$i) {
   my $url = <>;
   chomp $url;
   $url =~ m{http://([.a-z]+)(.*)};
   my ($hostname, $path) = ($1, $2);
   #print $hostname, ' ', $path, "\n";

   my $id;
   if ( not exists $map_paths{ $path } ) {
      $id = $map_paths{ $path } = $npaths++
   }
   else {
      $id = $map_paths{ $path }
   }
   push( @{$host_paths{ $hostname }}, $id )
}

my %paths_hosts = ();
while (my ($key, $list) = each %host_paths) {
   my $paths = join(':', sort @$list);
#  print $key, ' ', $paths, "\n"
   push( @{$paths_hosts{ $paths }}, $key )
}

my @res;
while (my ($key, $list) = each %paths_hosts) {
   next if @$list <= 1;
   push(@res, join(' ', map('http://' . $_, @$list)))
}

print scalar @res, "\n";
print join("\n", @res), "\n"


You are given an array $$$a$$$ of size $$$n$$$.You can perform the following operation on the array:   Choose two different integers $$$i, j$$$ $$$(1 \leq i < j \leq n$$$), replace $$$a_i$$$ with $$$x$$$ and $$$a_j$$$ with $$$y$$$. In order not to break the array, $$$a_i | a_j = x | y$$$ must be held, where $$$|$$$ denotes the bitwise OR operation. Notice that $$$x$$$ and $$$y$$$ are non-negative integers. Please output the minimum sum of the array you can get after using the operation above any number of times.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ $$$(1 \leq t \leq 1000)$$$. Description of the test cases follows. The first line of each test case contains an integer $$$n$$$ $$$(2 \leq n \leq 100)$$$ — the size of array $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots ,a_n$$$ $$$(0 \leq a_i < 2^{30})$$$.

For each test case, print one number in a line — the minimum possible sum of the array.

NoteIn the first example, you can perform the following operations to obtain the array $$$[1, 0, 2]$$$:1. choose $$$i = 1, j = 2$$$, change $$$a_1 = 1$$$ and $$$a_2 = 2$$$, it's valid since $$$1 | 3 = 1 | 2$$$. The array becomes $$$[1, 2, 2]$$$.2. choose $$$i = 2, j = 3$$$, change $$$a_2 = 0$$$ and $$$a_3 = 2$$$, it's valid since $$$2 | 2 = 0 | 2$$$. The array becomes $$$[1, 0, 2]$$$.We can prove that the minimum sum is $$$1 + 0 + 2 = 3$$$In the second example, We don't need any operations.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

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

	print 0 + eval join '|', @_;
	}


Let $$$LCM(x, y)$$$ be the minimum positive integer that is divisible by both $$$x$$$ and $$$y$$$. For example, $$$LCM(13, 37) = 481$$$, $$$LCM(9, 6) = 18$$$.You are given two integers $$$l$$$ and $$$r$$$. Find two integers $$$x$$$ and $$$y$$$ such that $$$l \le x < y \le r$$$ and $$$l \le LCM(x, y) \le r$$$.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10000$$$) — the number of test cases. Each test case is represented by one line containing two integers $$$l$$$ and $$$r$$$ ($$$1 \le l < r \le 10^9$$$).

For each test case, print two integers:   if it is impossible to find integers $$$x$$$ and $$$y$$$ meeting the constraints in the statement, print two integers equal to $$$-1$$$;  otherwise, print the values of $$$x$$$ and $$$y$$$ (if there are multiple valid answers, you may print any of them).


You helped Dima to have a great weekend, but it's time to work. Naturally, Dima, as all other men who have girlfriends, does everything wrong.Inna and Dima are now in one room. Inna tells Dima off for everything he does in her presence. After Inna tells him off for something, she goes to another room, walks there in circles muttering about how useless her sweetheart is. During that time Dima has time to peacefully complete k - 1 tasks. Then Inna returns and tells Dima off for the next task he does in her presence and goes to another room again. It continues until Dima is through with his tasks.Overall, Dima has n tasks to do, each task has a unique number from 1 to n. Dima loves order, so he does tasks consecutively, starting from some task. For example, if Dima has 6 tasks to do in total, then, if he starts from the 5-th task, the order is like that: first Dima does the 5-th task, then the 6-th one, then the 1-st one, then the 2-nd one, then the 3-rd one, then the 4-th one.Inna tells Dima off (only lovingly and appropriately!) so often and systematically that he's very well learned the power with which she tells him off for each task. Help Dima choose the first task so that in total he gets told off with as little power as possible.

The first line of the input contains two integers n, k (1 ≤ k ≤ n ≤ 105). The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 103), where ai is the power Inna tells Dima off with if she is present in the room while he is doing the i-th task. It is guaranteed that n is divisible by k.

In a single line print the number of the task Dima should start with to get told off with as little power as possible. If there are multiple solutions, print the one with the minimum number of the first task to do.

NoteExplanation of the first example.If Dima starts from the first task, Inna tells him off with power 3, then Dima can do one more task (as k = 2), then Inna tells him off for the third task with power 1, then she tells him off for the fifth task with power 5. Thus, Dima gets told off with total power 3 + 1 + 5 = 9. If Dima started from the second task, for example, then Inna would tell him off for tasks 2, 4 and 6 with power 2 + 6 + 4 = 12. Explanation of the second example.In the second example k = 5, thus, Dima manages to complete 4 tasks in-between the telling off sessions. Thus, Inna tells Dima off for tasks number 1 and 6 (if he starts from 1 or 6), 2 and 7 (if he starts from 2 or 7) and so on. The optimal answer is to start from task 3 or 8, 3 has a smaller number, so the answer is 3.

#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

    <>=~/ /;
#   <>=~/ (\d+) /;
#    <>=~/ (\d+) (\d+) /;

@_=split/ /,<>;
for (@_){
	$a[$i++ % $']+=$_;
	}
$min=min(@a);

for (@a){
	$j++;
	if ($_==$min){
		print $j;
		last
		}
	}

#***********SUBS************

sub num {$a <=> $b}
sub num_rev {$b <=> $a}
sub rev {$b cmp $a}

sub p{print}
sub n{print "\n"}
sub pn{p,n}
sub pn_mas {pn for @_}

# Transpose "charbox"
sub transpose{
    $i=@m=@_;
    chomp @m;
    while ($i--){
        $t[$i]=~s/$/chop/e for @m
    }
return @t
}

# Transpose "value sets"
sub transpose_space{
    my @t;
    for (@_){
        my $j=0;
        s/\d+/($t[$j++].="$& ")?$&:$&/eg;
        }
    chop @t;
return @t
}

sub div{
    my ($n, $k)=@_;
return ($n - $n % $k) / $k
}

sub uniq{
    my @m=sort @_;
    push @u, my $i=shift @m;
    for (@m){
        $i eq $_ or push @u, $_;
        $i=$_;
        }
return @u
}

sub max{
    my $max=shift;
    $max<$_ and $max=$_ for @_;
return $max
}

sub min{
    my $min=shift;
    $min>$_ and $min=$_ for @_;
return $min
}

# count (kas_ieskoma, masyvas)
sub count{
    my $i=0;
    $_ eq $_[0] and $i++ for @_;
return --$i
}


Pushok the dog has been chasing Imp for a few hours already.  Fortunately, Imp knows that Pushok is afraid of a robot vacuum cleaner. While moving, the robot generates a string t consisting of letters 's' and 'h', that produces a lot of noise. We define noise of string t as the number of occurrences of string "sh" as a subsequence in it, in other words, the number of such pairs (i, j), that i < j and  and . The robot is off at the moment. Imp knows that it has a sequence of strings ti in its memory, and he can arbitrary change their order. When the robot is started, it generates the string t as a concatenation of these strings in the given order. The noise of the resulting string equals the noise of this concatenation.Help Imp to find the maximum noise he can achieve by changing the order of the strings.

The first line contains a single integer n (1 ≤ n ≤ 105) — the number of strings in robot's memory. Next n lines contain the strings t1, t2, ..., tn, one per line. It is guaranteed that the strings are non-empty, contain only English letters 's' and 'h' and their total length does not exceed 105.

Print a single integer — the maxumum possible noise Imp can achieve by changing the order of the strings.

NoteThe optimal concatenation in the first sample is ssshhshhhs.


AquaMoon has $$$n$$$ friends. They stand in a row from left to right, and the $$$i$$$-th friend from the left wears a T-shirt with a number $$$a_i$$$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right.AquaMoon can make some operations on friends. On each operation, AquaMoon can choose two adjacent friends and swap their positions. After each operation, the direction of both chosen friends will also be flipped: left to right and vice versa.AquaMoon hopes that after some operations, the numbers written on the T-shirt of $$$n$$$ friends in the row, read from left to right, become non-decreasing. Also she wants, that all friends will have a direction of right at the end. Please find if it is possible.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 50$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of Aquamoon's friends. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \leq a_i \leq 10^5$$$) — the numbers, written on the T-shirts. It is guaranteed that the sum of $$$n$$$ for all test cases does not exceed $$$10^5$$$.

For each test case, if there exists a possible sequence of operations, print "YES" (without quotes); otherwise, print "NO" (without quotes). You can print each letter in any case (upper or lower).

NoteThe possible list of operations in the first test case:  Swap $$$a_1$$$ and $$$a_2$$$. The resulting sequence is $$$3, 4, 2, 5$$$. The directions are: left, left, right, right.  Swap $$$a_2$$$ and $$$a_3$$$. The resulting sequence is $$$3, 2, 4, 5$$$. The directions are: left, left, right, right.  Swap $$$a_1$$$ and $$$a_2$$$. The resulting sequence is $$$2, 3, 4, 5$$$. The directions are: right, right, right, right.