{"nl": {"description": "There are $$$n$$$ students in a school class, the rating of the $$$i$$$-th student on Codehorses is $$$a_i$$$. You have to form a team consisting of $$$k$$$ students ($$$1 \\le k \\le n$$$) such that the ratings of all team members are distinct.If it is impossible to form a suitable team, print \"NO\" (without quotes). Otherwise print \"YES\", and then print $$$k$$$ distinct numbers which should be the indices of students in the team you form. If there are multiple answers, print any of them.", "input_spec": "The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\le k \\le n \\le 100$$$) \u2014 the number of students and the size of the team you have to form. The second line contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 100$$$), where $$$a_i$$$ is the rating of $$$i$$$-th student.", "output_spec": "If it is impossible to form a suitable team, print \"NO\" (without quotes). Otherwise print \"YES\", and then print $$$k$$$ distinct integers from $$$1$$$ to $$$n$$$ which should be the indices of students in the team you form. All the ratings of the students in the team should be distinct. You may print the indices in any order. If there are multiple answers, print any of them. Assume that the students are numbered from $$$1$$$ to $$$n$$$.", "sample_inputs": ["5 3\n15 13 15 15 12", "5 4\n15 13 15 15 12", "4 4\n20 10 40 30"], "sample_outputs": ["YES\n1 2 5", "NO", "YES\n1 2 3 4"], "notes": "NoteAll possible answers for the first example: {1 2 5} {2 3 5} {2 4 5} Note that the order does not matter."}, "positive_code": [{"source_code": "import std.stdio ;\n\nvoid main() {\n\tint n,k,x,r,i = 1;\n\tbool[105] arr ;\n\n\treadf(\"%s %s\",&n,&k);\n\tint[105] arr2 ;\n\n\twhile(i <= n) {\n\t\treadf(\" %s\",&x);\n\t\tif(arr[x] == false && r 3 * n ? 0 : 3 * n - k); \n } \n}"}], "negative_code": [], "src_uid": "5a5e46042c3f18529a03cb5c868df7e8"} {"nl": {"description": "Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.Right now, Limak and Bob weigh a and b respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.Limak eats a lot and his weight is tripled after every year, while Bob's weight is doubled after every year.After how many full years will Limak become strictly larger (strictly heavier) than Bob?", "input_spec": "The only line of the input contains two integers a and b (1\u2009\u2264\u2009a\u2009\u2264\u2009b\u2009\u2264\u200910)\u00a0\u2014 the weight of Limak and the weight of Bob respectively.", "output_spec": "Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob.", "sample_inputs": ["4 7", "4 9", "1 1"], "sample_outputs": ["2", "3", "1"], "notes": "NoteIn the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4\u00b73\u2009=\u200912 and 7\u00b72\u2009=\u200914 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Limak became larger than Bob after two years so you should print 2.In the second sample, Limak's and Bob's weights in next years are: 12 and 18, then 36 and 36, and finally 108 and 72 (after three years). The answer is 3. Remember that Limak wants to be larger than Bob and he won't be satisfied with equal weights.In the third sample, Limak becomes larger than Bob after the first year. Their weights will be 3 and 2 then."}, "positive_code": [{"source_code": "import std.stdio;\n\nvoid main() {\n int a, b;\n readf(\"%d %d\\n\", &a, &b);\n int year = 0;\n while (a <= b) {\n year++;\n a *= 3;\n b *= 2;\n }\n writefln(\"%d\", year);\n}"}, {"source_code": "import std.stdio;\n\nvoid main() {\n\tint a, b;\n\treadf(\"%d %d\", &a, &b);\n\tint result = 0;\n\twhile(a <= b) {\n\t\ta *= 3;\n\t\tb *= 2;\n\t\tresult++;\n\t}\n\twriteln(result);\n}"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\nimport std.regex;\nimport std.algorithm.iteration;\nimport std.array;\n\nvoid main()\n{\n auto ab = stdin.readln.strip.split(regex(` +`)).map!(to!int);\n int a = ab[0], b = ab[1], y = 0;\n for (;a<=b; a*=3, b*=2, y++) {}\n write(y);\n} "}, {"source_code": "import std.stdio, std.string, std.conv;\nimport std.range, std.algorithm, std.array, std.typecons, std.container;\nimport std.math, std.numeric, core.bitop;\n\n\n\nvoid main() {\n int a, b;\n scan(a, b);\n\n int cnt;\n\n while (a <= b) {\n a *= 3;\n b *= 2;\n cnt++;\n }\n\n writeln(cnt);\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\nvoid scan(T...)(ref T args) {\n import std.stdio : readln;\n import std.algorithm : splitter;\n import std.conv : to;\n import std.range.primitives;\n\n auto line = readln().splitter();\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const A = readInt();\n const B = readInt();\n \n int ans;\n int a = A, b = B;\n for (; !(a > b); ) {\n ++ans;\n a *= 3;\n b *= 2;\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.stdio;\n\nint main()\n{\n\tint a=0;\n\tint b=0;\n\treadf(\" %d\", &a);\n\treadf(\" %d\", &b);\n\tint i=0;\n\twhile(a<=b)\n\t{\n\t\ta=a*3;\n\t\tb=b*2;\n\t\ti=i+1;\n\t}\n\twriteln(i);\n\treturn 0;\n}"}, {"source_code": "import std.stdio, std.string, std.conv;\nvoid main()\n{\n byte[] arr = readln.chomp.split(' ').to!(byte[]);\n byte ret = 0;\n while(3^^ret * arr[0] <= 2^^ret * arr[1]) ret ++;\n writeln(ret);\n}\n"}], "negative_code": [], "src_uid": "a1583b07a9d093e887f73cc5c29e444a"} {"nl": {"description": "An expedition group flew from planet ACM-1 to Earth in order to study the bipedal species (its representatives don't even have antennas on their heads!).The flying saucer, on which the brave pioneers set off, consists of three sections. These sections are connected by a chain: the 1-st section is adjacent only to the 2-nd one, the 2-nd one \u2014 to the 1-st and the 3-rd ones, the 3-rd one \u2014 only to the 2-nd one. The transitions are possible only between the adjacent sections.The spacecraft team consists of n aliens. Each of them is given a rank \u2014 an integer from 1 to n. The ranks of all astronauts are distinct. The rules established on the Saucer, state that an alien may move from section a to section b only if it is senior in rank to all aliens who are in the segments a and b (besides, the segments a and b are of course required to be adjacent). Any alien requires exactly 1 minute to make a move. Besides, safety regulations require that no more than one alien moved at the same minute along the ship.Alien A is senior in rank to alien B, if the number indicating rank A, is more than the corresponding number for B.At the moment the whole saucer team is in the 3-rd segment. They all need to move to the 1-st segment. One member of the crew, the alien with the identification number CFR-140, decided to calculate the minimum time (in minutes) they will need to perform this task.Help CFR-140, figure out the minimum time (in minutes) that all the astronauts will need to move from the 3-rd segment to the 1-st one. Since this number can be rather large, count it modulo m.", "input_spec": "The first line contains two space-separated integers: n and m (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u2009109) \u2014 the number of aliens on the saucer and the number, modulo which you should print the answer, correspondingly.", "output_spec": "Print a single number \u2014 the answer to the problem modulo m.", "sample_inputs": ["1 10", "3 8"], "sample_outputs": ["2", "2"], "notes": "NoteIn the first sample the only crew member moves from segment 3 to segment 2, and then from segment 2 to segment 1 without any problems. Thus, the whole moving will take two minutes.To briefly describe the movements in the second sample we will use value , which would correspond to an alien with rank i moving from the segment in which it is at the moment, to the segment number j. Using these values, we will describe the movements between the segments in the second sample: , , , , , , , , , , , , , , , , , , , , , , , , , ; In total: the aliens need 26 moves. The remainder after dividing 26 by 8 equals 2, so the answer to this test is 2."}, "positive_code": [{"source_code": "import std.stdio : readln, writeln;\nimport std.math : pow;\nimport std.conv : to;\nimport std.string : split;\n\n/*\n \u62e1\u5f35\u3055\u308c\u305f\u30cf\u30ce\u30a4\u306e\u5854(3^n-1)\n \u3068\u3001\u3079\u304d\u4e57\u4f59\n */\nint _hanoi(long n, long m)\n{\n long res = 1;\n long r = 3;\n \n while(0>= 1;\n r = (r*r)%m;\n }\n \n return (0>= 1;\n r = (r*r)%m;\n }\n \n return res.to!int -1;\n}\n\nvoid main()\n{\n io();\n}\n\nvoid io()\n{\n string[] str = readln().split();\n int n = str[0].to!int();\n int m = str[1].to!int();\n \n writeln = _hanoi(n, m)%m;\n}\n"}], "src_uid": "c62ad7c7d1ea7aec058d99223c57d33c"} {"nl": {"description": "A big company decided to launch a new series of rectangular displays, and decided that the display must have exactly n pixels. Your task is to determine the size of the rectangular display \u2014 the number of lines (rows) of pixels a and the number of columns of pixels b, so that: there are exactly n pixels on the display; the number of rows does not exceed the number of columns, it means a\u2009\u2264\u2009b; the difference b\u2009-\u2009a is as small as possible. ", "input_spec": "The first line contains the positive integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009106)\u00a0\u2014 the number of pixels display should have.", "output_spec": "Print two integers\u00a0\u2014 the number of rows and columns on the display. ", "sample_inputs": ["8", "64", "5", "999999"], "sample_outputs": ["2 4", "8 8", "1 5", "999 1001"], "notes": "NoteIn the first example the minimum possible difference equals 2, so on the display should be 2 rows of 4 pixels.In the second example the minimum possible difference equals 0, so on the display should be 8 rows of 8 pixels.In the third example the minimum possible difference equals 4, so on the display should be 1 row of 5 pixels."}, "positive_code": [{"source_code": "import std.bigint,std.container,std.array,std.algorithm,std.conv,std.functional,std.math,std.numeric,std.string,std.range,std.complex,std.typecons,std.regex,\nstd.random,std.uni,std.traits,std.variant;\nimport core.stdc.stdio:freopen;\nimport std.stdio;\n//import core.stdc.stdio;\nalias RedBlackTree Rbt;\nalias redBlackTree rbt;\nalias BigInt big;\nalias pair!(int,int) pii;\nalias pair!(long,long) pll;\nalias BoyerMooreFinder strfind;\nimmutable int mod=1000000007;\n@property pure nothrow T lcm (T)(auto ref T a,auto ref T b)\n{\n\treturn a/gcd(a,b)*b;\n}\npure nothrow @property X binpow(X,Y)(X base,Y exp)\nif(is(typeof(exp&1)))\n{\n\tif(exp<0)return X(0);\n\tX res=X(1);\n\twhile(exp>0)\n\t{\n\t\tif(exp&1)res*=base;\n\t\tbase*=base;\n\t\texp>>=1;\n\t}\n\treturn res;\n}\npure nothrow @property auto binpow(X,Y,Z)(X base,Y exp,in Z mm)\nif(is(typeof(exp&1)))\n{\n\tif(mm==0) return binpow(base,exp);\n\tif(exp<0)return X(0);\n\tauto res=X(1)%mm;\n\twhile(exp>0)\n\t{\n\t\tif(exp&1)res=(res*base)%mm;\n\t\tbase*=base;\n\t\tbase%=mm;\n\t\texp>>=1;\n\t}\n\treturn res;\n}\n@property void putarr(X)(in X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\n@property void putarr(X)(X a,in int n,in int m)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\n@property bool getarr(X)(X a,in int n){bool b=1; foreach(ref i;a[0..n])b=input(&i);return b;}\nbool input(T...)(T ptrs) if (ptrs.length > 0) {return readf(replicate(\" %s\", ptrs.length), ptrs)==ptrs.length;}\nstruct pair(X,Y)\n{\n\tX first;\n\tY second;\n\talias first fi;\n\talias second se;\n\tthis(X a_,Y b_){\n\t\tfi=a_;\n\t\tse=b_;\n\t}\n\tthis(this){fi=fi;se=se;}\n\tthis(A,B)(auto ref pair!(A,B) p)\n\t{\n\t\tfi=p.fi;\n\t\tse=p.se;\n\t}\n\tint opCmp(in pair!(X,Y) s_) const pure nothrow @safe\n\t{\n\t\tint cmp=0-(fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.se));\n\t}\n};\npair!(X,Y) mp(X,Y)(in X x_,in Y y_) pure nothrow @safe\n{\n\tpair!(X,Y) pp;\n\tpp.fi=x_;\n\tpp.se=y_;\n\treturn pp;\n}\nX sqr(X)(in X a_) pure nothrow @property @safe @nogc {return a_*a_;}\nX cub(X)(in X a_) pure nothrow @property @safe @nogc {return a_*a_*a_;}\nnothrow @nogc @system void inf(in char* name) {freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow @nogc @system void ouf(in char* name) {freopen(name,\"w\",core.stdc.stdio.stdout);}\nauto arread(T)(){return readln.split.map!(to!(T)).array;}\nnothrow @property pure size_t lowb(T,X)(in T a,auto ref X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m] f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nlong M;\nint A, B;\n\nvoid main() {\n try {\n for (; ; ) {\n M = readLong();\n A = readInt();\n B = readInt();\n \n const V = 2 * (A + B) + 10;\n alias Node = Tuple!(int, \"c\", int, \"u\");\n BinaryHeap!(Array!Node, \"a > b\") que;\n auto dist = new int[V];\n dist[] = V;\n dist[0] = 0;\n que.insert(Node(0, 0));\n for (; !que.empty; ) {\n const c = que.front.c;\n const u = que.front.u;\n que.removeFront;\n if (dist[u] == c) {\n foreach (v; [u + A, u - B]) {\n if (0 <= v && v < V) {\n const cc = max(c, v);\n if (dist[v] > cc) {\n dist[v] = cc;\n que.insert(Node(cc, v));\n }\n }\n }\n }\n }\n auto f = new int[V];\n foreach (u; 0 .. V) {\n if (dist[u] < V) {\n ++f[dist[u]];\n }\n }\n foreach (u; 1 .. V) {\n f[u] += f[u - 1];\n }\n debug {\n if (V <= 100) {\n writeln(\"dist = \", dist);\n writeln(\"f = \", f);\n }\n }\n \n const long g = gcd(A, B);\n const long q = (M + 1) / g, r = (M + 1) % g;\n long ans;\n ans += g * q * (q + 1) / 2;\n ans += (q + 1) * r;\n foreach (u; 0 .. V) {\n if (u <= M) {\n ans -= (u / g + 1);\n ans += f[u];\n }\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "d6290b69eddfcf5f131cc9e612ccab76"} {"nl": {"description": "Manao is trying to open a rather challenging lock. The lock has n buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the lock (that means that you've guessed correctly and pushed the button that goes next in the sequence), or all pressed buttons return to the initial position. When all buttons are pressed into the lock at once, the lock opens.Consider an example with three buttons. Let's say that the opening sequence is: {2, 3, 1}. If you first press buttons 1 or 3, the buttons unpress immediately. If you first press button 2, it stays pressed. If you press 1 after 2, all buttons unpress. If you press 3 after 2, buttons 3 and 2 stay pressed. As soon as you've got two pressed buttons, you only need to press button 1 to open the lock.Manao doesn't know the opening sequence. But he is really smart and he is going to act in the optimal way. Calculate the number of times he's got to push a button in order to open the lock in the worst-case scenario.", "input_spec": "A single line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u20092000) \u2014 the number of buttons the lock has.", "output_spec": "In a single line print the number of times Manao has to push a button in the worst-case scenario.", "sample_inputs": ["2", "3"], "sample_outputs": ["3", "7"], "notes": "NoteConsider the first test sample. Manao can fail his first push and push the wrong button. In this case he will already be able to guess the right one with his second push. And his third push will push the second right button. Thus, in the worst-case scenario he will only need 3 pushes."}, "positive_code": [{"source_code": "import std.stdio;\nimport core.stdc.stdio;\nimport std.algorithm;\nimport std.math;\n\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\tint sum = 0;\n\tforeach (int i; 1..n)\n\t{\n\t\tsum += i * (n-i);\n\t}\n\twrite(sum + n);\n\treturn 0;\n}"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.math;\n\nvoid main() {\n int n = readln.chomp.to!int;\n\n int ans = 0;\n for (int i = 1; i <= n - 1; i++) {\n ans += i * (n - i);\n }\n\n writeln(ans + n);\n}"}, {"source_code": "import std.stdio, std.string, std.conv;\nimport std.range, std.algorithm, std.array, std.typecons, std.container;\nimport std.math, std.numeric, core.bitop;\n\n\n\nvoid main() {\n long n;\n scan(n);\n long ans = n * (n*n + 5) / 6;\n writeln(ans);\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\nvoid scan(T...)(ref T args) {\n import std.stdio : readln;\n import std.algorithm : splitter;\n import std.conv : to;\n import std.range.primitives;\n\n auto line = readln().splitter();\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}"}, {"source_code": "import std.array : split;\nimport std.conv : to;\nimport std.stdio;\nimport std.string : strip;\n\nprivate {\n\tstring[] temp;\n}\n\nvoid main() {\n\tread();\n\n\tint n = get!int(0);\n\t\n\tint count = 0;\n\n\tforeach (i; 1 .. n + 1) {\n\t\tcount += (n - (i - 1)) * i - i + 1;\n\t}\n\n\tstdout.write(count);\n}\n\nvoid read() {\n\ttemp = split(strip(stdin.readln()));\n}\n\nT get(T)(int p) {\n\treturn to!(T)(temp[p]);\n}"}], "negative_code": [{"source_code": "import std.stdio;\nimport core.stdc.stdio;\nimport std.algorithm;\nimport std.math;\n\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\tint sum = 0;\n\tforeach (int i; 0..n)\n\t{\n\t\tsum += (sum + 1);\n\t}\n\twrite(sum);\n\treturn 0;\n}"}, {"source_code": "import std.array : split;\nimport std.conv : to;\nimport std.stdio;\nimport std.string : strip;\n\nprivate {\n\tstring[] temp;\n}\n\nvoid main() {\n\tread();\n\n\tint n = get!int(0);\n\t\n\tint count = n;\n\n\tforeach (i; 1 .. n) {\n\t\tcount += 2 * (n - i) - 1;\n\t}\n\n\tstdout.write(count);\n}\n\nvoid read() {\n\ttemp = split(strip(stdin.readln()));\n}\n\nT get(T)(int p) {\n\treturn to!(T)(temp[p]);\n}"}], "src_uid": "6df251ac8bf27427a24bc23d64cb9884"} {"nl": {"description": "Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: on this day the gym is closed and the contest is not carried out; on this day the gym is closed and the contest is carried out; on this day the gym is open and the contest is not carried out; on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day).Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has \u2014 he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days.", "input_spec": "The first line contains a positive integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100) \u2014 the number of days of Vasya's vacations. The second line contains the sequence of integers a1,\u2009a2,\u2009...,\u2009an (0\u2009\u2264\u2009ai\u2009\u2264\u20093) separated by space, where: ai equals 0, if on the i-th day of vacations the gym is closed and the contest is not carried out; ai equals 1, if on the i-th day of vacations the gym is closed, but the contest is carried out; ai equals 2, if on the i-th day of vacations the gym is open and the contest is not carried out; ai equals 3, if on the i-th day of vacations the gym is open and the contest is carried out.", "output_spec": "Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: to do sport on any two consecutive days, to write the contest on any two consecutive days. ", "sample_inputs": ["4\n1 3 2 0", "7\n1 3 3 2 1 2 3", "2\n2 2"], "sample_outputs": ["2", "0", "1"], "notes": "NoteIn the first test Vasya can write the contest on the day number 1 and do sport on the day number 3. Thus, he will have a rest for only 2 days.In the second test Vasya should write contests on days number 1, 3, 5 and 7, in other days do sport. Thus, he will not have a rest for a single day.In the third test Vasya can do sport either on a day number 1 or number 2. He can not do sport in two days, because it will be contrary to the his limitation. Thus, he will have a rest for only one day."}, "positive_code": [{"source_code": "import core.bitop;\nimport core.checkedint;\nimport core.simd;\nimport core.stdc.string;\nimport std.algorithm;\nimport std.array;\nimport std.ascii;\nimport std.bigint;\nimport std.bitmanip;\nimport std.complex;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.functional;\nimport std.math;\nimport std.meta;\nimport std.numeric;\nimport std.random;\nimport std.regex;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.variant;\n\nbool read(T...)(T ptrs) if (ptrs.length > 0) {\n return readf(' ' ~ replicate(\"%s \", ptrs.length), ptrs) == ptrs.length;\n}\n\nint n;\nint[100] _a;\nint[ ] a;\n\nint[3][100] dp;\n\nint dyn(int day, int prevMask) {\n if (day == n)\n return 0;\n if (~dp[day][prevMask])\n return dp[day][prevMask];\n int result = dyn(day + 1, 0x0) + 1;\n foreach (mask; 0x1 .. 0x3)\n if ((a[day] & mask) && !(prevMask & mask))\n result = min(result, dyn(day + 1, mask));\n return (dp[day][prevMask] = result);\n}\n\nvoid main() {\n while (read(&n)) {\n a = _a[0 .. n];\n foreach (ref x; a)\n read(&x);\n memset(dp.ptr, 0xFF, dp.sizeof);\n writeln(dyn(0, 0x0));\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.conv;\nimport std.algorithm;\nvoid main() {\n int d0 = 0, d1 = 0, d2 = 0;\n int n;\n readf(\"%d\", &n);\n foreach (i; 0 .. n) {\n \t//write(i);\n int c;\n readf(\" %d\", &c);\n int n0 = max(d0, max(d1, d2));\n int n1 = -1;\n int n2 = -1;\n if (c & 1) {\n n1 = max(n1, max(d0, d2) + 1);\n }\n if (c & 2) {\n n2 = max(n2, max(d0, d1) + 1);\n }\n d0 = n0, d1 = n1, d2 = n2;\n //writef(\"%d, %d, %d\\n\", d0, d1, d2);\n }\n write(n - max(d0, max(d1, d2)));\n}"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.split.map !(to !(int)).array;\n\t\tauto f = new int [3] [n + 1];\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto prev = f[i].reduce !(max);\n\t\t\tf[i + 1][] = prev;\n\t\t\tforeach (j; [1, 2])\n\t\t\t{\n\t\t\t\tif (a[i] & j)\n\t\t\t\t{\n\t\t\t\t\tf[i + 1][j] = max (f[i + 1][j],\n\t\t\t\t\t max (f[i][0], f[i][j ^ 3]) + 1);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tauto res = f[n].reduce !(max);\n\t\twriteln (n - res);\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\nvoid main() {\n int d0 = 0, d1 = 0, d2 = 0;\n int n;\n readf(\"%d\", &n);\n foreach (i; 1 .. n) {\n int c;\n readf(\" %d\", &c);\n int n0 = max(d0, max(d1, d2));\n int n1 = d1;\n int n2 = d2;\n if (c & 1) {\n n1 = max(n1, max(d0, d2) + 1);\n }\n if (c & 2) {\n n2 = max(n2, max(d0, d1) + 1);\n }\n d0 = n0, d1 = n1, d2 = n2;\n }\n write(n - max(d0, max(d1, d2)));\n}"}], "src_uid": "08f1ba79ced688958695a7cfcfdda035"} {"nl": {"description": "Vasya has got many devices that work on electricity. He's got n supply-line filters to plug the devices, the i-th supply-line filter has ai sockets.Overall Vasya has got m devices and k electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supply-line filter to any other supply-line filter. The device (or the supply-line filter) is considered plugged to electricity if it is either plugged to one of k electrical sockets, or if it is plugged to some supply-line filter that is in turn plugged to electricity. What minimum number of supply-line filters from the given set will Vasya need to plug all the devices he has to electricity? Note that all devices and supply-line filters take one socket for plugging and that he can use one socket to plug either one device or one supply-line filter.", "input_spec": "The first line contains three integers n, m, k (1\u2009\u2264\u2009n,\u2009m,\u2009k\u2009\u2264\u200950) \u2014 the number of supply-line filters, the number of devices and the number of sockets that he can plug to directly, correspondingly. The second line contains n space-separated integers a1,\u2009a2,\u2009...,\u2009an (1\u2009\u2264\u2009ai\u2009\u2264\u200950) \u2014 number ai stands for the number of sockets on the i-th supply-line filter.", "output_spec": "Print a single number \u2014 the minimum number of supply-line filters that is needed to plug all the devices to electricity. If it is impossible to plug all the devices even using all the supply-line filters, print -1.", "sample_inputs": ["3 5 3\n3 1 2", "4 7 2\n3 3 2 4", "5 5 1\n1 3 1 2 1"], "sample_outputs": ["1", "2", "-1"], "notes": "NoteIn the first test case he can plug the first supply-line filter directly to electricity. After he plug it, he get 5 (3 on the supply-line filter and 2 remaining sockets for direct plugging) available sockets to plug. Thus, one filter is enough to plug 5 devices.One of the optimal ways in the second test sample is to plug the second supply-line filter directly and plug the fourth supply-line filter to one of the sockets in the second supply-line filter. Thus, he gets exactly 7 sockets, available to plug: one to plug to the electricity directly, 2 on the second supply-line filter, 4 on the fourth supply-line filter. There's no way he can plug 7 devices if he use one supply-line filter."}, "positive_code": [{"source_code": "import std.algorithm;\nimport std.stdio;\n\n\nint main ()\n{\n\tint k, m, n;\n\tmain_loop:\n\twhile ((readf (\" %d %d %d\", &n, &m, &k) >= 0) && !stdin.eof ())\n\t{\n\t\tauto a = new int [n];\n\t foreach (i; 0..n)\n\t {\n\t \treadf (\" %d\", &a[i]);\n\t }\n\t sort (a);\n\t reverse (a);\n\t auto s = k;\n\t foreach (i; 0..n)\n\t {\n\t \tif (s >= m)\n\t \t{\n\t \t\twritef (\"%d\\n\", i);\n\t \t\tcontinue main_loop;\n\t \t}\n\t \ts += a[i] - 1;\n\t }\n\t\twritef (\"%d\\n\", (s >= m) ? n : -1);\n\t}\n\treturn 0;\n}\n"}], "negative_code": [], "src_uid": "b32ab27503ee3c4196d6f0d0f133d13c"} {"nl": {"description": "There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string s. The i-th (1-based) character of s represents the color of the i-th stone. If the character is \"R\", \"G\", or \"B\", the color of the corresponding stone is red, green, or blue, respectively.Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times.Each instruction is one of the three types: \"RED\", \"GREEN\", or \"BLUE\". After an instruction c, if Liss is standing on a stone whose colors is c, Liss will move one stone forward, else she will not move.You are given a string t. The number of instructions is equal to the length of t, and the i-th character of t represents the i-th instruction.Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence.", "input_spec": "The input contains two lines. The first line contains the string s (1\u2009\u2264\u2009|s|\u2009\u2264\u200950). The second line contains the string t (1\u2009\u2264\u2009|t|\u2009\u2264\u200950). The characters of each string will be one of \"R\", \"G\", or \"B\". It is guaranteed that Liss don't move out of the sequence.", "output_spec": "Print the final 1-based position of Liss in a single line.", "sample_inputs": ["RGB\nRRR", "RRRBGBRBBB\nBBBRR", "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB"], "sample_outputs": ["2", "3", "15"], "notes": null}, "positive_code": [{"source_code": "module main;\n\nimport std.stdio : readln, writeln, write, writefln, writef;\nimport std.conv : to;\nimport std.array : split, replace;\nimport std.string : strip;\nimport std.algorithm : max, min, map, reduce, sort, reverse;\nimport std.functional : memoize;\n\nversion = A;\n\nversion (A)\n{\n void main()\n {\n auto sequence = read_one!string();\n auto instructions = read_one!string();\n size_t position = 0;\n foreach (instruction; instructions)\n {\n if (sequence[position] == instruction)\n {\n position += 1;\n }\n }\n writeln(position + 1);\n }\n}\nversion (B)\n{\n void main()\n {\n auto n = read_one!int();\n }\n}\nversion (C)\n{\n void main()\n {\n auto n = read_one!int();\n }\n}\nversion (D)\n{\n void main()\n {\n auto n = read_one!int();\n }\n}\nversion (E)\n{\n void main()\n {\n }\n}\n\nT read_one(T)()\n{\n return readln().strip().to!T();\n}\n \nT[] read_some(T)()\n{\n T[] ret;\n foreach (e; readln().strip().split())\n {\n ret ~= e.to!T();\n }\n return ret;\n}\n\nT[m] read_fixed(int m, T)()\n{\n T[m] ret;\n foreach (i, e; readln().strip().split())\n {\n ret[i] = e.to!T();\n }\n return ret;\n}\n"}, {"source_code": "import std.stdio, std.algorithm, std.string, std.conv, std.array, std.range, std.math;\nint readint() { return readln.chomp.to!int; }\nint[] readints() { return readln.split.to!(int[]); }\n\nvoid main() {\n string s = readln.chomp;\n string t = readln.chomp;\n\n int cur = 0;\n foreach (c ; t) {\n if (c == s[cur]) cur++;\n }\n\n writeln(cur + 1);\n\n string _ = readln;\n}"}, {"source_code": "import std.stdio;\n\nvoid main() {\n\tstring land = stdin.readln();\n\n\tsize_t position = 1;\n\n\tforeach (char command; stdin.readln()) {\n\t\tif (command == land[position - 1]) {\n\t\t\t++position;\n\t\t}\n\t}\n\n\tstdout.write(position);\n}"}], "negative_code": [], "src_uid": "f5a907d6d35390b1fb11c8ce247d0252"} {"nl": {"description": "Bob loves everything sweet. His favorite chocolate bar consists of pieces, each piece may contain a nut. Bob wants to break the bar of chocolate into multiple pieces so that each part would contain exactly one nut and any break line goes between two adjacent pieces.You are asked to calculate the number of ways he can do it. Two ways to break chocolate are considered distinct if one of them contains a break between some two adjacent pieces and the other one doesn't. Please note, that if Bob doesn't make any breaks, all the bar will form one piece and it still has to have exactly one nut.", "input_spec": "The first line of the input contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100)\u00a0\u2014 the number of pieces in the chocolate bar. The second line contains n integers ai (0\u2009\u2264\u2009ai\u2009\u2264\u20091), where 0 represents a piece without the nut and 1 stands for a piece with the nut.", "output_spec": "Print the number of ways to break the chocolate into multiple parts so that each part would contain exactly one nut.", "sample_inputs": ["3\n0 1 0", "5\n1 0 1 0 1"], "sample_outputs": ["1", "4"], "notes": "NoteIn the first sample there is exactly one nut, so the number of ways equals 1\u00a0\u2014 Bob shouldn't make any breaks.In the second sample you can break the bar in four ways:10|10|11|010|110|1|011|01|01"}, "positive_code": [{"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\n\nvoid main()\n{\n\t auto s1 = split(strip(readln));\n\t long[] b;\n\t auto s2 = split(strip(readln));\n\t foreach(idx, num; s2)\n\t {\n\t \tif (num == \"1\")\n\t \t\tb ~= idx; \n\t }\n\t long prod = 1; long dif;\n\t if (b.length == 0)\n\t {\n\t \twrite(0);\n\t \treturn;\n\t }\n\t else if (b.length == 1)\n\t {\n\t \twrite(1);\n\t \treturn;\n\t }\t\n\t foreach(idx, num; b[1 .. $])\n\t {\n\t \tdif = num - b[idx];\n\t\tprod *= dif; \n\t }\n\t writeln(prod);\n}"}, {"source_code": "import std.stdio;\n\nvoid main() {\n\tlong n;\n\treadf!\"%s\\n\"(n);\n\n\tlong product=0;\n\tlong count=1;\n\tfor (int i=0; i 0) {\n\t\tt += n % 10;\n\t\tn /= 10;\n\t}\n\treturn t;\n}\n\nint m(long n) {\n\tint t = 0;\n\twhile (n > 0) { t++; n /= 10; }\n\treturn t * 9;\n}\n\n/*\nx^2 + tx > n\nx^2 + tx + t^2/4 > n + t^2/4\nx + t/2 > sqrt(4n^2+t^2)/2\nx > sqrt(4n^2+t^2)/2-t/2\n*/\n\nlong solve(long n) {\n\tlong r = cast(long) sqrt(n * 1.0);\n\tlong t = m(r);\n\tlong l = cast(long) (sqrt(4.0 * n + 1.0 * t * t) / 2 - t / 2);\n\tif (l == 0) l++;\n\twhile (l <= r) {\n\t\tif (n % l == 0) {\n\t\t\tif (l * (l + s(l)) == n) return l;\n\t\t}\n\t\tl++;\n\t}\n\treturn -1;\n}\n\nvoid main() {\n\tlong n;\n\treadf(\"%d\", &n);\n\twriteln(solve(n));\n}\n"}], "negative_code": [], "src_uid": "e1070ad4383f27399d31b8d0e87def59"} {"nl": {"description": "An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point x(x\u2009>\u20090) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order to get to his friend's house.", "input_spec": "The first line of the input contains an integer x (1\u2009\u2264\u2009x\u2009\u2264\u20091\u2009000\u2009000)\u00a0\u2014 The coordinate of the friend's house.", "output_spec": "Print the minimum number of steps that elephant needs to make to get from point 0 to point x.", "sample_inputs": ["5", "12"], "sample_outputs": ["1", "3"], "notes": "NoteIn the first sample the elephant needs to make one step of length 5 to reach the point x.In the second sample the elephant can get to point x if he moves by 3, 5 and 4. There are other ways to get the optimal answer but the elephant cannot reach x in less than three moves."}, "positive_code": [{"source_code": "import std.stdio;\nimport std.uni;\nimport std.string;\nimport core.stdc.stdio;\nimport std.array;\nimport std.algorithm;\nimport std.string;\nimport std.math;\n\nint main(string[] argv)\n{\n\tint x;\n\tscanf(\"%d\", &x);\n\tint r = 0;\n\tint s = 5;\n\twhile (x > 0)\n\t{\n\t\tr += x / s;\n\t\tx = x % s;\n\t\ts--;\n\t}\n\tprintf(\"%d\", r);\n\treturn 0;\n}\n\n"}, {"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\n\nvoid main()\n{\n\t auto s1 = split(strip(readln));\n\t long n = to!long(s1[0], 10);\n\t if (n % 5 == 0)\n\t writeln(n / 5 );\n\t else\n\t writeln(n / 5 + 1);\n}"}, {"source_code": "import std.stdio;\n\nint main( ) {\n int n ;\n\treadf(\"%d\",n);\n\tint[] ar = [5, 4 ,3 ,2 ,1];\n\tint c = 0;\n\tfor (int i = 0 ; i < 5 ; i++ ) {\n\t\tint _c = n / ar[i];\n\t\tn -= ar[i] * _c;\n\t\tc += _c;\n\t\tif (n == 0)\n\t\t\tbreak;\n\t}\n\twrite(c , '\\n');\n\n\treturn 0;\n}\n"}, {"source_code": "import std.stdio: writeln, readf;\n\nvoid main() {\n int coordinate = 0;\n int steps = 0;\n int moves = 5;\n\n readf(\" %s\", coordinate);\n\n for(int i = moves; i > 0; i--) {\n \tif(coordinate >= i) {\n \tsteps += coordinate/i;\n \tcoordinate = coordinate % i;\n \t}\n }\n\n writeln(steps);\n}"}, {"source_code": "import std.stdio, std.string, std.conv;\n\nvoid main() {\n int x = readln.chomp.to!int;\n writeln((x + 4)/ 5);\n}"}, {"source_code": "import std.stdio;\n\nint main()\n{\n\tint a=0;\n\treadf(\" %d\", &a);\n\tif (a%5==0)\n\t{\n\t\twriteln(a/5);\n\t}\n\telse\n\t{\n\t\twriteln((a/5)+1);\n\t}\n\treturn 0;\n}"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\n\nvoid main()\n{\n\t auto s1 = split(strip(readln));\n\t long n = to!long(s1[0], 10);\n\t writeln(n / 5 + 1);\n}"}], "src_uid": "4b3d65b1b593829e92c852be213922b6"} {"nl": {"description": "Petr has just bought a new car. He's just arrived at the most known Petersburg's petrol station to refuel it when he suddenly discovered that the petrol tank is secured with a combination lock! The lock has a scale of $$$360$$$ degrees and a pointer which initially points at zero: Petr called his car dealer, who instructed him to rotate the lock's wheel exactly $$$n$$$ times. The $$$i$$$-th rotation should be $$$a_i$$$ degrees, either clockwise or counterclockwise, and after all $$$n$$$ rotations the pointer should again point at zero.This confused Petr a little bit as he isn't sure which rotations should be done clockwise and which should be done counterclockwise. As there are many possible ways of rotating the lock, help him and find out whether there exists at least one, such that after all $$$n$$$ rotations the pointer will point at zero again.", "input_spec": "The first line contains one integer $$$n$$$ ($$$1 \\leq n \\leq 15$$$) \u2014 the number of rotations. Each of the following $$$n$$$ lines contains one integer $$$a_i$$$ ($$$1 \\leq a_i \\leq 180$$$) \u2014 the angle of the $$$i$$$-th rotation in degrees.", "output_spec": "If it is possible to do all the rotations so that the pointer will point at zero after all of them are performed, print a single word \"YES\". Otherwise, print \"NO\". Petr will probably buy a new car in this case. You can print each letter in any case (upper or lower).", "sample_inputs": ["3\n10\n20\n30", "3\n10\n10\n10", "3\n120\n120\n120"], "sample_outputs": ["YES", "NO", "YES"], "notes": "NoteIn the first example, we can achieve our goal by applying the first and the second rotation clockwise, and performing the third rotation counterclockwise.In the second example, it's impossible to perform the rotations in order to make the pointer point at zero in the end.In the third example, Petr can do all three rotations clockwise. In this case, the whole wheel will be rotated by $$$360$$$ degrees clockwise and the pointer will point at zero again."}, "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tauto a = new int [n];\n\t\tforeach (ref x; a)\n\t\t{\n\t\t\treadf (\" %s\", &x);\n\t\t}\n\n\t\tbool ok = false;\n\t\tforeach (s; 0..1 << n)\n\t\t{\n\t\t\tint cur = 0;\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tif (s & (1 << i))\n\t\t\t\t{\n\t\t\t\t\tcur += a[i];\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tcur -= a[i];\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (cur % 360 == 0)\n\t\t\t{\n\t\t\t\tok = true;\n\t\t\t}\n\t\t}\n\t\twriteln (ok ? \"YES\" : \"NO\");\n\t}\n}\n"}, {"source_code": "import std.stdio, std.string, std.conv;\nimport std.range, std.algorithm, std.array, std.typecons, std.container;\nimport std.math, std.numeric, core.bitop;\n\n\n\nvoid main() {\n int n;\n scan(n);\n auto a = iota(n).map!(i => readln.chomp.to!int).array;\n\n foreach (s ; 0 .. 1< 0)\n\t{\n\t\tauto a = new int [n];\n\t\tforeach (ref x; a)\n\t\t{\n\t\t\treadf (\" %s\", &x);\n\t\t}\n\n\t\tbool ok = false;\n\t\tforeach (s; 0..1 << n)\n\t\t{\n\t\t\tint cur = 0;\n\t\t\tforeach (i; 0..n)\n\t\t\t{\n\t\t\t\tif (s & (1 << i))\n\t\t\t\t{\n\t\t\t\t\tcur += a[i];\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tcur -= a[i];\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (cur % 180 == 0)\n\t\t\t{\n\t\t\t\tok = true;\n\t\t\t}\n\t\t}\n\t\twriteln (ok ? \"YES\" : \"NO\");\n\t}\n}\n"}], "src_uid": "01b50fcba4185ceb1eb8e4ba04a0cc10"} {"nl": {"description": "One spring day on his way to university Lesha found an array A. Lesha likes to split arrays into several parts. This time Lesha decided to split the array A into several, possibly one, new arrays so that the sum of elements in each of the new arrays is not zero. One more condition is that if we place the new arrays one after another they will form the old array A.Lesha is tired now so he asked you to split the array. Help Lesha!", "input_spec": "The first line contains single integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100)\u00a0\u2014 the number of elements in the array A. The next line contains n integers a1,\u2009a2,\u2009...,\u2009an (\u2009-\u2009103\u2009\u2264\u2009ai\u2009\u2264\u2009103)\u00a0\u2014 the elements of the array A.", "output_spec": "If it is not possible to split the array A and satisfy all the constraints, print single line containing \"NO\" (without quotes). Otherwise in the first line print \"YES\" (without quotes). In the next line print single integer k\u00a0\u2014 the number of new arrays. In each of the next k lines print two integers li and ri which denote the subarray A[li... ri] of the initial array A being the i-th new array. Integers li, ri should satisfy the following conditions: l1\u2009=\u20091 rk\u2009=\u2009n ri\u2009+\u20091\u2009=\u2009li\u2009+\u20091 for each 1\u2009\u2264\u2009i\u2009<\u2009k. If there are multiple answers, print any of them.", "sample_inputs": ["3\n1 2 -3", "8\n9 -12 3 4 -4 -10 7 3", "1\n0", "4\n1 2 3 -5"], "sample_outputs": ["YES\n2\n1 2\n3 3", "YES\n2\n1 2\n3 8", "NO", "YES\n4\n1 1\n2 2\n3 3\n4 4"], "notes": null}, "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!int).array;\n\n if (A.map!(a => a == 0).all) {\n writeln(\"NO\");\n return;\n }\n\n writeln(\"YES\");\n\n if (A.sum == 0) {\n foreach (i; 0..N) if (A[i] != 0) {\n writeln(2);\n writeln(1, \" \", i+1);\n writeln(i+2, \" \", N);\n break;\n }\n } else {\n writeln(1);\n writeln(1, \" \", N);\n }\n}\n"}, {"source_code": "module main;\nimport std.bigint,std.container,std.array,std.algorithm,std.conv,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.variant;\nimport core.stdc.stdio : freopen;\nimport core.stdc.stdlib : system;\nimport std.stdio;\n//import core.stdc.stdio;\nalias RedBlackTree Rbt;\nalias redBlackTree rbt;\nalias BigInt big;\nalias pair!(int,int) pii;\nalias pair!(long,long) pll;\nalias BoyerMooreFinder strfind;\nalias mp=make_pair;\nalias bins=binary_search;\nalias orsq=orient_square;\nimmutable int mod=1000000007;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b)\n\t{\n\t\treturn a/gcd(a,b)*b;\n\t}\n\tX binpow(X,Y)(X base,Y exp)\n\t\tif(is(typeof(exp&1)))\n\t{\n\t\tif(exp<0)return X(0);\n\t\tX res=X(1);\n\t\twhile(exp>0)\n\t\t{\n\t\t\tif(exp&1)res*=base;\n\t\t\tbase*=base;\n\t\t\texp>>=1;\n\t\t}\n\t\treturn res;\n\t}\n\tauto binpow(X,Y,Z)(X base,Y exp,in Z mm)\n\t\tif(is(typeof(exp&1)))\n\t{\n\t\tif(mm==0) return binpow(base,exp);\n\t\tif(exp<0)return X(0);\n\t\tauto res=X(1)%mm;\n\t\twhile(exp>0)\n\t\t{\n\t\t\tif(exp&1)res=(res*base)%mm;\n\t\t\tbase*=base;\n\t\t\tbase%=mm;\n\t\t\texp>>=1;\n\t\t}\n\t\treturn res;\n\t}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tsize_t lowb(T,X)(in T a,auto ref X g) \n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 0)\n{return readf(replicate(\" %s\", ptrs.length), ptrs)==ptrs.length;}\nstruct pair(X,Y)\n{\n\tX first;\n\tY second;\n\talias first fi;\n\talias second se;\n\tthis(X a_,Y b_){\n\t\tfi=a_;\n\t\tse=b_;\n\t}\n\tthis(this){fi=fi;se=se;}\n\tthis(A,B)(auto ref pair!(A,B) p) if(is(A:X) && is(B:Y))\n\t{\n\t\tfi=p.fi;\n\t\tse=p.se;\n\t}\n\tpair!(X,Y) opAssign(A,B)(pair!(A,B) val)\n\t{\n\t\treturn this=pair!(X,Y)(val);\n\t}\n\tint opCmp(A,B)(in pair!(A,B) s_) const pure nothrow @safe \n\t\tif(is(typeof(s_.fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.se));\n\t}\n};\npair!(X,Y) make_pair(X,Y)(in X x_,in Y y_) pure nothrow @safe\n{\n\tpair!(X,Y) pp;\n\tpp.fi=x_;\n\tpp.se=y_;\n\treturn pp;\n}\nnothrow void inf(in char* name) {freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow void ouf(in char* name) {freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.split.map!(to!(T)).array;}\nstruct Tree(T,alias arg=\"a+b\")\n{\n\tprivate alias fun=binaryFun!arg;\n\tprivate static const size_t n=size_t.max>>1;\n\tprivate T[size_t] t;\n\tthis(this){t=t.dup;}\n\tthis(R)(R range) if(isInputRange!R && is(ElementType!(R) : T))\n\t{\n\t\tforeach(pos,i;range) upd(pos,i);\n\t}\n\tthis(R,alias f)(Tree!(R,f) q) if(is(R:T))\n\t{\n\t\tforeach(i,j;q.t)\n\t\t{\n\t\t\tt[i]=j;\n\t\t}\n\t}\n\tTree!(T,arg) opAssign(R)(R val)\n\t{\n\t\treturn this=Tree!(T,arg)(val);\n\t}\n\tprivate void upd(in size_t v,in size_t vl,in size_t vr,in size_t i,in T x)\n\t{\n\t\tif (vr - vl == 1){t[v] = x;return;}\n\t\tsize_t vm = (vl + vr) >> 1;\n\t\tif(i < vm) upd(2*v, vl, vm, i, x);\n\t\telse upd(2*v+1, vm, vr, i, x);\n\t\tif(v*2+1 !in t)t[v]=t[v*2];\n\t\telse if (v*2 !in t)t[v]=t[v*2+1];\n\t\telse t[v]=fun(t[v*2],t[v*2+1]);\n\t}\n\tvoid upd(in size_t i,in T x)\n\t{\n\t\tupd(1,0,n,i,x);\n\t}\n\tprivate T cel(in size_t v,in size_t vl,in size_t vr,in size_t l,in size_t r)\n\t{\n\t\tif(vl==l && r==vr) return t[v];\n\t\tsize_t vm=(vl+vr) >> 1;\n\t\tif(r<=vm) return cel(2*v,vl,vm,l,r);\n\t\telse if(l>=vm) return cel(2*v+1,vm,vr,l,r);\n\t\telse return fun(cel(2*v,vl,vm,l,vm),cel(2*v+1,vm,vr,vm,r));\n\t}\n\tT cel(in size_t l,in size_t r){return cel(1,0,n,l,r);}\n};\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold schwartzSort multiSort partialSort heapify join filter countUntil\n//---------------------------------------------------------------program beginning-----------------------------------------------------------------\n\nvoid main()\n{\n\tint n;\n\tloop:while(input(&n))\n\t{\n\t\treadln;\n\t\tauto a=arread!int;\n\t\tif(a.sum!=0)\n\t\t{\n\t\t\twriteln(\"YES\");\n\t\t\twriteln(1);\n\t\t\twriteln(1,' ',n);\n\t\t\tcontinue loop;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tforeach(i;1..n)\n\t\t\t{\n\t\t\t\tif(sum(a[0..i])!=0 && sum(a[i..n])!=0)\n\t\t\t\t{\n\t\t\t\t\twriteln(\"YES\");\n\t\t\t\t\twriteln(2);\n\t\t\t\t\twriteln(1,' ',i);\n\t\t\t\t\twriteln(i+1,' ',n);\n\t\t\t\t\tcontinue loop;\n\t\t\t\t}\n\t\t\t}\t\n\t\t}\n\t\twriteln(\"NO\");\n\t}\n}"}, {"source_code": "import std.bigint,std.container,std.array,std.algorithm,std.conv,\nstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\nstd.typecons,std.regex,std.random,std.uni,std.traits,std.variant;\nimport core.stdc.stdio : freopen;\nimport core.stdc.stdlib : system;\nimport std.stdio;\n//import core.stdc.stdio;\nalias RedBlackTree Rbt;\nalias redBlackTree rbt;\nalias BigInt big;\nalias pair!(int,int) pii;\nalias pair!(long,long) pll;\nalias BoyerMooreFinder strfind;\nalias make_pair mp;\nalias binary_search bins;\nalias orient_square orsq;\nimmutable int mod=1000000007;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b)\n\t{\n\t\treturn a/gcd(a,b)*b;\n\t}\n\tX binpow(X,Y)(X base,Y exp)\n\t\tif(is(typeof(exp&1)))\n\t\t{\n\t\t\tif(exp<0)return X(0);\n\t\t\tX res=X(1);\n\t\t\twhile(exp>0)\n\t\t\t{\n\t\t\t\tif(exp&1)res*=base;\n\t\t\t\tbase*=base;\n\t\t\t\texp>>=1;\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\tauto binpow(X,Y,Z)(X base,Y exp,in Z mm)\n\t\tif(is(typeof(exp&1)))\n\t\t{\n\t\t\tif(mm==0) return binpow(base,exp);\n\t\t\tif(exp<0)return X(0);\n\t\t\tauto res=X(1)%mm;\n\t\t\twhile(exp>0)\n\t\t\t{\n\t\t\t\tif(exp&1)res=(res*base)%mm;\n\t\t\t\tbase*=base;\n\t\t\t\tbase%=mm;\n\t\t\t\texp>>=1;\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tsize_t lowb(T,X)(in T a,auto ref X g) \n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(!(a[m]1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(g1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(!(a[m] 0)\n{return readf(replicate(\" %s\", ptrs.length), ptrs)==ptrs.length;}\nstruct pair(X,Y)\n{\n\tX first;\n\tY second;\n\talias first fi;\n\talias second se;\n\tthis(X a_,Y b_){\n\t\tfi=a_;\n\t\tse=b_;\n\t}\n\tthis(this){fi=fi;se=se;}\n\tthis(A,B)(auto ref pair!(A,B) p) if(is(A:X) && is(B:Y))\n\t{\n\t\tfi=p.fi;\n\t\tse=p.se;\n\t}\n\tpair!(X,Y) opAssign(A,B)(pair!(A,B) val)\n\t{\n\t\treturn this=pair!(X,Y)(val);\n\t}\n\tint opCmp(A,B)(in pair!(A,B) s_) const pure nothrow @safe \n\t\tif(is(typeof(s_.fis_.fi);\n\t\t\tif(cmp!=0)return cmp;\n\t\t\telse return (0-(ses_.se));\n\t\t}\n};\npair!(X,Y) make_pair(X,Y)(in X x_,in Y y_) pure nothrow @safe\n{\n\tpair!(X,Y) pp;\n\tpp.fi=x_;\n\tpp.se=y_;\n\treturn pp;\n}\nnothrow void inf(in char* name) {freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow void ouf(in char* name) {freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.split.map!(to!(T)).array;}\nstruct Tree(T,alias arg=\"a+b\")\n{\n\tprivate alias fun=binaryFun!arg;\n\tprivate static const uint n=int.max;\n\tprivate T[uint] t;\n\tthis(this){t=t.dup;}\n\tthis(R)(R range) if(isInputRange!R && is(ElementType!(R) : T))\n\t{\n\t\tforeach(pos,i;range) upd(pos,i);\n\t}\n\tthis(R,alias f)(Tree!(R,f) q) if(is(R:T))\n\t{\n\t\tforeach(i,j;q.t)\n\t\t{\n\t\t\tt[i]=j;\n\t\t}\n\t}\n\tTree!(T,arg) opAssign(R)(R val)\n\t{\n\t\treturn this=Tree!(T,arg)(val);\n\t}\n\tprivate void upd(in uint v,in uint vl,in uint vr,in uint i,in T x)\n\t{\n\t\tif (vr - vl == 1){t[v] = x;return;}\n\t\tuint vm = (vl + vr) >> 1;\n\t\tif(i < vm) upd(2*v, vl, vm, i, x);\n\t\telse upd(2*v+1, vm, vr, i, x);\n\t\tif(v*2+1 !in t)t[v]=t[v*2];\n\t\telse if (v*2 !in t)t[v]=t[v*2+1];\n\t\telse t[v]=fun(t[v*2],t[v*2+1]);\n\t}\n\tvoid upd(in uint i,in T x)\n\t{\n\t\tupd(1,0,n,i,x);\n\t}\n\tprivate T cel(in uint v,in uint vl,in uint vr,in uint l,in uint r)\n\t{\n\t\tif(vl==l && r==vr) return t[v];\n\t\tuint vm=(vl+vr) >> 1;\n\t\tif(r<=vm) return cel(2*v,vl,vm,l,r);\n\t\telse if(l>=vm) return cel(2*v+1,vm,vr,l,r);\n\t\telse return fun(cel(2*v,vl,vm,l,vm),cel(2*v+1,vm,vr,vm,r));\n\t}\n\tT cel(in uint l,in uint r){return cel(1,0,n,l,r);}\n};\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold schwartzSort multiSort partialSort heapify join filter\n//---------------------------------------------------------------program beginning-----------------------------------------------------------------\n\nvoid main()\n{\n\tint n;\n\twhile(input(&n))\n\t{\n\t\treadln;\n\t\tauto a=arread!int;\n\t\tif(a.sum!=0)\n\t\t{\n\t\t\twriteln(\"YES\");\n\t\t\twriteln(1);\n\t\t\twriteln(1,' ',n);\n\t\t\treturn;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tforeach(i;1..n)\n\t\t\t{\n\t\t\t\tif(sum(a[0..i])!=0 && sum(a[i..n])!=0)\n\t\t\t\t{\n\t\t\t\t\twriteln(\"YES\");\n\t\t\t\t\twriteln(2);\n\t\t\t\t\twriteln(1,' ',i);\n\t\t\t\t\twriteln(i+1,' ',n);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\t\n\t\t}\n\t\twriteln(\"NO\");\n\t}\n\tdebug system(\"pause\");\n}"}], "negative_code": [{"source_code": "import std.bigint,std.container,std.array,std.algorithm,std.conv,\nstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\nstd.typecons,std.regex,std.random,std.uni,std.traits,std.variant;\nimport core.stdc.stdio : freopen;\nimport core.stdc.stdlib : system;\nimport std.stdio;\n//import core.stdc.stdio;\nalias RedBlackTree Rbt;\nalias redBlackTree rbt;\nalias BigInt big;\nalias pair!(int,int) pii;\nalias pair!(long,long) pll;\nalias BoyerMooreFinder strfind;\nalias make_pair mp;\nalias binary_search bins;\nalias orient_square orsq;\nimmutable int mod=1000000007;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b)\n\t{\n\t\treturn a/gcd(a,b)*b;\n\t}\n\tX binpow(X,Y)(X base,Y exp)\n\t\tif(is(typeof(exp&1)))\n\t\t{\n\t\t\tif(exp<0)return X(0);\n\t\t\tX res=X(1);\n\t\t\twhile(exp>0)\n\t\t\t{\n\t\t\t\tif(exp&1)res*=base;\n\t\t\t\tbase*=base;\n\t\t\t\texp>>=1;\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\tauto binpow(X,Y,Z)(X base,Y exp,in Z mm)\n\t\tif(is(typeof(exp&1)))\n\t\t{\n\t\t\tif(mm==0) return binpow(base,exp);\n\t\t\tif(exp<0)return X(0);\n\t\t\tauto res=X(1)%mm;\n\t\t\twhile(exp>0)\n\t\t\t{\n\t\t\t\tif(exp&1)res=(res*base)%mm;\n\t\t\t\tbase*=base;\n\t\t\t\tbase%=mm;\n\t\t\t\texp>>=1;\n\t\t\t}\n\t\t\treturn res;\n\t\t}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tsize_t lowb(T,X)(in T a,auto ref X g) \n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(!(a[m]1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(g1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(!(a[m] 0)\n{return readf(replicate(\" %s\", ptrs.length), ptrs)==ptrs.length;}\nstruct pair(X,Y)\n{\n\tX first;\n\tY second;\n\talias first fi;\n\talias second se;\n\tthis(X a_,Y b_){\n\t\tfi=a_;\n\t\tse=b_;\n\t}\n\tthis(this){fi=fi;se=se;}\n\tthis(A,B)(auto ref pair!(A,B) p) if(is(A:X) && is(B:Y))\n\t{\n\t\tfi=p.fi;\n\t\tse=p.se;\n\t}\n\tpair!(X,Y) opAssign(A,B)(pair!(A,B) val)\n\t{\n\t\treturn this=pair!(X,Y)(val);\n\t}\n\tint opCmp(A,B)(in pair!(A,B) s_) const pure nothrow @safe \n\t\tif(is(typeof(s_.fis_.fi);\n\t\t\tif(cmp!=0)return cmp;\n\t\t\telse return (0-(ses_.se));\n\t\t}\n};\npair!(X,Y) make_pair(X,Y)(in X x_,in Y y_) pure nothrow @safe\n{\n\tpair!(X,Y) pp;\n\tpp.fi=x_;\n\tpp.se=y_;\n\treturn pp;\n}\nnothrow void inf(in char* name) {freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow void ouf(in char* name) {freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.split.map!(to!(T)).array;}\nstruct Tree(T,alias arg=\"a+b\")\n{\n\tprivate alias fun=binaryFun!arg;\n\tprivate static const uint n=int.max;\n\tprivate T[uint] t;\n\tthis(this){t=t.dup;}\n\tthis(R)(R range) if(isInputRange!R && is(ElementType!(R) : T))\n\t{\n\t\tforeach(pos,i;range) upd(pos,i);\n\t}\n\tthis(R,alias f)(Tree!(R,f) q) if(is(R:T))\n\t{\n\t\tforeach(i,j;q.t)\n\t\t{\n\t\t\tt[i]=j;\n\t\t}\n\t}\n\tTree!(T,arg) opAssign(R)(R val)\n\t{\n\t\treturn this=Tree!(T,arg)(val);\n\t}\n\tprivate void upd(in uint v,in uint vl,in uint vr,in uint i,in T x)\n\t{\n\t\tif (vr - vl == 1){t[v] = x;return;}\n\t\tuint vm = (vl + vr) >> 1;\n\t\tif(i < vm) upd(2*v, vl, vm, i, x);\n\t\telse upd(2*v+1, vm, vr, i, x);\n\t\tif(v*2+1 !in t)t[v]=t[v*2];\n\t\telse if (v*2 !in t)t[v]=t[v*2+1];\n\t\telse t[v]=fun(t[v*2],t[v*2+1]);\n\t}\n\tvoid upd(in uint i,in T x)\n\t{\n\t\tupd(1,0,n,i,x);\n\t}\n\tprivate T cel(in uint v,in uint vl,in uint vr,in uint l,in uint r)\n\t{\n\t\tif(vl==l && r==vr) return t[v];\n\t\tuint vm=(vl+vr) >> 1;\n\t\tif(r<=vm) return cel(2*v,vl,vm,l,r);\n\t\telse if(l>=vm) return cel(2*v+1,vm,vr,l,r);\n\t\telse return fun(cel(2*v,vl,vm,l,vm),cel(2*v+1,vm,vr,vm,r));\n\t}\n\tT cel(in uint l,in uint r){return cel(1,0,n,l,r);}\n};\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold schwartzSort multiSort partialSort heapify join filter\n//---------------------------------------------------------------program beginning-----------------------------------------------------------------\n\nvoid main()\n{\n\tint n;\n\twhile(input(&n))\n\t{\n\t\treadln;\n\t\tauto a=arread!int;\n\t\tif(a.sum!=0)\n\t\t{\n\t\t\twriteln(\"YES\");\n\t\t\twriteln(1);\n\t\t\twriteln(1,' ',n);\n\t\t\treturn;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tforeach(i;1..n-1)\n\t\t\t{\n\t\t\t\tif(sum(a[0..i])!=0 && sum(a[i..n])!=0)\n\t\t\t\t{\n\t\t\t\t\twriteln(\"YES\");\n\t\t\t\t\twriteln(2);\n\t\t\t\t\twriteln(1,' ',i);\n\t\t\t\t\twriteln(i+1,' ',n);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\t\n\t\t}\n\t\twriteln(\"NO\");\n\t}\n\tdebug system(\"pause\");\n}"}], "src_uid": "3a9258070ff179daf33a4515def9897a"} {"nl": {"description": "Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw $$$n$$$ squares in the snow with a side length of $$$1$$$. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length $$$1$$$, parallel to the coordinate axes, with vertices at integer points.In order to draw a segment, Sofia proceeds as follows. If she wants to draw a vertical segment with the coordinates of the ends $$$(x, y)$$$ and $$$(x, y+1)$$$. Then Sofia looks if there is already a drawn segment with the coordinates of the ends $$$(x', y)$$$ and $$$(x', y+1)$$$ for some $$$x'$$$. If such a segment exists, then Sofia quickly draws a new segment, using the old one as a guideline. If there is no such segment, then Sofia has to take a ruler and measure a new segment for a long time. Same thing happens when Sofia wants to draw a horizontal segment, but only now she checks for the existence of a segment with the same coordinates $$$x$$$, $$$x+1$$$ and the differing coordinate $$$y$$$.For example, if Sofia needs to draw one square, she will have to draw two segments using a ruler: After that, she can draw the remaining two segments, using the first two as a guide: If Sofia needs to draw two squares, she will have to draw three segments using a ruler: After that, she can draw the remaining four segments, using the first three as a guide: Sofia is in a hurry, so she wants to minimize the number of segments that she will have to draw with a ruler without a guide. Help her find this minimum number.", "input_spec": "The only line of input contains a single integer $$$n$$$ ($$$1 \\le n \\le 10^{9}$$$), the number of squares that Sofia wants to draw.", "output_spec": "Print single integer, the minimum number of segments that Sofia will have to draw with a ruler without a guide in order to draw $$$n$$$ squares in the manner described above.", "sample_inputs": ["1", "2", "4"], "sample_outputs": ["2", "3", "4"], "notes": null}, "positive_code": [{"source_code": "import std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.format;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n long n = readln.strip.to!long;\n\n long l = 0, r = 200_000;\n while (r - l > 1) {\n long m = (l + r) / 2;\n if (m/2 * (m-m/2) >= n) {\n r = m;\n } else {\n l = m;\n }\n }\n\n writeln(r);\n}\n"}], "negative_code": [], "src_uid": "eb8212aec951f8f69b084446da73eaf7"} {"nl": {"description": "InputThe input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive.OutputOutput \"YES\" or \"NO\".ExamplesInput\nGENIUS\nOutput\nYES\nInput\nDOCTOR\nOutput\nNO\nInput\nIRENE\nOutput\nYES\nInput\nMARY\nOutput\nNO\nInput\nSMARTPHONE\nOutput\nNO\nInput\nREVOLVER\nOutput\nYES\nInput\nHOLMES\nOutput\nNO\nInput\nWATSON\nOutput\nYES\n", "input_spec": "The input consists of a single string of uppercase letters A-Z. The length of the string is between 1 and 10 characters, inclusive.", "output_spec": "Output \"YES\" or \"NO\".", "sample_inputs": ["GENIUS", "DOCTOR", "IRENE", "MARY", "SMARTPHONE", "REVOLVER", "HOLMES", "WATSON"], "sample_outputs": ["YES", "NO", "YES", "NO", "NO", "YES", "NO", "YES"], "notes": null}, "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nenum DATA = q\"EOS\n1\tH\tHYDROGEN\n2\tHE\tHELIUM\n3\tLI\tLITHIUM\n4\tBE\tBERYLLIUM\n5\tB\tBORON\n6\tC\tCARBON\n7\tN\tNITROGEN\n8\tO\tOXYGEN\n9\tF\tFLUORINE\n10\tNE\tNEON\n11\tNA\tSODIUM\n12\tMG\tMAGNESIUM\n13\tAL\tALUMINUM\n14\tSI\tSILICON\n15\tP\tPHOSPHORUS\n16\tS\tSULFUR\n17\tCL\tCHLORINE\n18\tAR\tARGON\n19\tK\tPOTASSIUM\n20\tCA\tCALCIUM\n21\tSC\tSCANDIUM\n22\tTI\tTITANIUM\n23\tV\tVANADIUM\n24\tCR\tCHROMIUM\n25\tMN\tMANGANESE\n26\tFE\tIRON\n27\tCO\tCOBALT\n28\tNI\tNICKEL\n29\tCU\tCOPPER\n30\tZN\tZINC\n31\tGA\tGALLIUM\n32\tGE\tGERMANIUM\n33\tAS\tARSENIC\n34\tSE\tSELENIUM\n35\tBR\tBROMINE\n36\tKR\tKRYPTON\n37\tRB\tRUBIDIUM\n38\tSR\tSTRONTIUM\n39\tY\tYTTRIUM\n40\tZR\tZIRCONIUM\n41\tNB\tNIOBIUM\n42\tMO\tMOLYBDENUM\n43\tTC\tTECHNETIUM\n44\tRU\tRUTHENIUM\n45\tRH\tRHODIUM\n46\tPD\tPALLADIUM\n47\tAG\tSILVER\n48\tCD\tCADMIUM\n49\tIN\tINDIUM\n50\tSN\tTIN\n51\tSB\tANTIMONY\n52\tTE\tTELLURIUM\n53\tI\tIODINE\n54\tXE\tXENON\n55\tCS\tCESIUM\n56\tBA\tBARIUM\n57\tLA\tLANTHANUM\n58\tCE\tCERIUM\n59\tPR\tPRASEODYMIUM\n60\tND\tNEODYMIUM\n61\tPM\tPROMETHIUM\n62\tSM\tSAMARIUM\n63\tEU\tEUROPIUM\n64\tGD\tGADOLINIUM\n65\tTB\tTERBIUM\n66\tDY\tDYSPROSIUM\n67\tHO\tHOLMIUM\n68\tER\tERBIUM\n69\tTM\tTHULIUM\n70\tYB\tYTTERBIUM\n71\tLU\tLUTETIUM\n72\tHF\tHAFNIUM\n73\tTA\tTANTALUM\n74\tW\tTUNGSTEN\n75\tRE\tRHENIUM\n76\tOS\tOSMIUM\n77\tIR\tIRIDIUM\n78\tPT\tPLATINUM\n79\tAU\tGOLD\n80\tHG\tMERCURY\n81\tTL\tTHALLIUM\n82\tPB\tLEAD\n83\tBI\tBISMUTH\n84\tPO\tPOLONIUM\n85\tAT\tASTATINE\n86\tRN\tRADON\n87\tFR\tFRANCIUM\n88\tRA\tRADIUM\n89\tAC\tACTINIUM\n90\tTH\tTHORIUM\n91\tPA\tPROTACTINIUM\n92\tU\tURANIUM\n93\tNP\tNEPTUNIUM\n94\tPU\tPLUTONIUM\n95\tAM\tAMERICIUM\n96\tCM\tCURIUM\n97\tBK\tBERKELIUM\n98\tCF\tCALIFORNIUM\n99\tES\tEINSTEINIUM\n100\tFM\tFERMIUM\n101\tMD\tMENDELEVIUM\n102\tNO\tNOBELIUM\n103\tLR\tLAWRENCIUM\n104\tRF\tRUTHERFORDIUM\n105\tDB\tDUBNIUM\n106\tSG\tSEABORGIUM\n107\tBH\tBOHRIUM\n108\tHS\tHASSIUM\n109\tMT\tMEITNERIUM\n110\tDS\tDARMSTADTIUM\n111\tRG\tROENTGENIUM\n112\tCN\tCOPERNICIUM\n113\tNH\tNIHONIUM\n114\tFL\tFLEROVIUM\n115\tMC\tMOSCOVIUM\n116\tLV\tLIVERMORIUM\n117\tTS\tTENNESSINE\n118\tOG\tOGANESSON\nEOS\";\n\nvoid main() {\n bool[string] el;\n const tokens = DATA.split;\n for (int i = 1; i < tokens.length; i += 3) {\n el[tokens[i]] = true;\n }\n \n try {\n for (; ; ) {\n const S = readToken();\n auto L = cast(int)(S.length);\n \n auto dp = new bool[L + 1];\n dp[0] = true;\n foreach (i; 0 .. L) {\n if (dp[i]) {\n foreach (j; [i + 1, i + 2]) {\n if (j <= L) {\n if (S[i .. j] in el) {\n dp[j] = true;\n }\n }\n }\n }\n }\n writeln(dp[L] ? \"YES\" : \"NO\");\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "d0ad35798119f98320967127c43ae88d"} {"nl": {"description": "There was once young lass called Mary, Whose jokes were occasionally scary. On this April's Fool Fixed limerick rules Allowed her to trip the unwary.Can she fill all the linesTo work at all times?On juggling the wordsRight around two-thirdsShe nearly ran out of rhymes.", "input_spec": "The input contains a single integer $$$a$$$ ($$$4 \\le a \\le 998$$$). Not every integer in the range is a valid input for the problem; you are guaranteed that the input will be a valid integer.", "output_spec": "Output a single number.", "sample_inputs": ["35", "57", "391"], "sample_outputs": ["57", "319", "1723"], "notes": null}, "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf !(\" %s\") (n) > 0)\n\t{\n\t\tfor (int i = 2; i * i <= n; i++)\n\t\t{\n\t\t\tif (n % i == 0)\n\t\t\t{\n\t\t\t\twriteln (i, n / i);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const A = readInt();\n int a = A;\n for (int p = 2; p <= a; ++p) {\n for (; a % p == 0; ) {\n write(p);\n a /= p;\n }\n }\n writeln();\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "7220f2da5081547a12118595bbeda4f6"} {"nl": {"description": "Several ages ago Berland was a kingdom. The King of Berland adored math. That's why, when he first visited one of his many palaces, he first of all paid attention to the floor in one hall. The floor was tiled with hexagonal tiles.The hall also turned out hexagonal in its shape. The King walked along the perimeter of the hall and concluded that each of the six sides has a, b, c, a, b and c adjacent tiles, correspondingly.To better visualize the situation, look at the picture showing a similar hexagon for a\u2009=\u20092, b\u2009=\u20093 and c\u2009=\u20094. According to the legend, as the King of Berland obtained the values a, b and c, he almost immediately calculated the total number of tiles on the hall floor. Can you do the same?", "input_spec": "The first line contains three integers: a, b and c (2\u2009\u2264\u2009a,\u2009b,\u2009c\u2009\u2264\u20091000).", "output_spec": "Print a single number \u2014 the total number of tiles on the hall floor.", "sample_inputs": ["2 3 4"], "sample_outputs": ["18"], "notes": null}, "positive_code": [{"source_code": "import std.stdio;\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n int a, b, c;\n readf(\" %s %s %s\\n\", &a, &b, &c);\n int answer = 7;\n answer += (a - 2) * (2 + 2 - 1);\n answer += (b - 2) * (a + 2 - 1);\n answer += (c - 2) * (a + b - 1);\n writeln(answer);\n \n return 0;\n}"}, {"source_code": "module cf_216A;\n\nimport std.stdio;\n\nvoid main() {\n int a, b, c;\n\n readf(\"%d %d %d\", &a, &b, &c);\n\n int count = c * (a + b - 1) + (a - 1) * (b - 1);\n writeln(count);\n}"}], "negative_code": [{"source_code": "module cf_216A;\n\nimport std.stdio;\n\nvoid main() {\n int a, b, c;\n\n readf(\"%d %d %d\", &a, &b, &c);\n writeln(2 * (a + b + c));\n}"}], "src_uid": "8ab25ed4955d978fe20f6872cb94b0da"} {"nl": {"description": "Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are n lanes of m desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to n from the left to the right, the desks in a lane are numbered from 1 to m starting from the blackboard. Note that the lanes go perpendicularly to the blackboard, not along it (see picture).The organizers numbered all the working places from 1 to 2nm. The places are numbered by lanes (i.\u00a0e. all the places of the first lane go first, then all the places of the second lane, and so on), in a lane the places are numbered starting from the nearest to the blackboard (i.\u00a0e. from the first desk in the lane), at each desk, the place on the left is numbered before the place on the right. The picture illustrates the first and the second samples. Santa Clause knows that his place has number k. Help him to determine at which lane at which desk he should sit, and whether his place is on the left or on the right!", "input_spec": "The only line contains three integers n, m and k (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u200910\u2009000, 1\u2009\u2264\u2009k\u2009\u2264\u20092nm)\u00a0\u2014 the number of lanes, the number of desks in each lane and the number of Santa Claus' place.", "output_spec": "Print two integers: the number of lane r, the number of desk d, and a character s, which stands for the side of the desk Santa Claus. The character s should be \"L\", if Santa Clause should sit on the left, and \"R\" if his place is on the right.", "sample_inputs": ["4 3 9", "4 3 24", "2 4 4"], "sample_outputs": ["2 2 L", "4 3 R", "1 2 R"], "notes": "NoteThe first and the second samples are shown on the picture. The green place corresponds to Santa Claus' place in the first example, the blue place corresponds to Santa Claus' place in the second example.In the third sample there are two lanes with four desks in each, and Santa Claus has the fourth place. Thus, his place is in the first lane at the second desk on the right."}, "positive_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\nimport std.algorithm;\nimport std.range;\nimport std.file;\n\nvoid main(string[] args)\n{\n auto s = map!(to!int)(readln.strip.split);\n auto d = s[1] * 2;\n int n = 1;\n while(n <= s[0])\n {\n auto des = d * n;\n if (des >= s[2])\n break;\n n++;\n }\n\n auto p = (n -1) * s[1] * 2;\n if (s[2] % 2 == 0)\n {\n auto m = (s[2] - p) / 2;\n writeln(n, \" \", m, \" R\");\n }\n else\n {\n auto m = ((s[2] + 1) - p) / 2;\n writeln(n, \" \", m, \" L\");\n }\n\n}"}], "negative_code": [], "src_uid": "d6929926b44c2d5b1a8e6b7f965ca1bb"} {"nl": {"description": "A new delivery of clothing has arrived today to the clothing store. This delivery consists of $$$a$$$ ties, $$$b$$$ scarves, $$$c$$$ vests and $$$d$$$ jackets.The store does not sell single clothing items \u2014 instead, it sells suits of two types: a suit of the first type consists of one tie and one jacket; a suit of the second type consists of one scarf, one vest and one jacket. Each suit of the first type costs $$$e$$$ coins, and each suit of the second type costs $$$f$$$ coins.Calculate the maximum possible cost of a set of suits that can be composed from the delivered clothing items. Note that one item cannot be used in more than one suit (though some items may be left unused).", "input_spec": "The first line contains one integer $$$a$$$ $$$(1 \\le a \\le 100\\,000)$$$ \u2014 the number of ties. The second line contains one integer $$$b$$$ $$$(1 \\le b \\le 100\\,000)$$$ \u2014 the number of scarves. The third line contains one integer $$$c$$$ $$$(1 \\le c \\le 100\\,000)$$$ \u2014 the number of vests. The fourth line contains one integer $$$d$$$ $$$(1 \\le d \\le 100\\,000)$$$ \u2014 the number of jackets. The fifth line contains one integer $$$e$$$ $$$(1 \\le e \\le 1\\,000)$$$ \u2014 the cost of one suit of the first type. The sixth line contains one integer $$$f$$$ $$$(1 \\le f \\le 1\\,000)$$$ \u2014 the cost of one suit of the second type.", "output_spec": "Print one integer \u2014 the maximum total cost of some set of suits that can be composed from the delivered items. ", "sample_inputs": ["4\n5\n6\n3\n1\n2", "12\n11\n13\n20\n4\n6", "17\n14\n5\n21\n15\n17"], "sample_outputs": ["6", "102", "325"], "notes": "NoteIt is possible to compose three suits of the second type in the first example, and their total cost will be $$$6$$$. Since all jackets will be used, it's impossible to add anything to this set.The best course of action in the second example is to compose nine suits of the first type and eleven suits of the second type. The total cost is $$$9 \\cdot 4 + 11 \\cdot 6 = 102$$$."}, "positive_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto a = RD!int;\n\tauto b = RD!int;\n\tauto c = RD!int;\n\tauto d = RD!int;\n\tauto e = RD!int;\n\tauto f = RD!int;\n\tlong ans1, ans2;\n\t{\n\t\tauto aa = a;\n\t\tauto bb = b;\n\t\tauto cc = c;\n\t\tauto dd = d;\n\t\tauto ad = min(aa, dd);\n\t\tans1 += ad * e;\n\t\taa -= ad;\n\t\tdd -= ad;\n\t\tauto bcd = min(bb, cc, dd);\n\t\tans1 += bcd * f;\n\t}\n\t{\n\t\tauto aa = a;\n\t\tauto bb = b;\n\t\tauto cc = c;\n\t\tauto dd = d;\n\t\tauto bcd = min(bb, cc, dd);\n\t\tans2 += bcd * f;\n\t\tbb -= bcd;\n\t\tcc -= bcd;\n\t\tdd -= bcd;\n\t\tauto ad = min(aa, dd);\n\t\tans2 += ad * e;\n\t}\n\twriteln(max(ans1, ans2));\n\tstdout.flush;\n\tdebug readln;\n}"}], "negative_code": [], "src_uid": "84d9e7e9c9541d997e6573edb421ae0a"} {"nl": {"description": "You have two variables a and b. Consider the following sequence of actions performed with these variables: If a\u2009=\u20090 or b\u2009=\u20090, end the process. Otherwise, go to step 2; If a\u2009\u2265\u20092\u00b7b, then set the value of a to a\u2009-\u20092\u00b7b, and repeat step 1. Otherwise, go to step 3; If b\u2009\u2265\u20092\u00b7a, then set the value of b to b\u2009-\u20092\u00b7a, 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\u2009\u2264\u2009n,\u2009m\u2009\u2264\u20091018). n is the initial value of variable a, and m is the initial value of variable b.", "output_spec": "Print two integers \u2014 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\u2009=\u200912, b\u2009=\u20095 a\u2009=\u20092, b\u2009=\u20095 a\u2009=\u20092, b\u2009=\u20091 a\u2009=\u20090, b\u2009=\u20091; a\u2009=\u200931, b\u2009=\u200912 a\u2009=\u20097, b\u2009=\u200912."}, "positive_code": [{"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n import std.exception, std.random;\n\n long a, b; rd(a, b);\n // auto rnd=Random(unpredictableSeed);\n // long a=uniform(1, 100, rnd), b=uniform(1, 100, rnd);\n\n while(a>0 && b>0){\n if(a>=b*2){\n auto m=a/b;\n if(m&1) m--;\n enforce(m>=2);\n a-=b*m;\n }else if(a*2<=b){\n auto m=b/a;\n if(m&1) m--;\n enforce(m>=2);\n b-=a*m;\n }else{\n break;\n }\n }\n \n writeln(a, \" \", b);\n // f(a, b);\n}\n\nvoid f(long a, long b){\n import std.stdio;\n while(a>0 && b>0){\n if(a>=b*2) a-=b*2;\n else if(a*2<=b) b-=a*2;\n else break;\n }\n writeln(a, \" \", b);\n}\n\nvoid rd(T...)(ref T x){\n import std.stdio, std.string, std.conv;\n auto l=readln.split;\n assert(l.length==x.length);\n foreach(i, ref e; x){\n e=l[i].to!(typeof(e));\n }\n}"}], "negative_code": [], "src_uid": "1f505e430eb930ea2b495ab531274114"} {"nl": {"description": "Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word.Hongcow has decided to try to make new words from this one. He starts by taking the word he just learned how to spell, and moves the last character of the word to the beginning of the word. He calls this a cyclic shift. He can apply cyclic shift many times. For example, consecutively applying cyclic shift operation to the word \"abracadabra\" Hongcow will get words \"aabracadabr\", \"raabracadab\" and so on.Hongcow is now wondering how many distinct words he can generate by doing the cyclic shift arbitrarily many times. The initial string is also counted.", "input_spec": "The first line of input will be a single string s (1\u2009\u2264\u2009|s|\u2009\u2264\u200950), the word Hongcow initially learns how to spell. The string s consists only of lowercase English letters ('a'\u2013'z').", "output_spec": "Output a single integer equal to the number of distinct strings that Hongcow can obtain by applying the cyclic shift arbitrarily many times to the given string.", "sample_inputs": ["abcd", "bbb", "yzyz"], "sample_outputs": ["4", "1", "2"], "notes": "NoteFor the first sample, the strings Hongcow can generate are \"abcd\", \"dabc\", \"cdab\", and \"bcda\".For the second sample, no matter how many times Hongcow does the cyclic shift, Hongcow can only generate \"bbb\".For the third sample, the two strings Hongcow can generate are \"yzyz\" and \"zyzy\"."}, "positive_code": [{"source_code": "module main;\nimport std.bigint,std.container,std.array,std.algorithm,std.conv,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.variant;\nimport core.stdc.stdio : freopen;\nimport core.stdc.stdlib : system;\nimport std.stdio;\n//import core.stdc.stdio;\nalias RedBlackTree Rbt;\nalias redBlackTree rbt;\nalias BigInt big;\nalias pair!(int,int) pii;\nalias pair!(long,long) pll;\nalias BoyerMooreFinder strfind;\nalias mp=make_pair;\nalias bins=binary_search;\nalias orsq=orient_square;\nimmutable int mod=1000000007;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b)\n\t{\n\t\treturn a/gcd(a,b)*b;\n\t}\n\tX binpow(X,Y)(X base,Y exp)\n\t\tif(is(typeof(exp&1)))\n\t{\n\t\tif(exp<0)return X(0);\n\t\tX res=X(1);\n\t\twhile(exp>0)\n\t\t{\n\t\t\tif(exp&1)res*=base;\n\t\t\tbase*=base;\n\t\t\texp>>=1;\n\t\t}\n\t\treturn res;\n\t}\n\tauto binpow(X,Y,Z)(X base,Y exp,in Z mm)\n\t\tif(is(typeof(exp&1)))\n\t{\n\t\tif(mm==0) return binpow(base,exp);\n\t\tif(exp<0)return X(0);\n\t\tauto res=X(1)%mm;\n\t\twhile(exp>0)\n\t\t{\n\t\t\tif(exp&1)res=(res*base)%mm;\n\t\t\tbase*=base;\n\t\t\tbase%=mm;\n\t\t\texp>>=1;\n\t\t}\n\t\treturn res;\n\t}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tsize_t lowb(T,X)(in T a,auto ref X g) \n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 0)\n{return readf(replicate(\" %s\", ptrs.length), ptrs)==ptrs.length;}\nstruct pair(X,Y)\n{\n\tX first;\n\tY second;\n\talias first fi;\n\talias second se;\n\tthis(X a_,Y b_){\n\t\tfi=a_;\n\t\tse=b_;\n\t}\n\tthis(this){fi=fi;se=se;}\n\tthis(A,B)(auto ref pair!(A,B) p) if(is(A:X) && is(B:Y))\n\t{\n\t\tfi=p.fi;\n\t\tse=p.se;\n\t}\n\tpair!(X,Y) opAssign(A,B)(pair!(A,B) val)\n\t{\n\t\treturn this=pair!(X,Y)(val);\n\t}\n\tint opCmp(A,B)(in pair!(A,B) s_) const pure nothrow @safe \n\t\tif(is(typeof(s_.fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.se));\n\t}\n};\npair!(X,Y) make_pair(X,Y)(in X x_,in Y y_) pure nothrow @safe\n{\n\tpair!(X,Y) pp;\n\tpp.fi=x_;\n\tpp.se=y_;\n\treturn pp;\n}\nnothrow void inf(in char* name) {freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow void ouf(in char* name) {freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.split.map!(to!(T)).array;}\nstruct Tree(T,alias arg=\"a+b\")\n{\n\tprivate alias fun=binaryFun!arg;\n\tprivate static const size_t n=size_t.max>>1;\n\tprivate T[size_t] t;\n\tthis(this){t=t.dup;}\n\tthis(R)(R range) if(isInputRange!R && is(ElementType!(R) : T))\n\t{\n\t\tforeach(pos,i;range) upd(pos,i);\n\t}\n\tthis(R,alias f)(Tree!(R,f) q) if(is(R:T))\n\t{\n\t\tforeach(i,j;q.t)\n\t\t{\n\t\t\tt[i]=j;\n\t\t}\n\t}\n\tTree!(T,arg) opAssign(R)(R val)\n\t{\n\t\treturn this=Tree!(T,arg)(val);\n\t}\n\tprivate void upd(in size_t v,in size_t vl,in size_t vr,in size_t i,in T x)\n\t{\n\t\tif (vr - vl == 1){t[v] = x;return;}\n\t\tsize_t vm = (vl + vr) >> 1;\n\t\tif(i < vm) upd(2*v, vl, vm, i, x);\n\t\telse upd(2*v+1, vm, vr, i, x);\n\t\tif(v*2+1 !in t)t[v]=t[v*2];\n\t\telse if (v*2 !in t)t[v]=t[v*2+1];\n\t\telse t[v]=fun(t[v*2],t[v*2+1]);\n\t}\n\tvoid upd(in size_t i,in T x)\n\t{\n\t\tupd(1,0,n,i,x);\n\t}\n\tprivate T cel(in size_t v,in size_t vl,in size_t vr,in size_t l,in size_t r)\n\t{\n\t\tif(vl==l && r==vr) return t[v];\n\t\tsize_t vm=(vl+vr) >> 1;\n\t\tif(r<=vm) return cel(2*v,vl,vm,l,r);\n\t\telse if(l>=vm) return cel(2*v+1,vm,vr,l,r);\n\t\telse return fun(cel(2*v,vl,vm,l,vm),cel(2*v+1,vm,vr,vm,r));\n\t}\n\tT cel(in size_t l,in size_t r){return cel(1,0,n,l,r);}\n};\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold schwartzSort multiSort partialSort heapify join filter countUntil\n//---------------------------------------------------------------program beginning-----------------------------------------------------------------\n\nvoid main()\n{\n\tstring n;\n\tloop:while((n=readln.strip)!=\"\")\n\t{\n\t\tint[string] q;\n\t\tforeach(i;0..n.length+1)\n\t\t{\n\t\t\tq[n]++;\n\t\t\tn=n[$-1]~n[0..$-1];\n\t\t}\n\t\twriteln(q.length);\n\t}\n}"}], "negative_code": [], "src_uid": "8909ac99ed4ab2ee4d681ec864c7831e"} {"nl": {"description": "Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a \"Double Cola\" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum.For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny.Write a program that will print the name of a man who will drink the n-th can.Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon.", "input_spec": "The input data consist of a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009109). It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers.", "output_spec": "Print the single line \u2014 the name of the person who drinks the n-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: \"Sheldon\", \"Leonard\", \"Penny\", \"Rajesh\", \"Howard\" (without the quotes). In that order precisely the friends are in the queue initially.", "sample_inputs": ["1", "6", "1802"], "sample_outputs": ["Sheldon", "Sheldon", "Penny"], "notes": null}, "positive_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\nimport std.algorithm;\nimport std.array;\nimport std.range;\n\n/// solve ==========================\nstring solve(int n){\n\n string[] persons = [\"Sheldon\", \"Leonard\", \"Penny\", \"Rajesh\", \"Howard\"];\n int times;\n int start;\n string res;\n int personNum;\n \n auto xs = recurrence!(\"(a[n-1] + (a[n-1] - a[n-2])*2)\")(1, 6);\n foreach(x; xs){\n if(x > n) break;\n start = x;\n times += 1;\n }\n personNum = (n - start) / (2^^(times-1));\n res = persons[personNum].to!string;\n return res;\n}\n\n/// main ====================\nvoid main(){\n auto n = readln.strip.to!int;\n solve(n).writeln;\n}\n"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\nimport std.algorithm;\nimport std.array;\nimport std.range;\n\nstring solve(int n){\n\n string[] names = [\"Sheldon\", \"Leonard\", \"Penny\", \"Rajesh\", \"Howard\"];\n int times;\n int start;\n string res;\n int modN;\n \n /// solve ==========================\n auto xs = recurrence!(\"(a[n-1] + (a[n-1] - a[n-2])*2)\")(1, 6);\n foreach(x; xs){\n if(x > n) break;\n start = x;\n times += 1;\n }\n modN = (n - start) / (2^^(times-1));\n res = names[modN].to!string;\n return res;\n}\n\n/// unittest -------------------\nunittest{\n assert( solve(1) == \"S\" );\n assert( solve(6) == \"S\" );\n assert( solve(1802) == \"P\" );\n writeln(\"---pass ---\");\n}\n\n/// main ====================\nvoid main(){\n auto n = readln.strip.to!int;\n solve(n).writeln;\n}"}, {"source_code": "import std.stdio;\nimport std.conv : to;\n\nimmutable names = [\"Sheldon\", \"Leonard\", \"Penny\", \"Rajesh\", \"Howard\"];\n\nvoid main()\n{\n ulong num;\n readf(\"%s\", &num);\n \n ulong groupSize = 5;\n \n while(true)\n {\n if (num <= groupSize)\n {\n names[cast(uint)((num-1)/(groupSize/5))].writeln;\n break;\n }\n \n num -= groupSize;\n groupSize *= 2;\n }\n}"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\n\nvoid main()\n{\n auto n = stdin.readln.strip.to!int;\n int m=0, j=0;\n for(int i=1; i<=n; i+=5*(2^^j),j++) m=i;\n write([\"Sheldon\", \"Leonard\", \"Penny\", \"Rajesh\", \"Howard\"][(n-m)/(2^^(--j))]);\n}"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm;\nimport core.stdc.stdio;\nimport std.bigint;\nimport std.format;\nimport std.math;\n\nstring readline()\n{\n\tstring result = readln();\n\tif (result[result.length - 1] == '\\n') result.length--;\n\treturn result;\n}\n\nint main(string[] argv)\n{\n\tlong n;\n\tscanf(\"%d\", &n); n--;\n\tlong pm = 0;\n\tlong m = 1;\n\twhile ((pm + m * 5) <= n)\n\t{\n\t\tpm += m * 5;\n\t\tm = m * 2;\n\t}\n\n\tlong l = (n - pm) / m;\n\n\tstring[long] names;\n\tnames[0] = \"Sheldon\";\n\tnames[1] = \"Leonard\";\n\tnames[2] = \"Penny\";\n\tnames[3] = \"Rajesh\";\n\tnames[4] = \"Howard\";\n\twrite(names[l]);\n\treturn 0;\n}\n"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\nimport std.array;\nimport std.range;\nimport std.algorithm;\nimport std.container;\nimport std.math;\n\nvoid main() {\n string[] p = [\"Sheldon\", \"Leonard\", \"Penny\", \"Rajesh\", \"Howard\"];\n int n = readln.chomp.to!int;\n n--;\n while (n >= 5) {\n n -= 5;\n n /= 2;\n }\n writeln(p[n]);\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\nimport std.algorithm;\nimport std.array;\nimport std.range;\n\nstring solve(int n){\n\n string names = \"SLPRH\";\n int times;\n int start;\n string res;\n int modN;\n \n /// solve ==========================\n auto xs = recurrence!(\"(a[n-1] + (a[n-1] - a[n-2])*2)\")(1, 6);\n foreach(x; xs){\n if(x > n) break;\n start = x;\n times += 1;\n }\n modN = (n - start) / (2^^(times-1));\n res = names[modN].to!string;\n return res;\n}\n\n/// unittest -------------------\nunittest{\n assert( solve(1) == \"S\" );\n assert( solve(6) == \"S\" );\n assert( solve(1802) == \"P\" );\n writeln(\"---pass ---\");\n}\n\n/// main ====================\nvoid main(){\n foreach(i; 1..25){\n writeln(i, \" \", solve(i));\n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm;\nimport core.stdc.stdio;\nimport std.bigint;\nimport std.format;\nimport std.math;\n\nstring readline()\n{\n\tstring result = readln();\n\tif (result[result.length - 1] == '\\n') result.length--;\n\treturn result;\n}\n\nint main(string[] argv)\n{\n\tlong n;\n\tscanf(\"%d\", &n); n--;\n\tlong pm = 0;\n\tlong m = 1;\n\twhile (pm + m * 5 <= n)\n\t{\n\t\tpm = pm + m * 5;\n\t\tm++;\n\t}\n\tdouble l = cast(double)(n - pm) / cast(double)(m);\n\n\tstring[long] names;\n\tnames[0] = \"Sheldon\";\n\tnames[1] = \"Leonard\";\n\tnames[2] = \"Penny\";\n\tnames[3] = \"Rajesh\";\n\tnames[4] = \"Howard\";\n\twrite(names[cast(long)round(l)]);\n\treturn 0;\n}\n"}], "src_uid": "023b169765e81d896cdc1184e5a82b22"} {"nl": {"description": "Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of L meters today. Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner. While watching previous races the organizers have noticed that Willman can perform only steps of length equal to w meters, and Bolt can perform only steps of length equal to b meters. Organizers decided to slightly change the rules of the race. Now, at the end of the racetrack there will be an abyss, and the winner will be declared the athlete, who manages to run farther from the starting point of the the racetrack (which is not the subject to change by any of the athletes). Note that none of the athletes can run infinitely far, as they both will at some moment of time face the point, such that only one step further will cause them to fall in the abyss. In other words, the athlete will not fall into the abyss if the total length of all his steps will be less or equal to the chosen distance L.Since the organizers are very fair, the are going to set the length of the racetrack as an integer chosen randomly and uniformly in range from 1 to t (both are included). What is the probability that Willman and Bolt tie again today?", "input_spec": "The first line of the input contains three integers t, w and b (1\u2009\u2264\u2009t,\u2009w,\u2009b\u2009\u2264\u20095\u00b71018) \u2014 the maximum possible length of the racetrack, the length of Willman's steps and the length of Bolt's steps respectively.", "output_spec": "Print the answer to the problem as an irreducible fraction . Follow the format of the samples output. The fraction (p and q are integers, and both p\u2009\u2265\u20090 and q\u2009>\u20090 holds) is called irreducible, if there is no such integer d\u2009>\u20091, that both p and q are divisible by d.", "sample_inputs": ["10 3 2", "7 1 2"], "sample_outputs": ["3/10", "3/7"], "notes": "NoteIn the first sample Willman and Bolt will tie in case 1, 6 or 7 are chosen as the length of the racetrack."}, "positive_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\nimport std.bigint;\nimport std.algorithm;\n\nBigInt gcd(BigInt a, BigInt b) {\n return (a % b != 0) ? gcd(b, a % b) : b;\n}\n\nBigInt lcm(BigInt a, BigInt b) {\n return a * b / gcd(a,b);\n}\n\nvoid main() {\n string s[] = split(readln());\n BigInt t = s[0];\n BigInt w = s[1];\n BigInt b = s[2];\n\n BigInt LCM = lcm(w,b);\n BigInt cnt = t / LCM;\n BigInt p, q;\n // \u306a\u305c\u3053\u308c\u306b\u6c17\u3065\u304b\u306a\u304b\u3063\u305f\u306e\u304b\n // p = min(w,b)-1;\n p = min(t, min(w,b)-1);\n if(cnt > 0)\n p += (cnt-1) * min(w,b) + min(min(w,b), t % LCM + 1);\n q = t;\n \n BigInt d = gcd(p, q);\n write(p / d);\n write(\"/\");\n writeln(q / d);\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\nimport std.bigint;\nimport std.algorithm;\n\nBigInt gcd(BigInt a, BigInt b) {\n return (a % b != 0) ? gcd(b, a % b) : b;\n}\n\nBigInt lcm(BigInt a, BigInt b) {\n return a * b / gcd(a,b);\n}\n\nvoid main() {\n string s[] = split(readln());\n BigInt t = s[0];\n BigInt w = s[1];\n BigInt b = s[2];\n\n BigInt LCM = lcm(w,b);\n BigInt cnt = t / LCM;\n BigInt p, q;\n BigInt one = \"1\", zero = \"0\";\n p = max(cnt - 1, zero) * min(w,b) + min(cnt, one) * min(min(w,b), t % LCM + 1);\n q = t;\n \n BigInt d = gcd(p, q);\n write(p / d);\n write(\"/\");\n writeln(q / d);\n}\n"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\nimport std.bigint;\nimport std.algorithm;\n\nBigInt gcd(BigInt a, BigInt b) {\n return (a % b != 0) ? gcd(b, a % b) : b;\n}\n\nBigInt lcm(BigInt a, BigInt b) {\n return a * b / gcd(a,b);\n}\n\nvoid main() {\n string s[] = split(readln());\n BigInt t = s[0];\n BigInt w = s[1];\n BigInt b = s[2];\n\n BigInt LCM = lcm(w,b);\n BigInt cnt = t / LCM;\n BigInt p, q;\n BigInt one = \"1\", zero = \"0\";\n p = max(cnt - 1, zero) * w + min(cnt, one) * min(w, t % LCM + 1);\n q = t;\n \n BigInt d = gcd(p, q);\n write(p / d);\n write(\"/\");\n writeln(q / d);\n}\n"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\nimport std.bigint;\nimport std.algorithm;\n\nBigInt gcd(BigInt a, BigInt b) {\n return (a % b != 0) ? gcd(b, a % b) : b;\n}\n\nBigInt lcm(BigInt a, BigInt b) {\n return a * b / gcd(a,b);\n}\n\nvoid main() {\n string s[] = split(readln());\n BigInt t = s[0];\n BigInt w = s[1];\n BigInt b = s[2];\n\n BigInt LCM = lcm(w,b);\n BigInt cnt = t / LCM;\n BigInt p, q;\n p = min(w,b)-1;\n if(cnt > 0)\n p += (cnt-1) * min(w,b) + min(min(w,b), t % LCM + 1);\n q = t;\n \n BigInt d = gcd(p, q);\n write(p / d);\n write(\"/\");\n writeln(q / d);\n}\n"}], "src_uid": "7a1d8ca25bce0073c4eb5297b94501b5"} {"nl": {"description": "One Martian boy called Zorg wants to present a string of beads to his friend from the Earth \u2014 Masha. He knows that Masha likes two colours: blue and red, \u2014 and right in the shop where he has come, there is a variety of adornments with beads of these two colours. All the strings of beads have a small fastener, and if one unfastens it, one might notice that all the strings of beads in the shop are of the same length. Because of the peculiarities of the Martian eyesight, if Zorg sees one blue-and-red string of beads first, and then the other with red beads instead of blue ones, and blue \u2014 instead of red, he regards these two strings of beads as identical. In other words, Zorg regards as identical not only those strings of beads that can be derived from each other by the string turnover, but as well those that can be derived from each other by a mutual replacement of colours and/or by the string turnover.It is known that all Martians are very orderly, and if a Martian sees some amount of objects, he tries to put them in good order. Zorg thinks that a red bead is smaller than a blue one. Let's put 0 for a red bead, and 1 \u2014 for a blue one. From two strings the Martian puts earlier the string with a red bead in the i-th position, providing that the second string has a blue bead in the i-th position, and the first two beads i\u2009-\u20091 are identical.At first Zorg unfastens all the strings of beads, and puts them into small heaps so, that in each heap strings are identical, in his opinion. Then he sorts out the heaps and chooses the minimum string in each heap, in his opinion. He gives the unnecassary strings back to the shop assistant and says he doesn't need them any more. Then Zorg sorts out the remaining strings of beads and buys the string with index k. All these manupulations will take Zorg a lot of time, that's why he asks you to help and find the string of beads for Masha.", "input_spec": "The input file contains two integers n and k (2\u2009\u2264\u2009n\u2009\u2264\u200950;1\u2009\u2264\u2009k\u2009\u2264\u20091016) \u2014the length of a string of beads, and the index of the string, chosen by Zorg. ", "output_spec": "Output the k-th string of beads, putting 0 for a red bead, and 1 \u2014 for a blue one. If it s impossible to find the required string, output the only number -1.", "sample_inputs": ["4 4"], "sample_outputs": ["0101"], "notes": "NoteLet's consider the example of strings of length 4 \u2014 0001, 0010, 0011, 0100, 0101, 0110, 0111, 1000, 1001, 1010, 1011, 1100, 1101, 1110. Zorg will divide them into heaps: {0001, 0111, 1000, 1110}, {0010, 0100, 1011, 1101}, {0011, 1100}, {0101, 1010}, {0110, 1001}. Then he will choose the minimum strings of beads in each heap: 0001, 0010, 0011, 0101, 0110. The forth string \u2014 0101."}, "positive_code": [{"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, const T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, const T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(S x, T y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(T[] as, bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(T[] as, T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(T[] as, T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nint N;\nlong K;\n\nlong solve(int[] head) {\n\tif (head[0] != 0) {\n\t\treturn 0;\n\t}\n// writeln(\"head = \",head);\n\tconst int m = head.length;\n\tbool fine(int pos, int val) {\n\t\treturn (pos >= m || head[pos] == val);\n\t}\n\tlong ret;\n\tforeach (l0; 0 .. N + 1) foreach (l1; 0 .. N +1) {\n\t\t/*\n\t\t\tx[i] = head[i] (0 <= i < m)\n\t\t\tx[i] = (!)x[N - 1 - i] (0 <= i < l)\n\t\t\tx[l] < (!)x[N - 1 - l] (if l < N)\n\t\t*/\n\t\tlong tmp = 1;\n\t\tforeach (i; 0 .. N) if (i <= N - 1 - i) {\n\t\t\tlong cnt;\n\t\t\tforeach (s; 0 .. 2) foreach (t; 0 .. 2) if (fine(i, s) && fine(N - 1 - i, t)) {\n\t\t\t\tbool ok = true;\n\t\t\t\tif (i == N - 1 - i) {\n\t\t\t\t\tok = ok && (s == t);\n\t\t\t\t} \n\t\t\t\t\n\t\t\t\tif (i < l0) {\n\t\t\t\t\tok = ok && (s == t);\n\t\t\t\t} else if (i == l0) {\n\t\t\t\t\tok = ok && (s < t);\n\t\t\t\t}\n\t\t\t\tif (N - 1 - i < l0) {\n\t\t\t\t\tok = ok && (t == s);\n\t\t\t\t} else if (N - 1 - i == l0) {\n\t\t\t\t\tok = ok && (t < s);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (i < l1) {\n\t\t\t\t\tok = ok && (s == 1 - t);\n\t\t\t\t} else if (i == l1) {\n\t\t\t\t\tok = ok && (s < 1 - t);\n\t\t\t\t}\n\t\t\t\tif (N - 1 - i < l1) {\n\t\t\t\t\tok = ok && (t == 1 - s);\n\t\t\t\t} else if (N - 1 - i == l1) {\n\t\t\t\t\tok = ok && (t < 1 - s);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif (ok) {\n\t\t\t\t\t++cnt;\n\t\t\t\t}\n\t\t\t}\n\t\t\ttmp *= cnt;\n\t\t}\n// writeln(\" l0 = \",l0,\", l1 = \",l1,\" : \",tmp);\n\t\tret += tmp;\n\t}\n\treturn ret;\n}\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tN = readInt;\n\t\tK = readLong;\n\t\t\n\t\tlong k = K + 1;\n\t\t\n\t\tint[] a = new int[N];\n\t\tbool ok = true;\n\t\tforeach (i; 0 .. N) {\n\t\t\tfor (a[i] = 0; a[i] < 2; ++a[i]) {\n\t\t\t\tconst res = solve(a[0 .. i + 1]);\n\t\t\t\tif (k > res) {\n\t\t\t\t\tk -= res;\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (a[i] == 2) {\n\t\t\t\tassert(i == 0);\n\t\t\t\twriteln(-1);\n\t\t\t\tok = false;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (ok) {\n\t\t\twriteln(a.to!string.removechars(\"[], \"));\n\t\t}\n\t}\n\t} catch (EOFException) {}\n}\n\n"}], "negative_code": [], "src_uid": "0a4a418dafaee71f1b31c928fc2ad24a"} {"nl": {"description": "Alena has successfully passed the entrance exams to the university and is now looking forward to start studying.One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic hours (an academic hour is equal to 45 minutes).The University works in such a way that every day it holds exactly n lessons. Depending on the schedule of a particular group of students, on a given day, some pairs may actually contain classes, but some may be empty (such pairs are called breaks).The official website of the university has already published the schedule for tomorrow for Alena's group. Thus, for each of the n pairs she knows if there will be a class at that time or not.Alena's House is far from the university, so if there are breaks, she doesn't always go home. Alena has time to go home only if the break consists of at least two free pairs in a row, otherwise she waits for the next pair at the university.Of course, Alena does not want to be sleepy during pairs, so she will sleep as long as possible, and will only come to the first pair that is presented in her schedule. Similarly, if there are no more pairs, then Alena immediately goes home.Alena appreciates the time spent at home, so she always goes home when it is possible, and returns to the university only at the beginning of the next pair. Help Alena determine for how many pairs she will stay at the university. Note that during some pairs Alena may be at the university waiting for the upcoming pair.", "input_spec": "The first line of the input contains a positive integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100) \u2014 the number of lessons at the university. The second line contains n numbers ai (0\u2009\u2264\u2009ai\u2009\u2264\u20091). Number ai equals 0, if Alena doesn't have the i-th pairs, otherwise it is equal to 1. Numbers a1,\u2009a2,\u2009...,\u2009an are separated by spaces.", "output_spec": "Print a single number \u2014 the number of pairs during which Alena stays at the university.", "sample_inputs": ["5\n0 1 0 1 1", "7\n1 0 1 0 0 1 0", "1\n0"], "sample_outputs": ["4", "4", "0"], "notes": "NoteIn the first sample Alena stays at the university from the second to the fifth pair, inclusive, during the third pair she will be it the university waiting for the next pair. In the last sample Alena doesn't have a single pair, so she spends all the time at home."}, "positive_code": [{"source_code": "import std.stdio;\nimport std.conv;\nimport std.array;\nimport std.algorithm;\nvoid main()\n{\n\tint num;\n\treadf(\"%d\\n\",&num);\n\tstring[]s=split(readln());\n\tint[]a;\n\tfor(int i=0;i= 0 && i + 1 < n && arr[i - 1] == 1 && arr[i + 1] == 1)\n count++;\n }\n writeln(count);\n } \n}"}], "negative_code": [], "src_uid": "2896aadda9e7a317d33315f91d1ca64d"} {"nl": {"description": "Polycarp decided to relax on his weekend and visited to the performance of famous ropewalkers: Agafon, Boniface and Konrad.The rope is straight and infinite in both directions. At the beginning of the performance, Agafon, Boniface and Konrad are located in positions $$$a$$$, $$$b$$$ and $$$c$$$ respectively. At the end of the performance, the distance between each pair of ropewalkers was at least $$$d$$$.Ropewalkers can walk on the rope. In one second, only one ropewalker can change his position. Every ropewalker can change his position exactly by $$$1$$$ (i. e. shift by $$$1$$$ to the left or right direction on the rope). Agafon, Boniface and Konrad can not move at the same time (Only one of them can move at each moment). Ropewalkers can be at the same positions at the same time and can \"walk past each other\".You should find the minimum duration (in seconds) of the performance. In other words, find the minimum number of seconds needed so that the distance between each pair of ropewalkers can be greater or equal to $$$d$$$.Ropewalkers can walk to negative coordinates, due to the rope is infinite to both sides.", "input_spec": "The only line of the input contains four integers $$$a$$$, $$$b$$$, $$$c$$$, $$$d$$$ ($$$1 \\le a, b, c, d \\le 10^9$$$). It is possible that any two (or all three) ropewalkers are in the same position at the beginning of the performance.", "output_spec": "Output one integer \u2014 the minimum duration (in seconds) of the performance.", "sample_inputs": ["5 2 6 3", "3 1 5 6", "8 3 3 2", "2 3 10 4"], "sample_outputs": ["2", "8", "2", "3"], "notes": "NoteIn the first example: in the first two seconds Konrad moves for 2 positions to the right (to the position $$$8$$$), while Agafon and Boniface stay at their positions. Thus, the distance between Agafon and Boniface will be $$$|5 - 2| = 3$$$, the distance between Boniface and Konrad will be $$$|2 - 8| = 6$$$ and the distance between Agafon and Konrad will be $$$|5 - 8| = 3$$$. Therefore, all three pairwise distances will be at least $$$d=3$$$, so the performance could be finished within 2 seconds."}, "positive_code": [{"source_code": "module main;\n\nimport std.stdio;\nimport std.container.array;\nimport std.algorithm.sorting;\n\nvoid main(string[] args){\n int[] arr = [2:0];\n for (int i = 0; i < 3; i++) {\n scanf(\"%d\", &arr[i]);\n }\n arr.sort();\n int d;\n scanf(\"%d\", &d);\n int ans;\n int inc = d - (arr[1] - arr[0]);\n if (inc > 0) {\n ans += inc;\n }\n inc = d - (arr[2] - arr[1]);\n if (inc > 0) {\n ans += inc;\n }\n printf(\"%d\", ans);\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tlong a, b, c, d;\n\twhile (readf !(\" %s %s %s %s\") (a, b, c, d) > 0)\n\t{\n\t\tauto z = [a, b, c];\n\t\tsort (z);\n\t\ta = z[0];\n\t\tb = z[1];\n\t\tc = z[2];\n\t\tlong res = 0;\n\t\tres += d - min (b - a, d);\n\t\tres += d - min (c - b, d);\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * y / gcd(x, y); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto abc = new long[](3);\n\tforeach (i; 0..3)\n\t{\n\t\tabc[i] = RD;\n\t}\n\tauto d = RD;\n\n\tabc.sort();\n\tlong ans = max(0, d - (abc[1] - abc[0])) + max(0, d - (abc[2] - abc[1]));\n\n\twriteln(ans);\n\tstdout.flush();\n\tdebug readln();\n}"}], "negative_code": [], "src_uid": "47c07e46517dbc937e2e779ec0d74eb3"} {"nl": {"description": "Developing tools for creation of locations maps for turn-based fights in a new game, Petya faced the following problem.A field map consists of hexagonal cells. Since locations sizes are going to be big, a game designer wants to have a tool for quick filling of a field part with identical enemy units. This action will look like following: a game designer will select a rectangular area on the map, and each cell whose center belongs to the selected rectangle will be filled with the enemy unit.More formally, if a game designer selected cells having coordinates (x1,\u2009y1) and (x2,\u2009y2), where x1\u2009\u2264\u2009x2 and y1\u2009\u2264\u2009y2, then all cells having center coordinates (x,\u2009y) such that x1\u2009\u2264\u2009x\u2009\u2264\u2009x2 and y1\u2009\u2264\u2009y\u2009\u2264\u2009y2 will be filled. Orthogonal coordinates system is set up so that one of cell sides is parallel to OX axis, all hexagon centers have integer coordinates and for each integer x there are cells having center with such x coordinate and for each integer y there are cells having center with such y coordinate. It is guaranteed that difference x2\u2009-\u2009x1 is divisible by 2.Working on the problem Petya decided that before painting selected units he wants to output number of units that will be painted on the map.Help him implement counting of these units before painting. ", "input_spec": "The only line of input contains four integers x1,\u2009y1,\u2009x2,\u2009y2 (\u2009-\u2009109\u2009\u2264\u2009x1\u2009\u2264\u2009x2\u2009\u2264\u2009109,\u2009\u2009-\u2009109\u2009\u2264\u2009y1\u2009\u2264\u2009y2\u2009\u2264\u2009109) \u2014 the coordinates of the centers of two cells.", "output_spec": "Output one integer \u2014 the number of cells to be filled.", "sample_inputs": ["1 1 5 5"], "sample_outputs": ["13"], "notes": null}, "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\n\nvoid main()\n{\n\tlong x1, x2, y1, y2;\n\n\tscanf(\"%lld%lld%lld%lld\", &x1, &y1, &x2, &y2);\n\n\tlong dx = (x2 - x1) / 2;\n\tlong dy = (y2 - y1) / 2;\n\tprintf(\"%lld\\n\", (dx + 1) * (dy + 1) + dx * dy);\n}"}, {"source_code": "import std.stdio;\n\nvoid main ()\n{\n\tint x1, y1, x2, y2;\n\twhile (readf (\" %s %s %s %s\", &x1, &y1, &x2, &y2) > 0)\n\t{\n\t\twriteln (((x2 - x1 + 1) * 1L * (y2 - y1 + 1) + 1) / 2);\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\n\nvoid main ()\n{\n\tint x1, y1, x2, y2;\n\twhile (readf (\" %s %s %s %s\", &x1, &y1, &x2, &y2) > 0)\n\t{\n\t\twriteln (((x2 - x1 + 1) * 1L * (y2 - y1 + 1) +\n\t\t (x1 % 2 == y1 % 2)) / 2);\n\t}\n}\n"}, {"source_code": "import std.stdio;\n\nvoid main ()\n{\n\tint x1, y1, x2, y2;\n\twhile (readf (\" %s %s %s %s\", &x1, &y1, &x2, &y2) > 0)\n\t{\n\t\twriteln (((x2 - x1 + 1) * 1L * (y2 - y1 + 1) +\n\t\t ((x1 ^ y1 ^ 1) & 1)) / 2);\n\t}\n}\n"}, {"source_code": "import std.stdio;\n\nvoid main ()\n{\n\tint x1, y1, x2, y2;\n\twhile (readf (\" %s %s %s %s\", &x1, &y1, &x2, &y2) > 0)\n\t{\n\t\twriteln (((x2 - x1 + 1) * 1L * (y2 - y1 + 1) +\n\t\t (x1 & y1 & 1)) / 2);\n\t}\n}\n"}, {"source_code": "import std.exception;\nimport std.stdio;\n\nvoid main ()\n{\n\tint x1, y1, x2, y2;\n\twhile (readf (\" %s %s %s %s\", &x1, &y1, &x2, &y2) > 0)\n\t{\n\t\tenforce (-1_000_000_000 <= x1 &&\n\t\t x1 <= x2 &&\n\t\t x2 <= +1_000_000_000);\n\t\tenforce (-1_000_000_000 <= x1 &&\n\t\t x1 <= x2 &&\n\t\t x2 <= +1_000_000_000);\n\t\tenforce ((x1 & 1) == (x2 & 1));\n\t\tauto res = (x2 - x1 + 1) * 1L * (y2 - y1 + 1) / 2;\n\t\tif ((x1 & 1) == (y1 & 1) && (y1 & 1) == (y2 & 1))\n\t\t{\n\t\t\tres++;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.stdio;\n\nvoid main ()\n{\n\tint x1, y1, x2, y2;\n\twhile (readf (\" %s %s %s %s\", &x1, &y1, &x2, &y2) > 0)\n\t{\n\t\tauto res = (x2 - x1 + 1) * 1L * (y2 - y1 + 1) / 2;\n\t\tif ((x1 & 1) == (y1 & 1) && (y1 & 1) == (y2 & 1))\n\t\t{\n\t\t\tres++;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.stdio;\n\nvoid main ()\n{\n\tint x1, y1, x2, y2;\n\twhile (readf (\" %s %s %s %s\", &x1, &y1, &x2, &y2) > 0)\n\t{\n\t\tauto res = (x2 - x1 + 1) * 1L * (y2 - y1 + 1) / 2;\n\t\tif (x1 % 2 == y1 % 2 && y1 % 2 == y2 % 2)\n\t\t{\n\t\t\tres++;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "src_uid": "00cffd273df24d1676acbbfd9a39630d"} {"nl": {"description": "One day Vasya heard a story: \"In the city of High Bertown a bus number 62 left from the bus station. It had n grown-ups and m kids...\"The latter events happen to be of no importance to us. Vasya is an accountant and he loves counting money. So he wondered what maximum and minimum sum of money these passengers could have paid for the ride.The bus fare equals one berland ruble in High Bertown. However, not everything is that easy \u2014 no more than one child can ride for free with each grown-up passenger. That means that a grown-up passenger who rides with his k (k\u2009>\u20090) children, pays overall k rubles: a ticket for himself and (k\u2009-\u20091) tickets for his children. Also, a grown-up can ride without children, in this case he only pays one ruble.We know that in High Bertown children can't ride in a bus unaccompanied by grown-ups.Help Vasya count the minimum and the maximum sum in Berland rubles, that all passengers of this bus could have paid in total.", "input_spec": "The input file consists of a single line containing two space-separated numbers n and m (0\u2009\u2264\u2009n,\u2009m\u2009\u2264\u2009105) \u2014 the number of the grown-ups and the number of the children in the bus, correspondingly.", "output_spec": "If n grown-ups and m children could have ridden in the bus, then print on a single line two space-separated integers \u2014 the minimum and the maximum possible total bus fare, correspondingly. Otherwise, print \"Impossible\" (without the quotes).", "sample_inputs": ["1 2", "0 5", "2 2"], "sample_outputs": ["2 2", "Impossible", "2 3"], "notes": "NoteIn the first sample a grown-up rides with two children and pays two rubles.In the second sample there are only children in the bus, so the situation is impossible. In the third sample there are two cases: Each of the two grown-ups rides with one children and pays one ruble for the tickets. In this case the passengers pay two rubles in total. One of the grown-ups ride with two children's and pays two rubles, the another one rides alone and pays one ruble for himself. So, they pay three rubles in total. "}, "positive_code": [{"source_code": "//DMD64 D Compiler 2.072.2\nimport std.stdio;\nvoid main(){\n int a,b,c,d;\n readf(\"%d %d\",&a,&b);\n if(a<1&&b>0){write(\"Impossible\");return;}\n c=a;\n if(b-a>0){c+=b-a;}\n d=a;\n if(b>0){d+=b-1;}\n write(c,' ',d);\n}"}, {"source_code": "import std.stdio;void main(){int a,b;readf(\"%d %d\",&a,&b);if(a<1&&b>0){write(\"Impossible\");return;}write(a>b?a:b,' ',b!=0?a+b-1:a);}"}, {"source_code": "//rextester.com:dmd64 2.072.2--codeforces.com:dmd32 2.071.2\nimport std.stdio;\nvoid main(){\n int a,b;readf(\"%d %d\",&a,&b);\n if(a<1&&b>0){write(\"Impossible\");return;}\n write(a>b?a:b,' ',b!=0?a+b-1:a);\n}"}, {"source_code": "//DMD64 2.072.2 | RexTester.Com & DMD32 2.079.0 | CodeForces.Com\nimport std.stdio;\nvoid main() {\n int grown_ups, children;\n readf(\"%d %d\", &grown_ups, &children);\n\n if (grown_ups < 1 && children > 0) {\n write(\"Impossible\");\n return;\n }\n\n write(grown_ups > children ? grown_ups : children, ' ', children != 0 ? grown_ups + children - 1 : grown_ups);\n}"}], "negative_code": [], "src_uid": "1e865eda33afe09302bda9077d613763"} {"nl": {"description": "Your friend has recently learned about coprime numbers. A pair of numbers {a,\u2009b} is called coprime if the maximum number that divides both a and b is equal to one. Your friend often comes up with different statements. He has recently supposed that if the pair (a,\u2009b) is coprime and the pair (b,\u2009c) is coprime, then the pair (a,\u2009c) is coprime. You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (a,\u2009b,\u2009c), for which the statement is false, and the numbers meet the condition l\u2009\u2264\u2009a\u2009<\u2009b\u2009<\u2009c\u2009\u2264\u2009r. More specifically, you need to find three numbers (a,\u2009b,\u2009c), such that l\u2009\u2264\u2009a\u2009<\u2009b\u2009<\u2009c\u2009\u2264\u2009r, pairs (a,\u2009b) and (b,\u2009c) are coprime, and pair (a,\u2009c) is not coprime.", "input_spec": "The single line contains two positive space-separated integers l, r (1\u2009\u2264\u2009l\u2009\u2264\u2009r\u2009\u2264\u20091018; r\u2009-\u2009l\u2009\u2264\u200950).", "output_spec": "Print three positive space-separated integers a, b, c\u00a0\u2014 three distinct numbers (a,\u2009b,\u2009c) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order. If the counterexample does not exist, print the single number -1.", "sample_inputs": ["2 4", "10 11", "900000000000000009 900000000000000029"], "sample_outputs": ["2 3 4", "-1", "900000000000000009 900000000000000010 900000000000000021"], "notes": "NoteIn the first sample pair (2,\u20094) is not coprime and pairs (2,\u20093) and (3,\u20094) are. In the second sample you cannot form a group of three distinct integers, so the answer is -1. In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three. "}, "positive_code": [{"source_code": "\ufeffimport std.stdio;\n\nlong GCD(long a, long b) {\n\treturn b ? GCD(b, a % b) : a;\n}\n\nvoid main() {\n\n\tlong l, r;\n\n\treadf(\" %s %s\", &l, &r);\n\n\tforeach (i; l .. r + 1)\n\t\tforeach (j; i + 1 .. r + 1)\n\t\t\tforeach (k; j + 1 .. r + 1)\n\t\t\tif (GCD(i, j) == 1 && GCD(j, k) == 1 && GCD(i, k) != 1) {\n\t\t\t\twritefln(\"%d %d %d\", i, j, k);\n\t\t\t\treturn;\n\t\t\t}\n\n\twriteln(\"-1\");\n}"}, {"source_code": "\ufeffimport std.stdio;\nimport std.numeric;\n\nvoid main() {\n\t\n\tlong l, r;\n\t\n\treadf(\" %s %s\", &l, &r);\n\t\n\tforeach (i; l .. r + 1)\n\t\tforeach (j; i + 1 .. r + 1)\n\t\t\tforeach (k; j + 1 .. r + 1)\n\t\t\tif (gcd(i, j) == 1 && gcd(j, k) == 1 && gcd(i, k) != 1) {\n\t\t\t\twritefln(\"%d %d %d\", i, j, k);\n\t\t\t\treturn;\n\t\t\t}\n\t\n\twriteln(\"-1\");\n}"}, {"source_code": "\ufeffimport std.stdio, std.bigint, std.string;\n\nBigInt gcd(BigInt a, BigInt b) {\n\treturn b ? gcd(b, a % b) : a;\n}\n\nvoid main() {\n\n\tauto l = BigInt (readln(' ').strip);\n\tauto r = BigInt (readln.strip);\n\t\n\tforeach (i; l .. r + 1)\n\t\tforeach (j; i + 1 .. r + 1)\n\t\t\tforeach (k; j + 1 .. r + 1)\n\t\t\tif (gcd(i, j) == 1 && gcd(j, k) == 1 && gcd(i, k) != 1) {\n\t\t\t\twritefln(\"%d %d %d\", i, j, k);\n\t\t\t\treturn;\n\t\t\t}\n\t\n\twriteln(\"-1\");\n}"}, {"source_code": "\ufeffimport std.stdio;\n\nvoid main() {\n\t\n\tlong l, r;\n\t\n\treadf(\" %s %s\", &l, &r);\n\t\n\tif (r - l < 2) {\n\t\twriteln(-1);\n\t\treturn;\n\t}\n\t\n\tif (!(l % 2)) {\n\t\twritefln(\"%s %s %s\", l, l + 1, l + 2);\n\t\treturn;\n\t}\n\t\n\tif (r - l > 2){\n\t\twritefln(\"%s %s %s\", l + 1, l + 2, l + 3);\n\t\treturn;\n\t}\n\t\n\twriteln(-1);\n}"}, {"source_code": "\ufeffimport std.stdio;\n\nlong GCD(long a, long b) {\n\treturn b ? GCD(b, a % b) : a;\n}\n\nvoid main() {\n\n\tlong l, r;\n\n\treadf(\" %s %s\", &l, &r);\n\n\tforeach (i; l .. r + 1) {\n\t\tforeach (j; i .. r + 1)\n\t\t\tforeach (k; j .. r + 1)\n\t\t\tif (GCD(i, j) == 1 && GCD(j, k) == 1 && GCD(i, k) != 1) {\n\t\t\t\t\twritefln(\"%d %d %d\", i, j, k);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t}\n\n\twriteln(\"-1\");\n}"}, {"source_code": "\ufeffimport std.stdio;\n\nvoid main() {\n\n\tlong l, r;\n\n\treadf(\" %s %s\", &l, &r);\n\n\tif (r - l + 1 < 3) {\n\t\twriteln(-1);\n\t\treturn;\n\t}\n\t\n\tif (l % 2 == 0) {\n\t\twritefln(\"%s %s %s\", l, l + 1, l + 2);\n\t\treturn;\n\t}\n\t\n\tif (r - l + 1 > 3){\n\t\twritefln(\"%s %s %s\", l + 1, l + 2, l + 3);\n\t\treturn;\n\t}\n\t\n\twriteln(-1);\n}"}, {"source_code": "//ahmat\nimport core.stdc.stdio:scanf,printf,puts;\nimport core.bitop;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.functional;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.container;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\npragma(inline,true);\n\nvoid main(){\n ulong l,r;\n readf!\"%d %d\"(l,r);\n r++;\n readln;\n foreach(a;l..r)\n foreach(b;a+1..r)\n foreach(c;b+1..r)\n if(gcd(a,b)==1 && gcd(b,c)==1 && gcd(a,c)!=1){\n writefln!\"%d %d %d\"(a,b,c);\n return;\n }\n puts(\"-1\");\n}\n\n"}], "negative_code": [{"source_code": "\ufeffimport std.stdio;\n\nlong GCD(long a, long b) {\n\treturn b ? GCD(b, a % b) : a;\n}\n\nvoid main() {\n\n\tlong l, r;\n\n\treadf(\" %s %s\", &l, &r);\n\n\tforeach (i; l .. r + 1) {\n\t\tforeach (j; i .. r + 1)\n\t\t\tforeach (k; j .. r + 1)\n\t\t\t\tif (j % i != 0 && k % j != 0 && GCD(i, k) != 1) {\n\t\t\t\t\twritefln(\"%d %d %d\", i, j, k);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t}\n\n\twriteln(\"-1\");\n}"}, {"source_code": "\ufeffimport std.stdio;\n\nvoid main() {\n\n\tlong l, r;\n\n\treadf(\" %s %s\", &l, &r);\n\n\tforeach (i; l .. r + 1) {\n\t\tforeach (j; i .. r + 1)\n\t\t\tforeach (k; j .. r + 1)\n\t\t\t\tif (j % i != 0 && k % j != 0) {\n\t\t\t\t\twritefln(\"%d %d %d\", i, j, k);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t}\n\n\twriteln(\"-1\");\n}"}], "src_uid": "6c1ad1cc1fbecff69be37b1709a5236d"} {"nl": {"description": "Let\u2019s 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\u2019re 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\u2019s 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": "import std.algorithm;\nimport std.array;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nstring solve (string s, int i, int j, int n)\n{\n\tchar [13] [2] res;\n\tint loopLength = (j - i + 1) / 2;\n\twhile (i > 0)\n\t{\n\t\ts = s[1..$] ~ s[0];\n\t\ti -= 1;\n\t\tj -= 1;\n\t}\n\tdebug {writeln (s, \" \", i, \" \", j);}\n\n\tint mid = loopLength - 1;\n\tmid = min (mid, 12);\n\tint pos = mid;\n\tres[0][pos] = s[i];\n\twhile (pos > 0)\n\t{\n\t\tpos -= 1;\n\t\ti += 1;\n\t\tres[0][pos] = s[i];\n\t}\n\ti += 1;\n\tres[1][pos] = s[i];\n\twhile (i < j - 1)\n\t{\n\t\tpos += 1;\n\t\ti += 1;\n\t\tres[1][pos] = s[i];\n\t}\n\ti += 1;\n\tassert (i == j);\n\tpos = mid;\n\tassert (res[0][pos] == s[i]);\n\twhile (pos < 12)\n\t{\n\t\tpos += 1;\n\t\ti += 1;\n\t\tres[0][pos] = s[i];\n\t}\n\ti += 1;\n\tif (i < n)\n\t{\n\t\tres[1][pos] = s[i];\n\t}\n\twhile (i + 1 < n)\n\t{\n\t\tpos -= 1;\n\t\ti += 1;\n\t\tres[1][pos] = s[i];\n\t}\n\n\treturn res[].map !(x => x.idup).join (\"\\n\");\n}\n\nvoid main ()\n{\n\tstring s;\n\twhile ((s = readln.strip) != \"\")\n\t{\n\t\tint n = cast (int) (s.length);\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tforeach (j; i + 1..n)\n\t\t\t{\n\t\t\t\tif (s[i] == s[j])\n\t\t\t\t{\n\t\t\t\t\tif (j - i == 1)\n\t\t\t\t\t{\n\t\t\t\t\t\twriteln (\"Impossible\");\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\twriteln (solve (s, i, j, n));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n"}], "negative_code": [], "src_uid": "56c5ea443dec7a732802b16aed5b934d"} {"nl": {"description": "You are given a chessboard of size 1\u2009\u00d7\u2009n. 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\u2009\u2264\u2009n\u2009\u2264\u2009100, n is even) \u2014 the size of the chessboard. The second line of the input contains integer numbers (1\u2009\u2264\u2009pi\u2009\u2264\u2009n) \u2014 initial positions of the pieces. It is guaranteed that all the positions are distinct.", "output_spec": "Print one integer \u2014 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": "import std.stdio;\nimport std.range;\nimport std.array;\nimport std.string;\nimport std.conv;\nimport std.typecons;\nimport std.algorithm;\nimport std.container;\nimport std.typecons;\nimport std.random;\nimport std.csv;\nimport std.regex;\nimport std.math;\nimport core.time;\nimport std.ascii;\nimport std.digest.sha;\nimport std.outbuffer;\nimport std.numeric;\nimport std.bigint;\n\nvoid main()\n{\n\tint n = readln.chomp.to!int;\n\tint[] p = readln.chomp.split.map!(to!int).array;\n\tstd.algorithm.sort(p);\n\tint ans = int.max;\n\tfor (int i = 1; i <= 2; ++i) {\n\t\tint sum = 0;\n\t\tforeach (int j, int t; p) {\n\t\t\tsum += abs(j * 2 + i - t);\n\t\t}\n\t\tans = min(ans, sum);\n\t}\n\tans.writeln;\n}\n\nvoid tie(R, Args...)(R arr, ref Args args)\n\t\tif (isRandomAccessRange!R || isArray!R)\nin\n{\n\tassert (arr.length == args.length);\n}\nbody\n{\n\tforeach (i, ref v; args) {\n\t\talias T = typeof(v);\n\t\tv = arr[i].to!T;\n\t}\n}\n\nvoid verbose(Args...)(in Args args)\n{\n\tstderr.write(\"[\");\n\tforeach (i, ref v; args) {\n\t\tif (i) stderr.write(\", \");\n\t\tstderr.write(v);\n\t}\n\tstderr.writeln(\"]\");\n}\n\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\n\nvoid main()\n{\n int n;\n readf( \"%s\\n\", &n );\n auto a = readln.splitter.map!( to!int ).array;\n a.sort;\n auto ans = n*n;\n foreach ( int shift; 1..3 ) {\n int cur = 0;\n foreach ( int idx, int e; a) {\n cur += abs( e - ( 2*idx + shift ) );\n }\n ans = min( ans, cur );\n }\n writeln(ans);\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\n\nvoid main()\n{\n int n;\n readf( \"%s\\n\", &n );\n auto a = readln.splitter.map!( to!int ).array;\n a.sort;\n auto ans = n*n;\n foreach ( int shift; 1..3 ) {\n int cur = 0;\n foreach ( int idx, int e; a ) {\n cur += abs( e - ( 2*idx + shift ) );\n }\n ans = min( ans, cur );\n }\n writeln( ans );\n}"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.range;\nimport std.array;\nimport std.string;\nimport std.conv;\nimport std.typecons;\nimport std.algorithm;\nimport std.container;\nimport std.typecons;\nimport std.random;\nimport std.csv;\nimport std.regex;\nimport std.math;\nimport core.time;\nimport std.ascii;\nimport std.digest.sha;\nimport std.outbuffer;\nimport std.numeric;\nimport std.bigint;\n\nvoid main()\n{\n\tint n = readln.chomp.to!int;\n\tint[] p = readln.chomp.split.map!(to!int).array;\n\tint ans = int.max;\n\tfor (int i = 1; i <= 2; ++i) {\n\t\tint sum = 0;\n\t\tforeach (int j, int t; p) {\n\t\t\tsum += abs(j * 2 + i - t);\n\t\t}\n\t\tans = min(ans, sum);\n\t}\n\tans.writeln;\n}\n\nvoid tie(R, Args...)(R arr, ref Args args)\n\t\tif (isRandomAccessRange!R || isArray!R)\nin\n{\n\tassert (arr.length == args.length);\n}\nbody\n{\n\tforeach (i, ref v; args) {\n\t\talias T = typeof(v);\n\t\tv = arr[i].to!T;\n\t}\n}\n\nvoid verbose(Args...)(in Args args)\n{\n\tstderr.write(\"[\");\n\tforeach (i, ref v; args) {\n\t\tif (i) stderr.write(\", \");\n\t\tstderr.write(v);\n\t}\n\tstderr.writeln(\"]\");\n}\n\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\n\nvoid main()\n{\n int n;\n readf( \"%s\\n\", &n );\n auto a = readln.splitter.map!( to!int ).array;\n auto ans = n*n;\n foreach ( int shift; 1..3 ) {\n int cur = 0;\n foreach ( int idx, int e; a) {\n cur += abs( e - ( 2*idx + shift ) );\n }\n ans = min( ans, cur );\n }\n writeln(ans);\n}"}], "src_uid": "0efe9afd8e6be9e00f7949be93f0ca1a"} {"nl": {"description": "Recently Luba learned about a special kind of numbers that she calls beautiful numbers. The number is called beautiful iff its binary representation consists of k\u2009+\u20091 consecutive ones, and then k consecutive zeroes.Some examples of beautiful numbers: 12 (110); 1102 (610); 11110002 (12010); 1111100002 (49610). More formally, the number is beautiful iff there exists some positive integer k such that the number is equal to (2k\u2009-\u20091)\u2009*\u2009(2k\u2009-\u20091).Luba has got an integer number n, and she wants to find its greatest beautiful divisor. Help her to find it!", "input_spec": "The only line of input contains one number n (1\u2009\u2264\u2009n\u2009\u2264\u2009105) \u2014 the number Luba has got.", "output_spec": "Output one number \u2014 the greatest beautiful divisor of Luba's number. It is obvious that the answer always exists.", "sample_inputs": ["3", "992"], "sample_outputs": ["1", "496"], "notes": null}, "positive_code": [{"source_code": "#!/usr/bin/env dub\n/+ dub.sdl:\n name \"B\"\n+/\n\nimport std.array;\nimport std.algorithm;\nimport std.algorithm.iteration;\nimport std.conv;\nimport std.math;\nimport std.stdio;\nimport std.string;\n\nvoid main()\n{\n long[] beauty;\n foreach (i; 1..15) {\n beauty ~= (2^^i - 1) * (2 ^^ (i-1));\n }\n beauty.reverse();\n\n debug {\n writeln(beauty);\n }\n \n long N = to!long(readln().strip());\n \n foreach (b; beauty) {\n if (N % b == 0) {\n writeln(b);\n return;\n }\n }\n \n}"}, {"source_code": "import std.stdio, std.string, std.conv, std.algorithm, std.numeric;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\n\nimmutable inf = 10^^9 + 7;\n\nvoid main() {\n int n;\n scan(n);\n\n long ans = 1;\n\n foreach (k ; 1 .. 30) {\n long bn = 1L * (2L^^k - 1) * (2L^^(k - 1));\n if (k > bn) break;\n if (n % bn == 0) {\n ans = max(ans, bn);\n }\n }\n\n writeln(ans);\n}\n\n\nstruct UnionFind {\n private {\n int N;\n int[] p;\n int[] rank;\n }\n\n this (int n) {\n N = n;\n p = iota(N).array;\n rank = new int[](N);\n }\n\n int find_root(int x) {\n if (p[x] != x) {\n p[x] = find_root(p[x]);\n }\n\n return p[x];\n }\n\n bool same(int x, int y) {\n return find_root(x) == find_root(y);\n }\n\n void unite(int x, int y) {\n int u = find_root(x), v = find_root(y);\n\n if (u == v) return;\n\n if (rank[u] < rank[v]) {\n p[u] = v;\n }\n else {\n p[v] = u;\n\n if (rank[u] == rank[v]) {\n rank[u]++;\n }\n }\n }\n}\n\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}\n\n\n\nstruct Queue(T) {\n private {\n int N, head, tail;\n T[] data;\n }\n\n this(int n) {\n N = n + 1;\n data = new T[](N);\n }\n\n bool empty() {\n return head == tail;\n }\n\n bool full() {\n return (tail + 1) % N == head;\n }\n\n T front() {\n return data[head];\n }\n\n void push(T x) {\n assert(!full);\n data[tail++] = x;\n tail %= N;\n }\n\n void pop() {\n assert(!empty);\n head = (head + 1) % N;\n }\n\n void clear() {\n head = tail = 0;\n }\n}"}], "negative_code": [], "src_uid": "339246a1be81aefe19290de0d1aead84"} {"nl": {"description": "Sereja owns a restaurant for n people. The restaurant hall has a coat rack with n hooks. Each restaurant visitor can use a hook to hang his clothes on it. Using the i-th hook costs ai rubles. Only one person can hang clothes on one hook.Tonight Sereja expects m guests in the restaurant. Naturally, each guest wants to hang his clothes on an available hook with minimum price (if there are multiple such hooks, he chooses any of them). However if the moment a guest arrives the rack has no available hooks, Sereja must pay a d ruble fine to the guest. Help Sereja find out the profit in rubles (possibly negative) that he will get tonight. You can assume that before the guests arrive, all hooks on the rack are available, all guests come at different time, nobody besides the m guests is visiting Sereja's restaurant tonight.", "input_spec": "The first line contains two integers n and d (1\u2009\u2264\u2009n,\u2009d\u2009\u2264\u2009100). The next line contains integers a1, a2, ..., an (1\u2009\u2264\u2009ai\u2009\u2264\u2009100). The third line contains integer m (1\u2009\u2264\u2009m\u2009\u2264\u2009100).", "output_spec": "In a single line print a single integer \u2014 the answer to the problem.", "sample_inputs": ["2 1\n2 1\n2", "2 1\n2 1\n10"], "sample_outputs": ["3", "-5"], "notes": "NoteIn the first test both hooks will be used, so Sereja gets 1\u2009+\u20092\u2009=\u20093 rubles.In the second test both hooks will be used but Sereja pays a fine 8 times, so the answer is 3\u2009-\u20098\u2009=\u2009\u2009-\u20095."}, "positive_code": [{"source_code": "import std.stdio, std.string, std.algorithm;\nimport std.conv, std.array;\nimport std.container;\nimport std.typecons;\n\nalias sum = reduce!\"a + b\";\n\nvoid main() {\n int n, d; readf(\"%d %d\\n\", &n, &d);\n int[] a = stdin.readln.split.map!(to!int).array;\n int m; readf(\"%d\\n\", &m);\n int ans = a.sort[0 .. min(m, $)].sum - d * max(m - n, 0);\n ans.writeln;\n}\n"}, {"source_code": "import std.stdio, std.algorithm, std.array, std.conv, std.string;\n\nvoid main() {\n auto input = new int[][2];\n foreach (ref elem; input) {\n elem = readln.chomp.split.map!(to!int).array;\n }\n int n = input[0][0];\n int d = input[0][1];\n int[] a = input[1].sort!(\"a < b\").array;\n int m = readln.chomp.to!int;\n\n int profit = 0;\n\n if (a.length >= m) {\n profit += reduce!(\"a + b\")(0, a[0 .. m]);\n } else {\n profit += reduce!(\"a + b\")(0, a);\n profit -= (m - a.length) * d;\n }\n\n profit.writeln;\n}\n"}], "negative_code": [], "src_uid": "5c21e2dd658825580522af525142397d"} {"nl": {"description": "In one of the games Arkady is fond of the game process happens on a rectangular field. In the game process Arkady can buy extensions for his field, each extension enlarges one of the field sizes in a particular number of times. Formally, there are n extensions, the i-th of them multiplies the width or the length (by Arkady's choice) by ai. Each extension can't be used more than once, the extensions can be used in any order.Now Arkady's field has size h\u2009\u00d7\u2009w. He wants to enlarge it so that it is possible to place a rectangle of size a\u2009\u00d7\u2009b on it (along the width or along the length, with sides parallel to the field sides). Find the minimum number of extensions needed to reach Arkady's goal.", "input_spec": "The first line contains five integers a, b, h, w and n (1\u2009\u2264\u2009a,\u2009b,\u2009h,\u2009w,\u2009n\u2009\u2264\u2009100\u2009000)\u00a0\u2014 the sizes of the rectangle needed to be placed, the initial sizes of the field and the number of available extensions. The second line contains n integers a1,\u2009a2,\u2009...,\u2009an (2\u2009\u2264\u2009ai\u2009\u2264\u2009100\u2009000), where ai equals the integer a side multiplies by when the i-th extension is applied.", "output_spec": "Print the minimum number of extensions needed to reach Arkady's goal. If it is not possible to place the rectangle on the field with all extensions, print -1. If the rectangle can be placed on the initial field, print 0.", "sample_inputs": ["3 3 2 4 4\n2 5 4 10", "3 3 3 3 5\n2 3 5 4 2", "5 5 1 2 3\n2 2 3", "3 4 1 1 3\n2 3 2"], "sample_outputs": ["1", "0", "-1", "3"], "notes": "NoteIn the first example it is enough to use any of the extensions available. For example, we can enlarge h in 5 times using the second extension. Then h becomes equal 10 and it is now possible to place the rectangle on the field."}, "positive_code": [{"source_code": "import core.bitop;\nimport core.checkedint;\nimport core.simd;\nimport core.stdc.stdlib;\nimport core.stdc.string;\nimport std.algorithm;\nimport std.array;\nimport std.ascii;\nimport std.bigint;\nimport std.bitmanip;\nimport std.complex;\nimport std.container;\nimport std.conv;\nimport std.datetime;\nimport std.format;\nimport std.functional;\nimport std.math;\nimport std.meta;\nimport std.numeric;\nimport std.random;\nimport std.range;\nimport std.regex;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.variant;\n\n__gshared:\n\nalias BitSet(size_t n) = size_t[(n + size_t.sizeof * 8 - 1) / (size_t.sizeof * 8)];\n\nauto getAddrTuple() {\n return tuple();\n}\n\nauto getAddrTuple(T, U...)(ref T head, ref U tail) {\n return tuple(&head, getAddrTuple(tail).expand);\n}\n\nbool read(T...)(ref T vars) if (vars.length > 0) {\n return readf(' ' ~ replicate(\"%s \", vars.length), getAddrTuple(vars).expand) == vars.length;\n}\n\nT[ ] allocate(T)(size_t n) {\n return (cast(T*)malloc(n * T.sizeof))[0 .. n];\n}\n\nauto pairwise(R)(R range) if (isForwardRange!R) {\n return lockstep(range, dropOne(range));\n}\n\nint ih, iw, n;\nint[10^^5] _exts;\nint[ ] exts;\nuint[Tuple!(int, int, int)] dp;\n\nuint dyn(int pos, int curh, int curw) {\n if (curh >= ih && curw >= iw)\n return pos;\n if (pos == n)\n return uint.max;\n if (auto p = tuple(pos, curh, curw) in dp)\n return *p;\n uint result = uint.max;\n bool overflow;\n if (curh < ih) {\n int nexth = muls(curh, exts[pos], overflow);\n if (overflow) {\n nexth = int.max;\n overflow = false;\n }\n result = dyn(pos + 1, nexth, curw);\n }\n if (curw < iw) {\n int nextw = muls(curw, exts[pos], overflow);\n if (overflow)\n nextw = int.max;\n result = min(result, dyn(pos + 1, curh, nextw));\n }\n dp[tuple(pos, curh, curw)] = result;\n return result;\n}\n\nuint solve(int oh, int ow) {\n dp = null;\n return dyn(0, oh, ow);\n}\n\nvoid main() {\n int oh, ow;\n while (read(ih, iw, oh, ow, n)) {\n exts = _exts[0 .. n];\n foreach (ref x; exts)\n read(x);\n exts.sort!`a > b`;\n writeln(cast(int)min(solve(oh, ow), solve(ow, oh)));\n }\n}\n"}, {"source_code": "module main;\nimport std.bigint,std.container,std.array,std.algorithm,std.conv,std.parallelism,\n\tstd.functional,std.math,std.string,std.range,std.complex,std.bitmanip,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,core.bitop,\n\tstd.meta,core.stdc.stdio : freopen;\nimport std.numeric: fft,Fft,gcd,inverseFft;alias big=BigInt;alias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");\nalias lint=long;private const int mod=1_000_000_007;\nalias pii=pair!(int,int);alias pll=pair!(long,long);alias mp=make_pair;alias gcd=std.numeric.gcd;\nprivate\n{\n\tpure nothrow \n\t{\n\t\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\t\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\t\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\t\tint sz(T)(T a) if(hasLength!T){return cast(int)a.length;}\n\t\tsize_t lowb(T,X)(T a,auto ref X g)\n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(!(a[m]1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(g 0)\n\t{\n\t\tsize_t s=0;\n\t\tforeach(ref e;ptrs)\n\t\t{\n\t\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\t\telse s+=readf(\" %s\",&e);\n\t\t}\n\t\treturn s==ptrs.length;\n\t}\n\tbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t{\n\t\tsize_t s=0;\n\t\tforeach(ref e;ptrs)\n\t\t{\n\t\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\t\telse s+=readf(\" %s\",&e);\n\t\t}\n\t\treadln;\n\t\treturn s==ptrs.length;\n\t}\n\tnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\n\tnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n\t@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n\tvoid enter(T...)(T args)\n\t{\n\t\twriteln(args);\n\t\tstdout.flush;\n\t}\n}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\nprivate\n{\n\t\n}\nvoid main()\n{\n\tversion(home)\n\t{\n\t\tassert(freopen(\"input.txt\",\"r\",core.stdc.stdio.stdin));\n\t\tassert(freopen(\"output.txt\",\"w\",core.stdc.stdio.stdout));\n\t}\n\tint n,x,y,w,h;\nloop:while(read(h,w,x,y,n))\n\t{\n\t\tauto a=arread!int;\n\t\tsort(a);\n\t\ta=a[max(0,sz(a)-34)..$];\n\t\treverse(a);\n\t\tauto dp=new int[10^^5+1],d=new int[10^^5+1];\n\t\tdp[x]=d[x]=y;\n\t\tforeach(i;0..a.length)\n\t\t{\n\t\t\tforeach(j;0..dp.length)\n\t\t\t{\n\t\t\t\tif((j>=w && dp[j]>=h) || (j>=h && dp[j]>=w))\n\t\t\t\t{\n\t\t\t\t\twriteln(i);\n\t\t\t\t\tcontinue loop;\n\t\t\t\t}\n\t\t\t}\n\t\t\t//d[]=dp[];\n\t\t\tforeach(j;0..dp.length)\n\t\t\t{\n\t\t\t\tif(dp[j]!=0)\n\t\t\t\t{\n\t\t\t\t\tif(1L*j*a[i]<=10^^5)d[j*a[i]]=max(d[j*a[i]],dp[j]);\n\t\t\t\t\telse d[10^^5]=max(d[10^^5],dp[j]);\n\t\t\t\t\tif(1L*dp[j]*a[i]<=10^^5)d[j]=max(dp[j]*a[i],d[j]);\n\t\t\t\t\telse d[j]=10^^5;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdp[]=d[];\n\t\t}\n\t\tforeach(j;0..dp.length)\n\t\t{\n\t\t\tif((j>=w && dp[j]>=h) || (j>=h && dp[j]>=w))\n\t\t\t{\n\t\t\t\twriteln(a.length);\n\t\t\t\tcontinue loop;\n\t\t\t}\n\t\t}\n\t\twriteln(-1);\n\t}\n}"}], "negative_code": [{"source_code": "module main;\nimport std.bigint,std.container,std.array,std.algorithm,std.conv,std.parallelism,\n\tstd.functional,std.math,std.string,std.range,std.complex,std.bitmanip,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,core.bitop,\n\tstd.meta,core.stdc.stdio : freopen;\nimport std.numeric: fft,Fft,gcd,inverseFft;alias big=BigInt;alias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");\nalias lint=long;private const int mod=1_000_000_007;\nalias pii=pair!(int,int);alias pll=pair!(long,long);alias mp=make_pair;alias gcd=std.numeric.gcd;\nprivate\n{\n\tpure nothrow \n\t{\n\t\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\t\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\t\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\t\tint sz(T)(T a) if(hasLength!T){return cast(int)a.length;}\n\t\tsize_t lowb(T,X)(T a,auto ref X g)\n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(!(a[m]1)\n\t\t\t{\n\t\t\t\tauto m=(l+r)>>1;\n\t\t\t\tif(g 0)\n\t{\n\t\tsize_t s=0;\n\t\tforeach(ref e;ptrs)\n\t\t{\n\t\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\t\telse s+=readf(\" %s\",&e);\n\t\t}\n\t\treturn s==ptrs.length;\n\t}\n\tbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t{\n\t\tsize_t s=0;\n\t\tforeach(ref e;ptrs)\n\t\t{\n\t\t\tif(isSomeChar!(Unqual!(typeof(e))))s+=readf(\" %c\",&e);\n\t\t\telse s+=readf(\" %s\",&e);\n\t\t}\n\t\treadln;\n\t\treturn s==ptrs.length;\n\t}\n\tnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\n\tnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n\t@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n\tvoid enter(T...)(T args)\n\t{\n\t\twriteln(args);\n\t\tstdout.flush;\n\t}\n}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\nprivate\n{\n\t\n}\nvoid main()\n{\n\tversion(home)\n\t{\n\t\tassert(freopen(\"input.txt\",\"r\",core.stdc.stdio.stdin));\n\t\tassert(freopen(\"output.txt\",\"w\",core.stdc.stdio.stdout));\n\t}\n\tint n,x,y,w,h;\nloop:while(read(h,w,x,y,n))\n\t{\n\t\tauto a=arread!int;\n\t\tsort(a);\n\t\ta=a[max(0,sz(a)-34)..$];\n\t\treverse(a);\n\t\tauto dp=new lint[10^^5+1],d=new long[10^^5+1];\n\t\tdp[x]=d[x]=y;\n\t\tforeach(i;0..a.length)\n\t\t{\n\t\t\tforeach(j;0..dp.length)\n\t\t\t{\n\t\t\t\tif((j>=w && dp[j]>=h) || (j>=h && dp[j]>=w))\n\t\t\t\t{\n\t\t\t\t\twriteln(i);\n\t\t\t\t\tcontinue loop;\n\t\t\t\t}\n\t\t\t}\n\t\t\t//d[]=dp[];\n\t\t\tforeach(j;0..dp.length)\n\t\t\t{\n\t\t\t\tif(dp[j]!=0)\n\t\t\t\t{\n\t\t\t\t\tif(1L*j*a[i]<=10^^5)d[j*a[i]]=max(d[j*a[i]],dp[j]);\n\t\t\t\t\tif(1L*dp[j]*a[i]<=10^^5)d[j]=max(dp[j]*a[i],d[j]);\n\t\t\t\t}\n\t\t\t}\n\t\t\tdp[]=d[];\n\t\t}\n\t\tforeach(j;0..dp.length)\n\t\t{\n\t\t\tif((j>=w && dp[j]>=h) || (j>=h && dp[j]>=w))\n\t\t\t{\n\t\t\t\twriteln(a.length);\n\t\t\t\tcontinue loop;\n\t\t\t}\n\t\t}\n\t\twriteln(-1);\n\t}\n}"}], "src_uid": "18cb436618b2b85c3f5dc348c80882d5"} {"nl": {"description": "Soon a school Olympiad in Informatics will be held in Berland, n schoolchildren will participate there.At a meeting of the jury of the Olympiad it was decided that each of the n participants, depending on the results, will get a diploma of the first, second or third degree. Thus, each student will receive exactly one diploma.They also decided that there must be given at least min1 and at most max1 diplomas of the first degree, at least min2 and at most max2 diplomas of the second degree, and at least min3 and at most max3 diplomas of the third degree.After some discussion it was decided to choose from all the options of distributing diplomas satisfying these limitations the one that maximizes the number of participants who receive diplomas of the first degree. Of all these options they select the one which maximizes the number of the participants who receive diplomas of the second degree. If there are multiple of these options, they select the option that maximizes the number of diplomas of the third degree.Choosing the best option of distributing certificates was entrusted to Ilya, one of the best programmers of Berland. However, he found more important things to do, so it is your task now to choose the best option of distributing of diplomas, based on the described limitations.It is guaranteed that the described limitations are such that there is a way to choose such an option of distributing diplomas that all n participants of the Olympiad will receive a diploma of some degree.", "input_spec": "The first line of the input contains a single integer n (3\u2009\u2264\u2009n\u2009\u2264\u20093\u00b7106)\u00a0\u2014\u00a0the number of schoolchildren who will participate in the Olympiad. The next line of the input contains two integers min1 and max1 (1\u2009\u2264\u2009min1\u2009\u2264\u2009max1\u2009\u2264\u2009106)\u00a0\u2014\u00a0the minimum and maximum limits on the number of diplomas of the first degree that can be distributed. The third line of the input contains two integers min2 and max2 (1\u2009\u2264\u2009min2\u2009\u2264\u2009max2\u2009\u2264\u2009106)\u00a0\u2014\u00a0the minimum and maximum limits on the number of diplomas of the second degree that can be distributed. The next line of the input contains two integers min3 and max3 (1\u2009\u2264\u2009min3\u2009\u2264\u2009max3\u2009\u2264\u2009106)\u00a0\u2014\u00a0the minimum and maximum limits on the number of diplomas of the third degree that can be distributed. It is guaranteed that min1\u2009+\u2009min2\u2009+\u2009min3\u2009\u2264\u2009n\u2009\u2264\u2009max1\u2009+\u2009max2\u2009+\u2009max3.", "output_spec": "In the first line of the output print three numbers, showing how many diplomas of the first, second and third degree will be given to students in the optimal variant of distributing diplomas. The optimal variant of distributing diplomas is the one that maximizes the number of students who receive diplomas of the first degree. Of all the suitable options, the best one is the one which maximizes the number of participants who receive diplomas of the second degree. If there are several of these options, the best one is the one that maximizes the number of diplomas of the third degree.", "sample_inputs": ["6\n1 5\n2 6\n3 7", "10\n1 2\n1 3\n1 5", "6\n1 3\n2 2\n2 2"], "sample_outputs": ["1 2 3", "2 3 5", "2 2 2"], "notes": null}, "positive_code": [{"source_code": "import std.stdio;\nimport std.c.stdio;\nimport std.math;\nimport std.algorithm;\nimport std.conv;\nimport std.string;\nimport std.array;\n\nvoid main() {\n int n = readln().strip.to!int;\n int x, y, z, u, v, w;\n scanf(\"%d%d%d%d%d%d\", &x, &u, &y, &v, &z, &w);\n n -= x + y + z;\n int d, e, f;\n d = min(n, u - x);\n n -= d;\n x += d;\n\n e = min(n, v - y);\n n -= e;\n y += e;\n \n f = min(n, w - z);\n n -= f;\n z += f;\n\n writeln(x, ' ', y, ' ', z);\n}\n"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.conv;\nimport std.range;\n\nvoid main() {\n int n = readln.chomp.to!int;\n int[][] diploma;\n for (int i = 0; i < 3; i++) {\n diploma ~= readln.chomp.split.map!(to!int).array;\n }\n\n int dip_1 = min(diploma[0][1], n - (diploma[1][0] + diploma[2][0]));\n n -= dip_1;\n int dip_2 = min(diploma[1][1], n - diploma[2][0]);\n int dip_3 = n - dip_2;\n writeln(dip_1, \" \", dip_2, \" \", dip_3);\n}"}], "negative_code": [], "src_uid": "3cd092b6507079518cf206deab21cf97"} {"nl": {"description": "It's been long after the events of the previous problems, and Karen has now moved on from student life and is looking to relocate to a new neighborhood. The neighborhood consists of n houses in a straight line, labelled 1 to n from left to right, all an equal distance apart.Everyone in this neighborhood loves peace and quiet. Because of this, whenever a new person moves into the neighborhood, he or she always chooses the house whose minimum distance to any occupied house is maximized. If there are multiple houses with the maximum possible minimum distance, he or she chooses the leftmost one.Note that the first person to arrive always moves into house 1.Karen is the k-th person to enter this neighborhood. If everyone, including herself, follows this rule, which house will she move into?", "input_spec": "The first and only line of input contains two integers, n and k (1\u2009\u2264\u2009k\u2009\u2264\u2009n\u2009\u2264\u20091018), describing the number of houses in the neighborhood, and that Karen was the k-th person to move in, respectively.", "output_spec": "Output a single integer on a line by itself, the label of the house Karen will move into.", "sample_inputs": ["6 4", "39 3"], "sample_outputs": ["2", "20"], "notes": "NoteIn the first test case, there are 6 houses in the neighborhood, and Karen is the fourth person to move in: The first person moves into house 1. The second person moves into house 6. The third person moves into house 3. The fourth person moves into house 2. In the second test case, there are 39 houses in the neighborhood, and Karen is the third person to move in: The first person moves into house 1. The second person moves into house 39. The third person moves into house 20. "}, "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nlong[long][long] cache;\nlong calc(long d, long m) {\n long ret;\n if (d !in cache) {\n long[long] tmp;\n cache[d] = tmp;\n }\n cache[d].update(m, {\n if (m > 1) {\n const half = m / 2;\n if (half >= d) {\n ret += 1;\n ret += calc(d, m / 2);\n ret += calc(d, m - m / 2);\n }\n }\n debug {\n writefln(\"calc %s %s = %s\", d, m, ret);\n }\n return ret;\n }, (ref long r) {\n return ret = r;\n });\n return ret;\n}\n\nlong solve(long d, long a, long b, long k) {\n assert(1 <= k);\n assert(k <= calc(d, b - a));\n long ret;\n const mid = (a + b) / 2;\n if (k == 1) {\n ret = mid;\n } else {\n assert(b - a > 1);\n const resL0 = calc(d, mid - a);\n const resR1 = calc(d + 1, b - mid);\n assert(k > 0);\n if (k <= 1 + resL0 + resR1) {\n ret = solve(d, a, mid, k - 1 - resR1);\n } else {\n ret = solve(d, mid, b, k - 1 - resL0);\n }\n }\n debug {\n writefln(\"solve %s %s %s %s = %s\", d, a, b, k, ret);\n }\n return ret;\n}\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readLong();\n const K = readLong();\n debug {\n writefln(\"==== N = %s, K = %s ====\", N, K);\n cache.clear;\n }\n \n long ans;\n if (K == 1) {\n ans = 1;\n } else if (K == 2) {\n ans = N;\n } else {\n long lo = 0, hi = N;\n for (; lo + 1 < hi; ) {\n const mid = (lo + hi) / 2;\n ((2 + calc(mid, N - 1) >= K) ? lo : hi) = mid;\n }\n debug {\n writeln(\"lo = \", lo);\n cache.clear;\n }\n ans = solve(lo, 1, N, K - 2);\n }\n writeln(ans);\n \n debug {\n if (N <= 300) {\n auto used = new bool[N + 1];\n foreach (k; 1 .. K + 1) {\n long mx;\n long im = -1;\n foreach (i; 1 .. N + 1) {\n if (!used[i]) {\n long score = N;\n foreach (j; 1 .. N + 1) {\n if (used[j]) {\n chmin(score, abs(j - i));\n }\n }\n if (chmax(mx, score)) {\n im = i;\n }\n }\n }\n used[im] = true;\n if (k == K) {\n writeln(\"brt = \", im);\n assert(im == ans, format(\"WA %s %s: %s %s\", N, K, im, ans));\n }\n }\n }\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nlong[long][long] cache;\nlong calc(long d, long m) {\n long ret;\n if (d !in cache) {\n long[long] tmp;\n cache[d] = tmp;\n }\n cache[d].update(m, {\n if (m > 1) {\n const half = m / 2;\n if (half >= d) {\n ret += 1;\n ret += calc(d, m / 2);\n ret += calc(d, m - m / 2);\n }\n }\n debug {\n writefln(\"calc %s %s = %s\", d, m, ret);\n }\n return ret;\n }, (ref long r) {\n return ret = r;\n });\n return ret;\n}\n\nlong solve(long d, long a, long b, long k) {\n assert(1 <= k);\n assert(k <= calc(d, b - a));\n long ret;\n const mid = (a + b) / 2;\n if (k == 1) {\n ret = mid;\n } else {\n assert(b - a > 1);\n const resL0 = calc(d, mid - a);\n const resL1 = calc(d + 1, mid - a);\n const resR1 = calc(d + 1, mid - a);\n assert(k > 0);\n if (k <= 1 + resL0 + resR1) {\n ret = solve(d, a, mid, k - 1 - resR1);\n } else {\n ret = solve(d, mid, b, k - 1 - resL0);\n }\n }\n debug {\n writefln(\"solve %s %s %s %s = %s\", d, a, b, k, ret);\n }\n return ret;\n}\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readLong();\n const K = readLong();\n debug {\n writefln(\"==== N = %s, K = %s ====\", N, K);\n cache.clear;\n }\n \n long ans;\n if (K == 1) {\n ans = 1;\n } else if (K == 2) {\n ans = N;\n } else {\n long lo = 0, hi = N;\n for (; lo + 1 < hi; ) {\n const mid = (lo + hi) / 2;\n ((2 + calc(mid, N - 1) >= K) ? lo : hi) = mid;\n }\n debug {\n writeln(\"lo = \", lo);\n cache.clear;\n }\n ans = solve(lo, 1, N, K - 2);\n }\n writeln(ans);\n \n debug {\n if (N <= 300) {\n auto used = new bool[N + 1];\n foreach (k; 1 .. K + 1) {\n long mx;\n long im = -1;\n foreach (i; 1 .. N + 1) {\n if (!used[i]) {\n long score = N;\n foreach (j; 1 .. N + 1) {\n if (used[j]) {\n chmin(score, abs(j - i));\n }\n }\n if (chmax(mx, score)) {\n im = i;\n }\n }\n }\n used[im] = true;\n if (k == K) {\n writeln(\"brt = \", im);\n assert(im == ans, format(\"WA %s %s: %s %s\", N, K, im, ans));\n }\n }\n }\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "eb311bde6a0e3244d92fafbd4aa1e61f"} {"nl": {"description": "Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals n (n is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first n\u2009/\u20092 digits) equals the sum of digits in the second half (the sum of the last n\u2009/\u20092 digits). Check if the given ticket is lucky.", "input_spec": "The first line contains an even integer n (2\u2009\u2264\u2009n\u2009\u2264\u200950) \u2014 the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly n \u2014 the ticket number. The number may contain leading zeros.", "output_spec": "On the first line print \"YES\" if the given ticket number is lucky. Otherwise, print \"NO\" (without the quotes).", "sample_inputs": ["2\n47", "4\n4738", "4\n4774"], "sample_outputs": ["NO", "NO", "YES"], "notes": "NoteIn the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4\u2009\u2260\u20097).In the second sample the ticket number is not the lucky number."}, "positive_code": [{"source_code": "module _template;\nimport std.stdio;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n\nstruct IO {\n string read_string() {\n while (tokens.empty) {\n tokens = readln.split;\n }\n auto token = tokens.front;\n tokens.popFront;\n return token;\n }\n \n int read_int() {\n return read_string.to!int;\n }\n \n string[] tokens;\n}\n\nvoid main() {\n IO cin;\n int t = 1;\n // int t = cin.read_int;\n while (t--) {\n int n = cin.read_int;\n string s = cin.read_string;\n\n for (int i = 0; i < s.length; i++) {\n if (s[i] == '4' || s[i] == '7') {\n continue;\n } else {\n writeln(\"NO\");\n return;\n }\n }\n\n if (sum(s[0..n / 2]) == sum(s[n / 2..n])) {\n writeln(\"YES\");\n } else writeln(\"NO\");\n } \n}"}], "negative_code": [], "src_uid": "435b6d48f99d90caab828049a2c9e2a7"} {"nl": {"description": "Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off.You know that there will be n interesting minutes t1,\u2009t2,\u2009...,\u2009tn. Your task is to calculate for how many minutes Limak will watch the game.", "input_spec": "The first line of the input contains one integer n (1\u2009\u2264\u2009n\u2009\u2264\u200990)\u00a0\u2014 the number of interesting minutes. The second line contains n integers t1,\u2009t2,\u2009...,\u2009tn (1\u2009\u2264\u2009t1\u2009<\u2009t2\u2009<\u2009... tn\u2009\u2264\u200990), given in the increasing order.", "output_spec": "Print the number of minutes Limak will watch the game.", "sample_inputs": ["3\n7 20 88", "9\n16 20 30 40 50 60 70 80 90", "9\n15 20 30 40 50 60 70 80 90"], "sample_outputs": ["35", "15", "90"], "notes": "NoteIn the first sample, minutes 21,\u200922,\u2009...,\u200935 are all boring and thus Limak will turn TV off immediately after the 35-th minute. So, he would watch the game for 35 minutes.In the second sample, the first 15 minutes are boring.In the third sample, there are no consecutive 15 boring minutes. So, Limak will watch the whole game."}, "positive_code": [{"source_code": "module _template;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n\nstruct IO {\n string read_string() {\n while (tokens.empty) {\n tokens = readln.split;\n }\n auto token = tokens.front;\n tokens.popFront;\n return token;\n }\n \n int read_int() {\n return read_string.to!int;\n }\n \n string[] tokens;\n}\n\nvoid main() {\n IO cin;\n int t = 1;\n // int t = cin.read_int;\n while (t--) {\n int n = cin.read_int;\n int[] arr = new int[n];\n\n int ans = 0;\n for (int i = 0; i < n; i++) {\n arr[i] = cin.read_int;\n if (arr[0] > 15) {\n writeln(15);\n return;\n }\n if (i != 0) {\n if (arr[i] - arr[i - 1] > 15) {\n writeln(arr[i - 1] + 15);\n return;\n }\n }\n }\n if (arr[n - 1] + 15 >= 90) {\n writeln(90);\n } else writeln(arr[n - 1] + 15);\n } \n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\n\nconst int BORING = 15;\nconst int MATCH = 90;\n\nvoid main()\n{\n\tint n;\n\tint last = 0;\n\t\n\tscanf(\"%d\", &n);\n\tfor (int i = 0; i < n; i++) {\n\t\tint x;\n\t\t\n\t\tscanf(\"%d\", &x);\n\t\t\n\t\tif ((x - 1) - last >= BORING) {\n\t\t\tprintf(\"%d\\n\", last + BORING);\n\t\t\treturn;\n\t\t}\n\t\t\n\t\tlast = x;\n\t}\n\t\n\tprintf(\"%d\\n\", min(last + BORING, MATCH));\n}\n\n"}], "negative_code": [{"source_code": "module _template;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n\nstruct IO {\n string read_string() {\n while (tokens.empty) {\n tokens = readln.split;\n }\n auto token = tokens.front;\n tokens.popFront;\n return token;\n }\n \n int read_int() {\n return read_string.to!int;\n }\n \n string[] tokens;\n}\n\nvoid main() {\n IO cin;\n int t = 1;\n // int t = cin.read_int;\n while (t--) {\n int n = cin.read_int;\n int[] arr = new int[n];\n\n int ans = 0;\n for (int i = 0; i < n; i++) {\n arr[i] = cin.read_int;\n if (arr[0] > 15) {\n writeln(15);\n return;\n }\n if (i != 0) {\n if (arr[i] - arr[i - 1] > 15) {\n writeln(arr[i - 1] + 15);\n return;\n }\n }\n }\n writeln(90);\n } \n}"}], "src_uid": "5031b15e220f0ff6cc1dd3731ecdbf27"} {"nl": {"description": "In this problem you will meet the simplified model of game King of Thieves.In a new ZeptoLab game called \"King of Thieves\" your aim is to reach a chest with gold by controlling your character, avoiding traps and obstacles on your way. An interesting feature of the game is that you can design your own levels that will be available to other players. Let's consider the following simple design of a level.A dungeon consists of n segments located at a same vertical level, each segment is either a platform that character can stand on, or a pit with a trap that makes player lose if he falls into it. All segments have the same length, platforms on the scheme of the level are represented as '*' and pits are represented as '.'. One of things that affects speedrun characteristics of the level is a possibility to perform a series of consecutive jumps of the same length. More formally, when the character is on the platform number i1, he can make a sequence of jumps through the platforms i1\u2009<\u2009i2\u2009<\u2009...\u2009<\u2009ik, if i2\u2009-\u2009i1\u2009=\u2009i3\u2009-\u2009i2\u2009=\u2009...\u2009=\u2009ik\u2009-\u2009ik\u2009-\u20091. Of course, all segments i1,\u2009i2,\u2009... ik should be exactly the platforms, not pits. Let's call a level to be good if you can perform a sequence of four jumps of the same length or in the other words there must be a sequence i1,\u2009i2,\u2009...,\u2009i5, consisting of five platforms so that the intervals between consecutive platforms are of the same length. Given the scheme of the level, check if it is good.", "input_spec": "The first line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100) \u2014 the number of segments on the level. Next line contains the scheme of the level represented as a string of n characters '*' and '.'.", "output_spec": "If the level is good, print the word \"yes\" (without the quotes), otherwise print the word \"no\" (without the quotes).", "sample_inputs": ["16\n.**.*..*.***.**.", "11\n.*.*...*.*."], "sample_outputs": ["yes", "no"], "notes": "NoteIn the first sample test you may perform a sequence of jumps through platforms 2,\u20095,\u20098,\u200911,\u200914."}, "positive_code": [{"source_code": "import std.conv;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\n\nvoid main() {\n\treadln;\n\tauto s = readln.strip;\n\n\tif(s.count('*') >= 5) {\n\t\twhile(true) {\n\t\t\tauto idx = cast(int)s.countUntil('*');\n\t\t\tif(idx < 0) break;\n\n\t\t\tforeach(k; 1..26) {\n\t\t\t\tubyte c;\n\n\t\t\t\tfor(uint i = idx; i < s.length && s[i] == '*'; c++, i += k) {}\n\n\t\t\t\tif(c >= 5) return `yes`.write;\n\t\t\t}\n\n\t\t\ts = s[idx + 1..$];\n\t\t}\n\t}\n\n\t`no`.write;\n}\n"}, {"source_code": "import std.stdio;\nimport std.range;\nimport std.array;\n\nT read(T)()\n{\n T t;\n readf(\" %s\", &t);\n return t;\n}\n\nint main(string[] args)\n{\n auto T = read!int;\n readln;\n auto arr = readln;\n arr = arr[0..T];\n arr ~= repeat('.', T).array;\n\n for (int i = 0; i < T; i++)\n {\n for (int j = 1; j < T; j++)\n {\n if (\n arr[i + j*0] == '*' &&\n arr[i + j*1] == '*' &&\n arr[i + j*2] == '*' &&\n arr[i + j*3] == '*' &&\n arr[i + j*4] == '*')\n {\n writeln(\"yes\");\n return 0;\n }\n }\n }\n\n writeln(\"no\");\n\n return 0;\n}\n"}, {"source_code": "\ufeffimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n\t\n\tint n = readln.strip.to!int;\n\tstring s = readln.strip;\n\t\n\tforeach (from; 0 .. n) {\n\t\tif (s[from] != '.')\n\t\tforeach (jump; 1 .. n) {\n\t\t\tbool ok;\n\t\t\tforeach (i; 1 .. 5) {\n\t\t\t\tint pos = from + i * jump;\n\t\t\t\tif (pos >= n || s[pos] != '*') {\n\t\t\t\t\tok = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!ok)\n\t\t\t\treturn write(\"yes\");\n\t\t}\n\t}\n\t\n\twrite(\"no\");\n}"}, {"source_code": "\ufeffimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n\t\n\tint n = readln.strip.to!int;\n\tstring s = readln.strip;\n\t\n\tforeach (from; 0 .. n)\n\tforeach (jump; 1 .. n) {\n\t\tbool ok;\n\t\tforeach (i; 0 .. 5) {\n\t\t\tint pos = from + i * jump;\n\t\t\tif (pos >= n || s[pos] != '*') {\n\t\t\t\tok = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (!ok)\n\t\t\treturn \"yes\".write;\n\t}\n\t\n\t\"no\".write;\n}"}, {"source_code": "\ufeffimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n\n\tint n = readln.strip.to!int;\n\tstring s = readln.strip;\n\n\tint[] idx;\n\tforeach (i, e; s)\n\t\tif (e == '*')\n\t\t\tidx ~= i;\n\t\n\tforeach (from; idx) {\n\t\tforeach (jump; 1 .. n) {\n\t\t\tbool ok;\n\t\t\tforeach (i; 1 .. 5) {\n\t\t\t\tint pos = from + i * jump;\n\t\t\t\tif (pos >= n || s[pos] != '*') {\n\t\t\t\t\tok = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!ok)\n\t\t\t\treturn write(\"yes\");\n\t\t}\n\t}\n\t\n\twrite(\"no\");\n}"}, {"source_code": "\ufeffimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n\n\tint n = readln.strip.to!int;\n\tstring s = readln.strip;\n\n\tforeach (from; 0 .. n)\n\t\tforeach (jump; 1 .. n) {\n\t\t\tbool ok;\n\t\t\tforeach (i; 0 .. 5) {\n\t\t\t\tint pos = from + i * jump;\n\t\t\t\tif (pos >= n || s[pos] != '*') {\n\t\t\t\t\tok = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!ok)\n\t\t\t\treturn `yes`.write;\n\t\t}\n\n\t`no`.write;\n}"}, {"source_code": "\ufeffimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n\t\n\tint n = readln.strip.to!int;\n\tstring s = readln.strip;\n\t\n\tforeach (from; 0 .. n) {\n\t\tif (s[from] != '.')\n\t\tforeach (jump; 1 .. n) {\n\t\t\tbool ok;\n\t\t\tforeach (i; 0 .. 5) {\n\t\t\t\tint pos = from + i * jump;\n\t\t\t\tif (pos >= n || s[pos] != '*') {\n\t\t\t\t\tok = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!ok)\n\t\t\t\treturn write(\"yes\");\n\t\t}\n\t}\n\t\n\twrite(\"no\");\n}"}, {"source_code": "\ufeffimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n\t\n\tint n = readln.strip.to!int;\n\tstring s = readln.strip;\n\t\n\tforeach (from; 0 .. n)\n\tforeach (jump; 1 .. n) {\n\t\tbool ok;\n\t\tforeach (i; 0 .. 5) {\n\t\t\tint pos = from + i * jump;\n\t\t\tif (pos >= n || s[pos] != '*') {\n\t\t\t\tok = true;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\tif (!ok)\n\t\t\treturn write(\"yes\");\n\t}\n\t\n\twrite(\"no\");\n}"}, {"source_code": "import std.algorithm, std.conv, std.range, std.stdio, std.string;\nvoid main() {\n\tauto n = readln.strip.to!int, s = readln.strip;\n\twriteln (iota (1, n).any !(d => iota (d).any !(p =>\n\t\ts.drop (p).stride (d).canFind (\"*****\"))) ? \"yes\" : \"no\");\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s \", &n) > 0)\n\t{\n\t\tauto s = readln ().strip ();\n\t\tbool ok = false;\n\t\tforeach (d; 1..n)\n\t\t{\n\t\t\tforeach (p; 0..n)\n\t\t\t{\n\t\t\t\tif (p + d * 4 < n)\n\t\t\t\t{\n\t\t\t\t\tif (s.drop (p)\n\t\t\t\t\t .stride (d)\n\t\t\t\t\t .takeExactly (5)\n\t\t\t\t\t .all !(q{a == '*'}))\n\t\t\t\t\t{\n\t\t\t\t\t\tok = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriteln (ok ? \"yes\" : \"no\");\n\t}\n}\n"}, {"source_code": "import std.algorithm, std.conv, std.range, std.stdio, std.string;\nvoid main() {\n\tauto n = readln.strip.to!int, s = readln.strip;\n\twriteln (iota (1, n).any !(d => iota (d).any !(p =>\n\t\ts.drop (p).stride (d).canFind (\"*****\"))) ? \"yes\" : \"no\");\n}\n"}], "negative_code": [{"source_code": "import std.conv;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\n\nvoid main() {\n\treadln;\n\tauto s = readln.strip;\n\n\tif(s.count('*') >= 5) {\n\t\twhile(true) {\n\t\t\tauto idx = cast(int)s.countUntil('*');\n\t\t\tif(idx < 0) break;\n\n\t\t\tforeach(k; 1..21) {\n\t\t\t\tubyte c;\n\n\t\t\t\tfor(uint i = idx; i < s.length && s[i] == '*'; c++, i += k) {}\n\n\t\t\t\tif(c >= 5) return `yes`.write;\n\t\t\t}\n\n\t\t\ts = s[idx + 1..$];\n\t\t}\n\t}\n\n\t`no`.write;\n}\n"}, {"source_code": "\ufeffimport std.stdio;\n\nvoid main() {\n\n\twriteln(__VERSION__);\n}"}, {"source_code": "\ufeffimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n\t\n\tint n = readln.strip.to!int;\n\tstring s = readln.strip;\n\t\n\tforeach (from; 0 .. n) {\n\t\tif (s[from] != '.')\n\t\tforeach (jump; 1 .. n) {\n\t\t\tbool ok;\n\t\t\tforeach (i; 0 .. 5) {\n\t\t\t\tint pos = from + i * jump;\n\t\t\t\tif (pos >= n || s[pos] != '*') {\n\t\t\t\t\twriteln(\"break\");\n\t\t\t\t\tok = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (!ok)\n\t\t\t\treturn write(\"yes\");\n\t\t}\n\t}\n\t\n\twrite(\"no\");\n}"}], "src_uid": "12d451eb1b401a8f426287c4c6909e4b"} {"nl": {"description": "Two bears are playing tic-tac-toe via mail. It's boring for them to play usual tic-tac-toe game, so they are a playing modified version of this game. Here are its rules.The game is played on the following field. Players are making moves by turns. At first move a player can put his chip in any cell of any small field. For following moves, there are some restrictions: if during last move the opposite player put his chip to cell with coordinates (xl,\u2009yl) in some small field, the next move should be done in one of the cells of the small field with coordinates (xl,\u2009yl). For example, if in the first move a player puts his chip to lower left cell of central field, then the second player on his next move should put his chip into some cell of lower left field (pay attention to the first test case). If there are no free cells in the required field, the player can put his chip to any empty cell on any field.You are given current state of the game and coordinates of cell in which the last move was done. You should find all cells in which the current player can put his chip.A hare works as a postman in the forest, he likes to foul bears. Sometimes he changes the game field a bit, so the current state of the game could be unreachable. However, after his changes the cell where the last move was done is not empty. You don't need to find if the state is unreachable or not, just output possible next moves according to the rules.", "input_spec": "First 11 lines contains descriptions of table with 9 rows and 9 columns which are divided into 9 small fields by spaces and empty lines. Each small field is described by 9 characters without spaces and empty lines. character \"x\" (ASCII-code 120) means that the cell is occupied with chip of the first player, character \"o\" (ASCII-code 111) denotes a field occupied with chip of the second player, character \".\" (ASCII-code 46) describes empty cell. The line after the table contains two integers x and y (1\u2009\u2264\u2009x,\u2009y\u2009\u2264\u20099). They describe coordinates of the cell in table where the last move was done. Rows in the table are numbered from up to down and columns are numbered from left to right. It's guaranteed that cell where the last move was done is filled with \"x\" or \"o\". Also, it's guaranteed that there is at least one empty cell. It's not guaranteed that current state of game is reachable.", "output_spec": "Output the field in same format with characters \"!\" (ASCII-code 33) on positions where the current player can put his chip. All other cells should not be modified.", "sample_inputs": ["... ... ...\n... ... ...\n... ... ...\n\n... ... ...\n... ... ...\n... x.. ...\n\n... ... ...\n... ... ...\n... ... ...\n6 4", "xoo x.. x..\nooo ... ...\nooo ... ...\n\nx.. x.. x..\n... ... ...\n... ... ...\n\nx.. x.. x..\n... ... ...\n... ... ...\n7 4", "o.. ... ...\n... ... ...\n... ... ...\n\n... xxx ...\n... xox ...\n... ooo ...\n\n... ... ...\n... ... ...\n... ... ...\n5 5"], "sample_outputs": ["... ... ... \n... ... ... \n... ... ... \n\n... ... ... \n... ... ... \n... x.. ... \n\n!!! ... ... \n!!! ... ... \n!!! ... ...", "xoo x!! x!! \nooo !!! !!! \nooo !!! !!! \n\nx!! x!! x!! \n!!! !!! !!! \n!!! !!! !!! \n\nx!! x!! x!! \n!!! !!! !!! \n!!! !!! !!!", "o!! !!! !!! \n!!! !!! !!! \n!!! !!! !!! \n\n!!! xxx !!! \n!!! xox !!! \n!!! ooo !!! \n\n!!! !!! !!! \n!!! !!! !!! \n!!! !!! !!!"], "notes": "NoteIn the first test case the first player made a move to lower left cell of central field, so the second player can put a chip only to cells of lower left field.In the second test case the last move was done to upper left cell of lower central field, however all cells in upper left field are occupied, so the second player can put his chip to any empty cell.In the third test case the last move was done to central cell of central field, so current player can put his chip to any cell of central field, which is already occupied, so he can move anywhere. Pay attention that this state of the game is unreachable."}, "positive_code": [{"source_code": "import std.stdio, std.string, std.conv, std.algorithm, std.numeric;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\nimport std.ascii;\n\nvoid main() {\n auto bd = new char[][](11, 11);\n bd.fillAll(' ');\n foreach (i ; 0 .. 11) {\n auto s = readln.chomp;\n if (i == 3 || i == 7) continue;\n bd[i][] = s.to!(char[]);\n }\n int x, y;\n scan(x, y);\n x--, y--;\n x %= 3;\n y %= 3;\n\n bool fc = 1;\n\n foreach (i ; x*4 .. x*4 + 3) {\n foreach (j ; y*4 .. y*4 + 3) {\n if (bd[i][j] == '.') {\n fc = 0;\n bd[i][j] = '!';\n }\n }\n }\n\n if (fc) {\n foreach (i ; 0 .. 11) {\n foreach (j ; 0 .. 11) {\n if (bd[i][j] == '.') {\n bd[i][j] = '!';\n }\n }\n }\n }\n\n writefln(\"%(%(%c%)\\n%)\", bd);\n}\n\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}"}], "negative_code": [], "src_uid": "8f0fad22f629332868c39969492264d3"} {"nl": {"description": "You're given a string of lower-case Latin letters. Your task is to find the length of its longest substring that can be met in the string at least twice. These occurrences can overlap (see sample test 2).", "input_spec": "The first input line contains the string. It's guaranteed, that the string is non-empty, consists of lower-case Latin letters, and its length doesn't exceed 100.", "output_spec": "Output one number \u2014 length of the longest substring that can be met in the string at least twice.", "sample_inputs": ["abcd", "ababa", "zzz"], "sample_outputs": ["0", "3", "2"], "notes": null}, "positive_code": [{"source_code": "module _template;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n\nstruct IO {\n string[] tk;\n string read_string() {\n while (tk.empty) \n tk = readln.split;\n auto tkt = tk.front;\n tk.popFront;\n return tkt;\n }\n int read_int() { \n return read_string.to!int; \n }\n double read_double() { \n return read_string.to!double; \n }\n}\n\nint count_substr(char[] s, char[] sample) {\n int count = 0;\n for (int i = 0; i < s.length - sample.length + 1; i++) {\n if (s[i..i + sample.length] == sample) {\n count++; \n }\n }\n return count;\n}\n\nvoid main() {\n IO cin;\n int t = 1;\n // t = cin.read_int;\n while (t--) {\n char[] s = cin.read_string.dup;\n\n int l = s.length;\n int maxx = -999;\n for (int i = l - 1; i >= 1; i--) {\n for (int j = 0; j < l - i + 1; j++) {\n int c = count_substr(s, s[j..j + i]); \n if (c >= 2) {\n writeln(s[j..j + i].length);\n return;\n }\n }\n }\n writeln(0);\n } \n}"}, {"source_code": "module _template;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n\nstruct IO {\n string[] tk;\n string read_string() {\n while (tk.empty) \n tk = readln.split;\n auto tkt = tk.front;\n tk.popFront;\n return tkt;\n }\n int read_int() { \n return read_string.to!int; \n }\n double read_double() { \n return read_string.to!double; \n }\n}\n\nint count_substr(char[] s, char[] sample) {\n int count = 0;\n for (int i = 0; i < s.length - sample.length + 1; i++) {\n if (s[i..i + sample.length] == sample) {\n count++; \n }\n }\n return count;\n}\n\nvoid main() {\n IO cin;\n int t = 1;\n // t = cin.read_int;\n while (t--) {\n char[] s = cin.read_string.dup;\n\n int l = s.length;\n int maxx = -999;\n for (int i = l - 1; i >= 1; i--) {\n for (int j = 0; j < l - i + 1; j++) {\n int c = count_substr(s, s[j..j + i]); \n if (c >= 2) {\n writeln(i);\n return;\n }\n }\n }\n writeln(0);\n } \n}"}, {"source_code": "import std.string, std.algorithm, std.stdio, std.range, std.array, std.typecons;\n\nvoid main()\n{\n auto s = readln.chomp;\n auto d = s.length.iota.retro.dropOne.map!(\n a => {\n string[] d = s.slide(a+1).map!\"a.text\".array;\n d.sort;\n return d.group.maxElement!\"a[1]\"; }()\n ).find!\"a[1]>b[1]\"(tuple(1,1));\n writeln(d.length>0?d[0][0].length:0);\n}"}], "negative_code": [], "src_uid": "13b5cf94f2fabd053375a5ccf3fd44c7"} {"nl": {"description": "Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money.Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance.Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift.", "input_spec": "The single line contains integer n (10\u2009\u2264\u2009|n|\u2009\u2264\u2009109) \u2014 the state of Ilya's bank account.", "output_spec": "In a single line print an integer \u2014 the maximum state of the bank account that Ilya can get. ", "sample_inputs": ["2230", "-10", "-100003"], "sample_outputs": ["2230", "0", "-10000"], "notes": "NoteIn the first test sample Ilya doesn't profit from using the present.In the second test sample you can delete digit 1 and get the state of the account equal to 0."}, "positive_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\nimport std.algorithm;\n\n// main================\nvoid main(){\n auto moneyStr = readln.chomp.dup;\n if(moneyStr.to!int >= 0){ writeln(moneyStr.to!int); }\n else{\n auto a = moneyStr[0..$-1].to!int;\n auto b = (moneyStr[0..$-2] ~ moneyStr[$-1]).to!int;\n max(a, b).writeln;\n }\n}\n"}, {"source_code": "module _template;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n\nstruct IO {\n string[] tk;\n string readString() {\n while (tk.empty) \n tk = readln.split;\n auto tkt = tk.front;\n tk.popFront;\n return tkt;\n }\n int readInt() { \n return readString.to!int; \n }\n double readDouble() { \n return readString.to!double; \n }\n}\n\nint solve(string s) {\n if (s.to!int > 0) return s.to!int;\n else {\n if (s.to!int > -10) return s.to!int;\n else {\n char[] s1 = s.dup;\n int n = s1.length;\n if (s1[n - 1] < s[n - 2]) {\n s1 = s1.remove(n - 2);\n } else s1 = s1.remove(n - 1);\n return s1.to!int;\n }\n }\n}\nvoid main() {\n IO cin;\n int t = 1;\n // t = cin.readInt;\n while (t--) {\n string s = cin.readString;\n writeln(solve(s));\n } \n}"}, {"source_code": "import std.stdio\n , std.typecons\n , std.traits\n , std.algorithm;\n\n\n\n\nT modulus(T)(auto ref T val) {\n import std.conv: to;\n return (val > 0.to!T\n ? val\n : -val);\n}\n\n\n\nvoid main() {\n \n long n;\n \n readf(\"%s\\n\", &n);\n //uint count;\n while(true) {\n //count.writeln;\n if(n >= 0) {\n writeln(n);\n return;\n }\n \n \n auto n2 = n.modulus % 100;\n \n if(n2 % 10 < n2 / 10) {\n const t = n.modulus / 100 * 10 + n2 % 10;\n writeln((t != 0 ? \"-\" : \"\"), t);\n }\n else\n {\n \n const t = n.modulus / 100 * 10 + n2 / 10;\n writeln((t != 0 ? \"-\" : \"\"), t);\n }\n \n //readf(\"%s\\n\", &n);\n //++count;\n break;\n }\n \n \n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "import std.stdio\n , std.typecons\n , std.traits\n , std.algorithm;\n\n\n\n\nT mod(T)(auto ref T val) {\n import std.conv: to;\n return (val > 0.to!T\n ? val\n : -val);\n}\n\n\n\nvoid main() {\n \n long n;\n \n readf(\"%s\\n\", &n);\n \n while(true) {\n if(n >= 0) {\n writeln(n);\n return;\n }\n \n \n auto n2 = n.mod % 100;\n \n if(n2 % 10 < n2 / 10) {\n const t = n.mod / 100 * 10 + n2 % 10;\n writeln((t != 0 ? \"-\" : \"\"), t);\n }\n else\n {\n \n const t = n.mod / 100 * 10 + n2 / 10;\n writeln((t != 0 ? \"-\" : \"\"), t);\n }\n break;\n }\n \n \n}"}, {"source_code": "import std.stdio;\nimport core.stdc.stdio;\n\nint main(string[] argv)\n{\n\tlong n;\n\tscanf(\"%lld\", &n);\n\tlong a = n % 100;\n\tlong b = (n / 100) * 10;\n\tlong n1 = b + (a % 10);\n\tlong n2 = b + ((a / 10) % 10);\n\twrite(n > n1 ? n : n1 > n2 ? n1 : n2);\n\treturn 0;\n}"}, {"source_code": "import std.stdio, std.string, std.conv;\nimport std.algorithm, std.math;\n\nstring[] tokens;\nint tokenId = 0;\nstring readToken() { for (; tokenId == tokens.length; ) tokens = readln.split, tokenId = 0; return tokens[tokenId++]; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\nint del(int a) {\n\tint temp = abs(a);\n\tint first = temp / 10;\n\tint second = (temp / 100) * 10 + temp % 10;\n\tfirst *= -1;\n\tsecond *= -1;\n\tif(first < second) return second;\n\treturn first;\n}\n\nvoid main () {\n\tint a = readInt();\n\t\n\tif(a >= 0) writeln(a);\n\telse writeln(del(a));\n}"}, {"source_code": "//ahmat\nimport core.stdc.stdio:printf,scanf;\nimport std.stdio;\nimport std.string;\nimport std.container;\nimport std.array;\nimport std.range;\nimport std.algorithm;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.bitmanip;\nimport core.bitop;\nint sz(Range)(in Range r){return cast(int)r.length;}\nalias rbt=RedBlackTree!int;\n\nvoid main(){\n\tint n=readln.chomp.to!int;\n\tif(n<0){\n\t\twriteln(max(n/10,10*(n/100)+n%10));\n\t}else writeln(n);\n}"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.stdio;\n\nvoid main ()\n{\n foreach (s; stdin.byLine ())\n {\n writeln (max (to!int (s), to!int (s[0..$ - 1]),\n to!int (s[0..$ - 2] ~ s[$ - 1])));\n }\n}\n"}, {"source_code": "import std.algorithm, std.stdio;\n\nvoid main ()\n{\n\tint n;\n\treadf (\" %s\", &n);\n\twriteln (max (n, n / 10, n / 100 * 10 + n % 10));\n}\n"}, {"source_code": "import std.algorithm;\nimport std.stdio;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) != 0)\n\t{\n\t\twriteln (max (n, n / 10, n / 100 * 10 + n % 10));\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tstring s;\n\twhile ((s = readln ().strip ()) != null)\n\t{\n\t\tif (s[0] == '-')\n\t\t{\n\t\t\twriteln (max (to!int (s[0..$ - 1]),\n\t\t\t to!int (s[0..$ - 2] ~ s[$ - 1])));\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln (s);\n\t\t}\n\t}\n}\n"}, {"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\n\nvoid main() {\n string n = readln.chomp;\n if (n.to!long > 0) {\n writeln(n);\n } else {\n if (n[$-2].to!int < n[$-1].to!int) {\n writeln(n[0..$-1].to!long);\n } else {\n writeln((n[0..$-2] ~ n[$-1]).to!long);\n }\n }\n}"}, {"source_code": "import std.stdio: readln, writeln;\nimport std.string: strip;\nimport std.conv: to;\nimport std.algorithm: max;\n\n/**\n * User: Jior\n * Date: 03.06.13\n * Time: 13:13\n */\n\nvoid main(string[] args) {\n char[] buffer = strip(readln()).dup;\n int account = to!int(buffer);\n\n if (account < 0 && buffer.length > 2) {\n int var1 = to!int(buffer[0..$-1]);\n int var2 = to!int(buffer[0..$-2] ~ buffer[$-1..$]);\n\n if(var1 > account || var2 > account)\n writeln(max(var1, var2));\n } else {\n writeln(account);\n } \n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main() {\n //stdin.open(\"input.txt\", \"r\");\n //stdout.open(\"output.txt\", \"w\");\n string num = strip(readln());\n if (num[0] == '-') {\n int a = to!int(num[0..$-1]);\n int b = to!int(num[0..$-2] ~ num[$-1..$]);\n writeln(a > b ? a : b);\n } else {\n writeln(num);\n }\n}"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\nimport std.algorithm;\n\n// main================\nvoid main(){\n auto moneyStr = readln.chomp.dup;\n auto a = moneyStr[0..$-1].to!int;\n auto b = (moneyStr[0..$-2] ~ moneyStr[$-1]).to!int;\n max(a, b).writeln;\n}\n"}, {"source_code": "module _template;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n\nstruct IO {\n string[] tk;\n string readString() {\n while (tk.empty) \n tk = readln.split;\n auto tkt = tk.front;\n tk.popFront;\n return tkt;\n }\n int readInt() { \n return readString.to!int; \n }\n double readDouble() { \n return readString.to!double; \n }\n}\n\nint solve(string s) {\n if (s.to!int > 0) return s.to!int;\n else {\n if (s.to!int > -10) return s.to!int;\n else {\n char[] s1 = s.dup;\n s1 = s1.remove(s1.indexOf(max(s1[s1.length - 1], s1[s1.length - 2])));\n return s1.to!int;\n }\n }\n}\nvoid main() {\n IO cin;\n int t = 1;\n // t = cin.readInt;\n while (t--) {\n string s = cin.readString;\n writeln(solve(s));\n } \n}"}, {"source_code": "module _template;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n\nstruct IO {\n string[] tk;\n string readString() {\n while (tk.empty) \n tk = readln.split;\n auto tkt = tk.front;\n tk.popFront;\n return tkt;\n }\n int readInt() { \n return readString.to!int; \n }\n double readDouble() { \n return readString.to!double; \n }\n}\n\nint solve(string s) {\n if (s.to!int > 0) return s.to!int;\n else {\n if (s.to!int > -10) return s.to!int;\n else {\n char[] s1 = s.dup;\n reverse(s1);\n s1 = s1.remove(s1.indexOf(max(s1[s1.length - 1], s1[s1.length - 2])));\n reverse(s1);\n return s1.to!int;\n }\n }\n}\nvoid main() {\n IO cin;\n int t = 1;\n // t = cin.readInt;\n while (t--) {\n string s = cin.readString;\n writeln(solve(s));\n } \n}"}, {"source_code": "import std.stdio\n , std.typecons\n , std.traits\n , std.algorithm;\n\n\n\n\nT modulus(T)(auto ref T val) {\n import std.conv: to;\n return (val > 0.to!T\n ? val\n : -val);\n}\n\n\n\nvoid main() {\n \n long n;\n \n readf(\"%s\\n\", &n);\n //uint count;\n while(true) {\n //count.writeln;\n if(n >= 0) {\n writeln(n);\n return;\n }\n \n \n auto n2 = n.modulus % 100;\n \n if(n2 % 10 < n2 / 10) {\n writeln(\"-\", n.modulus / 100 * 10 + n2 % 10);\n }\n else\n {\n \n const t = n.modulus / 100 * 10 + n2 / 10;\n writeln((t != 0 ? \"-\" : \"\"), n.modulus / 100 * 10 + n2 / 10);\n }\n \n //readf(\"%s\\n\", &n);\n //++count;\n break;\n }\n \n \n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "import std.stdio\n , std.typecons\n , std.traits\n , std.algorithm;\n\n\n\n\nT modulus(T)(auto ref T val) {\n import std.conv: to;\n return (val > 0.to!T\n ? val\n : -val);\n}\n\n\n\nvoid main() {\n \n long n;\n \n readf(\"%s\\n\", &n);\n //uint count;\n while(true) {\n //count.writeln;\n if(n >= 0) {\n writeln(n);\n return;\n }\n \n \n auto n2 = n.modulus % 100;\n \n if(n2 % 10 < n2 / 10) {\n writeln(\"-\", n.modulus / 100 * 10 + n2 % 10);\n }\n else\n {\n writeln(\"-\", n.modulus / 100 * 10 + n2 / 10);\n }\n \n //readf(\"%s\\n\", &n);\n //++count;\n break;\n }\n \n \n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "import std.stdio\n , std.typecons\n , std.traits\n , std.algorithm;\n\n\n\n\nT modulus(T)(auto ref T val) {\n import std.conv: to;\n return (val > 0.to!T\n ? val\n : -val);\n}\n\n\n\nvoid main() {\n \n long n;\n \n readf(\"%s\\n\", &n);\n //uint count;\n while(true) {\n //count.writeln;\n if(n >= 0) {\n writeln(n);\n return;\n }\n \n \n auto n2 = n.modulus % 100;\n \n if(n2 % 10 > n2 / 10) {\n writeln(\"-\", n.modulus / 100 * 10 + n2 % 10);\n }\n else\n {\n writeln(\"-\", n.modulus / 100 * 10 + n2 / 10);\n }\n \n //readf(\"%s\\n\", &n);\n //++count;\n break;\n }\n \n \n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"}, {"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\n\nvoid main() {\n string n = readln.chomp;\n if (n.to!long > 0) {\n writeln(n);\n } else {\n if (n[$-2].to!int < n[$-1].to!int) {\n writeln(n[0..$-1]);\n } else {\n writeln(n[0..$-2], n[$-1]);\n }\n }\n}"}, {"source_code": "import std.stdio: readln, writeln;\nimport std.string: strip;\nimport std.conv: to;\nimport std.algorithm: max;\n\n/**\n * User: Jior\n * Date: 03.06.13\n * Time: 13:13\n */\n\nvoid main(string[] args) {\n char[] buffer = strip(readln()).dup;\n int account = to!int(buffer);\n\n if (account < 0 && buffer.length > 2) {\n int var1 = to!int(buffer[0..$-1]);\n int var2 = to!int(buffer[0..$-2] ~ buffer[$-1..$]);\n\n if(var1 > account || var2 > account)\n writeln(max(var1, var2));\n } \n}\n"}], "src_uid": "4b0a8798a6d53351226d4f06e3356b1e"} {"nl": {"description": "Polycarp plays \"Game 23\". Initially he has a number $$$n$$$ and his goal is to transform it to $$$m$$$. In one move, he can multiply $$$n$$$ by $$$2$$$ or multiply $$$n$$$ by $$$3$$$. He can perform any number of moves.Print the number of moves needed to transform $$$n$$$ to $$$m$$$. Print -1 if it is impossible to do so.It is easy to prove that any way to transform $$$n$$$ to $$$m$$$ contains the same number of moves (i.e. number of moves doesn't depend on the way of transformation).", "input_spec": "The only line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\le n \\le m \\le 5\\cdot10^8$$$).", "output_spec": "Print the number of moves to transform $$$n$$$ to $$$m$$$, or -1 if there is no solution.", "sample_inputs": ["120 51840", "42 42", "48 72"], "sample_outputs": ["7", "0", "-1"], "notes": "NoteIn the first example, the possible sequence of moves is: $$$120 \\rightarrow 240 \\rightarrow 720 \\rightarrow 1440 \\rightarrow 4320 \\rightarrow 12960 \\rightarrow 25920 \\rightarrow 51840.$$$ The are $$$7$$$ steps in total.In the second example, no moves are needed. Thus, the answer is $$$0$$$.In the third example, it is impossible to transform $$$48$$$ to $$$72$$$."}, "positive_code": [{"source_code": "import std.stdio;\nimport std.array;\nimport std.algorithm.iteration;\n\nint solve(int n , int m) {\n if (m == n) return 0;\n if (m % n != 0) return -1;\n auto d = m/n;\n auto count = 0;\n if (d%2 != 0 && d%3!=0) return -1;\n while (d%6 == 0) {count+=2; d/=6;}\n while (d%3 == 0) {count++; d/=3;}\n while (d%2 == 0) {count++; d/=2;}\n if (d!=1) return -1;\n return count;\n}\n\nvoid main()\n{\n assert(solve(120,51840) == 7);\n assert(solve(42,42)==0);\n assert(solve(48,72)==-1);\n\n auto nm = readln.split.map!\"a.to!int\";\n auto n = nm[0], m =nm[1];\n writeln(solve(n,m));\n}\n"}, {"source_code": "void main() {\n import std.stdio;\n import std.algorithm;\n import std.string;\n import std.conv;\n\n auto x = readln().split;\n const long start = x[0].to!long;\n long desti = x[1].to!long;\n\n if(desti == start) {\n \"0\".writeln;\n } else if(desti % start != 0) {\n \"-1\".writeln;\n } else if(desti % 2 != 0 && desti % 3 != 0) {\n \"-1\".writeln;\n } else {\n int cnt = 0;\n desti /= start;\n while(desti > 1) {\n if(desti % 3 == 0) {\n desti /= 3;\n } else if(desti % 2 == 0) {\n desti /= 2;\n } else {\n cnt = -1;\n break;\n }\n cnt++;\n }\n cnt.writeln;\n }\n}"}], "negative_code": [{"source_code": "void main() {\n import std.stdio;\n import std.algorithm;\n import std.string;\n import std.conv;\n\n auto x = readln().split;\n const long start = x[0].to!long;\n long desti = x[1].to!long;\n if(desti == start) {\n \"0\".writeln;\n } else if(desti % start != 0) {\n \"-1\".writeln;\n } else if(desti % 2 != 0 && desti % 3 != 0) {\n \"-1\".writeln;\n } else {\n int cnt = 0;\n while(desti > start) {\n if(desti % 3 != 0) {\n desti /= 2;\n } else {\n desti /= 3;\n }\n cnt++;\n }\n cnt.writeln;\n }\n}"}, {"source_code": "void main() {\n import std.stdio;\n import std.algorithm;\n import std.string;\n import std.conv;\n\n auto x = readln().split;\n const long start = x[0].to!long;\n long desti = x[1].to!long;\n\n if(desti == start) {\n \"0\".writeln;\n } else if(desti % start != 0) {\n \"-1\".writeln;\n } else if(desti % 2 != 0 && desti % 3 != 0) {\n \"-1\".writeln;\n } else {\n int cnt = 0;\n desti /= start;\n while(desti > 1) {\n if(desti % 3 != 0) {\n desti /= 2;\n } else {\n desti /= 3;\n }\n cnt++;\n }\n cnt.writeln;\n }\n}"}, {"source_code": "void main() {\n import std.stdio;\n import std.algorithm;\n import std.string;\n import std.conv;\n\n auto x = readln().split;\n const int start = x[0].to!int;\n int desti = x[1].to!int;\n if(desti == start) {\n \"0\".writeln;\n } else if(desti % start != 0) {\n \"-1\".writeln;\n } else if(desti % 2 != 0 && desti % 3 != 0) {\n \"-1\".writeln;\n } else {\n int cnt = 0;\n while(desti > start) {\n if(desti % 3 != 0) {\n desti /= 2;\n } else {\n desti /= 3;\n }\n cnt++;\n }\n cnt.writeln;\n }\n}"}, {"source_code": "void main() {\n import std.stdio;\n import std.algorithm;\n import std.string;\n import std.conv;\n\n auto x = readln().split;\n const long start = x[0].to!long;\n long desti = x[1].to!long;\n\n if(desti == start) {\n \"0\".writeln;\n } else if(desti % start != 0) {\n \"-1\".writeln;\n } else if(desti % 2 != 0 && desti % 3 != 0) {\n \"-1\".writeln;\n } else {\n int cnt = 0;\n desti /= start;\n while(desti > 1) {\n if(desti % 3 != 0) {\n desti /= 2;\n } else if(desti % 2 != 0) {\n desti /= 3;\n } else {\n cnt = -1;\n break;\n }\n cnt++;\n }\n cnt.writeln;\n }\n}"}, {"source_code": "void main() {\n import std.stdio;\n import std.algorithm;\n import std.string;\n import std.conv;\n\n auto x = readln().split;\n const int start = x[0].to!int;\n int desti = x[1].to!int;\n\n if(desti % start != 0) {\n \"-1\".writeln;\n } else if(desti % 2 != 0 && desti % 3 != 0) {\n \"-1\".writeln;\n } else {\n int cnt = 0;\n while(desti > start) {\n if(desti % 3 != 0) {\n desti /= 2;\n } else {\n desti /= 3;\n }\n cnt++;\n }\n cnt.writeln;\n }\n}"}], "src_uid": "3f9980ad292185f63a80bce10705e806"} {"nl": {"description": "Let's assume that we have a pair of numbers (a,\u2009b). We can get a new pair (a\u2009+\u2009b,\u2009b) or (a,\u2009a\u2009+\u2009b) from the given pair in a single step.Let the initial pair of numbers be (1,1). Your task is to find number k, that is, the least number of steps needed to transform (1,1) into the pair where at least one number equals n.", "input_spec": "The input contains the only integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009106).", "output_spec": "Print the only integer k.", "sample_inputs": ["5", "1"], "sample_outputs": ["3", "0"], "notes": "NoteThe pair (1,1) can be transformed into a pair containing 5 in three moves: (1,1) \u2009\u2192\u2009 (1,2) \u2009\u2192\u2009 (3,2) \u2009\u2192\u2009 (5,2)."}, "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n\n int ans = n-1;\n foreach (i; 2 .. n/2 + 1) {\n int a = i, b = n - i;\n if (gcd(a, b) != 1) { continue; }\n \n int steps = 1;\n while (a != 1 && b != 1) {\n if (a < b) { swap(a, b); }\n \n steps += a / b;\n a %= b;\n }\n if (a > 1 || b > 1) { steps += a-1 + b-1; }\n \n ans = min(ans, steps);\n }\n \n ans.writeln;\n}"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.conv;\nimport std.container;\nimport std.functional;\nimport std.algorithm;\nimport std.array;\nimport std.typecons;\nimport std.range;\nimport std.numeric;\n\nvoid main(string[] args)\n{\n inputFile = stdin;\n int stepsTo(int a, int b)\n {\n if (gcd(a, b) != 1) return int.max;\n if (a > b) swap(a, b);\n if (a == 1) return b - 1;\n return (b/a) + stepsTo(b % a, a);\n }\n auto n = next!int;\n if (n == 1) return writeln(\"0\");\n (1 + iota(0, n).map!(i => stepsTo(i, n - i)).fold!min).writeln;\n}\nulong bitCnt(long x)\n{\n ulong cnt = 0;\n while(x) {cnt += x & 1; x>>=1;}\n return cnt;\n}\nalias Arr(T) = Mat!(T, 1);\nstruct Mat(T, size_t dimension)\n{\n T[] _baseArray;\n T[] _slice;\n size_t[dimension] _sizes; size_t dim(size_t i) {return _sizes[i];}\n size_t[dimension] _indexer;\n this(T[] baseArray, size_t[dimension] sizes)\n {\n _baseArray = baseArray;\n _sizes = sizes;\n _indexer[dimension - 1] = 1;\n static foreach_reverse(i; 0 .. dimension - 1)\n _indexer[i] = _indexer[i + 1] * _sizes[i + 1];\n auto requiredSize = _indexer[0] * _sizes[0];\n debug assert(_baseArray.length >= requiredSize);\n _slice = _baseArray[0 .. requiredSize];\n }\n this(size_t[dimension] sizes)\n {\n size_t reqSize = 1;\n static foreach(i; 0 .. dimension)\n reqSize *= sizes[i];\n this(new T[](reqSize), sizes);\n }\n ref auto opIndex()\n {\n pragma(inline, true);\n return _slice[];\n }\n ref auto opIndex(I...)(I i)\n {\n pragma(inline, true);\n debug assert(i.length <= dimension);\n size_t index = mixin(iota(0, i.length).map!(j => text(\"i[\", j, \"]*_indexer[\", j, \"]\")).join(\"+\"));\n static if (i.length == dimension)\n {\n\treturn _slice[index];\n }\n else\n {\n\tenum sliceDimension = dimension - i.length;\n\tsize_t[sliceDimension] remSizes = _sizes[i.length .. $];\n\tauto basePortion = _slice[index .. index + _indexer[i.length - 1]];\n \treturn Mat!(T, sliceDimension)(basePortion, remSizes);\n }\n }\n static if (dimension == 2)\n {\n auto identity()\n {\n\tdebug assert(dim(0) == dim(1));\n\tauto n = dim(0);\n\tauto id = Mat!(T, 2)([n, n]);\n\tforeach(k; 0 .. n)\n\t id[k, k] = T(1);\n\treturn id;\n }\n bool canMultiply(Mat!(T, 2) b)\n {\n\treturn this.dim(1) == b.dim(0);\n }\n auto opBinary(string op)(Mat!(T, 2) b)\n\tif (op == \"*\")\n\t {\n\t debug assert(canMultiply(b));\n\t auto res = Mat!(T, 2)([this.dim(0), b.dim(1)]);\n\t foreach(i; 0 .. res.dim(0))\n\t foreach(k; 0 .. this.dim(1))\n\t\tforeach(j; 0 .. res.dim(1))\n\t\t res[i, j] = res[i, j] + this[i, k] * b[k, j];\n\t return res;\n\t }\n auto opBinary(string op)(ulong exp)\n\tif (op == \"^^\")\n\t {\n\t return this.pow(identity, exp);\n\t }\n mixin interiorBinPow;\n }\n}\n\nstruct Mod(T, ulong mod)\n{\n alias This = Mod!(T, mod);\n T _rep; T rep() {return _rep;}\n this(W)(W w)\n {\n _rep = ((cast(T) w)%mod + mod) % mod;\n }\n static auto plainConstruct(T t)\n {\n pragma(inline, true);\n debug assert(t >= 0 && t < mod);\n auto res = Mod!(T, mod).init;\n res._rep = t;\n return res;\n }\n string toString()\n {\n return to!string(rep);\n }\n debug invariant\n {\n assert(_rep >= 0 && _rep < mod);\n }\n auto opBinary(string op)(This b)\n {\n static if (op == \"+\")\n {\n\tT resrep = _rep + b._rep;\n\tif (resrep >= mod) resrep -= mod;\n\treturn This.plainConstruct(resrep);\n }\n else static if (op == \"-\")\n {\n\tT resrep = _rep - b._rep;\n\tif (resrep < 0) resrep += mod;\n\treturn This.plainConstruct(resrep);\n }\n else static if (op == \"*\")\n {\n\treturn This(_rep * b._rep);\n }\n }\n}\n\nmixin template interiorBinPow()\n{\n alias ThisType = typeof(this);\n auto pow(ThisType res, ulong exp)\n {\n if (exp < 0) debug assert(0);\n auto pow = this;\n while(exp)\n\t{\n\t if (exp & 1)\n\t res = res * pow;\n\t pow = pow * pow;\n\t exp >>= 1;\n\t}\n return res;\n }\n}\n\n// INPUT\nFile inputFile;\nDList!string _words;\nvoid _wordsFill()\n{\n while (_words.empty) _words.insertBack(inputFile.readln.split); \n}\nstring popWord()\n{\n _wordsFill;\n auto word = _words.front;\n _words.removeFront;\n return word;\n}\nstring peekWord()\n{\n _wordsFill;\n return _words.front;\n}\nT next(T)()\n{\n return to!T(popWord);\n}\nT peek(T)()\n{\n return to!T(peekWord);\n}\nauto next(T, S...)(S s)\n{\n static if (S.length == 0)\n {\n return to!T(popWord);\n }\n else\n {\n auto res = new typeof(next!T(s[1 .. $]))[](cast(size_t)s[0]);\n foreach(ref elem; res)\n elem = next!T(s[1 .. $]);\n return res;\n }\n}\n"}], "negative_code": [], "src_uid": "75739f77378b21c331b46b1427226fa1"} {"nl": {"description": "A prime number is a number which has exactly two distinct divisors: one and itself. For example, numbers 2, 7, 3 are prime, and 1, 6, 4 are not.The next prime number after x is the smallest prime number greater than x. For example, the next prime number after 2 is 3, and the next prime number after 3 is 5. Note that there is exactly one next prime number after each number. So 5 is\u00a0not the next prime number for 2.One cold April morning Panoramix predicted that soon Kakofonix will break free from his straitjacket, and this will be a black day for the residents of the Gallic countryside.Panoramix's prophecy tells that if some day Asterix and Obelix beat exactly x Roman soldiers, where x is a prime number, and next day they beat exactly y Roman soldiers, where y is the next prime number after x, then it's time to wait for Armageddon, for nothing can shut Kakofonix up while he sings his infernal song.Yesterday the Gauls beat n Roman soldiers and it turned out that the number n was prime! Today their victims were a troop of m Romans (m\u2009>\u2009n). Determine whether the Gauls should wait for the black day after today's victory of Asterix and Obelix?", "input_spec": "The first and only input line contains two positive integers \u2014 n and m (2\u2009\u2264\u2009n\u2009<\u2009m\u2009\u2264\u200950). It is guaranteed that n is prime. Pretests contain all the cases with restrictions 2\u2009\u2264\u2009n\u2009<\u2009m\u2009\u2264\u20094.", "output_spec": "Print YES, if m is the next prime number after n, or NO otherwise.", "sample_inputs": ["3 5", "7 11", "7 9"], "sample_outputs": ["YES", "YES", "NO"], "notes": null}, "positive_code": [{"source_code": "import std.stdio, std.string, std.algorithm;\nimport std.conv, std.array;\nimport std.container;\nimport std.typecons;\n\nbool isPrime(int x) {\n for (int i = 2; i * i <= x; i++) {\n if (x % i == 0) {\n return false;\n }\n }\n return true;\n}\n\nvoid main() {\n int n, m; readf(\"%d %d\\n\", &n, &m);\n for (int i = n + 1; i < m; i++) {\n if (isPrime(i)) {\n \"NO\".writeln;\n return;\n }\n }\n if (!isPrime(m)) {\n \"NO\".writeln;\n return;\n }\n \"YES\".writeln;\n}\n"}], "negative_code": [], "src_uid": "9d52ff51d747bb59aa463b6358258865"} {"nl": {"description": "Polycarpus has recently got interested in sequences of pseudorandom numbers. He learned that many programming languages generate such sequences in a similar way: (for i\u2009\u2265\u20091). Here a, b, m are constants, fixed for the given realization of the pseudorandom numbers generator, r0 is the so-called randseed (this value can be set from the program using functions like RandSeed(r) or srand(n)), and denotes the operation of taking the remainder of division.For example, if a\u2009=\u20092,\u2009b\u2009=\u20096,\u2009m\u2009=\u200912,\u2009r0\u2009=\u200911, the generated sequence will be: 4,\u20092,\u200910,\u20092,\u200910,\u20092,\u200910,\u20092,\u200910,\u20092,\u200910,\u2009....Polycarpus realized that any such sequence will sooner or later form a cycle, but the cycle may occur not in the beginning, so there exist a preperiod and a period. The example above shows a preperiod equal to 1 and a period equal to 2.Your task is to find the period of a sequence defined by the given values of a,\u2009b,\u2009m and r0. Formally, you have to find such minimum positive integer t, for which exists such positive integer k, that for any i\u2009\u2265\u2009k: ri\u2009=\u2009ri\u2009+\u2009t.", "input_spec": "The single line of the input contains four integers a, b, m and r0 (1\u2009\u2264\u2009m\u2009\u2264\u2009105,\u20090\u2009\u2264\u2009a,\u2009b\u2009\u2264\u20091000,\u20090\u2009\u2264\u2009r0\u2009<\u2009m), separated by single spaces.", "output_spec": "Print a single integer \u2014 the period of the sequence.", "sample_inputs": ["2 6 12 11", "2 3 5 1", "3 6 81 9"], "sample_outputs": ["2", "4", "1"], "notes": "NoteThe first sample is described above. In the second sample the sequence is (starting from the first element): 0,\u20093,\u20094,\u20091,\u20090,\u20093,\u20094,\u20091,\u20090,\u2009...In the third sample the sequence is (starting from the first element): 33,\u200924,\u200978,\u200978,\u200978,\u200978,\u2009..."}, "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int a, b, m, r0;\n readf(\"%s %s %s %s\", &a, &b, &m, &r0);\n readln;\n\n auto v = new int[] (m);\n v[] = -1;\n v[r0] = 0;\n \n int r = r0;\n int ans;\n while (true) {\n int newr = (a * r + b) % m;\n if (v[newr] != -1) { \n ans = v[r] + 1 - v[newr];\n break;\n }\n v[newr] = v[r] + 1;\n r = newr;\n }\n \n ans.writeln;\n}"}], "negative_code": [], "src_uid": "9137197ee1b781cd5cc77c46f50b9012"} {"nl": {"description": "HQ9+ is a joke programming language which has only four one-character instructions: \"H\" prints \"Hello, World!\", \"Q\" prints the source code of the program itself, \"9\" prints the lyrics of \"99 Bottles of Beer\" song, \"+\" increments the value stored in the internal accumulator.Instructions \"H\" and \"Q\" are case-sensitive and must be uppercase. The characters of the program which are not instructions are ignored.You are given a program written in HQ9+. You have to figure out whether executing this program will produce any output.", "input_spec": "The input will consist of a single line p which will give a program in HQ9+. String p will contain between 1 and 100 characters, inclusive. ASCII-code of each character of p will be between 33 (exclamation mark) and 126 (tilde), inclusive.", "output_spec": "Output \"YES\", if executing the program will produce any output, and \"NO\" otherwise.", "sample_inputs": ["Hi!", "Codeforces"], "sample_outputs": ["YES", "NO"], "notes": "NoteIn the first case the program contains only one instruction \u2014 \"H\", which prints \"Hello, World!\".In the second case none of the program characters are language instructions."}, "positive_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\nimport std.algorithm;\nimport std.array;\n\n\nvoid main(){\n auto source = readln.chomp;\n auto hq = \"HQ9\";\n auto res = \"NO\";\n foreach(s; hq){\n if(source.find(s).length){\n res = \"YES\";\n break;\n }\n }\n res.writeln;\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\n\nvoid main()\n{\n (readln.any!(a => canFind(['H','Q','9'],a))\n ? \"YES\" : \"NO\")\n .writeln;\n}"}, {"source_code": "import std.stdio;\nimport std.string;\n\nint main(string[] argv)\n{\n\tstring line = stdin.readln();\n\tif (line[line.length - 1] == '\\n')\n\t\tline.length--;\n\n\tif (indexOf(line, \"H\") != -1\n\t || indexOf(line, \"Q\") != -1\n\t || indexOf(line, \"9\") != -1)\n\t{\n\t\twrite(\"YES\");\n\t} else {\n\t\twrite(\"NO\");\n\t}\n\treturn 0;\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.string;\nimport std.regex;\n\nvoid main() {\n if (!match(readln, regex(`[HQ9]`)).empty) {\n \"YES\".writeln;\n } else {\n \"NO\".writeln;\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\nimport std.algorithm;\nimport std.array;\n\n\nvoid main(){\n auto source = readln.chomp;\n auto hq = \"HQ9+\";\n auto res = \"NO\";\n foreach(s; hq){\n if(source.find(s).length){\n res = \"YES\";\n break;\n }\n }\n res.writeln;\n}"}], "src_uid": "1baf894c1c7d5aeea01129c7900d3c12"} {"nl": {"description": "Polycarp loves ciphers. He has invented his own cipher called repeating.Repeating cipher is used for strings. To encrypt the string $$$s=s_{1}s_{2} \\dots s_{m}$$$ ($$$1 \\le m \\le 10$$$), Polycarp uses the following algorithm: he writes down $$$s_1$$$ ones, he writes down $$$s_2$$$ twice, he writes down $$$s_3$$$ three times, ... he writes down $$$s_m$$$ $$$m$$$ times. For example, if $$$s$$$=\"bab\" the process is: \"b\" $$$\\to$$$ \"baa\" $$$\\to$$$ \"baabbb\". So the encrypted $$$s$$$=\"bab\" is \"baabbb\".Given string $$$t$$$ \u2014 the result of encryption of some string $$$s$$$. Your task is to decrypt it, i.\u2009e. find the string $$$s$$$.", "input_spec": "The first line contains integer $$$n$$$ ($$$1 \\le n \\le 55$$$) \u2014 the length of the encrypted string. The second line of the input contains $$$t$$$ \u2014 the result of encryption of some string $$$s$$$. It contains only lowercase Latin letters. The length of $$$t$$$ is exactly $$$n$$$. It is guaranteed that the answer to the test exists.", "output_spec": "Print such string $$$s$$$ that after encryption it equals $$$t$$$.", "sample_inputs": ["6\nbaabbb", "10\nooopppssss", "1\nz"], "sample_outputs": ["bab", "oops", "z"], "notes": null}, "positive_code": [{"source_code": "import std.stdio;\nint f(int a)\n{\n\tfor (int i=0; i<=a; i++)\n\t{\n\t\tif (i*(i+1)/2==a)\n\t\t{\n\t\t\treturn i;\n\t\t}\n\t}\n\treturn 0;\n}\nint main()\n{\n\tint a=0;\n\tstring s;\n\treadf(\" %d\", &a);\n\treadf(\" %s\", &s);\n\tchar[] m = s.dup;\n\tfor (int i=0; i to!int(a)).array();\n\tauto s\u0131rayaDizilmi\u015fSay\u0131lar = sayilar.sort();\n\t\n\tint sonu\u00e7 = 0; \n\tint bir\u00d6ncekiEleman = s\u0131rayaDizilmi\u015fSay\u0131lar[0];\n\tint ge\u00e7iciSonu\u00e7 = 0;\n\t//1 , 2, 4 ,3 ,3 ,2 ,1\n\tfor ( int i = 0 ; i < s\u0131rayaDizilmi\u015fSay\u0131lar.length; i++ )\n\t{\n\t\tint \u015fuandakiEleman = s\u0131rayaDizilmi\u015fSay\u0131lar[i];\n\t\tif ( \u015fuandakiEleman == bir\u00d6ncekiEleman)\n\t\t{\n\t\t\tge\u00e7iciSonu\u00e7++;\n\t\t\tif ( ge\u00e7iciSonu\u00e7 > sonu\u00e7 )\n\t\t\t\tsonu\u00e7 = ge\u00e7iciSonu\u00e7;\n\t\t}\n\t\telse \n\t\t{\n\n\t\t\tge\u00e7iciSonu\u00e7 = 1;\t\n\t\t\tbir\u00d6ncekiEleman = \u015fuandakiEleman;\n\t\t}\n\t}\n\twriteln(sonu\u00e7);\n\t\n}"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n readln;\n \n auto arr = readln.chomp.split.map!(to!int).array;\n \n int [int] cnt;\n arr.each!(x => ++cnt[x]);\n \n auto ans = cnt.values.maxElement;\n ans.writeln;\n}"}, {"source_code": "import std.stdio;\nint main()\n{\n\tint a=0;\n\treadf(\" %d\", &a);\n\tint[] m = new int[a];\n\tfor (int i=0; imax)\n\t\t{\n\t\t\tmax=n[i];\n\t\t}\n\t}\n\twriteln(max);\n\treturn 0;\n}"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.math;\nimport std.algorithm;\nimport std.array;\nimport std.string;\nimport std.conv;\n\nvoid main() {\n\t\n\tauto elemanSayisi = stdin.readln.strip.to!int();\n\tauto sayilar = stdin.readln.strip.split().map!(a => to!int(a)).array();\n\tauto s\u0131rayaDizilmi\u015fSay\u0131lar = sayilar.sort();\n\t\n\tint sonu\u00e7 = 0; \n\tint bir\u00d6ncekiEleman = s\u0131rayaDizilmi\u015fSay\u0131lar[0];\n\tint ge\u00e7iciSonu\u00e7 = 0;\n\t//1 , 2, 4 ,3 ,3 ,2 ,1\n\tfor ( int i = 0 ; i < s\u0131rayaDizilmi\u015fSay\u0131lar.length; i++ )\n\t{\n\t\tint \u015fuandakiEleman = s\u0131rayaDizilmi\u015fSay\u0131lar[i];\n\t\tif ( \u015fuandakiEleman == bir\u00d6ncekiEleman)\n\t\t{\n\t\t\tge\u00e7iciSonu\u00e7++;\n\t\t}\n\t\telse \n\t\t{\n\t\t\tif ( ge\u00e7iciSonu\u00e7 > sonu\u00e7 )\n\t\t\t\tsonu\u00e7 = ge\u00e7iciSonu\u00e7;\n\t\t\tge\u00e7iciSonu\u00e7 = 0;\t\n\t\t\tbir\u00d6ncekiEleman = \u015fuandakiEleman;\n\t\t}\n\t}\n\twriteln(sonu\u00e7);\n\t\n}"}, {"source_code": "import std.stdio;\nimport std.math;\nimport std.algorithm;\nimport std.array;\nimport std.string;\nimport std.conv;\n\nvoid main() {\n\t\n\tauto elemanSayisi = stdin.readln.strip.to!int();\n\tauto sayilar = stdin.readln.strip.split().map!(a => to!int(a)).array();\n\tauto s\u0131rayaDizilmi\u015fSay\u0131lar = sayilar.sort();\n\t\n\tint sonu\u00e7 = 0; \n\tint bir\u00d6ncekiEleman = s\u0131rayaDizilmi\u015fSay\u0131lar[0];\n\tint ge\u00e7iciSonu\u00e7 = 0;\n\t//1 , 2, 4 ,3 ,3 ,2 ,1\n\tfor ( int i = 0 ; i < s\u0131rayaDizilmi\u015fSay\u0131lar.length; i++ )\n\t{\n\t\tint \u015fuandakiEleman = s\u0131rayaDizilmi\u015fSay\u0131lar[i];\n\t\tif ( \u015fuandakiEleman == bir\u00d6ncekiEleman)\n\t\t{\n\t\t\tge\u00e7iciSonu\u00e7++;\n\t\t}\n\t\telse \n\t\t{\n\t\t\tif ( ge\u00e7iciSonu\u00e7 > sonu\u00e7 )\n\t\t\t\tsonu\u00e7 = ge\u00e7iciSonu\u00e7;\n\t\t\tge\u00e7iciSonu\u00e7 = 1;\t\n\t\t\tbir\u00d6ncekiEleman = \u015fuandakiEleman;\n\t\t}\n\t}\n\twriteln(sonu\u00e7);\n\t\n}"}], "src_uid": "f30329023e84b4c50b1b118dc98ae73c"} {"nl": {"description": "Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.Note, that during capitalization all the letters except the first one remains unchanged.", "input_spec": "A single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103.", "output_spec": "Output the given word after capitalization.", "sample_inputs": ["ApPLe", "konjac"], "sample_outputs": ["ApPLe", "Konjac"], "notes": null}, "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.range;\nimport std.ascii;\n\nvoid main()\n{\n string word = readln;\n (cast(char)word[0].toUpper~word[1..$]).writeln;\n}"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.typecons : Yes;\nimport std.algorithm.mutation : copy;\nimport std.conv : to;\n\nvoid main() {\n foreach(string s; stdin.byLineCopy(Yes.keepTerminator)) {\n (s[0].toUpper.to!string ~ s[1 .. $]).copy(stdout.lockingTextWriter);\n }\n}"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.string;\nimport core.stdc.stdio;\nimport std.array;\nimport std.algorithm;\n\nint main(string[] argv)\n{\n\tstring line = readln();\n\tif (line[line.length - 1] == '\\n') line.length--;\n\twrite(capitalize(\"\" ~ line[0]) ~ line[1..line.length]);\n\treturn 0;\n}\n"}, {"source_code": "//ahmat\nimport core.stdc.stdio:scanf,printf,puts;\nimport core.bitop;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.functional;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.container;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\npragma(inline,true);\n\nvoid main(){\n dchar[] s=readln.strip.to!(dchar[]);\n writeln(toUpper(s[0]),s[1..$]);\n}\n\n"}, {"source_code": "//ahmat\nimport core.stdc.stdio:scanf,printf,puts;\nimport core.bitop;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.functional;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.container;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\npragma(inline,true);\n\nvoid main(){\n dchar[] s=readln.strip.to!(dchar[]);\n writeln(toUpper(s[0])~s[1..$]);\n}\n\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.string;\nimport std.regex;\n\nvoid main() {\n string s = readln;\n\n if (!match(s[0].to!string, regex(`[a-z]`)).empty) {\n (s[0].to!string.toUpper ~ s[1..$]).write;\n } else {\n s.write;\n }\n}\n"}, {"source_code": "module sigod.codeforces.p281A;\n\nimport std.stdio;\nimport std.string;\nimport std.conv;\n\nvoid main()\n{\n\n\tstdout.write(solve(stdin.readln().strip()));\n}\n\nstring solve(string str)\n{\n\treturn toUpper(str[0].to!string) ~ str[1 .. $];\n}\n\nunittest {\n\tassert(solve(\"ApPLe\") == \"ApPLe\");\n\tassert(solve(\"konjac\") == \"Konjac\");\n}"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.typecons : Yes;\nimport std.algorithm.mutation : copy;\n\nvoid main() {\n foreach(string s; stdin.byLineCopy(Yes.keepTerminator)) {\n s.capitalize.copy(stdout.lockingTextWriter());\n }\n}"}], "src_uid": "29e0fc0c5c0e136ac8e58011c91397e4"} {"nl": {"description": "Tonight is brain dinner night and all zombies will gather together to scarf down some delicious brains. The artful Heidi plans to crash the party, incognito, disguised as one of them. Her objective is to get away with at least one brain, so she can analyze the zombies' mindset back home and gain a strategic advantage.They will be N guests tonight: N\u2009-\u20091 real zombies and a fake one, our Heidi. The living-dead love hierarchies as much as they love brains: each one has a unique rank in the range 1 to N\u2009-\u20091, and Heidi, who still appears slightly different from the others, is attributed the highest rank, N. Tonight there will be a chest with brains on display and every attendee sees how many there are. These will then be split among the attendees according to the following procedure:The zombie of the highest rank makes a suggestion on who gets how many brains (every brain is an indivisible entity). A vote follows. If at least half of the attendees accept the offer, the brains are shared in the suggested way and the feast begins. But if majority is not reached, then the highest-ranked zombie is killed, and the next zombie in hierarchy has to make a suggestion. If he is killed too, then the third highest-ranked makes one, etc. (It's enough to have exactly half of the votes \u2013 in case of a tie, the vote of the highest-ranked alive zombie counts twice, and he will of course vote in favor of his own suggestion in order to stay alive.)You should know that zombies are very greedy and sly, and they know this too \u2013 basically all zombie brains are alike. Consequently, a zombie will never accept an offer which is suboptimal for him. That is, if an offer is not strictly better than a potential later offer, he will vote against it. And make no mistake: while zombies may normally seem rather dull, tonight their intellects are perfect. Each zombie's priorities for tonight are, in descending order: survive the event (they experienced death already once and know it is no fun), get as many brains as possible. Heidi goes first and must make an offer which at least half of the attendees will accept, and which allocates at least one brain for Heidi herself.What is the smallest number of brains that have to be in the chest for this to be possible?", "input_spec": "The only line of input contains one integer: N, the number of attendees (1\u2009\u2264\u2009N\u2009\u2264\u2009109).", "output_spec": "Output one integer: the smallest number of brains in the chest which allows Heidi to take one brain home.", "sample_inputs": ["1", "4"], "sample_outputs": ["1", "2"], "notes": "Note"}, "positive_code": [{"source_code": "import std.stdio, std.conv, std.string;\n\nvoid main() {\n\n\tuint n = readln.strip.to!int;\n\n\twriteln(n & 1 ? n / 2 + 1 : n / 2);\n}"}], "negative_code": [], "src_uid": "30e95770f12c631ce498a2b20c2931c7"} {"nl": {"description": "Karl likes Codeforces and subsequences. He wants to find a string of lowercase English letters that contains at least $$$k$$$ subsequences codeforces. Out of all possible strings, Karl wants to find a shortest one.Formally, a codeforces subsequence of a string $$$s$$$ is a subset of ten characters of $$$s$$$ that read codeforces from left to right. For example, codeforces contains codeforces a single time, while codeforcesisawesome contains codeforces four times: codeforcesisawesome, codeforcesisawesome, codeforcesisawesome, codeforcesisawesome.Help Karl find any shortest string that contains at least $$$k$$$ codeforces subsequences.", "input_spec": "The only line contains a single integer $$$k$$$ ($$$1 \\leq k \\leq 10^{16})$$$.", "output_spec": "Print a shortest string of lowercase English letters that contains at least $$$k$$$ codeforces subsequences. If there are several such strings, print any of them.", "sample_inputs": ["1", "3"], "sample_outputs": ["codeforces", "codeforcesss"], "notes": null}, "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.numeric;\nimport std.stdio;\nimport std.typecons;\n\nimmutable string answer = \"codeforces\";\nimmutable int len = 10;\n\nvoid main ()\n{\n\tlong k;\n\twhile (readf !(\" %s\") (k) > 0)\n\t{\n\t\tlong [len] s;\n\t\ts[] = 1;\n\t\tlong total = 1;\n\t\tfor (int i = 0; total < k; i = (i + 1) % len)\n\t\t{\n\t\t\ttotal /= s[i];\n\t\t\ts[i] += 1;\n\t\t\ttotal *= s[i];\n\t\t}\n\t\tforeach (i; 0..len)\n\t\t{\n\t\t\tforeach (j; 0..s[i])\n\t\t\t{\n\t\t\t\twrite (answer[i]);\n\t\t\t}\n\t\t}\n\t\twriteln;\n\t}\n}\n"}, {"source_code": "// Code By H~$~C\n\nimport std.stdio, std.format;\nimport std.math, std.uni, std.bigint, std.numeric;\nimport std.array, std.string, std.container, std.range, std.typecons;\nimport std.algorithm, std.conv, std.functional, std.random;\n\nvoid _Main() {\n long k;\n readf!\" %s\"(k);\n if (k <= 1024) {\n int p = 1, c = 0;\n while (p < k) {\n p *= 2, c += 1;\n }\n foreach(i; \"codeforces\") {\n write(i);\n if (c) {\n write(i);\n c--;\n }\n }\n }\n else {\n long p = 2;\n while (true) {\n if (pow(p, 10) < k) {\n ++p;\n }\n else break;\n }\n --p;\n long r = pow(p, 10);\n int c = 0;\n while (r < k) {\n c += 1;\n r = r / p * (p + 1);\n }\n foreach(i; \"codeforces\") {\n foreach(j; 0 .. p) write(i);\n if (c) {\n write(i);\n c--;\n }\n }\n }\n}\n\nvoid main(string[] args) {\n int tests = 1;\n// readf!\" %d\"(tests);\n foreach (test; 0 .. tests) _Main();\n}\n\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n// floor(a^(1/k))\nulong floorKthRoot(ulong a, ulong k) {\n import core.bitop : bsr;\n import std.algorithm : min;\n if (a == 0) {\n return 0;\n } else if (k <= 1) {\n return a;\n } else if (k == 2) {\n ulong b = a, x = 0, y = 0;\n for (int e = bsr(a) & ~1; e >= 0; e -= 2) {\n x <<= 1;\n y <<= 1;\n if (b >= (y | 1) << e) {\n b -= (y | 1) << e;\n x |= 1;\n y += 2;\n }\n }\n return x;\n } else if (k <= 40) {\n // min x s.t. x^k >= 2^64\n enum ulong[] HIS =\n [0, 0, 4294967296UL, 2642246, 65536, 7132, 1626, 566, 256, 139, 85, 57,\n 41, 31, 24, 20, 16, 14, 12, 11, 10, 9, 8, 7, 7, 6, 6, 6, 5, 5, 5, 5,\n 4, 4, 4, 4, 4, 4, 4, 4, 4];\n ulong lo = 1UL << (bsr(a) / k);\n ulong hi = min(1UL << (bsr(a) / k + 1), HIS[cast(size_t)(k)]);\n for (; lo + 1 < hi; ) {\n const ulong mid = (lo + hi) / 2;\n ulong b = mid * mid;\n foreach (i; 2 .. k) b *= mid;\n ((b <= a) ? lo : hi) = mid;\n }\n return lo;\n } else if (k <= 63) {\n return ((1UL << k) <= a) ? 2 : 1;\n } else {\n return 1;\n }\n}\n\n\nenum S = \"codeforces\";\nenum L = cast(int)(S.length);\n\nvoid main() {\n try {\n for (; ; ) {\n const K = readLong();\n \n const long a = floorKthRoot(K, L);\n foreach (m; 0 .. L + 1) {\n long prod = 1;\n foreach (i; 0 .. L) {\n prod *= ((i < m) ? (a + 1) : a);\n }\n if (prod >= K) {\n foreach (i; 0 .. L) {\n foreach (_; 0 .. ((i < m) ? (a + 1) : a)) {\n write(S[i]);\n }\n }\n writeln();\n break;\n }\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "8001a7570766cadcc538217e941b3031"} {"nl": {"description": "Iahub got bored, so he invented a game to be played on paper. He writes n integers a1,\u2009a2,\u2009...,\u2009an. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices i and j (1\u2009\u2264\u2009i\u2009\u2264\u2009j\u2009\u2264\u2009n) and flips all values ak for which their positions are in range [i,\u2009j] (that is i\u2009\u2264\u2009k\u2009\u2264\u2009j). Flip the value of x means to apply operation x\u2009=\u20091 - x.The goal of the game is that after exactly one move to obtain the maximum number of ones. Write a program to solve the little game of Iahub.", "input_spec": "The first line of the input contains an integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100). In the second line of the input there are n integers: a1,\u2009a2,\u2009...,\u2009an. It is guaranteed that each of those n values is either 0 or 1.", "output_spec": "Print an integer \u2014 the maximal number of 1s that can be obtained after exactly one move. ", "sample_inputs": ["5\n1 0 0 1 0", "4\n1 0 0 1"], "sample_outputs": ["4", "4"], "notes": "NoteIn the first case, flip the segment from 2 to 5 (i\u2009=\u20092,\u2009j\u2009=\u20095). That flip changes the sequence, it becomes: [1 1 1 0 1]. So, it contains four ones. There is no way to make the whole sequence equal to [1 1 1 1 1].In the second case, flipping only the second and the third element (i\u2009=\u20092,\u2009j\u2009=\u20093) will turn all numbers into 1."}, "positive_code": [{"source_code": "\ufeffimport std.stdio;\n\nbool[] a;\nbyte n, max, ans;\n\nvoid maxone(int x, int y) {\n\tmax = 0;\n\tbool[] b = a[].dup;\n\tforeach (i; x .. y)\n\t\tb[i] ^= 1;\n\tforeach (i; 0 .. n)\n\t\tif (b[i])\n\t\t\tmax += 1;\n}\n\nvoid main() {\n\treadf(\" %s\", &n);\n\n\tbool c;\n\tforeach (i; 0 .. n) {\n\t\treadf(\" %b\", &c);\n\t\ta ~= c;\n\t}\n\n\tforeach (i; 0 .. n)\n\t\tforeach (j; i .. n) {\n\t\t\tmaxone(i, j + 1);\n\t\t\tif (max > ans)\n\t\t\t\tans = max;\n\t\t}\n\n\twriteln(ans);\n}"}, {"source_code": "import std.stdio;\nimport core.stdc.stdio;\n\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\tint initial_sum = 0;\n\tint[] bits; bits.length = n;\n\tforeach (int i; 0..n)\n\t{\n\t\tint b;\n\t\tscanf(\"%d\", &b);\n\t\tinitial_sum += (b == 0 ? 0 : 1);\n\t\tbits[i] = b;\n\t}\n\tint[] dp; dp.length = n;\n\tforeach (int i; 0..n)\n\t{\n\t\tdp[i] = initial_sum;\n\t}\n\tint max = int.min;\n\tforeach (int i; 0..n)\n\t{\n\t\tforeach (int j; 0..(i+1))\n\t\t{\n\t\t\tdp[j] = dp[j] - bits[i] + (1 - bits[i]);\n\t\t\tif (dp[j] > max)\n\t\t\t\tmax = dp[j];\n\t\t}\n\t}\n\tprintf(\"%d\", max);\n\treturn 0;\n}"}, {"source_code": "import std.stdio;\nimport core.stdc.stdio;\nimport std.algorithm;\nimport std.math;\nimport std.array;\n\nint main(string[] argv)\n{\n\tint n;\n\tscanf(\"%d\", &n);\n\tint initial_sum = 0;\n\tint[] bits; bits.length = n;\n\tforeach (int i; 0..n)\n\t{\n\t\tint b;\n\t\tscanf(\"%d\", &b);\n\t\tinitial_sum += (b == 0 ? 0 : 1);\n\t\tbits[i] = b;\n\t}\n\tint[][] dp; dp.length = n;\n\tforeach (int i; 0..n)\n\t{\n\t\tdp[i].length = n;\n\t}\n\tint max = int.min;\n\tforeach (int i; 0..n)\n\t{\n\t\tforeach (int j; 0..(i+1))\n\t\t{\n\t\t\tint cm = (i > 0 && j < i ? dp[i-1][j] : initial_sum);\n\t\t\tdp[i][j] = cm - bits[i] + (1 - bits[i]);\n\t\t\tif (dp[i][j] > max)\n\t\t\t\tmax = dp[i][j];\n\t\t}\n\t}\n\tprintf(\"%d\", max);\n\treturn 0;\n}"}, {"source_code": "import std.algorithm;\nimport std.stdio;\nimport std.array;\nimport std.conv;\nimport std.string;\n\nvoid main() {\n int n = readln.chomp.to!int;\n int[] a = readln.split.map!(x => x.to!int).array;\n int maxima = 0;\n for(int i = 0; i < n; i++) {\n for(int j = 0; j <= i; j++) {\n int ones = 0;\n for(int idx = 0; idx < n; idx++) {\n if(idx >= j && idx <= i)\n ones += 1-a[idx];\n else\n ones += a[idx];\n }\n maxima = max(maxima,ones);\n }\n }\n maxima.writeln;\n}\n\n"}, {"source_code": "import std.stdio, std.string, std.algorithm;\nimport std.conv, std.array;\nimport std.container;\nimport std.typecons;\n\nvoid main() {\n int n; readf(\"%d\\n\", &n);\n int[] xs = readln.split.map!(to!int).array;\n int[][] cs = new int[][n + 1];\n for (int i = 0; i < n + 1; i++) {\n cs[i] = new int[n + 1];\n }\n for (int i = 0; i < n + 1; i++) { \n cs[i][i] = 0;\n for (int j = i; j < n; j++) {\n cs[i][j + 1] = cs[i][j] + xs[j];\n }\n }\n int ans = 0;\n for (int i = 0; i < n; i++) {\n for (int j = i + 1; j < n + 1; j++) {\n ans = max(\n ans,\n cs[0][i] + (j - i) - cs[i][j] + cs[j][n]\n );\n }\n }\n ans.writeln;\n}\n"}], "negative_code": [{"source_code": "\ufeffimport std.stdio;\n\nbool[] a;\nbyte ans, one;\n\nvoid main() {\n\tbyte n;\n\n\treadf(\" %s\", &n);\n\n\tbool c;\n\tforeach (i; 0 .. n) {\n\t\treadf(\" %b\", &c);\n\t\ta ~= c;\n\t\tif (c)\n\t\t\tone +=1;\n\t}\n\n\tforeach (i; 0 .. n - 1) {\n\t\tif (!a[i]) {\n\t\t\tans += 1;\n\t\t\tif (a[i + 1])\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tbyte temp = 0;\n\tforeach (i; 0 .. n - 1) {\n\t\tif (!a[i]) {\n\t\t\ttemp += 1;\n\t\t\tif (a[i + 1]) {\n\t\t\t\tif (temp > ans)\n\t\t\t\t\tans = temp;\n\t\t\t\ttemp = 0;\n\t\t\t}\n\t\t}\n\t}\n\n\twriteln(ans + one);\n}"}, {"source_code": "import std.algorithm;\nimport std.stdio;\nimport std.array;\nimport std.conv;\nimport std.string;\n\nvoid main() {\n int n = readln.chomp.to!int;\n int[] a = readln.split.map!(x => x.to!int).array;\n int maxima = -1;\n for(int i = 0; i < n; i++) {\n for(int j = 0; j < i; j++) {\n int ones = 0;\n for(int idx = 0; idx < n; idx++) {\n if(idx >= j && idx <= i)\n ones += 1-a[idx];\n else\n ones += a[idx];\n }\n maxima = max(maxima,ones);\n }\n }\n maxima.writeln;\n}\n\n"}, {"source_code": "import std.algorithm;\nimport std.stdio;\nimport std.array;\nimport std.conv;\nimport std.string;\n\nvoid main() {\n int n = readln.chomp.to!int;\n int[] a = readln.split.map!(x => x.to!int).array;\n int maxima = 0;\n for(int i = 0; i < n; i++) {\n for(int j = 0; j < i; j++) {\n int ones = 0;\n for(int idx = 0; idx < n; idx++) {\n if(idx >= j && idx <= i)\n ones += 1-a[idx];\n else\n ones += a[idx];\n }\n maxima = max(maxima,ones);\n }\n }\n if(n == 1)\n if(a[0] == 0)\n maxima = 1;\n maxima.writeln;\n}\n\n"}, {"source_code": "import std.stdio, std.string, std.algorithm;\nimport std.conv, std.array;\nimport std.container;\nimport std.typecons;\n\nvoid main() {\n int n; readf(\"%d\\n\", &n);\n int[] xs = readln.split.map!(to!int).array;\n int[][] cs = new int[][n + 1];\n for (int i = 0; i < n + 1; i++) {\n cs[i] = new int[n + 1];\n }\n for (int i = 0; i < n + 1; i++) { \n cs[i][i] = 0;\n for (int j = i; j < n; j++) {\n cs[i][j + 1] = cs[i][j] + xs[j];\n }\n }\n int ans = max(cs[0][n], n - cs[0][n]);\n for (int i = 0; i < n; i++) {\n for (int j = i; j < n + 1; j++) {\n ans = max(\n ans,\n cs[0][i] + (j - i) - cs[i][j] + cs[j][n]\n );\n }\n }\n ans.writeln;\n}\n"}, {"source_code": "\ufeffimport std.stdio;\n\nbool[] a;\nbyte ans, one;\n\nvoid main() {\n\tbyte n;\n\n\treadf(\" %s\", &n);\n\n\tbool c;\n\tforeach (i; 0 .. n) {\n\t\treadf(\" %b\", &c);\n\t\ta ~= c;\n\t\tif (c)\n\t\t\tone +=1;\n\t}\n\n\tforeach (i; 0 .. n - 1) {\n\t\tif (!a[i]) {\n\t\t\tans += 1;\n\t\t\tif (a[i + 1])\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tbyte temp = 0;\n\tforeach (i; 0 .. n - 1) {\n\t\tif (!a[i]) {\n\t\t\ttemp += 1;\n\t\t\tif (a[i + 1]) {\n\t\t\t\tif (temp > ans)\n\t\t\t\t\tans = temp;\n\t\t\t\ttemp = 0;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (n == 1 && a[0] == 1)\n\t\twriteln(0);\n\telse\n\t\twriteln(ans + one);\n}"}, {"source_code": "\ufeffimport std.stdio;\n\nbool[] a;\nbyte ans, one;\n\nvoid main() {\n\tbyte n;\n\n\treadf(\" %s\", &n);\n\n\tbool c;\n\tforeach (i; 0 .. n) {\n\t\treadf(\" %b\", &c);\n\t\ta ~= c;\n\t\tif (c)\n\t\t\tone +=1;\n\t}\n\n\tforeach (i; 0 .. n - 1) {\n\t\tif (!a[i]) {\n\t\t\tans += 1;\n\t\t\tif (a[i + 1])\n\t\t\t\tbreak;\n\t\t}\n\t}\n\n\tbyte temp = 0;\n\tforeach (i; 0 .. n - 1) {\n\t\tif (!a[i]) {\n\t\t\ttemp += 1;\n\t\t\tif (a[i + 1]) {\n\t\t\t\tif (temp > ans)\n\t\t\t\t\tans = temp;\n\t\t\t\ttemp = 0;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (n == 1 && a[0] == 1)\n\t\twriteln(0);\n\telse\n\t\tif (n == 1 && a[0] == 0)\n\t\t\twriteln(1);\n\t\telse\n\t\t\twriteln(ans + one);\n}"}], "src_uid": "9b543e07e805fe1dd8fa869d5d7c8b99"} {"nl": {"description": "Tomorrow Peter has a Biology exam. He does not like this subject much, but d days ago he learnt that he would have to take this exam. Peter's strict parents made him prepare for the exam immediately, for this purpose he has to study not less than minTimei and not more than maxTimei hours per each i-th day. Moreover, they warned Peter that a day before the exam they would check how he has followed their instructions.So, today is the day when Peter's parents ask him to show the timetable of his preparatory studies. But the boy has counted only the sum of hours sumTime spent him on preparation, and now he wants to know if he can show his parents a timetable s\u0441hedule with d numbers, where each number s\u0441hedulei stands for the time in hours spent by Peter each i-th day on biology studies, and satisfying the limitations imposed by his parents, and at the same time the sum total of all schedulei should equal to sumTime.", "input_spec": "The first input line contains two integer numbers d,\u2009sumTime (1\u2009\u2264\u2009d\u2009\u2264\u200930,\u20090\u2009\u2264\u2009sumTime\u2009\u2264\u2009240) \u2014 the amount of days, during which Peter studied, and the total amount of hours, spent on preparation. Each of the following d lines contains two integer numbers minTimei,\u2009maxTimei (0\u2009\u2264\u2009minTimei\u2009\u2264\u2009maxTimei\u2009\u2264\u20098), separated by a space \u2014 minimum and maximum amount of hours that Peter could spent in the i-th day.", "output_spec": "In the first line print YES, and in the second line print d numbers (separated by a space), each of the numbers \u2014 amount of hours, spent by Peter on preparation in the corresponding day, if he followed his parents' instructions; or print NO in the unique line. If there are many solutions, print any of them.", "sample_inputs": ["1 48\n5 7", "2 5\n0 1\n3 5"], "sample_outputs": ["NO", "YES\n1 4"], "notes": null}, "positive_code": [{"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\nimport std.typecons;\nimport std.algorithm;\nimport std.array;\nimport std.range;\nimport std.math;\nimport std.regex;\n\nvoid main()\n{\n auto input = readln().split().map!(to!int)();\n int[][] times;\n foreach (i; 0 .. input[0]) {\n times ~= readln().split().map!(to!int)().array();\n }\n foreach (i, t; times) {\n int sum;\n foreach (tt; times[0 .. i]) {\n sum += tt[1];\n }\n while (sum + t[1] > input[1]) {\n if (t[1] - 1 >= t[0]) {\n t[1]--;\n } else {\n auto minu = sum + t[1] - input[1];\n foreach_reverse (tt; times[0 .. i]) {\n while (minu) {\n if (tt[0] == tt[1]) break;\n else {\n tt[1]--;\n minu--;\n sum--;\n }\n }\n }\n\n if (minu) {\n writeln(\"NO\");\n return;\n }\n }\n }\n }\n\n int sum;\n foreach (tt; times) {\n sum += tt[1];\n }\n if (sum != input[1]) {\n writeln(\"NO\");\n return;\n }\n writeln(\"YES\");\n foreach (t; times[0 .. $-1]) {\n write(t[1], \" \");\n }\n writeln(times[$-1][1]);\n \n}"}, {"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\nimport std.typecons;\nimport std.algorithm;\nimport std.array;\nimport std.range;\nimport std.math;\nimport std.regex;\n\nvoid main()\n{\n auto input = readln().split().map!(to!int)();\n int[][] times;\n foreach (s; stdin.byLine()) {\n \ttimes ~= s.split().map!(to!int)().array();\n }\n foreach (i, t; times) {\n \tint sum;\n \tforeach (tt; times[0 .. i]) {\n \t\tsum += tt[1];\n \t}\n \twhile (sum + t[1] > input[1]) {\n \t\tif (t[1] - 1 >= t[0]) {\n \t\t\tt[1]--;\n \t\t} else {\n \t\t\tauto minu = sum + t[1] - input[1];\n \t\t\tforeach_reverse (tt; times[0 .. i]) {\n \t\t\t\twhile (minu) {\n \t\t\t\t\tif (tt[0] == tt[1]) break;\n \t\t\t\t\telse {\n \t\t\t\t\t\ttt[1]--;\n \t\t\t\t\t\tminu--;\n \t\t\t\t\t\tsum--;\n \t\t\t\t\t}\n \t\t\t\t}\n \t\t\t}\n\n \t\t\tif (minu) {\n \t\t\t\twriteln(\"NO\");\n \t\t\t\treturn;\n \t\t\t}\n \t\t}\n \t}\n }\n\n int sum;\n foreach (tt; times) {\n \tsum += tt[1];\n }\n if (sum != input[1]) {\n \twriteln(\"NO\");\n \treturn;\n }\n writeln(\"YES\");\n foreach (t; times[0 .. $-1]) {\n \twrite(t[1], \" \");\n }\n writeln(times[$-1][1]);\n \n}"}, {"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\nimport std.typecons;\nimport std.algorithm;\nimport std.array;\nimport std.range;\nimport std.math;\nimport std.regex;\n\nvoid main()\n{\n int[][] times;\n int sum, diff;\n\n auto input = readln().split().map!(to!int)();\n\n a:foreach (s; stdin.byLine()) {\n \tauto t = s.split().map!(to!int)().array();\n\n \twhile (sum + t[1] > input[1]) {\n \t\tif (t[1] - 1 >= t[0]) {\n \t\t\tt[1]--;\n \t\t} else {\n \t\t\tdiff = sum + t[1] - input[1];\n \t\t\tforeach_reverse (tt; times) {\n \t\t\t\twhile (tt[0] != tt[1] && diff) {\n \t\t\t\t\ttt[1]--;\n \t\t\t\t\tdiff--;\n \t\t\t\t\tsum--;\n \t\t\t\t}\n \t\t\t}\n \t\t}\n \t\tif (diff) break a;\n \t}\n\n \ttimes ~= t;\n \tsum += t[1];\n }\n\n if (sum != input[1] || diff) {\n \twriteln(\"NO\");\n } else {\n \twriteln(\"YES\");\n \tforeach (t; times[0 .. $-1]) {\n \t\twrite(t[1], \" \");\n \t}\n \twriteln(times[$-1][1]);\n }\n \n}"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\nimport std.typecons;\nimport std.algorithm;\nimport std.array;\nimport std.range;\nimport std.math;\nimport std.regex;\n\nvoid main()\n{\n int[][] times;\n int sum, diff;\n\n auto input = readln().split().map!(to!int)();\n\n a:foreach (s; stdin.byLine()) {\n auto t = s.split().map!(to!int)().array();\n\n while (sum + t[1] > input[1]) {\n if (t[1] - 1 >= t[0]) {\n t[1]--;\n } else {\n diff = sum + t[1] - input[1];\n foreach_reverse (tt; times) {\n while (tt[0] != tt[1]) {\n tt[1]--;\n diff--;\n sum--;\n }\n }\n }\n if (diff) break a;\n }\n\n times ~= t;\n sum += t[1];\n }\n\n if (sum != input[1] || diff) {\n writeln(\"NO\");\n } else {\n writeln(\"YES\");\n foreach (t; times[0 .. $-1]) {\n write(t[1], \" \");\n }\n writeln(times[$-1][1]);\n }\n \n}"}, {"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\nimport std.typecons;\nimport std.algorithm;\nimport std.array;\nimport std.range;\nimport std.math;\nimport std.regex;\n\nvoid main()\n{\n int[][] times;\n int sum, diff;\n\n auto input = readln().split().map!(to!int)();\n\n a:foreach (s; stdin.byLine()) {\n \tauto t = s.split().map!(to!int)().array();\n\n \twhile (sum + t[1] > input[1]) {\n \t\tif (t[1] - 1 >= t[0]) {\n \t\t\tt[1]--;\n \t\t} else {\n \t\t\tdiff = sum + t[1] - input[1];\n \t\t\tforeach_reverse (tt; times) {\n \t\t\t\twhile (tt[0] != tt[1] && diff) {\n \t\t\t\t\ttt[1]--;\n \t\t\t\t\tdiff--;\n \t\t\t\t\tsum--;\n \t\t\t\t}\n \t\t\t}\n \t\t}\n \t\tif (diff) {writeln(\"u\");break a;}\n \t}\n\n \ttimes ~= t;\n \tsum += t[1];\n }\n\n if (sum != input[1] || diff) {\n \twriteln(\"NO\");\n } else {\n \twriteln(\"YES\");\n \tforeach (t; times[0 .. $-1]) {\n \t\twrite(t[1], \" \");\n \t}\n \twriteln(times[$-1][1]);\n }\n \n}"}, {"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\nimport std.typecons;\nimport std.algorithm;\nimport std.array;\nimport std.range;\nimport std.math;\nimport std.regex;\n\nvoid main()\n{\n auto input = readln().split().map!(to!int)();\n int[][] times;\n foreach (i; 0 .. input[0]) {\n times ~= readln().split().map!(to!int)().array();\n }\n foreach (i, t; times) {\n int sum;\n foreach (tt; times[0 .. i]) {\n sum += tt[1];\n }\n while (sum + t[1] > input[1]) {\n if (t[1] - 1 >= t[0]) {\n t[1]--;\n } else {\n auto minu = sum + t[1] - input[1];\n foreach_reverse (tt; times[0 .. i]) {\n while (minu) {\n if (tt[0] == tt[1]) break;\n else {\n tt[1]--;\n minu--;\n }\n }\n }\n\n if (minu) {\n writeln(\"NO\");\n return;\n }\n }\n }\n }\n\n int sum;\n foreach (tt; times) {\n sum += tt[1];\n }\n if (sum != input[1]) {\n writeln(\"NO\");\n return;\n }\n writeln(\"YES\");\n foreach (t; times[0 .. $-1]) {\n write(t[1], \" \");\n }\n writeln(times[$-1][1]);\n \n}"}], "src_uid": "f48ff06e65b70f49eee3d7cba5a6aed0"} {"nl": {"description": "A number is called quasibinary if its decimal representation contains only digits 0 or 1. For example, numbers 0, 1, 101, 110011\u00a0\u2014 are quasibinary and numbers 2, 12, 900 are not.You are given a positive integer n. Represent it as a sum of minimum number of quasibinary numbers.", "input_spec": "The first line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009106).", "output_spec": "In the first line print a single integer k\u00a0\u2014 the minimum number of numbers in the representation of number n as a sum of quasibinary numbers. In the second line print k numbers \u2014 the elements of the sum. All these numbers should be quasibinary according to the definition above, their sum should equal n. Do not have to print the leading zeroes in the numbers. The order of numbers doesn't matter. If there are multiple possible representations, you are allowed to print any of them.", "sample_inputs": ["9", "32"], "sample_outputs": ["9\n1 1 1 1 1 1 1 1 1", "3\n10 11 11"], "notes": null}, "positive_code": [{"source_code": "import std.stdio;\nimport std.range;\nimport std.string;\nimport std.algorithm;\n\nvoid main() {\n string s = readln.chomp;\n int n = s.minPos!\"a > b\"[0] - 48;\n n.writeln;\n n.iota\n .map!(i => s.map!(c => c > i + 48 ? \"1\" : \"0\").join.find!\"a!=48\").join(\" \").writeln;\n}"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.container;\nimport std.conv;\n\nchar[] n;\nlong[] result;\n\nvoid main() {\n\tn = cast(char[])(readln().strip);\n\tfor (;;) {\n\t\tstring t;\n\t\tfor (int i = 0; i < n.length; ++i)\n\t\t\tif (n[i] == '0')\n\t\t\t\tt ~= '0';\n\t\t\telse {\n\t\t\t\tt ~= '1';\n\t\t\t\t--n[i];\n\t\t\t}\n\t\tif (to!long(t))\n\t\t\tresult ~= to!long(t);\n\t\telse\n\t\t\tbreak;\n\t}\n\twriteln(result.length);\n\twritefln(\"%(%s %)\", result);\n}\n"}, {"source_code": "import std.math;\nimport std.stdio;\n\nvoid main() {\n\tuint n;\n\treadf(`%u`, &n);\n\tuint[] res;\n\n\twhile(n) {\n\t\tint k = cast(int)log10(n).floor.lrint, m = 10 ^^ k;\n\n\t\tloop: foreach(_; 0..n / m) {\n\t\t\tforeach(ref p; res)\n\t\t\t\tif(p / m % 10 == 0) {\n\t\t\t\t\tp += m;\n\t\t\t\t\tcontinue loop;\n\t\t\t\t}\n\n\t\t\tres ~= m;\n\t\t}\n\n\t\tn %= m;\n\t}\n\n\twritef(\"%u\\n%(%u %)\", res.length, res);\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio, std.bitmanip;\n\nint N;\nint[] Q;\n\nvoid main() {\n N = readln.chomp.to!int;\n\n int q = 1;\n while (format(\"%b\", q).to!int <= 10^^6) {\n Q ~= format(\"%b\", q).to!int;\n q++;\n }\n\n\n auto dp = new int[](N+1);\n fill(dp, 1 << 30);\n dp[0] = 0;\n auto fukugen = new int[](N+1);\n\n foreach (i; 0..N+1) {\n foreach (j; 0..Q.length.to!int) {\n if (i + Q[j] <= N && dp[i]+1 < dp[i+Q[j]]) {\n dp[i+Q[j]] = dp[i]+1;\n fukugen[i+Q[j]] = Q[j];\n }\n }\n }\n\n dp[N].writeln;\n int[] ans;\n int a = N;\n while (a > 0) {\n ans = fukugen[a] ~ ans;\n a -= fukugen[a];\n }\n ans.map!(to!string).join(\" \").writeln;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int MAX_N = 1_000_003;\nimmutable int BASE = 10;\n\nvoid main ()\n{\n\tint [] d;\n\tforeach (i; 0..MAX_N)\n\t{\n\t\tbool ok = true;\n\t\tint v = i;\n\t\twhile (v > 0)\n\t\t{\n\t\t\tok &= (v % BASE) < 2;\n\t\t\tv /= BASE;\n\t\t}\n\t\tif (ok)\n\t\t{\n\t\t\td ~= i;\n\t\t}\n\t}\n\n\tauto f = new int [MAX_N];\n\tf[1..$] = int.max >> 1;\n\tauto p = new int [MAX_N];\n\tp[] = 0;\n\tforeach (i; 0..MAX_N)\n\t{\n\t\tforeach (c; d)\n\t\t{\n\t\t\tif (c > i)\n\t\t\t{\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (f[i] > f[i - c] + 1)\n\t\t\t{\n\t\t\t\tf[i] = f[i - c] + 1;\n\t\t\t\tp[i] = c;\n\t\t\t}\n\t\t}\n\t}\n\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tint [] ans;\n\t\twhile (n)\n\t\t{\n\t\t\tans ~= p[n];\n\t\t\tn -= p[n];\n\t\t}\n\t\twriteln (ans.length);\n\t\twritefln (\"%(%s %)\", ans);\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.math;\nimport std.stdio;\n\nvoid main() {\n\tuint n;\n\treadf(`%u`, &n);\n\tuint[] res;\n\n\twhile(n) {\n\t\tint t, k = cast(int)log10(n).floor.lrint;\n\n\t\twhile(true) {\n\t\t\tauto c = t + 10 ^^ k--;\n\t\t\tif(c > n) break;\n\t\t\telse t = c;\n\t\t\tif(k < 0) break;\n\t\t}\n\n\t\tn -= t;\n\t\tres ~= t;\n\t}\n\n\twritef(\"%u\\n%(%u %)\", res.length, res);\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio, std.bitmanip;\n\nint N;\nint[] Q;\nTuple!(int, int)[int] mem;\n\nint dp(int n) {\n if (n < 10) return n;\n if (n in mem) return mem[n][0];\n\n mem[n] = tuple(1 << 30, -1);\n foreach (q; Q) {\n if (n >= q) {\n auto ret = dp(n-q) + 1;\n if (ret < mem[n][0]) {\n mem[n] = tuple(ret, q);\n }\n }\n }\n return mem[n][0];\n}\n\nvoid main() {\n N = readln.chomp.to!int;\n\n int q = 2;\n while (format(\"%b\", q).to!int <= 10^^6) {\n Q ~= format(\"%b\", q).to!int;\n q++;\n }\n\n reverse(Q);\n auto ans = dp(N);\n\n int[] ans2;\n while (N >= 10) {\n auto a = mem[N][1];\n ans2 ~= a;\n N -= a;\n }\n while (N--) {\n ans2 ~= 1;\n }\n ans2.map!(c => c.to!string).join(\" \").writeln;\n}\n"}, {"source_code": "import std.stdio;\nimport std.range;\nimport std.string;\nimport std.algorithm;\n\nvoid main() {\n auto s = readln.chomp;\n writeln(s);\n (s.minPos!\"a > b\"[0] - 48).iota\n .map!(i => s.map!(c => c > i + 48 ? \"1\" : \"0\").join.find!\"a!=48\").join(\" \").writeln;\n}"}, {"source_code": "import std.stdio;\nimport std.range;\nimport std.string;\nimport std.algorithm;\n\nvoid main() {\n auto s = readln.chomp;;\n (s.minPos!\"a > b\"[0] - 48).iota\n .map!(i => s.map!(c => c > i + 48 ? \"1\" : \"0\").join.find!\"a!=48\")\n .join(\" \").writeln;\n}"}], "src_uid": "033068c5e16d25f09039e29c88474275"} {"nl": {"description": "Two participants are each given a pair of distinct numbers from 1 to 9 such that there's exactly one number that is present in both pairs. They want to figure out the number that matches by using a communication channel you have access to without revealing it to you.Both participants communicated to each other a set of pairs of numbers, that includes the pair given to them. Each pair in the communicated sets comprises two different numbers.Determine if you can with certainty deduce the common number, or if you can determine with certainty that both participants know the number but you do not.", "input_spec": "The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\le n, m \\le 12$$$) \u2014 the number of pairs the first participant communicated to the second and vice versa. The second line contains $$$n$$$ pairs of integers, each between $$$1$$$ and $$$9$$$, \u2014 pairs of numbers communicated from first participant to the second. The third line contains $$$m$$$ pairs of integers, each between $$$1$$$ and $$$9$$$, \u2014 pairs of numbers communicated from the second participant to the first. All pairs within each set are distinct (in particular, if there is a pair $$$(1,2)$$$, there will be no pair $$$(2,1)$$$ within the same set), and no pair contains the same number twice. It is guaranteed that the two sets do not contradict the statements, in other words, there is pair from the first set and a pair from the second set that share exactly one number.", "output_spec": "If you can deduce the shared number with certainty, print that number. If you can with certainty deduce that both participants know the shared number, but you do not know it, print $$$0$$$. Otherwise print $$$-1$$$.", "sample_inputs": ["2 2\n1 2 3 4\n1 5 3 4", "2 2\n1 2 3 4\n1 5 6 4", "2 3\n1 2 4 5\n1 2 1 3 2 3"], "sample_outputs": ["1", "0", "-1"], "notes": "NoteIn the first example the first participant communicated pairs $$$(1,2)$$$ and $$$(3,4)$$$, and the second communicated $$$(1,5)$$$, $$$(3,4)$$$. Since we know that the actual pairs they received share exactly one number, it can't be that they both have $$$(3,4)$$$. Thus, the first participant has $$$(1,2)$$$ and the second has $$$(1,5)$$$, and at this point you already know the shared number is $$$1$$$.In the second example either the first participant has $$$(1,2)$$$ and the second has $$$(1,5)$$$, or the first has $$$(3,4)$$$ and the second has $$$(6,4)$$$. In the first case both of them know the shared number is $$$1$$$, in the second case both of them know the shared number is $$$4$$$. You don't have enough information to tell $$$1$$$ and $$$4$$$ apart.In the third case if the first participant was given $$$(1,2)$$$, they don't know what the shared number is, since from their perspective the second participant might have been given either $$$(1,3)$$$, in which case the shared number is $$$1$$$, or $$$(2,3)$$$, in which case the shared number is $$$2$$$. While the second participant does know the number with certainty, neither you nor the first participant do, so the output is $$$-1$$$."}, "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const M = readInt();\n const N = readInt();\n auto A = new int[M];\n foreach (i; 0 .. M) {\n A[i] |= 1 << readInt();\n A[i] |= 1 << readInt();\n }\n auto B = new int[N];\n foreach (j; 0 .. N) {\n B[j] |= 1 << readInt();\n B[j] |= 1 << readInt();\n }\n \n int ans = -1;\n int you;\n foreach (i; 0 .. M) foreach (j; 0 .. N) {\n const c = A[i] & B[j];\n if (popcnt(c) == 1) {\n you |= c;\n }\n }\n if (popcnt(you) == 1) {\n ans = bsf(you);\n } else {\n bool okA = true;\n foreach (i; 0 .. M) {\n int they;\n foreach (j; 0 .. N) {\n const c = A[i] & B[j];\n if (popcnt(c) == 1) {\n they |= c;\n }\n }\n okA = okA && (popcnt(they) <= 1);\n }\n bool okB = true;\n foreach (j; 0 .. N) {\n int they;\n foreach (i; 0 .. M) {\n const c = A[i] & B[j];\n if (popcnt(c) == 1) {\n they |= c;\n }\n }\n okB = okB && (popcnt(they) <= 1);\n }\n if (okA && okB) {\n ans = 0;\n }\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const M = readInt();\n const N = readInt();\n auto A = new int[M];\n foreach (i; 0 .. M) {\n A[i] |= 1 << readInt();\n A[i] |= 1 << readInt();\n }\n auto B = new int[N];\n foreach (j; 0 .. N) {\n B[j] |= 1 << readInt();\n B[j] |= 1 << readInt();\n }\n \n int ans = -1;\n int you;\n foreach (i; 0 .. M) foreach (j; 0 .. N) {\n const c = A[i] & B[j];\n if (popcnt(c) == 1) {\n you |= c;\n }\n }\n if (popcnt(you) == 1) {\n ans = bsf(you);\n } else {\n bool okA, okB;\n foreach (i; 0 .. M) {\n int they;\n foreach (j; 0 .. N) {\n const c = A[i] & B[j];\n if (popcnt(c) == 1) {\n they |= c;\n }\n }\n if (popcnt(they) == 1) {\n okA = true;\n }\n }\n foreach (j; 0 .. N) {\n int they;\n foreach (i; 0 .. M) {\n const c = A[i] & B[j];\n if (popcnt(c) == 1) {\n they |= c;\n }\n }\n if (popcnt(they) == 1) {\n okB = true;\n }\n }\n if (okA && okB) {\n ans = 0;\n }\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "cb4de190ae26127df6eeb7a1a1db8a6d"} {"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\u00a0\u2014 v0\u2009+\u2009a pages, at third\u00a0\u2014 v0\u2009+\u20092a 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\u2009\u2264\u2009c\u2009\u2264\u20091000, 0\u2009\u2264\u2009l\u2009<\u2009v0\u2009\u2264\u2009v1\u2009\u2264\u20091000, 0\u2009\u2264\u2009a\u2009\u2264\u20091000) \u2014 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 \u2014 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\u2009-\u20094, at second day\u00a0\u2014 4\u2009-\u200911, at third day\u00a0\u2014 11\u2009-\u200912 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": "// tested by Hightail - https://github.com/dj3500/hightail\nimport std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\n\nimmutable inf = 10^^9 + 7;\n\nint c, v0, v1, a, l;\n\nvoid main() {\n scan(c, v0, v1, a, l);\n\n int r;\n int cnt;\n\n while (true) {\n cnt++;\n r += min(v0 + a * (cnt - 1), v1);\n\n if (r >= c) {\n writeln(cnt);\n return;\n }\n\n r -= l;\n }\n}\n\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}"}], "negative_code": [], "src_uid": "b743110117ce13e2090367fd038d3b50"} {"nl": {"description": "Alice is the leader of the State Refactoring Party, and she is about to become the prime minister. The elections have just taken place. There are $$$n$$$ parties, numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th party has received $$$a_i$$$ seats in the parliament.Alice's party has number $$$1$$$. In order to become the prime minister, she needs to build a coalition, consisting of her party and possibly some other parties. There are two conditions she needs to fulfil: The total number of seats of all parties in the coalition must be a strict majority of all the seats, i.e. it must have strictly more than half of the seats. For example, if the parliament has $$$200$$$ (or $$$201$$$) seats, then the majority is $$$101$$$ or more seats. Alice's party must have at least $$$2$$$ times more seats than any other party in the coalition. For example, to invite a party with $$$50$$$ seats, Alice's party must have at least $$$100$$$ seats. For example, if $$$n=4$$$ and $$$a=[51, 25, 99, 25]$$$ (note that Alice'a party has $$$51$$$ seats), then the following set $$$[a_1=51, a_2=25, a_4=25]$$$ can create a coalition since both conditions will be satisfied. However, the following sets will not create a coalition: $$$[a_2=25, a_3=99, a_4=25]$$$ since Alice's party is not there; $$$[a_1=51, a_2=25]$$$ since coalition should have a strict majority; $$$[a_1=51, a_2=25, a_3=99]$$$ since Alice's party should have at least $$$2$$$ times more seats than any other party in the coalition. Alice does not have to minimise the number of parties in a coalition. If she wants, she can invite as many parties as she wants (as long as the conditions are satisfied). If Alice's party has enough people to create a coalition on her own, she can invite no parties.Note that Alice can either invite a party as a whole or not at all. It is not possible to invite only some of the deputies (seats) from another party. In other words, if Alice invites a party, she invites all its deputies.Find and print any suitable coalition.", "input_spec": "The first line contains a single integer $$$n$$$ ($$$2 \\leq n \\leq 100$$$)\u00a0\u2014 the number of parties. The second line contains $$$n$$$ space separated integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\leq a_i \\leq 100$$$)\u00a0\u2014 the number of seats the $$$i$$$-th party has.", "output_spec": "If no coalition satisfying both conditions is possible, output a single line with an integer $$$0$$$. Otherwise, suppose there are $$$k$$$ ($$$1 \\leq k \\leq n$$$) parties in the coalition (Alice does not have to minimise the number of parties in a coalition), and their indices are $$$c_1, c_2, \\dots, c_k$$$ ($$$1 \\leq c_i \\leq n$$$). Output two lines, first containing the integer $$$k$$$, and the second the space-separated indices $$$c_1, c_2, \\dots, c_k$$$. You may print the parties in any order. Alice's party (number $$$1$$$) must be on that list. If there are multiple solutions, you may print any of them.", "sample_inputs": ["3\n100 50 50", "3\n80 60 60", "2\n6 5", "4\n51 25 99 25"], "sample_outputs": ["2\n1 2", "0", "1\n1", "3\n1 2 4"], "notes": "NoteIn the first example, Alice picks the second party. Note that she can also pick the third party or both of them. However, she cannot become prime minister without any of them, because $$$100$$$ is not a strict majority out of $$$200$$$.In the second example, there is no way of building a majority, as both other parties are too large to become a coalition partner.In the third example, Alice already has the majority. The fourth example is described in the problem statement."}, "positive_code": [{"source_code": "/+ dub.sdl:\n name \"A\"\n dependency \"dunkelheit\" version=\"1.0.1\"\n+/\n\nimport std.stdio, std.algorithm, std.range, std.conv;\n// import dkh.foundation, dkh.scanner;\n\nint main() {\n Scanner sc = new Scanner(stdin);\n scope(exit) assert(!sc.hasNext);\n\n int n;\n long[] a;\n sc.read(n, a);\n\n long sm = a.sum;\n int[] our = iota(n).filter!(i => i == 0 || 2 * a[i] <= a[0]).array;\n long my = our.map!(i => a[i]).sum;\n\n debug writeln(sm, \" \", my, \" \", our);\n\n if (sm >= my * 2) {\n writeln(\"0\");\n } else {\n writeln(our.length);\n writeln(our.map!\"a + 1\".map!(to!string).join(\" \"));\n }\n return 0;\n}\n/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/foundation.d */\n \n// module dkh.foundation;\n\n \nstatic if (__VERSION__ <= 2070) {\n /*\n Copied by https://github.com/dlang/phobos/blob/master/std/algorithm/iteration.d\n Copyright: Andrei Alexandrescu 2008-.\n License: $(HTTP boost.org/LICENSE_1_0.txt, Boost License 1.0).\n */\n template fold(fun...) if (fun.length >= 1) {\n auto fold(R, S...)(R r, S seed) {\n import std.algorithm : reduce;\n static if (S.length < 2) {\n return reduce!fun(seed, r);\n } else {\n import std.typecons : tuple;\n return reduce!fun(tuple(seed), r);\n }\n }\n }\n \n}\n/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/container/stackpayload.d */\n// module dkh.container.stackpayload;\n\n \nstruct StackPayload(T, size_t MINCAP = 4) if (MINCAP >= 1) {\n import core.exception : RangeError;\n\n private T* _data;\n private uint len, cap;\n\n @property bool empty() const { return len == 0; }\n @property size_t length() const { return len; }\n alias opDollar = length;\n\n \n inout(T)[] data() inout { return (_data) ? _data[0..len] : null; }\n \n ref inout(T) opIndex(size_t i) inout {\n version(assert) if (len <= i) throw new RangeError();\n return _data[i];\n } \n ref inout(T) front() inout { return this[0]; } \n ref inout(T) back() inout { return this[$-1]; } \n\n void reserve(size_t newCap) {\n import core.memory : GC;\n import core.stdc.string : memcpy;\n import std.conv : to;\n if (newCap <= cap) return;\n void* newData = GC.malloc(newCap * T.sizeof);\n cap = newCap.to!uint;\n if (len) memcpy(newData, _data, len * T.sizeof);\n _data = cast(T*)(newData);\n } \n void free() {\n import core.memory : GC;\n GC.free(_data);\n } \n \n void clear() {\n len = 0;\n }\n\n void insertBack(T item) {\n import std.algorithm : max;\n if (len == cap) reserve(max(cap * 2, MINCAP));\n _data[len++] = item;\n } \n alias opOpAssign(string op : \"~\") = insertBack; \n void removeBack() {\n assert(!empty, \"StackPayload.removeBack: Stack is empty\");\n len--;\n } \n}\n\n \n/* IMPORT /home/yosupo/Programs/dunkelheit/source/dkh/scanner.d */\n// module dkh.scanner;\n\n// import dkh.container.stackpayload;\n\n \nclass Scanner {\n import std.stdio : File;\n import std.conv : to;\n import std.range : front, popFront, array, ElementType;\n import std.array : split;\n import std.traits : isSomeChar, isStaticArray, isArray; \n import std.algorithm : map;\n private File f;\n \n this(File f) {\n this.f = f;\n }\n private char[512] lineBuf;\n private char[] line;\n private bool succW() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n return !line.empty;\n }\n private bool succ() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (true) {\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n if (!line.empty) break;\n line = lineBuf[];\n f.readln(line);\n if (!line.length) return false;\n }\n return true;\n }\n\n private bool readSingle(T)(ref T x) {\n import std.algorithm : findSplitBefore;\n import std.string : strip;\n import std.conv : parse;\n if (!succ()) return false;\n static if (isArray!T) {\n alias E = ElementType!T;\n static if (isSomeChar!E) {\n \n \n auto r = line.findSplitBefore(\" \");\n x = r[0].strip.dup;\n line = r[1];\n } else static if (isStaticArray!T) {\n foreach (i; 0..T.length) {\n assert(succW());\n x[i] = line.parse!E;\n }\n } else {\n StackPayload!E buf;\n while (succW()) {\n buf ~= line.parse!E;\n }\n x = buf.data;\n }\n } else {\n x = line.parse!T;\n }\n return true;\n }\n\n \n int unsafeRead(T, Args...)(ref T x, auto ref Args args) {\n if (!readSingle(x)) return 0;\n static if (args.length == 0) {\n return 1;\n } else {\n return 1 + read(args);\n }\n }\n \n void read(Args...)(auto ref Args args) {\n import std.exception : enforce;\n static if (args.length != 0) {\n enforce(readSingle(args[0]));\n read(args[1..$]);\n }\n }\n \n bool hasNext() {\n return succ();\n }\n}\n\n\n \n \n\n \n\n/*\nThis source code generated by dunkelheit and include dunkelheit's source code.\ndunkelheit's Copyright: Copyright (c) 2016- Kohei Morita. (https://github.com/yosupo06/dunkelheit)\ndunkelheit's License: MIT License(https://github.com/yosupo06/dunkelheit/blob/master/LICENSE.txt)\n*/\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nint N;\nint[] A;\n\nvoid main() {\n try {\n for (; ; ) {\n N = readInt();\n A = new int[N];\n foreach (i; 0 .. N) {\n A[i] = readInt();\n }\n \n int[] ans;\n ans ~= 0;\n foreach (i; 1 .. N) {\n if (A[0] >= 2 * A[i]) {\n ans ~= i;\n }\n }\n int sum;\n foreach (i; ans) {\n sum += A[i];\n }\n if (2 * sum > A.sum) {\n writeln(ans.length);\n foreach (index, i; ans) {\n if (index > 0) {\n write(\" \");\n }\n write(i + 1);\n }\n writeln();\n } else {\n writeln(0);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "0a71fdaaf08c18396324ad762b7379d7"} {"nl": {"description": "PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: \"There exists such a positive integer n that for each positive integer m number n\u00b7m\u2009+\u20091 is a prime number\".Unfortunately, PolandBall is not experienced yet and doesn't know that his hypothesis is incorrect. Could you prove it wrong? Write a program that finds a counterexample for any n.", "input_spec": "The only number in the input is n (1\u2009\u2264\u2009n\u2009\u2264\u20091000)\u00a0\u2014 number from the PolandBall's hypothesis. ", "output_spec": "Output such m that n\u00b7m\u2009+\u20091 is not a prime number. Your answer will be considered correct if you output any suitable m such that 1\u2009\u2264\u2009m\u2009\u2264\u2009103. It is guaranteed the the answer exists.", "sample_inputs": ["3", "4"], "sample_outputs": ["1", "2"], "notes": "NoteA prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself.For the first sample testcase, 3\u00b71\u2009+\u20091\u2009=\u20094. We can output 1.In the second sample testcase, 4\u00b71\u2009+\u20091\u2009=\u20095. We cannot output 1 because 5 is prime. However, m\u2009=\u20092 is okay since 4\u00b72\u2009+\u20091\u2009=\u20099, which is not a prime number."}, "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.range;\nimport std.string;\n\n\nbool prime(int n)\n{\n int i=2;\n for(;i 0)\n\t{\n\t\tfor (int m = 1; ; m++)\n\t\t{\n\t\t\tif (!isPrime (n * m + 1))\n\t\t\t{\n\t\t\t\twriteln (m);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.range;\nimport std.string;\n\n\nbool prime(int n)\n{\n int i=2;\n for(;i a>=buf[k-1] && a>0 ).writeln;\n}"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\nimport std.algorithm;\nimport std.array;\nimport std.range;\n\nvoid main(){\n\tint n, k; readf(\"%d %d\\n\", &n, &k);\n\tauto buf = readln.split.map!(to!int).array;\n\tbuf.count!(a => (a >= buf[k-1]) && (a > 0) ).writeln;\n}"}, {"source_code": "import std.stdio;\n\nint main(string[] argv)\n{\n\tint n, pos;\n readf(\" %d %d\", &n, &pos);\n\tint[] a = new int[n];\n\tfor (int i = 0; i < n; ++i)\n\t\treadf(\" %d\", &a[i]);\n\tint j = pos - 1;\n\n\tif (a[j] == 0)\n\t\twhile (j >= 0 && a[j] == 0)\n\t\t\t--j;\n\telse\n\t\twhile (j+1 <= n-1 && a[j] == a[j+1])\n\t\t\t++j;\n\n\twriteln(j+1);\n\treadln;\n return 0;\n}\n"}, {"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\nimport std.array;\n\nvoid main() {\n string[] l1 = readln().chomp().split();\n auto n = to!int(l1[0]);\n auto k = to!int(l1[1]);\n string[] l2 = readln().chomp().split();\n auto tot = 0;\n for (auto i=0; i 0) {\n tot += 1;\n }\n }\n auto kv = to!int(l2[k-1]);\n if (kv > 0) {\n while (tot < n && to!int(l2[tot]) == kv) {\n tot += 1;\n }\n }\n writeln(tot);\n}\n"}, {"source_code": "\ufeffimport std.stdio, std.string, std.conv;\n\nvoid main() {\n\n\tbyte n, k;\n\n\treadf(\"%s %s\\n\", &n, &k);\n\n\tshort max, ki;\n\tforeach (idx, score; readln.split) {\n\t\tif (idx == k - 1)\n\t\t\tki = score.to!byte;\n\t\tif (idx > k - 1 && score.to!byte < ki || score.to!byte == 0)\n\t\t\tbreak;\n\t\t++max;\n\t}\n\n\twriteln(max);\n}"}, {"source_code": "import std.stdio : readf, readln, writeln;\nimport std.math : ceil;\nimport std.conv : to;\nimport std.array : split;\n\nvoid main()\n{\n uint[] nums;\n uint n, k;\n uint counter;\n uint pass;\n \n readf(\"%s %s\\n\", &n, &k);\n \n foreach(uint i, string num; split(readln))\n {\n uint unum = to!uint(num);\n if ((i+1)==k) pass = unum;\n nums ~= unum;\n }\n foreach(num; nums)\n {\n if (num > 0 && num >= pass) ++counter;\n }\n\n writeln(counter);\n}"}, {"source_code": "import std.stdio;\n\nvoid main() {\n int n, k;\n readf(\"%d %d\\n\", &n, &k);\n\n int[] scores = new int[n];\n\n for (int i = 0; i < n-1; ++i) {\n readf(\"%d \", &scores[i]);\n }\n readf(\"%d\\n\", &scores[n-1]);\n\n int kScore = scores[k-1];\n int nextRound = 0;\n\n for (int i = 0; i < n; ++i) {\n if (scores[i] > 0 && scores[i] >= kScore) {\n nextRound++;\n }\n }\n\n writefln(\"%d\", nextRound);\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\n\nvoid main() \n{\n int n, k;\n scanf(\"%d %d\", &n, &k);\n \n int[] a = new int[n];\n \n for (int i = 0; i < n; ++i) {\n scanf(\"%d\", &a[i]);\n }\n \n int f = a[k - 1];\n \n a.sort();\n \n \n int ans = 0;\n \n for (int i = 0; i < n; ++i) {\n \n \n if (a[i] > 0 && a[i] >= f)\n ans++;\n }\n \n \n \n printf(\"%d\\n\", ans);\n\n}\n"}, {"source_code": "import std.stdio;\nimport core.stdc.stdio;\nimport std.conv;\nimport std.container;\n\nint main(string[] argv)\n{\n\tint n, k;\n\tscanf(\"%d %d\", &n, &k);\n\tint[] contestants = new int[n];\n\tfor (int i = 0; i < n; i++)\n\t{\n\t\tscanf(\"%d\", &contestants[i]);\n\t}\n\tint score = contestants[k-1];\n\tint result = 0;\n\tfor (int i = 0; i < n; i++)\n\t{\n\t\tresult += (contestants[i] > 0 && contestants[i] >= score) ? 1 : 0;\n\t}\n\twriteln(result);\n\treturn 0;\n}\n"}, {"source_code": "import std.stdio; \nvoid main() { \n\tint n, k;\n\treadf(\" %s\",&n);\n\treadf(\" %s\",&k);\n\tk--;\n\tint[] a = new int[n];\n\tfor (int i = 0; i < n; i++) {\n\t\treadf(\" %s\",&a[i]);\n\t}\n\ta = a.sort.reverse;\n\t//writeln(a);\n\tint answer = 0;\n\tfor (int i = 0; i < n; i++) {\n\t\tif (a[i] > 0 && a[i] >= a[k]) {\n\t\t\tanswer++;\n\t\t}\n\t}\n\twriteln(answer);\n}"}, {"source_code": "// https://codeforces.com/problemset/problem/158/A\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int n, k;\n readf(\"%d %d\", &n, &k);\n readln;\n\n string input = readln;\n int[] a = input.split.map!(x => x.to!int).array;\n\n a.filter!(x => (x >= a[k-1]) && (x > 0)).count.writeln;\n}\n\n"}, {"source_code": "// https://codeforces.com/problemset/problem/158/A\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int n, k;\n readf(\"%d %d\", &n, &k);\n readln;\n\n string input = readln;\n int[] a = input.split.map!(x => x.to!int).array;\n\n a.count!(x => (x >= a[k-1]) && (x > 0)).writeln;\n}\n\n"}, {"source_code": "//ahmat\nimport core.stdc.stdio:scanf,printf,puts;\nimport core.bitop;\nimport std.stdio;\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.container;\npragma(inline,true);\n\nvoid main(){\n int k,n;\n readf!\"%d %d\"(n,k);\n readln;\n auto a=readln.splitter\n .map!(to!int)\n .array;\n k--;\n a.count!((x)=>x>0 && x>=a[k]).writeln;\n}\n"}, {"source_code": "import std.stdio;\nvoid main()\n{\n int [100000+10]arr;\n int n,k;\n readf(\"%d %d \",&n,&k);\n for(int i=1;i<=n;i++)readf(\"%d \",&arr[i]);\n int ans=0;\n for(int i=1;i<=n;i++)\n {\n if(arr[i]>=arr[k] && arr[i]>0)ans++;\n }\n writeln(ans);\n}\n"}, {"source_code": "\ufeffmodule main;\n\nimport std.c.stdio;\n\nint main(string[] argv)\n{\n\tint n,k;\n\tscanf(\"%d %d\", &n, &k);\n\tint [] arr = new int[n];\n\tfor(int i = 0; i= arr[k-1] && arr[i] >0)\n\t\t\tq++;\n\tprintf(\"%d\", q);\n\treturn 0;\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\nimport std.algorithm;\nimport std.array;\nimport std.range;\n\nvoid main(){\n\tint n, k; readf(\"%d %d\\n\", &n, &k);\n\tauto buf = readln.split.map!(to!int).array;\n\t(buf[0] == 0) ? writeln(0) : buf.count!(a => a>=buf[k-1]).writeln;\n}"}, {"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\nimport std.array;\n\nvoid main() {\n string[] l1 = readln().chomp().split();\n auto n = to!int(l1[0]);\n auto k = to!int(l1[1]);\n string[] l2 = readln().chomp().split();\n auto tot = k;\n auto kv = to!int(l2[k-1]);\n if (kv > 0) {\n while (tot < n && to!int(l2[tot]) == kv) {\n tot += 1;\n }\n writeln(tot);\n } else {\n writeln(0);\n }\n}\n"}, {"source_code": "import std.stdio : readf, readln, writeln;\nimport std.math : ceil;\nimport std.conv : to;\nimport std.array : split;\n\nvoid main()\n{\n\tuint[] nums;\n\tuint n, k;\n\tuint counter;\n\tuint pass;\n\t\n\treadf(\"%s %s\\n\", &n, &k);\n\t\n\tforeach(uint i, string num; split(readln))\n\t{\n\t\tuint unum = to!uint(num);\n\t\tif (i==k) pass = unum;\n\t\tnums ~= unum;\n\t}\n\tforeach(num; nums)\n\t{\n\t\tif (num > 0 && num >= pass) ++counter;\n\t}\n\n\twriteln(counter);\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\n\nvoid main() \n{\n int n, k;\n scanf(\"%d %d\", &n, &k);\n \n int[] a = new int[n];\n \n for (int i = 0; i < n; ++i) {\n scanf(\"%d\", &a[i]);\n }\n \n a.sort();\n \n int ans = 0;\n \n for (int i = 0; i < n; ++i) {\n if (a[i] > 0 && a[i] >= a[k - 1])\n ans++;\n }\n \n \n printf(\"%d\\n\", ans);\n\n}\n"}, {"source_code": "import std.stdio;\nimport core.stdc.stdio;\nimport std.conv;\nimport std.container;\n\nint main(string[] argv)\n{\n\tint n, k;\n\tscanf(\"%d %d\", &n, &k);\n\tint[] contestants = new int[n];\n\tfor (int i = 0; i < n; i++)\n\t{\n\t\tscanf(\"%d\", &contestants[i]);\n\t}\n\tint score = contestants[k];\n\tint result = 0;\n\tfor (int i = 0; i < n; i++)\n\t{\n\t\tresult += (contestants[i] > 0 && contestants[i] >= score) ? 1 : 0;\n\t}\n\twriteln(result);\n\treturn 0;\n}\n"}, {"source_code": "import std.stdio; \nvoid main() { \n\tint n, k;\n\treadf(\" %s\",&n);\n\treadf(\" %s\",&k);\n\tk--;\n\tint[] a = new int[n];\n\tfor (int i = 0; i < n; i++) {\n\t\treadf(\" %s\",&a[i]);\n\t}\n\ta = a.reverse;\n\tint answer = 0;\n\tfor (int i = 0; i < n; i++) {\n\t\tif (a[i] > 0 && a[i] >= a[k]) {\n\t\t\tanswer++;\n\t\t}\n\t}\n\twriteln(answer);\n}"}, {"source_code": "// https://codeforces.com/problemset/problem/158/A\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int n, k;\n readf(\"%d %d\", &n, &k);\n readln;\n\n string input = readln;\n int[] a = input.split.map!(x => x.to!int).array;\n\n a.filter!(x => (x >= a[k-1]) && (x > 0));\n a.length.writeln;\n}\n\n"}], "src_uid": "193ec1226ffe07522caf63e84a7d007f"} {"nl": {"description": "Ilya got tired of sports programming, left university and got a job in the subway. He was given the task to determine the escalator load factor. Let's assume that n people stand in the queue for the escalator. At each second one of the two following possibilities takes place: either the first person in the queue enters the escalator with probability p, or the first person in the queue doesn't move with probability (1\u2009-\u2009p), paralyzed by his fear of escalators and making the whole queue wait behind him.Formally speaking, the i-th person in the queue cannot enter the escalator until people with indices from 1 to i\u2009-\u20091 inclusive enter it. In one second only one person can enter the escalator. The escalator is infinite, so if a person enters it, he never leaves it, that is he will be standing on the escalator at any following second. Ilya needs to count the expected value of the number of people standing on the escalator after t seconds. Your task is to help him solve this complicated task.", "input_spec": "The first line of the input contains three numbers n,\u2009p,\u2009t (1\u2009\u2264\u2009n,\u2009t\u2009\u2264\u20092000, 0\u2009\u2264\u2009p\u2009\u2264\u20091). Numbers n and t are integers, number p is real, given with exactly two digits after the decimal point.", "output_spec": "Print a single real number \u2014 the expected number of people who will be standing on the escalator after t seconds. The absolute or relative error mustn't exceed 10\u2009-\u20096.", "sample_inputs": ["1 0.50 1", "1 0.50 4", "4 0.20 2"], "sample_outputs": ["0.5", "0.9375", "0.4"], "notes": null}, "positive_code": [{"source_code": "import std.stdio, std.string;\nimport std.algorithm;\n\ndouble saiki(int n, int t, double p, double[][] dp)\n{\n if (dp[n][t] != -1)\n {\n return dp[n][t];\n }\n if (n == 0)\n {\n dp[n][t] = 0.0;\n return 0.0;\n }\n if (t == 0)\n {\n dp[n][t] = cast(double)n;\n return cast(double)n;\n }\n auto ret0 = saiki(n - 1, t - 1, p, dp);\n auto ret1 = saiki(n, t - 1, p, dp);\n dp[n][t] = p * ret0 + (1.0 - p) * ret1;\n return dp[n][t];\n}\n\nvoid solve(int n, double p, int t)\n{\n auto dp = new double[][](n + 1, t + 1);\n foreach (i; 0 .. n + 1)\n {\n fill(dp[i], -1);\n }\n auto res = saiki(n, t, p, dp);\n writefln(\"%.10f\", cast(double)n - res);\n}\n\nint main(string[] args)\n{\n int n, t;\n double p;\n while (readf(\"%d %f %d\\n\", &n, &p, &t) == 3)\n {\n solve(n, p, t);\n }\n return 0;\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nvoid main ()\n{\n\tint n, t;\n\treal p;\n\twhile (readf (\" %s %s %s\", &n, &p, &t) > 0)\n\t{\n\t\treal q = 1.0 - p;\n\t\tauto f = new real [] [] (t + 1, n + 1);\n\t\tforeach (ref g; f)\n\t\t{\n\t\t\tg[] = 0.0;\n\t\t}\n\t\tf[0][0] = 1.0;\n\n\t\tforeach (i; 0..t)\n\t\t{\n\t\t\tforeach (j; 0..n)\n\t\t\t{\n\t\t\t\tf[i + 1][j + 1] += f[i][j] * p;\n\t\t\t\tf[i + 1][j + 0] += f[i][j] * q;\n\t\t\t}\n\t\t\tf[i + 1][n] += f[i][n];\n\t\t}\n\n\t\treal res = 0.0;\n\t\tforeach (j; 0..n + 1)\n\t\t{\n\t\t\tres += f[t][j] * j;\n\t\t}\n\t\twritefln (\"%.10f\", res);\n\t}\n}\n"}], "negative_code": [], "src_uid": "20873b1e802c7aa0e409d9f430516c1e"} {"nl": {"description": "Vova, the Ultimate Thule new shaman, wants to build a pipeline. As there are exactly n houses in Ultimate Thule, Vova wants the city to have exactly n pipes, each such pipe should be connected to the water supply. A pipe can be connected to the water supply if there's water flowing out of it. Initially Vova has only one pipe with flowing water. Besides, Vova has several splitters.A splitter is a construction that consists of one input (it can be connected to a water pipe) and x output pipes. When a splitter is connected to a water pipe, water flows from each output pipe. You can assume that the output pipes are ordinary pipes. For example, you can connect water supply to such pipe if there's water flowing out from it. At most one splitter can be connected to any water pipe. The figure shows a 4-output splitter Vova has one splitter of each kind: with 2, 3, 4, ..., k outputs. Help Vova use the minimum number of splitters to build the required pipeline or otherwise state that it's impossible.Vova needs the pipeline to have exactly n pipes with flowing out water. Note that some of those pipes can be the output pipes of the splitters.", "input_spec": "The first line contains two space-separated integers n and k (1\u2009\u2264\u2009n\u2009\u2264\u20091018, 2\u2009\u2264\u2009k\u2009\u2264\u2009109). Please, do not use the %lld specifier to read or write 64-bit integers in \u0421++. It is preferred to use the cin, cout streams or the %I64d specifier.", "output_spec": "Print a single integer \u2014 the minimum number of splitters needed to build the pipeline. If it is impossible to build a pipeline with the given splitters, print -1.", "sample_inputs": ["4 3", "5 5", "8 4"], "sample_outputs": ["2", "1", "-1"], "notes": null}, "positive_code": [{"source_code": "module sigod.codeforces.p287B;\n\nimport std.stdio;\n\nvoid main()\n{\n\tlong n, k;\n\tstdin.readf(\"%s %s\", &n, &k);\n\n\tlong count = solve(n, k);\n\n\tstdout.writeln(count);\n}\n\nlong solve(long n, long k)\n{\n\tif (n == 1) return 0;\n\telse if (n <= k) return 1;\n\n\tlong S = s(k - 1, k);\n\tif (n > S) return -1;\n\telse if (n == S) return k - 1;\n\n\tlong min_count;\n\tlong min = long.max;\n\n\tlong left_count = 1;\n\tlong right_count = k - 1;\n\n\twhile (left_count < right_count - 1) {\n\t\tlong middle_count = (left_count + right_count) / 2;\n\t\tlong middle = s(middle_count, k);\n\n\t\tif (middle < n) {\n\t\t\tleft_count = middle_count;\n\t\t}\n\t\telse {\n\t\t\tright_count = middle_count;\n\n\t\t\tif (min > middle) {\n\t\t\t\tmin_count = middle_count;\n\t\t\t\tmin = middle;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn min_count;\n}\n\nprivate\nlong s(long count, long k)\n{\n\t//long S = (1 + (k - 1)) * (k - 1) / 2 + 1;\n\treturn (k - count + k - 1) * count / 2 + 1;\n}\n\nunittest {\n\tstatic assert(solve(4, 3) == 2);\n\tstatic assert(solve(5, 5) == 1);\n\tstatic assert(solve(8, 4) == -1);\n}"}], "negative_code": [{"source_code": "module sigod.codeforces.p287B;\n\nimport std.stdio;\n\nvoid main()\n{\n\tlong n, k;\n\tstdin.readf(\"%s %s\", &n, &k);\n\n\tlong count = solve(n, k);\n\n\tstdout.writeln(count);\n}\n\nlong solve(long n, long k)\n{\n\tif (n <= k) return 1;\n\n\tlong S = s(k - 1, k);\n\tif (n > S) return -1;\n\telse if (n == S) return k - 1;\n\n\tlong min_count;\n\tlong min = long.max;\n\n\tlong left_count = 1;\n\tlong right_count = k - 1;\n\n\twhile (left_count < right_count - 1) {\n\t\tlong middle_count = (left_count + right_count) / 2;\n\t\tlong middle = s(middle_count, k);\n\n\t\tif (middle < n) {\n\t\t\tleft_count = middle_count;\n\t\t}\n\t\telse {\n\t\t\tright_count = middle_count;\n\n\t\t\tif (min > middle) {\n\t\t\t\tmin_count = middle_count;\n\t\t\t\tmin = middle;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn min_count;\n}\n\nprivate\nlong s(long count, long k)\n{\n\t//long S = (1 + (k - 1)) * (k - 1) / 2 + 1;\n\treturn (k - count + k - 1) * count / 2 + 1;\n}\n\nunittest {\n\tstatic assert(solve(4, 3) == 2);\n\tstatic assert(solve(5, 5) == 1);\n\tstatic assert(solve(8, 4) == -1);\n}"}], "src_uid": "83bcfe32db302fbae18e8a95d89cf411"} {"nl": {"description": "Stepan has a very big positive integer.Let's consider all cyclic shifts of Stepan's integer (if we look at his integer like at a string) which are also integers (i.e. they do not have leading zeros). Let's call such shifts as good shifts. For example, for the integer 10203 the good shifts are the integer itself 10203 and integers 20310 and 31020.Stepan wants to know the minimum remainder of the division by the given number m among all good shifts. Your task is to determine the minimum remainder of the division by m.", "input_spec": "The first line contains the integer which Stepan has. The length of Stepan's integer is between 2 and 200\u2009000 digits, inclusive. It is guaranteed that Stepan's integer does not contain leading zeros. The second line contains the integer m (2\u2009\u2264\u2009m\u2009\u2264\u2009108) \u2014 the number by which Stepan divides good shifts of his integer.", "output_spec": "Print the minimum remainder which Stepan can get if he divides all good shifts of his integer by the given number m.", "sample_inputs": ["521\n3", "1001\n5", "5678901234567890123456789\n10000"], "sample_outputs": ["2", "0", "123"], "notes": "NoteIn the first example all good shifts of the integer 521 (good shifts are equal to 521, 215 and 152) has same remainder 2 when dividing by 3.In the second example there are only two good shifts: the Stepan's integer itself and the shift by one position to the right. The integer itself is 1001 and the remainder after dividing it by 5 equals 1. The shift by one position to the right equals to 1100 and the remainder after dividing it by 5 equals 0, which is the minimum possible remainder."}, "positive_code": [{"source_code": "import std.stdio, std.bigint, std.string;\n\nvoid main() {\n auto a_ = readln.strip;\n auto n = a_.length;\n auto a = BigInt(a_);\n // auto b = BigInt(readln.strip);\n long b;\n scanf(\"%ld\", &b);\n auto ans = a % b;\n auto pow10n = 1; for (int i=0; i 100) {\n writeln(b);\n writeln(a);\n }\n auto ans = a % b;\n auto pow10n = 1; for (int i=0; i 100) {\n writeln(a);\n writeln(b);\n }\n auto ans = a % b;\n // auto pow10n = (BigInt(10) ^^ n);\n auto pow10n = 1;\n for (int i=0; i 0) {\n ans ~= c;\n int tmp = 1;\n while (N - tmp >= 0) {\n N -= tmp;\n ans ~= c;\n tmp += 1;\n }\n c += 1;\n }\n\n ans.writeln;\n}\n"}, {"source_code": "module main;\n__gshared:\nimport core.bitop, std.algorithm, std.bigint, std.bitmanip, std.complex,\n\tstd.container, std.conv, std.datetime, std.functional, std.math, std.meta,\n\tstd.numeric, std.parallelism, std.random, std.range, std.regex, std.stdio,\n\tstd.string, std.traits, std.typecons, std.uni, std.variant;\n\nalias pair(X, Y) = Tuple!(X, \"fi\", Y, \"se\");\nalias mp = make_pair;\nalias pii = pair!(int, int);\nalias pll = pair!(long, long);\nalias gcd = std.numeric.gcd;\nalias lint = long;\nalias rbt = RedBlackTree;\n///modulo\nenum mod = 10 ^^ 9 + 7, mod2 = mod + 2;\npublic\n{\n\tpure nothrow\n\t{\n\t\t///lcm\n\t\tT lcm(T)(auto ref T a, auto ref T b)\n\t\t{\n\t\t\treturn a / gcd(a, b) * b;\n\t\t}\n\t\t///make_pair\n\t\tpair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)\n\t\t{\n\t\t\treturn tuple!(X, \"fi\", Y, \"se\")(x_, y_);\n\t\t}\n\t\t///BigInt greatest common divizor\n\t\tBigInt gcd(BigInt a, BigInt b)\n\t\t{\n\t\t\twhile (b)\n\t\t\t{\n\t\t\t\ta %= b;\n\t\t\t\tswap(a, b);\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\t\t///square\n\t\t@property X sqr(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_;\n\t\t}\n\t\t///cube\n\t\t@property X cub(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_ * a_;\n\t\t}\n\t\t///integer size\n\t\tint sz(T)(T a) if (hasLength!T)\n\t\t{\n\t\t\treturn cast(int) a.length;\n\t\t}\n\t\t///posicion lower bound\n\t\tsize_t lowb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\tsize_t l = 0, r = a.length;\n\t\t\twhile (r - l > 1)\n\t\t\t{\n\t\t\t\tauto m = (l + r) >> 1;\n\t\t\t\tif (!(a[m] < g))\n\t\t\t\t\tr = m;\n\t\t\t\telse\n\t\t\t\t\tl = m;\n\t\t\t}\n\t\t\treturn (!(a[l] < g)) ? l : r;\n\t\t}\n\t\t///posicion upper bound\n\t\tsize_t upb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\tsize_t l = 0, r = a.length;\n\t\t\twhile (r - l > 1)\n\t\t\t{\n\t\t\t\tauto m = (l + r) >> 1;\n\t\t\t\tif (g < a[m])\n\t\t\t\t\tr = m;\n\t\t\t\telse\n\t\t\t\t\tl = m;\n\t\t\t}\n\t\t\treturn (g < a[l]) ? l : r;\n\t\t}\n\t\t///posicion binary search\n\t\tsize_t binf(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\tauto pos = lowb(a, g);\n\t\t\treturn (g == a[pos]) ? pos : a.length;\n\t\t}\n\t\t///binary search\n\t\tbool binary_search(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn binf(a, g) != a.length;\n\t\t}\n\t}\n\t///write an array\n\tvoid putarr(X)(in X a, in char ch = ' ') if (isInputRange!X)\n\t{\n\t\twritefln(\"%(%s\" ~ ch ~ \"%)\", a);\n\t}\n\t///write a matrix\n\tvoid putarr(X)(in X a)\n\t\t\tif (isInputRange!X && isInputRange!(ElementType!X) && !isSomeString!(ElementType!X))\n\t{\n\t\twritefln(\"%(%(%s %)\\n%)\", a);\n\t}\n\t///get an array\n\tbool getarr(X)(X a, in size_t n)\n\t{\n\t\tbool b = 1;\n\t\tforeach (ref i; a[0 .. n])\n\t\t\tb = input(&i);\n\t\treturn b;\n\t}\n\t///read without format\n\tbool input(T...)(ref T ptrs) if (ptrs.length > 0)\n\t{\n\t\tsize_t s = 0;\n\t\tforeach (ref e; ptrs)\n\t\t{\n\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\ts += readf(\" %c\", &e);\n\t\t\telse\n\t\t\t\ts += readf(\" %s\", &e);\n\t\t}\n\t\treturn s == ptrs.length;\n\t}\n\t///readln without format\n\tbool read(T...)(ref T ptrs) if (ptrs.length > 0)\n\t{\n\t\tsize_t s = 0;\n\t\tforeach (ref e; ptrs)\n\t\t{\n\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\ts += readf(\" %c\", &e);\n\t\t\telse\n\t\t\t\ts += readf(\" %s\", &e);\n\t\t}\n\t\treadln;\n\t\treturn s == ptrs.length;\n\t}\n\t///opening file\n\tnothrow auto inf(in char* name)\n\t{\n\t\treturn freopen(name, \"r\", core.stdc.stdio.stdin);\n\t}\n\t///closing file\n\tnothrow auto ouf(in char* name)\n\t{\n\t\treturn freopen(name, \"w\", core.stdc.stdio.stdout);\n\t}\n\t///parsing array from line\n\t@property auto arread(T)()\n\t{\n\t\treturn readln.splitter.map!(to!(T)).array;\n\t}\n\t///outbuffer\n\tvoid enter(T...)(T args)\n\t{\n\t\twriteln(args);\n\t\tstdout.flush;\n\t}\n}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\n\nvoid main()\n{\n\tversion (home)\n\t{\n\t\tfreopen(\"input.txt\", \"r\", core.stdc.stdio.stdin);\n\t\t//freopen(\"output.txt\", \"w\", core.stdc.stdio.stdout);\n\t\t/*StopWatch sw;\n\t\tsw.start;\n\t\tscope (exit)\n\t\t{\n\t\t\tsw.stop;\n\t\t\tstderr.writefln(\"\\nTime: %d ms\", sw.peek.msecs);\n\t\t}*/\n\t}\n\tint k;\n\tloop: while (read(k))\n\t{\n\t\tforeach (ch; 'a' .. 'z' + 1)\n\t\t{\n\t\t\tint i;\n\t\t\twhile (i * (i + 1) / 2 <= k)\n\t\t\t\ti++;\n\t\t\tk -= i * (i - 1) / 2;\n\t\t\tforeach (_; 0 .. i)\n\t\t\t{\n\t\t\t\twrite(cast(char) ch);\n\t\t\t}\n\t\t}\n\t\twriteln;\n\t}\n}\n"}, {"source_code": "/+ dub.sdl:\n name \"A\"\n dependency \"dcomp\" version=\">=0.6.0\"\n+/\n\nimport std.stdio, std.algorithm, std.range, std.conv;\n// import dcomp.foundation, dcomp.scanner;\n\nint main() {\n auto sc = new Scanner(stdin);\n int k;\n sc.read(k); k *= 2;\n if (k == 0) {\n writeln(\"miku\");\n return 0;\n }\n string s;\n char nw = 'a';\n while (k) {\n foreach (i; 1..1000) {\n if (k < (i+1)*(i)) {\n k -= i*(i-1);\n s ~= nw.repeat.take(i).array;\n nw++;\n break;\n }\n }\n }\n writeln(s);\n return 0;\n}\n/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/foundation.d */\n// module dcomp.foundation;\n \nstatic if (__VERSION__ <= 2070) {\n template fold(fun...) if (fun.length >= 1) {\n auto fold(R, S...)(R r, S seed) {\n import std.algorithm : reduce;\n static if (S.length < 2) {\n return reduce!fun(seed, r);\n } else {\n import std.typecons : tuple;\n return reduce!fun(tuple(seed), r);\n }\n }\n }\n \n}\nversion (X86) static if (__VERSION__ < 2071) {\n import core.bitop : bsf, bsr, popcnt;\n int bsf(ulong v) {\n foreach (i; 0..64) {\n if (v & (1UL << i)) return i;\n }\n return -1;\n }\n int bsr(ulong v) {\n foreach_reverse (i; 0..64) {\n if (v & (1UL << i)) return i;\n }\n return -1; \n }\n int popcnt(ulong v) {\n int c = 0;\n foreach (i; 0..64) {\n if (v & (1UL << i)) c++;\n }\n return c;\n }\n}\n/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/scanner.d */\n// module dcomp.scanner;\n\n \nclass Scanner {\n import std.stdio : File;\n import std.conv : to;\n import std.range : front, popFront, array, ElementType;\n import std.array : split;\n import std.traits : isSomeChar, isStaticArray, isArray; \n import std.algorithm : map;\n File f;\n this(File f) {\n this.f = f;\n }\n char[512] lineBuf;\n char[] line;\n private bool succ() {\n import std.range.primitives : empty, front, popFront;\n import std.ascii : isWhite;\n while (true) {\n while (!line.empty && line.front.isWhite) {\n line.popFront;\n }\n if (!line.empty) break;\n if (f.eof) return false;\n line = lineBuf[];\n f.readln(line);\n }\n return true;\n }\n\n private bool readSingle(T)(ref T x) {\n import std.algorithm : findSplitBefore;\n import std.string : strip;\n import std.conv : parse;\n if (!succ()) return false;\n static if (isArray!T) {\n alias E = ElementType!T;\n static if (isSomeChar!E) {\n \n \n auto r = line.findSplitBefore(\" \");\n x = r[0].strip.dup;\n line = r[1];\n } else {\n auto buf = line.split.map!(to!E).array;\n static if (isStaticArray!T) {\n \n assert(buf.length == T.length);\n }\n x = buf;\n line.length = 0;\n }\n } else {\n x = line.parse!T;\n }\n return true;\n }\n int read(T, Args...)(ref T x, auto ref Args args) {\n if (!readSingle(x)) return 0;\n static if (args.length == 0) {\n return 1;\n } else {\n return 1 + read(args);\n }\n }\n}\n\n\n \n \n\n \n"}, {"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nimmutable int limit = 1003;\n\nvoid main ()\n{\n\tauto f = new int [limit];\n\tf[0] = 0;\n\tf[1] = 0;\n\tforeach (j; 2..limit)\n\t{\n\t\tf[j] = int.max;\n\t\tforeach (k; 1..j)\n\t\t{\n\t\t\tf[j] = min (f[j], f[k] + f[j - k] + k * (j - k));\n\t\t}\n\t}\n\tdebug\n\t{\n\t\tforeach (j; 0..limit)\n\t\t{\n\t\t\twritefln (\"%6s: %6s\", j, f[j]);\n\t\t}\n\t}\n\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tstring res;\n\t\tforeach (c; 'a'..'p')\n\t\t{\n\t\t\tint len = 0;\n\t\t\twhile (f[len + 1] <= n)\n\t\t\t{\n\t\t\t\tlen += 1;\n\t\t\t}\n\t\t\tn -= f[len];\n\t\t\tforeach (i; 0..len)\n\t\t\t{\n\t\t\t\tres ~= c;\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nenum LIM = 10^^5 + 5;\n\nvoid main() {\n auto prev = new int[LIM];\n prev[] = -1;\n prev[0] = 0;\n foreach (i; 0 .. 3) {\n foreach_reverse (x; 0 .. LIM) {\n if (prev[x] != -1) {\n for (int a = 2; x + a * (a - 1) / 2 < LIM; ++a) {\n const xx = x + a * (a - 1) / 2;\n if (prev[xx] == -1) {\n prev[xx] = a;\n }\n }\n }\n }\n }\n foreach (x; 0 .. LIM) {\n assert(prev[x] != -1);\n }\n \n try {\n for (; ; ) {\n const K = readInt();\n \n int[] as;\n as ~= 1;\n for (int x = K; x > 0; ) {\n const a = prev[x];\n as ~= a;\n x -= a * (a - 1) / 2;\n }\n \n string ans;\n foreach (i, a; as) {\n ans ~= (cast(char)('a' + i)).repeat(a).array;\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop;\n\n\nvoid main() {\n auto N = readln.chomp.to!int;\n\n string ans = \"\";\n char c = 'a';\n\n while (N > 0) {\n ans ~= c;\n int tmp = 1;\n while (N - tmp >= 0) {\n N -= tmp;\n ans ~= c;\n tmp += 1;\n }\n c += 1;\n }\n\n ans.writeln;\n}\n"}, {"source_code": "module main;\n__gshared:\nimport core.bitop, std.algorithm, std.bigint, std.bitmanip, std.complex,\n\tstd.container, std.conv, std.datetime, std.functional, std.math, std.meta,\n\tstd.numeric, std.parallelism, std.random, std.range, std.regex, std.stdio,\n\tstd.string, std.traits, std.typecons, std.uni, std.variant;\n\nalias pair(X, Y) = Tuple!(X, \"fi\", Y, \"se\");\nalias mp = make_pair;\nalias pii = pair!(int, int);\nalias pll = pair!(long, long);\nalias gcd = std.numeric.gcd;\nalias lint = long;\nalias rbt = RedBlackTree;\n///modulo\nenum mod = 10 ^^ 9 + 7, mod2 = mod + 2;\npublic\n{\n\tpure nothrow\n\t{\n\t\t///lcm\n\t\tT lcm(T)(auto ref T a, auto ref T b)\n\t\t{\n\t\t\treturn a / gcd(a, b) * b;\n\t\t}\n\t\t///make_pair\n\t\tpair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)\n\t\t{\n\t\t\treturn tuple!(X, \"fi\", Y, \"se\")(x_, y_);\n\t\t}\n\t\t///BigInt greatest common divizor\n\t\tBigInt gcd(BigInt a, BigInt b)\n\t\t{\n\t\t\twhile (b)\n\t\t\t{\n\t\t\t\ta %= b;\n\t\t\t\tswap(a, b);\n\t\t\t}\n\t\t\treturn a;\n\t\t}\n\t\t///square\n\t\t@property X sqr(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_;\n\t\t}\n\t\t///cube\n\t\t@property X cub(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_ * a_;\n\t\t}\n\t\t///integer size\n\t\tint sz(T)(T a) if (hasLength!T)\n\t\t{\n\t\t\treturn cast(int) a.length;\n\t\t}\n\t\t///posicion lower bound\n\t\tsize_t lowb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\tsize_t l = 0, r = a.length;\n\t\t\twhile (r - l > 1)\n\t\t\t{\n\t\t\t\tauto m = (l + r) >> 1;\n\t\t\t\tif (!(a[m] < g))\n\t\t\t\t\tr = m;\n\t\t\t\telse\n\t\t\t\t\tl = m;\n\t\t\t}\n\t\t\treturn (!(a[l] < g)) ? l : r;\n\t\t}\n\t\t///posicion upper bound\n\t\tsize_t upb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\tsize_t l = 0, r = a.length;\n\t\t\twhile (r - l > 1)\n\t\t\t{\n\t\t\t\tauto m = (l + r) >> 1;\n\t\t\t\tif (g < a[m])\n\t\t\t\t\tr = m;\n\t\t\t\telse\n\t\t\t\t\tl = m;\n\t\t\t}\n\t\t\treturn (g < a[l]) ? l : r;\n\t\t}\n\t\t///posicion binary search\n\t\tsize_t binf(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\tauto pos = lowb(a, g);\n\t\t\treturn (g == a[pos]) ? pos : a.length;\n\t\t}\n\t\t///binary search\n\t\tbool binary_search(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn binf(a, g) != a.length;\n\t\t}\n\t}\n\t///write an array\n\tvoid putarr(X)(in X a, in char ch = ' ') if (isInputRange!X)\n\t{\n\t\twritefln(\"%(%s\" ~ ch ~ \"%)\", a);\n\t}\n\t///write a matrix\n\tvoid putarr(X)(in X a)\n\t\t\tif (isInputRange!X && isInputRange!(ElementType!X) && !isSomeString!(ElementType!X))\n\t{\n\t\twritefln(\"%(%(%s %)\\n%)\", a);\n\t}\n\t///get an array\n\tbool getarr(X)(X a, in size_t n)\n\t{\n\t\tbool b = 1;\n\t\tforeach (ref i; a[0 .. n])\n\t\t\tb = input(&i);\n\t\treturn b;\n\t}\n\t///read without format\n\tbool input(T...)(ref T ptrs) if (ptrs.length > 0)\n\t{\n\t\tsize_t s = 0;\n\t\tforeach (ref e; ptrs)\n\t\t{\n\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\ts += readf(\" %c\", &e);\n\t\t\telse\n\t\t\t\ts += readf(\" %s\", &e);\n\t\t}\n\t\treturn s == ptrs.length;\n\t}\n\t///readln without format\n\tbool read(T...)(ref T ptrs) if (ptrs.length > 0)\n\t{\n\t\tsize_t s = 0;\n\t\tforeach (ref e; ptrs)\n\t\t{\n\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\ts += readf(\" %c\", &e);\n\t\t\telse\n\t\t\t\ts += readf(\" %s\", &e);\n\t\t}\n\t\treadln;\n\t\treturn s == ptrs.length;\n\t}\n\t///opening file\n\tnothrow auto inf(in char* name)\n\t{\n\t\treturn freopen(name, \"r\", core.stdc.stdio.stdin);\n\t}\n\t///closing file\n\tnothrow auto ouf(in char* name)\n\t{\n\t\treturn freopen(name, \"w\", core.stdc.stdio.stdout);\n\t}\n\t///parsing array from line\n\t@property auto arread(T)()\n\t{\n\t\treturn readln.splitter.map!(to!(T)).array;\n\t}\n\t///outbuffer\n\tvoid enter(T...)(T args)\n\t{\n\t\twriteln(args);\n\t\tstdout.flush;\n\t}\n}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\n\nvoid main()\n{\n\tversion (home)\n\t{\n\t\tfreopen(\"input.txt\", \"r\", core.stdc.stdio.stdin);\n\t\t//freopen(\"output.txt\", \"w\", core.stdc.stdio.stdout);\n\t\t/*StopWatch sw;\n\t\tsw.start;\n\t\tscope (exit)\n\t\t{\n\t\t\tsw.stop;\n\t\t\tstderr.writefln(\"\\nTime: %d ms\", sw.peek.msecs);\n\t\t}*/\n\t}\n\tint k;\n\tloop: while (read(k))\n\t{\n\t\tforeach (ch; 'a' .. 'z' + 1)\n\t\t{\n\t\t\tint i = 1;\n\t\t\twhile (i * (i - 1) / 2 <= k)\n\t\t\t\ti++;\n\t\t\tk -= i * (i - 1) / 2;\n\t\t\tforeach (_; 0 .. i - 1)\n\t\t\t{\n\t\t\t\twrite(cast(char) ch);\n\t\t\t}\n\t\t}\n\t\twriteln;\n\t}\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nenum LIM = 10^^5 + 5;\n\nvoid main() {\n auto prev = new int[LIM];\n prev[] = -1;\n prev[0] = 0;\n foreach (i; 0 .. 3) {\n foreach_reverse (x; 0 .. LIM) {\n if (prev[x] != -1) {\n for (int a = 2; x + a * (a - 1) / 2 < LIM; ++a) {\n const xx = x + a * (a - 1) / 2;\n if (prev[xx] == -1) {\n prev[xx] = a;\n }\n }\n }\n }\n }\n foreach (x; 0 .. LIM) {\n assert(prev[x] != -1);\n }\n \n try {\n for (; ; ) {\n const K = readInt();\n \n int[] as;\n for (int x = K; x > 0; ) {\n const a = prev[x];\n as ~= a;\n x -= a * (a - 1) / 2;\n }\n \n string ans;\n foreach (i, a; as) {\n ans ~= (cast(char)('a' + i)).repeat(a).array;\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "b991c064562704b6106a6ff2a297e64a"} {"nl": {"description": "A string $$$s$$$ of length $$$n$$$ can be encrypted by the following algorithm: iterate over all divisors of $$$n$$$ in decreasing order (i.e. from $$$n$$$ to $$$1$$$), for each divisor $$$d$$$, reverse the substring $$$s[1 \\dots d]$$$ (i.e. the substring which starts at position $$$1$$$ and ends at position $$$d$$$). For example, the above algorithm applied to the string $$$s$$$=\"codeforces\" leads to the following changes: \"codeforces\" $$$\\to$$$ \"secrofedoc\" $$$\\to$$$ \"orcesfedoc\" $$$\\to$$$ \"rocesfedoc\" $$$\\to$$$ \"rocesfedoc\" (obviously, the last reverse operation doesn't change the string because $$$d=1$$$).You are given the encrypted string $$$t$$$. Your task is to decrypt this string, i.e., to find a string $$$s$$$ such that the above algorithm results in string $$$t$$$. It can be proven that this string $$$s$$$ always exists and is unique.", "input_spec": "The first line of input consists of a single integer $$$n$$$ ($$$1 \\le n \\le 100$$$) \u2014 the length of the string $$$t$$$. The second line of input consists of the string $$$t$$$. The length of $$$t$$$ is $$$n$$$, and it consists only of lowercase Latin letters.", "output_spec": "Print a string $$$s$$$ such that the above algorithm results in $$$t$$$.", "sample_inputs": ["10\nrocesfedoc", "16\nplmaetwoxesisiht", "1\nz"], "sample_outputs": ["codeforces", "thisisexampletwo", "z"], "notes": "NoteThe first example is described in the problem statement."}, "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n readln;\n \n auto s = readln.chomp.map!(to!dchar).array;\n \n foreach (i; 2..(s.length+1)) {\n if (s.length % i != 0) continue;\n \n s = s[0..i].retro.array ~ s[i..$];\n }\n \n s.writeln;\n}"}], "negative_code": [], "src_uid": "1b0b2ee44c63cb0634cb63f2ad65cdd3"} {"nl": {"description": "Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of n vertices numbered from 0 to n\u2009-\u20091. For all 0\u2009\u2264\u2009u\u2009<\u2009v\u2009<\u2009n, vertex u and vertex v are connected with an undirected edge that has weight (where is the bitwise-xor operation). Can you find the weight of the minimum spanning tree of that graph?You can read about complete graphs in https://en.wikipedia.org/wiki/Complete_graphYou can read about the minimum spanning tree in https://en.wikipedia.org/wiki/Minimum_spanning_treeThe weight of the minimum spanning tree is the sum of the weights on the edges included in it.", "input_spec": "The only line contains an integer n (2\u2009\u2264\u2009n\u2009\u2264\u20091012), the number of vertices in the graph.", "output_spec": "The only line contains an integer x, the weight of the graph's minimum spanning tree.", "sample_inputs": ["4"], "sample_outputs": ["4"], "notes": "NoteIn the first sample: The weight of the minimum spanning tree is 1+2+1=4."}, "positive_code": [{"source_code": "import std.algorithm, std.conv, std.range, std.stdio, std.string;\n\nvoid readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}\nvoid readA(T)(size_t n,ref T t){t=new T(n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(ElementType!T);r.popFront;}}\nvoid readM(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=readln.splitter;foreach(ref v;t){v[i]=r.front.to!(ElementType!(typeof(v)));r.popFront;}}}\nvoid readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=readln.splitter;foreach(ref j;v.tupleof){j=r.front.to!(typeof(j));r.popFront;}}}\n\nvoid main()\n{\n long n; readV(n);\n\n auto s = 0L, i = 0;\n while (n > 1) {\n s += n/2 * 2L^^(i++);\n n = n/2+n%2;\n }\n\n writeln(s);\n}\n"}], "negative_code": [{"source_code": "import std.algorithm, std.conv, std.range, std.stdio, std.string;\n\nvoid readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}\nvoid readA(T)(size_t n,ref T t){t=new T(n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(ElementType!T);r.popFront;}}\nvoid readM(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=readln.splitter;foreach(ref v;t){v[i]=r.front.to!(ElementType!(typeof(v)));r.popFront;}}}\nvoid readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=readln.splitter;foreach(ref j;v.tupleof){j=r.front.to!(typeof(j));r.popFront;}}}\n\nvoid main()\n{\n long n; readV(n);\n\n auto s = 0L, i = 0;\n while (n > 1) {\n s += n/2 * 2^^(i++);\n n = n/2+n%2;\n }\n\n writeln(s);\n}\n"}], "src_uid": "a98f0d924ea52cafe0048f213f075891"} {"nl": {"description": "Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards...There are four guardposts in Dima's dorm. Each post contains two guards (in Russia they are usually elderly women). You can bribe a guard by a chocolate bar or a box of juice. For each guard you know the minimum price of the chocolate bar she can accept as a gift and the minimum price of the box of juice she can accept as a gift. If a chocolate bar for some guard costs less than the minimum chocolate bar price for this guard is, or if a box of juice for some guard costs less than the minimum box of juice price for this guard is, then the guard doesn't accept such a gift.In order to pass through a guardpost, one needs to bribe both guards.The shop has an unlimited amount of juice and chocolate of any price starting with 1. Dima wants to choose some guardpost, buy one gift for each guard from the guardpost and spend exactly n rubles on it.Help him choose a post through which he can safely sneak Inna or otherwise say that this is impossible. Mind you, Inna would be very sorry to hear that!", "input_spec": "The first line of the input contains integer n\u00a0(1\u2009\u2264\u2009n\u2009\u2264\u2009105) \u2014 the money Dima wants to spend. Then follow four lines describing the guardposts. Each line contains four integers a,\u2009b,\u2009c,\u2009d\u00a0(1\u2009\u2264\u2009a,\u2009b,\u2009c,\u2009d\u2009\u2264\u2009105) \u2014 the minimum price of the chocolate and the minimum price of the juice for the first guard and the minimum price of the chocolate and the minimum price of the juice for the second guard, correspondingly.", "output_spec": "In a single line of the output print three space-separated integers: the number of the guardpost, the cost of the first present and the cost of the second present. If there is no guardpost Dima can sneak Inna through at such conditions, print -1 in a single line. The guardposts are numbered from 1 to 4 according to the order given in the input. If there are multiple solutions, you can print any of them.", "sample_inputs": ["10\n5 6 5 6\n6 6 7 7\n5 8 6 6\n9 9 9 9", "10\n6 6 6 6\n7 7 7 7\n4 4 4 4\n8 8 8 8", "5\n3 3 3 3\n3 3 3 3\n3 3 3 3\n3 3 3 3"], "sample_outputs": ["1 5 5", "3 4 6", "-1"], "notes": "NoteExplanation of the first example.The only way to spend 10 rubles to buy the gifts that won't be less than the minimum prices is to buy two 5 ruble chocolates to both guards from the first guardpost.Explanation of the second example.Dima needs 12 rubles for the first guardpost, 14 for the second one, 16 for the fourth one. So the only guardpost we can sneak through is the third one. So, Dima can buy 4 ruble chocolate for the first guard and 6 ruble juice of the second guard."}, "positive_code": [{"source_code": "import std.stdio;\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n \n //writeln(\"%s\", \n int n;\n readf(\" %s\", &n);\n foreach (k; 1..5) {\n int[4] gs;\n readf(\" %s %s %s %s\", &gs[0], &gs[1], &gs[2], &gs[3]);\n foreach (i; 0..2) {\n foreach (j; 2..4) {\n if (gs[i] + gs[j] <= n) {\n writefln(\"%s %s %s\", k, gs[i], n - gs[i]);\n return 0;\n }\n }\n }\n }\n writeln(\"-1\");\n\n return 0;\n}\n"}, {"source_code": "import std.stdio;\n\nvoid main() {\n debug stdin = File(\"input.txt\", \"r\");\n\n int n;\n readf(\" %s\", &n);\n foreach (i; 0 .. 4) {\n int[] a = new int[2];\n int[] b = new int[2];\n readf(\" %s %s %s %s\", &a[0], &a[1], &b[0], &b[1]);\n foreach (j; 0 .. 2) {\n foreach (k; 0 .. 2) {\n if (a[j] + b[k] <= n) {\n writeln(i + 1, \" \", n - b[k], \" \", b[k]);\n return;\n }\n }\n }\n }\n\n writeln(-1);\n}\n"}], "negative_code": [], "src_uid": "6e7ee0da980beb99ca49a5ddd04089a5"} {"nl": {"description": "Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.Yakko thrown a die and got Y points, Wakko \u2014 W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.", "input_spec": "The only line of the input file contains two natural numbers Y and W \u2014 the results of Yakko's and Wakko's die rolls.", "output_spec": "Output the required probability in the form of irreducible fraction in format \u00abA/B\u00bb, where A \u2014 the numerator, and B \u2014 the denominator. If the required probability equals to zero, output \u00ab0/1\u00bb. If the required probability equals to 1, output \u00ab1/1\u00bb. ", "sample_inputs": ["4 2"], "sample_outputs": ["1/2"], "notes": "NoteDot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points."}, "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm;\n\nstring getMessage(int bigger) {\n final switch (bigger) {\n case 1:\n return \"1/1\";\n case 2:\n return \"5/6\";\n case 3:\n return \"2/3\";\n case 4:\n return \"1/2\";\n case 5:\n return \"1/3\";\n case 6:\n return \"1/6\";\n }\n}\n\nvoid main() {\n int a, b;\n readf(\"%d %d\", &a, &b);\n writeln(getMessage(max(a, b)));\n}\n"}], "negative_code": [], "src_uid": "f97eb4ecffb6cbc8679f0c621fd59414"} {"nl": {"description": "Alice and Bob are playing a game with a string of characters, with Alice going first. The string consists n characters, each of which is one of the first k letters of the alphabet. On a player\u2019s turn, they can either arbitrarily permute the characters in the words, or delete exactly one character in the word (if there is at least one character). In addition, their resulting word cannot have appeared before throughout the entire game. The player unable to make a valid move loses the game.Given n,\u2009k,\u2009p, find the number of words with exactly n characters consisting of the first k letters of the alphabet such that Alice will win if both Alice and Bob play optimally. Return this number modulo the prime number p.", "input_spec": "The first line of input will contain three integers n,\u2009k,\u2009p (1\u2009\u2264\u2009n\u2009\u2264\u2009250\u2009000, 1\u2009\u2264\u2009k\u2009\u2264\u200926, 108\u2009\u2264\u2009p\u2009\u2264\u2009109\u2009+\u2009100, p will be prime).", "output_spec": "Print a single integer, the number of winning words for Alice, modulo p.", "sample_inputs": ["4 2 100000007"], "sample_outputs": ["14"], "notes": "NoteThere are 14 strings that that Alice can win with. For example, some strings are \"bbaa\" and \"baaa\". Alice will lose on strings like \"aaaa\" or \"bbbb\"."}, "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nstruct ModInt {\n static int M;\n int x;\n this(ModInt a) { x = a.x; }\n this(long a) { x = cast(int)(a % M); if (x < 0) x += M; }\n ref ModInt opAssign(long a) { return (this = ModInt(a)); }\n ref ModInt opOpAssign(string op)(ModInt a) {\n static if (op == \"+\") { x += a.x; if (x >= M) x -= M; }\n else static if (op == \"-\") { x -= a.x; if (x < 0) x += M; }\n else static if (op == \"*\") { x = cast(int)((cast(long)(x) * a.x) % M); }\n else static if (op == \"/\") { this *= a.inv(); }\n else static assert(false);\n return this;\n }\n ref ModInt opOpAssign(string op)(long a) {\n static if (op == \"^^\") {\n ModInt t2 = this, te = ModInt(1);\n for (long e = a; e; e >>= 1) {\n if (e & 1) te *= t2;\n t2 *= t2;\n }\n x = cast(int)(te.x);\n return this;\n } else return mixin(\"this \" ~ op ~ \"= ModInt(a)\");\n }\n ModInt inv() const {\n int a = x, b = M, y = 1, z = 0, t;\n for (; ; ) {\n t = a / b; a -= t * b;\n if (a == 0) {\n assert(b == 1 || b == -1);\n return ModInt(b * z);\n }\n y -= t * z;\n t = b / a; b -= t * a;\n if (b == 0) {\n assert(a == 1 || a == -1);\n return ModInt(a * y);\n }\n z -= t * y;\n }\n }\n ModInt opUnary(string op)() const if (op == \"-\") { return ModInt(-x); }\n ModInt opBinary(string op, T)(T a) const { return mixin(\"ModInt(this) \" ~ op ~ \"= a\"); }\n ModInt opBinaryRight(string op)(long a) const { return mixin(\"ModInt(a) \" ~ op ~ \"= this\"); }\n string toString() const { return x.to!string; }\n}\n\nalias Mint = ModInt;\n\nenum LIM = 250_010;\nMint[] inv, fac, invFac;\nvoid prepare() {\n inv = new Mint[LIM];\n fac = new Mint[LIM];\n invFac = new Mint[LIM];\n inv[1] = 1;\n foreach (i; 2 .. LIM) {\n inv[i] = -(Mint.M / i) * inv[cast(size_t)(Mint.M % i)];\n }\n fac[0] = invFac[0] = 1;\n foreach (i; 1 .. LIM) {\n fac[i] = fac[i - 1] * i;\n invFac[i] = invFac[i - 1] * inv[i];\n }\n}\nMint binom(long n, long k) {\n if (0 <= k && k <= n) {\n assert(n < LIM);\n return fac[cast(size_t)(n)] * invFac[cast(size_t)(k)] * invFac[cast(size_t)(n - k)];\n } else {\n return Mint(0);\n }\n}\n\n\nT[][] zeta(T)(const(T[]) as) {\n const n = bsr(as.length);\n assert(as.length == 1 << n, \"zeta: |as| = 2^n must hold\");\n auto zas = new T[][](n + 1, 1 << n);\n foreach (h; 0 .. 1 << n) zas[popcnt(h)][h] = as[h];\n foreach (k; 0 .. n + 1) foreach (i; 0 .. n) foreach (h; 0 .. 1 << n) {\n if (!(h & 1 << i)) zas[k][h | 1 << i] += zas[k][h];\n }\n return zas;\n}\n\n// Modifies zas\nT[] moebius(T)(T[][] zas) {\n const n = cast(int)(zas.length) - 1;\n foreach (k; 0 .. n + 1) foreach (i; 0 .. n) foreach (h; 0 .. 1 << n) {\n if (!(h & 1 << i)) zas[k][h | 1 << i] -= zas[k][h];\n }\n auto as = new T[1 << n];\n foreach (h; 0 .. 1 << n) as[h] = zas[popcnt(h)][h];\n return as;\n}\n\nMint[] subsetMul(const(Mint[]) as, const(Mint[]) bs) {\n const n = bsr(as.length);\n assert(as.length == 1 << n, \"subsetMul: |as| = 2^n must hold\");\n assert(bs.length == 1 << n, \"subsetMul: |bs| = 2^n must hold\");\n const zas = zeta(as);\n const zbs = zeta(bs);\n auto zcs = new Mint[][](n + 1, 1 << n);\n foreach (k; 0 .. n + 1) foreach (l; 0 .. n - k + 1) foreach (h; 0 .. 1 << n) {\n zcs[k + l][h] += zas[k][h] * zbs[l][h];\n }\n return moebius(zcs);\n}\n\n// Needs inv[1], ..., inv[n]\nMint[] subsetExp(const(Mint[]) as) {\n const n = bsr(as.length);\n assert(as.length == 1 << n, \"subsetExp: |as| = 2^n must hold\");\n assert(as[0].x == 0, \"subsetExp: as[0] = 1 must hold\");\n foreach (k; 1 .. n + 1) {\n assert((k * inv[k]).x == 1, \"subsetExp: inv must be prepared\");\n }\n const zas = zeta(as);\n auto zbs = new Mint[][](n + 1, 1 << n);\n zbs[0][] = Mint(1);\n foreach (h; 0 .. 1 << n) foreach (k; 1 .. n + 1) {\n Mint sum;\n foreach (l; 1 .. k + 1) sum += l * zas[l][h] * zbs[k - l][h];\n zbs[k][h] = inv[k] * sum;\n }\n return moebius(zbs);\n}\n\n// Needs inv[1], ..., inv[n]\nMint[] subsetLog(const(Mint[]) as) {\n const n = bsr(as.length);\n assert(as.length == 1 << n, \"subsetLog: |as| = 2^n must hold\");\n assert(as[0].x == 1, \"subsetLog: as[0] = 1 must hold\");\n foreach (k; 1 .. n + 1) {\n assert((k * inv[k]).x == 1, \"subsetLog: inv must be prepared\");\n }\n const zas = zeta(as);\n auto zbs = new Mint[][](n + 1, 1 << n);\n foreach (h; 0 .. 1 << n) foreach (k; 1 .. n + 1) {\n Mint sum;\n foreach (l; 1 .. k) sum += l * zas[k - l][h] * zbs[l][h];\n zbs[k][h] = zas[k][h] - inv[k] * sum;\n }\n return moebius(zbs);\n}\n\n// Needs inv[1], ..., inv[n]\nMint[] subsetPow(const(Mint[]) as, Mint e) {\n const n = bsr(as.length);\n assert(as.length == 1 << n, \"subsetPow: |as| = 2^n must hold\");\n assert(as[0].x == 1, \"subsetPow: as[0] = 1 must hold\");\n foreach (k; 1 .. n + 1) {\n assert((k * inv[k]).x == 1, \"subsetPow: inv must be prepared\");\n }\n const zas = zeta(as);\n auto zbs = new Mint[][](n + 1, 1 << n);\n auto fs = new Mint[n + 1], gs = new Mint[n + 1];\n zbs[0][] = Mint(1);\n foreach (h; 0 .. 1 << n) {\n fs[0] = 0;\n foreach (k; 1 .. n + 1) {\n Mint sum;\n foreach (l; 1 .. k) sum += l * zas[k - l][h] * fs[l];\n fs[k] = zas[k][h] - inv[k] * sum;\n }\n foreach (k; 1 .. n + 1) fs[k] *= e;\n foreach (k; 1 .. n + 1) {\n Mint sum;\n foreach (l; 1 .. k + 1) sum += l * fs[l] * zbs[k - l][h];\n zbs[k][h] = inv[k] * sum;\n }\n }\n return moebius(zbs);\n}\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n const K = readInt();\n const P = readInt();\n \n Mint.M = P;\n prepare;\n \n Mint ans = Mint(K)^^N;\n if (N % 2 == 0) {\n int[] es;\n foreach (e; 1 .. bsr(N) + 1) {\n if (N & 1 << e) {\n es ~= e;\n }\n }\n const esLen = cast(int)(es.length);\n auto sums = new int[1 << esLen];\n sums[0] = 0;\n foreach (u; 0 .. esLen) {\n foreach (h; 0 .. 1 << u) {\n sums[h | 1 << u] = sums[h] | 1 << es[u];\n }\n }\n auto as = new Mint[1 << esLen];\n foreach (h; 0 .. 1 << esLen) {\n as[h] = invFac[sums[h]];\n }\n const bs = subsetPow(as, Mint(K));\n ans -= fac[sums[$ - 1]] * bs[$ - 1];\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "97f737f59100babe5e45e1a82a1f7d99"} {"nl": {"description": "It is the easy version of the problem. The difference is that in this version, there are no nodes with already chosen colors.Theofanis is starving, and he wants to eat his favorite food, sheftalia. However, he should first finish his homework. Can you help him with this problem?You have a perfect binary tree of $$$2^k - 1$$$ nodes\u00a0\u2014 a binary tree where all vertices $$$i$$$ from $$$1$$$ to $$$2^{k - 1} - 1$$$ have exactly two children: vertices $$$2i$$$ and $$$2i + 1$$$. Vertices from $$$2^{k - 1}$$$ to $$$2^k - 1$$$ don't have any children. You want to color its vertices with the $$$6$$$ Rubik's cube colors (White, Green, Red, Blue, Orange and Yellow).Let's call a coloring good when all edges connect nodes with colors that are neighboring sides in the Rubik's cube. A picture of Rubik's cube and its 2D map. More formally: a white node can not be neighboring with white and yellow nodes; a yellow node can not be neighboring with white and yellow nodes; a green node can not be neighboring with green and blue nodes; a blue node can not be neighboring with green and blue nodes; a red node can not be neighboring with red and orange nodes; an orange node can not be neighboring with red and orange nodes; You want to calculate the number of the good colorings of the binary tree. Two colorings are considered different if at least one node is colored with a different color.The answer may be too large, so output the answer modulo $$$10^9+7$$$.", "input_spec": "The first and only line contains the integers $$$k$$$ ($$$1 \\le k \\le 60$$$)\u00a0\u2014 the number of levels in the perfect binary tree you need to color.", "output_spec": "Print one integer\u00a0\u2014 the number of the different colorings modulo $$$10^9+7$$$.", "sample_inputs": ["3", "14"], "sample_outputs": ["24576", "934234"], "notes": "NoteIn the picture below, you can see one of the correct colorings of the first example. "}, "positive_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nconst ll MOD = to!long(1e9) + 7L;\nll modexp(ll base, ll exp){\n ll x = base % MOD;\n ll y = exp;\n ll res = 1;\n while(y > 0){\n if(y & 1){\n res *= x; res %= MOD;\n }\n x *= x; x %= MOD;\n y >>= 1;\n }\n return res;\n}\n\nvoid solve(){\n ll k = scan;\n ll ex = 1;\n for(int i = 0; i < k; ++i) ex *= 2;\n ll res = 6;\n res *= modexp(4, ex-2);\n res %= MOD;\n writeln(res);\n}\n\nvoid main(){\n solve;\n}\n\n/************** ***** That's All Folks! ***** **************/\nimport std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math;\nstring[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}\nT[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }\nvoid show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, \"| \");} stderr.writeln; } }\nalias ll = long, tup = Tuple!(long, \"x\", long, \"y\");\n"}, {"source_code": "import std.stdio, std.algorithm, std.array, std.math, std.typecons, std.bigint, std.conv;\r\n \r\nvoid main()\r\n{\r\n int k;\r\n scanf(\"%d\", &k);\r\n long res1 = 2UL^^k - 2;\r\n BigInt n = 4;\r\n BigInt res2 = powmod(n, to!BigInt(res1), to!BigInt(10^^9 + 7));\r\n \r\n writeln((res2 * to!BigInt(6)) % (10^^9 + 7));\r\n}"}], "negative_code": [], "src_uid": "5144b9b281ea4087d8334d91c3c8bda4"} {"nl": {"description": "You are given an integer N. Consider all possible segments on the coordinate axis with endpoints at integer points with coordinates between 0 and N, inclusive; there will be of them.You want to draw these segments in several layers so that in each layer the segments don't overlap (they might touch at the endpoints though). You can not move the segments to a different location on the coordinate axis. Find the minimal number of layers you have to use for the given N.", "input_spec": "The only input line contains a single integer N (1\u2009\u2264\u2009N\u2009\u2264\u2009100).", "output_spec": "Output a single integer - the minimal number of layers required to draw the segments for the given N.", "sample_inputs": ["2", "3", "4"], "sample_outputs": ["2", "4", "6"], "notes": "NoteAs an example, here are the segments and their optimal arrangement into layers for N\u2009=\u20094. "}, "positive_code": [{"source_code": "import std.stdio, std.string, std.conv, std.algorithm, std.numeric;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\nimport std.ascii;\n\nvoid main() {\n int n;\n scan(n);\n\n int k = n/2;\n int ans = (n&1 ? (k+1)^^2 : k*(k+1));\n\n writeln(ans);\n}\n\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}"}], "negative_code": [], "src_uid": "f8af5dfcf841a7f105ac4c144eb51319"} {"nl": {"description": "Luke Skywalker got locked up in a rubbish shredder between two presses. R2D2 is already working on his rescue, but Luke needs to stay alive as long as possible. For simplicity we will assume that everything happens on a straight line, the presses are initially at coordinates 0 and L, and they move towards each other with speed v1 and v2, respectively. Luke has width d and is able to choose any position between the presses. Luke dies as soon as the distance between the presses is less than his width. Your task is to determine for how long Luke can stay alive.", "input_spec": "The first line of the input contains four integers d, L, v1, v2 (1\u2009\u2264\u2009d,\u2009L,\u2009v1,\u2009v2\u2009\u2264\u200910\u2009000,\u2009d\u2009<\u2009L)\u00a0\u2014 Luke's width, the initial position of the second press and the speed of the first and second presses, respectively.", "output_spec": "Print a single real value\u00a0\u2014 the maximum period of time Luke can stay alive for. Your answer will be considered correct if its absolute or relative error does not exceed 10\u2009-\u20096. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if .", "sample_inputs": ["2 6 2 2", "1 9 1 2"], "sample_outputs": ["1.00000000000000000000", "2.66666666666666650000"], "notes": "NoteIn the first sample Luke should stay exactly in the middle of the segment, that is at coordinates [2;4], as the presses move with the same speed.In the second sample he needs to occupy the position . In this case both presses move to his edges at the same time."}, "positive_code": [{"source_code": "module _template;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n\nstruct IO {\n string read_string() {\n while (tokens.empty) {\n tokens = readln.split;\n }\n auto token = tokens.front;\n tokens.popFront;\n return token;\n }\n \n int read_int() {\n return read_string.to!int;\n }\n\n double read_double() {\n return read_string.to!double;\n }\n string[] tokens;\n}\n\nvoid main() {\n IO cin;\n int t = 1;\n // int t = cin.read_int;\n while (t--) {\n double d = cin.read_double;\n double L = cin.read_double;\n double v1 = cin.read_double;\n double v2 = cin.read_double;\n\n double rel_vel = v1 + v2;\n double dist = L - d;\n writefln(\"%.*f\", 18, (dist) / (rel_vel));\n } \n}"}, {"source_code": "module _template;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n\nstruct IO {\n string read_string() {\n while (tokens.empty) {\n tokens = readln.split;\n }\n auto token = tokens.front;\n tokens.popFront;\n return token;\n }\n \n int read_int() {\n return read_string.to!int;\n }\n\n double read_double() {\n return read_string.to!double;\n }\n string[] tokens;\n}\n\nvoid main() {\n IO cin;\n int t = 1;\n // int t = cin.read_int;\n while (t--) {\n double d = cin.read_double;\n double L = cin.read_double;\n double v1 = cin.read_double;\n double v2 = cin.read_double;\n\n double rel_vel = v1 + v2 + 0.0;\n double dist = L - d - 0.0;\n writefln(\"%.*f\", 18, (dist) / (rel_vel));\n } \n}"}], "negative_code": [], "src_uid": "f34f3f974a21144b9f6e8615c41830f5"} {"nl": {"description": "You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done...You are given an array of integers. Sort it in non-descending order.", "input_spec": "The input consists of a single line of space-separated integers. The first number is n (1\u2009\u2264\u2009n\u2009\u2264\u200910) \u2014 the size of the array. The following n numbers are the elements of the array (1\u2009\u2264\u2009ai\u2009\u2264\u2009100).", "output_spec": "Output space-separated elements of the sorted array.", "sample_inputs": ["3 3 1 2"], "sample_outputs": ["1 2 3"], "notes": "NoteRemember, this is a very important feature, and you have to make sure the customers appreciate it!"}, "positive_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tauto a = readln.split.map !(to !(int)).array;\n\t\tsort (a);\n\t\tforeach (i; 0..1_000_000_000)\n\t\t{\n\t\t\tif (n == -1)\n\t\t\t{\n\t\t\t\tassert (false);\n\t\t\t}\n\t\t\tn ^= 2;\n\t\t}\n\t\twritefln (\"%(%s %)\", a);\n\t}\n}\n"}], "negative_code": [], "src_uid": "29e481abfa9ad1f18e6157c9e833f16e"} {"nl": {"description": "Our bear's forest has a checkered field. The checkered field is an n\u2009\u00d7\u2009n table, the rows are numbered from 1 to n from top to bottom, the columns are numbered from 1 to n from left to right. Let's denote a cell of the field on the intersection of row x and column y by record (x,\u2009y). Each cell of the field contains growing raspberry, at that, the cell (x,\u2009y) of the field contains x\u2009+\u2009y raspberry bushes.The bear came out to walk across the field. At the beginning of the walk his speed is (dx,\u2009dy). Then the bear spends exactly t seconds on the field. Each second the following takes place: Let's suppose that at the current moment the bear is in cell (x,\u2009y). First the bear eats the raspberry from all the bushes he has in the current cell. After the bear eats the raspberry from k bushes, he increases each component of his speed by k. In other words, if before eating the k bushes of raspberry his speed was (dx,\u2009dy), then after eating the berry his speed equals (dx\u2009+\u2009k,\u2009dy\u2009+\u2009k). Let's denote the current speed of the bear (dx,\u2009dy) (it was increased after the previous step). Then the bear moves from cell (x,\u2009y) to cell (((x\u2009+\u2009dx\u2009-\u20091)\u00a0mod\u00a0n)\u2009+\u20091,\u2009((y\u2009+\u2009dy\u2009-\u20091)\u00a0mod\u00a0n)\u2009+\u20091). Then one additional raspberry bush grows in each cell of the field. You task is to predict the bear's actions. Find the cell he ends up in if he starts from cell (sx,\u2009sy). Assume that each bush has infinitely much raspberry and the bear will never eat all of it.", "input_spec": "The first line of the input contains six space-separated integers: n, sx, sy, dx, dy, t (1\u2009\u2264\u2009n\u2009\u2264\u2009109;\u00a01\u2009\u2264\u2009sx,\u2009sy\u2009\u2264\u2009n;\u00a0\u2009-\u2009100\u2009\u2264\u2009dx,\u2009dy\u2009\u2264\u2009100;\u00a00\u2009\u2264\u2009t\u2009\u2264\u20091018).", "output_spec": "Print two integers \u2014 the coordinates of the cell the bear will end up in after t seconds.", "sample_inputs": ["5 1 2 0 1 2", "1 1 1 -1 -1 2"], "sample_outputs": ["3 1", "1 1"], "notes": "NoteOperation a\u00a0mod\u00a0b means taking the remainder after dividing a by b. Note that the result of the operation is always non-negative. For example, (\u2009-\u20091)\u00a0mod\u00a03\u2009=\u20092.In the first sample before the first move the speed vector will equal (3,4) and the bear will get to cell (4,1). Before the second move the speed vector will equal (9,10) and he bear will get to cell (3,1). Don't forget that at the second move, the number of berry bushes increased by 1.In the second sample before the first move the speed vector will equal (1,1) and the bear will get to cell (1,1). Before the second move, the speed vector will equal (4,4) and the bear will get to cell (1,1). Don't forget that at the second move, the number of berry bushes increased by 1."}, "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nint mod;\n\nstruct modint\n{\n\tlong value;\n\n\talias value this;\n\n\tthis (long nvalue)\n\t{\n\t\tvalue = nvalue % mod;\n\t}\n\n\tmodint opBinary (string op) (long other)\n\t{\n\t\treturn mixin (\"modint ((value \" ~ op ~ \" other) % mod)\");\n\t}\n\t\n\tmodint opBinary (string op) (modint other)\n\t{\n\t\treturn opBinary !(op) (other.value);\n\t}\n\t\n\tmodint opAssign (long nvalue)\n\t{\n\t\tvalue = nvalue % mod;\n\t\treturn this;\n\t}\n\n\tmodint opOpAssign (string op, T) (T other)\n\t{\n\t\tmixin (\"this = this \" ~ op ~ \" other;\");\n\t\treturn this;\n\t}\n\n\tstring toString ()\n\t{\n\t\treturn to !(string) (value);\n\t}\n}\n\nimmutable int SIDE = 6;\nalias modint [SIDE] vector;\nalias vector [SIDE] matrix;\n\nmatrix mult (const ref matrix a, const ref matrix b)\n{\n\tmatrix res;\n\tforeach (i; 0..SIDE)\n\t{\n\t\tforeach (j; 0..SIDE)\n\t\t{\n\t\t\tforeach (k; 0..SIDE)\n\t\t\t{\n\t\t\t\tres[i][j] += a[i][k] * b[k][j];\n\t\t\t}\n\t\t}\n\t}\n\treturn res;\n}\n\nvector mult (const ref matrix a, const ref vector b)\n{\n\tvector res;\n\tforeach (i; 0..SIDE)\n\t{\n\t\tforeach (j; 0..SIDE)\n\t\t{\n\t\t\tres[i] += a[i][j] * b[j];\n\t\t}\n\t}\n\treturn res;\n}\n\nmatrix powmod (matrix a, long b)\n{\n\tmatrix res;\n\tforeach (i; 0..SIDE)\n\t{\n\t\tres[i][i] = 1;\n\t}\n\twhile (b)\n\t{\n\t\tif (b & 1)\n\t\t{\n\t\t\tres = mult (res, a);\n\t\t}\n\t\ta = mult (a, a);\n\t\tb >>= 1;\n\t}\n\treturn res;\n}\n\nvoid main ()\n{\n\tint n, sx, sy, dx, dy;\n\tlong t;\n\tmod = 1_000_000_000;\n\tmatrix m = cast (matrix)\n/*\nx, y, dx, dy, t, 1:\nx x + dx + x + y + t + 2\ny y + dy + x + y + t + 2\ndx dx + x + y + t + 2\ndy dy + x + y + t + 2\nt t + 1\n1 1\n*/\n\t[[2L, 1L, 1L, 0L, 1L, 0L],\n\t [1L, 2L, 0L, 1L, 1L, 0L],\n\t [1L, 1L, 1L, 0L, 1L, 0L],\n\t [1L, 1L, 0L, 1L, 1L, 0L],\n\t [0L, 0L, 0L, 0L, 1L, 1L],\n\t [0L, 0L, 0L, 0L, 0L, 1L]];\n\twhile (readf (\" %s %s %s %s %s %s\", &n, &sx, &sy, &dx, &dy, &t) > 0)\n\t{\n\t\tmod = n;\n\t\tvector v = [modint (sx), modint (sy),\n\t\t modint (dx), modint (dy), modint (0), modint (1)];\n\t\tmatrix a = powmod (m, t);\n\t\tvector res = mult (a, v);\n\t\tint x = cast (int) (res[0] - 1 + mod);\n\t\tint y = cast (int) (res[1] - 1 + mod);\n\t\tenforce (0 <= x && x < n);\n\t\tenforce (0 <= y && y < n);\n\t\twriteln (x + 1, ' ', y + 1);\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nint mod;\n\nstruct modint\n{\n\tint value;\n\n\talias value this;\n\n\tthis (int nvalue)\n\t{\n\t\tvalue = nvalue % mod;\n\t}\n\n\tmodint opBinary (string op) (int other)\n\t{\n\t\treturn mixin (\"modint ((cast (long) value \" ~\n\t\t op ~ \" other) % mod)\");\n\t}\n\n\tmodint opOpAssign (string op, T) (T other)\n\t{\n\t\treturn mixin (\"(this = this \" ~ op ~ \" other)\");\n\t}\n}\n\nimmutable int SIDE = 6;\nalias modint [SIDE] vector;\nalias vector [SIDE] matrix;\n\nmatrix mult (const ref matrix a, const ref matrix b)\n{\n\tmatrix res;\n\tforeach (i; 0..SIDE)\n\t{\n\t\tforeach (j; 0..SIDE)\n\t\t{\n\t\t\tforeach (k; 0..SIDE)\n\t\t\t{\n\t\t\t\tres[i][j] += a[i][k] * b[k][j];\n\t\t\t}\n\t\t}\n\t}\n\treturn res;\n}\n\nvector mult (const ref matrix a, const ref vector b)\n{\n\tvector res;\n\tforeach (i; 0..SIDE)\n\t{\n\t\tforeach (j; 0..SIDE)\n\t\t{\n\t\t\tres[i] += a[i][j] * b[j];\n\t\t}\n\t}\n\treturn res;\n}\n\nmatrix powmod (matrix a, long b)\n{\n\tmatrix res;\n\tforeach (i; 0..SIDE)\n\t{\n\t\tres[i][i] = 1;\n\t}\n\twhile (b)\n\t{\n\t\tif (b & 1)\n\t\t{\n\t\t\tres = mult (res, a);\n\t\t}\n\t\ta = mult (a, a);\n\t\tb >>= 1;\n\t}\n\treturn res;\n}\n\nvoid main ()\n{\n\tint n, sx, sy, dx, dy;\n\tlong t;\n\tmatrix m = cast (matrix)\n/*\nx, y, dx, dy, t, 1:\nx x + dx + x + y + t + 2\ny y + dy + x + y + t + 2\ndx dx + x + y + t + 2\ndy dy + x + y + t + 2\nt t + 1\n1 1\n*/\n\t[[2, 1, 1, 0, 1, 2],\n\t [1, 2, 0, 1, 1, 2],\n\t [1, 1, 1, 0, 1, 2],\n\t [1, 1, 0, 1, 1, 2],\n\t [0, 0, 0, 0, 1, 1],\n\t [0, 0, 0, 0, 0, 1]];\n\twhile (readf (\" %s %s %s %s %s %s\", &n, &sx, &sy, &dx, &dy, &t) > 0)\n\t{\n\t\tmod = n;\n\t\tvector v = [modint (sx - 1), modint (sy - 1),\n\t\t modint (dx), modint (dy), modint (0), modint (1)];\n\t\tauto a = powmod (m, t);\n\t\tvector res = mult (a, v);\n\t\twriteln (cast (int) (res[0] + mod) + 1, ' ',\n\t\t cast (int) (res[1] + mod) + 1);\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nint mod;\n\nstruct modint\n{\n\tint value;\n\n\talias value this;\n\n\tthis (int nvalue)\n\t{\n\t\tvalue = nvalue % mod;\n\t}\n\n\tmodint opBinary (string op) (int other)\n\t{\n\t\treturn mixin (\"modint (((cast (long) (value)) \" ~\n\t\t op ~ \" (other)) % mod)\");\n\t}\n\n\tmodint opOpAssign (string op, T) (T other)\n\t{\n\t\treturn mixin (\"((this) = ((this) \" ~ op ~ \" (other)))\");\n\t}\n}\n\nimmutable int SIDE = 6;\nalias modint [SIDE] vector;\nalias vector [SIDE] matrix;\n\nmatrix mult (const ref matrix a, const ref matrix b)\n{\n\tmatrix res;\n\tforeach (i; 0..SIDE)\n\t{\n\t\tforeach (j; 0..SIDE)\n\t\t{\n\t\t\tforeach (k; 0..SIDE)\n\t\t\t{\n\t\t\t\tres[i][j] += a[i][k] * b[k][j];\n\t\t\t}\n\t\t}\n\t}\n\treturn res;\n}\n\nvector mult (const ref matrix a, const ref vector b)\n{\n\tvector res;\n\tforeach (i; 0..SIDE)\n\t{\n\t\tforeach (j; 0..SIDE)\n\t\t{\n\t\t\tres[i] += a[i][j] * b[j];\n\t\t}\n\t}\n\treturn res;\n}\n\nmatrix powmod (matrix a, long b)\n{\n\tmatrix res;\n\tforeach (i; 0..SIDE)\n\t{\n\t\tres[i][i] = 1;\n\t}\n\twhile (b)\n\t{\n\t\tif (b & 1)\n\t\t{\n\t\t\tres = mult (res, a);\n\t\t}\n\t\ta = mult (a, a);\n\t\tb >>= 1;\n\t}\n\treturn res;\n}\n\nvoid main ()\n{\n\tint n, sx, sy, dx, dy;\n\tlong t;\n\tmatrix m = cast (matrix)\n/*\nx, y, dx, dy, t, 1:\nx x + dx + x + y + t + 2\ny y + dy + x + y + t + 2\ndx dx + x + y + t + 2\ndy dy + x + y + t + 2\nt t + 1\n1 1\n*/\n\t[[2, 1, 1, 0, 1, 0],\n\t [1, 2, 0, 1, 1, 0],\n\t [1, 1, 1, 0, 1, 0],\n\t [1, 1, 0, 1, 1, 0],\n\t [0, 0, 0, 0, 1, 1],\n\t [0, 0, 0, 0, 0, 1]];\n\twhile (readf (\" %s %s %s %s %s %s\", &n, &sx, &sy, &dx, &dy, &t) > 0)\n\t{\n\t\tmod = n;\n\t\tvector v = [modint (sx), modint (sy),\n\t\t modint (dx), modint (dy), modint (0), modint (1)];\n\t\tmatrix a = powmod (m, t);\n\t\tvector res = mult (a, v);\n\t\twriteln (cast (int) (res[0] + mod - 1) + 1, ' ',\n\t\t cast (int) (res[1] + mod - 1) + 1);\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nint mod;\n\nstruct modint\n{\n\tint value;\n\n\talias value this;\n\n\tthis (int nvalue)\n\t{\n\t\tvalue = nvalue % mod;\n\t}\n\n\tmodint opBinary (string op) (int other)\n\t{\n\t\treturn mixin (\"modint (((cast (long) (value)) \" ~\n\t\t op ~ \" (other)) % mod)\");\n\t}\n\n\tmodint opOpAssign (string op, T) (T other)\n\t{\n\t\treturn mixin (\"((this) = ((this) \" ~ op ~ \" (other)))\");\n\t}\n}\n\nimmutable int SIDE = 6;\nalias modint [SIDE] vector;\nalias vector [SIDE] matrix;\n\nmatrix mult (const ref matrix a, const ref matrix b)\n{\n\tmatrix res;\n\tforeach (i; 0..SIDE)\n\t{\n\t\tforeach (j; 0..SIDE)\n\t\t{\n\t\t\tforeach (k; 0..SIDE)\n\t\t\t{\n\t\t\t\tres[i][j] += a[i][k] * b[k][j];\n\t\t\t}\n\t\t}\n\t}\n\treturn res;\n}\n\nvector mult (const ref matrix a, const ref vector b)\n{\n\tvector res;\n\tforeach (i; 0..SIDE)\n\t{\n\t\tforeach (j; 0..SIDE)\n\t\t{\n\t\t\tres[i] += a[i][j] * b[j];\n\t\t}\n\t}\n\treturn res;\n}\n\nmatrix powmod (matrix a, long b)\n{\n\tmatrix res;\n\tforeach (i; 0..SIDE)\n\t{\n\t\tres[i][i] = 1;\n\t}\n\twhile (b)\n\t{\n\t\tif (b & 1)\n\t\t{\n\t\t\tres = mult (res, a);\n\t\t}\n\t\ta = mult (a, a);\n\t\tb >>= 1;\n\t}\n\treturn res;\n}\n\nvoid main ()\n{\n\tint n, sx, sy, dx, dy;\n\tlong t;\n\tmatrix m = cast (matrix)\n/*\nx, y, dx, dy, t, 1:\nx x + dx + x + y + t + 2\ny y + dy + x + y + t + 2\ndx dx + x + y + t + 2\ndy dy + x + y + t + 2\nt t + 1\n1 1\n*/\n\t[[2, 1, 1, 0, 1, 2],\n\t [1, 2, 0, 1, 1, 2],\n\t [1, 1, 1, 0, 1, 2],\n\t [1, 1, 0, 1, 1, 2],\n\t [0, 0, 0, 0, 1, 1],\n\t [0, 0, 0, 0, 0, 1]];\n\twhile (readf (\" %s %s %s %s %s %s\", &n, &sx, &sy, &dx, &dy, &t) > 0)\n\t{\n\t\tmod = n;\n\t\tvector v = [modint (sx - 1), modint (sy - 1),\n\t\t modint (dx), modint (dy), modint (0), modint (1)];\n\t\tauto a = powmod (m, t);\n\t\tvector res;\n\t\tif (t < 10000)\n\t\t{\n\t\t\tres = v;\n\t\t\tforeach (s; 0..t)\n\t\t\t{\n\t\t\t\tres = mult (m, res);\n\t\t\t}\n\t\t}\n\t\telse\n\t\t{\n\t\t\tres = mult (a, v);\n\t\t}\n\t\twriteln (cast (int) (res[0] + mod) + 1, ' ',\n\t\t cast (int) (res[1] + mod) + 1);\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nint mod;\n\nstruct modint\n{\n\tint value;\n\n\talias value this;\n\n\tthis (int nvalue)\n\t{\n\t\tvalue = nvalue % mod;\n\t}\n\n\tmodint opBinary (string op) (int other)\n\t{\n\t\treturn mixin (\"modint (((cast (long) (value)) \" ~\n\t\t op ~ \" (other)) % mod)\");\n\t}\n\n\tmodint opOpAssign (string op, T) (T other)\n\t{\n\t\treturn mixin (\"((this) = ((this) \" ~ op ~ \" (other)))\");\n\t}\n}\n\nimmutable int SIDE = 6;\nalias modint [SIDE] vector;\nalias vector [SIDE] matrix;\n\nmatrix mult (const ref matrix a, const ref matrix b)\n{\n\tmatrix res;\n\tforeach (i; 0..SIDE)\n\t{\n\t\tforeach (j; 0..SIDE)\n\t\t{\n\t\t\tforeach (k; 0..SIDE)\n\t\t\t{\n\t\t\t\tres[i][j] += a[i][k] * b[k][j];\n\t\t\t}\n\t\t}\n\t}\n\treturn res;\n}\n\nvector mult (const ref matrix a, const ref vector b)\n{\n\tvector res;\n\tforeach (i; 0..SIDE)\n\t{\n\t\tforeach (j; 0..SIDE)\n\t\t{\n\t\t\tres[i] += a[i][j] * b[j];\n\t\t}\n\t}\n\treturn res;\n}\n\nmatrix powmod (matrix a, long b)\n{\n\tmatrix res;\n\tforeach (i; 0..SIDE)\n\t{\n\t\tres[i][i] = 1;\n\t}\n\twhile (b)\n\t{\n\t\tif (b & 1)\n\t\t{\n\t\t\tres = mult (res, a);\n\t\t}\n\t\ta = mult (a, a);\n\t\tb >>= 1;\n\t}\n\treturn res;\n}\n\nvoid main ()\n{\n\tint n, sx, sy, dx, dy;\n\tlong t;\n\tmatrix m = cast (matrix)\n/*\nx, y, dx, dy, t, 1:\nx x + dx + x + y + t + 2\ny y + dy + x + y + t + 2\ndx dx + x + y + t + 2\ndy dy + x + y + t + 2\nt t + 1\n1 1\n*/\n\t[[2, 1, 1, 0, 1, 0],\n\t [1, 2, 0, 1, 1, 0],\n\t [1, 1, 1, 0, 1, 0],\n\t [1, 1, 0, 1, 1, 0],\n\t [0, 0, 0, 0, 1, 1],\n\t [0, 0, 0, 0, 0, 1]];\n\twhile (readf (\" %s %s %s %s %s %s\", &n, &sx, &sy, &dx, &dy, &t) > 0)\n\t{\n\t\tmod = n;\n\t\tvector v = [modint (sx), modint (sy),\n\t\t modint (dx), modint (dy), modint (0), modint (1)];\n\t\tmatrix a = powmod (m, t);\n\t\tvector res = mult (a, v);\n\t\twriteln (cast (int) (res[0] - 1 + mod) + 1, ' ',\n\t\t cast (int) (res[1] - 1 + mod) + 1);\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nint mod;\n\nstruct modint\n{\n\tint value;\n\n\talias value this;\n\n\tthis (int nvalue)\n\t{\n\t\tvalue = nvalue;\n\t}\n\n\tmodint opBinary (string op) (int other)\n\t{\n\t\treturn mixin (\"modint ((cast (long) value \" ~\n\t\t op ~ \" other) % mod)\");\n\t}\n\n\tmodint opOpAssign (string op, T) (T other)\n\t{\n\t\treturn mixin (\"(this = this \" ~ op ~ \" other)\");\n\t}\n}\n\nimmutable int SIDE = 6;\nalias modint [SIDE] vector;\nalias vector [SIDE] matrix;\n\nmatrix mult (const ref matrix a, const ref matrix b)\n{\n\tmatrix res;\n\tforeach (i; 0..SIDE)\n\t{\n\t\tforeach (j; 0..SIDE)\n\t\t{\n\t\t\tforeach (k; 0..SIDE)\n\t\t\t{\n\t\t\t\tres[i][j] += a[i][k] * b[k][j];\n\t\t\t}\n\t\t}\n\t}\n\treturn res;\n}\n\nvector mult (const ref matrix a, const ref vector b)\n{\n\tvector res;\n\tforeach (i; 0..SIDE)\n\t{\n\t\tforeach (j; 0..SIDE)\n\t\t{\n\t\t\tres[i] += a[i][j] * b[j];\n\t\t}\n\t}\n\treturn res;\n}\n\nmatrix powmod (matrix a, long b)\n{\n\tmatrix res;\n\tforeach (i; 0..SIDE)\n\t{\n\t\tres[i][i] = 1;\n\t}\n\twhile (b)\n\t{\n\t\tif (b & 1)\n\t\t{\n\t\t\tres = mult (res, a);\n\t\t}\n\t\ta = mult (a, a);\n\t\tb >>= 1;\n\t}\n\treturn res;\n}\n\nvoid main ()\n{\n\tint n, sx, sy, dx, dy;\n\tlong t;\n\tmatrix m = cast (matrix)\n/*\nx, y, dx, dy, t, 1:\nx x + dx + x + y + t + 2\ny y + dy + x + y + t + 2\ndx dx + x + y + t + 2\ndy dy + x + y + t + 2\nt t + 1\n1 1\n*/\n\t[[2, 1, 1, 0, 1, 2],\n\t [1, 2, 0, 1, 1, 2],\n\t [1, 1, 1, 0, 1, 2],\n\t [1, 1, 0, 1, 1, 2],\n\t [0, 0, 0, 0, 1, 1],\n\t [0, 0, 0, 0, 0, 1]];\n\twhile (readf (\" %s %s %s %s %s %s\", &n, &sx, &sy, &dx, &dy, &t) > 0)\n\t{\n\t\tmod = n;\n\t\tvector v = [modint (sx - 1), modint (sy - 1),\n\t\t modint (dx), modint (dy), modint (0), modint (1)];\n\t\tauto a = powmod (m, t);\n\t\tvector res = mult (a, v);\n\t\twriteln (cast (int) (res[0] + mod) + 1, ' ',\n\t\t cast (int) (res[1] + mod) + 1);\n\t}\n}\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport core.bitop;\n\nint mod;\n\nstruct modint\n{\n\tint value;\n\n\talias value this;\n\n\tthis (int nvalue)\n\t{\n\t\tvalue = nvalue % mod;\n\t}\n\n\tmodint opBinary (string op) (int other)\n\t{\n\t\treturn mixin (\"modint (((cast (long) (value)) \" ~\n\t\t op ~ \" (other)) % mod)\");\n\t}\n\n\tmodint opOpAssign (string op, T) (T other)\n\t{\n\t\treturn mixin (\"((this) = ((this) \" ~ op ~ \" (other)))\");\n\t}\n}\n\nimmutable int SIDE = 6;\nalias modint [SIDE] vector;\nalias vector [SIDE] matrix;\n\nmatrix mult (const ref matrix a, const ref matrix b)\n{\n\tmatrix res;\n\tforeach (i; 0..SIDE)\n\t{\n\t\tforeach (j; 0..SIDE)\n\t\t{\n\t\t\tforeach (k; 0..SIDE)\n\t\t\t{\n\t\t\t\tres[i][j] += a[i][k] * b[k][j];\n\t\t\t}\n\t\t}\n\t}\n\treturn res;\n}\n\nvector mult (const ref matrix a, const ref vector b)\n{\n\tvector res;\n\tforeach (i; 0..SIDE)\n\t{\n\t\tforeach (j; 0..SIDE)\n\t\t{\n\t\t\tres[i] += a[i][j] * b[j];\n\t\t}\n\t}\n\treturn res;\n}\n\nmatrix powmod (matrix a, long b)\n{\n\tmatrix res;\n\tforeach (i; 0..SIDE)\n\t{\n\t\tres[i][i] = 1;\n\t}\n\twhile (b)\n\t{\n\t\tif (b & 1)\n\t\t{\n\t\t\tres = mult (res, a);\n\t\t}\n\t\ta = mult (a, a);\n\t\tb >>= 1;\n\t}\n\treturn res;\n}\n\nvoid main ()\n{\n\tint n, sx, sy, dx, dy;\n\tlong t;\n\tmod = 1_000_000_000;\n\tmatrix m = cast (matrix)\n/*\nx, y, dx, dy, t, 1:\nx x + dx + x + y + t + 2\ny y + dy + x + y + t + 2\ndx dx + x + y + t + 2\ndy dy + x + y + t + 2\nt t + 1\n1 1\n*/\n\t[[2, 1, 1, 0, 1, 0],\n\t [1, 2, 0, 1, 1, 0],\n\t [1, 1, 1, 0, 1, 0],\n\t [1, 1, 0, 1, 1, 0],\n\t [0, 0, 0, 0, 1, 1],\n\t [0, 0, 0, 0, 0, 1]];\n\twhile (readf (\" %s %s %s %s %s %s\", &n, &sx, &sy, &dx, &dy, &t) > 0)\n\t{\n\t\tmod = n;\n\t\tvector v = [modint (sx), modint (sy),\n\t\t modint (dx), modint (dy), modint (0), modint (1)];\n\t\tmatrix a = powmod (m, t);\n\t\tvector res = mult (a, v);\n\t\tint x = res[0] - 1 + mod;\n\t\tint y = res[1] - 1 + mod;\n\t\tenforce (0 <= x && x < n);\n\t\tenforce (0 <= y && y < n);\n\t\twriteln (x + 1, ' ', y + 1);\n\t}\n}\n"}], "src_uid": "ee9fa8be2ae05a4e831a4f608c0cc785"} {"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": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional, std.meta;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.ascii, std.typecons;\n\nvoid main()\n{\n immutable int MD = 10 ^^ 9 + 7;\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n \n int[] dp;\n dp ~= 0;\n dp ~= 2;\n dp ~= 4;\n foreach (i; 3 .. max(n, m) + 1) {\n dp ~= (dp[i-1] + dp[i-2]) % MD;\n }\n \n debug { dp.writeln; }\n \n int ans = (((dp[n] + dp[m] - 2) % MD) + MD) % MD;\n \n ans.writeln;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int mod = 10 ^^ 9 + 7;\nimmutable int limit = 100_005;\n\nvoid main ()\n{\n\tauto f = new int [limit];\n\tf[0] = 1;\n\tf[1] = 1;\n\tforeach (i; 2..limit)\n\t{\n\t\tf[i] = (f[i - 1] + f[i - 2]) % mod;\n\t}\n\n\tint m, n;\n\twhile (readf !(\" %s %s\") (&m, &n) > 0)\n\t{\n\t\tint res = 0;\n\t\tres = (res + f[m]) % mod;\n\t\tres = (res + f[n]) % mod;\n\t\tres = (res + mod - 1) % mod;\n\t\tres = (res * 2) % mod;\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [], "src_uid": "0f1ab296cbe0952faa904f2bebe0567b"} {"nl": {"description": "Natasha is planning an expedition to Mars for $$$n$$$ people. One of the important tasks is to provide food for each participant.The warehouse has $$$m$$$ daily food packages. Each package has some food type $$$a_i$$$.Each participant must eat exactly one food package each day. Due to extreme loads, each participant must eat the same food type throughout the expedition. Different participants may eat different (or the same) types of food.Formally, for each participant $$$j$$$ Natasha should select his food type $$$b_j$$$ and each day $$$j$$$-th participant will eat one food package of type $$$b_j$$$. The values $$$b_j$$$ for different participants may be different.What is the maximum possible number of days the expedition can last, following the requirements above?", "input_spec": "The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\le n \\le 100$$$, $$$1 \\le m \\le 100$$$)\u00a0\u2014 the number of the expedition participants and the number of the daily food packages available. The second line contains sequence of integers $$$a_1, a_2, \\dots, a_m$$$ ($$$1 \\le a_i \\le 100$$$), where $$$a_i$$$ is the type of $$$i$$$-th food package.", "output_spec": "Print the single integer\u00a0\u2014 the number of days the expedition can last. If it is not possible to plan the expedition for even one day, print 0.", "sample_inputs": ["4 10\n1 5 2 1 1 1 2 5 7 2", "100 1\n1", "2 5\n5 4 3 2 1", "3 9\n42 42 42 42 42 42 42 42 42"], "sample_outputs": ["2", "0", "1", "3"], "notes": "NoteIn the first example, Natasha can assign type $$$1$$$ food to the first participant, the same type $$$1$$$ to the second, type $$$5$$$ to the third and type $$$2$$$ to the fourth. In this case, the expedition can last for $$$2$$$ days, since each participant can get two food packages of his food type (there will be used $$$4$$$ packages of type $$$1$$$, two packages of type $$$2$$$ and two packages of type $$$5$$$).In the second example, there are $$$100$$$ participants and only $$$1$$$ food package. In this case, the expedition can't last even $$$1$$$ day."}, "positive_code": [{"source_code": "import core.bitop;\nimport std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n, m;\n readf(\"%s %s\", &n, &m);\n readln;\n \n int [int] cnt;\n readln.chomp.split.map!(to!int).array.each!(x => ++cnt[x]);\n \n debug { cnt.writeln; }\n \n auto okDays = (int days) => cnt.values.map!(x => x / days).sum >= n;\n auto ans = okDays(1) ? (101).iota.dropOne.until!(days => !okDays(days)).array.back : 0;\n \n ans.writeln;\n}"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n, m;\n\twhile (readf (\" %s %s\", &n, &m) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tauto b = new int [101];\n\t\tforeach (c; a)\n\t\t{\n\t\t\tb[c] += 1;\n\t\t}\n\t\tint res = 1;\n\t\twhile (b.map !(x => x / res).sum >= n)\n\t\t{\n\t\t\tres += 1;\n\t\t}\n\t\twriteln (res - 1);\n\t}\n}\n"}, {"source_code": "import std.algorithm,std.conv,std.range,std.stdio;void main(){int r=1,n=readln.split[0].to!int;int[101]b;foreach(c;readln.split)b[c.to!int]++;while(b[].map!(x=>x/r).sum>=n)r++;writeln(r-1);}\n"}, {"source_code": "import std.algorithm, std.conv, std.range, std.stdio;\nvoid main () {\n\tint r = 1, n = readln.split[0].to!int;\n\tint [101] b;\n\tforeach (c; readln.split) b[c.to!int]++;\n\twhile (b[].map !(x => x / r).sum >= n) r++;\n\twriteln (r - 1);\n}\n"}], "negative_code": [], "src_uid": "b7ef696a11ff96f2e9c31becc2ff50fe"} {"nl": {"description": "You are given n rectangles. The corners of rectangles have integer coordinates and their edges are parallel to the Ox and Oy axes. The rectangles may touch each other, but they do not overlap (that is, there are no points that belong to the interior of more than one rectangle). Your task is to determine if the rectangles form a square. In other words, determine if the set of points inside or on the border of at least one rectangle is precisely equal to the set of points inside or on the border of some square.", "input_spec": "The first line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u20095). Next n lines contain four integers each, describing a single rectangle: x1, y1, x2, y2 (0\u2009\u2264\u2009x1\u2009<\u2009x2\u2009\u2264\u200931400,\u20090\u2009\u2264\u2009y1\u2009<\u2009y2\u2009\u2264\u200931400) \u2014 x1 and x2 are x-coordinates of the left and right edges of the rectangle, and y1 and y2 are y-coordinates of the bottom and top edges of the rectangle. No two rectangles overlap (that is, there are no points that belong to the interior of more than one rectangle).", "output_spec": "In a single line print \"YES\", if the given rectangles form a square, or \"NO\" otherwise.", "sample_inputs": ["5\n0 0 2 3\n0 3 3 5\n2 0 5 2\n3 2 5 5\n2 2 3 3", "4\n0 0 2 3\n0 3 3 5\n2 0 5 2\n3 2 5 5"], "sample_outputs": ["YES", "NO"], "notes": null}, "positive_code": [{"source_code": "import std.stdio : write, writeln;\nimport std.array;\nimport std.range;\nimport std.typecons;\nimport std.bigint;\nimport std.algorithm;\n\nconst int INF = 1<<28;\n\nint n;\nint[4][] ps;\nint[2][] p;\nbool ans = false;\n\nvoid make( int depth, int end, int i ){\n\tif( depth == end ){\n\t\tsolve( depth );\n\t\treturn;\n\t}\n\tfor( int j = i; j < n; ++j ){\n\t\tauto tmp = p.clone;\n\t\tp ~= [ ps[ j ][ 0 ], ps[ j ][ 1 ] ];\n\t\tp ~= [ ps[ j ][ 2 ], ps[ j ][ 1 ] ];\n\t\tp ~= [ ps[ j ][ 0 ], ps[ j ][ 3 ] ];\n\t\tp ~= [ ps[ j ][ 2 ], ps[ j ][ 3 ] ];\n\t\tmake( depth + 1, end, j + 1 );\n\t\tassert( tmp !is p );\n\t\tp = tmp.clone;\n\t}\n}\n\nvoid solve( int s ){\n\tbool[int[2]] data;\n\tfor( int i = 0; i < s*4; ++i ){\n\t\tbool f = false;\n\t\tfor( int j = 0; j < s*4; ++j ){\n\t\t\tif( i == j )continue;\n\t\n\t\t\tassert( p[ i ] !is p[ j ] );\n\t\t\tf |= p[ i ] == p[ j ];\n\t\t}\n\t\tif( !f ){\n\t\t\tdata[ p[ i ] ] = true;\n\t\t}\n\t}\n\t\n\tif( data.keys.length == 4 ){\n\t\tint min_x = INF, min_y = INF, max_x = 0, max_y = 0;\n\t\tforeach( v; data.keys ){\n\t\t\tmin_x = min( min_x, v.front );\n\t\t\tmin_y = min( min_y, v.back );\n\t\t\tmax_x = max( max_x, v.front );\n\t\t\tmax_y = max( max_y, v.back );\n\t\t}\n\t\tint[2] cntx, cnty;\n\t\tforeach( v; data.keys ){\n\t\t\tif( v.front == min_x )++cntx[0];\n\t\t\tif( v.front == max_x )++cntx[1];\n\t\t\tif( v.back == min_y )++cnty[0];\n\t\t\tif( v.back == max_y )++cnty[1];\n\t\t}\n\t\tans |= (cntx == [ 2, 2 ] && cnty == [ 2, 2 ] && (max_x - min_x) == (max_y - min_y) );\n\t}\n}\n\nvoid main(){\n\tn = next!int;\n\t\n\tforeach( i; n.iota ){\n\t\tint x1 = next!int;\n\t\tint y1 = next!int;\n\t\t\n\t\tint x2 = next!int;\n\t\tint y2 = next!int;\n\n\t\tps ~= [x1, y1, x2, y2];\n\t}\n\t\n/+\n\tfor( int s = 1; s <= n; ++s ){\n\t\tp = p.init;\n\t\tmake( 0, s, 0 );\n\t}\n+/\n\tp = p.init;\n\tmake( 0, n, 0 );\n\t\n\twriteln = ans ? \"YES\": \"NO\";\n}\n\n\nimport std.stdio : readln;\nimport std.conv : to;\nimport std.string : split, chomp;\nimport std.traits;\nstring[] input;\nstring delim = \" \";\nT next(T)()\nin\n{\n\tassert(hasNext());\n}\nout\n{\n\tinput.popFront;\n}\nbody\n{\n\treturn input.front.to!T;\n}\n\nT next( T : char )()\nin\n{\n\tassert(hasNext());\n}\nout\n{\n\tinput.front.popFront;\n}\nbody\n{\n\treturn input.front.front.to!T;\n}\n\n\n\nbool hasNext(){\n\tif(input.length > 0){\n\t\tif(input.front.length == 0){\n\t\t\tinput.popFront;\n\t\t\treturn hasNext;\n\t\t}\n\t\treturn true;\n\t}\n\t\n\tstring str = readln;\n\tif(str.length > 0){\n\t\tinput ~= str.chomp.split(delim);\n\t\treturn hasNext;\n\t}else{\n\t\treturn false;\n\t}\n}\n\n\nvoid dbg(T...)(T vs)\n{\n\timport std.stdio : stderr;\n\tforeach(v; vs)\n\t\tstderr.write(v.to!string ~ \" \");\n\tstderr.write(\"\\n\");\n}\n\nT clone(T)(T v){\n\tT v_;\n\tstatic if(isInputRange!(T)){\n\t\tforeach(ite; v){\n\t\t\tv_ ~= ite.clone;\n\t\t}\n\t}else{\n\t\tv_ = v;\n\t}\n\t\n\treturn v_;\n}\n\n"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n\n struct rect { int x1, y1, x2, y2; }\n rect[] rs = new rect[] (n);\n foreach (i; 0 .. n) {\n readf(\"%s %s %s %s\", &rs[i].x1, &rs[i].y1, &rs[i].x2, &rs[i].y2);\n readln;\n }\n \n debug { rs.writeln; }\n \n immutable int INF = 10 ^^ 9;\n int sx1 = INF, sy1 = INF, sx2 = -INF, sy2 = -INF;\n \n foreach (r; rs) {\n sx1 = min(sx1, r.x1);\n sy1 = min(sy1, r.y1);\n sx2 = max(sx2, r.x2);\n sy2 = max(sy2, r.y2);\n }\n\n if (sy2 - sy1 != sx2 - sx1) { \n writeln(\"NO\");\n return;\n }\n\n int rectArea = rs.map!(r => (r.y2 - r.y1) * (r.x2 - r.x1)).sum;\n int sqArea = (sy2 - sy1) * (sx2 - sx1);\n if (rectArea != sqArea) { \n writeln(\"NO\");\n return; \n }\n\n writeln(\"YES\");\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n\n struct rect { int x1, y1, x2, y2; }\n rect[] rs = new rect[] (n);\n foreach (i; 0 .. n) {\n readf(\"%s %s %s %s\", &rs[i].x1, &rs[i].y1, &rs[i].x2, &rs[i].y2);\n readln;\n }\n \n debug { rs.writeln; }\n \n immutable int INF = 10 ^^ 9;\n int sx1 = INF, sy1 = INF, sx2 = -INF, sy2 = -INF;\n int rectArea = rs.map!(r => (r.y2 - r.y1) * (r.x2 - r.x1)).sum;\n \n foreach (j; 0 .. n) {\n sx1 = min(sx1, rs[j].x1);\n sy1 = min(sy1, rs[j].y1);\n sx2 = max(sx2, rs[j].x2);\n sy2 = max(sy2, rs[j].y2);\n }\n\n if (sy2 - sy1 != sx2 - sx1) { \n writeln(\"NO\");\n return;\n }\n\n int area = (sy2 - sy1) * (sx2 - sx1);\n if (area != rectArea) { \n writeln(\"NO\");\n return; \n }\n\n writeln(\"YES\");\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n\n struct rect { int x1, y1, x2, y2; }\n rect[] rs = new rect[] (n);\n foreach (i; 0 .. n) {\n readf(\"%s %s %s %s\", &rs[i].x1, &rs[i].y1, &rs[i].x2, &rs[i].y2);\n readln;\n }\n \n debug { rs.writeln; }\n \n immutable int INF = 10 ^^ 9;\n int sx1 = INF, sy1 = INF, sx2 = -INF, sy2 = -INF;\n int rectArea = rs.map!(r => (r.y2 - r.y1) * (r.x2 - r.x1)).sum;\n \n foreach (r; rs) {\n sx1 = min(sx1, r.x1);\n sy1 = min(sy1, r.y1);\n sx2 = max(sx2, r.x2);\n sy2 = max(sy2, r.y2);\n }\n\n if (sy2 - sy1 != sx2 - sx1) { \n writeln(\"NO\");\n return;\n }\n\n int area = (sy2 - sy1) * (sx2 - sx1);\n if (area != rectArea) { \n writeln(\"NO\");\n return; \n }\n\n writeln(\"YES\");\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.exception;\nimport std.functional;\nimport std.math;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\talias Tuple !(long, \"x\", long, \"y\") point;\n\t\talias Tuple !(point, \"a\", point, \"b\") rect;\n\t\tauto r = new rect [n];\n\t\tauto t = rect (point (int.max, int.max),\n\t\t point (int.min, int.min));\n\t\tlong s = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\treadf (\" %s %s %s %s\", &r[i].a.x, &r[i].a.y,\n\t\t\t &r[i].b.x, &r[i].b.y);\n\t\t\ts += (r[i].b.x - r[i].a.x) * (r[i].b.y - r[i].a.y);\n\t\t\tt.a.x = min (t.a.x, r[i].a.x);\n\t\t\tt.a.y = min (t.a.y, r[i].a.y);\n\t\t\tt.b.x = max (t.b.x, r[i].b.x);\n\t\t\tt.b.y = max (t.b.y, r[i].b.y);\n\t\t}\n\t\tif (t.b.x - t.a.x == t.b.y - t.a.y &&\n\t\t (t.b.x - t.a.x) * (t.b.y - t.a.y) == s)\n\t\t{\n\t\t\twriteln (\"YES\");\n\t\t}\n\t\telse\n\t\t{\n\t\t\twriteln (\"NO\");\n\t\t}\n\t}\n}\n"}], "negative_code": [{"source_code": "import std.stdio : write, writeln;\nimport std.array;\nimport std.range;\nimport std.typecons;\nimport std.bigint;\nimport std.algorithm;\n\nconst int INF = 1<<28;\n\nvoid main(){\n\tint n = next!int;\n\t\n\tint[4][] ps;\n\tforeach( i; n.iota ){\n\t\tint x1 = next!int;\n\t\tint y1 = next!int;\n\t\t\n\t\tint x2 = next!int;\n\t\tint y2 = next!int;\n\n\t\tps ~= [x1, y1, x2, y2];\n\t}\n\t\n\tbool ans = false;\n\tfor( int s = 0; s <= n; ++s ){\n\t\tint[2][] p;\n\t\tfor( int r = 0; r < s; ++r ){\n\t\t\tp ~= [ ps[ r ][ 0 ], ps[ r ][ 1 ] ];\n\t\t\tp ~= [ ps[ r ][ 2 ], ps[ r ][ 1 ] ];\n\t\t\tp ~= [ ps[ r ][ 0 ], ps[ r ][ 3 ] ];\n\t\t\tp ~= [ ps[ r ][ 2 ], ps[ r ][ 3 ] ];\n\t\t}\n\t\tfor( int k = 0; k < s*4; ++k ){\n\t\t\tfor( int l = k+1; l < s*4; ++l ){\n\t\t\t\tbool[int[2]] data;\n\t\t\t\tfor( int i = 0; i <= k; ++i ){\n\t\t\t\t\tbool f = false;\n\t\t\t\t\tfor( int j = 0; j <= l; ++j ){\n\t\t\t\t\t\tif( i == j )continue;\n\t\t\t\t\n\t\t\t\t\t\tassert( p[ i ] !is p[ j ] );\n\t\t\t\t\t\tf |= p[ i ] == p[ j ];\n\t\t\t\t\t}\n\t\t\t\t\tif( !f ){\n\t\t\t\t\t\tdata[ p[ i ] ] = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tif( data.keys.length == 4 ){\n\t\t\t\t\tint min_x = INF, min_y = INF, max_x = 0, max_y = 0;\n\t\t\t\t\tforeach( v; data.keys ){\n\t\t\t\t\t\tmin_x = min( min_x, v.front );\n\t\t\t\t\t\tmin_y = min( min_x, v.back );\n\t\t\t\t\t\tmax_x = max( max_x, v.front );\n\t\t\t\t\t\tmax_y = max( max_y, v.back );\n\t\t\t\t\t}\n\t\t\t\t\tint[2] cntx, cnty;\n\t\t\t\t\tforeach( v; data.keys ){\n\t\t\t\t\t\tif( v.front == min_x )++cntx[0];\n\t\t\t\t\t\tif( v.front == max_x )++cntx[1];\n\t\t\t\t\t\tif( v.back == min_y )++cnty[0];\n\t\t\t\t\t\tif( v.back == max_y )++cnty[1];\n\t\t\t\t\t}\n\t\t\t\t\tans |= (cntx == [ 2, 2 ] && cnty == [ 2, 2 ]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\t\n\twriteln = ans ? \"YES\": \"NO\";\n}\n\n\nimport std.stdio : readln;\nimport std.conv : to;\nimport std.string : split, chomp;\nimport std.traits;\nstring[] input;\nstring delim = \" \";\nT next(T)()\nin\n{\n\tassert(hasNext());\n}\nout\n{\n\tinput.popFront;\n}\nbody\n{\n\treturn input.front.to!T;\n}\n\nT next( T : char )()\nin\n{\n\tassert(hasNext());\n}\nout\n{\n\tinput.front.popFront;\n}\nbody\n{\n\treturn input.front.front.to!T;\n}\n\n\n\nbool hasNext(){\n\tif(input.length > 0){\n\t\tif(input.front.length == 0){\n\t\t\tinput.popFront;\n\t\t\treturn hasNext;\n\t\t}\n\t\treturn true;\n\t}\n\t\n\tstring str = readln;\n\tif(str.length > 0){\n\t\tinput ~= str.chomp.split(delim);\n\t\treturn hasNext;\n\t}else{\n\t\treturn false;\n\t}\n}\n\n\nvoid dbg(T...)(T vs)\n{\n\timport std.stdio : stderr;\n\tforeach(v; vs)\n\t\tstderr.write(v.to!string ~ \" \");\n\tstderr.write(\"\\n\");\n}\n\nT clone(T)(T v){\n\tT v_;\n\tstatic if(isInputRange!(T)){\n\t\tforeach(ite; v){\n\t\t\tv_ ~= ite.clone;\n\t\t}\n\t}else{\n\t\tv_ = v;\n\t}\n\t\n\treturn v_;\n}\n\n"}, {"source_code": "import std.stdio : write, writeln;\nimport std.array;\nimport std.range;\nimport std.typecons;\nimport std.bigint;\nimport std.algorithm;\n\nconst int INF = 1<<28;\n\nint n;\nint[4][] ps;\nint[2][] p;\nbool ans = false;\n\nvoid make( int depth, int end, int i ){\n\tif( depth == end ){\n\t\tsolve( depth );\n\t}\n\tfor( int j = i; j < end; ++j ){\n\t\tp ~= [ ps[ j ][ 0 ], ps[ j ][ 1 ] ];\n\t\tp ~= [ ps[ j ][ 2 ], ps[ j ][ 1 ] ];\n\t\tp ~= [ ps[ j ][ 0 ], ps[ j ][ 3 ] ];\n\t\tp ~= [ ps[ j ][ 2 ], ps[ j ][ 3 ] ];\n\t\tmake( depth + 1, end, j + 1 );\n\t}\n}\n\nvoid solve( int s ){\n\tbool[int[2]] data;\n\tfor( int i = 0; i < s*4; ++i ){\n\t\tbool f = false;\n\t\tfor( int j = 0; j < s*4; ++j ){\n\t\t\tif( i == j )continue;\n\t\n\t\t\tassert( p[ i ] !is p[ j ] );\n\t\t\tf |= p[ i ] == p[ j ];\n\t\t}\n\t\tif( !f ){\n\t\t\tdata[ p[ i ] ] = true;\n\t\t}\n\t}\n\tif( data.keys.length == 4 ){\n\t\tint min_ = INF, max_ = 0;\n\t\tforeach( vs; data.keys ){\n\t\t\tforeach( v; vs ){\n\t\t\t\tmin_ = min( min_, v );\n\t\t\t\tmax_ = max( max_, v );\n\t\t\t}\n\t\t}\n\t\tassert( min_ != max_ );\n\t\tint[2] cnt;\n\t\tforeach( vs; data.keys ){\n\t\t\tforeach( v; vs ){\n\t\t\t\tif( v == min_ )++cnt[ 0 ];\n\t\t\t\tif( v == max_ )++cnt[ 1 ];\n\t\t\t}\n\t\t}\n\t\tans |= cnt.front == 4 && cnt.back == 4;\n\t}\n}\n\nvoid main(){\n\tn = next!int;\n\t\n\tforeach( i; n.iota ){\n\t\tint x1 = next!int;\n\t\tint y1 = next!int;\n\t\t\n\t\tint x2 = next!int;\n\t\tint y2 = next!int;\n\n\t\tps ~= [x1, y1, x2, y2];\n\t}\n\t\n\tfor( int s = 1; s <= n; ++s ){\n\t\tp = p.init;\n\t\tmake( 0, s, 0 );\n\t}\n\t\n\twriteln = ans ? \"YES\": \"NO\";\n}\n\n\nimport std.stdio : readln;\nimport std.conv : to;\nimport std.string : split, chomp;\nimport std.traits;\nstring[] input;\nstring delim = \" \";\nT next(T)()\nin\n{\n\tassert(hasNext());\n}\nout\n{\n\tinput.popFront;\n}\nbody\n{\n\treturn input.front.to!T;\n}\n\nT next( T : char )()\nin\n{\n\tassert(hasNext());\n}\nout\n{\n\tinput.front.popFront;\n}\nbody\n{\n\treturn input.front.front.to!T;\n}\n\n\n\nbool hasNext(){\n\tif(input.length > 0){\n\t\tif(input.front.length == 0){\n\t\t\tinput.popFront;\n\t\t\treturn hasNext;\n\t\t}\n\t\treturn true;\n\t}\n\t\n\tstring str = readln;\n\tif(str.length > 0){\n\t\tinput ~= str.chomp.split(delim);\n\t\treturn hasNext;\n\t}else{\n\t\treturn false;\n\t}\n}\n\n\nvoid dbg(T...)(T vs)\n{\n\timport std.stdio : stderr;\n\tforeach(v; vs)\n\t\tstderr.write(v.to!string ~ \" \");\n\tstderr.write(\"\\n\");\n}\n\nT clone(T)(T v){\n\tT v_;\n\tstatic if(isInputRange!(T)){\n\t\tforeach(ite; v){\n\t\t\tv_ ~= ite.clone;\n\t\t}\n\t}else{\n\t\tv_ = v;\n\t}\n\t\n\treturn v_;\n}\n\n"}, {"source_code": "import std.stdio : write, writeln;\nimport std.array;\nimport std.range;\nimport std.typecons;\nimport std.bigint;\nimport std.algorithm;\n\nconst int INF = 1<<28;\n\nint n;\nint[4][] ps;\nint[2][] p;\nbool ans = false;\n\nvoid make( int depth, int end, int i ){\n\tif( depth == end ){\n\t\tsolve( depth );\n\t\treturn;\n\t}\n\tfor( int j = i; j < n; ++j ){\n\t\tauto tmp = p.clone;\n\t\tp ~= [ ps[ j ][ 0 ], ps[ j ][ 1 ] ];\n\t\tp ~= [ ps[ j ][ 2 ], ps[ j ][ 1 ] ];\n\t\tp ~= [ ps[ j ][ 0 ], ps[ j ][ 3 ] ];\n\t\tp ~= [ ps[ j ][ 2 ], ps[ j ][ 3 ] ];\n\t\tmake( depth + 1, end, j + 1 );\n\t\tassert( tmp !is p );\n\t\tp = tmp.clone;\n\t}\n}\n\nvoid solve( int s ){\n\tbool[int[2]] data;\n\tfor( int i = 0; i < s*4; ++i ){\n\t\tbool f = false;\n\t\tfor( int j = 0; j < s*4; ++j ){\n\t\t\tif( i == j )continue;\n\t\n\t\t\tassert( p[ i ] !is p[ j ] );\n\t\t\tf |= p[ i ] == p[ j ];\n\t\t}\n\t\tif( !f ){\n\t\t\tdata[ p[ i ] ] = true;\n\t\t}\n\t}\n\tif( data.keys.length == 4 ){\n\t\tint min_x = INF, min_y = INF, max_x = 0, max_y = 0;\n\t\tforeach( v; data.keys ){\n\t\t\tmin_x = min( min_x, v.front );\n\t\t\tmin_y = min( min_x, v.back );\n\t\t\tmax_x = max( max_x, v.front );\n\t\t\tmax_y = max( max_y, v.back );\n\t\t}\n\t\tint[2] cntx, cnty;\n\t\tforeach( v; data.keys ){\n\t\t\tif( v.front == min_x )++cntx[0];\n\t\t\tif( v.front == max_x )++cntx[1];\n\t\t\tif( v.back == min_y )++cnty[0];\n\t\t\tif( v.back == max_y )++cnty[1];\n\t\t}\n\t\tans |= (cntx == [ 2, 2 ] && cnty == [ 2, 2 ] && (max_x - min_x) == (max_y - min_y) );\n\t}\n}\n\nvoid main(){\n\tn = next!int;\n\t\n\tforeach( i; n.iota ){\n\t\tint x1 = next!int;\n\t\tint y1 = next!int;\n\t\t\n\t\tint x2 = next!int;\n\t\tint y2 = next!int;\n\n\t\tps ~= [x1, y1, x2, y2];\n\t}\n\t\n\tfor( int s = 1; s <= n; ++s ){\n\t\tp = p.init;\n\t\tmake( 0, s, 0 );\n\t}\n\t\n\twriteln = ans ? \"YES\": \"NO\";\n}\n\n\nimport std.stdio : readln;\nimport std.conv : to;\nimport std.string : split, chomp;\nimport std.traits;\nstring[] input;\nstring delim = \" \";\nT next(T)()\nin\n{\n\tassert(hasNext());\n}\nout\n{\n\tinput.popFront;\n}\nbody\n{\n\treturn input.front.to!T;\n}\n\nT next( T : char )()\nin\n{\n\tassert(hasNext());\n}\nout\n{\n\tinput.front.popFront;\n}\nbody\n{\n\treturn input.front.front.to!T;\n}\n\n\n\nbool hasNext(){\n\tif(input.length > 0){\n\t\tif(input.front.length == 0){\n\t\t\tinput.popFront;\n\t\t\treturn hasNext;\n\t\t}\n\t\treturn true;\n\t}\n\t\n\tstring str = readln;\n\tif(str.length > 0){\n\t\tinput ~= str.chomp.split(delim);\n\t\treturn hasNext;\n\t}else{\n\t\treturn false;\n\t}\n}\n\n\nvoid dbg(T...)(T vs)\n{\n\timport std.stdio : stderr;\n\tforeach(v; vs)\n\t\tstderr.write(v.to!string ~ \" \");\n\tstderr.write(\"\\n\");\n}\n\nT clone(T)(T v){\n\tT v_;\n\tstatic if(isInputRange!(T)){\n\t\tforeach(ite; v){\n\t\t\tv_ ~= ite.clone;\n\t\t}\n\t}else{\n\t\tv_ = v;\n\t}\n\t\n\treturn v_;\n}\n\n"}, {"source_code": "import std.stdio : write, writeln;\nimport std.array;\nimport std.range;\nimport std.typecons;\nimport std.bigint;\nimport std.algorithm;\n\nconst int INF = 1<<28;\n\nint n;\nint[4][] ps;\nint[2][] p;\nbool ans = false;\n\nvoid make( int depth, int end, int i ){\n\tif( depth == end ){\n\t\tsolve( depth );\n\t}\n\tfor( int j = i; j < end; ++j ){\n\t\tp ~= [ ps[ j ][ 0 ], ps[ j ][ 1 ] ];\n\t\tp ~= [ ps[ j ][ 2 ], ps[ j ][ 1 ] ];\n\t\tp ~= [ ps[ j ][ 0 ], ps[ j ][ 3 ] ];\n\t\tp ~= [ ps[ j ][ 2 ], ps[ j ][ 3 ] ];\n\t\tmake( depth + 1, end, j + 1 );\n\t}\n}\n\nvoid solve( int s ){\n\tfor( int k = 0; k < s*4; ++k ){\n\t\tfor( int l = k+1; l < s*4; ++l ){\n\t\t\tbool[int[2]] data;\n\t\t\tfor( int i = 0; i <= k; ++i ){\n\t\t\t\tbool f = false;\n\t\t\t\tfor( int j = 0; j <= l; ++j ){\n\t\t\t\t\tif( i == j )continue;\n\t\t\t\n\t\t\t\t\tassert( p[ i ] !is p[ j ] );\n\t\t\t\t\tf |= p[ i ] == p[ j ];\n\t\t\t\t}\n\t\t\t\tif( !f ){\n\t\t\t\t\tdata[ p[ i ] ] = true;\n\t\t\t\t}\n\t\t\t}\n\t\t\t\n\t\t\tif( data.keys.length == 4 ){\n\t\t\t\tint min_x = INF, min_y = INF, max_x = 0, max_y = 0;\n\t\t\t\tforeach( v; data.keys ){\n\t\t\t\t\tmin_x = min( min_x, v.front );\n\t\t\t\t\tmin_y = min( min_x, v.back );\n\t\t\t\t\tmax_x = max( max_x, v.front );\n\t\t\t\t\tmax_y = max( max_y, v.back );\n\t\t\t\t}\n\t\t\t\tint[2] cntx, cnty;\n\t\t\t\tforeach( v; data.keys ){\n\t\t\t\t\tif( v.front == min_x )++cntx[0];\n\t\t\t\t\tif( v.front == max_x )++cntx[1];\n\t\t\t\t\tif( v.back == min_y )++cnty[0];\n\t\t\t\t\tif( v.back == max_y )++cnty[1];\n\t\t\t\t}\n\t\t\t\tans |= (cntx == [ 2, 2 ] && cnty == [ 2, 2 ]);\n\t\t\t}\n\t\t}\n\t}\n}\n\nvoid main(){\n\tn = next!int;\n\t\n\tforeach( i; n.iota ){\n\t\tint x1 = next!int;\n\t\tint y1 = next!int;\n\t\t\n\t\tint x2 = next!int;\n\t\tint y2 = next!int;\n\n\t\tps ~= [x1, y1, x2, y2];\n\t}\n\t\n\tfor( int s = 1; s <= n; ++s ){\n\t\tp = p.init;\n\t\tmake( 0, s, 0 );\n\t}\n\t\n\twriteln = ans ? \"YES\": \"NO\";\n}\n\n\nimport std.stdio : readln;\nimport std.conv : to;\nimport std.string : split, chomp;\nimport std.traits;\nstring[] input;\nstring delim = \" \";\nT next(T)()\nin\n{\n\tassert(hasNext());\n}\nout\n{\n\tinput.popFront;\n}\nbody\n{\n\treturn input.front.to!T;\n}\n\nT next( T : char )()\nin\n{\n\tassert(hasNext());\n}\nout\n{\n\tinput.front.popFront;\n}\nbody\n{\n\treturn input.front.front.to!T;\n}\n\n\n\nbool hasNext(){\n\tif(input.length > 0){\n\t\tif(input.front.length == 0){\n\t\t\tinput.popFront;\n\t\t\treturn hasNext;\n\t\t}\n\t\treturn true;\n\t}\n\t\n\tstring str = readln;\n\tif(str.length > 0){\n\t\tinput ~= str.chomp.split(delim);\n\t\treturn hasNext;\n\t}else{\n\t\treturn false;\n\t}\n}\n\n\nvoid dbg(T...)(T vs)\n{\n\timport std.stdio : stderr;\n\tforeach(v; vs)\n\t\tstderr.write(v.to!string ~ \" \");\n\tstderr.write(\"\\n\");\n}\n\nT clone(T)(T v){\n\tT v_;\n\tstatic if(isInputRange!(T)){\n\t\tforeach(ite; v){\n\t\t\tv_ ~= ite.clone;\n\t\t}\n\t}else{\n\t\tv_ = v;\n\t}\n\t\n\treturn v_;\n}\n\n"}, {"source_code": "import std.stdio : write, writeln;\nimport std.array;\nimport std.range;\nimport std.typecons;\nimport std.bigint;\nimport std.algorithm;\n\nconst int INF = 1<<28;\n\nint n;\nint[4][] ps;\nint[2][] p;\nbool ans = false;\n\nvoid make( int depth, int end, int i ){\n\tif( depth == end ){\n\t\tsolve( depth );\n\t\treturn;\n\t}\n\tfor( int j = i; j < n; ++j ){\n\t\tauto tmp = p.clone;\n\t\tp ~= [ ps[ j ][ 0 ], ps[ j ][ 1 ] ];\n\t\tp ~= [ ps[ j ][ 2 ], ps[ j ][ 1 ] ];\n\t\tp ~= [ ps[ j ][ 0 ], ps[ j ][ 3 ] ];\n\t\tp ~= [ ps[ j ][ 2 ], ps[ j ][ 3 ] ];\n\t\tmake( depth + 1, end, j + 1 );\n\t\tassert( tmp !is p );\n\t\tp = tmp.clone;\n\t}\n}\n\nvoid solve( int s ){\n\tbool[int[2]] data;\n\tfor( int i = 0; i < s*4; ++i ){\n\t\tbool f = false;\n\t\tfor( int j = 0; j < s*4; ++j ){\n\t\t\tif( i == j )continue;\n\t\n\t\t\tassert( p[ i ] !is p[ j ] );\n\t\t\tf |= p[ i ] == p[ j ];\n\t\t}\n\t\tif( !f ){\n\t\t\tdata[ p[ i ] ] = true;\n\t\t}\n\t}\n\t\n\tif( data.keys.length == 4 ){\n\t\tint min_x = INF, min_y = INF, max_x = 0, max_y = 0;\n\t\tforeach( v; data.keys ){\n\t\t\tmin_x = min( min_x, v.front );\n\t\t\tmin_y = min( min_y, v.back );\n\t\t\tmax_x = max( max_x, v.front );\n\t\t\tmax_y = max( max_y, v.back );\n\t\t}\n\t\tint[2] cntx, cnty;\n\t\tforeach( v; data.keys ){\n\t\t\tif( v.front == min_x )++cntx[0];\n\t\t\tif( v.front == max_x )++cntx[1];\n\t\t\tif( v.back == min_y )++cnty[0];\n\t\t\tif( v.back == max_y )++cnty[1];\n\t\t}\n\t\tans |= (cntx == [ 2, 2 ] && cnty == [ 2, 2 ] && (max_x - min_x) == (max_y - min_y) );\n\t}\n}\n\nvoid main(){\n\tn = next!int;\n\t\n\tforeach( i; n.iota ){\n\t\tint x1 = next!int;\n\t\tint y1 = next!int;\n\t\t\n\t\tint x2 = next!int;\n\t\tint y2 = next!int;\n\n\t\tps ~= [x1, y1, x2, y2];\n\t}\n\t\n\tfor( int s = 1; s <= n; ++s ){\n\t\tp = p.init;\n\t\tmake( 0, s, 0 );\n\t}\n\t\n\twriteln = ans ? \"YES\": \"NO\";\n}\n\n\nimport std.stdio : readln;\nimport std.conv : to;\nimport std.string : split, chomp;\nimport std.traits;\nstring[] input;\nstring delim = \" \";\nT next(T)()\nin\n{\n\tassert(hasNext());\n}\nout\n{\n\tinput.popFront;\n}\nbody\n{\n\treturn input.front.to!T;\n}\n\nT next( T : char )()\nin\n{\n\tassert(hasNext());\n}\nout\n{\n\tinput.front.popFront;\n}\nbody\n{\n\treturn input.front.front.to!T;\n}\n\n\n\nbool hasNext(){\n\tif(input.length > 0){\n\t\tif(input.front.length == 0){\n\t\t\tinput.popFront;\n\t\t\treturn hasNext;\n\t\t}\n\t\treturn true;\n\t}\n\t\n\tstring str = readln;\n\tif(str.length > 0){\n\t\tinput ~= str.chomp.split(delim);\n\t\treturn hasNext;\n\t}else{\n\t\treturn false;\n\t}\n}\n\n\nvoid dbg(T...)(T vs)\n{\n\timport std.stdio : stderr;\n\tforeach(v; vs)\n\t\tstderr.write(v.to!string ~ \" \");\n\tstderr.write(\"\\n\");\n}\n\nT clone(T)(T v){\n\tT v_;\n\tstatic if(isInputRange!(T)){\n\t\tforeach(ite; v){\n\t\t\tv_ ~= ite.clone;\n\t\t}\n\t}else{\n\t\tv_ = v;\n\t}\n\t\n\treturn v_;\n}\n\n"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n\n struct rect { int x1, y1, x2, y2; }\n rect[] rs = new rect[] (n);\n foreach (i; 0 .. n) {\n readf(\"%s %s %s %s\", &rs[i].x1, &rs[i].y1, &rs[i].x2, &rs[i].y2);\n readln;\n }\n \n debug { rs.writeln; }\n \n immutable int INF = 10 ^^ 9;\n foreach (i; 1 .. (1 << n)) {\n int sx1 = INF, sy1 = INF, sx2 = -INF, sy2 = -INF;\n \n int rectArea = i.bitsSet.map!(x => (rs[x].y2 - rs[x].y1) * (rs[x].x2 - rs[x].x1)).sum;\n \n foreach (j; i.bitsSet) {\n sx1 = min(sx1, rs[j].x1);\n sy1 = min(sy1, rs[j].y1);\n sx2 = max(sx2, rs[j].x2);\n sy2 = max(sy2, rs[j].y2);\n }\n \n if (sy2 - sy1 != sx2 - sx1) { continue; }\n \n int area = (sy2 - sy1) * (sx2 - sx1);\n \n if (area != rectArea) { continue; }\n \n writeln(\"YES\");\n return;\n }\n \n writeln(\"NO\");\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n\n struct rect { int x1, y1, x2, y2; }\n rect[] rs = new rect[] (n);\n foreach (i; 0 .. n) {\n readf(\"%s %s %s %s\", &rs[i].x1, &rs[i].y1, &rs[i].x2, &rs[i].y2);\n readln;\n }\n \n debug { rs.writeln; }\n \n immutable int INF = 10 ^^ 9;\n int sx1 = INF, sy1 = INF, sx2 = -INF, sy2 = -INF;\n int rectArea = rs.map!(r => (r.y2 - r.y1) * (r.x2 - r.x1)).sum;\n \n foreach (j; 0 .. 5) {\n sx1 = min(sx1, rs[j].x1);\n sy1 = min(sy1, rs[j].y1);\n sx2 = max(sx2, rs[j].x2);\n sy2 = max(sy2, rs[j].y2);\n }\n\n if (sy2 - sy1 != sx2 - sx1) { \n writeln(\"NO\");\n return;\n }\n\n int area = (sy2 - sy1) * (sx2 - sx1);\n if (area != rectArea) { \n writeln(\"NO\");\n return; \n }\n\n writeln(\"YES\");\n}"}], "src_uid": "f63fc2d97fd88273241fce206cc217f2"} {"nl": {"description": "Ralph has a magic field which is divided into n\u2009\u00d7\u2009m blocks. That is to say, there are n rows and m columns on the field. Ralph can put an integer in each block. However, the magic field doesn't always work properly. It works only if the product of integers in each row and each column equals to k, where k is either 1 or -1.Now Ralph wants you to figure out the number of ways to put numbers in each block in such a way that the magic field works properly. Two ways are considered different if and only if there exists at least one block where the numbers in the first way and in the second way are different. You are asked to output the answer modulo 1000000007\u2009=\u2009109\u2009+\u20097.Note that there is no range of the numbers to put in the blocks, but we can prove that the answer is not infinity.", "input_spec": "The only line contains three integers n, m and k (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u20091018, k is either 1 or -1).", "output_spec": "Print a single number denoting the answer modulo 1000000007.", "sample_inputs": ["1 1 -1", "1 3 1", "3 3 -1"], "sample_outputs": ["1", "1", "16"], "notes": "NoteIn the first example the only way is to put -1 into the only block.In the second example the only way is to put 1 into every block."}, "positive_code": [{"source_code": "import std.stdio, std.string, std.conv, std.algorithm, std.numeric;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\n\nimmutable long mod = 10^^9 + 7;\n\nvoid main() {\n long n, m, k;\n scan(n, m, k);\n\n if (n > m) swap(n, m);\n\n long ans = powmod(2, n - 1, mod);\n ans = powmod(ans, m - 1, mod);\n\n if (k == 1) {\n writeln(ans);\n }\n else {\n if ((n & 1) != (m & 1)) {\n writeln(0);\n }\n else {\n writeln(ans);\n }\n }\n}\n\nlong powmod(long x, long y, long mod) {\n return y > 0 ? powmod(x, y>>1, mod)^^2 % mod * x^^(y & 1) % mod : 1L;\n}\n\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}\n\n\n\nstruct Queue(T) {\n private {\n int N, head, tail;\n T[] data;\n }\n\n this(int n) {\n N = n + 1;\n data = new T[](N);\n }\n\n bool empty() {\n return head == tail;\n }\n\n bool full() {\n return (tail + 1) % N == head;\n }\n\n T front() {\n return data[head];\n }\n\n void push(T x) {\n assert(!full);\n data[tail++] = x;\n tail %= N;\n }\n\n void pop() {\n assert(!empty);\n head = (head + 1) % N;\n }\n\n void clear() {\n head = tail = 0;\n }\n}"}], "negative_code": [], "src_uid": "6b9eff690fae14725885cbc891ff7243"} {"nl": {"description": "A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase.", "input_spec": "The first line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100)\u00a0\u2014 the number of characters in the string. The second line contains the string. The string consists only of uppercase and lowercase Latin letters.", "output_spec": "Output \"YES\", if the string is a pangram and \"NO\" otherwise.", "sample_inputs": ["12\ntoosmallword", "35\nTheQuickBrownFoxJumpsOverTheLazyDog"], "sample_outputs": ["NO", "YES"], "notes": null}, "positive_code": [{"source_code": "\ufeffimport std.ascii;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\n\nbyte n, sum;\n\nvoid main() {\n\n\treadf(\" %s\\n\", &n);\n\n\tauto s = readln.strip;\n\n\tforeach (i; lowercase)\n\t\tif (find(s, i).length != 0 || find(s, std.string.toUpper(i)).length != 0)\n\t\t\t++sum;\n\n\tputs((sum == 26) ? \"YES\" : \"NO\");\n}"}, {"source_code": "\ufeffimport std.ascii;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\n\nbyte n, sum;\n\nvoid main() {\n\t\n\treadf(\" %s\\n\", &n);\n\n\tauto s = readln.strip;\n\n\tforeach (idx, el; lowercase)\n\t\tif (find(s, el).length != 0 || find(s, uppercase[idx]).length != 0)\n\t\t\t++sum;\n\t\n\tputs((sum == 26) ? \"YES\" : \"NO\");\n}"}, {"source_code": "\ufeffimport std.stdio, std.string, std.algorithm;\n\nbyte sum;\n\nvoid main() {\n\n\tint n;\n\treadf(\" %s\\n\", &n);\n\n\tstring a = readln.strip;\n\n\tforeach (immutable i; 'a' .. 'z' + 1)\n\t\tif (count(a, i) || count(a, toUpper(i)))\n\t\t\t++sum;\n\n\twriteln((sum is 26) ? \"YES\" : \"NO\");\n}"}, {"source_code": "import std.stdio;\nimport std.string;\n\nbool isPangram(string str) {\n str = str.toUpper();\n\n uint['Z'-'A'+1] seen;\n foreach (char i; str) {\n seen[i-'A']++;\n }\n\n bool result = true;\n for (int i = 0; i < seen.length && result; ++i) {\n if (seen[i] == 0) {\n result = false;\n }\n }\n\n return result;\n}\n\nunittest {\n assert(!isPangram(\"toosmallword\"));\n assert(isPangram(\"TheQuickBrownFoxJumpsOverTheLazyDog\"));\n}\n\nvoid main() {\n int len;\n string str;\n\n readf(\"%d\\n%s\\n\", &len, &str);\n\n if (isPangram(str)) {\n writeln(\"YES\");\n } else {\n writeln(\"NO\");\n }\n}"}, {"source_code": "import std.stdio: writeln, stdin;\nimport std.string: strip,tr;\nimport std.algorithm.iteration: uniq;\nimport std.algorithm.mutation: copy;\nimport std.algorithm.sorting: sort;\nimport std.array;\n\n\nvoid main()\n{\n stdin.readln;\n auto h = stdin.readln.strip.dup.tr(\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\",\"abcdefghijklmnopqrstuvwxyz\");\n auto g = cast(ubyte[])h;\n g.sort();\n writeln (g.uniq().array.length == 26 ? \"YES\" : \"NO\" );\n}"}, {"source_code": "import std.stdio;\nimport core.stdc.stdio;\nimport std.string;\n\nint main()\n{\n\treadln();\n\tint l = 'z' - 'a' + 1;\n\tstring line = readln();\n\tline = line.toLower;\n\tint[] letters; letters.length = l;\n\tint sum = 0;\n\tforeach (char x; line)\n\t{\n\t\tint idx = x - 'a';\n\t\tif (idx >= 0 && idx < l)\n\t\t{\n\t\t\tletters[idx] = 1;\n\t\t}\n\t}\n\n\tforeach (int i; 0..l) sum += letters[i];\n\twrite (sum == l ? \"YES\" : \"NO\");\n\treturn 0;\n}"}, {"source_code": "//ahmat\nimport core.stdc.stdio:scanf,printf,puts;\nimport core.bitop;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.range;\nimport std.functional;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.container;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\npragma(inline,true);\n\nvoid main(){\n import std.bitmanip:BitArray;\n BitArray b;\n int n=readln.chomp.to!int;\n string s=readln.strip.toLower;\n b.length=26;\n foreach(c;s)\n b[c-'a']=true;\n writeln(b.count<26?\"NO\":\"YES\"); \n}\n\n"}, {"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) throw new EOFException; tokens = readln.split; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, in T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, in T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp( const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nint N;\nstring S;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tN = readInt;\n\t\tS = readToken;\n\t\t\n\t\tauto app = new bool[26];\n\t\tforeach (s; S) {\n\t\t\tapp[s.toUpper - 'A'] = true;\n\t\t}\n\t\tconst ans = app.all;\n\t\twriteln(ans ? \"YES\" : \"NO\");\n\t\t\n\t}\n\t} catch (EOFException) {}\n}\n\n"}], "negative_code": [{"source_code": "import std.stdio: writeln, stdin;\nimport std.string: strip,tr;\nimport std.algorithm.searching: any;\nimport std.algorithm.iteration: filter;\nimport std.range;\nimport std.array;\n\n\nvoid main()\n{\n auto h = stdin.readln.strip.dup.tr(\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\",\"abcdefghijklmnopqrstuvwxyz\");\n auto g = cast(ubyte[])h;\n g = g.filter!\"a>=97 && a<=122\".array;\n ubyte[26] cs;\n auto a = cast(ubyte)'a';\n foreach(e;g ) cs[e-a]++;\n writeln(cs.dup.any!\"a==0\" ? \"NO\" : \"YES\");\n}"}, {"source_code": "import std.stdio: writeln, stdin;\nimport std.string: strip,tr;\nimport std.algorithm.searching: any;\nimport std.range;\nimport std.array;\n\n\nvoid main()\n{\n auto h = stdin.readln.strip.dup.tr(\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\",\"abcdefghijklmnopqrstuvwxyz\");\n ubyte[26] cs;\n auto a = cast(ubyte)'a';\n foreach(e;h ) cs[(cast(ubyte)e)-a]++;\n writeln(cs.dup.any!\"a==0\" ? \"NO\" : \"YES\");\n}"}, {"source_code": "import std.stdio: writeln, stdin;\nimport std.string: strip,tr;\nimport std.algorithm.searching: any;\nimport std.range;\nimport std.array;\n\n\nvoid main()\n{\n auto h = stdin.readln.strip.dup.tr(\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\",\"abcdefghijklmnopqrstuvwxyz\");\n auto g = cast(ubyte[])h;\n ubyte[26] cs;\n auto a = cast(ubyte)'a';\n foreach(e;h ) cs[e-a]++;\n writeln(cs.dup.any!\"a==0\" ? \"NO\" : \"YES\");\n}"}, {"source_code": "import std.stdio: writeln, stdin;\nimport std.string: strip,tr;\nimport std.algorithm.iteration: uniq;\nimport std.algorithm.mutation: copy;\nimport std.algorithm.sorting: sort;\nimport std.range;\nimport std.array;\n\n\nvoid main()\n{\n auto h = stdin.readln.strip.dup.tr(\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\",\"abcdefghijklmnopqrstuvwxyz\");\n auto g = cast(ubyte[])h;\n g.sort();\n writeln (g.uniq().array.length == 26 ? \"YES\" : \"NO\" );\n}"}, {"source_code": "import std.stdio;\nimport core.stdc.stdio;\nimport std.string;\n\nint main()\n{\n\treadln();\n\tint l = 'z' - 'a';\n\tstring line = readln();\n\tline = line.toLower;\n\tint[] letters; letters.length = l;\n\tint sum = 0;\n\tforeach (char x; line)\n\t{\n\t\tint idx = x - 'a';\n\t\tif (idx >= 0 && idx < l)\n\t\t{\n\t\t\tletters[idx] = 1;\n\t\t}\n\t}\n\n\tforeach (int i; 0..l) sum += letters[i];\n\twrite (sum == l ? \"YES\" : \"NO\");\n\treturn 0;\n}"}], "src_uid": "f13eba0a0fb86e20495d218fc4ad532d"} {"nl": {"description": "Bizon the Champion is called the Champion for a reason. Bizon the Champion has recently got a present \u2014 a new glass cupboard with n shelves and he decided to put all his presents there. All the presents can be divided into two types: medals and cups. Bizon the Champion has a1 first prize cups, a2 second prize cups and a3 third prize cups. Besides, he has b1 first prize medals, b2 second prize medals and b3 third prize medals. Naturally, the rewards in the cupboard must look good, that's why Bizon the Champion decided to follow the rules: any shelf cannot contain both cups and medals at the same time; no shelf can contain more than five cups; no shelf can have more than ten medals. Help Bizon the Champion find out if we can put all the rewards so that all the conditions are fulfilled.", "input_spec": "The first line contains integers a1, a2 and a3 (0\u2009\u2264\u2009a1,\u2009a2,\u2009a3\u2009\u2264\u2009100). The second line contains integers b1, b2 and b3 (0\u2009\u2264\u2009b1,\u2009b2,\u2009b3\u2009\u2264\u2009100). The third line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100). The numbers in the lines are separated by single spaces.", "output_spec": "Print \"YES\" (without the quotes) if all the rewards can be put on the shelves in the described manner. Otherwise, print \"NO\" (without the quotes).", "sample_inputs": ["1 1 1\n1 1 1\n4", "1 1 3\n2 3 4\n2", "1 0 0\n1 0 0\n1"], "sample_outputs": ["YES", "YES", "NO"], "notes": null}, "positive_code": [{"source_code": "import std.stdio;\nimport std.c.stdio;\nimport std.range;\nimport std.array;\nimport std.functional;\nimport std.algorithm;\nimport std.conv;\nimport std.container;\nimport std.math;\nimport std.numeric;\nimport std.string;\nimport std.c.string;\nimport std.regex;\nimport std.typecons;\n \nvoid main() {\n int a = readln.chomp.split(\" \").map!(to!int).array.reduce!\"a + b\";\n int b = readln.chomp.split(\" \").map!(to!int).array.reduce!\"a + b\";\n int n; scanf(\"%d\\n\", &n);\n\n int x = (a + 4) / 5 + (b + 9) / 10;\n writeln( x <= n ? \"YES\" : \"NO\" );\n}\n"}, {"source_code": "import std.stdio;\nimport core.stdc.stdio;\nimport std.algorithm;\nimport std.math;\nimport std.array;\n\nint main(string[] argv)\n{\n\tint[] a; a.length = 3;\n\tint[] b; b.length = 3;\n\tint n;\n\tscanf(\"%d %d %d\\n%d %d %d\\n%d\", &a[0], &a[1], &a[2], &b[0], &b[1], &b[2], &n);\n\tint as = a[0] + a[1] + a[2];\n\tint bs = b[0] + b[1] + b[2];\n\tint ts = as / 5 + (as % 5 == 0 ? 0 : 1) + bs / 10 + (bs % 10 == 0 ? 0 : 1);\n\twrite (ts <= n ? \"YES\" : \"NO\");\n\treturn 0;\n}"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.bigint;\nimport std.array;\nimport std.ascii;\nimport std.math;\nimport std.numeric;\nimport std.algorithm;\nimport std.container;\nimport core.bitop;\nimport std.conv;\n\nalias Int = long;\n\nvoid main() {\n Int a = readln.split.map!(to!Int).reduce!((a, b) => a + b);\n Int b = readln.split.map!(to!Int).reduce!((a, b) => a + b);\n int n = readln.split.map!(to!int).array[0];\n debug writeln(a);\n debug writeln(b);\n debug writeln(n);\n\n auto rem = new Int[n];\n\n {\n rem[] = 5;\n while ( a > 0 && ! rem.empty ) {\n if ( rem.empty ) {\n writeln(\"NO\");\n return;\n }\n auto d = min(a, 5);\n a -= d;\n rem.front -= d;\n if ( rem.front <= 0 ) {\n rem.popFront();\n }\n }\n if ( ! rem.empty && rem.front < 5 ) {\n rem.popFront();\n }\n }\n\n debug writeln(rem);\n\n {\n rem[] = 10;\n while ( b > 0 && ! rem.empty ) {\n if ( rem.empty ) {\n writeln(\"NO\");\n return;\n }\n auto d = min(b, 10);\n b -= d;\n rem.front -= d;\n if ( rem.front <= 0 ) {\n rem.popFront();\n }\n }\n if ( ! rem.empty && rem.front < 10 ) {\n rem.popFront();\n }\n }\n\n if ( a > 0 || b > 0 ) {\n writeln(\"NO\");\n } else {\n writeln(\"YES\"); \n }\n}\n"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.math;\n\nvoid main() {\n auto a = readln.chomp.split.map!(to!double).reduce!(\"a + b\");\n auto b = readln.chomp.split.map!(to!double).reduce!(\"a + b\");\n auto n = readln.chomp.to!double;\n\n if ((a / 5).ceil + (b / 10).ceil <= n)\n writeln(\"YES\");\n else\n writeln(\"NO\");\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm;\n\nvoid main(){\n int[3] as;\n int[3] bs;\n int n;\n for(int i = 0; i < 3; i++){\n int t;\n readf(\"%s \",&t);\n as[i] = t;\n }\n for(int i = 0; i < 3; i++){\n int t;\n readf(\"%s \",&t);\n bs[i] = t;\n }\n readf(\"%s \",&n);\n if (run(as,bs,n) == 0){\n writefln(\"NO\");\n return;\n }\n writefln(\"YES\");\n}\n\nint suma(int[] x){\n int sum = 0;\n foreach(v;x){\n sum += v;\n }\n return sum;\n}\n\nint run(int[] a, int[] b, int n){\n int sa = suma(a);\n int sb = suma(b);\n int pa = (sa / 5);\n int pb = (sb / 10);\n if (sa % 5 != 0){\n pa++;\n }\n if (sb % 10 != 0){\n pb++;\n }\n if (pa + pb > n){\n return 0;\n }\n return 1;\n}\n\n// TEST CASE AREA\nvoid test_case(){\n int[][] rs;\n\n rs ~= [run([1,1,1],[1,1,1],4),1];\n rs ~= [run([1,1,3],[2,3,4],2),1];\n rs ~= [run([1,0,0],[1,0,0],1),0];\n\n array_assert(rs);\n}\n\nvoid array_assert(int[][] rs){\n uint i = 1;\n bool failed = false;\n\n writefln(\"TEST\");\n\n foreach(int[] r;rs){\n if(r[0] != r[1]){\n failed = true;\n writefln(\"%s Failed %s is NOT %s\",i,r[0],r[1]);\n }\n i++;\n }\n\n if(!failed){\n writefln(\"OK\");\n }\n}\n\nuint[][] numerate(uint[] l){\n uint n = 0;\n uint[][] nl;\n\n foreach(uint x; l){\n nl ~= [x,n];\n n++;\n }\n\n return nl;\n}\n"}, {"source_code": "import std.stdio;\nimport std.c.stdio;\nimport std.algorithm;\nint main(string[] argv)\n{\n\tint a1,a2,a3,b1,b2,b3,n;\n\tscanf(\"%d\",&a1);\n\tscanf(\"%d\",&a2);\n\tscanf(\"%d\",&a3);\n\tscanf(\"%d\",&b1);\n\tscanf(\"%d\",&b2);\n\tscanf(\"%d\",&b3);\n\tscanf(\"%d\",&n);\n\twriteln(((a1+a2+a3+4)/5+(b1+b2+b3+9)/10)<=n? \"YES\":\"NO\");\n return 0;\n}\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.bigint;\nimport std.array;\nimport std.ascii;\nimport std.math;\nimport std.numeric;\nimport std.algorithm;\nimport std.container;\nimport core.bitop;\nimport std.conv;\n\nalias Int = long;\n\nvoid main() {\n Int a = readln.split.map!(to!Int).reduce!((a, b) => a + b);\n Int b = readln.split.map!(to!Int).reduce!((a, b) => a + b);\n int n = readln.split.map!(to!int).array[0];\n debug writeln(a);\n debug writeln(b);\n debug writeln(n);\n\n auto rem = new Int[n];\n\n {\n rem[] = 5;\n while ( a > 0 ) {\n if ( rem.empty ) {\n writeln(\"NO\");\n return;\n }\n auto d = min(a, 5);\n a -= d;\n rem.front -= d;\n if ( rem.front <= 0 ) {\n rem.popFront();\n }\n }\n if ( rem.front < 5 ) {\n rem.popFront();\n }\n }\n\n debug writeln(rem);\n\n {\n rem[] = 10;\n while ( b > 0 ) {\n if ( rem.empty ) {\n writeln(\"NO\");\n return;\n }\n auto d = min(b, 10);\n b -= d;\n rem.front -= d;\n if ( rem.front <= 0 ) {\n rem.popFront();\n }\n }\n if ( rem.front < 10 ) {\n rem.popFront();\n }\n }\n\n writeln(\"YES\");\n}\n"}], "src_uid": "fe6301816dea7d9cea1c3a06a7d1ea7e"} {"nl": {"description": "Numbers k-bonacci (k is integer, k\u2009>\u20091) are a generalization of Fibonacci numbers and are determined as follows: F(k,\u2009n)\u2009=\u20090, for integer n, 1\u2009\u2264\u2009n\u2009<\u2009k; F(k,\u2009k)\u2009=\u20091; F(k,\u2009n)\u2009=\u2009F(k,\u2009n\u2009-\u20091)\u2009+\u2009F(k,\u2009n\u2009-\u20092)\u2009+\u2009...\u2009+\u2009F(k,\u2009n\u2009-\u2009k), for integer n, n\u2009>\u2009k. Note that we determine the k-bonacci numbers, F(k,\u2009n), only for integer values of n and k.You've got a number s, represent it as a sum of several (at least two) distinct k-bonacci numbers. ", "input_spec": "The first line contains two integers s and k (1\u2009\u2264\u2009s,\u2009k\u2009\u2264\u2009109;\u00a0k\u2009>\u20091).", "output_spec": "In the first line print an integer m (m\u2009\u2265\u20092) that shows how many numbers are in the found representation. In the second line print m distinct integers a1,\u2009a2,\u2009...,\u2009am. Each printed integer should be a k-bonacci number. The sum of printed integers must equal s. It is guaranteed that the answer exists. If there are several possible answers, print any of them.", "sample_inputs": ["5 2", "21 5"], "sample_outputs": ["3\n0 2 3", "3\n4 1 16"], "notes": null}, "positive_code": [{"source_code": "import std.conv;\nimport std.string;\nimport std.functional;\nimport std.stdio;\nimport std.algorithm;\n\nint main() {\n\tint fib(int n, int k) {\n\t\talias memoize!fib mfib;\n\t\tif (n < k)\n\t\t\treturn 0;\n\t\telse if (n == k)\n\t\t\treturn 1;\n\t\telse {\n\t\t\tint ans = 0;\n\t\t\tfor (int j = max(k, n - k); j <= n - 1; ++j)\n\t\t\t\tans += mfib(j, k);\n\t\t\treturn ans;\n\t\t}\n\t}\n\tauto tmp = split(strip(readln()), \" \");\n\tauto s = to!int(tmp[0]);\n\tauto k = to!int(tmp[1]);\n\tint[] ans = [];\n\twhile (s > 0) {\n\t\tint cnt = k;\n\t\twhile (fib(cnt, k) <= s)\n\t\t\t++cnt;\n\t\t--cnt;\n\t\tans ~= fib(cnt, k);\n\t\ts -= fib(cnt, k);\n\t}\n\tif (ans.length == 1)\n\t\tans ~= 0;\n\twriteln(ans.length);\n\tforeach (int i; ans)\n\t\twrite(i, \" \");\n\treturn 0;\n}"}, {"source_code": "import std.conv;\nimport std.string;\nimport std.functional;\nimport std.stdio;\nimport std.algorithm;\n\nint main() {\n\tulong fib(ulong n, ulong k) {\n\t\talias memoize!fib mfib;\n\t\tif (n < k)\n\t\t\treturn 0;\n\t\telse if (n == k)\n\t\t\treturn 1;\n\t\telse {\n\t\t\tulong ans = 0;\n\t\t\tfor (ulong j = max(k, n - k); j <= n - 1; ++j)\n\t\t\t\tans += mfib(j, k);\n\t\t\treturn ans;\n\t\t}\n\t}\n\tauto tmp = split(strip(readln()), \" \");\n\tauto s = to!ulong(tmp[0]);\n\tauto k = to!ulong(tmp[1]);\n\tulong[] ans = [];\n\twhile (s > 0) {\n\t\tulong cnt = k;\n\t\twhile (fib(cnt, k) <= s)\n\t\t\t++cnt;\n\t\t--cnt;\n\t\tans ~= fib(cnt, k);\n\t\ts -= fib(cnt, k);\n\t}\n\tif (ans.length == 1)\n\t\tans ~= 0;\n\twriteln(ans.length);\n\tforeach (ulong i; ans)\n\t\twrite(i, \" \");\n\treturn 0;\n}"}, {"source_code": "import std.conv;\nimport std.string;\nimport std.functional;\nimport std.stdio;\nimport std.algorithm;\n\nint main() {\n\tulong fib(ulong n, ulong k, ulong max) {\n\t\talias memoize!fib mfib;\n\t\tif (n < k)\n\t\t\treturn 0;\n\t\telse if (n == k)\n\t\t\treturn 1;\n\t\telse {\n\t\t\tulong ans = 0;\n\t\t\tfor (ulong j = std.algorithm.max(k, n - k); (ans <= max) & (j <= n - 1); ++j) {\n\t\t\t\tans += mfib(j, k, max);\n\t\t\t\tif (ans > max) \n\t\t\t\t\treturn max + 1;\n\t\t\t}\n\t\t\treturn ans;\n\t\t}\n\t}\n\tauto tmp = split(strip(readln()), \" \");\n\tauto s = to!ulong(tmp[0]);\n\tauto k = to!ulong(tmp[1]);\n\t/*ulong ke = k;\n\twhile (fib(ke, k, s) <= s) {\n\t\twrite(fib(ke, k, s), \" \");\n\t\t++ke;\n\t}\n\twriteln();*/\n\tulong[] ans = [];\n\tauto s0 = s;\n\twhile (s > 0) {\n\t\tulong cnt = k;\n\t\twhile (fib(cnt, k, s0) <= s)\n\t\t\t++cnt;\n\t\t--cnt;\n\t\tans ~= fib(cnt, k, s0);\n\t\ts -= fib(cnt, k, s0);\n\t}\n\tif (ans.length == 1)\n\t\tans ~= 0;\n\twriteln(ans.length);\n\tforeach (ulong i; ans)\n\t\twrite(i, \" \");\n\treturn 0;\n}"}, {"source_code": "import std.conv;\nimport std.string;\nimport std.functional;\nimport std.stdio;\nimport std.algorithm;\n\nint main() {\n\tuint fib(uint n, uint k) {\n\t\talias memoize!fib mfib;\n\t\tif (n < k)\n\t\t\treturn 0;\n\t\telse if (n == k)\n\t\t\treturn 1;\n\t\telse {\n\t\t\tuint ans = 0;\n\t\t\tfor (uint j = max(k, n - k); j <= n - 1; ++j)\n\t\t\t\tans += mfib(j, k);\n\t\t\treturn ans;\n\t\t}\n\t}\n\tauto tmp = split(strip(readln()), \" \");\n\tauto s = to!uint(tmp[0]);\n\tauto k = to!uint(tmp[1]);\n\tuint[] ans = [];\n\twhile (s > 0) {\n\t\tuint cnt = k;\n\t\twhile (fib(cnt, k) <= s)\n\t\t\t++cnt;\n\t\t--cnt;\n\t\tans ~= fib(cnt, k);\n\t\ts -= fib(cnt, k);\n\t}\n\tif (ans.length == 1)\n\t\tans ~= 0;\n\twriteln(ans.length);\n\tforeach (uint i; ans)\n\t\twrite(i, \" \");\n\treturn 0;\n}"}], "negative_code": [], "src_uid": "da793333b977ed179fdba900aa604b52"} {"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\u2009+\u2009s, t\u2009+\u2009s\u2009+\u20091, t\u2009+\u20092s, t\u2009+\u20092s\u2009+\u20091, 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\u2009\u2264\u2009t,\u2009x\u2009\u2264\u2009109, 2\u2009\u2264\u2009s\u2009\u2264\u2009109)\u00a0\u2014 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": "module main;\nimport std.bigint,std.container,std.array,std.algorithm,std.conv,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.variant;\nimport core.stdc.stdio : freopen;\nimport core.stdc.stdlib : system;\nimport std.stdio;\n//import core.stdc.stdio;\nalias RedBlackTree Rbt;\nalias redBlackTree rbt;\nalias BigInt big;\nalias pair!(int,int) pii;\nalias pair!(long,long) pll;\nalias BoyerMooreFinder strfind;\nalias mp=make_pair;\nalias bins=binary_search;\nalias orsq=orient_square;\nimmutable int mod=1000000007;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b)\n\t{\n\t\treturn a/gcd(a,b)*b;\n\t}\n\tX binpow(X,Y)(X base,Y exp)\n\t\tif(is(typeof(exp&1)))\n\t{\n\t\tif(exp<0)return X(0);\n\t\tX res=X(1);\n\t\twhile(exp>0)\n\t\t{\n\t\t\tif(exp&1)res*=base;\n\t\t\tbase*=base;\n\t\t\texp>>=1;\n\t\t}\n\t\treturn res;\n\t}\n\tauto binpow(X,Y,Z)(X base,Y exp,in Z mm)\n\t\tif(is(typeof(exp&1)))\n\t{\n\t\tif(mm==0) return binpow(base,exp);\n\t\tif(exp<0)return X(0);\n\t\tauto res=X(1)%mm;\n\t\twhile(exp>0)\n\t\t{\n\t\t\tif(exp&1)res=(res*base)%mm;\n\t\t\tbase*=base;\n\t\t\tbase%=mm;\n\t\t\texp>>=1;\n\t\t}\n\t\treturn res;\n\t}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tsize_t lowb(T,X)(in T a,auto ref X g) \n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 0)\n{return readf(replicate(\" %s\", ptrs.length), ptrs)==ptrs.length;}\nstruct pair(X,Y)\n{\n\tX first;\n\tY second;\n\talias first fi;\n\talias second se;\n\tthis(X a_,Y b_){\n\t\tfi=a_;\n\t\tse=b_;\n\t}\n\tthis(this){fi=fi;se=se;}\n\tthis(A,B)(auto ref pair!(A,B) p) if(is(A:X) && is(B:Y))\n\t{\n\t\tfi=p.fi;\n\t\tse=p.se;\n\t}\n\tpair!(X,Y) opAssign(A,B)(pair!(A,B) val)\n\t{\n\t\treturn this=pair!(X,Y)(val);\n\t}\n\tint opCmp(A,B)(in pair!(A,B) s_) const pure nothrow @safe \n\t\tif(is(typeof(s_.fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.se));\n\t}\n};\npair!(X,Y) make_pair(X,Y)(in X x_,in Y y_) pure nothrow @safe\n{\n\tpair!(X,Y) pp;\n\tpp.fi=x_;\n\tpp.se=y_;\n\treturn pp;\n}\nnothrow void inf(in char* name) {freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow void ouf(in char* name) {freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.split.map!(to!(T)).array;}\nstruct Tree(T,alias arg=\"a+b\")\n{\n\tprivate alias fun=binaryFun!arg;\n\tprivate static const size_t n=size_t.max>>1;\n\tprivate T[size_t] t;\n\tthis(this){t=t.dup;}\n\tthis(R)(R range) if(isInputRange!R && is(ElementType!(R) : T))\n\t{\n\t\tforeach(pos,i;range) upd(pos,i);\n\t}\n\tthis(R,alias f)(Tree!(R,f) q) if(is(R:T))\n\t{\n\t\tforeach(i,j;q.t)\n\t\t{\n\t\t\tt[i]=j;\n\t\t}\n\t}\n\tTree!(T,arg) opAssign(R)(R val)\n\t{\n\t\treturn this=Tree!(T,arg)(val);\n\t}\n\tprivate void upd(in size_t v,in size_t vl,in size_t vr,in size_t i,in T x)\n\t{\n\t\tif (vr - vl == 1){t[v] = x;return;}\n\t\tsize_t vm = (vl + vr) >> 1;\n\t\tif(i < vm) upd(2*v, vl, vm, i, x);\n\t\telse upd(2*v+1, vm, vr, i, x);\n\t\tif(v*2+1 !in t)t[v]=t[v*2];\n\t\telse if (v*2 !in t)t[v]=t[v*2+1];\n\t\telse t[v]=fun(t[v*2],t[v*2+1]);\n\t}\n\tvoid upd(in size_t i,in T x)\n\t{\n\t\tupd(1,0,n,i,x);\n\t}\n\tprivate T cel(in size_t v,in size_t vl,in size_t vr,in size_t l,in size_t r)\n\t{\n\t\tif(vl==l && r==vr) return t[v];\n\t\tsize_t vm=(vl+vr) >> 1;\n\t\tif(r<=vm) return cel(2*v,vl,vm,l,r);\n\t\telse if(l>=vm) return cel(2*v+1,vm,vr,l,r);\n\t\telse return fun(cel(2*v,vl,vm,l,vm),cel(2*v+1,vm,vr,vm,r));\n\t}\n\tT cel(in size_t l,in size_t r){return cel(1,0,n,l,r);}\n};\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold schwartzSort multiSort partialSort heapify join filter countUntil\n//---------------------------------------------------------------program beginning-----------------------------------------------------------------\n\nvoid main()\n{\n\tint t,x,s;\n\tloop:while(input(&t,&s,&x))\n\t{\n\t\tif(x==t ||(x>=t+s && (x-t)%s<=1))writeln(\"YES\");\n\t\telse writeln(\"NO\");\n\t}\n}"}, {"source_code": "\nimport std.stdio;\n\nvoid main() {\n // writeln(\"hello world!\");\n // int[3] A;\n // foreach (i; 0 .. 3) {\n // readf(\" %s\", &A[i]);\n // }\n // writeln(A);\n // write(A, \"\\n\");\n // writefln(\"%(%s %)\", A);\n int t, s, x;\n readf(\" %s %s %s\\n\", &t, &s, &x);\n // writeln(n, x, y);\n if (t == x) {\n writeln(\"YES\");\n return;\n }\n foreach(k; 1 .. (x + s) / s) {\n if (t + k * s == x || t + k * s + 1 == x) {\n writeln(\"YES\");\n return;\n }\n }\n writeln(\"NO\");\n}\n"}], "negative_code": [{"source_code": "\nimport std.stdio;\n\nvoid main() {\n // writeln(\"hello world!\");\n // int[3] A;\n // foreach (i; 0 .. 3) {\n // readf(\" %s\", &A[i]);\n // }\n // writeln(A);\n // write(A, \"\\n\");\n // writefln(\"%(%s %)\", A);\n int t, s, x;\n readf(\" %s %s %s\\n\", &t, &x, &s);\n // writeln(n, x, y);\n if (t == x) {\n writeln(\"YES\");\n return;\n }\n foreach(k; 1 .. (x + s) / s) {\n if (t + k * s == x || t + k * s + 1 == x) {\n writeln(\"YES\");\n return;\n }\n }\n writeln(\"NO\");\n}\n"}], "src_uid": "3baf9d841ff7208c66f6de1b47b0f952"} {"nl": {"description": "There are well-known formulas: , , . Also mathematicians found similar formulas for higher degrees.Find the value of the sum modulo 109\u2009+\u20097 (so you should find the remainder after dividing the answer by the value 109\u2009+\u20097).", "input_spec": "The only line contains two integers n,\u2009k (1\u2009\u2264\u2009n\u2009\u2264\u2009109,\u20090\u2009\u2264\u2009k\u2009\u2264\u2009106).", "output_spec": "Print the only integer a \u2014 the remainder after dividing the value of the sum by the value 109\u2009+\u20097.", "sample_inputs": ["4 1", "4 2", "4 3", "4 0"], "sample_outputs": ["10", "30", "100", "4"], "notes": null}, "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n// a^-1 (mod m)\nlong modInv(long a, long m)\nin {\n assert(m > 0, \"modInv: m > 0 must hold\");\n}\ndo {\n long b = m, x = 1, y = 0, t;\n for (; ; ) {\n t = a / b;\n a -= t * b;\n if (a == 0) {\n assert(b == 1 || b == -1, \"modInv: gcd(a, m) != 1\");\n if (b == -1) {\n y = -y;\n }\n return (y < 0) ? (y + m) : y;\n }\n x -= t * y;\n t = b / a;\n b -= t * a;\n if (b == 0) {\n assert(a == 1 || a == -1, \"modInv: gcd(a, m) != 1\");\n if (a == -1) {\n x = -x;\n }\n return (x < 0) ? (x + m) : x;\n }\n y -= t * x;\n }\n}\n\n\nenum MO = 10L^^9 + 7;\nenum LIM = 3 * 10^^6;\n\nlong[] inv, fac, invFac;\nvoid prepare() {\n inv = new long[LIM];\n fac = new long[LIM];\n invFac = new long[LIM];\n inv[1] = 1;\n foreach (i; 2 .. LIM) {\n inv[i] = MO - ((MO / i) * inv[cast(size_t)(MO % i)]) % MO;\n }\n fac[0] = invFac[0] = 1;\n foreach (i; 1 .. LIM) {\n fac[i] = (fac[i - 1] * i) % MO;\n invFac[i] = (invFac[i - 1] * inv[i]) % MO;\n }\n}\nlong binom(long n, long k) {\n if (0 <= k && k <= n) {\n assert(n < LIM);\n return fac[cast(size_t)(n)] * invFac[cast(size_t)(k)] % MO * invFac[cast(size_t)(n - k)] % MO;\n } else {\n return 0;\n }\n}\n\n\nlong power(long a, long e) {\n long x = a % MO, y = 1;\n for (; e; e >>= 1) {\n if (e & 1) {\n y = (y * x) % MO;\n }\n x = (x * x) % MO;\n }\n return y;\n}\n\nlong N;\nint K;\n\nvoid main() {\n prepare();\n try {\n for (; ; ) {\n N = readLong();\n K = readInt();\n \n auto f = new long[K + 2];\n f[0] = 0;\n foreach (i; 1 .. K + 2) {\n f[i] = (f[i - 1] + power(i, K)) % MO;\n }\n \n bool zero;\n long prod = 1;\n foreach (i; 0 .. K + 2) {\n const d = (N - i) % MO;\n if (d == 0) {\n zero = true;\n } else {\n prod *= d;\n prod %= MO;\n }\n }\n debug {\n writeln(\"zero = \", zero, \", prod = \", prod);\n }\n \n long ans;\n foreach (i; 0 .. K + 2) {\n const d = (N - i) % MO;\n long tmp = f[i];\n if (zero) {\n tmp *= ((d == 0) ? prod : 0);\n tmp %= MO;\n } else {\n tmp *= prod;\n tmp %= MO;\n tmp *= modInv(d, MO);\n tmp %= MO;\n }\n tmp *= invFac[i];\n tmp %= MO;\n tmp *= invFac[K + 1 - i];\n tmp %= MO;\n tmp *= (((K + 1 - i) % 2 != 0) ? -1 : +1);\n tmp %= MO;\n ans += tmp;\n ans %= MO;\n }\n ans = (ans % MO + MO) % MO;\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "6f6fc42a367cdce60d76fd1914e73f0c"} {"nl": {"description": "Vasya will fancy any number as long as it is an integer power of two. Petya, on the other hand, is very conservative and only likes a single integer $$$p$$$ (which may be positive, negative, or zero). To combine their tastes, they invented $$$p$$$-binary numbers of the form $$$2^x + p$$$, where $$$x$$$ is a non-negative integer.For example, some $$$-9$$$-binary (\"minus nine\" binary) numbers are: $$$-8$$$ (minus eight), $$$7$$$ and $$$1015$$$ ($$$-8=2^0-9$$$, $$$7=2^4-9$$$, $$$1015=2^{10}-9$$$).The boys now use $$$p$$$-binary numbers to represent everything. They now face a problem: given a positive integer $$$n$$$, what's the smallest number of $$$p$$$-binary numbers (not necessarily distinct) they need to represent $$$n$$$ as their sum? It may be possible that representation is impossible altogether. Help them solve this problem.For example, if $$$p=0$$$ we can represent $$$7$$$ as $$$2^0 + 2^1 + 2^2$$$.And if $$$p=-9$$$ we can represent $$$7$$$ as one number $$$(2^4-9)$$$.Note that negative $$$p$$$-binary numbers are allowed to be in the sum (see the Notes section for an example).", "input_spec": "The only line contains two integers $$$n$$$ and $$$p$$$ ($$$1 \\leq n \\leq 10^9$$$, $$$-1000 \\leq p \\leq 1000$$$).", "output_spec": "If it is impossible to represent $$$n$$$ as the sum of any number of $$$p$$$-binary numbers, print a single integer $$$-1$$$. Otherwise, print the smallest possible number of summands.", "sample_inputs": ["24 0", "24 1", "24 -1", "4 -7", "1 1"], "sample_outputs": ["2", "3", "4", "2", "-1"], "notes": "Note$$$0$$$-binary numbers are just regular binary powers, thus in the first sample case we can represent $$$24 = (2^4 + 0) + (2^3 + 0)$$$.In the second sample case, we can represent $$$24 = (2^4 + 1) + (2^2 + 1) + (2^0 + 1)$$$.In the third sample case, we can represent $$$24 = (2^4 - 1) + (2^2 - 1) + (2^2 - 1) + (2^2 - 1)$$$. Note that repeated summands are allowed.In the fourth sample case, we can represent $$$4 = (2^4 - 7) + (2^1 - 7)$$$. Note that the second summand is negative, which is allowed.In the fifth sample case, no representation is possible."}, "positive_code": [{"source_code": "\n\n import core.bitop, std.bitmanip;\n import core.checkedint;\n import std.algorithm, std.functional;\n import std.array, std.container;\n import std.bigint;\n import std.conv;\n import std.math, std.numeric;\n import std.range, std.range.interfaces;\n import std.stdio, std.string;\n import std.typecons;\n \n void main()\n { \n int n, p;\n readf(\"%s %s\", &n, &p);\n readln;\n \n foreach (k; 1 .. 32) {\n long s = k.to!long * p;\n long nn = n.to!long - s;\n \n if (nn == 0) {\n continue;\n }\n \n int pcnt = nn > 0 ? nn.popcnt() : (-nn).popcnt();\n if (pcnt <= k && nn >= k) {\n writeln(k);\n return;\n }\n }\n \n writeln(-1);\n return;\n }"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nT[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto p = RD!int;\n\tint ans = -1;\n\tforeach (i; 1..33)\n\t{\n\t\tauto x = n - i * p;\n\t\tint cnt, cnt_max;\n\t\tforeach (j; 0..32)\n\t\t{\n\t\t\tauto bit = 1L << j;\n\t\t\tif (x & bit)\n\t\t\t{\n\t\t\t\t++cnt;\n\t\t\t\tcnt_max += 2^^j;\n\t\t\t}\n\t\t}\n\t\tdebug writeln(\"i:\", i, \" x:\", x, \" cnt:\", cnt);\n\t\tif (i >= cnt && i <= cnt_max)\n\t\t{\n\t\t\tans = i;\n\t\t\tbreak;\n\t\t}\n\t}\n\n\twriteln(ans);\n\tstdout.flush();\n\tdebug readln();\n}"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nenum LIM = 10^^5;\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readLong();\n const P = readLong();\n \n int ans = LIM;\n foreach (k; 0 .. LIM) {\n const m = N - k * P;\n if (m >= 0) {\n if (popcnt(m) <= k && k <= m) {\n chmin(ans, k);\n }\n }\n }\n writeln((ans >= LIM) ? -1 : ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n \nvoid main()\n{ \n int n, p;\n readf(\"%s %s\", &n, &p);\n readln;\n\n foreach (k; 1 .. n/2 + 2) {\n long s = k.to!long * p;\n long nn = n.to!long - s;\n \n if (nn == 0) {\n continue;\n }\n \n int pcnt = nn > 0 ? nn.popcnt() : (-nn).popcnt();\n if (pcnt <= k && nn >= k) {\n writeln(k);\n return;\n }\n }\n \n writeln(-1);\n return;\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n \nvoid main()\n{ \n int n, p;\n readf(\"%s %s\", &n, &p);\n readln;\n\n foreach (k; 1 .. n/2 + 2) {\n int s = k * p;\n long nn = n - s;\n \n if (nn == 0) {\n continue;\n }\n \n int pcnt = nn > 0 ? nn.popcnt() : (-nn).popcnt();\n if (pcnt <= k && nn >= k) {\n writeln(k);\n return;\n }\n }\n \n writeln(-1);\n return;\n}"}, {"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n \nvoid main()\n{ \n int n, p;\n readf(\"%s %s\", &n, &p);\n readln;\n\n foreach (k; 1 .. n/2 + 2) {\n int s = k * p;\n long nn = n - s;\n \n if (nn > 0 && (nn > 0 ? nn.popcnt() : (-nn).popcnt()) <= k) {\n writeln(k);\n return;\n }\n }\n \n writeln(-1);\n return;\n}"}], "src_uid": "9e86d87ce5a75c6a982894af84eb4ba8"} {"nl": {"description": "Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xenia. She is only beginning to count, so she can calculate a sum only if the summands follow in non-decreasing order. For example, she can't calculate sum 1+3+2+1 but she can calculate sums 1+1+2 and 3+3.You've got the sum that was written on the board. Rearrange the summans and print the sum in such a way that Xenia can calculate the sum.", "input_spec": "The first line contains a non-empty string s \u2014 the sum Xenia needs to count. String s contains no spaces. It only contains digits and characters \"+\". Besides, string s is a correct sum of numbers 1, 2 and 3. String s is at most 100 characters long.", "output_spec": "Print the new sum that Xenia can count.", "sample_inputs": ["3+2+1", "1+1+3+1+3", "2"], "sample_outputs": ["1+2+3", "1+1+1+3+3", "2"], "notes": null}, "positive_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\nimport std.algorithm;\nimport std.array;\n\nvoid main(){\n auto s = readln.strip.split(\"+\").map!(e => e.strip).array;\n s.sort.join(\"+\").writeln;\n}"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.range;\n\nvoid main()\n{\n readln\n .strip\n .splitter(\"+\")\n .array\n .sort\n .joiner(\"+\")\n .writeln;\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm.comparison : equal;\nimport std.uni;\nimport std.array;\nimport std.algorithm;\n\nint main(string[] argv)\n{\n\tstring line = stdin.readln();\n\tif (line[line.length - 1] == '\\n')\n\t\tline.length--;\n\n\tstring[] nums = split(line, \"+\");\n\tnums.sort();\n\twritef(\"%s\", nums[0]);\n\tfor (int i = 1; i < nums.length; i++)\n\t{\n\t\twritef(\"+%s\", nums[i]);\n\t}\n\treturn 0;\n}\n"}, {"source_code": "import std.stdio;\nimport std.array;\nimport std.algorithm;\n\nint main() {\n auto s = stdin.byLine;\n foreach (line; s) {\n auto arr = line.split(\"+\");\n writeln(arr.sort().join(\"+\"));\n }\n return 0;\n}"}, {"source_code": "import std.stdio;\n\nvoid main(string[] args) {\n string data = std.stdio.readln();\n data = std.string.stripRight(data);\n\n auto words = std.string.split(data, \"+\");\n \n std.algorithm.sort(words);\n\n auto answer = std.string.join(words, \"+\");\n //foreach(word; words) {\n // std.stdio.writeln(word);\n //}\n\n std.stdio.writeln(answer);\n}\n"}, {"source_code": "// https://codeforces.com/problemset/problem/339/A\nimport std.algorithm;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n readln.strip.splitter(\"+\").array.sort.joiner(\"+\").writeln;\n}\n\n"}, {"source_code": "//ahmat\nimport core.stdc.stdio:scanf,printf,puts;\nimport core.bitop;\nimport std.stdio;\nimport std.string;\nimport std.ascii;\nimport std.algorithm;\nimport std.range;\nimport std.functional;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.container;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\npragma(inline,true);\n\nvoid main(){\n readln.split.to!(char[]).filter!isDigit.map!\"a-'0'\".array.sort.writefln!\"%(%d+%)\";\n}\n\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.string;\nimport std.regex;\n\nvoid main() {\n readln.chomp.split(\"+\").sort.join(\"+\").writeln;\n}\n"}], "negative_code": [], "src_uid": "76c7312733ef9d8278521cf09d3ccbc8"} {"nl": {"description": "Igor the analyst is at work. He learned about a feature in his text editor called \"Replace All\". Igor is too bored at work and thus he came up with the following problem:Given two strings x and y which consist of the English letters 'A' and 'B' only, a pair of strings (s,\u2009t) is called good if: s and t consist of the characters '0' and '1' only. 1\u2009\u2264\u2009|s|,\u2009|t|\u2009\u2264\u2009n, where |z| denotes the length of string z, and n is a fixed positive integer. If we replace all occurrences of 'A' in x and y with the string s, and replace all occurrences of 'B' in x and y with the string t, then the two obtained from x and y strings are equal. For example, if x\u2009=\u2009AAB, y\u2009=\u2009BB and n\u2009=\u20094, then (01, 0101) is one of good pairs of strings, because both obtained after replacing strings are \"01010101\".The flexibility of a pair of strings x and y is the number of pairs of good strings (s,\u2009t). The pairs are ordered, for example the pairs (0, 1) and (1, 0) are different.You're given two strings c and d. They consist of characters 'A', 'B' and '?' only. Find the sum of flexibilities of all possible pairs of strings (c',\u2009d') such that c' and d' can be obtained from c and d respectively by replacing the question marks with either 'A' or 'B', modulo 109\u2009+\u20097.", "input_spec": "The first line contains the string c (1\u2009\u2264\u2009|c|\u2009\u2264\u20093\u00b7105). The second line contains the string d (1\u2009\u2264\u2009|d|\u2009\u2264\u20093\u00b7105). The last line contains a single integer n (1\u2009\u2264\u2009n\u2009\u2264\u20093\u00b7105).", "output_spec": "Output a single integer: the answer to the problem, modulo 109\u2009+\u20097.", "sample_inputs": ["A?\n?\n3", "A\nB\n10"], "sample_outputs": ["2", "2046"], "notes": "NoteFor the first sample, there are four possible pairs of (c',\u2009d').If (c',\u2009d')\u2009=\u2009(AA,\u2009A), then the flexibility is 0.If (c',\u2009d')\u2009=\u2009(AB,\u2009A), then the flexibility is 0.If (c',\u2009d')\u2009=\u2009(AA,\u2009B), then the flexibility is 2, as the pairs of binary strings (1,\u200911), (0,\u200900) are the only good pairs.If (c',\u2009d')\u2009=\u2009(AB,\u2009B), then the flexibility is 0.Thus, the total flexibility is 2.For the second sample, there are 21\u2009+\u200922\u2009+\u2009...\u2009+\u2009210\u2009=\u20092046 possible binary strings of length not greater 10, and the set of pairs of good strings is precisely the set of pairs (s,\u2009s), where s is a binary string of length not greater than 10."}, "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nstruct ModInt(int M_) {\n import std.conv : to;\n alias M = M_;\n int x;\n this(ModInt a) { x = a.x; }\n this(long a) { x = cast(int)(a % M); if (x < 0) x += M; }\n ref ModInt opAssign(long a) { return (this = ModInt(a)); }\n ref ModInt opOpAssign(string op)(ModInt a) {\n static if (op == \"+\") { x += a.x; if (x >= M) x -= M; }\n else static if (op == \"-\") { x -= a.x; if (x < 0) x += M; }\n else static if (op == \"*\") { x = cast(int)((cast(long)(x) * a.x) % M); }\n else static if (op == \"/\") { this *= a.inv(); }\n else static assert(false);\n return this;\n }\n ref ModInt opOpAssign(string op)(long a) {\n static if (op == \"^^\") {\n if (a < 0) return (this = inv()^^(-a));\n ModInt t2 = this, te = ModInt(1);\n for (long e = a; e > 0; e >>= 1) {\n if (e & 1) te *= t2;\n t2 *= t2;\n }\n x = cast(int)(te.x);\n return this;\n } else return mixin(\"this \" ~ op ~ \"= ModInt(a)\");\n }\n ModInt inv() const {\n int a = x, b = M, y = 1, z = 0, t;\n for (; ; ) {\n t = a / b; a -= t * b;\n if (a == 0) {\n assert(b == 1 || b == -1);\n return ModInt(b * z);\n }\n y -= t * z;\n t = b / a; b -= t * a;\n if (b == 0) {\n assert(a == 1 || a == -1);\n return ModInt(a * y);\n }\n z -= t * y;\n }\n }\n ModInt opUnary(string op: \"-\")() const { return ModInt(-x); }\n ModInt opBinary(string op, T)(T a) const {\n return mixin(\"ModInt(this) \" ~ op ~ \"= a\");\n }\n ModInt opBinaryRight(string op)(long a) const {\n return mixin(\"ModInt(a) \" ~ op ~ \"= this\");\n }\n bool opCast(T: bool)() const { return (x != 0); }\n string toString() const { return x.to!string; }\n}\n\nenum MO = 10^^9 + 7;\nalias Mint = ModInt!MO;\n\nenum LIM = 6 * 10^^5 + 10;\nMint[] inv, fac, invFac;\nvoid prepare() {\n inv = new Mint[LIM];\n fac = new Mint[LIM];\n invFac = new Mint[LIM];\n inv[1] = 1;\n foreach (i; 2 .. LIM) {\n inv[i] = -(Mint.M / i) * inv[cast(size_t)(Mint.M % i)];\n }\n fac[0] = invFac[0] = 1;\n foreach (i; 1 .. LIM) {\n fac[i] = fac[i - 1] * i;\n invFac[i] = invFac[i - 1] * inv[i];\n }\n}\nMint binom(long n, long k) {\n if (0 <= k && k <= n) {\n assert(n < LIM);\n return fac[cast(size_t)(n)] * invFac[cast(size_t)(k)] * invFac[cast(size_t)(n - k)];\n } else {\n return Mint(0);\n }\n}\n\n\nvoid main() {\n prepare;\n \n auto two = new Mint[LIM];\n two[0] = 1;\n foreach (i; 1 .. LIM) {\n two[i] = two[i - 1] * 2;\n }\n \n try {\n for (; ; ) {\n const C = readToken();\n const D = readToken();\n const N = readInt();\n \n const CLen = cast(int)(C.length);\n const DLen = cast(int)(D.length);\n \n const ca = cast(int)(C.count('A'));\n const cb = cast(int)(C.count('B'));\n const cc = CLen - ca - cb;\n const da = cast(int)(D.count('A'));\n const db = cast(int)(D.count('B'));\n const dc = DLen - da - db;\n \n auto dp = new Mint[N + 1];\n foreach (n; 1 .. N + 1) {\n dp[n] = Mint(N / n)^^2;\n }\n foreach_reverse (n; 1 .. N + 1) {\n for (int m = 2 * n; m <= N; m += n) {\n dp[n] -= dp[m];\n }\n }\n Mint score;\n foreach (n; 1 .. N + 1) {\n score += dp[n] * two[n];\n }\n debug {\n writeln(\"dp = \", dp);\n writeln(\"score = \", score);\n Mint scoreBrt;\n foreach (x; 1 .. N + 1) foreach (y; 1 .. N + 1) {\n scoreBrt += two[gcd(x, y)];\n }\n writeln(\"scoreBrt = \", scoreBrt);\n assert(scoreBrt.x == score.x);\n }\n \n Mint ans;\n foreach (y; -DLen .. CLen + 1) {\n /*\n a x + b y = a' x + b' y\n x : y = (b' - b) : (a - a')\n \n a - a' = (ca + ci) - (da + di)\n */\n const num = binom(cc + dc, y - (ca - da) + dc);\n int x = -((CLen - DLen) - y);\n debug {\n writefln(\"%s %s: %s\", x, y, num);\n }\n if (x < 0) {\n x *= -1;\n y *= -1;\n }\n if (x > 0 && y > 0) {\n const g = gcd(x, y);\n const n = N / (max(x, y) / g);\n ans += num * (two[n + 1] - 2);\n } else if (x == 0 && y == 0) {\n ans += num * score;\n }\n }\n \n // exactly same\n Mint same = 1;\n if (CLen == DLen) {\n foreach (i; 0 .. CLen) {\n if (C[i] == '?' && D[i] == '?') {\n same *= 2;\n } else if (C[i] == '?' || D[i] == '?') {\n same *= 1;\n } else if (C[i] == D[i]) {\n same *= 1;\n } else {\n same *= 0;\n }\n }\n ans -= same * score;\n ans += same * (two[N + 1] - 2)^^2;\n }\n \n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nstruct ModInt(int M_) {\n import std.conv : to;\n alias M = M_;\n int x;\n this(ModInt a) { x = a.x; }\n this(long a) { x = cast(int)(a % M); if (x < 0) x += M; }\n ref ModInt opAssign(long a) { return (this = ModInt(a)); }\n ref ModInt opOpAssign(string op)(ModInt a) {\n static if (op == \"+\") { x += a.x; if (x >= M) x -= M; }\n else static if (op == \"-\") { x -= a.x; if (x < 0) x += M; }\n else static if (op == \"*\") { x = cast(int)((cast(long)(x) * a.x) % M); }\n else static if (op == \"/\") { this *= a.inv(); }\n else static assert(false);\n return this;\n }\n ref ModInt opOpAssign(string op)(long a) {\n static if (op == \"^^\") {\n if (a < 0) return (this = inv()^^(-a));\n ModInt t2 = this, te = ModInt(1);\n for (long e = a; e > 0; e >>= 1) {\n if (e & 1) te *= t2;\n t2 *= t2;\n }\n x = cast(int)(te.x);\n return this;\n } else return mixin(\"this \" ~ op ~ \"= ModInt(a)\");\n }\n ModInt inv() const {\n int a = x, b = M, y = 1, z = 0, t;\n for (; ; ) {\n t = a / b; a -= t * b;\n if (a == 0) {\n assert(b == 1 || b == -1);\n return ModInt(b * z);\n }\n y -= t * z;\n t = b / a; b -= t * a;\n if (b == 0) {\n assert(a == 1 || a == -1);\n return ModInt(a * y);\n }\n z -= t * y;\n }\n }\n ModInt opUnary(string op: \"-\")() const { return ModInt(-x); }\n ModInt opBinary(string op, T)(T a) const {\n return mixin(\"ModInt(this) \" ~ op ~ \"= a\");\n }\n ModInt opBinaryRight(string op)(long a) const {\n return mixin(\"ModInt(a) \" ~ op ~ \"= this\");\n }\n bool opCast(T: bool)() const { return (x != 0); }\n string toString() const { return x.to!string; }\n}\n\nenum MO = 10^^9 + 7;\nalias Mint = ModInt!MO;\n\nenum LIM = 3 * 10^^5 + 10;\nMint[] inv, fac, invFac;\nvoid prepare() {\n inv = new Mint[LIM];\n fac = new Mint[LIM];\n invFac = new Mint[LIM];\n inv[1] = 1;\n foreach (i; 2 .. LIM) {\n inv[i] = -(Mint.M / i) * inv[cast(size_t)(Mint.M % i)];\n }\n fac[0] = invFac[0] = 1;\n foreach (i; 1 .. LIM) {\n fac[i] = fac[i - 1] * i;\n invFac[i] = invFac[i - 1] * inv[i];\n }\n}\nMint binom(long n, long k) {\n if (0 <= k && k <= n) {\n assert(n < LIM);\n return fac[cast(size_t)(n)] * invFac[cast(size_t)(k)] * invFac[cast(size_t)(n - k)];\n } else {\n return Mint(0);\n }\n}\n\n\n// a^-1 (mod m)\nlong modInv(long a, long m)\nin {\n assert(m > 0, \"modInv: m > 0 must hold\");\n}\ndo {\n long b = m, x = 1, y = 0, t;\n for (; ; ) {\n t = a / b; a -= t * b;\n if (a == 0) {\n assert(b == 1 || b == -1, \"modInv: gcd(a, m) != 1\");\n if (b == -1) y = -y;\n return (y < 0) ? (y + m) : y;\n }\n x -= t * y;\n t = b / a; b -= t * a;\n if (b == 0) {\n assert(a == 1 || a == -1, \"modInv: gcd(a, m) != 1\");\n if (a == -1) x = -x;\n return (x < 0) ? (x + m) : x;\n }\n y -= t * x;\n }\n}\n\n// M: prime, G: primitive root\nclass Fft(int M_, int G, int K) {\n import std.algorithm : reverse;\n import std.traits : isIntegral;\n alias M = M_;\n // 1, 1/4, 1/8, 3/8, 1/16, 5/16, 3/16, 7/16, ...\n int[] gs;\n this() {\n static assert(2 <= K && K <= 30, \"Fft: 2 <= K <= 30 must hold\");\n static assert(!((M - 1) & ((1 << K) - 1)), \"Fft: 2^K | M - 1 must hold\");\n gs = new int[1 << (K - 1)];\n gs[0] = 1;\n long g2 = G, gg = 1;\n for (int e = (M - 1) >> K; e; e >>= 1) {\n if (e & 1) gg = (gg * g2) % M;\n g2 = (g2 * g2) % M;\n }\n gs[1 << (K - 2)] = cast(int)(gg);\n for (int l = 1 << (K - 2); l >= 2; l >>= 1) {\n gs[l >> 1] = cast(int)((cast(long)(gs[l]) * gs[l]) % M);\n }\n assert((cast(long)(gs[1]) * gs[1]) % M == M - 1,\n \"Fft: g^(2^(K-1)) == -1 (mod M) must hold\");\n for (int l = 2; l <= 1 << (K - 2); l <<= 1) {\n foreach (i; 1 .. l) {\n gs[l + i] = cast(int)((cast(long)(gs[l]) * gs[i]) % M);\n }\n }\n }\n void fft(int[] xs) const {\n const n = cast(int)(xs.length);\n assert(!(n & (n - 1)), \"Fft.fft: |xs| must be a power of two\");\n assert(n <= 1 << K, \"Fft.fft: |xs| <= 2^K must hold\");\n for (int l = n; l >>= 1; ) {\n foreach (i; 0 .. (n >> 1) / l) {\n const(long) g = gs[i];\n foreach (j; (i << 1) * l .. (i << 1 | 1) * l) {\n const t = cast(int)((g * xs[j + l]) % M);\n if ((xs[j + l] = xs[j] - t) < 0) xs[j + l] += M;\n if ((xs[j] += t) >= M) xs[j] -= M;\n }\n }\n }\n }\n void invFft(int[] xs) const {\n const n = cast(int)(xs.length);\n assert(!(n & (n - 1)), \"Fft.invFft: |xs| must be a power of two\");\n assert(n <= 1 << K, \"Fft.invFft: |xs| <= 2^K must hold\");\n for (int l = 1; l < n; l <<= 1) reverse(xs[l .. l << 1]);\n for (int l = 1; l < n; l <<= 1) {\n foreach (i; 0 .. (n >> 1) / l) {\n const(long) g = gs[i];\n foreach (j; (i << 1) * l .. (i << 1 | 1) * l) {\n int t = cast(int)((g * (xs[j] - xs[j + l])) % M);\n if (t < 0) t += M;\n if ((xs[j] += xs[j + l]) >= M) xs[j] -= M;\n xs[j + l] = t;\n }\n }\n }\n }\n T[] convolute(T)(inout(T)[] as, inout(T)[] bs) const if (isIntegral!T) {\n const na = cast(int)(as.length), nb = cast(int)(bs.length);\n int n, invN = 1;\n for (n = 1; n < na + nb - 1; n <<= 1) {\n invN = ((invN & 1) ? (invN + M) : invN) >> 1;\n }\n auto xs = new int[n], ys = new int[n];\n foreach (i; 0 .. na) if ((xs[i] = cast(int)(as[i] % M)) < 0) xs[i] += M;\n foreach (i; 0 .. nb) if ((ys[i] = cast(int)(bs[i] % M)) < 0) ys[i] += M;\n fft(xs);\n fft(ys);\n foreach (i; 0 .. n) {\n xs[i] = cast(int)((((cast(long)(xs[i]) * ys[i]) % M) * invN) % M);\n }\n invFft(xs);\n auto cs = new T[na + nb - 1];\n foreach (i; 0 .. na + nb - 1) cs[i] = cast(T)(xs[i]);\n return cs;\n }\n ModInt!M[] convolute(inout(ModInt!M)[] as, inout(ModInt!M)[] bs) const {\n const na = cast(int)(as.length), nb = cast(int)(bs.length);\n int n, invN = 1;\n for (n = 1; n < na + nb - 1; n <<= 1) {\n invN = ((invN & 1) ? (invN + M) : invN) >> 1;\n }\n auto xs = new int[n], ys = new int[n];\n foreach (i; 0 .. na) xs[i] = as[i].x;\n foreach (i; 0 .. nb) ys[i] = bs[i].x;\n fft(xs);\n fft(ys);\n foreach (i; 0 .. n) {\n xs[i] = cast(int)((((cast(long)(xs[i]) * ys[i]) % M) * invN) % M);\n }\n invFft(xs);\n auto cs = new ModInt!M[na + nb - 1];\n foreach (i; 0 .. na + nb - 1) cs[i].x = xs[i];\n return cs;\n }\n int[] convolute(int M1)(inout(ModInt!M1)[] as, inout(ModInt!M1)[] bs) const\n if (M != M1) {\n const na = cast(int)(as.length), nb = cast(int)(bs.length);\n int n, invN = 1;\n for (n = 1; n < na + nb - 1; n <<= 1) {\n invN = ((invN & 1) ? (invN + M) : invN) >> 1;\n }\n auto xs = new int[n], ys = new int[n];\n foreach (i; 0 .. na) xs[i] = as[i].x;\n foreach (i; 0 .. nb) ys[i] = bs[i].x;\n fft(xs);\n fft(ys);\n foreach (i; 0 .. n) {\n xs[i] = cast(int)((((cast(long)(xs[i]) * ys[i]) % M) * invN) % M);\n }\n invFft(xs);\n return xs[0 .. na + nb - 1];\n }\n}\n\n\nenum FFT_K = 20;\nalias Fft3_0 = Fft!(1045430273, 3, FFT_K); // 2^20 997 + 1\nalias Fft3_1 = Fft!(1051721729, 6, FFT_K); // 2^20 1003 + 1\nalias Fft3_2 = Fft!(1053818881, 7, FFT_K); // 2^20 1005 + 1\n\nenum long FFT_INV01 = modInv(Fft3_0.M, Fft3_1.M);\nenum long FFT_INV012 = modInv(cast(long)(Fft3_0.M) * Fft3_1.M, Fft3_2.M);\nFft3_0 FFT3_0;\nFft3_1 FFT3_1;\nFft3_2 FFT3_2;\nvoid initFft3() {\n FFT3_0 = new Fft3_0;\n FFT3_1 = new Fft3_1;\n FFT3_2 = new Fft3_2;\n}\nModInt!M[] convolute(int M)(inout(ModInt!M)[] as, inout(ModInt!M)[] bs) {\n const cs0 = FFT3_0.convolute(as, bs);\n const cs1 = FFT3_1.convolute(as, bs);\n const cs2 = FFT3_2.convolute(as, bs);\n auto cs = new ModInt!M[cs0.length];\n foreach (i; 0 .. cs0.length) {\n long d0 = cs0[i] % Fft3_0.M;\n long d1 = (FFT_INV01 * (cs1[i] - d0)) % Fft3_1.M;\n if (d1 < 0) d1 += Fft3_1.M;\n long d2 =\n (FFT_INV012 * ((cs2[i] - d0 - Fft3_0.M * d1) % Fft3_2.M)) % Fft3_2.M;\n if (d2 < 0) d2 += Fft3_2.M;\n cs[i] =\n (d0 + Fft3_0.M * d1 + ((cast(long)(Fft3_0.M) * Fft3_1.M) % M) * d2) % M;\n }\n return cs;\n}\n\n\nvoid main() {\n prepare;\n initFft3;\n \n auto two = new Mint[LIM];\n two[0] = 1;\n foreach (i; 1 .. LIM) {\n two[i] = two[i - 1] * 2;\n }\n \n try {\n for (; ; ) {\n const C = readToken();\n const D = readToken();\n const N = readInt();\n \n const CLen = cast(int)(C.length);\n const DLen = cast(int)(D.length);\n \n auto fs = new Mint[CLen + 1];\n const ca = cast(int)(C.count('A'));\n const cb = cast(int)(C.count('B'));\n const cc = CLen - ca - cb;\n foreach (i; 0 .. cc + 1) {\n fs[ca + i] = binom(cc, i);\n }\n \n auto gs = new Mint[DLen + 1];\n const da = cast(int)(D.count('A'));\n const db = cast(int)(D.count('B'));\n const dc = DLen - da - db;\n foreach (i; 0 .. dc + 1) {\n gs[DLen - (da + i)] = binom(dc, i);\n }\n \n auto hs = convolute(fs, gs);\n debug {\n writeln(\"hs = \", hs);\n }\n \n Mint ans;\n foreach (i; 0 .. cast(int)(hs.length)) {\n /*\n a x + b y = a' x + b' y\n x : y = (b' - b) : (a - a')\n */\n int y = i - DLen;\n int x = -((CLen - DLen) - y);\n if (x < 0) {\n x *= -1;\n y *= -1;\n }\n if (x > 0 && y > 0) {\n debug {\n writefln(\"%s %s: %s\", x, y, hs[i]);\n }\n const g = gcd(x, y);\n const n = N / (max(x, y) / g);\n ans += hs[i] * (two[n + 1] - 2);\n }\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "4a6525f37d70dd1bf4f33cef57371b64"} {"nl": {"description": "You are given a regular polygon with $$$n$$$ vertices labeled from $$$1$$$ to $$$n$$$ in counter-clockwise order. The triangulation of a given polygon is a set of triangles such that each vertex of each triangle is a vertex of the initial polygon, there is no pair of triangles such that their intersection has non-zero area, and the total area of all triangles is equal to the area of the given polygon. The weight of a triangulation is the sum of weigths of triangles it consists of, where the weight of a triagle is denoted as the product of labels of its vertices.Calculate the minimum weight among all triangulations of the polygon.", "input_spec": "The first line contains single integer $$$n$$$ ($$$3 \\le n \\le 500$$$) \u2014 the number of vertices in the regular polygon.", "output_spec": "Print one integer \u2014 the minimum weight among all triangulations of the given polygon.", "sample_inputs": ["3", "4"], "sample_outputs": ["6", "18"], "notes": "NoteAccording to Wiki: polygon triangulation is the decomposition of a polygonal area (simple polygon) $$$P$$$ into a set of triangles, i.\u2009e., finding a set of triangles with pairwise non-intersecting interiors whose union is $$$P$$$.In the first example the polygon is a triangle, so we don't need to cut it further, so the answer is $$$1 \\cdot 2 \\cdot 3 = 6$$$.In the second example the polygon is a rectangle, so it should be divided into two triangles. It's optimal to cut it using diagonal $$$1-3$$$ so answer is $$$1 \\cdot 2 \\cdot 3 + 1 \\cdot 3 \\cdot 4 = 6 + 12 = 18$$$."}, "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nvoid main() {\n auto N = readln.chomp.to!long;\n long ans = 0;\n\n foreach (i; 2..N) ans += i * (i + 1);\n\n ans.writeln;\n}\n"}, {"source_code": "import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;\n\nvoid main()\n{\n auto N = readln.chomp.to!int;\n\n long r;\n foreach (i; 2..N) {\n r += i * (i+1);\n }\n writeln(r);\n}"}, {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nvoid main() {\n int n;\n readf (\" %d\", &n);\n auto a = new long[][] (n+2, n+2);\n auto c = new int[n + 1];\n foreach (i; 0 .. n + 1) {\n c[i] = i;\n }\n debug stderr.writeln (c);\n long f (int i, int j) {\n if (i == j) return 0;\n assert (i < j);\n if (a[i][j] != 0) return a[i][j]; \n long r = long.max;\n foreach (k; i .. j) {\n //r = max (r, f (i, k) + f (k + 1, j) + c[i-1] * c[k] * c[j]);\n r = min (r, f (i, k) + f (k + 1, j) + (i - 1) * k * j);\n }\n debug stderr.writefln (\"f(%d, %d) = %d\", i, j, r);\n return a[i][j] = r;\n }\n writeln (f (2, n));\n}\n\n"}], "negative_code": [{"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nvoid main() {\n int n;\n readf (\" %d\", &n);\n if (n == 3) {\n writeln (6);\n return;\n }\n auto a = new long[][] (n+2, n+2);\n auto c = new int[n + 2];\n foreach (i; 0 .. n + 1) {\n c[i] = i;\n }\n c[n+1] = 1;\n debug stderr.writeln (c);\n long f (int i, int j) {\n if (i >= j) {\n j += n;\n }\n if (a[i][j] != 0) return a[i][j]; \n long r;\n if (j == i + 2) {\n r = c[i] * c[i + 1] * c[i + 2];\n } else {\n foreach (k; i + 2 .. j) {\n debug stderr.writefln (\"i = %d, j = %d, k = %d\", i, j, k);\n r = max (r, f (i, k) + f (k, j));\n }\n }\n debug stderr.writefln (\"f(%d, %d) = %d\", i, j, r);\n return a[i][j] = r;\n }\n writeln (f (1, 1));\n}\n\n"}, {"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nvoid main() {\n int n;\n readf (\" %d\", &n);\n if (n == 3) {\n writeln (6);\n return;\n }\n auto a = new long[][] (n+2, n+2);\n auto c = new int[n + 2];\n foreach (i; 0 .. n + 1) {\n c[i] = i;\n }\n c[n+1] = 1;\n debug stderr.writeln (c);\n long f (int i, int j) {\n if (i >= j) {\n j += n;\n }\n if (a[i][j] != 0) return a[i][j]; \n long r;\n if (j == i + 2) {\n r = c[i] * c[i + 1] * c[i + 2];\n } else {\n foreach (k; i + 2 .. j - 1) {\n debug stderr.writefln (\"i = %d, j = %d, k = %d\", i, j, k);\n r = max (r, f (i, k) + f (k, j));\n }\n }\n debug stderr.writefln (\"f(%d, %d) = %d\", i, j, r);\n return a[i][j] = r;\n }\n writeln (f (1, 1));\n}\n\n"}], "src_uid": "1bd29d7a8793c22e81a1f6fd3991307a"} {"nl": {"description": "Stepan is a very experienced olympiad participant. He has n cups for Physics olympiads and m cups for Informatics olympiads. Each cup is characterized by two parameters \u2014 its significance ci and width wi.Stepan decided to expose some of his cups on a shelf with width d in such a way, that: there is at least one Physics cup and at least one Informatics cup on the shelf, the total width of the exposed cups does not exceed d, from each subjects (Physics and Informatics) some of the most significant cups are exposed (i. e. if a cup for some subject with significance x is exposed, then all the cups for this subject with significance greater than x must be exposed too). Your task is to determine the maximum possible total significance, which Stepan can get when he exposes cups on the shelf with width d, considering all the rules described above. The total significance is the sum of significances of all the exposed cups.", "input_spec": "The first line contains three integers n, m and d (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u2009100\u2009000, 1\u2009\u2264\u2009d\u2009\u2264\u2009109) \u2014 the number of cups for Physics olympiads, the number of cups for Informatics olympiads and the width of the shelf. Each of the following n lines contains two integers ci and wi (1\u2009\u2264\u2009ci,\u2009wi\u2009\u2264\u2009109) \u2014 significance and width of the i-th cup for Physics olympiads. Each of the following m lines contains two integers cj and wj (1\u2009\u2264\u2009cj,\u2009wj\u2009\u2264\u2009109) \u2014 significance and width of the j-th cup for Informatics olympiads.", "output_spec": "Print the maximum possible total significance, which Stepan can get exposing cups on the shelf with width d, considering all the rules described in the statement. If there is no way to expose cups on the shelf, then print 0.", "sample_inputs": ["3 1 8\n4 2\n5 5\n4 2\n3 2", "4 3 12\n3 4\n2 4\n3 5\n3 4\n3 5\n5 2\n3 4", "2 2 2\n5 3\n6 3\n4 2\n8 1"], "sample_outputs": ["8", "11", "0"], "notes": "NoteIn the first example Stepan has only one Informatics cup which must be exposed on the shelf. Its significance equals 3 and width equals 2, so after Stepan exposes it, the width of free space on the shelf becomes equal to 6. Also, Stepan must expose the second Physics cup (which has width 5), because it is the most significant cup for Physics (its significance equals 5). After that Stepan can not expose more cups on the shelf, because there is no enough free space. Thus, the maximum total significance of exposed cups equals to 8."}, "positive_code": [{"source_code": "module main;\n\nimport core.stdc.stdio;\nimport std.stdio;\nimport std.algorithm.sorting;\nimport std.typecons;\nalias TL = Tuple!(long, \"c\", long, \"w\");\n\nint main(string[] argv)\n{\n\tint n, m;\n\tlong d;\n\tscanf(\"%d%d%lld\", &n, &m, &d);\n\tauto a = new TL[n];\n\tauto b = new TL[m];\n\tfor(int i = 0; i < n; i++)\n\t\tscanf(\"%lld%lld\", &a[i].c, &a[i].w);\n\tfor(int i = 0; i < m; i++)\n\t\tscanf(\"%lld%lld\", &b[i].c, &b[i].w);\n\talias myComp = (x, y) => x.c > y.c || (x.c == y.c && x.w < y.w);\n\tsort!(myComp)(a);\n\tsort!(myComp)(b);\n\tauto u = new TL[n + 1];\n\tauto v = new TL[m + 1];\n\tu[0].c = 0; u[0].w = 0;\n\tfor (int i = 0; i < n; ++i) {\n\t u[i + 1].c = u[i].c + a[i].c;\n\t u[i + 1].w = u[i].w + a[i].w;\n\t}\n\tv[0].c = 0; v[0].w = 0;\n\tfor (int i = 0; i < m; ++i) {\n\t v[i + 1].c = v[i].c + b[i].c;\n\t v[i + 1].w = v[i].w + b[i].w;\n\t}\n\tlong ans = 0;\n for (int i = 1; i <= n && u[i].w < d; ++i) {\n int l = 0;\n int r = m + 1;\n while (r - l > 1) {\n int x = (l + r) / 2;\n if (u[i].w + v[x].w <= d) {\n l = x;\n } else {\n r = x;\n }\n }\n if (l > 0 && u[i].c + v[l].c > ans) {\n ans = u[i].c + v[l].c;\n }\n }\n writeln(ans);\n\treturn 0;\n}"}], "negative_code": [], "src_uid": "da573a39459087ed7c42f70bc1d0e8ff"} {"nl": {"description": "Awruk is taking part in elections in his school. It is the final round. He has only one opponent\u00a0\u2014 Elodreip. The are $$$n$$$ students in the school. Each student has exactly $$$k$$$ votes and is obligated to use all of them. So Awruk knows that if a person gives $$$a_i$$$ votes for Elodreip, than he will get exactly $$$k - a_i$$$ votes from this person. Of course $$$0 \\le k - a_i$$$ holds.Awruk knows that if he loses his life is over. He has been speaking a lot with his friends and now he knows $$$a_1, a_2, \\dots, a_n$$$ \u2014 how many votes for Elodreip each student wants to give. Now he wants to change the number $$$k$$$ to win the elections. Of course he knows that bigger $$$k$$$ means bigger chance that somebody may notice that he has changed something and then he will be disqualified.So, Awruk knows $$$a_1, a_2, \\dots, a_n$$$ \u2014 how many votes each student will give to his opponent. Help him select the smallest winning number $$$k$$$. In order to win, Awruk needs to get strictly more votes than Elodreip.", "input_spec": "The first line contains integer $$$n$$$ ($$$1 \\le n \\le 100$$$)\u00a0\u2014 the number of students in the school. The second line contains $$$n$$$ integers $$$a_1, a_2, \\ldots, a_n$$$ ($$$1 \\leq a_i \\leq 100$$$)\u00a0\u2014 the number of votes each student gives to Elodreip.", "output_spec": "Output the smallest integer $$$k$$$ ($$$k \\ge \\max a_i$$$) which gives Awruk the victory. In order to win, Awruk needs to get strictly more votes than Elodreip.", "sample_inputs": ["5\n1 1 1 5 1", "5\n2 2 3 2 2"], "sample_outputs": ["5", "5"], "notes": "NoteIn the first example, Elodreip gets $$$1 + 1 + 1 + 5 + 1 = 9$$$ votes. The smallest possible $$$k$$$ is $$$5$$$ (it surely can't be less due to the fourth person), and it leads to $$$4 + 4 + 4 + 0 + 4 = 16$$$ votes for Awruk, which is enough to win.In the second example, Elodreip gets $$$11$$$ votes. If $$$k = 4$$$, Awruk gets $$$9$$$ votes and loses to Elodreip."}, "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tauto start = a.maxElement;\n\t\tint res = start;\n\t\twhile (a.sum * 2 >= n * res)\n\t\t{\n\t\t\tres += 1;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [], "src_uid": "d215b3541d6d728ad01b166aae64faa2"} {"nl": {"description": "This morning, Roman woke up and opened the browser with $$$n$$$ opened tabs numbered from $$$1$$$ to $$$n$$$. There are two kinds of tabs: those with the information required for the test and those with social network sites. Roman decided that there are too many tabs open so he wants to close some of them.He decided to accomplish this by closing every $$$k$$$-th ($$$2 \\leq k \\leq n - 1$$$) tab. Only then he will decide whether he wants to study for the test or to chat on the social networks. Formally, Roman will choose one tab (let its number be $$$b$$$) and then close all tabs with numbers $$$c = b + i \\cdot k$$$ that satisfy the following condition: $$$1 \\leq c \\leq n$$$ and $$$i$$$ is an integer (it may be positive, negative or zero).For example, if $$$k = 3$$$, $$$n = 14$$$ and Roman chooses $$$b = 8$$$, then he will close tabs with numbers $$$2$$$, $$$5$$$, $$$8$$$, $$$11$$$ and $$$14$$$.After closing the tabs Roman will calculate the amount of remaining tabs with the information for the test (let's denote it $$$e$$$) and the amount of remaining social network tabs ($$$s$$$). Help Roman to calculate the maximal absolute value of the difference of those values $$$|e - s|$$$ so that it would be easy to decide what to do next.", "input_spec": "The first line contains two integers $$$n$$$ and $$$k$$$ ($$$2 \\leq k < n \\leq 100$$$) \u2014 the amount of tabs opened currently and the distance between the tabs closed. The second line consists of $$$n$$$ integers, each of them equal either to $$$1$$$ or to $$$-1$$$. The $$$i$$$-th integer denotes the type of the $$$i$$$-th tab: if it is equal to $$$1$$$, this tab contains information for the test, and if it is equal to $$$-1$$$, it's a social network tab.", "output_spec": "Output a single integer \u2014 the maximum absolute difference between the amounts of remaining tabs of different types $$$|e - s|$$$.", "sample_inputs": ["4 2\n1 1 -1 1", "14 3\n-1 1 -1 -1 1 -1 -1 1 -1 -1 1 -1 -1 1"], "sample_outputs": ["2", "9"], "notes": "NoteIn the first example we can choose $$$b = 1$$$ or $$$b = 3$$$. We will delete then one tab of each type and the remaining tabs are then all contain test information. Thus, $$$e = 2$$$ and $$$s = 0$$$ and $$$|e - s| = 2$$$.In the second example, on the contrary, we can leave opened only tabs that have social networks opened in them."}, "positive_code": [{"source_code": "import std.algorithm;\nimport std.container;\nimport std.conv;\nimport std.format;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main() {\n int n,k;\n readf!\" %s %s\"(n, k);\n\n int[] a = new int[](n);\n foreach (i; 0 .. n) {\n readf!\" %s\"(a[i]);\n }\n\n int total = a.sum;\n\n int ans = 0;\n foreach (i; 0 .. k) {\n int temp = 0;\n for (int j = i; j < n; j += k) {\n temp += a[j];\n }\n ans = max(ans, (total - temp).abs);\n }\n\n writeln(ans);\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nimmutable long INF = 1L << 59;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto K = s[1];\n auto A = readln.split.map!(to!int).array;\n int x1 = A.count(1).to!int;\n int x2 = A.count(-1).to!int;\n\n int ans = 0;\n foreach (i; 0..N) {\n int cnt1 = 0, cnt2 = 0;\n foreach (j; 0..N) {\n if (abs(j - i) % K == 0) {\n if (A[j] == 1) cnt1 += 1;\n else cnt2 += 1;\n }\n }\n ans = max(ans, abs((x1 - cnt1) - (x2 - cnt2)));\n }\n\n ans.writeln;\n}\n"}], "negative_code": [], "src_uid": "6119258322e06fa6146e592c63313df3"} {"nl": {"description": "Sasha is a very happy guy, that's why he is always on the move. There are $$$n$$$ cities in the country where Sasha lives. They are all located on one straight line, and for convenience, they are numbered from $$$1$$$ to $$$n$$$ in increasing order. The distance between any two adjacent cities is equal to $$$1$$$ kilometer. Since all roads in the country are directed, it's possible to reach the city $$$y$$$ from the city $$$x$$$ only if $$$x < y$$$. Once Sasha decided to go on a trip around the country and to visit all $$$n$$$ cities. He will move with the help of his car, Cheetah-2677. The tank capacity of this model is $$$v$$$ liters, and it spends exactly $$$1$$$ liter of fuel for $$$1$$$ kilometer of the way. At the beginning of the journey, the tank is empty. Sasha is located in the city with the number $$$1$$$ and wants to get to the city with the number $$$n$$$. There is a gas station in each city. In the $$$i$$$-th city, the price of $$$1$$$ liter of fuel is $$$i$$$ dollars. It is obvious that at any moment of time, the tank can contain at most $$$v$$$ liters of fuel.Sasha doesn't like to waste money, that's why he wants to know what is the minimum amount of money is needed to finish the trip if he can buy fuel in any city he wants. Help him to figure it out!", "input_spec": "The first line contains two integers $$$n$$$ and $$$v$$$ ($$$2 \\le n \\le 100$$$, $$$1 \\le v \\le 100$$$) \u00a0\u2014 the number of cities in the country and the capacity of the tank.", "output_spec": "Print one integer\u00a0\u2014 the minimum amount of money that is needed to finish the trip.", "sample_inputs": ["4 2", "7 6"], "sample_outputs": ["4", "6"], "notes": "NoteIn the first example, Sasha can buy $$$2$$$ liters for $$$2$$$ dollars ($$$1$$$ dollar per liter) in the first city, drive to the second city, spend $$$1$$$ liter of fuel on it, then buy $$$1$$$ liter for $$$2$$$ dollars in the second city and then drive to the $$$4$$$-th city. Therefore, the answer is $$$1+1+2=4$$$.In the second example, the capacity of the tank allows to fill the tank completely in the first city, and drive to the last city without stops in other cities."}, "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.conv;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable long INF = 10L ^^ 18 + 23;\n\nvoid main()\n{ \n int n, v;\n readf(\"%s %s\", &n, &v);\n readln;\n \n int tank = min(n - 1, v);\n int ans = tank;\n for (int i = 2; i < n; ++i) {\n tank -= 1;\n if (tank < n - i) {\n ++tank;\n ans += i;\n }\n }\n \n ans.writeln;\n}"}], "negative_code": [], "src_uid": "f8eb96deeb82d9f011f13d7dac1e1ab7"} {"nl": {"description": "Consider the infinite sequence of integers: 1,\u20091,\u20092,\u20091,\u20092,\u20093,\u20091,\u20092,\u20093,\u20094,\u20091,\u20092,\u20093,\u20094,\u20095.... The sequence is built in the following way: at first the number 1 is written out, then the numbers from 1 to 2, then the numbers from 1 to 3, then the numbers from 1 to 4 and so on. Note that the sequence contains numbers, not digits. For example number 10 first appears in the sequence in position 55 (the elements are numerated from one).Find the number on the n-th position of the sequence.", "input_spec": "The only line contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u20091014) \u2014 the position of the number to find. Note that the given number is 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.", "output_spec": "Print the element in the n-th position of the sequence (the elements are numerated from one).", "sample_inputs": ["3", "5", "10", "55", "56"], "sample_outputs": ["2", "2", "4", "10", "1"], "notes": null}, "positive_code": [{"source_code": "import std.stdio;\n\nvoid main()\n{\n long n;\n\treadf(\"%s\", &n);\n\n\tlong before = 0;\n\tint last = 1;\n\n\twhile (before + last < n) {\n\t\tbefore += last;\n\t\tlast++;\n\t}\n\n\tint x = 0;\n\twhile (before + x < n) {\n\t\tx++;\n\t}\n\n\twriteln(x);\n}\n"}], "negative_code": [], "src_uid": "1db5631847085815461c617854b08ee5"} {"nl": {"description": "Duff is in love with lovely numbers! A positive integer x is called lovely if and only if there is no such positive integer a\u2009>\u20091 such that a2 is a divisor of x. Malek has a number store! In his store, he has only divisors of positive integer n (and he has all of them). As a birthday present, Malek wants to give her a lovely number from his store. He wants this number to be as big as possible.Malek always had issues in math, so he asked for your help. Please tell him what is the biggest lovely number in his store.", "input_spec": "The first and only line of input contains one integer, n (1\u2009\u2264\u2009n\u2009\u2264\u20091012).", "output_spec": "Print the answer in one line.", "sample_inputs": ["10", "12"], "sample_outputs": ["10", "6"], "notes": "NoteIn first sample case, there are numbers 1, 2, 5 and 10 in the shop. 10 isn't divisible by any perfect square, so 10 is lovely.In second sample case, there are numbers 1, 2, 3, 4, 6 and 12 in the shop. 12 is divisible by 4\u2009=\u200922, so 12 is not lovely, while 6 is indeed lovely."}, "positive_code": [{"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\nimport std.math;\nimport std.algorithm;\nimport std.range;\n\nvoid main() {\n long n = readln.chomp.to!long;\n long[] answer;\n for (long i = 2; i <= sqrt(cast(float)n); i++) {\n if (n % i == 0) {\n answer ~= i;\n }\n\n while (n % i == 0) {\n n /= i;\n }\n }\n\n if (answer.empty) {\n writeln(n);\n } else {\n writeln(answer.reduce!(\"a * b\") * n);\n }\n}"}], "negative_code": [], "src_uid": "6d0da975fa0961acfdbe75f2f29aeb92"} {"nl": {"description": "Let's consider a table consisting of n rows and n columns. The cell located at the intersection of i-th row and j-th column contains number i\u2009\u00d7\u2009j. The rows and columns are numbered starting from 1.You are given a positive integer x. Your task is to count the number of cells in a table that contain number x.", "input_spec": "The single line contains numbers n and x (1\u2009\u2264\u2009n\u2009\u2264\u2009105, 1\u2009\u2264\u2009x\u2009\u2264\u2009109) \u2014 the size of the table and the number that we are looking for in the table.", "output_spec": "Print a single number: the number of times x occurs in the table.", "sample_inputs": ["10 5", "6 12", "5 13"], "sample_outputs": ["2", "4", "0"], "notes": "NoteA table for the second sample test is given below. The occurrences of number 12 are marked bold. "}, "positive_code": [{"source_code": "import std.stdio;\nimport core.stdc.stdio;\n\nint main(string[] argv)\n{\n\tlong n, x;\n\tscanf(\"%d %d\", &n, &x);\n\tlong count = 0;\n\tforeach (long i; 1..(n+1))\n\t{\n\t\tif (x % i == 0)\n\t\t{\n\t\t\tlong a = i;\n\t\t\tlong b = x / a;\n\t\t\tif (a <= n && b <= n)\n\t\t\t\tcount += 1;\n\t\t}\n\t}\n\tprintf(\"%d\", count);\n\treturn 0;\n}"}], "negative_code": [{"source_code": "import std.stdio;\nimport core.stdc.stdio;\n\nint main(string[] argv)\n{\n\tlong n, x;\n\tscanf(\"%d %d\", &n, &x);\n\tlong count;\n\tlong l = (n / 2) + (n % 2 == 0 ? 1 : 2);\n\tforeach (long i; 1..l)\n\t{\n\t\tif (x % i == 0)\n\t\t{\n\t\t\tlong a = i;\n\t\t\tlong b = x / a;\n\t\t\tif (a <= n && b <= n)\n\t\t\t\tcount += 1;\n\t\t}\n\t}\n\tprintf(\"%d\", count);\n\treturn 0;\n}"}], "src_uid": "c4b139eadca94201596f1305b2f76496"} {"nl": {"description": "Two teams meet in The Game World Championship. Some scientists consider this game to be the most intellectually challenging game in the world. You are given two strings describing the teams' actions in the final battle. Figure out who became the champion.", "input_spec": "The input contains two strings of equal length (between 2 and 20 characters, inclusive). Each line describes the actions of one team.", "output_spec": "Output \"TEAM 1 WINS\" if the first team won, \"TEAM 2 WINS\" if the second team won, and \"TIE\" if there was a tie.", "sample_inputs": ["[]()[]8<\n8<[]()8<", "8<8<()\n[]8<[]"], "sample_outputs": ["TEAM 2 WINS", "TIE"], "notes": null}, "positive_code": [{"source_code": "import std.stdio;\nimport std.conv;\nimport std.string;\nimport std.typecons;\nimport std.algorithm;\nimport std.array;\nimport std.range;\nimport std.math;\nimport std.container;\nimport std.bigint;\n\nvoid main()\n{\n auto str1 = readln.chomp;\n auto str2 = readln.chomp;\n int s1, s2;\n \n for (int i; i < str1.length; i+=2) {\n if (str1[i] == '(' && str2[i] == '8') s1++;\n else if (str1[i] == '8' && str2[i] == '[') s1++;\n else if (str1[i] == '[' && str2[i] == '(') s1++;\n else if (str2[i] == '(' && str1[i] == '8') s2++;\n else if (str2[i] == '8' && str1[i] == '[') s2++;\n else if (str2[i] == '[' && str1[i] == '(') s2++;\n }\n if (s1 > s2) \"TEAM 1 WINS\".writeln;\n else if (s1 < s2) \"TEAM 2 WINS\".writeln;\n else \"TIE\".writeln;\n}"}, {"source_code": "import std.algorithm;\nimport std.stdio;\n\nimmutable string TYPES = \"[]()8<\";\n\nvoid main ()\n{\n\tauto s = readln ();\n\tauto t = readln ();\n\tint n = s.length;\n\tint [2] x;\n\tfor (int i = 0; i < n - 1; i += 2)\n\t{\n\t\tint u = (TYPES.length - find (TYPES, s[i..i + 2]).length) / 2;\n\t\tint v = (TYPES.length - find (TYPES, t[i..i + 2]).length) / 2;\n\t\tif ((u + 1) % 3 == v)\n\t\t{\n\t\t\tx[0]++;\n\t\t}\n\t\telse if ((u + 2) % 3 == v)\n\t\t{\n\t\t\tx[1]++;\n\t\t}\n\t}\n\tif (x[0] > x[1])\n\t{\n\t\twriteln (\"TEAM 1 WINS\");\n\t}\n\telse if (x[0] < x[1])\n\t{\n\t\twriteln (\"TEAM 2 WINS\");\n\t}\n\telse\n\t{\n\t\twriteln (\"TIE\");\n\t}\n}\n"}], "negative_code": [], "src_uid": "bdf2e78c47d078b4ba61741b6fbb23cf"} {"nl": {"description": "Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the blue button, device subtracts one from the number on the display. If at some point the number stops being positive, the device breaks down. The display can show arbitrarily large numbers. Initially, the display shows number n.Bob wants to get number m on the display. What minimum number of clicks he has to make in order to achieve this result?", "input_spec": "The first and the only line of the input contains two distinct integers n and m (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u2009104), separated by a space .", "output_spec": "Print a single number \u2014 the minimum number of times one needs to push the button required to get the number m out of number n.", "sample_inputs": ["4 6", "10 1"], "sample_outputs": ["2", "9"], "notes": "NoteIn the first example you need to push the blue button once, and then push the red button once.In the second example, doubling the number is unnecessary, so we need to push the blue button nine times."}, "positive_code": [{"source_code": "\ufeffimport std.stdio;\n\nint bfs(short n, short m) {\n\t\n\tif (n >= m)\n\t\treturn n - m;\n\n\tif (!(m & 1))\n\t\treturn bfs(n, m / 2) + 1;\n\t\n\tif (m & 1)\n\t\treturn bfs(n, (m + 1) / 2) + 2;\n\n\tassert(0);\n}\n\nvoid main() {\n\n\tshort n, m;\n\n\tscanf(\"%hd%hd\", &n, &m);\n\n\twriteln(bfs(n, m));\n}"}, {"source_code": "\ufeffimport std.stdio;\n\nvoid main() {\n\n\tshort n, m;\n\n\tscanf(\"%hd%hd\", &n, &m);\n\n\tint sum;\n\twhile (m > n) {\n\t\tif (!(m & 1))\n\t\t\tm /= 2;\n\t\telse\n\t\t\tm++;\n\t\tsum++;\n\t}\n\n\twriteln(sum + n - m);\n}"}, {"source_code": "\ufeffimport std.stdio;\n\nint bfs(short n, short m) {\n\t\n\tif (n >= m)\n\t\treturn n - m;\n\n\tif (m % 2 == 0)\n\t\treturn bfs(n, m / 2) + 1;\n\t\n\tif (m % 2 == 1)\n\t\treturn bfs(n, (m + 1) / 2) + 2;\n\n\tassert(0);\n}\n\nvoid main() {\n\n\tshort n, m;\n\n\tscanf(\"%hd%hd\", &n, &m);\n\n\twriteln(bfs(n, m));\n}"}, {"source_code": "import std.stdio;\nimport std.container;\nimport std.array;\nimport std.conv;\nimport std.string;\nimport std.algorithm;\n\n\nvoid main()\n{\n auto i = readln.chomp.split.map!\"a.to!int\";\n auto s = DList!int(i[0]);\n auto v = DList!int(0);\n bool [int] visited;\n\n int a,b;\n while (!s.empty && s.front!= i[1]) {\n a = s.front;\n b = v.front;\n s.removeFront();\n v.removeFront();\n if (! (a in visited)) {\n visited[a] = true;\n if (a1) {\n s.insertBack(a-1);\n v.insertBack(b+1);\n }\n\n }\n //writeln(array(s));\n }\n\n writeln(v.front);\n\n}\n"}, {"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) throw new EOFException; tokens = readln.split; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, in T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, in T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp( const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nimmutable V = 10^^6;\n\nint S, T;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tS = readInt;\n\t\tT = readInt;\n\t\t\n\t\tint[] q;\n\t\tint[] d = new int[V];\n\t\td[] = -1;\n\t\td[S] = 0;\n\t\tq ~= S;\n\t\tfor (; !q.empty; ) {\n\t\t\tconst u = q.front;\n\t\t\tq.popFront;\n\t\t\tforeach (v; [ u * 2, u - 1 ]) if (0 < v && v < V) {\n\t\t\t\tif (d[v] == -1) {\n\t\t\t\t\td[v] = d[u] + 1;\n\t\t\t\t\tq ~= v;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t\n\t\twriteln(d[T]);\n\t\t\n\t}\n\t} catch (EOFException) {}\n}\n\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.container;\nimport std.array;\nimport std.conv;\nimport std.string;\nimport std.algorithm;\n\n\nvoid main()\n{\n auto i = readln.chomp.split.map!\"a.to!int\";\n auto s = SList!int(i[0]);\n auto v = SList!int(0);\n bool [int] visited;\n\n int a,b;\n while (!s.empty && s.front!= i[1]) {\n a = s.front;\n b = v.front;\n s.removeFront();\n v.removeFront();\n if (! (a in visited)) {\n s.insertFront(a*2);\n v.insertFront(b+1);\n visited[a] = true;\n if (a>0) {\n writeln(\"here\");\n s.insertFront(a-1);\n v.insertFront(b+1);\n }\n }\n }\n\n writeln(v.front);\n\n}\n"}, {"source_code": "import std.stdio;\nimport std.container;\nimport std.array;\nimport std.conv;\nimport std.string;\nimport std.algorithm;\n\n\nvoid main()\n{\n auto i = readln.chomp.split.map!\"a.to!int\";\n auto s = SList!int(i[0]);\n auto v = SList!int(0);\n bool [int] visited;\n\n int a,b;\n while (!s.empty && s.front!= i[1]) {\n a = s.front;\n b = v.front;\n s.removeFront();\n v.removeFront();\n if (! (a in visited)) {\n s.insertFront(a*2);\n v.insertFront(b+1);\n visited[a] = true;\n if (a>0) {\n s.insertFront(a-1);\n v.insertFront(b+1);\n }\n }\n }\n\n writeln(v.front);\n\n}\n"}], "src_uid": "861f8edd2813d6d3a5ff7193a804486f"} {"nl": {"description": "Vasya is an active Internet user. One day he came across an Internet resource he liked, so he wrote its address in the notebook. We know that the address of the written resource has format: <protocol>://<domain>.ru[/<context>] where: <protocol> can equal either \"http\" (without the quotes) or \"ftp\" (without the quotes), <domain> is a non-empty string, consisting of lowercase English letters, the /<context> part may not be present. If it is present, then <context> is a non-empty string, consisting of lowercase English letters. If string <context> isn't present in the address, then the additional character \"/\" isn't written. Thus, the address has either two characters \"/\" (the ones that go before the domain), or three (an extra one in front of the context).When the boy came home, he found out that the address he wrote in his notebook had no punctuation marks. Vasya must have been in a lot of hurry and didn't write characters \":\", \"/\", \".\".Help Vasya to restore the possible address of the recorded Internet resource.", "input_spec": "The first line contains a non-empty string that Vasya wrote out in his notebook. This line consists of lowercase English letters only. It is guaranteed that the given string contains at most 50 letters. It is guaranteed that the given string can be obtained from some correct Internet resource address, described above.", "output_spec": "Print a single line \u2014 the address of the Internet resource that Vasya liked. If there are several addresses that meet the problem limitations, you are allowed to print any of them.", "sample_inputs": ["httpsunrux", "ftphttprururu"], "sample_outputs": ["http://sun.ru/x", "ftp://http.ru/ruru"], "notes": "NoteIn the second sample there are two more possible answers: \"ftp://httpruru.ru\" and \"ftp://httpru.ru/ru\"."}, "positive_code": [{"source_code": "import std.stdio;\nimport std.algorithm.comparison;\nimport std.algorithm.sorting;\nimport std.algorithm.searching;\nimport std.algorithm.mutation;\nimport std.range;\nimport std.range.primitives;\nimport std.conv;\nimport std.string;\n\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n string str, outstr;\n readf(\" %s\\n\", &str);\n if (str[0] == 'h') {\n outstr = \"http://\";\n str = str[4 .. $];\n }\n else {\n outstr = \"ftp://\";\n str = str[3 .. $];\n }\n int pos = str.indexOf(\"ru\", 1);\n outstr ~= str[0 .. pos] ~ \".ru\";\n if (str.length > pos + 2) outstr ~= \"/\" ~ str[pos + 2 .. $];\n writeln(outstr);\n \n return 0;\n}"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.algorithm.comparison;\nimport std.algorithm.sorting;\nimport std.algorithm.searching;\nimport std.algorithm.mutation;\nimport std.range;\nimport std.range.primitives;\nimport std.conv;\nimport std.string;\n\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n string str, outstr;\n readf(\" %s\\n\", &str);\n if (str[0] == 'h') {\n outstr = \"http://\";\n str = str[4 .. $];\n }\n else {\n outstr = \"ftp://\";\n str = str[3 .. $];\n }\n int pos = str.indexOf(\"ru\");\n outstr ~= str[0 .. pos] ~ \".ru\";\n if (str.length > pos + 1) outstr ~= \"/\" ~ str[pos + 2 .. $];\n writeln(outstr);\n \n return 0;\n}"}, {"source_code": "import std.stdio;\nimport std.algorithm.comparison;\nimport std.algorithm.sorting;\nimport std.algorithm.searching;\nimport std.algorithm.mutation;\nimport std.range;\nimport std.range.primitives;\nimport std.conv;\nimport std.string;\n\n\nint main() {\n debug stdin = File(\"in.txt\", \"r\");\n\n string str, outstr;\n readf(\" %s\\n\", &str);\n if (str[0] == 'h') {\n outstr = \"http://\";\n str = str[4 .. $];\n }\n else {\n outstr = \"ftp://\";\n str = str[3 .. $];\n }\n int pos = str.indexOf(\"ru\", 1);\n outstr ~= str[0 .. pos] ~ \".ru\";\n if (str.length > pos + 1) outstr ~= \"/\" ~ str[pos + 2 .. $];\n writeln(outstr);\n \n return 0;\n}"}], "src_uid": "4c999b7854a8a08960b6501a90b3bba3"} {"nl": {"description": "Petya is having a party soon, and he has decided to invite his $$$n$$$ friends.He wants to make invitations in the form of origami. For each invitation, he needs two red sheets, five green sheets, and eight blue sheets. The store sells an infinite number of notebooks of each color, but each notebook consists of only one color with $$$k$$$ sheets. That is, each notebook contains $$$k$$$ sheets of either red, green, or blue.Find the minimum number of notebooks that Petya needs to buy to invite all $$$n$$$ of his friends.", "input_spec": "The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1\\leq n, k\\leq 10^8$$$)\u00a0\u2014 the number of Petya's friends and the number of sheets in each notebook respectively.", "output_spec": "Print one number\u00a0\u2014 the minimum number of notebooks that Petya needs to buy.", "sample_inputs": ["3 5", "15 6"], "sample_outputs": ["10", "38"], "notes": "NoteIn the first example, we need $$$2$$$ red notebooks, $$$3$$$ green notebooks, and $$$5$$$ blue notebooks.In the second example, we need $$$5$$$ red notebooks, $$$13$$$ green notebooks, and $$$20$$$ blue notebooks."}, "positive_code": [{"source_code": "import std.stdio;\n\nint f(int a, int b)\n{\n\tif (a%b==0)\n\t{\n\t\treturn a/b;\n\t}\n\telse\n\t{\n\t\treturn a/b+1;\n\t}\n}\nint main()\n{\n\tint a=0;\n\tint b=0;\n\treadf(\" %d\", &a);\n\treadf(\" %d\", &b);\n\twriteln(f((a*2),b) + f((a*5),b) + f((a*8),b));\n\treturn 0;\n}"}], "negative_code": [], "src_uid": "d259a3a5c38af34b2a15d61157cc0a39"} {"nl": {"description": "You're given a row with $$$n$$$ chairs. We call a seating of people \"maximal\" if the two following conditions hold: There are no neighbors adjacent to anyone seated. It's impossible to seat one more person without violating the first rule. The seating is given as a string consisting of zeros and ones ($$$0$$$ means that the corresponding seat is empty, $$$1$$$ \u2014 occupied). The goal is to determine whether this seating is \"maximal\".Note that the first and last seats are not adjacent (if $$$n \\ne 2$$$).", "input_spec": "The first line contains a single integer $$$n$$$ ($$$1 \\leq n \\leq 1000$$$)\u00a0\u2014 the number of chairs. The next line contains a string of $$$n$$$ characters, each of them is either zero or one, describing the seating.", "output_spec": "Output \"Yes\" (without quotation marks) if the seating is \"maximal\". Otherwise print \"No\". You are allowed to print letters in whatever case you'd like (uppercase or lowercase).", "sample_inputs": ["3\n101", "4\n1011", "5\n10001"], "sample_outputs": ["Yes", "No", "No"], "notes": "NoteIn sample case one the given seating is maximal.In sample case two the person at chair three has a neighbour to the right.In sample case three it is possible to seat yet another person into chair three."}, "positive_code": [{"source_code": "import std.stdio, std.algorithm, std.string;\n\nvoid main()\n{\n readln();\n auto s = readln().strip();\n\n bool ok = true;\n ok &= !canFind(s, \"000\");\n ok &= !canFind(s, \"11\");\n ok &= !s.startsWith(\"00\");\n ok &= !s.endsWith(\"00\");\n ok &= s != \"0\";\n\n writeln(ok ? \"Yes\" : \"No\");\n}"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip, std.regex;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.chomp;\n\n foreach (i; 0..N-1) {\n if (A[i] == '1' && A[i+1] == '1') {\n writeln(\"No\");\n return;\n }\n }\n\n foreach (i; 0..N) {\n if (A[i] == '1') continue;\n bool ok1 = (i == 0) || (i > 0 && A[i-1] == '0');\n bool ok2 = (i == N-1) || (i < N-1 && A[i+1] == '0');\n if (ok1 && ok2) {\n writeln(\"No\");\n return;\n }\n }\n\n writeln(\"Yes\");\n}\n"}, {"source_code": "import core.bitop, std.algorithm, std.bigint, std.compiler, std.container,\n\tstd.complex, std.bitmanip, std.conv, std.math;\nimport std.numeric : Fft, fft, gcd, inverseFft;\nimport std.random, std.range, std.regex, std.stdio, std.string, std.traits,\n\tstd.typecons, std.uni;\n\nalias pair(X, Y) = Tuple!(X, \"fi\", Y, \"se\");\nalias mp = make_pair;\nalias pii = pair!(int, int);\nalias pll = pair!(long, long);\n// alias gcd = std.numeric.gcd;\nalias lint = long;\nalias rbt = RedBlackTree;\n///modulo\nconst int mod = 10 ^^ 9 + 7, mod2 = mod + 2;\npublic\n{\n\tpure nothrow\n\t{\n\t\t///int length\n\t\tint sz(T)(ref const T a) if (hasLength!T)\n\t\t{\n\t\t\treturn cast(int) a.length;\n\t\t}\n\t\t///make_pair\n\t\tpair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)\n\t\t{\n\t\t\treturn tuple!(X, \"fi\", Y, \"se\")(x_, y_);\n\t\t}\n\t\t///square\n\t\t@property X sqr(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_;\n\t\t}\n\t\t///cube\n\t\t@property X cub(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_ * a_;\n\t\t}\n\t\t///posicion lower bound\n\t\tsize_t lowb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn assumeSorted(a).lowerBound(g).length;\n\t\t}\n\t\t///posicion upper bound\n\t\tsize_t upb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn a.length - assumeSorted(a).upperBound(g).length;\n\t\t}\n\t\t///posicion binary search\n\t\tsize_t binf(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\tauto pos = lowb(a, g);\n\t\t\treturn (g == a[pos]) ? pos : a.length;\n\t\t}\n\t\t///binary search\n\t\tbool binary_search(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn assumeSorted(a).contains(g);\n\t\t}\n\t}\n\tstatic if (version_minor >= 74)\n\t{\n\t\t///read without format\n\t\tbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\treturn readf!(replicate(\" %s\", ptrs.length))(ptrs) == ptrs.length;\n\t\t}\n\t\t///readln without format\n\t\tbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tconst bool fl = readf!(replicate(\" %s\", ptrs.length))(ptrs) == ptrs.length;\n\t\t\treadln;\n\t\t\treturn fl;\n\t\t}\n\t}\n\telse\n\t{\n\t\t///read without format\n\t\tbool input(T...)(ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tsize_t s;\n\t\t\tforeach (ref e; ptrs)\n\t\t\t{\n\t\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\t\ts += readf(\" %c\", &e);\n\t\t\t\telse\n\t\t\t\t\ts += readf(\" %s\", &e);\n\t\t\t}\n\t\t\treturn s == ptrs.length;\n\t\t}\n\t\t///readln without format\n\t\tbool read(T...)(ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tsize_t s;\n\t\t\tforeach (ref e; ptrs)\n\t\t\t{\n\t\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\t\ts += readf(\" %c\", &e);\n\t\t\t\telse\n\t\t\t\t\ts += readf(\" %s\", &e);\n\t\t\t}\n\t\t\treadln;\n\t\t\treturn s == ptrs.length;\n\t\t}\n\t}\n\t///opening file\n\tnothrow auto inf(in char* name)\n\t{\n\t\treturn freopen(name, \"r\", core.stdc.stdio.stdin);\n\t}\n\t///closing file\n\tnothrow auto ouf(in char* name)\n\t{\n\t\treturn freopen(name, \"w\", core.stdc.stdio.stdout);\n\t}\n\t///parsing array from line\n\t@property auto arread(T)()\n\t{\n\t\treturn readln.splitter.map!(to!(T)).array;\n\t}\n\t///outbuffer\n\tvoid enter(T...)(T args)\n\t{\n\t\twriteln(args);\n\t\tstdout.flush;\n\t}\n}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\nvoid main()\n{\n\tversion (home)\n\t{\n\t\tassert(freopen(\"input.txt\", \"r\", core.stdc.stdio.stdin));\n\t}\n\tint n;\n\tread(n);\n\tstring s = readln.strip;\n\tforeach (i; 0 .. n - 1)\n\t{\n\t\tif (s[i] == '1' && s[i + 1] == '1')\n\t\t{\n\t\t\treturn writeln(\"No\");\n\t\t}\n\t\tif (i == 0 && s[i] == '0' && s[i + 1] == '0')\n\t\t\treturn writeln(\"No\");\n\t\tif (i == n - 2 && s[i] == '0' && s[i + 1] == '0')\n\t\t\treturn writeln(\"No\");\n\t\tif (i > 0 && s[i] == '0' && s[i - 1] == '0' && s[i + 1] == '0')\n\t\t{\n\t\t\treturn writeln(\"No\");\n\t\t}\n\t}\n\tif (n == 1 && s[0] == '0')\n\t\twriteln(\"No\");\n\telse\n\t\twriteln(\"Yes\");\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.algorithm, std.string;\n\nvoid main()\n{\n readln();\n auto s = readln();\n\n bool ok = true;\n ok &= !canFind(s, \"000\");\n ok &= !canFind(s, \"11\");\n ok &= !s.startsWith(\"00\");\n ok &= !s.endsWith(\"00\");\n\n writeln(ok ? \"Yes\" : \"No\");\n}"}, {"source_code": "import core.bitop, std.algorithm, std.bigint, std.compiler, std.container,\n\tstd.complex, std.bitmanip, std.conv, std.math;\nimport std.numeric : Fft, fft, gcd, inverseFft;\nimport std.random, std.range, std.regex, std.stdio, std.string, std.traits,\n\tstd.typecons, std.uni;\n\nalias pair(X, Y) = Tuple!(X, \"fi\", Y, \"se\");\nalias mp = make_pair;\nalias pii = pair!(int, int);\nalias pll = pair!(long, long);\n// alias gcd = std.numeric.gcd;\nalias lint = long;\nalias rbt = RedBlackTree;\n///modulo\nconst int mod = 10 ^^ 9 + 7, mod2 = mod + 2;\npublic\n{\n\tpure nothrow\n\t{\n\t\t///int length\n\t\tint sz(T)(ref const T a) if (hasLength!T)\n\t\t{\n\t\t\treturn cast(int) a.length;\n\t\t}\n\t\t///make_pair\n\t\tpair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)\n\t\t{\n\t\t\treturn tuple!(X, \"fi\", Y, \"se\")(x_, y_);\n\t\t}\n\t\t///square\n\t\t@property X sqr(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_;\n\t\t}\n\t\t///cube\n\t\t@property X cub(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_ * a_;\n\t\t}\n\t\t///posicion lower bound\n\t\tsize_t lowb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn assumeSorted(a).lowerBound(g).length;\n\t\t}\n\t\t///posicion upper bound\n\t\tsize_t upb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn a.length - assumeSorted(a).upperBound(g).length;\n\t\t}\n\t\t///posicion binary search\n\t\tsize_t binf(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\tauto pos = lowb(a, g);\n\t\t\treturn (g == a[pos]) ? pos : a.length;\n\t\t}\n\t\t///binary search\n\t\tbool binary_search(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn assumeSorted(a).contains(g);\n\t\t}\n\t}\n\tstatic if (version_minor >= 74)\n\t{\n\t\t///read without format\n\t\tbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\treturn readf!(replicate(\" %s\", ptrs.length))(ptrs) == ptrs.length;\n\t\t}\n\t\t///readln without format\n\t\tbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tconst bool fl = readf!(replicate(\" %s\", ptrs.length))(ptrs) == ptrs.length;\n\t\t\treadln;\n\t\t\treturn fl;\n\t\t}\n\t}\n\telse\n\t{\n\t\t///read without format\n\t\tbool input(T...)(ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tsize_t s;\n\t\t\tforeach (ref e; ptrs)\n\t\t\t{\n\t\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\t\ts += readf(\" %c\", &e);\n\t\t\t\telse\n\t\t\t\t\ts += readf(\" %s\", &e);\n\t\t\t}\n\t\t\treturn s == ptrs.length;\n\t\t}\n\t\t///readln without format\n\t\tbool read(T...)(ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tsize_t s;\n\t\t\tforeach (ref e; ptrs)\n\t\t\t{\n\t\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\t\ts += readf(\" %c\", &e);\n\t\t\t\telse\n\t\t\t\t\ts += readf(\" %s\", &e);\n\t\t\t}\n\t\t\treadln;\n\t\t\treturn s == ptrs.length;\n\t\t}\n\t}\n\t///opening file\n\tnothrow auto inf(in char* name)\n\t{\n\t\treturn freopen(name, \"r\", core.stdc.stdio.stdin);\n\t}\n\t///closing file\n\tnothrow auto ouf(in char* name)\n\t{\n\t\treturn freopen(name, \"w\", core.stdc.stdio.stdout);\n\t}\n\t///parsing array from line\n\t@property auto arread(T)()\n\t{\n\t\treturn readln.splitter.map!(to!(T)).array;\n\t}\n\t///outbuffer\n\tvoid enter(T...)(T args)\n\t{\n\t\twriteln(args);\n\t\tstdout.flush;\n\t}\n}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\nvoid main()\n{\n\tversion (home)\n\t{\n\t\tassert(freopen(\"input.txt\", \"r\", core.stdc.stdio.stdin));\n\t}\n\tint n;\n\tread(n);\n\tstring s = readln.strip;\n\tforeach (i; 0 .. n - 1)\n\t{\n\t\tif (s[i] == '1' && s[i + 1] == '1')\n\t\t{\n\t\t\treturn writeln(\"No\");\n\t\t}\n\t\tif (i == 0 && s[i] == '0' && s[i + 1] == '0')\n\t\t\treturn writeln(\"No\");\n\t\tif (i == n - 2 && s[i] == '0' && s[i + 1] == '0')\n\t\t\treturn writeln(\"No\");\n\t\tif (i > 0 && s[i] == '0' && s[i - 1] == '0' && s[i + 1] == '0')\n\t\t{\n\t\t\treturn writeln(\"No\");\n\t\t}\n\t}\n\twriteln(\"Yes\");\n\n}\n"}, {"source_code": "import core.bitop, std.algorithm, std.bigint, std.compiler, std.container,\n\tstd.complex, std.bitmanip, std.conv, std.math;\nimport std.numeric : Fft, fft, gcd, inverseFft;\nimport std.random, std.range, std.regex, std.stdio, std.string, std.traits,\n\tstd.typecons, std.uni;\n\nalias pair(X, Y) = Tuple!(X, \"fi\", Y, \"se\");\nalias mp = make_pair;\nalias pii = pair!(int, int);\nalias pll = pair!(long, long);\n// alias gcd = std.numeric.gcd;\nalias lint = long;\nalias rbt = RedBlackTree;\n///modulo\nconst int mod = 10 ^^ 9 + 7, mod2 = mod + 2;\npublic\n{\n\tpure nothrow\n\t{\n\t\t///int length\n\t\tint sz(T)(ref const T a) if (hasLength!T)\n\t\t{\n\t\t\treturn cast(int) a.length;\n\t\t}\n\t\t///make_pair\n\t\tpair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)\n\t\t{\n\t\t\treturn tuple!(X, \"fi\", Y, \"se\")(x_, y_);\n\t\t}\n\t\t///square\n\t\t@property X sqr(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_;\n\t\t}\n\t\t///cube\n\t\t@property X cub(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_ * a_;\n\t\t}\n\t\t///posicion lower bound\n\t\tsize_t lowb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn assumeSorted(a).lowerBound(g).length;\n\t\t}\n\t\t///posicion upper bound\n\t\tsize_t upb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn a.length - assumeSorted(a).upperBound(g).length;\n\t\t}\n\t\t///posicion binary search\n\t\tsize_t binf(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\tauto pos = lowb(a, g);\n\t\t\treturn (g == a[pos]) ? pos : a.length;\n\t\t}\n\t\t///binary search\n\t\tbool binary_search(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn assumeSorted(a).contains(g);\n\t\t}\n\t}\n\tstatic if (version_minor >= 74)\n\t{\n\t\t///read without format\n\t\tbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\treturn readf!(replicate(\" %s\", ptrs.length))(ptrs) == ptrs.length;\n\t\t}\n\t\t///readln without format\n\t\tbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tconst bool fl = readf!(replicate(\" %s\", ptrs.length))(ptrs) == ptrs.length;\n\t\t\treadln;\n\t\t\treturn fl;\n\t\t}\n\t}\n\telse\n\t{\n\t\t///read without format\n\t\tbool input(T...)(ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tsize_t s;\n\t\t\tforeach (ref e; ptrs)\n\t\t\t{\n\t\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\t\ts += readf(\" %c\", &e);\n\t\t\t\telse\n\t\t\t\t\ts += readf(\" %s\", &e);\n\t\t\t}\n\t\t\treturn s == ptrs.length;\n\t\t}\n\t\t///readln without format\n\t\tbool read(T...)(ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tsize_t s;\n\t\t\tforeach (ref e; ptrs)\n\t\t\t{\n\t\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\t\ts += readf(\" %c\", &e);\n\t\t\t\telse\n\t\t\t\t\ts += readf(\" %s\", &e);\n\t\t\t}\n\t\t\treadln;\n\t\t\treturn s == ptrs.length;\n\t\t}\n\t}\n\t///opening file\n\tnothrow auto inf(in char* name)\n\t{\n\t\treturn freopen(name, \"r\", core.stdc.stdio.stdin);\n\t}\n\t///closing file\n\tnothrow auto ouf(in char* name)\n\t{\n\t\treturn freopen(name, \"w\", core.stdc.stdio.stdout);\n\t}\n\t///parsing array from line\n\t@property auto arread(T)()\n\t{\n\t\treturn readln.splitter.map!(to!(T)).array;\n\t}\n\t///outbuffer\n\tvoid enter(T...)(T args)\n\t{\n\t\twriteln(args);\n\t\tstdout.flush;\n\t}\n}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\nvoid main()\n{\n\tversion (home)\n\t{\n\t\tassert(freopen(\"input.txt\", \"r\", core.stdc.stdio.stdin));\n\t}\n\tint n;\n\tread(n);\n\tstring s = readln.strip;\n\tif (count(s, '1') == (n + 1) / 2)\n\t\twriteln(\"Yes\");\n\telse\n\t\twriteln(\"No\");\n}\n"}, {"source_code": "import core.bitop, std.algorithm, std.bigint, std.compiler, std.container,\n\tstd.complex, std.bitmanip, std.conv, std.math;\nimport std.numeric : Fft, fft, gcd, inverseFft;\nimport std.random, std.range, std.regex, std.stdio, std.string, std.traits,\n\tstd.typecons, std.uni;\n\nalias pair(X, Y) = Tuple!(X, \"fi\", Y, \"se\");\nalias mp = make_pair;\nalias pii = pair!(int, int);\nalias pll = pair!(long, long);\n// alias gcd = std.numeric.gcd;\nalias lint = long;\nalias rbt = RedBlackTree;\n///modulo\nconst int mod = 10 ^^ 9 + 7, mod2 = mod + 2;\npublic\n{\n\tpure nothrow\n\t{\n\t\t///int length\n\t\tint sz(T)(ref const T a) if (hasLength!T)\n\t\t{\n\t\t\treturn cast(int) a.length;\n\t\t}\n\t\t///make_pair\n\t\tpair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)\n\t\t{\n\t\t\treturn tuple!(X, \"fi\", Y, \"se\")(x_, y_);\n\t\t}\n\t\t///square\n\t\t@property X sqr(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_;\n\t\t}\n\t\t///cube\n\t\t@property X cub(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_ * a_;\n\t\t}\n\t\t///posicion lower bound\n\t\tsize_t lowb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn assumeSorted(a).lowerBound(g).length;\n\t\t}\n\t\t///posicion upper bound\n\t\tsize_t upb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn a.length - assumeSorted(a).upperBound(g).length;\n\t\t}\n\t\t///posicion binary search\n\t\tsize_t binf(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\tauto pos = lowb(a, g);\n\t\t\treturn (g == a[pos]) ? pos : a.length;\n\t\t}\n\t\t///binary search\n\t\tbool binary_search(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn assumeSorted(a).contains(g);\n\t\t}\n\t}\n\tstatic if (version_minor >= 74)\n\t{\n\t\t///read without format\n\t\tbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\treturn readf!(replicate(\" %s\", ptrs.length))(ptrs) == ptrs.length;\n\t\t}\n\t\t///readln without format\n\t\tbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tconst bool fl = readf!(replicate(\" %s\", ptrs.length))(ptrs) == ptrs.length;\n\t\t\treadln;\n\t\t\treturn fl;\n\t\t}\n\t}\n\telse\n\t{\n\t\t///read without format\n\t\tbool input(T...)(ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tsize_t s;\n\t\t\tforeach (ref e; ptrs)\n\t\t\t{\n\t\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\t\ts += readf(\" %c\", &e);\n\t\t\t\telse\n\t\t\t\t\ts += readf(\" %s\", &e);\n\t\t\t}\n\t\t\treturn s == ptrs.length;\n\t\t}\n\t\t///readln without format\n\t\tbool read(T...)(ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tsize_t s;\n\t\t\tforeach (ref e; ptrs)\n\t\t\t{\n\t\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\t\ts += readf(\" %c\", &e);\n\t\t\t\telse\n\t\t\t\t\ts += readf(\" %s\", &e);\n\t\t\t}\n\t\t\treadln;\n\t\t\treturn s == ptrs.length;\n\t\t}\n\t}\n\t///opening file\n\tnothrow auto inf(in char* name)\n\t{\n\t\treturn freopen(name, \"r\", core.stdc.stdio.stdin);\n\t}\n\t///closing file\n\tnothrow auto ouf(in char* name)\n\t{\n\t\treturn freopen(name, \"w\", core.stdc.stdio.stdout);\n\t}\n\t///parsing array from line\n\t@property auto arread(T)()\n\t{\n\t\treturn readln.splitter.map!(to!(T)).array;\n\t}\n\t///outbuffer\n\tvoid enter(T...)(T args)\n\t{\n\t\twriteln(args);\n\t\tstdout.flush;\n\t}\n}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\nvoid main()\n{\n\tversion (home)\n\t{\n\t\tassert(freopen(\"input.txt\", \"r\", core.stdc.stdio.stdin));\n\t}\n\tint n;\n\tread(n);\n\tstring s = readln.strip;\n\tforeach (i; 0 .. n - 1)\n\t{\n\t\tif (s[i] == '1' && s[i + 1] == '1')\n\t\t{\n\t\t\treturn writeln(\"No\");\n\t\t}\n\t\tif (i > 0 && s[i] == '0' && s[i - 1] == '0' && s[i + 1] == '0')\n\t\t{\n\t\t\treturn writeln(\"No\");\n\t\t}\n\t}\n\twriteln(\"Yes\");\n\n}\n"}, {"source_code": "import core.bitop, std.algorithm, std.bigint, std.compiler, std.container,\n\tstd.complex, std.bitmanip, std.conv, std.math;\nimport std.numeric : Fft, fft, gcd, inverseFft;\nimport std.random, std.range, std.regex, std.stdio, std.string, std.traits,\n\tstd.typecons, std.uni;\n\nalias pair(X, Y) = Tuple!(X, \"fi\", Y, \"se\");\nalias mp = make_pair;\nalias pii = pair!(int, int);\nalias pll = pair!(long, long);\n// alias gcd = std.numeric.gcd;\nalias lint = long;\nalias rbt = RedBlackTree;\n///modulo\nconst int mod = 10 ^^ 9 + 7, mod2 = mod + 2;\npublic\n{\n\tpure nothrow\n\t{\n\t\t///int length\n\t\tint sz(T)(ref const T a) if (hasLength!T)\n\t\t{\n\t\t\treturn cast(int) a.length;\n\t\t}\n\t\t///make_pair\n\t\tpair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)\n\t\t{\n\t\t\treturn tuple!(X, \"fi\", Y, \"se\")(x_, y_);\n\t\t}\n\t\t///square\n\t\t@property X sqr(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_;\n\t\t}\n\t\t///cube\n\t\t@property X cub(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_ * a_;\n\t\t}\n\t\t///posicion lower bound\n\t\tsize_t lowb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn assumeSorted(a).lowerBound(g).length;\n\t\t}\n\t\t///posicion upper bound\n\t\tsize_t upb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn a.length - assumeSorted(a).upperBound(g).length;\n\t\t}\n\t\t///posicion binary search\n\t\tsize_t binf(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\tauto pos = lowb(a, g);\n\t\t\treturn (g == a[pos]) ? pos : a.length;\n\t\t}\n\t\t///binary search\n\t\tbool binary_search(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn assumeSorted(a).contains(g);\n\t\t}\n\t}\n\tstatic if (version_minor >= 74)\n\t{\n\t\t///read without format\n\t\tbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\treturn readf!(replicate(\" %s\", ptrs.length))(ptrs) == ptrs.length;\n\t\t}\n\t\t///readln without format\n\t\tbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tconst bool fl = readf!(replicate(\" %s\", ptrs.length))(ptrs) == ptrs.length;\n\t\t\treadln;\n\t\t\treturn fl;\n\t\t}\n\t}\n\telse\n\t{\n\t\t///read without format\n\t\tbool input(T...)(ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tsize_t s;\n\t\t\tforeach (ref e; ptrs)\n\t\t\t{\n\t\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\t\ts += readf(\" %c\", &e);\n\t\t\t\telse\n\t\t\t\t\ts += readf(\" %s\", &e);\n\t\t\t}\n\t\t\treturn s == ptrs.length;\n\t\t}\n\t\t///readln without format\n\t\tbool read(T...)(ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tsize_t s;\n\t\t\tforeach (ref e; ptrs)\n\t\t\t{\n\t\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\t\ts += readf(\" %c\", &e);\n\t\t\t\telse\n\t\t\t\t\ts += readf(\" %s\", &e);\n\t\t\t}\n\t\t\treadln;\n\t\t\treturn s == ptrs.length;\n\t\t}\n\t}\n\t///opening file\n\tnothrow auto inf(in char* name)\n\t{\n\t\treturn freopen(name, \"r\", core.stdc.stdio.stdin);\n\t}\n\t///closing file\n\tnothrow auto ouf(in char* name)\n\t{\n\t\treturn freopen(name, \"w\", core.stdc.stdio.stdout);\n\t}\n\t///parsing array from line\n\t@property auto arread(T)()\n\t{\n\t\treturn readln.splitter.map!(to!(T)).array;\n\t}\n\t///outbuffer\n\tvoid enter(T...)(T args)\n\t{\n\t\twriteln(args);\n\t\tstdout.flush;\n\t}\n}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\nvoid main()\n{\n\tversion (home)\n\t{\n\t\tassert(freopen(\"input.txt\", \"r\", core.stdc.stdio.stdin));\n\t}\n\tint n;\n\tread(n);\n\tstring s = readln.strip;\n\tif (n == 2)\n\t\tn++;\n\tif (count(s, '1') == (n + 1) / 2)\n\t\twriteln(\"Yes\");\n\telse\n\t\twriteln(\"No\");\n}\n"}, {"source_code": "import core.bitop, std.algorithm, std.bigint, std.compiler, std.container,\n\tstd.complex, std.bitmanip, std.conv, std.math;\nimport std.numeric : Fft, fft, gcd, inverseFft;\nimport std.random, std.range, std.regex, std.stdio, std.string, std.traits,\n\tstd.typecons, std.uni;\n\nalias pair(X, Y) = Tuple!(X, \"fi\", Y, \"se\");\nalias mp = make_pair;\nalias pii = pair!(int, int);\nalias pll = pair!(long, long);\n// alias gcd = std.numeric.gcd;\nalias lint = long;\nalias rbt = RedBlackTree;\n///modulo\nconst int mod = 10 ^^ 9 + 7, mod2 = mod + 2;\npublic\n{\n\tpure nothrow\n\t{\n\t\t///int length\n\t\tint sz(T)(ref const T a) if (hasLength!T)\n\t\t{\n\t\t\treturn cast(int) a.length;\n\t\t}\n\t\t///make_pair\n\t\tpair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)\n\t\t{\n\t\t\treturn tuple!(X, \"fi\", Y, \"se\")(x_, y_);\n\t\t}\n\t\t///square\n\t\t@property X sqr(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_;\n\t\t}\n\t\t///cube\n\t\t@property X cub(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_ * a_;\n\t\t}\n\t\t///posicion lower bound\n\t\tsize_t lowb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn assumeSorted(a).lowerBound(g).length;\n\t\t}\n\t\t///posicion upper bound\n\t\tsize_t upb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn a.length - assumeSorted(a).upperBound(g).length;\n\t\t}\n\t\t///posicion binary search\n\t\tsize_t binf(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\tauto pos = lowb(a, g);\n\t\t\treturn (g == a[pos]) ? pos : a.length;\n\t\t}\n\t\t///binary search\n\t\tbool binary_search(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn assumeSorted(a).contains(g);\n\t\t}\n\t}\n\tstatic if (version_minor >= 74)\n\t{\n\t\t///read without format\n\t\tbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\treturn readf!(replicate(\" %s\", ptrs.length))(ptrs) == ptrs.length;\n\t\t}\n\t\t///readln without format\n\t\tbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tconst bool fl = readf!(replicate(\" %s\", ptrs.length))(ptrs) == ptrs.length;\n\t\t\treadln;\n\t\t\treturn fl;\n\t\t}\n\t}\n\telse\n\t{\n\t\t///read without format\n\t\tbool input(T...)(ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tsize_t s;\n\t\t\tforeach (ref e; ptrs)\n\t\t\t{\n\t\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\t\ts += readf(\" %c\", &e);\n\t\t\t\telse\n\t\t\t\t\ts += readf(\" %s\", &e);\n\t\t\t}\n\t\t\treturn s == ptrs.length;\n\t\t}\n\t\t///readln without format\n\t\tbool read(T...)(ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tsize_t s;\n\t\t\tforeach (ref e; ptrs)\n\t\t\t{\n\t\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\t\ts += readf(\" %c\", &e);\n\t\t\t\telse\n\t\t\t\t\ts += readf(\" %s\", &e);\n\t\t\t}\n\t\t\treadln;\n\t\t\treturn s == ptrs.length;\n\t\t}\n\t}\n\t///opening file\n\tnothrow auto inf(in char* name)\n\t{\n\t\treturn freopen(name, \"r\", core.stdc.stdio.stdin);\n\t}\n\t///closing file\n\tnothrow auto ouf(in char* name)\n\t{\n\t\treturn freopen(name, \"w\", core.stdc.stdio.stdout);\n\t}\n\t///parsing array from line\n\t@property auto arread(T)()\n\t{\n\t\treturn readln.splitter.map!(to!(T)).array;\n\t}\n\t///outbuffer\n\tvoid enter(T...)(T args)\n\t{\n\t\twriteln(args);\n\t\tstdout.flush;\n\t}\n}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\nvoid main()\n{\n\tversion (home)\n\t{\n\t\tassert(freopen(\"input.txt\", \"r\", core.stdc.stdio.stdin));\n\t}\n\tint n;\n\tread(n);\n\tstring s = readln.strip;\n\tif (n == 2)\n\t{\n\t\tif (s[0] == '1' && s[1] == '1')\n\t\t\twriteln(\"Yes\");\n\t\telse\n\t\t\twriteln(\"No\");\n\t\treturn;\n\t}\n\tforeach (i; 0 .. s.length - 1)\n\t{\n\t\tif (s[i] == '1' && s[i + 1] == '1')\n\t\t{\n\t\t\treturn writeln(\"No\");\n\t\t}\n\t}\n\tif (count(s, '1') == (n + 1) / 2)\n\t\twriteln(\"Yes\");\n\telse\n\t\twriteln(\"No\");\n}\n"}, {"source_code": "import core.bitop, std.algorithm, std.bigint, std.compiler, std.container,\n\tstd.complex, std.bitmanip, std.conv, std.math;\nimport std.numeric : Fft, fft, gcd, inverseFft;\nimport std.random, std.range, std.regex, std.stdio, std.string, std.traits,\n\tstd.typecons, std.uni;\n\nalias pair(X, Y) = Tuple!(X, \"fi\", Y, \"se\");\nalias mp = make_pair;\nalias pii = pair!(int, int);\nalias pll = pair!(long, long);\n// alias gcd = std.numeric.gcd;\nalias lint = long;\nalias rbt = RedBlackTree;\n///modulo\nconst int mod = 10 ^^ 9 + 7, mod2 = mod + 2;\npublic\n{\n\tpure nothrow\n\t{\n\t\t///int length\n\t\tint sz(T)(ref const T a) if (hasLength!T)\n\t\t{\n\t\t\treturn cast(int) a.length;\n\t\t}\n\t\t///make_pair\n\t\tpair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)\n\t\t{\n\t\t\treturn tuple!(X, \"fi\", Y, \"se\")(x_, y_);\n\t\t}\n\t\t///square\n\t\t@property X sqr(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_;\n\t\t}\n\t\t///cube\n\t\t@property X cub(X)(in X a_)\n\t\t{\n\t\t\treturn a_ * a_ * a_;\n\t\t}\n\t\t///posicion lower bound\n\t\tsize_t lowb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn assumeSorted(a).lowerBound(g).length;\n\t\t}\n\t\t///posicion upper bound\n\t\tsize_t upb(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn a.length - assumeSorted(a).upperBound(g).length;\n\t\t}\n\t\t///posicion binary search\n\t\tsize_t binf(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\tauto pos = lowb(a, g);\n\t\t\treturn (g == a[pos]) ? pos : a.length;\n\t\t}\n\t\t///binary search\n\t\tbool binary_search(T, X)(T a, auto ref X g)\n\t\t\t\tif (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))\n\t\t{\n\t\t\treturn assumeSorted(a).contains(g);\n\t\t}\n\t}\n\tstatic if (version_minor >= 74)\n\t{\n\t\t///read without format\n\t\tbool input(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\treturn readf!(replicate(\" %s\", ptrs.length))(ptrs) == ptrs.length;\n\t\t}\n\t\t///readln without format\n\t\tbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tconst bool fl = readf!(replicate(\" %s\", ptrs.length))(ptrs) == ptrs.length;\n\t\t\treadln;\n\t\t\treturn fl;\n\t\t}\n\t}\n\telse\n\t{\n\t\t///read without format\n\t\tbool input(T...)(ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tsize_t s;\n\t\t\tforeach (ref e; ptrs)\n\t\t\t{\n\t\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\t\ts += readf(\" %c\", &e);\n\t\t\t\telse\n\t\t\t\t\ts += readf(\" %s\", &e);\n\t\t\t}\n\t\t\treturn s == ptrs.length;\n\t\t}\n\t\t///readln without format\n\t\tbool read(T...)(ref T ptrs) if (ptrs.length > 0)\n\t\t{\n\t\t\tsize_t s;\n\t\t\tforeach (ref e; ptrs)\n\t\t\t{\n\t\t\t\tif (isSomeChar!(Unqual!(typeof(e))))\n\t\t\t\t\ts += readf(\" %c\", &e);\n\t\t\t\telse\n\t\t\t\t\ts += readf(\" %s\", &e);\n\t\t\t}\n\t\t\treadln;\n\t\t\treturn s == ptrs.length;\n\t\t}\n\t}\n\t///opening file\n\tnothrow auto inf(in char* name)\n\t{\n\t\treturn freopen(name, \"r\", core.stdc.stdio.stdin);\n\t}\n\t///closing file\n\tnothrow auto ouf(in char* name)\n\t{\n\t\treturn freopen(name, \"w\", core.stdc.stdio.stdout);\n\t}\n\t///parsing array from line\n\t@property auto arread(T)()\n\t{\n\t\treturn readln.splitter.map!(to!(T)).array;\n\t}\n\t///outbuffer\n\tvoid enter(T...)(T args)\n\t{\n\t\twriteln(args);\n\t\tstdout.flush;\n\t}\n}\n//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold return static heapify join filter foreach\n//------------------------------------------program beginning--------------------------\nvoid main()\n{\n\tversion (home)\n\t{\n\t\tassert(freopen(\"input.txt\", \"r\", core.stdc.stdio.stdin));\n\t}\n\tint n;\n\tread(n);\n\tstring s = readln.strip;\n\tforeach (i; 0 .. s.length - 1)\n\t{\n\t\tif (s[i] == '1' && s[i + 1] == '1')\n\t\t{\n\t\t\treturn writeln(\"No\");\n\t\t}\n\t}\n\tif (count(s, '1') == (n + 1) / 2)\n\t\twriteln(\"Yes\");\n\telse\n\t\twriteln(\"No\");\n}\n"}], "src_uid": "c14d255785b1f668d04b0bf6dcadf32d"} {"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\u2009\u2264\u2009n\u2009\u2264\u2009100) \u2014 the number of apples. The second line contains n integers w1,\u2009w2,\u2009...,\u2009wn (wi\u2009=\u2009100 or wi\u2009=\u2009200), 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": "import std.stdio,std.conv,std.array;\n\nvoid main()\n{\n\tint CountLarge = 0,CountSmall = 0;\n\tauto n = readln();\n\tforeach(string s;split(readln(),\" \"))\n\t{\n\t\tuint ui = parse!uint(s);\n\t\tif(ui == 200)CountLarge++; else CountSmall++;\n\t}\n\tif(CountLarge % 2 == 0) CountLarge = 0;\n\telse{\n\t\tif(CountSmall >= 2){\n\t\t\tCountLarge = 0;\n\t\t\tCountSmall -= 2;\n\t\t}else{\n\t\t\twriteln(\"NO\");\n\t\t\treturn;\n\t\t}\n\t}\n\tif(CountSmall % 2 == 0) writeln(\"YES\"); else writeln(\"NO\");\n}"}, {"source_code": "import std.stdio,std.conv,std.array;\n\nvoid main()\n{\n\tint CountLarge = 0,CountSmall = 0;\n\tauto n = readln();\n\tforeach(string s;split(readln(),\" \"))\n\t{\n\t\tuint ui = parse!uint(s);\n\t\tif(ui == 200)CountLarge++; else CountSmall++;\n\t}\n\twriteln(((CountSmall % 2 == 1) || ((CountLarge % 2 == 1)&&(CountSmall <= 1)))?\"NO\":\"YES\");\n}"}], "negative_code": [{"source_code": "import std.stdio,std.conv,std.array;\n\nvoid main()\n{\n\tint CountLarge = 0,CountSmall = 0;\n\tauto n = readln();\n\tforeach(string s;split(readln(),\" \"))\n\t{\n\t\tuint ui = parse!uint(s);\n\t\tif(ui == 200)CountLarge++; else CountSmall++;\n\t}\n\t// if(CountLarge % 2 == 0) CountLarge = 0;\n\t// else{\n\t\t// if(CountSmall >= 2){\n\t\t\t// CountLarge = 0;\n\t\t\t// CountSmall -= 2;\n\t\t// }else{\n\t\t\t// writeln(\"NO\");\n\t\t\t// return;\n\t\t// }\n\t// }\n\t// if(CountSmall % 2 == 0) writeln(\"YES\"); else writeln(\"NO\");\n\twriteln(((CountSmall % 2 != 0) || (CountSmall < 2))?\"NO\":\"YES\");\n}"}], "src_uid": "9679acef82356004e47b1118f8fc836a"} {"nl": {"description": " It's the end of July\u00a0\u2013 the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to be disclosed to the general public: the information can cause discord in the kingdom of Sweetland in case it turns out to reach the wrong hands. So it's a necessity to not let any uninvited guests in.There are 26 entrances in Jelly Castle, enumerated with uppercase English letters from A to Z. Because of security measures, each guest is known to be assigned an entrance he should enter the castle through. The door of each entrance is opened right before the first guest's arrival and closed right after the arrival of the last guest that should enter the castle through this entrance. No two guests can enter the castle simultaneously.For an entrance to be protected from possible intrusion, a candy guard should be assigned to it. There are k such guards in the castle, so if there are more than k opened doors, one of them is going to be left unguarded! Notice that a guard can't leave his post until the door he is assigned to is closed.Slastyona had a suspicion that there could be uninvited guests at the evening. She knows the order in which the invited guests entered the castle, and wants you to help her check whether there was a moment when more than k doors were opened.", "input_spec": "Two integers are given in the first string: the number of guests n and the number of guards k (1\u2009\u2264\u2009n\u2009\u2264\u2009106, 1\u2009\u2264\u2009k\u2009\u2264\u200926). In the second string, n uppercase English letters s1s2... sn are given, where si is the entrance used by the i-th guest.", "output_spec": "Output \u00abYES\u00bb if at least one door was unguarded during some time, and \u00abNO\u00bb otherwise. You can output each letter in arbitrary case (upper or lower).", "sample_inputs": ["5 1\nAABBB", "5 1\nABABB"], "sample_outputs": ["NO", "YES"], "notes": "NoteIn the first sample case, the door A is opened right before the first guest's arrival and closed when the second guest enters the castle. The door B is opened right before the arrival of the third guest, and closed after the fifth one arrives. One guard can handle both doors, as the first one is closed before the second one is opened.In the second sample case, the door B is opened before the second guest's arrival, but the only guard can't leave the door A unattended, as there is still one more guest that should enter the castle through this door. "}, "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.stdio;\n\nvoid main() {\n auto s = readln.split.map!(to!int);\n auto N = s[0];\n auto K = s[1];\n auto S = readln.chomp;\n auto F = new int[](26);\n auto L = new int[](26);\n fill(F, 1 << 29);\n\n foreach (i; 0..N) {\n F[S[i] - 'A'] = min(F[S[i] - 'A'], i);\n L[S[i] - 'A'] = max(L[S[i] - 'A'], i);\n }\n\n auto imos = new int[](10^^6 + 100);\n foreach (i; 0..26) if (F[i] != 1 << 29) imos[F[i]] += 1, imos[L[i] + 1] -= 1;\n foreach (i; 0..10^^6 + 50) imos[i + 1] += imos[i];\n\n writeln(imos.reduce!max > K ? \"YES\" : \"NO\");\n}\n"}, {"source_code": "// tested by Hightail - https://github.com/dj3500/hightail\nimport std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.math, std.typecons, std.container, core.bitop;\nimport std.datetime, std.bigint;\n\nint n, k;\nstring s;\n\nvoid main() {\n scan(n, k);\n s = readln.chomp;\n\n auto t = new int[](n + 10);\n\n foreach (char ch ; 'A' .. 'Z' + 1) {\n foreach (i ; 0 .. n) {\n if (s[i] == ch) {\n t[i]++;\n break;\n }\n }\n\n foreach_reverse (i ; 0 .. n) {\n if (s[i] == ch) {\n t[i + 1]--;\n break;\n }\n }\n }\n\n foreach (i ; 0 .. n + 1) {\n t[i + 1] += t[i];\n }\n\n debug {\n writeln(t);\n }\n\n if (t.reduce!max > k) {\n writeln(\"YES\");\n }\n else {\n writeln(\"NO\");\n }\n}\n\n\n\n\nvoid scan(T...)(ref T args) {\n string[] line = readln.split;\n foreach (ref arg; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}\n\n\nvoid fillAll(R, T)(ref R arr, T value) {\n static if (is(typeof(arr[] = value))) {\n arr[] = value;\n }\n else {\n foreach (ref e; arr) {\n fillAll(e, value);\n }\n }\n}"}], "negative_code": [], "src_uid": "216323563f5b2dd63edc30cb9b4849a5"} {"nl": {"description": "As you have noticed, there are lovely girls in Arpa\u2019s land.People in Arpa's land are numbered from 1 to n. Everyone has exactly one crush, i-th person's crush is person with the number crushi. Someday Arpa shouted Owf loudly from the top of the palace and a funny game started in Arpa's land. The rules are as follows.The game consists of rounds. Assume person x wants to start a round, he calls crushx and says: \"Oww...wwf\" (the letter w is repeated t times) and cuts off the phone immediately. If t\u2009>\u20091 then crushx calls crushcrushx and says: \"Oww...wwf\" (the letter w is repeated t\u2009-\u20091 times) and cuts off the phone immediately. The round continues until some person receives an \"Owf\" (t\u2009=\u20091). This person is called the Joon-Joon of the round. There can't be two rounds at the same time.Mehrdad has an evil plan to make the game more funny, he wants to find smallest t (t\u2009\u2265\u20091) such that for each person x, if x starts some round and y becomes the Joon-Joon of the round, then by starting from y, x would become the Joon-Joon of the round. Find such t for Mehrdad if it's possible.Some strange fact in Arpa's land is that someone can be himself's crush (i.e. crushi\u2009=\u2009i).", "input_spec": "The first line of input contains integer n (1\u2009\u2264\u2009n\u2009\u2264\u2009100)\u00a0\u2014 the number of people in Arpa's land. The second line contains n integers, i-th of them is crushi (1\u2009\u2264\u2009crushi\u2009\u2264\u2009n)\u00a0\u2014 the number of i-th person's crush.", "output_spec": "If there is no t satisfying the condition, print -1. Otherwise print such smallest t.", "sample_inputs": ["4\n2 3 1 4", "4\n4 4 4 4", "4\n2 1 4 3"], "sample_outputs": ["3", "-1", "1"], "notes": "NoteIn the first sample suppose t\u2009=\u20093. If the first person starts some round:The first person calls the second person and says \"Owwwf\", then the second person calls the third person and says \"Owwf\", then the third person calls the first person and says \"Owf\", so the first person becomes Joon-Joon of the round. So the condition is satisfied if x is 1.The process is similar for the second and the third person.If the fourth person starts some round:The fourth person calls himself and says \"Owwwf\", then he calls himself again and says \"Owwf\", then he calls himself for another time and says \"Owf\", so the fourth person becomes Joon-Joon of the round. So the condition is satisfied when x is 4.In the last example if the first person starts a round, then the second person becomes the Joon-Joon, and vice versa."}, "positive_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nlong gcd (long a, long b)\n{\n\tif (a == 0)\n\t{\n\t\treturn b;\n\t}\n\treturn gcd (b % a, a);\n}\n\nlong lcm (long a, long b)\n{\n\treturn a / gcd (a, b) * b;\n}\n\nlong solve (int [] p)\n{\n\tint n = cast (int) (p.length);\n\n\tauto q = new int [n];\n\tq[] = -1;\n\tforeach (i; 0..n)\n\t{\n\t\tq[p[i]] = i;\n\t}\n\tif (q.any !(x => x == -1))\n\t{\n\t\treturn -1;\n\t}\n\n\tlong res = 1;\n\tforeach (i; 0..n)\n\t{\n\t\tif (p[i] != -1)\n\t\t{\n\t\t\tint len = 0;\n\t\t\tint k = i;\n\t\t\twhile (p[k] != -1)\n\t\t\t{\n\t\t\t\tint r = k;\n\t\t\t\tk = p[k];\n\t\t\t\tp[r] = -1;\n\t\t\t\tlen += 1;\n\t\t\t}\n\t\t\tif (len % 2 == 0)\n\t\t\t{\n\t\t\t\tlen /= 2;\n\t\t\t}\n\t\t\tres = lcm (res, len);\n\t\t}\n\t}\n\n\treturn res;\n}\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto p = readln.split.map !(to !(int)).array;\n\t\tp[] -= 1;\n\t\twriteln (solve (p));\n\t}\n}\n"}, {"source_code": "import std.bigint,std.container,std.array,std.algorithm,std.conv,std.bitmanip,std.functional,std.math,std.numeric,std.string,std.range,std.uni,std.complex,\nstd.typecons,std.regex,std.complex,std.random;\nimport core.stdc.stdio:freopen;\nimport std.stdio;\n//import core.stdc.stdio;\nalias RedBlackTree set;\nalias redBlackTree rbt;\nalias BigInt big;\nalias pair!(int,int) pii;\nalias pair!(long,long) pll;\nalias BoyerMooreFinder strfind;\nimmutable int mod=1000000007;\nT lcm (T)(T a,T b)\n{\n\treturn a/gcd(a,b)*b;\n}\npure nothrow X binpow(X,Y)(X base,Y exp)\nif(!is(Y==float) && !is(Y==real) && !is(Y==double))\n{\n\tif(exp<0)return X(0);\n\tX res=X(1);\n\twhile(exp>0)\n\t{\n\t\tif(exp&1)res*=base;\n\t\tbase*=base;\n\t\texp>>=1;\n\t}\n\treturn res;\n}\npure nothrow auto binpow(X,Y,Z)(X base,Y exp,in Z mm)\nif(!is(Y==float) && !is(Y==real) && !is(Y==double))\n{\n\tif(mm==0) return binpow(base,exp);\n\tif(exp<0)return X(0);\n\tauto res=X(1)%mm;\n\twhile(exp>0)\n\t{\n\t\tif(exp&1)res=(res*base)%mm;\n\t\tbase*=base;\n\t\tbase%=mm;\n\t\texp>>=1;\n\t}\n\treturn res;\n}\n@property void putarr(X)(X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(X a,in int n,in int m)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nvoid getarr(X)(X a,in int n){foreach(ref i;a[0..n])input(&i);}\nbool input(T...)(T ptrs) if (ptrs.length > 0) {return readf(replicate(\" %s\", ptrs.length), ptrs)==ptrs.length;}\nstruct pair(X,Y)\n{\n\tX first;\n\tY second;\n\talias first fi;\n\talias second se;\n\tthis(X a_,Y b_){\n\t\tfi=a_;\n\t\tse=b_;\n\t\t}\n\tthis(this){fi=fi;se=se;}\n\tint opCmp(ref const pair!(X,Y) s_) const pure nothrow\n\t{\n\t\tint cmp=0-(fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.se));\n\t}\n};\npair!(X,Y) mp(X,Y)(X x_,Y y_) pure nothrow\n{\n\tpair!(X,Y) pp;\n\tpp.fi=x_;\n\tpp.se=y_;\n\treturn pp;\n}\nX sqr(X)(X a_) pure nothrow @property @nogc {return a_*a_;}\nX cub(X)(X a_) pure nothrow @property @nogc {return a_*a_*a_;}\nnothrow @nogc @system void inf(in char* name) {freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow @nogc @system void ouf(in char* name) {freopen(name,\"w\",core.stdc.stdio.stdout);}\nauto arread(T)(){return readln.split.map!(to!(T)).array;}\nnothrow pure size_t lowb(T,X)(T a,X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m] q[q[x]] == x))\n\t\t{\n\t\t\treturn res;\n\t\t}\n\t}\n\treturn -1;\n}\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto p = readln.split.map !(to !(int)).array;\n\t\tp[] -= 1;\n\t\twriteln (solve (p));\n\t}\n}\n"}], "src_uid": "149221131a978298ac56b58438df46c9"} {"nl": {"description": "There exists an island called Arpa\u2019s land, some beautiful girls live there, as ugly ones do.Mehrdad wants to become minister of Arpa\u2019s land. Arpa has prepared an exam. Exam has only one question, given n, print the last digit of 1378n. Mehrdad has become quite confused and wants you to help him. Please help, although it's a naive cheat.", "input_spec": "The single line of input contains one integer n (0\u2009\u2009\u2264\u2009\u2009n\u2009\u2009\u2264\u2009\u2009109).", "output_spec": "Print single integer\u00a0\u2014 the last digit of 1378n.", "sample_inputs": ["1", "2"], "sample_outputs": ["8", "4"], "notes": "NoteIn the first example, last digit of 13781\u2009=\u20091378 is 8.In the second example, last digit of 13782\u2009=\u20091378\u00b71378\u2009=\u20091898884 is 4."}, "positive_code": [{"source_code": "import std.bigint,std.container,std.array,std.algorithm,std.conv,std.bitmanip,std.functional,std.math,std.numeric,std.string,std.range,std.uni,std.complex,\nstd.typecons,std.regex,std.complex,std.random;\nimport core.stdc.stdio:freopen;\nimport std.stdio;\n//import core.stdc.stdio;\nalias RedBlackTree set;\nalias redBlackTree rbt;\nalias BigInt big;\nalias pair!(int,int) pii;\nalias pair!(long,long) pll;\nalias BoyerMooreFinder strfind;\nimmutable int mod=1000000007;\npure nothrow X binpow(X,Y)(X base,Y exp)\nif(!is(Y==float) && !is(Y==real) && !is(Y==double))\n{\n\tif(exp<0)return X(0);\n\tX res=X(1);\n\twhile(exp>0)\n\t{\n\t\tif(exp&1)res*=base;\n\t\tbase*=base;\n\t\texp>>=1;\n\t}\n\treturn res;\n}\npure nothrow auto binpow(X,Y,Z)(X base,Y exp,in Z mm)\nif(!is(Y==float) && !is(Y==real) && !is(Y==double))\n{\n\tif(mm==0) return binpow(base,exp);\n\tif(exp<0)return X(0);\n\tauto res=X(1)%mm;\n\twhile(exp>0)\n\t{\n\t\tif(exp&1)res=(res*base)%mm;\n\t\tbase*=base;\n\t\tbase%=mm;\n\t\texp>>=1;\n\t}\n\treturn res;\n}\n@property void putarr(X)(X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\nvoid putarr(X)(X a,in int n,in int m)\n{\n\tforeach(i;0..n)\n\t{\n\t\tforeach(j;0..m)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}\nvoid getarr(X)(X a,in int n){foreach(ref i;a[0..n])input(&i);}\nbool input(T...)(T ptrs) if (ptrs.length > 0) {return readf(replicate(\" %s\", ptrs.length), ptrs)==ptrs.length;}\nstruct pair(X,Y)\n{\n\tX fi;\n\tY se;\n\tthis(X a_,Y b_){\n\t\tfi=a_;\n\t\tse=b_;\n\t\t}\n\tthis(this){fi=fi;se=se;}\n\tint opCmp(ref const pair!(X,Y) s_) const pure nothrow\n\t{\n\t\tint cmp=0-(fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.se));\n\t}\n};\npair!(X,Y) mp(X,Y)(X x_,Y y_) pure nothrow\n{\n\tpair!(X,Y) pp;\n\tpp.fi=x_;\n\tpp.se=y_;\n\treturn pp;\n}\nX sqr(X)(X a_) pure nothrow @property @nogc {return a_*a_;}\nX cub(X)(X a_) pure nothrow @property @nogc {return a_*a_*a_;}\nnothrow @nogc @system void inf(in char* name) {freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow @nogc @system void ouf(in char* name) {freopen(name,\"w\",core.stdc.stdio.stdout);}\nauto arread(T)(){return readln.split.map!(to!(T)).array;}\nnothrow pure size_t lowb(T,X)(T a,X g) if(isRandomAccessRange!T && hasLength!T && is(typeof(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(g1)\n\t{\n\t\tauto m=(l+r)>>1;\n\t\tif(!(a[m]0)\n\t{\n\t\tif(exp&1)res*=base;\n\t\tbase*=base;\n\t\texp>>=1;\n\t}\n\treturn res;\n}\npure nothrow @safe auto binpow(X,Y,Z)(X base,Y exp,in Z mm)\nif(!is(Y==float) && !is(Y==real) && !is(Y==double))\n{\n\tif(mm==0) return binpow(base,exp);\n\tif(exp<0)return X(0);\n\tauto res=X(1)%mm;\n\twhile(exp>0)\n\t{\n\t\tif(exp&1)res=(res*base)%mm;\n\t\tbase*=base;\n\t\tbase%=mm;\n\t\texp>>=1;\n\t}\n\treturn res;\n}\n@safe @property void putarr(X)(X a,in char ch=' '){foreach(const ref i;a)write(i,ch);}\n/*@safe @property void putarr(X)(X[][] a)\n{\n\tforeach(i;0..a.length)\n\t{\n\t\tforeach(j;0..a[i].length)write(a[i][j],' ');\n\t\twriteln;\n\t}\n}*/\nvoid getarr(X)(X a,in int n){foreach(ref i;a[0..n])input(&i);}\nbool input(T...)(T ptrs) if (ptrs.length > 0) {return readf(replicate(\" %s\", ptrs.length), ptrs)==ptrs.length;}\nstruct pair(X,Y)\n{\n\tX fi;\n\tY se;\n\tthis(X a_,Y b_){\n\t\tfi=a_;\n\t\tse=b_;\n\t\t}\n\tthis(this){fi=fi;se=se;}\n\tint opCmp(ref const pair!(X,Y) s_) const pure nothrow\n\t{\n\t\tint cmp=0-(fis_.fi);\n\t\tif(cmp!=0)return cmp;\n\t\telse return (0-(ses_.se));\n\t}\n};\npair!(X,Y) mp(X,Y)(X x_,Y y_) pure nothrow\n{\n\tpair!(X,Y) pp;\n\tpp.fi=x_;\n\tpp.se=y_;\n\treturn pp;\n}\nX sqr(X)(X a_) pure nothrow @safe @property @nogc {return a_*a_;}\nX cub(X)(X a_) pure nothrow @safe @property @nogc {return a_*a_*a_;}\nnothrow @nogc @system void inf(in char* name) {freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow @nogc @system void ouf(in char* name) {freopen(name,\"w\",core.stdc.stdio.stdout);}\nauto arread(T)(){return readln.split.map!(to!(T)).array;}\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin cumulativeFold schwartzSort multiSort partialSort heapify join\n//---------------------------------------------------------------program beginning-----------------------------------------------------------\n\nvoid main()\n{\n\tint n;\n\tinput(&n);\n\twriteln(binpow(1378,n,10));\n}"}], "negative_code": [], "src_uid": "4b51b99d1dea367bf37dc5ead08ca48f"} {"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 \u00a0\u2014 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\u00a0\u2014 $$$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\u00a0\u2014 calculate the minimum amount of lab works Vasya has to redo.", "input_spec": "The first line contains a single integer $$$n$$$\u00a0\u2014 the number of Vasya's grades ($$$1 \\leq n \\leq 100$$$). The second line contains $$$n$$$ integers from $$$2$$$ to $$$5$$$\u00a0\u2014 Vasya's grades for his lab works.", "output_spec": "Output a single integer\u00a0\u2014 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": "import std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n int n;\n readf(\"%s\", &n);\n readln;\n \n auto a = readln.chomp.split.map!(to!int).array;\n \n int need = 45 * n;\n \n a.sort();\n int now = a.sum() * 10;\n int ans = 0;\n \n debug { writeln(need, ' ', now); }\n \n foreach (e; a) {\n if (now >= need) break;\n \n now += (5 - e) * 10;\n ++ans;\n }\n \n ans.writeln;\n}"}], "negative_code": [], "src_uid": "715608282b27a0a25b66f08574a6d5bd"} {"nl": {"description": "You have n problems. You have estimated the difficulty of the i-th one as integer ci. Now you want to prepare a problemset for a contest, using some of the problems you've made.A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must be at least l and at most r. Also, you think that the difference between difficulties of the easiest and the hardest of the chosen problems must be at least x.Find the number of ways to choose a problemset for the contest.", "input_spec": "The first line contains four integers n, l, r, x (1\u2009\u2264\u2009n\u2009\u2264\u200915, 1\u2009\u2264\u2009l\u2009\u2264\u2009r\u2009\u2264\u2009109, 1\u2009\u2264\u2009x\u2009\u2264\u2009106) \u2014 the number of problems you have, the minimum and maximum value of total difficulty of the problemset and the minimum difference in difficulty between the hardest problem in the pack and the easiest one, respectively. The second line contains n integers c1,\u2009c2,\u2009...,\u2009cn (1\u2009\u2264\u2009ci\u2009\u2264\u2009106) \u2014 the difficulty of each problem.", "output_spec": "Print the number of ways to choose a suitable problemset for the contest. ", "sample_inputs": ["3 5 6 1\n1 2 3", "4 40 50 10\n10 20 30 25", "5 25 35 10\n10 10 20 10 20"], "sample_outputs": ["2", "2", "6"], "notes": "NoteIn the first example two sets are suitable, one consisting of the second and third problem, another one consisting of all three problems.In the second example, two sets of problems are suitable \u2014 the set of problems with difficulties 10 and 30 as well as the set of problems with difficulties 20 and 30.In the third example any set consisting of one problem of difficulty 10 and one problem of difficulty 20 is suitable."}, "positive_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.conv;\nimport std.algorithm;\nimport std.c.stdio;\n\n\nvoid main() {\n int n, l, r, x;\n scanf(\"%d%d%d%d\\n\", &n, &l, &r, &x);\n auto a = readln().split().map!(to!long);\n int ans = 0;\n for (int S = 1; S < (1 << n); S++) {\n long s = 0, mn = long.max, mx = long.min;\n for (int i = 0; i < n; i++) {\n if (S & (1 << i)) {\n s += a[i];\n mn = min(mn, a[i]);\n mx = max(mx, a[i]);\n }\n }\n if (l <= s && s <= r && mx - mn >= x) {\n ans++;\n }\n }\n writeln(ans);\n}\n"}], "negative_code": [], "src_uid": "0d43104a0de924cdcf8e4aced5aa825d"} {"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$$$) \u2014 the number of test cases. The only line of the test case contains one integer $$$x$$$ ($$$1 \\le x \\le 9999$$$) \u2014 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": "import std.stdio;\nimport std.conv;\nimport std.string;\n\nint[string] precalc;\n\nvoid main()\n{\n {\n int strokes = 0;\n for (int i = 1; i <= 9; ++i) {\n string key = \"\";\n for (int j = 1; j <= 4; ++j) {\n key ~= i.to!string;\n strokes += j;\n precalc[key] = strokes;\n }\n }\n }\n\n auto t = readln.strip.to!int;\n while (t-- > 0) {\n writeln(precalc[readln.strip]);\n }\n}\n"}, {"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nvoid play(){\n int n;\n n = rd!int;\n int dig = n % 10;\n int tim = 0;\n while(n > 0){\n n /= 10;\n ++tim;\n }\n int res = 10*(dig - 1) + (tim*(tim+1))/2;\n writeln(res);\n}\n\nint main(){\n long t = 1;\n t = rd; // Toggle!\n while(t--) play(); // Let's play!\n stdout.flush;\n return 0;\n}\n\n/**********It's A Me Mario!**********/\nimport std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.numeric, std.math, std.random;\nstatic string[] inp;\nT rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}\nT[] rdarr(T = long)(){ auto r = readln.chomp.split.to!(T[]); return r; }\nvoid show(A...)(A a) { debug{ a.each!(w => write(w, \"| \")); writeln; } }\nalias ll = long;\nalias rbt = redBlackTree;\nalias tup = Tuple!(long, long);\nT max(T = long)(T a, T b){ return (a > b) ? a : b; }\nT min(T = long)(T a, T b){ return (a < b) ? a : b; }\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tauto tests = readln.strip.to !(int);\nmultitest_loop:\n\tforeach (test; 0..tests)\n\t{\n\t\tauto s = readln.strip;\n\t\tint res = 0;\n\t\tforeach (d; 1..10)\n\t\t{\n\t\t\tforeach (k; 1..5)\n\t\t\t{\n\t\t\t\tauto t = repeat (cast (char) (d + '0'), k);\n\t\t\t\tres += k;\n\t\t\t\tif (equal (s, t))\n\t\t\t\t{\n\t\t\t\t\twriteln (res);\n\t\t\t\t\tcontinue multitest_loop;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tassert (false);\n\t}\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nT lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(T)(ref T x, T y) { x = (x + y) % mod; }\nvoid mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(T)(ref T x, T y) { x = (x * y) % mod; }\nvoid modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\nvoid modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }\n\nvoid main()\n{\n\tauto t = RD!int;\n\tauto ans = new long[](t);\n\tforeach (ti; 0..t)\n\t{\n\t\tauto x = RD!string;\n\n\t\tauto len = x.length;\n\t\tans[ti] = (cast(long)(x[0]-'0')-1)*10 + (len*(len+1)/2);\n\t}\n\n\tforeach (e; ans)\n\t\twriteln(e);\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [], "src_uid": "289a55128be89bb86a002d218d31b57f"} {"nl": {"description": "A long time ago (probably even in the first book), Nicholas Flamel, a great alchemist and the creator of the Philosopher's Stone, taught Harry Potter three useful spells. The first one allows you to convert a grams of sand into b grams of lead, the second one allows you to convert c grams of lead into d grams of gold and third one allows you to convert e grams of gold into f grams of sand. When Harry told his friends about these spells, Ron Weasley was amazed. After all, if they succeed in turning sand into lead, lead into gold, and then turning part of the gold into sand again and so on, then it will be possible to start with a small amount of sand and get huge amounts of gold! Even an infinite amount of gold! Hermione Granger, by contrast, was skeptical about that idea. She argues that according to the law of conservation of matter getting an infinite amount of matter, even using magic, is impossible. On the contrary, the amount of matter may even decrease during transformation, being converted to magical energy. Though Hermione's theory seems convincing, Ron won't believe her. As far as Ron is concerned, Hermione made up her law of conservation of matter to stop Harry and Ron wasting their time with this nonsense, and to make them go and do homework instead. That's why Ron has already collected a certain amount of sand for the experiments. A quarrel between the friends seems unavoidable...Help Harry to determine which one of his friends is right, and avoid the quarrel after all. To do this you have to figure out whether it is possible to get the amount of gold greater than any preassigned number from some finite amount of sand.", "input_spec": "The first line contains 6 integers a, b, c, d, e, f (0\u2009\u2264\u2009a,\u2009b,\u2009c,\u2009d,\u2009e,\u2009f\u2009\u2264\u20091000).", "output_spec": "Print \"Ron\", if it is possible to get an infinitely large amount of gold having a certain finite amount of sand (and not having any gold and lead at all), i.e., Ron is right. Otherwise, print \"Hermione\".", "sample_inputs": ["100 200 250 150 200 250", "100 50 50 200 200 100", "100 10 200 20 300 30", "0 0 0 0 0 0", "1 1 0 1 1 1", "1 0 1 2 1 2", "100 1 100 1 0 1"], "sample_outputs": ["Ron", "Hermione", "Hermione", "Hermione", "Ron", "Hermione", "Ron"], "notes": "NoteConsider the first sample. Let's start with the 500 grams of sand. Apply the first spell 5 times and turn the sand into 1000 grams of lead. Then apply the second spell 4 times to get 600 grams of gold. Let\u2019s take 400 grams from the resulting amount of gold turn them back into sand. We get 500 grams of sand and 200 grams of gold. If we apply the same operations to 500 grams of sand again, we can get extra 200 grams of gold every time. Thus, you can get 200, 400, 600 etc. grams of gold, i.e., starting with a finite amount of sand (500 grams), you can get the amount of gold which is greater than any preassigned number.In the forth sample it is impossible to get sand, or lead, or gold, applying the spells.In the fifth sample an infinitely large amount of gold can be obtained by using only the second spell, which allows you to receive 1 gram of gold out of nothing. Note that if such a second spell is available, then the first and the third one do not affect the answer at all.The seventh sample is more interesting. We can also start with a zero amount of sand there. With the aid of the third spell you can get sand out of nothing. We get 10000 grams of sand in this manner. Let's get 100 grams of lead using the first spell 100 times. Then make 1 gram of gold from them. We managed to receive 1 gram of gold, starting with a zero amount of sand! Clearly, in this manner you can get an infinitely large amount of gold."}, "positive_code": [{"source_code": "import core.bitop, std.bitmanip;\nimport core.checkedint;\nimport std.algorithm, std.functional;\nimport std.array, std.container;\nimport std.bigint;\nimport std.conv;\nimport std.datetime.stopwatch;\nimport std.math, std.numeric;\nimport std.range, std.range.interfaces;\nimport std.stdio, std.string;\nimport std.typecons;\n\nimmutable int INF = 10 ^^ 8;\n\nvoid main()\n{\n int a, b, c, d, e, f;\n readf(\"%s %s %s %s %s %s\", &a, &b, &c, &d, &e, &f);\n readln;\n\n string solve() {\n auto r = \"Ron\";\n auto h = \"Hermione\";\n\n if (d == 0) { return h; }\n if (c == 0) { return r; }\n if (b == 0) { return h; }\n if (a == 0) { return r; }\n if (f == 0) { return h; }\n if (e == 0) { return r; }\n \n long lcm1 = b * c / gcd(b, c);\n long aa = a * (lcm1 / b);\n long dd = d * (lcm1 / c);\n \n long lcm2 = dd * e / gcd(dd, e);\n long fff = f * (lcm2 / e);\n long mult = lcm2 / dd;\n long aaa = aa * mult; \n \n return aaa < fff ? r : h;\n }\n \n solve().writeln;\n}"}], "negative_code": [], "src_uid": "44d608de3e1447f89070e707ba550150"} {"nl": {"description": "There are $$$n$$$ heroes fighting in the arena. Initially, the $$$i$$$-th hero has $$$a_i$$$ health points.The fight in the arena takes place in several rounds. At the beginning of each round, each alive hero deals $$$1$$$ damage to all other heroes. Hits of all heroes occur simultaneously. Heroes whose health is less than $$$1$$$ at the end of the round are considered killed.If exactly $$$1$$$ hero remains alive after a certain round, then he is declared the winner. Otherwise, there is no winner.Your task is to calculate the number of ways to choose the initial health points for each hero $$$a_i$$$, where $$$1 \\le a_i \\le x$$$, so that there is no winner of the fight. The number of ways can be very large, so print it modulo $$$998244353$$$. Two ways are considered different if at least one hero has a different amount of health. For example, $$$[1, 2, 1]$$$ and $$$[2, 1, 1]$$$ are different.", "input_spec": "The only line contains two integers $$$n$$$ and $$$x$$$ ($$$2 \\le n \\le 500; 1 \\le x \\le 500$$$).", "output_spec": "Print one integer\u00a0\u2014 the number of ways to choose the initial health points for each hero $$$a_i$$$, where $$$1 \\le a_i \\le x$$$, so that there is no winner of the fight, taken modulo $$$998244353$$$. ", "sample_inputs": ["2 5", "3 3", "5 4", "13 37"], "sample_outputs": ["5", "15", "1024", "976890680"], "notes": null}, "positive_code": [{"source_code": "immutable multi = false;\n\nint n, x;\nimmutable long p = 998244353;\nalias Zp = Z!p;\nZp[][] ways, prePow;\n\nZp getWays(int size, int range)\n{\n\tpragma(inline, true);\n\tassert(size >= 0);\n\tif (range >= 0) return ways[size][range];\n\telse return Zp(size == 0);\n}\n\nZp[][] C = new Zp[][](501, 501);\nstatic this()\n{\n\tC[0][0] = Zp(1);\n\tforeach(size; 1 .. 501)\n\t{\n\t\tC[size][0] = Zp(1);\n\t\tforeach(subsize; 1 .. size + 1)\n\t\t{\n\t\t\tC[size][subsize] = C[size-1][subsize-1] + C[size-1][subsize];\n\t\t}\n\t}\n}\n\nZp calcWays(int size, int range)\n{\n\tpragma(inline, true);\n\tif (size == 0) return Zp(1);\n\tif (size == 1) return Zp(0);\n\tif (range == 0) return Zp(0);\n\tZp ans = Zp(0);\n\tforeach(noDies; 0 .. size + 1)\n\t{\n\t\tZp noWaysDies = prePow[min(range, size - 1)][noDies];\n\t\tnoWaysDies = noWaysDies * C[size][noDies];\n\t\tnoWaysDies = noWaysDies * getWays(size - noDies, range - (size - 1));\n\t\tans = ans + noWaysDies;\n\t}\n\treturn ans;\n}\n\nvoid solve(int tc)\n{\n\tn = readInt!int;\n\tx = readInt!int;\n\tZp.makeFactorials(2 * n);\n\tways = new Zp[][](n+1, x+1);\n\tprePow = new Zp[][](501, 501);\n\tforeach(b; 0 .. 501) prePow[b][0] = Zp(1);\n\tforeach(b; 0 .. 501)\n\t{\n\t\tforeach(ex; 1 .. 501)\n\t\t\tprePow[b][ex] = prePow[b][ex-1] * Zp(b);\n\t}\n\tforeach(size; 0 .. n + 1)\n\t\tforeach(range; 0 .. x + 1)\n\t\t\tways[size][range] = calcWays(size, range);\n\tdebug\n\t{\n\t\tforeach(size; 0 .. n + 1)\n\t\t\tways[size].writeln;\n\t}\n\tways[n][x].rep.writeln;\n}\n\n// modular {{{\nstruct Z(immutable long m)\n{\n\tlong rep;\n\tstatic immutable bool primeModulus = isPrime(m);\n\tstatic Z!m[] fact;\n\tstatic if (primeModulus) { static Z!m[] invFact; }\n\tstatic makeFactorials(int n)\n\t{\n\t\tfact = new Z!m[](n + 1);\n\t\tfact[0] = Z!m(1);\n\t\tforeach(i; 1 .. n + 1) fact[i] = Z!m(i) * fact[i - 1];\n\t\tstatic if (primeModulus)\n\t\t{\n\t\t\tinvFact = new Z!m[](n + 1);\n\t\t\tinvFact[n] = fact[n].inv;\n\t\t\tforeach_reverse(i; 0 .. n) invFact[i] = Z!m(i + 1) * invFact[i + 1];\n\t\t}\n\t}\n\n\tthis(long num)\n\t{\n\t\trep = num;\n\t}\n\n\tZ!m opBinary(string operator)(Z!m rhs)\n\t{\n\t\tstatic if (operator == \"+\")\n\t\t{\n\t\t\tlong result = rhs.rep + this.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult -= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"-\")\n\t\t{\n\t\t\tlong result = this.rep - rhs.rep;\n\t\t\tif (result < 0)\n\t\t\t\tresult += m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"*\")\n\t\t{\n\t\t\tlong result = this.rep * rhs.rep;\n\t\t\tif (result >= m)\n\t\t\t\tresult %= m;\n\t\t\treturn Z!m(result);\n\t\t}\n\t\telse static if (operator == \"/\" && primeModulus)\n\t\t{\n\t\t\tassert(rhs != Z!m(0));\n\t\t\treturn this * rhs.inv;\n\t\t}\n\t\telse\n\t\t{\n\t\t\tstatic assert(text(\"Operator \", operator, \" not supported\"));\n\t\t}\n\t}\n\n\tZ!m opBinary(string operator)(long exponent) if (operator == \"^^\")\n\t{\n\t\tassert(exponent >= 0);\n\t\tZ!m base = this;\n\t\tZ!m result = 1;\n\t\twhile (exponent)\n\t\t{\n\t\t\tif (exponent & 1)\n\t\t\t\tresult = result * base;\n\t\t\tbase = base * base;\n\t\t\texponent >>= 1;\n\t\t}\n\t\treturn result;\n\t}\n\n\tstatic if (primeModulus)\n\t{\n\t\tZ!m inv()\n\t\t{\n\t\t\treturn this^^(m - 2);\n\t\t}\n\t\tstatic Z!m C(int n, int k)\n\t\t{\n\t\t\tif (k < 0 || k > n) return Z!m(0);\n\t\t\treturn fact[n] * invFact[k] * invFact[n - k];\n\t\t}\n\t}\n\n\tinvariant\n\t{\n\t\tassert(rep >= 0 && rep < m);\n\t}\n}\nbool isPrime(long n)\n{\n\tfor(long d = 2; d * d <= n; d++)\n\t\tif (n % d == 0) return false;\n\treturn true; \n}\nunittest\n{\n\talias Zp = Z!23;\n\tstatic assert(Zp.primeModulus);\n\tforeach(i; 1 .. 23) assert(Zp(i) * Zp(i).inv == Zp(1));\n\tZp.makeFactorials(22);\n\tforeach(i; 0 .. 23) assert(Zp.fact[i] * Zp.invFact[i] == Zp(1));\n\tassert(Zp.C(3, 2) == Zp(3));\n\tassert(Zp.C(4, 2) == Zp(6));\n}\n// }}}\n\n\n//{{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1;\n\tforeach(tc; 0 .. t) solve(tc);\n}\n//}}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t{\n\t\tpopChar;\n\t}\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nimmutable int mod = 998_244_353;\r\nimmutable int limit = 504;\r\n\r\nvoid main ()\r\n{\r\n\tauto c = new int [] [] (limit, limit);\r\n\tforeach (i; 0..limit)\r\n\t{\r\n\t\tc[i][0] = 1 % mod;\r\n\t\tforeach (j; 1..i + 1)\r\n\t\t{\r\n\t\t\tc[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;\r\n\t\t}\r\n\t}\r\n\r\n\tauto p = new int [] [] (limit, limit);\r\n\tforeach (i; 1..limit)\r\n\t{\r\n\t\tp[i][0] = 1;\r\n\t\tforeach (j; 1..limit)\r\n\t\t{\r\n\t\t\tp[i][j] = (p[i][j - 1] * 1L * i) % mod;\r\n\t\t}\r\n\t}\r\n\r\n\tauto f = new int [] [] (limit, limit);\r\n\tforeach (x; 0..limit)\r\n\t{\r\n\t\tf[0][x] = 1;\r\n\t}\r\n\tforeach (n; 2..limit)\r\n\t{\r\n\t\tforeach (x; 1..limit)\r\n\t\t{\r\n\t\t\tint delta = min (n - 1, x);\r\n\t\t\tint y = x - delta;\r\n\t\t\tforeach (k; 0..n + 1)\r\n\t\t\t{\r\n\t\t\t\tf[n][x] = (f[n][x] + f[k][y] * 1L *\r\n\t\t\t\t (c[n][k] * 1L * p[delta][n - k] %\r\n\t\t\t\t mod)) % mod;\r\n\t\t\t}\r\n\t\t\tdebug {writefln !(\"f[%s][%s] = %s\") (n, x, f[n][x]);}\r\n\t\t}\r\n\t}\r\n\r\n\tint n, x;\r\n\twhile (readf !(\" %s %s\") (n, x) > 0)\r\n\t{\r\n\t\twriteln (f[n][x]);\r\n\t}\r\n}\r\n"}], "negative_code": [{"source_code": "immutable multi = true;\n\nvoid solve(int tc)\n{\n\tauto n = readInt!int;\n\tauto m = readInt!int;\n\tauto a = ma(n, ma(m, readInt!int));\n\tauto minmaxL = new Tuple!(int, int)[][](n);\n\tauto minmaxR = new Tuple!(int, int)[][](n);\n\tforeach(i, ref ai; a)\n\t{\n\t\tminmaxL[i] = ai.cumulativeFold!(min, max).array;\n\t\tminmaxR[i] = ai.retro.cumulativeFold!(min, max).array.retro.array;\n\t}\n\tchar[] getConfiguration(int k)\n\t{\n\t\tdebug writeln(\"for k = \", k);\n\t\tstruct Row\n\t\t{\n\t\t\tTuple!(int, int) left, right;\n\t\t}\n\t\tRow[] rows = new Row[](n);\n\t\tforeach(i, ref rowi; rows)\n\t\t{\n\t\t\trowi = Row(minmaxL[i][k], minmaxR[i][k+1]);\n\t\t}\n\t\tdebug writeln(\"rows = \", rows);\n\t\tauto events = new Tuple!(int, int, int)[](2 * n);\n\t\tint evlen = 0;\n\t\tforeach(i, row; rows)\n\t\t{\n\t\t\tevents[evlen++] = tuple(row.left[0], +1, cast(int)i);\n\t\t\tevents[evlen++] = tuple(row.left[1] + 1, -1, cast(int)i);\n\t\t}\n\t\tint pfMinPrev = int.max;\n\t\tint sfMaxPrev = int.min;\n\t\tauto pfMin = new int[](2 * n);\n\t\tauto sfMax = new int[](2 * n);\n\t\tsort(events);\n\t\tdebug writeln(\"events = \", events);\n\t\tdebug writeln(\"evlen = \", evlen);\n\t\tforeach(i, evi; events)\n\t\t{\n\t\t\tif (evi[1] == +1)\n\t\t\t{\n\t\t\t\tpfMinPrev = min(pfMinPrev, rows[evi[2]].right[0]);\n\t\t\t}\n\t\t\tpfMin[i] = pfMinPrev;\n\t\t}\n\t\t\n\t\tforeach_reverse(i, evi; events)\n\t\t{\n\t\t\tif (evi[1] == +1)\n\t\t\t{\n\t\t\t\tsfMaxPrev = max(sfMaxPrev, rows[evi[2]].right[1]);\n\t\t\t}\n\t\t\tsfMax[i] = sfMaxPrev;\n\t\t}\n\t\tdebug writeln(\"pfMin = \", pfMin);\n\t\tdebug writeln(\"sfMax = \", sfMax);\n\t\tint open = 0;\n\t\tint cut = -1;\n\t\tauto color = new char[](n);\n\t\tcolor[] = 'R';\n\t\tforeach(i, evi; events)\n\t\t{\n\t\t\topen += evi[1];\n\t\t\tif (i+1 < events.length && open == 0)\n\t\t\t{\n\t\t\t\tdebug writeln(\"found a cut at i = \", i);\n\t\t\t\tif (pfMin[i] > sfMax[i])\n\t\t\t\t{\n\t\t\t\t\tdebug writeln(\"it's a good cut!\");\n\t\t\t\t\tforeach(j; 0 .. i)\n\t\t\t\t\t{\n\t\t\t\t\t\tif (events[j][1] > 0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcolor[events[j][2]] = 'B';\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn color;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn null;\n\t}\n\tforeach(k; 0 .. m - 1)\n\t{\n\t\tauto config = getConfiguration(k);\n\t\tif (config !is null)\n\t\t{\n\t\t\twriteln(\"YES\");\n\t\t\tconfig.write(\" \");\n\t\t\treturn writeln(k+1);\n\t\t}\n\t}\n\treturn writeln(\"NO\");\n}\n\n//{{{\nvoid main()\n{\n\tauto t = multi? readInt!int : 1;\n\tforeach(tc; 0 .. t) solve(tc);\n}\n//}}}\n// input {{{\nint currChar;\nstatic this()\n{\n\tcurrChar = ' ';\n}\n\nchar topChar()\n{\n\treturn cast(char) currChar;\n}\n\nvoid popChar()\n{\n\timport core.stdc.stdio;\n\tcurrChar = getchar();\n}\n\nauto readInt(T)()\n{\n\tT num = 0;\n\tint sgn = 0;\n\twhile (topChar.isWhite)\n\t{\n\t\tpopChar;\n\t}\n\twhile (topChar == '-' || topChar == '+')\n\t{\n\t\tsgn ^= (topChar == '-');\n\t\tpopChar;\n\t}\n\twhile (topChar.isDigit)\n\t{\n\t\tnum *= 10;\n\t\tnum += (topChar - '0');\n\t\tpopChar;\n\t}\n\tif (sgn)\n\t\treturn -num;\n\treturn num;\n}\n\nstring readString()\n{\n\tstring res = \"\";\n\twhile (topChar.isWhite)\n\t\tpopChar;\n\twhile (!topChar.isWhite)\n\t{\n\t\tres ~= topChar;\n\t\tpopChar;\n\t}\n\treturn res;\n}\nvoid writes(T...)(T t)\n{\n\tstatic foreach(i, ti; t)\n\t{\n\t\tstatic if (isIterable!(T[i]))\n\t\t{\n\t\t\tforeach(e; ti)\n\t\t\t{\n\t\t\t\twrite(e, \" \");\n\t\t\t}\n\t\t}\n\t}\n}\nauto ra(V)()\n{\n\tint n = readInt!int;\n\treturn ma(n, readInt!V);\n}\nauto rt(V)()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\treturn ma(n, ma(m, readInt!V));\n}\nauto rbg()\n{\n\tint n = readInt!int;\n\tint m = readInt!int;\n\tauto adj = new int[][](n);\n\tforeach(i; 0 .. m)\n\t{\n\t\tauto u = readInt!int - 1;\n\t\tauto v = readInt!int - 1;\n\t\tadj[u] ~= v;\n\t\tadj[v] ~= u;\n\t}\n\treturn adj;\n}\nauto ma(V)(size_t n, lazy V v)\n{\n\tauto arr = new V[](n);\n\tforeach(ref ai; arr) ai = v;\n\treturn arr;\n}\n// }}}\n// imports {{{\nimport std.stdio;\nimport std.algorithm;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\nimport std.container;\nimport std.range;\nimport std.array;\nimport std.ascii;\n// }}}\n"}, {"source_code": "import std.algorithm;\r\nimport std.conv;\r\nimport std.range;\r\nimport std.stdio;\r\nimport std.string;\r\nimport std.typecons;\r\n\r\nimmutable int mod = 998_244_353;\r\nimmutable int limit = 504;\r\n\r\nvoid main ()\r\n{\r\n\tauto c = new int [] [] (limit, limit);\r\n\tforeach (i; 0..limit)\r\n\t{\r\n\t\tc[i][0] = 1 % mod;\r\n\t\tforeach (j; 1..i + 1)\r\n\t\t{\r\n\t\t\tc[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;\r\n\t\t}\r\n\t}\r\n\r\n\tauto p = new int [] [] (limit, limit);\r\n\tforeach (i; 1..limit)\r\n\t{\r\n\t\tp[i][0] = 1;\r\n\t\tforeach (j; 1..limit)\r\n\t\t{\r\n\t\t\tp[i][j] = (p[i][j - 1] * 1L * i) % mod;\r\n\t\t}\r\n\t}\r\n\r\n\tauto f = new int [] [] (limit, limit);\r\n\tforeach (x; 0..limit)\r\n\t{\r\n\t\tf[0][x] = 1;\r\n\t}\r\n\tforeach (n; 2..limit)\r\n\t{\r\n\t\tforeach (x; 1..limit)\r\n\t\t{\r\n\t\t\tint delta = min (n - 1, x);\r\n\t\t\tint y = x - delta;\r\n\t\t\tforeach (k; 0..n + 1)\r\n\t\t\t{\r\n\t\t\t\tf[n][x] = (f[n][x] + f[k][y] * 1L *\r\n\t\t\t\t (c[n][k] * 1L * p[delta][n - k]) %\r\n\t\t\t\t mod) % mod;\r\n\t\t\t}\r\n\t\t\tdebug {writefln !(\"f[%s][%s] = %s\") (n, x, f[n][x]);}\r\n\t\t}\r\n\t}\r\n\r\n\tint n, x;\r\n\twhile (readf !(\" %s %s\") (n, x) > 0)\r\n\t{\r\n\t\twriteln (f[n][x]);\r\n\t}\r\n}\r\n"}], "src_uid": "1908d1c8c6b122a4c6633a7af094f17f"} {"nl": {"description": "Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to write a program for rectangles detection. According to his plan, the program detects if the four given segments form a rectangle of a positive area and with sides parallel to coordinate axes. As Alex does badly at school and can't write this program by himself, he asks you to help him.", "input_spec": "The input data contain four lines. Each of these lines contains four integers x1, y1, x2, y2 (\u2009-\u2009109\u2009\u2264\u2009x1,\u2009y1,\u2009x2,\u2009y2\u2009\u2264\u2009109) \u2014 coordinates of segment's beginning and end positions. The given segments can degenerate into points.", "output_spec": "Output the word \u00abYES\u00bb, if the given four segments form the required rectangle, otherwise output \u00abNO\u00bb.", "sample_inputs": ["1 1 6 1\n1 0 6 0\n6 0 6 1\n1 1 1 0", "0 0 0 3\n2 0 0 0\n2 2 2 0\n0 2 2 2"], "sample_outputs": ["YES", "NO"], "notes": null}, "positive_code": [{"source_code": "import std.stdio;\nimport std.format;\n\nclass Point\n{\n public const int x;\n public const int y;\n\n this(in int x, in int y)\n {\n this.x = x;\n this.y = y;\n }\n}\n\nbool isPresent(Point[] vertexes, int x, int y)\n{\n foreach (point; vertexes) {\n if (point is null) {\n return false;\n }\n if (point.x == x && point.y == y) {\n return true;\n }\n }\n return false;\n}\n\nvoid insert(Point[] vertexes, Point p)\n{\n for (int i = 0; i < vertexes.length; i++) {\n if (vertexes[i] is null) {\n vertexes[i] = p;\n return;\n }\n }\n}\n\nbool processPoint(Point[] vertexes, int x, int y)\n{\n if (isPresent(vertexes, x, y)) {\n return true;\n }\n if (vertexes[vertexes.length - 1] !is null) {\n return false;\n }\n insert(vertexes, new Point(x, y));\n return true;\n}\n\nclass Integer\n{\n const int value;\n this(int value) {\n this.value = value;\n }\n}\n\nbool checkRectangle()\n{\n Point[4] vertexes;\n Integer[2] xLines;\n Integer[2] yLines;\n\n for (int i = 0; i < 4; i++)\n {\n int x1, y1, x2, y2;\n auto line = stdin.readln();\n formattedRead(line, \"%s %s %s %s\", &x1, &y1, &x2, &y2);\n if (x1 == x2 && y1 != y2) {\n if (xLines[0] is null) {\n xLines[0] = new Integer(x1);\n } else {\n if (xLines[0].value == x1 || xLines[1] !is null) {\n return false;\n }\n xLines[1] = new Integer(x1);\n }\n } else if (x1 != x2 && y1 == y2) {\n if (yLines[0] is null) {\n yLines[0] = new Integer(y1);\n } else {\n if (yLines[0].value == y1 || yLines[1] !is null) {\n return false;\n }\n yLines[1] = new Integer(y1);\n }\n } else {\n return false;\n }\n\n if (!processPoint(vertexes, x1, y1)) {\n return false;\n }\n if (!processPoint(vertexes, x2, y2)) {\n return false;\n }\n }\n return true;\n}\n\nvoid main()\n{\n if (checkRectangle()) {\n stdout.writeln(\"YES\");\n } else {\n stdout.writeln(\"NO\");\n }\n}\n\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.format;\n\nclass Point\n{\n public const int x;\n public const int y;\n\n this(in int x, in int y)\n {\n this.x = x;\n this.y = y;\n }\n}\n\nbool isPresent(Point[] vertexes, int x, int y)\n{\n foreach (point; vertexes) {\n if (point is null) {\n return false;\n }\n if (point.x == x && point.y == y) {\n return true;\n }\n }\n return false;\n}\n\nvoid insert(Point[] vertexes, Point p)\n{\n for (int i = 0; i < vertexes.length; i++) {\n if (vertexes[i] is null) {\n vertexes[i] = p;\n return;\n }\n }\n}\n\nbool processPoint(Point[] vertexes, int x, int y)\n{\n if (isPresent(vertexes, x, y)) {\n return true;\n }\n if (vertexes[vertexes.length - 1] !is null) {\n return false;\n }\n insert(vertexes, new Point(x, y));\n return true;\n}\n\nclass Integer\n{\n const int value;\n this(int value) {\n this.value = value;\n }\n}\n\nbool checkRectangle()\n{\n Point[4] vertexes;\n Integer[2] xLines;\n Integer[2] yLines;\n\n for (int i = 0; i < 4; i++)\n {\n int x1, y1, x2, y2;\n auto line = stdin.readln();\n formattedRead(line, \"%s %s %s %s\", &x1, &y1, &x2, &y2);\n if (x1 == x2 && y1 != y2) {\n if (xLines[0] is null) {\n xLines[0] = new Integer(x1);\n } else {\n if (xLines[0].value == x1 || xLines[1] !is null) {\n return false;\n }\n xLines[1] = new Integer(x1);\n }\n } else if (x1 != x2 && y1 == y2) {\n if (yLines[0] is null) {\n yLines[0] = new Integer(y1);\n } else {\n if (yLines[0].value == y1 || yLines[1] !is null) {\n return false;\n }\n yLines[1] = new Integer(y1);\n }\n }\n if (!processPoint(vertexes, x1, y1)) {\n return false;\n }\n if (!processPoint(vertexes, x2, y2)) {\n return false;\n }\n }\n return true;\n}\n\nvoid main()\n{\n if (checkRectangle()) {\n stdout.writeln(\"YES\");\n } else {\n stdout.writeln(\"NO\");\n }\n}\n\n"}], "src_uid": "ad105c08f63e9761fe90f69630628027"} {"nl": {"description": "Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $$$x$$$ in an array. For an array $$$a$$$ indexed from zero, and an integer $$$x$$$ the pseudocode of the algorithm is as follows: Note that the elements of the array are indexed from zero, and the division is done in integers (rounding down).Andrey read that the algorithm only works if the array is sorted. However, he found this statement untrue, because there certainly exist unsorted arrays for which the algorithm find $$$x$$$!Andrey wants to write a letter to the book authors, but before doing that he must consider the permutations of size $$$n$$$ such that the algorithm finds $$$x$$$ in them. A permutation of size $$$n$$$ is an array consisting of $$$n$$$ distinct integers between $$$1$$$ and $$$n$$$ in arbitrary order.Help Andrey and find the number of permutations of size $$$n$$$ which contain $$$x$$$ at position $$$pos$$$ and for which the given implementation of the binary search algorithm finds $$$x$$$ (returns true). As the result may be extremely large, print the remainder of its division by $$$10^9+7$$$.", "input_spec": "The only line of input contains integers $$$n$$$, $$$x$$$ and $$$pos$$$ ($$$1 \\le x \\le n \\le 1000$$$, $$$0 \\le pos \\le n - 1$$$) \u2014 the required length of the permutation, the number to search, and the required position of that number, respectively.", "output_spec": "Print a single number\u00a0\u2014 the remainder of the division of the number of valid permutations by $$$10^9+7$$$.", "sample_inputs": ["4 1 2", "123 42 24"], "sample_outputs": ["6", "824071958"], "notes": "NoteAll possible permutations in the first test case: $$$(2, 3, 1, 4)$$$, $$$(2, 4, 1, 3)$$$, $$$(3, 2, 1, 4)$$$, $$$(3, 4, 1, 2)$$$, $$$(4, 2, 1, 3)$$$, $$$(4, 3, 1, 2)$$$."}, "positive_code": [{"source_code": "// Cheese-Cracker: cheese-cracker.github.io\n\nconst ll PRIME = 10^^9 + 7;\n\nvoid play(){\n ll n, x, pos;\n n = rd; x = rd; pos = rd;\n ll clo = x-1, chi = n - x;\n ll res = 1;\n int lo = 0, hi = n.to!int;\n while(lo < hi){\n int midd = (lo + hi)/2;\n show(midd, pos, clo, chi);\n if(midd <= pos){\n if(pos != midd){\n res *= clo;\n res %= PRIME;\n --clo;\n }\n lo = midd + 1;\n }else{\n res *= chi;\n res %= PRIME;\n --chi;\n hi = midd;\n }\n }\n assert(lo - 1 == pos);\n ll left = chi + clo;\n show(left);\n foreach(i; 1..left+1){\n res *= i;\n res %= PRIME;\n }\n writeln(res);\n}\n\nint main(){\n long t = 1;\n /* t = rd; // Toggle! */\n while(t--) play(); // Let's play!\n stdout.flush;\n return 0;\n}\n\n/**********It's A Me Mario!**********/\nimport std.stdio, std.conv, std.functional, std.string, std.algorithm;\nimport std.container, std.range, std.typecons, std.numeric, std.math, std.random;\nstatic string[] inp;\nT rd(T = long)(){while(!inp.length) inp = readln.chomp.split; string a = inp[0]; inp.popFront; return a.to!T;}\nT[] rdarr(T = long)(){ auto r = readln.chomp.split.to!(T[]); return r; }\nvoid show(A...)(A a) { debug{ foreach(t; a){ write(t, \"| \"); } writeln; } }\nalias ll = long;\nalias rbt = redBlackTree;\nalias tup = Tuple!(long, \"x\", long, \"y\");\nT max(T = long)(T a, T b){ return (a > b) ? a : b; }\nT min(T = long)(T a, T b){ return (a < b) ? a : b; }\n"}], "negative_code": [], "src_uid": "24e2f10463f440affccc2755f4462d8a"} {"nl": {"description": "Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.", "input_spec": "You are given a string consisting of 6 characters (all characters are digits from 0 to 9) \u2014 this string denotes Luba's ticket. The ticket can start with the digit 0.", "output_spec": "Print one number \u2014 the minimum possible number of digits Luba needs to replace to make the ticket lucky.", "sample_inputs": ["000000", "123456", "111000"], "sample_outputs": ["0", "2", "1"], "notes": "NoteIn the first example the ticket is already lucky, so the answer is 0.In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required."}, "positive_code": [{"source_code": "// Try Codeforces\n// author: Leonardone @ NEETSDKASU\nimport std.stdio : readln, writeln;\nimport std.string : chomp;\nimport std.array : split;\nimport std.conv : to;\nimport std.algorithm : sum;\n\nauto gets() { return readln.chomp; }\nauto getNum(T)() { return gets.to!T; }\nauto getVals(T)() { return gets.split.to!(T[]); }\n\nvoid main() {\n auto n = getNum!int;\n int[6] xs;\n for (int i = 0; i < 6; i++) {\n xs[i] = n % 10;\n n = (n - n % 10) / 10;\n }\n auto check = () => sum(xs[0..3]) == sum(xs[3..$]);\n if (check()) {\n writeln(0);\n return;\n }\n foreach (i; 0..6) {\n auto backup = xs[i];\n foreach (j; 0..10) {\n xs[i] = j;\n if (check()) {\n writeln(1);\n return;\n }\n }\n xs[i] = backup;\n }\n foreach (i; 0..5) {\n auto backupA = xs[i];\n foreach (a; 0..10) {\n xs[i] = a;\n foreach (j; i+1..6) {\n auto backupB = xs[j];\n foreach (b; 0..10) {\n xs[j] = b;\n if (check()) {\n writeln(2);\n return;\n }\n }\n xs[j] = backupB;\n }\n }\n xs[i] = backupA;\n }\n writeln(3);\n}"}], "negative_code": [], "src_uid": "09601fd1742ffdc9f822950f1d3e8494"} {"nl": {"description": "Mancala is a game famous in the Middle East. It is played on a board that consists of 14 holes. Initially, each hole has $$$a_i$$$ stones. When a player makes a move, he chooses a hole which contains a positive number of stones. He takes all the stones inside it and then redistributes these stones one by one in the next holes in a counter-clockwise direction.Note that the counter-clockwise order means if the player takes the stones from hole $$$i$$$, he will put one stone in the $$$(i+1)$$$-th hole, then in the $$$(i+2)$$$-th, etc. If he puts a stone in the $$$14$$$-th hole, the next one will be put in the first hole.After the move, the player collects all the stones from holes that contain even number of stones. The number of stones collected by player is the score, according to Resli.Resli is a famous Mancala player. He wants to know the maximum score he can obtain after one move.", "input_spec": "The only line contains 14 integers $$$a_1, a_2, \\ldots, a_{14}$$$ ($$$0 \\leq a_i \\leq 10^9$$$)\u00a0\u2014 the number of stones in each hole. It is guaranteed that for any $$$i$$$ ($$$1\\leq i \\leq 14$$$) $$$a_i$$$ is either zero or odd, and there is at least one stone in the board.", "output_spec": "Output one integer, the maximum possible score after one move.", "sample_inputs": ["0 1 1 0 0 0 0 0 0 7 0 0 0 0", "5 1 1 1 1 0 0 0 0 0 0 0 0 0"], "sample_outputs": ["4", "8"], "notes": "NoteIn the first test case the board after the move from the hole with $$$7$$$ stones will look like 1 2 2 0 0 0 0 0 0 0 1 1 1 1. Then the player collects the even numbers and ends up with a score equal to $$$4$$$."}, "positive_code": [{"source_code": "import std.stdio;\nimport std.range;\nimport std.array;\nimport std.string;\nimport std.conv;\nimport std.typecons;\nimport std.algorithm;\nimport std.container;\nimport std.typecons;\nimport std.random;\nimport std.csv;\nimport std.regex;\nimport std.math;\nimport core.time;\nimport std.ascii;\nimport std.digest.sha;\nimport std.outbuffer;\n\nvoid main()\n{\n\tenum N = 14;\n\tlong[] a = readln.chomp.split.map!(to!long).array;\n\tlong ans = 0;\n\tforeach (i, v; a) {\n\t\t// simulate\n\t\tlong[] b = a.dup;\n\t\tb[i] = 0;\n\t\tforeach (j; 0..N) {\n\t\t\tb[cast(uint)((i + j + 1) % N)] += v / N;\n\t\t}\n\t\tforeach (j; 0 .. v % N) {\n\t\t\t++b[cast(uint)((i + j + 1) % N)];\n\t\t}\n\t\tlong sub = 0;\n\t\tforeach (w; b) {\n\t\t\tif (w % 2 == 0) {\n\t\t\t\tsub += w;\n\t\t\t}\n\t\t}\n\t\tans = max(ans, sub);\n\t}\n\tans.writeln;\n}\n\nvoid tie(R, Args...)(R arr, ref Args args)\n\t\tif (isRandomAccessRange!R || isArray!R)\nin\n{\n\tassert (arr.length == args.length);\n}\nbody\n{\n\tforeach (i, ref v; args) {\n\t\talias T = typeof(v);\n\t\tv = arr[i].to!T;\n\t}\n}\n\nvoid verbose(Args...)(in ref Args args)\n{\n\tstderr.write(\"[\");\n\tforeach (i, ref v; args) {\n\t\tif (i) stderr.write(\", \");\n\t\tstderr.write(v);\n\t}\n\tstderr.writeln(\"]\");\n}\n\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n auto a = readln.splitter.map!(to!int).array;\n a ~= a;\n long ans = 0;\n foreach (i; 0..14) {\n auto now = a[i+1..i+1+14].dup;\n \n debug { writeln(now); }\n \n now[$-1] = 0;\n \n auto curVal = (int j, long e) => e + a[i] / 14 + (a[i] % 14 >= j);\n auto vals = now.enumerate(1).map!(x => curVal(x.index, x.value));\n \n debug { writeln(vals); }\n \n ans = max (ans, vals.filter!(x => x % 2 == 0).sum);\n }\n \n writeln (ans);\n}"}, {"source_code": "import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;\n\nauto rdsp(){return readln.splitter;}\nvoid pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}\nvoid readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}\n\nvoid main()\n{\n long[] a; readA(14, a);\n\n auto ans = 0L;\n foreach (i; 0..14) {\n auto b = a.dup;\n b[i] = 0;\n foreach (j; 0..14)\n b[(i+j+1)%14] += a[i]/14 + (j < a[i]%14);\n\n auto r = 0L;\n foreach (j; 0..14)\n if (b[j]%2 == 0) r += b[j];\n ans = max(ans, r);\n }\n\n writeln(ans);\n}\n"}, {"source_code": "import std.algorithm, std.array, std.conv, std.stdio, std.string;\n\nvoid main ()\n{\n\tstring s;\n\twhile ((s = readln.strip) != \"\")\n\t{\n\t\tauto a = s.splitter.map !(to !(long)).array;\n\t\tauto n = a.length;\n\t\tlong res = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tauto q = a[i] / n;\n\t\t\tauto r = a[i] % n;\n\t\t\tauto b = a.dup;\n\t\t\tb[i] = 0;\n\t\t\tforeach (j; 0..n)\n\t\t\t{\n\t\t\t\tb[(i + j + 1) % n] += q + (j < r);\n\t\t\t}\n\t\t\tauto cur = b.filter !(x => x % 2 == 0).sum;\n\t\t\tres = max (res, cur);\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n=14;\n auto a=readln.split.to!(long[]);\n long ret=0;\n foreach(i; 0..n)if(a[i]>0){\n auto b=a.dup;\n long k=b[i];\n b[i]=0;\n foreach(j; 0..n) b[j]+=k/n;\n for(int j=1; j<=(k%n).to!(int); j++) b[(i+j)%n]+=1;\n long score=0;\n foreach(e; b)if(e%2==0) score+=e;\n ret=max(ret, score);\n }\n writeln(ret);\n}\n\nvoid rd(T...)(ref T x){\n import std.stdio, std.string, std.conv;\n auto l=readln.split;\n assert(l.length==x.length);\n foreach(i, ref e; x) e=l[i].to!(typeof(e));\n}"}], "negative_code": [{"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n auto a = readln.splitter.map!(to!int).array;\n a ~= a;\n long ans = 0;\n foreach (i; 0..14) {\n auto now = a[i+1..i+1+14].dup;\n \n debug { writeln(now); }\n \n now[$-1] = 0;\n \n auto curVal = (int j, int e) => e + a[i] / 14 + (a[i] % 14 >= j);\n auto vals = now.enumerate(1).map!(x => curVal(x.index, x.value));\n \n debug { writeln(vals); }\n \n ans = max (ans, vals.filter!(x => x % 2 == 0).sum);\n }\n \n writeln (ans);\n}"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\n\nvoid main()\n{\n auto a = readln.splitter.map!(to!int).array;\n a ~= a;\n int ans = 0;\n foreach (i; 0..14) {\n auto now = a[i+1..i+1+14].dup;\n \n debug { writeln(now); }\n \n now[$-1] = 0;\n \n auto curVal = (int j, int e) => e + a[i] / 14 + (a[i] % 14 >= j);\n auto vals = now.enumerate(1).map!(x => curVal(x.index, x.value));\n \n debug { writeln(vals); }\n \n ans = max (ans, vals.filter!(x => x % 2 == 0).sum);\n }\n \n writeln (ans);\n}"}, {"source_code": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int n=14;\n auto a=readln.split.to!(long[]);\n long ret=0;\n foreach(i; 0..n)if(a[i]>0){\n auto b=a.dup;\n long k=b[i];\n b[i]=0;\n foreach(j; 0..n) b[j]+=k/n;\n for(int j=1; j<=(k%n).to!(int); j++) b[j%n]+=1;\n long score=reduce!((r, e)=>(r+(e%2==0 ? e : 0L)))(0L, b);\n ret=max(ret, score);\n }\n writeln(ret);\n}\n\nvoid rd(T...)(ref T x){\n import std.stdio, std.string, std.conv;\n auto l=readln.split;\n assert(l.length==x.length);\n foreach(i, ref e; x) e=l[i].to!(typeof(e));\n}"}], "src_uid": "1ac11153e35509e755ea15f1d57d156b"} {"nl": {"description": "Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to \"All World Classical Singing Festival\". Other than Devu, comedian Churu was also invited.Devu has provided organizers a list of the songs and required time for singing them. He will sing n songs, ith song will take ti minutes exactly. The Comedian, Churu will crack jokes. All his jokes are of 5 minutes exactly.People have mainly come to listen Devu. But you know that he needs rest of 10 minutes after each song. On the other hand, Churu being a very active person, doesn't need any rest.You as one of the organizers should make an optimal s\u0441hedule for the event. For some reasons you must follow the conditions: The duration of the event must be no more than d minutes; Devu must complete all his songs; With satisfying the two previous conditions the number of jokes cracked by Churu should be as many as possible. If it is not possible to find a way to conduct all the songs of the Devu, output -1. Otherwise find out maximum number of jokes that Churu can crack in the grand event.", "input_spec": "The first line contains two space separated integers n, d (1\u2009\u2264\u2009n\u2009\u2264\u2009100;\u00a01\u2009\u2264\u2009d\u2009\u2264\u200910000). The second line contains n space-separated integers: t1,\u2009t2,\u2009...,\u2009tn (1\u2009\u2264\u2009ti\u2009\u2264\u2009100).", "output_spec": "If there is no way to conduct all the songs of Devu, output -1. Otherwise output the maximum number of jokes that Churu can crack in the grand event.", "sample_inputs": ["3 30\n2 2 1", "3 20\n2 1 1"], "sample_outputs": ["5", "-1"], "notes": "NoteConsider the first example. The duration of the event is 30 minutes. There could be maximum 5 jokes in the following way: First Churu cracks a joke in 5 minutes. Then Devu performs the first song for 2 minutes. Then Churu cracks 2 jokes in 10 minutes. Now Devu performs second song for 2 minutes. Then Churu cracks 2 jokes in 10 minutes. Now finally Devu will perform his last song in 1 minutes. Total time spent is 5\u2009+\u20092\u2009+\u200910\u2009+\u20092\u2009+\u200910\u2009+\u20091\u2009=\u200930 minutes.Consider the second example. There is no way of organizing Devu's all songs. Hence the answer is -1. "}, "positive_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.conv;\nimport std.array;\nimport std.range;\n\nvoid main()\n{\n auto nm = readln.split.map!(to!int);\n auto ts = readln.split.map!(to!int);\n auto count = 0;\n auto d = nm[1]-ts[0];\n foreach(t; ts.dropOne) {\n if (d<0) {\n writeln(-1);\n return;\n } else {\n d-=10;\n count+=2;\n }\n //writef(\"d=%d c=%d \",d,count);\n d-=t;\n }\n if (d<0) {\n writeln(-1);\n return;\n }\n while (d>=10) {\n d-=10;\n count+=2;\n }\n if (d>=5) { count++;}\n writeln(count);\n}\n"}, {"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, in T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, in T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp( const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(inout(S) x, inout(T) y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(in T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nint N, D;\nint[] A;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tN = readInt;\n\t\tD = readInt;\n\t\tA = new int[N];\n\t\tforeach (i; 0 .. N) {\n\t\t\tA[i] = readInt;\n\t\t}\n\t\t\n\t\tconst x = D - reduce!\"a + b\"(0, A) - 10 * (N - 1);\n\t\tif (x < 0) {\n\t\t\twriteln(-1);\n\t\t} else {\n\t\t\twriteln(x / 5 + 2 * (N - 1));\n\t\t}\n\t}\n\t} catch (EOFException) {}\n}\n\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.conv;\n\nvoid main()\n{\n auto nm = readln.split.map!(to!int);\n auto ts = readln.split.map!(to!int);\n auto count = 0;\n auto d = nm[1];\n foreach(t; ts) {\n d-=t;\n if (d<0) {\n writeln(-1);\n return;\n } else {\n d-=10;\n count+=2;\n }\n }\n if (d>5) { count++;}\n writeln(count);\n}\n"}], "src_uid": "b16f5f5c4eeed2a3700506003e8ea8ea"} {"nl": {"description": "You are given names of two days of the week.Please, determine whether it is possible that during some non-leap year the first day of some month was equal to the first day of the week you are given, while the first day of the next month was equal to the second day of the week you are given. Both months should belong to one year.In this problem, we consider the Gregorian calendar to be used. The number of months in this calendar is equal to 12. The number of days in months during any non-leap year is: 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31.Names of the days of the week are given with lowercase English letters: \"monday\", \"tuesday\", \"wednesday\", \"thursday\", \"friday\", \"saturday\", \"sunday\".", "input_spec": "The input consists of two lines, each of them containing the name of exactly one day of the week. It's guaranteed that each string in the input is from the set \"monday\", \"tuesday\", \"wednesday\", \"thursday\", \"friday\", \"saturday\", \"sunday\".", "output_spec": "Print \"YES\" (without quotes) if such situation is possible during some non-leap year. Otherwise, print \"NO\" (without quotes).", "sample_inputs": ["monday\ntuesday", "sunday\nsunday", "saturday\ntuesday"], "sample_outputs": ["NO", "YES", "YES"], "notes": "NoteIn the second sample, one can consider February 1 and March 1 of year 2015. Both these days were Sundays.In the third sample, one can consider July 1 and August 1 of year 2017. First of these two days is Saturday, while the second one is Tuesday."}, "positive_code": [{"source_code": "import std.stdio;\nimport std.math;\nimport std.algorithm;\nimport std.range;\nimport std.random;\nimport std.regex;\nimport std.string;\nimport std.numeric;\nimport std.functional;\nimport std.bigint;\nimport std.bitmanip;\nimport std.conv;\nimport std.container;\nalias redBlackTree rbt;\nalias BigInt big;\n//writeln readf readln string wstring dstring delegate function static length\n//double float real foreach immutable assert unittest continue break\n\nvoid main()\n{\n\tint[string] q=[\"monday\" : 1,\"tuesday\" : 2,\"wednesday\" : 3,\"thursday\" : 4,\"friday\" : 5,\"saturday\" : 6 ,\"sunday\" : 7];\n\tstring a=readln,b=readln;\n a=a[0..$-1];\n b=b[0..$-1];\n int x=q[a],y=q[b];\n\tint p;\n\tif(x>y) p=7+y-x;\n\telse p=y-x;\n\tif(p <4 && p!=1)writeln(\"YES\");\n\telse writeln(\"NO\");\n}\n"}, {"source_code": "import std.stdio;\nvoid main()\n{\n\tauto q=[\"monday\" : 1,\"tuesday\" : 2,\"wednesday\" : 3,\"thursday\" : 4,\"friday\" : 5,\"saturday\" : 6 ,\"sunday\" : 7];\n\tstring a,b;\n\treadf(\"%s\\n%s\\n\",&a,&b);\n\t//writeln(a);\n\tint x=q[a],y=q[b];\n\tint p;\n\tif(x>y) p=7+y-x;\n\telse p=y-x;\n\tif(p <4 && p!=1)writeln(\"YES\");\n\telse writeln(\"NO\");\n}\n"}, {"source_code": "import std.stdio;\nimport std.math;\nimport std.algorithm;\nimport std.range;\nimport std.random;\nimport std.regex;\nimport std.string;\nimport std.numeric;\nimport std.functional;\nimport std.bigint;\nimport std.bitmanip;\nimport std.conv;\nimport std.container;\nalias redBlackTree rbt;\nalias BigInt big;\n//writeln readf readln string wstring dstring delegate function static length\n//double float real foreach immutable assert unittest continue break\n\nvoid main()\n{\n\tauto q=[\"monday\" : 1,\"tuesday\" : 2,\"wednesday\" : 3,\"thursday\" : 4,\"friday\" : 5,\"saturday\" : 6 ,\"sunday\" : 7];\n\tstring a,b;\n\treadf(\"%s\\n%s\\n\",&a,&b);\n\t//writeln(a);\n\tint x=q[a],y=q[b];\n\tint p;\n\tif(x>y) p=7+y-x;\n\telse p=y-x;\n\tif(p <4 && p!=1)writeln(\"YES\");\n\telse writeln(\"NO\");\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nenum DOWS = [\n\"monday\", \"tuesday\", \"wednesday\", \"thursday\", \"friday\", \"saturday\", \"sunday\"\n];\n\nvoid main() {\n try {\n for (; ; ) {\n const S = readToken();\n const T = readToken();\n \n const s = DOWS.countUntil(S);\n const t = DOWS.countUntil(T);\n bool ans;\n foreach (n; [28, 30, 31]) {\n if ((s + n - t) % 7 == 0) {\n debug {\n writeln(\"ok \", n);\n }\n ans = true;\n }\n }\n writeln(ans ? \"YES\" : \"NO\");\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "2a75f68a7374b90b80bb362c6ead9a35"} {"nl": {"description": "Ujan has been lazy lately, but now has decided to bring his yard to good shape. First, he decided to paint the path from his house to the gate.The path consists of $$$n$$$ consecutive tiles, numbered from $$$1$$$ to $$$n$$$. Ujan will paint each tile in some color. He will consider the path aesthetic if for any two different tiles with numbers $$$i$$$ and $$$j$$$, such that $$$|j - i|$$$ is a divisor of $$$n$$$ greater than $$$1$$$, they have the same color. Formally, the colors of two tiles with numbers $$$i$$$ and $$$j$$$ should be the same if $$$|i-j| > 1$$$ and $$$n \\bmod |i-j| = 0$$$ (where $$$x \\bmod y$$$ is the remainder when dividing $$$x$$$ by $$$y$$$).Ujan wants to brighten up space. What is the maximum number of different colors that Ujan can use, so that the path is aesthetic?", "input_spec": "The first line of input contains a single integer $$$n$$$ ($$$1 \\leq n \\leq 10^{12}$$$), the length of the path.", "output_spec": "Output a single integer, the maximum possible number of colors that the path can be painted in.", "sample_inputs": ["4", "5"], "sample_outputs": ["2", "5"], "notes": "NoteIn the first sample, two colors is the maximum number. Tiles $$$1$$$ and $$$3$$$ should have the same color since $$$4 \\bmod |3-1| = 0$$$. Also, tiles $$$2$$$ and $$$4$$$ should have the same color since $$$4 \\bmod |4-2| = 0$$$.In the second sample, all five colors can be used. "}, "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.numeric;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tlong n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\tlong res = n;\n\t\tfor (long d = 2; d * d <= n; d++)\n\t\t{\n\t\t\tif (n % d == 0)\n\t\t\t{\n\t\t\t\tres = gcd (res, d);\n\t\t\t\tres = gcd (res, n / d);\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nvoid solve(){\n\tlong n = rlong;\n\t\n\tlong[] ds = [n];\n\tfor(long i = 2 ; i * i <= n; i ++){\n\t\tif(n % i == 0) ds ~= i, ds ~= n / i;\n\t}\n\tds.sort();\n\t\n\tforeach(d; ds[1 .. $]){\n\t\tif(d % ds[0] != 0){\n\t\t\t1.writeln;\n\t\t\treturn;\n\t\t}\n\t}\n\tds[0].writeln;\n\treturn;\n}\n"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\nint root(int[] uf, int u) {\n return (uf[u] < 0) ? u : (uf[u] = uf.root(uf[u]));\n}\nbool connect(int[] uf, int u, int v) {\n u = uf.root(u);\n v = uf.root(v);\n if (u == v) return false;\n if (uf[u] > uf[v]) swap(u, v);\n uf[u] += uf[v];\n uf[v] = u;\n return true;\n}\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readLong();\n \n long[] ds;\n for (long d = 1; d * d <= N; ++d) {\n if (N % d == 0) {\n ds ~= d;\n if (d != N / d) {\n ds ~= N / d;\n }\n }\n }\n ds.sort();\n const dsLen = cast(int)(ds.length);\n debug {\n writeln(\"ds = \", ds);\n }\n if (dsLen <= 2) {\n writeln(N);\n } else {\n const V = cast(int)(ds[1]);\n auto uf = new int[V];\n uf[] = -1;\n foreach (j; 2 .. dsLen) {\n for (int u = 0, v = cast(int)(ds[j] % V); u < V; ++u, ++v %= V) {\n uf.connect(u, v);\n }\n }\n int ans;\n foreach (u; 0 .. V) {\n if (uf[u] < 0) {\n ++ans;\n }\n }\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\n//long mod = 10^^9 + 7;\nlong mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto n = RD;\n\tlong[] p;\n\tfor (long i = 2; i*i <= n; ++i)\n\t{\n\t\tif (n % i == 0)\n\t\t{\n\t\t\tp ~= i;\n\t\t\tp ~= n/i;\n\t\t}\n\t}\n\tlong ans = n;\n\tforeach (e; p)\n\t{\n\t\tans = gcd(ans, e);\n\t}\n\n\twriteln(ans);\n\tstdout.flush();\n\tdebug readln();\n}"}], "negative_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\nint root(int[] uf, int u) {\n return (uf[u] < 0) ? u : (uf[u] = uf.root(uf[u]));\n}\nbool connect(int[] uf, int u, int v) {\n u = uf.root(u);\n v = uf.root(v);\n if (u == v) return false;\n if (uf[u] > uf[v]) swap(u, v);\n uf[u] += uf[v];\n uf[v] = u;\n return true;\n}\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readLong();\n \n long[] ds;\n for (long d = 1; d * d <= N; ++d) {\n if (N % d == 0) {\n ds ~= d;\n if (d != N / d) {\n ds ~= d;\n }\n }\n }\n ds.sort();\n const dsLen = cast(int)(ds.length);\n if (dsLen <= 2) {\n writeln(N);\n } else {\n const V = cast(int)(ds[1]);\n auto uf = new int[V];\n uf[] = -1;\n foreach (j; 2 .. dsLen) {\n for (int u = 0, v = cast(int)(ds[j] % V); u < V; ++u, ++v %= V) {\n uf.connect(u, v);\n }\n }\n int ans;\n foreach (u; 0 .. V) {\n if (uf[u] < 0) {\n ++ans;\n }\n }\n writeln(ans);\n }\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "f553e89e267c223fd5acf0dd2bc1706b"} {"nl": {"description": "You are given a sequence $$$a_1, a_2, \\dots, a_n$$$ consisting of $$$n$$$ integers.You can choose any non-negative integer $$$D$$$ (i.e. $$$D \\ge 0$$$), and for each $$$a_i$$$ you can: add $$$D$$$ (only once), i.\u2009e. perform $$$a_i := a_i + D$$$, or subtract $$$D$$$ (only once), i.\u2009e. perform $$$a_i := a_i - D$$$, or leave the value of $$$a_i$$$ unchanged. It is possible that after an operation the value $$$a_i$$$ becomes negative.Your goal is to choose such minimum non-negative integer $$$D$$$ and perform changes in such a way, that all $$$a_i$$$ are equal (i.e. $$$a_1=a_2=\\dots=a_n$$$).Print the required $$$D$$$ or, if it is impossible to choose such value $$$D$$$, print -1.For example, for array $$$[2, 8]$$$ the value $$$D=3$$$ is minimum possible because you can obtain the array $$$[5, 5]$$$ if you will add $$$D$$$ to $$$2$$$ and subtract $$$D$$$ from $$$8$$$. And for array $$$[1, 4, 7, 7]$$$ the value $$$D=3$$$ is also minimum possible. You can add it to $$$1$$$ and subtract it from $$$7$$$ and obtain the array $$$[4, 4, 4, 4]$$$.", "input_spec": "The first line of the input contains one integer $$$n$$$ ($$$1 \\le n \\le 100$$$) \u2014 the number of elements in $$$a$$$. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 100$$$) \u2014 the sequence $$$a$$$.", "output_spec": "Print one integer \u2014 the minimum non-negative integer value $$$D$$$ such that if you add this value to some $$$a_i$$$, subtract this value from some $$$a_i$$$ and leave some $$$a_i$$$ without changes, all obtained values become equal. If it is impossible to choose such value $$$D$$$, print -1.", "sample_inputs": ["6\n1 4 4 7 4 1", "5\n2 2 5 2 5", "4\n1 3 3 7", "2\n2 8"], "sample_outputs": ["3", "3", "-1", "3"], "notes": null}, "positive_code": [{"source_code": "import std.algorithm, std.conv, std.range, std.stdio, std.string;\nvoid main () {\n\tauto n = readln.strip.to!int, a = readln.split.map !(to!int).array;\n\tforeach (d; 0..101) foreach (b; 0..101) if (a.all !(x => [b - d, b, b + d].canFind (x))) {d.write; return;}\n\twrite (-1);\n}\n"}, {"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\n\nimmutable int limit = 101;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto a = readln.splitter.map !(to !(int)).array;\n\t\tint res = limit;\n\t\tforeach (base; 0..limit)\n\t\t{\n\t\t\tforeach (diff; 0..limit)\n\t\t\t{\n\t\t\t\tif (a.all !(x => x == base ||\n\t\t\t\t x == base - diff || x == base + diff))\n\t\t\t\t{\n\t\t\t\t\tres = min (res, diff);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (res == limit)\n\t\t{\n\t\t\tres = -1;\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.stdio, std.conv, std.string;\nimport std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n\nint DEBUG_LEVEL = 0;\nvoid print()(){ writeln(\"\"); }\nvoid print(T, A ...)(T t, lazy A a){ write(t), print(a); }\nvoid print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }\n\nconst long mod = 1_000_000_007;\n\nvoid main(string[] args){\n\tif(args.length > 1 && args[1] == \"-debug\"){\n\t\tif(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;\n\t\telse DEBUG_LEVEL = 1;\n\t}\n\t\n\tint n = read.to!int;\n\tint[] as = readln.chomp.split.map!(to!int).array;\n\t\n\tbool[int] aset;\n\tforeach(a; as) aset[a] = 1;\n\t\n\tint ans;\n\t\n\tint[] ks = aset.keys;\n\tks.sort();\n\tif(ks.length == 1) ans = 0;\n\telse if(ks.length == 2){\n\t\tans = ks[1] - ks[0];\n\t\tif(ans % 2 == 0) ans /= 2;\n\t}\n\telse if(ks.length == 3){\n\t\tif(ks[1] - ks[0] == ks[2] - ks[1]) ans = ks[1] - ks[0];\n\t\telse ans = -1;\n\t}\n\telse ans = -1;\n\t\n\tans.writeln;\n\n}\n/*\n\nHow many different a do they have?\nIf more than 4, impossible.\nIf 3, possible if and only if it is like 1-4-7.\nIf 2 or 1, always possible.\n\n*/\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nbool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }\nbool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }\n\nlong mod = 10^^9 + 7;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\t\n\tauto N = RD;\n\tauto a = RDR.ARR;\n\ta = a.sort().uniq.array;\n\n\tif (a.length == 1)\n\t{\n\t\twriteln(0);\n\t}\n\telse if (a.length == 2)\n\t{\n\t\tauto x = a[1] - a[0];\n\t\twriteln(x % 2 == 0 ? x / 2 : x);\n\t}\n\telse if (a.length == 3)\n\t{\n\t\tlong l = a[0];\n\t\tlong m = a[1];\n\t\tlong r = a[2];\n\t\twriteln(m - l == r - m ? m - l : -1);\n\t}\n\telse \n\t{\n\t\twriteln(-1);\n\t}\n\t\n\tstdout.flush();\n\tdebug readln();\n}"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.string;\nimport std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nstring read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\n\nint DEBUG_LEVEL = 0;\nvoid print()(){ writeln(\"\"); }\nvoid print(T, A ...)(T t, lazy A a){ write(t), print(a); }\nvoid print(int level, T, A ...)(T t, lazy A a){ if(level <= DEBUG_LEVEL) print(t, a); }\n\nconst long mod = 1_000_000_007;\n\nvoid main(string[] args){\n\tif(args.length > 1 && args[1] == \"-debug\"){\n\t\tif(args.length > 2 && args[2].isNumeric) DEBUG_LEVEL = args[2].to!int;\n\t\telse DEBUG_LEVEL = 1;\n\t}\n\t\n\tint n = read.to!int;\n\tint[] as = readln.chomp.split.map!(to!int).array;\n\t\n\tbool[int] aset;\n\tforeach(a; as) aset[a] = 1;\n\t\n\tint ans;\n\t\n\tint[] ks = aset.keys;\n\tks.sort();\n\tif(ks.length == 1) ans = 0;\n\telse if(ks.length == 2) ans = ks[1] - ks[0];\n\telse if(ks.length == 3){\n\t\tif(ks[1] - ks[0] == ks[2] - ks[1]) ans = ks[1] - ks[0];\n\t\telse ans = -1;\n\t}\n\telse ans = -1;\n\t\n\tans.writeln;\n\n}\n/*\n\nHow many different a do they have?\nIf more than 4, impossible.\nIf 3, possible if and only if it is like 1-4-7.\nIf 2 or 1, always possible.\n\n*/\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nbool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }\nbool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }\n\nlong mod = 10^^9 + 7;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\t\n\tauto N = RD;\n\tauto a = RDR.ARR;\n\ta = a.sort().uniq.array;\n\n\tif (a.length == 1)\n\t{\n\t\twriteln(0);\n\t}\n\telse if (a.length == 2)\n\t{\n\t\tauto x = a[1] - a[0];\n\t\twriteln(x % 2 == 0 ? x / 2 : -1);\n\t}\n\telse if (a.length == 3)\n\t{\n\t\tlong l = a[0];\n\t\tlong m = a[1];\n\t\tlong r = a[2];\n\t\twriteln(m - l == r - m ? m - l : -1);\n\t}\n\telse \n\t{\n\t\twriteln(-1);\n\t}\n\t\n\tstdout.flush();\n\tdebug readln();\n}"}], "src_uid": "d486a88939c132848a7efdf257b9b066"} {"nl": {"description": "Vadim loves decorating the Christmas tree, so he got a beautiful garland as a present. It consists of $$$n$$$ light bulbs in a single row. Each bulb has a number from $$$1$$$ to $$$n$$$ (in arbitrary order), such that all the numbers are distinct. While Vadim was solving problems, his home Carp removed some light bulbs from the garland. Now Vadim wants to put them back on.Vadim wants to put all bulb back on the garland. Vadim defines complexity of a garland to be the number of pairs of adjacent bulbs with numbers with different parity (remainder of the division by $$$2$$$). For example, the complexity of 1 4 2 3 5 is $$$2$$$ and the complexity of 1 3 5 7 6 4 2 is $$$1$$$.No one likes complexity, so Vadim wants to minimize the number of such pairs. Find the way to put all bulbs back on the garland, such that the complexity is as small as possible.", "input_spec": "The first line contains a single integer $$$n$$$ ($$$1 \\le n \\le 100$$$)\u00a0\u2014 the number of light bulbs on the garland. The second line contains $$$n$$$ integers $$$p_1,\\ p_2,\\ \\ldots,\\ p_n$$$ ($$$0 \\le p_i \\le n$$$)\u00a0\u2014 the number on the $$$i$$$-th bulb, or $$$0$$$ if it was removed.", "output_spec": "Output a single number\u00a0\u2014 the minimum complexity of the garland.", "sample_inputs": ["5\n0 5 0 2 3", "7\n1 0 0 5 0 0 2"], "sample_outputs": ["2", "1"], "notes": "NoteIn the first example, one should place light bulbs as 1 5 4 2 3. In that case, the complexity would be equal to 2, because only $$$(5, 4)$$$ and $$$(2, 3)$$$ are the pairs of adjacent bulbs that have different parity.In the second case, one of the correct answers is 1 7 3 5 6 4 2. "}, "positive_code": [{"source_code": "//prewritten code: https://github.com/antma/algo\nimport std.algorithm;\nimport std.array;\nimport std.conv;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.traits;\n\nfinal class InputReader {\n private:\n ubyte[] p, buffer;\n bool eof;\n bool rawRead () {\n if (eof) {\n return false;\n }\n p = stdin.rawRead (buffer);\n if (p.empty) {\n eof = true;\n return false;\n }\n return true;\n }\n ubyte nextByte(bool check) () {\n static if (check) {\n if (p.empty) {\n if (!rawRead ()) {\n return 0;\n }\n }\n }\n auto r = p.front;\n p.popFront ();\n return r;\n }\n public:\n this () {\n buffer = uninitializedArray!(ubyte[])(16<<20);\n }\n bool seekByte (in ubyte lo) {\n while (true) {\n p = p.find! (c => c >= lo);\n if (!p.empty) {\n return false;\n }\n if (!rawRead ()) {\n return true;\n }\n }\n }\n template next(T) if (isSigned!T) {\n T next () {\n if (seekByte (45)) {\n return 0;\n }\n T res;\n ubyte b = nextByte!false ();\n if (b == 45) {\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 - (b - 48);\n }\n } else {\n res = b - 48;\n while (true) {\n b = nextByte!true ();\n if (b < 48 || b >= 58) {\n return res;\n }\n res = res * 10 + (b - 48);\n }\n }\n }\n }\n template next(T) if (isUnsigned!T) {\n T next () {\n if (seekByte (48)) {\n return 0;\n }\n T res = nextByte!false () - 48;\n while (true) {\n ubyte b = nextByte!true ();\n if (b < 48 || b >= 58) {\n break;\n }\n res = res * 10 + (b - 48);\n }\n return res;\n }\n }\n T[] nextA(T) (in int n) {\n auto a = uninitializedArray!(T[]) (n);\n foreach (i; 0 .. n) {\n a[i] = next!T;\n }\n return a;\n }\n}\n\nvoid main() {\n auto r = new InputReader ();\n immutable n = r.next!uint ();\n auto a = r.nextA!uint (n);\n auto b = new bool[n + 1];\n foreach (i; a) {\n b[i] = true;\n }\n int odds, evens;\n for (int i = 1; i <= n; ++i) {\n if (!b[i]) {\n if (i & 1) odds++; else evens++;\n }\n }\n int[] pos;\n foreach (i; 0 .. n) {\n if (a[i] == 0) pos ~= i;\n }\n immutable int m = pos.length.to!int;\n auto dp = new int[][][] (m + 1, odds + 1, 3);\n foreach (i; 0 .. m + 1) foreach (j; 0 .. odds + 1) dp[i][j][] = -1;\n auto vo = new int[m];\n auto ve = new int[m];\n b = new bool[m];\n foreach (i; 0 .. m) {\n immutable int k = pos[i];\n if (k > 0) {\n if (a[k-1] != 0) {\n if (a[k-1] & 1) {\n ve[i]++;\n } else {\n vo[i]++;\n }\n } else b[i] = true;\n }\n if (k+1 < n) {\n if (a[k+1] != 0) {\n if (a[k+1] & 1) {\n ve[i]++;\n } else {\n vo[i]++;\n }\n }\n }\n }\n debug stderr.writeln (vo);\n debug stderr.writeln (ve);\n debug stderr.writeln (b);\n debug stderr.writeln (odds);\n debug stderr.writeln (evens);\n\n int f (const int k, const int o, const int last) {\n if (dp[k][o][last] >= 0) return dp[k][o][last];\n immutable int r = m - k;\n if (!r) return dp[k][o][last] = 0; \n immutable int co = odds - o,\n ce = k - co,\n e = evens - ce;\n assert (e >= 0);\n int res = int.max;\n if (o > 0) {\n int w = f (k + 1, o - 1, 1) + vo[k];\n if (b[k] && last == 0) ++w;\n res = min (res, w);\n }\n if (e > 0) {\n int w = f (k + 1, o, 0) + ve[k];\n if (b[k] && last == 1) ++w;\n res = min (res, w);\n }\n return dp[k][o][last] = res;\n }\n int res = f (0, odds, 2);\n foreach (i; 1 .. n) {\n if (a[i-1] != 0 && a[i] != 0 && 0 != ((a[i-1] ^ a[i]) & 1)) {\n ++res;\n }\n }\n writeln (res);\n}\n\n"}, {"source_code": "import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;\nimport std.math, std.random, std.bigint, std.datetime, std.format;\nvoid main(string[] args){ if(args.length > 1) if(args[1] == \"-debug\") DEBUG = 1; solve(); }\nvoid log()(){ writeln(\"\"); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, \" \"), log(a); } bool DEBUG = 0; \nstring rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }\nT rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;\nT[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;\nT[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;\nT chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }\n\n// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //\n\nconst long infty = 100999;\n\nvoid solve(){\n\tint n = rint;\n\tlong[] as = rlong(n);\n\n\tint p = (n + 1) / 2, q = n / 2, z; // how many odds, evens, zeros\n\tforeach(a; as){\n\t\tif(a == 0) z += 1;\n\t\telse if(a % 2) p -= 1;\n\t\telse q -= 1;\n\t}\n\tlog(\"p:\", p, \"q:\", q, \"z:\", z);\n\n\tlong[][][] xs = new long[][][](n, p + 1, q + 1);\n\t\t\t// xs[i][j][k]: use j odd and k even bulbs and the rightmost is odd and the min score\n\tlong[][][] ys = new long[][][](n, p + 1, q + 1);\n\t\t\t// ys[i][j][k]: use j odd and k even bulbs and the rightmost is even and the min score\n\n\tforeach(i, a; as){\n\t\tif(a > 0){ // forced\n\t\t\tif(a % 2){ // forced odd\n\t\t\t\tforeach(j; 0 .. p + 1) foreach(k; 0 .. q + 1){\n\t\t\t\t\tif(i > 0) xs[i][j][k] = min(xs[i - 1][j][k], ys[i - 1][j][k] + 1);\n\t\t\t\t\telse xs[i][j][k] = 0;\n\t\t\t\t\tys[i][j][k] = infty;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse{ // forced even\n\t\t\t\tforeach(j; 0 .. p + 1) foreach(k; 0 .. q + 1){\n\t\t\t\t\txs[i][j][k] = infty;\n\t\t\t\t\tif(i > 0) ys[i][j][k] = min(xs[i - 1][j][k] + 1, ys[i - 1][j][k]);\n\t\t\t\t\telse ys[i][j][k] = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\telse{ // free\n\t\t\tforeach(j; 0 .. p + 1) foreach(k; 0 .. q + 1){\n\t\t\t\tif(i > 0){\n\t\t\t\t\tif(j > 0) xs[i][j][k] = min(xs[i - 1][j - 1][k], ys[i - 1][j - 1][k] + 1);\n\t\t\t\t\telse xs[i][j][k] = infty;\n\t\t\t\t\tif(k > 0) ys[i][j][k] = min(xs[i - 1][j][k - 1] + 1, ys[i - 1][j][k - 1]);\n\t\t\t\t\telse ys[i][j][k] = infty;\n\t\t\t\t}\n\t\t\t\telse{\n\t\t\t\t\tif(j == 1 && k == 0) xs[i][j][k] = 0;\n\t\t\t\t\telse xs[i][j][k] = infty;\n\t\t\t\t\tif(j == 0 && k == 1) ys[i][j][k] = 0;\n\t\t\t\t\telse ys[i][j][k] = infty;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tlog(\"xs:\", xs[i], \"ys:\", ys[i]);\n\t}\n\tlong ans = min(xs[n - 1][p][q], ys[n - 1][p][q]);\n\tans.writeln;\n}"}, {"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nenum INF = 10^^9;\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n auto P = new int[N];\n foreach (i; 0 .. N) {\n P[i] = readInt();\n }\n \n auto dp = new int[][][](N + 1, N + 1, 2);\n foreach (i; 0 .. N + 1) {\n foreach (j; 0 .. N + 1) {\n dp[i][j][] = INF;\n }\n }\n dp[0][0][] = 0;\n foreach (i; 0 .. N) {\n foreach (j; 0 .. i + 1) foreach (s; 0 .. 2) {\n foreach (t; 0 .. 2) {\n if (P[i] == 0 || P[i] % 2 == t) {\n chmin(dp[i + 1][j + t][t], dp[i][j][s] + abs(s - t));\n }\n }\n }\n }\n int ans = INF;\n foreach (s; 0 .. 2) {\n chmin(ans, dp[N][N - N / 2][s]);\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}, {"source_code": "import std.stdio : writeln;\n\nstruct IO {\n string readToken() {\n import std.stdio : stdin;\n import std.array : split;\n import std.range : empty, front, popFront;\n\n while (tokens.empty) {\n tokens = stdin.readln.split;\n }\n string token = tokens.front;\n tokens.popFront;\n return token;\n }\n\n int readInt() {\n import std.conv : to;\n\n return readToken.to!(int);\n }\n\n string[] tokens;\n}\n\nvoid main() {\n import std.algorithm : min, sort;\n\n IO io;\n int n = io.readInt;\n int[] p = new int[n + 2];\n int target = n >> 1;\n for (int i = 1; i <= n; ++i) {\n p[i] = io.readInt - 1;\n if (~p[i]) {\n if (p[i] &= 1) {\n target--;\n }\n }\n }\n int result = n;\n for (int mask = 0; mask < 1 << 2; ++mask) {\n p[0] = mask & 1, p[n + 1] = mask >> 1;\n int cost = 0, low = 0, high = 0, j = 0, pc = 0, nc = 0;\n int[] positives = new int[n + 1], negatives = new int[n + 1];\n for (int i = 1; i <= n + 1; ++i) {\n if (~p[i]) {\n int length = i - j - 1;\n if (p[i] != p[j]) {\n cost++, high += length;\n }\n else if (p[i]) {\n low += length, high += length, negatives[nc++] = length;\n }\n else {\n positives[pc++] = length;\n }\n j = i;\n }\n }\n positives.sort!(\"a > b\");\n negatives.sort!(\"a > b\");\n for (int i = 0; i < pc && high < target; ++i) {\n cost += 2, high += positives[i];\n }\n for (int i = 0; i < nc && low > target; ++i) {\n cost += 2, low -= negatives[i];\n }\n result = min(result, cost);\n }\n writeln(result);\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.bigint, std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic File _f;\nvoid file_io(string fn) { _f = File(fn, \"r\"); }\nstatic string[] s_rd;\nT _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nT[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }\nT[] RDA(T = long)(T fix = 0) { if (_f.isOpen) return _RDA!T(_f, fix); else return _RDA!T(fix); }\n\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nvoid chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998244353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\nvoid modpow(ref long x, long y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }\n\nvoid main()\n{\n\tauto n = RD!int;\n\tauto p = RDA!int;\n\t\n\tauto cnt = new int[](2);\n\tcnt[0] = n/2;\n\tcnt[1] = (n+1)/2;\n\tforeach (i; 0..n)\n\t{\n\t\tif (p[i] == 0) continue;\n\t\tauto j = p[i] % 2;\n\t\t--cnt[j];\n\t}\n\n\tauto dp = new int[][][](n+1, n+1, 2);\n\tforeach (i; 0..n+1)\n\t{\n\t\tforeach (j; 0..n+1)\n\t\t\tdp[i][j][] = -1;\n\t}\n\tdp[cnt[0]][cnt[1]][0] = 0;\n\tdp[cnt[0]][cnt[1]][1] = 0;\n\tforeach (i; 0..n)\n\t{\n\t\tauto ndp = new int[][][](n+1, n+1, 2);\n\t\tforeach (j; 0..n+1)\n\t\t{\n\t\t\tforeach (k; 0..n+1)\n\t\t\t\tndp[j][k][] = -1;\n\t\t}\n\t\tforeach (j; 0..n+1)\n\t\t{\n\t\t\tforeach (k; 0..n+1)\n\t\t\t{\n\t\t\t\tforeach (l; 0..2)\n\t\t\t\t{\n\t\t\t\t\tif (dp[j][k][l] == -1) continue;\n\t\t\t\t\tif (p[i] != 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tauto eo = p[i] % 2;\n\t\t\t\t\t\tauto num = dp[j][k][l] + (eo != l ? 1 : 0);\n\t\t\t\t\t\tif (ndp[j][k][eo] == -1)\n\t\t\t\t\t\t\tndp[j][k][eo] = num;\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tndp[j][k][eo].chmin(num);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\tif (j != 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tauto num = dp[j][k][l] + (l != 0 ? 1 : 0);\n\t\t\t\t\t\tif (ndp[j-1][k][0] == -1)\n\t\t\t\t\t\t\tndp[j-1][k][0] = num;\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tndp[j-1][k][0].chmin(num);\n\t\t\t\t\t}\n\t\t\t\t\tif (k != 0)\n\t\t\t\t\t{\n\t\t\t\t\t\tauto num = dp[j][k][l] + (l != 1 ? 1 : 0);\n\t\t\t\t\t\tif (ndp[j][k-1][1] == -1)\n\t\t\t\t\t\t\tndp[j][k-1][1] = num;\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\tndp[j][k-1][1].chmin(num);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tdp = ndp;\n\t}\n\tdebug writeln(dp);\n\n\tint ans = int.max;\n\tforeach (i; 0..2)\n\t{\n\t\tif (dp[0][0][i] != -1)\n\t\t\tans.chmin(dp[0][0][i]);\n\t}\n\n\twriteln(ans);\n\tstdout.flush;\n\tdebug readln;\n}\n"}], "negative_code": [], "src_uid": "90db6b6548512acfc3da162144169dba"} {"nl": {"description": "Mishka started participating in a programming contest. There are $$$n$$$ problems in the contest. Mishka's problem-solving skill is equal to $$$k$$$.Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves problems from one of the ends of the list. Every time, he chooses which end (left or right) he will solve the next problem from. Thus, each problem Mishka solves is either the leftmost or the rightmost problem in the list.Mishka cannot solve a problem with difficulty greater than $$$k$$$. When Mishka solves the problem, it disappears from the list, so the length of the list decreases by $$$1$$$. Mishka stops when he is unable to solve any problem from any end of the list.How many problems can Mishka solve?", "input_spec": "The first line of input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\le n, k \\le 100$$$) \u2014 the number of problems in the contest and Mishka's problem-solving skill. The second line of input contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 100$$$), where $$$a_i$$$ is the difficulty of the $$$i$$$-th problem. The problems are given in order from the leftmost to the rightmost in the list.", "output_spec": "Print one integer \u2014 the maximum number of problems Mishka can solve.", "sample_inputs": ["8 4\n4 2 3 1 5 1 6 4", "5 2\n3 1 2 1 3", "5 100\n12 34 55 43 21"], "sample_outputs": ["5", "0", "5"], "notes": "NoteIn the first example, Mishka can solve problems in the following order: $$$[4, 2, 3, 1, 5, 1, 6, 4] \\rightarrow [2, 3, 1, 5, 1, 6, 4] \\rightarrow [2, 3, 1, 5, 1, 6] \\rightarrow [3, 1, 5, 1, 6] \\rightarrow [1, 5, 1, 6] \\rightarrow [5, 1, 6]$$$, so the number of solved problems will be equal to $$$5$$$.In the second example, Mishka can't solve any problem because the difficulties of problems from both ends are greater than $$$k$$$.In the third example, Mishka's solving skill is so amazing that he can solve all the problems."}, "positive_code": [{"source_code": "module acmd;\n\nimport std.stdio;\nimport std.conv;\nimport std.algorithm;\nimport std.string;\nimport std.container;\n\nint main () {\n version (offline_judje) {\n stdin.reopen (\"input.txt\", \"rt\");\n }\n\n int n, k;\n readf!\" %d %d\" (n, k);\n int[] nums;\n foreach (i; 0 .. n) {\n int num; readf!\" %d\" (num);\n nums ~= num;\n }\n auto curnums = nums[];\n int ans = 0;\n while (curnums.length > 0) {\n if (curnums[0] <= k) {\n ans++;\n curnums = curnums[1 .. $];\n }\n else if (curnums[$ - 1] <= k) {\n ans++;\n curnums = curnums[0 .. $ - 1];\n }\n else break;\n }\n write (ans);\n\n return 0;\n}\n\n"}, {"source_code": "import std.algorithm;\nimport std.array;\nimport std.bitmanip;\nimport std.container;\nimport std.conv;\nimport std.functional;\nimport std.math;\nimport std.range;\nimport std.stdio;\nimport std.string;\nimport std.typecons;\nimport std.range.interfaces;\n\nvoid main()\n{\n int n, k;\n readf(\"%s %s\", &n, &k);\n readln;\n \n auto a = readln.chomp.split.map!(to!int).array;\n \n int check(int[] a, int k) {\n return cast(int) a.until!(x => x > k).array.length;\n }\n \n auto ans = min(check(a, k) + check(a.retro.array, k), n);\n \n ans.writeln;\n}"}], "negative_code": [], "src_uid": "ecf0ead308d8a581dd233160a7e38173"} {"nl": {"description": "Nezzar buys his favorite snack\u00a0\u2014 $$$n$$$ chocolate bars with lengths $$$l_1,l_2,\\ldots,l_n$$$. However, chocolate bars might be too long to store them properly! In order to solve this problem, Nezzar designs an interesting process to divide them into small pieces. Firstly, Nezzar puts all his chocolate bars into a black box. Then, he will perform the following operation repeatedly until the maximum length over all chocolate bars does not exceed $$$k$$$. Nezzar picks a chocolate bar from the box with probability proportional to its length $$$x$$$. After step $$$1$$$, Nezzar uniformly picks a real number $$$r \\in (0,x)$$$ and divides the chosen chocolate bar into two chocolate bars with lengths $$$r$$$ and $$$x-r$$$. Lastly, he puts those two new chocolate bars into the black box. Nezzar now wonders, what is the expected number of operations he will perform to divide his chocolate bars into small pieces.It can be shown that the answer can be represented as $$$\\frac{P}{Q}$$$, where $$$P$$$ and $$$Q$$$ are coprime integers and $$$Q \\not \\equiv 0$$$ ($$$\\bmod 998\\,244\\,353$$$). Print the value of $$$P\\cdot Q^{-1} \\mod 998\\,244\\,353$$$.", "input_spec": "The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\le n \\le 50, 1 \\le k \\le 2000$$$). The second line contains $$$n$$$ integers $$$l_1, l_2, \\ldots, l_n$$$ ($$$1 \\le l_i$$$, $$$\\sum_{i=1}^{n} l_i \\le 2000$$$).", "output_spec": "Print a single integer \u2014 the expected number of operations Nezzar will perform to divide his chocolate bars into small pieces modulo $$$998\\,244\\,353$$$.", "sample_inputs": ["1 1\n2", "1 1\n1", "1 5\n1234", "2 1\n2 3", "10 33\n10 20 30 40 50 60 70 80 90 100"], "sample_outputs": ["4", "0", "15630811", "476014684", "675105648"], "notes": null}, "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\nstruct ModInt(int M_) {\n import std.conv : to;\n alias M = M_;\n int x;\n this(ModInt a) { x = a.x; }\n this(long a) { x = cast(int)(a % M); if (x < 0) x += M; }\n ref ModInt opAssign(long a) { return (this = ModInt(a)); }\n ref ModInt opOpAssign(string op)(ModInt a) {\n static if (op == \"+\") { x += a.x; if (x >= M) x -= M; }\n else static if (op == \"-\") { x -= a.x; if (x < 0) x += M; }\n else static if (op == \"*\") { x = cast(int)((cast(long)(x) * a.x) % M); }\n else static if (op == \"/\") { this *= a.inv(); }\n else static assert(false);\n return this;\n }\n ref ModInt opOpAssign(string op)(long a) {\n static if (op == \"^^\") {\n if (a < 0) return (this = inv()^^(-a));\n ModInt t2 = this, te = ModInt(1);\n for (long e = a; e > 0; e >>= 1) {\n if (e & 1) te *= t2;\n t2 *= t2;\n }\n x = cast(int)(te.x);\n return this;\n } else return mixin(\"this \" ~ op ~ \"= ModInt(a)\");\n }\n ModInt inv() const {\n int a = x, b = M, y = 1, z = 0, t;\n for (; ; ) {\n t = a / b; a -= t * b;\n if (a == 0) {\n assert(b == 1 || b == -1);\n return ModInt(b * z);\n }\n y -= t * z;\n t = b / a; b -= t * a;\n if (b == 0) {\n assert(a == 1 || a == -1);\n return ModInt(a * y);\n }\n z -= t * y;\n }\n }\n ModInt opUnary(string op: \"-\")() const { return ModInt(-x); }\n ModInt opBinary(string op, T)(T a) const {\n return mixin(\"ModInt(this) \" ~ op ~ \"= a\");\n }\n ModInt opBinaryRight(string op)(long a) const {\n return mixin(\"ModInt(a) \" ~ op ~ \"= this\");\n }\n bool opCast(T: bool)() const { return (x != 0); }\n string toString() const { return x.to!string; }\n}\n\nenum MO = 998244353;\nalias Mint = ModInt!MO;\n\nenum LIM = 10^^5 + 10;\nMint[] inv, fac, invFac;\nvoid prepare() {\n inv = new Mint[LIM];\n fac = new Mint[LIM];\n invFac = new Mint[LIM];\n inv[1] = 1;\n foreach (i; 2 .. LIM) {\n inv[i] = -(Mint.M / i) * inv[cast(size_t)(Mint.M % i)];\n }\n fac[0] = invFac[0] = 1;\n foreach (i; 1 .. LIM) {\n fac[i] = fac[i - 1] * i;\n invFac[i] = invFac[i - 1] * inv[i];\n }\n}\nMint binom(long n, long k) {\n if (0 <= k && k <= n) {\n assert(n < LIM);\n return fac[cast(size_t)(n)] * invFac[cast(size_t)(k)] * invFac[cast(size_t)(n - k)];\n } else {\n return Mint(0);\n }\n}\n\n\nclass Fft(int M_, int G, int K) {\n import std.algorithm : reverse;\n import std.traits : isIntegral;\n alias M = M_;\n // 1, 1/4, 1/8, 3/8, 1/16, 5/16, 3/16, 7/16, ...\n int[] gs;\n this() {\n static assert(2 <= K && K <= 30, \"Fft: 2 <= K <= 30 must hold\");\n static assert(!((M - 1) & ((1 << K) - 1)), \"Fft: 2^K | M - 1 must hold\");\n gs = new int[1 << (K - 1)];\n gs[0] = 1;\n long g2 = G, gg = 1;\n for (int e = (M - 1) >> K; e; e >>= 1) {\n if (e & 1) gg = (gg * g2) % M;\n g2 = (g2 * g2) % M;\n }\n gs[1 << (K - 2)] = cast(int)(gg);\n for (int l = 1 << (K - 2); l >= 2; l >>= 1) {\n gs[l >> 1] = cast(int)((cast(long)(gs[l]) * gs[l]) % M);\n }\n assert((cast(long)(gs[1]) * gs[1]) % M == M - 1,\n \"Fft: g^(2^(K-1)) == -1 (mod M) must hold\");\n for (int l = 2; l <= 1 << (K - 2); l <<= 1) {\n foreach (i; 1 .. l) {\n gs[l + i] = cast(int)((cast(long)(gs[l]) * gs[i]) % M);\n }\n }\n }\n void fft(int[] xs) const {\n const n = cast(int)(xs.length);\n assert(!(n & (n - 1)), \"Fft.fft: |xs| must be a power of two\");\n assert(n <= 1 << K, \"Fft.fft: |xs| <= 2^K must hold\");\n for (int l = n; l >>= 1; ) {\n foreach (i; 0 .. (n >> 1) / l) {\n const(long) g = gs[i];\n foreach (j; (i << 1) * l .. (i << 1 | 1) * l) {\n const t = cast(int)((g * xs[j + l]) % M);\n if ((xs[j + l] = xs[j] - t) < 0) xs[j + l] += M;\n if ((xs[j] += t) >= M) xs[j] -= M;\n }\n }\n }\n }\n void invFft(int[] xs) const {\n const n = cast(int)(xs.length);\n assert(!(n & (n - 1)), \"Fft.invFft: |xs| must be a power of two\");\n assert(n <= 1 << K, \"Fft.invFft: |xs| <= 2^K must hold\");\n for (int l = 1; l < n; l <<= 1) reverse(xs[l .. l << 1]);\n for (int l = 1; l < n; l <<= 1) {\n foreach (i; 0 .. (n >> 1) / l) {\n const(long) g = gs[i];\n foreach (j; (i << 1) * l .. (i << 1 | 1) * l) {\n int t = cast(int)((g * (xs[j] - xs[j + l])) % M);\n if (t < 0) t += M;\n if ((xs[j] += xs[j + l]) >= M) xs[j] -= M;\n xs[j + l] = t;\n }\n }\n }\n }\n T[] convolute(T)(inout(T)[] as, inout(T)[] bs) const if (isIntegral!T) {\n const na = cast(int)(as.length), nb = cast(int)(bs.length);\n int n, invN = 1;\n for (n = 1; n < na + nb - 1; n <<= 1) {\n invN = ((invN & 1) ? (invN + M) : invN) >> 1;\n }\n auto xs = new int[n], ys = new int[n];\n foreach (i; 0 .. na) if ((xs[i] = cast(int)(as[i] % M)) < 0) xs[i] += M;\n foreach (i; 0 .. nb) if ((ys[i] = cast(int)(bs[i] % M)) < 0) ys[i] += M;\n fft(xs);\n fft(ys);\n foreach (i; 0 .. n) {\n xs[i] = cast(int)((((cast(long)(xs[i]) * ys[i]) % M) * invN) % M);\n }\n invFft(xs);\n auto cs = new T[na + nb - 1];\n foreach (i; 0 .. na + nb - 1) cs[i] = cast(T)(xs[i]);\n return cs;\n }\n ModInt!M[] convolute(inout(ModInt!M)[] as, inout(ModInt!M)[] bs) const {\n const na = cast(int)(as.length), nb = cast(int)(bs.length);\n int n, invN = 1;\n for (n = 1; n < na + nb - 1; n <<= 1) {\n invN = ((invN & 1) ? (invN + M) : invN) >> 1;\n }\n auto xs = new int[n], ys = new int[n];\n foreach (i; 0 .. na) xs[i] = as[i].x;\n foreach (i; 0 .. nb) ys[i] = bs[i].x;\n fft(xs);\n fft(ys);\n foreach (i; 0 .. n) {\n xs[i] = cast(int)((((cast(long)(xs[i]) * ys[i]) % M) * invN) % M);\n }\n invFft(xs);\n auto cs = new ModInt!M[na + nb - 1];\n foreach (i; 0 .. na + nb - 1) cs[i].x = xs[i];\n return cs;\n }\n int[] convolute(int M1)(inout(ModInt!M1)[] as, inout(ModInt!M1)[] bs) const\n if (M != M1) {\n const na = cast(int)(as.length), nb = cast(int)(bs.length);\n int n, invN = 1;\n for (n = 1; n < na + nb - 1; n <<= 1) {\n invN = ((invN & 1) ? (invN + M) : invN) >> 1;\n }\n auto xs = new int[n], ys = new int[n];\n foreach (i; 0 .. na) xs[i] = as[i].x;\n foreach (i; 0 .. nb) ys[i] = bs[i].x;\n fft(xs);\n fft(ys);\n foreach (i; 0 .. n) {\n xs[i] = cast(int)((((cast(long)(xs[i]) * ys[i]) % M) * invN) % M);\n }\n invFft(xs);\n return xs[0 .. na + nb - 1];\n }\n}\n\nalias Fft0 = Fft!(998244353, 3, 20);\n\n\n/*\n Pr[large piece after m cuts]\n = 1 - \\prod_{m[1]+...+m[N]=m} m!/(m[1]!...m[N]!) \\prod_{i=1}^N (L[i]/L)^m[i] Pr[no large piece after m[i] cuts on the i-th chocolate]\n \n \\sum_{m>=0} (L[i]/L)^m Pr[no large piece after m cuts on the i-th chocolate] x^m/m!\n = \\sum_{m>=0} (L[i]/L)^m (\\sum_{j: L[i]-Kj>0} binom(m+1, j) (-1)^j ((L[i]-Kj)/L[i])^m) x^m/m!\n = \\sum_{j: L[i]-Kj>0} \\sum_m binom(m+1, j) (-1)^j (((L[i]-Kj)/L) x)^m / m!\n = \\sum_{m>=0} ((L[i]/L) x)^m / m! + \\sum_{j>=1: L[i]-Kj>0} (-1)^j/j! \\sum_{m>=j-1} (m+1)/((m-j+1)!) (((L[i]-Kj)/L) x)^m\n |\n | \\sum_{m>=j-1} (m+1)/((m-j+1)!) X^m\n | = \\sum_{m>=0} (m+j)/m! X^(m+j-1)\n | = \\sum_{m>=1} 1/(m-1)! X^(m+j-1) + j \\sum_{m>=0} (j/m!) X^(m+j-1)\n | = exp(X) (X^j + j X^(j-1))\n |\n = exp((L[i]/L) x) + (-1)^j/j! \\sum_{j>=1: L[i]-Kj>0} exp(((L[i]-Kj)/L) x) ((((L[i]-Kj)/L) x)^j + j (((L[i]-Kj)/L) x)^(j-1))\n |\n | y := exp(-(K/L) x) x\n | c[i] := (L[i]-Kj)/L\n |\n = exp((L[i]/L) x) (1 + \\sum_{j>=1: L[i]-Kj>0} (-1)^j/j! y^j (c[i]^j + j c[i]^(j-1) x^-1))\n \n \\sum_{m\\ge0} Pr[large piece after m cuts]\n = exp(x) - exp(x) \\prod_{i=1}^N (1 + \\sum_{j>=1: L[i]-Kj>0} (-1)^j/j! y^j (c[i]^j + j c[i]^(j-1) x^-1))\n*/\n\nFft0 FFT;\nMint[][] mul(Mint[][] fss, Mint[][] gss) {\n const mf = cast(int)(fss.length), nf = cast(int)(fss[0].length);\n const mg = cast(int)(gss.length), ng = cast(int)(gss[0].length);\n const m = mf + mg - 1, n = nf + ng - 1;\n auto fs = new Mint[m * n];\n auto gs = new Mint[m * n];\n foreach (i; 0 .. mf) foreach (j; 0 .. nf) fs[i * n + j] = fss[i][j];\n foreach (i; 0 .. mg) foreach (j; 0 .. ng) gs[i * n + j] = gss[i][j];\n const hs = FFT.convolute(fs, gs);\n auto hss = new Mint[][](m, n);\n foreach (i; 0 .. m) foreach (j; 0 .. n) hss[i][j] = hs[i * n + j];\n return hss;\n}\n\nvoid main() {\n prepare;\n FFT = new Fft0;\n \n try {\n for (; ; ) {\n const N = readInt();\n const K = readInt();\n auto L = new int[N];\n foreach (i; 0 .. N) {\n L[i] = readInt();\n }\n \n const LSum = L.sum;\n \n // rectangular\n auto fsss = new Mint[][][2 * N - 1];\n foreach (i; 0 .. N) {\n const jLim = (L[i] + K - 1) / K;\n fsss[i] = new Mint[][](jLim, 2);\n fsss[i][0][0] = 1;\n foreach (j; 1 .. jLim) {\n const c = Mint(L[i] - K * j) / Mint(LSum);\n fsss[i][j][0] = (-1)^^(j & 1) * invFac[j] * c^^j;\n fsss[i][j][1] = (-1)^^(j & 1) * invFac[j] * j * c^^(j - 1);\n }\n }\n foreach (i; N .. 2 * N - 1) {\n fsss[i] = mul(fsss[(i - N) << 1], fsss[(i - N) << 1 | 1]);\n }\n const fss = fsss[$ - 1];\n debug {\n if (LSum / K <= 20) {\n writeln(\"fss = \", fss);\n }\n }\n \n Mint ans;\n foreach (j; 1 .. cast(int)(fss.length)) {\n foreach (h; 0 .. cast(int)(fss[j].length)) {\n /*\n exp((1 - (K/L) j) x) x^(j-h)\n \n \\sum_m m! [x^m] exp(r x) x^a\n = \\sum_m (m+a)!/m! r^m\n = a! / (1 - r)^(a+1)\n */\n if (j - h >= 0) {\n const r = Mint(1) - Mint(K) / Mint(LSum) * Mint(j);\n const a = j - h;\n debug {\n if (LSum / K <= 20) {\n writeln(r, \" \", a, \": \", fss[j][h]);\n }\n }\n ans -= (fac[a] / (1 - r)^^(a + 1)) * fss[j][h];\n } else {\n assert(!fss[j][h]);\n }\n }\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "26d565c193a5920b042c783109496b4c"} {"nl": {"description": "You are given an integer $$$n$$$ from $$$1$$$ to $$$10^{18}$$$ without leading zeroes.In one move you can swap any two adjacent digits in the given number in such a way that the resulting number will not contain leading zeroes. In other words, after each move the number you have cannot contain any leading zeroes.What is the minimum number of moves you have to make to obtain a number that is divisible by $$$25$$$? Print -1 if it is impossible to obtain a number that is divisible by $$$25$$$.", "input_spec": "The first line contains an integer $$$n$$$ ($$$1 \\le n \\le 10^{18}$$$). It is guaranteed that the first (left) digit of the number $$$n$$$ is not a zero.", "output_spec": "If it is impossible to obtain a number that is divisible by $$$25$$$, print -1. Otherwise print the minimum number of moves required to obtain such number. Note that you can swap only adjacent digits in the given number.", "sample_inputs": ["5071", "705", "1241367"], "sample_outputs": ["4", "1", "-1"], "notes": "NoteIn the first example one of the possible sequences of moves is 5071 $$$\\rightarrow$$$ 5701 $$$\\rightarrow$$$ 7501 $$$\\rightarrow$$$ 7510 $$$\\rightarrow$$$ 7150."}, "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nvoid main() {\n immutable int INF = 1 << 29;\n\n auto S = readln.chomp;\n auto N = S.length.to!int;\n\n if (S == \"25\" || S == \"50\" || S == \"75\") {\n writeln(0);\n return;\n }\n\n if (S == \"52\" || S == \"57\") {\n writeln(1);\n return;\n }\n\n int[][] A = new int[][](10);\n foreach (i; 0..N) A[S[i]-'0'] ~= i;\n\n int minv = INF;\n\n int simple_swap(int i1, int i2) {\n return N - i1 - 1 + N - i2 - 2;\n }\n\n if (A[0].length >= 2) {\n minv = min(minv, simple_swap(A[0][$-1], A[0][$-2]));\n }\n\n int solve(int d1, int d2) {\n if (A[d1].length == 0 || A[d2].length == 0) {\n return INF;\n }\n\n int ret = 0;\n int a = A[d1].back;\n int b = A[d2].back;\n if (a > b) swap(a, b), ret += 1;\n\n if (a != 0) {\n ret += simple_swap(a, b);\n } else {\n int left_other = INF;\n foreach (i; 1..10) {\n if (A[i].length == 0) continue;\n if (i == d1 || i == d2) {\n if (A[i].length >= 2) {\n left_other = min(left_other, A[i].front);\n }\n } else {\n left_other = min(left_other, A[i].front);\n }\n }\n\n if (left_other != INF && left_other < b) {\n ret += left_other + simple_swap(a+1, b);\n } else if (left_other != INF && left_other > b) {\n ret += left_other + simple_swap(a+1, b+1);\n } else {\n ret = INF;\n }\n }\n\n return ret;\n }\n\n minv = min(minv, solve(2, 5));\n minv = min(minv, solve(5, 0));\n minv = min(minv, solve(7, 5));\n writeln(minv == INF ? -1 : minv);\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nvoid main() {\n immutable int INF = 1 << 29;\n\n auto S = readln.chomp;\n auto N = S.length.to!int;\n\n int[][] A = new int[][](10);\n foreach (i; 0..N) A[S[i]-'0'] ~= i;\n\n int minv = INF;\n\n int simple_swap(int i1, int i2) {\n return N - i1 - 1 + N - i2 - 2;\n }\n\n if (A[0].length >= 2) {\n minv = min(minv, simple_swap(A[0][$-1], A[0][$-2]));\n }\n\n int solve(int d1, int d2) {\n if (A[d1].length == 0 || A[d2].length == 0) {\n return INF;\n }\n\n int ret = 0;\n int a = A[d1].back;\n int b = A[d2].back;\n if (a > b) swap(a, b), ret += 1;\n\n if (a != 0) {\n ret += simple_swap(a, b);\n } else {\n int left_other = INF;\n foreach (i; 1..10) {\n if (A[i].length == 0) continue;\n if (i == d1 || i == d2) {\n if (A[i].length >= 2) {\n left_other = min(left_other, A[i].front);\n }\n } else {\n left_other = min(left_other, A[i].front);\n }\n }\n\n if (left_other != INF && left_other < b) {\n ret += left_other + simple_swap(a+1, b);\n } else if (left_other != INF && left_other > b) {\n ret += left_other + simple_swap(a+1, b+1);\n } else {\n ret = INF;\n }\n }\n\n return ret;\n }\n\n minv = min(minv, solve(2, 5));\n minv = min(minv, solve(5, 0));\n minv = min(minv, solve(7, 5));\n writeln(minv == INF ? -1 : minv);\n}\n"}, {"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, std.bitmanip;\n\nvoid main() {\n immutable int INF = 1 << 29;\n\n auto S = readln.chomp;\n auto N = S.length.to!int;\n\n if (S == \"25\" || S == \"50\" || S == \"75\") {\n writeln(0);\n return;\n }\n\n int[][] A = new int[][](10);\n foreach (i; 0..N) A[S[i]-'0'] ~= i;\n\n int minv = INF;\n\n int simple_swap(int i1, int i2) {\n return N - i1 - 1 + N - i2 - 2;\n }\n\n if (A[0].length >= 2) {\n minv = min(minv, simple_swap(A[0][$-1], A[0][$-2]));\n }\n\n int solve(int d1, int d2) {\n if (A[d1].length == 0 || A[d2].length == 0) {\n return INF;\n }\n\n int ret = 0;\n int a = A[d1].back;\n int b = A[d2].back;\n if (a > b) swap(a, b), ret += 1;\n\n if (a != 0) {\n ret += simple_swap(a, b);\n } else {\n int left_other = INF;\n foreach (i; 1..10) {\n if (A[i].length == 0) continue;\n if (i == d1 || i == d2) {\n if (A[i].length >= 2) {\n left_other = min(left_other, A[i].front);\n }\n } else {\n left_other = min(left_other, A[i].front);\n }\n }\n\n if (left_other != INF && left_other < b) {\n ret += left_other + simple_swap(a+1, b);\n } else if (left_other != INF && left_other > b) {\n ret += left_other + simple_swap(a+1, b+1);\n } else {\n ret = INF;\n }\n }\n\n return ret;\n }\n\n minv = min(minv, solve(2, 5));\n minv = min(minv, solve(5, 0));\n minv = min(minv, solve(7, 5));\n writeln(minv == INF ? -1 : minv);\n}\n"}], "src_uid": "ea1c737956f88be94107f2565ca8bbfd"} {"nl": {"description": "There are $$$n$$$ students in a university. The number of students is even. The $$$i$$$-th student has programming skill equal to $$$a_i$$$. The coach wants to form $$$\\frac{n}{2}$$$ teams. Each team should consist of exactly two students, and each student should belong to exactly one team. Two students can form a team only if their skills are equal (otherwise they cannot understand each other and cannot form a team).Students can solve problems to increase their skill. One solved problem increases the skill by one.The coach wants to know the minimum total number of problems students should solve to form exactly $$$\\frac{n}{2}$$$ teams (i.e. each pair of students should form a team). Your task is to find this number.", "input_spec": "The first line of the input contains one integer $$$n$$$ ($$$2 \\le n \\le 100$$$) \u2014 the number of students. It is guaranteed that $$$n$$$ is even. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \\dots, a_n$$$ ($$$1 \\le a_i \\le 100$$$), where $$$a_i$$$ is the skill of the $$$i$$$-th student.", "output_spec": "Print one number \u2014 the minimum total number of problems students should solve to form exactly $$$\\frac{n}{2}$$$ teams.", "sample_inputs": ["6\n5 10 2 3 14 5", "2\n1 100"], "sample_outputs": ["5", "99"], "notes": "NoteIn the first example the optimal teams will be: $$$(3, 4)$$$, $$$(1, 6)$$$ and $$$(2, 5)$$$, where numbers in brackets are indices of students. Then, to form the first team the third student should solve $$$1$$$ problem, to form the second team nobody needs to solve problems and to form the third team the second student should solve $$$4$$$ problems so the answer is $$$1 + 4 = 5$$$.In the second example the first student should solve $$$99$$$ problems to form a team with the second one."}, "positive_code": [{"source_code": "import std.stdio, std.array, std.string, std.conv, std.algorithm;\nimport std.typecons, std.range, std.random, std.math, std.container;\nimport std.numeric, std.bigint, core.bitop, core.stdc.string;\n\nvoid main() {\n auto N = readln.chomp.to!int;\n auto A = readln.split.map!(to!int).array;\n A.sort();\n iota(0, N, 2).map!(i => A[i+1] - A[i]).sum.writeln;\n}\n"}, {"source_code": "import std.stdio;\nimport std.algorithm;\nint main()\n{\n\tint t=0;\n\treadf(\" %d\", &t);\n\tint[] m = new int[t];\n\tfor (int i=0; i=0)\n\t\twriteln(\"YES\");\n\telse writeln(\"NO\");\n}\n"}], "src_uid": "b6456a39d38fabcd25267793ed94d90c"} {"nl": {"description": "Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At that as little as possible letters should be changed in the word. For example, the word HoUse must be replaced with house, and the word ViP \u2014 with VIP. If a word contains an equal number of uppercase and lowercase letters, you should replace all the letters with lowercase ones. For example, maTRIx should be replaced by matrix. Your task is to use the given method on one given word.", "input_spec": "The first line contains a word s \u2014 it consists of uppercase and lowercase Latin letters and possesses the length from 1 to 100.", "output_spec": "Print the corrected word s. If the given word s has strictly more uppercase letters, make the word written in the uppercase register, otherwise - in the lowercase one.", "sample_inputs": ["HoUse", "ViP", "maTRIx"], "sample_outputs": ["house", "VIP", "matrix"], "notes": null}, "positive_code": [{"source_code": "module main;\nimport std.bigint,std.container,std.array,std.algorithm,std.conv,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.variant,\n\tstd.stdio,std.bitmanip;\nimport core.stdc.stdio : freopen;\nalias RedBlackTree Rbt;\nalias redBlackTree rbt;\nalias BigInt big;\nalias pair!(int,int) pii;\nalias pair!(long,long) pll;\nalias boyerMooreFinder strfind;\nalias make_pair mp;\nalias binary_search bins;\nalias pair(X,Y)=Tuple!(X,q{fi},Y,q{se});\npair!(X,Y) make_pair(X,Y)(in X x_,in Y y_)\n{\n\tpair!(X,Y) pp;\n\tpp.fi=x_;\n\tpp.se=y_;\n\treturn pp;\n}\nimmutable int mod=10^^9+7;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b)\n\t{\n\t\treturn a/gcd(a,b)*b;\n\t}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tsize_t lowb(T,X)(in T a,auto ref X g) \n\t\tif(isRandomAccessRange!T && hasLength!T && is(typeof(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m]1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 0)\n{return readf(replicate(\" %s\", ptrs.length), ptrs)==ptrs.length;}\nbool read(T...)(T ptrs) if (ptrs.length > 0)\n{return readf(replicate(\" %s\", ptrs.length)~'\\n', ptrs)==ptrs.length;}\nnothrow void inf(in char* name) {freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow void ouf(in char* name) {freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold schwartzSort multiSort partialSort heapify join filter countUntil\n//---------------------------------------------------------------program beginning-----------------------------------------------------------------\n\nvoid main()\n{\n\t/*int n;\n\tloop:while(read(&n))\n\t{\n\n\t}*/\n\tauto s=readln.strip;\n\tif(s.count!isUpper>s.count!isLower)\n\t{\n\t\tforeach(c;s)write(toUpper(c));\n\t}\n\telse foreach(c;s)write(toLower(c));\n}"}, {"source_code": "import std.stdio;\nimport core.stdc.stdio;\nimport std.algorithm;\nimport std.string;\nimport std.math;\n\nint main(string[] argv)\n{\n\tstring line = readln();\n\tif (line[$-1] == '\\n') line.length--;\n\tstring upper = toUpper(line);\n\tstring lower = toLower(line);\n\tint diffu, diffl;\n\tforeach (int i; 0..line.length)\n\t{\n\t\tdiffu += abs(line[i] - upper[i]);\n\t\tdiffl += abs(line[i] - lower[i]);\n\t}\n\twrite (diffu >= diffl ? lower : upper);\n\treturn 0;\n}\n"}, {"source_code": "//ahmat\nimport core.stdc.stdio:scanf,printf,puts;\nimport core.bitop;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.functional;\nimport std.array;\nimport std.container;\nimport std.conv;\nimport std.container;\nimport std.typecons;\nimport std.math;\nimport std.numeric;\npragma(inline,true);\n\nvoid main(){\n char[] s=readln.strip.to!(char[]);\n int n=0;\n foreach(ref x;s){\n if(x.to!int<97) n++;\n }\n if(2*n>s.length)\n s.toUpper.writeln;\n else \n s.toLower.writeln;\n}\n\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport core.stdc.stdio;\nimport std.algorithm;\nimport std.string;\nimport std.math;\n\nint main(string[] argv)\n{\n\tstring line = readln();\n\tif (line[$-1] == '\\n') line.length--;\n\tstring upper = toUpper(line);\n\tstring lower = toLower(line);\n\tint diffu, diffl;\n\tforeach (int i; 0..line.length)\n\t{\n\t\tdiffu += abs(line[i] - upper[i]);\n\t\tdiffl += abs(line[i] - lower[i]);\n\t}\n\twrite (diffu > diffl ? lower : upper);\n\treturn 0;\n}\n"}], "src_uid": "b432dfa66bae2b542342f0b42c0a2598"} {"nl": {"description": "The football season has just ended in Berland. According to the rules of Berland football, each match is played between two teams. The result of each match is either a draw, or a victory of one of the playing teams. If a team wins the match, it gets $$$w$$$ points, and the opposing team gets $$$0$$$ points. If the game results in a draw, both teams get $$$d$$$ points.The manager of the Berland capital team wants to summarize the results of the season, but, unfortunately, all information about the results of each match is lost. The manager only knows that the team has played $$$n$$$ games and got $$$p$$$ points for them.You have to determine three integers $$$x$$$, $$$y$$$ and $$$z$$$ \u2014 the number of wins, draws and loses of the team. If there are multiple answers, print any of them. If there is no suitable triple $$$(x, y, z)$$$, report about it.", "input_spec": "The first line contains four integers $$$n$$$, $$$p$$$, $$$w$$$ and $$$d$$$ $$$(1 \\le n \\le 10^{12}, 0 \\le p \\le 10^{17}, 1 \\le d < w \\le 10^{5})$$$ \u2014 the number of games, the number of points the team got, the number of points awarded for winning a match, and the number of points awarded for a draw, respectively. Note that $$$w > d$$$, so the number of points awarded for winning is strictly greater than the number of points awarded for draw.", "output_spec": "If there is no answer, print $$$-1$$$. Otherwise print three non-negative integers $$$x$$$, $$$y$$$ and $$$z$$$ \u2014 the number of wins, draws and losses of the team. If there are multiple possible triples $$$(x, y, z)$$$, print any of them. The numbers should meet the following conditions: $$$x \\cdot w + y \\cdot d = p$$$, $$$x + y + z = n$$$. ", "sample_inputs": ["30 60 3 1", "10 51 5 4", "20 0 15 5"], "sample_outputs": ["17 9 4", "-1", "0 0 20"], "notes": "NoteOne of the possible answers in the first example \u2014 $$$17$$$ wins, $$$9$$$ draws and $$$4$$$ losses. Then the team got $$$17 \\cdot 3 + 9 \\cdot 1 = 60$$$ points in $$$17 + 9 + 4 = 30$$$ games.In the second example the maximum possible score is $$$10 \\cdot 5 = 50$$$. Since $$$p = 51$$$, there is no answer.In the third example the team got $$$0$$$ points, so all $$$20$$$ games were lost."}, "positive_code": [{"source_code": "import std.algorithm;\nimport std.range;\nimport std.stdio;\nimport std.typecons;\nimport std.traits;\nimport std.array;\nvoid read(T...)(ref T args)\n{\n import std.traits;\n static foreach(i; 0 .. T.length)\n static if(isArray!(T[i]) && !is(T[i] == string))\n foreach(ref e; args[i])\n \tread(e);\n else static if(isTuple!(T[i]))\n {\n\tstatic foreach(n; 0 .. T[i].Types.length)\n\t {\n\t read(args[i][n]);\n\t }\n }\n else\n readf!\" %s \"(args[i]);\n}\nauto brange(alias low, alias high, alias pred, bool value)()\n{\n return iota(low, high + 1).map!((a) => cast(int) pred(a)).assumeSorted.equalRange(value);\n}\nauto ftrue(alias low, alias high, alias pred)()\n{\n return brange!(low, high, pred, false).length + low;\n}\nauto itup(alias k, alias F)()\n{\n alias T = Parameters!F;\n foreach(i; 0 .. k)\n {\n T t;\n get(t);\n F(t);\n }\n}\nalias get = read;\nvoid wone(T)(T t, char end)\n{\n static if(isArray!T && !is(T == string))\n {\n foreach(i; 0 .. t.length - 1)\n\t write(t[i], ' ');\n write(t[$ - 1], end);\n }\n else\n write(t, end);\n}\nvoid wr(T...)(T t)\n{\n static foreach(i; 0 .. T.length)\n static if(i + 1 < T.length)\n wone(t[i], ' ');\n else\n wone(t[i], '\\n');\n}\nvoid ans(T...)(T t)\n{\n import core.stdc.stdlib;\n wr(t);\n exit(0);\n}\nstruct ModNum(T)\n{\n T representative, modulus;\n this(T representative, T modulus)\n {\n this.representative = representative;\n this.modulus = modulus;\n }\n T minimalPositiveRepresentative()\n {\n return ((representative % modulus) + modulus) % modulus;\n }\n T minimalNegativeRepresentative()\n {\n return ((representative % modulus) - modulus) % modulus;\n }\n T maxRepresentative(T upperBound)\n {\n return upperBound - pmod(upperBound - representative, modulus);\n }\n}\n// minimum possible representative of x modulo m.\nT pmod(T)(T x, T m)\n{\n return (x % m + m) % m;\n}\n// solves ax + by = gcd(a, b) and returns gcd(a, b)\nT extendedEuclideanAlgorithm(T)(T a, T b, out T x, out T y)\n{\n if (a == 0)\n {\n x = 0, y = 1;\n return b;\n }\n T x1, y1;\n auto d = egcd(b % a, a, x1, y1);\n x = y1 - (b / a) * x1, y = x1;\n return d;\n}\nalias egcd = extendedEuclideanAlgorithm;\n// solves ax = b (mod m) giving a solution as a modulus class.\nbool solveLinearCongruence(T)(T a, T b, T m, out ModNum!T res)\n{\n T x, p;\n b = pmod(b, m);\n T y;\n T g = egcd(a, m, x, y);\n if (b % g != 0)\n return false;\n p = m / g;\n x = pmod(x * b / g, p);\n res.representative = x;\n res.modulus = p;\n return true;\n}\nvoid main()\n{\n alias solve = solveLinearCongruence;\n alias ln = long;\n ln n, p, w, d; get(n, p, w, d);\n auto h = w - d;\n ModNum!ln np;\n if (solve(w, p, h, np))\n {\n ln maxNp = np.maxRepresentative(/*upper bound*/ min(n, p / d));\n ln z = n - maxNp;\n ln y = (w * maxNp - p) / h;\n ln x = maxNp - y;\n if (y >= 0 && x >= 0 && z >= 0)\n\t ans(x, y, z);\n }\n ans(-1);\n}\n"}, {"source_code": "import std.algorithm;\nimport std.range;\nimport std.stdio;\nimport std.typecons;\nimport std.traits;\nimport std.array;\nvoid read(T...)(ref T args)\n{\n import std.traits;\n static foreach(i; 0 .. T.length)\n static if(isArray!(T[i]) && !is(T[i] == string))\n foreach(ref e; args[i])\n \tread(e);\n else static if(isTuple!(T[i]))\n {\n\tstatic foreach(n; 0 .. T[i].Types.length)\n\t {\n\t read(args[i][n]);\n\t }\n }\n else\n readf!\" %s \"(args[i]);\n}\nauto brange(alias low, alias high, alias pred, bool value)()\n{\n return iota(low, high + 1).map!((a) => cast(int) pred(a)).assumeSorted.equalRange(value);\n}\nauto ftrue(alias low, alias high, alias pred)()\n{\n return brange!(low, high, pred, false).length + low;\n}\nauto itup(alias k, alias F)()\n{\n alias T = Parameters!F;\n foreach(i; 0 .. k)\n {\n T t;\n get(t);\n F(t);\n }\n}\nalias get = read;\nalias wr = writeln;\n\nT egcd(T)(T a, T b, out T x, out T y)\n{\n if (a == 0) {\n x = 0;\n y = 1;\n return b;\n }\n T x1, y1;\n auto d = egcd(b % a, a, x1, y1);\n x = y1 - (b / a) * x1;\n y = x1;\n return d;\n}\n\nvoid solve(ln a, ln b, ln m, out ln x, out ln p, out bool hassol)\n{\n b %= m;\n ln y = 0;\n ln g = egcd(a, m, x, y);\n if (b % g != 0)\n {\n hassol = false;\n return;\n }\n hassol = true;\n x *= b / g;\n p = m / g;\n x %= p;\n x += p;\n x %= p;\n return;\n}\n\nalias ln = long;\n\nint main()\n{\n ln n, p, w, d; get(n, p, w, d);\n auto h = w - d;\n ln np;\n ln period;\n bool hassol;\n solve(w, p, h, np, period, hassol);\n if (hassol)\n {\n ln top = min(n, p / d);\n ln delta = top - np;\n np += (delta / period) * period;\n ln z = n - np;\n ln y = (w * np - p) / h;\n ln x = np - y;\n if (y >= 0 && x >= 0 && z >= 0)\n\t{\n\t wr(x, \" \", y, \" \", z);\n\t}\n else\n\t{\n\t wr(-1);\n\t}\n }\n else\n {\n wr(-1);\n }\n return 0;\n}\n"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nT[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto n = RD;\n\tauto p = RD;\n\tauto w = RD!int;\n\tauto d = RD!int;\n\n\tauto r = p % w;\n\tauto used = new bool[](10^^5);\n\tint a;\n\tint cnt = -1;\n\tforeach (i; 0..10^^5)\n\t{\n\t\tif (a == r)\n\t\t{\n\t\t\tcnt = i;\n\t\t\tbreak;\n\t\t}\n\t\telse if (used[a] == true)\n\t\t\tbreak;\n\t\tused[a] = true;\n\n\t\ta += d;\n\t\ta %= w;\n\t}\n\n\tif (cnt == -1)\n\t\twriteln(-1);\n\telse\n\t{\n\t\tauto y = cast(long)cnt;\n\t\tauto x = (p - y*d) / w;\n\t\tauto z = n - x - y;\n\t\tif (x < 0 || z < 0)\n\t\t\twriteln(-1);\n\t\telse\n\t\t\twriteln(x, \" \", y, \" \", z);\n\t}\n\n\tstdout.flush();\n\tdebug readln();\n}"}], "negative_code": [{"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nT[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto n = RD;\n\tauto p = RD;\n\tauto w = RD!int;\n\tauto d = RD!int;\n\n\tauto r = p % w;\n\tauto used = new bool[](10^^5);\n\tint a;\n\tint cnt = -1;\n\tforeach (i; 0..10^^5)\n\t{\n\t\tif (a == r)\n\t\t{\n\t\t\tcnt = i;\n\t\t\tbreak;\n\t\t}\n\t\telse if (used[a] == true)\n\t\t\tbreak;\n\t\tused[a] = true;\n\n\t\ta += d;\n\t\ta %= w;\n\t}\n\n\tif (cnt == -1)\n\t\twriteln(-1);\n\telse\n\t{\n\t\tauto y = cast(long)cnt;\n\t\tauto x = (p - y*d) / w;\n\t\tauto z = n - x - y;\n\t\tif (z < 0)\n\t\t\twriteln(-1);\n\t\telse\n\t\t\twriteln(x, \" \", y, \" \", z);\n\t}\n\n\tstdout.flush();\n\tdebug readln();\n}"}, {"source_code": "import std.stdio, std.conv, std.functional, std.string;\nimport std.algorithm, std.array, std.container, std.range, std.typecons;\nimport std.numeric, std.math, std.random;\nimport core.bitop;\n\nstring FMT_F = \"%.10f\";\n\nstatic string[] s_rd;\nT RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }\nstring RDR()() { return readln.chomp; }\nT[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }\nT[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }\nT[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }\nsize_t[] MAKE_IDX(alias less = \"a < b\", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}\nsize_t MIN_POS(alias less = \"a < b\", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }\n\nbool inside(T)(T x, T b, T e) { return x >= b && x < e; }\nlong lcm(long x, long y) { return x * (y / gcd(x, y)); }\n\nlong mod = 10^^9 + 7;\n//long mod = 998_244_353;\n//long mod = 1_000_003;\nvoid moda(ref long x, long y) { x = (x + y) % mod; }\nvoid mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }\nvoid modm(ref long x, long y) { x = (x * y) % mod; }\n\nvoid main()\n{\n\tauto n = RD;\n\tauto p = RD;\n\tauto w = RD!int;\n\tauto d = RD!int;\n\n\tauto r = p % w;\n\tauto used = new bool[](10^^5);\n\tint a;\n\tint cnt = -1;\n\tforeach (i; 0..10^^5)\n\t{\n\t\tif (a == r)\n\t\t{\n\t\t\tcnt = i;\n\t\t\tbreak;\n\t\t}\n\t\telse if (used[a] == true)\n\t\t\tbreak;\n\t\tused[a] = true;\n\n\t\ta += d;\n\t\ta %= w;\n\t}\n\n\tif (cnt == -1)\n\t\twriteln(-1);\n\telse\n\t{\n\t\tauto y = cnt;\n\t\tauto x = (p - y*d) / w;\n\t\tauto z = n - x - y;\n\t\tif (z < 0)\n\t\t\twriteln(-1);\n\t\telse\n\t\t\twriteln(x, \" \", y, \" \", z);\n\t}\n\n\tstdout.flush();\n\tdebug readln();\n}"}], "src_uid": "503116e144d19eb953954d99c5526a7d"} {"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}$$$)\u00a0\u2014 the constraints on the screen width and height, and on the aspect ratio.", "output_spec": "Print one integer\u00a0\u2014 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": "void main(){\n import std.stdio, std.string, std.conv, std.algorithm;\n import std.numeric;\n\n long a, b, x, y; rd(a, b, x, y);\n\n auto g=gcd(x, y);\n x/=g; y/=g;\n writeln(min(a/x, b/y));\n}\n\nvoid rd(T...)(ref T x){\n import std.stdio, std.string, std.conv;\n auto l=readln.split;\n assert(l.length==x.length);\n foreach(i, ref e; x) e=l[i].to!(typeof(e));\n}\n"}], "negative_code": [], "src_uid": "907ac56260e84dbb6d98a271bcb2d62d"} {"nl": {"description": "One day Vasya the Hipster decided to count how many socks he had. It turned out that he had a red socks and b blue socks.According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot.Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them.Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got.Can you help him?", "input_spec": "The single line of the input contains two positive integers a and b (1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u2009100) \u2014 the number of red and blue socks that Vasya's got.", "output_spec": "Print two space-separated integers \u2014 the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day.", "sample_inputs": ["3 1", "2 3", "7 3"], "sample_outputs": ["1 1", "2 0", "3 2"], "notes": "NoteIn the first sample Vasya can first put on one pair of different socks, after that he has two red socks left to wear on the second day."}, "positive_code": [{"source_code": "import std.stdio,\n\tstd.algorithm;\n\nvoid main() {\n\tint a, b;\n\treadf!` %s %s`(a, b);\n\twriteln(min(a, b), ' ', (max(a, b) - min(a, b)) / 2);\n}\n"}, {"source_code": "import std.stdio;\n\nint main(string[] argv)\n{\n\tint a, b;\n\treadf(\"%d %d\", &a, &b);\n\tif (a < b) { int t = a; a = b; b = t; }\n\tint t = a - b;\n\twrite(b, \" \", t / 2);\n\treturn 0;\n}"}, {"source_code": "import std.stdio;\nint min(int a, int b)\n{\n\tif (ab)\n\t{\n\t\treturn a;\n\t}\n\telse\n\t{\n\t\treturn b;\n\t}\n}\nint main()\n{\n\tint a=0;\n\tint b=0;\n\treadf(\" %d\", &a);\n\treadf(\" %d\", &b);\n\twriteln(min(a,b));\n\tint c=a-min(a,b);\n\tint d=b-min(a,b);\n\tint e=max(c,d);\n\twriteln(e/2);\n\treturn 0;\n}"}], "negative_code": [], "src_uid": "775766790e91e539c1cfaa5030e5b955"} {"nl": {"description": "Makoto has a big blackboard with a positive integer $$$n$$$ written on it. He will perform the following action exactly $$$k$$$ times:Suppose the number currently written on the blackboard is $$$v$$$. He will randomly pick one of the divisors of $$$v$$$ (possibly $$$1$$$ and $$$v$$$) and replace $$$v$$$ with this divisor. As Makoto uses his famous random number generator (RNG) and as he always uses $$$58$$$ as his generator seed, each divisor is guaranteed to be chosen with equal probability.He now wonders what is the expected value of the number written on the blackboard after $$$k$$$ steps.It can be shown that this value can be represented as $$$\\frac{P}{Q}$$$ where $$$P$$$ and $$$Q$$$ are coprime integers and $$$Q \\not\\equiv 0 \\pmod{10^9+7}$$$. Print the value of $$$P \\cdot Q^{-1}$$$ modulo $$$10^9+7$$$.", "input_spec": "The only line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \\leq n \\leq 10^{15}$$$, $$$1 \\leq k \\leq 10^4$$$).", "output_spec": "Print a single integer \u2014 the expected value of the number on the blackboard after $$$k$$$ steps as $$$P \\cdot Q^{-1} \\pmod{10^9+7}$$$ for $$$P$$$, $$$Q$$$ defined above.", "sample_inputs": ["6 1", "6 2", "60 5"], "sample_outputs": ["3", "875000008", "237178099"], "notes": "NoteIn the first example, after one step, the number written on the blackboard is $$$1$$$, $$$2$$$, $$$3$$$ or $$$6$$$ \u2014 each occurring with equal probability. Hence, the answer is $$$\\frac{1+2+3+6}{4}=3$$$.In the second example, the answer is equal to $$$1 \\cdot \\frac{9}{16}+2 \\cdot \\frac{3}{16}+3 \\cdot \\frac{3}{16}+6 \\cdot \\frac{1}{16}=\\frac{15}{8}$$$."}, "positive_code": [{"source_code": "import std.algorithm;\nimport std.conv;\nimport std.range;\nimport std.stdio;\nimport std.string;\n\nimmutable int mod = 10 ^^ 9 + 7;\nimmutable int small = 100;\n\nint powMod (int a, int b)\n{\n\tint res = 1;\n\twhile (b > 0)\n\t{\n\t\tif (b & 1)\n\t\t{\n\t\t\tres = (res * 1L * a) % mod;\n\t\t}\n\t\ta = (a * 1L * a) % mod;\n\t\tb >>= 1;\n\t}\n\treturn res;\n}\n\nint invMod (int a)\n{\n\treturn powMod (a, mod - 2);\n}\n\nvoid main ()\n{\n\tlong n;\n\tint k;\n\twhile (readf (\" %s %s\", &n, &k) > 0)\n\t{\n\t\tint [] primes;\n\t\tint [] powers;\n\t\tint [] [] prob;\n\t\tint total = 0;\n\t\tfor (int d = 2; d * 1L * d <= n; d++)\n\t\t{\n\t\t\tif (n % d == 0)\n\t\t\t{\n\t\t\t\tint num = 0;\n\t\t\t\tdo\n\t\t\t\t{\n\t\t\t\t\tn /= d;\n\t\t\t\t\tnum += 1;\n\t\t\t\t}\n\t\t\t\twhile (n % d == 0);\n\t\t\t\tprimes ~= d;\n\t\t\t\tpowers ~= num;\n\t\t\t\ttotal += 1;\n\t\t\t}\n\t\t}\n\t\tif (n > 1)\n\t\t{\n\t\t\tprimes ~= n % mod;\n\t\t\tpowers ~= 1;\n\t\t\ttotal += 1;\n\t\t}\n\n\t\tauto inv = new int [small];\n\t\tforeach (i; 1..small)\n\t\t{\n\t\t\tinv[i] = invMod (i);\n\t\t}\n\n\t\tforeach (i; 0..total)\n\t\t{\n\t\t\tint limit = powers[i];\n\t\t\tauto f = new int [] [] (2, limit + 1);\n\t\t\tint b = 0;\n\t\t\tf[b][] = 0;\n\t\t\tf[b][limit] = 1;\n\t\t\tforeach (j; 0..k)\n\t\t\t{\n\t\t\t\tb ^= 1;\n\t\t\t\tf[b][] = 0;\n\t\t\t\tforeach (u; 0..limit + 1)\n\t\t\t\t{\n\t\t\t\t\tforeach (v; 0..u + 1)\n\t\t\t\t\t{\n\t\t\t\t\t\tf[b][v] = (f[b][v] +\n\t\t\t\t\t\t f[!b][u] * 1L *\n\t\t\t\t\t\t inv[u + 1]) % mod;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tdebug {writeln (primes[i], \": \", f[b]);}\n\t\t\tprob ~= f[b];\n\t\t}\n\n\t\tint res = 0;\n\n\t\tvoid recur (int i, int cur)\n\t\t{\n\t\t\tdebug {writeln (\"recur \", i, \" \", cur);}\n\t\t\tif (i == total)\n\t\t\t{\n\t\t\t\tres = (res + cur) % mod;\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tint temp = cur;\n\t\t\tforeach (u; 0..powers[i] + 1)\n\t\t\t{\n\t\t\t\trecur (i + 1, (temp * 1L * prob[i][u]) % mod);\n\t\t\t\ttemp = (temp * 1L * primes[i]) % mod;\n\t\t\t}\n\t\t}\n\n\t\trecur (0, 1);\n\t\twriteln (res);\n\t}\n}\n"}, {"source_code": "import std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex, std.typecons;\nimport core.bitop, core.thread;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) throw new EOFException; tokens = readln.split; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return readToken().to!int; }\nlong readLong() { return readToken().to!long; }\nreal readReal() { return readToken().to!real; }\n\nvoid chmin(T)(ref T t, in T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, in T f) { if (t < f) t = f; }\n\nint binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = cast(int)(as.length); for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a < val)); }\nint upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a <= val)); }\n\n\nimmutable MO = 10L^^9 + 7;\nimmutable LIM = 10^^5 + 10;\n\nlong[] inv;\nvoid prepare() {\n inv = new long[LIM];\n inv[1] = 1;\n foreach (i; 2 .. LIM) {\n inv[i] = MO - (MO / i) * inv[cast(size_t)(MO % i)] % MO;\n }\n}\n\nlong N;\nint K;\n\nvoid main() {\n prepare();\n \n try {\n for (; ; ) {\n N = readLong();\n K = readInt();\n Tuple!(long, int)[] ps;\n long n = N;\n for (long d = 2; d * d <= n; ++d) {\n if (n % d == 0) {\n int e;\n do {\n ++e;\n n /= d;\n } while (n % d == 0);\n ps ~= tuple(d, e);\n }\n }\n if (n > 1) {\n ps ~= tuple(n, 1);\n }\n debug {\n writeln(\"ps = \", ps);\n }\n long ans = 1;\n foreach (entry; ps) {\n const p = entry[0];\n const e = entry[1];\n auto dp = new long[][](K + 1, e + 1);\n dp[0][0] = 1;\n foreach (i; 1 .. e + 1) {\n dp[0][i] = (dp[0][i - 1] * p) % MO;\n }\n foreach (k; 1 .. K + 1) {\n long sum;\n foreach (i; 0 .. e + 1) {\n (sum += dp[k - 1][i]) %= MO;\n dp[k][i] = (sum * inv[i + 1]) % MO;\n }\n }\n (ans *= dp[K][e]) %= MO;\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [{"source_code": "import std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex, std.typecons;\nimport core.bitop, core.thread;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) throw new EOFException; tokens = readln.split; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return readToken().to!int; }\nlong readLong() { return readToken().to!long; }\nreal readReal() { return readToken().to!real; }\n\nvoid chmin(T)(ref T t, in T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, in T f) { if (t < f) t = f; }\n\nint binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = cast(int)(as.length); for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a < val)); }\nint upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a <= val)); }\n\n\nimmutable MO = 10L^^9 + 7;\nimmutable LIM = 10^^5 + 10;\n\nlong[] inv;\nvoid prepare() {\n inv = new long[LIM];\n inv[1] = 1;\n foreach (i; 2 .. LIM) {\n inv[i] = MO - (MO / i) * inv[cast(size_t)(MO % i)] % MO;\n }\n}\n\nlong N;\nint K;\n\nvoid main() {\n prepare();\n \n try {\n for (; ; ) {\n N = readLong();\n K = readInt();\n Tuple!(long, int)[] ps;\n long n = N;\n for (long d = 2; d * d <= n; ++d) {\n int e;\n do {\n ++e;\n n /= d;\n } while (n % d == 0);\n ps ~= tuple(d, e);\n }\n if (n > 1) {\n ps ~= tuple(n, 1);\n }\n debug {\n writeln(\"ps = \", ps);\n }\n long ans = 1;\n foreach (entry; ps) {\n const p = entry[0];\n const e = entry[1];\n auto dp = new long[][](K + 1, e + 1);\n dp[0][0] = 1;\n foreach (i; 1 .. e + 1) {\n dp[0][i] = (dp[0][i - 1] * p) % MO;\n }\n foreach (k; 1 .. K + 1) {\n long sum;\n foreach (i; 0 .. e + 1) {\n (sum += dp[k - 1][i]) %= MO;\n dp[k][i] = (sum * inv[i + 1]) % MO;\n }\n }\n (ans *= dp[K][e]) %= MO;\n }\n writeln(ans);\n }\n } catch (EOFException e) {\n }\n}\n"}], "src_uid": "dc466d9c24b7dcb37c0e99337b4124d2"} {"nl": {"description": "There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name \"snookah\")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back.Jinotega's best friends, team Base have found a list of their itinerary receipts with information about departure and arrival airports. Now they wonder, where is Jinotega now: at home or at some competition far away? They know that: this list contains all Jinotega's flights in this year (in arbitrary order), Jinotega has only flown from his hometown to a snooker contest and back, after each competition Jinotega flies back home (though they may attend a competition in one place several times), and finally, at the beginning of the year Jinotega was at home. Please help them to determine Jinotega's location!", "input_spec": "In the first line of input there is a single integer n: the number of Jinotega's flights (1\u2009\u2264\u2009n\u2009\u2264\u2009100). In the second line there is a string of 3 capital Latin letters: the name of Jinotega's home airport. In the next n lines there is flight information, one flight per line, in form \"XXX->YYY\", where \"XXX\" is the name of departure airport \"YYY\" is the name of arrival airport. Exactly one of these airports is Jinotega's home airport. It is guaranteed that flights information is consistent with the knowledge of Jinotega's friends, which is described in the main part of the statement.", "output_spec": "If Jinotega is now at home, print \"home\" (without quotes), otherwise print \"contest\".", "sample_inputs": ["4\nSVO\nSVO->CDG\nLHR->SVO\nSVO->LHR\nCDG->SVO", "3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP"], "sample_outputs": ["home", "contest"], "notes": "NoteIn the first sample Jinotega might first fly from SVO to CDG and back, and then from SVO to LHR and back, so now they should be at home. In the second sample Jinotega must now be at RAP because a flight from RAP back to SVO is not on the list."}, "positive_code": [{"source_code": "import std.conv, std.functional, std.range, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;\nimport core.bitop;\n\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }\nint readInt() { return readToken.to!int; }\nlong readLong() { return readToken.to!long; }\nreal readReal() { return readToken.to!real; }\n\nbool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }\nbool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }\n\nint binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }\nint lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }\nint upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }\n\n\n\n\nvoid main() {\n try {\n for (; ; ) {\n const N = readInt();\n readToken();\n foreach (_; 0 .. N) {\n readToken();\n }\n \n writeln((N % 2 != 0) ? \"contest\" : \"home\");\n }\n } catch (EOFException e) {\n }\n}\n"}], "negative_code": [], "src_uid": "51d1c79a52d3d4f80c98052b6ec77222"} {"nl": {"description": "Calvin the robot lies in an infinite rectangular grid. Calvin's source code contains a list of n commands, each either 'U', 'R', 'D', or 'L'\u00a0\u2014 instructions to move a single square up, right, down, or left, respectively. How many ways can Calvin execute a non-empty contiguous substrings of commands and return to the same square he starts in? Two substrings are considered different if they have different starting or ending indices.", "input_spec": "The first line of the input contains a single positive integer, n (1\u2009\u2264\u2009n\u2009\u2264\u2009200)\u00a0\u2014 the number of commands. The next line contains n characters, each either 'U', 'R', 'D', or 'L'\u00a0\u2014 Calvin's source code.", "output_spec": "Print a single integer\u00a0\u2014 the number of contiguous substrings that Calvin can execute and return to his starting square.", "sample_inputs": ["6\nURLLDR", "4\nDLUU", "7\nRLRLRLR"], "sample_outputs": ["2", "0", "12"], "notes": "NoteIn the first case, the entire source code works, as well as the \"RL\" substring in the second and third characters.Note that, in the third case, the substring \"LR\" appears three times, and is therefore counted three times to the total result."}, "positive_code": [{"source_code": "import std.stdio;\n\nvoid main()\n{\n\tint n;\n\tint res = 0;\n\tchar[200 + 1] s;\n\t\n\tscanf(\"%d%s\", &n, &s[0]);\n\tfor (int i = 0; i < n; i++) {\n\t\tint vertical = 0;\n\t\tint horizontal = 0;\n\t\tfor (int j = i; j < n; j++) {\n\t\t\tif (s[j] == 'U')\n\t\t\t\tvertical--;\n\t\t\tif (s[j] == 'D')\n\t\t\t\tvertical++;\n\t\t\tif (s[j] == 'L')\n\t\t\t\thorizontal--;\n\t\t\tif (s[j] == 'R')\n\t\t\t\thorizontal++;\n\t\t\t\n\t\t\tif (vertical == 0 && horizontal == 0)\n\t\t\t\tres++;\n\t\t}\n\t}\n\t\n\tprintf(\"%d\\n\", res);\n}\n"}, {"source_code": "import std.stdio;\nimport std.string;\n\nimmutable int[] dx = [-1, 0, 1, 0];\nimmutable int[] dy = [0, -1, 0, 1];\nimmutable string dir = \"LURD\";\n\nvoid main() {\n int n;\n readf(\" %s\", &n);\n readln;\n auto s = readln.strip;\n int ans = 0;\n foreach (i; 0..n) {\n foreach (j; i..n) {\n int x = 0;\n int y = 0;\n foreach (k; i..j + 1) {\n x += dx[dir.indexOf(s[k])];\n y += dy[dir.indexOf(s[k])];\n }\n if (x == 0 && y == 0) {\n ans++;\n }\n }\n }\n writeln(ans);\n}\n\n"}, {"source_code": "import std.algorithm, std.stdio, std.range, std.string;\n\nauto f (string t)\n{\n\treturn t.count ('U') == t.count ('D') &&\n\t\tt.count ('L') == t.count ('R');\n}\n\nvoid main ()\n{\n\treadln;\n\tauto s = readln.strip;\n\ts.length.iota.map !(x =>\n\t\tx.iota.map !(y =>\n\t\t\tf (s[y..x + 1])\n\t\t).sum\n\t).sum.writeln;\n}\n"}, {"source_code": "import std.algorithm;\nimport std.stdio;\nimport std.string;\n\nvoid main ()\n{\n\tint n;\n\twhile (readf (\" %s\", &n) > 0)\n\t{\n\t\treadln;\n\t\tauto s = readln.strip;\n\t\tint res = 0;\n\t\tforeach (i; 0..n)\n\t\t{\n\t\t\tforeach (j; i..n)\n\t\t\t{\n\t\t\t\tauto t = s[i..j + 1];\n\t\t\t\tif (t.count ('U') == t.count ('D') &&\n\t\t\t\t t.count ('L') == t.count ('R'))\n\t\t\t\t{\n\t\t\t\t\tres++;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\twriteln (res);\n\t}\n}\n"}], "negative_code": [], "src_uid": "7bd5521531950e2de9a7b0904353184d"} {"nl": {"description": "Polycarp knows that if the sum of the digits of a number is divisible by $$$3$$$, then the number itself is divisible by $$$3$$$. He assumes that the numbers, the sum of the digits of which is divisible by $$$4$$$, are also somewhat interesting. Thus, he considers a positive integer $$$n$$$ interesting if its sum of digits is divisible by $$$4$$$.Help Polycarp find the nearest larger or equal interesting number for the given number $$$a$$$. That is, find the interesting number $$$n$$$ such that $$$n \\ge a$$$ and $$$n$$$ is minimal.", "input_spec": "The only line in the input contains an integer $$$a$$$ ($$$1 \\le a \\le 1000$$$).", "output_spec": "Print the nearest greater or equal interesting number for the given number $$$a$$$. In other words, print the interesting number $$$n$$$ such that $$$n \\ge a$$$ and $$$n$$$ is minimal.", "sample_inputs": ["432", "99", "237", "42"], "sample_outputs": ["435", "103", "237", "44"], "notes": null}, "positive_code": [{"source_code": "void main() {\n import std.stdio, std.string, std.conv, std.algorithm;\n\n int a;\n rd(a);\n\n int digit_sum(int x) {\n int ret = 0;\n while (x) {\n ret += x % 10;\n x /= 10;\n }\n return ret;\n }\n\n for (int n = a;; n++) {\n if (digit_sum(n) % 4 == 0) {\n writeln(n);\n break;\n }\n }\n\n}\n\nvoid rd(T...)(ref T x) {\n import std.stdio : readln;\n import std.string : split;\n import std.conv : to;\n\n auto l = readln.split;\n assert(l.length == x.length);\n foreach (i, ref e; x)\n e = l[i].to!(typeof(e));\n}\n"}, {"source_code": "import std.stdio;\nint sum(int a)\n{\n\tint s=0;\n\twhile(a!=0)\n\t{\n\t\ts=s+a%10;\n\t\ta=a/10;\n\t}\n\treturn s;\n}\nint main()\n{\n\tint a=0;\n\treadf(\" %d\", &a);\n\tint i=a;\n\twhile (true)\n\t{\n\t\tif (sum(i)%4==0)\n\t\t{\n\t\t\twriteln(i);\n\t\t\treturn 0;\n\t\t}\n\t\ti=i+1;\n\t}\n\treturn 0;\n}"}], "negative_code": [], "src_uid": "bb6fb9516b2c55d1ee47a30d423562d7"} {"nl": {"description": "After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of n horizontal and m vertical sticks.An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick.In the grid shown below, n\u2009=\u20093 and m\u2009=\u20093. There are n\u2009+\u2009m\u2009=\u20096 sticks in total (horizontal sticks are shown in red and vertical sticks are shown in green). There are n\u00b7m\u2009=\u20099 intersection points, numbered from 1 to 9. The rules of the game are very simple. The players move in turns. Akshat won gold, so he makes the first move. During his/her move, a player must choose any remaining intersection point and remove from the grid all sticks which pass through this point. A player will lose the game if he/she cannot make a move (i.e. there are no intersection points remaining on the grid at his/her move).Assume that both players play optimally. Who will win the game?", "input_spec": "The first line of input contains two space-separated integers, n and m (1\u2009\u2264\u2009n,\u2009m\u2009\u2264\u2009100).", "output_spec": "Print a single line containing \"Akshat\" or \"Malvika\" (without the quotes), depending on the winner of the game.", "sample_inputs": ["2 2", "2 3", "3 3"], "sample_outputs": ["Malvika", "Malvika", "Akshat"], "notes": "NoteExplanation of the first sample:The grid has four intersection points, numbered from 1 to 4. If Akshat chooses intersection point 1, then he will remove two sticks (1\u2009-\u20092 and 1\u2009-\u20093). The resulting grid will look like this. Now there is only one remaining intersection point (i.e. 4). Malvika must choose it and remove both remaining sticks. After her move the grid will be empty.In the empty grid, Akshat cannot make any move, hence he will lose.Since all 4 intersection points of the grid are equivalent, Akshat will lose no matter which one he picks."}, "positive_code": [{"source_code": "module _template;\nimport std.stdio;\nimport std.string;\nimport std.algorithm;\nimport std.container;\nimport std.range;\nimport std.math;\nimport std.numeric;\nimport std.conv;\nimport std.typecons;\nimport std.format;\n\nstruct IO {\n string[] tk;\n string readString() {\n while (tk.empty) \n tk = readln.split;\n auto tkt = tk.front;\n tk.popFront;\n return tkt;\n }\n int readInt() { \n return readString.to!int; \n }\n double readDouble() { \n return readString.to!double; \n }\n}\n\nvoid main() {\n IO cin;\n int t = 1;\n // t = cin.readInt;\n while (t--) {\n int n = cin.readInt;\n int m = cin.readInt;\n writeln(min(n, m) % 2 ? \"Akshat\" : \"Malvika\");\n } \n}"}, {"source_code": "import std.stdio;\nimport std.uni;\nimport std.string;\nimport core.stdc.stdio;\nimport std.array;\nimport std.algorithm;\nimport std.string;\nimport std.math;\n\nint main(string[] argv)\n{\n\tint n, m;\n\tscanf(\"%d %d\", &n, &m);\n\tint ww = 1;\n\twhile (n > 0 && m > 0)\n\t{\n\t\tn--; m--;\n\t\tww++;\n\t\tww %= 2;\n\t}\n\tprintf((ww == 0 ? \"Akshat\" : \"Malvika\"));\n\treturn 0;\n}\n\n"}, {"source_code": "import std.stdio;\nimport std.string;\nimport std.bigint;\nimport std.array;\nimport std.ascii;\nimport std.math;\nimport std.numeric;\nimport std.algorithm;\nimport std.container;\nimport core.bitop;\n\nalias Int = long;\n\nvoid main() {\n Int n, m;\n readf(\" %s\", &n);\n readf(\" %s\", &m);\n if ( min(n, m) % 2 == 0 ) {\n writeln(\"Malvika\");\n } else {\n writeln(\"Akshat\");\n }\n}\n"}, {"source_code": "import core.thread;\nimport std.conv, std.stdio, std.string;\nimport std.algorithm, std.array, std.bigint, std.math, std.range;\n\n//\tInput\nclass EOFException : Throwable { this() { super(\"EOF\"); } }\nstring[] tokens;\nstring readToken() { for (; tokens.empty; ) { tokens = readln.split; if (stdin.eof) throw new EOFException; } auto token = tokens[0]; tokens.popFront; return token; }\nint readInt() { return to!int(readToken); }\nlong readLong() { return to!long(readToken); }\nreal readReal() { return to!real(readToken); }\n\n//\tchmin/chmax\nvoid chmin(T)(ref T t, const T f) { if (t > f) t = f; }\nvoid chmax(T)(ref T t, const T f) { if (t < f) t = f; }\n\n//\tPair\nstruct Pair(S, T) {\n\tS x; T y;\n\tint opCmp(ref const Pair p) const { return (x < p.x) ? -1 : (x > p.x) ? +1 : (y < p.y) ? -1 : (y > p.y) ? +1 : 0; }\n\tstring toString() const { return \"(\" ~ to!string(x) ~ \", \" ~ to!string(y) ~ \")\"; }\n}\nauto pair(S, T)(S x, T y) { return Pair!(S, T)(x, y); }\n\n//\tArray\nint binarySearch(T)(T[] as, bool delegate(T) test) { int low = -1, upp = as.length; for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }\nint lowerBound(T)(T[] as, T val) { return as.binarySearch((T a) { return (a < val); }); }\nint upperBound(T)(T[] as, T val) { return as.binarySearch((T a) { return (a <= val); }); }\nT[] unique(T)(T[] as) { T[] bs; foreach (a; as) if (bs.empty || bs[$ - 1] != a) bs ~= a; return bs; }\n\n\nint M, N;\n\nvoid main(string[] args) {\n\ttry {\n\tfor (; ; ) {\n\t\tM = readInt;\n\t\tN = readInt;\n\t\tbool ans = (min(M, N) % 2 != 0);\n\t\twriteln(ans ? \"Akshat\" : \"Malvika\");\n\t}\n\t} catch (EOFException) {}\n}\n\n"}], "negative_code": [{"source_code": "import std.stdio;\nimport std.uni;\nimport std.string;\nimport core.stdc.stdio;\nimport std.array;\nimport std.algorithm;\nimport std.string;\nimport std.math;\n\nint main(string[] argv)\n{\n\tint n, m;\n\tscanf(\"%d %d\", &n, &m);\n\tint s = n + m;\n\tint ww = 1;\n\twhile (s > 1)\n\t{\n\t\ts -= 2;\n\t\tww++;\n\t\tww %= 2;\n\t}\n\tprintf((ww == 0 ? \"Akshat\" : \"Malvika\"));\n\treturn 0;\n}\n\n"}], "src_uid": "a4b9ce9c9f170a729a97af13e81b5fe4"} {"nl": {"description": "Iahub and his friend Floyd have started painting a wall. Iahub is painting the wall red and Floyd is painting it pink. You can consider the wall being made of a very large number of bricks, numbered 1, 2, 3 and so on. Iahub has the following scheme of painting: he skips x\u2009-\u20091 consecutive bricks, then he paints the x-th one. That is, he'll paint bricks x, 2\u00b7x, 3\u00b7x and so on red. Similarly, Floyd skips y\u2009-\u20091 consecutive bricks, then he paints the y-th one. Hence he'll paint bricks y, 2\u00b7y, 3\u00b7y and so on pink.After painting the wall all day, the boys observed that some bricks are painted both red and pink. Iahub has a lucky number a and Floyd has a lucky number b. Boys wonder how many bricks numbered no less than a and no greater than b are painted both red and pink. This is exactly your task: compute and print the answer to the question. ", "input_spec": "The input will have a single line containing four integers in this order: x, y, a, b. (1\u2009\u2264\u2009x,\u2009y\u2009\u2264\u20091000, 1\u2009\u2264\u2009a,\u2009b\u2009\u2264\u20092\u00b7109, a\u2009\u2264\u2009b).", "output_spec": "Output a single integer \u2014 the number of bricks numbered no less than a and no greater than b that are painted both red and pink.", "sample_inputs": ["2 3 6 18"], "sample_outputs": ["3"], "notes": "NoteLet's look at the bricks from a to b (a\u2009=\u20096,\u2009b\u2009=\u200918). The bricks colored in red are numbered 6, 8, 10, 12, 14, 16, 18. The bricks colored in pink are numbered 6, 9, 12, 15, 18. The bricks colored in both red and pink are numbered with 6, 12 and 18. "}, "positive_code": [{"source_code": "import std.stdio, std.string, std.algorithm;\nimport std.conv, std.array;\nimport std.numeric;\n\nvoid main() {\n int x, y, a, b;\n readf(\"%d %d %d %d\\n\", &x, &y, &a, &b);\n int z = x * y / gcd(x, y);\n int f = (a + z - 1) / z;\n int t = b / z;\n //writeln(f, \" \", t);\n writef(\"%d\\n\", t - f + 1);\n}\n"}, {"source_code": "module main;\n\nimport std.stdio,std.numeric;\n\nint main(string[] args)\n{\n ulong x,y,a,b;\n readf(\" %s %s %s %s\",&x,&y,&a,&b);\n auto l=lcm(x,y);\n writefln(\"%s\",(b/l-a/l)+(a%l?0:1));\n return 0;\n}\n\nT lcm(T)(T a, T b)\n{\n return (a/gcd(a,b))*b;\n}\n"}], "negative_code": [{"source_code": "import std.stdio, std.string, std.algorithm;\nimport std.conv, std.array;\nimport std.numeric;\n\nvoid main() {\n int x, y, a, b;\n readf(\"%d %d %d %d\\n\", &x, &y, &a, &b);\n int z = x * y / gcd(x, y);\n int f = (a + z - 1) / z;\n int t = (b + z - 1) / z;\n writef(\"%d\\n\", t - f + 1);\n}\n"}], "src_uid": "c7aa8a95d5f8832015853cffa1374c48"} {"nl": {"description": "Given a positive integer n, find k integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to n.", "input_spec": "The first line contains two integers n and k (2\u2009\u2264\u2009n\u2009\u2264\u2009100000, 1\u2009\u2264\u2009k\u2009\u2264\u200920).", "output_spec": "If it's impossible to find the representation of n as a product of k numbers, print -1. Otherwise, print k integers in any order. Their product must be equal to n. If there are multiple answers, print any of them.", "sample_inputs": ["100000 2", "100000 20", "1024 5"], "sample_outputs": ["2 50000", "-1", "2 64 2 2 2"], "notes": null}, "positive_code": [{"source_code": "import std.bigint,std.container,std.array,std.algorithm,std.conv,\n\tstd.functional,std.math,std.numeric,std.string,std.range,std.complex,\n\tstd.typecons,std.regex,std.random,std.uni,std.traits,std.stdio,std.variant,\n\tcore.stdc.stdio : freopen;\nimport core.stdc.stdlib : system;\n//import core.stdc.stdio;\nalias RedBlackTree Rbt;alias redBlackTree rbt;alias BigInt big;\nalias pair(X,Y)=Tuple!(X,\"fi\",Y,\"se\");\nalias pair!(int,int) pii;alias pair!(long,long) pll;alias BoyerMooreFinder strfind;\nalias long lint;\nalias make_pair mp;alias binary_search bins;alias gcd=std.numeric.gcd;\nimmutable int mod=1000000007;\npure nothrow \n{\n\tT lcm (T)(auto ref T a,auto ref T b){return a/gcd(a,b)*b;}\n\tpair!(X,Y) make_pair(X,Y)(in X x_,in Y y_){return tuple!(X,\"fi\",Y,\"se\")(x_,y_);}\n\tbig gcd(big a,big b){while(b){a%=b;swap(a,b);}return a;}\n\t@property X sqr(X)(in X a_) {return a_*a_;}\n\t@property X cub(X)(in X a_) {return a_*a_*a_;}\n\tsize_t lowb(T,X)(in T a,auto ref X g)\n\t if(isRandomAccessRange!T && hasLength!T && is(typeof(g1)\n\t\t{\n\t\t\tauto m=(l+r)>>1;\n\t\t\tif(!(a[m] 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\ts+=readf(\" %s\",&e);\n\t}\n\treturn s==ptrs.length;\n}\nbool read(T...)(auto ref T ptrs) if (ptrs.length > 0)\n{\n\tsize_t s=0;\n\tforeach(ref e;ptrs)\n\t{\n\t\ts+=readf(\" %s\",&e);\n\t}\n\treadln;\n\treturn s==ptrs.length;\n}\nnothrow auto inf(in char* name) {return freopen(name,\"r\",core.stdc.stdio.stdin);}\nnothrow auto ouf(in char* name) {return freopen(name,\"w\",core.stdc.stdio.stdout);}\n@property auto arread(T)(){return readln.splitter.map!(to!(T)).array;}\n//split strip isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin\n//cumulativeFold schwartzSort multiSort partialSort heapify join filter\n//------------------------------------------program beginning--------------------------------------------\n\nvoid main()\n{\n\tversion(ONLINE_JUDGE){}\n\telse\n\t{\n\t\tassert(freopen(\"input.txt\",\"r\",core.stdc.stdio.stdin));\n\t\tassert(freopen(\"output.txt\",\"w\",core.stdc.stdio.stdout));\n\t}\n\tint n,k;\n\t//writeln(\"hello\");\nloop:while(read(n,k))\n\t{\n\t\tint[int] q;\n\t\tfor(int i=2;i*i<=n;i++)\n\t\t{\n\t\t\twhile(n%i==0)\n\t\t\t{\n\t\t\t\tq[i]++;\n\t\t\t\tn/=i;\n\t\t\t}\n\t\t}\n\t\tif(n>1)q[n]++;\n\t\tauto s=q.byValue.sum;\n\t\tif(s=k)\n\t\t\t{\n\t\t\t\tg*=del.front;\n\t\t\t\tdel.popFront;\n\t\t\t}\n\t\t\twrite(g,' ');\n\t\t\tforeach(x;del)write(x,' ');\n\t\t\twriteln;\n\t\t}\n\t}\n\t//debug system(\"pause\");\n}\n"}, {"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.math, std.typecons;\n\nint n, k;\n\nvoid main() {\n scan(n, k);\n\n if (k == 1) {\n writeln(n);\n return;\n }\n\n int[] ans;\n int cnt;\n\n for (int p = 2; p <= n/p; ++p) {\n while (n % p == 0) {\n ans ~= p;\n cnt++;\n n /= p;\n\n if (cnt == k - 1 && n > 1) {\n ans ~= n;\n cnt++;\n n = 1;\n break;\n }\n }\n\n if (cnt == k) break;\n }\n\n if (n > 1) {\n ans ~= n;\n cnt++;\n }\n\n if (cnt == k) {\n writefln(\"%(%s %)\", ans);\n }\n else {\n writeln(-1);\n }\n}\n\n\nvoid scan(T...)(ref T args) {\n auto line = readln.split;\n foreach (ref arg ; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}"}, {"source_code": "import std.stdio, std.string, std.conv, std.algorithm;\nimport std.range, std.array, std.math, std.typecons;\n\nimmutable int inf = 10^^9 + 7;\n\nint n, k;\n\nvoid main() {\n scan(n, k);\n\n if (k == 1) {\n writeln(n);\n return;\n }\n\n auto primes = new int[](0);\n int cnt;\n\n for (int p = 2; p*p <= n; ++p) {\n while (n % p == 0) {\n n /= p;\n primes ~= p;\n cnt++;\n\n if (cnt == k - 1 && n > 1) {\n cnt++;\n primes ~= n;\n n = 1;\n break;\n }\n }\n\n if (cnt == k) break;\n }\n\n if (n > 1) {\n cnt++;\n primes ~= n;\n }\n\n if (cnt == k) {\n writefln(\"%(%s %)\", primes);\n }\n else {\n writeln(-1);\n }\n}\n\n\nvoid scan(T...)(ref T args) {\n auto line = readln.split;\n foreach (ref arg ; args) {\n arg = line.front.to!(typeof(arg));\n line.popFront();\n }\n assert(line.empty);\n}"}], "negative_code": [], "src_uid": "bd0bc809d52e0a17da07ccfd450a4d79"}