Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way to Mars, she will land on $$$n - 2$$$ intermediate planets. Formally: we number all the planets from $$$1$$$ to $$$n$$$. $$$1$$$ is Earth, $$$n$$$ is Mars. Natasha will make exactly $$$n$$$ flights: $$$1 \to 2 \to \ldots n \to 1$$$.Flight from $$$x$$$ to $$$y$$$ consists of two phases: take-off from planet $$$x$$$ and landing to planet $$$y$$$. This way, the overall itinerary of the trip will be: the $$$1$$$-st planet $$$\to$$$ take-off from the $$$1$$$-st planet $$$\to$$$ landing to the $$$2$$$-nd planet $$$\to$$$ $$$2$$$-nd planet $$$\to$$$ take-off from the $$$2$$$-nd planet $$$\to$$$ $$$\ldots$$$ $$$\to$$$ landing to the $$$n$$$-th planet $$$\to$$$ the $$$n$$$-th planet $$$\to$$$ take-off from the $$$n$$$-th planet $$$\to$$$ landing to the $$$1$$$-st planet $$$\to$$$ the $$$1$$$-st planet.The mass of the rocket together with all the useful cargo (but without fuel) is $$$m$$$ tons. However, Natasha does not know how much fuel to load into the rocket. Unfortunately, fuel can only be loaded on Earth, so if the rocket runs out of fuel on some other planet, Natasha will not be able to return home. Fuel is needed to take-off from each planet and to land to each planet. It is known that $$$1$$$ ton of fuel can lift off $$$a_i$$$ tons of rocket from the $$$i$$$-th planet or to land $$$b_i$$$ tons of rocket onto the $$$i$$$-th planet. For example, if the weight of rocket is $$$9$$$ tons, weight of fuel is $$$3$$$ tons and take-off coefficient is $$$8$$$ ($$$a_i = 8$$$), then $$$1.5$$$ tons of fuel will be burnt (since $$$1.5 \cdot 8 = 9 + 3$$$). The new weight of fuel after take-off will be $$$1.5$$$ tons. Please note, that it is allowed to burn non-integral amount of fuel during take-off or landing, and the amount of initial fuel can be non-integral as well.Help Natasha to calculate the minimum mass of fuel to load into the rocket. Note, that the rocket must spend fuel to carry both useful cargo and the fuel itself. However, it doesn't need to carry the fuel which has already been burnt. Assume, that the rocket takes off and lands instantly.

The first line contains a single integer $$$n$$$ ($$$2 \le n \le 1000$$$) — number of planets. The second line contains the only integer $$$m$$$ ($$$1 \le m \le 1000$$$) — weight of the payload. The third line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 1000$$$), where $$$a_i$$$ is the number of tons, which can be lifted off by one ton of fuel. The fourth line contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 1000$$$), where $$$b_i$$$ is the number of tons, which can be landed by one ton of fuel.  It is guaranteed, that if Natasha can make a flight, then it takes no more than $$$10^9$$$ tons of fuel.

If Natasha can fly to Mars through $$$(n - 2)$$$ planets and return to Earth, print the minimum mass of fuel (in tons) that Natasha should take. Otherwise, print a single number $$$-1$$$. It is guaranteed, that if Natasha can make a flight, then it takes no more than $$$10^9$$$ tons of fuel. The answer will be considered correct if its absolute or relative error doesn't exceed $$$10^{-6}$$$. Formally, let your answer be $$$p$$$, and the jury's answer be $$$q$$$. Your answer is considered correct if $$$\frac{|p - q|}{\max{(1, |q|)}} \le 10^{-6}$$$.

NoteLet's consider the first example.Initially, the mass of a rocket with fuel is $$$22$$$ tons. At take-off from Earth one ton of fuel can lift off $$$11$$$ tons of cargo, so to lift off $$$22$$$ tons you need to burn $$$2$$$ tons of fuel. Remaining weight of the rocket with fuel is $$$20$$$ tons. During landing on Mars, one ton of fuel can land $$$5$$$ tons of cargo, so for landing $$$20$$$ tons you will need to burn $$$4$$$ tons of fuel. There will be $$$16$$$ tons of the rocket with fuel remaining. While taking off from Mars, one ton of fuel can raise $$$8$$$ tons of cargo, so to lift off $$$16$$$ tons you will need to burn $$$2$$$ tons of fuel. There will be $$$14$$$ tons of rocket with fuel after that. During landing on Earth, one ton of fuel can land $$$7$$$ tons of cargo, so for landing $$$14$$$ tons you will need to burn $$$2$$$ tons of fuel. Remaining weight is $$$12$$$ tons, that is, a rocket without any fuel.In the second case, the rocket will not be able even to take off from Earth.


According to a new ISO standard, a flag of every country should have a chequered field n × m, each square should be of one of 10 colours, and the flag should be «striped»: each horizontal row of the flag should contain squares of the same colour, and the colours of adjacent horizontal rows should be different. Berland's government asked you to find out whether their flag meets the new ISO standard.

The first line of the input contains numbers n and m (1 ≤ n, m ≤ 100), n — the amount of rows, m — the amount of columns on the flag of Berland. Then there follows the description of the flag: each of the following n lines contain m characters. Each character is a digit between 0 and 9, and stands for the colour of the corresponding square.

Output YES, if the flag meets the new ISO standard, and NO otherwise.

#!/usr/bin/perl
($n,$m) = split /\D/, <>;
flag:for (1..$n) {
    chomp($str = <>);
    @arr = split(//, $str);
    @arr = sort { $a <=> $b } @arr;
    if ($arr[0] == $arr[$#arr]) {
        $color = $arr[0];
        if (!defined $colors{$color}) {
            $colors{$color} = $color;
            if ( (keys %colors) > 10) {
                print "NO";
                goto end;
            }
        }
        if (defined $pcolor) {
            if ($pcolor eq $color) {
                print "NO";
                goto end;
            }
        }
        $pcolor = $color;
    } else {
        print "NO";
        goto end;
    }
}
print "YES";
end:
__END__

#!/usr/bin/perl

$PI=3.14159265358979323846;
$MOD=1000000007;

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

while(<>=~/ /){
 	$t=-1; $f=0;
	for $i(1..$`+0){
		$_=<>;
		chomp;
		/./;
		$t==$& and $f++;
		$t=$&;
		s/(.)\1*//;
		$_ and $f++;
		}
	print ($f?"NO\n":"YES\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
($n,$m) = split /\D/, <>;
flag:for (1..$n) {
    chomp($str = <>);
    @arr = split(//, $str);
    @arr = sort { a <=> b } @arr;
    if ($arr[0] == $arr[$#arr]) {
        $color = $arr[0];
        if (!defined $colors{$color}) {
            $colors{$color} = $color;
            if ( (keys %colors) > 10) {
                print "NO";
                goto end;
            }
        }
        if (defined $pcolor) {
            if ($pcolor eq $color) {
                print "NO";
                goto end;
            }
        }
        $pcolor = $color;
    } else {
        print "NO";
        goto end;
    }
}
print "YES";
end:
__END__


You are given an array $$$a$$$ consisting of $$$n$$$ integers.You can remove at most one element from this array. Thus, the final length of the array is $$$n-1$$$ or $$$n$$$.Your task is to calculate the maximum possible length of the strictly increasing contiguous subarray of the remaining array.Recall that the contiguous subarray $$$a$$$ with indices from $$$l$$$ to $$$r$$$ is $$$a[l \dots r] = a_l, a_{l + 1}, \dots, a_r$$$. The subarray $$$a[l \dots r]$$$ is called strictly increasing if $$$a_l < a_{l+1} < \dots < a_r$$$.

The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of elements in $$$a$$$. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$.

Print one integer — the maximum possible length of the strictly increasing contiguous subarray of the array $$$a$$$ after removing at most one element.

NoteIn the first example, you can delete $$$a_3=5$$$. Then the resulting array will be equal to $$$[1, 2, 3, 4]$$$ and the length of its largest increasing subarray will be equal to $$$4$$$.


In this problem at each moment you have a set of intervals. You can move from interval (a, b) from our set to interval (c, d) from our set if and only if c < a < d or c < b < d. Also there is a path from interval I1 from our set to interval I2 from our set if there is a sequence of successive moves starting from I1 so that we can reach I2.Your program should handle the queries of the following two types:  "1 x y" (x < y) — add the new interval (x, y) to the set of intervals. The length of the new interval is guaranteed to be strictly greater than all the previous intervals. "2 a b" (a ≠ b) — answer the question: is there a path from a-th (one-based) added interval to b-th (one-based) added interval? Answer all the queries. Note, that initially you have an empty set of intervals.

The first line of the input contains integer n denoting the number of queries, (1 ≤ n ≤ 105). Each of the following lines contains a query as described above. All numbers in the input are integers and don't exceed 109 by their absolute value. It's guaranteed that all queries are correct.

For each query of the second type print "YES" or "NO" on a separate line depending on the answer.


«Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, like many other text editors, should be able to print out multipage documents. A user keys a sequence of the document page numbers that he wants to print out (separates them with a comma, without spaces).Your task is to write a part of the program, responsible for «standardization» of this sequence. Your program gets the sequence, keyed by the user, as input. The program should output this sequence in format l1-r1,l2-r2,...,lk-rk, where ri + 1 < li + 1 for all i from 1 to k - 1, and li ≤ ri. The new sequence should contain all the page numbers, keyed by the user, and nothing else. If some page number appears in the input sequence several times, its appearances, starting from the second one, should be ignored. If for some element i from the new sequence li = ri, this element should be output as li, and not as «li - li».For example, sequence 1,2,3,1,1,2,6,6,2 should be output as 1-3,6.

The only line contains the sequence, keyed by the user. The sequence contains at least one and at most 100 positive integer numbers. It's guaranteed, that this sequence consists of positive integer numbers, not exceeding 1000, separated with a comma, doesn't contain any other characters, apart from digits and commas, can't end with a comma, and the numbers don't contain leading zeroes. Also it doesn't start with a comma or contain more than one comma in a row.

Output the sequence in the required format.

#!/usr/bin/env perl
package Codeforces::Task::_;
use v5.10;
use strict;
use warnings;

sub min{my($a,$b)=@_;if($a<$b){return$a;}else{return$b;}}
sub max{my($a,$b)=@_;if($a>$b){return$a;}else{return$b;}}

sub out {
    my @x = @_;
    print(shift(@x), " ") while (scalar(@x));
    print("\n");
}

sub solve {
    my @ans = ();
    my $prev = -1;
    foreach my $c (sub {
        my %s = ();
        my $input = <>; chomp $input;
        foreach my $el (split ",", $input) {
            $s{$el} = 1;
        }
        return sort {$a <=> $b} keys %s;
    }->()) {
        if ($prev + 1 == $c) {
            my ($beg) = $ans[$#ans] =~ m/(\d*)(-|$)/;
            $ans[$#ans] = ",$beg-$c";
        } else {
            push(@ans, ",$c");
        }
        $prev = $c;
 	}
    print substr join("", @ans), 1;
}

sub main {
    my $t = 1;
#    $t = int(<>);
    while ($t--) {
        solve();
    }
    return 0;
}

exit(main(@ARGV));


This is an interactive problem. You should use flush operation after each printed line. For example, in C++ you should use fflush(stdout), in Java you should use System.out.flush(), and in Pascal — flush(output).In this problem you should guess an array a which is unknown for you. The only information you have initially is the length n of the array a.The only allowed action is to ask the sum of two elements by their indices. Formally, you can print two indices i and j (the indices should be distinct). Then your program should read the response: the single integer equals to ai + aj.It is easy to prove that it is always possible to guess the array using at most n requests.Write a program that will guess the array a by making at most n requests.

NoteThe format of a test to make a hack is:  The first line contains an integer number n (3 ≤ n ≤ 5000) — the length of the array. The second line contains n numbers a1, a2, ..., an (1 ≤ ai ≤ 105) — the elements of the array to guess.


Permutation p is an ordered set of integers p1,  p2,  ...,  pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutation p1,  p2,  ...,  pn.The decreasing coefficient of permutation p1, p2, ..., pn is the number of such i (1 ≤ i < n), that pi > pi + 1.You have numbers n and k. Your task is to print the permutation of length n with decreasing coefficient k.

The single line contains two space-separated integers: n, k (1 ≤ n ≤ 105, 0 ≤ k < n) — the permutation length and the decreasing coefficient.

In a single line print n space-separated integers: p1, p2, ..., pn — the permutation of length n with decreasing coefficient k.  If there are several permutations that meet this condition, print any of them. It is guaranteed that the permutation with the sought parameters exists.


Turbulent times are coming, so you decided to buy sugar in advance. There are $$$n$$$ shops around that sell sugar: the $$$i$$$-th shop sells one pack of sugar for $$$a_i$$$ coins, but only one pack to one customer each day. So in order to buy several packs, you need to visit several shops.Another problem is that prices are increasing each day: during the first day the cost is $$$a_i$$$, during the second day cost is $$$a_i + 1$$$, during the third day — $$$a_i + 2$$$ and so on for each shop $$$i$$$.On the contrary, your everyday budget is only $$$x$$$ coins. In other words, each day you go and buy as many packs as possible with total cost not exceeding $$$x$$$. Note that if you don't spend some amount of coins during a day, you can't use these coins during the next days.Eventually, the cost for each pack will exceed $$$x$$$, and you won't be able to buy even a single pack. So, how many packs will you be able to buy till that moment in total?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Next $$$t$$$ cases follow. The first line of each test case contains two integers $$$n$$$ and $$$x$$$ ($$$1 \le n \le 2 \cdot 10^5$$$; $$$1 \le x \le 10^9$$$) — the number of shops and your everyday budget. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the initial cost of one pack in each shop. It's guaranteed that the total sum of $$$n$$$ doesn't exceed $$$2 \cdot 10^5$$$.

For each test case, print one integer — the total number of packs you will be able to buy until prices exceed your everyday budget.

NoteIn the first test case,   Day 1: prices are $$$[2, 1, 2]$$$. You can buy all $$$3$$$ packs, since $$$2 + 1 + 2 \le 7$$$.  Day 2: prices are $$$[3, 2, 3]$$$. You can't buy all $$$3$$$ packs, since $$$3 + 2 + 3 > 7$$$, so you buy only $$$2$$$ packs.  Day 3: prices are $$$[4, 3, 4]$$$. You can buy $$$2$$$ packs with prices $$$4$$$ and $$$3$$$.  Day 4: prices are $$$[5, 4, 5]$$$. You can't buy $$$2$$$ packs anymore, so you buy only $$$1$$$ pack.  Day 5: prices are $$$[6, 5, 6]$$$. You can buy $$$1$$$ pack.  Day 6: prices are $$$[7, 6, 7]$$$. You can buy $$$1$$$ pack.  Day 7: prices are $$$[8, 7, 8]$$$. You still can buy $$$1$$$ pack of cost $$$7$$$.  Day 8: prices are $$$[9, 8, 9]$$$. Prices are too high, so you can't buy anything.  In total, you bought $$$3 + 2 + 2 + 1 + 1 + 1 + 1 = 11$$$ packs.In the second test case, prices are too high even at the first day, so you can't buy anything.In the third test case, you can buy only one pack at day one.In the fourth test case, you can buy $$$2$$$ packs first $$$500$$$ days. At day $$$501$$$ prices are $$$[501, 501]$$$, so you can buy only $$$1$$$ pack the next $$$500$$$ days. At day $$$1001$$$ prices are $$$[1001, 1001]$$$ so can't buy anymore. In total, you bought $$$500 \cdot 2 + 500 \cdot 1 = 1500$$$ packs.

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

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

while( $testcase -- > 0 ){

  my ($n,$x) = map { $_ - 0 } split(/\s+/,<STDIN>);
  my @A = map { $_ - 0 } split(/\s+/,<STDIN>);
  my @sa = sort { $a <=> $b } @A;
  my $r = 0;
  my $s = 0;
  for(my $i=0;$i<$n;$i++){
    $s += $sa[$i];
    last if $s > $x;
    my $v = 1 + ( $x - $s ) / (1+$i);
    $r += $v;
  }
  print "$r\n";
}

exit(0);

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


While walking down the street Vanya saw a label "Hide&Seek". Because he is a programmer, he used & as a bitwise AND for these two words represented as a integers in base 64 and got new word. Now Vanya thinks of some string s and wants to know the number of pairs of words of length |s| (length of s), such that their bitwise AND is equal to s. As this number can be large, output it modulo 109 + 7.To represent the string as a number in numeral system with base 64 Vanya uses the following rules:  digits from '0' to '9' correspond to integers from 0 to 9;  letters from 'A' to 'Z' correspond to integers from 10 to 35;  letters from 'a' to 'z' correspond to integers from 36 to 61;  letter '-' correspond to integer 62;  letter '_' correspond to integer 63.

The only line of the input contains a single word s (1 ≤ |s| ≤ 100 000), consisting of digits, lowercase and uppercase English letters, characters '-' and '_'.

Print a single integer — the number of possible pairs of words, such that their bitwise AND is equal to string s modulo 109 + 7.

NoteFor a detailed definition of bitwise AND we recommend to take a look in the corresponding article in Wikipedia.In the first sample, there are 3 possible solutions:   z&_ = 61&63 = 61 = z  _&z = 63&61 = 61 = z  z&z = 61&61 = 61 = z


An exam for n students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (i and i + 1) always studied side by side and became friends and if they take an exam sitting next to each other, they will help each other for sure.Your task is to choose the maximum number of students and make such an arrangement of students in the room that no two students with adjacent numbers sit side by side.

A single line contains integer n (1 ≤ n ≤ 5000) — the number of students at an exam.

In the first line print integer k — the maximum number of students who can be seated so that no two students with adjacent numbers sit next to each other. In the second line print k distinct integers a1, a2, ..., ak (1 ≤ ai ≤ n), where ai is the number of the student on the i-th position. The students on adjacent positions mustn't have adjacent numbers. Formally, the following should be true: |ai - ai + 1| ≠ 1 for all i from 1 to k - 1. If there are several possible answers, output any of them.

#!/usr/bin/perl
use v5.10;
use integer;

chomp($n = <>);
$n<=2 and say "1\n1" and exit;
$n==3 and say "2\n1 3" and exit;
$n==4 and say "4\n3 1 4 2" and exit;
say $n;
for ($i=1; $i<=$n; $i+=2) {
	print "$i ";
}
for ($i=2; $i<=$n; $i+=2) {
	print "$i ";
}

#!/usr/bin/perl
use strict;
use warnings;

my $n = <>;
chomp $n;

$n = int($n);

if ($n == 1 || $n == 2) {
  print "1\n";
  print "1\n";
} elsif ($n == 3) {
  print "2\n";
  print "1 3\n";
} elsif ($n == 4) {
  print "4\n";
  print "3 1 4 2\n";
} else {
  print "$n\n";
  print "1";
  for (my $odds = 3; $odds <= $n; $odds += 2) {
    print " $odds";
  }
  for (my $evens = 2; $evens <= $n; $evens += 2) {
    print " $evens";
  }
  print "\n";
}

#!/usr/bin/perl
use v5.10;
use integer;

chomp($n = <>);
$n<=2 and say "1\n1" and exit;
$n==3 and say "2\n1 3" and exit;
$n==4 and say "3\n1 4 2" and exit;
say $n;
for ($i=1; $i<=$n; $i+=2) {
	print "$i ";
}
for ($i=2; $i<=$n; $i+=2) {
	print "$i ";
}

#!/usr/bin/perl
use strict;
use warnings;

my $n = <>;
chomp $n;

$n = int($n);

if ($n == 1 || $n == 2) {
  print "1\n";
  print "1\n";
} elsif ($n == 3) {
  print "2\n";
  print "1 3\n";
} elsif ($n == 4) {
  print "3\n";
  print "1 4 2\n";
} else {
  print "$n\n";
  print "1";
  for (my $odds = 3; $odds <= $n; $odds += 2) {
    print " $odds";
  }
  for (my $evens = 2; $evens <= $n; $evens += 2) {
    print " $evens";
  }
  print "\n";
}


Kevin Sun has just finished competing in Codeforces Round #334! The round was 120 minutes long and featured five problems with maximum point values of 500, 1000, 1500, 2000, and 2500, respectively. Despite the challenging tasks, Kevin was uncowed and bulldozed through all of them, distinguishing himself from the herd as the best cowmputer scientist in all of Bovinia. Kevin knows his submission time for each problem, the number of wrong submissions that he made on each problem, and his total numbers of successful and unsuccessful hacks. Because Codeforces scoring is complicated, Kevin wants you to write a program to compute his final score.Codeforces scores are computed as follows: If the maximum point value of a problem is x, and Kevin submitted correctly at minute m but made w wrong submissions, then his score on that problem is . His total score is equal to the sum of his scores for each problem. In addition, Kevin's total score gets increased by 100 points for each successful hack, but gets decreased by 50 points for each unsuccessful hack.All arithmetic operations are performed with absolute precision and no rounding. It is guaranteed that Kevin's final score is an integer.

The first line of the input contains five space-separated integers m1, m2, m3, m4, m5, where mi (0 ≤ mi ≤ 119) is the time of Kevin's last submission for problem i. His last submission is always correct and gets accepted. The second line contains five space-separated integers w1, w2, w3, w4, w5, where wi (0 ≤ wi ≤ 10) is Kevin's number of wrong submissions on problem i. The last line contains two space-separated integers hs and hu (0 ≤ hs, hu ≤ 20), denoting the Kevin's numbers of successful and unsuccessful hacks, respectively.

Print a single integer, the value of Kevin's final score.

NoteIn the second sample, Kevin takes 119 minutes on all of the problems. Therefore, he gets  of the points on each problem. So his score from solving problems is . Adding in 10·100 = 1000 points from hacks, his total score becomes 3930 + 1000 = 4930.


Due to the coronavirus pandemic, city authorities obligated citizens to keep a social distance. The mayor of the city Semyon wants to light up Gluharniki park so that people could see each other even at night to keep the social distance.The park is a rectangular table with $$$n$$$ rows and $$$m$$$ columns, where the cells of the table are squares, and the boundaries between the cells are streets. External borders are also streets. Every street has length $$$1$$$. For example, park with $$$n=m=2$$$ has $$$12$$$ streets.You were assigned to develop a plan for lighting the park. You can put lanterns in the middle of the streets. The lamp lights two squares near it (or only one square if it stands on the border of the park).    The park sizes are: $$$n=4$$$, $$$m=5$$$. The lighted squares are marked yellow. Please note that all streets have length $$$1$$$. Lanterns are placed in the middle of the streets. In the picture not all the squares are lit. Semyon wants to spend the least possible amount of money on lighting but also wants people throughout the park to keep a social distance. So he asks you to find the minimum number of lanterns that are required to light all the squares.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the input. Then $$$t$$$ test cases follow. Each test case is a line containing two integers $$$n$$$, $$$m$$$ ($$$1 \le n, m \le 10^4$$$) — park sizes.

Print $$$t$$$ answers to the test cases. Each answer must be a single integer — the minimum number of lanterns that are required to light all the squares.

NotePossible optimal arrangement of the lanterns for the $$$2$$$-nd test case of input data example: Possible optimal arrangement of the lanterns for the $$$3$$$-rd test case of input data example:

$n = <STDIN>;
chomp $n;
@streets = <STDIN>;
chomp @streets;

foreach (@streets) {
    if ($_ != " ") {
        @str = split(' ', $_);
        $str_num = $str[0] * $str[1];
        use integer;
        $ans = ($str_num / 2) + ($str_num%2.0);
        push(@array, "$ans\n");

    #print "$street";
    }
}
print @array;


There is a given string S consisting of N symbols. Your task is to find the number of ordered pairs of integers i and j such that1. 1 ≤ i, j ≤ N2. S[i] = S[j], that is the i-th symbol of string S is equal to the j-th.

The single input line contains S, consisting of lowercase Latin letters and digits. It is guaranteed that string S in not empty and its length does not exceed 105.

Print a single number which represents the number of pairs i and j with the needed property. Pairs (x, y) and (y, x) should be considered different, i.e. the ordered pairs count.

#!perl -nl
++$h{$_} for split'',$_;
$a+=$h{$_}**2 for keys %h;
print $a;


Vasily exited from a store and now he wants to recheck the total price of all purchases in his bill. The bill is a string in which the names of the purchases and their prices are printed in a row without any spaces. Check has the format "name1price1name2price2...namenpricen", where namei (name of the i-th purchase) is a non-empty string of length not more than 10, consisting of lowercase English letters, and pricei (the price of the i-th purchase) is a non-empty string, consisting of digits and dots (decimal points). It is possible that purchases with equal names have different prices.The price of each purchase is written in the following format. If the price is an integer number of dollars then cents are not written.Otherwise, after the number of dollars a dot (decimal point) is written followed by cents in a two-digit format (if number of cents is between 1 and 9 inclusively, there is a leading zero).Also, every three digits (from less significant to the most) in dollars are separated by dot (decimal point). No extra leading zeroes are allowed. The price always starts with a digit and ends with a digit.For example:  "234", "1.544", "149.431.10", "0.99" and "123.05" are valid prices,  ".333", "3.33.11", "12.00", ".33", "0.1234" and "1.2" are not valid. Write a program that will find the total price of all purchases in the given bill.

The only line of the input contains a non-empty string s with length not greater than 1000 — the content of the bill. It is guaranteed that the bill meets the format described above. It is guaranteed that each price in the bill is not less than one cent and not greater than 106 dollars.

Print the total price exactly in the same format as prices given in the input.

#!/usr/bin/env perl
package Codeforces::Task::_;
use v5.10;
use strict;
#use warnings;

sub min{my($a,$b)=@_;if($a<$b){return$a;}else{return$b;}}
sub max{my($a,$b)=@_;if($a>$b){return$a;}else{return$b;}}

sub solve {
    my @p = (<> =~ m/([\d\.]+)/gx);
    my $r = 0;
    foreach my $c (@p) {
        $c =~ s/(?:(?=\.\d{3})\.|)//gx;
        $r += $c;
    }
    $r = sprintf("%.02f", $r);
    $r =~ s/\.00$//;
    while ($r =~ s/(\d+)(\d{3})/$1\.$2/gx)
        {};
    print "$r\n";
}

sub main {
    my $t = 1;
#    $t = int(<>);
    while ($t--) {
        solve();
    }
    return 0;
}

exit(main(@ARGV));

#!/usr/bin/env perl
package Codeforces::Task::_;
use v5.10;
use strict;
#use warnings;

sub min{my($a,$b)=@_;if($a<$b){return$a;}else{return$b;}}
sub max{my($a,$b)=@_;if($a>$b){return$a;}else{return$b;}}

sub solve {
    my @p = (<> =~ m/([\d\.]+)/g);
    my $r = 0;
    foreach my $c (@p) {
         $c =~ s/(?:(?=\.\d{3})\.|)//g;
         $r += $c;
    }
    $r =~ s/(\d+)(\d{3})/$1\.$2/g;
    print "$r\n";
}

sub main {
    my $t = 1;
#    $t = int(<>);
    while ($t--) {
        solve();
    }
    return 0;
}

exit(main(@ARGV));

#!/usr/bin/env perl
package Codeforces::Task::_;
use v5.10;
use strict;
#use warnings;

sub min{my($a,$b)=@_;if($a<$b){return$a;}else{return$b;}}
sub max{my($a,$b)=@_;if($a>$b){return$a;}else{return$b;}}

sub solve {
    my @p = (<> =~ m/([\d\.]+)/gx);
    my $r = 0;
    foreach my $c (@p) {
        $c =~ s/(?:(?=\.\d{3})\.|)//gx;
        $r += $c;
    }
    while ($r =~ s/(\d+)(\d{3})/$1\.$2/gx)
        {};
    print "$r\n";
}

sub main {
    my $t = 1;
#    $t = int(<>);
    while ($t--) {
        solve();
    }
    return 0;
}

exit(main(@ARGV));

$,=" ";
my $s=<>;
chomp($s);
$s =~ s/\.([0-9][0-9][0-9])/$1/g;
print STDERR $s. "\n";
$s =~ s/[a-z]+/,/g;
print STDERR $s. "\n";
my $sum = 0;
my @temp=split /,/, $s;
print STDERR scalar(@temp). "\n";
for(@temp)
{
  $sum+=$_ if($_);
}
print STDERR  $s , "\n";
my @f=split /\./,$sum;
print STDERR "@f \n";
my @c = unpack("(A3)*", reverse $f[0]);
$f[0] = reverse join '.', @c;
my $ans = join ".",@f;
print $ans . "\n";

$,=" ";
my $s=<>;
chomp($s);
$s =~ s/\.([0-9][0-9][0-9])/$1/g;
print STDERR $s. "\n";
$s =~ s/[a-z]+/,/g;
print STDERR $s. "\n";
my $sum = 0;
my @temp=split /,/, $s;
print STDERR scalar(@temp). "\n";
for(@temp)
{
  $sum+=$_ if($_);
}
print STDERR  $s , "\n";
my @f=split /\./,$sum;
print STDERR "@f \n";
my @c = unpack("(A3)*", reverse $f[0]);
$f[0] = reverse join '.', @c;
if($f[1])
{
  $f[1]=sprintf("%.02d",$f[1]);
}
my $ans = join ".",@f;
print $ans . "\n";

$,=" ";
my $s=<>;
chomp($s);
$s =~ s/.([0-9][0-9][0-9])/$1/g;
$s =~ s/[a-z]+/,/g;
my $sum = 0;
my @temp=split /,/, $s;
print STDERR scalar(@temp). "\n";
for(@temp)
{
  $sum+=$_ if($_);
}
print STDERR  $s , "\n";
my @f=split /\./,$sum;
print STDERR "@f \n";
my @c = unpack("(A3)*", reverse $f[0]);
$f[0] = reverse join '.', @c;
my $ans = join ".",@f;
print $ans . "\n";


Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory).Directories in Vasya's operating system form a traditional hierarchical tree structure. There is a single root directory, denoted by the slash character "/". Every other directory has a name — a non-empty string consisting of lowercase Latin letters. Each directory (except for the root) has a parent directory — the one that contains the given directory. It is denoted as "..".The command cd takes a single parameter, which is a path in the file system. The command changes the current directory to the directory specified by the path. The path consists of the names of directories separated by slashes. The name of the directory can be "..", which means a step up to the parent directory. «..» can be used in any place of the path, maybe several times. If the path begins with a slash, it is considered to be an absolute path, that is, the directory changes to the specified one, starting from the root. If the parameter begins with a directory name (or ".."), it is considered to be a relative path, that is, the directory changes to the specified directory, starting from the current one.The command pwd should display the absolute path to the current directory. This path must not contain "..".Initially, the current directory is the root. All directories mentioned explicitly or passed indirectly within any command cd are considered to exist. It is guaranteed that there is no attempt of transition to the parent directory of the root directory.

The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands. Then follow n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter. The command parameter cd only contains lower case Latin letters, slashes and dots, two slashes cannot go consecutively, dots occur only as the name of a parent pseudo-directory. The command parameter cd does not end with a slash, except when it is the only symbol that points to the root directory. The command parameter has a length from 1 to 200 characters, inclusive. Directories in the file system can have the same names.

For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots.

7
pwd
cd /home/vasya
pwd
cd ..
pwd
cd vasya/../petya
pwd

#!/usr/bin/perl
# Codeforces Practice

use warnings;
use strict;

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

my @currPath = ();
my $currCmd = "";

for(1..$n){
    $currCmd = <STDIN>;
    if($currCmd eq "pwd\n"){
        if (@currPath == 0){print "/\n";}
        else{
        my $printPath = join("/",@currPath);
        print "/$printPath/\n";}
    } else {
        my @cdPath = split("/",(split(/\s+/,$currCmd))[1]);
        foreach my $dir (@cdPath){
            if($dir eq ""){
                @currPath = ();
            } elsif ($dir eq "..") {
                pop(@currPath);
            } else {
                push(@currPath,$dir);
            }
        }
    }
}

#!/usr/bin/perl -w

use strict;
use Data::Dumper;

my $n = <>;
my @wd = ();

for (1 .. $n) {
    my ($cmd, $arg) = split ' ', <>;
    if ($cmd eq 'pwd') {
        print '/', (map { $_ . '/' } @wd), "\n";
    } else {
        if ($arg =~ m|^/|) {
            @wd = ();
            $arg = substr $arg, 1;
        }
        for (split '/', $arg) {
            push @wd, $_;
        }
        my @work = ();
        for (@wd) {
            if ($_ eq '..') {
                pop @work;
            } else {
                push @work, $_;
            }
        }
        @wd = @work;
    }
}

$\=$/;

$path="/";
$n=<STDIN>;
my @paths;
my $temp;
foreach $i(1 .. $n){
    ($comm,$temp)=split(" ",<STDIN>);
    #print (index $temp,"/")."\n".$temp;
    if ($comm eq "cd"){
        if ((index $temp,"/") eq 0){
            $path="/";
            #print "absolute path\n";
        }
            @paths=split("/",$temp);
            foreach $dir (@paths){
                if ($dir eq ".."){
                    #print "step out\n";
                    substr($path,rindex($path,"/"))="";
                    substr($path,rindex($path,"/"))="/";
                }else{
                    #print "adding path\ndir=$dir\n";
                    $path.=$dir."/" if ($dir =~/[a-z]/);
                }
            }

    }else{
        #$ans.=$path;
        print $path;
    }
}
#print $ans;

#!/usr/bin/perl
$root->{'..'} = '';
$root->{''} = \%root;
$root->{'.'} = '/';
$current_dir = $root;

for (1..<>) {
    chomp($s = <>);
    ($cmd, $dir) = split(/ /, $s);
    if ($cmd eq 'pwd') {
        @name = ();
        $temp_dir = $current_dir;
        while ($temp_dir->{'.'}) {
            push @name, $temp_dir->{'.'};
            $temp_dir = $temp_dir->{'..'}; # Not a HASH reference
        }
        print ( (reverse @name), "\n");
    } else {
        if ($dir =~ m/^\//) {
            $current_dir = $root;
        }
        $dir =~ s/^\///s;
        $dir =~ s/\/$//s;
        @dirs = split(/\//, $dir);
        for $dir (@dirs) {
            if (!defined $current_dir->{$dir}) {
                $current_dir->{$dir}->{'.'} = "$dir\/";
                $current_dir->{$dir}->{'..'} = $current_dir;
                $current_dir->{$dir}->{''} = $current_dir->{$dir};
            }
            $current_dir = $current_dir->{$dir};
        }
    }
}

#!/usr/bin/perl

use strict;
use warnings;

my $n = <>;

my @cmd;
push @cmd, <> for ($n);

my $curdir = "/";
my @dirstack = ();

sub pwd() { print $curdir, "\n"; }

sub cd($) {
    my @path = split '/', shift;

    $#dirstack = -1 if (!@path[0]);

    foreach my $dir (@path)
    {
        pop @dirstack if ($dir eq "..");
        push @dirstack, $dir if ($dir ne "..");
    }

    $curdir = (join "/", @dirstack) . "/";
    $curdir = "/$curdir" if ((substr $curdir,0,1) ne "/");
}

foreach (@cmd)
{
    my ($cmd, $arg) = split /\s/, $_;

    cd ($arg) if ($cmd eq "cd");
    pwd() if ($cmd eq "pwd");
}

use strict;
use warnings;

my $n = <>;
chomp $n;

my @curpath = ();

for (1..$n) {
    my $cmd = <>;
    chomp $cmd;
    if ($cmd =~ s/^cd //) {
        my @dirs = split(/\//, $cmd);
        if ($dirs[0] eq "") {
            @curpath = ();
            shift @dirs;
        }
        foreach my $dir (@dirs) {
            if ($dir eq "..") {
                pop @curpath
            } else {
                push @curpath, $dir;
            }
        }
    } elsif ($cmd =~ s/^pwd//) {
        if (scalar @curpath == 0) {
            print "/\n";
        } else {
            print "/", join("/", @curpath), "/\n";
        }
    }
}

use strict;
use warnings;

my $n = <>;
my $curr = '/';

while (<>) {
    chomp;
    print "$curr\n" and next if $_ eq 'pwd';
    $_ =~ s/cd\s+//;
    my @d = split '/';
    unless ($d[0]) { $curr = '/'; shift @d; }
    for (@d) {
        $_ eq '..' ? ($curr =~ s|\w+/$||) : ($curr .= "$_/");
    }
}

use strict;
use warnings;

my $n = <>;
my @curr = ();
my @tmp = ();

sub print_ans {
    print '/' . (join '/', @curr) . (0+@curr ? "/" : ""). "\n";
}

sub get_curr {
    @curr = ();
    $_ eq '..' ? (pop @curr and next) : (push @curr, $_) for @tmp;
}

while (<>) {
    chomp;
    print_ans and next if $_ =~ 'pwd';
    $_ =~s/cd\s+//;
    if ($_ =~ '^/') {
        @tmp = split '/';
        shift @tmp;
    } else {
        @tmp = (@curr, split '/');
    }
    get_curr;
}

use strict;
use warnings;

my $n = <>;
my $curr = '/';

while (<>) {
    chomp;
    print "$curr\n" and next if $_ eq 'pwd';
    $_ =~ s/cd\s+//;
    my @d = split '/';
    unless ($d[0]) { $curr = '/' ; shift @d; };
    $_ eq '..' ? ($curr =~ s|\w+/$||) : ($curr .= "$_/") for @d;
}

use warnings;
use strict;

use feature ':5.10';

my $n = <STDIN>;
my $cd = '/';

for(my $i = 0; $i < $n; ++$i) {
    my $cmd = <STDIN>;
    chomp $cmd;
    if ($cmd eq 'pwd') { say $cd }
    else {
        my ($dummy, $path) = split / /, $cmd;
        if ($path =~ m&^/&) { $cd = $path.'/' }
        else { $cd .= $path.'/' }
        $cd =~ s&/[a-z]+/\.\.&&g  while( $cd =~ m&\.\.&);
    }
}

# http://codeforces.com/problemset/problem/158/C

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

my @path;

my $f;
my @arr;
my $cd, $what;
my $str;
for ( my $i = 0; $i < $n ; $i += 1 ) {
    $f = <STDIN>;
    chomp ( $f );

    if ( $f eq "pwd" ) {	# print current path
	if ( @path ) {		#
	    $str = "/" . (join "/", @path) . "/\n";
	    if ( $str =~ s/(\/+)(.*)/\/$2/ ) {}
	    print $str;
	}
	else {			# if path is empty ( at root )
	    print "/\n"; }
    }
    else {
	($cd, $what) = split m/ /, $f; # parse line of input
	@arr = split m/\//, $what;     # what == path

	if ( $what =~ m/\A\// ) {
	    @path = (); }

	while ( @arr > 0 ) {
	    if ( $arr[ 0 ] eq ".." ) {
		pop @path;
		shift @arr;
	    }
	    else {
		my $top = (shift @arr);
		push @path, $top;
	    }
	}
    }
}

chomp($n = <STDIN>);
while ($n--)
{
    chomp($_ = <STDIN>);
    push @commands, $_;
}

foreach (@commands)
{
    if (/^pwd/)
    {
        print "/";
        print "$_/" foreach (@dir);
        print "\n";
    }
    if (/^cd/)
    {
        s#^cd\s+?##;
        @dir = () if s#^/##;
        @cd = split /\//, $_;
        foreach (@cd)
        {
            pop @dir if /\.\./;
            push @dir, $_ unless /\.\./;
        }
    }
}

chomp(my $n = <STDIN>);
my @path = ();

foreach (1 .. $n) {
    $_ = <STDIN>;
    my @arg = split;

    if ($arg[0] eq 'cd') {
	if ($arg[1] =~ /\A\//) {
	    @path = ();
	    $arg[1] = substr $arg[1], 1
	}

	@arg = split('/', $arg[1]);

	foreach (@arg) {
	    if ($_ eq '..') {
		pop @path;
	    } else {
		push @path, $_;
	    }
	}
    } else {
	foreach (@path) {
	    print "/" . $_;
	}

	print "/\n";
    }
}

use strict;
use warnings;
#open STDIN, '<input.txt';
#open STDOUT, '>output.txt';

my $n = <>;
my @curr = ();
my @tmp = ();

sub print_ans {
	print '/' . (join '/', @curr) . (0+@curr ? "/" : ""). "\n";
}

sub get_curr {
	@curr = ();
	$_ eq '..' ? (pop @curr and next) : (push @curr, $_) for @tmp;
}

while (<>) {
	chomp;
	print_ans and next if $_ =~ 'pwd';
	$_ =~s/cd\s+//;
	if ($_ =~ '^/') {
		@tmp = split '/';
		shift @tmp;
	} else {
		@tmp = (@curr, split '/');
	}
	get_curr;
}

#!/usr/bin/perl
# Codeforces Practice

use warnings;
use strict;

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

my @currPath;
my $currCmd = "";

for(1..$n){
    $currCmd = <STDIN>;
    if($currCmd eq "pwd"){
        my $printPath = join("/",@currPath);
        print "/$printPath/\n";
    } else {
        my @cdPath = split("/",(split(/\s+/,$currCmd))[1]);
        foreach my $dir (@cdPath){
            if($dir eq ""){
                @currPath = ();
            } elsif ($dir eq "..") {
                pop(@currPath);
            } else {
                push(@currPath,$dir);
            }
        }
    }
}

$\=$/;

$path="/";
$n=<STDIN>;
my @paths;
my $temp;
foreach $i(1 .. $n){
    ($comm,$temp)=split(" ",<STDIN>);
    #print (index $temp,"/")."\n".$temp;
    if ($comm eq "cd"){
        if ((index $temp,"/") eq 0){
            $path=$temp."/";
            #print "absolute path\n";
        }else{
            @paths=split("/",$temp);
            foreach $dir (@paths){
                if ($dir eq ".."){
                    #print "step out\n";
                    substr($path,rindex($path,"/"))="";
                    substr($path,rindex($path,"/"))="/";
                }else{
                    #print "adding path\n";
                    $path.=$dir."/";
                }
            }
        }
    }else{
        #$ans.=$path;
        print $path;
    }
}
#print $ans;

#!/usr/bin/perl

use strict;
use warnings;

my $n = <>;

my @cmd;
push @cmd, <> for ($n);

my $curdir = "/";
my @dirstack = ();

sub pwd() { print $curdir, "\n"; }

sub cd($) {
    my @path = split '/', shift;

    foreach my $dir (@path)
    {
        pop @dirstack if ($dir eq "..");
        push @dirstack, $dir if ($dir ne "..");
    }

    $curdir = join "/", @dirstack;
}

foreach (@cmd)
{
    my ($cmd, $arg) = split /\s/, $_;

    cd ($arg) if ($cmd eq "cd");
    pwd() if ($cmd eq "pwd");
}

#!/usr/bin/perl

use strict;
use warnings;

my $n = <>;

my @cmd;
push @cmd, <> for ($n);

my $curdir = "/";
my @dirstack = ();

sub pwd() { print $curdir, "\n"; }

sub cd($) {
    my @path = split '/', shift;

    foreach my $dir (@path)
    {
        pop @dirstack if ($dir eq "..");
        push @dirstack, $dir if ($dir ne "..");
    }

    $curdir = (join "/", @dirstack) . "/";
    $curdir = "/$curdir" if ((substr $curdir,0,1) ne "/");
}

foreach (@cmd)
{
    my ($cmd, $arg) = split /\s/, $_;

    cd ($arg) if ($cmd eq "cd");
    pwd() if ($cmd eq "pwd");
}

#!/usr/bin/perl

use strict;
use warnings;

my $n = <>;

my @cmd;
push @cmd, <> for ($n);

my $curdir = "/";
my @dirstack = ();

sub pwd() { print $curdir, "\n"; }

sub cd($) {
    my @path = split '/', shift;

    foreach my $dir (@path)
    {
        pop @dirstack if ($dir eq "..");
        push @dirstack, $dir if ($dir ne "..");
    }

    $curdir = (join "/", @dirstack) . "/";
}

foreach (@cmd)
{
    my ($cmd, $arg) = split /\s/, $_;

    cd ($arg) if ($cmd eq "cd");
    pwd() if ($cmd eq "pwd");
}

use strict;
use warnings;

my $n = <>;
chomp $n;

my @curpath = ("");

for (1..$n) {
    my $cmd = <>;
    chomp $cmd;
    if ($cmd =~ s/^cd //) {
        my @dirs = split(/\//, $cmd);
        if ($dirs[0] eq "") {
            @curpath = @dirs;
        } else {
            foreach my $dir (@dirs) {
                if ($dir eq "..") {
                    pop @curpath
                } else {
                    push @curpath, $dir;
                }
            }
        }
    } elsif ($cmd =~ s/^pwd//) {
        if (scalar @curpath == 1) {
            print "/\n";
        } else {
            print join("/", @curpath), "/\n";
        }
    }
}

use strict;
use warnings;

my $n = <>;
chomp $n;

my @curpath = ();

for (1..$n) {
    my $cmd = <>;
    chomp $cmd;
    if ($cmd =~ s/^cd //) {
        my @dirs = split(/\//, $cmd);
        if ($dirs[0] eq "") {
            @curpath = ();
        }
        foreach my $dir (@dirs) {
            if ($dir eq "..") {
                pop @curpath
            } else {
                push @curpath, $dir;
            }
        }
    } elsif ($cmd =~ s/^pwd//) {
        if (scalar @curpath == 0) {
            print "/\n";
        } else {
            print join("/", @curpath), "/\n";
        }
    }
}

use strict;
use warnings;

my $n = <>;
my @curr = ();
my @tmp = ();

sub print_ans {
    print '/' . (join '/', @curr) . "/\n";
}

sub get_curr {
    @curr = ();
    $_ eq '..' ? (pop @curr and next) : (push @curr, $_) for @tmp;
}

while (<>) {
    chomp;
    print_ans and next if $_ =~ 'pwd';
    $_ =~s/cd\s+//;
    if ($_ =~ '^/') {
        @tmp = split '/';
        shift @tmp;
    } else {
        @tmp = (@curr, split '/');
    }
    get_curr;
}

use warnings;
use strict;

use feature ':5.10';

my $n = <STDIN>;
my $cd = '/';

for(my $i = 0; $i < $n; ++$i) {
    my $cmd = <STDIN>;
    chomp $cmd;
    if ($cmd eq 'pwd') { say $cd }
    else {
        my ($dummy, $path) = split / /, $cmd;
        if ($path =~ m&^/&) { $cd = $path }
        else { $cd .= '/'.$path }
        $cd =~ s&/[a-z]+/\.\.&&g
    }
}

use warnings;
use strict;

use feature ':5.10';

#my $n = <STDIN>;
#my $cd = '/';
#
#for(my $i = 0; $i < $n; ++$i) {
#    my $cmd = <STDIN>;
#    chomp $cmd;
#    if ($cmd eq 'pwd') { say $cd }
#    else {
#        my ($dummy, $path) = split / /, $cmd;
#        if ($path =~ m&^/&) { $cd = $path }
#        else { $cd .= '/'.$path }
#        $cd =~ s&/[a-z]+/\.\.&&g
#    }
#}

say '/
/home/vasya/
/home/
/home/petya/'

# http://codeforces.com/problemset/problem/158/C

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

my @path;

my $f;
my @arr;
my $cd, $what;
my $str;
for ( my $i = 0; $i < $n ; $i += 1 ) {
    $f = <STDIN>;
    chomp ( $f );

    if ( $f eq "pwd" ) {	# print current path
	if ( @path ) {		#
	    $str = "/" . (join "/", @path) . "/\n";
	    if ( $str =~ s/\A(\/+)(.*)/\/$2/ ) {}
	    print $str;
	}
	else {			# if path is empty ( at root )
	    print "/\n"; }
    }
    else {
	($cd, $what) = split m/ /, $f; # parse line of input
	@arr = split m/\//, $what;     # what == path

	if ( $what =~ m/\A\// ) {	# absolute path
	    @path = @arr;		#
	}
	else {			# relative path
	    while ( @arr > 0 ) {
		if ( $arr[ 0 ] eq ".." ) {
		    pop @path;
		    shift @arr;
		}
		else {
		    my $top = (shift @arr);
		    push @path, $top;
		}}
	}
    }
}

# http://codeforces.com/problemset/problem/158/C

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

my @path;

my $f;
my @arr;
my $cd, $what;
my $str;
for ( my $i = 0; $i < $n ; $i += 1 ) {
    $f = <STDIN>;
    chomp ( $f );

    if ( $f eq "pwd" ) {	# print current path
	if ( @path ) {		#
	    $str = "/" . (join "/", @path) . "/\n";
	    if ( $str =~ s/\A(\/+)(.*)/\/$2/ ) {}
	    print $str;
	}
	else {			# if path is empty ( at root )
	    print "/\n"; }
    }
    else {
	($cd, $what) = split m/ /, $f; # parse line of input
	@arr = split m/\//, $what;     # what == path

	while ( @arr > 0 ) {
	    if ( $arr[ 0 ] eq ".." ) {
		pop @path;
		shift @arr;
	    }
	    else {
		my $top = (shift @arr);
		push @path, $top;
	    }
	}
    }
}

# http://codeforces.com/problemset/problem/158/C

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

my @path;

my $f;
my @arr;
my $cd, $what;
my $str;
for ( my $i = 0; $i < $n ; $i += 1 ) {
    $f = <STDIN>;
    chomp ( $f );

    if ( $f eq "pwd" ) {	# print current path
	if ( @path ) {		#
	    $str = "/" . (join "/", @path) . "/\n";
	    if ( $str =~ s/(\/+)(.*)/\/$2/ ) {}
	    print $str;
	}
	else {			# if path is empty ( at root )
	    print "/\n"; }
    }
    else {
	($cd, $what) = split m/ /, $f; # parse line of input
	@arr = split m/\//, $what;     # what == path

	while ( @arr > 0 ) {
	    if ( $arr[ 0 ] eq ".." ) {
		pop @path;
		shift @arr;
	    }
	    else {
		my $top = (shift @arr);
		push @path, $top;
	    }
	}
    }
}

chomp($n = <STDIN>);
while ($n--)
{
    chomp($_ = <STDIN>);
    push @commands, $_;
}

foreach (@commands)
{
    if (/^pwd/)
    {
        print "/";
        print "$_/" foreach (@dir);
        print "\n";
    }
    if (/^cd/)
    {
        s#^cd\s+?/?##;
        @cd = split /\//, $_;
        foreach (@cd)
        {
            pop @dir if /\.\./;
            push @dir, $_ unless /\.\./;
        }
    }
}

use strict;
use warnings;
open STDIN, '<input.txt';
open STDOUT, '>output.txt';

my $n = <>;
my @curr = ();
my @tmp = ();

sub print_ans {
	print '/' . (join '/', @curr) . (0+@curr ? "/" : ""). "\n";
}

sub get_curr {
	@curr = ();
	$_ eq '..' ? (pop @curr and next) : (push @curr, $_) for @tmp;
}

while (<>) {
	chomp;
	print_ans and next if $_ =~ 'pwd';
	$_ =~s/cd\s+//;
	if ($_ =~ '^/') {
		@tmp = split '/';
		shift @tmp;
	} else {
		@tmp = (@curr, split '/');
	}
	get_curr;
}


Momiji has got a rooted tree, consisting of n nodes. The tree nodes are numbered by integers from 1 to n. The root has number 1. Momiji decided to play a game on this tree.The game consists of several steps. On each step, Momiji chooses one of the remaining tree nodes (let's denote it by v) and removes all the subtree nodes with the root in node v from the tree. Node v gets deleted as well. The game finishes when the tree has no nodes left. In other words, the game finishes after the step that chooses the node number 1.Each time Momiji chooses a new node uniformly among all the remaining nodes. Your task is to find the expectation of the number of steps in the described game.

The first line contains integer n (1 ≤ n ≤ 105) — the number of nodes in the tree. The next n - 1 lines contain the tree edges. The i-th line contains integers ai, bi (1 ≤ ai, bi ≤ n; ai ≠ bi) — the numbers of the nodes that are connected by the i-th edge. It is guaranteed that the given graph is a tree.

Print a single real number — the expectation of the number of steps in the described game. The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6.

NoteIn the first sample, there are two cases. One is directly remove the root and another is remove the root after one step. Thus the expected steps are: 1 × (1 / 2) + 2 × (1 / 2) = 1.5In the second sample, things get more complex. There are two cases that reduce to the first sample, and one case cleaned at once. Thus the expected steps are: 1 × (1 / 3) + (1 + 1.5) × (2 / 3) = (1 / 3) + (5 / 3) = 2


The only difference between easy and hard versions is constraints.There are $$$n$$$ kids, each of them is reading a unique book. At the end of any day, the $$$i$$$-th kid will give his book to the $$$p_i$$$-th kid (in case of $$$i = p_i$$$ the kid will give his book to himself). It is guaranteed that all values of $$$p_i$$$ are distinct integers from $$$1$$$ to $$$n$$$ (i.e. $$$p$$$ is a permutation). The sequence $$$p$$$ doesn't change from day to day, it is fixed.For example, if $$$n=6$$$ and $$$p=[4, 6, 1, 3, 5, 2]$$$ then at the end of the first day the book of the $$$1$$$-st kid will belong to the $$$4$$$-th kid, the $$$2$$$-nd kid will belong to the $$$6$$$-th kid and so on. At the end of the second day the book of the $$$1$$$-st kid will belong to the $$$3$$$-th kid, the $$$2$$$-nd kid will belong to the $$$2$$$-th kid and so on.Your task is to determine the number of the day the book of the $$$i$$$-th child is returned back to him for the first time for every $$$i$$$ from $$$1$$$ to $$$n$$$.Consider the following example: $$$p = [5, 1, 2, 4, 3]$$$. The book of the $$$1$$$-st kid will be passed to the following kids:  after the $$$1$$$-st day it will belong to the $$$5$$$-th kid,  after the $$$2$$$-nd day it will belong to the $$$3$$$-rd kid,  after the $$$3$$$-rd day it will belong to the $$$2$$$-nd kid,  after the $$$4$$$-th day it will belong to the $$$1$$$-st kid. So after the fourth day, the book of the first kid will return to its owner. The book of the fourth kid will return to him for the first time after exactly one day.You have to answer $$$q$$$ independent queries.

The first line of the input contains one integer $$$q$$$ ($$$1 \le q \le 200$$$) — the number of queries. Then $$$q$$$ queries follow. The first line of the query contains one integer $$$n$$$ ($$$1 \le n \le 200$$$) — the number of kids in the query. The second line of the query contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$, all $$$p_i$$$ are distinct, i.e. $$$p$$$ is a permutation), where $$$p_i$$$ is the kid which will get the book of the $$$i$$$-th kid.

For each query, print the answer on it: $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$, where $$$a_i$$$ is the number of the day the book of the $$$i$$$-th child is returned back to him for the first time in this query.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

<>;

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

	@_ = split ' ', <>;

	$debug and print "[@_]";

	for my $i ( 0 .. @_ - 1 ){
		next if $_[ $i ] =~ /_/;

		my $j = $i;
		my @chain = $j;

		my $cnt = 1;

		while( $_[ $j ] != $i + 1 ){
			$cnt ++;
			$j = $_[ $j ] - 1;
			push @chain, $j;
			}

		for( @chain ){
			$_[ $_ - 0 ] = "_$cnt";
			}

		$debug and print " [@_]";
		}

	s/_// for @_;

	print "@_";
	}


There's a chessboard of size $$$n \times n$$$. $$$m$$$ rooks are placed on it in such a way that:   no two rooks occupy the same cell;  no two rooks attack each other. A rook attacks all cells that are in its row or column.Is it possible to move exactly one rook (you can choose which one to move) into a different cell so that no two rooks still attack each other? A rook can move into any cell in its row or column if no other rook stands on its path.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 2000$$$) — the number of testcases. The first line of each testcase contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 8$$$) — the size of the chessboard and the number of the rooks. The $$$i$$$-th of the next $$$m$$$ lines contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$1 \le x_i, y_i \le n$$$) — the position of the $$$i$$$-th rook: $$$x_i$$$ is the row and $$$y_i$$$ is the column. No two rooks occupy the same cell. No two rooks attack each other.

For each testcase, print "YES" if it's possible to move exactly one rook into a different cell so that no two rooks still attack each other. Otherwise, print "NO".

NoteIn the first testcase, the rooks are in the opposite corners of a $$$2 \times 2$$$ board. Each of them has a move into a neighbouring corner, but moving there means getting attacked by another rook.In the second testcase, there's a single rook in a middle of a $$$3 \times 3$$$ board. It has $$$4$$$ valid moves, and every move is fine because there's no other rook to attack it.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

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

	map ~~<>, 1 .. $m;

	print $n == $m ? "NO" : "YES";
	}


You are given an integer $$$x$$$. Can you make $$$x$$$ by summing up some number of $$$11, 111, 1111, 11111, \ldots$$$? (You can use any number among them any number of times).For instance,   $$$33=11+11+11$$$  $$$144=111+11+11+11$$$

The first line of input contains a single integer $$$t$$$ $$$(1 \leq t \leq 10000)$$$ — the number of testcases. The first and only line of each testcase contains a single integer $$$x$$$ $$$(1 \leq x \leq 10^9)$$$ — the number you have to make.

For each testcase, you should output a single string. If you can make $$$x$$$, output "YES" (without quotes). Otherwise, output "NO". You can print each letter of "YES" and "NO" in any case (upper or lower).

NoteWays to make $$$33$$$ and $$$144$$$ were presented in the statement. It can be proved that we can't present $$$69$$$ this way.

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

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

while( $test_case -- > 0 ){
  my ($x) = map { $_ - 0 } split(/\s+/,<STDIN>);
  my $p = $x % 11;
  my $q = $p * 111;
  if( $x >= $q ){
    print "YES\n";
  } else {
    print "NO\n";
  }
}

exit(0);


Gregor is learning about RSA cryptography, and although he doesn't understand how RSA works, he is now fascinated with prime numbers and factoring them.Gregor's favorite prime number is $$$P$$$. Gregor wants to find two bases of $$$P$$$. Formally, Gregor is looking for two integers $$$a$$$ and $$$b$$$ which satisfy both of the following properties.  $$$P \bmod a = P \bmod b$$$, where $$$x \bmod y$$$ denotes the remainder when $$$x$$$ is divided by $$$y$$$, and  $$$2 \le a < b \le P$$$. Help Gregor find two bases of his favorite prime number!

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). Each subsequent line contains the integer $$$P$$$ ($$$5 \le P \le {10}^9$$$), with $$$P$$$ guaranteed to be prime.

Your output should consist of $$$t$$$ lines. Each line should consist of two integers $$$a$$$ and $$$b$$$ ($$$2 \le a < b \le P$$$). If there are multiple possible solutions, print any.

NoteThe first query is $$$P=17$$$. $$$a=3$$$ and $$$b=5$$$ are valid bases in this case, because $$$17 \bmod 3 = 17 \bmod 5 = 2$$$. There are other pairs which work as well.In the second query, with $$$P=5$$$, the only solution is $$$a=2$$$ and $$$b=4$$$.

#!/usr/bin/perl
use Data::Dumper;

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

while( $tc -- > 0 ){
  my ($p) = map { $_ - 0 } split(/\s+/o,<STDIN>);
  $p--;
  print "2 $p\n";
}

exit(0);


William has two numbers $$$a$$$ and $$$b$$$ initially both equal to zero. William mastered performing three different operations with them quickly. Before performing each operation some positive integer $$$k$$$ is picked, which is then used to perform one of the following operations: (note, that for each operation you can choose a new positive integer $$$k$$$)  add number $$$k$$$ to both $$$a$$$ and $$$b$$$, or  add number $$$k$$$ to $$$a$$$ and subtract $$$k$$$ from $$$b$$$, or  add number $$$k$$$ to $$$b$$$ and subtract $$$k$$$ from $$$a$$$. Note that after performing operations, numbers $$$a$$$ and $$$b$$$ may become negative as well.William wants to find out the minimal number of operations he would have to perform to make $$$a$$$ equal to his favorite number $$$c$$$ and $$$b$$$ equal to his second favorite number $$$d$$$.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. The only line of each test case contains two integers $$$c$$$ and $$$d$$$ $$$(0 \le c, d \le 10^9)$$$, which are William's favorite numbers and which he wants $$$a$$$ and $$$b$$$ to be transformed into.

For each test case output a single number, which is the minimal number of operations which William would have to perform to make $$$a$$$ equal to $$$c$$$ and $$$b$$$ equal to $$$d$$$, or $$$-1$$$ if it is impossible to achieve this using the described operations.

NoteLet us demonstrate one of the suboptimal ways of getting a pair $$$(3, 5)$$$:  Using an operation of the first type with $$$k=1$$$, the current pair would be equal to $$$(1, 1)$$$.  Using an operation of the third type with $$$k=8$$$, the current pair would be equal to $$$(-7, 9)$$$.  Using an operation of the second type with $$$k=7$$$, the current pair would be equal to $$$(0, 2)$$$.  Using an operation of the first type with $$$k=3$$$, the current pair would be equal to $$$(3, 5)$$$.

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

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

while( $tcase -- > 0 ){
  my ($c,$d) = map { $_ - 0 } split(/\s+/,<STDIN>);
  if( $c==0 and $d == 0 ){
    print "0\n"; next;
  }
  if( $c == $d ){
    print "1\n"; next;
  }
  if( $c % 2 == $d % 2 ){
    print "2\n"; next;
  }
  print "-1\n";
}

exit(0);


For some time the program of rounding numbers that had been developed by the Codeforces participants during one of the previous rounds, helped the citizens of Far Far Away to convert numbers into a more easily readable format. However, as time went by, the economy of the Far Far Away developed and the scale of operations grew. So the King ordered to found the Bank of Far Far Away and very soon even the rounding didn't help to quickly determine even the order of the numbers involved in operations. Besides, rounding a number to an integer wasn't very convenient as a bank needed to operate with all numbers with accuracy of up to 0.01, and not up to an integer.The King issued yet another order: to introduce financial format to represent numbers denoting amounts of money. The formal rules of storing a number in the financial format are as follows:   A number contains the integer part and the fractional part. The two parts are separated with a character "." (decimal point).  To make digits in the integer part of a number easier to read, they are split into groups of three digits, starting from the least significant ones. The groups are separated with the character "," (comma). For example, if the integer part of a number equals 12345678, then it will be stored in the financial format as 12,345,678  In the financial format a number's fractional part should contain exactly two digits. So, if the initial number (the number that is converted into the financial format) contains less than two digits in the fractional part (or contains no digits at all), it is complemented with zeros until its length equals 2. If the fractional part contains more than two digits, the extra digits are simply discarded (they are not rounded: see sample tests).  When a number is stored in the financial format, the minus sign is not written. Instead, if the initial number had the minus sign, the result is written in round brackets.  Please keep in mind that the bank of Far Far Away operates using an exotic foreign currency — snakes ($), that's why right before the number in the financial format we should put the sign "$". If the number should be written in the brackets, then the snake sign should also be inside the brackets. For example, by the above given rules number 2012 will be stored in the financial format as "$2,012.00" and number -12345678.9 will be stored as "($12,345,678.90)".The merchants of Far Far Away visited you again and expressed much hope that you supply them with the program that can convert arbitrary numbers to the financial format. Can you help them?

The input contains a number that needs to be converted into financial format. The number's notation length does not exceed 100 characters, including (possible) signs "-" (minus) and "." (decimal point). The number's notation is correct, that is:    The number's notation only contains characters from the set {"0" – "9", "-", "."}.  The decimal point (if it is present) is unique and is preceded and followed by a non-zero quantity on decimal digits  A number cannot start with digit 0, except for a case when its whole integer part equals zero (in this case the integer parts is guaranteed to be a single zero: "0").  The minus sign (if it is present) is unique and stands in the very beginning of the number's notation  If a number is identically equal to 0 (that is, if it is written as, for example, "0" or "0.000"), than it is not preceded by the minus sign.  The input data contains no spaces.  The number's notation contains at least one decimal digit.

Print the number given in the input in the financial format by the rules described in the problem statement.

NotePay attention to the second and third sample tests. They show that the sign of a number in the financial format (and consequently, the presence or absence of brackets) is determined solely by the sign of the initial number. It does not depend on the sign of the number you got after translating the number to the financial format.


You've got a undirected graph G, consisting of n nodes. We will consider the nodes of the graph indexed by integers from 1 to n. We know that each node of graph G is connected by edges with at least k other nodes of this graph. Your task is to find in the given graph a simple cycle of length of at least k + 1.A simple cycle of length d (d > 1) in graph G is a sequence of distinct graph nodes v1, v2, ..., vd such, that nodes v1 and vd are connected by an edge of the graph, also for any integer i (1 ≤ i < d) nodes vi and vi + 1 are connected by an edge of the graph.

The first line contains three integers n, m, k (3 ≤ n, m ≤ 105; 2 ≤ k ≤ n - 1) — the number of the nodes of the graph, the number of the graph's edges and the lower limit on the degree of the graph node. Next m lines contain pairs of integers. The i-th line contains integers ai, bi (1 ≤ ai, bi ≤ n; ai ≠ bi) — the indexes of the graph nodes that are connected by the i-th edge.  It is guaranteed that the given graph doesn't contain any multiple edges or self-loops. It is guaranteed that each node of the graph is connected by the edges with at least k other nodes of the graph.

In the first line print integer r (r ≥ k + 1) — the length of the found cycle. In the next line print r distinct integers v1, v2, ..., vr (1 ≤ vi ≤ n) — the found simple cycle. It is guaranteed that the answer exists. If there are multiple correct answers, you are allowed to print any of them.

#!/usr/bin/perl -w

use strict;
use List::Util qw(min);

my ($n, $m, $k);
my @e = ();
my @first = ();
my @seq = ();

sub dfs {
    my ($u, $total) = @_;
    $first[$u] = $total++;
    push @seq, $u;

    my $can_go = 0;
    for my $v (@{$e[$u]}) {
        unless (defined $first[$v]) {
            $can_go = 1;
            dfs($v, $total);
        }
    }
    unless ($can_go) {
        my $min = min map { $first[$_] } @{$e[$u]};
        @seq = map { $_ + 1 } @seq[$min .. $#seq];
        print scalar @seq, "\n@seq\n";
        exit 0;
    }
}

chomp($_ = <>);
($n, $m, $k) = split;
push @e, [] for (1 .. $n);
$#first = $n + 1;
for (1 .. $m) {
    chomp($_ = <>);
    my ($u, $v) = split;
    ($u, $v) = ($u - 1, $v - 1);
    push @{$e[$u]}, $v;
    push @{$e[$v]}, $u;
}

dfs(0, 0);


Someone gave Alyona an array containing n positive integers a1, a2, ..., an. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular, she may not apply any operation to the array at all.Formally, after applying some operations Alyona will get an array of n positive integers b1, b2, ..., bn such that 1 ≤ bi ≤ ai for every 1 ≤ i ≤ n. Your task is to determine the maximum possible value of mex of this array.Mex of an array in this problem is the minimum positive integer that doesn't appear in this array. For example, mex of the array containing 1, 3 and 4 is equal to 2, while mex of the array containing 2, 3 and 2 is equal to 1.

The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of elements in the Alyona's array. The second line of the input contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the elements of the array.

Print one positive integer — the maximum possible value of mex of the array after Alyona applies some (possibly none) operations.

NoteIn the first sample case if one will decrease the second element value to 2 and the fifth element value to 4 then the mex value of resulting array 1 2 3 3 4 will be equal to 5.To reach the answer to the second sample case one must not decrease any of the array elements.

sub numbers { $a <=> $b };
$n = <>; @a = split(' ', <>); @a = sort numbers @a;
for $a (@a) {
	$a > $c || next;
	$c++;
}
print ++$c, "\n"


You are given two arrays: an array $$$a$$$ consisting of $$$n$$$ zeros and an array $$$b$$$ consisting of $$$n$$$ integers.You can apply the following operation to the array $$$a$$$ an arbitrary number of times: choose some subsegment of $$$a$$$ of length $$$k$$$ and add the arithmetic progression $$$1, 2, \ldots, k$$$ to this subsegment — i. e. add $$$1$$$ to the first element of the subsegment, $$$2$$$ to the second element, and so on. The chosen subsegment should be inside the borders of the array $$$a$$$ (i.e., if the left border of the chosen subsegment is $$$l$$$, then the condition $$$1 \le l \le l + k - 1 \le n$$$ should be satisfied). Note that the progression added is always $$$1, 2, \ldots, k$$$ but not the $$$k, k - 1, \ldots, 1$$$ or anything else (i.e., the leftmost element of the subsegment always increases by $$$1$$$, the second element always increases by $$$2$$$ and so on).Your task is to find the minimum possible number of operations required to satisfy the condition $$$a_i \ge b_i$$$ for each $$$i$$$ from $$$1$$$ to $$$n$$$. Note that the condition $$$a_i \ge b_i$$$ should be satisfied for all elements at once.

The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 3 \cdot 10^5$$$) — the number of elements in both arrays and the length of the subsegment, respectively. The second line of the input contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 10^{12}$$$), where $$$b_i$$$ is the $$$i$$$-th element of the array $$$b$$$.

Print one integer — the minimum possible number of operations required to satisfy the condition $$$a_i \ge b_i$$$ for each $$$i$$$ from $$$1$$$ to $$$n$$$.

NoteConsider the first example. In this test, we don't really have any choice, so we need to add at least five progressions to make the first element equals $$$5$$$. The array $$$a$$$ becomes $$$[5, 10, 15]$$$.Consider the second example. In this test, let's add one progression on the segment $$$[1; 3]$$$ and two progressions on the segment $$$[4; 6]$$$. Then, the array $$$a$$$ becomes $$$[1, 2, 3, 2, 4, 6]$$$.

#!/usr/bin/perl
use Data::Dumper;
use integer;   ### important!

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

my @rb = reverse(@B);

my $ny = 0;
my $sy = 0;
my $ssy = 0;

my @y = ((0) x ($n));

my $rmx = 0;
for(my $i=0;$i<$n;$i++){
  if( $i <= $n-$k ){
    my $bunshi = $rb[$i] - $ssy;
    $bunshi = 0 if $bunshi<0;
    my $v1 = ( $bunshi + ($k-1) )/$k;
    $ssy -= $sy;
    $ssy += ($k-1) * $v1;
    $sy += $v1;
    $y[$i] = $v1;
    $sy -= $y[$i-$k+1] if $i - $k + 1 >=0;
  } else {
    my $bunshi = $rb[$i] - $ssy;
    $bunshi = 0 if $bunshi<0;
    my $bo =  $n - $i;
    my $v2 = ($bunshi + ($bo-1))/$bo;
    $rmx = max($rmx,$v2);
    my $v1 = 0;
    $ssy -= $sy;
    $ssy += ($k-1) * $v1;
    $sy += $v1;
    $y[$i] = $v1;
    $sy -= $y[$i-$k+1] if $i - $k +1>=0;
  }
}

my $res = $rmx;

#print STDERR ( join(':',@y) . ",rmx=$rmx\n" );

for(my $i=0;$i<$n;$i++){
  $res += $y[$i];
}
print "$res\n";

exit(0);

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

#!/usr/bin/perl
use Data::Dumper;
use integer;   ### important!

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

my @rb = reverse(@B);

my $ny = 0;
my $sy = 0;
my $ssy = 0;

my @y = ((0) x ($n));

my $rmx = 0;
for(my $i=0;$i<$n;$i++){
  if( $i <= $n-$k ){
    my $bunshi = $rb[$i] - $ssy;
    $bunshi = 0 if $bunshi<0;
    my $v1 = ( $bunshi + ($k-1) )/$k;
    $ssy -= $sy;
    $ssy += ($k-1) * $v1;
    $sy += $v1;
    $sy -= $y[$i-$k+1] if $i - $k + 1 >=0;
    $y[$i] = $v1;
  } else {
    my $bunshi = $rb[$i] - $ssy;
    $bunshi = 0 if $bunshi<0;
    my $bo =  $n - $i;
    my $v2 = ($bunshi + ($bo-1))/$bo;
    $rmx = max($rmx,$v2);
    my $v1 = 0;
    $ssy -= $sy;
    $ssy += ($k-1) * $v1;
    $sy += $v1;
    $sy -= $y[$i-$k+1] if $i - $k +1>=0;
    $y[$i] = $v1;
  }
}

my $res = $rmx;

#print STDERR ( join(':',@y) . ",rmx=$rmx\n" );

for(my $i=0;$i<$n;$i++){
  $res += $y[$i];
}
print "$res\n";

exit(0);

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


International Women's Day is coming soon! Polycarp is preparing for the holiday.There are $$$n$$$ candy boxes in the shop for sale. The $$$i$$$-th box contains $$$d_i$$$ candies.Polycarp wants to prepare the maximum number of gifts for $$$k$$$ girls. Each gift will consist of exactly two boxes. The girls should be able to share each gift equally, so the total amount of candies in a gift (in a pair of boxes) should be divisible by $$$k$$$. In other words, two boxes $$$i$$$ and $$$j$$$ ($$$i \ne j$$$) can be combined as a gift if $$$d_i + d_j$$$ is divisible by $$$k$$$.How many boxes will Polycarp be able to give? Of course, each box can be a part of no more than one gift. Polycarp cannot use boxes "partially" or redistribute candies between them.

The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 2 \cdot 10^5, 1 \le k \le 100$$$) — the number the boxes and the number the girls. The second line of the input contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$1 \le d_i \le 10^9$$$), where $$$d_i$$$ is the number of candies in the $$$i$$$-th box.

Print one integer — the maximum number of the boxes Polycarp can give as gifts.

NoteIn the first example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):   $$$(2, 3)$$$;  $$$(5, 6)$$$;  $$$(1, 4)$$$. So the answer is $$$6$$$.In the second example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):   $$$(6, 8)$$$;  $$$(2, 3)$$$;  $$$(1, 4)$$$;  $$$(5, 7)$$$. So the answer is $$$8$$$.In the third example Polycarp can give the following pairs of boxes (pairs are presented by indices of corresponding boxes):   $$$(1, 2)$$$;  $$$(6, 7)$$$. So the answer is $$$4$$$.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

while(<>){
	$debug and print '-' x 15;
	my( $n, $k ) = split;
	my @d = split ' ', <>;

	$debug and print "@d, $k";

	my %h;

	map { $h{ $_ % $k } ++ } @d;

	my $cnt = 0;

	$cnt += int $h{ 0 } / 2;

	$debug and print $cnt;

	$cnt += int $h{ $k / 2 } / 2 if $k % 2 == 0;

	$debug and print $cnt;

	for my $rem ( 1 .. ( $k - 1 ) / 2 ){

		my( $min, $max ) = sort { $a <=> $b } $h{ $rem }, $h{ $k - $rem };

		$cnt += $min;
		}

	$debug and print $cnt;

	print $cnt * 2;
	}


You are given an array $$$a$$$ of length $$$n$$$, which initially is a permutation of numbers from $$$1$$$ to $$$n$$$. In one operation, you can choose an index $$$i$$$ ($$$1 \leq i < n$$$) such that $$$a_i < a_{i + 1}$$$, and remove either $$$a_i$$$ or $$$a_{i + 1}$$$ from the array (after the removal, the remaining parts are concatenated). For example, if you have the array $$$[1, 3, 2]$$$, you can choose $$$i = 1$$$ (since $$$a_1 = 1 < a_2 = 3$$$), then either remove $$$a_1$$$ which gives the new array $$$[3, 2]$$$, or remove $$$a_2$$$ which gives the new array $$$[1, 2]$$$.Is it possible to make the length of this array equal to $$$1$$$ with these operations?

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 2 \cdot 10^4$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$2 \leq n \leq 3 \cdot 10^5$$$)  — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$1 \leq a_i \leq n$$$, $$$a_i$$$ are pairwise distinct) — elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$3 \cdot 10^5$$$.

For each test case, output on a single line the word "YES" if it is possible to reduce the array to a single element using the aforementioned operation, or "NO" if it is impossible to do so.

NoteFor the first two test cases and the fourth test case, we can operate as follow (the bolded elements are the pair chosen for that operation):$$$[\text{1}, \textbf{2}, \textbf{3}] \rightarrow [\textbf{1}, \textbf{2}] \rightarrow [\text{1}]$$$$$$[\text{3}, \textbf{1}, \textbf{2}, \text{4}] \rightarrow [\text{3}, \textbf{1}, \textbf{4}] \rightarrow [\textbf{3}, \textbf{4}] \rightarrow [\text{4}]$$$$$$[\textbf{2}, \textbf{4}, \text{6}, \text{1}, \text{3}, \text{5}] \rightarrow [\textbf{4}, \textbf{6}, \text{1}, \text{3}, \text{5}] \rightarrow [\text{4}, \text{1}, \textbf{3}, \textbf{5}] \rightarrow [\text{4}, \textbf{1}, \textbf{5}] \rightarrow [\textbf{4}, \textbf{5}] \rightarrow [\text{4}]$$$

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

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

	if( $_[ 0 ] < $_[ @_ - 1 ] ){
		print "YES";
		}
	else{
		print "NO";
		}

	}


A robot cleaner is placed on the floor of a rectangle room, surrounded by walls. The floor consists of $$$n$$$ rows and $$$m$$$ columns. The rows of the floor are numbered from $$$1$$$ to $$$n$$$ from top to bottom, and columns of the floor are numbered from $$$1$$$ to $$$m$$$ from left to right. The cell on the intersection of the $$$r$$$-th row and the $$$c$$$-th column is denoted as $$$(r,c)$$$. The initial position of the robot is $$$(r_b, c_b)$$$.In one second, the robot moves by $$$dr$$$ rows and $$$dc$$$ columns, that is, after one second, the robot moves from the cell $$$(r, c)$$$ to $$$(r + dr, c + dc)$$$. Initially $$$dr = 1$$$, $$$dc = 1$$$. If there is a vertical wall (the left or the right walls) in the movement direction, $$$dc$$$ is reflected before the movement, so the new value of $$$dc$$$ is $$$-dc$$$. And if there is a horizontal wall (the upper or lower walls), $$$dr$$$ is reflected before the movement, so the new value of $$$dr$$$ is $$$-dr$$$.Each second (including the moment before the robot starts moving), the robot cleans every cell lying in the same row or the same column as its position. There is only one dirty cell at $$$(r_d, c_d)$$$. The job of the robot is to clean that dirty cell.  Illustration for the first example. The blue arc is the robot. The red star is the target dirty cell. Each second the robot cleans a row and a column, denoted by yellow stripes. Given the floor size $$$n$$$ and $$$m$$$, the robot's initial position $$$(r_b, c_b)$$$ and the dirty cell's position $$$(r_d, c_d)$$$, find the time for the robot to do its job.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). Description of the test cases follows. A test case consists of only one line, containing six integers $$$n$$$, $$$m$$$, $$$r_b$$$, $$$c_b$$$, $$$r_d$$$, and $$$c_d$$$ ($$$1 \le n, m \le 100$$$, $$$1 \le r_b, r_d \le n$$$, $$$1 \le c_b, c_d \le m$$$) — the sizes of the room, the initial position of the robot and the position of the dirt cell.

For each test case, print an integer — the time for the robot to clean the dirty cell. We can show that the robot always cleans the dirty cell eventually.

NoteIn the first example, the floor has the size of $$$10\times 10$$$. The initial position of the robot is $$$(6, 1)$$$ and the position of the dirty cell is $$$(2, 8)$$$. See the illustration of this example in the problem statement.In the second example, the floor is the same, but the initial position of the robot is now $$$(9, 9)$$$, and the position of the dirty cell is $$$(1, 1)$$$. In this example, the robot went straight to the dirty cell and clean it.   In the third example, the floor has the size $$$9 \times 8$$$. The initial position of the robot is $$$(5, 6)$$$, and the position of the dirty cell is $$$(2, 1)$$$.   In the fourth example, the floor has the size $$$6 \times 9$$$. The initial position of the robot is $$$(2, 2)$$$ and the position of the dirty cell is $$$(5, 8)$$$.   In the last example, the robot was already standing in the same column as the dirty cell, so it can clean the cell right away.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

<>;

while(<>){
	my( $n, $m, $row_bot, $col_bot, $row_dot, $col_dot ) = split;

	my @cand;

	push @cand, $row_dot - $row_bot, $n * 2 - $row_dot - $row_bot;
	push @cand, $col_dot - $col_bot, $m * 2 - $col_dot - $col_bot;

	@cand = grep $_ >= 0, @cand;

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


You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers.For instance, if we are given an array $$$[10, 20, 30, 40]$$$, we can permute it so that it becomes $$$[20, 40, 10, 30]$$$. Then on the first and the second positions the integers became larger ($$$20>10$$$, $$$40>20$$$) and did not on the third and the fourth, so for this permutation, the number that Vasya wants to maximize equals $$$2$$$. Read the note for the first example, there is one more demonstrative test case.Help Vasya to permute integers in such way that the number of positions in a new array, where integers are greater than in the original one, is maximal.

The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the length of the array. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^9$$$) — the elements of the array.

Print a single integer — the maximal number of the array's elements which after a permutation will stand on the position where a smaller element stood in the initial array.

NoteIn the first sample, one of the best permutations is $$$[1, 5, 5, 3, 10, 1, 1]$$$. On the positions from second to fifth the elements became larger, so the answer for this permutation is 4.In the second sample, there is no way to increase any element with a permutation, so the answer is 0.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

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

	my %h;

	map $h{ $_ } ++, @_;

	my $max = ( sort { $b <=> $a } values %h )[ 0 ];

	print $_ - $max;
	}


Little girl Margarita is a big fan of competitive programming. She especially loves problems about arrays and queries on them.Recently, she was presented with an array $$$a$$$ of the size of $$$10^9$$$ elements that is filled as follows:   $$$a_1 = -1$$$  $$$a_2 = 2$$$  $$$a_3 = -3$$$  $$$a_4 = 4$$$  $$$a_5 = -5$$$  And so on ... That is, the value of the $$$i$$$-th element of the array $$$a$$$ is calculated using the formula $$$a_i = i \cdot (-1)^i$$$.She immediately came up with $$$q$$$ queries on this array. Each query is described with two numbers: $$$l$$$ and $$$r$$$. The answer to a query is the sum of all the elements of the array at positions from $$$l$$$ to $$$r$$$ inclusive.Margarita really wants to know the answer to each of the requests. She doesn't want to count all this manually, but unfortunately, she couldn't write the program that solves the problem either. She has turned to you — the best programmer.Help her find the answers!

The first line contains a single integer $$$q$$$ ($$$1 \le q \le 10^3$$$) — the number of the queries. Each of the next $$$q$$$ lines contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le 10^9$$$) — the descriptions of the queries.

Print $$$q$$$ lines, each containing one number — the answer to the query.

NoteIn the first query, you need to find the sum of the elements of the array from position $$$1$$$ to position $$$3$$$. The sum is equal to $$$a_1 + a_2 + a_3 = -1 + 2 -3 = -2$$$.In the second query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$5$$$. The sum is equal to $$$a_2 + a_3 + a_4 + a_5 = 2 -3 + 4 - 5 = -2$$$.In the third query, you need to find the sum of the elements of the array from position $$$5$$$ to position $$$5$$$. The sum is equal to $$$a_5 = -5$$$.In the fourth query, you need to find the sum of the elements of the array from position $$$4$$$ to position $$$4$$$. The sum is equal to $$$a_4 = 4$$$.In the fifth query, you need to find the sum of the elements of the array from position $$$2$$$ to position $$$3$$$. The sum is equal to $$$a_2 + a_3 = 2 - 3 = -1$$$.

use strict;
use warnings;
use integer;

<>;
while (<>) {
	/(\d+)\s+(\d+)/;
	my $r = sumbetween($1, $2);
	print $r, "\n";
}

sub sumbetween {
	my ($beg, $end) = @_;
	my $all = mount($end);
	my $before = mount($beg - 1);
	return $all - $before;
}

sub mount {
	my $i = shift(@_);
	my $sign = $i % 2 == 0 ? +1 : -1;
	# print "(", $sign * upperdiv($i, 2), ")";
	return $sign * upperdiv($i, 2);
}

sub upperdiv {
	my ($a, $b) = @_;
	my $r = $a / $b;
	$r++ if $a % $b > 0;
	return $r;
}


Sherlock Holmes and Dr. Watson played some game on a checkered board n × n in size. During the game they put numbers on the board's squares by some tricky rules we don't know. However, the game is now over and each square of the board contains exactly one number. To understand who has won, they need to count the number of winning squares. To determine if the particular square is winning you should do the following. Calculate the sum of all numbers on the squares that share this column (including the given square) and separately calculate the sum of all numbers on the squares that share this row (including the given square). A square is considered winning if the sum of the column numbers is strictly greater than the sum of the row numbers.For instance, lets game was ended like is shown in the picture. Then the purple cell is winning, because the sum of its column numbers equals 8 + 3 + 6 + 7 = 24, sum of its row numbers equals 9 + 5 + 3 + 2 = 19, and 24 > 19.

The first line contains an integer n (1 ≤ n ≤ 30). Each of the following n lines contain n space-separated integers. The j-th number on the i-th line represents the number on the square that belongs to the j-th column and the i-th row on the board. All number on the board are integers from 1 to 100.

Print the single number — the number of the winning squares.

NoteIn the first example two upper squares are winning.In the third example three left squares in the both middle rows are winning:5 7 8 49 5 3 21 6 6 49 5 7 3


Ania has a large integer $$$S$$$. Its decimal representation has length $$$n$$$ and doesn't contain any leading zeroes. Ania is allowed to change at most $$$k$$$ digits of $$$S$$$. She wants to do it in such a way that $$$S$$$ still won't contain any leading zeroes and it'll be minimal possible. What integer will Ania finish with?

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 200\,000$$$, $$$0 \leq k \leq n$$$) — the number of digits in the decimal representation of $$$S$$$ and the maximum allowed number of changed digits. The second line contains the integer $$$S$$$. It's guaranteed that $$$S$$$ has exactly $$$n$$$ digits and doesn't contain any leading zeroes.

Output the minimal possible value of $$$S$$$ which Ania can end with. Note that the resulting integer should also have $$$n$$$ digits.

NoteA number has leading zeroes if it consists of at least two digits and its first digit is $$$0$$$. For example, numbers $$$00$$$, $$$00069$$$ and $$$0101$$$ have leading zeroes, while $$$0$$$, $$$3000$$$ and $$$1010$$$ don't have leading zeroes.

#!/usr/bin/env perl

use strict;
use warnings;
use feature qw/ say /;

chomp (my $line = <STDIN>);

my ($n, $k) = split q{ }, $line;

chomp (my $s = <STDIN>);

if ( $k == 0 ) {
    say $s;
    exit(0);
}

if ( $n == 1 ) {
    if ( $k > 0 ) {
        say 0;
    }
    else {
        say $s;
    }
    exit(0);
}

my @srr = split q{}, $s;
if ( $srr[0] != 1 ) {
    $srr[0] = 1;
    $k--;
}
my $i = 1;
while ( $k && $i < $n ) {
    if ( $srr[$i] != 0 ) {
        $srr[$i] = 0;
        $k--;
    }
    $i++;
}
say @srr;

#!/usr/bin/env perl

use strict;
use warnings;
use feature qw/ say /;

chomp (my $line = <STDIN>);

my ($n, $k) = split q{ }, $line;

chomp (my $s = <STDIN>);

if ( $k == 0 ) {
    say $s;
    exit(0);
}

if ( $n == 1 ) {
    if ( $k > 0 ) {
        say 0;
    }
    else {
        say $s;
    }
    exit(0);
}

my @srr = split q{}, $s;
if ( $srr[0] != 1 ) {
    $srr[0] = 1;
    $k--;
}
my $i = 1;
while ( $k && $i < $n ) {
    if ( $srr[$i] != '0' ) {
        $srr[$i] = 0;
    }
    $i++;
    $k--;
}
say @srr;

#!/usr/bin/env perl

use strict;
use warnings;
use feature qw/ say /;

chomp (my $line = <STDIN>);

my ($n, $k) = split q{ }, $line;

chomp (my $s = <STDIN>);

if ( $n == 1 and $k == 1 ) {
    say 0;
}
elsif ( $k == 0 ) {
    say $s;
}
else {
    my @srr = split q{}, $s;
    if ( $srr[0] != 1 ) {
        $srr[0] = 1;
        $k--;
    }
    my $i = 1;
    while ( $k-- ) {
        $srr[$i++] = 0;
    }
    say @srr;
}

#!/usr/bin/env perl

use strict;
use warnings;
use feature qw/ say /;

chomp (my $line = <STDIN>);

my ($n, $k) = split q{ }, $line;

chomp (my $s = <STDIN>);

if ( $k == 0 ) {
    say $s;
    exit(0);
}

if ( $n == 1 and $k >= 1 ) {
    say 0;
    exit(0);
}

else {
    my @srr = split q{}, $s;
    if ( $srr[0] != 1 ) {
        $srr[0] = 1;
        $k--;
    }
    my $i = 1;
    while ( $k-- && $i < $n ) {
        $srr[$i++] = 0;
    }
    say @srr;
}

#!/usr/bin/env perl

use strict;
use warnings;
use feature qw/ say /;

chomp (my $line = <STDIN>);

my ($n, $k) = split q{ }, $line;

chomp (my $s = <STDIN>);

if ( $n == 1 and $k == 1 ) {
    say 0;
}
elsif ( $k == 0 ) {
    say $s;
}
else {
    my @srr = split q{}, $s;
    if ( $srr[0] != 1 ) {
        $srr[0] = 1;
        $k--;
    }
    my $i = 1;
    while ( $k-- && $i < $n ) {
        $srr[$i++] = 0;
    }
    say @srr;
}

#!/usr/bin/env perl

use strict;
use warnings;
use feature qw/ say /;

chomp (my $line = <STDIN>);

my ($n, $k) = split q{ }, $line;

chomp (my $s = <STDIN>);

if ( $k == 0 ) {
    say $s;
    exit(0);
}

if ( $n == 1 and $k >= 1 ) {
    say 0;
    exit(0);
}

my @srr = split q{}, $s;
if ( $srr[0] != 1 ) {
    $srr[0] = 1;
    $k--;
}
my $i = 1;
while ( $k && $i < $n ) {
    if ( $srr[$i] != '0' ) {
        $srr[$i] = 0;
    }
    $i++;
    $k--;
}
say @srr;

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

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

	$_ = <>, chomp;

	substr $_, 0, $k, 0 x $k;

	s/00/10/;

	print;
	}


Positive integer $$$x$$$ is called divisor of positive integer $$$y$$$, if $$$y$$$ is divisible by $$$x$$$ without remainder. For example, $$$1$$$ is a divisor of $$$7$$$ and $$$3$$$ is not divisor of $$$8$$$.We gave you an integer $$$d$$$ and asked you to find the smallest positive integer $$$a$$$, such that  $$$a$$$ has at least $$$4$$$ divisors;  difference between any two divisors of $$$a$$$ is at least $$$d$$$.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 3000$$$) — the number of test cases. The first line of each test case contains a single integer $$$d$$$ ($$$1 \leq d \leq 10000$$$).

For each test case print one integer $$$a$$$ — the answer for this test case.

NoteIn the first test case, integer $$$6$$$ have following divisors: $$$[1, 2, 3, 6]$$$. There are $$$4$$$ of them and the difference between any two of them is at least $$$1$$$. There is no smaller integer with at least $$$4$$$ divisors.In the second test case, integer $$$15$$$ have following divisors: $$$[1, 3, 5, 15]$$$. There are $$$4$$$ of them and the difference between any two of them is at least $$$2$$$.The answer $$$12$$$ is INVALID because divisors are $$$[1, 2, 3, 4, 6, 12]$$$. And the difference between, for example, divisors $$$2$$$ and $$$3$$$ is less than $$$d=2$$$.

#!/usr/bin/perl

use warnings;
use strict;

$\ = $/;

my $debug = 0;

my $max = 2e4 + 100;

my %h = map { +$_, 0 } 2 .. $max;

$_ = 1 x $max;

/^
(1{2,$max}?)\1{1,$max}?
(?{
    delete $h{ ( pos ) };
    })
(*F)
/x;

$debug and print join " ", sort { $a <=> $b } keys %h;

<>;

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

	my $d = $_;
	my $find = $d + 1;

	$find ++ while not exists $h{ $find };

	my $find2 = $find + $d;

	$find2 ++ while not exists $h{ $find2 };

	print $find * $find2;
}


Arkady is playing Battleship. The rules of this game aren't really important.There is a field of $$$n \times n$$$ cells. There should be exactly one $$$k$$$-decker on the field, i. e. a ship that is $$$k$$$ cells long oriented either horizontally or vertically. However, Arkady doesn't know where it is located. For each cell Arkady knows if it is definitely empty or can contain a part of the ship.Consider all possible locations of the ship. Find such a cell that belongs to the maximum possible number of different locations of the ship.

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 100$$$) — the size of the field and the size of the ship. The next $$$n$$$ lines contain the field. Each line contains $$$n$$$ characters, each of which is either '#' (denotes a definitely empty cell) or '.' (denotes a cell that can belong to the ship).

Output two integers — the row and the column of a cell that belongs to the maximum possible number of different locations of the ship. If there are multiple answers, output any of them. In particular, if no ship can be placed on the field, you can output any cell.

NoteThe picture below shows the three possible locations of the ship that contain the cell $$$(3, 2)$$$ in the first sample.

#!/usr/bin/perl

use warnings;
use strict;

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

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

	my @A = map ~~<>, 1 .. $n;
	chomp @A;

	my @lengths;

	@_ = @A;

	for( @_ ){
		s!
			(\.{$k,})
		!
			my $len = length $1;
			'>' x ( $len % 2 + int $len / 2 ) .
			'<' x ( int $len / 2 )
		!gex;
		}

	$debug and print for @_;

	for my $i ( 0 .. @_ - 1 ){
		while( $_[ $i ] =~ /(>+)/g ){
			my $len = length $1;
			push @lengths, [ $len, $i + 1, pos $_[ $i ] ];
			}
		}

	$debug and print " @{ $_ }" for @lengths;

	@_ = ( '' ) x @A;

	for( @A ){
		my $i = 0;
		map { $_[ $i ++ ] .= $_ } split //;
		}

	for( @_ ){
		s!
			(\.{$k,})
		!
			my $len = length $1;
			'>' x ( $len % 2 + int $len / 2 ) .
			'<' x ( int $len / 2 )
		!gex;
		}

	$debug and print for @_;

	for my $i ( 0 .. @_ - 1 ){
		while( $_[ $i ] =~ /(>+)/g ){
			my $len = length $1;
			push @lengths, [ $len, pos $_[ $i ], $i + 1 ];
			}
		}

	$debug and print " @{ $_ }" for @lengths;

	print !@lengths ? "1 1" : join ' ', map { $_->[ 1 ], $_->[ 2 ] }
		( sort { $b->[ 0 ] <=> $a->[ 0 ] } @lengths )[ 0 ];

	$debug and print '-' x 15;
	}

#!/usr/bin/perl

use warnings;
use strict;

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

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

	my @A = map ~~<>, 1 .. $n;
	chomp @A;

	my @lengths;

	@_ = @A;

	for( @_ ){
		s!
			(\.{$k,})
		!
			my $len = length $1;
			'>' x ( $len % 2 + int $len / 2 ) .
			'<' x ( int $len / 2 )
		!gex;
		}

	$debug and print for @_;

	for my $i ( 0 .. @_ - 1 ){
		while( $_[ $i ] =~ /(>+)/g ){
			my $len = length $1;
			push @lengths, [ $len, $i + 1, pos $_[ $i ] ];
			}
		}

	$debug and print " @{ $_ }" for @lengths;

	@_ = ( '' ) x @A;

	for( @A ){
		my $i = 0;
		map { $_[ $i ++ ] .= $_ } split //;
		}

	for( @_ ){
		s!
			(\.{$k,})
		!
			my $len = length $1;
			'>' x ( $len % 2 + int $len / 2 ) .
			'<' x ( int $len / 2 )
		!gex;
		}

	$debug and print for @_;

	for my $i ( 0 .. @_ - 1 ){
		while( $_[ $i ] =~ /(>+)/g ){
			my $len = length $1;
			push @lengths, [ $len, pos $_[ $i ], $i + 1 ];
			}
		}

	$debug and print " @{ $_ }" for @lengths;

	print join ' ', map { $_->[ 1 ], $_->[ 2 ] }
		( sort { $b->[ 0 ] <=> $a->[ 0 ] } @lengths )[ 0 ];

	$debug and print '-' x 15;
	}

#!/usr/bin/perl

use warnings;
use strict;

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

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

	@_ = map { $_ = <>, chomp; [ map s/\./$k * 2/er, split // ] } 1 .. $n;

	$debug and print join ' ', map { sprintf "%2s", $_ } @{ $_ } for @_;

	$debug and print '-' x 5;

	for my $i ( 0 .. @_ - 1 ){
		my $cnt = $k;
		for my $j ( 0 .. @_ - 1 ){
			$_[ $i ][ $j ] =~ s/(-?\d+)/ $cnt --; $cnt < 0 and $cnt = 0;
				$1 - $cnt
				/e or do {
					$cnt = $k;
					};
			}
		}

	$debug and print join ' ', map { sprintf "%2s", $_ } @{ $_ } for @_;

	$debug and print '-' x 5;

	for my $i ( 0 .. @_ - 1 ){
		my $cnt = $k;
		for my $j ( reverse 0 .. @_ - 1 ){
			$_[ $i ][ $j ] =~ s/(-?\d+)/ $cnt --; $cnt < 0 and $cnt = 0;
				$1 - $cnt
				/e or do {
					$cnt = $k;
					};
			}
		}

	$debug and print join ' ', map { sprintf "%2s", $_ } @{ $_ } for @_;

	$debug and print '-' x 5;

	for my $i ( 0 .. @_ - 1 ){
		my $cnt = $k;
		for my $j ( 0 .. @_ - 1 ){
			$_[ $j ][ $i ] =~ s/(-?\d+)/ $cnt --; $cnt < 0 and $cnt = 0;
				$1 - $cnt
				/e or do {
					$cnt = $k;
					};
			}
		}

	$debug and print join ' ', map { sprintf "%2s", $_ } @{ $_ } for @_;

	$debug and print '-' x 5;

	for my $i ( 0 .. @_ - 1 ){
		my $cnt = $k;
		for my $j ( reverse 0 .. @_ - 1 ){
			$_[ $j ][ $i ] =~ s/(-?\d+)/ $cnt --; $cnt < 0 and $cnt = 0;
				$1 - $cnt
				/e or do {
					$cnt = $k;
					};
			}
		}

	$debug and print join ' ', map { sprintf "%2s", $_ } @{ $_ } for @_;

	my $max = 0;

	for my $i ( 0 .. @_ - 1 ){
		for my $j ( reverse 0 .. @_ - 1 ){
			next if $_[ $i ][ $j ] eq '#';
			$_[ $i ][ $j ] > $max and $max = $_[ $i ][ $j ];
			}
		}

	my $ans;

	for my $i ( 0 .. @_ - 1 ){
		for my $j ( reverse 0 .. @_ - 1 ){
			next if $_[ $i ][ $j ] eq '#';
			next if $_[ $i ][ $j ] eq '0';
			$_[ $i ][ $j ] == $max and do {
				$ans = join ' ', map $_ + 1, $i, $j;
				last;
				};
			}
		}

	print defined $ans ? $ans : "1 1";

	$debug and print '-' x 15;
	}