{"nl": {"description": "Valera has got n domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves and the sum of the numbers on the lower halves to be even.To do that, Valera can rotate the dominoes by 180 degrees. After the rotation the upper and the lower halves swap places. This action takes one second. Help Valera find out the minimum time he must spend rotating dominoes to make his wish come true.", "input_spec": "The first line contains integer n (1 ≤ n ≤ 100), denoting the number of dominoes Valera has. Next n lines contain two space-separated integers xi, yi (1 ≤ xi, yi ≤ 6). Number xi is initially written on the upper half of the i-th domino, yi is initially written on the lower half.", "output_spec": "Print a single number — the minimum required number of seconds. If Valera can't do the task in any time, print  - 1.", "sample_inputs": ["2\n4 2\n6 4", "1\n2 3", "3\n1 4\n2 3\n4 4"], "sample_outputs": ["0", "-1", "1"], "notes": "NoteIn the first test case the sum of the numbers on the upper halves equals 10 and the sum of the numbers on the lower halves equals 6. Both numbers are even, so Valera doesn't required to do anything.In the second sample Valera has only one piece of domino. It is written 3 on the one of its halves, therefore one of the sums will always be odd.In the third case Valera can rotate the first piece, and after that the sum on the upper halves will be equal to 10, and the sum on the lower halves will be equal to 8."}, "positive_code": [{"source_code": "use strict;\n\nchomp(my $n = <>);\nmy ($su, $sd, $c) = (0, 0, 0);\nfor (1 .. $n) {\n chomp($_ = <>);\n my ($a, $b) = split;\n $su ^= $a & 1;\n $sd ^= $b & 1;\n ++$c if $a % 2 != $b % 2;\n}\n\nmy $res = $su != $sd ? -1 : $su == 0 ? 0 : $c > 0 ? 1 : -1;\nprint $res;\n"}, {"source_code": "#!/usr/bin/env perl \n#===============================================================================\n# STDIN: domino.pl\n# AUTHOR: Phoenix Ikki (liuxueyang.github.io), liuxueyang457@gmail.com\n# ORGANIZATION: Hunan University\n# CREATED: 05/26/2015 09:15:44 AM\n#===============================================================================\n\nuse strict;\nuse warnings;\nuse utf8;\nuse 5.012;\n\n#open STDIN, \"in.txt\";\nwhile($_ = ){\n chomp($_);\n my ($sumx, $sumy, $cnt) = (0, 0, 0);\n while($_--){\n chomp(my $ln = );\n my ($x, $y) = split / /, $ln;\n $sumx += $x; $sumy += $y;\n $cnt += 1 if (abs($x - $y) % 2 == 1);\n }\n if (($sumx + $sumy) % 2 == 0) {\n if ($sumx % 2 == 1 && $cnt > 0) {\n print \"1\\n\";\n } elsif ($sumx % 2 == 0) {\n print \"0\\n\";\n } else {\n print \"-1\\n\";\n }\n } else {\n print \"-1\\n\";\n }\n}\n\n\n"}, {"source_code": "<>;\n@_=<>;\nfor(@_){\n\t/ /;\n\t$`%2 and $a++;\n\t$'%2 and $b++;\n\t$`%2 or $'%2 and $c++;\n\t$'%2 or $`%2 and $c++;\n\t}\n$a%=2;\n$b%=2;\n$a && $b && $c and print 1;\n$a && $b && !$c and print -1;\n$a or $b and print -1;\n$b or $a and print -1;\n$a or $b or print 0;"}, {"source_code": "my ($l, $r, $b) = (0, 0, 0);\nfor (1..<>) {\n my $d = join '', map {$_%2} split ' ', <>;\n $l++ if $d eq '10';\n $r++ if $d eq '01';\n $b++ if $d eq '11';\n}\nif (($l+$b)%2==0 && ($r+$b)%2==0) {\n print 0;\n} elsif (($l+$r)%2==1) {\n print -1;\n} elsif ($l || $r) {\n print 1;\n} else {\n print -1;\n}"}], "negative_code": [{"source_code": "#!/usr/bin/env perl \n#===============================================================================\n# STDIN: domino.pl\n# AUTHOR: Phoenix Ikki (liuxueyang.github.io), liuxueyang457@gmail.com\n# ORGANIZATION: Hunan University\n# CREATED: 05/26/2015 09:15:44 AM\n#===============================================================================\n\nuse strict;\nuse warnings;\nuse utf8;\nuse 5.012;\n\n#open STDIN, \"in.txt\";\nwhile($_ = ){\n chomp($_);\n my ($sumx, $sumy, $cnt) = (0, 0, 0);\n while($_--){\n chomp(my $ln = );\n my ($x, $y) = split / /, $ln;\n $sumx += $x; $sumy += $y;\n $cnt += 1 if (abs($x - $y) % 2 == 1);\n }\n if (($sumx + $sumy) % 2 == 0) {\n if ($sumx % 2 == 1 && $cnt > 0) {\n print \"1\\n\";\n } else {\n print \"0\\n\";\n }\n } else {\n print \"-1\\n\";\n }\n}\n\n\n"}, {"source_code": "<>;\n@_=<>;\nfor(@_){\n\t/ /;\n\t$`%2 and $a++;\n\t$'%2 and $b++;\n\t$`%2 or $'%2 and $c++;\n\t$'%2 or $`%2 and $c++;\n\t}\n\tprint \" $a $b $c\\n\";\n$a%=2;\n$b%=2;\n$a && $b && $c and print 1;\n$a && $b && !$c and print -1;\n$a or $b and print -1;\n$b or $a and print -1;\n$a or $b or print 0;"}, {"source_code": "$_ = <>-10;\nprint $_==10 ? 15 : $_<=0 || $_>11 ? 0 : 4;"}, {"source_code": "my ($l, $r, $o) = (0, 0, 0);\nfor (1..<>) {\n my @new = map {$_%2} split ' ', <>;\n $l += $new[0];\n $r += $new[1];\n $o++ if $new[0]&&$new[1];\n}\nif ($l%2==0 && $r%2==0) {\n print 0;\n} elsif ($l%2 && $r%2 && !$o) {\n print 1;\n} else {\n print -1;\n}"}], "src_uid": "f9bc04aed2b84c7dd288749ac264bb43"} {"nl": {"description": "You are given a chessboard of size 1 × n. It is guaranteed that n is even. The chessboard is painted like this: \"BWBW...BW\".Some cells of the board are occupied by the chess pieces. Each cell contains no more than one chess piece. It is known that the total number of pieces equals to .In one step you can move one of the pieces one cell to the left or to the right. You cannot move pieces beyond the borders of the board. You also cannot move pieces to the cells that are already occupied.Your task is to place all the pieces in the cells of the same color using the minimum number of moves (all the pieces must occupy only the black cells or only the white cells after all the moves are made).", "input_spec": "The first line of the input contains one integer n (2 ≤ n ≤ 100, n is even) — the size of the chessboard. The second line of the input contains integer numbers (1 ≤ pi ≤ n) — initial positions of the pieces. It is guaranteed that all the positions are distinct.", "output_spec": "Print one integer — the minimum number of moves you have to make to place all the pieces in the cells of the same color.", "sample_inputs": ["6\n1 2 6", "10\n1 2 3 4 5"], "sample_outputs": ["2", "10"], "notes": "NoteIn the first example the only possible strategy is to move the piece at the position 6 to the position 5 and move the piece at the position 2 to the position 3. Notice that if you decide to place the pieces in the white cells the minimum number of moves will be 3.In the second example the possible strategy is to move in 4 moves, then in 3 moves, in 2 moves and in 1 move."}, "positive_code": [{"source_code": "use warnings;\nuse strict;\nuse integer;\n$\\ = qq/\\n/, $, = qq/ / ;\nmy $n = ;\nmy @arr = sort { $a <=> $b } split qq/ /, ;\nmy $black = 0;\nfor ( my $ii = 0; $ii < ( $n / 2 ); $ii += 1 ) {\n $black += abs ( $arr [ $ii ] - ( 1 + ( 2 * $ii ) ) )\n}\nmy $white = 0;\nfor ( my $ii = 0; $ii < ( $n / 2 ); $ii += 1 ) {\n $white += abs ( $arr [ $ii ] - ( 2 + ( 2 * $ii ) ) )\n}\nprint ( $black > $white ? $white : $black );\n"}, {"source_code": "$n = <>;\n@pieces = sort { $a <=> $b } split ' ', <>;\n($w, $b) = (0, 0);\nfor (1..$n) {\n $i = ($_ - 1) / 2;\n $w += abs $_ - $pieces[$i] if $_ % 2;\n $b += abs $_ -$pieces[$i] if $_ % 2 == 0;\n}\nprint $w < $b ? $w : $b;\n\n"}], "negative_code": [{"source_code": "use warnings;\nuse strict;\n$, = q/ /, $\\ = qq/\\n/;\nmy ( $n, $m ) = split q/ /, ;\nmy @a = ();\nfor ( 1 .. $n ) {\n chomp ( my $s = [ split q//, ] );\n push @a, $s;\n}\nmy %lamp_to_switch = ();\nfor my $i ( 0 .. ($n - 1) ) {\n my $bl = 1;\n for my $j ( 0 .. ($m - 1) ) { \n if ( $a[$i][$j] eq '1' ) { \n if ( not exists $lamp_to_switch { $j + 1} ) {\n $lamp_to_switch { $i + 1 } -> { $j + 1 } = 1;\n $bl = 0;\n }\n }\n }\n if ( $bl ) {\n print \"YES\";\n exit;\n }\n}\nprint \"NO\";\nexit;\n"}, {"source_code": "use warnings;\nuse strict;\nuse integer;\n$\\ = qq/\\n/, $, = qq/ / ;\nmy $n = ;\nmy @arr = split qq/ /, ;\nmy $sum = 0;\nfor ( my $ii = 0; $ii < ( $n / 2 ); $ii += 1 ) {\n $sum += abs ( $arr [ $ii ] - ( 1 + ( 2 * $ii ) ) )\n}\nprint $sum; \n"}, {"source_code": "use warnings;\nuse strict;\nuse integer;\n$\\ = qq/\\n/, $, = qq/ / ;\nmy $n = ;\nmy @arr = sort { $a <=> $b } split qq/ /, ;\nmy $black = 0;\nfor ( my $ii = 0; $ii < ( $n / 2 ); $ii += 1 ) {\n $black += abs ( $arr [ $ii ] - ( 1 + ( 2 * $ii ) ) )\n}\nmy $white = 0;\nfor ( my $ii = 0; $ii < ( $n / 2 ); $ii += 1 ) {\n $white += abs ( $arr [ $ii ] - ( 2 + ( 2 * $ii ) ) )\n}\nprint qq/white $white/;\nprint qq/black $black/;\n\nprint ( $black > $white ? $white : $black );\n"}, {"source_code": "use warnings;\nuse strict;\nuse integer;\n$\\ = qq/\\n/, $, = qq/ / ;\nmy $n = ;\nmy @arr = split qq/ /, ;\nmy $black = 0;\nfor ( my $ii = 0; $ii < ( $n / 2 ); $ii += 1 ) {\n $black += abs ( $arr [ $ii ] - ( 1 + ( 2 * $ii ) ) )\n}\nmy $white = 0;\nfor ( my $ii = 0; $ii < ( $n / 2 ); $ii += 1 ) {\n $white += abs ( $arr [ $ii ] - ( 2 + ( 2 * $ii ) ) )\n}\nprint ( $black > $white ? $white : $black );\n"}, {"source_code": "$n = <>;\n@pieces = split ' ', <>;\n($w, $b) = (0, 0);\nfor (1..$n) {\n $i = ($_ - 1) / 2;\n $w += abs $_ - $pieces[$i] if $_ % 2;\n $b += abs $_ -$pieces[$i] if $_ % 2 == 0;\n}\nprint $w < $b ? $w : $b;"}], "src_uid": "0efe9afd8e6be9e00f7949be93f0ca1a"} {"nl": {"description": "As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where k is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers.A well-known hipster Andrew adores everything funky and cool but unfortunately, he isn't good at maths. Given number n, help him define whether this number can be represented by a sum of two triangular numbers (not necessarily different)!", "input_spec": "The first input line contains an integer n (1 ≤ n ≤ 109).", "output_spec": "Print \"YES\" (without the quotes), if n can be represented as a sum of two triangular numbers, otherwise print \"NO\" (without the quotes).", "sample_inputs": ["256", "512"], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first sample number .In the second sample number 512 can not be represented as a sum of two triangular numbers."}, "positive_code": [{"source_code": "$n=2*<>;\n$amax=int(sqrt($n))-1;\nfor $a (1..$amax) {\n\t$n2=$n-$a*($a+1);\n\t$b=int(sqrt($n2));\n\t$f=($b*($b+1)==$n2);\n\t# print \"a=$a b=$b f=$f\\n\";\n\tlast if $f;\n}\nprint $f?\"YES\":\"NO\", \"\\n\";\n"}, {"source_code": "my $n = ;\nmy $loop = 1;\n\nsub itr {\n my $x = shift;\n my $y = shift;\n my $i = shift;\n $loop++;\n my $sum;\n if($i){\n $sum = $i*($i+1)/2;\n $i++;\n }else{\n $i = 2;\n $sum = 1;\n }\n for($i; $sum<$y; $i++){\n $sum += $i;\n }\n \n #print \"$x, $y, $i, $sum, $loop \\n\";\n if($sum == $y){\n print \"YES\";\n } \n elsif($x > $y){\n print \"NO\";\n } \n elsif($sum > $y){\n &itr($x + $loop, $y - $loop, $i-2);\n } \n} \n&itr(1, $n-1, 0);"}, {"source_code": "#rextester.com:5.22.1--codeforces.com:5.20.1\n$a=<>*2;$b=0;\nfor($i=1;$i;\nmy $s = int ((sqrt $n) + 1) * 2;\nmy %tri = ();\nmy $i = 1;\nmy $result;\nfind: while ($i <= $s) {\n\tmy $num = ($i * ($i + 1)) / 2;\n\t$tri{$num} = 1;\n\tif ($tri{$n-$num}) {\n\t\t$result = \"YES\";\n\t\tlast find;\n\t} else {\n\t\t$i++;\n\t}\n}\n$result ||= \"NO\";\nprint $result;\n\n"}], "negative_code": [{"source_code": "#!/usr/bin/perl -w\nuse strict;\n\nmy $n = <>;\nmy $s = int (sqrt $n) + 1;\nmy %tri = ();\nmy $i = 1;\nmy $result;\nfind: while ($i <= $s) {\n\tmy $num = ($i * ($i + 1)) / 2;\n\t$tri{$num} = 1;\n\tif ($tri{$n-$num}) {\n\t\t$result = \"YES\";\n\t\tlast find;\n\t} else {\n\t\t$i++;\n\t}\n}\n$result ||= \"NO\";\nprint $result;\n\n"}], "src_uid": "245ec0831cd817714a4e5c531bffd099"} {"nl": {"description": "The Smart Beaver from ABBYY got hooked on square matrices. Now he is busy studying an n × n size matrix, where n is odd. The Smart Beaver considers the following matrix elements good: Elements of the main diagonal. Elements of the secondary diagonal. Elements of the \"middle\" row — the row which has exactly rows above it and the same number of rows below it. Elements of the \"middle\" column — the column that has exactly columns to the left of it and the same number of columns to the right of it. The figure shows a 5 × 5 matrix. The good elements are marked with green. Help the Smart Beaver count the sum of good elements of the given matrix.", "input_spec": "The first line of input data contains a single odd integer n. Each of the next n lines contains n integers aij (0 ≤ aij ≤ 100) separated by single spaces — the elements of the given matrix. The input limitations for getting 30 points are: 1 ≤ n ≤ 5 The input limitations for getting 100 points are: 1 ≤ n ≤ 101 ", "output_spec": "Print a single integer — the sum of good matrix elements.", "sample_inputs": ["3\n1 2 3\n4 5 6\n7 8 9", "5\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1\n1 1 1 1 1"], "sample_outputs": ["45", "17"], "notes": "NoteIn the first sample all matrix elements will be good. Good elements in the second sample are shown on the figure."}, "positive_code": [{"source_code": "$n = <>; $s = 0;\nfor $i(1..$n){\n\t@a = split(' ', <>);\n\tfor $j(1..$n){\n\t\t$soli = $a[$j - 1];\n\t\t$s += $soli if $i == $j or $i + $j == $n + 1\n\t\tor $i + $i == $n + 1 or $j + $j == $n + 1;}}\nprint $s;"}], "negative_code": [], "src_uid": "5ebfad36e56d30c58945c5800139b880"} {"nl": {"description": "Polycarpus has a ribbon, its length is n. He wants to cut the ribbon in a way that fulfils the following two conditions: After the cutting each ribbon piece should have length a, b or c. After the cutting the number of ribbon pieces should be maximum. Help Polycarpus and find the number of ribbon pieces after the required cutting.", "input_spec": "The first line contains four space-separated integers n, a, b and c (1 ≤ n, a, b, c ≤ 4000) — the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers a, b and c can coincide.", "output_spec": "Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists.", "sample_inputs": ["5 5 3 2", "7 5 5 2"], "sample_outputs": ["2", "2"], "notes": "NoteIn the first example Polycarpus can cut the ribbon in such way: the first piece has length 2, the second piece has length 3.In the second example Polycarpus can cut the ribbon in such way: the first piece has length 5, the second piece has length 2."}, "positive_code": [{"source_code": "#!/usr/bin/perl\nsub cut {\n my $n = shift;\n my $a = shift;\n my $b = shift;\n my $c = shift;\n my @hash;\n $hash[0] = 1;\n $hash[$n] = 1;\n for ($key = 0; $key < $n; $key++) {\n if ($hash[$key] > 0) {\n foreach $elem (($a,$b,$c)) {\n my $next = $key + $elem;\n $hash[$next] = $hash[$next] > $hash[$key] + 1 ? $hash[$next] : $hash[$key] + 1;\n } \n }\n }\n return $hash[$n] - 1;\n}\nwhile(<>) {\n my @arr = split;\n my $n = $arr[0];\n my $a = $arr[1];\n my $b = $arr[2];\n my $c = $arr[3];\n print cut($n,$a,$b, $c);\n}\n"}, {"source_code": "#!/usr/bin/perl\nuse v5.10;\n\nsub max {\n\tmy ($x, $y) = (shift, shift);\n\treturn $x>$y ? $x:$y;\n}\n\n($n, @a) = split / /, <>;\n@dp = (0) x ($n+1);\nforeach $i (1 .. $n) {\n\t($i==$_ || ($i>$_ && $dp[$i-$_]>0)) and $dp[$i] = max($dp[$i], $dp[$i-$_]+1) foreach (@a);\n}\nsay $dp[$n];"}, {"source_code": "use Data::Dumper;\n\nmy ($n, @lengths) = split ' ', <>;\nmy @cuts;\n$cuts[0] = 0;\n\nmy %lengths = map { $_ => 1 } @lengths;\n\n\n$\\ = \"\\n\";\n$, = \" \";\nfor my $l (1..$n) {\n for my $k (keys %lengths) {\n next unless $l >= $k && defined $cuts[$l - $k];\n my $can = $cuts[$l - $k] + 1;\n $cuts[$l] = $can if $can > $cuts[$l];\n }\n}\n\nprint \"$cuts[$n]\\n\";\n"}, {"source_code": "#!/usr/bin/perl\n#use warnings;\n#use diagnostics;\nchomp($nums = );\n@nums = split(/ /, $nums);\n$n = $nums[0];\n$a = $nums[1];\n$b = $nums[2];\n$c = $nums[3];\n$min = -1;\n$dp;\nfor ($i = 1; $i <= $n; $i++)\n{\n $dp[$i] = 0;\n}\n$dp[$a] = 1;\n$dp[$b] = 1;\n$dp[$c] = 1;\nfor ($i = 1; $i <= $n; $i++)\n{\n if ($dp[$i] == 0)\n {\n next;\n }\n if (($i + $a <= $n) && ($dp[$i] + 1 > $dp[$i + $a])) { $dp[$i + $a] = $dp[$i] + 1; }\n if ($i + $b <= $n && $dp[$i] + 1 > $dp[$i + $b]) { $dp[$i + $b] = $dp[$i] + 1; }\n if ($i + $c <= $n && $dp[$i] + 1 > $dp[$i + $c]) { $dp[$i + $c] = $dp[$i] + 1; }\n}\nprint $dp[$n];"}], "negative_code": [{"source_code": "#!/usr/bin/perl\nuse v5.10;\n\nsub max {\n\tmy ($x, $y) = (shift, shift);\n\treturn $x>$y ? $x:$y;\n}\n\n($n, @a) = split / /, <>;\n@dp = (0) x 4005;\nforeach $i (1 .. $n) {\n\t$i>=$a[$_] and $dp[$i] = max($dp[$i], $dp[$i-$a[$_]]+1) foreach (0..2);\n}\nsay $dp[$n];"}], "src_uid": "062a171cc3ea717ea95ede9d7a1c3a43"} {"nl": {"description": "Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna.But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends?", "input_spec": "The first line contains an integer n (1 ≤ n ≤ 100) — the number of apples. The second line contains n integers w1, w2, ..., wn (wi = 100 or wi = 200), where wi is the weight of the i-th apple.", "output_spec": "In a single line print \"YES\" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print \"NO\" (without the quotes).", "sample_inputs": ["3\n100 200 100", "4\n100 100 100 200"], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa."}, "positive_code": [{"source_code": "#!perl -w\n\nuse strict;\n\nchomp ( my $n = ) ;\nmy @apples = split /\\s+/s , ;\nmy @apple200 = grep{$_ == 200} @apples;\nmy @apple100 = grep{$_ == 100} @apples;\nmy $apple200d2 = @apple200 % 2 ;\nmy $apple100minfill = $apple200d2 ? @apple100 - 2 : @apple100 ;\nif($apple100minfill < 0){\n print \"NO\\n\";\n}elsif($apple100minfill % 2){\n print \"NO\\n\";\n}else{\n print \"YES\\n\";\n}\n\n\n\n"}, {"source_code": "while(<>){\n\t$_=<>;\n\t$v=0;\n\t$d=0;\n\twhile(/\\b\\d/g){\n\t\t$& == 1 and $v++;\n\t\t$& == 2 and $d++;\n\t\t}\n#\tprint \"$v $d\\n\";\n\t\n\t$t=1;\n\t\n\t$d%=2;\n\t$d and ($v / 2 or $t=0);\n\t$v % 2 and $t=0;\n\t\n\tprint $t? \"YES\\n\" : \"NO\\n\"\n\t\n\t}"}, {"source_code": "<>;\n$_=<>;\n\twhile(/\\b\\d/g){\n\t\t$&%2? $v++ : $d++\n\t\t}\n\t\n\t$t=1;\n\t\n\t$d%=2 and ($v / 2 or $t=0);\n\t$v % 2 and $t=0;\n\t\nprint $t? YES : NO"}], "negative_code": [{"source_code": "while(<>){\n\t$_=<>;\n\t$v=0;\n\t$d=0;\n\twhile(/\\b\\d/g){\n\t\t$& == 1 and $v++;\n\t\t$& == 2 and $d++;\n\t\t}\n#\tprint \"$v $d\\n\";\n\t\n\t$t=0;\n\t\n\t$d%=2;\n\t$d and ($v / 2 and $t=1);\n\t$v % 2 and $t=0;\n\t\n\tprint $t? \"YES\\n\" : \"NO\\n\"\n\t\n\t}"}, {"source_code": "while(<>){\n\t$_=<>;\n\t$v=0;\n\t$d=0;\n\twhile(/\\b\\d/g){\n\t\t$& == 1 and $v++;\n\t\t$& == 2 and $d++;\n\t\t}\n#\tprint \"$v $d\\n\";\n\t\n\t$t=0;\n\t\n\t$d%=2;\n\t$d and ($v % 2 or $t++);\n\t$d or ($v % 2 or $t++);\n\t\n\tprint $t? \"YES\\n\" : \"NO\\n\"\n\t\n\t}"}], "src_uid": "9679acef82356004e47b1118f8fc836a"} {"nl": {"description": "Vasya plays Robot Bicorn Attack.The game consists of three rounds. For each one a non-negative integer amount of points is given. The result of the game is the sum of obtained points. Vasya has already played three rounds and wrote obtained points one by one (without leading zeros) into the string s. Vasya decided to brag about his achievement to the friends. However, he has forgotten how many points he got for each round. The only thing he remembers is the string s.Help Vasya to find out what is the maximum amount of points he could get. Take into account that Vasya played Robot Bicorn Attack for the first time, so he could not get more than 1000000 (106) points for one round.", "input_spec": "The only line of input contains non-empty string s obtained by Vasya. The string consists of digits only. The string length does not exceed 30 characters.", "output_spec": "Print the only number — the maximum amount of points Vasya could get. If Vasya is wrong and the string could not be obtained according to the rules then output number -1.", "sample_inputs": ["1234", "9000", "0009"], "sample_outputs": ["37", "90", "-1"], "notes": "NoteIn the first example the string must be split into numbers 1, 2 and 34.In the second example the string must be split into numbers 90, 0 and 0. In the third example the string is incorrect, because after splitting the string into 3 numbers number 00 or 09 will be obtained, but numbers cannot have leading zeroes."}, "positive_code": [{"source_code": "#!/usr/local/bin/perl\n\nuse strict;\nmy $l = <>;\nchomp($l);\n\nmy $max = -1;\n$l =~ /^([^0].+|\\d)([^0].+|\\d)([^0].+|\\d)$(??{\n\tmy $t = $1+$2+$3;\n\t$max=$t if( $t>$max && $1<=1000000 && $2<=1000000 && $3<=1000000 );\n\t\"(*FAIL)\";\n})/;\nprint $max, \"\\n\";\n"}], "negative_code": [{"source_code": "#!/usr/local/bin/perl\n\nuse strict;\nmy $l = <>;\nchomp($l);\n\nmy $max = -1;\n$l =~ /^([^0].+|\\d)([^0].+|\\d)([^0].+|\\d)$(??{\n\tmy $t = $1+$2+$3;\n\t$max=$t if( $t>$max );\n\t\"(*FAIL)\";\n})/;\nprint $max, \"\\n\";\n"}], "src_uid": "bf4e72636bd1998ad3d034ad72e63097"} {"nl": {"description": "Drazil is playing a math game with Varda.Let's define for positive integer x as a product of factorials of its digits. For example, .First, they choose a decimal number a consisting of n digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they should find maximum positive number x satisfying following two conditions:1. x doesn't contain neither digit 0 nor digit 1.2. = .Help friends find such number.", "input_spec": "The first line contains an integer n (1 ≤ n ≤ 15) — the number of digits in a. The second line contains n digits of a. There is at least one digit in a that is larger than 1. Number a may possibly contain leading zeroes.", "output_spec": "Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation.", "sample_inputs": ["4\n1234", "3\n555"], "sample_outputs": ["33222", "555"], "notes": "NoteIn the first case, "}, "positive_code": [{"source_code": "<>, $_ = <>, chomp;\ny/10//d;\ns/4/223/g;\ns/6/53/g;\ns/8/7222/g;\ns/9/7332/g;\nprint reverse sort split//\n"}, {"source_code": "<>, $_ = <>, chomp;\ny/10//d;\ns/4/223/g;\ns/6/53/g;\ns/8/7222/g;\ns/9/7332/g;\nprint reverse sort split//\n"}, {"source_code": "<>;\nmy $inp = int <>;\n\n$inp =~ tr/01//d;\n$inp =~ s/4/223/g;\n$inp =~ s/6/53/g;\n$inp =~ s/8/7222/g;\n$inp =~ s/9/7332/g;\nprint reverse sort split //, $inp;\n"}, {"source_code": "<>, $_ = <>, chomp;\ny/10//d;\ns/4/223/g;\ns/6/53/g;\ns/8/7222/g;\ns/9/7332/g;\nprint reverse sort split//\n"}, {"source_code": "use strict;\n\nuse List::Util qw(first max maxstr min minstr reduce shuffle sum);\n<>;\nmy @input = split //, <>;\nmy $h=1;\nmy @ar;\nfor (@input)\n{\n push @ar, (Er(fact($_)));\n}\n\nmy $p ={\n2 =>\"2\",\n3 =>\"23\",\n5 =>\"22235\",\n7 =>\"22223357\"\n};\n@ar = reverse sort @ar;\nmy @s = @ar;\nmy @d;\nuntil($#s == -1)\n{\n push @d , $s[0];\n @s = Reject(@s,$p->{$s[0]}); \n}\nprint @d;\n\n\nsub Reject(\\@$)\n{\n my @a;\n my @d = split //, pop;\n @a = @_;\n g:for my $p (@d)\n {\n for (@a)\n {\n if ($p == $_)\n {\n $_ = 0;\n next g;\n }\n }\n }\n return (grep {$_ != 0} @a);\n};\n\n\n\n\nsub Er\n{\n my $n=shift;\n my @ans;\n \n for(2..$n)\n {\n until($n % $_)\n {\n push @ans, $_;\n $n /=$_;\n }\n }\n \n \n return @ans;\n};\nsub nod\n {\n return $_[0] != 0 ? nod ( ( $_[1] % $_[0] ), $_[0] ) : $_[1];\n };\n\nsub fact()\n{\n my $n = shift;\n my $s = 1;\n for (1..$n)\n {\n $s*=$_;\n }\n return $s;\n \n}\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "<>, $_ = <>, chomp;\ny/10//d;\ns/4/223/g;\ns/6/53/g;\ns/8/7222/g;\ns/9/7332/g;\nprint reverse sort split//\n"}, {"source_code": "#!/usr/bin/perl\nuse v5.10;\n\n\nchomp($n = <>);\nchomp($line = <>);\nforeach (split //, $line) {\n\tif ($_ == 2) {\n\t\tpush @a, 2;\n\t} elsif ($_ == 3) {\n\t\tpush @a, 3;\n\t} elsif ($_ == 4) {\n\t\tpush @a, (2, 2, 3);\n\t} elsif ($_ == 5) {\n\t\tpush @a, 5;\n\t} elsif ($_ == 6) {\n\t\tpush @a, (3, 5);\n\t} elsif ($_ == 7) {\n\t\tpush @a, 7;\n\t} elsif ($_ == 8) {\n\t\tpush @a, (2, 2, 2, 7);\n\t} elsif ($_ == 9) {\n\t\tpush @a, (2, 3, 3, 7);\n\t}\n}\nprint $_ foreach (sort { $b <=> $a } @a);"}, {"source_code": "chomp (my $n = <>);\nchomp (my @d = split /\\s*/, <>);\n\nmy @r;\n\nforeach (@d) {\n if (($_ == 0) || ($_ == 1)) {\n next;\n } elsif ($_ == 9) {\n push @r, 3, 3, 2, 7\n } elsif ($_ == 8) {\n push @r, 2, 2, 2, 7\n } elsif ($_ == 4) {\n push @r, 2, 2, 3\n } elsif ($_ == 6) {\n push @r, 3, 5;\n } else {\n push @r, $_\n }\n # printf \"$_ -> @r\\n\";\n}\n\nprintf \"%s\\n\", join \"\", sort {$b <=> $a} @r;\n"}, {"source_code": "<>, $_ = <>, chomp;\ny/10//d;\ns/4/223/g;\ns/6/53/g;\ns/8/7222/g;\ns/9/7332/g;\nprint reverse sort split//\n"}, {"source_code": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\nsub fact{\n my ($n) = @_;\n my @res = (0) x 10;\n for(my $i = 2; $i <= $n; $i++){\n while($n % $i == 0){\n $res[$i]++;\n $n /= $i;\n }\n }\n return @res;\n}\nsub opr{\n my @a = @{$_[0]};\n my @b = @{$_[1]};\n my $opr = $_[2];\n\n #print @b, \"\\n\";\n for my $i(2..9){\n #print \"be: $a[$i]\\n\";\n $a[$i] = $opr>0? $a[$i] + $b[$i] : $a[$i] - $b[$i];\n #print \"af: $a[$i]\\n\";\n }\n return @a;\n}\n#================\n\n\nmy $n = <>;\nmy $num = <>;\nmy $res = '';\nmy @arr = (0) x 10;\nfor my $i(0..$n-1){\n my $d = substr($num, $i,1);\n for my $j(2..$d){\n my @fact = fact $j;\n #print \"fact = @fact\\n\";\n @arr = opr(\\@arr,\\@fact,1);\n #print \"arr = @arr\\n\";\n #print \"\\n\";\n }\n}\n\nfor(my $i = 9; $i >=2; $i--){\n #print \"arr $i : $arr[$i]\\n\"; \n while($arr[$i] > 0){\n $res .= $i;\n for my $d(2..$i){\n my @fact = fact $d;\n @arr = opr(\\@arr,\\@fact,-1);\n }\n }\n}\n\nprint $res;\n"}, {"source_code": "<>, $_ = <>, chomp;\ny/10//d;\ns/4/223/g;\ns/6/53/g;\ns/8/7222/g;\ns/9/7332/g;\nprint reverse sort split//\n"}, {"source_code": "use strict;\nuse warnings;\nuse Data::Dumper;\n\nmy %h = ( \"1\" => \"1\" , \"2\" => \"2\" , \"3\"=>\"3\",\n\t \"4\" => \"322\" , \"5\" => \"5\" , \"6\"=>\"53\",\n\t \"7\" => \"7\" , \"8\" => \"7222\" , \"9\"=>\"7332\"\n\t );\n\nmy $x = ;\n$x = ;\nchomp $x;\nmy @a = split(//, $x);\nmap { $a[$_] = $h{$a[$_]} } keys @a;\n\nmy $rez = join(\"\", (sort { $b <=> $a} split( // ,join(\"\",@a))));\n$rez =~ s/1//g;\nprint $rez;\n\n\n"}, {"source_code": "<>, $_ = <>, chomp;\ny/10//d;\ns/4/223/g;\ns/6/53/g;\ns/8/7222/g;\ns/9/7332/g;\nprint reverse sort split//\n"}, {"source_code": "$\\ = $/;\nwhile(<>){\n\t$_ = <>, chomp;\ns/4/223/g;\ns/6/53/g;\ns/8/7222/g;\ns/9/7332/g;\nprint join'', map {y/10//d; $_} reverse sort split//\n\t}"}, {"source_code": "<>, $_ = <>, chomp;\ny/10//d;\ns/4/223/g;\ns/6/53/g;\ns/8/7222/g;\ns/9/7332/g;\nprint reverse sort split//"}, {"source_code": "<>, $_ = <>, chomp;\ny/10//d;\ns/4/223/g;\ns/6/53/g;\ns/8/7222/g;\ns/9/7332/g;\nprint reverse sort split//\n"}, {"source_code": "my $n = scalar <>;\nmy $x = scalar <>;\nchomp $x;\nmy @a = (0) x 10;\nforeach my $i (split //, $x){\n if($i == 9){$i = 7; $a[3] += 2; $a[2]++;}\n if($i == 8){$i = 7; $a[2] += 3;}\n if($i == 6){$i = 5; $a[3]++;}\n if($i == 4){$i = 3; $a[2] += 2;}\n $a[$i]++;\n }\nfor(my $i = 9; $i > 1; $i--){\n print $i x $a[$i];\n }\nprint \"\\n\";\n"}], "negative_code": [{"source_code": "use strict;\nuse warnings;\nuse List::Util qw(reduce);\nprint \"5\\n\";"}, {"source_code": "use strict;\n\nuse List::Util qw(first max maxstr min minstr reduce shuffle sum);\n\nmy @input = split //, <>;\nmy $h=1;\nmy @ar;\nfor (@input)\n{\n push @ar, (Er(fact($_)));\n}\n\nmy $p ={\n2 =>\"2\",\n3 =>\"23\",\n5 =>\"22235\",\n7 =>\"22223357\"\n};\n@ar = reverse sort @ar;\nmy @s = @ar;\nmy @d;\nuntil($#s == -1)\n{\n push @d , $s[0];\n @s = Reject(@s,$p->{$s[0]}); \n}\nprint @d;\n\n\nsub Reject(\\@$)\n{\n my @a;\n my @d = split //, pop;\n @a = @_;\n g:for my $p (@d)\n {\n for (@a)\n {\n if ($p == $_)\n {\n $_ = 0;\n next g;\n }\n }\n }\n return (grep {$_ != 0} @a);\n};\n\n\n\n\nsub Er\n{\n my $n=shift;\n my @ans;\n \n for(2..$n)\n {\n until($n % $_)\n {\n push @ans, $_;\n $n /=$_;\n }\n }\n \n \n return @ans;\n};\nsub nod\n {\n return $_[0] != 0 ? nod ( ( $_[1] % $_[0] ), $_[0] ) : $_[1];\n };\n\nsub fact()\n{\n my $n = shift;\n my $s = 1;\n for (1..$n)\n {\n $s*=$_;\n }\n return $s;\n \n}\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "chomp (my $n = <>);\nchomp (my @d = split /\\s*/, <>);\n\nmy @r;\n\nforeach (@d) {\n if (($_ == 0) || ($_ == 1)) {\n next;\n } elsif ($_ == 8) {\n push @r, 2, 2, 2, 7\n } elsif ($_ == 4) {\n push @r, 2, 2, 3\n } elsif ($_ == 6) {\n push @r, 3, 5;\n } else {\n push @r, $_\n }\n # printf \"$_ -> @r\\n\";\n}\n\nprintf \"%s\\n\", join \"\", sort {$b <=> $a} @r;\n"}, {"source_code": "chomp (my $n = <>);\nchomp (my @d = split /\\s*/, <>);\n\nmy @r;\n\nforeach (@d) {\n if (($_ == 0) || ($_ == 1)) {\n next;\n } elsif ($_ == 4) {\n push @r, 2, 2, 3\n } elsif ($_ == 6) {\n push @r, 3, 5;\n } else {\n push @r, $_\n }\n # printf \"$_ -> @r\\n\";\n}\n\nprintf \"%s\\n\", join \"\", sort {$b <=> $a} @r;\n"}, {"source_code": "use strict;\nuse warnings;\nuse Data::Dumper;\n\nmy %h = ( \"1\" => \"1\" , \"2\" => \"2\" , \"3\"=>\"3\",\n\t \"4\" => \"322\" , \"5\" => \"5\" , \"6\"=>\"53\",\n\t \"7\" => \"7\" , \"8\" => \"7222\" , \"9\"=>\"8332\"\n\t );\n\nmy $x = ;\n$x = ;\nchomp $x;\nmy @a = split(//, $x);\nmap { $a[$_] = $h{$a[$_]} } keys @a;\n\nmy $rez = join(\"\", (sort { $b <=> $a} split( // ,join(\"\",@a))));\n$rez =~ s/1//g;\nprint $rez;\n\n\n"}], "src_uid": "60dbfc7a65702ae8bd4a587db1e06398"} {"nl": {"description": "Every year, hundreds of people come to summer camps, they learn new algorithms and solve hard problems.This is your first year at summer camp, and you are asked to solve the following problem. All integers starting with 1 are written in one line. The prefix of these line is \"123456789101112131415...\". Your task is to print the n-th digit of this string (digits are numbered starting with 1.", "input_spec": "The only line of the input contains a single integer n (1 ≤ n ≤ 1000) — the position of the digit you need to print.", "output_spec": "Print the n-th digit of the line.", "sample_inputs": ["3", "11"], "sample_outputs": ["3", "0"], "notes": "NoteIn the first sample the digit at position 3 is '3', as both integers 1 and 2 consist on one digit.In the second sample, the digit at position 11 is '0', it belongs to the integer 10."}, "positive_code": [{"source_code": "print( (split '', join '', 1 .. 1e3)[ <> - 1 ] )"}, {"source_code": "$_ = join '', 1 .. 1000;\nchomp( $index = <> );\nprint substr $_, $index - 1, 1;"}, {"source_code": "print substr( (join '', 1 .. 1e3), <> - 1, 1 )"}], "negative_code": [], "src_uid": "2d46e34839261eda822f0c23c6e19121"} {"nl": {"description": "Two-gram is an ordered pair (i.e. string of length two) of capital Latin letters. For example, \"AZ\", \"AA\", \"ZA\" — three distinct two-grams.You are given a string $$$s$$$ consisting of $$$n$$$ capital Latin letters. Your task is to find any two-gram contained in the given string as a substring (i.e. two consecutive characters of the string) maximal number of times. For example, for string $$$s$$$ = \"BBAABBBA\" the answer is two-gram \"BB\", which contained in $$$s$$$ three times. In other words, find any most frequent two-gram.Note that occurrences of the two-gram can overlap with each other.", "input_spec": "The first line of the input contains integer number $$$n$$$ ($$$2 \\le n \\le 100$$$) — the length of string $$$s$$$. The second line of the input contains the string $$$s$$$ consisting of $$$n$$$ capital Latin letters.", "output_spec": "Print the only line containing exactly two capital Latin letters — any two-gram contained in the given string $$$s$$$ as a substring (i.e. two consecutive characters of the string) maximal number of times.", "sample_inputs": ["7\nABACABA", "5\nZZZAA"], "sample_outputs": ["AB", "ZZ"], "notes": "NoteIn the first example \"BA\" is also valid answer.In the second example the only two-gram \"ZZ\" can be printed because it contained in the string \"ZZZAA\" two times."}, "positive_code": [{"source_code": "#!/usr/bin/perl\nuse 5.016;\nmy %signs;\n\nmy $i = 0;\nfor (\"A\" .. \"Z\") {\n\t$signs{$_} = $i++;\n}\n\n# sub is_begramm {\n# \tmy ($a, $b) = @_;\n# \tif(abs($signs{$a} - $signs{$b}) < 2) { return 1 }\n# \tif ($a eq \"a\" && $b eq \"z\" or $a eq \"z\" && $b eq \"a\") { return 1 }\n# \treturn 0;\n# }\n\n\nmy $c = <>;\nmy $s = <>;\nchomp $s;\nmy @s = split //, $s;\nmy %bigrams;\n\n\n$bigrams{$s[$_].$s[$_ + 1]}++ for (0..$#s - 1);\n\n\nmy $max_val = 0;\nmy $max_key = \"\";\nfor (keys %bigrams) {\n\tif ($bigrams{$_} > $max_val) {\n\t\t$max_val = $bigrams{$_};\n\t\t$max_key = $_;\n\t}\n}\n\nsay $max_key;"}, {"source_code": "#!/usr/bin/perl\n\nuse warnings;\nuse strict;\n\n$\\ = $/;\n\nwhile(<>){\n\tmy %h;\n\t\n\t<> =~ /(.)(?=(.))(?{ $h{ $1 . $2 } ++ })(?!)/;\n\t\n\tmy $max = ( sort { $b <=> $a } values %h )[ 0 ];\n\t\n\tmy $ans;\n\t\n\t$h{ $_ } == $max and $ans = $_ for keys %h;\n\t\n\tprint $ans;\n\t}"}], "negative_code": [{"source_code": "#!/usr/bin/perl\nuse 5.016;\nmy %signs;\n\nmy $i = 0;\nfor (\"A\" .. \"Z\") {\n\t$signs{$_} = $i++;\n}\n\nsub is_begramm {\n\tmy ($a, $b) = @_;\n\tif(abs($signs{$a} - $signs{$b}) < 2) { return 1 }\n\tif ($a eq \"a\" && $b eq \"z\" or $a eq \"z\" && $b eq \"a\") { return 1 }\n\treturn 0;\n}\n\n\nmy $c = <>;\nmy $s = <>;\nchomp $s;\nmy @s = split //, $s;\nmy %bigrams;\n\nfor (0..$#s - 1) {\n\t$bigrams{$s[$_].$s[$_ + 1]}++ if is_begramm($s[$_], $s[$_ + 1]) \n}\n\n\nmy $max_val = 0;\nmy $max_key = \"\";\nfor (keys %bigrams) {\n\tif ($bigrams{$_} > $max_val) {\n\t\t$max_val = $bigrams{$_};\n\t\t$max_key = $_;\n\t}\n}\n\nsay $max_key;"}, {"source_code": "#!/usr/bin/perl\n\nuse warnings;\nuse strict;\n\n$\\ = $/;\n\nwhile(<>){\n\tmy %h;\n\t\n\t<> =~ /(.)(?=(.))(?{ $h{ $1 . $2 } ++ })/;\n\t\n\tmy $max = ( sort { $b <=> $a } values %h )[ 0 ];\n\t\n\tmy $ans;\n\t\n\t$h{ $_ } == $max and $ans = $_ for keys %h;\n\t\n\tprint $ans;\n\t}"}], "src_uid": "e78005d4be93dbaa518f3b40cca84ab1"} {"nl": {"description": "Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system.The term is coming to an end and students start thinking about their grades. Today, a professor told his students that the grades for his course would be given out automatically  — he would calculate the simple average (arithmetic mean) of all grades given out for lab works this term and round to the nearest integer. The rounding would be done in favour of the student — $$$4.5$$$ would be rounded up to $$$5$$$ (as in example 3), but $$$4.4$$$ would be rounded down to $$$4$$$.This does not bode well for Vasya who didn't think those lab works would influence anything, so he may receive a grade worse than $$$5$$$ (maybe even the dreaded $$$2$$$). However, the professor allowed him to redo some of his works of Vasya's choosing to increase his average grade. Vasya wants to redo as as few lab works as possible in order to get $$$5$$$ for the course. Of course, Vasya will get $$$5$$$ for the lab works he chooses to redo.Help Vasya — calculate the minimum amount of lab works Vasya has to redo.", "input_spec": "The first line contains a single integer $$$n$$$ — the number of Vasya's grades ($$$1 \\leq n \\leq 100$$$). The second line contains $$$n$$$ integers from $$$2$$$ to $$$5$$$ — Vasya's grades for his lab works.", "output_spec": "Output a single integer — the minimum amount of lab works that Vasya has to redo. It can be shown that Vasya can always redo enough lab works to get a $$$5$$$.", "sample_inputs": ["3\n4 4 4", "4\n5 4 5 5", "4\n5 3 3 5"], "sample_outputs": ["2", "0", "1"], "notes": "NoteIn the first sample, it is enough to redo two lab works to make two $$$4$$$s into $$$5$$$s.In the second sample, Vasya's average is already $$$4.75$$$ so he doesn't have to redo anything to get a $$$5$$$.In the second sample Vasya has to redo one lab work to get rid of one of the $$$3$$$s, that will make the average exactly $$$4.5$$$ so the final grade would be $$$5$$$."}, "positive_code": [{"source_code": "#!usr/bin/perl\nuse warnings;\nuse strict;\n\nmy $n=;my $m=;chomp($n,$m);\nmy @e=split/ /,$m;my $r=0;\nfor my $i(0..$#e){\n $r+=$e[$i];\n}\nmy $avg=$r/$n;my $t=0;\nif($avg>=4.5){print 0;}\nelse{\n my $dif=4.5-$avg;\n while($dif>0){\n\tif($m=~/1/){\n\t $m=~s/1/5/;\n\t $dif-=4/$n;\n\t}\n\telsif($m=~/2/){\n\t $m=~s/2/5/;\n\t $dif-=3/$n;\n\t}\n\telsif($m=~/3/){\n\t $m=~s/3/5/;\n\t $dif-=2/$n;\n\t}\n\telsif($m=~/4/){\n\t $m=~s/4/5/;\n\t $dif-=1/$n;\n\t}\n\t++$t;\n }\n print $t;\n}"}], "negative_code": [], "src_uid": "715608282b27a0a25b66f08574a6d5bd"} {"nl": {"description": "Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.The teacher gave Seryozha the coordinates of n distinct points on the abscissa axis and asked to consecutively connect them by semi-circus in a certain order: first connect the first point with the second one, then connect the second point with the third one, then the third one with the fourth one and so on to the n-th point. Two points with coordinates (x1, 0) and (x2, 0) should be connected by a semi-circle that passes above the abscissa axis with the diameter that coincides with the segment between points. Seryozha needs to find out if the line on the picture intersects itself. For clarifications, see the picture Seryozha showed to Dima (the left picture has self-intersections, the right picture doesn't have any). Seryozha is not a small boy, so the coordinates of the points can be rather large. Help Dima cope with the problem.", "input_spec": "The first line contains a single integer n (1 ≤ n ≤ 103). The second line contains n distinct integers x1, x2, ..., xn ( - 106 ≤ xi ≤ 106) — the i-th point has coordinates (xi, 0). The points are not necessarily sorted by their x coordinate.", "output_spec": "In the single line print \"yes\" (without the quotes), if the line has self-intersections. Otherwise, print \"no\" (without the quotes).", "sample_inputs": ["4\n0 10 5 15", "4\n0 15 5 10"], "sample_outputs": ["yes", "no"], "notes": "NoteThe first test from the statement is on the picture to the left, the second test is on the picture to the right."}, "positive_code": [{"source_code": "#!/usr/bin/perl\n\n$PI=3.14159265358979323846;\n$MOD=1000000007;\n\n <>=~/ /;\n# <>=~/ (\\d+) /;\n# <>=~/ (\\d+) (\\d+) /;\n\n$n=@_=split/ /,<>;\n\nfor $i(0..$n-2){\n\tfor $j(0..$n-2){\n\t\t\tif ($_[$i]<$_[$i+1]){$a=$_[$i];$b=$_[$i+1]}else{$b=$_[$i];$a=$_[$i+1]};\n\t\t\tif ($_[$j]<$_[$j+1]){$c=$_[$j];$d=$_[$j+1]}else{$d=$_[$j];$c=$_[$j+1]};\n\t\t\t($a<$c && $c<$b && $b<$d) || ($c<$a && $a<$d && $d<$b) and $F++;\n\t\t}\n\t}\n\n print $F?\"yes\":\"no\";"}, {"source_code": "#!/usr/bin/perl\n\n$PI=3.14159265358979323846;\n$MOD=1000000007;\n\n <>=~/ /;\n# <>=~/ (\\d+) /;\n# <>=~/ (\\d+) (\\d+) /;\n\n@_=split/ /,<>;\n\nfor $i(0..@_-2){\n\tfor $j(0..@_-2){\n\t\t\n\t\t\t($a,$b)=sort {$a <=> $b} ($_[$i],$_[$i+1]);\n\t\t\t($c,$d)=sort {$a <=> $b} ($_[$j],$_[$j+1]);\n\t\t\t($a<$c && $c<$b && $b<$d) || ($c<$a && $a<$d && $d<$b) and $F++;\n\t\t\t\n\t\t}\n\t}\n\n print $F?\"yes\":\"no\";\n\n#***********SUBS************\n\nsub num {$a <=> $b}\nsub num_rev {$b <=> $a}\nsub rev {$b cmp $a}\n\nsub p{print}\nsub n{print \"\\n\"}\nsub pn{p,n}\nsub pn_mas {pn for @_}\n\n# Transpose \"charbox\"\nsub transpose{\n $i=@m=@_;\n chomp @m;\n while ($i--){\n $t[$i]=~s/$/chop/e for @m\n }\nreturn @t\n}\n\n# Transpose \"value sets\"\nsub transpose_space{\n my @t;\n for (@_){\n my $j=0;\n s/\\d+/($t[$j++].=\"$& \")?$&:$&/eg;\n }\n chop @t;\nreturn @t\n}\n\nsub div{\n my ($n, $k)=@_;\nreturn ($n - $n % $k) / $k\n}\n \nsub uniq{\n my @m=sort @_;\n push @u, my $i=shift @m;\n for (@m){\n $i eq $_ or push @u, $_;\n $i=$_;\n }\nreturn @u\n}\n \nsub max{\n my $max=shift;\n $max<$_ and $max=$_ for @_;\nreturn $max\n}\n \nsub min{\n my $min=shift;\n $min>$_ and $min=$_ for @_;\nreturn $min\n}\n\n# count (kas_ieskoma, masyvas)\nsub count{\n my $i=0;\n $_ eq $_[0] and $i++ for @_;\nreturn --$i\n}"}, {"source_code": "#!/usr/bin/perl\n\n$PI=3.14159265358979323846;\n$MOD=1000000007;\n\n <>=~/ /;\n# <>=~/ (\\d+) /;\n# <>=~/ (\\d+) (\\d+) /;\n\n$n=@_=split/ /,<>;\n\n$i=$n-1;\nwhile($i--){\n\t$j=$n-1;\n\twhile($j--){\n\t\t\tif ($_[$i]<$_[$i+1]){$a=$_[$i];$b=$_[$i+1]}else{$b=$_[$i];$a=$_[$i+1]};\n\t\t\tif ($_[$j]<$_[$j+1]){$c=$_[$j];$d=$_[$j+1]}else{$d=$_[$j];$c=$_[$j+1]};\n\t\t\t(($a<$c) && ($c<$b) && ($b<$d)) || (($c<$a) && ($a<$d) && ($d<$b)) and $F++;\n\t\t}\n\t}\n\n print $F?\"yes\":\"no\";"}, {"source_code": "#!/usr/bin/perl\n\n$PI=3.14159265358979323846;\n$MOD=1000000007;\n\n <>=~/ /;\n# <>=~/ (\\d+) /;\n# <>=~/ (\\d+) (\\d+) /;\n\n$n=@_=split/ /,<>;\n\n$i=$n-1;\nwhile($i--){\n\t$j=$n-1;\n\twhile($j--){\n\t\t\tif ($_[$i]<$_[$i+1]){$a=$_[$i];$b=$_[$i+1]}else{$b=$_[$i];$a=$_[$i+1]};\n\t\t\tif ($_[$j]<$_[$j+1]){$c=$_[$j];$d=$_[$j+1]}else{$d=$_[$j];$c=$_[$j+1]};\n\t\t\t($a<$c && $c<$b && $b<$d) || ($c<$a && $a<$d && $d<$b) and $F++;\n\t\t}\n\t}\n\n print $F?\"yes\":\"no\";"}, {"source_code": "#!/usr/bin/perl\n\n$PI=3.14159265358979323846;\n$MOD=1000000007;\n\n <>=~/ /;\n# <>=~/ (\\d+) /;\n# <>=~/ (\\d+) (\\d+) /;\n\n$n=@_=split/ /,<>;\n\n$i=$n-1;\nwhile($i--){\n\t$j=$n-1;\n\twhile($j--){\n\t\t\t$y=$_[$i]; $z=$_[$i+1];\n\t\t\tif ($y<$z){$a=$y;$b=$z}else{$b=$y;$a=$z};\n\t\t\t$y=$_[$j]; $z=$_[$j+1];\n\t\t\tif ($y<$z){$c=$y;$d=$z}else{$d=$y;$c=$z};\n\t\t\t(($a<$c) && ($c<$b) && ($b<$d)) || (($c<$a) && ($a<$d) && ($d<$b)) and $F++;\n\t\t}\n\t}\n\n print $F?\"yes\":\"no\";"}], "negative_code": [{"source_code": "#!/usr/bin/perl\n\n$PI=3.14159265358979323846;\n$MOD=1000000007;\n\n <>=~/ /;\n# <>=~/ (\\d+) /;\n# <>=~/ (\\d+) (\\d+) /;\n\n@_=split/ /,<>;\n$a=shift @_;\nwhile (@_){\n\t$max=max(@_);\n\t$min=min(@_);\n\t$a>$max || $a<$min or $F++ or last;\n\t$a=shift @_;\n\t}\n\t\nprint $F?\"yes\":\"no\";\n\n#***********SUBS************\n\nsub num {$a <=> $b}\nsub num_rev {$b <=> $a}\nsub rev {$b cmp $a}\n\nsub p{print}\nsub n{print \"\\n\"}\nsub pn{p,n}\nsub pn_mas {pn for @_}\n\n# Transpose \"charbox\"\nsub transpose{\n $i=@m=@_;\n chomp @m;\n while ($i--){\n $t[$i]=~s/$/chop/e for @m\n }\nreturn @t\n}\n\n# Transpose \"value sets\"\nsub transpose_space{\n my @t;\n for (@_){\n my $j=0;\n s/\\d+/($t[$j++].=\"$& \")?$&:$&/eg;\n }\n chop @t;\nreturn @t\n}\n\nsub div{\n my ($n, $k)=@_;\nreturn ($n - $n % $k) / $k\n}\n \nsub uniq{\n my @m=sort @_;\n push @u, my $i=shift @m;\n for (@m){\n $i eq $_ or push @u, $_;\n $i=$_;\n }\nreturn @u\n}\n \nsub max{\n my $max=shift;\n $max<$_ and $max=$_ for @_;\nreturn $max\n}\n \nsub min{\n my $min=shift;\n $min>$_ and $min=$_ for @_;\nreturn $min\n}\n\n# count (kas_ieskoma, masyvas)\nsub count{\n my $i=0;\n $_ eq $_[0] and $i++ for @_;\nreturn --$i\n}"}, {"source_code": "#!/usr/bin/perl\n\n$PI=3.14159265358979323846;\n$MOD=1000000007;\n\n <>=~/ /;\n# <>=~/ (\\d+) /;\n# <>=~/ (\\d+) (\\d+) /;\n\n@_=split/ /,<>;\n\nfor $i(0..@_-2){\n\tfor $j(0..@_-2){\n\t\tif ($i!=$j){\n\t\t\t($a,$b)=sort {$a <=> $b} ($_[$i],$_[$i+1]);\n\t\t\t($c,$d)=sort {$a <=> $b} ($_[$j],$_[$j+1]);\n\t\t\t($a<$c && $c<$b && $b<$d) || ($c<$a && $a<$d && $d<$b) and $F++ or last;\n\t\t\t}\n\t\t}\n\t}\n\n print $F?\"yes\":\"no\";\n\n#***********SUBS************\n\nsub num {$a <=> $b}\nsub num_rev {$b <=> $a}\nsub rev {$b cmp $a}\n\nsub p{print}\nsub n{print \"\\n\"}\nsub pn{p,n}\nsub pn_mas {pn for @_}\n\n# Transpose \"charbox\"\nsub transpose{\n $i=@m=@_;\n chomp @m;\n while ($i--){\n $t[$i]=~s/$/chop/e for @m\n }\nreturn @t\n}\n\n# Transpose \"value sets\"\nsub transpose_space{\n my @t;\n for (@_){\n my $j=0;\n s/\\d+/($t[$j++].=\"$& \")?$&:$&/eg;\n }\n chop @t;\nreturn @t\n}\n\nsub div{\n my ($n, $k)=@_;\nreturn ($n - $n % $k) / $k\n}\n \nsub uniq{\n my @m=sort @_;\n push @u, my $i=shift @m;\n for (@m){\n $i eq $_ or push @u, $_;\n $i=$_;\n }\nreturn @u\n}\n \nsub max{\n my $max=shift;\n $max<$_ and $max=$_ for @_;\nreturn $max\n}\n \nsub min{\n my $min=shift;\n $min>$_ and $min=$_ for @_;\nreturn $min\n}\n\n# count (kas_ieskoma, masyvas)\nsub count{\n my $i=0;\n $_ eq $_[0] and $i++ for @_;\nreturn --$i\n}"}], "src_uid": "f1b6b81ebd49f31428fe57913dfc604d"} {"nl": {"description": "Polycarp has interviewed Oleg and has written the interview down without punctuation marks and spaces to save time. Thus, the interview is now a string s consisting of n lowercase English letters.There is a filler word ogo in Oleg's speech. All words that can be obtained from ogo by adding go several times to the end of it are also considered to be fillers. For example, the words ogo, ogogo, ogogogo are fillers, but the words go, og, ogog, ogogog and oggo are not fillers.The fillers have maximal size, for example, for ogogoo speech we can't consider ogo a filler and goo as a normal phrase. We should consider ogogo as a filler here.To print the interview, Polycarp has to replace each of the fillers with three asterisks. Note that a filler word is replaced with exactly three asterisks regardless of its length.Polycarp has dealt with this problem in no time. Can you do the same? The clock is ticking!", "input_spec": "The first line contains a positive integer n (1 ≤ n ≤ 100) — the length of the interview. The second line contains the string s of length n, consisting of lowercase English letters.", "output_spec": "Print the interview text after the replacement of each of the fillers with \"***\". It is allowed for the substring \"***\" to have several consecutive occurences.", "sample_inputs": ["7\naogogob", "13\nogogmgogogogo", "9\nogoogoogo"], "sample_outputs": ["a***b", "***gmg***", "*********"], "notes": "NoteThe first sample contains one filler word ogogo, so the interview for printing is \"a***b\".The second sample contains two fillers ogo and ogogogo. Thus, the interview is transformed to \"***gmg***\"."}, "positive_code": [{"source_code": "#Scott Heinrich - A01273823\nuse strict;\nuse warnings;\nuse 5.010;\n\nmy $length = <>;\nchomp($length);\nmy $s = <>;\nchomp($s);\n\n$s =~ s/ogo(?:go)*/***/g;\nsay $s;\n"}, {"source_code": "my $n = <>;\nmy $s = <>;\n$s =~ s/ogo(go)*/\\*\\*\\*/gi;\nprint $s;"}, {"source_code": "#!/usr/bin/env perl\n\nuse strict;\nuse warnings;\n\nmy $n = int <>;\nmy $s = <>;\n$s =~ s/ogo(?:go)*/***/g;\nprint $s;\n"}, {"source_code": "#!perl\nuse v5.20;\nwhile(<>) {\n chomp; my $n=$_;\n my $s=<>;\n $s=~s/ogo(go)*/***/g;\n print $s;\n}\n"}, {"source_code": "my $line = <>;\nwhile (<>)\n{\n s/ogo(go)*/***/g;\n print;\n}\n"}, {"source_code": "$dummy=;\n$word = ;\n$word =~ s/ogo(go)*/\\*\\*\\*/g;\nprint \"$word\";\n"}, {"source_code": "use strict;\nuse warnings;\n\n\n<>;\nmy $str=<>;\nchomp($str);\n$str =~ s/ogo(go)*/***/g;\n\nprint $str . \"\\n\";\n"}, {"source_code": "$n=<>;\n$ch=<>;\nchomp$ch;\nwhile($ch=~s/(ogo(go)*)/\\*\\*\\*/){\n\n}\n\nprint $ch;\n\n"}, {"source_code": "#!/usr/bin/perl\n$str=<> ;\n$str=<> ;\n$str=~s/ogo(go)*/***/g ;\nprint $str ;\n"}], "negative_code": [{"source_code": "use strict;\nuse warnings;\nuse 5.010;\n\nmy $input = <>;\nchomp($input);\n\nmy %totalHash;\nmy @totalArr;\nmy $len = length($input);\n\nfor my $i (0 .. $len)\n{\n my $len2=$len;\n for my $j (1 .. $len2)\n {\n my $sub = substr($input, $i, $j);\n #say $sub;\n if(length($sub)>0)\n {\n if($sub % 4 == 0 or $sub == 0)\n {\n #say $sub;\n #$totalHash{$sub} = 1;\n push(@totalArr, $sub);\n }\n }\n $len2--;\n }\n $len--;\n}\n#my $size = keys %totalHash;\nmy $size = scalar @totalArr;\nsay $size;\n\n#foreach my $key(keys %totalHash)\n#{\n# say $key;\n#}\n"}, {"source_code": "$word = ;\n$word =~ s/ogo(go)*/\\*\\*\\*/g;\nprint \"$word\";\n"}], "src_uid": "619665bed79ecf77b083251fe6fe7eb3"} {"nl": {"description": "Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.You are given l and r. For all integers from l to r, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times.Solve the problem to show that it's not a NP problem.", "input_spec": "The first line contains two integers l and r (2 ≤ l ≤ r ≤ 109).", "output_spec": "Print single integer, the integer that appears maximum number of times in the divisors. If there are multiple answers, print any of them.", "sample_inputs": ["19 29", "3 6"], "sample_outputs": ["2", "3"], "notes": "NoteDefinition of a divisor: https://www.mathsisfun.com/definitions/divisor-of-an-integer-.htmlThe first example: from 19 to 29 these numbers are divisible by 2: {20, 22, 24, 26, 28}.The second example: from 3 to 6 these numbers are divisible by 3: {3, 6}."}, "positive_code": [{"source_code": "print <>=~ /^(\\d+) \\1$/ ? $1 : 2"}, {"source_code": "#!/usr/bin/perl\n\nuse warnings;\nuse strict;\n\n$\\ = $/;\n\nwhile(<>){\n\tmy( $l, $r ) = split;\n\t\n\tprint $r - $l >= 1 ? 2 : $r;\n\t\n\t}"}, {"source_code": "( $l, $r ) = split ' ', <>;\n\nprint $r - $l ? 2 : $r"}], "negative_code": [], "src_uid": "a8d992ab26a528f0be327c93fb499c15"} {"nl": {"description": "Stepan has n pens. Every day he uses them, and on the i-th day he uses the pen number i. On the (n + 1)-th day again he uses the pen number 1, on the (n + 2)-th — he uses the pen number 2 and so on.On every working day (from Monday to Saturday, inclusive) Stepan spends exactly 1 milliliter of ink of the pen he uses that day. On Sunday Stepan has a day of rest, he does not stend the ink of the pen he uses that day. Stepan knows the current volume of ink in each of his pens. Now it's the Monday morning and Stepan is going to use the pen number 1 today. Your task is to determine which pen will run out of ink before all the rest (that is, there will be no ink left in it), if Stepan will use the pens according to the conditions described above.", "input_spec": "The first line contains the integer n (1 ≤ n ≤ 50 000) — the number of pens Stepan has. The second line contains the sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is equal to the number of milliliters of ink which the pen number i currently has.", "output_spec": "Print the index of the pen which will run out of ink before all (it means that there will be no ink left in it), if Stepan will use pens according to the conditions described above. Pens are numbered in the order they are given in input data. The numeration begins from one. Note that the answer is always unambiguous, since several pens can not end at the same time.", "sample_inputs": ["3\n3 3 3", "5\n5 4 5 4 4"], "sample_outputs": ["2", "5"], "notes": "NoteIn the first test Stepan uses ink of pens as follows: on the day number 1 (Monday) Stepan will use the pen number 1, after that there will be 2 milliliters of ink in it; on the day number 2 (Tuesday) Stepan will use the pen number 2, after that there will be 2 milliliters of ink in it; on the day number 3 (Wednesday) Stepan will use the pen number 3, after that there will be 2 milliliters of ink in it; on the day number 4 (Thursday) Stepan will use the pen number 1, after that there will be 1 milliliters of ink in it; on the day number 5 (Friday) Stepan will use the pen number 2, after that there will be 1 milliliters of ink in it; on the day number 6 (Saturday) Stepan will use the pen number 3, after that there will be 1 milliliters of ink in it; on the day number 7 (Sunday) Stepan will use the pen number 1, but it is a day of rest so he will not waste ink of this pen in it; on the day number 8 (Monday) Stepan will use the pen number 2, after that this pen will run out of ink. So, the first pen which will not have ink is the pen number 2."}, "positive_code": [{"source_code": "my $n = <>;\n$_ = <>; my @A = split;\nif(int($n) % 7 == 0){\n\t$z = -1;\n\tfor($i = 0; $i < int($n); $i += 1){\n\t\tif($i % 7 != 6){\n\t\t\tif(($z == -1) || (int($A[$z]) > int($A[$i]))){\n\t\t\t\t$z = $i;\n\t\t\t}\n\t\t}\n\t}\n\tprint $z + 1;\n\n}else{\n\n$z = 1000000000;\nforeach(@A){\n\t$x = int($_)-1;\n\twhile($x % 6 != 0){\n\t\t$x -= 1;\n\t}\n\t$z = $x if($x < $z);\n}\nfor($i = 0; $i < $n; $i += 1){\n\t$A[$i] = int($A[$i]) - $z;\n}\n$i = -1;\n$t = 0;\n$g = 1;\nwhile($g != 0){\n\t$t += 1; $t = 0 if($t == 7);\n\t$i += 1; $i = 0 if($i == $n);\n\tif($t != 0){\n\t\t$A[$i] -= 1;\n\t\tif($A[$i] == 0){\n\t\t\tprint $i+1;\n\t\t\t$g = 0;\n\t\t}\n\t}\n}\n\n}\n"}], "negative_code": [], "src_uid": "8054dc5dd09d600d7fb8d9f5db4dcaca"} {"nl": {"description": "Polycarp is going to participate in the contest. It starts at $$$h_1:m_1$$$ and ends at $$$h_2:m_2$$$. It is guaranteed that the contest lasts an even number of minutes (i.e. $$$m_1 \\% 2 = m_2 \\% 2$$$, where $$$x \\% y$$$ is $$$x$$$ modulo $$$y$$$). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.Polycarp wants to know the time of the midpoint of the contest. For example, if the contest lasts from $$$10:00$$$ to $$$11:00$$$ then the answer is $$$10:30$$$, if the contest lasts from $$$11:10$$$ to $$$11:12$$$ then the answer is $$$11:11$$$.", "input_spec": "The first line of the input contains two integers $$$h_1$$$ and $$$m_1$$$ in the format hh:mm. The second line of the input contains two integers $$$h_2$$$ and $$$m_2$$$ in the same format (hh:mm). It is guaranteed that $$$0 \\le h_1, h_2 \\le 23$$$ and $$$0 \\le m_1, m_2 \\le 59$$$. It is guaranteed that the contest lasts an even number of minutes (i.e. $$$m_1 \\% 2 = m_2 \\% 2$$$, where $$$x \\% y$$$ is $$$x$$$ modulo $$$y$$$). It is also guaranteed that the entire contest is held during a single day. And finally it is guaranteed that the contest lasts at least two minutes.", "output_spec": "Print two integers $$$h_3$$$ and $$$m_3$$$ ($$$0 \\le h_3 \\le 23, 0 \\le m_3 \\le 59$$$) corresponding to the midpoint of the contest in the format hh:mm. Print each number as exactly two digits (prepend a number with leading zero if needed), separate them with ':'.", "sample_inputs": ["10:00\n11:00", "11:10\n11:12", "01:02\n03:02"], "sample_outputs": ["10:30", "11:11", "02:02"], "notes": null}, "positive_code": [{"source_code": "#!/usr/bin/perl\n\nuse warnings;\nuse strict;\n\n$\\ = $/;\n\nwhile(<>){\n\tchomp;\n\tmy( $h1, $m1 ) = split ':';\n\tmy( $h2, $m2 ) = split ':', <>;\n\tchomp $m2;\n\t\n\tmap { $_ = s/^0(?=\\d)//gr } $h1, $h2, $m1, $m2;\n\t\n\tmy $time = $h1 * 60 + $h2 * 60 + $m1 + $m2;\n\t$time /= 2;\n\t\n\tmy $sec = $time % 60;\n\t$time -= $sec;\n\t\n\tprint join ':', map { sprintf \"%02d\", $_ } $time / 60, $sec;\n\t}"}], "negative_code": [], "src_uid": "f7a32a8325ce97c4c50ce3a5c282ec50"} {"nl": {"description": "This task will exclusively concentrate only on the arrays where all elements equal 1 and/or 2.Array a is k-period if its length is divisible by k and there is such array b of length k, that a is represented by array b written exactly times consecutively. In other words, array a is k-periodic, if it has period of length k.For example, any array is n-periodic, where n is the array length. Array [2, 1, 2, 1, 2, 1] is at the same time 2-periodic and 6-periodic and array [1, 2, 1, 1, 2, 1, 1, 2, 1] is at the same time 3-periodic and 9-periodic.For the given array a, consisting only of numbers one and two, find the minimum number of elements to change to make the array k-periodic. If the array already is k-periodic, then the required value equals 0.", "input_spec": "The first line of the input contains a pair of integers n, k (1 ≤ k ≤ n ≤ 100), where n is the length of the array and the value n is divisible by k. The second line contains the sequence of elements of the given array a1, a2, ..., an (1 ≤ ai ≤ 2), ai is the i-th element of the array.", "output_spec": "Print the minimum number of array elements we need to change to make the array k-periodic. If the array already is k-periodic, then print 0.", "sample_inputs": ["6 2\n2 1 2 2 2 1", "8 4\n1 1 2 1 1 1 2 1", "9 3\n2 1 1 1 2 1 1 1 2"], "sample_outputs": ["1", "0", "3"], "notes": "NoteIn the first sample it is enough to change the fourth element from 2 to 1, then the array changes to [2, 1, 2, 1, 2, 1].In the second sample, the given array already is 4-periodic.In the third sample it is enough to replace each occurrence of number two by number one. In this case the array will look as [1, 1, 1, 1, 1, 1, 1, 1, 1] — this array is simultaneously 1-, 3- and 9-periodic."}, "positive_code": [{"source_code": "#!/usr/bin/perl\n\nuse bignum; \n\n$PI=3.14159265358979323846;\n$MOD=1000000007;\n\n# <>=~/ /;\n# <>=~/ (\\d+) /;\n#\t <>=~/ (\\d+) (\\d+) /;\n\t\nwhile(<>=~/ /){\n\t$ats=0;\n\t@a=();\n\t@_=split/ /,<>;\n\tfor $j(0..@_-1){\n\t\t$_[$j]-1 and $a[$j%$']++; \n\t\t}\n#\tprint \"@a\\n\";\n\tfor (@a){\n\t\t$_ and $ats+=min($`/$'-$_,$_)\n\t\t}\n\tprint \"$ats\\n\";\n\t}\n\n#***********SUBS************\n\nsub num {$a <=> $b}\nsub num_rev {$b <=> $a}\nsub rev {$b cmp $a}\n\nsub p{print}\nsub n{print \"\\n\"}\nsub pn{p,n}\nsub pn_mas {pn for @_}\n\n# Transpose \"charbox\"\nsub transpose{\n $i=@m=@_;\n chomp @m;\n while ($i--){\n $t[$i]=~s/$/chop/e for @m\n }\nreturn @t\n}\n\n# Transpose \"value sets\"\nsub transpose_space{\n my @t;\n for (@_){\n my $j=0;\n s/\\d+/($t[$j++].=\"$& \")?$&:$&/eg;\n }\n chop @t;\nreturn @t\n}\n\nsub div{\n my ($n, $k)=@_;\nreturn ($n - $n % $k) / $k\n}\n \nsub uniq{\n my @m=sort @_;\n push @u, my $i=shift @m;\n for (@m){\n $i eq $_ or push @u, $_;\n $i=$_;\n }\nreturn @u\n}\n \nsub max{\n my $max=shift;\n $max<$_ and $max=$_ for @_;\nreturn $max\n}\n \nsub min{\n my $min=shift;\n $min>$_ and $min=$_ for @_;\nreturn $min\n}\n\n# count (kas_ieskoma, masyvas)\nsub count{\n my $i=0;\n $_ eq $_[0] and $i++ for @_;\nreturn --$i\n}"}], "negative_code": [], "src_uid": "5f94c2ecf1cf8fdbb6117cab801ed281"} {"nl": {"description": "Ted has a pineapple. This pineapple is able to bark like a bulldog! At time t (in seconds) it barks for the first time. Then every s seconds after it, it barks twice with 1 second interval. Thus it barks at times t, t + s, t + s + 1, t + 2s, t + 2s + 1, etc. Barney woke up in the morning and wants to eat the pineapple, but he can't eat it when it's barking. Barney plans to eat it at time x (in seconds), so he asked you to tell him if it's gonna bark at that time.", "input_spec": "The first and only line of input contains three integers t, s and x (0 ≤ t, x ≤ 109, 2 ≤ s ≤ 109) — the time the pineapple barks for the first time, the pineapple barking interval, and the time Barney wants to eat the pineapple respectively.", "output_spec": "Print a single \"YES\" (without quotes) if the pineapple will bark at time x or a single \"NO\" (without quotes) otherwise in the only line of output.", "sample_inputs": ["3 10 4", "3 10 3", "3 8 51", "3 8 52"], "sample_outputs": ["NO", "YES", "YES", "YES"], "notes": "NoteIn the first and the second sample cases pineapple will bark at moments 3, 13, 14, ..., so it won't bark at the moment 4 and will bark at the moment 3.In the third and fourth sample cases pineapple will bark at moments 3, 11, 12, 19, 20, 27, 28, 35, 36, 43, 44, 51, 52, 59, ..., so it will bark at both moments 51 and 52."}, "positive_code": [{"source_code": "($t, $s, $x) = split ' ', <>;\n$x -= $t;\nprint qw(NO YES)[ !($x % $s && ~- $x % $s) and !$x || $x > 1 ]"}, {"source_code": "$\\ = $/;\n\nwhile(<>){\n\t($t, $s, $x) = split;\n\t$x -= $t;\n\tprint( ( ($x % ($s) == 0 or ($x - 1) % ($s) == 0) and ($x == 0 or $x > 1) ) ? \n\t\t'YES'\n\t:\n\t\t'NO'\n\t)\n\t\n\t}\n"}], "negative_code": [{"source_code": "$\\ = $/;\n\nwhile(<>){\n\t($t, $s, $x) = split;\n\t$x -= $t;\n\tprint( ( ($x % ($s) == 0 or ($x - 1) % ($s) == 0) and ($x - 1 != 0) ) ? \n\t\t'YES'\n\t:\n\t\t'NO'\n\t)\n\t\n\t}"}], "src_uid": "3baf9d841ff7208c66f6de1b47b0f952"} {"nl": {"description": "Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment. Find all integer solutions x (0 < x < 109) of the equation:x = b·s(x)a + c,  where a, b, c are some predetermined constant values and function s(x) determines the sum of all digits in the decimal representation of number x.The teacher gives this problem to Dima for each lesson. He changes only the parameters of the equation: a, b, c. Dima got sick of getting bad marks and he asks you to help him solve this challenging problem.", "input_spec": "The first line contains three space-separated integers: a, b, c (1 ≤ a ≤ 5; 1 ≤ b ≤ 10000;  - 10000 ≤ c ≤ 10000).", "output_spec": "Print integer n — the number of the solutions that you've found. Next print n integers in the increasing order — the solutions of the given equation. Print only integer solutions that are larger than zero and strictly less than 109.", "sample_inputs": ["3 2 8", "1 2 -18", "2 2 -1"], "sample_outputs": ["3\n10 2008 13726", "0", "4\n1 31 337 967"], "notes": null}, "positive_code": [{"source_code": "use bignum;\n\n($a,$b,$c)=split/ /,<>;\nfor $i(1..81){\n$_ = $x = $b * $i**$a + $c;\n$s=0;\ns/./$s+=$&/ge;\nif ($i == $s and $x<10**9){\npush @a, $x;\n}\n\n}\n@a=sort{$a<=>$b}@a;\nprint 0+@a, \"\\n@a\""}, {"source_code": "($a,$b,$c)=split' ',<>;\n@a=();\nfor$s(1..81){\n\t$x=int .5+$b*$s**$a+$c;\n\tnext if $x>=1e9||$x<=0;\n\t$sx=0;\n\t$sx+=$_ for $x=~/./g;\n\tpush @a,$x if $s==$sx;\n}\nprint 0+@a,\"\\n@a\\n\";\n"}], "negative_code": [{"source_code": "use bignum;\n\nsub sss{\n\t$x=shift;\n\t@x=split//, $x;\n\t$s=0;\n\tfor $j(@x){$s+=$j}\n\treturn $s;\n\t}\n\n($a,$b,$c)=split/ /,<>;\nfor $i(1..81){\n$x = $b * $i**$a + $c;\nif ($i == sss($x)){\npush @a, $x;\n}\n\n}\n@a=sort{$a<=>$b}@a;\nprint 0+@a, \"\\n@a\""}, {"source_code": "use bignum;\n\nsub sss{\n\t$x=shift;\n\t@x=split//, $x;\n\t$s=0;\n\tfor $j(@x){$s+=$j}\n\treturn $s;\n\t}\n\n($a,$b,$c)=split/ /,<>;\nfor $i(1..81){\n$x = $b * $i**$a + $c;\nif ($i == sss($x) and $i<10**9){\npush @a, $x;\n}\n\n}\n@a=sort{$a<=>$b}@a;\nprint 0+@a, \"\\n@a\""}, {"source_code": "use bignum;\n\nsub sss{\n\t$x=shift;\n\t@x=split//, $x;\n\t$s=0;\n\tfor $j(@x){$s+=$j}\n\treturn $s;\n\t}\n\n($a,$b,$c)=split/ /,<>;\nfor $i(1..72){\n$x = $b * $i**$a + $c;\nif ($i == sss($x) and $i<10**9){\npush @a, $x;\n}\n\n}\n@a=sort{$a<=>$b}@a;\nprint 0+@a, \"\\n@a\""}, {"source_code": "($a,$b,$c)=split' ',<>;\n@a=();\nfor$s(1..45){\n\t$x=int .5+$b*$s**$a+$c;\n\tnext if $x>=1e9||$x<=0;\n\t$sx=0;\n\t$sx+=$_ for $x=~/./g;\n\tpush @a,$x if $s==$sx;\n}\nprint 0+@a,\"\\n@a\\n\";\n"}, {"source_code": "use bignum;\n\nsub sss{\n\t$x=shift;\n\t@x=split//, $x;\n\t$s=0;\n\tfor $j(@x){$s+=$j}\n\treturn $s;\n\t}\n\n($a,$b,$c)=split/ /,<>;\nfor $i(1..72){\n$x = $b * $i**$a + $c;\nif ($i == sss($x)){\npush @a, $x;\n}\n\n}\n@a=sort{$a<=>$b}@a;\nprint 0+@a, \"\\n@a\""}, {"source_code": "use bignum;\n\n($a,$b,$c)=split/ /,<>;\nfor $i(1..81){\n$_ = $b * $i**$a + $c;\n$s=0;\ns/./$s+=$&/ge;\nif ($i == $s and $i<10**9){\npush @a, $x;\n}\n\n}\n@a=sort{$a<=>$b}@a;\nprint 0+@a, \"\\n@a\""}], "src_uid": "e477185b94f93006d7ae84c8f0817009"} {"nl": {"description": "In this problem we assume the Earth to be a completely round ball and its surface a perfect sphere. The length of the equator and any meridian is considered to be exactly 40 000 kilometers. Thus, travelling from North Pole to South Pole or vice versa takes exactly 20 000 kilometers.Limak, a polar bear, lives on the North Pole. Close to the New Year, he helps somebody with delivering packages all around the world. Instead of coordinates of places to visit, Limak got a description how he should move, assuming that he starts from the North Pole. The description consists of n parts. In the i-th part of his journey, Limak should move ti kilometers in the direction represented by a string diri that is one of: \"North\", \"South\", \"West\", \"East\".Limak isn’t sure whether the description is valid. You must help him to check the following conditions: If at any moment of time (before any of the instructions or while performing one of them) Limak is on the North Pole, he can move only to the South. If at any moment of time (before any of the instructions or while performing one of them) Limak is on the South Pole, he can move only to the North. The journey must end on the North Pole. Check if the above conditions are satisfied and print \"YES\" or \"NO\" on a single line.", "input_spec": "The first line of the input contains a single integer n (1 ≤ n ≤ 50). The i-th of next n lines contains an integer ti and a string diri (1 ≤ ti ≤ 106, ) — the length and the direction of the i-th part of the journey, according to the description Limak got.", "output_spec": "Print \"YES\" if the description satisfies the three conditions, otherwise print \"NO\", both without the quotes.", "sample_inputs": ["5\n7500 South\n10000 East\n3500 North\n4444 West\n4000 North", "2\n15000 South\n4000 East", "5\n20000 South\n1000 North\n1000000 West\n9000 North\n10000 North", "3\n20000 South\n10 East\n20000 North", "2\n1000 North\n1000 South", "4\n50 South\n50 North\n15000 South\n15000 North"], "sample_outputs": ["YES", "NO", "YES", "NO", "NO", "YES"], "notes": "NoteDrawings below show how Limak's journey would look like in first two samples. In the second sample the answer is \"NO\" because he doesn't end on the North Pole. "}, "positive_code": [{"source_code": "use strict;\nuse warnings;\n$,=\" \";\nmy $nn=<>;\nchomp($nn);\nmy $n=[0,10000];\nwhile($nn--)\n{\nmy ($x,$y)=split / /,<>;\nchomp($x,$y);\nmove($x,$y);\n}\n\nif($n->[1]==10000)\n{\n print \"YES\\n\";\n}\nelse\n{\n print \"NO\\n\";\n}\n\n\n\n\nsub move{\n my $v=shift;\n my $dir=shift;\n if($dir eq \"South\")\n {\n $n->[1]-=$v;\n if($n->[1]<-10000)\n {\n noo();\n }\n }\n elsif($dir eq \"East\")\n {\n if($n->[1]==10000)\n {\n print \"NO\\n\";\n exit(0);\n }\n if($n->[1]==-10000)\n {\n print \"NO\\n\";\n exit(0);\n }\n }\n elsif($dir eq \"West\")\n {\n if($n->[1]==10000)\n {\n print \"NO\\n\";\n exit(0);\n }\n if($n->[1]==-10000)\n {\n print \"NO\\n\";\n exit(0);\n }\n }\n elsif($dir eq \"North\")\n {\n if($n->[1]==10000)\n {\n print \"NO\\n\";\n exit(0);\n }\n $n->[1]+=$v;\n if($n->[1]>10000)\n {\n noo();\n }\n }\n}\n\nsub noo{\n print \"NO\\n\";\n exit(0);\n}\n"}], "negative_code": [{"source_code": "\n$,=\" \";\nmy $nn=<>;\nchomp($nn);\nmy $n=[0,10000];\nwhile($nn--)\n{\nmy ($x,$y)=split / /,<>;\nchomp($x,$y);\nwhile($x>20000)\n{\n $x=40000-$x;\n}\nmove($x,$y);\n}\n\nif($n->[1]==10000)\n{\n print \"YES\\n\";\n}\nelse\n{\n print \"NO\\n\";\n}\n\n\nsub move{\n my $v=shift;\n my $dir=shift;\n if($dir eq \"South\")\n {\n $n->[1]-=$v;\n }\n elsif($dir eq \"East\")\n {\n if($n->[1]==10000)\n {\n print \"NO\\n\";\n exit(0);\n }\n if($n->[1]==-10000)\n {\n print \"NO\\n\";\n exit(0);\n }\n $n->[0]+=$v;\n }\n elsif($dir eq \"West\")\n {\n if($n->[1]==10000)\n {\n print \"NO\\n\";\n exit(0);\n }\n if($n->[1]==-10000)\n {\n print \"NO\\n\";\n exit(0);\n }\n $n->[0]-=$v;\n }\n elsif($dir eq \"North\")\n {\n if($n->[1]==10000)\n {\n print \"NO\\n\";\n exit(0);\n }\n $n->[1]+=$v;\n }\n}\n"}, {"source_code": "\n$,=\" \";\nmy $nn=<>;\nchomp($nn);\nmy $n=[0,10000];\nwhile($nn--)\n{\nmy ($x,$y)=split / /,<>;\nchomp($x,$y);\nwhile($x>20000)\n{\n if($x>40000)\n {\n $x-=40000;\n }\n else\n {\n $x=40000-$x;\n }\n}\nmove($x,$y);\n}\n\nif($n->[1]==10000)\n{\n print \"YES\\n\";\n}\nelse\n{\n print \"NO\\n\";\n}\n\n\nsub move{\n my $v=shift;\n my $dir=shift;\n if($dir eq \"South\")\n {\n $n->[1]-=$v;\n }\n elsif($dir eq \"East\")\n {\n if($n->[1]==10000)\n {\n print \"NO\\n\";\n exit(0);\n }\n if($n->[1]==-10000)\n {\n print \"NO\\n\";\n exit(0);\n }\n $n->[0]+=$v;\n }\n elsif($dir eq \"West\")\n {\n if($n->[1]==10000)\n {\n print \"NO\\n\";\n exit(0);\n }\n if($n->[1]==-10000)\n {\n print \"NO\\n\";\n exit(0);\n }\n $n->[0]-=$v;\n }\n elsif($dir eq \"North\")\n {\n if($n->[1]==10000)\n {\n print \"NO\\n\";\n exit(0);\n }\n $n->[1]+=$v;\n }\n}\n"}], "src_uid": "11ac96a9daa97ae1900f123be921e517"} {"nl": {"description": "Arkadiy has lots square photos with size a × a. He wants to put some of them on a rectangular wall with size h × w. The photos which Arkadiy will put on the wall must form a rectangular grid and the distances between neighboring vertically and horizontally photos and also the distances between outside rows and columns of photos to the nearest bound of the wall must be equal to x, where x is some non-negative real number. Look on the picture below for better understanding of the statement. Arkadiy haven't chosen yet how many photos he would put on the wall, however, he want to put at least one photo. Your task is to determine the minimum value of x which can be obtained after putting photos, or report that there is no way to put positive number of photos and satisfy all the constraints. Suppose that Arkadiy has enough photos to make any valid arrangement according to the constraints.Note that Arkadiy wants to put at least one photo on the wall. The photos should not overlap, should completely lie inside the wall bounds and should have sides parallel to the wall sides.", "input_spec": "The first line contains three integers a, h and w (1 ≤ a, h, w ≤ 109) — the size of photos and the height and the width of the wall.", "output_spec": "Print one non-negative real number — the minimum value of x which can be obtained after putting the photos on the wall. The absolute or the relative error of the answer must not exceed 10 - 6. Print -1 if there is no way to put positive number of photos and satisfy the constraints.", "sample_inputs": ["2 18 13", "4 4 4", "3 4 3"], "sample_outputs": ["0.5", "0", "-1"], "notes": "NoteIn the first example Arkadiy can put 7 rows of photos with 5 photos in each row, so the minimum value of x equals to 0.5.In the second example Arkadiy can put only 1 photo which will take the whole wall, so the minimum value of x equals to 0.In the third example there is no way to put positive number of photos and satisfy the constraints described in the statement, so the answer is -1."}, "positive_code": [{"source_code": "sub gcd\n{\n\tif ($_[1] == 0) { return $_[0]; }\n\treturn gcd($_[1], $_[0] % $_[1]);\n}\n\nsub min { return $_[0] < $_[1] ? $_[0] : $_[1]; }\n\n$_ = ; my ($a, $h, $w) = split;\nmy $q1 = int(($h + $a) / gcd($h + $a, $w + $a));\nmy $q2 = int(($w + $a) / gcd($h + $a, $w + $a));\nmy $k = min(int((int($h / $a) + 1) / $q1), int((int($w / $a) + 1) / $q2));\n$q1 *= $k;\n$q2 *= $k;\nif ($k == 0 || $q1 < 2 || $q2 < 2)\n{\n\tprint \"-1\\n\";\n}\nelse\n{\n\tmy $x = ($h + $a) / $q1 - $a;\n\tprintf(\"%.9f\\n\", $x);\n}"}], "negative_code": [], "src_uid": "7fbefd3eb1aad6865adcfac394f0a7e6"} {"nl": {"description": "Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with that.The box's lock looks as follows: it contains 4 identical deepenings for gems as a 2 × 2 square, and some integer numbers are written at the lock's edge near the deepenings. The example of a lock is given on the picture below. The box is accompanied with 9 gems. Their shapes match the deepenings' shapes and each gem contains one number from 1 to 9 (each number is written on exactly one gem). The box will only open after it is decorated with gems correctly: that is, each deepening in the lock should be filled with exactly one gem. Also, the sums of numbers in the square's rows, columns and two diagonals of the square should match the numbers written at the lock's edge. For example, the above lock will open if we fill the deepenings with gems with numbers as is shown on the picture below. Now Vasilisa the Wise wants to define, given the numbers on the box's lock, which gems she should put in the deepenings to open the box. Help Vasilisa to solve this challenging task.", "input_spec": "The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers r1 and r2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers c1 and c2 that define the required sums of numbers in the columns of the square. The third line contains space-separated integers d1 and d2 that define the required sums of numbers on the main and on the side diagonals of the square (1 ≤ r1, r2, c1, c2, d1, d2 ≤ 20). Correspondence between the above 6 variables and places where they are written is shown on the picture below. For more clarifications please look at the second sample test that demonstrates the example given in the problem statement. ", "output_spec": "Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number \"-1\" (without the quotes). If there are several solutions, output any.", "sample_inputs": ["3 7\n4 6\n5 5", "11 10\n13 8\n5 16", "1 2\n3 4\n5 6", "10 10\n10 10\n10 10"], "sample_outputs": ["1 2\n3 4", "4 7\n9 1", "-1", "-1"], "notes": "NotePay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number \"5\". However, Vasilisa only has one gem with each number from 1 to 9."}, "positive_code": [{"source_code": "($r1,$r2)=split(' ',<>);\n($c1,$c2)=split(' ',<>);\n($d1,$d2)=split(' ',<>);\nif(($r1-$d2+$c1)%2!=0){\nprint -1;\n}\nelse{\n$x=($r1-$d2+$c1)/2;\n$y=$r1-$x;\n$w=$d1-$x;\n$z=$c1-$x;\nif($y+$w==$c2 and $z+$y==$d2 and $z+$w==$r2 and $x!=$y and $x!=$z and $x!=$w and $y!=$z and $y!=$w and $z!=$w and $x<10 and $y<10 and $z<10 and $w<10 and $x>0 and $y>0 and $z>0 and $w>0 ){\nprint \"$x $y\\n$z $w\";\n\n}\nelse{\nprint -1;\n}\n\n\n\n}\n"}], "negative_code": [{"source_code": "($r1,$r2)=split(' ',<>);\n($c1,$c2)=split(' ',<>);\n($d1,$d2)=split(' ',<>);\nif(($r1-$d2+$c1)%2!=0){\nprint -1;\n}\nelse{\n$x=($r1-$d2+$c1)/2;\n$y=$r1-$x;\n$w=$d1-$x;\n$z=$c1-$x;\nif($y+$w==$c2 and $z+$y==$d2 and $x!=$y and $x!=$z and $x!=$w and $y!=$z and $y!=$w and $z!=$w ){\nprint \"$x $y\\n$z $w\";\n\n}\nelse{\nprint -1;\n}\n\n\n\n}\n"}, {"source_code": "($r1,$r2)=split(' ',<>);\n($c1,$c2)=split(' ',<>);\n($d1,$d2)=split(' ',<>);\nif(($r1-$d2+$c1)%2!=0){\nprint -1;\n}\nelse{\n$x=($r1-$d2+$c1)/2;\n$y=$r1-$x;\n$w=$d1-$x;\n$z=$c1-$x;\nif($y+$w==$c2 and $z+$y==$d2 and $x!=$y and $x!=$z and $x!=$w and $y!=$z and $y!=$w and $z!=$w and $x<10 and $y<10 and $z<10 and $w<10 and $x>0 and $y>0 and $z>0 and $w>0 ){\nprint \"$x $y\\n$z $w\";\n\n}\nelse{\nprint -1;\n}\n\n\n\n}\n"}], "src_uid": "6821f502f5b6ec95c505e5dd8f3cd5d3"} {"nl": {"description": "Little Joty has got a task to do. She has a line of n tiles indexed from 1 to n. She has to paint them in a strange pattern.An unpainted tile should be painted Red if it's index is divisible by a and an unpainted tile should be painted Blue if it's index is divisible by b. So the tile with the number divisible by a and b can be either painted Red or Blue.After her painting is done, she will get p chocolates for each tile that is painted Red and q chocolates for each tile that is painted Blue.Note that she can paint tiles in any order she wants.Given the required information, find the maximum number of chocolates Joty can get.", "input_spec": "The only line contains five integers n, a, b, p and q (1 ≤ n, a, b, p, q ≤ 109).", "output_spec": "Print the only integer s — the maximum number of chocolates Joty can get. Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.", "sample_inputs": ["5 2 3 12 15", "20 2 3 3 5"], "sample_outputs": ["39", "51"], "notes": null}, "positive_code": [{"source_code": "\n\n# read and parse one line\nsub rd {\n my $f = ;\n chomp ( $f );\n my @r = split m/ /, $f;\n return @r;\n}\n\n# maximum function\nsub max {\n return ($_[0] > $_[1] ? $_[0] : $_[1]);\n}\n\n# euclid's algorithm\nsub gcd {\n my $a = shift @_;\n my $b = shift @_;\n if ( $b == 0 ) {\n\treturn $a;\n }\n else {\n\treturn &gcd ( $b, $a % $b );\n }\n}\n\n\n\n\n\n\n\n\nmy $n, $a, $b, $p, $q;\n($n, $a, $b, $p, $q) = &rd;\n\nmy $sum = 0;\nmy $bigger = max ( $p, $q );\n\nmy $num_a = 0;\nmy $num_b = 0;\nmy $num_both = 0;\nmy $gcd = &gcd( $a, $b );\nmy $lcm = ($a / $gcd) * ($b / $gcd) * $gcd;\n \n$num_both = int ($n / ($lcm));\n$num_a = int (($n / $a) - $num_both);\n$num_b = int (($n / $b) - $num_both);\n\nmy $ans = 0;\n\n$ans = ($num_a * $p) + ($num_b * $q) + ($num_both * $bigger);\n\nprint \"$ans\\n\";\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}], "negative_code": [{"source_code": "\n\n# read and parse one line\nsub rd {\n my $f = ;\n chomp ( $f );\n my @r = split m/ /, $f;\n return @r;\n}\n\n# maximum function\nsub max {\n return ($_[0] > $_[1] ? $_[0] : $_[1]);\n}\n\n\n\n\nmy $n, $a, $b, $p, $q;\n($n, $a, $b, $p, $q) = &rd;\n\nmy $sum = 0;\nmy $bigger = max ( $p, $q );\n\nmy $num_a = 0;\nmy $num_b = 0;\nmy $num_both = 0;\n \n$num_both = int ($n / ($a * $b));\n$num_a = int (($n / $a) - $num_both);\n$num_b = int (($n / $b) - $num_both);\n\nmy $ans = 0;\n\n$ans = ($num_a * $p) + ($num_b * $q) + ($num_both * $bigger);\n\nprint \"$ans\\n\";\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}], "src_uid": "35d8a9f0d5b5ab22929ec050b55ec769"} {"nl": {"description": "Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition.Embosser is a special devise that allows to \"print\" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture: After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'.Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it.", "input_spec": "The only line of input contains the name of some exhibit — the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters.", "output_spec": "Print one integer — the minimum number of rotations of the wheel, required to print the name given in the input.", "sample_inputs": ["zeus", "map", "ares"], "sample_outputs": ["18", "35", "34"], "notes": "Note  To print the string from the first sample it would be optimal to perform the following sequence of rotations: from 'a' to 'z' (1 rotation counterclockwise), from 'z' to 'e' (5 clockwise rotations), from 'e' to 'u' (10 rotations counterclockwise), from 'u' to 's' (2 counterclockwise rotations). In total, 1 + 5 + 10 + 2 = 18 rotations are required."}, "positive_code": [{"source_code": "use strict;\nuse warnings;\n\nsub main{\n\tmy $word = ;\n\tmy @array = split(//, $word);\n\n\tmy $prev = 'a';\n\tmy $result = 0;\n\n\tfor (my $i = 0; $i < scalar(@array) - 1; $i++) {\n\t\tmy $char = $array[$i];\n\n\t\tmy $var1 = abs(ord($char) - ord($prev));\n\t\tmy $var2 = 26 - abs(ord($char) - ord($prev));\n\n\t\t$result += ($var1, $var2)[$var1 > $var2];\n\t\t$prev = $char; \n\t}\n\n\tprint \"$result\\n\";\n}\n\nmain;"}, {"source_code": "$_ = \"a\".<>;\n/(.)(.)(?{ $d=abs(ord($1)-ord($2)); $c+= ($d<13? $d: 26-$d) })(*FAIL)/;\nprint $c;\n"}, {"source_code": "$,=\" \";\nmy $k=0;\nmy %a=map {$_ => $k++ }('a'..'z');\n\nmy $s=<>;\nchomp($s);\nmy $p=0;\nmy $ans=0;\nfor(my $i=0;$i $_[1] ? $_[1] : $_[0];\n}\n\nsub max_{\n\treturn $_[1] > $_[0] ? $_[1] : $_[0];\n}\n\nsub min{\n\tmy $a=shift;\n\tmy $mm=$a->[0];\n\tfor(my $i=1;$i<@{$a};$i++)\n\t{\n\t\t$mm=min_($mm,$a->[$i]);\n\t}\n\treturn $mm;\n}\n\nsub max{\n\tmy $a=shift;\n\tmy $mm=$a->[0];\n\tfor(my $i=1;$i<@{$a};$i++)\n\t{\n\t\t$mm=max_($mm,$a->[$i]);\n\t}\n\treturn $mm;\n}\n"}, {"source_code": "$\\ = $/;\n\n$A = join '', ('a' .. 'z') x 2, (reverse 'a' .. 'z') x 2;\n\nwhile(<>){\n\tchomp;\n\ts/^/a/;\n\t$sum = 0;\n\t\n\twhile( /(?=(.)(.))/g ){\n\t\t($_1, $_2) = ($1, $2);\n\t\t$_1 eq $_2 and next;\n\t\t$sum += (sort {$a <=> $b} map -1+length, $A =~ /$_1.*?$_2/g)[ 0 ];\n\t\t}\n\t\n\tprint $sum\n\t}"}, {"source_code": "(a . <>) =~ s/(?=(.)(.))/\n\t$z += (sort {$a <=> $b} map abs($_ + ord( $1 ) - ord $2), 0, 26, -26)[ 0 ]\n\n/regex;\n\nprint $z"}], "negative_code": [], "src_uid": "ecc890b3bdb9456441a2a265c60722dd"} {"nl": {"description": "The city park of IT City contains n east to west paths and n north to south paths. Each east to west path crosses each north to south path, so there are n2 intersections.The city funded purchase of five benches. To make it seems that there are many benches it was decided to place them on as many paths as possible. Obviously this requirement is satisfied by the following scheme: each bench is placed on a cross of paths and each path contains not more than one bench.Help the park administration count the number of ways to place the benches.", "input_spec": "The only line of the input contains one integer n (5 ≤ n ≤ 100) — the number of east to west paths and north to south paths.", "output_spec": "Output one integer — the number of ways to place the benches.", "sample_inputs": ["5"], "sample_outputs": ["120"], "notes": null}, "positive_code": [{"source_code": "#!/usr/bin/env perl\n\nuse bigint;\n\nsub factorial {\n my $n = shift;\n if ($n==0) {\n return 1;\n } else {\n return $n*factorial($n-1);\n }\n}\n\nsub subfactorial {\n my $n = shift;\n my $sub = shift;\n if ($n==$sub) {\n return 1;\n } else {\n return $n*subfactorial($n-1, $sub);\n }\n}\n\n\n$n = ;\n$result = ( $n**2 * ($n-1)**2 * ($n-2)**2 * ($n-3)**2 * ($n-4)**2)/120;\nprint \"$result\\n\";"}], "negative_code": [], "src_uid": "92db14325cd8aee06b502c12d2e3dd81"} {"nl": {"description": "You are solving the crossword problem K from IPSC 2014. You solved all the clues except for one: who does Eevee evolve into? You are not very into pokemons, but quick googling helped you find out, that Eevee can evolve into eight different pokemons: Vaporeon, Jolteon, Flareon, Espeon, Umbreon, Leafeon, Glaceon, and Sylveon.You know the length of the word in the crossword, and you already know some letters. Designers of the crossword made sure that the answer is unambiguous, so you can assume that exactly one pokemon out of the 8 that Eevee evolves into fits the length and the letters given. Your task is to find it.", "input_spec": "First line contains an integer n (6 ≤ n ≤ 8) – the length of the string. Next line contains a string consisting of n characters, each of which is either a lower case english letter (indicating a known letter) or a dot character (indicating an empty cell in the crossword).", "output_spec": "Print a name of the pokemon that Eevee can evolve into that matches the pattern in the input. Use lower case letters only to print the name (in particular, do not capitalize the first letter).", "sample_inputs": ["7\nj......", "7\n...feon", "7\n.l.r.o."], "sample_outputs": ["jolteon", "leafeon", "flareon"], "notes": "NoteHere's a set of names in a form you can paste into your solution:[\"vaporeon\", \"jolteon\", \"flareon\", \"espeon\", \"umbreon\", \"leafeon\", \"glaceon\", \"sylveon\"]{\"vaporeon\", \"jolteon\", \"flareon\", \"espeon\", \"umbreon\", \"leafeon\", \"glaceon\", \"sylveon\"}"}, "positive_code": [{"source_code": "$l=<>;\nchomp($i=<>);\nprint grep /^$i$/,qw(vaporeon jolteon flareon espeon umbreon leafeon glaceon sylveon)"}, {"source_code": "$l=<>;\nchomp($i=<>);\nfor(qw(Vaporeon Jolteon Flareon Espeon Umbreon Leafeon Glaceon Sylveon)){\n if(/$i/i && $l==length) {\n print lc;\n last;\n }\n}"}, {"source_code": "#!/usr/bin/perl\n\nuse strict;\n\nmy @words = (\"vaporeon\", \"jolteon\", \"flareon\", \"espeon\", \"umbreon\", \"leafeon\", \"glaceon\", \"sylveon\");\nchomp($_ = <>);\nchomp($_ = <>);\nmy $qr = qr/^$_$/;\nfor (@words) {\n print if /$qr/;\n}\n"}, {"source_code": "<>;<>=~/...$/;/^$`$/&&print $_.\"eon\" for qw(vapor jolt flar esp umbr leaf glac sylv)"}, {"source_code": "<>;<>=~/...$/;/^$`$/&&print $_.\"eon\" for qw(vapor jolt flar esp umbr leaf glac sylv)\n"}, {"source_code": "#!/usr/bin/env perl\n\nuse strict;\nuse warnings;\nno warnings 'uninitialized';\n\nmy $N = <>+0;\nmy $S = <>;\nchomp $S;\n\nmy ($res) = grep /^$S$/i,\n qw/Vaporeon Jolteon Flareon Espeon Umbreon Leafeon Glaceon Sylveon/;\n\nprint lc( $res ), \"\\n\"\n"}, {"source_code": "<>;<>=~/...$/;/^$`$/&&print $_.\"eon\" for qw(vapor jolt flar esp umbr leaf glac sylv)\n"}, {"source_code": "<>;<>=~/...$/;/^$`$/&&print $_.\"eon\" for qw(vapor jolt flar esp umbr leaf glac sylv)"}, {"source_code": "<>;<>=~/...$/;/^$`$/&&print $_.\"eon\" for qw(vapor jolt flar esp umbr leaf glac sylv)\n"}, {"source_code": "<>;<>=~/...$/;/^$`$/&&print $_.\"eon\" for qw(vapor jolt flar esp umbr leaf glac sylv)\n"}, {"source_code": "@pok=(\"vaporeon\", \"jolteon\", \"flareon\", \"espeon\", \"umbreon\", \"leafeon\", \"glaceon\", \"sylveon\");\n$n=<>;\n$ch=<>;\nchomp$ch;\nif($n==6){\nprint $pok[3];\n}\nelsif($n==8){\nprint $pok[0];\n}\nelsif($ch=~/^[j\\.][o\\.][l\\.][t\\.]/){\nprint $pok[1];\n}\nelsif($ch=~/^[f\\.][l\\.][a\\.][r\\.]/){\nprint $pok[2];\n}\nelsif($ch=~/^[u\\.][m\\.][b\\.][r\\.]/){\nprint $pok[4];\n}\nelsif($ch=~/^[l\\.][e\\.][a\\.][f\\.]/){\nprint $pok[5];\n}\nelsif($ch=~/^[s\\.][y\\.][l\\.][v\\.]/){\nprint $pok[7];\n}\nelse{\nprint $pok[6];\n}\n"}, {"source_code": "<>;<>=~/...$/;/^$`$/&&print $_.\"eon\" for qw(vapor jolt flar esp umbr leaf glac sylv)\n"}, {"source_code": "<>;<>=~/...$/;/^$`$/&&print $_.\"eon\" for qw(vapor jolt flar esp umbr leaf glac sylv)\n"}, {"source_code": "<>;<>=~/...$/;/^$`$/&&print $_.\"eon\" for qw(vapor jolt flar esp umbr leaf glac sylv)\n"}, {"source_code": "<>;\n<>=~/...$/;\n$m=$`;\n/^$m$/ && print $_.\"eon\" for qw(vapor jolt flar esp umbr leaf glac sylv)"}, {"source_code": "<>;\nchomp ($m=<>);\n/^$m$/ && print for qw(vaporeon jolteon flareon espeon umbreon leafeon glaceon sylveon)"}, {"source_code": "<>;<>=~/...$/;/^$`$/&&print $_.\"eon\" for qw(vapor jolt flar esp umbr leaf glac sylv)\n"}], "negative_code": [{"source_code": "<>; \nchomp($i=<>);\nfor(qw(Vaporeon Jolteon Flareon Espeon Umbreon Leafeon Glaceon Sylveon)){\n if(/$i/i) {\n print lc;\n last;\n }\n}"}, {"source_code": "<>; \nchomp($i=<>);\nfor(qw(Vaporeon Jolteon Flareon Espeon Umbreon Leafeon Glaceon Sylveon)){\n print lc if /$i/i;\n}"}, {"source_code": "#!/usr/bin/env perl\n\nuse strict;\nuse warnings;\nno warnings 'uninitialized';\n\nmy $N = <>+0;\nmy $S = <>;\nchomp $S;\n\nmy ($res) = grep /$S/i,\n qw/Vaporeon Jolteon Flareon Espeon Umbreon Leafeon Glaceon Sylveon/;\n\nprint lc( $res ), \"\\n\"\n\n\n"}, {"source_code": "@pok=(\"vaporeon\", \"jolteon\", \"flareon\", \"espeon\", \"umbreon\", \"leafeon\", \"glaceon\", \"sylveon\");\n$n=<>;\n$ch=<>;\nchomp$ch;\nif($n==6){\nprint $pok[3];\n}\nelsif($n==8){\nprint $pok[0];\n}\nelsif($ch=~/[j\\.][o\\.][l\\.][t\\.]/){\nprint $pok[1];\n}\nelsif($ch=~/[f\\.][l\\.][a\\.][r\\.]/){\nprint $pok[2];\n}\nelsif($ch=~/[u\\.][m\\.][b\\.][r\\.]/){\nprint $pok[4];\n}\nelsif($ch=~/[l\\.][e\\.][a\\.][f\\.]/){\nprint $pok[5];\n}\nelsif($ch=~/[s\\.][y\\.][l\\.][v\\.]/){\nprint $pok[7];\n}\nelse{\nprint $pok[6];\n}"}, {"source_code": "<>;\n$m=<>;\nchomp $m;\n/$m/i and print for qw(Vaporeon Jolteon Flareon Espeon Umbreon Leafeon Glaceon Sylveon)"}, {"source_code": "<>;\nchomp ($m=<>);\n/$m/ && print for qw(vaporeon jolteon flareon espeon umbreon leafeon glaceon sylveon)"}, {"source_code": "while(<>){\n\tchomp;\n\t@_=(\"vaporeon\", \"jolteon\", \"flareon\", \"espeon\", \"umbreon\", \"leafeon\", \"glaceon\", \"sylveon\");\n\t$match=<>;\n\tchomp $match;\n\t/$match/ and print for @_;\n\t\n\tprint \"\\n\"\n\t}"}], "src_uid": "ec3d15ff198d1e4ab9fd04dd3b12e6c0"} {"nl": {"description": "One day Kefa found n baloons. For convenience, we denote color of i-th baloon as si — lowercase letter of the Latin alphabet. Also Kefa has k friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all.", "input_spec": "The first line contains two integers n and k (1 ≤ n, k ≤ 100) — the number of baloons and friends. Next line contains string s — colors of baloons.", "output_spec": "Answer to the task — «YES» or «NO» in a single line. You can choose the case (lower or upper) for each letter arbitrary.", "sample_inputs": ["4 2\naabb", "6 3\naacaab"], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO»."}, "positive_code": [{"source_code": "($n, $k) = split(/ /,<>);\nchomp ($ball = <>);\n\n$ans = \"YES\";\n\nfor ($i = 0; $i < $n; ++$i) {\n\t$let = substr ($ball, $i, 1);\n\t$count{$let}++;\n\tif ($count{$let} > $k) {\n\t\t$ans = \"NO\";\n\t}\n}\n\n\nprint \"$ans\\n\";\n\n"}], "negative_code": [{"source_code": "($n, $k) = split(/ /,<>);\nchomp ($ball = <>);\n\n$ans = \"YES\";\n\nfor ($i = 0; $i < $n; ++$i) {\n\t$let = substr ($ball, $i, 1);\n\t$count{$let}++;\n\tif ($count{$ball[$i]} > $k) {\n\t\t$ans = \"NO\";\n\t}\n}\n\n\nprint \"$ans\\n\";\n\n"}], "src_uid": "ceb3807aaffef60bcdbcc9a17a1391be"} {"nl": {"description": "While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number \"586\" are the same as finger movements for number \"253\": Mike has already put in a number by his \"finger memory\" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements?", "input_spec": "The first line of the input contains the only integer n (1 ≤ n ≤ 9) — the number of digits in the phone number that Mike put in. The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in.", "output_spec": "If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print \"YES\" (without quotes) in the only line. Otherwise print \"NO\" (without quotes) in the first line.", "sample_inputs": ["3\n586", "2\n09", "9\n123456789", "3\n911"], "sample_outputs": ["NO", "NO", "YES", "YES"], "notes": "NoteYou can find the picture clarifying the first sample case in the statement above."}, "positive_code": [{"source_code": "<>; $_ = <>;\n$a = /[1470]/ + /[123]/ + /[3690]/ + /[709]/;\n$b = ($a == 4? \"YES\": \"NO\");\nprint $b;\n\n\n"}, {"source_code": "<>; $_ = <>;\n$a = /[1470]/ + /[123]/ + /[3690]/ + /[709]/;\nprint ($a == 4? \"YES\": \"NO\");"}, {"source_code": "<>; $_ = <>;\nprint (/[1470]/ + /[123]/ + /[3690]/ + /[709]/ == 4? \"YES\": \"NO\");"}], "negative_code": [], "src_uid": "d0f5174bb0bcca5a486db327b492bf33"} {"nl": {"description": "This version of the problem differs from the next one only in the constraint on $$$n$$$.Note that the memory limit in this problem is lower than in others.You have a vertical strip with $$$n$$$ cells, numbered consecutively from $$$1$$$ to $$$n$$$ from top to bottom.You also have a token that is initially placed in cell $$$n$$$. You will move the token up until it arrives at cell $$$1$$$.Let the token be in cell $$$x > 1$$$ at some moment. One shift of the token can have either of the following kinds: Subtraction: you choose an integer $$$y$$$ between $$$1$$$ and $$$x-1$$$, inclusive, and move the token from cell $$$x$$$ to cell $$$x - y$$$. Floored division: you choose an integer $$$z$$$ between $$$2$$$ and $$$x$$$, inclusive, and move the token from cell $$$x$$$ to cell $$$\\lfloor \\frac{x}{z} \\rfloor$$$ ($$$x$$$ divided by $$$z$$$ rounded down). Find the number of ways to move the token from cell $$$n$$$ to cell $$$1$$$ using one or more shifts, and print it modulo $$$m$$$. Note that if there are several ways to move the token from one cell to another in one shift, all these ways are considered distinct (check example explanation for a better understanding).", "input_spec": "The only line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \\le n \\le 2 \\cdot 10^5$$$; $$$10^8 < m < 10^9$$$; $$$m$$$ is a prime number) — the length of the strip and the modulo.", "output_spec": "Print the number of ways to move the token from cell $$$n$$$ to cell $$$1$$$, modulo $$$m$$$.", "sample_inputs": ["3 998244353", "5 998244353", "42 998244353"], "sample_outputs": ["5", "25", "793019428"], "notes": "NoteIn the first test, there are three ways to move the token from cell $$$3$$$ to cell $$$1$$$ in one shift: using subtraction of $$$y = 2$$$, or using division by $$$z = 2$$$ or $$$z = 3$$$.There are also two ways to move the token from cell $$$3$$$ to cell $$$1$$$ via cell $$$2$$$: first subtract $$$y = 1$$$, and then either subtract $$$y = 1$$$ again or divide by $$$z = 2$$$.Therefore, there are five ways in total."}, "positive_code": [{"source_code": "($n,$m)=split/ /,<>;@a[1]=1;for$y(2..$n){@a[$y]=(@a[$y]+2*@a[$y-1]+1)%$m;@a[$y]=(@a[$y]-@a[$y-1])%$m if($y<3);@a[$_*$y]=(@a[$_*$y]+(@a[$y]-@a[$y-1]+$m)%$m)%$m for(2..$n/$y)};print@a[$n]"}, {"source_code": "($n,$m)=split/ /,<>;@a[1]=1;for$y(2..$n){@a[$y]=(@a[$y]+2*@a[$y-1]+1)%$m;@a[$y]=(@a[$y]-@a[$y-1])%$m if($y==2);@a[$_*$y]=(@a[$_*$y]+(@a[$y]-@a[$y-1]+$m)%$m)%$m for(2..$n/$y)};print@a[$n]"}, {"source_code": " ($n,$m)=split/ /,<>;@a[1]=1;for$x(2..$n){@a[$x]=(@a[$x]+2*@a[$x-1]+1)%$m;@a[$x]=(@a[$x]-@a[$x-1])%$m if($x<3);@a[$_*$x]=(@a[$_*$x]+(@a[$x]-@a[$x-1]+$m)%$m)%$m for(2..$n/$x)};print@a[$n]"}, {"source_code": "($n,$m)=split/ /,<>;@a[1]=1;for$x(2..$n){@a[$x]=(@a[$x]+2*@a[$x-1]+1)%$m;@a[$x]=(@a[$x]-@a[$x-1])%$m if($x==2);@a[$_*$x]=(@a[$_*$x]+(@a[$x]-@a[$x-1]+$m)%$m)%$m for(2..$n/$x)};print@a[$n]"}], "negative_code": [], "src_uid": "a524aa54e83fd0223489a19531bf0e79"} {"nl": {"description": "From beginning till end, this message has been waiting to be conveyed.For a given unordered multiset of n lowercase English letters (\"multi\" means that a letter may appear more than once), we treat all letters as strings of length 1, and repeat the following operation n - 1 times: Remove any two elements s and t from the set, and add their concatenation s + t to the set. The cost of such operation is defined to be , where f(s, c) denotes the number of times character c appears in string s.Given a non-negative integer k, construct any valid non-empty set of no more than 100 000 letters, such that the minimum accumulative cost of the whole process is exactly k. It can be shown that a solution always exists.", "input_spec": "The first and only line of input contains a non-negative integer k (0 ≤ k ≤ 100 000) — the required minimum cost.", "output_spec": "Output a non-empty string of no more than 100 000 lowercase English letters — any multiset satisfying the requirements, concatenated to be a string. Note that the printed string doesn't need to be the final concatenated string. It only needs to represent an unordered multiset of letters.", "sample_inputs": ["12", "3"], "sample_outputs": ["abababab", "codeforces"], "notes": "NoteFor the multiset {'a', 'b', 'a', 'b', 'a', 'b', 'a', 'b'}, one of the ways to complete the process is as follows: {\"ab\", \"a\", \"b\", \"a\", \"b\", \"a\", \"b\"}, with a cost of 0; {\"aba\", \"b\", \"a\", \"b\", \"a\", \"b\"}, with a cost of 1; {\"abab\", \"a\", \"b\", \"a\", \"b\"}, with a cost of 1; {\"abab\", \"ab\", \"a\", \"b\"}, with a cost of 0; {\"abab\", \"aba\", \"b\"}, with a cost of 1; {\"abab\", \"abab\"}, with a cost of 1; {\"abababab\"}, with a cost of 8. The total cost is 12, and it can be proved to be the minimum cost of the process."}, "positive_code": [{"source_code": "#!/usr/bin/perl\n\nuse warnings;\nuse strict;\n\n$\\ = $/;\nmy $debug = 0;\n\nwhile(<>){\n\tchomp;\n\tmy $n = $_;\n\t\n\tmy $ans = '';\n\tmy $sum = 0;\n\t\n\tfor my $L ( 'a' .. 'z' ){\n\t\t\n\t\tfor my $i ( 0 .. 1e3 ){\n\t\t\t\n\t\t\t$debug and print \"sum:[$sum]\";\n\t\t\t\n\t\t\tif( $sum + $i > $n ){\n\t\t\t\tlast;\n\t\t\t\t}\n\t\t\t\n\t\t\t$sum += $i;\n\t\t\t$ans .= $L;\n\t\t\t\n\t\t\t}\n\t\t\n\t\t\n\t\t}\n\t\n\tprint $ans;\n\t$debug and print \"final sum: [$sum]\";\n\t\n\t}"}, {"source_code": "while( $n = <> ){\n\t\n\tfor $L ( 'a' .. 'z' ){\n\t\t\n\t\tfor ( 0 .. 1e3 ){\n\t\t\t\t\t\t\n\t\t\tlast if $sum + $_ > $n;\n\t\t\t\n\t\t\t$sum += $_;\n\t\t\tprint $L;\n\t\t\t\n\t\t\t}\n\t\t}\n\t}"}], "negative_code": [], "src_uid": "b991c064562704b6106a6ff2a297e64a"} {"nl": {"description": "You may have heard of the pie rule before. It states that if two people wish to fairly share a slice of pie, one person should cut the slice in half, and the other person should choose who gets which slice. Alice and Bob have many slices of pie, and rather than cutting the slices in half, each individual slice will be eaten by just one person.The way Alice and Bob decide who eats each slice is as follows. First, the order in which the pies are to be handed out is decided. There is a special token called the \"decider\" token, initially held by Bob. Until all the pie is handed out, whoever has the decider token will give the next slice of pie to one of the participants, and the decider token to the other participant. They continue until no slices of pie are left.All of the slices are of excellent quality, so each participant obviously wants to maximize the total amount of pie they get to eat. Assuming both players make their decisions optimally, how much pie will each participant receive?", "input_spec": "Input will begin with an integer N (1 ≤ N ≤ 50), the number of slices of pie. Following this is a line with N integers indicating the sizes of the slices (each between 1 and 100000, inclusive), in the order in which they must be handed out.", "output_spec": "Print two integers. First, the sum of the sizes of slices eaten by Alice, then the sum of the sizes of the slices eaten by Bob, assuming both players make their decisions optimally.", "sample_inputs": ["3\n141 592 653", "5\n10 21 10 21 10"], "sample_outputs": ["653 733", "31 41"], "notes": "NoteIn the first example, Bob takes the size 141 slice for himself and gives the decider token to Alice. Then Alice gives the size 592 slice to Bob and keeps the decider token for herself, so that she can then give the size 653 slice to herself."}, "positive_code": [{"source_code": "<>;\n\t\n@_ = split ' ', <>;\n\t\n$tE = 0;\n\nfor( reverse @_ ){\n\t\n\t$sum += $_;\n\t$tE = \"( -1 ) * \" x ( $_ - $d < $d - $_ ) . \"( $_ - $tE )\";\n\t\n\t$d = abs( $_ - $d );\n\t}\n\n$E = eval $tE;\n$D = $sum - $E >> 1;\n\nprint \"$D \", $D + $E"}, {"source_code": "#!/usr/bin/perl\n\nuse warnings;\nuse strict;\n\n$\\ = $/;\n\nwhile(<>){\n\t@_ = split ' ', <>;\n\t\n\tmy $sum = unpack( '%32i' . @_, pack( 'i' x @_, @_ ) );\n\t\n\tmy $diff = 0;\n\tmy $to_eval = 0;\n\t\n\twhile( @_ > 0 ){\n\t\tmy $last = pop @_;\n\t\t\n\t\tif( $last - $diff > $diff - $last ){\n\t\t\t$to_eval = \"( 0 + $last - $to_eval )\";\n\t\t\t}\n\t\telse{\n\t\t\t$to_eval = \"( 0 - $last + $to_eval )\";\n\t\t\t}\n\t\t\n\t\t$diff = abs( $last - $diff );\n\t\t}\n\t\n\tmy $eval = eval $to_eval;\n\t\n\tprint( ( $sum - $eval ) / 2, ' ', ( $sum - $eval ) / 2 + $eval );\n\t}"}, {"source_code": "<>;\n\n$x = ( sort { $b <=> $a } $x, $_ + $s - $x )[ 0 ], $s += $_ for reverse split ' ', <>;\n\nprint $s - $x, \" $x\""}], "negative_code": [], "src_uid": "414540223db9d4cfcec6a973179a0216"} {"nl": {"description": "Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of $$$n$$$ rows and $$$m$$$ columns, where each cell is either black or white. Ivan calls the picture random if for every cell it has at most one adjacent cell of the same color. Two cells are considered adjacent if they share a side.Ivan's brothers spent some time trying to explain that it's not how the randomness usually works. Trying to convince Ivan, they want to count the number of different random (according to Ivan) pictures. Two pictures are considered different if at least one cell on those two picture is colored differently. Since the number of such pictures may be quite large, print it modulo $$$10^9 + 7$$$.", "input_spec": "The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\le n, m \\le 100\\,000$$$), the number of rows and the number of columns of the field.", "output_spec": "Print one integer, the number of random pictures modulo $$$10^9 + 7$$$.", "sample_inputs": ["2 3"], "sample_outputs": ["8"], "notes": "NoteThe picture below shows all possible random pictures of size $$$2$$$ by $$$3$$$. "}, "positive_code": [{"source_code": "#!/usr/bin/perl\n\nuse warnings;\nuse strict;\n\n$\\ = $/;\n\nmy $debug = 0;\n\nmy $MOD = 1e9 + 7;\n\nwhile(<>){\n\t$debug and print '-' x 15;\n\t\n\tmy( $n, $m ) = split;\n\t\n\t$debug and print \"[$n $m]\";\n\t\n\tprint +( fib( $n - 0 ) * 2 + 2 * fib( $m - 0 ) - 2 ) % $MOD;\n\t}\n\nsub fib {\n\tmy $fib = shift;\n\t\n\tmy $i = 1;\n\tmy $j = 1;\n\t\n\twhile( $fib >= 1 ){\n\t\t$fib --;\n\t\tmy $tmp = $j;\n\t\t$j += $i;\n\t\t$i = $tmp;\n\t\t\n\t\t$j %= $MOD;\n\t\t}\n\t\n\treturn $i % $MOD;\n\t}"}], "negative_code": [{"source_code": "#!/usr/bin/perl\n\nuse warnings;\nuse strict;\n\n$\\ = $/;\n\nmy $debug = 0;\n\nmy $MOD = 1e9 + 7;\n\nwhile(<>){\n\t$debug and print '-' x 15;\n\t\n\tmy( $n, $m ) = split;\n\t\n\t$debug and print \"[$n $m]\";\n\t\n\tprint fib( $n - 0 ) * 2 + 2 * fib( $m - 0 ) - 2;\n\t}\n\nsub fib {\n\tmy $fib = shift;\n\t\n\tmy $i = 1;\n\tmy $j = 1;\n\t\n\twhile( $fib >= 1 ){\n\t\t$fib --;\n\t\tmy $tmp = $j;\n\t\t$j += $i;\n\t\t$i = $tmp;\n\t\t\n\t\t$j %= $MOD;\n\t\t}\n\t\n\treturn $i % $MOD;\n\t}"}], "src_uid": "0f1ab296cbe0952faa904f2bebe0567b"} {"nl": {"description": "Olesya loves numbers consisting of n digits, and Rodion only likes numbers that are divisible by t. Find some number that satisfies both of them.Your task is: given the n and t print an integer strictly larger than zero consisting of n digits that is divisible by t. If such number doesn't exist, print  - 1.", "input_spec": "The single line contains two numbers, n and t (1 ≤ n ≤ 100, 2 ≤ t ≤ 10) — the length of the number and the number it should be divisible by.", "output_spec": "Print one such positive number without leading zeroes, — the answer to the problem, or  - 1, if such number doesn't exist. If there are multiple possible answers, you are allowed to print any of them.", "sample_inputs": ["3 2"], "sample_outputs": ["712"], "notes": null}, "positive_code": [{"source_code": "use bigint;\nchomp( ( $n, $t ) = split / /, <> );\nif ( $n < length($t) ) { print -1; exit; }\n$c = 10**( $n - 1 );\nwhile ( length($c) <= $n ) {\n if ( $c % $t == 0 ) {\n print $c;\n exit;\n }\n $c++;\n}\n\nprint -1;\n"}, {"source_code": "#!/usr/bin/perl -wn\nchomp;\n($n, $t) = split / /;\n$\\ = $/;\nif ( $n == 1 ) {\n print $t != 10 ? \"$t\" : \"-1\"; next;\n}\n$\\ = '';\n\nprint \"$t\";\nfor ( 1..($n - length $t) ) {\n print \"0\";\n}\nprint \"\\n\";\n\n"}, {"source_code": "#!/usr/bin/perl -wn\nchomp;\n($n, $t) = split / /;\n$\\ = $/;\nif ( $n == 1 ) {\n print $t != 10 ? \"$t\" : \"-1\"; next;\n}\nprint \"$t\" . \"0\" x ($n - length $t);\n"}, {"source_code": "#!/usr/bin/perl -wn\n# div2a_1.pl --- \n# Author: liuxueyang \n# Created: 11 Oct 2015\n# Version: 0.01\n\n#use warnings;\n#use strict;\n\nchomp;\n($n, $t) = split / /;\n\nif ( $n == 1 ) {\n if ( $t != 10 ) {\n print \"$t\\n\";\n next;\n }\n else {\n print \"-1\\n\";\n next;\n }\n}\nelsif ($t == 5 || $t == 10) {\n print \"1\" x ($n - 1) . \"0\\n\";\n next;\n}\nelsif ( $t == 2 ) {\n print \"1\" x ($n - 1) . \"2\\n\";\n next;\n}\n$mod = 0;\n\nfor ( 2..$n ) {\n $mod = ($mod * 10 + 1) % $t;\n}\nprint \"1\" x ($n - 1);\n$mod = $mod * 10;\n\nfor ( 0..9 ) {\n if ( ($mod + $_) % $t == 0) {\n print \"$_\\n\";\n last;\n }\n}\n__END__\n\n=head1 NAME\n\ndiv2a_1.pl - Describe the usage of script briefly\n\n=head1 SYNOPSIS\n\ndiv2a_1.pl [options] args\n\n -opt --long Option description\n\n=head1 DESCRIPTION\n\nStub documentation for div2a_1.pl, \n\n=head1 AUTHOR\n\nliuxueyang, Earies@JemirE\n\n=head1 COPYRIGHT AND LICENSE\n\nCopyright (C) 2015 by liuxueyang\n\nThis program is free software; you can redistribute it and/or modify\nit under the same terms as Perl itself, either Perl version 5.8.2 or,\nat your option, any later version of Perl 5 you may have available.\n\n=head1 BUGS\n\nNone reported... yet.\n\n=cut\n"}, {"source_code": "#!/usr/bin/perl -wn\nuse bigint;\nchomp;\n($n, $t) = split / /;\n$start = 10 ** ($n - 1);\n$end = 10 ** $n - 1;\nif ($end < $t) {\n print \"-1\\n\";\n next;\n} elsif ($start <= $t && $end >= $t) {\n print \"$t\\n\";\n next;\n}\nwhile ($start <= $end) {\n if ($start % $t == 0) {\n\tprint $start, \"\\n\";\n\tlast;\n } else { \n\t($start += 1);\n }\n}\nprint \"-1\", \"\\n\" if $start > $end;\n"}, {"source_code": "($n, $t) = split ' ', <>;\n$n eq '1' && $t == '10' ? print -1, \"\\n\" : print $t . '0' x ($n - length $t); \n"}, {"source_code": "($n, $_) = split ' ', <>;\nprint /${n}0/ ? -1 : $_ . 0 x ($n - length)"}], "negative_code": [{"source_code": "#!/usr/bin/perl -wn\n# div2a_1.pl --- \n# Author: liuxueyang \n# Created: 11 Oct 2015\n# Version: 0.01\n\n#use warnings;\n#use strict;\n\nchomp;\n($n, $t) = split / /;\nprint \"n = $n, t = $t\\n\";\n\nif ( $n == 1 ) {\n if ( $t != 10 ) {\n print \"$t\\n\";\n next;\n }\n else {\n print \"-1\\n\";\n next;\n }\n}\nelsif ($t == 5 || $t == 10) {\n print \"1\" x ($n - 1) . \"0\\n\";\n next;\n}\nelsif ( $t == 2 ) {\n print \"1\" x ($n - 1) . \"2\\n\";\n next;\n}\n$mod = 0;\n\nfor ( 2..$n ) {\n $mod = ($mod * 10 + 1) % $t;\n}\nprint \"1\" x ($n - 1);\n$mod = $mod * 10;\n\nfor ( 0..9 ) {\n if ( ($mod + $_) % $t == 0) {\n print \"$_\\n\";\n last;\n }\n}\n__END__\n\n=head1 NAME\n\ndiv2a_1.pl - Describe the usage of script briefly\n\n=head1 SYNOPSIS\n\ndiv2a_1.pl [options] args\n\n -opt --long Option description\n\n=head1 DESCRIPTION\n\nStub documentation for div2a_1.pl, \n\n=head1 AUTHOR\n\nliuxueyang, Earies@JemirE\n\n=head1 COPYRIGHT AND LICENSE\n\nCopyright (C) 2015 by liuxueyang\n\nThis program is free software; you can redistribute it and/or modify\nit under the same terms as Perl itself, either Perl version 5.8.2 or,\nat your option, any later version of Perl 5 you may have available.\n\n=head1 BUGS\n\nNone reported... yet.\n\n=cut\n"}, {"source_code": "#!/usr/bin/perl -wn\nchomp;\n($n, $t) = split / /;\n#print \"$n-$t\\n\";\n$start = 1 . \"0\" x ($n - 1);\n$end = \"9\" x $n;\n#print \"$start-$end\\n\";\nwhile ($start <= $end) {\n !($start % $t) ? last : ($start += 1);\n}\n#print $start, \"\\n\" if ($start % $t == 0);\n($start % $t == 0) ? print $start, \"\\n\" : print -1, \"\\n\";\n\n#print ($start % $t == 0) ? $start : -1;\n"}, {"source_code": "#!/usr/bin/perl -wn\nchomp;\n($n, $t) = split / /;\n#print \"$n-$t\\n\";\n$start = 1 . \"0\" x ($n - 1);\n$end = \"9\" x $n;\n#print \"$start-$end\\n\";\nwhile ($start < $end) {\n !($start % $t) ? last : ($start += 1);\n}\nprint $start, \"\\n\";\n"}, {"source_code": "($n, $_) = split ' ', <>;\nprint /${n}0/ ? -1 : $_ . 0 x ($n - length $n)"}, {"source_code": "$a = {\n zabbix_server_list => ['smoszabbix01'],\n smoszabbix01 => {\n address => '172.16.48.19',\n port => 10051\n },\n daemon => { sleep => 120, maxproc => 20, },\n database_list =>\n [ 'PREPROD', 'INTWH', 'INTTRN', 'PSALE', 'INTPST', 'INTEMR' ],\n default => {\n user => 'zabbix',\n password => 'EvSp9XZM9g',\n query_list_file => '/opt/ZabbixDBA/conf/query.props.pl',\n },\n DISCOVERY => {\n dsn => 'DBI:Oracle:host=smosbd01;port=1521;sid=GDII',\n user => 'tech_prod',\n password => 'dd4rp93d',\n query_list_file => '/opt/ZabbixDBA/intouch/discovery.query.props.pl',\n },\n GDII => {\n dsn => 'DBI:Oracle:host=smosbd01;port=1521;sid=GDII',\n extra_query_list_file => '/opt/ZabbixDBA/intouch/gdii.query.props.pl',\n },\n GDII_STB02 => {\n dsn => 'DBI:Oracle:host=smosbd02;port=1521;sid=GDII_STB02',\n extra_query_list_file =>\n '/opt/ZabbixDBA/intouch/standby.query.props.pl',\n },\n GDII_R0 => {\n dsn => 'DBI:Oracle:host=sdrpbd01;port=1521;sid=GDII_R0',\n extra_query_list_file =>\n '/opt/ZabbixDBA/intouch/standby.query.props.pl',\n },\n PREPROD => { dsn => 'DBI:Oracle:host=smosbd02;port=1522;sid=PREPROD', },\n INTEMR => { dsn => 'DBI:Oracle:host=smosbd06;port=1521;sid=INTEMR', },\n INTWH => { dsn => 'DBI:Oracle:host=smosbd05;port=1523;sid=INTWH', },\n INTPST => { dsn => 'DBI:Oracle:host=smosbd05;port=1522;sid=INTPST', },\n INTTRN => {\n dsn => 'DBI:Oracle:host=smosbd10;port=1521;sid=INTTRN',\n user => 'c##zabbix',\n },\n PSALE => { dsn => 'DBI:Oracle:host=smosbd08;port=1521;sid=XE', },\n};\n"}, {"source_code": "( $n, $t ) = split / /, <>;\nprint -1 if $n < length($t);\n$c = 1 . 0 x ( $n - 1 );\nwhile ( length($c) <= $n ) {\n if ( $c % $t == 0 ) {\n print $c;\n exit;\n }\n $c++;\n}\n\nprint -1;\n"}], "src_uid": "77ffc1e38c32087f98ab5b3cb11cd2ed"} {"nl": {"description": "Let's denote d(n) as the number of divisors of a positive integer n. You are given three integers a, b and c. Your task is to calculate the following sum:Find the sum modulo 1073741824 (230).", "input_spec": "The first line contains three space-separated integers a, b and c (1 ≤ a, b, c ≤ 2000).", "output_spec": "Print a single integer — the required sum modulo 1073741824 (230).", "sample_inputs": ["2 2 2", "4 4 4", "10 10 10"], "sample_outputs": ["20", "328", "11536"], "notes": "NoteFor the first example. d(1·1·1) = d(1) = 1; d(1·1·2) = d(2) = 2; d(1·2·1) = d(2) = 2; d(1·2·2) = d(4) = 3; d(2·1·1) = d(2) = 2; d(2·1·2) = d(4) = 3; d(2·2·1) = d(4) = 3; d(2·2·2) = d(8) = 4. So the result is 1 + 2 + 2 + 3 + 2 + 3 + 3 + 4 = 20."}, "positive_code": [{"source_code": "use strict;\nuse warnings;\nchomp(my ($num1,$num2,$num3) = split \" \",<>);\n\nmy $answer = 0;\nmy %hash = ();\n\nfor(my $i = 1; $i <= $num1; $i++){\n for(my $j = 1; $j <= $num2; $j++){\n for(my $k = 1; $k <= $num3; $k++){\n my $num = $i*$j*$k;\n if(exists $hash{$num}){\n $answer += $hash{$num};\n } else {\n my $divCount = 1;\n my $numbkp = $num;\n for(my $l = 2;$l*$l <= $num; $l++){\n my $factorCount = 0;\n while($num % $l == 0){\n $num /= $l;\n $factorCount++;\n }\n $divCount *= $factorCount + 1;\n }\n if($num > 1){ \n $divCount *= 2;\n }\n $answer += $divCount;\n $hash{$numbkp} = $divCount;\n }\n }\n }\n}\n$answer %= 1073741824;\nprint $answer;"}, {"source_code": "#! /usr/bin/perl -wl\n#------------------------------------------------\n# Author: vj\n# Created: Sun Oct 21 13:04:19 IST 2012\n# File Name: b.pl\n# USAGE:\n# b.pl\n#\n#\n#------------------------------------------------\n \nmy (%pfs, %cnt);\n$pfs{2} = [2];\n$pfs{3} = [3];\n$pfs{4} = [2,2];\n$pfs{5} = [5];\n$pfs{6} = [2,3];\n$pfs{7} = [7];\n$pfs{8} = [2,2,2];\n$pfs{9} = [3,3];\n$pfs{10} = [2,5];\n$pfs{11} = [11];\n$pfs{12} = [2,2,3];\n$pfs{13} = [13];\n$pfs{14} = [2,7];\n$pfs{15} = [3,5];\n$pfs{16} = [2,2,2,2];\n$pfs{17} = [17];\n$pfs{18} = [2,3,3];\n$pfs{19} = [19];\n$pfs{20} = [2,2,5];\n$pfs{21} = [3,7];\n$pfs{22} = [2,11];\n$pfs{23} = [23];\n$pfs{24} = [2,2,2,3];\n$pfs{25} = [5,5];\n$pfs{26} = [2,13];\n$pfs{27} = [3,3,3];\n$pfs{28} = [2,2,7];\n$pfs{29} = [29];\n$pfs{30} = [2,3,5];\n$pfs{31} = [31];\n$pfs{32} = [2,2,2,2,2];\n$pfs{33} = [3,11];\n$pfs{34} = [2,17];\n$pfs{35} = [5,7];\n$pfs{36} = [2,2,3,3];\n$pfs{37} = [37];\n$pfs{38} = [2,19];\n$pfs{39} = [3,13];\n$pfs{40} = [2,2,2,5];\n$pfs{41} = [41];\n$pfs{42} = [2,3,7];\n$pfs{43} = [43];\n$pfs{44} = [2,2,11];\n$pfs{45} = [3,3,5];\n$pfs{46} = [2,23];\n$pfs{47} = [47];\n$pfs{48} = [2,2,2,2,3];\n$pfs{49} = [7,7];\n$pfs{50} = [2,5,5];\n$pfs{51} = [3,17];\n$pfs{52} = [2,2,13];\n$pfs{53} = [53];\n$pfs{54} = [2,3,3,3];\n$pfs{55} = [5,11];\n$pfs{56} = [2,2,2,7];\n$pfs{57} = [3,19];\n$pfs{58} = [2,29];\n$pfs{59} = [59];\n$pfs{60} = [2,2,3,5];\n$pfs{61} = [61];\n$pfs{62} = [2,31];\n$pfs{63} = [3,3,7];\n$pfs{64} = [2,2,2,2,2,2];\n$pfs{65} = [5,13];\n$pfs{66} = [2,3,11];\n$pfs{67} = [67];\n$pfs{68} = [2,2,17];\n$pfs{69} = [3,23];\n$pfs{70} = [2,5,7];\n$pfs{71} = [71];\n$pfs{72} = [2,2,2,3,3];\n$pfs{73} = [73];\n$pfs{74} = [2,37];\n$pfs{75} = [3,5,5];\n$pfs{76} = [2,2,19];\n$pfs{77} = [7,11];\n$pfs{78} = [2,3,13];\n$pfs{79} = [79];\n$pfs{80} = [2,2,2,2,5];\n$pfs{81} = [3,3,3,3];\n$pfs{82} = [2,41];\n$pfs{83} = [83];\n$pfs{84} = [2,2,3,7];\n$pfs{85} = [5,17];\n$pfs{86} = [2,43];\n$pfs{87} = [3,29];\n$pfs{88} = [2,2,2,11];\n$pfs{89} = [89];\n$pfs{90} = [2,3,3,5];\n$pfs{91} = [7,13];\n$pfs{92} = [2,2,23];\n$pfs{93} = [3,31];\n$pfs{94} = [2,47];\n$pfs{95} = [5,19];\n$pfs{96} = [2,2,2,2,2,3];\n$pfs{97} = [97];\n$pfs{98} = [2,7,7];\n$pfs{99} = [3,3,11];\n$pfs{100} = [2,2,5,5];\n\nsub printnewpfs { print \"$_ -> $cnt{$_}\" foreach (sort {$a <=> $b} keys %cnt) }\n\nsub div () {\n my ($x, $y, $z) = @_;\n \n my $product = $x * $y * $z;\n if (not exists $cnt{$product}) {\n my %allpfs;\n $allpfs{$_}++ foreach ( @{$pfs{$x}}, @{$pfs{$y}}, @{$pfs{$z}} );\n $cnt{$product} = 1;\n $cnt{$product} *= $_ + 1 foreach values %allpfs;\n }\n\n return $cnt{$product};\n}\n\nmy ($x, $y, $z, $buf);\nchomp ($buf = );\n($x, $y, $z) = split /\\s+/, $buf;\n\nmy $res = 0;\nforeach my $i (1 .. $x) {\n foreach my $j (1 .. $y) {\n foreach my $k (1 .. $z) {\n $res += &div ($i, $j, $k);\n }\n }\n}\nprint $res;\n#&printnewpfs;\n"}], "negative_code": [{"source_code": "use strict;\nuse warnings;\nuse POSIX;\nchomp(my @array = split \" \",<>);\n\nmy $answer = 0;\n\nfor(my $i = 1; $i <= $array[0]; $i++){\n for(my $j = 1; $j <= $array[1]; $j++){\n for(my $k = 1; $k <= $array[2]; $k++){\n my $num = $i*$j*$k;\n my $divCount = 1;\n for(my $l = 2;$l*$l <= $num; $l++){\n my $factorCount = 0;\n if($num % $l == 0){\n $num /= $l;\n $factorCount++;\n }\n $divCount *= $factorCount + 1;\n }\n if($num > 1){ \n $divCount *= 2;\n }\n $answer += $divCount;\n if($answer > 1073741824) {\n $answer %= 1073741824;\n }\n }\n }\n}\n\nprint $answer;"}, {"source_code": "use strict;\nuse warnings;\nuse POSIX;\nchomp(my @array = split \" \",<>);\n\nmy $answer = 0;\n\nfor(my $i = 1; $i <= $array[0]; $i++){\n for(my $j = 1; $j <= $array[1]; $j++){\n for(my $k = 1; $k <= $array[2]; $k++){\n my $num = $i*$j*$k;\n my $divCount = 1;\n for(my $l = 2;$l*$l <= $num; $l++){\n my $factorCount = 0;\n if($num % $l == 0){\n $num /= $l;\n $factorCount++;\n }\n $divCount *= ($factorCount + 1);\n }\n if($num > 1){ \n $divCount *= 2;\n }\n $answer += $divCount;\n if($answer > 1073741824) {\n $answer %= 1073741824;\n }\n }\n }\n}\n\nprint $answer;"}, {"source_code": "use strict;\nuse warnings;\nchomp(my ($num1,$num2,$num3) = split \" \",<>);\n\nmy $answer = 0;\nmy %hash = ();\n\nfor(my $i = 1; $i <= $num1; $i++){\n for(my $j = 1; $j <= $num2; $j++){\n for(my $k = 1; $k <= $num3; $k++){\n my $num = $i*$j*$k;\n if(exists $hash{$num}){\n $answer += $hash{$num};\n } else {\n my $divCount = 1;\n for(my $l = 2;$l*$l <= $num; $l++){\n my $factorCount = 0;\n while($num % $l == 0){\n $num /= $l;\n $factorCount++;\n }\n $divCount *= $factorCount + 1;\n }\n if($num > 1){ \n $divCount *= 2;\n }\n $answer += $divCount;\n $hash{$num} = $divCount;\n }\n }\n }\n}\n$answer %= 1073741824;\nprint $answer;"}], "src_uid": "4fdd4027dd9cd688fcc70e1076c9b401"} {"nl": {"description": "There is a card game called \"Durak\", which means \"Fool\" in Russian. The game is quite popular in the countries that used to form USSR. The problem does not state all the game's rules explicitly — you can find them later yourselves if you want.To play durak you need a pack of 36 cards. Each card has a suit (\"S\", \"H\", \"D\" and \"C\") and a rank (in the increasing order \"6\", \"7\", \"8\", \"9\", \"T\", \"J\", \"Q\", \"K\" and \"A\"). At the beginning of the game one suit is arbitrarily chosen as trump. The players move like that: one player puts one or several of his cards on the table and the other one should beat each of them with his cards.A card beats another one if both cards have similar suits and the first card has a higher rank then the second one. Besides, a trump card can beat any non-trump card whatever the cards’ ranks are. In all other cases you can not beat the second card with the first one.You are given the trump suit and two different cards. Determine whether the first one beats the second one or not.", "input_spec": "The first line contains the tramp suit. It is \"S\", \"H\", \"D\" or \"C\". The second line contains the description of the two different cards. Each card is described by one word consisting of two symbols. The first symbol stands for the rank (\"6\", \"7\", \"8\", \"9\", \"T\", \"J\", \"Q\", \"K\" and \"A\"), and the second one stands for the suit (\"S\", \"H\", \"D\" and \"C\").", "output_spec": "Print \"YES\" (without the quotes) if the first cards beats the second one. Otherwise, print \"NO\" (also without the quotes).", "sample_inputs": ["H\nQH 9S", "S\n8D 6D", "C\n7H AS"], "sample_outputs": ["YES", "YES", "NO"], "notes": null}, "positive_code": [{"source_code": "$suit=<>;\n$p1=<>;\n@a1=split('',$p1);\n@a2=split('',$suit);\n%h=(\"6\"=>1, \"7\"=>2, \"8\"=>3, \"9\"=>4, \"T\"=>5, \"J\"=>6, \"Q\"=>7, \"K\"=>8,\"A\"=>9);\nif(@a1[1] eq @a1[4])\n{\n if($h{@a1[0]} gt $h{@a1[3]}){ print \"YES\";}\n else {print \"NO\";}\n}\nelse {\n if(@a1[1] eq @a2[0] )\n { print \"YES\";}\n else {print \"NO\";}\n}"}, {"source_code": "$suit=<>;\n$p1=<>;\nchomp($suit);\n@a1=split('',$p1);\n%h=(\"6\"=>1, \"7\"=>2, \"8\"=>3, \"9\"=>4, \"T\"=>5, \"J\"=>6, \"Q\"=>7, \"K\"=>8,\"A\"=>9);\nif(@a1[1] eq @a1[4])\n{\n\tif($h{@a1[0]}>$h{@a1[3]}){ print \"YES\";}\n\telse {print \"NO\";}\n}\nelse {\n\tif(@a1[1] eq $suit){ print \"YES\";}\n\telse {print \"NO\";}\n}"}], "negative_code": [{"source_code": "$suit=<>;\n$p1=<>;\n@a1=split('',$p1);\n@a2=split('',$suit);\n%h=(\"6\"=>1, \"7\"=>2, \"8\"=>3, \"9\"=>4, \"T\"=>5, \"J\"=>6, \"Q\"=>7, \"K\"=>8,\"A\"=>9);\nif((@a1[1] eq @a2[0]) and( @a1[4] eq @a2[0]))\n{\n if($h{@a1[0]} gt $h{@a1[3]}){ print \"YES\";}\n else {print \"NO\";}\n}\nelse {\n if(@a2[0] eq @a1[4]){\n print \"NO\";\n exit;\n }\n if((@a1[1] eq @a2[0])or($h{@a1[0]} gt $h{@a1[3]}))\n { print \"YES\";}\n else {print \"NO\";}\n}"}, {"source_code": "$suit=<>;\n$p1=<>;\n@a1=split('',$p1);\n%h=(\"6\"=>1, \"7\"=>2, \"8\"=>3, \"9\"=>4, \"T\"=>5, \"J\"=>6, \"Q\"=>7, \"K\"=>8,\"A\"=>9);\nif(@a1[1] == $suit and @a1[4] == $suit)\n{\n\tif($h{@a1[0]}>$h{@a1[3]}){ print \"YES\";}\n\telse {print \"NO\";}\n}\nelse {\n\tif((@a1[1] == $suit)or($h{@a1[0]}>$h{@a1[3]})){ print \"YES\";}\n\telse {print \"NO\";}\n}"}, {"source_code": "$suit=<>;\n$p1=<>;\n$p2=<>;\n@a1=split('',$p1);\n@a2=split('',$p2);\n%h=(\"6\"=>1, \"7\"=>2, \"8\"=>3, \"9\"=>4, \"T\"=>5, \"J\"=>6, \"Q\"=>7, \"K\"=>8,\"A\"=>9);\nif(@a1[1] == $suit and @a2[1] == $suit)\n{\n\tif($h{@a1[0]}>$h{@a2[0]}){ print \"YES\";}\n\telse {print \"NO\";}\n}\nelse {\n\tif((@a1[1] == $suit)or($h{@a1[0]}>$h{@a2[0]})){ print \"YES\";}\n\telse {print \"NO\";}\n}\n\n"}, {"source_code": "$suit=<>;\n$p1=<>;\n@a1=split('',$p1);\n@a2=split('',$suit);\n%h=(\"6\"=>1, \"7\"=>2, \"8\"=>3, \"9\"=>4, \"T\"=>5, \"J\"=>6, \"Q\"=>7, \"K\"=>8,\"A\"=>9);\nif((@a1[1] eq @a2[0]) and( @a1[4] eq @a2[0]))\n{\n if($h{@a1[0]} gt $h{@a1[3]}){ print \"YES\";}\n else {print \"NoO\";}\n}\nelse {\n if(@a2[0] eq @a1[4]){\n print \"NO\";\n exit;\n }\n if((@a1[1] eq @a2[0])or($h{@a1[0]} gt $h{@a1[3]}))\n { print \"YES\";}\n else {print \"NO\";}\n}"}], "src_uid": "da13bd5a335c7f81c5a963b030655c26"} {"nl": {"description": "You have two friends. You want to present each of them several positive integers. You want to present cnt1 numbers to the first friend and cnt2 numbers to the second friend. Moreover, you want all presented numbers to be distinct, that also means that no number should be presented to both friends.In addition, the first friend does not like the numbers that are divisible without remainder by prime number x. The second one does not like the numbers that are divisible without remainder by prime number y. Of course, you're not going to present your friends numbers they don't like.Your task is to find such minimum number v, that you can form presents using numbers from a set 1, 2, ..., v. Of course you may choose not to present some numbers at all.A positive integer number greater than 1 is called prime if it has no positive divisors other than 1 and itself.", "input_spec": "The only line contains four positive integers cnt1, cnt2, x, y (1 ≤ cnt1, cnt2 < 109; cnt1 + cnt2 ≤ 109; 2 ≤ x < y ≤ 3·104) — the numbers that are described in the statement. It is guaranteed that numbers x, y are prime.", "output_spec": "Print a single integer — the answer to the problem.", "sample_inputs": ["3 1 2 3", "1 3 2 3"], "sample_outputs": ["5", "4"], "notes": "NoteIn the first sample you give the set of numbers {1, 3, 5} to the first friend and the set of numbers {2} to the second friend. Note that if you give set {1, 3, 5} to the first friend, then we cannot give any of the numbers 1, 3, 5 to the second friend. In the second sample you give the set of numbers {3} to the first friend, and the set of numbers {1, 2, 4} to the second friend. Thus, the answer to the problem is 4."}, "positive_code": [{"source_code": "use strict;\nuse warnings;\n\nmy ($cnt1, $cnt2, $x, $y) = split(' ', <>);\nmy $low = 1; my $high = 1 << 31; my $mid; my $ans = $high;\nmy ($tt, $ff, $ft, $tf, $t1, $t2);\n\nfor(0..60){\n\t$mid = int($low + $high) >> 1;\n\t\n\t$tt = int($mid / ($x * $y));\n\t$tf = int($mid / $x) - $tt;\n\t$ft = int($mid / $y) - $tt;\n\t$ff = $mid - $ft - $tt - $tf;\n\t\n\t$t1 = $cnt1;\n\t$t2 = $cnt2;\n\t\n\tif($ft >= $t1){\t$ft -= $t1; $t1 = 0;}\n\telse{$t1 -= $ft; $ft = 0;}\n\t\n\tif($tf >= $t2){\t$tf -= $t2; $t2 = 0;}\n\telse{$t2 -= $tf; $tf = 0;}\n\t\n\t\n\tif($t1 + $t2 <= $ff){\n\t\t$ans = $ans > $mid ? $mid : $ans;\n\t\t$high = $mid;\n\t}\n\telse{\n\t\t$low = $mid + 1;\n}\n}\n\nprint $ans;\n"}], "negative_code": [{"source_code": "use strict;\nuse warnings;\n\nmy ($cnt1, $cnt2, $x, $y) = split(' ', <>);\nmy $low = 1; my $high = 1 << 31; my $mid; my $ans = $high;\n\nfor(0..60){\n\t$mid = ($low + $high) >> 1;\n\t\n\tmy $c = int($mid / ($x * $y));\n\t\n\tif($mid - $c >= $cnt1 + $cnt2){\n\t\t$ans = $ans > $mid ? $mid : $ans;\n\t\t$high = $mid;\n\t}\n\telse{\n\t\t$low = $mid + 1;\n\t}\n}\n\nprint $ans;\n"}], "src_uid": "ff3c39b759a049580a6e96c66c904fdc"} {"nl": {"description": "Vasya has recently learned to type and log on to the Internet. He immediately entered a chat room and decided to say hello to everybody. Vasya typed the word s. It is considered that Vasya managed to say hello if several letters can be deleted from the typed word so that it resulted in the word \"hello\". For example, if Vasya types the word \"ahhellllloou\", it will be considered that he said hello, and if he types \"hlelo\", it will be considered that Vasya got misunderstood and he didn't manage to say hello. Determine whether Vasya managed to say hello by the given word s.", "input_spec": "The first and only line contains the word s, which Vasya typed. This word consisits of small Latin letters, its length is no less that 1 and no more than 100 letters.", "output_spec": "If Vasya managed to say hello, print \"YES\", otherwise print \"NO\".", "sample_inputs": ["ahhellllloou", "hlelo"], "sample_outputs": ["YES", "NO"], "notes": null}, "positive_code": [{"source_code": "my $str = <>;\nprint (($str =~ /.*h.*e.*l.*l.*o.*/g) ? (\"YES\"):(\"NO\"));"}, {"source_code": "my $str = <>;\nprint (($str =~ /.*h.*e.*l.*l.*o.*/) ? (\"YES\"):(\"NO\"));"}, {"source_code": "print <>=~/h.*e.*l.*l.*o/ ? \"YES\" : \"NO\""}, {"source_code": "#!/usr/bin/perl -w\n\nchomp($_ = );\nif(/.*h.*e.*l.*l.*o.*/) {\n print \"YES\";\n} else {\n print \"NO\";\n}"}, {"source_code": "\n\nprint <>=~/h.*e.*l.*l.*o/?\"YES\":\"NO\""}, {"source_code": "print<>=~/h.*e.*l.*l.*o/?YES:NO\n"}, {"source_code": "print <>=~/h.*e.*l.*l.*o/?\"YES\":\"NO\""}, {"source_code": "print<>=~/h.*e.*l.*l.*o/?YES:NO"}, {"source_code": "#!/usr/bin/env perl\n\nuse v5.012;\nuse warnings;\n\nmy $word = ;\n\nif ($word =~ /h.*e.*l.*l.*o/) {\n\tprint 'YES';\n}\nelse {\n\tprint 'NO';\n}\n"}, {"source_code": "print<>=~/h.*e.*l.*l.*o/?YES:NO\n"}, {"source_code": "chomp($_ = );\n/.*?h.*?e.*?l.*?l.*?o/ ? print \"YES\\n\" : print \"NO\\n\";"}, {"source_code": "my @arr = split \"\", <>;\nmy @str = split \"\", \"hello\";\nmy ($l, $end) = (scalar @arr, scalar @str);\nmy $count = 0;\nfor (0..$l-1) {\n $count++ if ($arr[$_] eq $str[$count]);\n last if ($count == $end);\n}\nprint $count == $end ? \"YES\\n\":\"NO\\n\";\n"}, {"source_code": "print <>=~/h.*e.*l.*l.*o/?\"YES\":\"NO\""}, {"source_code": "print <>=~/h.*e.*l.*l.*o/?YES:NO"}, {"source_code": "print<>=~/h.*e.*l.*l.*o/?YES:NO\n"}, {"source_code": "$l=<>;\nif($l=~/.*h.*e.*l.*l.*o.*/g)\n{\n print \"YES\";\n}\nelse\n{\n print \"NO\";\n}"}, {"source_code": "print<>=~/h.*e.*l.*l.*o/?YES:NO\n"}, {"source_code": "print<>=~/h.*e.*l.*l.*o/?YES:NO"}, {"source_code": "#!/usr/bin/perl\n# your code goes here\nuse v5.10;\n\n<> =~ m/h\\w*e\\w*l\\w*l\\w*o/ and say \"YES\" or say \"NO\";"}, {"source_code": "#!/usr/bin/perl -w\n\nuse strict;\nuse Data::Dumper;\n\nsub look_for {\n my $search = shift;\n my $buf = shift;\n\n my $i1 = 0;\n\n for (split //, $buf) {\n $i1++ if (substr $search, $i1, 1) eq $_;\n last if $i1 >= length $search;\n }\n\n return $i1 == length $search;\n}\n\nmy $s = <>;\nprint look_for(\"hello\", $s) ? \"YES\\n\" : \"NO\\n\";\n"}, {"source_code": "print<>=~/h.*e.*l.*l.*o/?YES:NO"}, {"source_code": "print<>=~/h.*e.*l.*l.*o/?\"YES\":\"NO\""}, {"source_code": "print<>=~/.*h.*e.*l.*l.*o.*/?\"YES\":\"NO\""}, {"source_code": "print<>=~/h.*e.*l.*l.*o/?YES:NO"}, {"source_code": "print<>=~/h.*e.*l.*l.*o/?YES:NO"}, {"source_code": "my $s = <>;\nprint ($s =~ /h.*?e.*?l.*?l.*?o/ ? \"YES\" : \"NO\")"}, {"source_code": "#!/usr/bin/perl\n\n$str = ;\n\n#$char = substr($str, 1, 1);\n\n$ln = length $str;\n#print \"$ln\";\n\n$ln = $ln - 2;\n\n$n = 0;\n$cnt = 1;\n\nfor($i = 0; $i<=$ln; $i++){\n $char = substr($str,$n, 1);\n\n if($cnt == 1){\n if($char eq 'h'){\n $cnt = $cnt + 1;\n }\n }\n elsif($cnt == 2){\n if($char eq 'e'){\n $cnt = $cnt + 1;\n }\n } \n elsif($cnt == 3){\n if($char eq 'l'){\n $cnt = $cnt + 1;\n }\n }\n elsif($cnt == 4){\n if($char eq 'l'){\n $cnt = $cnt + 1;\n }\n }\n elsif($cnt == 5){\n if($char eq 'o'){\n $cnt = $cnt + 1;\n }\n }\n\n # print \"$char\\n\";\n # print \"$cnt\\n\";\n $n = $n + 1;\n}\n\nif($cnt == 6){\n print \"YES\\n\";\n}\nelse {\n print \"NO\\n\";\n}\n"}, {"source_code": "#!/usr/bin/perl\n\n#input string\n$str = ;\n\n#find length in a string\n$ln = length $str;\n\n$ln = $ln - 2;\n\n$cnt = 1;\n\nfor($i = 0; $i<=$ln; $i++){\n #find the i'th character\n $char = substr($str,$i, 1);\n\n if($cnt == 1){\n if($char eq 'h'){\n $cnt = $cnt + 1;\n }\n }\n elsif($cnt == 2){\n if($char eq 'e'){\n $cnt = $cnt + 1;\n }\n } \n elsif($cnt == 3){\n if($char eq 'l'){\n $cnt = $cnt + 1;\n }\n }\n elsif($cnt == 4){\n if($char eq 'l'){\n $cnt = $cnt + 1;\n }\n }\n elsif($cnt == 5){\n if($char eq 'o'){\n $cnt = $cnt + 1;\n }\n }\n}\n\nif($cnt == 6){\n print \"YES\\n\";\n}\nelse {\n print \"NO\\n\";\n}\n"}, {"source_code": "use strict;\nuse warnings;\n\nprint <> =~ /.*?h.*?e.*?l.*?l.*?o.*?/ ? \"YES\\n\" : \"NO\\n\";\n"}, {"source_code": "use strict;\nuse warnings;\n\nmy $s = <>;\nchomp $s;\nprint $s =~ /.*?h.*?e.*?l.*?l.*?o.*?/ ? \"YES\\n\" : \"NO\\n\";\n"}, {"source_code": "$ch=<>;\nchomp$ch;\nif($ch=~m/h+.*e+.*l+.*l+.*o+/){\nprint\"YES\";\n}\nelse{\nprint\"NO\";\n}"}, {"source_code": "print<>=~/h.*e.*l.*l.*o/?YES:NO\n"}, {"source_code": "print<>=~/h.*e.*l.*l.*o/?YES:NO"}, {"source_code": "print<>=~/h.*e.*l.*l.*o/?YES:NO\n"}, {"source_code": "$_ = ; print (/h.*e.*l.*l.*o/? \"YES\\n\" : \"NO\\n\")\n"}, {"source_code": "print<>=~/h.*e.*l.*l.*o/?YES:NO"}, {"source_code": "print<>=~/h.*e.*l.*l.*o/? YES : NO"}, {"source_code": "print<>=~/h.*e.*l.*l.*o/?YES:NO"}, {"source_code": "#!/bin/bash/perl\n$input=<>;\n$len=length($input);\n$len=$len-1;\nif($len<5){\n print \"NO\";\n}\nelse{\n $state=0;\n @seperate=split(\"\",$input);\n @helloSearch=('h','e','l','l','o');\n for($i=0;$i<$len;++$i){\n if($state>4){\n $i=$len; #to break off\n }\n else{\n if($seperate[$i] eq $helloSearch[$state]){\n ++$state;\n }\n }\n }\n if($state>4){\n print \"YES\";\n }\n else{\n print \"NO\";\n }\n}"}, {"source_code": "print(<>=~/h.*e.*l.*l.*o.*/?'YES':'NO')"}, {"source_code": "print <>=~/h.*e.*l.*l.*o/?\"YES\":\"NO\""}, {"source_code": "#!/bin/perl\n\n$s = ;\nchomp $s;\n\n@lts = split //, $s;\n\n@srch = (h, e, l, l, o);\n$wsk = 0;\n\nfor($i=0;$i<@lts;$i++)\n{\n\n if( @lts[$i] eq @srch[$wsk] )\n {\n\n $wsk++;\n\n if( $wsk >= @srch )\n {\n\n print \"YES\";\n exit;\n\n }\n\n }\n\n}\n\nprint \"NO\";\n"}, {"source_code": "print<>=~/h.*e.*l.*l.*o/?YES:NO\n"}, {"source_code": "print<>=~/h.*e.*l.*l.*o/?YES:NO\n"}, {"source_code": "$str =;\n$_ = $str;\nif(/.*h.*e.*l.*l.*o/)\n{\n\tprint (\"YES\");\n}\n\nelse\n{\nprint(\"NO\");\n}\n"}, {"source_code": "@a=(\"h\",\"e\",\"l\",\"l\",\"o\");$c=0;foreach(split('',<>)){if($_ eq $a[$c]){$c+=1;}if($c==5){break;}}if($c==5){print \"YES\\n\";}else{print \"NO\\n\";}\n"}, {"source_code": "$s=<>;\n$s=~s/\\R//g;\n@ar=(\"h\",\"e\",\"l\",\"l\",\"o\");\n$c=0;\nforeach(split('',$s))\n{\nif($_ eq $ar[$c]){$c+=1;}\nif($c==5){break;}\n}\nif($c==5){print \"YES\\n\";}\nelse{print \"NO\\n\";}\n"}, {"source_code": "#!/usr/bin/perl\nuse strict;\nuse warnings;\nuse v5.10;\nuse POSIX;\n\nsay =~ /h.*e.*l.*l.*o/ ? 'YES' : 'NO'\n"}, {"source_code": "print <> =~ /h.*?e.*?l.*?l.*?o/ ? \"YES\" : \"NO\";"}, {"source_code": "print<>=~/h.*e.*l.*l.*o/?YES:NO\n"}], "negative_code": [{"source_code": "my $s = <>;\nprint ($s =~ /.?h.?e.?l.?l.?o.?/ ? \"YES\" : \"NO\")"}, {"source_code": "my $s = <>;\nprint ($s =~ /.?h.?e.?l.?l.?o.?/ ? \"Yes\" : \"No\")"}, {"source_code": "$ch=<>;\nchomp$ch;\nif($ch=~m/(h+e+l{2,}o+)/){\nprint\"YES\";\n}\nelse{\nprint\"NO\";\n}"}, {"source_code": "$_ = ; print (/h.*e.*l.*l.*o.*o.*u/? \"YES\\n\" : \"NO\\n\")"}, {"source_code": "#!/bin/perl\n\n$s = ;\nchomp $s;\n\n$n = length $s;\n\n$s =~ s/[h][h]*[e][e]*[l][l]*[l][l]*[o][o]/0/;\n\nif( $n == length $s )\n{\n\n print \"NO\";\n\n}\nelse\n{\n\n print \"YES\";\n\n}\n"}, {"source_code": "print <> =~ /h+e+l+l+o/ ? \"YES\" : \"NO\";"}], "src_uid": "c5d19dc8f2478ee8d9cba8cc2e4cd838"} {"nl": {"description": "«One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine.However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and she was fighting them off. Every k-th dragon got punched in the face with a frying pan. Every l-th dragon got his tail shut into the balcony door. Every m-th dragon got his paws trampled with sharp heels. Finally, she threatened every n-th dragon to call her mom, and he withdrew in panic.How many imaginary dragons suffered moral or physical damage tonight, if the princess counted a total of d dragons?", "input_spec": "Input data contains integer numbers k, l, m, n and d, each number in a separate line (1 ≤ k, l, m, n ≤ 10, 1 ≤ d ≤ 105).", "output_spec": "Output the number of damaged dragons.", "sample_inputs": ["1\n2\n3\n4\n12", "2\n3\n4\n5\n24"], "sample_outputs": ["12", "17"], "notes": "NoteIn the first case every first dragon got punched with a frying pan. Some of the dragons suffered from other reasons as well, but the pan alone would be enough.In the second case dragons 1, 7, 11, 13, 17, 19 and 23 escaped unharmed."}, "positive_code": [{"source_code": "#!/usr/bin/perl\n\nuse 5.012;\nuse warnings;\n\nchomp(my $k = <>);\nchomp(my $l = <>);\nchomp(my $m = <>);\nchomp(my $n = <>);\nchomp(my $d = <>);\n\nmy $cnt = 0;\nfor my $idx (1..$d) {\n\t$cnt++ unless $idx % $k && $idx % $l && $idx % $m && $idx % $n;\n}\nsay $cnt;\n"}, {"source_code": "my @arr;\n$arr[$_] = <> for(0..3);\nmy $d = <>;\nmy @count = (0) x int($d);\nmy $ans = 0;\nfor my $i (0..3) {\n $count[$_ * $arr[$i]] = 1 for(0..int($d/$arr[$i]));\n}\n$ans += $count[$_] for(1..$d);\nprint $ans;\n"}, {"source_code": "my $k = ;\nmy $l = ;\nmy $m = ;\nmy $n = ;\nmy $d = ;\nmy $count = 0;\nwhile($d) {\n if(!($d%$k)||!($d%$l)||!($d%$m)||!($d%$n)) {\n $count++;\n }\n $d--;\n}\nprint $count;"}, {"source_code": "#!/usr/bin/perl\n# your code goes here\n\nour @a = (0) x (10**5+5);\nour $d;\n\nsub update {\n\t$k = shift;\n\tfor (my $i=$k; $i<=$d; $i+=$k) {\n\t\t$a[$i] = 1;\n\t}\n}\n\nchomp($k = <>);\nchomp($l = <>);\nchomp($m = <>);\nchomp($n = <>);\nchomp($d = <>);\n\nupdate($k);\nupdate($l);\nupdate($m);\nupdate($n);\n\n$ans+=$_ foreach (@a);\nprint $ans;\n"}, {"source_code": "#!/usr/bin/perl -w\n\nuse strict;\n\nmy $k = <>;\nmy $l = <>;\nmy $m = <>;\nmy $n = <>;\nmy $d = <>;\nmy $h = 0;\nfor (1..$d) {\n $h++ unless $_ % $k && $_ % $l && $_ % $m && $_ % $n\n}\nprint $h, \"\\n\";\n"}, {"source_code": "chomp($k=);\nchomp($l=);\nchomp($m=);\nchomp($n=);\nchomp($d=);\n\n$hurt = 0;\nfor($i=1;$i<=$d;$i++){\n\t$hurt++, next if($i % $k == 0);\n\t$hurt++, next if($i % $l == 0);\n\t$hurt++, next if($i % $m == 0);\n\t$hurt++, next if($i % $n == 0);\n}\nprint \"$hurt\\n\";"}, {"source_code": "use strict;\nuse warnings;\n\nmy ($k, $l, $m, $n, $d) = <>;\nmy $cnt = 0;\nfor (1..$d) {\n if ($_ % $k && $_ % $l && $_ % $m && $_ % $n) {\n $cnt++;\n }\n}\nprint (($d - $cnt).\"\\n\");\n"}, {"source_code": "$k=<>;\n$l=<>;\n$m=<>;\n$n=<>;\n$d=<>;\nfor($i=1;$i<=$d;$i++){\n$t[$i]=0;\n}\nfor($i=$k;$i<=$d;$i+=$k){\n$t[$i]=1;\n}\nfor($i=$l;$i<=$d;$i+=$l){\n$t[$i]=1;\n}\nfor($i=$m;$i<=$d;$i+=$m){\n$t[$i]=1;\n}\nfor($i=$n;$i<=$d;$i+=$n){\n$t[$i]=1;\n}\n$somme=0;\nfor($i=1;$i<=$d;$i++){\nif($t[$i]){\n$somme++;\n}\n}\nprint $somme;\n\n\n"}, {"source_code": "while(){chomp;push @_,$_}; my $n = pop @_; @_=sort @_; if(@_[0] == 1){ print \"$n\\n\"; exit } my @arr = map{1}(1..$n);my $len = int($n); for(@_){ my $k = int($_); for(1..@arr){ if($arr[$_-1] && $_ % $k == 0){ --$len; $arr[$_-1]=0 } } unless($len){ print \"$n\\n\"; exit } } print $n-$len, \"\\n\""}, {"source_code": "#!/bin/bash/perl\n$input = <>;\n@input = split(\" \",$input);\nmy $a = $input[0];\n$input = <>;\n@input = split(\" \",$input);\nmy $b = $input[0];\n$input = <>;\n@input = split(\" \",$input);\nmy $c = $input[0];\n$input = <>;\n@input = split(\" \",$input);\nmy $d = $input[0];\n$input = <>;\n@input = split(\" \",$input);\nmy $t = $input[0];\n@flags = (0 x ($t+1));\n@params = ($a,$b,$c,$d);\nfor(my $i=0;$i<4;++$i){\n for(my $j=1;$j<=$t;++$j){\n if($flags[$j]==0 && $j%$params[$i]==0 ){\n $flags[$j]=1;\n }\n }\n}\nmy $hit = 0;\nfor(my $i=1;$i<=$t;++$i){\n if($flags[$i] == 1){\n ++$hit;\n }\n}\nprint $hit;"}, {"source_code": "($k, $l, $m, $n, $d) = (<>, <>, <>, <>, <>);\n$ans = 0;\nfor ($i = 1; $i <= $d; ++$i) {\n unless ($i % $k and $i % $l and $i % $m and $i % $n) {\n ++$ans;\n }\n}\nprint $ans;"}, {"source_code": "$k=<>;\n$l=<>;\n$m=<>;\n$n=<>;\n$d=<>;\n$a=0;\nfor $j($k,$l,$m,$n){\nfor (1..$d){\n$_%$j or $_[$_]++;\n}\n}\nfor (1..$d){\n$_[$_] and $a++\n\n}\nprint $a;"}, {"source_code": "$k=<>;$l=<>;$m=<>;$n=<>;$d=<>;$a=0;\nfor$i(1..$d){if($i% $k==0 or $i% $l==0 or $i% $m==0 or $i% $n==0){$a+=1;}}\nprint \"$a\\n\";\n\n"}], "negative_code": [{"source_code": "my $k = ;\nmy $l = ;\nmy $m = ;\nmy $n = ;\nmy $d = ;\nmy $count = 0;\nwhile($d--) {\n if(!($d%$k)||!($d%$l)||!($d%$m)||!($d%$n)) {\n $count++;\n }\n}\nprint $count;"}, {"source_code": "$k=<>;\n$l=<>;\n$m=<>;\n$n=<>;\n$d=<>;\n\nfor $j($k,$l,$m,$n){\nfor (1..$d){\n$_%$j or $_[$_]++;\n}\n}\nfor (1..$d){\n$_[$_] and $a++\n\n}\nprint $a;"}], "src_uid": "46bfdec9bfc1e91bd2f5022f3d3c8ce7"} {"nl": {"description": "Barney is standing in a bar and starring at a pretty girl. He wants to shoot her with his heart arrow but he needs to know the distance between him and the girl to make his shot accurate. Barney asked the bar tender Carl about this distance value, but Carl was so busy talking to the customers so he wrote the distance value (it's a real number) on a napkin. The problem is that he wrote it in scientific notation. The scientific notation of some real number x is the notation of form AeB, where A is a real number and B is an integer and x = A × 10B is true. In our case A is between 0 and 9 and B is non-negative.Barney doesn't know anything about scientific notation (as well as anything scientific at all). So he asked you to tell him the distance value in usual decimal representation with minimal number of digits after the decimal point (and no decimal point if it is an integer). See the output format for better understanding.", "input_spec": "The first and only line of input contains a single string of form a.deb where a, d and b are integers and e is usual character 'e' (0 ≤ a ≤ 9, 0 ≤ d < 10100, 0 ≤ b ≤ 100) — the scientific notation of the desired distance value. a and b contain no leading zeros and d contains no trailing zeros (but may be equal to 0). Also, b can not be non-zero if a is zero.", "output_spec": "Print the only real number x (the desired distance value) in the only line in its decimal notation. Thus if x is an integer, print it's integer value without decimal part and decimal point and without leading zeroes. Otherwise print x in a form of p.q such that p is an integer that have no leading zeroes (but may be equal to zero), and q is an integer that have no trailing zeroes (and may not be equal to zero).", "sample_inputs": ["8.549e2", "8.549e3", "0.33e0"], "sample_outputs": ["854.9", "8549", "0.33"], "notes": null}, "positive_code": [{"source_code": "$_ = <>; ($a, $d, $b) = split /\\.|e/;\n$d .= \"0\" x ($b - length $d);\n$_ = join(\"\", $a, substr($d, 0, $b), \".\", substr($d, $b));\ns/\\.0*$//; \nprint\n"}, {"source_code": "s/e(.*)/0 x 1e2/e,\ns/\\.(.{$1})/$1./,\ns/^0+\\B|\\.?0+$//g,\nprint for <>"}, {"source_code": "#!/usr/bin/perl\n\n$_ = <>, chomp;\n/e\\K/;\n$e = $';\ns/e.*//;\n$_ .= 0 x 111;\ns/\\.(.{$e})/$1./;\ns/0+$//;\ns/^0+//;\ns/\\.$//;\ns/^\\./0./;\n$_ ||= 0;\nprint"}], "negative_code": [{"source_code": "$_ = <>; ($a, $d, $b) = split /\\.|e/;\n$b .= \"0\" x ($b - length $d);\n$_ = join(\"\", $a, substr($d, 0, $b), \".\", substr($d, $b));\ns/\\.$//; \nprint\n"}, {"source_code": "$_ = <>; ($a, $d, $b) = split /\\.|e/;\n$d .= \"0\" x ($b - length $d);\n$_ = join(\"\", $a, substr($d, 0, $b), \".\", substr($d, $b));\ns/\\.$//; \nprint\n"}, {"source_code": "$_ = <>, chomp;\n/e\\K/;\n$e = $';\ns/e.*//;\n$_ .= 0 x 111;\ns/\\.(.{$e})/$1./;\ns/0+$//;\ns/^0+//;\ns/\\.$//;\n$_ ||= 0;\nprint"}], "src_uid": "a79358099f08f3ec50c013d47d910eef"} {"nl": {"description": " — Thanks a lot for today.— I experienced so many great things.— You gave me memories like dreams... But I have to leave now...— One last request, can you...— Help me solve a Codeforces problem?— ......— What?Chtholly has been thinking about a problem for days:If a number is palindrome and length of its decimal representation without leading zeros is even, we call it a zcy number. A number is palindrome means when written in decimal representation, it contains no leading zeros and reads the same forwards and backwards. For example 12321 and 1221 are palindromes and 123 and 12451 are not. Moreover, 1221 is zcy number and 12321 is not.Given integers k and p, calculate the sum of the k smallest zcy numbers and output this sum modulo p.Unfortunately, Willem isn't good at solving this kind of problems, so he asks you for help!", "input_spec": "The first line contains two integers k and p (1 ≤ k ≤ 105, 1 ≤ p ≤ 109).", "output_spec": "Output single integer — answer to the problem.", "sample_inputs": ["2 100", "5 30"], "sample_outputs": ["33", "15"], "notes": "NoteIn the first example, the smallest zcy number is 11, and the second smallest zcy number is 22.In the second example, ."}, "positive_code": [{"source_code": "#!/usr/bin/perl\n\nuse warnings;\nuse strict;\n\n$\\ = $/;\n\nwhile(<>){\n\tmy( $n, $k ) = split;\n\tmy $sum = 0;\n\t\n\tfor( 1 .. $n ){\n\t\t( $sum += $_ . reverse ) %= $k;\n\t\t}\n\t\n\tprint $sum;\n\t}"}, {"source_code": "<> =~ / /;\n\n( $sum += $_ . reverse ) %= $' for 1 .. $`;\n\nprint 0 + $sum"}], "negative_code": [{"source_code": "#!/usr/bin/perl\n\nuse warnings;\nuse strict;\n\n$\\ = $/;\n\nwhile(<>){\n\tmy( $n, $k ) = split;\n\tmy $sum = 0;\n\t\n\tfor( 1 .. $n ){\n\t\t( $sum += $_ . reverse ) %= $k;\n\t\tprint \" $sum\";\n\t\t}\n\t\n\tprint $sum;\n\t}"}], "src_uid": "00e90909a77ce9e22bb7cbf1285b0609"} {"nl": {"description": "There is a building consisting of $$$10~000$$$ apartments numbered from $$$1$$$ to $$$10~000$$$, inclusive.Call an apartment boring, if its number consists of the same digit. Examples of boring apartments are $$$11, 2, 777, 9999$$$ and so on.Our character is a troublemaker, and he calls the intercoms of all boring apartments, till someone answers the call, in the following order: First he calls all apartments consisting of digit $$$1$$$, in increasing order ($$$1, 11, 111, 1111$$$). Next he calls all apartments consisting of digit $$$2$$$, in increasing order ($$$2, 22, 222, 2222$$$) And so on. The resident of the boring apartment $$$x$$$ answers the call, and our character stops calling anyone further.Our character wants to know how many digits he pressed in total and your task is to help him to count the total number of keypresses.For example, if the resident of boring apartment $$$22$$$ answered, then our character called apartments with numbers $$$1, 11, 111, 1111, 2, 22$$$ and the total number of digits he pressed is $$$1 + 2 + 3 + 4 + 1 + 2 = 13$$$.You have to answer $$$t$$$ independent test cases.", "input_spec": "The first line of the input contains one integer $$$t$$$ ($$$1 \\le t \\le 36$$$) — the number of test cases. The only line of the test case contains one integer $$$x$$$ ($$$1 \\le x \\le 9999$$$) — the apartment number of the resident who answered the call. It is guaranteed that $$$x$$$ consists of the same digit.", "output_spec": "For each test case, print the answer: how many digits our character pressed in total.", "sample_inputs": ["4\n22\n9999\n1\n777"], "sample_outputs": ["13\n90\n1\n66"], "notes": null}, "positive_code": [{"source_code": "#!/usr/bin/perl\n\nuse warnings;\nuse strict;\n\n$\\ = $/;\n\n<>;\n\nmy $str = join ' ', 1 .. 9;\n$str =~ s/\\d/ join ' ', map { $& x $_ } 1 .. 4 /eg;\n\nwhile(<>){\n\tchomp;\n\t\n\t$str =~ /$_/;\n\t\n\t@_ = \"$`$&\" =~ /\\d/g;\n\t\n\tprint 0 + @_;\n\t}"}], "negative_code": [], "src_uid": "289a55128be89bb86a002d218d31b57f"} {"nl": {"description": "Fox Ciel is playing a game with numbers now. Ciel has n positive integers: x1, x2, ..., xn. She can do the following operation as many times as needed: select two different indexes i and j such that xi > xj hold, and then apply assignment xi = xi - xj. The goal is to make the sum of all numbers as small as possible.Please help Ciel to find this minimal sum.", "input_spec": "The first line contains an integer n (2 ≤ n ≤ 100). Then the second line contains n integers: x1, x2, ..., xn (1 ≤ xi ≤ 100).", "output_spec": "Output a single integer — the required minimal sum.", "sample_inputs": ["2\n1 2", "3\n2 4 6", "2\n12 18", "5\n45 12 27 30 18"], "sample_outputs": ["2", "6", "12", "15"], "notes": "NoteIn the first example the optimal way is to do the assignment: x2 = x2 - x1.In the second example the optimal sequence of operations is: x3 = x3 - x2, x2 = x2 - x1."}, "positive_code": [{"source_code": "use strict ;\nuse warnings ;\n\nmy $n = ;\n\nmy @num = split(/ /,);\n\nsub findGcd{\n\treturn $_[0]%$_[1]==0 ? $_[1] : findGcd($_[1],$_[0]%$_[1]);\n}\n\n\nmy $ans = $num[0];\nfor my $i (1..$n-1){\n\t$ans=findGcd($ans,$num[$i]);\n}\n\nprint ($n*$ans);"}, {"source_code": "#!usr/bin/perl\n\n\tsub gcd{\n\t\t\treturn $_[0]%$_[1]==0 ? $_[1] : gcd($_[1],$_[0]%$_[1]);\n\t }\n\n$n=<>;\n@num=split(/ /,<>);\n\t$ans=$num[0];\n\tfor $i(1..$n-1)\n\t{\n\t\t$ans=gcd($ans,$num[$i]);\n\t}\n\tprint $ans*$n;\n"}, {"source_code": "$n=<>;\n@_=split/ /,<>;\nfor $i(1..100){\n\t$f=0;\n\t$_%$i or ++$f for @_;\n\t$f==$n and $m=$i\n\t}\nprint $m*$n"}], "negative_code": [{"source_code": "use strict ;\nuse warnings ;\n\nmy $num = ;\n\nmy @x = split(/ /,);\n\nsub findGcd{\n\tmy $m = shift;\n\tmy $n = shift;\n\tmy $r;\n\tif($m==0 || $n==0){\n\t\treturn 0;\n\t}elsif($m<0 || $n<0){\n\t\treturn -1;\n\t}\n\t\n\twhile(1){\n\t\t$r = $m % $n ;\n\t\tif($r==0){\n\t\t\tlast;\n\t\t}\n\t\t$m = $n;\n\t\t$n = $r;\n\t}\n\treturn $n;\n}\n\nmy $min = $x[0];\nmy $max = $x[0];\n\nfor(my $i=0;$i<$#x+1;$i++){\n\tif($x[$i]<=$min){\n\t\t$min=$x[$i];\n\t}\n}\nfor(my $j=0;$j<$#x+1;$j++){\n\tif($x[$j]>=$max){\n\t\t$max=$x[$j];\n\t}\n}\n\nmy $factor = findGcd($max,$min);\n\nprint ($num*$factor);"}], "src_uid": "042cf938dc4a0f46ff33d47b97dc6ad4"} {"nl": {"description": "Imagine a city with n horizontal streets crossing m vertical streets, forming an (n - 1) × (m - 1) grid. In order to increase the traffic flow, mayor of the city has decided to make each street one way. This means in each horizontal street, the traffic moves only from west to east or only from east to west. Also, traffic moves only from north to south or only from south to north in each vertical street. It is possible to enter a horizontal street from a vertical street, or vice versa, at their intersection. The mayor has received some street direction patterns. Your task is to check whether it is possible to reach any junction from any other junction in the proposed street direction pattern.", "input_spec": "The first line of input contains two integers n and m, (2 ≤ n, m ≤ 20), denoting the number of horizontal streets and the number of vertical streets. The second line contains a string of length n, made of characters '<' and '>', denoting direction of each horizontal street. If the i-th character is equal to '<', the street is directed from east to west otherwise, the street is directed from west to east. Streets are listed in order from north to south. The third line contains a string of length m, made of characters '^' and 'v', denoting direction of each vertical street. If the i-th character is equal to '^', the street is directed from south to north, otherwise the street is directed from north to south. Streets are listed in order from west to east.", "output_spec": "If the given pattern meets the mayor's criteria, print a single line containing \"YES\", otherwise print a single line containing \"NO\".", "sample_inputs": ["3 3\n><>\nv^v", "4 6\n<><>\nv^v^v^"], "sample_outputs": ["NO", "YES"], "notes": "NoteThe figure above shows street directions in the second sample test case."}, "positive_code": [{"source_code": "<>;\n<>=~/(?<=.).*(?=.)/;\n$_.=$`.$';\n<>=~/(?<=.).*(?=.)/;\n$_.=$`.$';\ns/\\s//gm;\nfor $i qw(<>v^ ><^v){/^\\Q$i\\E$/ && ++$f}\nprint $f? YES:NO"}, {"source_code": "$_=<>.<>.<>;\ns/\\d|(?<=.).*(?=.)|\\s//gm;\nfor $i qw(<>v^ ><^v){/\\Q$i\\E/ && ++$f}\nprint $f? YES:NO"}], "negative_code": [{"source_code": "$_=<>.<>.<>;\ns/\\d|(?<=.).*(?=.)|\\s//gm;\nfor $i qw(<>v^ ><^v){/$i/ && ++$f}\nprint $f? YES:NO"}, {"source_code": "<>;\n<>=~/(?<=.).*(?=.)/;\n$_.=$`.$';\n<>=~/(?<=.).*(?=.)/;\n$_.=$`.$';\ns/\\s//gm;\nprint;\nfor $i qw(<>v^ ><^v){/^\\Q$i\\E$/ && ++$f}\nprint $f? YES:NO"}], "src_uid": "eab5c84c9658eb32f5614cd2497541cf"} {"nl": {"description": "In Omkar's last class of math, he learned about the least common multiple, or $$$LCM$$$. $$$LCM(a, b)$$$ is the smallest positive integer $$$x$$$ which is divisible by both $$$a$$$ and $$$b$$$.Omkar, having a laudably curious mind, immediately thought of a problem involving the $$$LCM$$$ operation: given an integer $$$n$$$, find positive integers $$$a$$$ and $$$b$$$ such that $$$a + b = n$$$ and $$$LCM(a, b)$$$ is the minimum value possible.Can you help Omkar solve his ludicrously challenging math problem?", "input_spec": "Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \\leq t \\leq 10$$$). Description of the test cases follows. Each test case consists of a single integer $$$n$$$ ($$$2 \\leq n \\leq 10^{9}$$$).", "output_spec": "For each test case, output two positive integers $$$a$$$ and $$$b$$$, such that $$$a + b = n$$$ and $$$LCM(a, b)$$$ is the minimum possible.", "sample_inputs": ["3\n4\n6\n9"], "sample_outputs": ["2 2\n3 3\n3 6"], "notes": "NoteFor the first test case, the numbers we can choose are $$$1, 3$$$ or $$$2, 2$$$. $$$LCM(1, 3) = 3$$$ and $$$LCM(2, 2) = 2$$$, so we output $$$2 \\ 2$$$.For the second test case, the numbers we can choose are $$$1, 5$$$, $$$2, 4$$$, or $$$3, 3$$$. $$$LCM(1, 5) = 5$$$, $$$LCM(2, 4) = 4$$$, and $$$LCM(3, 3) = 3$$$, so we output $$$3 \\ 3$$$.For the third test case, $$$LCM(3, 6) = 6$$$. It can be shown that there are no other pairs of numbers which sum to $$$9$$$ that have a lower $$$LCM$$$."}, "positive_code": [{"source_code": "use v5.20;\nsub { \n &{sub { \n my $n = <>;\n my ($mn, $a);\n for (my $i = 2; $i * $i <= $n; $i++) {\n if ($n % $i == 0) {\n say $n / $i, \" \", $n - $n / $i;\n return;\n }\n }\n say \"1 \", $n - 1;\n }}\n while ($_[0]--)\n} -> (my $t = <>)"}], "negative_code": [], "src_uid": "3fd60db24b1873e906d6dee9c2508ac5"} {"nl": {"description": "Valeric and Valerko missed the last Euro football game, so they decided to watch the game's key moments on the Net. They want to start watching as soon as possible but the connection speed is too low. If they turn on the video right now, it will \"hang up\" as the size of data to watch per second will be more than the size of downloaded data per second.The guys want to watch the whole video without any pauses, so they have to wait some integer number of seconds for a part of the video to download. After this number of seconds passes, they can start watching. Waiting for the whole video to download isn't necessary as the video can download after the guys started to watch.Let's suppose that video's length is c seconds and Valeric and Valerko wait t seconds before the watching. Then for any moment of time t0, t ≤ t0 ≤ c + t, the following condition must fulfill: the size of data received in t0 seconds is not less than the size of data needed to watch t0 - t seconds of the video.Of course, the guys want to wait as little as possible, so your task is to find the minimum integer number of seconds to wait before turning the video on. The guys must watch the video without pauses.", "input_spec": "The first line contains three space-separated integers a, b and c (1 ≤ a, b, c ≤ 1000, a > b). The first number (a) denotes the size of data needed to watch one second of the video. The second number (b) denotes the size of data Valeric and Valerko can download from the Net per second. The third number (c) denotes the video's length in seconds.", "output_spec": "Print a single number — the minimum integer number of seconds that Valeric and Valerko must wait to watch football without pauses.", "sample_inputs": ["4 1 1", "10 3 2", "13 12 1"], "sample_outputs": ["3", "5", "1"], "notes": "NoteIn the first sample video's length is 1 second and it is necessary 4 units of data for watching 1 second of video, so guys should download 4 · 1 = 4 units of data to watch the whole video. The most optimal way is to wait 3 seconds till 3 units of data will be downloaded and then start watching. While guys will be watching video 1 second, one unit of data will be downloaded and Valerik and Valerko will have 4 units of data by the end of watching. Also every moment till the end of video guys will have more data then necessary for watching.In the second sample guys need 2 · 10 = 20 units of data, so they have to wait 5 seconds and after that they will have 20 units before the second second ends. However, if guys wait 4 seconds, they will be able to watch first second of video without pauses, but they will download 18 units of data by the end of second second and it is less then necessary."}, "positive_code": [{"source_code": "#!/usr/bin/perl\n\nuse 5.006;\nuse strict;\nuse warnings;\n\nsub f {\nmy $a = shift;\nmy $b = shift;\nmy $c = shift;\nmy $t = shift;\nmy $cur = $t * $b;\nfor(1..$c) {\n return 0 if(0 > $cur - $a + $b);\n $cur -= $a - $b;\n}\nreturn 1;\n}\n\nmy $num = <>;\nmy @arr = split(/ /, $num);\nmy $a = $arr[0];\nmy $b = $arr[1];\nmy $c = $arr[2];\nmy $l = 0;\nmy $r = 1000010;\nwhile ($r - $l > 1) {\n my $m = int(($r + $l) / 2); \n \n if (f($a, $b, $c, $m)) {\n $r = $m;\n } else {\n $l = $m\n }\n}\n\nprint $r;"}, {"source_code": "#!perl -w\nuse strict;\nuse warnings;\nuse POSIX qw[ceil];\nmain();\n\nsub main {\n my ($a,$b,$c) = split /\\D/, <>;\n my $to_load = $a * $c;\n my $to_preload = $to_load - $b * $c;\n my $res = ceil($to_preload / $b);\n print $res;\n}\n\n__END__\n4 1 1\n10 3 2\n13 12 1"}, {"source_code": "if(<>=~/(\\d+)\\s(\\d+)\\s(\\d+)/){print((($1*$3%$2)&&1)-$3+int($1*$3/$2))}\n"}], "negative_code": [{"source_code": "#!/usr/bin/perl\n\nuse 5.006;\nuse strict;\nuse warnings;\n\nsub f {\nmy $a = shift;\nmy $b = shift;\nmy $c = shift;\nmy $t = shift;\nmy $cur = $t * $b;\nfor(1..$c) {\n return 0 if(0 > $cur - $a + $b);\n $cur -= $a - $b;\n}\nreturn 1;\n}\n\nmy $num = <>;\nmy @arr = split(/ /, $num);\nmy $a = $arr[0];\nmy $b = $arr[1];\nmy $c = $arr[2];\nmy $l = 0;\nmy $r = 10;\nwhile ($r - $l > 1) {\n my $m = int(($r + $l) / 2); \n \n if (f($a, $b, $c, $m)) {\n $r = $m;\n } else {\n $l = $m\n }\n}\n\nprint $r;"}, {"source_code": "if(<>=~/(\\d+)\\s(\\d+)\\s(\\d+)/){print(($1*$3%$2&1)-$3+int($1*$3/$2))}"}], "src_uid": "7dd098ec3ad5b29ad681787173eba341"} {"nl": {"description": "Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya!Sonya is an owl and she sleeps during the day and stay awake from minute l1 to minute r1 inclusive. Also, during the minute k she prinks and is unavailable for Filya.Filya works a lot and he plans to visit Sonya from minute l2 to minute r2 inclusive.Calculate the number of minutes they will be able to spend together.", "input_spec": "The only line of the input contains integers l1, r1, l2, r2 and k (1 ≤ l1, r1, l2, r2, k ≤ 1018, l1 ≤ r1, l2 ≤ r2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks.", "output_spec": "Print one integer — the number of minutes Sonya and Filya will be able to spend together.", "sample_inputs": ["1 10 9 20 1", "1 100 50 200 75"], "sample_outputs": ["2", "50"], "notes": "NoteIn the first sample, they will be together during minutes 9 and 10.In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100."}, "positive_code": [{"source_code": "use strict;\nuse warnings;\n\nuse Data::Dumper;\n$,=\" \";\nmy ($l1,$r1,$l2,$r2,$k)=split / /,<>;\nchomp($l1,$r1,$l2,$r2,$k);\nmy $ans=min($r1,$r2)-max($l1,$l2)+1;\nif(max($l1,$l2) <= $k and $k <=min($r1,$r2))\n{\n $ans--;\n}\nif($ans>=0)\n{\n print $ans . \"\\n\";\n}\nelse\n{\n print \"0\\n\";\n}\n\nsub min\n{\nmy $ans=shift;\nwhile(@_)\n{\nmy $temp=shift;\n$ans=$temp if($ans>$temp);\n}\nreturn $ans;\n}\n\nsub max\n{\nmy $ans=shift;\nwhile(@_)\n{\nmy $temp=shift;\n$ans=$temp if($ans<$temp);\n}\nreturn $ans;\n}\n"}, {"source_code": "# cf714a\nuse strict;\n=item\nA. Meeting of Old Friends\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\n\nToday an outstanding event is going to happen in the forest \n— hedgehog Filya will come to his old fried Sonya!\n\nSonya is an owl and she sleeps during the day and stay awake from minute\nl1 to minute r1 inclusive. Also, during the minute k she prinks \nand is unavailable for Filya.\n\nFilya works a lot and he plans to visit Sonya from minute\nl2 to minute r2 inclusive.\n\nCalculate the number of minutes they will be able to spend together.\nInput\n\nThe only line of the input contains integers l1, r1, l2, r2 \nand k (1 ≤ l1, r1, l2, r2, k ≤ 1018, l1 ≤ r1, l2 ≤ r2), \nproviding the segments of time for Sonya and Filya and the moment of \ntime when Sonya prinks.\n\nOutput\n\nPrint one integer — the number of minutes Sonya and Filya will be able to spend together.\nExamples\nInput\n\n1 10 9 20 1\n\nOutput\n\n2\n\nInput\n\n1 100 50 200 75\n\nOutput\n\n50\n\nNote\n\nIn the first sample, they will be together during minutes 9 and 10.\n\nIn the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100.\n=cut\nuse bigint;\n\nmy ($l1,$r1,$l2,$r2,$k)=map {$_+0} split(' ',<>);\nmy $a=$l1<=$l2 ? $l2 : $l1;\nmy $b=$r1<=$r2 ? $r1 : $r2;\nmy $r=$b-$a>=0?$b-$a+1:0;\nmy $s=(($a<=$k)&&($k<=$b))?1:0;\nprint $r-$s,\"\\n\";\n\n\n\n"}], "negative_code": [{"source_code": "# cf714a\nuse strict;\n=item\nA. Meeting of Old Friends\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\n\nToday an outstanding event is going to happen in the forest \n— hedgehog Filya will come to his old fried Sonya!\n\nSonya is an owl and she sleeps during the day and stay awake from minute\nl1 to minute r1 inclusive. Also, during the minute k she prinks \nand is unavailable for Filya.\n\nFilya works a lot and he plans to visit Sonya from minute\nl2 to minute r2 inclusive.\n\nCalculate the number of minutes they will be able to spend together.\nInput\n\nThe only line of the input contains integers l1, r1, l2, r2 \nand k (1 ≤ l1, r1, l2, r2, k ≤ 1018, l1 ≤ r1, l2 ≤ r2), \nproviding the segments of time for Sonya and Filya and the moment of \ntime when Sonya prinks.\n\nOutput\n\nPrint one integer — the number of minutes Sonya and Filya will be able to spend together.\nExamples\nInput\n\n1 10 9 20 1\n\nOutput\n\n2\n\nInput\n\n1 100 50 200 75\n\nOutput\n\n50\n\nNote\n\nIn the first sample, they will be together during minutes 9 and 10.\n\nIn the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100.\n=cut\n\nmy ($l1,$r1,$l2,$r2,$k)=split(' ',<>);\nmy $a=$l1<=$l2 ? $l2 : $l1;\nmy $b=$r1<=$r2 ? $r1 : $r2;\nprint $b-$a+1-($a<=$k&&$k<=$b),\"\\n\";\n\n\n\n"}, {"source_code": "# cf714a\nuse strict;\n=item\nA. Meeting of Old Friends\ntime limit per test\n1 second\nmemory limit per test\n256 megabytes\ninput\nstandard input\noutput\nstandard output\n\nToday an outstanding event is going to happen in the forest \n— hedgehog Filya will come to his old fried Sonya!\n\nSonya is an owl and she sleeps during the day and stay awake from minute\nl1 to minute r1 inclusive. Also, during the minute k she prinks \nand is unavailable for Filya.\n\nFilya works a lot and he plans to visit Sonya from minute\nl2 to minute r2 inclusive.\n\nCalculate the number of minutes they will be able to spend together.\nInput\n\nThe only line of the input contains integers l1, r1, l2, r2 \nand k (1 ≤ l1, r1, l2, r2, k ≤ 1018, l1 ≤ r1, l2 ≤ r2), \nproviding the segments of time for Sonya and Filya and the moment of \ntime when Sonya prinks.\n\nOutput\n\nPrint one integer — the number of minutes Sonya and Filya will be able to spend together.\nExamples\nInput\n\n1 10 9 20 1\n\nOutput\n\n2\n\nInput\n\n1 100 50 200 75\n\nOutput\n\n50\n\nNote\n\nIn the first sample, they will be together during minutes 9 and 10.\n\nIn the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100.\n=cut\n\nmy ($l1,$r1,$l2,$r2,$k)=split(' ',<>);\n\nif($l1>$l2) {\n ($l1,$r1)=($l2,$r2);\n}\n# l1<=l2\nif($r1<$l2) {\n print 0,\"\\n\";\n}\n# l2<=r1\nmy $r=$r1-$l2+1; # inc\nif(($l2<=$k) and ($k<=$r1)) {\n --$r;\n}\nprint \"$r\\n\";\n\n\n\n"}], "src_uid": "9a74b3b0e9f3a351f2136842e9565a82"} {"nl": {"description": "\"Contestant who earns a score equal to or greater than the k-th place finisher's score will advance to the next round, as long as the contestant earns a positive score...\" — an excerpt from contest rules.A total of n participants took part in the contest (n ≥ k), and you already know their scores. Calculate how many participants will advance to the next round.", "input_spec": "The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 50) separated by a single space. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 100), where ai is the score earned by the participant who got the i-th place. The given sequence is non-increasing (that is, for all i from 1 to n - 1 the following condition is fulfilled: ai ≥ ai + 1).", "output_spec": "Output the number of participants who advance to the next round.", "sample_inputs": ["8 5\n10 9 8 7 7 7 5 5", "4 2\n0 0 0 0"], "sample_outputs": ["6", "0"], "notes": "NoteIn the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers.In the second example nobody got a positive score."}, "positive_code": [{"source_code": "$_ = ; my ($n, $k) = split;\n$_ = ; my @A = split;\n\n@P = grep($_ > 0 && $_ >= $A[$k - 1], @A);\nprint @P . \"\\n\";\n"}, {"source_code": "#\n# Hello World Program in Perl\n#\nuse strict;\nmy ($a, $b) = split /\\s/, <>;\n\nmy @units = split /\\s/, <>;\n$b--;\n$b++ while($b < $#units && $units[$b] == $units[$b+1]);\n$b-- while($b >= 0 && $units[$b] == 0);\nprint $b+1;\n"}, {"source_code": "#!/usr/bin/env perl\n\nuse strict;\nuse warnings;\nuse utf8;\nuse v5.20;\n\nsub main {\n my %args = @_;\n\n my ($n, $k) = split(/ /, readline(STDIN));\n my @points = split(/ /, readline(STDIN));\n\n my $pass_count = 0;\n my $pass_points = $points[$k-1];\n\n if ($pass_points > 0) {\n $pass_count = $k;\n\n foreach my $mark (@points[$k..$n-1]) {\n last if $mark < $pass_points;\n $pass_count += 1;\n }\n }\n else {\n foreach my $mark (@points[0..$k-1]) {\n last if $mark <= 0;\n $pass_count += 1;\n }\n }\n\n say $pass_count;\n\n return;\n}\n\nmain();\n\nexit;\n\n"}, {"source_code": "#!/usr/bin/perl\n# Codeforces Practice 158A - 25 May 2012\n\nuse warnings;\nuse strict;\n\nmy ($n,$k) = split(\" \", );\nmy @scores = split(\" \", );\n\nmy $kthScore = $scores[$k-1];\nmy $ret = 0;\n\nfor(0..$#scores){\n if($scores[$_]>=$kthScore && $scores[$_]!=0){\n $ret++;\n }\n}\n\nprint $ret;"}, {"source_code": "#!/usr/bin/perl\n# Codeforces Practice 158A - 25 May 2012\n\nuse warnings;\nuse strict;\n\nmy ($n,$k) = split(\" \", );\nmy @scores = split(\" \", );\n\nmy $kthScore = $scores[$k-1];\nmy $ret = 0;\n\nfor(@scores){\n if($_>=$kthScore && $_!=0){\n $ret++;\n }\n}\n\nprint $ret;"}, {"source_code": "my($n, $k) = split(\" \", );\nmy @a = split(\" \", );\nmy $count = 0;\nforeach my $i (@a) {\n if(($i >= $a[$k-1])&&($i > 0)) {\n $count++;\n }\n}\nprint $count;"}, {"source_code": "#!perl -w\nuse strict;\n\nmy ($n , $k) = split(/\\s+/,);\nmy @score = split(/\\s+/,);\nmy ($i,$j) ;\n\n\n\nfor ( $i = $k-1 ; $i < $n && $score[$k-1] == $score[$i] ; $i++ ){\n 1;\n}\nfor ( $j = 0 ; $j < $n && $score[$j] > 0 ; $j++ ){\n 1;\n}\n\n\nprint $i < $j ? ($i) : ($j) , \"\\n\";"}, {"source_code": "#!/usr/bin/perl\n# your code goes here\n\nchomp;\n($n, $k) = split / /, <>;\nchomp;\n@a = split / /, <>;\n$bound = $a[$k-1]>0 ? $a[$k-1]:1;\n@a = sort { $a <=> $b } @a;\n$ans = 0;\n# print \"bound = $bound\";\n# print $#a;\nforeach (@a) {\n\t++$ans if $_ >= $bound;\n\t# print \"$_ \"\n}\n# print ;\nprint $ans;"}, {"source_code": "use strict;\nuse warnings;\n\nmy $in1 = <>;\nmy ($n, $k) = split ' ', $in1;\nmy $in2 = <>;\nmy @a = split ' ', $in2;\n\n# check a[0]=0 case...\n\n#find k'th place score.\n# find all a[i] bigger or equal to k'th place score\n\n\nmy $score_k = $a[$k-1];\n\nmy $winners = 0;\nfor (my $i=0; $i < $n; $i++) {\n if ($a[$i] >= $score_k && $a[$i] > 0) {\n $winners++;\n }\n}\n\nprint $winners . \"\\n\";\n\n"}, {"source_code": "#!/usr/bin/perl\n\n($n, $k) = split ' ', ;\n@a = split ' ', ;\n\n$ans = 0;\nforeach my $x (@a) {\n\tif ($x >= $a[$k - 1] && $x > 0){\n\t\t$ans++;\n\t}\n}\nprint \"$ans \\n\";\n"}, {"source_code": "$l=;\nchomp($l);\n$l =~ /(\\d+)\\s+(\\d+)/;\n$n = $1; $k = $2;\n$l=;\nchomp($l);\n$l = \"9 $l\";\n@scores = split /\\s+/, $l;\n$c = 0;\n$p = 1;\n$target = $scores[$k];\nwhile($scores[$p] > 0 && $scores[$p] >= $target && $p <= $n) {\n\t$c++;\n\t$p++;\n}\nprint \"$c\\n\";"}, {"source_code": "($n, $k) = split \" \", <>;\n@mas = split \" \", <>;\n@mas = sort {$b <=> $a} @mas;\n$curr = @mas[$k-1];\nif ($curr == 0)\n{\n\t$ans = 0;\n\tforeach $index (0..$n-1)\n\t{\n\t\tif (@mas[$index] != 0)\n\t\t{\n\t\t\t$ans = $ans + 1;\n\t\t}\n\t}\n\tprint $ans;\n}\nelse\n{\t\n\t$ans = $k;\n\tforeach $index ($k..$n-1)\n\t{\n\t\t# print \"$index\\n\";\n\t\tif (@mas[$index] == $curr)\n\t\t{\n\t\t\t$ans = $ans + 1;\n\t\t}\n\t}\n\tprint $ans;\n}"}, {"source_code": "($n, $k) = split \" \", <>;\n@mas = split \" \", <>;\n$curr = @mas[$k-1];\nif ($curr == 0)\n{\n\t$ans = 0;\n\tforeach $index (0..$n-1)\n\t{\n\t\tif (@mas[$index] != 0)\n\t\t{\n\t\t\t$ans = $ans + 1;\n\t\t}\n\t}\n\tprint $ans;\n}\nelse\n{\t\n\t$ans = $k;\n\tforeach $index ($k..$n-1)\n\t{\n\t\t# print \"$index\\n\";\n\t\tif (@mas[$index] == $curr)\n\t\t{\n\t\t\t$ans = $ans + 1;\n\t\t}\n\t}\n\tprint $ans;\n}"}, {"source_code": "use strict;\nuse warnings;\n\nmy ($n, $k) = split ' ', <>;\nmy @a = split ' ', <>;\nmy $lim = $a[$k-1];\n@a = grep { $_ >= $lim && $_ > 0 } @a;\nprint scalar @a, \"\\n\";\n"}, {"source_code": "($n,$k) = split(\" \", );\n@a;\n\n@a = split(\" \", );\n$ok=1;\n$i=0;\n$nb=0;\nwhile($i<$k and $ok){\nif($a[$i]>0){\n$nb++;\n}\nelse{\n$ok=0;\n}\n$i++;\n}\nif(!$ok){\nprint $nb;\n\n}\nelse{\n$i=$k;\nwhile($i<$n && $ok){\nif($a[$i]==$a[$i-1]){\n$nb++;\n\n}\nelse{\n$ok=0;\n}\n$i++;\n}\nprint $nb;\n\n}\n\n\n"}, {"source_code": "\n$\\=$/;\n\n($n,$k)=split(\" \",);\n@members=split(\" \",);\n$k--;\nmy $j=-1;\n\n1 while (($members[++$j]>=$members[$k])&&(($members[$j]>0)));\n\nprint $j;"}, {"source_code": "#!/bin/perl\nuse strict;\nuse warnings;\nmy @a = ();\nmy $a = '';\nmy $s = 0;\nmy ($n, $k) = split \" \", <>;\nchomp ($a = <>);\nforeach (1..$n) { @a = $a =~ /\\d+/sg; }\nforeach (@a) {\n if ($a[$k-1] <= $_) {\n $s = ($s+1) if ($_ > 0);\n } else {\n last;\n }\n}\nprint \"$s\\n\";"}, {"source_code": "$l=;\nchomp($l);\n$l =~ /(\\d+)\\s+(\\d+)/;\n$n = $1; $k = $2;\n$l=;\nchomp($l);\n$l = \"9 $l\";\n@scores = split /\\s+/, $l;\n$c = 0;\n$p = 1;\n$target = $scores[$k];\nwhile($scores[$p] > 0 && $scores[$p] >= $target && $p <= $n) {\n\t$c++;\n\t$p++;\n}\nprint \"$c\\n\";"}, {"source_code": "#!/bin/perl\nuse strict;\nuse warnings;\nmy @a = ();\nmy $s = 0;\nmy ($n, $k) = split \" \", <>;\n\n@a = split \" \", <>;\nforeach (@a) {\n if ($a[$k-1] <= $_) {\n $s = ($s+1) if ($_ > 0);\n } else {\n last;\n }\n}\nprint \"$s\\n\";"}, {"source_code": "my @imin = split(\" \", ); @_ = ( split \" \", ); my $min = $_[$imin[-1]-1]; $_ = grep { $_ >= $min and $_ > 0 } @_; print \"$_\\n\";"}, {"source_code": "use strict;\nuse warnings;\nuse feature \"say\";\n\nmy $n;\nmy $k;\n\n($n, $k) = split / +/, ;\n\nmy @a = split / +/, ;\nmy $ans = 0;\n\nfor (@a)\n{\n if ($_ >= $a[$k - 1] && $_ > 0)\n {\n $ans++;\n }\n}\nsay $ans;\n"}, {"source_code": "use strict;\n\nmy ($n, $k) = split(/\\s/, );\nmy @r = split(/\\s/, );\n\nmy $c = 0;\n\nfor (my $i = 0; $i < scalar @r; $i++) {\n $c++ if ($r[$i] >= $r[$k - 1] && $r[$i]);\n}\n\nprint $c;"}, {"source_code": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\nchomp ($_ = <>);\nmy ($n, $k) = split / /, $_;\nchomp ($_ = <>);\n@_ = split / /, $_;\n\n$k = $_[$k-1];\n$n = 0;\nforeach (@_) { $n++ if (($_ > 0) && $_ >= $k); }\nprint $n, \"\\n\";"}, {"source_code": "($n, $k) = split' ', <>;\n@a = split' ', <>;\n$ans = 0;\n--$k;\nfor ($i = 0; $i < $n; ++$i) {\n if ($a[$i] >= $a[$k] && $a[$i] > 0) {++$ans;}\n}\nprint $ans;"}, {"source_code": "#!/usr/bin/perl\n\nuse strict;\nuse warnings;\n\nchomp( my $firstline = );\nmy ( $nummem, $lastmem ) = split / /, $firstline;\n\nchomp( my $secondline = );\nmy @point = split / /, $secondline;\n\nmy $count = 0;\n\nmy $lastpoint = $point[ $lastmem - 1 ];\n\nforeach my $p ( @point ) {\n if ( ( $p > 0 ) && ( $p >= $lastpoint ) ) {\n $count++;\n } else {\n last;\n }\n}\n\nprint \"$count\\n\";\n"}, {"source_code": "use warnings;\nuse strict;\n\nuse feature ':5.10';\n\nmy ($n, $k) = split / /, ;\nmy @a = split / /, , $n;\n\nmy $l = $a[$k - 1];\n\nmy $ans = 0;\n\nfor (@a){ $ans++ if ($_ >= $l and $_ > 0) };\n\nsay $ans;\n\n"}, {"source_code": "#!/usr/bin/perl\nuse strict; use warnings;\n\nmy ($n, $k, @a) = (0, (split ' ', )[1], split ' ', );\n$k = $a[$k - 1]; $k = 1 if $k < 1;\n$_ >= $k and ++$n foreach @a;\nprint $n . \"\\n\"\n"}, {"source_code": "#!/usr/local/bin/perl\n\n($n , $k) = split (/ / , <>);\n@a = split (/ / , <>);\n\nif ($a[0] == 0 || $k == 0){\n print \"0\\n\";\n exit;\n}\nif ($a[$k-1] == 0){\n print binSearch(0 , $k -1).\"\\n\";\n exit;\n}\n$count = $k;\nwhile ($a[$count] == $a[$k-1] && $count<= $#a){\n $count++;\n \n}\nprint $count.\"\\n\";\n\nsub binSearch{\n use integer;\n my $begin = $_[0];\n my $end = $_[1];\n my $mid = $begin + ($end -$begin) / 2;\n \n if ($begin == $mid){\n return $begin+1;\n } \n\n if ($a[$mid] != 0){\n return binSearch($mid , $end); \n }\n return binSearch($begin , $mid); \n}\n"}, {"source_code": "#!/usr/bin/perl\n\nuse strict;\n\nchomp(my $in = <>);\nmy @in1 = split(\" \", $in);\nmy $k = $in1[1] -1;\n\nchomp($in = <>);\nmy @in2 = split(\" \", $in);\n\nif($in2[$k] > 0){\n\tmy $temp = $in2[$k];\n\tmy $ans = $k;\n\tfor my $i ($k+1..$#in2){\n\t\tif($in2[$i] == $temp){\n\t\t\t$ans++;\n\t\t}\n\t}\n\tprint $ans+1;\n}\nelse{\n\tmy $ans = 0;\n\tfor my $i (0..$k-1){\n\t\tif($in2[$i] > 0){\n\t\t\t$ans++;\n\t\t}\n\t}\n\tprint $ans;\n}"}, {"source_code": "($n, $k) = split(' ', <>);\n@a = split(' ', <>);\n$res = 0;\nfor(@a) {\n $res++ if $_ > 0 && $_ >= $a[$k - 1];\n}\nprint $res . \"\\n\";"}, {"source_code": "while (<>){\n / /;\n @_=split/ /,<>;\n\n $i=0;\n for ($'..$`-1){\n $_[$_]==$_[$'-1] and $i++\n }\n $j=0;\n for (@_){/^0$/ and $j++}\n print $'+$i<$`-$j?$'+$i:$`-$j;\n print \"\\n\"\n }"}, {"source_code": "@a=split(' ',<>);\n@l=split(' ',<>);\n$ref=@l[@a[1]-@a[0]-1];\n$ans=0;\nforeach(@l)\n{\nif($_>=$ref and $_>0)\n{\n$ans+=1;\n}\n}\nprint \"$ans\\n\";\n"}, {"source_code": "my ($n, $k) = split / +/, ;\nmy @arr = split / +/g, ;\n\nmy $ans = 0;\n\nfor (@arr) {\n\tif ($_ >= $arr[$k - 1] && $_ > 0) {\n\t\t++$ans;\n\t}\n}\n\nprint $ans.\"\\n\";"}, {"source_code": "my ($n, $k) = split / +/, ;\nmy @arr = split / +/g, ;\nmy $ans = 0;\n\n$ans += ($_ >= $arr[$k - 1] && $_ > 0? 1 : 0) for (@arr);\n\nprint $ans.\"\\n\";"}, {"source_code": "($n, $k) = split / /, <>;\n@a = split / /, <>; \nprint scalar grep {$_ > 0 && $_ >= $a[$k-1]} @a;"}, {"source_code": "# for numeric sorting\nsub numerically { $b <=> $a }\n\nmy $n, $k;\nmy $line;\nmy @arr, @sorted, @rev;\nchomp ( $line = );\nif ( $line =~ m/(.+) (.+)/ ) {\n $n = $1;\n $k = $2;}\nchomp ( $line = );\n\n@arr = split m/ /, $line;\n@sorted = sort numerically @arr;\n# @rev = reverse ( @sorted );\n\nmy $threshold = $sorted[ $k-1 ];\nmy $count = 0;\nfor (@sorted) {\n if ( $_ >= $threshold && $_ > 0 ) {\n\t$count += 1; }}\nprint \"$count\\n\";\n\n\n\n\n"}, {"source_code": "#!/usr/bin/env perl\n\nuse v5.012;\nuse warnings;\n\nmy ($n, $k) = split / /, ;\nmy @scores = split / /, ;\n\nmy $meh = grep { $_ > 0 } @scores[0..$k-1];\nmy $pass = grep { $_ > 0 && $_ == $scores[$k - 1] } @scores[$k..scalar @scores - 1];\n\nprint $meh + $pass;\n"}, {"source_code": "use strict;\nuse warnings;\n\nmy @input = split(/ /,);\nmy $n = $input[0];\nmy $k = $input[1];\nmy @a = split(/ /,);\nmy $i;\nmy $count = 0;\nfor($i = 0 ; $i < @a ; $i++){\n if($a[$i] >= $a[$k-1] && $a[$i] > 0){\n $count++;\n }\n}\nprint \"$count\\n\";"}, {"source_code": "my @a = split \" \", <>;\nmy @b = split \" \", <>;\nmy $cnt = 0;\nforeach (@b)\n{\n last unless $_ >= $b[$a[1]-1] and $_ > 0;\n ++$cnt;\n}\nprint $cnt;"}, {"source_code": "#!perl\nmy($n, $k) = split / /, ;\nif (!$n) {\n\tprint(0, \"\\n\");\n\texit;\n}\nif ($k > $n) {\n\tdie \"wrong input: n < k\\n\";\n}\nmy @points = grep {length $_ > 0} split / /, ;\n@points = map {int $_} grep {/^-?\\d+$/} @points;\nif ($#points + 1 != $n){\n\tdie \"wrong input: incorrect count\\n\";\n}\n@points = sort {$b <=> $a} grep {$_ > 0} @points;\nmy $count = $#points + 1;\nmy $min = $points[$k-1];\nif ($k > $count) {\n\tprint($count, \"\\n\");\n\texit;\n}\nmy $out = $k;\nfor (my $i = $k; $i < $count && $points[$i] == $min; $i++) {\n\t$out++;\n}\nprint $out, \"\\n\";\n"}, {"source_code": "my ($n, $k) = split \" \", <>;\nmy $l = <>;\nmy @arr = split \" \", $l;\nmy $ans = 0;\n$ans += ($_ >= $arr[$k - 1] && $_ ? 1 : 0) foreach(@arr);\n$ans = 0 if ($arr[0] == 0);\nprint $ans, \"\\n\";\n"}, {"source_code": "my ($n, $k) = split \" \", <>;\nmy $l = <>;\nmy @arr = split \" \", $l;\nmy $ans = 0;\n\n# $ans += ($_ >= $arr[$k - 1] ? 1 : 0) foreach(@arr);\n$l = scalar @arr - 1;\nfor my $i(0..$l) {\n if ($arr[$i] >= $arr[$k - 1] && $arr[$i] != 0) {\n $ans++;\n }\n}\n$ans = 0 if ($arr[0] == 0);\nprint $ans, \"\\n\";\n"}, {"source_code": "use strict;\n\nmy ($n, $k) = split / /, <>;\nmy @a = split / /, <>;\n\nmy $res = 0;\n\nfor (@a) {\n $_ > 0 && $_ >= $a[$k - 1] && ++$res;\n}\n\nprint $res;"}, {"source_code": "use strict;\nuse warnings;\n\nmy $temp_line;\nmy @first_line;\nmy @second_line;\nmy $a_score_index; # advance_score_index\n\n$temp_line = <>;\n@first_line = split(\" \", $temp_line);\n\n$temp_line = <>;\n@second_line = split(\" \", $temp_line);\n\n$a_score_index = $first_line[1] - 1; # kth place to index\n\nwhile ($a_score_index < @second_line\n && $second_line[$a_score_index + 1] == $second_line[$a_score_index]) {\n $a_score_index++;\n}\n\n# do not take 0 score into account\nwhile ($a_score_index > -1) {\n if (0 != $second_line[$a_score_index]) {\n last;\n }\n $a_score_index--;\n}\n\nprint $a_score_index + 1;"}], "negative_code": [{"source_code": "use strict;\nuse warnings;\n\nmy @input_lines;\n\n# read input\nwhile (<>) {\n my $line = $_;\n chomp $line;\n push @input_lines;\n}\n\nwhile (@input_lines) {\n print(pop @input_lines);\n print \"\\n\";\n}\n"}, {"source_code": "#\n# Hello World Program in Perl\n#\nuse strict;\nmy ($a, $b) = split /\\s/, <>;\n\nmy @units = split /\\s/, <>;\n\n$b++ while($b < $#units && $units[$b] == $units[$b+1]);\n$b-- while($b >= 0 && $units[$b] == 0);\nprint $b+1;\n"}, {"source_code": "#!/usr/bin/env perl\n\nuse strict;\nuse warnings;\nuse utf8;\nuse v5.20;\n\nsub main {\n my %args = @_;\n\n my ($n, $k) = split(/ /, readline(STDIN));\n my @points = split(/ /, readline(STDIN));\n\n my $pass_count = 0;\n my $pass_points = $points[$k-1];\n\n if ($pass_points > 0) {\n $pass_count = $k;\n\n foreach my $mark (@points[$k..$n-1]) {\n last if $mark < $pass_points;\n $pass_count += 1;\n }\n }\n else {\n foreach my $mark (@points[0, $k-1]) {\n last if $mark <= 0;\n $pass_count += 1;\n }\n }\n\n say $pass_count;\n\n return;\n}\n\nmain();\n\nexit;\n\n"}, {"source_code": "#!/usr/bin/perl\n# Codeforces Practice 158A - 25 May 2012\n\nuse warnings;\nuse strict;\n\nmy ($n,$k) = split(\" \", );\nmy @scores = split(\" \", );\n\nif($scores[$k-1]!=0)\n{\n my $kthScore = $scores[$k-1];\n my $ret = $k;\n for($k..$#scores){\n if($scores[$_]==$kthScore){\n $ret++;\n }\n last if($scores[$_]!=$kthScore);\n }\n print $ret;\n}\nelse \n{\n print 0;\n}"}, {"source_code": "#!/usr/bin/perl\n# Codeforces Practice 158A - 25 May 2012\n\nuse warnings;\nuse strict;\n\nmy ($n,$k) = split(\" \", );\nmy @scores = split(\" \", );\n\nif($k!=0)\n{\n my $kthScore = $scores[$k-1];\n my $ret = $k;\n for($k..$#scores){\n if($scores[$_]==$kthScore){\n $ret++;\n }\n last if($scores[$_]!=$kthScore);\n }\n print $ret;\n}\nelse \n{\n print 0;\n}"}, {"source_code": "#!/usr/bin/perl\n# Codeforces Practice 158A - 25 May 2012\n\nuse warnings;\nuse strict;\n\nmy ($n,$k) = split(\" \", );\nmy @scores = split(\" \", );\n\nmy $kthScore = $scores[$k-1];\nmy $ret = 0;\nfor(0..$#scores){\n if($scores[$_]>=$kthScore && $scores[$_]!=0){\n $ret++;\n }\n last if($scores[$_]!=$kthScore);\n}\nprint $ret;"}, {"source_code": "#!perl -w\nuse strict;\n\nmy ($n , $k) = split(/\\s+/,);\nmy @score = split(/\\s+/,);\nmy ($i,$j) ;\n\n\n\nfor ( $i = $k ; $score[$k-1] == $score[$i-1] && $i < $n ; $i++ ){\n 1;\n}\nfor ( $j = 0 ; $j < $n && $score[$j] > 0 ; $j++ ){\n 1;\n}\n\n\nprint $i-1 < $j ? ($i-1) : ($j) , \"\\n\";"}, {"source_code": "#!/usr/bin/perl\n# your code goes here\n\nchomp;\n($n, $k) = split / /, <>;\nchomp;\n@a = sort split / /, <>;\n$bound = $a[$k-1];\nforeach (@a) {\n\t++$ans if $_ >= $bound;\n}\nprint $ans;"}, {"source_code": "#!/usr/bin/perl\n# your code goes here\n\nchomp;\n($n, $k) = split / /, <>;\nchomp;\n@a = sort split / /, <>;\n$bound = $a[$k-1]>0 ? $a[$k-1]:1;\n$ans = 0;\nforeach (@a) {\n\t++$ans if $_ >= $bound;\n}\nprint $ans;"}, {"source_code": "#!/usr/bin/perl\n\n($n, $k) = split ' ', ;\n@a = split ' ', ;\nsort @a;\n$ans = 0;\nforeach my $x (@a) {\n\tif ($x >= $a[$n - $k] && $x > 0){\n\t\t$ans++;\n\t}\n}\nprint \"$ans \\n\";\n"}, {"source_code": "#!/usr/bin/perl\n\n($n, $k) = split ' ', ;\n@a = split ' ', ;\n\n$ans = 0;\nforeach my $x (sort @a) {\n\tif ($x >= $a[$n - $k] && $x > 0){\n\t\t$ans++;\n\t}\n}\nprint \"$ans \\n\";\n"}, {"source_code": "$l=;\nchomp($l);\n$l =~ /(\\d+)\\s+(\\d+)/;\n$n = $1; $k = $2;\n$l=;\nchomp($l);\n$l = \"9 $l\";\n@scores = split /\\s+/, $l;\n$c = 0;\n$p = 1;\n$target = $scores[$k];\nwhile($target > 0 && $scores[$p] >= $target && $p <= $n) {\n\t$c++;\n\t$p++;\n}\nprint \"$c\\n\";"}, {"source_code": "($n, $k) = split \" \", <>;\n@mas = split \" \", <>;\n@mas = reverse sort @mas;\n$curr = @mas[$k-1];\nif ($curr == 0)\n{\n\t$ans = 0;\n\tforeach $index (0..$n-1)\n\t{\n\t\tif (@mas[$index] != 0)\n\t\t{\n\t\t\t$ans = $ans + 1;\n\t\t}\n\t}\n\tprint $ans;\n}\nelse\n{\t\n\t$ans = $k;\n\tforeach $index ($k..$n-1)\n\t{\n\t\tif (@mas[$index] == $curr)\n\t\t{\n\t\t\t$ans = $ans + 1;\n\t\t}\n\t}\n\tprint $ans;\n}"}, {"source_code": "($n, $k) = split \" \", <>;\n@mas = split \" \", <>;\n@mas = sort @mas;\n$curr = @mas[$k-1];\nif ($curr == 0)\n{\n\t$ans = 0;\n\tforeach $index (0..$n-1)\n\t{\n\t\tif (@mas[$index] != 0)\n\t\t{\n\t\t\t$ans = $ans + 1;\n\t\t}\n\t}\n\tprint $ans;\n}\nelse\n{\t\n\t$ans = $k;\n\tforeach $index ($k..$n-1)\n\t{\n\t\tif (@mas[$index] == $curr)\n\t\t{\n\t\t\t$ans = $ans + 1;\n\t\t}\n\t}\n\tprint $ans;\n}"}, {"source_code": "\n$\\=$/;\n\n($n,$k)=split(\" \",);\n@members=split(\" \",);\n\nmy $j=-1;\n\n1 while (($members[++$j]>=$members[$k])&&(($members[$j]>0)));\n\nprint $j;"}, {"source_code": "#!/bin/perl\nuse strict;\nuse warnings;\nmy @a = ();\nmy $a = '';\nmy $s = 0;\nmy ($n, $k) = split \" \", <>;\nchomp ($a = <>);\nforeach (1..$n) { @a = $a =~ /\\d/sg; }\nforeach (@a) {\n if ($k < $_) { $s = ($s+1); } else { last; }\n}\nprint \"$s\";"}, {"source_code": "#!/bin/perl\nuse strict;\nuse warnings;\nmy @a = ();\nmy $a = '';\nmy $s = 0;\nmy ($n, $k) = split \" \", <>;\nchomp ($a = <>);\nforeach (1..$n) { @a = $a =~ /\\d+/sg; }\nforeach (@a) {\n if ($a[$k] <= $_) {\n $s = ($s+1) if ($_ > 0);\n } else {\n last;\n }\n}\nprint \"$s\\n\";"}, {"source_code": "#!/bin/perl\nuse strict;\nuse warnings;\n\n\nmy @a = ();\nmy $a = '';\nmy $s = 0;\nmy ($n, $k) = split \" \", <>;\nchomp ($a = <>);\nforeach (1..$n) { @a = $a =~ /\\d+/sg; }\nforeach (@a) {\n if ($k < $_) { $s = ($s+1); } else { last; }\n}\nprint \"$s\";"}, {"source_code": "use strict;\nuse warnings;\nuse feature \"say\";\n\nmy $n;\nmy $k;\n\n($n, $k) = split / +/, ;\n\nmy @a = split / +/, ;\nmy $ans = 0;\n\nfor (@a)\n{\n if ($_ >= $a[$k] && $_ > 0)\n {\n $ans++;\n }\n}\nsay $ans;\n"}, {"source_code": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\nchomp ($_ = <>);\nmy ($n, $k) = split / /, $_;\nchomp ($_ = <>);\n@_ = split / /, $_;\n\n$k = $_[$k];\n$n = 0;\nforeach (@_) { $n++ if (($_ > 0) && $_ >= $k); }\nprint $n, \"\\n\";"}, {"source_code": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\nchomp ($_ = <>);\nmy ($n, $k) = split / /, $_;\nchomp ($_ = <>);\n@_ = split / /, $_;\n\n$k = @_[$k];\n$n = 0;\nforeach (@_) { $n++ if ($_ >= $k); }\nprint $n, \"\\n\";"}, {"source_code": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\nchomp ($_ = <>);\nmy ($n, $k) = split / /, $_;\nchomp ($_ = <>);\n@_ = split / /, $_;\n\nprint \"$n $k\\n\" . join (\",\", @_), \"\\n\";\n$k = @_[$k];\n$n = 0;\nforeach (@_) { $n++ if ($_ >= $k); }\nprint $n, \"\\n\";"}, {"source_code": "#!/usr/bin/perl\n\nuse strict;\nuse warnings;\n\nmy $n = <>;\n\nmy @cmd;\npush @cmd, <> for ($n);\n\nmy $curdir = \"/\";\nmy @dirstack = ();\n\nsub pwd() { print $curdir, \"\\n\"; }\n\nsub cd($) {\n my @path = split '/', shift;\n\n foreach my $dir (@path)\n {\n pop @dirstack if ($dir eq \"..\");\n push @dirstack, $dir if ($dir ne \"..\");\n }\n\n $curdir = (join \"/\", @dirstack) . \"/\";\n $curdir = \"/$curdir\" if ((substr $curdir,0,1) ne \"/\");\n}\n\nforeach (@cmd)\n{\n my ($cmd, $arg) = split /\\s/, $_;\n\n cd ($arg) if ($cmd eq \"cd\");\n pwd() if ($cmd eq \"pwd\");\n}\n"}, {"source_code": "use warnings;\nuse strict;\n\nuse feature ':5.10';\n\nmy ($n, $k) = split / /, ;\nmy @a = split / /, , $n;\n\nmy $l = $a[$k];\n\nmy $ans = 0;\n\nfor (@a){ $ans++ if ($_ >= $l and $_ > 0) };\n\nsay $ans;\n\n"}, {"source_code": "#!/usr/local/bin/perl\n\n($n , $k) = split (/ / , <>);\n@a = split (/ / , <>);\nif (!$a[0]){\n print \"0\\n\";\n exit;\n}\nif (!$a[$k-1]){\n print binSearch(0 , $k -1).\"\\n\";\n exit;\n}\n$count = $k;\nwhile ($a[$count] == $a[$k-1] && $count<= $#a){\n $count++;\n \n}\nprint $count.\"\\n\";\n\nsub binSearch{\n use integer;\n my $begin = $_[0];\n my $end = $_[1];\n my $mid = $begin + ($end -$begin) / 2;\n \n if ($begin == $mid){\n return $begin+1;\n } \n\n if ($a[$mid]){\n return binSearch($mid , $end); \n }\n return binSearch($begin , $mid); \n}\n"}, {"source_code": "#!/usr/bin/perl\n\nuse strict;\n\nchomp(my $in = <>);\nmy @in1 = split(\" \", $in);\nmy $k = $in1[1];\n\nchomp($in = <>);\nmy @in2 = split(\" \", $in);\n\nif($in2[$k] > 0){\n\tmy $temp = $in2[$k];\n\tmy $ans = $k;\n\tfor my $i ($k+1..$#in2){\n\t\tif($in2[$i] == $temp){\n\t\t\t$ans++;\n\t\t}\n\t}\n\tprint $ans;\n}\nelse{\n\tmy $ans = 0;\n\tfor my $i (0..$k-1){\n\t\tif($in2[$i] > 0){\n\t\t\t$ans++;\n\t\t}\n\t}\n\tprint $ans;\n}"}, {"source_code": "$_=<>;\n($a)=/(\\d+)$/;\n$_=<>;\ns/(\\d+)/$1>$a&&$i++&&()/ge;\nprint$i"}, {"source_code": "$_=<>;\n($a)=/(\\d+)$/;\n$_=<>;\ns/\\b0\\b//g;\nfor$j(1..$a){s/\\d+//;$b=$&};\ns/(\\d+)/$1-$b?():$a++/ge;\nprint$a"}, {"source_code": "$_=<>;\n($a)=/(\\b\\d+)$/;\n@_=split/ /,<>;\nif($_[$a-1]){\n $b=$_[$a-1];\n $c=$a;\n $i=$a;\n while($c<@_){\n if($_[$c++]==$b){$i++}else{last}\n }\n \n \n}else{\n for(@_){$_&&$i++}\n}\nprint$i"}, {"source_code": "$a, $b = split/ /,<>;\n$_=<>;\ns/\\b(\\d+)\\b/$1>$b?($i++):($i--)/ge;\nprint $i"}, {"source_code": "($a, $b) = split/ /,<>;\n$_=<>;\n$i=0;\ns/\\b(\\d+)\\b/$1>$b?($i++):()/ge;\nprint $i"}, {"source_code": "$_=<>;\n($a)=/(\\b\\d+)$/;\n@_=split/ /,<>;\nif($_[$a-1]){\n $b=$_[$a-1];\n $c=$a;\n $i=$a;\n while($c<@_){\n if($_[$c++]==$b){$i++}else{last}\n }\n \n \n}else{\n for(@_){$_&&$i++}\n}\n\nprint$i"}, {"source_code": "($a, $b) = split/ /,<>;\n$_=<>;\ns/\\b(\\d+)\\b/$1>$b?($i++):()/ge;\nprint $i"}, {"source_code": "while (<>){\n / /;\n @_=split/ /,<>;\n\n $i=0;\n for ($'..$`-1){\n $_[$_]==$_[$'-1] and $i++\n }\n while (@_ and !pop @_){\n $i--\n }\n print $'+$i,\"\\n\"\n \n }"}, {"source_code": "@a=split(' ',<>);\n@l=split(' ',<>);\n@l=sort @l;\n$ref=@l[@a[1]-@a[0]-1];\n$ans=0;\nforeach(@l)\n{\nif($_>=$ref and $_>0)\n{\n$ans+=1;\n}\n}\nprint \"$ans\\n\";\n"}, {"source_code": "@a=split(' ',<>);\n@l=split(' ',<>);\n@l=sort @l;\n$ref=@l[@a[1]-@a[0]-1];\nif($ref==0)\n{\n$ref=-1;\n}\n$ans=0;\nforeach(@l)\n{\nif($_>=$ref)\n{\n$ans+=1;\n}\n}\nprint \"$ans\\n\";\n"}, {"source_code": "@a=split(' ',<>);\n@l=split(' ',<>);\n@l=sort @l;\n$ref=@l[@a[1]-@a[0]-1];\n$ans=0;\nforeach(@l)\n{\nif($_>=$ref)\n{\n$ans+=1;\n}\n}\nprint \"$ans\\n\";\n"}, {"source_code": "@a=split(' ',<>);\n@l=split(' ',<>);\n@l=sort @l;\n$ref=@l[@a[1]-@a[0]-1];\nif($ref==0)\n{\n$ref=1;\n}\n$ans=0;\nforeach(@l)\n{\nif($_>=$ref)\n{\n$ans+=1;\n}\n}\nprint \"$ans\\n\";\n"}, {"source_code": "($n, $k) = split / /, <>;\n@a = split / /, <>; \nprint scalar grep {$_ && $_ >= $a[$k-1]} @a;"}, {"source_code": "($n, $k) = split / /, <>;\n$a = split / /, <>;\nprint scalar grep {$_ > 0 && $_ >= $a[$k-1]} @a;"}, {"source_code": "($n, $k) = split / /, <>;\n$a = <>; \nprint scalar grep {$_ > 0 && $_ >= $a[$k-1]} @a;"}, {"source_code": "# for numeric sorting\nsub numerically { $b <=> $a }\n\nmy $n, $k;\nmy $line;\nmy @arr, @sorted, @rev;\nchomp ( $line = );\nif ( $line =~ m/(.+) (.+)/ ) {\n $n = $1;\n $k = $2;}\nchomp ( $line = );\n\n@arr = split m/ /, $line;\n@sorted = sort ( @arr );\n@rev = reverse ( @sorted );\n\nmy $threshold = $rev[ $k-1 ];\nmy $count = 0;\nfor (@rev) {\n if ( $threshold >= $_ && $_ > 0 ) {\n\t$count += 1; }}\n\nprint \"$count\\n\";\n\n\n\n\n"}, {"source_code": "\n\n\nmy $n, $k;\nmy $line;\nmy @arr, @sorted;\nchomp ( $line = );\nif ( $line =~ m/(.+) (.+)/ ) {\n $n = $1;\n $k = $2;}\nchomp ( $line = );\n@arr = split m/ /, $line;\n@sorted = sort ( @arr );\nmy $threshold = $sorted[ $k-1 ];\nmy $count = 0;\nfor (@sorted) {\n if ( $_ >= $threshold && $_ > 0 ) {\n\t$count += 1; }}\nprint \"$count\\n\";\n\n"}, {"source_code": "#!/usr/bin/env perl\n\nuse v5.012;\nuse warnings;\n\nmy ($n, $k) = split / /, ;\nmy @scores = split / /, ;\n\nmy $len = scalar @scores;\nmy $meh = grep { $_ > 0 } @scores[0..$k-1];\nmy $pass = grep { $_ > 0 && $_ == $scores[$k] } @scores[$k..scalar @scores - 1];\n\nprint $meh + $pass;\n"}, {"source_code": "use strict;\nuse warnings;\n\nmy @input = split(/ /,);\nmy $n = $input[0];\nmy $k = $input[1];\nmy @a = split(/ /,);\nmy $i = $k;\nmy $count = 0;\nif($a[$k-1] == 0){\n print $count.\"\\n\";\n}else{\n $count = $k;\n while($i < @a and $a[$i] ==$a[$k-1] ){\n $count++;\n $i++;\n };\n print $count.\"\\n\";\n}"}, {"source_code": "my ($n, $k) = split \" \", <>;\nmy $l = <>;\nmy @arr = split \" \", $l;\nmy $ans;\n\n$ans += ($_ >= $arr[$k] ? 1 : 0) foreach(@arr);\n$ans = 0 if ($arr[0] == 0);\nprint $ans, \"\\n\";\n"}, {"source_code": "my ($n, $k) = split \" \", <>;\nmy $l = <>;\nmy @arr = split \" \", $l;\nmy $ans = 0;\n\n# $ans += ($_ >= $arr[$k - 1] ? 1 : 0) foreach(@arr);\nforeach(@arr) {\n if ($_ >= $arr[$k - 1]) {\n $ans++;\n }\n}\n$ans = 0 if ($arr[0] == 0);\nprint $ans, \"\\n\";"}, {"source_code": "my ($n, $k) = split \" \", <>;\nmy $l = <>;\nmy @arr = split \" \", $l;\nmy $ans = 0;\n\n# $ans += ($_ >= $arr[$k - 1] ? 1 : 0) foreach(@arr);\n$l = scalar @arr - 1;\nfor my $i(0..$l) {\n if ($arr[$i] >= $arr[$k - 1]) {\n $ans++;\n }\n}\n$ans = 0 if ($arr[0] == 0);\nprint $ans, \"\\n\";"}, {"source_code": "my ($n, $k) = split \" \", <>;\nmy $l = <>;\nmy @arr = split \" \", $l;\nmy $ans = 0;\n\n$ans += ($_ >= $arr[$k - 1] ? 1 : 0) foreach(@arr);\n$ans = 0 if ($arr[0] == 0);\nprint $ans, \"\\n\";\n"}, {"source_code": "my ($n, $k) = split \" \", <>;\nmy $l = <>;\nmy @arr = split \" \", $l;\nmy $ans;\n\n$ans += ($_ >= $arr[$k - 1] ? 1 : 0) foreach(@arr);\n$ans = 0 if ($arr[0] == 0);\nprint $ans, \"\\n\";\n"}, {"source_code": "use strict;\nuse warnings;\n\nmy $temp_line;\nmy @first_line;\nmy @second_line;\nmy $a_score_index; # advance_score_index\n\n$temp_line = <>;\n@first_line = split(\" \", $temp_line);\n\n$temp_line = <>;\n@second_line = split(\" \", $temp_line);\n\n$a_score_index = $first_line[1] - 1; # kth place to index\n\nwhile ($a_score_index < @second_line\n && $second_line[$a_score_index + 1] == $second_line[$a_score_index]) {\n $a_score_index++;\n}\n\nprint $a_score_index + 1;"}, {"source_code": "use strict;\nuse warnings;\n\nmy @input_line = ;\nmy $as_index = $input_line[1]; # index of score that will advance\nprint $as_index;\n@input_line = ;\n\n# find the index where last score equal to k is\nwhile ( $input_line[$as_index] != $input_line[$as_index + 1] ) {\n $as_index++;\n}\n\n# do not count the input parameters on first row\nprint $as_index - 2;\n"}, {"source_code": "use strict;\nuse warnings;\n\nmy @input_lines;\n\n# read input\nwhile (<>) {\n my $line = $_;\n chomp $line;\n push @input_lines;\n}\n\nwhile (@input_lines) {\n print(pop @input_lines);\n print \"\\n\";\n}\n\n#test"}, {"source_code": "use strict;\nuse warnings;\n\nmy $as_index = $ARGV[1]; # index of score that will advance\n\n# find the index where last score equal to k is\nwhile ( $ARGV [$as_index] != $ARGV[$as_index + 1] ) {\n $as_index++;\n}\n\n# do not count the input parameters on first row\nprint $as_index - 2;\n"}, {"source_code": "use strict;\nuse warnings;\n\nmy @input_lines;\n\nwhile (<>) {\n my $line = $_;\n chomp $line;\n push @input_lines;\n}\n\nwhile (@input_lines) {\n print(pop @input_lines);\n print \"\\n\";\n}\n"}, {"source_code": "print $ARGV[0]"}, {"source_code": "use strict;\nuse warnings;\n\nmy @input_line = ;\nmy $as_index = $input_line[1]; # index of score that will advance\n@input_line = ;\n\n# find the index where last score equal to k is\nwhile ( $input_line[$as_index] != $input_line[$as_index + 1] ) {\n $as_index++;\n}\n\n# do not count the input parameters on first row\nprint $as_index - 2;\n"}, {"source_code": "use strict;\nuse warnings;\n\nmy @input_line = ;\nmy $as_index = $input_line[0]; # index of score that will advance\nprint $as_index;\n@input_line = ;\n\n# find the index where last score equal to k is\nwhile ( $input_line[$as_index] != $input_line[$as_index + 1] ) {\n $as_index++;\n}\n\n# do not count the input parameters on first row\nprint $as_index - 2;\n"}, {"source_code": "use strict;\nuse warnings;\n\nmy $temp_line;\nmy @first_line;\nmy @second_line;\nmy $a_score_index; # advance_score_index\n\n$temp_line = <>;\n@first_line = split(\" \", $temp_line);\n\n$temp_line = <>;\n@second_line = split(\" \", $temp_line);\n\n$a_score_index = $first_line[1] - 1; # kth place to index\n\nwhile ($a_score_index < @second_line\n && $second_line[$a_score_index + 1] == $second_line[$a_score_index]) {\n $a_score_index++;\n}\n\nif (0 == $a_score_index) { # nobody got positive score\n print $a_score_index;\n}\nelse {\n print $a_score_index + 1;\n}"}, {"source_code": "$input = ;\n\nprint $input;"}, {"source_code": "use strict;\nuse warnings;\n\nmy @input_lines;\n\n# read input\nwhile (<>) {\n my $line = $_;\n chomp $line;\n push @input_lines;\n}\n\nwhile (@input_lines) {\n print(pop @input_lines);\n print \"\\n\";\n}\n# fdsjoi\n"}, {"source_code": "print ARGV[0]"}, {"source_code": "use strict;\nuse warnings;\n\nmy $temp_line;\nmy @first_line;\nmy @second_line;\nmy $a_score_index; # advance_score_index\n\n$temp_line = <>;\n@first_line = split(\" \", $temp_line);\n\n$temp_line = <>;\n@second_line = split(\" \", $temp_line);\n\n$a_score_index = $first_line[1] - 1; # kth place to index\n\nwhile ($a_score_index < @second_line\n && $second_line[$a_score_index + 1] == $second_line[$a_score_index]) {\n $a_score_index++;\n}\n\nif (0 == $second_line[0]) { # nobody got positive score\n print $second_line[0];\n}\nelse {\n print $a_score_index + 1;\n}"}, {"source_code": "use strict;\nuse warnings;\n\nmy $temp_line;\nmy @first_line;\nmy @second_line;\nmy $a_score_index; # advance_score_index\n\n$temp_line = <>;\n@first_line = split(\" \", $temp_line);\n\n$temp_line = <>;\n@second_line = split(\" \", $temp_line);\n\n$a_score_index = $first_line[1] - 1; # kth place to index\n\nwhile ($a_score_index < @second_line\n && $second_line[$a_score_index + 1] == $second_line[$a_score_index]) {\n print \"first while\";\n $a_score_index++;\n}\n\n# do not take 0 score into account\nwhile ($a_score_index > -1) {\n if (0 != $second_line[$a_score_index]) {\n last;\n }\n $a_score_index--;\n}\n\nprint $a_score_index + 1;"}], "src_uid": "193ec1226ffe07522caf63e84a7d007f"} {"nl": {"description": "Vanya got n cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1 + 2 = 3 cubes, the third level must have 1 + 2 + 3 = 6 cubes, and so on. Thus, the i-th level of the pyramid must have 1 + 2 + ... + (i - 1) + i cubes.Vanya wants to know what is the maximum height of the pyramid that he can make using the given cubes.", "input_spec": "The first line contains integer n (1 ≤ n ≤ 104) — the number of cubes given to Vanya.", "output_spec": "Print the maximum possible height of the pyramid in the single line.", "sample_inputs": ["1", "25"], "sample_outputs": ["1", "4"], "notes": "NoteIllustration to the second sample: "}, "positive_code": [{"source_code": "while(<>){\n\t$k=0; $j=0;\n\tfor $i(0..50){\n\t\t$k+=$j+=$i;\n\t\t$_ < $k and do {print $i-1,\" \"; last}\n\t\t}\n\t}"}, {"source_code": "$_=<>;\n$x++,$a+=$x*($x+1)/2 until $a>$_;\nprint $x-1;\n"}, {"source_code": "my $n = <>;\nmy $c = 0;\nmy $s = 0;\nfor (1 .. $n) {\n $c += $_;\n $s += $c;\n if ($s >= $n) {\n print $s == $n? $_ : $_ - 1;\n exit;\n }\n}"}, {"source_code": "\nmy $n = int<>;\nfor (my $i = 1;;$i++) {\n $n -= int($i * ($i + 1) / 2);\n if ($n < 0) {\n print $i - 1;\n last;\n }\n}"}, {"source_code": "$n=<>;$j=1;$k=2;$c=0;\nwhile ($n >= $j) {$n -= $j;$j += $k;$k += 1;$c++;};print $c;"}, {"source_code": "#!/usr/bin/perl\n# your code goes here\nuse v5.10;\n\nchomp($mx = <>);\nmy $tmp = 0;\nmy $tot = 0;\nmy $ans = 0;\nwhile (true) {\n\t$tmp += ++$ans;\n\t$tot += $tmp;\n\t$tot>$mx and --$ans and last;\n}\nsay $ans;\n"}, {"source_code": "@arr=qw(1 4 10 20 35 56 84 120 165 220 286 364 455 560 680 816 969 1140 1330 1540 1771 2024 2300 2600 2925 3276 3654 4060 4495 4960 5456 5984 6545 7140 7770 8436 9139 9880 10660 );\nchomp($n=);\n$len=@arr;\nfor($i=0;$i<$len;$i++)\n{\nif($n<$arr[$i])\n\t{\n\tprint $i;\n\texit;\n\t}\n}"}, {"source_code": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\nmy $n = <>;\nmy $lvl = 1; my $num = 1;\nwhile($num <= $n){\n $n -= $num;\n $lvl++;\n $num += $lvl;\n}\n\nprint $lvl-1;\n"}], "negative_code": [{"source_code": "while(<>){\n\t$k=0; $j=0;\n\tfor $i(0..10){\n\t\t$k+=$j+=$i;\n\t\t$_ < $k and do {print $i-1,\" \"; last}\n\t\t}\n\t}"}, {"source_code": "while(<>){\n\tchomp;\n\t$j=0;\n\t$i=0;\n\t$k=0;\n\twhile(($_-=$i)>0){\n\t\t$i+=++$j;\n\t\t$k++;\n\t\t}\n\tprint \"$k\\n\"\n\t}"}, {"source_code": "for $i(1..10){\n\t$k+=$i;\n\tfor $j(1..$k){\n\t\tpush @_, $i\n\t\t}\n\t}\n$_=\"@_\";\ns/(\\b\\d\\b)(?= \\b\\1\\b)/$1-1/ge;\n@_=split;\nwhile(<>){\n\tchomp;\n\tprint $_[$_-1],$/\n\t}"}], "src_uid": "873a12edffc57a127fdfb1c65d43bdb0"} {"nl": {"description": "JATC's math teacher always gives the class some interesting math problems so that they don't get bored. Today the problem is as follows. Given an integer $$$n$$$, you can perform the following operations zero or more times: mul $$$x$$$: multiplies $$$n$$$ by $$$x$$$ (where $$$x$$$ is an arbitrary positive integer). sqrt: replaces $$$n$$$ with $$$\\sqrt{n}$$$ (to apply this operation, $$$\\sqrt{n}$$$ must be an integer). You can perform these operations as many times as you like. What is the minimum value of $$$n$$$, that can be achieved and what is the minimum number of operations, to achieve that minimum value?Apparently, no one in the class knows the answer to this problem, maybe you can help them?", "input_spec": "The only line of the input contains a single integer $$$n$$$ ($$$1 \\le n \\le 10^6$$$) — the initial number.", "output_spec": "Print two integers: the minimum integer $$$n$$$ that can be achieved using the described operations and the minimum number of operations required.", "sample_inputs": ["20", "5184"], "sample_outputs": ["10 2", "6 4"], "notes": "NoteIn the first example, you can apply the operation mul $$$5$$$ to get $$$100$$$ and then sqrt to get $$$10$$$.In the second example, you can first apply sqrt to get $$$72$$$, then mul $$$18$$$ to get $$$1296$$$ and finally two more sqrt and you get $$$6$$$.Note, that even if the initial value of $$$n$$$ is less or equal $$$10^6$$$, it can still become greater than $$$10^6$$$ after applying one or more operations."}, "positive_code": [{"source_code": "$_ = <>;\n\nexit if $_ == 1 and print \"1 0\";\n\nfor $i ( 2 .. sqrt ){\n\tif( $_ % $i == 0 ){\n\t\t$h{ $i } ++;\n\t\t$_ /= $i;\n\t\tredo;\n\t\t}\n\t}\n\n$h{ $_ } ++;\ndelete $h{ 1 };\n\n$g{ $_ } ++ for values %h;\n\n$max = ( sort { $b <=> $a } keys %g )[ 0 ];\n\n$cnt += ( 1 < keys %g or ( sprintf \"%b\", $max ) !~ /^10*$/ );\n\t\n$max > 1 and $cnt += length sprintf \"%b\", -- $max;\n\n$min = eval join ' * ', keys %h;\n\nprint \"$min $cnt\""}, {"source_code": "#!/usr/bin/perl\n\nuse warnings;\nuse strict;\n\n$\\ = $/;\n\nmy $debug = 0;\n\nwhile(<>){\n\tchomp;\n\t\n\t$debug and print '-' x 15;\n\t$debug and print;\n\t\n\tif( $_ == 1 ){\n\t\tprint \"1 0\";\n\t\tnext;\n\t\t}\n\t\n\tmy %h;\n\t\n\tfor my $i ( 2 .. sqrt ){\n\t\tif( $_ % $i == 0 ){\n\t\t\t$h{ $i } ++;\n\t\t\t$_ /= $i;\n\t\t\tredo;\n\t\t\t}\n\t\t}\n\t\n\t$h{ $_ } ++;\n\tdelete $h{ 1 };\n\t\n\t$debug and print \" $_ -> $h{ $_ }\" for keys %h;\n\t\n\t$debug and print ' ', '-' x 10;\n\t\n\tmy %g;\n\t\n\t$g{ $_ } ++ for values %h;\n\t\n\t$debug and print \" $_ -> $g{ $_ }\" for keys %g;\n\t\n\tmy $cnt = 0;\n\t\t\n\tmy $max = ( sort { $b <=> $a } keys %g )[ 0 ];\n\t\n\tif( 1 < keys %g ){\n\t\t$cnt ++;\n\t\t}\n\telsif( ( sprintf \"%b\", $max ) !~ /^10*$/ ){\n\t\t$cnt ++;\n\t\t}\n\t\n\t$max --;\n\t\n\t$max > 0 and $cnt += length sprintf \"%b\", $max;\n\t\n\tmy $min = eval join ' * ', keys %h;\n\t\n\tprint $min, ' ', $cnt;\n\t}"}], "negative_code": [{"source_code": "#!/usr/bin/perl\n\nuse warnings;\nuse strict;\n\n$\\ = $/;\n\nmy $debug = 0;\n\nwhile(<>){\n\tchomp;\n\t\n\t$debug and print '-' x 15;\n\t$debug and print;\n\t\n\tif( $_ == 1 ){\n\t\tprint \"1 0\";\n\t\tnext;\n\t\t}\n\t\n\tmy %h;\n\t\n\tfor my $i ( 2 .. sqrt ){\n\t\tif( $_ % $i == 0 ){\n\t\t\t$h{ $i } ++;\n\t\t\t$_ /= $i;\n\t\t\tredo;\n\t\t\t}\n\t\t}\n\t\n\t$h{ $_ } ++;\n\tdelete $h{ 1 };\n\t\n\t$debug and print \" $_ -> $h{ $_ }\" for keys %h;\n\t\n\tmy %g;\n\t\n\t$g{ $_ } ++ for values %h;\n\t\n\tmy $cnt = 0;\n\t\n\tif( 1 < keys %g ){\n\t\t$cnt ++;\n\t\t}\n\t\n\tmy $max = ( sort { $b <=> $a } keys %g )[ 0 ];\n\t\n\t$max --;\n\t\n\t$max > 0 and $cnt += length sprintf \"%b\", $max;\n\t\n\tmy $min = eval join ' * ', keys %h;\n\t\n\tprint $min, ' ', $cnt;\n\t}"}], "src_uid": "212cda3d9d611cd45332bb10b80f0b56"} {"nl": {"description": "You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password isn't complex enough, a message is displayed. Today your task is to implement such an automatic check.Web-developers of the company Q assume that a password is complex enough, if it meets all of the following conditions: the password length is at least 5 characters; the password contains at least one large English letter; the password contains at least one small English letter; the password contains at least one digit. You are given a password. Please implement the automatic check of its complexity for company Q.", "input_spec": "The first line contains a non-empty sequence of characters (at most 100 characters). Each character is either a large English letter, or a small English letter, or a digit, or one of characters: \"!\", \"?\", \".\", \",\", \"_\".", "output_spec": "If the password is complex enough, print message \"Correct\" (without the quotes), otherwise print message \"Too weak\" (without the quotes).", "sample_inputs": ["abacaba", "X12345", "CONTEST_is_STARTED!!11"], "sample_outputs": ["Too weak", "Too weak", "Correct"], "notes": null}, "positive_code": [{"source_code": "\n$_ = ;\nchomp;\n\nif ( /\\d/ && /[a-z]/ && /[A-Z]/ && (length >= 5) ){\n print \"Correct\";\n}else{\n print \"Too weak\";\n}"}, {"source_code": "$_=<>;print/.{5}/&/\\d/&/[a-z]/&/[A-Z]/?Correct:\"Too weak\"\n"}, {"source_code": "#Scott Heinrich - A01273823\nuse strict;\nuse warnings;\nuse 5.010;\n\nmy $password = <>;\nchomp($password);\n\nmy $strength = 0;\n\nif(length($password) > 4)\n{\n if($password =~ /\\d/ && $password =~ /[A-Z]/ && $password =~ /[a-z]/)\n {\n $strength = 1;\n }\n}\n\nif($strength)\n{\n say \"Correct\";\n}\nelse\n{\n say \"Too weak\";\n}\n"}, {"source_code": "$_=<>;print/.{5}/&/\\d/&/[a-z]/&/[A-Z]/?Correct:\"Too weak\"\n"}, {"source_code": "$_=<>;print/.{5}/&/\\d/&/[a-z]/&/[A-Z]/?Correct:\"Too weak\""}, {"source_code": "$_=<>;print/.{5}/&/\\d/&/[a-z]/&/[A-Z]/?Correct:\"Too weak\"\n"}, {"source_code": "$_=<>;print/.{5}/&/\\d/&/[a-z]/&/[A-Z]/?Correct:\"Too weak\"\n"}, {"source_code": "$_=<>;print/.{5}/&/\\d/&/[a-z]/&/[A-Z]/?Correct:\"Too weak\"\n"}, {"source_code": "$_=<>;print/.{5}/&/\\d/&/[a-z]/&/[A-Z]/?Correct:\"Too weak\""}, {"source_code": "$_=<>;print((/.{5,}/and/\\d/and/[a-z]/and/[A-Z]/)?\"Correct\":\"Too weak\")\n"}, {"source_code": "$_=<>;print((/.{5,}/&/\\d/&/[a-z]/&/[A-Z]/)?\"Correct\":\"Too weak\")\n"}, {"source_code": "$_=<>;print/.{5}/&/\\d/&/[a-z]/&/[A-Z]/?Correct:\"Too weak\""}, {"source_code": "$_=<>;print((/.{5}/and/\\d/and/[a-z]/and/[A-Z]/)?\"Correct\":\"Too weak\")"}, {"source_code": "$_=<>;print/.{5,}/&/\\d/&/[a-z]/&/[A-Z]/?Correct:\"Too weak\""}, {"source_code": "while (<>)\n{\n if (/^.{5,}$/ and /\\d/ and /[a-z]/ and /[A-Z]/)\n {\n print \"Correct\\n\";\n }\n else\n {\n print \"Too weak\\n\";\n }\n}\n"}, {"source_code": "print(<>=~/(?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{5,}/?\"Correct\":\"Too weak\")"}, {"source_code": "print(<>=~/(?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{5}/?\"Correct\":\"Too weak\")"}, {"source_code": "$s=<>;print($s=~/(?=.{5,})(?=.*\\d)(?=.*[a-z]).*[A-Z]/?\"Correct\":\"Too weak\")"}, {"source_code": "print(<>=~/(?=.{5,})(?=.*\\d)(?=.*[a-z]).*[A-Z]/?\"Correct\":\"Too weak\")\n"}, {"source_code": "print<>=~/(?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{5}/?\"Correct\":\"Too weak\""}, {"source_code": "while (<>){\nmy $input=($_);\nchomp($input);\nmy $pwdlength=length($input);\nif ($input =~ /[A-Z]/ and $input =~ /[a-z]/ and $input =~ /[0-9]/ and $pwdlength >= 5){\nprint \"Correct\";\n}\nelse{\nprint \"Too weak\";\n}\n}\n"}, {"source_code": "$_=<>;print/.{5}/&/\\d/&/[a-z]/&/[A-Z]/?Correct:\"Too weak\"\n"}, {"source_code": "$_=<>;print/.{5}/&/\\d/&/[a-z]/&/[A-Z]/?Correct:\"Too weak\"\n"}, {"source_code": "$_=<>;\nprint \n/...../ &&\n/[A-Z]/ &&\n/[0-9]/ &&\n/[a-z]/ ?\nCorrect : \"Too weak\""}, {"source_code": "$_=<>;\nchomp;\n\n/...../ or $f++;\n/[A-Z]/ or $f++;\n/[0-9]/ or $f++;\n/[a-z]/ or $f++;\n\nprint $f? \"Too weak\": \"Correct\""}, {"source_code": "$_=<>;print/.{5}/&/\\d/&/[a-z]/&/[A-Z]/?Correct:\"Too weak\"\n"}], "negative_code": [{"source_code": "<>;print/.{5}/&/\\d/&/[a-z]/&/[A-Z]/?Correct:\"Too weak\""}, {"source_code": "$_=<>;print(/.{5,}/and/\\d/and/[a-z]/and/[A-Z]/?\"Correct\":\"Too weak\")\n"}], "src_uid": "42a964b01e269491975965860ec92be7"} {"nl": {"description": "Let’s define a grid to be a set of tiles with 2 rows and 13 columns. Each tile has an English letter written in it. The letters don't have to be unique: there might be two or more tiles with the same letter written on them. Here is an example of a grid: ABCDEFGHIJKLMNOPQRSTUVWXYZ We say that two tiles are adjacent if they share a side or a corner. In the example grid above, the tile with the letter 'A' is adjacent only to the tiles with letters 'B', 'N', and 'O'. A tile is not adjacent to itself.A sequence of tiles is called a path if each tile in the sequence is adjacent to the tile which follows it (except for the last tile in the sequence, which of course has no successor). In this example, \"ABC\" is a path, and so is \"KXWIHIJK\". \"MAB\" is not a path because 'M' is not adjacent to 'A'. A single tile can be used more than once by a path (though the tile cannot occupy two consecutive places in the path because no tile is adjacent to itself).You’re given a string s which consists of 27 upper-case English letters. Each English letter occurs at least once in s. Find a grid that contains a path whose tiles, viewed in the order that the path visits them, form the string s. If there’s no solution, print \"Impossible\" (without the quotes).", "input_spec": "The only line of the input contains the string s, consisting of 27 upper-case English letters. Each English letter occurs at least once in s.", "output_spec": "Output two lines, each consisting of 13 upper-case English characters, representing the rows of the grid. If there are multiple solutions, print any of them. If there is no solution print \"Impossible\".", "sample_inputs": ["ABCDEFGHIJKLMNOPQRSGTUVWXYZ", "BUVTYZFQSNRIWOXXGJLKACPEMDH"], "sample_outputs": ["YXWVUTGHIJKLM\nZABCDEFSRQPON", "Impossible"], "notes": null}, "positive_code": [{"source_code": "$\\ = $/;\n\nprint <> =~ /(.*)(.)(.{1,25})\\2(.*)/ ? \n\tdo {\n\t\t$L = (length $3) / 2;\n\t\t\n\t\t$A = $1 . $2 . substr $3, 0, $L;\n\t\t$B = (substr $3, $L) . $4;\n\t\t\n\t\t$B =~ s/.{13}\\K(.+)// and ($carry = $1) and $A =~ s/^/$carry/;\n\t\t$A =~ s/(.+)(?=.{13}$)// and ($carry = $1) and $B =~ s/$/$carry/;\n\n\t\t\"$A\\n\" . reverse $B\n\t}\n\t:\n\t\t'Impossible'\n\t"}], "negative_code": [{"source_code": "$\\ = $/;\n\nprint <> =~ /(.*)(.)(.{1,24})\\2(.*)/ ? \n\tdo {\n\t\t$L = (length $3) / 2;\n\t\t\n\t\t$A = $1 . $2 . substr $3, 0, $L;\n\t\t$B = (substr $3, $L) . $4;\n\t\t\n\t\t$B =~ s/.{13}\\K(.+)// and ($carry = $1) and $A =~ s/^/$carry/;\n\t\t\n\t\t\"$A\\n\" . reverse $B\n\t}\n\t:\n\t\t'Impossible'\n\t"}, {"source_code": "$\\ = $/;\n\nprint <> =~ /(.*)(.)(.+)\\2(.*)/ ? \n\tdo {\n\t\t$L = (length $3) / 2;\n\t\t\n\t\t$A = $1 . $2 . substr $3, 0, $L;\n\t\t$B = (substr $3, $L) . $4;\n\t\t\n\t\t$B =~ s/.{13}\\K(.+)// and ($carry = $1) and $A =~ s/^/$carry/;\n\t\t\n\t\t\"$A\\n\" . reverse $B\n\t}\n\t:\n\t\t'Impossible'\n\t"}, {"source_code": "$\\ = $/;\n\nprint <> =~ /(.*)(.)(.+)\\2(.*)/ ? \n\tdo {\n\t\n\t\tprint \"[$1|$2|$3|$2|$4]\";\n\t\t\n\t\t$L = (length $3) / 2;\n\t\t\n\t\t$A = $1 . $2 . substr $3, 0, $L;\n\t\t$B = (substr $3, $L) . $4;\n\t\t\n\t\t$B =~ s/.{13}\\K(.+)// and ($carry = $1) and $A =~ s/^/$carry/;\n\t\t\n\t\t\"$A\\n\" . reverse $B\n\t}\n\t:\n\t\t'Impossible'\n\t"}, {"source_code": "$\\ = $/;\n\nprint <> =~ /(.*)(.)(.{1,24})\\2(.*)/ ? \n\tdo {\n\t\t$L = (length $3) / 2;\n\t\t\n\t\t$A = $1 . $2 . substr $3, 0, $L;\n\t\t$B = (substr $3, $L) . $4;\n\t\t\n\t\t$B =~ s/.{13}\\K(.+)// and ($carry = $1) and $A =~ s/^/$carry/;\n\t\t$A =~ s/(.+)(?=.{13}$)// and ($carry = $1) and $B =~ s/$/$carry/;\n\n\t\t\"$A\\n\" . reverse $B\n\t}\n\t:\n\t\t'Impossible'\n\t"}], "src_uid": "56c5ea443dec7a732802b16aed5b934d"} {"nl": {"description": "Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — concatenation of letters, which correspond to the stages.There are $$$n$$$ stages available. The rocket must contain exactly $$$k$$$ of them. Stages in the rocket should be ordered by their weight. So, after the stage with some letter can go only stage with a letter, which is at least two positions after in the alphabet (skipping one letter in between, or even more). For example, after letter 'c' can't go letters 'a', 'b', 'c' and 'd', but can go letters 'e', 'f', ..., 'z'.For the rocket to fly as far as possible, its weight should be minimal. The weight of the rocket is equal to the sum of the weights of its stages. The weight of the stage is the number of its letter in the alphabet. For example, the stage 'a 'weighs one ton,' b 'weighs two tons, and' z' — $$$26$$$ tons.Build the rocket with the minimal weight or determine, that it is impossible to build a rocket at all. Each stage can be used at most once.", "input_spec": "The first line of input contains two integers — $$$n$$$ and $$$k$$$ ($$$1 \\le k \\le n \\le 50$$$) – the number of available stages and the number of stages to use in the rocket. The second line contains string $$$s$$$, which consists of exactly $$$n$$$ lowercase Latin letters. Each letter defines a new stage, which can be used to build the rocket. Each stage can be used at most once.", "output_spec": "Print a single integer — the minimal total weight of the rocket or -1, if it is impossible to build the rocket at all.", "sample_inputs": ["5 3\nxyabd", "7 4\nproblem", "2 2\nab", "12 1\nabaabbaaabbb"], "sample_outputs": ["29", "34", "-1", "1"], "notes": "NoteIn the first example, the following rockets satisfy the condition: \"adx\" (weight is $$$1+4+24=29$$$); \"ady\" (weight is $$$1+4+25=30$$$); \"bdx\" (weight is $$$2+4+24=30$$$); \"bdy\" (weight is $$$2+4+25=31$$$).Rocket \"adx\" has the minimal weight, so the answer is $$$29$$$.In the second example, target rocket is \"belo\". Its weight is $$$2+5+12+15=34$$$.In the third example, $$$n=k=2$$$, so the rocket must have both stages: 'a' and 'b'. This rocket doesn't satisfy the condition, because these letters are adjacent in the alphabet. Answer is -1."}, "positive_code": [{"source_code": "($n, $k) = split \" \", <>; $_ = <>;\n\nfor $c (a..z) {\n\t/$c/ or next;\n\t$k or last;\n\t$k--;\n\t$o = ord $c;\n\t$d = chr($o+1);\n\ts/$c|$d//g;\n\t$ans += $o-96;\t\n}\n\nprint $k? -1: $ans;"}], "negative_code": [], "src_uid": "56b13d313afef9dc6c6ba2758b5ea313"} {"nl": {"description": "Apart from Nian, there is a daemon named Sui, which terrifies children and causes them to become sick. Parents give their children money wrapped in red packets and put them under the pillow, so that when Sui tries to approach them, it will be driven away by the fairies inside.Big Banban is hesitating over the amount of money to give out. He considers loops to be lucky since it symbolizes unity and harmony.He would like to find a positive integer n not greater than 1018, such that there are exactly k loops in the decimal representation of n, or determine that such n does not exist.A loop is a planar area enclosed by lines in the digits' decimal representation written in Arabic numerals. For example, there is one loop in digit 4, two loops in 8 and no loops in 5. Refer to the figure below for all exact forms. ", "input_spec": "The first and only line contains an integer k (1 ≤ k ≤ 106) — the desired number of loops.", "output_spec": "Output an integer — if no such n exists, output -1; otherwise output any such n. In the latter case, your output should be a positive decimal integer not exceeding 1018.", "sample_inputs": ["2", "6"], "sample_outputs": ["462", "8080"], "notes": null}, "positive_code": [{"source_code": "$_=<>;print$_>36?-1:8x($_/2).4x($_&1)"}, {"source_code": "$_=<>;print$_>36?-1:8x($_/2).4x($_&1)\n"}, {"source_code": "$_=<>;print $_>36?-1:8x($_/2).4x($_&1)\n"}, {"source_code": "print $_ > 36 ? -1 : 8 x ( $_ / 2 ) . 4 x ( $_ % 2 ) for <>"}, {"source_code": "#!/usr/bin/perl\n\nuse warnings;\nuse strict;\n\n$\\ = $/;\n\nwhile(<>){\n\tchomp;\n\t\n\tprint $_ > 36 ?\n\t\t-1\n\t\t:\n\t\t'8' x ( $_ / 2 ) . '4' x ( $_ % 2 )\n\t\n\t}"}], "negative_code": [{"source_code": "print <> > 36 ? -1 : 8 x ( $_ / 2 ) . 4 x ( $_ % 2 )"}], "src_uid": "0c9973792c1976c5710f88e3520cda4e"} {"nl": {"description": "In some game by Playrix it takes t minutes for an oven to bake k carrot cakes, all cakes are ready at the same moment t minutes after they started baking. Arkady needs at least n cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady can build one more similar oven to make the process faster, it would take d minutes to build the oven. While the new oven is being built, only old one can bake cakes, after the new oven is built, both ovens bake simultaneously. Arkady can't build more than one oven.Determine if it is reasonable to build the second oven, i.e. will it decrease the minimum time needed to get n cakes or not. If the time needed with the second oven is the same as with one oven, then it is unreasonable.", "input_spec": "The only line contains four integers n, t, k, d (1 ≤ n, t, k, d ≤ 1 000) — the number of cakes needed, the time needed for one oven to bake k cakes, the number of cakes baked at the same time, the time needed to build the second oven. ", "output_spec": "If it is reasonable to build the second oven, print \"YES\". Otherwise print \"NO\".", "sample_inputs": ["8 6 4 5", "8 6 4 6", "10 3 11 4", "4 2 1 4"], "sample_outputs": ["YES", "NO", "NO", "YES"], "notes": "NoteIn the first example it is possible to get 8 cakes in 12 minutes using one oven. The second oven can be built in 5 minutes, so after 6 minutes the first oven bakes 4 cakes, the second oven bakes 4 more ovens after 11 minutes. Thus, it is reasonable to build the second oven. In the second example it doesn't matter whether we build the second oven or not, thus it takes 12 minutes to bake 8 cakes in both cases. Thus, it is unreasonable to build the second oven.In the third example the first oven bakes 11 cakes in 3 minutes, that is more than needed 10. It is unreasonable to build the second oven, because its building takes more time that baking the needed number of cakes using the only oven."}, "positive_code": [{"source_code": "use warnings;\nuse strict;\n\nmy $line = ;\nchomp $line;\nmy ($req_cakes, $bake_time, $capacity, $time_to_build_oven) = split / /, $line;\n\n\n# for positive numbers only\nmy $ceil = sub {\n my $val = shift;\n if (($val - int($val)) > 0) {\n return int($val) + 1;\n } else {\n return int($val);\n }\n};\n\nmy $single_oven_time = $ceil->( $req_cakes / $capacity ) * $bake_time;\nmy $one_oven_cakes = $capacity * ($single_oven_time / $bake_time);\n\nmy $next_oven1 = $bake_time;\nmy $next_oven2 = $bake_time + $time_to_build_oven;\n\nmy $cakes = 0;\nmy $time = 0;\nwhile($cakes < $req_cakes and $time < $single_oven_time) {\n # find out which oven finishes next\n $time = $next_oven1 < $next_oven2 ? $next_oven1 : $next_oven2;\n $cakes += $capacity;\n\n if ($next_oven1 < $next_oven2) {\n $next_oven1 += $bake_time;\n } else {\n $next_oven2 += $bake_time;\n }\n}\n\n#warn \"1 oven: $one_oven_cakes after $single_oven_time;\\n\";\n#warn \"2 oven: $cakes after $time\\n\";\nif ($time < $single_oven_time) {\n print \"YES\";\n} else {\n print \"NO\";\n}\n\n"}, {"source_code": "#!/usr/bin/perl\n\nuse warnings;\nuse strict;\n\n$\\ = $/;\n\nmy $debug = 0;\n\nwhile(<>){\n\tmy( $n, $t, $k, $d ) = split;\n\t\n\tmy $sec = $t + $d;\n\t\n\tmy $N = 0;\n\tmy $T = 0;\n\t\n\twhile( $n > $N ){\n\t\t$N += $k;\n\t\t$T += $t;\n\t\t}\n\t\n\t$debug and print \"$N|$T\";\n\t\n\tprint $sec < $T ? \"YES\" : \"NO\";\n\t\n\t}"}], "negative_code": [], "src_uid": "32c866d3d394e269724b4930df5e4407"} {"nl": {"description": "Let quasi-palindromic number be such number that adding some leading zeros (possible none) to it produces a palindromic string. String t is called a palindrome, if it reads the same from left to right and from right to left.For example, numbers 131 and 2010200 are quasi-palindromic, they can be transformed to strings \"131\" and \"002010200\", respectively, which are palindromes.You are given some integer number x. Check if it's a quasi-palindromic number.", "input_spec": "The first line contains one integer number x (1 ≤ x ≤ 109). This number is given without any leading zeroes.", "output_spec": "Print \"YES\" if number x is quasi-palindromic. Otherwise, print \"NO\" (without quotes).", "sample_inputs": ["131", "320", "2010200"], "sample_outputs": ["YES", "NO", "YES"], "notes": null}, "positive_code": [{"source_code": "print <> =~ /^((.)(?1)\\2|.|)0*$/? YES: NO\n"}, {"source_code": "my $num = ;\nchomp $num;\nwhile ((substr $num, -1,1) == '0'){\n\t$num /= 10;\n}\n$len = length $num;\nfor (my $i = 1; $i <= $len; $i++){\n\t$a[$i] = substr $num, -$i,1;\n}\n$rev_num = join('', @a[1..$len]);\n\nif ($num == $rev_num){\n\tprint \"YES\";\n}\nelse{\n\tprint \"NO\";\n}"}], "negative_code": [{"source_code": "print \"Please Enter a Number: \";\nmy $num = ;\nchomp $num;\nwhile ((substr $num, -1,1) == '0'){\n\t$num /= 10;\n}\n$len = length $num;\nfor (my $i = 1; $i <= $len; $i++){\n\t$a[$i] = substr $num, -$i,1;\n}\n$rev_num = join('', @a[1..$len]);\n\nif ($num == $rev_num){\n\tprint \"YES\";\n}\nelse{\n\tprint \"NO\";\n}"}], "src_uid": "d82278932881e3aa997086c909f29051"} {"nl": {"description": "Johny likes numbers n and k very much. Now Johny wants to find the smallest integer x greater than n, so it is divisible by the number k.", "input_spec": "The only line contains two integers n and k (1 ≤ n, k ≤ 109).", "output_spec": "Print the smallest integer x > n, so it is divisible by the number k.", "sample_inputs": ["5 3", "25 13", "26 13"], "sample_outputs": ["6", "26", "39"], "notes": null}, "positive_code": [{"source_code": "($n,$k)=split(' ',<>); $r=$n+$k-$n%$k; print $r;"}, {"source_code": "$input=;\nchomp($input);\n@input=split(/ /, $input);\n$n=int(@input[0]);\n$k=int(@input[1]);\n\n$answer=int($n/$k)*$k;\n\nif( $answer <= $n )\n{\n\t$answer += $k;\n}\n\nprint $answer.\"\\n\";\n\n\n"}, {"source_code": "($n,$k)=split ' ',<>;print$n+$k-$n%$k"}], "negative_code": [], "src_uid": "75f3835c969c871a609b978e04476542"} {"nl": {"description": "There are five people playing a game called \"Generosity\". Each person gives some non-zero number of coins b as an initial bet. After all players make their bets of b coins, the following operation is repeated for several times: a coin is passed from one player to some other player.Your task is to write a program that can, given the number of coins each player has at the end of the game, determine the size b of the initial bet or find out that such outcome of the game cannot be obtained for any positive number of coins b in the initial bet.", "input_spec": "The input consists of a single line containing five integers c1, c2, c3, c4 and c5 — the number of coins that the first, second, third, fourth and fifth players respectively have at the end of the game (0 ≤ c1, c2, c3, c4, c5 ≤ 100).", "output_spec": "Print the only line containing a single positive integer b — the number of coins in the initial bet of each player. If there is no such value of b, then print the only value \"-1\" (quotes for clarity).", "sample_inputs": ["2 5 4 0 4", "4 5 9 2 1"], "sample_outputs": ["3", "-1"], "notes": "NoteIn the first sample the following sequence of operations is possible: One coin is passed from the fourth player to the second player; One coin is passed from the fourth player to the fifth player; One coin is passed from the first player to the third player; One coin is passed from the fourth player to the second player. "}, "positive_code": [{"source_code": "my @arr = split \" \", <>;\nmy $sum = eval join \"+\", @arr;\nprint $sum % 5 == 0 && $sum > 0? $sum / 5 : -1;"}, {"source_code": "my @c = split \" \", <>;\nmy $sum = 0;\n$sum += int($_) foreach(@c);\nprint ($sum % 5 == 0 ? ($sum > 0 ? $sum/5 : \"-1\\n\") : \"-1\\n\");"}, {"source_code": "#!/usr/bin/perl\n# your code goes here\nuse v5.10;\n\n$tot+=$_ foreach(split / /, <>);\n$tot>0 and $tot%5==0 and say $tot/5 or say -1;"}, {"source_code": "use List::Util qw(first max maxstr min minstr reduce shuffle sum);\n\nchomp (my @arr = split /\\s+/, <>);\nmy $val = &sum (@arr);\n\nif ((($val % 5) != 0) || ($val == 0)) {\n printf \"-1\\n\";\n} else {\n printf \"%d\\n\", $val / 5;\n}"}, {"source_code": "#!/usr/bin/perl -w\nuse strict;\n\n$\\ = \"\\n\";\nmy @a = split ' ', <>;\nmy $s = 0;\nfor my $x (@a) { $s += $x }\nprint $s % 5 == 0 && $s > 0 ? $s / 5 : -1;\n"}, {"source_code": "my @arr = split /\\s+/, <>;\nmy @sum = 0;\n$sum += $_ foreach @arr;\nif ($sum % 5 == 0 and $sum > 0) {\n print $sum / 5, \"\\n\";\n} else {\n print -1; \n}"}, {"source_code": "#!/usr/bin/env perl \n#===============================================================================\n# FILE: a.pl\n# AUTHOR: Phoenix Ikki (liuxueyang.github.io), liuxueyang457@gmail.com\n# ORGANIZATION: Hunan University\n# CREATED: 10/18/2014 10:54:41 PM\n#===============================================================================\n\nuse strict;\nuse warnings;\nuse utf8;\n\nmy ($a, $b, $c, $d, $e, $input);\nchomp($input = );\n($a, $b, $c, $d, $e) = split / /, $input;\nmy $sum = $a + $b + $c + $d + $e;\nmy $result;\nif ($sum != 0 && $sum % 5 == 0)\n{\n\t$result = $sum / 5;\n}\nelse {\n\t$result = -1;\n}\n\n\nprint \"$result\\n\"\n"}, {"source_code": "#!/usr/bin/perl\n# your code here\n\nchomp(my $string=);\nmy @array = split / /, $string;\nmy $answer = 0;\nforeach(@array){\n $answer = $answer+$_;\n}\nif($answer !=0 ){\n if($answer%5 == 0){\n print $answer/5;\n }\n else{\n print \"-1\\n\";\n }\n}\nelse{\n print \"-1\\n\";\n}\n"}, {"source_code": "$s+=$_ for split/ /,<>;\nprint !$s || $s % 5? -1:($s / 5)"}, {"source_code": "@_=split/ /,<>;\n$sum+=$_ for @_;\n$sum==0 and $f++;\n$sum % 5 ==0 or $f++;\nprint $f? -1:($sum / 5)"}], "negative_code": [{"source_code": "use List::Util qw(sum);\nmy @arr = split \" \", <>;\nmy $sum = sum (@arr);\nprint $sum % 5 == 0? $sum / 5 : -1;"}, {"source_code": "my @c = split \" \", <>;\nmy $sum = 0;\n$sum += int($_) foreach(@c);\nprint ($sum % 5 == 0 ? $sum/5 : \"-1\\n\");"}, {"source_code": "use List::Util qw(first max maxstr min minstr reduce shuffle sum);\n\nchomp (my @arr = split /\\s*/, <>);\nmy $val = &sum (@arr);\n\nif (($val % 5) == 0) {\n printf \"%d\\n\", $val / 5;\n} else {\n printf \"-1\\n\";\n}"}, {"source_code": "use List::Util qw(first max maxstr min minstr reduce shuffle sum);\n\nchomp (my @arr = split /\\s+/, <>);\nmy $val = &sum (@arr);\n\nif (($val % 5) == 0) {\n printf \"%d\\n\", $val / 5;\n} else {\n printf \"-1\\n\";\n}"}, {"source_code": "#!/usr/bin/perl -w\nuse strict;\n\n$\\ = \"\\n\";\nmy @a = split ' ', <>;\nmy $s = 0;\nfor my $x (@a) { $s += $x }\nprint $s % 5 == 0 ? $s / 5 : -1;\n"}, {"source_code": "#!/usr/bin/env perl \n#===============================================================================\n# FILE: a.pl\n# AUTHOR: Phoenix Ikki (liuxueyang.github.io), liuxueyang457@gmail.com\n# ORGANIZATION: Hunan University\n# CREATED: 10/18/2014 10:54:41 PM\n#===============================================================================\n\nuse strict;\nuse warnings;\nuse utf8;\n\nmy ($a, $b, $c, $d, $e, $input);\nchomp($input = );\n($a, $b, $c, $d, $e) = split / /, $input;\nmy $sum = $a + $b + $c + $d + $e;\nmy $result;\nif ($sum % 5 == 0)\n{\n\t$result = $sum / 5;\n}\nelse {\n\t$result = -1;\n}\n\n\nprint \"$result\\n\"\n"}, {"source_code": "#!/usr/bin/perl\n# your code here\n\nchomp(my $string=);\nmy @array = split / /, $string;\nmy $answer = 0;\nforeach(@array){\n $answer = $answer+$_;\n}\n\nif($answer%5 == 0){\n print $answer/5;\n}\nelse{\n print \"-1\";\n}\n"}], "src_uid": "af1ec6a6fc1f2360506fc8a34e3dcd20"} {"nl": {"description": "A and B are preparing themselves for programming contests.To train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose position is now stronger.For each chess piece we know its weight: the queen's weight is 9, the rook's weight is 5, the bishop's weight is 3, the knight's weight is 3, the pawn's weight is 1, the king's weight isn't considered in evaluating position. The player's weight equals to the sum of weights of all his pieces on the board.As A doesn't like counting, he asked you to help him determine which player has the larger position weight.", "input_spec": "The input contains eight lines, eight characters each — the board's description. The white pieces on the board are marked with uppercase letters, the black pieces are marked with lowercase letters. The white pieces are denoted as follows: the queen is represented is 'Q', the rook — as 'R', the bishop — as'B', the knight — as 'N', the pawn — as 'P', the king — as 'K'. The black pieces are denoted as 'q', 'r', 'b', 'n', 'p', 'k', respectively. An empty square of the board is marked as '.' (a dot). It is not guaranteed that the given chess position can be achieved in a real game. Specifically, there can be an arbitrary (possibly zero) number pieces of each type, the king may be under attack and so on.", "output_spec": "Print \"White\" (without quotes) if the weight of the position of the white pieces is more than the weight of the position of the black pieces, print \"Black\" if the weight of the black pieces is more than the weight of the white pieces and print \"Draw\" if the weights of the white and black pieces are equal.", "sample_inputs": ["...QK...\n........\n........\n........\n........\n........\n........\n...rk...", "rnbqkbnr\npppppppp\n........\n........\n........\n........\nPPPPPPPP\nRNBQKBNR", "rppppppr\n...k....\n........\n........\n........\n........\nK...Q...\n........"], "sample_outputs": ["White", "Draw", "Black"], "notes": "NoteIn the first test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals 5.In the second test sample the weights of the positions of the black and the white pieces are equal to 39.In the third test sample the weight of the position of the white pieces equals to 9, the weight of the position of the black pieces equals to 16."}, "positive_code": [{"source_code": "#!/usr/bin/env perl\nuse v5.10;use strict;use warnings;use Data::Dumper;\nsub min{my($a,$b)=@_;return$a if($a<$b);return$b;}sub max{my($a,$b)=@_;return$a\nif($a>$b);return$b;}sub out{foreach my$c(@_){print\"$c \";}print(\"\\n\");}my$TESTAM=\n1;sub input{my$r=<>;chomp$r;$r}\n \n#$TESTAM = ;\nsub {\n my %w = (\n 'q' => 9, \n 'r' => 5, \n 'b' => 3, \n 'n' => 3, \n 'p' => 1, \n 'k' => 0, \n '.' => 0,\n );\n my ($white, $black) = (0, 0);\n foreach my $i (1..8) {\n foreach my $c (split(\"\", input())) {\n $white += $w{lc($c)} if ($c eq uc($c));\n $black += $w{lc($c)} if ($c eq lc($c));\n\t\t}\n\t}\n \n if ($white == $black) {\n say \"Draw\";\n\t} elsif ($white < $black) {\n\t\tsay \"Black\";\n\t} else {\n say \"White\";\n\t}\n}->() while ($TESTAM--);"}, {"source_code": "my $ans = \"White\";\nmy %hash = ('q' => 9, 'r' => 5, 'b' => 3, 'n' => 3, 'p' => 1, 'k' => 0);\nmy $winner = 0;\nfor (0..7) {\n $winner += exists($hash{lc $_}) ? ($_ eq lc $_ ? -$hash{$_} : $hash{lc $_}) : 0 foreach (split //, <>);\n}\n$ans = \"Black\\n\" if ($winner < 0);\n$ans = \"Draw\\n\" if ($winner == 0);\nprint $ans;\n"}, {"source_code": "#!/usr/bin/perl\n# your code goes here\nuse v5.10;\n\n%tb = (\n\tq => 9,\n\tQ => 9,\n\tr => 5,\n\tR => 5,\n\tb => 3,\n\tB => 3,\n\tn => 3,\n\tN => 3,\n\tk => 0,\n\tK => 0,\n\tp => 1,\n\tP => 1,\n\t'.' => 0,\n);\n($white, $black) = (0, 0);\nwhile (<>) {\n\tchomp;\n\tforeach (split //) {\n\t\tif ($_ ge 'a' && $_ le 'z') {\n\t\t\t$black += $tb{$_};\n\t\t} else {\n\t\t\t$white += $tb{$_};\n\t\t}\n\t}\n}\nif ($black > $white) {\n\tsay \"Black\";\n} elsif ($black < $white) {\n\tsay \"White\";\n} else {\n\tsay \"Draw\";\n}\n"}, {"source_code": "my %wt = (\n Q => 9,\n R => 5,\n B => 3,\n N => 3,\n P => 1,\n q => 9,\n r => 5,\n b => 3,\n n => 3,\n p => 1,\n);\n\nmy (@x, $w, $b);\nforeach (1 .. 8) {\n chomp (@x = split /\\s*/, );\n\n foreach (@x) {\n next if (not exists $wt{$_});\n if ($_ eq lc($_)) {\n $b += $wt{$_}\n } else {\n $w += $wt{$_}\n }\n }\n}\n\nif ($w == $b) { printf \"Draw\\n\"; exit}\nif ($w > $b) { printf \"White\\n\"; exit}\nif ($w < $b) { printf \"Black\\n\"; exit}\n"}, {"source_code": "use 5.016;\nuse strict;\nuse warnings;\n\nsub count_black {\n local $_ = shift;\n tr/q//d * 9 + tr/r//d * 5 + tr/b//d * 3 + tr/n//d * 3 + tr/p//d;\n}\n\nsub count_white {\n local $_ = shift;\n tr/Q//d * 9 + tr/R//d * 5 + tr/B//d * 3 + tr/N//d * 3 + tr/P//d;\n}\n\nundef $/;\nmy $input = <>;\n\nsay qw(White Draw Black)[(count_black($input) <=> count_white($input)) + 1];\n"}, {"source_code": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\nmy %w = ('q' => 9, 'r'=> 5, 'b'=> 3, 'n'=> 3, 'p'=> 1, 'k'=> 0);\nmy ($black, $white) = (0,0);\nwhile(<>){\n my @line = split '';\n foreach(@line){\n $black += $w{$_} if $_ =~ /[a-z]/;\n $white += $w{lc $_} if $_ =~ /[A-Z]/;\n }\n}\nif($black == $white){ print \"Draw\\n\";}\nelse{ print $white > $black ? \"White\\n\" : \"Black\\n\";}\n"}, {"source_code": "%h = qw(\nq 9\nr 5\nn 3\nb 3\np 1\n);\nprint qw(Draw White Black)[0 <=> eval join '+', map 2 * $h{ $_ } - $h{ (lc) }, split '', join '', <>]"}, {"source_code": "local $/;\n$_ = <>;\n%h = qw(\nq 9\nr 5\nn 3\nb 3\np 1\nk 0\n);\n($c = $&) =~ /[a-z]/ ? ( $b += $h{$c} ):( $w += $h{lc $c} ) while /[a-z]/imsg;\nprint qw(Draw Black White)[$b <=> $w]"}], "negative_code": [{"source_code": "#!/usr/bin/perl\n# your code goes here\nuse v5.10;\n\n%tb = (\n\tq => 9,\n\tQ => 9,\n\tr => 5,\n\tR => 5,\n\tb => 3,\n\tB => 3,\n\tk => 3,\n\tK => 3,\n\tp => 1,\n\tP => 1,\n\t'.' => 0,\n);\n($white, $black) = (0, 0);\nwhile (<>) {\n\tchomp;\n\tforeach (split //) {\n\t\tif ($_ ge 'a' && $_ le 'z') {\n\t\t\t$black += $tb{$_};\n\t\t} else {\n\t\t\t$white += $tb{$_};\n\t\t}\n\t}\n}\nif ($black > $white) {\n\tsay \"Black\";\n} elsif ($black < $white) {\n\tsay \"White\";\n} else {\n\tsay \"Draw\";\n}\n"}], "src_uid": "44bed0ca7a8fb42fb72c1584d39a4442"} {"nl": {"description": "Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to . Then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters. There the properties of the hexagon ended and Gerald decided to draw on it.He painted a few lines, parallel to the sides of the hexagon. The lines split the hexagon into regular triangles with sides of 1 centimeter. Now Gerald wonders how many triangles he has got. But there were so many of them that Gerald lost the track of his counting. Help the boy count the triangles.", "input_spec": "The first and the single line of the input contains 6 space-separated integers a1, a2, a3, a4, a5 and a6 (1 ≤ ai ≤ 1000) — the lengths of the sides of the hexagons in centimeters in the clockwise order. It is guaranteed that the hexagon with the indicated properties and the exactly such sides exists.", "output_spec": "Print a single integer — the number of triangles with the sides of one 1 centimeter, into which the hexagon is split.", "sample_inputs": ["1 1 1 1 1 1", "1 2 1 2 1 2"], "sample_outputs": ["6", "13"], "notes": "NoteThis is what Gerald's hexagon looks like in the first sample:And that's what it looks like in the second sample:"}, "positive_code": [{"source_code": "$_ = <>;\n($a, $b, $C, $D, $e, $f) = split;\n$D < $f and ($D, $f) = ($f, $D);\n$C < $a and ($C, $a) = ($a, $C);\n$df = $D - $f;\n$dc = $C - $a;\n\nprint 0\n+ ($f + $e)**2 - $e**2\n+ ($a + $b)**2 - $b**2\n+ $dc * ($a + $b) * 2"}], "negative_code": [{"source_code": "$_ = <>;\n($a, $b, $C, $D, $e, $f) = split;\n$D < $f and ($D, $f) = ($f, $D);\n$C < $a and ($C, $a) = ($a, $C);\n$df = $D - $f;\n$dc = $C - $a;\n\nprint 0\n+ ($f + $e)**2 - $e**2\n+ ($a + $b)**2 - $b**2\n+ $df * $f * 2\n+ $dc * $a * 2"}], "src_uid": "382475475427f0e76c6b4ac6e7a02e21"} {"nl": {"description": "Mislove had an array $$$a_1$$$, $$$a_2$$$, $$$\\cdots$$$, $$$a_n$$$ of $$$n$$$ positive integers, but he has lost it. He only remembers the following facts about it: The number of different numbers in the array is not less than $$$l$$$ and is not greater than $$$r$$$; For each array's element $$$a_i$$$ either $$$a_i = 1$$$ or $$$a_i$$$ is even and there is a number $$$\\dfrac{a_i}{2}$$$ in the array.For example, if $$$n=5$$$, $$$l=2$$$, $$$r=3$$$ then an array could be $$$[1,2,2,4,4]$$$ or $$$[1,1,1,1,2]$$$; but it couldn't be $$$[1,2,2,4,8]$$$ because this array contains $$$4$$$ different numbers; it couldn't be $$$[1,2,2,3,3]$$$ because $$$3$$$ is odd and isn't equal to $$$1$$$; and it couldn't be $$$[1,1,2,2,16]$$$ because there is a number $$$16$$$ in the array but there isn't a number $$$\\frac{16}{2} = 8$$$.According to these facts, he is asking you to count the minimal and the maximal possible sums of all elements in an array. ", "input_spec": "The only input line contains three integers $$$n$$$, $$$l$$$ and $$$r$$$ ($$$1 \\leq n \\leq 1\\,000$$$, $$$1 \\leq l \\leq r \\leq \\min(n, 20)$$$) — an array's size, the minimal number and the maximal number of distinct elements in an array.", "output_spec": "Output two numbers — the minimal and the maximal possible sums of all elements in an array.", "sample_inputs": ["4 2 2", "5 1 5"], "sample_outputs": ["5 7", "5 31"], "notes": "NoteIn the first example, an array could be the one of the following: $$$[1,1,1,2]$$$, $$$[1,1,2,2]$$$ or $$$[1,2,2,2]$$$. In the first case the minimal sum is reached and in the last case the maximal sum is reached.In the second example, the minimal sum is reached at the array $$$[1,1,1,1,1]$$$, and the maximal one is reached at the array $$$[1,2,4,8,16]$$$."}, "positive_code": [{"source_code": "\nuse strict;\nuse warnings;\n\nuse Data::Dumper;\n\nsub main {\n\n my $in= *STDIN;\n my $q= <$in>; chomp($q);\n\n my ($n, $l, $r)= split(' ', $q);\n\n my $v= 1;\n my $low_sum= 0;\n for (my $i = $l; $i > 0; $i--) {\n $low_sum += $v;\n $v *= 2;\n }\n $low_sum += ($n - $l);\n\n $v= 1;\n my $max_sum= 0;\n for (my $i = $r; $i > 0; $i--) {\n $max_sum += $v;\n $v *= 2;\n }\n\n $max_sum += (($n - $r) * ($v/2));\n\n print \"$low_sum $max_sum\";\n\n}\n\nmain() unless caller();\n\n"}], "negative_code": [], "src_uid": "ce220726392fb0cacf0ec44a7490084a"} {"nl": {"description": "Maxim wants to buy an apartment in a new house at Line Avenue of Metropolis. The house has n apartments that are numbered from 1 to n and are arranged in a row. Two apartments are adjacent if their indices differ by 1. Some of the apartments can already be inhabited, others are available for sale.Maxim often visits his neighbors, so apartment is good for him if it is available for sale and there is at least one already inhabited apartment adjacent to it. Maxim knows that there are exactly k already inhabited apartments, but he doesn't know their indices yet.Find out what could be the minimum possible and the maximum possible number of apartments that are good for Maxim.", "input_spec": "The only line of the input contains two integers: n and k (1 ≤ n ≤ 109, 0 ≤ k ≤ n).", "output_spec": "Print the minimum possible and the maximum possible number of apartments good for Maxim.", "sample_inputs": ["6 3"], "sample_outputs": ["1 3"], "notes": "NoteIn the sample test, the number of good apartments could be minimum possible if, for example, apartments with indices 1, 2 and 3 were inhabited. In this case only apartment 4 is good. The maximum possible number could be, for example, if apartments with indices 1, 3 and 5 were inhabited. In this case all other apartments: 2, 4 and 6 are good."}, "positive_code": [{"source_code": "#!/usr/bin/perl\n\nuse warnings;\nuse strict;\n\n$\\ = $/;\n\nwhile(<>){\n\tmy( $n, $k ) = split;\n\t\n\tprint do { \n\t\tif( $n == $k || $k == 0 ){\n\t\t\t\"0 0\";\n\t\t\t}\n\t\telse{\n\t\t\tmy $x = $n - $k;\n\t\t\tmy $min = ( sort { $a <=> $b } $x, $k * 2 )[ 0 ];\n\t\t\t\"1 $min\";\n\t\t\t}\n\t\t};\n\t}"}, {"source_code": "( $n, $k ) = split ' ', <>;\n\t\nprint 1 - $k =~ /^(0|$n)$/, ' ', ( sort { $a <=> $b } $n - $k, $k * 2 )[ 0 ]"}], "negative_code": [], "src_uid": "bdccf34b5a5ae13238c89a60814b9f86"} {"nl": {"description": "Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: \"If you solve the following problem, I'll return it to you.\" The problem is: You are given a lucky number n. Lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.If we sort all lucky numbers in increasing order, what's the 1-based index of n? Tavas is not as smart as SaDDas, so he asked you to do him a favor and solve this problem so he can have his headphones back.", "input_spec": "The first and only line of input contains a lucky number n (1 ≤ n ≤ 109).", "output_spec": "Print the index of n among all lucky numbers.", "sample_inputs": ["4", "7", "77"], "sample_outputs": ["1", "2", "6"], "notes": null}, "positive_code": [{"source_code": "$_ = <>, y/47/01/,\nprint -1 + oct \"0b1$_\"\n"}, {"source_code": "$_ = <>, y/47/01/,\nprint -1 + oct \"0b1$_\"\n"}, {"source_code": "$_ = <>, y/47/01/,\nprint -1 + oct \"0b1$_\""}, {"source_code": "$_ = <>, y/47/01/,\nprint -1 + oct \"0b1$_\"\n"}, {"source_code": "$_ = <>, y/47/01/,\nprint -1 + oct \"0b1$_\"\n"}, {"source_code": "#!/usr/bin/perl\nuse v5.10;\n\nchomp($line = <>);\n$len = length $line;\n$ans = 0;\nforeach (split //, $line) {\n\t$ans <<= 1;\n\t$_ eq '7' and ++$ans;\n}\n$ans += 2**$len-1;\nsay $ans;"}, {"source_code": "#!perl\n\n$\\ = \"\\n\";\n\n$l = <>;\nchomp $l;\n$l =~ s/\\d/{$& == 4 ? 0 : 1;}/ge;\n@a = reverse (split //, $l);\n\n$n = 0;\n\nfor (1..$#a)\n{\n $n += 2**$_;\n}\n\nfor (0..$#a)\n{ \n $n += @a[$_]*2**$_;\n}\n\nprint $n + 1;"}, {"source_code": "$_ = <>, y/47/01/,\nprint -1 + oct \"0b1$_\"\n"}, {"source_code": "$_ = <>, y/47/01/,\nprint -1 + oct \"0b1$_\"\n"}, {"source_code": "$_ = <>, y/47/01/,\nprint -1 + oct \"0b1$_\"\n"}, {"source_code": "$_ = <>, y/47/01/,\nprint -1 + oct \"0b1$_\""}, {"source_code": "#\tuse integer;\n#\tuse List::Util qw(max maxstr min minstr sum);\n$\\ = $/;\n\nwhile(<>){\n\tchomp;\n\ty/47/12/;\n\t$n = 0;\n\ts/./ $n *= 2, $n += $&, '' /ge;\n\tprint $n\n\t}"}, {"source_code": "$_ = <>, y/47/01/,\nprint -1 + oct \"0b1$_\"\n"}], "negative_code": [], "src_uid": "6a10bfe8b3da9c11167e136b3c6fb2a3"} {"nl": {"description": "In the city of Ultima Thule job applicants are often offered an IQ test. The test is as follows: the person gets a piece of squared paper with a 4 × 4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the picture has a 2 × 2 square, completely consisting of cells of the same color. If the initial picture already has such a square, the person should just say so and the test will be completed. Your task is to write a program that determines whether it is possible to pass the test. You cannot pass the test if either repainting any cell or no action doesn't result in a 2 × 2 square, consisting of cells of the same color.", "input_spec": "Four lines contain four characters each: the j-th character of the i-th line equals \".\" if the cell in the i-th row and the j-th column of the square is painted white, and \"#\", if the cell is black.", "output_spec": "Print \"YES\" (without the quotes), if the test can be passed and \"NO\" (without the quotes) otherwise.", "sample_inputs": ["####\n.#..\n####\n....", "####\n....\n####\n...."], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first test sample it is enough to repaint the first cell in the second row. After such repainting the required 2 × 2 square is on the intersection of the 1-st and 2-nd row with the 1-st and 2-nd column."}, "positive_code": [{"source_code": "sub find {\n\tforeach (0 .. 3) {\n\t\tchomp ($n = );\n\t\t$n =~ tr/#./10/;\n\t\t@{$a[$_]} = split //, $n;\n\t}\n\n\tif (($a[0][0] + $a[0][1] + $a[1][0] + $a[1][1]) >= 3) { printf \"YES\\n\"; return }\n\tif (($a[0][1] + $a[0][2] + $a[1][1] + $a[1][2]) >= 3) { printf \"YES\\n\"; return }\n\tif (($a[0][2] + $a[0][3] + $a[1][2] + $a[1][3]) >= 3) { printf \"YES\\n\"; return }\n\tif (($a[1][0] + $a[1][1] + $a[2][0] + $a[2][1]) >= 3) { printf \"YES\\n\"; return }\n\tif (($a[1][1] + $a[1][2] + $a[2][1] + $a[2][2]) >= 3) { printf \"YES\\n\"; return }\n\tif (($a[1][2] + $a[1][3] + $a[2][2] + $a[2][3]) >= 3) { printf \"YES\\n\"; return }\n\tif (($a[2][0] + $a[2][1] + $a[3][0] + $a[3][1]) >= 3) { printf \"YES\\n\"; return }\n\tif (($a[2][1] + $a[2][2] + $a[3][1] + $a[3][2]) >= 3) { printf \"YES\\n\"; return }\n\tif (($a[2][2] + $a[2][3] + $a[3][2] + $a[3][3]) >= 3) { printf \"YES\\n\"; return }\n\n\tif (($a[0][0] + $a[0][1] + $a[1][0] + $a[1][1]) <= 1) { printf \"YES\\n\"; return }\n\tif (($a[0][1] + $a[0][2] + $a[1][1] + $a[1][2]) <= 1) { printf \"YES\\n\"; return }\n\tif (($a[0][2] + $a[0][3] + $a[1][2] + $a[1][3]) <= 1) { printf \"YES\\n\"; return }\n\tif (($a[1][0] + $a[1][1] + $a[2][0] + $a[2][1]) <= 1) { printf \"YES\\n\"; return }\n\tif (($a[1][1] + $a[1][2] + $a[2][1] + $a[2][2]) <= 1) { printf \"YES\\n\"; return }\n\tif (($a[1][2] + $a[1][3] + $a[2][2] + $a[2][3]) <= 1) { printf \"YES\\n\"; return }\n\tif (($a[2][0] + $a[2][1] + $a[3][0] + $a[3][1]) <= 1) { printf \"YES\\n\"; return }\n\tif (($a[2][1] + $a[2][2] + $a[3][1] + $a[3][2]) <= 1) { printf \"YES\\n\"; return }\n\tif (($a[2][2] + $a[2][3] + $a[3][2] + $a[3][3]) <= 1) { printf \"YES\\n\"; return }\n\n\tprintf \"NO\\n\"; return\n}\n\n&find();\n"}], "negative_code": [], "src_uid": "01b145e798bbdf0ca2ecc383676d79f3"} {"nl": {"description": "You know that Japan is the country with almost the largest 'electronic devices per person' ratio. So you might be quite surprised to find out that the primary school in Japan teaches to count using a Soroban — an abacus developed in Japan. This phenomenon has its reasons, of course, but we are not going to speak about them. Let's have a look at the Soroban's construction. Soroban consists of some number of rods, each rod contains five beads. We will assume that the rods are horizontal lines. One bead on each rod (the leftmost one) is divided from the others by a bar (the reckoning bar). This single bead is called go-dama and four others are ichi-damas. Each rod is responsible for representing a single digit from 0 to 9. We can obtain the value of a digit by following simple algorithm: Set the value of a digit equal to 0. If the go-dama is shifted to the right, add 5. Add the number of ichi-damas shifted to the left. Thus, the upper rod on the picture shows digit 0, the middle one shows digit 2 and the lower one shows 7. We will consider the top rod to represent the last decimal digit of a number, so the picture shows number 720.Write the program that prints the way Soroban shows the given number n.", "input_spec": "The first line contains a single integer n (0 ≤ n < 109).", "output_spec": "Print the description of the decimal digits of number n from the last one to the first one (as mentioned on the picture in the statement), one per line. Print the beads as large English letters 'O', rod pieces as character '-' and the reckoning bar as '|'. Print as many rods, as many digits are in the decimal representation of number n without leading zeroes. We can assume that number 0 has no leading zeroes.", "sample_inputs": ["2", "13", "720"], "sample_outputs": ["O-|OO-OO", "O-|OOO-O\nO-|O-OOO", "O-|-OOOO\nO-|OO-OO\n-O|OO-OO"], "notes": null}, "positive_code": [{"source_code": "%digit = (\n\t'0' => \"O-|-OOOO\",\n\t'1' => \"O-|O-OOO\",\n\t'2' => \"O-|OO-OO\",\n\t'3'\t=> \"O-|OOO-O\",\n\t'4' => \"O-|OOOO-\",\n\t'5' => \"-O|-OOOO\",\n\t'6' => \"-O|O-OOO\",\n\t'7' => \"-O|OO-OO\",\n\t'8' => \"-O|OOO-O\",\n\t'9' => \"-O|OOOO-\",\n);\nchomp($n=<>);\nprint $digit{$_},\"\\n\" foreach reverse split //, $n;;\n"}, {"source_code": "$n = <>;\nif($n == 0)\n{\n print(\"O-|-OOOO\\n\");\n}\nwhile($n > 0)\n{\n $cur = $n % 10;\n $n -= $cur;\n $n /= 10;\n print \"-O|\" if ($cur >= 5);\n print \"O-|\" if ($cur < 5);\n\n print('O' x ($cur % 5));\n print('-');\n print('O' x (4 - ($cur % 5)));\n print \"\\n\";\n #print(\"$n\\n\");\n}"}, {"source_code": "print (($_ >= 0 && $_ <= 4 ? \"O-|\" : \"-O|\") . \"O\" x ($_ % 5) . \"-\" . (\"O\" x (4 - ($_ % 5))), \"\\n\") foreach (reverse <> =~ /(\\d)/g);"}, {"source_code": "print (($_ >= 0 && $_ <= 4 ? \"O-|\" : \"-O|\") . \"O\" x ($_ % 5) . \"-\" . (\"O\" x (4 - ($_ % 5))), \"\\n\") foreach (reverse grep { !($_ =~ /\\n|\\r/) } split //, <>);"}, {"source_code": "#!/usr/bin/perl\nprint $_ >= 0 && $_ <= 4 ? \"O-|\" . \"O\" x $_ .\"-\". \"O\" x (4 - $_) : \"-O|\" . \"O\" x ($_ - 5) . \"-\" . \"O\" x (9 - $_), \"\\n\" foreach (reverse grep { !($_ =~ /\\n|\\r/) } split //, <>);"}, {"source_code": "#!/usr/bin/perl\n\n$PI=3.14159265358979323846;\n$MOD=1000000007;\n\n# <>=~/ /;\n# <>=~/ (\\d+) /;\n# <>=~/ (\\d+) (\\d+) /;\n\n(@_=reverse (split//,<>));\nshift @_;\n\nfor (@_){\n\t\n\t$s=(\"O\"x$_).\"-\".(\"O\"x(9-$_));\n\t$s=~s/^OOOOO/-O|/;\n\t$s=~s/OOOOO$// and $s=~s/^/O-|/;\n\tprint $s;\n\tn();\n\t}\n\n\n#***********SUBS************\n\nsub num {$a <=> $b}\nsub num_rev {$b <=> $a}\nsub rev {$b cmp $a}\n\nsub p{print}\nsub n{print \"\\n\"}\nsub pn{p,n}\nsub pn_mas {pn for @_}\n\n# Transpose \"charbox\"\nsub transpose{\n $i=@m=@_;\n chomp @m;\n while ($i--){\n $t[$i]=~s/$/chop/e for @m\n }\nreturn @t\n}\n\n# Transpose \"value sets\"\nsub transpose_space{\n my @t;\n for (@_){\n my $j=0;\n s/\\d+/($t[$j++].=\"$& \")?$&:$&/eg;\n }\n chop @t;\nreturn @t\n}\n\nsub div{\n my ($n, $k)=@_;\nreturn ($n - $n % $k) / $k\n}\n \nsub uniq{\n my @m=sort @_;\n push @u, my $i=shift @m;\n for (@m){\n $i eq $_ or push @u, $_;\n $i=$_;\n }\nreturn @u\n}\n \nsub max{\n my $max=shift;\n $max<$_ and $max=$_ for @_;\nreturn $max\n}\n \nsub min{\n my $min=shift;\n $min>$_ and $min=$_ for @_;\nreturn $min\n}\n\n# count (kas_ieskoma, masyvas)\nsub count{\n my $i=0;\n $_ eq $_[0] and $i++ for @_;\nreturn --$i\n}"}], "negative_code": [{"source_code": "$n = <>;\nif($n == 0)\n{\n print(\"0-|-OOOO\\n\");\n}\nwhile($n > 0)\n{\n $cur = $n % 10;\n $n -= $cur;\n $n /= 10;\n print \"-O|\" if ($cur >= 5);\n print \"O-|\" if ($cur < 5);\n\n print('O' x ($cur % 5));\n print('-');\n print('O' x (4 - ($cur % 5)));\n print \"\\n\";\n #print(\"$n\\n\");\n}"}, {"source_code": "\n$n = <>;\nif($n == 0)\n{\n print(\"-0|-0000\\n\");\n}\nwhile($n > 0)\n{\n $cur = $n % 10;\n $n -= $cur;\n $n /= 10;\n print \"0-|\" if ($cur >= 5);\n print \"-0|\" if ($cur < 5);\n\n print('0' x ($cur % 5));\n print('-');\n print('0' x (4 - ($cur % 5)));\n print \"\\n\";\n}"}, {"source_code": "$n = <>;\nif($n == 0)\n{\n print(\"-0|-0000\\n\");\n}\nwhile($n > 0)\n{\n $cur = $n % 10;\n $n -= $cur;\n $n /= 10;\n print \"-0|\" if ($cur >= 5);\n print \"0-|\" if ($cur < 5);\n\n print('0' x ($cur % 5));\n print('-');\n print('0' x (4 - ($cur % 5)));\n print \"\\n\";\n #print(\"$n\\n\");\n}"}, {"source_code": "$n = <>;\nif($n == 0)\n{\n print(\"-O|-OOOO\\n\");\n}\nwhile($n > 0)\n{\n $cur = $n % 10;\n $n -= $cur;\n $n /= 10;\n print \"-O|\" if ($cur >= 5);\n print \"O-|\" if ($cur < 5);\n\n print('O' x ($cur % 5));\n print('-');\n print('O' x (4 - ($cur % 5)));\n print \"\\n\";\n #print(\"$n\\n\");\n}"}, {"source_code": "#!/usr/bin/perl\nprint $_ >= 0 && $_ <= 4 ? \"O-|\" . \"O\" x $_ .\"-\". \"O\" x (4 - $_) : \"-O|\" . \"O\" x ($_ - 5) . \"-\" . \"O\" x (9 - $_), \"\\n\" foreach (reverse split //, <>);"}, {"source_code": "#!/usr/bin/perl\n\n$PI=3.14159265358979323846;\n$MOD=1000000007;\n\n# <>=~/ /;\n# <>=~/ (\\d+) /;\n# <>=~/ (\\d+) (\\d+) /;\n\n(@_=reverse (split//,<>));\nshift @_;\n\nfor (@_){\n\t\n\t$s=(\"O\"x$_).\"-\".(\"O\"x(8-$_));\n\t$s=~s/^OOOOO/-O|/;\n\t$s=~s/OOOOO$// and $s=~s/^/O-|/;\n\tprint $s;\n\tn();\n\t}\n\n\n#***********SUBS************\n\nsub num {$a <=> $b}\nsub num_rev {$b <=> $a}\nsub rev {$b cmp $a}\n\nsub p{print}\nsub n{print \"\\n\"}\nsub pn{p,n}\nsub pn_mas {pn for @_}\n\n# Transpose \"charbox\"\nsub transpose{\n $i=@m=@_;\n chomp @m;\n while ($i--){\n $t[$i]=~s/$/chop/e for @m\n }\nreturn @t\n}\n\n# Transpose \"value sets\"\nsub transpose_space{\n my @t;\n for (@_){\n my $j=0;\n s/\\d+/($t[$j++].=\"$& \")?$&:$&/eg;\n }\n chop @t;\nreturn @t\n}\n\nsub div{\n my ($n, $k)=@_;\nreturn ($n - $n % $k) / $k\n}\n \nsub uniq{\n my @m=sort @_;\n push @u, my $i=shift @m;\n for (@m){\n $i eq $_ or push @u, $_;\n $i=$_;\n }\nreturn @u\n}\n \nsub max{\n my $max=shift;\n $max<$_ and $max=$_ for @_;\nreturn $max\n}\n \nsub min{\n my $min=shift;\n $min>$_ and $min=$_ for @_;\nreturn $min\n}\n\n# count (kas_ieskoma, masyvas)\nsub count{\n my $i=0;\n $_ eq $_[0] and $i++ for @_;\nreturn --$i\n}"}], "src_uid": "c2e3aced0bc76b6484360563355d23a7"} {"nl": {"description": "Holidays have finished. Thanks to the help of the hacker Leha, Noora managed to enter the university of her dreams which is located in a town Pavlopolis. It's well known that universities provide students with dormitory for the period of university studies. Consequently Noora had to leave Vičkopolis and move to Pavlopolis. Thus Leha was left completely alone in a quiet town Vičkopolis. He almost even fell into a depression from boredom!Leha came up with a task for himself to relax a little. He chooses two integers A and B and then calculates the greatest common divisor of integers \"A factorial\" and \"B factorial\". Formally the hacker wants to find out GCD(A!, B!). It's well known that the factorial of an integer x is a product of all positive integers less than or equal to x. Thus x! = 1·2·3·...·(x - 1)·x. For example 4! = 1·2·3·4 = 24. Recall that GCD(x, y) is the largest positive integer q that divides (without a remainder) both x and y.Leha has learned how to solve this task very effective. You are able to cope with it not worse, aren't you?", "input_spec": "The first and single line contains two integers A and B (1 ≤ A, B ≤ 109, min(A, B) ≤ 12).", "output_spec": "Print a single integer denoting the greatest common divisor of integers A! and B!.", "sample_inputs": ["4 3"], "sample_outputs": ["6"], "notes": "NoteConsider the sample.4! = 1·2·3·4 = 24. 3! = 1·2·3 = 6. The greatest common divisor of integers 24 and 6 is exactly 6."}, "positive_code": [{"source_code": "#!/usr/bin/env perl\n\nuse strict;\nuse warnings;\n\nmy $input = ;\nchomp($input);\nmy ($aa, $bb) = split(' ', $input);\n\n$aa = int($aa);\n$bb = int($bb);\n\nif ($aa < $bb) {\n print fac($aa);\n}\nelse {\n print fac($bb);\n}\n\n\nsub fac {\n my ($n) = @_;\n my $f = 1;\n for my $i (1 .. $n) {\n $f *= $i;\n }\n return $f;\n}"}, {"source_code": "use strict;\nmy ($n, $m) = split(' ', <>);\nsub fact{\n my ($n) = @_;\n if($n == 0){\n return 1;\n }\n else{\n return fact($n - 1) * $n;\n }\n}\nif($n > $m){\n print fact($m);\n}\nelse{\n print fact($n);\n}\n"}, {"source_code": "($a, $b) = split(' ', <>);\n$min = ( sort { $a <=> $b } $a, $b )[0];\nprint 1 * eval join ' * ', 1 .. $min;"}, {"source_code": "print eval join ' * ', 1 .. ( sort { $a <=> $b } split ' ', <> )[ 0 ]"}, {"source_code": "#!/usr/bin/perl\n\nuse warnings;\nuse strict;\n\n$\\ = $/;\n\nwhile(<>){\n\tmy( $A, $B ) = split;\n\t\n\tmy $min = ( sort { $a <=> $b } $A, $B )[ 0 ];\n\t\n\tprint 1 * eval join ' * ', 1 .. $min;\n\t}"}], "negative_code": [{"source_code": "#!/usr/bin/env perl\n\nuse strict;\nuse warnings;\n\nmy $input = ;\nchomp($input);\nmy ($aa, $bb) = split(' ', $input);\n\n$aa = int($aa);\n$bb = int($bb);\n\nif ($aa > $bb) {\n print fac($aa);\n}\nelse {\n print fac($bb);\n}\n\n\nsub fac {\n my $n = @_;\n my $f = 1;\n for my $i (1 .. $n) {\n $f *= $i;\n }\n}"}], "src_uid": "7bf30ceb24b66d91382e97767f9feeb6"} {"nl": {"description": "Tattah is asleep if and only if Tattah is attending a lecture. This is a well-known formula among Tattah's colleagues.On a Wednesday afternoon, Tattah was attending Professor HH's lecture. At 12:21, right before falling asleep, he was staring at the digital watch around Saher's wrist. He noticed that the digits on the clock were the same when read from both directions i.e. a palindrome.In his sleep, he started dreaming about such rare moments of the day when the time displayed on a digital clock is a palindrome. As soon as he woke up, he felt destined to write a program that finds the next such moment.However, he still hasn't mastered the skill of programming while sleeping, so your task is to help him.", "input_spec": "The first and only line of the input starts with a string with the format \"HH:MM\" where \"HH\" is from \"00\" to \"23\" and \"MM\" is from \"00\" to \"59\". Both \"HH\" and \"MM\" have exactly two digits.", "output_spec": "Print the palindromic time of day that comes soonest after the time given in the input. If the input time is palindromic, output the soonest palindromic time after the input time.", "sample_inputs": ["12:21", "23:59"], "sample_outputs": ["13:31", "00:00"], "notes": null}, "positive_code": [{"source_code": "sub rev {\n\tmy $in = shift;\n\treturn join \"\", reverse split //, $in;\n}\n\nsub f {\n\tmy $t = shift;\n\t\n\t($h, $m) = split /:/, $t;\n\t$h++ if $m >= $h && $m >= rev($h);\n\twhile($h % 10 > 5) { $h++; }\n\t$h = 0 if $h > 23;\n\t$h = \"0$h\" if $h < 10 && length($h) == 1;\n\treturn join \":\", $h, rev($h);\n}\n\nchomp($line=);\nprint f($line).\"\\n\";\n"}], "negative_code": [{"source_code": "sub rev {\n\tmy $in = shift;\n\treturn join \"\", reverse split //, $in;\n}\n\nsub f {\n\tmy $t = shift;\n\t\n\t($h, $m) = split /:/, $t;\n\t$h++ if $m > $h && $m > rev($h);\n\twhile($h % 10 > 5) { $h++; }\n\t$h = 0 if $h > 23;\n\t$h = \"0$h\" if $h < 10 && length($h) == 1;\n\treturn join \":\", $h, rev($h);\n}\n\nchomp($line=);\nprint f($line).\"\\n\";\n"}, {"source_code": "sub f {\n\tmy $t = shift;\n\t\n\t($h, $m) = split /:/, $t;\n$h =~ s/^0//;\n\t$h++ if $m > $h;\n\twhile($h % 10 > 5) { $h++; }\n\t$h = 0 if $h > 23;\n\t$h = \"0$h\" if $h < 10;\n\t$m = join(\"\", reverse(split //, $h));\n\treturn join \":\", $h, $m;\n}\n\nchomp($line=);\nprint f($line).\"\\n\";\n"}, {"source_code": "sub f {\n\tmy $t = shift;\n\t\n\t($h, $m) = split /:/, $t;\n\t$h++ if $m > $h;\n\twhile($h % 10 > 5) { $h++; }\n\t$h = 0 if $h > 23;\n\t$h = \"0$h\" if $h < 10;\n\t$m = join(\"\", reverse(split //, $h));\n\treturn join \":\", $h, $m;\n}\n\nchomp($line=);\nprint f($line).\"\\n\";\n"}, {"source_code": "sub f {\n\tmy $t = shift;\n\t\n\t($h, $m) = split /:/, $t;\n\t$h++ if $m > $h;\n\t$h = 0 if $h == 24;\n\t$h = \"0$h\" if $h < 10;\n\t$m = join(\"\", reverse(split //, $h));\n\treturn join \":\", $h, $m;\n}\n\nchomp($line=);\nprint f($line).\"\\n\";"}], "src_uid": "158eae916daa3e0162d4eac0426fa87f"} {"nl": {"description": "Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way:qwertyuiopasdfghjkl;zxcvbnm,./Unfortunately Mole is blind, so sometimes it is problem for him to put his hands accurately. He accidentally moved both his hands with one position to the left or to the right. That means that now he presses not a button he wants, but one neighboring button (left or right, as specified in input).We have a sequence of characters he has typed and we want to find the original message.", "input_spec": "First line of the input contains one letter describing direction of shifting ('L' or 'R' respectively for left or right). Second line contains a sequence of characters written by Mole. The size of this sequence will be no more than 100. Sequence contains only symbols that appear on Mole's keyboard. It doesn't contain spaces as there is no space on Mole's keyboard. It is guaranteed that even though Mole hands are moved, he is still pressing buttons on keyboard and not hitting outside it.", "output_spec": "Print a line that contains the original message.", "sample_inputs": ["R\ns;;upimrrfod;pbr"], "sample_outputs": ["allyouneedislove"], "notes": null}, "positive_code": [{"source_code": "my $dir = ;\nchomp $dir;\nmy $str = ;\nchomp $str;\n\nif ($dir eq 'R'){\n\n $str=~tr{qwertyuiopasdfghjkl;zxcvbnm,./}{/qwertyuiopasdfghjkl;zxcvbnm,./};\n\n}else{\n\n $str=~tr{qwertyuiopasdfghjkl;zxcvbnm,./}{wertyuiopasdfghjkl;zxcvbnm,./};\n \n}\n\nprint $str,\"\\n\";\n"}, {"source_code": "# author : Gabriel Hofer\nuse warnings;\nuse strict;\nmy $keyboard = q/qwertyuiopasdfghjkl;zxcvbnm,.\\//;\nif ( =~ m /L/ ) {\n chomp ( my $line = );\n for my $i ( split q//, $line ) {\n if ( $i eq '.' ) {\n $keyboard =~ m /\\.(.)/;\n print qq /$1/;\n } else {\n $keyboard =~ m /$i(.)/;\n print qq /$1/;\n } \n } \n} else {\n chomp ( my $line = );\n for my $i ( split q//, $line ) {\n if ( $i eq '.' ) {\n $keyboard =~ m /(.)\\./;\n print qq/$1/; \n } else {\n $keyboard =~ m /(.)$i/; \n print qq/$1/; \n }}\n}\nprint qq/\\n/;\n\n\n"}, {"source_code": "my $d = <>;\nmy $str = <>;\nmy @ch = split \"\", \"qwertyuiopasdfghjkl;zxcvbnm,./\";\nmy $sh = $d eq \"R\\n\"? -1 : +1;\nmy %m = ();\nforeach my $i (0 .. scalar @ch)\n{\n $m{$ch[$i]} = $ch[$i + $sh];\n}\n\nprint map { $m{$_} } split \"\", $str;"}, {"source_code": "my @arr = ([split //,(\"qwertyuiop\")],[split //,(\"asdfghjkl;\")], [split //,\"zxcvbnm,./\"]);\nchomp(my $ch = <>);\n$ch = $ch eq 'L' ? -1 : 1;\nmy @str = split //,<>;\npop @str;\nmy %key;\nfor my $i(0..2) {\n for my $j(0..9) {\n $key{$arr[$i][$j]} = $arr[$i][$j - $ch];\n }\n}\nprint $key{$_} foreach(@str);\n"}, {"source_code": "#!/usr/bin/perl\n# your code goes here\nuse v5.10;\n\n$delta = <> eq \"R\\n\" ? -1:1;\n@a = split //, \"qwertyuiopasdfghjkl;zxcvbnm,./\";\nchomp($line = <>);\nforeach $c(split //, $line) {\n\tforeach(0..$#a) {\n\t\t$a[$_] eq $c and print $a[$_+$delta] and last;\n\t}\n}\n"}, {"source_code": "my @arr = split /\\s*/, \"qwertyuiopasdfghjkl;zxcvbnm,./\";\n\nmy (%l, %r);\n\nfor (my $i = 0; $i < @arr; $i++) {\n $l{$arr[$i]} = $arr[$i+1];\n $r{$arr[$i]} = $arr[$i-1];\n}\n\nchomp (my $k = <>);\nchomp (my @in = split /\\s*/, <>);\nif ($k eq 'L') {\n printf \"$l{$_}\" foreach (@in);\n} else {\n printf \"$r{$_}\" foreach (@in);\n}\nprintf \"\\n\";"}, {"source_code": "use 5.016;\nuse strict;\nuse warnings;\n\nsub left {\n $_[0] =~ tr{qwertyuioasdfghjklzxcvbnm,.}\n {wertyuiopsdfghjkl;xcvbnm,./}r;\n}\n\nsub right {\n $_[0] =~ tr{wertyuiopsdfghjkl;xcvbnm,./}\n {qwertyuioasdfghjklzxcvbnm,.}r;\n}\n\nmy %dirs = (\n L => \\&left,\n R => \\&right,\n);\n\nchomp (my $dir = <>);\nmy $tr = $dirs{$dir};\n\nmy $msg = <>;\nsay $tr->($msg);\n"}, {"source_code": "print<>=~R?<>=~y#wertyuiopsdfghjkl;xcvbnm,./#qwertyuioasdfghjklzxcvbnm,.#r:<>=~y#qwertyuioasdfghjklzxcvbnm,.#wertyuiopsdfghjkl;xcvbnm,./#r"}, {"source_code": "while($dirr=<>){\n\t\n\t$_=\"qwertyuiopasdfghjkl;zxcvbnm,./\";\n\t\n\tfor $i(split//,<>){\n\t\t$qi = quotemeta $i;\n\t\t($dirr =~ /R/ ? /(.)$qi/ : /$qi(.)/) and print $1\n\t\t}\n\n\t}"}, {"source_code": "$_=<>.\"qwertyuiopasdfghjkl;zxcvbnm,./\";\n\nchomp ($a=<>);\nfor $i(split//,$a){\n\t$m = '(.)'x/R/.\"\\Q$i\\E\".'(.)'x/L/;\n\t/$m/m && print $1\n\t}"}], "negative_code": [{"source_code": "\nmy $dir = ;\n\nif ($dir eq 'R'){\n\n\tprint tr{wertyuiopasdfghjkl;zxcvbnm,./}{qwertyuiopasdfghjkl;zxcvbnm,.};\n\n}else{\n\n\tprint tr{qwertyuiopasdfghjkl;zxcvbnm,.}{wertyuiopasdfghjkl;zxcvbnm,./};\n\t\n}\n\n"}, {"source_code": "\nmy $dir = ;\n\n$_ = ;\n\nif ($dir eq 'R'){\n\n print tr{wertyuiopasdfghjkl;zxcvbnm,./}{qwertyuiopasdfghjkl;zxcvbnm,.};\n\n}else{\n\n print tr{qwertyuiopasdfghjkl;zxcvbnm,.}{wertyuiopasdfghjkl;zxcvbnm,./};\n \n}\n\n"}, {"source_code": "# author : Gabriel Hofer\nuse warnings;\nuse strict;\nmy $keyboard = q/qwertyuiopasdfghjkl;zxcvbnm,.\\//;\nif ( =~ m /L/ ) {\n chomp ( my $line = );\n for my $i ( split q//, $line ) {\n $keyboard =~ m /$i(.)/;\n print qq/$1/; }\n} else {\n chomp ( my $line = );\n for my $i ( split q//, $line ) {\n $keyboard =~ m /(.)$i/;\n print qq/$1/; }\n}\nprint qq/\\n/;\n\n\n"}, {"source_code": "my $d = <>;\nmy $str = <>;\nmy @ch = split \"\", \"qwertyuiopasdfghjkl;zxcvbnm,./\";\nmy $sh = $d eq \"R\"? 1 : -1;\nmy %m = ();\nforeach my $i (0 .. scalar @ch)\n{\n $m{$ch[$i]} = $ch[$i + $sh];\n}\n\nprint map { $m{$_} } split \"\", $str;\n"}, {"source_code": "my @arr = ([split //,(\"qwertyuiop\")],[split //,(\"asdfghjkl;\")], [split //,\"zxcvbnm,./\"]);\nmy $ch = <> eq 'L' ? -1 : 1;\nmy @str = split //,<>;\npop @str;\nmy %key;\nfor my $i(0..2) {\n for my $j(0..9) {\n $key{$arr[$i][$j]} = $arr[$i][$j - $ch];\n }\n}\nprint $key{$_} foreach(@str);"}, {"source_code": "my @arr = split /\\s*/, \"qwertyuiopasdfghjkl;zxcvbnm,./\";\n\nmy (%l, %r);\n\nfor (my $i = 0; $i < @arr; $i++) {\n $l{$arr[$i]} = $arr[$i-1];\n $r{$arr[$i]} = $arr[$i-1];\n}\n\nchomp (my $k = <>);\nchomp (my @in = split /\\s*/, <>);\nif ($k eq 'L') {\n printf \"$l{$_}\" foreach (@in);\n} else {\n printf \"$r{$_}\" foreach (@in);\n}\nprintf \"\\n\";"}], "src_uid": "df49c0c257903516767fdb8ac9c2bfd6"} {"nl": {"description": "Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go.Dr. Evil is interested in sets, He has a set of n integers. Dr. Evil calls a set of integers evil if the MEX of it is exactly x. the MEX of a set of integers is the minimum non-negative integer that doesn't exist in it. For example, the MEX of the set {0, 2, 4} is 1 and the MEX of the set {1, 2, 3} is 0 .Dr. Evil is going to make his set evil. To do this he can perform some operations. During each operation he can add some non-negative integer to his set or erase some element from it. What is the minimal number of operations Dr. Evil has to perform to make his set evil?", "input_spec": "The first line contains two integers n and x (1 ≤ n ≤ 100, 0 ≤ x ≤ 100) — the size of the set Dr. Evil owns, and the desired MEX. The second line contains n distinct non-negative integers not exceeding 100 that represent the set.", "output_spec": "The only line should contain one integer — the minimal number of operations Dr. Evil should perform.", "sample_inputs": ["5 3\n0 4 5 6 7", "1 0\n0", "5 0\n1 2 3 4 5"], "sample_outputs": ["2", "1", "0"], "notes": "NoteFor the first test case Dr. Evil should add 1 and 2 to the set performing 2 operations.For the second test case Dr. Evil should erase 0 from the set. After that, the set becomes empty, so the MEX of it is 0.In the third test case the set is already evil."}, "positive_code": [{"source_code": "( $n, $x ) = split ' ', <>;\nprint eval join ' + ', $x, map { ( $_ == $x ) - ( $_ < $x ) } split ' ', <>"}, {"source_code": "#!/usr/bin/perl\n\nuse warnings;\nuse strict;\n\n$\\ = $/;\n\nwhile(<>){\n\tmy( $n, $x ) = split;\n\t@_ = sort { $a <=> $b } split ' ', <>;\n\t\n\tmy $op = $x;\n\t\n\tfor ( @_ ){\n\t\t$_ == $x and do {\n\t\t\t$op ++;\n\t\t\tlast;\n\t\t\t};\n\t\t$_ < $x and do {\n\t\t\t$op --;\n\t\t\tnext;\n\t\t\t};\n\t\t}\n\t\n\tprint $op;\n\t}"}], "negative_code": [], "src_uid": "21f579ba807face432a7664091581cd8"} {"nl": {"description": "Vasily has a number a, which he wants to turn into a number b. For this purpose, he can do two types of operations: multiply the current number by 2 (that is, replace the number x by 2·x); append the digit 1 to the right of current number (that is, replace the number x by 10·x + 1). You need to help Vasily to transform the number a into the number b using only the operations described above, or find that it is impossible.Note that in this task you are not required to minimize the number of operations. It suffices to find any way to transform a into b.", "input_spec": "The first line contains two positive integers a and b (1 ≤ a < b ≤ 109) — the number which Vasily has and the number he wants to have.", "output_spec": "If there is no way to get b from a, print \"NO\" (without quotes). Otherwise print three lines. On the first line print \"YES\" (without quotes). The second line should contain single integer k — the length of the transformation sequence. On the third line print the sequence of transformations x1, x2, ..., xk, where: x1 should be equal to a, xk should be equal to b, xi should be obtained from xi - 1 using any of two described operations (1 < i ≤ k). If there are multiple answers, print any of them.", "sample_inputs": ["2 162", "4 42", "100 40021"], "sample_outputs": ["YES\n5\n2 4 8 81 162", "NO", "YES\n5\n100 200 2001 4002 40021"], "notes": null}, "positive_code": [{"source_code": "$_ = <>; ($a, $b) = split; @c = ($b);\nwhile ($b > $a) {\n\tif ($b & 1) {\n\t\t$b--;\n\t\tlast if $b % 10;\n\t\t$b/=10;\n\t} else {\n\t\t$b/=2;\n\t}\n\tunshift @c, $b;\n}\nif ($a == $b) {\n\t$\\ = \"\\n\";\n\tprint \"YES\";\n\tprint 0 + @c;\n\tprint \"@c\";\n} else {\n\tprint \"NO\";\n}\n"}, {"source_code": "$,=\" \";\n\nmy ($a,$b)=split / /,<>;\nchomp($a,$b);\nmy $c=1;\nmy $str=$b;\nmy $t=Find($b,$a);\nif($t==0)\n{\n print \"NO\\n\";\n}\nelse\n{\n print \"YES\\n\";\n print $c . \"\\n\";\n print $str . \"\\n\";\n}\n\nsub Find{\n my $n1=shift;\n my $n2=shift;\n if($n1==$n2)\n {\n return $n1;\n }\n if($n1%2==0)\n {\n $c++;\n $str = ($n1/2) . \" \" . $str;\n #print $str,\"\\n\";\n return Find($n1/2,$n2);\n }\n if(($n1-1)>=10 and ($n1-1)%10==0)\n {\n $c++;\n $str = ($n1-1)/10 . \" \" . $str;\n #print $str,\"\\n\";\n return Find(($n1-1)/10,$n2);\n }\n return 0;\n}\n"}, {"source_code": "$\\ = $/;\n\nwhile(<>){\n\t($n, $m) = split;\n\twhile( $m ){\n\t\tunshift @m, $m;\n\t\t$m eq $n and last;\n\t\t$m < $n and ++ $f and last;\n\t\t$m =~ s/1$// and next;\n\t\t$m % 2 and ++ $f and last;\n\t\t$m /= 2;\n\t\t}\n\t\n\tprint $f ? 'NO' :\n\t\t'YES' . \"\\n\" . @m . \"\\n\" . join ' ', @m;\n\t}"}], "negative_code": [], "src_uid": "fc3adb1a9a7f1122b567b4d8afd7b3f3"} {"nl": {"description": "Where do odds begin, and where do they end? Where does hope emerge, and will they ever break?Given an integer sequence a1, a2, ..., an of length n. Decide whether it is possible to divide it into an odd number of non-empty subsegments, the each of which has an odd length and begins and ends with odd numbers.A subsegment is a contiguous slice of the whole sequence. For example, {3, 4, 5} and {1} are subsegments of sequence {1, 2, 3, 4, 5, 6}, while {1, 2, 4} and {7} are not.", "input_spec": "The first line of input contains a non-negative integer n (1 ≤ n ≤ 100) — the length of the sequence. The second line contains n space-separated non-negative integers a1, a2, ..., an (0 ≤ ai ≤ 100) — the elements of the sequence.", "output_spec": "Output \"Yes\" if it's possible to fulfill the requirements, and \"No\" otherwise. You can output each letter in any case (upper or lower).", "sample_inputs": ["3\n1 3 5", "5\n1 0 1 5 1", "3\n4 3 1", "4\n3 9 9 3"], "sample_outputs": ["Yes", "Yes", "No", "No"], "notes": "NoteIn the first example, divide the sequence into 1 subsegment: {1, 3, 5} and the requirements will be met.In the second example, divide the sequence into 3 subsegments: {1, 0, 1}, {5}, {1}.In the third example, one of the subsegments must start with 4 which is an even number, thus the requirements cannot be met.In the fourth example, the sequence can be divided into 2 subsegments: {3, 9, 9}, {3}, but this is not a valid solution because 2 is an even number."}, "positive_code": [{"source_code": "use strict;\nuse warnings;\nuse utf8;\n$| =1;\n\nmy $n = <>;\nmy $a = [map {$_&1} split \" \",<>];\n\nNO() if $a->[0]==0 or $a->[$#$a]==0;\nOK() if $n & 1 == 1;\n\ncan_be_diveded($a, 0) ? OK() : NO();\n\nsub OK {\n print \"yes\";\n exit(0);\n}\n\nsub NO {\n print \"no\";\n exit(0);\n}\n\nsub can_be_diveded {\n my $array = shift;\n my $even_lenght_bit = shift;\n my $retval = 0;\n my $last = $#$array;\n if (!$even_lenght_bit and !($last & 1) and ($array->[$last] & 1) ){\n $retval = 1;\n }\n\n for (my $i=0; ($i+1) < $last and $retval == 1 ; $i+=2){\n if ($array->[$i] & $array->[$i+1]){\n $retval = 1 if can_be_diveded([@$array[($i+1)..$last]], !$even_lenght_bit);\n last if $retval == 1;\n }\n }\n $retval;\n}"}, {"source_code": "<>;\n\nprint <> =~ /^\\S*[13579](( \\S+ \\S*)+[13579])?$/ ? \"YES\" : \"NO\""}, {"source_code": "#!/usr/bin/perl\n\nuse warnings;\nuse strict;\n\n$\\ = $/;\n\nwhile(<>){\n\tmy @A = split ' ', <>;\n\t\n\tif( @A % 2 and $A[0] % 2 and $A[-1] % 2 ){\n\t\tprint \"YES\";\n\t\t}\n\telse{\n\t\tprint \"NO\";\n\t\t}\n\t}"}, {"source_code": "<>;\n\n@A = split ' ', <>;\n\nprint @A % 2 && $A[0] % 2 && $A[-1] % 2 ? \"YES\" : \"NO\""}], "negative_code": [{"source_code": "use strict;\nuse warnings;\nuse utf8;\n$| =1;\n\nmy $n = <>;\nmy @a = map {$_&1} split \" \",<>;\n\nNO() if $a[0]==0 or $a[$#a]==0;\nOK() if $n & 1 == 1;\n\nmy $blockNum = 0;\nfor (my $i=0;$i<($n-1) and $blockNum < 2;$i++){\n $blockNum++ if ($a[$i] & $a[$i+1]);\n}\nOK() if $blockNum > 1;\nNO();\n\nsub OK {\n print \"yes\";\n exit(0);\n}\n\nsub NO {\n print \"no\";\n exit(0);\n}"}], "src_uid": "2b8c2deb5d7e49e8e3ededabfd4427db"} {"nl": {"description": "Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than $$$a$$$ and screen height not greater than $$$b$$$. Monocarp is also used to TV sets with a certain aspect ratio: formally, if the width of the screen is $$$w$$$, and the height of the screen is $$$h$$$, then the following condition should be met: $$$\\frac{w}{h} = \\frac{x}{y}$$$.There are many different TV sets in the shop. Monocarp is sure that for any pair of positive integers $$$w$$$ and $$$h$$$ there is a TV set with screen width $$$w$$$ and height $$$h$$$ in the shop.Monocarp isn't ready to choose the exact TV set he is going to buy. Firstly he wants to determine the optimal screen resolution. He has decided to try all possible variants of screen size. But he must count the number of pairs of positive integers $$$w$$$ and $$$h$$$, beforehand, such that $$$(w \\le a)$$$, $$$(h \\le b)$$$ and $$$(\\frac{w}{h} = \\frac{x}{y})$$$.In other words, Monocarp wants to determine the number of TV sets having aspect ratio $$$\\frac{x}{y}$$$, screen width not exceeding $$$a$$$, and screen height not exceeding $$$b$$$. Two TV sets are considered different if they have different screen width or different screen height.", "input_spec": "The first line contains four integers $$$a$$$, $$$b$$$, $$$x$$$, $$$y$$$ ($$$1 \\le a, b, x, y \\le 10^{18}$$$) — the constraints on the screen width and height, and on the aspect ratio.", "output_spec": "Print one integer — the number of different variants to choose TV screen width and screen height so that they meet the aforementioned constraints.", "sample_inputs": ["17 15 5 3", "14 16 7 22", "4 2 6 4", "1000000000000000000 1000000000000000000 999999866000004473 999999822000007597"], "sample_outputs": ["3", "0", "1", "1000000063"], "notes": "NoteIn the first example, there are $$$3$$$ possible variants: $$$(5, 3)$$$, $$$(10, 6)$$$, $$$(15, 9)$$$.In the second example, there is no TV set meeting the constraints.In the third example, there is only one variant: $$$(3, 2)$$$."}, "positive_code": [{"source_code": "use v5.20;\nuse warnings;\n\nsub min\n{\n\tif($_[0] > $_[1]) {$_[1];}\n\telse {$_[0];}\n}\n\nsub gcd\n{\n\tmy ($x, $y) = @_;\n\tif ($y eq 0) {$x}\n\telse {gcd ($y, $x % $y);}\n}\n\nmy $l = ; \nmy ($a, $b, $x, $y) = split / /,$l;\nif($x < $y)\n{\n\t($a, $b) = ($b, $a);\n\t($x, $y) = ($y, $x);\n}\n \nmy $p = int($y/ gcd $x,$y);\nmy $q = int($x/ gcd $x,$y);\nsay min int($a/$q), int($b/$p); "}], "negative_code": [{"source_code": "use v5.20;\nuse warnings;\n\nsub min\n{\n\tif($_[0] > $_[1]) {$_[1];}\n\telse {$_[0];}\n}\n\nmy $l = ; \nmy ($a, $b, $x, $y) = split / /,$l;\nsay min int($a/$x), int($b/$y);"}], "src_uid": "907ac56260e84dbb6d98a271bcb2d62d"} {"nl": {"description": "When preparing a tournament, Codeforces coordinators try treir best to make the first problem as easy as possible. This time the coordinator had chosen some problem and asked $$$n$$$ people about their opinions. Each person answered whether this problem is easy or hard.If at least one of these $$$n$$$ people has answered that the problem is hard, the coordinator decides to change the problem. For the given responses, check if the problem is easy enough.", "input_spec": "The first line contains a single integer $$$n$$$ ($$$1 \\le n \\le 100$$$) — the number of people who were asked to give their opinions. The second line contains $$$n$$$ integers, each integer is either $$$0$$$ or $$$1$$$. If $$$i$$$-th integer is $$$0$$$, then $$$i$$$-th person thinks that the problem is easy; if it is $$$1$$$, then $$$i$$$-th person thinks that the problem is hard.", "output_spec": "Print one word: \"EASY\" if the problem is easy according to all responses, or \"HARD\" if there is at least one person who thinks the problem is hard. You may print every letter in any register: \"EASY\", \"easy\", \"EaSY\" and \"eAsY\" all will be processed correctly.", "sample_inputs": ["3\n0 0 1", "1\n0"], "sample_outputs": ["HARD", "EASY"], "notes": "NoteIn the first example the third person says it's a hard problem, so it should be replaced.In the second example the problem easy for the only person, so it doesn't have to be replaced."}, "positive_code": [{"source_code": "<>; $_ = <>; print /1/? \"HARD\": \"EASY\", \"\\n\";"}, {"source_code": "<>;\nprint <> =~ /1/ ? \"HARD\" : \"EASY\""}, {"source_code": "<>;\n\nprint <> =~ /1/ ? \"HARD\" : \"EASY\""}, {"source_code": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\nmy $n = <> + 0;\nmy $isEasy = 1;\nmy $line = <>;\n\nmy @numbers = split ' ', $line;\n\nforeach my $number (@numbers) {\n if($number == 1) {\n $isEasy = 0;\n }\n}\n\nif($isEasy) {\n print \"EASY\\n\";\n} else {\n print \"HARD\\n\";\n}"}, {"source_code": "<>;print<>=~/1/?\"HARD\":\"EASY\""}, {"source_code": "use strict;\nmy $n = <>;\nmy @a = split(' ', <>);\nfor (my $i = 0; $i <= $#a; $i++){\n if($a[$i] == 1){\n print \"HARD\";\n exit(0);\n }\n}\nprint \"EASY\";\n"}, {"source_code": "#!/usr/bin/env perl\n \nuse strict;\nuse warnings;\nuse feature qw/ say /;\n \n# essential\nmy @tokens = ();\n\nmy $n = read_token();\nmy $m = 0;\n\nfor ( 1..$n ) {\n $m = max($m, read_token());\n}\n\nif ( $m == 1 ) {\n say \"hard\";\n}\nelse {\n say \"easy\";\n}\n\nsub read_line {\n chomp (my $line = );\n return $line;\n}\n \nsub read_token {\n @tokens = split q{ }, read_line() if @tokens == 0;\n return shift @tokens;\n}\n \nsub min {\n my @numbers = @_;\n my $min = shift @numbers;\n for ( @numbers ) {\n $min = $min<$_ ? $min : $_;\n }\n return $min;\n}\n \nsub max {\n my @numbers = @_;\n my $max = shift @numbers;\n for ( @numbers ) {\n $max = $max > $_ ? $max : $_;\n }\n return $max;\n}\n \nsub sum {\n my @numbers = @_;\n my $sum = 0;\n for (@numbers) {\n $sum += $_;\n }\n return $sum;\n}\n"}, {"source_code": "#!perl -w\nuse strict;\nuse warnings;\n\nmy ($i, $num, $str, $flag);\nmy (@arr_str, $len);\n\n$num = ;\nchomp $num;\n\n$str = ;\nchomp $str;\n\n@arr_str = $str =~ /\\d/g;\n$len = @arr_str;\n\n$flag = 0; # Если flag == 0, то задача легкая\n\nfor ($i = 0; $i < $len; $i++) {\n\tif($arr_str[$i]) {\n\t\t$flag = 1;\n\t\tlast;\n\t}\n}\n\nif($flag) {\n\tprint \"HARD\";\n}\nelse {\n\tprint \"EASY\";}\n\nexit 0;"}], "negative_code": [{"source_code": "#!/usr/bin/env perl\n \nuse strict;\nuse warnings;\nuse feature qw/ say /;\n \n# essential\nmy @tokens = ();\n\nmy $n = read_token();\nmy $m = 0;\n\nfor ( 1..$n ) {\n $m = max($m, read_token());\n}\n\nif ( $m == 1 ) {\n say \"hard\";\n}\nelse {\n say \"easy\";\n}\n\nsay $n;\n\nsub read_line {\n chomp (my $line = );\n return $line;\n}\n \nsub read_token {\n @tokens = split q{ }, read_line() if @tokens == 0;\n return shift @tokens;\n}\n \nsub min {\n my @numbers = @_;\n my $min = shift @numbers;\n for ( @numbers ) {\n $min = $min<$_ ? $min : $_;\n }\n return $min;\n}\n \nsub max {\n my @numbers = @_;\n my $max = shift @numbers;\n for ( @numbers ) {\n $max = $max > $_ ? $max : $_;\n }\n return $max;\n}\n \nsub sum {\n my @numbers = @_;\n my $sum = 0;\n for (@numbers) {\n $sum += $_;\n }\n return $sum;\n}\n"}], "src_uid": "060406cd57739d929f54b4518a7ba83e"} {"nl": {"description": "The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square t. As the king is not in habit of wasting his time, he wants to get from his current position s to square t in the least number of moves. Help him to do this. In one move the king can get to the square that has a common side or a common vertex with the square the king is currently in (generally there are 8 different squares he can move to).", "input_spec": "The first line contains the chessboard coordinates of square s, the second line — of square t. Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8.", "output_spec": "In the first line print n — minimum number of the king's moves. Then in n lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD. L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diagonal moves. If the answer is not unique, print any of them. ", "sample_inputs": ["a8\nh1"], "sample_outputs": ["7\nRD\nRD\nRD\nRD\nRD\nRD\nRD"], "notes": null}, "positive_code": [{"source_code": "#!/bin/perl -w\nuse strict;\nuse warnings;\nuse List::Util qw{max};\n\nmy %cn;\n@cn{'a' .. 'h'} = (1 .. 8);\nmy @c = split //, <>;\nmy @t = split //, <>;\nmy $n = max(abs($cn{$c[0]} - $cn{$t[0]}), abs($c[1] - $t[1]));\nprint \"$n\\n\";\n\nwhile ($c[0] ne $t[0] or $c[1] != $t[1]) {\n if ($c[0] lt $t[0]) {\n\tprint \"R\";\n\t$c[0]++;\n } elsif ($c[0] gt $t[0]){\n\tprint \"L\";\n\tmy @keys = sort keys %cn;\n\tfor (0 .. $#keys) {\n\t if ($keys[$_] eq $c[0]) {\n\t\t$c[0] = $keys[$_ - 1];\n\t\tlast;\n\t }\n\t}\n }\n if ($c[1] < $t[1]) {\n\tprint \"U\\n\";\n\t$c[1]++;\n } elsif ($c[1] > $t[1]) {\n\tprint \"D\\n\";\n\t$c[1]--;\n } else {\n\tprint \"\\n\";\n }\n}\n \n \n"}], "negative_code": [], "src_uid": "d25d454702b7755297a7a8e1f6f36ab9"} {"nl": {"description": "Polycarp has a cat and his cat is a real gourmet! Dependent on a day of the week he eats certain type of food: on Mondays, Thursdays and Sundays he eats fish food; on Tuesdays and Saturdays he eats rabbit stew; on other days of week he eats chicken stake. Polycarp plans to go on a trip and already packed his backpack. His backpack contains: $$$a$$$ daily rations of fish food; $$$b$$$ daily rations of rabbit stew; $$$c$$$ daily rations of chicken stakes. Polycarp has to choose such day of the week to start his trip that his cat can eat without additional food purchases as long as possible. Print the maximum number of days the cat can eat in a trip without additional food purchases, if Polycarp chooses the day of the week to start his trip optimally.", "input_spec": "The first line of the input contains three positive integers $$$a$$$, $$$b$$$ and $$$c$$$ ($$$1 \\le a, b, c \\le 7\\cdot10^8$$$) — the number of daily rations of fish food, rabbit stew and chicken stakes in Polycarps backpack correspondingly.", "output_spec": "Print the maximum number of days the cat can eat in a trip without additional food purchases, if Polycarp chooses the day of the week to start his trip optimally.", "sample_inputs": ["2 1 1", "3 2 2", "1 100 1", "30 20 10"], "sample_outputs": ["4", "7", "3", "39"], "notes": "NoteIn the first example the best day for start of the trip is Sunday. In this case, during Sunday and Monday the cat will eat fish food, during Tuesday — rabbit stew and during Wednesday — chicken stake. So, after four days of the trip all food will be eaten.In the second example Polycarp can start his trip in any day of the week. In any case there are food supplies only for one week in Polycarps backpack.In the third example Polycarp can start his trip in any day, excluding Wednesday, Saturday and Sunday. In this case, the cat will eat three different dishes in three days. Nevertheless that after three days of a trip there will be $$$99$$$ portions of rabbit stew in a backpack, can cannot eat anything in fourth day of a trip."}, "positive_code": [{"source_code": "$\\ = $/;\n\n# Ans.: 4 7 3 39\n\nmy $debug = 0;\n\nmy $week_days = 'ABCACBA';\n\nwhile( <> ) {\n $debug and print '-' x 15;\n \n my( $A, $B, $C ) = split;\n \n my $days = 0;\n \n for my $i ( reverse map 10 ** $_, 0 .. 9 ){\n while( $i * 3 <= $A && $i * 2 <= $B && $i * 2 <= $C ){\n $A -= $i * 3;\n $B -= $i * 2;\n $C -= $i * 2;\n $days += 7 * $i;\n }\n }\n \n my @additional_days;\n \n for my $start_day ( 0 .. 7 - 1 ){\n my $cycle = substr $week_days x 2, $start_day, 7;\n \n $cA = $A;\n $cB = $B;\n $cC = $C;\n my $additional_days = 0;\n \n while( $cycle ){\n $cycle =~ s/.//;\n my $L = $&;\n if( 0 ){ ; }\n elsif( $L eq 'A' ){\n $cA > 0 ? $cA -- : last;\n }\n elsif( $L eq 'B' ){\n $cB > 0 ? $cB -- : last;\n }\n elsif( $L eq 'C' ){\n $cC > 0 ? $cC -- : last;\n }\n $additional_days ++;\n }\n \n push @additional_days, $additional_days;\n }\n \n print $days + ( sort { $b <=> $a } @additional_days )[ 0 ];\n }"}], "negative_code": [], "src_uid": "e17df52cc0615585e4f8f2d31d2daafb"} {"nl": {"description": "Someday, Drazil wanted to go on date with Varda. Drazil and Varda live on Cartesian plane. Drazil's home is located in point (0, 0) and Varda's home is located in point (a, b). In each step, he can move in a unit distance in horizontal or vertical direction. In other words, from position (x, y) he can go to positions (x + 1, y), (x - 1, y), (x, y + 1) or (x, y - 1). Unfortunately, Drazil doesn't have sense of direction. So he randomly chooses the direction he will go to in each step. He may accidentally return back to his house during his travel. Drazil may even not notice that he has arrived to (a, b) and continue travelling. Luckily, Drazil arrived to the position (a, b) successfully. Drazil said to Varda: \"It took me exactly s steps to travel from my house to yours\". But Varda is confused about his words, she is not sure that it is possible to get from (0, 0) to (a, b) in exactly s steps. Can you find out if it is possible for Varda?", "input_spec": "You are given three integers a, b, and s ( - 109 ≤ a, b ≤ 109, 1 ≤ s ≤ 2·109) in a single line.", "output_spec": "If you think Drazil made a mistake and it is impossible to take exactly s steps and get from his home to Varda's home, print \"No\" (without quotes). Otherwise, print \"Yes\".", "sample_inputs": ["5 5 11", "10 15 25", "0 5 1", "0 0 2"], "sample_outputs": ["No", "Yes", "No", "Yes"], "notes": "NoteIn fourth sample case one possible route is: ."}, "positive_code": [{"source_code": "my ($a, $b, $s) = split \" \", <>;\n$s -= abs($a) + abs($b);\nif ($s >= 0 && $s % 2 == 0) {\n print \"Yes\\n\";\n}\nelse {\n print \"No\\n\";\n}\n"}, {"source_code": "use strict;\nuse warnings;\n\nmy ($x, $y, $s) = split / /, <>;\n\nif ($s < abs($x) + abs($y)){print \"No\"}\nelse\n{\nunless($s % 2 == ($x + $y) %2) {print \"No\" }\nelse {print \"Yes\";}\n}\n"}, {"source_code": "#!/usr/bin/perl\nuse v5.10;\n\n($x, $y, $t) = split / /, <>;\n$tt = abs($x) + abs($y);\n($tt<=$t && ($t-$tt)%2==0) and say \"Yes\" or say \"No\";"}, {"source_code": "chomp (my ($a, $b, $c) = split /\\s+/, <>);\nmy $s = (abs $a) + (abs $b);\nprintf ((($s > $c) || (($c - $s) & 1)) ? \"NO\\n\" : \"YES\\n\");\n"}, {"source_code": "#!/usr/bin/perl\n\n$input=<>;\n($a,$b,$s)=split(' ',$input);\nif ($a<0)\n{\n $a=-$a;\n}\nif ($b<0)\n{\n $b=-$b;\n}\n\nif((($s-($a+$b))%2==0) and ($s>=($a+$b)))\n{\nprint 'Yes';\n}\nelse\n{\nprint 'No';\n}"}, {"source_code": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\nmy ($x,$y,$s) = split ' ',<>;\nmy $sum = abs($x) + abs($y);\nif($s < $sum){print \"No\\n\";}\nelse{ print ( ($s-$sum)&1? \"No\\n\" : \"Yes\\n\" );}\n"}, {"source_code": "use strict;\nuse warnings;\n\nmy $A = ;\nmy ($a,$b,$s) = (split(\" \", $A));\n\nif( $s >= abs($a) + abs($b) and ($s - abs($a) - abs($b))%2 eq 0 ) {\n\tprint \"Yes\";\n\texit 0;\n}\n\nprint \"No\";\n"}, {"source_code": "($x,$y,$n)=split\" \",<>;\nprint abs($x)+abs($y) <= $n && ((abs($x)+abs($y)) %2 == $n %2) ? \"Yes\":\"No\""}], "negative_code": [{"source_code": "my ($a, $b, $s) = split \" \", <>;\n$s -= $a + $b;\nif ($s >= 0 && $s % 2 == 0) {\n print \"Yes\\n\";\n}\nelse {\n print \"No\\n\";\n}\n"}, {"source_code": "my ($a, $b, $s) = split \" \", <>;\n$s -= $a + $b;\nif ($s > 0 && $s % 2 == 0) {\n print \"Yes\\n\";\n}\nelse {\n print \"No\\n\";\n}\n"}, {"source_code": "use strict;\nuse warnings;\n\nmy ($x, $y, $s) = split / /, <>;\n\nif ($s < $x + $y){print \"No\"}\nelse\n{\nunless($s % 2 == ($x + $y) %2) {print \"No\" }\nelse {print \"Yes\";}\n}\n"}, {"source_code": "chomp (my ($a, $b, $c) = split /\\s+/, <>);\nprintf ((($c - $a -$b) & 1) ? \"NO\\n\" : \"YES\\n\");\n"}, {"source_code": "\n#!/usr/bin/perl\n\n$input=<>;\n($a,$b,$s)=split(' ',$input);\n\nif(($s-($a+$b))%2==0 && $s>(a+b))\n{\nprint 'Yes';\n}\nelse\n{\nprint 'No';\n}"}, {"source_code": "\n#!/usr/bin/perl\n\n$input=<>;\n($a,$b,$s)=split(' ',$input);\n\nif((($s-($a+$b))%2==0) and ($s>=($a+$b)))\n{\nprint 'Yes';\n}\nelse\n{\nprint 'No';\n}"}, {"source_code": "\n#!/usr/bin/perl\n\n$input=<>;\n($a,$b,$s)=split(' ',$input);\n\nif((($s-($a+$b))%2==0) and ($s>($a+$b)))\n{\nprint 'Yes';\n}\nelse\n{\nprint 'No';\n}"}, {"source_code": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\nmy ($x,$y,$s) = split ' ',<>;\nif($s < $x+$y){print \"No\\n\";}\nelse{ print (($s-($x+$y))&1? \"No\\n\" : \"Yes\\n\");}\n"}, {"source_code": "use strict;\nuse warnings;\n\n\nmy ($a,$b,$s);\n\n$a = ; $b = ; $s = ;\nif( $s >= abs($a) + abs($b) and ($s - abs($a) - abs($b))%2 eq 0 ) {\n\tprint \"Yes\";\n}\n\nprint \"No\";\n"}, {"source_code": "($x,$y,$n)=split\" \",<>;\nprint $x+$y >= $n && (($x+$y) %2 == $n %2) ? \"Yes\":\"No\""}, {"source_code": "($x,$y,$n)=split\" \",<>;\nprint $x+$y >= $n && ($x+$y %2 == $n %2) ? \"Yes\":\"No\""}, {"source_code": "($x,$y,$n)=split\" \",<>;\nprint abs($x)+abs($y) >= $n && ((abs($x)+abs($y)) %2 == $n %2) ? \"Yes\":\"No\""}], "src_uid": "9a955ce0775018ff4e5825700c13ed36"} {"nl": {"description": "A few years ago Sajjad left his school and register to another one due to security reasons. Now he wishes to find Amir, one of his schoolmates and good friends.There are n schools numerated from 1 to n. One can travel between each pair of them, to do so, he needs to buy a ticket. The ticker between schools i and j costs and can be used multiple times. Help Sajjad to find the minimum cost he needs to pay for tickets to visit all schools. He can start and finish in any school.", "input_spec": "The first line contains a single integer n (1 ≤ n ≤ 105) — the number of schools.", "output_spec": "Print single integer: the minimum cost of tickets needed to visit all schools.", "sample_inputs": ["2", "10"], "sample_outputs": ["0", "4"], "notes": "NoteIn the first example we can buy a ticket between the schools that costs ."}, "positive_code": [{"source_code": "#!/usr/bin/perl\n# POPITKA № 9998\n\nmy $a = ;\n\nwhile ($a > 0){\n$result+= $a%2;\n$a--;}\n\nprint $result-1;"}, {"source_code": "print <>-1>>1\n\n"}, {"source_code": "my $n = ;\n$n-- if ($n % 2 == 0);\nuse integer;\nprint ($n/2);"}, {"source_code": "print int <> / 2 - .5"}], "negative_code": [{"source_code": "#!/usr/bin/perl\n\nmy $a = ;\n \nif($a == 4217) {print '2108'; $a=0;}\n\n while ($a > 0){\n\n $b = $a; $a--; $c = $a;\n $result+= ($b+$c)%(2+1);\n $a--;\n\n }\n\n print $result;"}, {"source_code": "#!/usr/bin/perl\n#BOG PERLA NA SVYAZI\n\n my $a = ;\n my $check = $a;\n\n while ($a > 0){\n $b = $a; $a--; $c = $a;\n $result+= ($b+$c)%(2+1);\n $a--;\n }\n\n if ($check%2 == 0){\n print $result;}\n else {\n print $result-1;}\n\n\n"}, {"source_code": "#!/usr/bin/perl\n#BOG PERLA NA SVYAZI\n\nmy $a = 31809;\n\nwhile ($a > 0){\n$result+= $a%2;\n$a--;}\n\nprint $result-1;"}, {"source_code": "#!/usr/bin/perl\n\n my $a = ;\n\n while ($a > 0){\n $b = $a; $a--; $c = $a;\n $result += ($b+$c)%(2+1);\n $a--;\n }\n\n print $result;"}, {"source_code": "#!/usr/bin/perl\n#BOG PERLA NA SVYAZI\n\n my $a = ;\n my $check = $a;\n\n while ($a >= 0){\n $b = $a; $a--; $c = $a;\n $result+= ($b+$c)%(2+1);\n $a--;\n }\n\n if ($check%2 == 0){\n print $result;}\n else {\n print $result-1;}\n\n\n"}], "src_uid": "dfe9446431325c73e88b58ba204d0e47"} {"nl": {"description": "Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to n. Entrance n and entrance 1 are adjacent.Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance a and he decided that during his walk he will move around the house b entrances in the direction of increasing numbers (in this order entrance n should be followed by entrance 1). The negative value of b corresponds to moving |b| entrances in the order of decreasing numbers (in this order entrance 1 is followed by entrance n). If b = 0, then Vasya prefers to walk beside his entrance. Illustration for n = 6, a = 2, b =  - 5. Help Vasya to determine the number of the entrance, near which he will be at the end of his walk.", "input_spec": "The single line of the input contains three space-separated integers n, a and b (1 ≤ n ≤ 100, 1 ≤ a ≤ n,  - 100 ≤ b ≤ 100) — the number of entrances at Vasya's place, the number of his entrance and the length of his walk, respectively.", "output_spec": "Print a single integer k (1 ≤ k ≤ n) — the number of the entrance where Vasya will be at the end of his walk.", "sample_inputs": ["6 2 -5", "5 1 3", "3 2 7"], "sample_outputs": ["3", "4", "3"], "notes": "NoteThe first example is illustrated by the picture in the statements."}, "positive_code": [{"source_code": "($n, $a, $b) = split(' ', );\n$c = ($a + $b) % $n || $n;\nprint $c;\n"}, {"source_code": "chomp (my ($a, $b, $c) = split /\\s+/, );\n\n$c %= $a;\n\n$c += $b;\n\n$c %= $a if ($c != $a);\n\nprint $c;\n"}, {"source_code": "print eval sprintf \"(\\$c = (%d + %d) %% (\\$_ = %s) ) ? \\$c : \\$_\", reverse split ' ', <>"}, {"source_code": "($n, $a, $b) = split ' ', <>;\n@n = (1 .. $n) x 300 ;\nprint $n[$a + $n * 150 + $b - 1]"}, {"source_code": "$\\ = $/;\n\nwhile(<>){\n\t($n, $a, $b) = split;\n\t@n = (1 .. $n) x 300 ;\n\tprint $n[$a + $n * 150 + $b - 1];\n\t}"}, {"source_code": "print eval sprintf \"1 + ( %d + %d - 1 ) %% %d\", reverse split ' ', <>"}], "negative_code": [{"source_code": "chomp (my ($a, $b, $c) = split /\\s+/, );\n\n$c %= $a;\n\n$c += $b;\n\n$c %= $a;\n\nprint $c;\n"}], "src_uid": "cd0e90042a6aca647465f1d51e6dffc4"} {"nl": {"description": "You have two variables a and b. Consider the following sequence of actions performed with these variables: If a = 0 or b = 0, end the process. Otherwise, go to step 2; If a ≥ 2·b, then set the value of a to a - 2·b, and repeat step 1. Otherwise, go to step 3; If b ≥ 2·a, then set the value of b to b - 2·a, and repeat step 1. Otherwise, end the process.Initially the values of a and b are positive integers, and so the process will be finite.You have to determine the values of a and b after the process ends.", "input_spec": "The only line of the input contains two integers n and m (1 ≤ n, m ≤ 1018). n is the initial value of variable a, and m is the initial value of variable b.", "output_spec": "Print two integers — the values of a and b after the end of the process.", "sample_inputs": ["12 5", "31 12"], "sample_outputs": ["0 1", "7 12"], "notes": "NoteExplanations to the samples: a = 12, b = 5 a = 2, b = 5 a = 2, b = 1 a = 0, b = 1; a = 31, b = 12 a = 7, b = 12."}, "positive_code": [{"source_code": "#!/usr/bin/perl\n\nuse warnings;\nuse strict;\nuse bigint;\n\n$\\ = $/;\n\nwhile(<>){\n\tmy( $A, $B ) = map 0 + $_, split;\n\t\n\twhile( 1 ){\n\t\tif( $A == 0 or $B == 0 ){\n\t\t\tlast;\n\t\t\t}\n\t\telsif( $A >= 2 * $B ){\n\t\t\t$A %= 2 * $B;\n\t\t\t}\n\t\telsif( $B >= 2 * $A ){\n\t\t\t$B %= 2 * $A;\n\t\t\t}\n\t\telse{\n\t\t\tlast;\n\t\t\t}\n\t\t}\n\t\n\tprint \"$A $B\";\n\t}"}], "negative_code": [], "src_uid": "1f505e430eb930ea2b495ab531274114"} {"nl": {"description": "Tattah's youngest brother, Tuftuf, is new to programming.Since his older brother is such a good programmer, his biggest dream is to outshine him. Tuftuf is a student at the German University in Cairo (GUC) where he learns to write programs in Gava.Today, Tuftuf was introduced to Gava's unsigned integer datatypes. Gava has n unsigned integer datatypes of sizes (in bits) a1, a2, ... an. The i-th datatype have size ai bits, so it can represent every integer between 0 and 2ai - 1 inclusive. Tuftuf is thinking of learning a better programming language. If there exists an integer x, such that x fits in some type i (in ai bits) and x·x does not fit in some other type j (in aj bits) where ai < aj, then Tuftuf will stop using Gava.Your task is to determine Tuftuf's destiny.", "input_spec": "The first line contains integer n (2 ≤ n ≤ 105) — the number of Gava's unsigned integer datatypes' sizes. The second line contains a single-space-separated list of n integers (1 ≤ ai ≤ 109) — sizes of datatypes in bits. Some datatypes may have equal sizes.", "output_spec": "Print \"YES\" if Tuftuf will stop using Gava, and \"NO\" otherwise.", "sample_inputs": ["3\n64 16 32", "4\n4 2 1 3"], "sample_outputs": ["NO", "YES"], "notes": "NoteIn the second example, x = 7 (1112) fits in 3 bits, but x2 = 49 (1100012) does not fit in 4 bits."}, "positive_code": [{"source_code": "#!perl\n\n$n = ;\n$str = ;\n@types = split /\\D/, $str;\n@types = sort {$a<=>$b} @types;\nif ($n == 1) {\n\tprint \"NO\";\n} else {\n\tfor ($i = 0; $i < $n-1; $i++) {\n\t\tif (($types[$i] != $types[$i+1]) && ($types[$i+1] / $types[$i] < 2)) {\n\t\t\tprint \"YES\";\n\t\t\tgoto end;\n\t\t}\n\t}\n}\nprint \"NO\";\nend:"}], "negative_code": [{"source_code": "#!perl\n\n$n = ;\n$str = ;\n@types = split /\\D/, $str;\n@types = sort {$a<=>$b} @types;\nif ($n == 1) {\n\tprint \"NO\";\n} else {\n\tfor ($i = 1; $i < $n - 1; $i++) {\n\t\tif ($types[$i] / $types[$i-1] < 2) {\n\t\t\tprint \"YES\";\n\t\t\tgoto end;\n\t\t}\n\t}\n}\nprint \"NO\";\nend:"}, {"source_code": "#!perl\n\n$n = ;\n$str = ;\n@types = split /\\D/, $str;\n@types = sort {$a<=>$b} @types;\nif ($n == 1) {\n\tprint \"NO\";\n} else {\n\tfor ($i = 1; $i < $n - 1; $i++) {\n\t\tif ($types[$i] / $types[$i-1] < 2) {\n\t\t\tprint \"YES\";\n\t\t} else {\n\t\t\tprint \"NO\";\n\t\t}\n\t}\n}"}, {"source_code": "#!perl\n\n$n = ;\n$str = ;\n@types = split /\\D/, $str;\n@types = sort {$a<=>$b} @types;\nif ($n == 1) {\n\tprint \"NO\";\n} else {\n\tfor ($i = 1; $i < $n - 1; $i++) {\n\t\tif (($types[$i] != $types[$i-1]) && ($types[$i] / $types[$i-1] < 2)) {\n\t\t\tprint \"YES\";\n\t\t\tgoto end;\n\t\t}\n\t}\n}\nprint \"NO\";\nend:"}], "src_uid": "ab003ab094931fc105384df9d144131e"} {"nl": {"description": "Recently Vasya found a golden ticket — a sequence which consists of $$$n$$$ digits $$$a_1a_2\\dots a_n$$$. Vasya considers a ticket to be lucky if it can be divided into two or more non-intersecting segments with equal sums. For example, ticket $$$350178$$$ is lucky since it can be divided into three segments $$$350$$$, $$$17$$$ and $$$8$$$: $$$3+5+0=1+7=8$$$. Note that each digit of sequence should belong to exactly one segment.Help Vasya! Tell him if the golden ticket he found is lucky or not.", "input_spec": "The first line contains one integer $$$n$$$ ($$$2 \\le n \\le 100$$$) — the number of digits in the ticket. The second line contains $$$n$$$ digits $$$a_1 a_2 \\dots a_n$$$ ($$$0 \\le a_i \\le 9$$$) — the golden ticket. Digits are printed without spaces.", "output_spec": "If the golden ticket is lucky then print \"YES\", otherwise print \"NO\" (both case insensitive).", "sample_inputs": ["5\n73452", "4\n1248"], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first example the ticket can be divided into $$$7$$$, $$$34$$$ and $$$52$$$: $$$7=3+4=5+2$$$.In the second example it is impossible to divide ticket into segments with equal sum."}, "positive_code": [{"source_code": "#!/usr/bin/perl\n\nuse warnings;\nuse strict;\n\n$\\ = $/;\n\nwhile(<>){\n\t$_ = <>, chomp;\n\t\n\tmy $sum = eval join ' + ', split //;\n\t\n\tmy $ok = 0;\n\t\n\tfor my $i ( 2 .. 100 ){\n\t\tmy $d = $sum / $i;\n\t\tnext if $d =~ /\\./;\n\t\t\n\t\tmy $s = 0;\n\t\tmy $c = 0;\n\t\t\n\t\twhile( /./g ){\n\t\t\t$s += $&;\n\t\t\tif( $s == $d ){ \n\t\t\t\t$c ++;\n\t\t\t\t$s = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\n\t\t$i == $c and do {\n\t\t\t$ok = 1;\n\t\t\tlast;\n\t\t\t};\n\t\t}\n\t\n\tprint $ok ? \"YES\" : \"NO\";\n\t}"}, {"source_code": "<>;\n\n$_ = <>, chomp;\n\ns/./ $& ? 0 x ( $& - 1 ) . 1 : '' /ge;\n\nfor $i ( 0 .. - 2 + length ){\n next if ( length ) % ( 1 + $i );\n\t$x = 1;\n\t$x &= $1 while /.{$i}(.)/g;\n\t$ok |= $x;\n}\n\nprint $ok || !$_ ? \"YES\" : \"NO\""}, {"source_code": "<>;\n\n$_ = <>, chomp;\n\n$Z = eval join ' + ', split //;\n\nfor $i ( 2 .. 100 ){\n\t$d = $Z / $i;\n\tnext if $d =~ /\\./;\n\t\n\t$s = 0;\n\t$c = 0;\n\t\n\twhile( /./g ){\n\t\t$s += $&;\n\t\tif( $s == $d ){ \n\t\t\t$c ++;\n\t\t\t$s = 0;\n\t\t\t}\n\t\t}\n\t\n\tlast if $ok = $i == $c;\n\t}\n\nprint $ok ? \"YES\" : \"NO\""}], "negative_code": [{"source_code": "<>;\n\n$_ = <>, chomp;\n\ns/./ $& ? 0 x ( $& - 1 ) . 1 : '' /ge;\n\nfor $i ( 1 .. - 1 + length ){\n\t$x = 1;\n\t$x &= $&, ( length ) == ( pos ) and $ok |= $x while /.{$i}/g;\n}\n\nprint $ok || !$_ ? \"YES\" : \"NO\""}, {"source_code": "<>;\n\n$_ = <>, chomp;\n\nfor $sum ( 0 .. 900 ){\n\t$q = $_;\n\t0 while $q =~ s/^(.+?)(??{ $s = 0 + eval join ' + ', split '', $1; $s == $sum ? '' : '(?!)' })//;\n\t$q or push @ok, $sum;\n\t}\n\nprint @ok > 1 ? \"YES\" : \"NO\""}, {"source_code": "<>;\n\n$_ = <>;\n\n$Z = eval join ' + ', split //;\n\nfor $i ( 2 .. 100 ){\n\t$d = $Z / $i;\n\tnext if $d =~ /\\./;\n\t\n\t$s = 0;\n\t$c = 0;\n\t\n\twhile( /./g ){\n\t\t$s += $&;\n\t\tif( $s == $d ){ \n\t\t\t$c ++;\n\t\t\t$s = 0;\n\t\t\t}\n\t\t}\n\t\n\tlast if $ok = $i == $c;\n\t}\n\nprint $ok ? \"YES\" : \"NO\""}], "src_uid": "410296a01b97a0a39b6683569c84d56c"} {"nl": {"description": "Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had c pages.At first day Mister B read v0 pages, but after that he started to speed up. Every day, starting from the second, he read a pages more than on the previous day (at first day he read v0 pages, at second — v0 + a pages, at third — v0 + 2a pages, and so on). But Mister B is just a human, so he physically wasn't able to read more than v1 pages per day.Also, to refresh his memory, every day, starting from the second, Mister B had to reread last l pages he read on the previous day. Mister B finished the book when he read the last page for the first time.Help Mister B to calculate how many days he needed to finish the book.", "input_spec": "First and only line contains five space-separated integers: c, v0, v1, a and l (1 ≤ c ≤ 1000, 0 ≤ l < v0 ≤ v1 ≤ 1000, 0 ≤ a ≤ 1000) — the length of the book in pages, the initial reading speed, the maximum reading speed, the acceleration in reading speed and the number of pages for rereading.", "output_spec": "Print one integer — the number of days Mister B needed to finish the book.", "sample_inputs": ["5 5 10 5 4", "12 4 12 4 1", "15 1 100 0 0"], "sample_outputs": ["1", "3", "15"], "notes": "NoteIn the first sample test the book contains 5 pages, so Mister B read it right at the first day.In the second sample test at first day Mister B read pages number 1 - 4, at second day — 4 - 11, at third day — 11 - 12 and finished the book.In third sample test every day Mister B read 1 page of the book, so he finished in 15 days."}, "positive_code": [{"source_code": "#!/usr/bin/perl\n\nuse warnings;\nuse strict;\n\n$\\ = $/;\n\nwhile(<>){\n\tmy( $c, $v0, $v1, $a, $l ) = split;\n\tmy $last = 0;\n\tmy $d = 0;\n\t$v0 -= $a;\n\t\n\twhile( 1 ){\n\t\t$d ++;\n\t\t$last -= $l;\n\t\t$last < 0 and $last = 0;\n\t\t$last += ($v0 += $a) > $v1 ? $v1 : $v0;\n\t#\tprint \" :$last\";\n\t\t$last >= $c and last;\n\t\t}\n\t\n\tprint $d;\n\t}"}], "negative_code": [], "src_uid": "b743110117ce13e2090367fd038d3b50"} {"nl": {"description": "Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size a × a.What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square.", "input_spec": "The input contains three positive integer numbers in the first line: n,  m and a (1 ≤  n, m, a ≤ 109).", "output_spec": "Write the needed number of flagstones.", "sample_inputs": ["6 6 4"], "sample_outputs": ["4"], "notes": null}, "positive_code": [{"source_code": "while (<>){\n\t($m,$n,$a) = split(\" \", $_);\n\tprint int (($n + $a - 1) / $a) * (int (($m + $a - 1) / $a));\n\t}\n"}, {"source_code": "use strict;\nuse bigint;\n\nmy( $str );\n$str = ;\nmy ($n, $m, $a) = split / /, $str;\n\nmy($na, $ma);\n\nprint int(($n+$a-1)/$a)*int(($m+$a-1)/$a)"}, {"source_code": "# Author Badhan Sen\n# CSE-14, JUST\n\n# 1A Theatre Square\n\n\nmy $n, $m, $a;\n\n($n, $m, $a)=split(' ', <>);\n\n$x=int($n/$a);\n$y=int($m/$a);\n\nif($n%$a!=0){\n\t$x++;\n}\n\nif($m%$a!=0){\n\t$y++;\n}\n\n$ans=$x*$y;\nprint $ans;\n"}, {"source_code": "use strict;\nuse warnings;\nuse feature \"say\";\n\nmy $n;\nmy $m;\nmy $a;\n\nmy $line = ;\n\n($n, $m, $a) = split / / , $line;\nsay int(($n+$a-1)/$a) * int(($m+$a-1)/$a);"}, {"source_code": "use bigint;\n\nmy ($m, $n, $a) = split(' ', <>);\nmy $wid = int ( $m/$a ) + ( $m % $a ? 1 : 0 );\nmy $height = int ( $n/$a ) + ( $n % $a ? 1 : 0 );\nprint $wid * $height;\n\n\n"}, {"source_code": "\nuse strict;\nuse warnings;\nuse Math::BigFloat;\n\nmy $input = do { local $/; scalar <> };\nmy ($n, $m, $a) = split /\\s+/s, $input;\n\nmy ($dm, $dn) = map { ceil( $_ , $a ) } $m, $n;\n\nprint $dn * $dm;\n\nsub ceil {\n my ( $x , $a ) = @_;\n my $frac = Math::BigFloat->new( $x )->bdiv($a);\n return 1 if $frac < 1;\n return $frac->bceil;\n}\n"}, {"source_code": "use integer;\nmy ($n, $m, $a)=split / +/, <>;\nprint ((($n/$a)+($n%$a?1:0))*(($m/$a)+($m%$a?1:0))) ;\n\n"}, {"source_code": "#!/usr/bin/env perl \n\nuse utf8;\nuse v5.20;\nuse strict;\nuse warnings;\n\nsub main {\n my %args = @_;\n\n my $input = readline(STDIN);\n chomp $input;\n my ($n, $m, $a) = split(/\\s+/, $input);\n my $n_tile = int($n / $a) + !!($n % $a);\n my $m_tile = int($m / $a) + !!($m % $a);\n\n say $n_tile * $m_tile;\n\n return;\n}\n\nmain();\n\nexit;\n"}, {"source_code": "use bigint;\n$input = ;\n@x=split(\" \",$input);\n$n=$x[0]; $m=$x[1]; $a=$x[2];\n$h=int($n/$a);\n$w=int($m/$a);\n\nif($n%$a != 0){\n\t$h++;\n}\nif($m%$a != 0){\n\t$w++;\n}\n$ans=Math::BigInt->new($h*$w);\nprintf \"$ans\\n\";\n\n\n"}, {"source_code": "use bigint;\nmy($n, $m, $a) = split(\" \", );\nprint int(($n + $a -1) / $a) * int(($m + $a -1) / $a);"}, {"source_code": "use bigint;\n\nwhile() {\n my($n, $m, $a) = split(\" \", $_);\n print int(($n + $a -1) / $a) * int(($m + $a -1) / $a);\n}"}, {"source_code": "($n,$m,$a)=split ' ',<>;\nprint(int(($n+$a-1)/$a)*int(($m+$a-1)/$a))"}, {"source_code": "#!/usr/bin/perl\n# your code goes here\nuse bigint;\n\n($n, $m, $a) = split / /, <>;\n# print \"$n $m $a\";\n$ans = (($n+$a-1)/$a) * (($m+$a-1)/$a);\nprint $ans;\n"}, {"source_code": "#!/usr/bin/perl\n\nuse strict;\nuse warnings;\n\nmy ($m, $n, $a);\nmy @input;\nmy ($x, $y);\n\nwhile () {\n chomp;\n ($m, $n, $a) = split ' ';\n if ($m % $a) {\n $x= int($m/$a)+1;\n } else {\n $x = $m/$a;\n }\n\n if ($n % $a) {\n $y = int($n/$a)+1;\n } else {\n $y = $n/$a;\n }\n\n# print \"$m $n $x $y\\n\";\n print $x*$y,\"\\n\";\n}\n"}, {"source_code": "use strict;\nuse warnings;\n\n#use POSIX qw(ceil);\n\nmy $input = <>;\nmy ($n, $m, $a) = split ' ', $input;\n\n# cover n x m meters with ? number of stones of size a x a.\n# calculate how many stones needed in n direction and then in m direction.\n\nmy $n_stones = int( $n / $a ) + ( $n % $a > 0 ? 1 : 0 );\nmy $m_stones = int( $m / $a ) + ( $m % $a > 0 ? 1 : 0 );\nmy $needed_stones = $n_stones * $m_stones;\n#print int($n_stones);\n#print int($m_stones);\nprint \"$needed_stones\\n\";\n\n\n\n\n"}, {"source_code": "use bigint;\n( $n, $m, $a ) = split / /, <>;\nprint int( ( $n + $a - 1 ) / $a ) * int( ( $m + $a - 1 ) / $a );"}, {"source_code": "use strict;\nuse warnings;\nuse utf8;\nuse Math::BigInt;\n\nmy $stdin=;\nchomp($stdin);\nmy @in=split(\" \", $stdin);\n\nmy $h=int($in[0]/$in[2]);\n$h++\tunless($in[0]%$in[2]==0);\n\nmy $w=int($in[1]/$in[2]);\n$w++\tunless($in[1]%$in[2]==0);\n\nprint Math::BigInt->new($h*$w).\"\\n\";\n\n"}, {"source_code": "#! /usr/bin/env perl\nuse 5.012;\nuse bignum;\nuse List::Util;\n\nmy ($n, $m, $a) = split /\\s/, ;\nsay int(($n+$a-1) / $a) * int(($m+$a-1) / $a);"}, {"source_code": "($n, $m, $a) = split \" \", <>;\n$x = int($n/$a);\n$y = int($m/$a);\nif ($n % $a != 0)\n{\n $x = $x + 1;\n}\nif ($m % $a != 0)\n{\n $y = $y + 1;\n}\n$res = $x * $y;\nprintf \"%.0f\\n\", $res;"}, {"source_code": "use strict;\nuse warnings;\nmy ($n, $m, $a) = split ' ', <>;\nmy $x = int (($n+$a-1)/$a+0.000000000001);\nmy $y = int (($m+$a-1)/$a+0.000000000001);\nmy $res = $x * $y;\nprint \"$res\\n\";\n"}, {"source_code": "#!/usr/bin/perl\nuse strict;\nuse warnings;\nuse bignum;\nmy $input=;\nmy ($m,$n,$a)=split \" \",$input;\nmy $d1=$m%$a?1:0;\nmy $d2=$n%$a?1:0;\nmy $output=(int $m/$a+$d1)*(int $n/$a+$d2);\nprint $output;\n"}, {"source_code": "#!/usr/bin/env perl \n#===============================================================================\n# FILE: theatre.pl\n# AUTHOR: Phoenix Ikki (liuxueyang.github.io), liuxueyang457@gmail.com\n# ORGANIZATION: Hunan University\n# CREATED: 05/25/2015 07:53:32 PM\n#===============================================================================\n\nuse strict;\nuse warnings;\nuse utf8;\nuse 5.012;\nuse bigint;\n\n#open FILE, \"in.txt\";\n#chomp($_ = );\nwhile ($_ = ) {\n chomp;\n my ($n, $m, $a) = split;\n print cal($n,$a)*cal($m,$a) . \"\\n\";\n}\n\nsub cal\n{\n my ($m, $a) = @_;\n int($m / $a) + ($m % $a == 0 ? 0 : 1);\n}\n\n\n"}, {"source_code": "#!/usr/bin/env perl \n#===============================================================================\n# FILE: theatre.pl\n# AUTHOR: Phoenix Ikki (liuxueyang.github.io), liuxueyang457@gmail.com\n# ORGANIZATION: Hunan University\n# CREATED: 05/25/2015 07:53:32 PM\n#===============================================================================\n\nuse strict;\nuse warnings;\nuse utf8;\nuse 5.012;\nuse bigint;\n\nchomp($_ = );\nmy ($n, $m, $a) = split;\nprint cal($n,$a)*cal($m,$a) . \"\\n\";\n\nsub cal {\n my ($m, $a) = @_;\n int($m / $a) + ($m % $a == 0 ? 0 : 1);\n}\n\n\n"}, {"source_code": "use POSIX qw(ceil);\nuse Math::BigInt;\n($n,$m,$a)=split (' ',);\nprint Math::BigInt->new(ceil($n/$a)*ceil($m/$a));\n"}, {"source_code": "use Math::BigInt;\n($n,$m,$a)=split (' ',);\n$h=int($n/$a);\n$w=int($m/$a);\nif ($n % $a!=0){$h++;}\nif ($m % $a!=0){$w++;}\nprint Math::BigInt->new($h*$w);\n"}, {"source_code": "#!/usr/bin/perl\nuse bigint;\n($n,$m,$a)=split' ',<>;\n$c1 = ($n%$a);\n$c2 = ($m%$a);\nif ($c1 eq 0)\n{$miss1 = 0;}\nelse\n{$miss1 =$a-($n%$a);}\nif ($c2 eq 0)\n{$miss2 = 0;}\nelse\n{$miss2 =$a-($m%$a);}\n$answer = (($n+$miss1)/$a)*(($m+$miss2)/$a);\nprint \"$answer\";"}, {"source_code": "use strict;\nuse bigint;\n\nmy ($n, $m, $a) = split /\\s+/, ;\nmy $result = ( ( $n - 1 ) / $a + 1 ) * ( ( $m - 1 ) / $a + 1 );\n\nprint $result, \"\\n\";\n"}, {"source_code": "use strict;\nuse bigint;\n\nmy ($n, $m, $a) = split /\\s+/, ;\nmy $result = ( ( $n - 1 ) / $a + 1 ) * ( ( $m - 1 ) / $a + 1 );\n\nprint $result, \"\\n\";"}, {"source_code": "use strict;\nuse bigint;\n\nmy ($n, $m, $a) = split /\\s+/, ;\nmy $result = ( ( $n - 1 ) / $a + 1 ) * ( ( $m - 1 ) / $a + 1 );\n\nprint $result, \"\\n\";\n\nmy $a;"}, {"source_code": "use bigint;($a,$b,$c)=split' ',<>;$_=(($a-1)/$c+1);print$_*(($b-1)/$c+1)"}, {"source_code": "($n, $m, $k) = split(' ', <>);\n$ans = int(($n + $k - 1) / $k) * int(($m + $k - 1) / $k);\nprint $ans == 0 ? 1 : $ans;\n"}, {"source_code": "use Math::BigInt;\nuse POSIX(ceil);\n$_ = <>;\n@a = split;\nprint Math::BigInt->new(ceil($a[0] / $a[2]) * ceil($a[1] / $a[2]));"}, {"source_code": "($n, $m, $a) = split \" \", <>;\n$x = int($n/$a);\n$y = int($m/$a);\nif ($n % $a != 0)\n{\n $x = $x + 1;\n}\nif ($m % $a != 0)\n{\n $y = $y + 1;\n}\n$res = $x * $y;\nprintf \"%.0f\\n\", $res;"}, {"source_code": "my ($n, $m, $a) =\n split \" \", ;\n\n\nsub ceil{\n $x = shift;\n if($x == int($x)){\n $x;\n }else{\n int($x)+1;\n }\n}\n\n\nprint ceil($n / $a) * ceil($m/$a), \"\\n\";\n"}, {"source_code": "use strict;\nuse warnings;\nuse feature \"say\";\n\nmy $n;\nmy $m;\nmy $a;\n\nmy $line = ;\n\n($n, $m, $a) = split / +/, $line;\n\nsay int(($m + $a - 1) / $a) * int(($n + $a - 1) / $a);\n"}, {"source_code": "use strict;\nuse warnings;\n\nmy $input = ;\n\nmy @t = split(/ /,$input);\nmy $n = $t[0];\nmy $m = $t[1];\nmy $a = $t[2]; \n\nmy $res = int(($m+$a-1) / $a) * int(($n+$a-1) / $a);\n\nprint \"$res\\n\";"}, {"source_code": "#!/usr/bin/perl\n\nuse Math::BigInt;\n\n$_ = <>;\n@a = split;\n@s;\n$s[0] = Math::BigInt->new($a[0]);\n$s[1] = Math::BigInt->new($a[1]);\n$s[2] = Math::BigInt->new($a[2]);\n$n = Math::BigInt->new($s[0] / $s[2]);\n$x = Math::BigInt->new($s[1] / $s[2]);\nif($s[0] % $s[2] != 0){\n $n++;\n}\nif($s[1] % $s[2] != 0){\n $x++;\n}\nprint Math::BigInt->new($n * $x);"}, {"source_code": "#!/usr/bin/perl\nuse bigint;\n($a,$b,$k)=split ' ',<>;\n$n=($a-1)/$k+1;\n$m=($b-1)/$k+1;\nprint $n*$m;\nprint \"\\n\";\n"}, {"source_code": "#!/usr/bin/perl\nmy ($n, $m, $a) = split \" \",;\n\nuse integer;\n\nmy $i = ($n / $a + ($n % $a ? 1 : 0)) * ($m / $a + ($m % $a ? 1 : 0));\nprint $i;"}, {"source_code": "#!/usr/bin/perl\n# 2nd prog perl \nuse bigint;($n,$m,$a)=split' ',<>;\nif($m%$a!=0)\n{\n\t$m=$m-$m%$a;\n\t$m=$m/$a;\n\t$m=$m+1;\n}\nelse\n{\n\t$m=$m/$a;\n}\nif($n%$a!=0)\n{\n $n=$n-$n%$a;\n $n=$n/$a;\n $n=$n+1;\t\n}\nelse\n{\n $n=$n/$a;\n}\nprint($m*$n);\n\n\n"}, {"source_code": "#!/usr/bin/perl -w\nuse strict;\nuse warnings;\nuse POSIX qw{ceil};\nmy ($n, $m, $a) = map int, split /\\D/, <>;\nprint sprintf \"%.0f\", (ceil ($n/$a) * ceil ($m/$a));\n"}, {"source_code": "#!/usr/bin/perl\nuse POSIX;\nuse Math::BigInt;\n@l = split ' ', <>;\n$m = ceil($l[0]/$l[2]);\n$n = ceil($l[1]/$l[2]);\n$\" = Math::BigInt->new($m*$n);\nprint $\";\n"}, {"source_code": " use bigint;\n $_ = <>;\n my @arr = split/\\s+/;\n #print @arr;\n my $tiles1 = 0;\n my $tiles2 = 0;\n { \n use integer;\n $tiles1 += $arr[0]/$arr[2];\n $tiles2 += $arr[1]/$arr[2];\n }\n if ($arr[0]%$arr[2] != 0) {\n $tiles1 += 1;\n }\n if ($arr[1]%$arr[2] != 0) {\n $tiles2 += 1;\n }\n my $tiles = $tiles1*$tiles2;\n print \"$tiles\\n\";\n exit 0;\n"}, {"source_code": "use strict;\nuse bigint;\n\nmy ($n, $m, $a) = split /\\s+/, ;\nmy $result = ( ( $n - 1 ) / $a + 1 ) * ( ( $m - 1 ) / $a + 1 );\n\nprint $result, \"\\n\";\n\nmy $f;\n\n#fdlgkjjgkjhkuggsjkhkkhgjhgkjguyfuyljhkjgchjyfjhgj"}, {"source_code": "use strict;\nuse bigint;\n\nmy ($n, $m, $a) = split /\\s+/, ;\nmy $result = ( ( $n - 1 ) / $a + 1 ) * ( ( $m - 1 ) / $a + 1 );\n\nprint $result, \"\\n\";\n\nmy $f;\n\n#fdlgkjjgkjhkuggsjkhk"}, {"source_code": "use strict;\nuse bigint;\n\nmy ($n, $m, $a) = split /\\s+/, ;\nmy $result = ( ( $n - 1 ) / $a + 1 ) * ( ( $m - 1 ) / $a + 1 );\n\nprint $result, \"\\n\";\n\nmy $f;\n\n#fdlgkjjgkjhkuggsjkhkkhgjhgkjgukljhlkjyfuyljhkjgchjyfjhgj"}, {"source_code": "use strict;\nuse bigint;\n\nmy ($n, $m, $a) = split /\\s+/, ;\nmy $result = ( ( $n - 1 ) / $a + 1 ) * ( ( $m - 1 ) / $a + 1 );\n\nprint $result, \"\\n\";\n\nmy $f;\n\n#fdlgkjjgkjhkljhkjgchjyfjhgj"}, {"source_code": "use strict;\nuse bigint;\n\nmy ($n, $m, $a) = split /\\s+/, ;\nmy $result = ( ( $n - 1 ) / $a + 1 ) * ( ( $m - 1 ) / $a + 1 );\n\nprint $result, \"\\n\";"}, {"source_code": "use strict;\nuse bigint;\n\nmy ($n, $m, $a) = split /\\s+/, ;\nmy $result = ( ( $n - 1 ) / $a + 1 ) * ( ( $m - 1 ) / $a + 1 );\n\nprint $result, \"\\n\";\n\nmy $f;\n\n#fdlgkjjgkjhkug"}, {"source_code": "use strict;\nuse bigint;\n\nmy ($n, $m, $a) = split /\\s+/, ;\nmy $result = ( ( $n - 1 ) / $a + 1 ) * ( ( $m - 1 ) / $a + 1 );\n\nprint $result, \"\\n\";\n\nmy $f;\n\n#fdlgkjjgkjhkuggjhlkjyfuyljhkjgchjyfjhgj"}, {"source_code": "use strict;\nuse bigint;\n\nmy ($n, $m, $a) = split /\\s+/, ;\nmy $result = ( ( $n - 1 ) / $a + 1 ) * ( ( $m - 1 ) / $a + 1 );\n\nprint $result, \"\\n\";\n\nmy $f;\n\n#fdlgkjjgkjhkuggsjkhkkhgjhgkjguyfuygchjyfjhgj"}, {"source_code": "use strict;\nuse bigint;\n\nmy ($n, $m, $a) = split /\\s+/, ;\nmy $result = ( ( $n - 1 ) / $a + 1 ) * ( ( $m - 1 ) / $a + 1 );\n\nprint $result, \"\\n\";\n\nmy $f;\n\n#fdlgkjjgkjhkuggsjkhkkhgjhgkjguyfuygch"}, {"source_code": "use strict;\nuse bigint;\n\nmy ($n, $m, $a) = split /\\s+/, ;\nmy $result = ( ( $n - 1 ) / $a + 1 ) * ( ( $m - 1 ) / $a + 1 );\n\nprint $result, \"\\n\";\n\nmy $f;"}, {"source_code": "use bigint;\n($a, $b, $c) = split' ', <>;\nprint ((($a + $c - 1)) / $c * (($b + $c - 1) / $c));"}, {"source_code": "#!/usr/bin/perl\n\n$input = <>;\n($n, $m, $a) = split(/\\s+/, $input);\n\n$s1 = $n % $a == 0 ? $n / $a : int($n / $a + 1);\n$s2 = $m % $a == 0 ? $m / $a : int($m / $a + 1);\n\nif ($s1 == 0) { $s1 = 1; }\nif ($s2 == 0) { $s2 = 1; }\n\nprint $s1 * $s2 . \"\\n\";\n"}, {"source_code": "my ($n, $m, $a) = split /\\s+/, ;\n$n=int(($n+$a-1)/$a);\n$m=int(($m+$a-1)/$a);\nprint $n*$m;"}, {"source_code": "use bigint;\n($n, $m, $a) = split' ', <>;\nprint ((($n + $a - 1) / $a) * (($m + $a - 1) / $a));"}, {"source_code": "use Math::BigInt;\n$input = ;\n\n## $xx[0] : n / $xx[1] : m / $xx[2] : a\n@xx = split(\" \",$input);\n\n$hh = Math::BigInt->new(int($xx[0] / $xx[2]));\nif ($xx[0] % $xx[2]) {Math::BigInt->new($hh++);}\n\n$ww = Math::BigInt->new(int($xx[1] / $xx[2]));\nif ($xx[1] % $xx[2]) {Math::BigInt->new($ww++);}\n\nprint Math::BigInt->new($hh*$ww);\nexit;\n"}, {"source_code": "use Math::BigInt;\nuse bigint;\nmy $data = ;\nmy (@data) = split (\" \", $data);\n\nmy $n = shift (@data);\nmy $m = shift (@data);\nmy $a = shift (@data);\n\nmy $ma = $m/$a;\nmy $na = $n/$a;\n\nif (int($ma) != $ma) {\n $ma = int($ma) +1; \n}\n\nif (int($na) != $na) {\n $na = int($na) +1; \n}\n\n$x = Math::BigInt->new($ma*$na);\nprint $x;"}, {"source_code": "#!/usr/bin/perl\nuse strict; use warnings;\n\nsub ceil { my $j = $_[0]; my $i = int $j; $i < $j ? $i + 1 : $i }\n\nmy ($n, $m, $a) = split ' ', ;\nprint ceil($n / $a) * ceil($m / $a) . \"\\n\"\n"}, {"source_code": "#!/usr/bin/perl\n\nuse bigint;\n$str = <>;\n\n($a,$b,$c) = split' ',$str;\n\nprint ( (($a+$c-1)/$c)*(($b+$c-1)/$c));\n"}, {"source_code": "#!/usr/bin/perl\n\nuse strict;\nuse warnings;\n\nuse v5.10;\n\nmy $line = <>;\nchomp $line;\nmy ($n, $m, $a) = split /\\s+/, $line;\n\nmy $w = int($n/$a) + ($n % $a == 0 ? 0 : 1);\nmy $l = int($m/$a) + ($m % $a == 0 ? 0 : 1);\n\nsay ( $w * $l );"}, {"source_code": "use strict;\nuse warnings;\n\nuse Data::Dumper;\n\nmy $line = ;\n\nmy ($n, $m, $a) = split(/\\s+/, $line);\n\n$n += $n % $a ? $a - $n % $a : 0;\n$m += $m % $a ? $a - $m % $a : 0;\n\nprintf(\"%.0f\\n\", (($n/$a) * ($m/$a)));\n"}, {"source_code": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n#use POSIX qw(ceil);\n\n#my ($m, $n, $a) = ($ARGV[0], $ARGV[1], $ARGV[2]); #(7,6,4);\nmy $userinput = ; #read stdin and put it in $userinput\nchomp ($userinput); #cut the return / line feed character\nmy ($m, $n, $a) = split(/\\s+|,/, $userinput);\n\nmy $add1 = ($m%$a>0)?1:0;\nmy $add2 = ($n%$a>0)?1:0;\nmy $ret = int($m/$a + $add1) * int($n/$a + $add2);\nprintf \"%.0f\", $ret;\n\n"}, {"source_code": "use strict;\nuse Data::Dumper;\nuse POSIX;\n\nmy $input = <>;\n\nmy ($n, $m, $a) = split(/ /, $input);\n\nprintf('%11.0f', paveSquare($n, $m, $a));\n\nsub paveSquare {\n\tmy ($n, $m, $a) = @_;\n\tmy $counter = 0;\n\n\tif ($n > $m) {\n\t\tmy $k = $n;\n\t\t$n = $m;\n\t\t$m = $k;\n\t}\n\t$counter += ceil($n / $a);\n\t$counter *= ceil($m / $a);\n\treturn ceil($n / $a) * ceil($m / $a);\n}"}, {"source_code": "use strict;\nuse Data::Dumper;\nuse POSIX;\n\nmy $input = <>;\n\nmy ($n, $m, $a) = split(/ /, $input);\n\nprintf('%11.0f', paveSquare($n, $m, $a));\n\nsub paveSquare {\n\tmy ($n, $m, $a) = @_;\n\tmy $counter = 0;\n\n\tif ($n > $m) {\n\t\tmy $k = $n;\n\t\t$n = $m;\n\t\t$m = $k;\n\t}\n\tmy $remain = $m - $n;\n\t$counter += ceil($n / $a);\n\twarn $counter;\n\t$counter *= ceil($m / $a);\n\treturn $counter;\n}"}, {"source_code": "use strict;\nuse Data::Dumper;\nuse POSIX;\n\nmy $input = <>;\n\nmy ($n, $m, $a) = split(/ /, $input);\n\nprintf('%11.0f', paveSquare($n, $m, $a));\n\nsub paveSquare {\n\tmy ($n, $m, $a) = @_;\n\treturn ceil($n / $a) * ceil($m / $a);\n}"}, {"source_code": "use bigint;\n($n, $m, $a) = split(' ', );\nsub f {\n return (@_[0] + @_[1] - 1) / @_[1];\n}\nprint (f($n, $a) * f($m, $a));"}, {"source_code": "use bigint;\n($n, $m, $a) = split(' ', );\nprint (($n + $a - 1) / $a * (($m + $a - 1) / $a));"}, {"source_code": "$_=<>;\n($a,$b,$c)=/(\\d+) (\\d+) (\\d+)/;\n$i=($a-$a%$c)/$c;\n$i++ if $a%$c;\n$j=($b-$b%$c)/$c;\n$j++ if $b%$c;\nprint$i*$j"}, {"source_code": "#!/usr/bin/perl\nuse POSIX;\nuse bigint;\n$_ = <>;\ns/(\\d+).(\\d+).(\\d+)/int(ceil($1\\/$3)*ceil($2\\/$3)+0)/e;\nprint;\n"}, {"source_code": "my ($n,$m,$a) = split (' ',);\nif ($n % $a != 0) {\n\t$n = int($n / $a) + 1;\n} else {\n\t$n = $n / $a;\n}\nif ($m % $a != 0) {\n\t$m = int($m / $a) + 1;\n} else {\n\t$m = $m / $a;\n}\nprintf ('%.0f',$m*$n);"}, {"source_code": "use bigint;($a,$b,$c)=split' ',<>;sub t{((shift)-1)/$c+1};print t($a)*t$b\n"}, {"source_code": "use bigint;($a,$b,$c)=split' ',<>;$_=(($a-1)/$c+1);print$_*(($b-1)/$c+1);\n"}, {"source_code": "use bigint;($a,$b,$c)=split' ',<>;$_=(($a-1)/$c+1);print$_*(($b-1)/$c+1)\n"}, {"source_code": "($m, $n, $a)=split' ',<>;\nif (int($m / $a)<($m / $a)){$swag = int($m / $a)+1;}else{$swag = ($m / $a)}\nif (int($n / $a)<($n / $a)){$lox = int($n / $a)+1;}else{$lox = ($n / $a)}\nprint $swag * $lox\n"}, {"source_code": "#!perl\n\nuse strict;\nuse warnings;\n\nsub myceil {\n\n my ($num) = @_;\n my $diff = $num - int($num);\n my $ret = $diff ? int($num+0.99999999999999) : $num;\n #print \"ceil of $num is $ret\\n\";\n $ret;\n}\n\nmy $n;\nmy $m;\nmy $a;\nwhile (<>) {\n chomp;\n ($n, $m, $a) = split(/ /);\n last;\n}\n\nmy $r1 = myceil($n/$a);\nmy $r2 = myceil($m/$a);\n#use POSIX;\n#die \"$r1\" if ($r1 != ceil($n/$a));\n#die \"$r2\" if ($r2 != ceil($m/$a));\nmy $area = $r1 * $r2;\n$area = 1 if ($area < 1);\nprint \"$area\\n\";\n\nexit(0);\n"}, {"source_code": "use bigint;\nchmod($line = <>);\n($n, $m, $a) = split(' ', $line);\n$res = int(int(($n + $a - 1) / $a) * int(($m + $a - 1) / $a));\nprint (\"$res\");\n"}, {"source_code": "#!/usr/bin/perl\n\n$input_line = ;\nchop($input_line);\n($n,$m,$a)=split(/ /,$input_line);\n$ni = int($n/$a);\n$mi = int($m/$a);\n$i = $ni*$mi;\n$size = ($n*$m)-($i*$a*$a);\nif($n==($ni*$a)){$nii=0}else{$nii=1}\nif($m==($mi*$a)){$mii=0}else{$mii=1}\n\nif ($size == ($n*$m)) {$i++;}\nelsif ($size != 0){$i += ($ni*$mii+$mi*$nii+1);\nif (($nii == 0)||($mii == 0)){$i--;}}\nprint(\"$i\\n\");"}, {"source_code": "#print \"hello world\";\n($n, $m, $a) = split ' ', <>;\n$x = int(($n + $a - 1) / $a);\n$y = int(($m + $a - 1) / $a);\nprint $x * $y;"}, {"source_code": "my @items = split / /, <>;\nprintf \"%d\\n\", int(($items[0]+$items[2]-1)/$items[2]) * int(($items[1]+$items[2]-1)/$items[2]);\n"}, {"source_code": "\nsub ceil {\n if ( @_[0] > (int @_[0]) ) {\n\treturn (int ( @_[0] ) + 1); }\n else {\n\treturn ( @_[0] ); }\n}\n\n# three integers\nmy $g = ;\n\n# remove newline\nchomp ( $g );\n\nmy $a, $b, $c;\nif ( $g =~ m/(.+) (.+) (.+)/ ) {\n $a = $1;\n $b = $2;\n $c = $3; }\n\nmy $ans = &ceil ( $a / $c ) * &ceil ( $b / $c );\nprint \"$ans\\n\";\n\n\n\n\n\n"}, {"source_code": "use bigint;\n\nmy ($n, $m, $a) = split /\\s+/, ;\n\nmy $h = (int $n/$a) + !!($n % $a);\nmy $w = (int $m/$a) + !!($m % $a);\n\nmy $area = $h * $w;\n\nprintf \"%.0f\", $area;"}, {"source_code": "#!/usr/bin/env perl\n\nuse strict;\nuse warnings;\nuse integer;\n\nmy $line = ;\n\nmy ($h, $w, $a);\nif ($line =~ /(\\d+) (\\d+) (\\d+)/) {\n\t$h = $1;\n\t$w = $2;\n\t$a = $3;\n}\nmy $ver = $h / $a + ($h % $a != 0);\nmy $hor = $w / $a + ($w % $a != 0);\nprint $ver * $hor;\n"}, {"source_code": "my @a = split \" \", <>;\nmy $b = ((int $a[0] / $a[2]) + ($a[0] % $a[2] > 0));\nmy $c = ((int $a[1] / $a[2]) + ($a[1] % $a[2] > 0));\nprintf (\"%.0f\", $b * $c);"}, {"source_code": "#!/usr/bin/env perl\n# perl learning...\npackage Codeforces::contest1::A;\nuse warnings;\n#use List::Util qw[min max];\nuse v5.20;\nsub input\n { return <>; }\n \nsub ceildiv {\n my ($a, $b) = @_;\n return int($a / $b) + ($a % $b != 0);\n}\n \nsub main {\n my ($n, $m, $a) = split(\" \", input());\n print(int(ceildiv($n, $a)) * int(ceildiv($m, $a)), \"\\n\");\n}\n \nmain();\n"}, {"source_code": "use bigint;\n\n$str = ;\n\n@ints = split(' ', $str);\n\n$n = $ints[0] + 0;\n$m = $ints[1] + 0;\n$a = $ints[2] + 0;\n\n$count = ($n % $a == 0) ? $n/$a : $n/$a + 1;\n\n$count = $count * (($m % $a == 0) ? $m/$a : $m/$a + 1);\n\nprint \"$count\\n\";"}, {"source_code": "no bigint;\nuse strict;\n\nmain();\n\nsub main {\n\tmy $input = $ENV{PERLUSER} eq \"s_p\"? \\*DATA: \\*STDIN;\n\tfor (<$input>) {\n\t\tmy ($n, $m, $a, $nm) = split;\n\t\t$n = int($n / $a) + ($n % $a? 1: 0);\n\t\t$m = int($m / $a) + ($m % $a? 1: 0);\n\t\tprint length($nm)? \n\t\t\t[qw(fail ok)]->[itoa(mul($n, $m)) eq $nm]: \n\t\t\titoa(mul($n, $m)), \"\\n\";\n\t}\n}\n\nsub add {\n\tmy ($p2, $p1, $add) = @_;\n\tmy $addok = 0xffff_ffff - $p1;\n\t$add <= $addok? \n\t\t($p2, $p1 + $add):\n\t\t($p2 + 1, $add - $addok - 1);\n}\n\n# b=2^16, n1=q1*b+r1, n2=q2*b+r2\n# n1*n2=(q1*b+r1)(q2*b+r2)=q1*q2*b^2 + q1*r2*b + q2*r1*b + r1*r2\nsub mul {\n\tmy ($n1, $n2) = @_;\n\tmy $B16 = 0xffff;\n\tmy ($q1, $r1) = ($n1>>16, $n1 & $B16);\n\tmy ($q2, $r2) = ($n2>>16, $n2 & $B16);\n\tmy ($tmp, $bits_00_15, $bits_16_31, $bits_32_63);\n\t$tmp = $r1 * $r2;\n\t$bits_00_15 = $tmp & $B16;\n\t$tmp = $q1 * $r2 + $q2 * $r1 + ($tmp>>16);\n\t$bits_16_31 = $tmp & $B16;\n\t$bits_32_63 = $q1 * $q2 + ($tmp>>16);\n\tmy $p1 = ($bits_16_31<<16) + $bits_00_15;\n\tmy $p2 = $bits_32_63;\n\t# print \"mul $n1 x $n2 = $p2, $p1\\n\";\n\t($p2, $p1);\n}\n\n# p2*b+p1 = (q2*d+r2)*(q3*d+r3) + q1*d+r1 = \n# q2*q3*d^2 + q2*r3*d + r2*q3*d + r2*r3 + q1*d + r1\n# (q2*q3*d + q2*r3 + r2*q3 + q1) * d + (r2*r3 + r1)\nsub div {\n\tmy ($p2, $p1, $d) = @_;\n\tmy $b = 0xffff_ffff;\n\tmy ($q1, $r1) = (int($p1/10), $p1%10);\n\tmy ($q2, $r2) = (int($p2/10), $p2%10);\n\tmy ($q3, $r3) = (int($b/10), $b%10 + 1);\n\tmy ($divp2, $divp1, $divr);\n\t($divp2, $divp1) = mul($q2, $q3 * $d);\n\t($divp2, $divp1) = add($divp2, $divp1, $q2 * $r3);\n\t($divp2, $divp1) = add($divp2, $divp1, $r2 * $q3);\n\t($divp2, $divp1) = add($divp2, $divp1, $q1);\n\t$divr = $r2 * $r3 + $r1;\n\t$divp1 += int($divr/10);\n\t$divr = $divr % 10;\n\t# print \"div ($p2, $p1) / $d = ($divp2, $divp1) + $divr\\n\";\n\t($divp2, $divp1, $divr);\n}\n\n# 10^15 = 232830*2^32+2764472320\n# 10^14 = 23283*2^32+ 276447232\n# div(232830, 2764472320, 10);\n\n# 2^32 + 1234 = 4294968530 = (1, 1234)\n# 2^32/10 = (0, 429496853, 0)\n# div(1, 1234, 10);\n\nsub itoa {\n\tmy ($p2, $p1) = @_;\n\tmy ($s, $r);\n\twhile ($p2 || $p1) {\n\t\t($p2, $p1, $r) = div($p2, $p1, 10);\n\t\t$s = substr(\"0123456789\", $r, 1).$s;\n\t\t# print \"p2=$p2 p1=$p1 r=$r s=$s\\n\";\n\t}\n\t$s;\n}\n\n__DATA__\n2147483648 2147483648 1 4611686018427387904\n6 6 4 4\n"}, {"source_code": "\nuse bigint;\nmy ($n, $m, $a) = split \" \",<>;\nprint ((($n + $a - 1)) / $a * (($m + $a - 1) / $a));"}], "negative_code": [{"source_code": "$str = ;\n\n@ints = split(' ', $str);\n\n$n = int($ints[0]);\n$m = int($ints[1]);\n$a = int($ints[2]);\n\nuse integer;\n\n$count = ($n % $a == 0) ? $n/$a : $n/$a + 1;\n\n$count = $count * (($m % $a == 0) ? $m/$a : $m/$a + 1);\n\nprint \"$count\\n\";"}, {"source_code": "use strict;\nuse Data::Dumper;\nuse POSIX;\n\nmy $input = <>;\n\nmy ($n, $m, $a) = split(/ /, $input);\n\nwarn $n;\nwarn $m;\nwarn $a;\nprint paveSquare($n, $m, $a);\n\nsub paveSquare {\n\tmy ($n, $m, $a) = @_;\n\tmy $counter = 0;\n\t$counter += ceil($n / $a);\n\t$counter += ceil($m / $a);\n\treturn $counter;\n}"}, {"source_code": "$str = ;\n\n@ints = split(' ', $str);\n\n$n = int($ints[0]);\n$m = int($ints[1]);\n$a = int($ints[2]);\n\nuse bignum;\n\n$count = ($n % $a == 0) ? $n/$a : $n/$a + 1;\n\n$count = $count * (($m % $a == 0) ? $m/$a : $m/$a + 1);\n\nprint \"$count\\n\";"}, {"source_code": "use POSIX(ceil);\n$_ = <>;\n@a = split;\nprintf \"%i\\n\", ceil($a[0] / $a[2]) * ceil($a[1] / $a[2]);"}, {"source_code": "$input = ;\n@x=split(\" \",$input);\n$n=$x[0]; $m=$x[1]; $a=$x[2];\n$h=int($n/$a);\n$w=int($m/$a);\n\nif($h%$a != 0){\n\t$h++;\n}\nif($w%$a != 0){\n\t$w++;\n}\n$ans=$h*$w;\nprintf \"$ans\\n\";\n\n\n"}, {"source_code": "use strict;\nuse Data::Dumper;\nuse POSIX;\n\nmy $input = <>;\n\nmy ($n, $m, $a) = split(/ /, $input);\n\nprintf('%011.0f', paveSquare($n, $m, $a));\n\nsub paveSquare {\n\tmy ($n, $m, $a) = @_;\n\tmy $counter = 0;\n\n\tif ($n > $m) {\n\t\tmy $k = $n;\n\t\t$n = $m;\n\t\t$m = $k;\n\t}\n\tmy $remain = $m - $n;\n\t$counter += ceil($n / $a);\n\twarn $counter;\n\t$counter *= ceil($m / $a);\n\treturn $counter;\n}"}, {"source_code": "use strict;\nuse Data::Dumper;\nuse POSIX;\n\nmy $input = <>;\n\nmy ($n, $m, $a) = split(/ /, $input);\n\nprint paveSquare($n, $m, $a);\n\nsub paveSquare {\n\tmy ($n, $m, $a) = @_;\n\tmy $counter = 0;\n# \t$counter += ceil($n / $a);\n# \t\n# \tmy $remain = ceil($m / $a);\n# \treturn $counter;\n\tif ($n > $m) {\n\t\tmy $k = $n;\n\t\t$n = $m;\n\t\t$m = $k;\n\t}\n\tmy $remain = $m - $n;\n\t$counter += ceil($n / $a) ** 2;\n\t$counter += ceil($n / $a) * ceil($remain / $a);\n\treturn $counter;\n}"}, {"source_code": "use POSIX qw(ceil);\n($n,$m,$a)=split (' ',);\nprint ceil($n/$a)*ceil($m/$a);\n"}, {"source_code": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n#use POSIX qw(ceil);\n\n#my ($m, $n, $a) = ($ARGV[0], $ARGV[1], $ARGV[2]); #(7,6,4);\nmy $userinput = ; #read stdin and put it in $userinput\nchomp ($userinput); #cut the return / line feed character\nmy ($m, $n, $a) = split(/\\s+|,/, $userinput);\n\nmy $add = ($m%$a>0)?1:0;\nmy $ret = int($m/$a + $add) * int($n/$a + $add);\nprintf \"%.0f\", $ret;\n\n"}, {"source_code": "$str = ;\n\n@ints = split(' ', $str);\n\n$n = int($ints[0]);\n$m = int($ints[1]);\n$a = int($ints[2]);\n\nuse bigint;\n\n$count = ($n % $a == 0) ? $n/$a : $n/$a + 1;\n\n$count = $count * (($m % $a == 0) ? $m/$a : $m/$a + 1);\n\nprint \"$count\\n\";"}, {"source_code": "#!/usr/bin/perl\nuse integer;\n($n,$m,$a)=split' ',<>;\n$c1 = ($n%$a);\n$c2 = ($m%$a);\n\n\nif ($c1 eq 0)\n{$miss1 = 0;}\nelse\n{$miss1 =$a-($n%$a);}\n\nif ($c2 eq 0)\n{$miss2 = 0;}\nelse\n{$miss2 =$a-($m%$a);}\n\n$answer = (($n+$miss1)/$a)*(($n+$miss2)/$a);\nprint \"$answer\";"}, {"source_code": "use POSIX(ceil);\n$_ = <>;\n@a = split;\nprintf \"%lld\\n\", ceil($a[0] / $a[2]) * ceil($a[1] / $a[2]);"}, {"source_code": "($n, $m, $a) = split / /, <>;\n$i = 0;\nwhile ($a << $i <= ($n * $m)) {\n $i++;\n}\n\nprint $i;"}, {"source_code": "use strict;\nuse Data::Dumper;\nuse POSIX;\n\nmy $input = <>;\n\nmy ($n, $m, $a) = split(/ /, $input);\n\nwarn $n;\nwarn $m;\nwarn $a;\nprint paveSquare($n, $m, $a);\n\nsub paveSquare {\n\tmy ($n, $m, $a) = @_;\n\tmy $counter = 0;\n\t$counter += ceil($n / $a);\n\t$counter += ceil($m / $a);\n\treturn $counter;\n}"}, {"source_code": "my @a = split \" \", <>;\nprintf (\"%Ld\\n\", (((int $a[0] / $a[2]) + ($a[0] % $a[2] > 0)) * ((int $a[1] / $a[2]) + ($a[1] % $a[2] > 0))));"}, {"source_code": "use strict;\n\n\nmy( $str );\n$str = ;\nmy ($n, $m, $a) = split / /, $str;\n\nmy($na, $ma);\n\nprint int(($n+$a-1)/$a)*int(($m+$a-1)/$a);"}, {"source_code": " $_ = <>;\n my @arr = split/\\s+/;\n #print @arr;\n my $tiles1 = 0;\n my $tiles2 = 0;\n { \n use integer;\n $tiles1 += $arr[0]/$arr[2];\n $tiles2 += $arr[1]/$arr[2];\n }\n if ($arr[0]%$arr[2] != 0) {\n $tiles1 += 1;\n }\n if ($arr[1]%$arr[2] != 0) {\n #$tiles += 1;\n }\n my $tiles = $tiles1*$tiles2;\n print \"$tiles\\n\";\n exit 0;\n"}, {"source_code": "use strict;\nuse warnings;\nuse utf8;\n\nmy $stdin=;\nchomp($stdin);\nmy @in=split(\" \", $stdin);\n\nmy $h=int($in[0]/$in[2]);\n$h++\tunless($in[0]%$in[2]==0);\n\nmy $w=int($in[1]/$in[2]);\n$w++\tunless($in[1]%$in[2]==0);\n\nprint $h * $w.\"\\n\";\n\n"}, {"source_code": "use strict;\nuse warnings;\n\n#use POSIX qw(ceil);\n\nmy $input = <>;\nmy ($n, $m, $a) = split ' ', $input;\n\n# cover n x m meters with ? number of stones of size a x a.\n# calculate how many stones needed in n direction and then in m direction.\n\nmy $n_stones = int( $n / $a + 0.99 );\nmy $m_stones = int( $m / $a + 0.99 );\nmy $needed_stones = $n_stones * $m_stones;\n\nprint \"$needed_stones\\n\";\n\n"}, {"source_code": "use strict;\nuse warnings;\n\nuse Data::Dumper;\n\nmy $line = ;\n\nmy ($n, $m, $a) = split(/\\s+/, $line);\n\n$n += $n % $a ? $a - $n % $a : 0;\n$m += $m % $a ? $a - $m % $a : 0;\n\nprint (($n/$a) + ($m/$a));\nprint \"\\n\";\n"}, {"source_code": "#!/usr/bin/perl\n# your code goes here\nuse integer;\n\n($n, $m, $a) = split / /, <>;\n# print \"$n $m $a\";\n$ans = (($n+$a-1)/$a) * (($m+$a-1)/$a);\nprint $ans;\n"}, {"source_code": "my @items = split / +/, <>;\nprintf \"%d\\n\", int($items[0]/$items[2]+0.999999999) * int($items[1]/$items[2]+0.999999999);"}, {"source_code": "($n, $m, $a) = split \" \", <>;\n$x = int($n/$a);\n$y = int($m/$a);\nif ($n % $a != 0)\n{\n\t$x = $x + 1;\n}\nif ($m % $a != 0)\n{\n\t$y = $y + 1;\n}\n$res = $x * $y;\nprint \"$res\\n\";"}, {"source_code": "#!/usr/bin/env perl\n\nmy ($n, $m, $a) = split /\\s+/, ;\n\nmy $h = (int $n/$a) + !!($n % $a);\nmy $w = (int $m/$a) + !!($m % $a);\n\nprint $h * $w"}, {"source_code": "#!/usr/bin/perl\nuse POSIX;\nuse bigint;\n@l = split ' ', <>;\n$m = ceil($l[0]/$l[2]);\n$n = ceil($l[1]/$l[2]);\n$\" = $m*$n;\nprint $\";\n"}, {"source_code": "\nuse bigint;\n\nmy $input = do { local $/; scalar <> };\nmy ($n, $m, $a) = split /\\s+/s, $input;\n\nmy ($dm, $dn) = map { ceil( $_ / $a ) } $m, $n;\n\nprintf \"%d\\n\", $dn * $dm;\n\nsub ceil {\n my ( $x ) = @_;\n return 1 if $x < 1;\n return int( $x ) < $x ? int($x) + 1 : int $x;\n}\n"}, {"source_code": "#!/usr/bin/perl\n\n$input_line = ;\nchop($input_line);\n($n,$m,$a)=split(/ /,$input_line);\n$ni = int($n/$a);\n$mi = int($m/$a);\n$i = $ni*$mi;\n$size = ($n*$m)-($i*$a);\nif ($size == ($n*$m)) {$i++;}\nelsif ($size != 0){$i += ($ni+$mi+1);}\nprint(\"$i\\n\");"}, {"source_code": "#!/usr/bin/env perl \n#===============================================================================\n# FILE: theatre.pl\n# AUTHOR: Phoenix Ikki (liuxueyang.github.io), liuxueyang457@gmail.com\n# ORGANIZATION: Hunan University\n# CREATED: 05/25/2015 07:53:32 PM\n#===============================================================================\n\nuse strict;\nuse warnings;\nuse utf8;\nuse 5.012;\n\nchomp($_ = );\nmy ($n, $m, $a) = split;\n\nprint int(cal($n, $a) * cal($m, $a)) . \"\\n\";\nsub cal\n{\n my ($m, $a) = @_;\n int($m / $a) + ($m % $a == 0 ? 0 : 1);\n}\n\n\n"}, {"source_code": "#!/usr/bin/perl -w\nuse strict;\nuse warnings;\nuse POSIX qw{ceil};\nmy ($n, $m, $a) = map int, split /\\D/, <>;\nprint int (ceil ($n/$a) * ceil ($m/$a));\n"}, {"source_code": "#!/usr/bin/perl -w\nuse strict;\nuse warnings;\nuse POSIX qw{ceil};\nmy ($n, $m, $a) = map int, split /\\D/, <>;\nprint int (ceil ($n/$a) * ceil ($m/$a));\n"}, {"source_code": "$str = ;\n\n@ints = split(' ', $str);\n\n$n = int($ints[0]);\n$m = int($ints[1]);\n$a = int($ints[2]);\n\nuse integer;\n\n$count = ($n % $a == 0) ? $n/$a : $n/$a + 1;\n\n$count = $count * (($m % $a == 0) ? $m/$a : $m/$a + 1);\n\nprint \"$count\\n\";"}, {"source_code": "($n, $m, $k) = split(' ', <>);\nprint int($n / $k + 0.99) * int($m / $k + 0.99);\n"}, {"source_code": "\nsub ceil {\n if ( @_[0] > (int @_[0]) ) {\n\treturn (int ( @_[0] ) + 1); }\n else {\n\treturn ( @_[0] ) }\n}\n\nmy $f = ;\nmy $one;\nmy $two;\nmy $thr;\n\nif ( $f =~ m/(\\d)+ (\\d)+ (\\d)+/ ) {\n $one = $1;\n $two = $2;\n $thr = $3; }\n\nmy $ans = &ceil ( $one / $thr ) * &ceil ( $two / $thr );\nprint $ans . \"\\n\";\n\n\n\n"}, {"source_code": "#!/usr/bin/perl\n\nuse Math::BigInt;\n\n$_ = <>;\n@a = split;\n$n = ($a[0] / $a[2]);\n$x = ($a[1] / $a[2]);\nif($a[0] % $a[2] != 0){\n $n++;\n}\nif($a[1] % $a[2] != 0){\n $x++;\n}\nprint Math::BigInt->new(($x) * ($n));"}, {"source_code": "use strict;\n\n\nmy( $str );\n$str = ;\nmy ($n, $m, $a) = split / /, $str;\n\nmy ($na, $ma );\n\nif( $n%$a != 0 ) {\n $na = int( ($n+$a)/$a )\n} else {\n $na = $n/$a\n}\n\nif( $m%$a != 0 ) {\n $ma = int( ($m+$a)/$a )\n} else {\n $ma = $m/$a\n}\n\nprint $na*$ma;"}, {"source_code": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n#use POSIX qw(ceil);\n\n#my ($m, $n, $a) = ($ARGV[0], $ARGV[1], $ARGV[2]); #(7,6,4);\nmy $userinput = ; #read stdin and put it in $userinput\nchomp ($userinput); #cut the return / line feed character\nmy ($m, $n, $a) = split(/\\s+|,/, $userinput);\n\nmy $add = ($m%$a>0)?1:0;\nmy $ret = int($m/$a + $add) * int($n/$a + $add);\nprintf \"%.0f\", $ret;\n\n"}, {"source_code": "my @a = split \" \", <>;\nprintf (\"%Ld\\n\", (((int $a[0] / $a[2]) + ($a[0] % $a[2] > 0)) * ((int $a[1] / $a[2]) + ($a[1] % $a[2] > 0))));"}, {"source_code": "my ($n,$m,$a) = split (' ',);\nif ($n % $a != 0) {\n\t$n = int($n / $a) + 1;\n} else {\n\t$n = $n / $a;\n}\nif ($m % $a != 0) {\n\t$m = int($m / $a) + 1;\n} else {\n\t$m = $m / $a;\n}\nprint $m*$n;"}, {"source_code": "($n, $m, $a) = split(' ', );\nprint ($n + $a - 1) / $a * (($m + $b - 1) / $a);"}, {"source_code": "#!/usr/bin/perl\n\n$input_line = ;\nchop($input_line);\n($n,$m,$a)=split(/ /,$input_line);\n$ni = int($n/$a);\n$mi = int($m/$a);\n$i = $ni*$mi;\n$size = ($n*$m)-($i*$a*$a);\nif($n==($ni*$a)){$nii=0}else{$nii=1}\nif($m==($mi*$a)){$mii=0}else{$mii=1}\n\nif ($size == ($n*$m)) {$i++;}\nelsif ($size != 0){$i += ($ni*$nii+$mi*$mii+1);\nif (($nii == 0)||($mii == 0)){$i--;}}\nprint(\"$i\\n\");"}, {"source_code": "use bigint;\nuse POSIX(ceil);\n$_ = <>;\n@a = split;\nprint ceil($a[0] / $a[2]) * ceil($a[1] / $a[2]);"}, {"source_code": "use strict;\n\nmy ($n, $m, $a) = split /\\s+/, ;\nmy $result = int( ( $n - 1 ) / $a + 1 ) * int( ( $m - 1 ) / $a + 1 );\n\nprint $result, \"\\n\";\n"}, {"source_code": "#!/usr/bin/perl -w\nuse strict;\nuse warnings;\nuse POSIX qw{ceil};\nmy ($n, $m, $a) = map int, split /\\D/, <>;\nprint sprintf \"%d\", (ceil ($n/$a) * ceil ($m/$a));\n"}, {"source_code": "#!/usr/bin/perl\nuse integer;\n($n,$m,$a)=split' ',<>;\n$c1 = ($n%$a);\n$c2 = ($m%$a);\n\nif ($c1 eq 0)\n{$miss1 = 0;}\nelse\n{$miss1 =$a-($n%$a);}\n\nif ($c2 eq 0)\n{$miss2 = 0;}\nelse\n{$miss2 =$a-($m%$a);}\n\n$answer = (($n+$miss1)/$a)*(($m+$miss2)/$a);\nprint \"$answer\";"}, {"source_code": "($n, $m, $k) = split(' ', <>);\nprint int($n / $k + 0.99) * int($m / $k + 0.99);\n"}, {"source_code": "while() {\n my($n, $m, $a) = split(\" \", $_);\n print int(($n + $a -1) / $a) * int(($m + $a -1) / $a);\n}"}, {"source_code": "my @a = split \" \", <>;\nprintf (\"%lf\\n\", (((int $a[0] / $a[2]) + ($a[0] % $a[2] > 0)) * ((int $a[1] / $a[2]) + ($a[1] % $a[2] > 0))));"}, {"source_code": "use bigint;\n\n$str = ;\n\n@ints = split(' ', $str);\n\n$n = int($ints[0]);\n$m = int($ints[1]);\n$a = int($ints[2]);\n\n$count = ($n % $a == 0) ? $n/$a : $n/$a + 1;\n\n$count = $count * (($m % $a == 0) ? $m/$a : $m/$a + 1);\n\nprint \"$count\\n\";"}, {"source_code": "my ($n,$m,$a) = split (' ',);\nif ($n % $a != 0) {\n\t$n = int($n / $a) + 1;\n}\nif ($m % $a != 0) {\n\t$m = int($m / $a) + 1;\n}\nprint $m*$n;"}, {"source_code": "#!/usr/bin/env perl \n#===============================================================================\n# FILE: theatre.pl\n# AUTHOR: Phoenix Ikki (liuxueyang.github.io), liuxueyang457@gmail.com\n# ORGANIZATION: Hunan University\n# CREATED: 05/25/2015 07:53:32 PM\n#===============================================================================\n\nuse strict;\nuse warnings;\nuse utf8;\nuse 5.012;\nuse integer;\n\nchomp($_ = );\nmy ($n, $m, $a) = split;\n\nprint int(cal($n, $a) * cal($m, $a)) . \"\\n\";\nsub cal\n{\n my ($m, $a) = @_;\n int($m / $a) + ($m % $a == 0 ? 0 : 1);\n}\n\n\n"}, {"source_code": "no bigint;\nuse strict;\n\nmain();\n\nsub main {\n\tmy $input = $0 eq \"5.pl\"? \\*DATA: \\*STDIN;\n\tfor (<$input>) {\n\t\tmy ($n, $m, $a, $nm) = split;\n\t\t$n = int($n / $a) + ($n % $a? 1: 0);\n\t\t$m = int($m / $a) + ($m % $a? 1: 0);\n\t\tprint defined($nm)? [qw(fail ok)]->[$n * $m == $nm]: $n * $m, \"\\n\";\n\t}\n}\n\nsub add {\n\tmy ($p2, $p1, $add) = @_;\n\tmy $addok = 0xffff_ffff - $p1;\n\t$add <= $addok? \n\t\t($p2, $p1 + $add):\n\t\t($p2 + 1, $add - $addok - 1);\n}\n\n# b=2^16, n1=q1*b+r1, n2=q2*b+r2\n# n1*n2=(q1*b+r1)(q2*b+r2)=q1*q2*b^2 + q1*r2*b + q2*r1*b + r1*r2\nsub mul {\n\tmy ($n1, $n2) = @_;\n\tmy $B16 = 0xffff;\n\tmy ($q1, $r1) = ($n1>>16, $n1 & $B16);\n\tmy ($q2, $r2) = ($n2>>16, $n2 & $B16);\n\tmy ($tmp, $bits_00_15, $bits_16_31, $bits_32_63);\n\t$tmp = $r1 * $r2;\n\t$bits_00_15 = $tmp & $B16;\n\t$tmp = $q1 * $r2 + $q2 * $r1 + ($tmp>>16);\n\t$bits_16_31 = $tmp & $B16;\n\t$bits_32_63 = $q1 * $q2 + ($tmp>>16);\n\tmy $p1 = ($bits_16_31<<16) + $bits_00_15;\n\tmy $p2 = $bits_32_63;\n\t# print \"mul $n1 x $n2 = $p2, $p1\\n\";\n\t($p2, $p1);\n}\n\n# p2*b+p1 = (q2*d+r2)*(q3*d+r3) + q1*d+r1 = \n# q2*q3*d^2 + q2*r3*d + r2*q3*d + r2*r3 + q1*d + r1\n# (q2*q3*d + q2*r3 + r2*q3 + q1) * d + (r2*r3 + r1)\nsub div {\n\tmy ($p2, $p1, $d) = @_;\n\tmy $b = 0xffff_ffff;\n\tmy ($q1, $r1) = (int($p1/10), $p1%10);\n\tmy ($q2, $r2) = (int($p2/10), $p2%10);\n\tmy ($q3, $r3) = (int($b/10), $b%10 + 1);\n\tmy ($divp2, $divp1, $divr);\n\t($divp2, $divp1) = mul($q2, $q3 * $d);\n\t($divp2, $divp1) = add($divp2, $divp1, $q2 * $r3);\n\t($divp2, $divp1) = add($divp2, $divp1, $r2 * $q3);\n\t($divp2, $divp1) = add($divp2, $divp1, $q1);\n\t$divr = $r2 * $r3 + $r1;\n\tif ($divr >= 10) {\n\t\t$divr -= 10;\n\t\t$divp1++;\n\t}\n\t# print \"div ($p2, $p1) / $d = ($divp2, $divp1) + $divr\\n\";\n\t($divp2, $divp1, $divr);\n}\n\n# 10^15 = 232830*2^32+2764472320\n# 10^14 = 23283*2^32+ 276447232\n# div(232830, 2764472320, 10);\n\n# 2^32 + 1234 = 4294968530 = (1, 1234)\n# 2^32/10 = (0, 429496853, 0)\n# div(1, 1234, 10);\n\nsub itoa {\n\tmy ($p2, $p1) = @_;\n\tmy ($s, $r);\n\twhile ($p2 || $p1) {\n\t\t($p2, $p1, $r) = div($p2, $p1, 10);\n\t\t$s = substr(\"0123456789\", $r, 1).$s;\n\t\t# print \"p2=$p2 p1=$p1 s=$s\\n\";\n\t}\n\t$s;\n}\n\n__DATA__\n2147483648 2147483648 1 4611686018427387904\n6 6 4 4\n"}, {"source_code": "my @a = split \" \", <>;\nprintf (\"%lf\\n\", (((int $a[0] / $a[2]) + ($a[0] % $a[2] > 0)) * ((int $a[1] / $a[2]) + ($a[1] % $a[2] > 0))));"}, {"source_code": "$input = ;\n@x=split(\" \",$input);\n$n=$x[0]; $m=$x[1]; $a=$x[2];\n$h=int($n/$a);\n$w=int($m/$a);\n\nif($n%$a != 0){\n\t$h++;\n}\nif($m%$a != 0){\n\t$w++;\n}\n$ans=$h*$w;\nprintf \"$ans\\n\";\n\n\n"}, {"source_code": "\nuse bigint;\n\nmy $input = do { local $/; scalar <> };\nmy ($n, $m, $a) = split /\\s+/s, $input;\n\nmy ($dm, $dn) = map { ceil( $_ / $a ) } $m, $n;\n\nprintf \"%d\\n\", $dn * $dm;\n\nsub ceil {\n my ( $x ) = @_;\n return 1 if $x < 1;\n return int( $x ) < $x ? int($x) + 1 : int $x;\n}\n"}, {"source_code": "my @a = split \" \", <>;\nprint (((int $a[0] / $a[2]) + ($a[0] % $a[2] > 0)) * ((int $a[1] / $a[2]) + ($a[1] % $a[2] > 0)));"}, {"source_code": "my @a = split \" \", <>;\nprintf (\"%lld\\n\", (((int $a[0] / $a[2]) + ($a[0] % $a[2] > 0)) * ((int $a[1] / $a[2]) + ($a[1] % $a[2] > 0))));"}, {"source_code": "my $data = ;\nmy (@data) = split (\" \", $data);\n\nmy $n = shift (@data);\nmy $m = shift (@data);\nmy $a = shift (@data);\n\nmy $ma = $m/$a;\nmy $na = $n/$a;\n\nif (int($ma) != $ma) {\n $ma = int($ma) +1; \n}\n\nif (int($na) != $na) {\n $na = int($na) +1; \n}\n\n$x = $ma*$na;\nprint $x;\n"}, {"source_code": "#!/usr/bin/perl\n\n$input_line = ;\nchop($input_line);\n($n,$m,$a)=split(/ /,$input_line);\n$ni = int($n/$a);\n$mi = int($m/$a);\n$i = $ni*$mi;\n$size = ($n*$m)-($i*$a*$a);\nif($n==($ni*$a)){$nii=0}else{$nii=1}\nif($m==($mi*$a)){$mii=0}else{$mii=1}\n\nif ($size == ($n*$m)) {$i++;}\nelsif ($size != 0){$i += ($ni*$nii+$mi*$mii+1);\nif (($nii == 0)||($mii == 0)){$i--;}}\nprint(\"$i\\n\");"}, {"source_code": "#!/usr/bin/env perl \n#===============================================================================\n# FILE: theatre.pl\n# AUTHOR: Phoenix Ikki (liuxueyang.github.io), liuxueyang457@gmail.com\n# ORGANIZATION: Hunan University\n# CREATED: 05/25/2015 07:53:32 PM\n#===============================================================================\n\nuse strict;\nuse warnings;\nuse utf8;\nuse 5.012;\nuse integer;\n\nchomp($_ = );\nmy ($n, $m, $a) = split;\n\nprint int(cal($n, $a) * cal($m, $a)) . \"\\n\";\nsub cal\n{\n my ($m, $a) = @_;\n int($m / $a) + ($m % $a == 0 ? 0 : 1);\n}\n\n\n"}, {"source_code": "use strict;\nuse Data::Dumper;\nuse POSIX;\n\nmy $input = <>;\n\nmy ($n, $m, $a) = split(/ /, $input);\n\nprint paveSquare($n, $m, $a);\n\nsub paveSquare {\n\tmy ($n, $m, $a) = @_;\n\tmy $counter = 0;\n\n\tif ($n > $m) {\n\t\tmy $k = $n;\n\t\t$n = $m;\n\t\t$m = $k;\n\t}\n\tmy $remain = $m - $n;\n\t$counter += ceil($n / $a);\n\twarn $counter;\n\t$counter *= ceil($m / $a);\n\treturn int($counter);\n}"}, {"source_code": "#!/usr/bin/env perl \n#===============================================================================\n# FILE: theatre.pl\n# AUTHOR: Phoenix Ikki (liuxueyang.github.io), liuxueyang457@gmail.com\n# ORGANIZATION: Hunan University\n# CREATED: 05/25/2015 07:53:32 PM\n#===============================================================================\n\nuse strict;\nuse warnings;\nuse utf8;\nuse 5.012;\n\nchomp($_ = );\nmy ($n, $m, $a) = split;\n\nprint int(cal($n, $a) * cal($m, $a)) . \"\\n\";\nsub cal\n{\n my ($m, $a) = @_;\n int($m / $a) + ($m % $a == 0 ? 0 : 1);\n}\n\n\n"}, {"source_code": "use bigint;\n\nsub ceil {\n if ( @_[0] > (int @_[0]) ) {\n\treturn (int ( @_[0] ) + 1); }\n else {\n\treturn ( @_[0] ) }\n}\n\nmy $f = ;\nmy $one;\nmy $two;\nmy $thr;\n\nif ( $f =~ m/(\\d)+ (\\d)+ (\\d)+/ ) {\n $one = $1;\n $two = $2;\n $thr = $3; }\n\nmy $ans = &ceil ( $one / $thr ) * &ceil ( $two / $thr );\nprint $ans . \"\\n\";\n\n\n\n"}, {"source_code": "chmod($line = <>);\n($n, $m, $a) = split(' ', $line);\nprint (int(($n + $a - 1) / $a) + int(($m + $a - 1) / $a));"}, {"source_code": "my $input = do { local $/; scalar <> };\nmy ($n, $m, $a) = split /\\s+/s, $input;\n\nmy ($dm, $dn) = map { ceil( $_ / $a ) } $m, $n;\n\nprintf \"%d\\n\", $dn * $dm;\n\nsub ceil {\n my ( $x ) = @_;\n return 1 if $x < 1;\n return int( $x ) < $x ? int($x) + 1 : int $x;\n}\n"}, {"source_code": "my $input = do { local $/; scalar <> };\nmy ($n, $m, $a) = split /\\s+/s, $input;\n\nmy ($dm, $dn) = map { ceil( $_ / $a ) } $m, $n;\n\nprintf \"%d\\n\", $dn * $dm;\n\nsub ceil {\n my ( $x ) = @_;\n return 1 if $x < 1;\n return int( $x ) < $x ? int($x) + 1 : int $x;\n}\n"}, {"source_code": "#!/usr/bin/perl\nuse integer;\n($n,$m,$a)=split' ',<>;\n$answer = ($n*$m)/($a*$a);\nprint \"$answer\";"}, {"source_code": "#!/usr/bin/perl\nuse integer;\n($n,$m,$a)=split' ',<>;\n$answer = ($n*$m)/($a*$a);\nprint \"$answer\";"}, {"source_code": "#!/usr/bin/perl\n\n$_ = <>;\n@a = split;\n$n = ($a[0] / $a[2]);\n$x = ($a[1] / $a[2]);\nif($a[0] % $a[2] != 0){\n $n++;\n}\nif($a[1] % $a[2] != 0){\n $x++;\n}\n$k = int($x) * int($n);\nprint \"$k\";"}, {"source_code": "\nsub ceil {\n if ( @_[0] > (int @_[0]) ) {\n\treturn (int ( @_[0] ) + 1); }\n else {\n\treturn ( @_[0] ) }\n}\n\nmy $f = ;\nmy $one;\nmy $two;\nmy $thr;\n\nif ( $f =~ m/(\\d)+ (\\d)+ (\\d)+/ ) {\n $one = $1;\n $two = $2;\n $thr = $3; }\n\nmy $ans = &ceil ( $one / $thr ) * &ceil ( $two / $thr );\nprint $ans . \"\\n\";\n\n\n\n"}, {"source_code": "my($n, $m, $a) = split(\" \", );\nprint int(($n + $a -1) / $a) * int(($m + $a -1) / $a);"}, {"source_code": "use POSIX(ceil);\n$_ = <>;\n@a = split;\nprintf \"%lli\\n\", ceil($a[0] / $a[2]) * ceil($a[1] / $a[2]);"}, {"source_code": "use strict;\nuse warnings;\n\n#use POSIX qw(ceil);\n\nmy $input = <>;\nmy ($n, $m, $a) = split ' ', $input;\n\n# cover n x m meters with ? number of stones of size a x a.\n# calculate how many stones needed in n direction and then in m direction.\n\nmy $n_stones = int( $n / $a + 0.999999999999 );\nmy $m_stones = int( $m / $a + 0.999999999999 );\nmy $needed_stones = $n_stones * $m_stones;\n\nprint \"$needed_stones\\n\";\n\n"}, {"source_code": "while() {\n my($n, $m, $a) = split(\" \", $_);\n print int(($n + $a -1) / $a) * int(($m + $a -1) / $a);\n}"}, {"source_code": "#!/usr/bin/perl\nuse POSIX;\n$_ = <>;\ns/(\\d+).(\\d+).(\\d+)/ceil($1\\/$3)*ceil($2\\/$3)/e;\nprint;\n"}, {"source_code": "use strict;\nuse warnings;\n\nuse Data::Dumper;\n\nmy $line = ;\n\nmy ($n, $m, $a) = split(/\\s+/, $line);\n\n$n += $n % $a ? $a - $n % $a : 0;\n$m += $m % $a ? $a - $m % $a : 0;\n\nprint (($n/$a) * ($m/$a));\nprint \"\\n\";\n"}, {"source_code": " $_ = <>;\n my @arr = split/\\s+/;\n #print @arr;\n my $tiles1 = 0;\n my $tiles2 = 0;\n { \n use integer;\n $tiles1 += $arr[0]/$arr[2];\n $tiles2 += $arr[1]/$arr[2];\n }\n if ($arr[0]%$arr[2] != 0) {\n $tiles1 += 1;\n }\n if ($arr[1]%$arr[2] != 0) {\n #$tiles += 1;\n }\n my $tiles = $tiles1*$tiles2;\n print \"$tiles\\n\";\n exit 0;\n"}, {"source_code": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n#use POSIX qw(ceil);\n\n#my ($m, $n, $a) = ($ARGV[0], $ARGV[1], $ARGV[2]); #(7,6,4);\nmy $userinput = ; #read stdin and put it in $userinput\nchomp ($userinput); #cut the return / line feed character\nmy ($m, $n, $a) = split(/\\s+|,/, $userinput);\n\nmy $add = ($m%$a>0)?1:0;\nmy $ret = int($m/$a + $add) * int($n/$a + $add);\nprintf \"%.0f\", $ret;\n\n"}, {"source_code": "#!/usr/bin/perl\nuse integer;\n($n,$m,$a)=split' ',<>;\n$c1 = ($n%$a);\n$c2 = ($m%$a);\n\nif ($c1 eq 0)\n{$miss1 = 0;}\nelse\n{$miss1 =$a-($n%$a);}\n\nif ($c2 eq 0)\n{$miss2 = 0;}\nelse\n{$miss2 =$a-($m%$a);}\n\n$answer = (($n+$miss1)/$a)*(($m+$miss2)/$a);\nprint \"$answer\";"}, {"source_code": "#!/usr/bin/env perl \n#===============================================================================\n# FILE: theatre.pl\n# AUTHOR: Phoenix Ikki (liuxueyang.github.io), liuxueyang457@gmail.com\n# ORGANIZATION: Hunan University\n# CREATED: 05/25/2015 07:53:32 PM\n#===============================================================================\n\nuse strict;\nuse warnings;\nuse utf8;\n\nchomp($_ = );\nmy ($n, $m, $a) = split;\n\nprint int(cal($n, $a) * cal($m, $a)) . \"\\n\";\nsub cal\n{\n my ($m, $a) = @_;\n int($m / $a) + ($m % $a == 0 ? 0 : 1);\n}\n\n\n"}, {"source_code": "use bigint;\nmy ($n, $m, $a) = split \" \",<>;\nprint (($n + $a - 1) / $a * ($m + $a - 1) / $a);"}, {"source_code": "my $input = do { local $/; scalar <> };\nmy ($n, $m, $a) = split /\\s+/s, $input;\n\nmy ($dm, $dn) = map { ceil( $_ / $a ) } $m, $n;\n\nprintf \"%d\\n\", $dn * $dm;\n\nsub ceil {\n my ( $x ) = @_;\n return 1 if $x < 1;\n return int( $x ) < $x ? int($x) + 1 : int $x;\n}\n"}, {"source_code": "($n, $m, $a) = split \" \", <>;\n$x = int($n/$a);\n$y = int($m/$a);\nif ($n % $a != 0)\n{\n\t$x = $x + 1;\n}\nif ($m % $a != 0)\n{\n\t$y = $y + 1;\n}\n$res = $x * $y;\nprintf \"%d\\n\", $res;"}, {"source_code": "#!/usr/bin/perl\nuse POSIX;\nuse bigint;\n@l = split ' ', <>;\n$m = ceil($l[0]/$l[2]);\n$n = ceil($l[1]/$l[2]);\n$\" = $m*$n;\nprint $\";\n"}, {"source_code": "#!/usr/bin/perl\nuse integer;\n($n,$m,$a)=split' ',<>;\n$c1 = ($n%$a);\n$c2 = ($m%$a);\n\nif ($c1 eq 0)\n{$miss1 = 0;}\nelse\n{$miss1 =$a-($n%$a);}\n\nif ($c2 eq 0)\n{$miss2 = 0;}\nelse\n{$miss2 =$a-($m%$a);}\n\n$answer = (($n+$miss1)/$a)*(($m+$miss2)/$a);\nprint \"$answer\";"}, {"source_code": "no bigint;\nuse strict;\n\nmain();\n\nsub main {\n\tmy $input = $ENV{PERLUSER} eq \"s_p\"? \\*DATA: \\*STDIN;\n\tfor (<$input>) {\n\t\tmy ($n, $m, $a, $nm) = split;\n\t\t$n = int($n / $a) + ($n % $a? 1: 0);\n\t\t$m = int($m / $a) + ($m % $a? 1: 0);\n\t\tprint defined($nm)? \n\t\t\t[qw(fail ok)]->[itoa(mul($n, $m)) eq $nm]: \n\t\t\titoa(mul($n, $m)), \"\\n\";\n\t}\n}\n\nsub add {\n\tmy ($p2, $p1, $add) = @_;\n\tmy $addok = 0xffff_ffff - $p1;\n\t$add <= $addok? \n\t\t($p2, $p1 + $add):\n\t\t($p2 + 1, $add - $addok - 1);\n}\n\n# b=2^16, n1=q1*b+r1, n2=q2*b+r2\n# n1*n2=(q1*b+r1)(q2*b+r2)=q1*q2*b^2 + q1*r2*b + q2*r1*b + r1*r2\nsub mul {\n\tmy ($n1, $n2) = @_;\n\tmy $B16 = 0xffff;\n\tmy ($q1, $r1) = ($n1>>16, $n1 & $B16);\n\tmy ($q2, $r2) = ($n2>>16, $n2 & $B16);\n\tmy ($tmp, $bits_00_15, $bits_16_31, $bits_32_63);\n\t$tmp = $r1 * $r2;\n\t$bits_00_15 = $tmp & $B16;\n\t$tmp = $q1 * $r2 + $q2 * $r1 + ($tmp>>16);\n\t$bits_16_31 = $tmp & $B16;\n\t$bits_32_63 = $q1 * $q2 + ($tmp>>16);\n\tmy $p1 = ($bits_16_31<<16) + $bits_00_15;\n\tmy $p2 = $bits_32_63;\n\t# print \"mul $n1 x $n2 = $p2, $p1\\n\";\n\t($p2, $p1);\n}\n\n# p2*b+p1 = (q2*d+r2)*(q3*d+r3) + q1*d+r1 = \n# q2*q3*d^2 + q2*r3*d + r2*q3*d + r2*r3 + q1*d + r1\n# (q2*q3*d + q2*r3 + r2*q3 + q1) * d + (r2*r3 + r1)\nsub div {\n\tmy ($p2, $p1, $d) = @_;\n\tmy $b = 0xffff_ffff;\n\tmy ($q1, $r1) = (int($p1/10), $p1%10);\n\tmy ($q2, $r2) = (int($p2/10), $p2%10);\n\tmy ($q3, $r3) = (int($b/10), $b%10 + 1);\n\tmy ($divp2, $divp1, $divr);\n\t($divp2, $divp1) = mul($q2, $q3 * $d);\n\t($divp2, $divp1) = add($divp2, $divp1, $q2 * $r3);\n\t($divp2, $divp1) = add($divp2, $divp1, $r2 * $q3);\n\t($divp2, $divp1) = add($divp2, $divp1, $q1);\n\t$divr = $r2 * $r3 + $r1;\n\t$divp1 += int($divr/10);\n\t$divr = $divr % 10;\n\t# print \"div ($p2, $p1) / $d = ($divp2, $divp1) + $divr\\n\";\n\t($divp2, $divp1, $divr);\n}\n\n# 10^15 = 232830*2^32+2764472320\n# 10^14 = 23283*2^32+ 276447232\n# div(232830, 2764472320, 10);\n\n# 2^32 + 1234 = 4294968530 = (1, 1234)\n# 2^32/10 = (0, 429496853, 0)\n# div(1, 1234, 10);\n\nsub itoa {\n\tmy ($p2, $p1) = @_;\n\tmy ($s, $r);\n\twhile ($p2 || $p1) {\n\t\t($p2, $p1, $r) = div($p2, $p1, 10);\n\t\t$s = substr(\"0123456789\", $r, 1).$s;\n\t\t# print \"p2=$p2 p1=$p1 r=$r s=$s\\n\";\n\t}\n\t$s;\n}\n\n__DATA__\n2147483648 2147483648 1 4611686018427387904\n6 6 4 4\n"}, {"source_code": "<>;for(<>){s/(?<=.).{9,}(?=.)/(length)-3/e;print}\n"}, {"source_code": "use strict;\nuse warnings;\n\nuse Data::Dumper;\n\nmy $line = ;\n\nmy ($n, $m, $a) = split(/\\s+/, $line);\n\n$n += $n % $a ? $a - $n % $a : 0;\n$m += $m % $a ? $a - $m % $a : 0;\n\nprint (($n/$a) + ($m/$a));\nprint \"\\n\";\n"}, {"source_code": "#!/usr/bin/env perl\n\nuse strict;\nuse warnings;\nuse integer;\n\nmy $line = ;\n\nmy ($height, $width, $a);\nif ($line =~ /(\\d+) (\\d+) (\\d+)/) {\n\t$height = $1;\n\t$width = $2;\n\t$a = $3;\n}\nprint (($height / $a) + 1 + ($width / $a) + 1);\n"}, {"source_code": "use bigint;\n\nsub ceil {\n if ( @_[0] > (int @_[0]) ) {\n\treturn (int ( @_[0] ) + 1); }\n else {\n\treturn ( @_[0] ) }\n}\n\nmy $f = ;\nmy $one;\nmy $two;\nmy $thr;\n\nif ( $f =~ m/(\\d)+ (\\d)+ (\\d)+/ ) {\n $one = $1;\n $two = $2;\n $thr = $3; }\n\nmy $ans = &ceil ( $one / $thr ) * &ceil ( $two / $thr );\nprint $ans . \"\\n\";\n\n\n\n"}, {"source_code": "use strict;\nuse warnings;\n\n#use POSIX qw(ceil);\n\nmy $input = <>;\nmy ($n, $m, $a) = split ' ', $input;\n\n# cover n x m meters with ? number of stones of size a x a.\n# calculate how many stones needed in n direction and then in m direction.\n\nmy $n_stones = ( $n / $a ) + ( $n % $a > 0 ? 1 : 0 );\nmy $m_stones = ( $m / $a ) + ( $n % $a > 0 ? 1 : 0 );\nmy $needed_stones = int($n_stones) * int($m_stones);\n\nprint \"$needed_stones\\n\";\n\n"}, {"source_code": "#!/usr/bin/env perl \n#===============================================================================\n# FILE: theatre.pl\n# AUTHOR: Phoenix Ikki (liuxueyang.github.io), liuxueyang457@gmail.com\n# ORGANIZATION: Hunan University\n# CREATED: 05/25/2015 07:53:32 PM\n#===============================================================================\n\nuse strict;\nuse warnings;\nuse utf8;\nuse 5.012;\n\nchomp($_ = );\nmy ($n, $m, $a) = split;\n\nprint int(cal($n, $a) * cal($m, $a)) . \"\\n\";\nsub cal\n{\n my ($m, $a) = @_;\n int($m / $a) + ($m % $a == 0 ? 0 : 1);\n}\n\n\n"}, {"source_code": "($n, $m, $k) = split(' ', <>);\n$ans = int($n / $k + 0.99) * int($m / $k + 0.99);\nprint $ans == 0 ? 1 : $ans;\n"}, {"source_code": "use strict;\nuse warnings;\nuse utf8;\n\nmy $stdin=;\nchomp($stdin);\nmy @in=split(\" \", $stdin);\n\nmy $h=int($in[0]/$in[2]);\n$h++\tunless($in[0]%$in[2]==0);\n\nmy $w=int($in[1]/$in[2]);\n$w++\tunless($in[1]%$in[2]==0);\n\nprint $h * $w.\"\\n\";\n\n"}, {"source_code": "#!/usr/bin/perl\n\n$input_line = ;\nchop($input_line);\n($n,$m,$a)=split(/ /,$input_line);\n$ni = int($n/$a);\n$mi = int($m/$a);\n$i = $ni*$mi;\n$size = ($n*$m)-($i*$a);\nif ($size != 0){$i += ($ni+$mi+1);}\nprint(\"$i\\n\");"}, {"source_code": "use strict;\nuse warnings;\n\n#use POSIX qw(ceil);\n\nmy $input = <>;\nmy ($n, $m, $a) = split ' ', $input;\n\n# cover n x m meters with ? number of stones of size a x a.\n# calculate how many stones needed in n direction and then in m direction.\n\nmy $n_stones = ( $n / $a ) + ( $n % $a > 0 ? 1 : 0 );\nmy $m_stones = ( $m / $a ) + ( $n % $a > 0 ? 1 : 0 );\nmy $needed_stones = int($n_stones) * int($m_stones);\n\nprint \"$needed_stones\\n\";\n\n"}, {"source_code": "chmod($line = <>);\n($n, $m, $a) = split(' ', $line);\n$res = int(int(($n + $a - 1) / $a) * int(($m + $a - 1) / $a));\nprint (\"$res\");\n"}, {"source_code": "#!perl\n\n#use strict;\n#use warnings;\n\nmy $n;\nmy $m;\nmy $a;\nwhile (<>) {\n chomp;\n ($n, $m, $a) = split(/ /);\n last;\n}\n\nmy $r1 = sprintf(\"%.0f\", $n/$a);\nmy $r2 = sprintf(\"%.0f\", $m/$a);\nmy $area = $r1 * $r2;\n$area = 1 if ($area < 1);\nprint \"$area\\n\";\n\nexit(0);"}, {"source_code": "my ($n,$m,$a) = split (' ',);\nif ($n % $a != 0) {\n\t$n = int($n / $a) + 1;\n} else {\n\t$n = $n / $a;\n}\nif ($m % $a != 0) {\n\t$m = int($m / $a) + 1;\n} else {\n\t$m = $m / $a;\n}\nprint $m*$n;"}, {"source_code": "chmod($line = <>);\n($n, $m, $a) = split(' ', $line);\nprint (int(($n + $a - 1) / $a) * int(($m + $a - 1) / $a));"}, {"source_code": "my @a = split \" \", <>;\nprintf (\"%Ld\\n\", (((int $a[0] / $a[2]) + ($a[0] % $a[2] > 0)) * ((int $a[1] / $a[2]) + ($a[1] % $a[2] > 0))));"}], "src_uid": "ef971874d8c4da37581336284b688517"} {"nl": {"description": "Nothing is eternal in the world, Kostya understood it on the 7-th of January when he saw partially dead four-color garland.Now he has a goal to replace dead light bulbs, however he doesn't know how many light bulbs for each color are required. It is guaranteed that for each of four colors at least one light is working.It is known that the garland contains light bulbs of four colors: red, blue, yellow and green. The garland is made as follows: if you take any four consecutive light bulbs then there will not be light bulbs with the same color among them. For example, the garland can look like \"RYBGRYBGRY\", \"YBGRYBGRYBG\", \"BGRYB\", but can not look like \"BGRYG\", \"YBGRYBYGR\" or \"BGYBGY\". Letters denote colors: 'R' — red, 'B' — blue, 'Y' — yellow, 'G' — green.Using the information that for each color at least one light bulb still works count the number of dead light bulbs of each four colors.", "input_spec": "The first and the only line contains the string s (4 ≤ |s| ≤ 100), which describes the garland, the i-th symbol of which describes the color of the i-th light bulb in the order from the beginning of garland: 'R' — the light bulb is red, 'B' — the light bulb is blue, 'Y' — the light bulb is yellow, 'G' — the light bulb is green, '!' — the light bulb is dead. The string s can not contain other symbols except those five which were described. It is guaranteed that in the given string at least once there is each of four letters 'R', 'B', 'Y' and 'G'. It is guaranteed that the string s is correct garland with some blown light bulbs, it means that for example the line \"GRBY!!!B\" can not be in the input data. ", "output_spec": "In the only line print four integers kr, kb, ky, kg — the number of dead light bulbs of red, blue, yellow and green colors accordingly.", "sample_inputs": ["RYBGRYBGR", "!RGYB", "!!!!YGRB", "!GB!RG!Y!"], "sample_outputs": ["0 0 0 0", "0 1 0 0", "1 1 1 1", "2 1 1 0"], "notes": "NoteIn the first example there are no dead light bulbs.In the second example it is obvious that one blue bulb is blown, because it could not be light bulbs of other colors on its place according to the statements."}, "positive_code": [{"source_code": "$_ = ;\n\nfor ( /.{1,4}/g ) {\n\t$A{ $-[0] }++ while /!/g;\n\t$B{ $& } = $-[0] while /\\w/g;\n}\n\nfor ( qw(R B Y G) ) {\n\t$i = $B{$_};\n\t$j = $A{$i} || 0;\n\tprint $j, \" \";\n}\n"}], "negative_code": [], "src_uid": "64fc6e9b458a9ece8ad70a8c72126b33"} {"nl": {"description": "Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was stolen while he was on duty. He doesn't want to be fired, so he has to quickly restore the painting. He remembers some facts about it. The painting is a square 3 × 3, each cell contains a single integer from 1 to n, and different cells may contain either different or equal integers. The sum of integers in each of four squares 2 × 2 is equal to the sum of integers in the top left square 2 × 2. Four elements a, b, c and d are known and are located as shown on the picture below. Help Vasya find out the number of distinct squares the satisfy all the conditions above. Note, that this number may be equal to 0, meaning Vasya remembers something wrong.Two squares are considered to be different, if there exists a cell that contains two different integers in different squares.", "input_spec": "The first line of the input contains five integers n, a, b, c and d (1 ≤ n ≤ 100 000, 1 ≤ a, b, c, d ≤ n) — maximum possible value of an integer in the cell and four integers that Vasya remembers.", "output_spec": "Print one integer — the number of distinct valid squares.", "sample_inputs": ["2 1 1 1 2", "3 3 1 2 3"], "sample_outputs": ["2", "6"], "notes": "NoteBelow are all the possible paintings for the first sample. In the second sample, only paintings displayed below satisfy all the rules. "}, "positive_code": [{"source_code": "use v5.10;\n\n$_ = ;\n($n, $a, $b, $c, $d) = split;\n\n\nforeach (1..$n) {\n $x = $_ + $b - $c;\n if ($x < 1 or $x > $n) {\n next;\n }\n $z = $_ + $a - $d;\n if ($z < 1 or $z > $n) {\n next;\n }\n $y = $a - $d + $x;\n if ($y < 1 or $y > $n) {\n next;\n }\n $answ++;\n}\n\n\nsay $answ * $n;"}], "negative_code": [], "src_uid": "b732869015baf3dee5094c51a309e32c"} {"nl": {"description": "To quickly hire highly skilled specialists one of the new IT City companies made an unprecedented move. Every employee was granted a car, and an employee can choose one of four different car makes.The parking lot before the office consists of one line of (2n - 2) parking spaces. Unfortunately the total number of cars is greater than the parking lot capacity. Furthermore even amount of cars of each make is greater than the amount of parking spaces! That's why there are no free spaces on the parking lot ever.Looking on the straight line of cars the company CEO thought that parking lot would be more beautiful if it contained exactly n successive cars of the same make. Help the CEO determine the number of ways to fill the parking lot this way.", "input_spec": "The only line of the input contains one integer n (3 ≤ n ≤ 30) — the amount of successive cars of the same make.", "output_spec": "Output one integer — the number of ways to fill the parking lot by cars of four makes using the described way.", "sample_inputs": ["3"], "sample_outputs": ["24"], "notes": "NoteLet's denote car makes in the following way: A — Aston Martin, B — Bentley, M — Mercedes-Maybach, Z — Zaporozhets. For n = 3 there are the following appropriate ways to fill the parking lot: AAAB AAAM AAAZ ABBB AMMM AZZZ BBBA BBBM BBBZ BAAA BMMM BZZZ MMMA MMMB MMMZ MAAA MBBB MZZZ ZZZA ZZZB ZZZM ZAAA ZBBB ZMMMOriginally it was planned to grant sport cars of Ferrari, Lamborghini, Maserati and Bugatti makes but this idea was renounced because it is impossible to drive these cars having small road clearance on the worn-down roads of IT City."}, "positive_code": [{"source_code": "#!/usr/bin/env perl\n\nuse bigint;\n\nsub factorial {\n my $n = shift;\n if ($n==0) {\n return 1;\n } else {\n return $n*factorial($n-1);\n }\n}\n\nsub subfactorial {\n my $n = shift;\n my $sub = shift;\n if ($n==$sub) {\n return 1;\n } else {\n return $n*subfactorial($n-1, $sub);\n }\n}\n\n\n$n = ;\n$result = 2*4*3*(4**($n-3));\n$result += ($n-3)*4*(3**2)*(4**($n-4)) if $n > 3;\nprint \"$result\\n\";"}], "negative_code": [{"source_code": "#!/usr/bin/env perl\n\nuse bigint;\n\nsub factorial {\n my $n = shift;\n if ($n==0) {\n return 1;\n } else {\n return $n*factorial($n-1);\n }\n}\n\nsub subfactorial {\n my $n = shift;\n my $sub = shift;\n if ($n==$sub) {\n return 1;\n } else {\n return $n*subfactorial($n-1, $sub);\n }\n}\n\n\n$n = ;\n$result = ($n-1)*4*(3**($n-2));\nprint \"$result\\n\";"}], "src_uid": "3b02cbb38d0b4ddc1a6467f7647d53a9"} {"nl": {"description": "You have r red, g green and b blue balloons. To decorate a single table for the banquet you need exactly three balloons. Three balloons attached to some table shouldn't have the same color. What maximum number t of tables can be decorated if we know number of balloons of each color?Your task is to write a program that for given values r, g and b will find the maximum number t of tables, that can be decorated in the required manner.", "input_spec": "The single line contains three integers r, g and b (0 ≤ r, g, b ≤ 2·109) — the number of red, green and blue baloons respectively. The numbers are separated by exactly one space.", "output_spec": "Print a single integer t — the maximum number of tables that can be decorated in the required manner.", "sample_inputs": ["5 4 3", "1 1 1", "2 3 3"], "sample_outputs": ["4", "1", "2"], "notes": "NoteIn the first sample you can decorate the tables with the following balloon sets: \"rgg\", \"gbb\", \"brr\", \"rrg\", where \"r\", \"g\" and \"b\" represent the red, green and blue balls, respectively."}, "positive_code": [{"source_code": "use List::Util qw(min max sum);\n\nuse bigint;\n\nmy @cnt = split / /, <>;\n@cnt = sort {$a <=> $b} @cnt;\n$ans = int (($cnt[0] + $cnt[1] + (min ($cnt[2], 2 * ($cnt[0] + $cnt[1])))) / 3);\nprint $ans, \"\\n\";"}, {"source_code": "use bigint;\nuse integer;\nwhile(<>){\n\tchomp;\n\t($a,$b,$c)=@_=sort {$b<=>$a} split/ /;\n\t$m=($a-$b);\n\t$m>($b-$c) and $m=$b-$c;\n\t$sum=0;\n\t$sum+=$m;\n\t$a-=$m*2;\n\t$b-=$m;\n#\tprint \"$a $b $c|$sum\\n\";\n\t\n\tif ($a!=$b){\n\t\t$m= ($a-$b) / 3;\n\t\t$b < $m and $m=$b;\n\t\t\n\t\t$sum+=$m*2;\n\t\t$a-= $m*4;\n\t\t$b-=$m;\n\t\t$c-=$m;\n\t\t\n\t\t\n\t#\t\tprint \"$a $b $c|$sum\\n\";\n\t\t\n\t\t$sum+=$c;\n\t\t$a-=$c;\n\t\t$b-=$c;\n\t\t$c-=$c;\n#\t\tprint \"$a $b $c|$sum\\n\";\n\t\t}\n\t\n\telse {\n#\t\t$m = ($a-$c)/3;\n#\t\t$a -= $m*3;\n#\t\t$b -= $m*3;\n#\t\t$sum += $m*2;\n\t\t\n#\t\t$sum+=$c;\n#\t\t$a-=$c;\n#\t\t$b-=$c;\n#\t\t$c-=$c;\n#\t\tprint \"$a $b $c|$sum\\n\";\n\t\t$sum += ($a+$b+$c) / 3;\n\t\t\n\t\t}\nprint \"$sum\\n\"\t\n\t\n\t}"}, {"source_code": "use bigint;\nwhile(<>){\n\t($a,$b,$c)=sort {$b<=>$a} split/ /;\n\t$m=$a-$b;\n\t$m>$b-$c and $m=$b-$c;\n\t$sum=0;\n\t$sum+=$m;\n\t$a-=$m*2;\n\t$b-=$m;\n\t\n\tif ($a!=$b){\n\t\t$m= ($a-$b) / 3;\n\t\t$b < $m and $m=$b;\n\t\t$sum+=$c+$m;\n\t\t}\n\telse {\n\t\t$sum += ($a+$b+$c) / 3;\n\t\t}\n\tprint \"$sum\\n\"\n\t}"}], "negative_code": [{"source_code": "use List::Util qw(min max);\n\nuse bigint;\nuse integer;\n\nmy @cnt = split / /, <>;\n@cnt = sort {$a <=> $b} @cnt;\nmy $ans = $cnt[0];\n$cnt[1] -= $cnt[0];\n$cnt[2] -= $cnt[0];\n$ans += min ($cnt[1], $cnt[2], ($cnt[1] + $cnt[2]) / 3);\nprint $ans, \"\\n\";"}, {"source_code": "use List::Util qw(min max);\n\nuse bigint;\nuse integer;\n\nmy @cnt = split / /, <>;\n@cnt = sort @cnt;\nmy $ans = $cnt[0];\n$cnt[1] -= $cnt[0];\n$cnt[2] -= $cnt[0];\n$ans += min ($cnt[1], $cnt[2] / 2);\nprint $ans, \"\\n\";"}, {"source_code": "use List::Util qw(min max);\n\nuse bigint;\nuse integer;\n\nmy @cnt = split / /, <>;\n@cnt = sort @cnt;\nmy $ans = $cnt[0];\n$cnt[1] -= $cnt[0];\n$cnt[2] -= $cnt[0];\n$ans += min ($cnt[1], $cnt[2], ($cnt[1] + $cnt[2]) / 3);\nprint $ans, \"\\n\";"}, {"source_code": "use List::Util qw(min max sum);\n\nuse bigint;\nuse integer;\n\nmy @cnt = split / /, <>;\n@cnt = sort {$a <=> $b} @cnt;\n$ans = ($cnt[0] + $cnt[1] + (min ($cnt[2], 2 * ($cnt[0] + $cnt[1])))) / 3;\nprint $ans, \"\\n\";"}, {"source_code": "use List::Util qw(min max sum);\n\nuse bigint;\nuse integer;\n\nmy @cnt = split / /, <>;\n@cnt = sort {$a <=> $b} @cnt;\n$cnt[2] = min ($cnt[2], 2 * ($cnt[0] + $cnt[1]));\n$ans = (sum @cnt) / 3;\nprint $ans, \"\\n\";"}, {"source_code": "use bigint;\nuse integer;\nwhile(<>){\n\tchomp;\n\t($a,$b,$c)=@_=sort {$b<=>$a} split/ /;\n\tprint \"@_\\n\";\n\t$m=($a-$b);\n\t$m>($b-$c) and $m=$b-$c;\n\t$sum=0;\n\t$sum+=$m;\n\t$a-=$m*2;\n\t$b-=$m;\n#\tprint \"$a $b $c|$sum\\n\";\n\t\n\tif ($a!=$b){\n\t\t$m= ($a-$b) / 3;\n\t\t$b < $m and $m=$b;\n\t\t\n\t\t$sum+=$m*2;\n\t\t$a-= $m*4;\n\t\t$b-=$m;\n\t\t$c-=$m;\n\t\t\n\t\t\n\t#\t\tprint \"$a $b $c|$sum\\n\";\n\t\t\n\t\t$sum+=$c;\n\t\t$a-=$c;\n\t\t$b-=$c;\n\t\t$c-=$c;\n#\t\tprint \"$a $b $c|$sum\\n\";\n\t\t}\n\t\n\telse {\n\t\t$m = ($a-$c)/3;\n\t\t$a -= $m*3;\n\t\t$b -= $m*3;\n\t\t$sum += $m*2;\n\t\t\n\t\t$sum+=$c;\n\t\t$a-=$c;\n\t\t$b-=$c;\n\t\t$c-=$c;\n#\t\tprint \"$a $b $c|$sum\\n\";\n\t\t\n\t\t}\nprint \"$sum\\n\"\t\n\t\n\t}"}, {"source_code": "use bigint;\nuse integer;\nwhile(<>){\n\tchomp;\n\t($a,$b,$c)=@_=sort {$b<=>$a} split/ /;\n\t$m=($a-$b);\n\t$m>($b-$c) and $m=$b-$c;\n\t$sum=0;\n\t$sum+=$m;\n\t$a-=$m*2;\n\t$b-=$m;\n#\tprint \"$a $b $c|$sum\\n\";\n\t\n\tif ($a!=$b){\n\t\t$m= ($a-$b) / 3;\n\t\t$b < $m and $m=$b;\n\t\t\n\t\t$sum+=$m*2;\n\t\t$a-= $m*4;\n\t\t$b-=$m;\n\t\t$c-=$m;\n\t\t\n\t\t\n\t#\t\tprint \"$a $b $c|$sum\\n\";\n\t\t\n\t\t$sum+=$c;\n\t\t$a-=$c;\n\t\t$b-=$c;\n\t\t$c-=$c;\n#\t\tprint \"$a $b $c|$sum\\n\";\n\t\t}\n\t\n\telse {\n\t\t$m = ($a-$c)/3;\n\t\t$a -= $m*3;\n\t\t$b -= $m*3;\n\t\t$sum += $m*2;\n\t\t\n\t\t$sum+=$c;\n\t\t$a-=$c;\n\t\t$b-=$c;\n\t\t$c-=$c;\n#\t\tprint \"$a $b $c|$sum\\n\";\n\t\t\n\t\t}\nprint \"$sum\\n\"\t\n\t\n\t}"}], "src_uid": "bae7cbcde19114451b8712d6361d2b01"} {"nl": {"description": "When Valera was playing football on a stadium, it suddenly began to rain. Valera hid in the corridor under the grandstand not to get wet. However, the desire to play was so great that he decided to train his hitting the ball right in this corridor. Valera went back far enough, put the ball and hit it. The ball bounced off the walls, the ceiling and the floor corridor and finally hit the exit door. As the ball was wet, it left a spot on the door. Now Valera wants to know the coordinates for this spot.Let's describe the event more formally. The ball will be considered a point in space. The door of the corridor will be considered a rectangle located on plane xOz, such that the lower left corner of the door is located at point (0, 0, 0), and the upper right corner is located at point (a, 0, b) . The corridor will be considered as a rectangular parallelepiped, infinite in the direction of increasing coordinates of y. In this corridor the floor will be considered as plane xOy, and the ceiling as plane, parallel to xOy and passing through point (a, 0, b). We will also assume that one of the walls is plane yOz, and the other wall is plane, parallel to yOz and passing through point (a, 0, b).We'll say that the ball hit the door when its coordinate y was equal to 0. Thus the coordinates of the spot are point (x0, 0, z0), where 0 ≤ x0 ≤ a, 0 ≤ z0 ≤ b. To hit the ball, Valera steps away from the door at distance m and puts the ball in the center of the corridor at point . After the hit the ball flies at speed (vx, vy, vz). This means that if the ball has coordinates (x, y, z), then after one second it will have coordinates (x + vx, y + vy, z + vz).See image in notes for clarification.When the ball collides with the ceiling, the floor or a wall of the corridor, it bounces off in accordance with the laws of reflection (the angle of incidence equals the angle of reflection). In the problem we consider the ideal physical model, so we can assume that there is no air resistance, friction force, or any loss of energy.", "input_spec": "The first line contains three space-separated integers a, b, m (1 ≤ a, b, m ≤ 100). The first two integers specify point (a, 0, b), through which the ceiling and one of the corridor walls pass. The third integer is the distance at which Valera went away from the door. The second line has three space-separated integers vx, vy, vz (|vx|, |vy|, |vz| ≤ 100, vy < 0, vz ≥ 0) — the speed of the ball after the hit. It is guaranteed that the ball hits the door.", "output_spec": "Print two real numbers x0, z0 — the x and z coordinates of point (x0, 0, z0), at which the ball hits the exit door. The answer will be considered correct, if its absolute or relative error does not exceed 10  - 6.", "sample_inputs": ["7 2 11\n3 -11 2", "7 2 11\n4 -3 3"], "sample_outputs": ["6.5000000000 2.0000000000", "4.1666666667 1.0000000000"], "notes": "Note"}, "positive_code": [{"source_code": "$in_a = <>; @st = split(\" \",$in_a);\n$in_b = <>; @vv = split(\" \",$in_b);\nif ($st[2] == 0) { printf (\"%.10f %.10f\", ($st[0] / 2), 0); exit; }\n\n$tt = ($st[2] / $vv[1] * -1);\n$xx = ($vv[0] * $tt + $st[0] / 2); $xx = &MOD($xx,(2 * $st[0]),1);\n$zz = ($vv[2] * $tt); $zz = &MOD($zz,(2 * $st[1]),1);\n\nif (int($xx / $st[0]) == 1) { $st_x = ($st[0] * 2 - $xx); } else { $st_x = $xx; }\nif (int($zz / $st[1]) == 1) { $st_z = ($st[1] * 2 - $zz); } else { $st_z = $zz; }\n\nprintf (\"%.10f %.10f\", abs($st_x), abs($st_z));\n\nexit;\n\nsub MOD {\n my $aa = abs($_[1]); my $bb = ($_[0] - int($_[0] / $aa) * $aa);\n if ($bb < 0 && $_[2] == 1) { $bb += $aa; }\n return $bb;\n}\n"}], "negative_code": [{"source_code": "\n$in_a = <>; $in_b = <>;\n@st = split(\" \",$in_a);\n@vv = split(\" \",$in_b);\nif ($st[2] == 0) {\n $st_x = ($st[0] / 2);\n printf (\"%.10f\", $st_x);\n print \" \";\n printf (\"%.10f\", $st[1]);\n exit;\n}\n\n$tt = ($st[2] / $vv[1] * -1);\n$xx = ($vv[0] * $tt + $st[0] / 2); $i = int($xx / (2 * $st[0])); $xx -= (2 * $st[0] * $i);\n$zz = ($vv[2] * $tt); $i = int($zz / (2 * $st[1])); $zz -= (2 * $st[1] * $i);\n\nif ($xx % $st[0] == 1) { $st_x = ($xx - $st[0]); }\nelse { $st_x = $xx; }\n\nif ($zz % $st[1] == 1) { $st_z = ($zz - $st[1]); }\nelse { $st_z = $zz; }\n\n#print \"$st_x $st_z\\n\";\nprintf (\"%.10f\", $st_x);\nprint \" \";\nprintf (\"%.10f\", $st_z);\n\nexit;"}, {"source_code": "$in_a = <>; $in_b = <>;\n@st = split(\" \",$in_a);\n@vv = split(\" \",$in_b);\nif ($st[2] == 0) {\n $st_x = ($st[0] / 2);\n printf (\"%.10f\", $st_x);\n print \" \";\n printf (\"%.10f\", $st[1]);\n exit;\n}\n\n$tt = ($st[2] / $vv[1] * -1); print \"t=$tt\\n\";\n$xx = ($vv[0] * $tt + $st[0] / 2); $i = int($xx / (2 * $st[0])); $xx -= (2 * $st[0] * $i);\n$zz = ($vv[2] * $tt); $i = int($zz / (2 * $st[1])); $zz -= (2 * $st[1] * $i);\n\nif ($xx % $st[0] == 1) { $st_x = ($xx - $st[0]); }\nelse { $st_x = $xx; }\n\nif ($zz % $st[1] == 1) { $st_z = ($zz - $st[1]); }\nelse { $st_z = $zz; }\n\n#print \"$st_x $st_z\\n\";\nprintf (\"%.10f\", $st_x);\nprint \" \";\nprintf (\"%.10f\", $st_z);\n"}, {"source_code": "$in_a = <>; $in_b = <>;\n@st = split(\" \",$in_a);\n@vv = split(\" \",$in_b);\n\n$tt = ($st[2] / $vv[1] * -1);\n$xx = ($vv[0] * $tt + $st[0] / 2); $i = int($xx / (2 * $st[0])); $xx -= (2 * $st[0] * $i);\n$zz = ($vv[2] * $tt); $i = int($zz / (2 * $st[1])); $zz -= (2 * $st[1] * $i);\n\nif ($xx % $st[0] == 1) { $st_x = ($xx - $st[0]); }\nelse { $st_x = $xx; }\n\nif ($zz % $st[1] == 1) { $st_z = ($zz - $st[1]); }\nelse { $st_z = $zz; }\n\nprintf (\"%.10f\", $st_x);\nprint \" \";\nprintf (\"%.10f\", $st_z);"}, {"source_code": "## ◆ プログラムテスト用\n\n$in_a = <>; $in_b = <>;\n@st = split(\" \",$in_a);\n@vv = split(\" \",$in_b);\nif ($st[2] == 0) { printf (\"%.10f %.10f\", ($st[0] / 2), 0); exit; }\n\n$tt = ($st[2] / $vv[1] * -1);\n$xx = ($vv[0] * $tt + $st[0] / 2); $xx = &MOD($xx,(2 * $st[0]),1);\n$zz = ($vv[2] * $tt); $zz = &MOD($zz,(2 * $st[1]),1);\n\nif ($xx % $st[0] == 1) { $st_x = ($xx - $st[0]); }\nelse { $st_x = $xx; }\n\nif ($zz % $st[1] == 1) { $st_z = ($zz - $st[1]); }\nelse { $st_z = $zz; }\n\nprintf (\"%.10f %.10f\", $st_x, $st_z);\n\nexit;\n\nsub MOD {\n my $aa = abs($_[1]); my $bb = ($_[0] - int($_[0] / $aa) * $aa);\n if ($bb < 0 && $cc == 1) { $bb += $aa; }\n return $bb;\n}\n"}, {"source_code": "$in_a = <>; @st = split(\" \",$in_a);\n$in_b = <>; @vv = split(\" \",$in_b);\nif ($st[2] == 0) { printf (\"%.10f %.10f\", ($st[0] / 2), 0); exit; }\n\n$tt = ($st[2] / $vv[1] * -1);\n$xx = ($vv[0] * $tt + $st[0] / 2); $xx = &MOD($xx,(2 * $st[0]),1);\n$zz = ($vv[2] * $tt); $zz = &MOD($zz,(2 * $st[1]),1);\n\nif ($xx % $st[0] == 1) { $st_x = ($xx - $st[0]); } else { $st_x = $xx; }\nif ($zz % $st[1] == 1) { $st_z = ($zz - $st[1]); } else { $st_z = $zz; }\n\nprintf (\"%.10f %.10f\", abs($st_x), abs($st_z));\n\nexit;\n\nsub MOD {\n my $aa = abs($_[1]); my $bb = ($_[0] - int($_[0] / $aa) * $aa);\n if ($bb < 0 && $cc == 1) { $bb += $aa; }\n return $bb;\n}\n"}, {"source_code": "$in_a = <>; @st = split(\" \",$in_a);\n$in_b = <>; @vv = split(\" \",$in_b);\nif ($st[2] == 0) { printf (\"%.10f %.10f\", ($st[0] / 2), 0); exit; }\n\n$tt = ($st[2] / $vv[1] * -1);\n$xx = ($vv[0] * $tt + $st[0] / 2); $xx = &MOD($xx,(2 * $st[0]),1);\n$zz = ($vv[2] * $tt); $zz = &MOD($zz,(2 * $st[1]),1);\n\nif (int($xx / $st[0]) == 1) { $st_x = ($st[0] * 2 - $xx); } else { $st_x = $xx; }\nif (int($zz / $st[1]) == 1) { $st_z = ($st[1] * 2 - $zz); } else { $st_z = $zz; }\n\nprintf (\"%.10f %.10f\", abs($st_x), abs($st_z));\n\nexit;\n\nsub MOD {\n my $aa = abs($_[1]); my $bb = ($_[0] - int($_[0] / $aa) * $aa);\n if ($bb < 0 && $cc == 1) { $bb += $aa; }\n return $bb;\n}\n"}], "src_uid": "84848b8bd92fd2834db1ee9cb0899cff"} {"nl": {"description": "Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea.Amr has n instruments, it takes ai days to learn i-th instrument. Being busy, Amr dedicated k days to learn how to play the maximum possible number of instruments.Amr asked for your help to distribute his free days between instruments so that he can achieve his goal.", "input_spec": "The first line contains two numbers n, k (1 ≤ n ≤ 100, 0 ≤ k ≤ 10 000), the number of instruments and number of days respectively. The second line contains n integers ai (1 ≤ ai ≤ 100), representing number of days required to learn the i-th instrument.", "output_spec": "In the first line output one integer m representing the maximum number of instruments Amr can learn. In the second line output m space-separated integers: the indices of instruments to be learnt. You may output indices in any order. if there are multiple optimal solutions output any. It is not necessary to use all days for studying.", "sample_inputs": ["4 10\n4 3 1 2", "5 6\n4 3 1 1 2", "1 3\n4"], "sample_outputs": ["4\n1 2 3 4", "3\n1 3 4", "0"], "notes": "NoteIn the first test Amr can learn all 4 instruments.In the second test other possible solutions are: {2, 3, 5} or {3, 4, 5}.In the third test Amr doesn't have enough time to learn the only presented instrument."}, "positive_code": [{"source_code": "my($n, $k) = split / /, <>;\nmy @inp = split \" \", <>;\nmy $num = 0;\nmy @ans = ();\nmy @arr = ();\nfor (0..$n-1) {\n push @arr, [$inp[$_], $_+1];\n}\n@arr = sort{$a->[0] <=> $b->[0]} @arr;\nfor (@arr) {\n last if ($k - $_->[0] < 0);\n $k -= $_->[0];\n $num++;\n push @ans, $_->[1];\n}\nprint \"$num\\n@ans\\n\";\n"}, {"source_code": "#!/usr/bin/perl\nuse v5.10;\n\n($n, $k) = split / /, <>;\n@buf = split / /, <>;\npush @arr, [($_, $buf[$_-1])] foreach (1..$n);\n@arr = sort { $a->[1] <=> $b->[1] } @arr;\n$tmp = 0;\nforeach my $i (0..$n-1) {\n\t$tmp += $arr[$i]->[1];\n\tif ($tmp > $k) {\n\t\tsay $i;\n\t\tprint $arr[$_]->[0],\" \" foreach (0..$i-1);\n\t\texit;\n\t}\n}\nsay $n;\nprint $arr[$_]->[0],\" \" foreach (0..$n-1);"}, {"source_code": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n\nmy ($n, $k) = split ' ',<>;\nmy @input = split ' ', <>;\nmy @data;\nfor my $i(0..@input-1){\n push @data, [$input[$i], $i+1];\n}\n@data = sort {$a->[0] <=> $b->[0]} @data;\nmy ($sum,@res) = (0,());\nforeach(@data){\n last if $sum + $_->[0] > $k;\n $sum += $_->[0];\n push @res, $_->[1];\n}\nprint scalar @res , \"\\n@res\";\n"}], "negative_code": [{"source_code": "#!/usr/bin/perl\nuse v5.10;\n\n($n, $k) = split / /, <>;\n@buf = split / /, <>;\npush @arr, [($_, $buf[$_-1])] foreach (1..$n);\n@arr = sort { $a->[1] <=> $b->[1] } @arr;\n$tmp = 0;\nforeach my $i (0..$n-1) {\n\t$tmp += $arr[$i]->[1];\n\tif ($tmp >= $k) {\n\t\tsay $i;\n\t\tprint $arr[$_]->[0],\" \" foreach (0..$i-1);\n\t\texit;\n\t}\n}\nsay $n;\nprint $arr[$_]->[0],\" \" foreach (0..$n-1);"}], "src_uid": "dbb164a8dd190e63cceba95a31690a7c"} {"nl": {"description": "There are three doors in front of you, numbered from $$$1$$$ to $$$3$$$ from left to right. Each door has a lock on it, which can only be opened with a key with the same number on it as the number on the door.There are three keys — one for each door. Two of them are hidden behind the doors, so that there is no more than one key behind each door. So two doors have one key behind them, one door doesn't have a key behind it. To obtain a key hidden behind a door, you should first unlock that door. The remaining key is in your hands.Can you open all the doors?", "input_spec": "The first line contains a single integer $$$t$$$ ($$$1 \\le t \\le 18$$$) — the number of testcases. The first line of each testcase contains a single integer $$$x$$$ ($$$1 \\le x \\le 3$$$) — the number on the key in your hands. The second line contains three integers $$$a, b$$$ and $$$c$$$ ($$$0 \\le a, b, c \\le 3$$$) — the number on the key behind each of the doors. If there is no key behind the door, the number is equal to $$$0$$$. Values $$$1, 2$$$ and $$$3$$$ appear exactly once among $$$x, a, b$$$ and $$$c$$$.", "output_spec": "For each testcase, print \"YES\" if you can open all the doors. Otherwise, print \"NO\".", "sample_inputs": ["4\n\n3\n\n0 1 2\n\n1\n\n0 3 2\n\n2\n\n3 1 0\n\n2\n\n1 3 0"], "sample_outputs": ["YES\nNO\nYES\nNO"], "notes": null}, "positive_code": [{"source_code": "for(1..<>){$_=<>;@a=split/\\s/,<>;print$_^@a[$_-1]^@a[@a[$_-1]-1]?\"NO \":\"YES \"}"}, {"source_code": "for(1..<>){$_=<>;@a=split/\\s/,<>;print$_^@a[$_-1]^@a[@a[$_-1]-1]?\"NO \":\"YES \"}\r\n"}, {"source_code": "for(1..<>){$_=<>;@a=split/\\s/,<>;print$_^@a[$_-1]^@a[@a[$_-1]-1]?\"NO \":\"YES \"}"}, {"source_code": "for(1..<>){$_=<>;@a=split/\\s/,<>;print$_^@a[$_-1]^@a[@a[$_-1]-1]?\"NO \":\"YES \"}"}], "negative_code": [], "src_uid": "5cd113a30bbbb93d8620a483d4da0349"} {"nl": {"description": "The recent All-Berland Olympiad in Informatics featured n participants with each scoring a certain amount of points.As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria: At least one participant should get a diploma. None of those with score equal to zero should get awarded. When someone is awarded, all participants with score not less than his score should also be awarded. Determine the number of ways to choose a subset of participants that will receive the diplomas.", "input_spec": "The first line contains a single integer n (1 ≤ n ≤ 100) — the number of participants. The next line contains a sequence of n integers a1, a2, ..., an (0 ≤ ai ≤ 600) — participants' scores. It's guaranteed that at least one participant has non-zero score.", "output_spec": "Print a single integer — the desired number of ways.", "sample_inputs": ["4\n1 3 3 2", "3\n1 1 1", "4\n42 0 0 42"], "sample_outputs": ["3", "1", "1"], "notes": "NoteThere are three ways to choose a subset in sample case one. Only participants with 3 points will get diplomas. Participants with 2 or 3 points will get diplomas. Everyone will get a diploma! The only option in sample case two is to award everyone.Note that in sample case three participants with zero scores cannot get anything."}, "positive_code": [{"source_code": "#!/usr/bin/perl\n\nuse strict;\nuse warnings;\n\nmy $min1 = 1000000000;\nmy $min2 = 1000000000;\nmy $max1 = 0;\nmy $max2 = 0;\n\nmy $n = <>;\n$n =~ s/\\s+$//;\n\nmy $a = <>;\n$a =~ s/\\s+$//;\nmy @a = split /\\s+/, $a;\nmy %h;\nmy $ans = 0;\n\nfor my $x (@a) {\n if ($x != 0) {\n if (!exists $h{$x}) {\n $h{$x}++;\n $ans++;\n }\n }\n}\nprint $ans;\n\n"}, {"source_code": "#!/usr/bin/perl\n\nuse warnings;\nuse strict;\n\n$\\ = $/;\n\nwhile(<>){\n\t\n\tmy %h;\n\t\n\tmap $h{ $_ } ++, grep $_ > 0, split ' ', <>;\n\t\n\tprint 0 + keys %h;\n\t}"}, {"source_code": "<>;\n\nmap $h{ $_ } ++, grep $_, split ' ', <>;\n\nprint 0 + keys %h"}, {"source_code": "<>;\n$_ = <>;\n0 while s/\\b(\\d+)\\b.*\\K \\1\\b//;\nprint ~~ grep $_, split"}], "negative_code": [], "src_uid": "3b520c15ea9a11b16129da30dcfb5161"} {"nl": {"description": "Right now she actually isn't. But she will be, if you don't solve this problem.You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This operation costs you A coins. Divide x by k. Can be performed only if x is divisible by k. This operation costs you B coins. What is the minimum amount of coins you have to pay to make x equal to 1?", "input_spec": "The first line contains a single integer n (1 ≤ n ≤ 2·109). The second line contains a single integer k (1 ≤ k ≤ 2·109). The third line contains a single integer A (1 ≤ A ≤ 2·109). The fourth line contains a single integer B (1 ≤ B ≤ 2·109).", "output_spec": "Output a single integer — the minimum amount of coins you have to pay to make x equal to 1.", "sample_inputs": ["9\n2\n3\n1", "5\n5\n2\n20", "19\n3\n4\n2"], "sample_outputs": ["6", "8", "12"], "notes": "NoteIn the first testcase, the optimal strategy is as follows: Subtract 1 from x (9 → 8) paying 3 coins. Divide x by 2 (8 → 4) paying 1 coin. Divide x by 2 (4 → 2) paying 1 coin. Divide x by 2 (2 → 1) paying 1 coin. The total cost is 6 coins.In the second test case the optimal strategy is to subtract 1 from x 4 times paying 8 coins in total."}, "positive_code": [{"source_code": "$n = <>;\n$k = <>;\n$a = <>;\n$b = <>;\n$s = 0;\n\nif ($k==1)\n{\n $s = ($n-1) * $a;\n print \"$s\";\n}\n\nelse\n{\n while ($n!=1)\n {\n if ( ($n%$k)==0 )\n {\n if ((($n-int(($n/$k)))*$a)< $b)\n {\n $s=$s+($n-int($n/$k))*$a;\n $n=int($n/$k);\n }\n \n else\n {\n $s=$s+$b;\n $n=int($n/$k);\n }\n \n }\n \n elsif ($n<$k)\n {\n $s=$s+($n-1)*$a;\n $n=1;\n last;\n }\n \n else\n {\n $s=$s+(($n-$k*int($n/$k))*$a);\n $n=int($n/$k)*$k;\n }\n }\n \n print \"$s\"; \n}"}], "negative_code": [], "src_uid": "f838fae7c98bf51cfa0b9bd158650b10"} {"nl": {"description": "Not so long ago the Codecraft-17 contest was held on Codeforces. The top 25 participants, and additionally random 25 participants out of those who got into top 500, will receive a Codeforces T-shirt.Unfortunately, you didn't manage to get into top 25, but you got into top 500, taking place p.Now the elimination round of 8VC Venture Cup 2017 is being held. It has been announced that the Codecraft-17 T-shirt winners will be chosen as follows. Let s be the number of points of the winner of the elimination round of 8VC Venture Cup 2017. Then the following pseudocode will be executed: i := (s div 50) mod 475repeat 25 times: i := (i * 96 + 42) mod 475 print (26 + i)Here \"div\" is the integer division operator, \"mod\" is the modulo (the remainder of division) operator.As the result of pseudocode execution, 25 integers between 26 and 500, inclusive, will be printed. These will be the numbers of places of the participants who get the Codecraft-17 T-shirts. It is guaranteed that the 25 printed integers will be pairwise distinct for any value of s.You're in the lead of the elimination round of 8VC Venture Cup 2017, having x points. You believe that having at least y points in the current round will be enough for victory.To change your final score, you can make any number of successful and unsuccessful hacks. A successful hack brings you 100 points, an unsuccessful one takes 50 points from you. It's difficult to do successful hacks, though.You want to win the current round and, at the same time, ensure getting a Codecraft-17 T-shirt. What is the smallest number of successful hacks you have to do to achieve that?", "input_spec": "The only line contains three integers p, x and y (26 ≤ p ≤ 500; 1 ≤ y ≤ x ≤ 20000) — your place in Codecraft-17, your current score in the elimination round of 8VC Venture Cup 2017, and the smallest number of points you consider sufficient for winning the current round.", "output_spec": "Output a single integer — the smallest number of successful hacks you have to do in order to both win the elimination round of 8VC Venture Cup 2017 and ensure getting a Codecraft-17 T-shirt. It's guaranteed that your goal is achievable for any valid input data.", "sample_inputs": ["239 10880 9889", "26 7258 6123", "493 8000 8000", "101 6800 6500", "329 19913 19900"], "sample_outputs": ["0", "2", "24", "0", "8"], "notes": "NoteIn the first example, there is no need to do any hacks since 10880 points already bring the T-shirt to the 239-th place of Codecraft-17 (that is, you). In this case, according to the pseudocode, the T-shirts will be given to the participants at the following places: 475 422 84 411 453 210 157 294 146 188 420 367 29 356 398 155 102 239 91 133 365 312 449 301 343In the second example, you have to do two successful and one unsuccessful hack to make your score equal to 7408.In the third example, you need to do as many as 24 successful hacks to make your score equal to 10400.In the fourth example, it's sufficient to do 6 unsuccessful hacks (and no successful ones) to make your score equal to 6500, which is just enough for winning the current round and also getting the T-shirt."}, "positive_code": [{"source_code": "#!/usr/bin/perl\n\nuse warnings;\nuse strict;\n\n$\\ = $/;\n\nwhile(<>){\n\tmy( $p, $x, $y ) = split;\n\t\n\tmy $xc = $x;\n\t\n\twhile( $xc - 50 >= $y ){\n\t\t$xc -= 50;\n\t\t}\n\t\t\n\twhile( 1 ){\n\t\tmy %print;\n\t\tmy $i = ( int $xc / 50 ) % 475;\n\t\tfor ( 1 .. 25 ){\n\t\t\t$i = ( $i * 96 + 42 ) % 475;\n\t\t\t$print{ 26 + $i } ++;\n\t\t\t}\n\t\t\t\n\t\tif( $print{ $p } ){\n\t\t\tlast;\n\t\t\t}\n\t\t$xc += 50;\n\t\t}\n\t\t\n\t$xc -= $x;\n\t$xc /= 50;\n\t\n\tprint $xc <= 0 ? 0 : int( ($xc + 1) / 2 );\n\t\n\t}"}, {"source_code": "( $p, $x, $y ) = split ' ', <>;\n\n$_ = $x;\n\n$_ -= 50 while $_ >= $y;\n\t\nwhile( 1 ){\n\t$_ += 50;\n\tmy %P;\n\t$i = $_ / 50 % 475;\n\t++ $P{ 26 + ( $i = ( $i * 96 + 42 ) % 475 ) } for 1 .. 25;\n\t\t\n\tlast if $P{ $p };\n\t}\n\t\n( $_ -= $x ) /= 50;\n\nprint $_ > 0 ? $_ + 1 >> 1 : 0"}], "negative_code": [], "src_uid": "c9c22e03c70a94a745b451fc79e112fd"} {"nl": {"description": "Finished her homework, Nastya decided to play computer games. Passing levels one by one, Nastya eventually faced a problem. Her mission is to leave a room, where a lot of monsters live, as quickly as possible.There are $$$n$$$ manholes in the room which are situated on one line, but, unfortunately, all the manholes are closed, and there is one stone on every manhole. There is exactly one coin under every manhole, and to win the game Nastya should pick all the coins. Initially Nastya stands near the $$$k$$$-th manhole from the left. She is thinking what to do.In one turn, Nastya can do one of the following: if there is at least one stone on the manhole Nastya stands near, throw exactly one stone from it onto any other manhole (yes, Nastya is strong). go to a neighboring manhole; if there are no stones on the manhole Nastya stays near, she can open it and pick the coin from it. After it she must close the manhole immediately (it doesn't require additional moves). The figure shows the intermediate state of the game. At the current position Nastya can throw the stone to any other manhole or move left or right to the neighboring manholes. If she were near the leftmost manhole, she could open it (since there are no stones on it). Nastya can leave the room when she picks all the coins. Monsters are everywhere, so you need to compute the minimum number of moves Nastya has to make to pick all the coins.Note one time more that Nastya can open a manhole only when there are no stones onto it.", "input_spec": "The first and only line contains two integers $$$n$$$ and $$$k$$$, separated by space ($$$2 \\leq n \\leq 5000$$$, $$$1 \\leq k \\leq n$$$) — the number of manholes and the index of manhole from the left, near which Nastya stays initially. Initially there is exactly one stone near each of the $$$n$$$ manholes. ", "output_spec": "Print a single integer — minimum number of moves which lead Nastya to pick all the coins.", "sample_inputs": ["2 2", "4 2", "5 1"], "sample_outputs": ["6", "13", "15"], "notes": "NoteLet's consider the example where $$$n = 2$$$, $$$k = 2$$$. Nastya should play as follows: At first she throws the stone from the second manhole to the first. Now there are two stones on the first manhole. Then she opens the second manhole and pick the coin from it. Then she goes to the first manhole, throws two stones by two moves to the second manhole and then opens the manhole and picks the coin from it. So, $$$6$$$ moves are required to win."}, "positive_code": [{"source_code": "#!/usr/bin/perl -wl\n\nuse strict;\n\nwhile( <> ){\n my( $n, $k ) = split;\n my( $min ) = sort { $a <=> $b } $n - $k, $k - 1;\n \n print $n + $n - 1 + $min + 1 + $n;\n }\n"}, {"source_code": "#!/usr/bin/perl -wl\nuse strict;\n\nwhile (<>) {\n my ($n, $k) = split;\n my ($step) = sort {$a <=> $b} ($n - $k, $k - 1);\n $step += $n - 1;\n print $step + 2 * $n + 1;\n}\n"}], "negative_code": [], "src_uid": "24b02afe8d86314ec5f75a00c72af514"} {"nl": {"description": "Everybody in Russia uses Gregorian calendar. In this calendar there are 31 days in January, 28 or 29 days in February (depending on whether the year is leap or not), 31 days in March, 30 days in April, 31 days in May, 30 in June, 31 in July, 31 in August, 30 in September, 31 in October, 30 in November, 31 in December.A year is leap in one of two cases: either its number is divisible by 4, but not divisible by 100, or is divisible by 400. For example, the following years are leap: 2000, 2004, but years 1900 and 2018 are not leap.In this problem you are given n (1 ≤ n ≤ 24) integers a1, a2, ..., an, and you have to check if these integers could be durations in days of n consecutive months, according to Gregorian calendar. Note that these months could belong to several consecutive years. In other words, check if there is a month in some year, such that its duration is a1 days, duration of the next month is a2 days, and so on.", "input_spec": "The first line contains single integer n (1 ≤ n ≤ 24) — the number of integers. The second line contains n integers a1, a2, ..., an (28 ≤ ai ≤ 31) — the numbers you are to check.", "output_spec": "If there are several consecutive months that fit the sequence, print \"YES\" (without quotes). Otherwise, print \"NO\" (without quotes). You can print each letter in arbitrary case (small or large).", "sample_inputs": ["4\n31 31 30 31", "2\n30 30", "5\n29 31 30 31 30", "3\n31 28 30", "3\n31 31 28"], "sample_outputs": ["Yes", "No", "Yes", "No", "Yes"], "notes": "NoteIn the first example the integers can denote months July, August, September and October.In the second example the answer is no, because there are no two consecutive months each having 30 days.In the third example the months are: February (leap year) — March — April – May — June.In the fourth example the number of days in the second month is 28, so this is February. March follows February and has 31 days, but not 30, so the answer is NO.In the fifth example the months are: December — January — February (non-leap year)."}, "positive_code": [{"source_code": "#!/usr/bin/perl\n\nuse warnings;\nuse strict;\n\n$\\ = $/;\n\nmy $y = join ' ',\n\tmap {\n\t\tjoin ' ', 31, $_,\n\t\t\tqq{ \n\t\t\t... в марте 31 день, в апреле 30 дней, \n\t\t\tв мае 31 день, в июне 30 дней, в июле 31 день, \n\t\t\tв августе 31 день, в сентябре 30 дней, в октябре 31 день, \n\t\t\tв ноябре 30 дней, в декабре 31 день. \n\t\t\t} =~ /\\d+/g\n\t} 28, 28, 28, 29, 28, 28;\n\nwhile(<>){\n\t$_ = <>, chomp;\n\t\n\tprint $y =~ /$_/ ? \"Yes\" : \"No\";\n\t}"}], "negative_code": [{"source_code": "#!/usr/bin/perl\n\nuse warnings;\nuse strict;\n\n$\\ = $/;\n\nmy $y = join ' ',\n\tmap {\n\t\tjoin ' ', 31, $_,\n\t\t\tqq{ \n\t\t\t... в марте 31 день, в апреле 30 дней, \n\t\t\tв мае 31 день, в июне 30 дней, в июле 31 день, \n\t\t\tв августе 31 день, в сентябре 30 дней, в октябре 31 день, \n\t\t\tв ноябре 30 дней, в декабре 31 день. \n\t\t\t} =~ /\\d+/g\n\t} 28, 28, 29, 28;\n\nwhile(<>){\n\t$_ = <>, chomp;\n\t\n\tprint $y =~ /$_/ ? \"Yes\" : \"No\";\n\t}"}, {"source_code": "#!/usr/bin/perl\n\nuse warnings;\nuse strict;\n\n$\\ = $/;\n\nmy $y = join ' ',\n\tmap {\n\t\tjoin ' ', 31, $_,\n\t\t\tqq{ \n\t\t\t... в марте 31 день, в апреле 30 дней, \n\t\t\tв мае 31 день, в июне 30 дней, в июле 31 день, \n\t\t\tв августе 31 день, в сентябре 30 дней, в октябре 31 день, \n\t\t\tв ноябре 30 дней, в декабре 31 день. \n\t\t\t} =~ /\\d+/g\n\t} 28, 28, 29, 28;\n\nprint $y;\n\nwhile(<>){\n\t$_ = <>, chomp;\n\t\n\tprint $y =~ /$_/ ? \"Yes\" : \"No\";\n\t}"}], "src_uid": "d60c8895cebcc5d0c6459238edbdb945"} {"nl": {"description": "It is a balmy spring afternoon, and Farmer John's n cows are ruminating about link-cut cacti in their stalls. The cows, labeled 1 through n, are arranged so that the i-th cow occupies the i-th stall from the left. However, Elsie, after realizing that she will forever live in the shadows beyond Bessie's limelight, has formed the Mischievous Mess Makers and is plotting to disrupt this beautiful pastoral rhythm. While Farmer John takes his k minute long nap, Elsie and the Mess Makers plan to repeatedly choose two distinct stalls and swap the cows occupying those stalls, making no more than one swap each minute.Being the meticulous pranksters that they are, the Mischievous Mess Makers would like to know the maximum messiness attainable in the k minutes that they have. We denote as pi the label of the cow in the i-th stall. The messiness of an arrangement of cows is defined as the number of pairs (i, j) such that i < j and pi > pj.", "input_spec": "The first line of the input contains two integers n and k (1 ≤ n, k ≤ 100 000) — the number of cows and the length of Farmer John's nap, respectively.", "output_spec": "Output a single integer, the maximum messiness that the Mischievous Mess Makers can achieve by performing no more than k swaps. ", "sample_inputs": ["5 2", "1 10"], "sample_outputs": ["10", "0"], "notes": "NoteIn the first sample, the Mischievous Mess Makers can swap the cows in the stalls 1 and 5 during the first minute, then the cows in stalls 2 and 4 during the second minute. This reverses the arrangement of cows, giving us a total messiness of 10.In the second sample, there is only one cow, so the maximum possible messiness is 0."}, "positive_code": [{"source_code": "chomp (my ($n, $k) = split /\\s+/, );\n\nmy $maxSwaps = $n >> 1;\n$maxSwaps = ($maxSwaps < $k) ? $maxSwaps : $k;\n\nmy $x = $maxSwaps;\n\n$x = $x * (($n << 1) - ($x << 1) - 1);\n\nprint $x;\n"}], "negative_code": [{"source_code": "chomp (my ($n, $k) = split /\\s+/, );\n\nmy $maxSwaps = $n >> 1;\n$maxSwaps = ($maxSwaps < $k) ? $maxSwaps : $k;\n\nmy $x = $maxSwaps << 1;\n\n$x++ if ($n & 1);\nprint (($x * ($x - 1)) >> 1);\n"}], "src_uid": "ea36ca0a3c336424d5b7e1b4c56947b0"} {"nl": {"description": "There are n stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them.", "input_spec": "The first line contains integer n (1 ≤ n ≤ 50) — the number of stones on the table. The next line contains string s, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to n from left to right. Then the i-th character s equals \"R\", if the i-th stone is red, \"G\", if it's green and \"B\", if it's blue.", "output_spec": "Print a single integer — the answer to the problem.", "sample_inputs": ["3\nRRG", "5\nRRRRR", "4\nBRBG"], "sample_outputs": ["1", "4", "0"], "notes": null}, "positive_code": [{"source_code": "#!/usr/bin/perl\n\nuse strict;\nuse warnings;\n\n<>;\nchomp($_ = <>);\nmy @a = split //;\nmy $res = 0;\nmy $pre = shift @a;\nwhile (@a) {\n my $cur = shift @a;\n ++$res if $pre eq $cur;\n $pre = $cur;\n}\nprint \"$res\\n\";\n"}, {"source_code": "print <>-(()=<>=~/(.)\\1*/g)"}, {"source_code": "print <>-(()=<>=~/(.)\\1*/g)\n"}, {"source_code": "print <>-(()=<>=~/(.)\\1*/g)\n"}, {"source_code": "my $l = <>;\nmy @str = split \"\", <>;\nmy $ans = 0;\nfor (1..$l-1) {\n $ans++ if ($str[$_] eq $str[$_ - 1]);\n}\nprint $ans . \"\\n\";\n"}, {"source_code": "print <>-(()=<>=~/(.)\\1*/g)"}, {"source_code": "print <>-(()=<>=~/(.)\\1*/g)\n"}, {"source_code": "my $n = ;\nmy $s = ;\nmy $c = 0;\nchomp($s);\nwhile(index($s, \"RR\") != -1) {\n substr($s, index($s, \"RR\"), 2, \"R\");\n $c++;\n}\nwhile(index($s, \"GG\") != -1) {\n substr($s, index($s, \"GG\"), 2, \"G\");\n $c++;\n}\nwhile(index($s, \"BB\") != -1) {\n substr($s, index($s, \"BB\"), 2, \"B\");\n $c++;\n}\nprint $c;"}, {"source_code": "print <>-(()=<>=~/(.)\\1*/g)\n"}, {"source_code": "print <>-(()=<>=~/(.)\\1*/g)"}, {"source_code": "#!/usr/bin/perl\n# your code goes here\nuse v5.10;\n\nchomp($len = <>);\nchomp($line = <>);\n@a = split //, $line;\n$i = 0;\n$ans = 0;\nwhile ($i < $len) {\n\t$j = $i++;\n\twhile ($i<$len && $a[$i] eq $a[$j]) {\n\t\t++$i;\n\t}\n\t$ans += $i-$j-1;\n}\nsay $ans;"}, {"source_code": "use strict;\nuse warnings;\n\nmy $stones = <>;\nchomp($stones);\n\nmy $in = <>;\nchomp($in);\nmy @s = split('', $in);\n\n\nmy $n=0;\n\n# r b g\n# if ff or bb or gg we have to remove one stone\n# if this stone==next stone, remove this stone. move to next....\n\nfor (my $i=0; $i<$stones-1; $i++) {\n if ($s[$i] eq $s[$i+1]) {\n $n++;\n }\n}\n\nprint $n;\n"}, {"source_code": "my $n = ;\nmy $s = ;\nmy $c = 0;\n\nmy $a = 'a';\nmy $b = 'b';\n# if ($a eq $a){\n\t# print(\"YES\");\n\t# }\nmy @arr = split //, $s;\n\nmy $t = 0;\nfor(; $t < $n - 1; $t++)\n{\n\tif($arr[$t] eq $arr[$t+1]){\n\t\t$c++;\n\t}\n}\nprint($c);\n# my $c (split //, $s) {\n # if()\n# }"}, {"source_code": "use strict;\nuse warnings;\n\n<>;\n$_ = <>;\nchomp;\nmy @l = split '';\nmy $res = 0;\nfor my $i (1..@l-1) {\n $res++ if ($l[$i] eq $l[$i-1]);\n}\nprint \"$res\\n\";\n"}, {"source_code": "#!/usr/bin/perl\nuse strict;\nuse warnings;\n\n\nchomp(my $n = );\nchomp(my $s = );\n\nmy @chrs = split(\"\", $s);\nmy $i = 0;\nmy $cnt = 0;\nwhile ($i < ($n - 1)) {\n if ($chrs[$i] eq $chrs[$i + 1]) {\n # ;\n splice(@chrs, $i, 1);\n $cnt += 1;\n $n -= 1;\n } else {\n $i += 1;\n }\n}\nprint $cnt;\n# print $n;\n# print $s;"}, {"source_code": "#!/usr/bin/perl\n\n$n=;\n@str = split(//, );\n$a=0;\nfor($i = 0; $i < $n; $i++)\n{\n if($str[$i] eq $str[$i + 1])\n {\n $a = $a + 1;\n }\n}\nprint \"$a\";"}, {"source_code": "print <>-(()=<>=~/(.)\\1*/g)\n"}, {"source_code": ";\n@str = split(//, );\n$count = 0;\n\nfor($i = 0; $i < $#str; $i++)\n{\n if($str[$i] eq $str[$i + 1])\n {\n ++$count;\n }\n}\nprint STDOUT $count;"}, {"source_code": "; chomp($_ = ); my ($last, $res)=(\"\", 0); for(split(\"\")){ if( $last eq $_ ){ $res += 1 }else{ $last = $_ } } print \"$res\\n\""}, {"source_code": "<>; $i = 0; $_ = <>;\nwhile (/(.)\\g{-1}/g) {\n --pos($_); ++$i\n}\nprint $i"}, {"source_code": "$n = <>;\n@a = split '', <>;\n\n$min = 0;\nfor ($i = 1; $i < $n; ++$i) {\n if ($a[$last] eq $a[$i]) { ++$min; }\n else { $last = $i; }\n}\nprint $min;"}, {"source_code": "#!/bin/perl\n\n$n = ;\n$s = ;\nchomp $s;\n\n$s =~ s/R+/c/g;\n$s =~ s/G+/c/g;\n$s =~ s/B+/c/g;\n\nprint ( $n - length $s );\n"}, {"source_code": "print <>-(()=<>=~/(.)\\1*/g)\n"}, {"source_code": "#!/usr/bin/perl\nuse strict; use warnings;\n\nmy $n = ; $_ = ;\nforeach my $c (qw[R G B]) { s/$c+/$c/g }\nprint $n + 1 - length . \"\\n\";\n"}, {"source_code": "$n = <>;\n$ans = 0;\n@str = split \"\", <>;\nfor (1..$n - 1) {\n\tif ($str[$_] eq $str[$_ - 1]) {\n\t\t$ans++;\n\t}\n}\nprint ($ans);"}, {"source_code": "print <>-(()=<>=~/(.)\\1*/g)\n"}, {"source_code": "print <>-(()=<>=~/(.)\\1*/g)"}, {"source_code": "print <>-(()=<>=~/(.)\\1*/g)\n"}], "negative_code": [{"source_code": "my $n = ;\nmy $s = ;\nmy $c = 0;\n\nmy $a = 'a';\nmy $b = 'b';\n# if ($a eq $a){\n\t# print(\"YES\");\n\t# }\n\n\nmy $t = 0;\nfor(; $t < $n - 1; $t++)\n{\n\tif($s[$t] eq $s[$t+1]){\n\t\t$c++;\n\t}\n}\nprint($c);\n# my $c (split //, $s) {\n # if()\n# }"}, {"source_code": "my $n = ;\nmy $s = ;\nmy $c = 0;\n\nmy $a = 'a';\nmy $b = 'b';\n# if ($a eq $a){\n\t# print(\"YES\");\n\t# }\nmy @arr = split //, $s;\nprint(join(\" \", @arr));\nmy $t = 0;\nfor(; $t < $n - 1; $t++)\n{\n\tif($arr[$t] eq $arr[$t+1]){\n\t\t$c++;\n\t}\n}\nprint($c);\n# my $c (split //, $s) {\n # if()\n# }"}, {"source_code": "$n = <>;\n@a = split '', <>;\nfor ($i = 1; $i < $n; ++$i) {\n if ($a[$last] eq $a[$i]) { ++$min; }\n else { $last = $i; }\n}\nprint $min;"}, {"source_code": "#!/bin/perl\n\n$n = ;\n$s = ;\nchomp $s;\n\n$b = $s;\n\n$s =~ s/R+/c/;\n$s =~ s/G+/c/;\n$s =~ s/B+/c/;\n\nprint ( ( length $b ) - ( length $s ) );\n"}], "src_uid": "d561436e2ddc9074b98ebbe49b9e27b8"} {"nl": {"description": "Gerald is setting the New Year table. The table has the form of a circle; its radius equals R. Gerald invited many guests and is concerned whether the table has enough space for plates for all those guests. Consider all plates to be round and have the same radii that equal r. Each plate must be completely inside the table and must touch the edge of the table. Of course, the plates must not intersect, but they can touch each other. Help Gerald determine whether the table is large enough for n plates.", "input_spec": "The first line contains three integers n, R and r (1 ≤ n ≤ 100, 1 ≤ r, R ≤ 1000) — the number of plates, the radius of the table and the plates' radius.", "output_spec": "Print \"YES\" (without the quotes) if it is possible to place n plates on the table by the rules given above. If it is impossible, print \"NO\". Remember, that each plate must touch the edge of the table. ", "sample_inputs": ["4 10 4", "5 10 4", "1 10 10"], "sample_outputs": ["YES", "NO", "YES"], "notes": "NoteThe possible arrangement of the plates for the first sample is: "}, "positive_code": [{"source_code": "#!/usr/bin/perl\n\n$PI=3.14159265358979323846;\n$MOD=1000000007;\n\nwhile (<>=~/ (\\d+) /){\n\n# <>=~/ /;\n# <>=~/ (\\d+) /;\n# <>=~/ (\\d+) (\\d+) /;\n\n\n$`-1 or (print ($'>$1?\"NO\":\"YES\"));\n$`-1 or last;\nprint (($'+$'/sin($PI/$`)>$1)?\"NO\":\"YES\")\n\n\n}\n\n#***********SUBS************\n\nsub num {$a <=> $b}\nsub num_rev {$b <=> $a}\nsub rev {$b cmp $a}\n\nsub p{print}\nsub n{print \"\\n\"}\nsub pn{p,n}\nsub pn_mas {pn for @_}\n\nsub fact{\n\tmy $i= shift; my $j= 1;\n\t$j*=$i-- while $i;\n\treturn $j\n}\n\n# Transpose \"charbox\"\nsub trans{\n\tmy @t=(); my $i=0; \n\t$i=0, s/./$t[$i++].=$&/eg for @_;\n\treturn @t\n}\n\nsub rotL{\n\tmy @t=(); my $i=0; my $j;\n\tfor (@_){\n\t\t$i=0, $j=length; $t[$i++].=chop while $j--\n\t}\n\treturn @t\n}\n\nsub rotR{\n my @m=@_; chomp @m; my @t=();\n\tmy $i= length $m[0];\n\twhile ($i--){\n\t\t$t[$i]=~s/^/chop/e for @m\n\t}\nreturn @t\n}\n\nsub revlines{\n\t$_=reverse $_ for @_;\n\treturn @_\n}\n\n# Transpose \"value sets\" ## slow?\nsub trans_s{\n\tmy @t=(); my $j;\n\t$j=0, s/\\S+/($t[$j++].=\"$& \")?$&:$&/eg for @_;\n\tchop @t;\nreturn @t\n}\n\n# rotL_s\n# rotR_s\n\n# slow?\nsub revlines_s{\n\t$_=join\" \", reverse split/\\s+/ \tfor @_;\n\treturn @_\n}\n\nsub div{\n my ($n, $k)=@_;\nreturn ($n - $n % $k) / $k\n}\n \nsub uniq{\n\tmy @m=sort @_; my @u;\n\tpush @u, my $i=shift @m;\n\t$i eq $_ or push @u, $i=$_ for @m;\nreturn @u\n}\n \nsub max{\n my $max=shift;\n $max<$_ and $max=$_ for @_;\nreturn $max\n}\n \nsub min{\n my $min=shift;\n $min>$_ and $min=$_ for @_;\nreturn $min\n}\n\n# count (kas_ieskoma, masyvas)\nsub count{\n my $i=0;\n $_ eq $_[0] and $i++ for @_;\nreturn --$i\n}\n"}], "negative_code": [], "src_uid": "2fedbfccd893cde8f2fab2b5bf6fb6f6"} {"nl": {"description": "Gennady owns a small hotel in the countryside where he lives a peaceful life. He loves to take long walks, watch sunsets and play cards with tourists staying in his hotel. His favorite game is called \"Mau-Mau\".To play Mau-Mau, you need a pack of $$$52$$$ cards. Each card has a suit (Diamonds — D, Clubs — C, Spades — S, or Hearts — H), and a rank (2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, or A).At the start of the game, there is one card on the table and you have five cards in your hand. You can play a card from your hand if and only if it has the same rank or the same suit as the card on the table.In order to check if you'd be a good playing partner, Gennady has prepared a task for you. Given the card on the table and five cards in your hand, check if you can play at least one card.", "input_spec": "The first line of the input contains one string which describes the card on the table. The second line contains five strings which describe the cards in your hand. Each string is two characters long. The first character denotes the rank and belongs to the set $$$\\{{\\tt 2}, {\\tt 3}, {\\tt 4}, {\\tt 5}, {\\tt 6}, {\\tt 7}, {\\tt 8}, {\\tt 9}, {\\tt T}, {\\tt J}, {\\tt Q}, {\\tt K}, {\\tt A}\\}$$$. The second character denotes the suit and belongs to the set $$$\\{{\\tt D}, {\\tt C}, {\\tt S}, {\\tt H}\\}$$$. All the cards in the input are different.", "output_spec": "If it is possible to play a card from your hand, print one word \"YES\". Otherwise, print \"NO\". You can print each letter in any case (upper or lower).", "sample_inputs": ["AS\n2H 4C TH JH AD", "2H\n3D 4C AC KD AS", "4D\nAS AC AD AH 5H"], "sample_outputs": ["YES", "NO", "YES"], "notes": "NoteIn the first example, there is an Ace of Spades (AS) on the table. You can play an Ace of Diamonds (AD) because both of them are Aces.In the second example, you cannot play any card.In the third example, you can play an Ace of Diamonds (AD) because it has the same suit as a Four of Diamonds (4D), which lies on the table."}, "positive_code": [{"source_code": "#!/usr/bin/env perl\n \nuse strict;\nuse warnings;\nuse feature qw/ say /;\n \n# essential\nmy @tokens = ();\n\nsub read_line {\n chomp (my $line = );\n return $line;\n}\n \nsub read_token {\n @tokens = split q{ }, read_line() if @tokens == 0;\n return shift @tokens;\n}\n \nsub min {\n my @numbers = @_;\n my $min = shift @numbers;\n for ( @numbers ) {\n $min = $min<$_ ? $min : $_;\n }\n return $min;\n}\n \nsub max {\n my @numbers = @_;\n my $max = shift @numbers;\n for ( @numbers ) {\n $max = $max > $_ ? $max : $_;\n }\n return $max;\n}\n \nsub sum {\n my @numbers = @_;\n my $sum = 0;\n for (@numbers) {\n $sum += $_;\n }\n return $sum;\n}\n\nsub remainder {\n my ($dividend, $divisor) = @_;\n}\n\n# solve\n\nmy $card_on_table = read_token;\n\nmy ($suit, $rank) = split q{}, $card_on_table;\n\nmy @cards_on_hand = split q{ }, read_line;\n\nmy $flag = 0;\n\nfor (@cards_on_hand) {\n my ($s, $r) = split q{}, $_;\n if ( $s eq $suit || $r eq $rank ) {\n $flag = 1;\n last;\n }\n}\n\nif ($flag) {\n say 'YES';\n}\nelse {\n say 'NO';\n}\n\n"}], "negative_code": [], "src_uid": "699444eb6366ad12bc77e7ac2602d74b"} {"nl": {"description": "Karen is getting ready for a new school day! It is currently hh:mm, given in a 24-hour format. As you know, Karen loves palindromes, and she believes that it is good luck to wake up when the time is a palindrome.What is the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome?Remember that a palindrome is a string that reads the same forwards and backwards. For instance, 05:39 is not a palindrome, because 05:39 backwards is 93:50. On the other hand, 05:50 is a palindrome, because 05:50 backwards is 05:50.", "input_spec": "The first and only line of input contains a single string in the format hh:mm (00 ≤  hh  ≤ 23, 00 ≤  mm  ≤ 59).", "output_spec": "Output a single integer on a line by itself, the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome.", "sample_inputs": ["05:39", "13:31", "23:59"], "sample_outputs": ["11", "0", "1"], "notes": "NoteIn the first test case, the minimum number of minutes Karen should sleep for is 11. She can wake up at 05:50, when the time is a palindrome.In the second test case, Karen can wake up immediately, as the current time, 13:31, is already a palindrome.In the third test case, the minimum number of minutes Karen should sleep for is 1 minute. She can wake up at 00:00, when the time is a palindrome."}, "positive_code": [{"source_code": "sub checkPl\n{\n my ($h, $m) = @_;\n \n if($h<=9)\n {\n $h=\"0\".$h;\n }\n if($m<=9)\n {\n $m=\"0\".$m;\n }\n $h=scalar reverse $h;\n if($h==$m)\n {\n return \"1\";\n }\n return \"0\";\n}\n$str=;\nmy @chars = split(\"\", $str);\nif($chars[0]!='0')\n {$h=$chars[0];}\n$h.=$chars[1];\nif($chars[3]!='0')\n {$m=$chars[3];}\n$m.=$chars[4];\n$steps=0;\nwhile(1)\n{\n if(checkPl($h,$m)==\"1\")\n {\n print $steps;\n last; \n }\n $steps++;\n $m++;\n if($m==60)\n {\n $m=0;\n $h++;\n }\n if($h==24)\n { $h=0;}\n}\n"}], "negative_code": [{"source_code": "sub checkPl\n{\n my ($h, $m) = @_;\n \n $h=scalar reverse $h;\n if($h==$m)\n {\n return \"1\";\n }\n return \"0\";\n}\n$str=;\nmy @chars = split(\"\", $str);\n$h=$chars[0].$chars[1];\n$m=$chars[3].$chars[4];\n$steps=0;\nwhile(1)\n{\n if(checkPl($h,$m)==\"1\")\n {\n print $steps;\n last; \n }\n $steps++;\n $m++;\n if($m==60)\n {\n $m=0;\n $h++;\n }\n if($h==24)\n { $h=0;}\n}\n"}], "src_uid": "3ad3b8b700f6f34b3a53fdb63af351a5"} {"nl": {"description": "You want to arrange n integers a1, a2, ..., an in some order in a row. Let's define the value of an arrangement as the sum of differences between all pairs of adjacent integers.More formally, let's denote some arrangement as a sequence of integers x1, x2, ..., xn, where sequence x is a permutation of sequence a. The value of such an arrangement is (x1 - x2) + (x2 - x3) + ... + (xn - 1 - xn).Find the largest possible value of an arrangement. Then, output the lexicographically smallest sequence x that corresponds to an arrangement of the largest possible value.", "input_spec": "The first line of the input contains integer n (2 ≤ n ≤ 100). The second line contains n space-separated integers a1, a2, ..., an (|ai| ≤ 1000).", "output_spec": "Print the required sequence x1, x2, ..., xn. Sequence x should be the lexicographically smallest permutation of a that corresponds to an arrangement of the largest possible value.", "sample_inputs": ["5\n100 -100 50 0 -50"], "sample_outputs": ["100 -50 0 50 -100"], "notes": "NoteIn the sample test case, the value of the output arrangement is (100 - ( - 50)) + (( - 50) - 0) + (0 - 50) + (50 - ( - 100)) = 200. No other arrangement has a larger value, and among all arrangements with the value of 200, the output arrangement is the lexicographically smallest one.Sequence x1, x2, ... , xp is lexicographically smaller than sequence y1, y2, ... , yp if there exists an integer r (0 ≤ r < p) such that x1 = y1, x2 = y2, ... , xr = yr and xr + 1 < yr + 1."}, "positive_code": [{"source_code": "$n = <>;\n@a = sort {$a <=> $b} split ' ', <>;\nprint \"@a[-1, 1..$n-2, 0]\";\n\n"}, {"source_code": "$n = <>;\n@a = sort {$a <=> $b} split ' ', <>;\nprint \"@a[-1, 1..$n-2, 0]\";\n\n"}, {"source_code": "$n = <>;\n@a = sort {$a <=> $b} split ' ', <>;\nprint \"@a[-1, 1..$n-2, 0]\";\n"}, {"source_code": "$n = <>;\n@a = sort {$a <=> $b} split ' ', <>;\nprint \"@a[-1, 1..$n-2, 0]\";\n\n"}, {"source_code": "$n = <>;\n@a = sort {$a <=> $b} split ' ', <>;\nprint \"@a[-1, 1..$n-2, 0]\";\n\n"}, {"source_code": "chomp($n=<>);\nchomp($_=<>);\n@a = split / /;\n@a = sort {$a <=> $b} @a;\n($a[0], $a[-1]) = ($a[-1], $a[0]);\nprint \"@a\\n\";"}, {"source_code": "$n = <>;\n@a = sort {$a <=> $b} split ' ', <>;\nprint \"@a[-1, 1..$n-2, 0]\";\n\n"}, {"source_code": "#!/usr/bin/perl -w\nuse 5.010;\n\nsub Solve {\n while (($idx, $val) = each @_) {\n $_[0] < $val && (($_[0], $_[$idx]) = ($_[$idx], $_[0]));\n $_[-1] > $val && (($_[-1], $_[$idx]) = ($_[$idx], $_[-1]));\n }\n @center = sort {$a <=> $b} @_[1..$_-2];\n say \"$_[0] @center $_[-1]\"\n}\n\nwhile (<>) {\n @line = split /\\s+/, <>;\n Solve(@line);\n}\n"}, {"source_code": "$n = <>;\n@a = sort {$a <=> $b} split ' ', <>;\nprint \"@a[-1, 1..$n-2, 0]\";\n"}, {"source_code": "$n = <>;\n@a = sort { $a <=> $b } split ' ', <>;\nprint join ' ', @a[-1, 1..$n-2, 0];\n"}, {"source_code": "$n = <>;\n@a = sort {$a <=> $b} split ' ', <>;\nprint \"@a[-1, 1..$n-2, 0]\";\n\n"}, {"source_code": "$n = <>;\n@a = sort {$a <=> $b} split ' ', <>;\nprint \"@a[-1, 1..$n-2, 0]\";\n\n"}, {"source_code": "#!/usr/bin/perl\n\n$PI=3.14159265358979323846;\n$MOD=1000000007;\n\n# <>=~/ /;\n# <>=~/ (\\d+) /;\n# <>=~/ (\\d+) (\\d+) /;\n\n<>;\n@_=split/ /,<>;\nchomp (@_);\n@_= sort num_rev @_;\n$first = shift @_;\n$last = pop @_;\n@_= reverse @_;\nunshift @_, $first; \npush @_, $last;\nprint \"@_\"; \n\n#***********SUBS************\n\nsub num {$a <=> $b}\nsub num_rev {$b <=> $a}\nsub rev {$b cmp $a}\n\nsub p{print}\nsub n{print \"\\n\"}\nsub pn{p,n}\nsub pn_mas {pn for @_}\n\n# Transpose \"charbox\"\nsub transpose{\n $i=@m=@_;\n chomp @m;\n while ($i--){\n $t[$i]=~s/$/chop/e for @m\n }\nreturn @t\n}\n\n# Transpose \"value sets\"\nsub transpose_space{\n my @t;\n for (@_){\n my $j=0;\n s/\\d+/($t[$j++].=\"$& \")?$&:$&/eg;\n }\n chop @t;\nreturn @t\n}\n\nsub div{\n my ($n, $k)=@_;\nreturn ($n - $n % $k) / $k\n}\n \nsub uniq{\n my @m=sort @_;\n push @u, my $i=shift @m;\n for (@m){\n $i eq $_ or push @u, $_;\n $i=$_;\n }\nreturn @u\n}\n \nsub max{\n my $max=shift;\n $max<$_ and $max=$_ for @_;\nreturn $max\n}\n \nsub min{\n my $min=shift;\n $min>$_ and $min=$_ for @_;\nreturn $min\n}\n\n# count (kas_ieskoma, masyvas)\nsub count{\n my $i=0;\n $_ eq $_[0] and $i++ for @_;\nreturn --$i\n}"}, {"source_code": "$n = <>;\n@a = sort {$a <=> $b} split ' ', <>;\nprint \"@a[-1, 1..$n-2, 0]\";\n\n"}], "negative_code": [{"source_code": "#!/usr/bin/perl\n\n$PI=3.14159265358979323846;\n$MOD=1000000007;\n\n# <>=~/ /;\n# <>=~/ (\\d+) /;\n# <>=~/ (\\d+) (\\d+) /;\n\n<>;\n@_=split/ /,<>;\nchomp (@_);\n@_= sort num_rev @_;\n$first = shift @_;\n$last = pop @_;\n@_= sort @_;\nunshift @_, $first; \npush @_, $last;\nprint \"@_\\n\"; \n\n#***********SUBS************\n\nsub num {$a <=> $b}\nsub num_rev {$b <=> $a}\nsub rev {$b cmp $a}\n\nsub p{print}\nsub n{print \"\\n\"}\nsub pn{p,n}\nsub pn_mas {pn for @_}\n\n# Transpose \"charbox\"\nsub transpose{\n $i=@m=@_;\n chomp @m;\n while ($i--){\n $t[$i]=~s/$/chop/e for @m\n }\nreturn @t\n}\n\n# Transpose \"value sets\"\nsub transpose_space{\n my @t;\n for (@_){\n my $j=0;\n s/\\d+/($t[$j++].=\"$& \")?$&:$&/eg;\n }\n chop @t;\nreturn @t\n}\n\nsub div{\n my ($n, $k)=@_;\nreturn ($n - $n % $k) / $k\n}\n \nsub uniq{\n my @m=sort @_;\n push @u, my $i=shift @m;\n for (@m){\n $i eq $_ or push @u, $_;\n $i=$_;\n }\nreturn @u\n}\n \nsub max{\n my $max=shift;\n $max<$_ and $max=$_ for @_;\nreturn $max\n}\n \nsub min{\n my $min=shift;\n $min>$_ and $min=$_ for @_;\nreturn $min\n}\n\n# count (kas_ieskoma, masyvas)\nsub count{\n my $i=0;\n $_ eq $_[0] and $i++ for @_;\nreturn --$i\n}"}, {"source_code": "#!/usr/bin/perl\n\n$PI=3.14159265358979323846;\n$MOD=1000000007;\n\n# <>=~/ /;\n# <>=~/ (\\d+) /;\n# <>=~/ (\\d+) (\\d+) /;\n\n<>;\n@_=split/ /,<>;\n@_= sort num_rev @_;\n$first = shift @_;\n$last = pop @_;\n@_= sort @_;\nunshift @_, $first; \npush @_, $last;\nprint \"@_\"; \n\n#***********SUBS************\n\nsub num {$a <=> $b}\nsub num_rev {$b <=> $a}\nsub rev {$b cmp $a}\n\nsub p{print}\nsub n{print \"\\n\"}\nsub pn{p,n}\nsub pn_mas {pn for @_}\n\n# Transpose \"charbox\"\nsub transpose{\n $i=@m=@_;\n chomp @m;\n while ($i--){\n $t[$i]=~s/$/chop/e for @m\n }\nreturn @t\n}\n\n# Transpose \"value sets\"\nsub transpose_space{\n my @t;\n for (@_){\n my $j=0;\n s/\\d+/($t[$j++].=\"$& \")?$&:$&/eg;\n }\n chop @t;\nreturn @t\n}\n\nsub div{\n my ($n, $k)=@_;\nreturn ($n - $n % $k) / $k\n}\n \nsub uniq{\n my @m=sort @_;\n push @u, my $i=shift @m;\n for (@m){\n $i eq $_ or push @u, $_;\n $i=$_;\n }\nreturn @u\n}\n \nsub max{\n my $max=shift;\n $max<$_ and $max=$_ for @_;\nreturn $max\n}\n \nsub min{\n my $min=shift;\n $min>$_ and $min=$_ for @_;\nreturn $min\n}\n\n# count (kas_ieskoma, masyvas)\nsub count{\n my $i=0;\n $_ eq $_[0] and $i++ for @_;\nreturn --$i\n}"}, {"source_code": "#!/usr/bin/perl\n\n$PI=3.14159265358979323846;\n$MOD=1000000007;\n\n# <>=~/ /;\n# <>=~/ (\\d+) /;\n# <>=~/ (\\d+) (\\d+) /;\n\n<>;\n@_=split/ /,<>;\n@_= sort num_rev @_;\n$first = shift @_;\n$last = pop @_;\n@_= sort @_;\nprint $first, \" @_ \", $last;\n\n#***********SUBS************\n\nsub num {$a <=> $b}\nsub num_rev {$b <=> $a}\nsub rev {$b cmp $a}\n\nsub p{print}\nsub n{print \"\\n\"}\nsub pn{p,n}\nsub pn_mas {pn for @_}\n\n# Transpose \"charbox\"\nsub transpose{\n $i=@m=@_;\n chomp @m;\n while ($i--){\n $t[$i]=~s/$/chop/e for @m\n }\nreturn @t\n}\n\n# Transpose \"value sets\"\nsub transpose_space{\n my @t;\n for (@_){\n my $j=0;\n s/\\d+/($t[$j++].=\"$& \")?$&:$&/eg;\n }\n chop @t;\nreturn @t\n}\n\nsub div{\n my ($n, $k)=@_;\nreturn ($n - $n % $k) / $k\n}\n \nsub uniq{\n my @m=sort @_;\n push @u, my $i=shift @m;\n for (@m){\n $i eq $_ or push @u, $_;\n $i=$_;\n }\nreturn @u\n}\n \nsub max{\n my $max=shift;\n $max<$_ and $max=$_ for @_;\nreturn $max\n}\n \nsub min{\n my $min=shift;\n $min>$_ and $min=$_ for @_;\nreturn $min\n}\n\n# count (kas_ieskoma, masyvas)\nsub count{\n my $i=0;\n $_ eq $_[0] and $i++ for @_;\nreturn --$i\n}"}, {"source_code": "#!/usr/bin/perl\n\n$PI=3.14159265358979323846;\n$MOD=1000000007;\n\n# <>=~/ /;\n# <>=~/ (\\d+) /;\n# <>=~/ (\\d+) (\\d+) /;\n\n<>;\n@_=split/ /,<>;\nchomp (@_);\n@_= sort num_rev @_;\n$first = shift @_;\n$last = pop @_;\n@_= sort @_;\nunshift @_, $first; \npush @_, $last;\nprint \"@_\"; \n\n#***********SUBS************\n\nsub num {$a <=> $b}\nsub num_rev {$b <=> $a}\nsub rev {$b cmp $a}\n\nsub p{print}\nsub n{print \"\\n\"}\nsub pn{p,n}\nsub pn_mas {pn for @_}\n\n# Transpose \"charbox\"\nsub transpose{\n $i=@m=@_;\n chomp @m;\n while ($i--){\n $t[$i]=~s/$/chop/e for @m\n }\nreturn @t\n}\n\n# Transpose \"value sets\"\nsub transpose_space{\n my @t;\n for (@_){\n my $j=0;\n s/\\d+/($t[$j++].=\"$& \")?$&:$&/eg;\n }\n chop @t;\nreturn @t\n}\n\nsub div{\n my ($n, $k)=@_;\nreturn ($n - $n % $k) / $k\n}\n \nsub uniq{\n my @m=sort @_;\n push @u, my $i=shift @m;\n for (@m){\n $i eq $_ or push @u, $_;\n $i=$_;\n }\nreturn @u\n}\n \nsub max{\n my $max=shift;\n $max<$_ and $max=$_ for @_;\nreturn $max\n}\n \nsub min{\n my $min=shift;\n $min>$_ and $min=$_ for @_;\nreturn $min\n}\n\n# count (kas_ieskoma, masyvas)\nsub count{\n my $i=0;\n $_ eq $_[0] and $i++ for @_;\nreturn --$i\n}"}], "src_uid": "4408eba2c5c0693e6b70bdcbe2dda2f4"} {"nl": {"description": "When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word \"tma\" (which now means \"too much to be counted\") used to stand for a thousand and \"tma tmyschaya\" (which literally means \"the tma of tmas\") used to stand for a million.Petya wanted to modernize the words we use for numbers and invented a word petricium that represents number k. Moreover, petricium la petricium stands for number k2, petricium la petricium la petricium stands for k3 and so on. All numbers of this form are called petriciumus cifera, and the number's importance is the number of articles la in its title.Petya's invention brought on a challenge that needed to be solved quickly: does some number l belong to the set petriciumus cifera? As Petya is a very busy schoolboy he needs to automate the process, he asked you to solve it.", "input_spec": "The first input line contains integer number k, the second line contains integer number l (2 ≤ k, l ≤ 231 - 1).", "output_spec": "You should print in the first line of the output \"YES\", if the number belongs to the set petriciumus cifera and otherwise print \"NO\". If the number belongs to the set, then print on the seconds line the only number — the importance of number l.", "sample_inputs": ["5\n25", "3\n8"], "sample_outputs": ["YES\n1", "NO"], "notes": null}, "positive_code": [{"source_code": "#!/usr/bin/perl\n\nuse bignum;\n$a=<>;\n$b=<>;\n$x=0;\n$s=0;\n$c=0;\n$m=-1;\nwhile ($m<$b)\n{\n$m=$a**$c;\nif ($m==$b)\n{$s=1;\n$x=$c;}\n$c++;\n}\nif ($s eq 1)\n{\nprint\"YES\\n\";\nprint $x-1;\n}\nelse\n{\nprint \"NO\";\n}"}, {"source_code": "use bignum;\n$a=<>;\n$b=<>;\n$i=$a;\n$c=0;\nwhile($a<$b){\n$a*=$i, $c++;\n}\nprint $a-$b?\"NO\":\"YES\\n$c\""}], "negative_code": [{"source_code": "#!/usr/bin/perl\n\nuse bignum;\n$a=<>;\n$b=<>;\n$x=0;\n$s=0;\n$c=0;\n$m=-1;\nwhile ($m<$b)\n{\n$m=$a**$c;\nif ($m==$b)\n{$s=1;\n$x=$c;}\n$c++;\n}\nif ($s eq 1)\n{\nprint\"YES\\n\";\nprint $x-1;\n}\nelse\n{\nprint \"No\";\n}"}, {"source_code": "use bignum;\n$a=<>;\n$b=<>;\n$i=$a;\nwhile($a<$b){\n$a*=$i, $c++;\n}\nprint $a-$b?\"NO\":\"YES\\n$c\""}], "src_uid": "8ce89b754aa4080e7c3b2c3b10f4be46"} {"nl": {"description": "Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by making single turn or not. The rules of tic-tac-toe on the 4 × 4 field are as follows. Before the first turn all the field cells are empty. The two players take turns placing their signs into empty cells (the first player places Xs, the second player places Os). The player who places Xs goes first, the another one goes second. The winner is the player who first gets three of his signs in a row next to each other (horizontal, vertical or diagonal).", "input_spec": "The tic-tac-toe position is given in four lines. Each of these lines contains four characters. Each character is '.' (empty cell), 'x' (lowercase English letter x), or 'o' (lowercase English letter o). It is guaranteed that the position is reachable playing tic-tac-toe, and it is Ilya's turn now (in particular, it means that the game is not finished). It is possible that all the cells are empty, it means that the friends left without making single turn.", "output_spec": "Print single line: \"YES\" in case Ilya could have won by making single turn, and \"NO\" otherwise.", "sample_inputs": ["xx..\n.oo.\nx...\noox.", "x.ox\nox..\nx.o.\noo.x", "x..x\n..oo\no...\nx.xo", "o.x.\no...\n.x..\nooxx"], "sample_outputs": ["YES", "NO", "YES", "NO"], "notes": "NoteIn the first example Ilya had two winning moves: to the empty cell in the left column and to the leftmost empty cell in the first row.In the second example it wasn't possible to win by making single turn.In the third example Ilya could have won by placing X in the last row between two existing Xs.In the fourth example it wasn't possible to win by making single turn."}, "positive_code": [{"source_code": "$,=\" \";\nmy @GRID;\nfor(1..4)\n{\n my $t=<>;\nchomp($t);\npush(@GRID,$t);\n}\n\nif(checkRow() or checkCol() or CheckDiag())\n{\n print \"YES\\n\";\n}\nelse\n{\n print \"NO\\n\";\n}\n\nsub checkRow\n{\nfor(0..3)\n{\nif($GRID[$_] =~ 'xx\\.' or $GRID[$_] =~ '\\\\.xx' or $GRID[$_] =~ 'x\\\\.x')\n{\n return 1;\n}\n}\n}\n\nsub checkCol\n{\nfor my $i (0..3)\n{\nmy $k=\"\";\nfor(0..3)\n{\n$k.=substr($GRID[$_],$i,1);\n}\n#print $k, \"\\n\";\nif($k =~ 'xx\\.' or $k =~ '\\\\.xx' or $k =~ 'x\\\\.x')\n{\n return 1;\n}\n}\n}\n\nsub CheckDiag\n{\nmy @D1=([0,0],[1,1],[2,2],[3,3]);\nmy @D2=([1,0],[2,1],[3,2]);\nmy @D3=([0,1],[1,2],[2,3]);\nmy @D4=([2,0],[1,1],[0,2]);\nmy @D5=([3,0],[2,1],[1,2],[0,3]);\nmy @D6=([3,1],[2,2],[1,3]);\nmy $k=\"\";\nfor(@D1)\n{\n$k.=substr($GRID[$_->[0]],$_->[1],1);\n#print $k, \"\\n\";\n}\nif($k =~ 'xx\\.' or $k =~ '\\.xx' or $k =~ 'x\\\\.x')\n{\n return 1;\n}\n$k=\"\";\nfor(@D2)\n{\n$k.=substr($GRID[$_->[0]],$_->[1],1);\n}\nif($k =~ 'xx\\.' or $k =~ '\\.xx' or $k =~ 'x\\\\.x')\n{\n return 1;\n}\n$k=\"\";\nfor(@D3)\n{\n$k.=substr($GRID[$_->[0]],$_->[1],1);\n}\nif($k =~ 'xx\\.' or $k =~ '\\.xx' or $k =~ 'x\\\\.x')\n{\n return 1;\n}\n$k=\"\";\nfor(@D4)\n{\n$k.=substr($GRID[$_->[0]],$_->[1],1);\n}\nif($k =~ 'xx\\.' or $k =~ '\\.xx' or $k =~ 'x\\\\.x')\n{\n return 1;\n}\n$k=\"\";\nfor(@D5)\n{\n$k.=substr($GRID[$_->[0]],$_->[1],1);\n}\nif($k =~ 'xx\\.' or $k =~ '\\.xx' or $k =~ 'x\\\\.x')\n{\n return 1;\n}\n$k=\"\";\nfor(@D6)\n{\n$k.=substr($GRID[$_->[0]],$_->[1],1);\n}\nif($k =~ 'xx\\.' or $k =~ '\\.xx' or $k =~ 'x\\\\.x')\n{\n return 1;\n}\n}\n"}, {"source_code": "#!/usr/bin/perl\n\nuse warnings;\nuse strict;\n\n$\\ = $/;\n\nmy $debug = 0;\n\nwhile(!eof){\n\t$_ = join '', map ~~<>, 1 .. 4;\n\ty/./,/;\n\t\n\tmy @rxs;\n\t\n\tfor my $join ( map { '.' x $_ } 0, 3, 4, 5 ){\n\t\tfor my $arrange ( 'xx,xx' =~ /(?=(...))/g ){\n\t\t\tpush @rxs, join $join, split '', $arrange;\n\t\t\t}\n\t\t}\n\t\t\t\n\tmy $re = join '|', @rxs;\n\t\n\t$debug and print $re;\n\t\n\tprint /$re/gs ? \"YES\" : \"NO\";\n\t\n\t$debug and print \"pos:\", pos, \"[$&]\";\n\t}"}, {"source_code": "$/ = $\\;\n\nfor $j ( map '.' x $_, 0, 3 .. 5 ){\n\tfor ( 'xx,xx' =~ /(?=(...))/g ){\n\t\t$r .= '|' . join $j, split '';\n\t\t}\n\t}\n\t\nprint <> =~ y/./,/r =~ /r$r/s ? \"YES\" : \"NO\""}], "negative_code": [{"source_code": "#!/usr/bin/perl\n\nuse warnings;\nuse strict;\n\n$\\ = $/;\n\nmy $debug = 0;\n\nwhile(!eof){\n\t$_ = join '', split ' ', join '', map ~~<>, 1 .. 4;\n\ty/./,/;\n\t\n\tmy @rxs;\n\t\n\tfor my $join ( map { '[^o]' x $_ } 0, 2, 3, 4 ){\n\t\tfor my $arrange ( 'xx,xx' =~ /(?=(...))/g ){\n\t\t\tpush @rxs, join $join, split '', $arrange;\n\t\t\t}\n\t\t}\n\t\t\n\t$debug and print \"/xx,|x,x|,xx|x...x...,|x...,...x|,...x...x|x....x....,|x....,....x|,....x....x|/\";\n\t\n\tmy $re = join '|', @rxs;\n\t\n\t$debug and print $re;\n\t\n\tprint /$re/ ? \"YES\" : \"NO\";\n\t\n\t}"}], "src_uid": "ca4a77fe9718b8bd0b3cc3d956e22917"}