Download mdtxt_to_json.json from EasyChCh/abc: direct link, hf CLI and curl.
- Browser
- Download file 114 kB
-
https://huggingface.co/datasets/EasyChCh/abc/resolve/main/mdtxt_to_json.json
- Command line
-
hf download hf://datasets/EasyChCh/abc/mdtxt_to_json.json
-
curl -L -o mdtxt_to_json.json https://huggingface.co/datasets/EasyChCh/abc/resolve/main/mdtxt_to_json.json
114 kB
| [ | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# 100 The 3 n + 1 problem\n\nProblems in Computer Science are often classified as belonging to a certain class of problems (e.g., NP, Unsolvable, Recursive). In this problem you will be analyzing a property of an algorithm whose classification is not known for all possible inputs.\n\nConsider the following algorithm:\n\n1. input *n*\n2. print *n*\n3. if *n* = 1 then STOP\n4. if *n* is odd then *n ←−* 3 *n* + 1\n5. else *n ←−* *n* /2\n6. GOTO 2\n\nGiven the input 22, the following sequence of numbers will be printed\n\n22 11 34 17 52 26 13 40 20 10 5 16 8 4 2 1\n\nIt is conjectured that the algorithm above will terminate (when a 1 is printed) for any integral input value. Despite the simplicity of the algorithm, it is unknown whether this conjecture is true. It has been verified, however, for all integers *n* such that 0 *< n <* 1 *,* 000 *,* 000 (and, in fact, for many more numbers than this.) Given an input *n*, it is possible to determine the number of numbers printed before and includin g the 1 is printed. For a given *n* this is called the *cycle-length* of *n* . In the example above, the cycle length of 22 is 16. For any two numbers *i* and *j* you are to determine the maximum cycle length over all numbers between and includin g both *i* and *j* .\n\n**Input**\n\nThe input will consist of a series of pairs of integers *i* and *j*, one pair of integers per line. All integers will be less than 10,000 and greater than 0. You should process all pairs of integers and for each pair determine the maximum cycle length over all integers between and including *i* and *j* . You can assume that no operation overflows a 32-bit integer.\n\n**Output**\n\nFor each pair of input integers *i* and *j* you should output *i*, *j*, and the maximum cycle length for integers between and including *i* and *j* . These three numbers should be separated by at least one space with all three numbers on one line and with one line of output for each line of input. The integers *i* and *j* must appear in the output in the same order in which they appeared in the input and should be followed by the maximum cycle length (on the same line).\n\n**Sample Input**\n```\n1 10\n100 200\n201 210\n900 1000\n\n```\n**Sample Output**\n```\n1 10 20\n100 200 125\n201 210 89\n900 1000 174\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\nusing namespace std;\n \nint main() {\n int i, j;\n while (cin >> i >> j){\n int mx = 0;\n for (int n = min(i, j); n <= max(i, j); n++){\n int n1 = n, cnt = 1;\n while (n1 != 1){\n if (n1 % 2) n1 = 3 * n1 + 1;\n else n1 /= 2;\n cnt++;\n }\n mx = max(mx, cnt);\n }\n cout << i << \" \" << j << \" \" << mx << \"\\n\";\n }\n return 0;\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **10008 What’s Cryptanalysis?**\n\nCryptanalysis is the process of breaking someone else’s cryptographic writing. This sometimes involves some kind of statistical analysis of a passage of (encrypted) text. Your task is to write a program which performs a simple analysis of a given text.\n\n**Input**\n\nThe first line of input contains a single positive decimal integer *n* . This is the number of lines which follow in the input. The next *n* lines will contain zero or more characters (possibly including whitespace). This is the text which must be analyzed.\n\n**Output**\n\nEach line of output contains a single uppercase letter, followed by a single space, then followed by a positive decimal integer. The integer indicates how many times the corresponding letter appears in the input text. Upper and lower case letters in the input are to be considered the same. No other characters must be counted. The output must be sorted in descending count order; that is, the most frequent letter is on the first output line, and the last line of output indicates the least frequent letter. If two letters have the same frequency, then the letter which comes first in the alphabet must appear first in the output. If a letter does not appear in the text, then that letter must not appear in the output.\n\n**Sample Input**\n```\n3\nThis is a test.\nCount me 1 2 3 4 5.\nWow!!!! Is this question easy?\n\n```\n**Sample Output**\n```\nS 7\nT 6\nI 5\nE 4\nO 3\nA 2\nH 2\nN 2\nU 2\nW 2\nC 1\nM 1\nQ 1\nY 1\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\n#include <algorithm>\n#include <vector>\nusing namespace std;\n \nbool cmp(pair<int, char> a, pair<int, char> b) {\n if (a.first != b.first) return a.first > b.first;\n else return a.second < b.second;\n}\n \nint main() {\n vector <pair<int, char> > v(26);\n for (int i = 0; i < 26; i++) {\n v[i] = {0, 'A'+i};\n }\n int n;\n string s;\n cin >> n;\n getline(cin, s); // clear buffer (\\n)\n while (n--) {\n getline(cin, s);\n for (int i = 0; i < s.size(); i++) {\n if ('A' <= s[i] && s[i] <= 'Z') {\n v[s[i] - 'A'].first++;\n }\n if ('a' <= s[i] && s[i] <= 'z') {\n v[s[i] - 'a'].first++;\n }\n }\n }\n sort(v.begin(), v.end(), cmp);\n for (auto i: v) {\n if (i.first > 0) cout << i.second << \" \" << i.first << \"\\n\";\n }\n return 0;\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **10019 Funny Encryption Method**\n\nA student from ITESM Campus Monterrey plays with a new encryption method for numbers. These method consist of the following steps:\n\n**Steps : Example**\n\n1. Read the number *N* to encrypt : *M* = `265`\n\n2. Interpret *N* as a decimal number : *X*1 = `265` (decimal)\n\n3. Convert the decimal interpretation of *N* to its binary representation : *X*1 = `100001001` (binary)\n\n4. Let *b*1 be equal to the number of `1` ’s in this binary representation : *b*1 = `3`\n\n5. Interpret *N* as a Hexadecimal number : *X*2 = `265` (hexadecimal)\n\n6. Convert the hexadecimal interpretation of *N* to its binary representation : *X*2 = `1001100101`\n\n7. Let *b*2 be equal to the number of `1` ’s in the last binary representation : *b*2 = `5`\n\n8. The encryption is the result of *M xor* ( *b*1 *∗* *b*2) : `265` *xor* ( `3*5` ) = `262`\n\nThis student failed Computational Organization, thats why this student asked the judges of ITESM Campus Monterrey internal ACM programming Contest to ask for the numbers of `1` ’s bits of this two representations so that he can continue playing.\n\nYou have to write a program that read a *Number* and give as output the number *b*1 and *b*2\n\n**Input**\n\nThe first line will contain a number *N* which is the number of cases that you have to process. Each of the following *N* Lines (0 *< N ≤* 1000) will contain the number *M* (0 *< M ≤* 9999, in decimal representation) which is the number the student wants to encrypt.\n\n**Output**\n\nYou will have to output *N* lines, each containing the number *b*1 and *b*2 in that order, separated by one space corresponding to that lines number to crypt\n\n**Sample Input**\n```\n3\n265\n111\n1234\n\n```\n**Sample Output**\n```\n3 5\n6 3\n5 5\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\nusing namespace std;\n \nint main() {\n int T, N;\n cin >> T;\n while (T--){\n cin >> N;\n int X1 = N;\n int b1 = 0;\n while (X1){\n b1 += X1 & 1;\n X1 >>= 1;\n }\n int X2 = 0;\n int mul = 1;\n X1 = N;\n while (X1){\n X2 += (X1 % 10) * mul;\n X1 /= 10;\n mul *= 16;\n }\n int b2 = 0;\n while (X2){\n b2 += X2 & 1;\n X2 >>= 1;\n }\n cout << b1 << \" \" << b2 << \"\\n\";\n }\n return 0;\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **10035 Primary Arithmetic**\n\nChildren are taught to add multi-digit numbers from right-to-left one digit at a time. Many find the “carry” operation - in which a 1 is carried from one digit position to be added to the next - to be a significant challenge. Your job is to count the number of carry operations for each of a set of addition problems so that educators may assess their difficulty.\n\n**Input**\n\nEach line of input contains two unsigned integers less than 10 digits. The last line of input contains ‘ `0` `0` ’.\n\n**Output**\n\nFor each line of input except the last you should compute and print the number of carry operations that would result from adding the two numbers, in the format shown below.\n\n**Sample Input**\n```\n123 456\n555 555\n123 594\n0 0\n\n```\n**Sample Output**\n```\nNo carry operation.\n3 carry operations.\n1 carry operation.\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\nusing namespace std;\n \nint main() {\n int n1, n2;\n while (cin >> n1 >> n2){\n int carry = 0, cnt = 0;\n if (n1 == 0 && n2 == 0) break;\n while (n1 > 0 || n2 > 0){\n int tmp = n1 % 10 + n2 % 10 + carry;\n if (tmp >= 10){\n carry = tmp / 10;\n cnt++;\n } else {\n carry = 0;\n }\n n1 /= 10;\n n2 /= 10;\n }\n if (cnt == 0) cout << \"No carry operation.\\n\";\n else if (cnt == 1) cout << \"1 carry operation.\\n\";\n else cout << cnt << \" carry operations.\\n\";\n }\n return 0;\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **10038 Jolly Jumpers**\n\nA sequence of *n >* 0 integers is called a *jolly jumper* if the absolute values of the difference between successive elements take on all the values 1 through *n −* 1. For instance,\n\n 1 4 2 3\n\n is a jolly jumper, because the absolutes differences are 3, 2, and 1 respectively. The definition implies that any sequence of a single integer is a jolly jumper. You are to write a program to determine whether or not each of a number of sequences is a jolly jumper.\n\n**Input**\n\nEach line of input contains an integer *n ≤* 3000 followed by *n* integers representing the sequence.\n\n**Output**\n\nFor each line of input, generate a line of output saying ‘ `Jolly` ’ or ‘ `Not jolly` ’.\n\n**Sample Input**\n```\n4 1 4 2 3\n5 1 4 2 -1 6\n\n```\n**Sample Output**\n```\nJolly\nNot jolly\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\n#include <cstring>\nusing namespace std;\n \nint main() {\n int n;\n while (cin >> n){\n int pre, now;\n int d[n]; // initial value not guanranteed to be zero\n for (int i = 0; i < n; i++) {\n d[i] = 0;\n }\n cin >> pre;\n for (int i = 1; i < n; i++){\n cin >> now;\n d[abs(now - pre)]++;\n pre = now;\n }\n bool flag = true;\n for (int i = 1; i < n; i++) {\n if (d[i] != 1) {\n flag = false;\n break;\n }\n }\n if (flag) cout << \"Jolly\\n\";\n else cout << \"Not jolly\\n\";\n }\n return 0;\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **10041 Vito’s family**\n\nThe world-known gangster Vito Deadstone is moving to New York. He has a very big family there, all of them living in Lamafia Avenue. Since he will visit all his relatives very often, he is trying to find a house close to them.\n\nVito wants to minimize the total distance to all of them and has blackmailed you to write a program that solves his problem.\n\n**Input**\n\nThe input consists of several test cases. The first line contains the number of test cases. For each test case you will be given the integer number of relatives *r* (0 *< r <* 500) and the street numbers (also integers) *s* 1 *, s* 2 *, . . ., s* *i* *, . . ., s* *r* where they live (0 *< s* *i* *<* 30000 ). Note that several relatives could live in the same street number.\n\n**Output**\n\nFor each test case your program must write the minimal sum of distances from the optimal Vito’s house to each one of his relatives. The distance between two street numbers *s* *i* and *s* *j* is *d* *ij* = *|s* *i* *−* *s* *j* *|* .\n\n**Sample Input**\n```\n2\n2 2 4\n3 2 4 6\n\n```\n**Sample Output**\n```\n2\n4\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\n#include <algorithm>\nusing namespace std;\n \nint main() {\n int T, r;\n cin >> T;\n while (T--) {\n cin >> r;\n int s[r];\n for (int i = 0; i < r; i++){\n cin >> s[i];\n }\n sort(s, s+r);\n int sum = 0;\n for (int i = 0; i < r; i++){\n sum += abs(s[i] - s[r/2]);\n }\n cout << sum << \"\\n\";\n }\n return 0;\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **10055 Hashmat the brave warrior**\n\nHashmat is a brave warrior who with his group of young soldiers moves from one place to another to fight against his opponents. Before Fighting he just calculates one thing, the difference between his soldier number and the opponent’s soldier number. From this difference he decides whether to fight or not. Hashmat’s soldier number is never greater than his opponent.\n\n**Input**\n\nThe input contains two numbers in every line. These two numbers in each line denotes the number soldiers in Hashmat’s army and his opponent’s army or vice versa. The input numbers are not greater than 2<sup>32</sup> . Input is terminated by ‘End of File’.\n\n**Output**\n\nFor each line of input, print the difference of number of soldiers between Hashmat’s army and his opponent’s army. Each output should be in seperate line.\n\n**Sample Input**\n```\n10 12\n10 14\n100 200\n\n```\n**Sample Output**\n```\n2\n4\n100\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\nusing namespace std;\n \nint main() {\n long long n1, n2;\n while (cin >> n1 >> n2){\n cout << abs(n1 - n2) << \"\\n\";\n }\n return 0;\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **10056 What is the Probability?**\n\nProbability has always been an integrated part of computer algorithms. Where the deterministic algorithms have failed to solve a problem in short time, probabilistic algorithms have come to the rescue. In this problem we are not dealing with any probabilistic algorithm. We will just try to determine the winning probability of a certain player.\n\nA game is played by throwing a dice like thing (it should not be assumed that it has six sides like an ordinary dice). If a certain event occurs when a player throws the dice (such as getting a 3, getting green side on top or whatever) he is declared the winner. There can be *N* such player. So the first player will throw the dice, then the second and at last the *N* -th player and again the first player and so on. When a player gets the desired event he or she is declared winner and playing stops. You will have to determine the winning probability of one (The *I* -th) of these players.\n\n**Input**\n\nInput will contain an integer *S* ( *S ≤* 1000) at first, which indicates how many sets of inputs are there. The next *S* lines will contain *S* sets of inputs. Each line contain an integer *N* ( *N ≤* 1000) which denotes the number players, a floating point number *p* which indicates the probability of the happening of a successful event in a single throw (If success means getting 3 then *p* is the probability of getting 3 in a single throw. For a normal dice the probability of getting 3 is 1/6), and *I* ( *I ≤* *N* ) the serial of the player whose winning probability is to be determined (Serial no varies from 1 to *N* ). You can assume that no invalid probability ( *p* ) value will be given as input.\n\n**Output**\n\nFor each set of input, output in a single line the probability of the *I* -th player to win. The output floating point number will always have four digits after the decimal point as shown in the sample\n\noutput.\n\n**Sample Input**\n```\n2\n2 0.166666 1\n2 0.166666 2\n\n```\n**Sample Output**\n```\n0.5455\n0.4545\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\n#include <iomanip>\n#include <cmath>\nusing namespace std;\n \nint main() {\n int S, N, K;\n double p;\n cin >> S;\n while (S--){\n cin >> N >> p >> K;\n if (p == 0) {\n cout << \"0.0000\\n\";\n continue;\n }\n double first = pow(1.0 - p, K-1) * p;\n double r = pow(1.0 - p, N);\n cout << fixed << setprecision(4) <<\n first / (1.0 - r) << \"\\n\";\n }\n return 0;\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **10057 A mid-summer night’s dream**\n\nThis is year 2200AD. Science has progressed a lot in two hundred years. Two hundred years is mentioned here because this problem is being sent back to 2000AD with the help of time machine. Now it is possible to establish direct connection between man and computer CPU. People can watch other peoples dream on 3D displayer (That is the monitor today) as if they were watching a movie. One problem in this century is that people have become so dependent on computers that their analytical ability is approaching zero. Computers can now read problems and solve them automatically. But they can solve only difficult problems. There are no easy problems now. Our chief scientist is in great trouble as he has forgotten the number of his combination lock. For security reasons computers today cannot solve combination lock related problems. In a mid-summer night the scientist has a dream where he sees a lot of unsigned integer numbers flying around. He records them with the help of his computer, Then he has a clue that if the numbers are ( *X* 1, *X* 2, …, *X* *n* ) he will have to find an integer number *A* (This *A* is the combination lock code) such that\n\n( *|X* 1 *−* *A|* + *|X* 2 *−* *A|* + *. . .* + *|Xn −* *A|* )\n\nis minimum.\n\n**Input**\n\nInput will contain several blocks. Each block will start with a number *n* (0 *< n ≤* 1000000) indicating how many numbers he saw in the dream. Next there will be *n* numbers. All the numbers will be less that 65536. The input will be terminated by end of file.\n\n**Output**\n\nFor each set of input there will be one line of output. That line will contain the minimum possible value for *A* . Next it will contain how many numbers are there in the input that satisfy the property of *A* (The summation of absolute deviation from *A* is minimum). And finally you have to print how many possible different integer values are there for *A* (these values need not be present in the input).\n\nThese numbers will be separated by single space.\n\n**Sample Input**\n```\n2\n10\n10\n4\n1\n2\n2\n4\n\n```\n**Sample Output**\n```\n10 2 1\n2 2 1\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\n#include <algorithm>\n#include <map>\nusing namespace std;\n \nint main() {\n int n;\n while (cin >> n){\n int a[n];\n for (int i = 0; i < n; i++){\n cin >> a[i];\n }\n sort(a, a+n);\n int mid1 = a[(n-1)/2];\n int mid2 = a[n/2];\n int ans = 0;\n for (int i = 0; i < n; i++){\n if (a[i] == mid1 || a[i] == mid2) ans++;\n }\n cout << mid1 << \" \" << ans << \" \" << mid2 - mid1 + 1 << \"\\n\";\n }\n return 0;\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **10062 Tell me the frequencies!**\n\nGiven a line of text you will have to find out the frequencies of the ASCII characters present in it. The given lines will contain none of the first 32 or last 128 ASCII characters. Of course lines may end with `\\n` and `\\r` but always keep those out of consideration.\n\n**Input**\n\nSeveral lines of text are given as input. Each line of text is considered as a single input. Maximum length of each line is 1000.\n\n**Output**\n\nPrint the ASCII value of the ASCII characters which are present and their frequency according to the given format below. A blank line should separate each set of output. Print the ASCII characters in the ascending order of their frequencies. If two characters are present the same time print the information of the ASCII character with higher ASCII value first. Input is terminated by end of file.\n\n**Sample Input**\n```\nAAABBC\n122333\n\n```\n**Sample Output**\n```\n67 1\n66 2\n65 3\n\n49 1\n50 2\n51 3\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\n#include <algorithm>\nusing namespace std;\n#define pii pair<int,int>\n \nbool cmp(pii a, pii b){\n if (a.first != b.first) return a.first < b.first;\n else return a.second > b.second;\n}\n \nint main() {\n string s;\n while (getline(cin, s)) {\n pii a[256];\n for (int i = 0; i < 256; i++) {\n a[i] = {0, i};\n }\n for (int i = 0; i < s.size(); i++) {\n a[(int)s[i]].first++;\n }\n sort(a, a+256, cmp);\n for (auto i: a){\n if (i.first > 0) cout << i.second << \" \" << i.first << \"\\n\";\n }\n cout << \"\\n\";\n }\n return 0;\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **10071 Back to High School Physics**\n\nA particle has initial velocity and acceleration. If its velocity after certain time is v then what will its displacement be in twice of that time?\n\n**Input**\n\nThe input will contain two integers in each line. Each line makes one set of input. These two integers denote the value of *v* ( *−* 100 *≤* *v ≤* 100) and *t* (0 *≤* *t ≤* 200) ( *t* means at the time the particle gains that velocity)\n\n**Output**\n\nFor each line of input print a single integer in one line denoting the displacement in double of that time.\n\n**Sample Input**\n```\n0 0\n5 12\n\n```\n**Sample Output**\n```\n0\n120\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\nusing namespace std;\n \nint main() {\n int v, t;\n while (cin >> v >> t){\n cout << 2 * v * t << \"\\n\";\n }\n return 0;\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **10093 An Easy Problem!**\n\nHave you heard the fact “ *The base of every normal number system is 10* ”? Of course, I am not talking about number systems like Stern Brockot Number System. This problem has nothing to do with this fact but may have some similarity.\n\nYou will be given an *N* based integer number *R* and you are given the guaranty that *R* is divisible by ( *N −* 1). You will have to print the smallest possible value for *N* . The range for *N* is 2 *≤* *N ≤* 62 and the digit symbols for 62 based number is ( `0..9` and `A..Z` and `a..z` ). Similarly, the digit symbols for 61 based number system is `0..9` and `A..Z` and `a..y` ) and so on.\n\n**Input**\n\nEach line in the input file will contain an integer (as defined in mathematics) number of any integer base (2..62). You will have to determine what is the smallest possible base of that number for the given conditions. No invalid number will be given as input.\n\n**Output**\n\nIf number with such condition is not possible output the line ‘ `such number is impossible!` ’ For each line of input there will be only a single line of output. The output will always be in decimal number\n\nsystem.\n\n**Sample Input**\n```\n3\n5\nA\n\n```\n**Sample Output**\n```\n4\n6\n11\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\nusing namespace std;\n \nint main() {\n int sum, mx, temp;\n string s;\n while (getline(cin, s)){\n sum = 0;\n mx = 1;\n int i;\n for (i = 0; i < s.size(); i++) {\n if (s[i] >= '0' && s[i] <= '9') {\n temp = s[i] - '0';\n }\n else if (s[i] >= 'A' && s[i] <= 'Z') {\n temp = s[i] - 'A' + 10;\n }\n else if (s[i] >= 'a' && s[i] <= 'z') {\n temp = s[i] - 'a' + 36;\n }\n else continue;\n \n if (mx < temp)\n mx = temp;\n sum += temp;\n }\n \n for (i = mx; i < 62; i++)\n if (!(sum % i)) {\n cout << i + 1 << \"\\n\";\n break;\n }\n \n if (i == 62)\n cout << \"such number is impossible!\\n\";\n }\n return 0;\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **10101 Bangla Numbers**\n\nBangla numbers normally use ’kuti’ (10000000), ’lakh’ (100000), ’hajar’ (1000), ’shata’ (100) while expanding and converting to text. You are going to write a program to convert a given number to text with them.\n\n**Input**\n\nThe input file may contain several test cases. Each case will contain a non-negative number *≤* 999999999999999.\n\n**Output**\n\nFor each case of input, you have to output a line starting with the case number with four digits adjustment followed by the converted text.\n\n**Sample Input**\n```\n23764\n45897458973958\n\n```\n**Sample Output**\n```\n 1. 23 hajar 7 shata 64\n 2. 45 lakh 89 hajar 7 shata 45 kuti 89 lakh 73 hajar 9 shata 58\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\n#include <algorithm>\nusing namespace std;\n#define ll long long\nint a[] = {10000000, 100000, 1000, 100};\nstring s[] = {\"kuti\", \"lakh\", \"hajar\", \"shata\"};\nstring ans;\n \nstring num2str(ll x){\n string s = \"\";\n while (x){\n s += '0' + (x % 10);\n x /= 10;\n }\n reverse(s.begin(), s.end());\n return s;\n}\n \nvoid solve(ll x){\n if (x >= a[0]){\n solve(x / a[0]);\n ans += \" \" + s[0];\n x %= (int)a[0];\n }\n for (int i = 0; i < 4; i++){\n if (x / a[i] > 0){\n ans += \" \" + num2str(x / a[i]) + \" \" + s[i];\n x %= a[i];\n }\n }\n if (x > 0) ans += \" \" + num2str(x);\n}\n \nint main() {\n ll N;\n int Case = 1;\n while (cin >> N){\n cout << \" \" << Case++ << \".\";\n if (N == 0) cout << \" 0\\n\";\n else {\n ans = \"\";\n solve(N);\n cout << ans << \"\\n\";\n }\n }\n return 0;\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **10170 The Hotel with Infinite Rooms**\n\nThe city of **HaluaRuti** has a strange hotel with infinite rooms. The groups that come to this hotel follow the following rules:\n\na) At the same time only members of one group can rent the hotel.\n\nb) Each group comes in the morning of the check-in day and leaves the hotel in the evening of the check-out day.\n\nc) Another group comes in the very next morning after the previous group has left the hotel.\n\nd) A very important property of the incoming group is that it has one more member than its previous group unless it is the starting group. You will be given the no of members of the starting group.\n\ne) A group with *n* members stays for *n* days in the hotel. For example, if a group of four members comes on 1st August in the morning, it will leave the hotel on 4th August in the evening and the next group of five members will come on 5th August in the morning and stay for five days and so on.\n\nGiven the initial group size you will have to find the group size staying in the hotel on a specified day.\n\n**Input**\n\nThe input contains round numbers *S* (1 *≤* *S ≤* 10000) and *D* (1 *≤* *D <* 10<sup>15</sup> ) in every line. *S* denotes the initial size of the group and *D* denotes that you will have to find the group size staying in the hotel on *D* -th day (starting from 1). All the input and output integers will be less than 10<sup>15</sup> . A group size *S* means that on the first day a group of *S* members come to the hotel and stays for *S* days then comes a group of *S* + 1 members according to the previously described rules and so on.\n\n**Output**\n\nFor each line of input, print on a single line the size of the group staying in the hotel on the *D* -th day.\n\n**Sample Input**\n```\n1 6\n3 10\n3 14\n\n```\n**Sample Output**\n```\n3\n5\n6\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\nusing namespace std;\n \nint main() {\n long long S, D, cnt;\n while (cin >> S >> D){\n cnt = S;\n D -= S;\n while (D > 0){\n cnt++;\n D -= cnt;\n }\n cout << cnt << \"\\n\";\n }\n return 0;\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **10189 Minesweeper**\n\nHave you ever played Minesweeper? It’s a cute little game which comes within a certain Operating System which name we can’t really remember. Well, the goal of the game is to find where are all the mines within a *M × N* field. To help you, the game shows a number in a square which tells you how many mines there are adjacent to that square. For instance, supose the following 4 *×* 4 field with 2 mines (which are represented by an ‘ `*` ’ character): \n\n``` \n *...\n ....\n .*..\n ....\n```\n\nIf we would represent the same field placing the hint numbers described above, we would end up with:\n\n ```\n *100 \n 2210 \n 1*10 \n 1110\n\n```\n As you may have already noticed, each square may have at most 8 adjacent squares.\n\n**Input**\n\nThe input will consist of an arbitrary number of fields. The first line of each field contains two integers *n* and *m* (0 *< n, m ≤* 100) which stands for the number of lines and columns of the field respectively. The next *n* lines contains exactly *m* characters and represent the field.\n\nEach safe square is represented by an ‘ `.` ’ character (without the quotes) and each mine square is represented by an ‘ `*` ’ character (also without the quotes). The first field line where *n* = *m* = 0 represents the end of input and should not be processed.\n\n**Output**\n\nFor each field, you must print the following message in a line alone:\n\nField #*x*:\n\nWhere *x* stands for the number of the field (starting from 1). The next *n* lines should contain the field with the ‘ `.` ’ characters replaced by the number of adjacent mines to that square. There must be an empty line between field outputs.\n\n**Sample Input**\n```\n4 4\n*...\n....\n.*..\n....\n3 5\n\n```\n**Sample Output**\n```\nField #1:\n*100\n2210\n1*10\n1110\nField #2:\n**100\n33200\n1*100\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\n#include <cstring>\nusing namespace std;\nchar a[105][105];\nint b[105][105];\nint dx[] = {1, -1, 0, 0, -1, 1, -1, 1};\nint dy[] = {0, 0, 1, -1, 1, 1, -1, -1};\n \nint main() {\n int n, m, Case = 1;\n string s;\n while (cin >> n >> m){\n if (n == 0 && m == 0) break;\n for (int i = 0; i < n; i++){\n cin >> s;\n for (int j = 0; j < m; j++){\n a[i][j] = s[j];\n }\n }\n memset(b, 0, sizeof(b));\n for (int i = 0; i < n; i++){\n for (int j = 0; j < m; j++){\n if (a[i][j] == '*'){\n b[i][j] = -1;\n } else {\n for (int k = 0; k < 8; k++){\n int x = i + dx[k];\n int y = j + dy[k];\n if (x >= 0 && x < n && y >= 0 && y < m && a[x][y] == '*')\n b[i][j]++;\n }\n }\n }\n }\n if (Case > 1) cout << \"\\n\";\n cout << \"Field #\" << Case++ << \":\\n\";\n for (int i = 0; i < n; i++){\n for (int j = 0; j < m; j++){\n if (b[i][j] == -1) cout << '*';\n else cout << b[i][j];\n }\n cout << \"\\n\";\n }\n }\n return 0;\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **10190 Divide, But Not Quite Conquer!**\n\nYour goal in this problem is to divide a certain integer *n* by another integer *m* until *n* = 1, obtaining a sequence of numbers. Lets call *a* [ *i* ] each number of this sequence, and let’s say it has *k* numbers (i.e. you must do *k −* 1 succesive divisions to reach *n* = 1). You can only have this sequence if the following restrictions are met:\n\n - *a* [1] = *n, a* [ *i* ] = *a* [ *i −* 1] *÷ m*, for all 1 *< i ≤* *k*\n\n - *a* [ *i* ] is divisible by *m* (that is, *a* [ *i* ] mod *m* = 0) for all 1 *≤* *i < k*\n\n - *a* [1] *> a* [2] *> a* [3] *> . . . > a* [ *k* ]\n\nFor instance, if *n* = 125 and *m* = 5, you have 125, 25, 5 and 1 (you did 3 divisions: 125/5, 25/5 and 5/5). So, *k* = 4, *a* [1] = 125, *a* [2] = 25, *a* [3] = 5 and *a* [4] = 1.\n\nIf *n* = 30 and *m* = 3, you have 30, 10, 3 and 1. But *a* [2] = 10, and 10 mod 3 = 1, so there is no sequence because it violates restriction 2. When the sequence doesn’t exist we think it’s not fun and, thus, very boring!\n\n**Input**\n\nThe input will consist on an arbitrary number of lines. Each line will consist of two non-negative integers *n*, *m* which are both less than 2000000000. You must read until you reach the end of file.\n\n**Output**\n\nFor each pair *n*, *m* you must print the correspondent sequence a (as defined above) in a single line, with each adjacent numbers of the sequence separated by a single space. In the case the sequence doesn’t exist because it violates some restriction, just print the phrase ‘ `Boring!` ’ in a single line (without the quotes).\n\n**Sample Input**\n```\n125 5\n30 3\n80 2\n81 3\n\n```\n**Sample Output**\n```\n125 25 5 1\nBoring!\nBoring!\n81 27 9 3 1\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\n#include <vector>\nusing namespace std;\n \nint main() {\n int n, m;\n while (cin >> n >> m){\n vector <int> ans;\n bool boring = false;\n if (n == 0 || m == 0) boring = true;\n else {\n ans.push_back(n);\n while (n > 1) {\n if (n%m == 0){\n n /= m;\n ans.push_back(n);\n } else {\n boring = true;\n break;\n }\n }\n }\n if (boring) cout << \"Boring!\\n\";\n else {\n for (auto i: ans) cout << i << \" \";\n cout << \"\\n\";\n }\n }\n return 0;\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **10193 All You Need Is Love**\n\n*”All you need is love. All you need is love.* *All you need is love, love... love is all you need.”*\n\n*The Beatles*\n\nThere was invented a new powerfull gadget by the International Beautifull Machines corporation called the love machine! Given a string made of binary digits, the love machine answers if it’s made only of love, that is, if all you need is love to build that string. The definition of love for the love machine is another string of binary digits, given by a human operator. Let’s say we have a string *L* which represents “ *love* ” and we give a string *S* for the love machine. We say that all you need is love to build *S*, if we can repeatly subtract *L* from *S* until we reach *L* . The subtraction defined here is the same arithmetic subtraction in base 2. By this definition it’s easy to see that if *L > S* (in binary), then *S* is not made of love.\n\nIf *S* = *L* then *S* is obvious made of love.\n\nLet’s see an example. Supose *S* = “ `11011` ” and *L* = “ `11` ”. If we reapetly subtract *L* from *S*, we get: `11011`, `11000`, `10101`, `10010`, `1111`, `1100`, `1001`, `110`, `11` . So, given this *L*, all you need is love to build *S* . Because of some limitations of the love machine, there can be no string with leading zeroes. That is, “ `0010101` ”, “ `01110101` ”, “ `011111` ”, etc. are invalid strings. Strings which have only one digit are also invalid (it’s another limitation).\n\nYour task in this problem is: given two valid binary strings, *S*1 and *S*2, find if it’s possible to have a valid string *L* such that both *S*1 and *S*2 can be made only of *L* (i.e. given two valid strings *S*1 and *S*2, find if there exists at least one valid string *L* such as both *S*1 and *S*2 are made only of *L* ). For instance, for *S*1 = `11011` and *S*2 = `11000`, we can have *L* = `11` such that *S*1 and *S*2 are both made only of *L* (as we can see in the example above).\n\n**Input**\n\nThe first line of input is a positive integer *N <* 10000 which stands for the number of teste cases. Then, 2 *∗* *N* lines will follow. Each pair of lines consists in one teste case. Each line of the pair stands for each string ( *S*1 and *S*2 ) to be entered as an input for the love machine. No string will have more than 30 characters. You can assume that all strings in the input will be valid acording to the rules above.\n\n**Output**\n\nFor each string pair, you must print one of the following messages:\n```\nPair #*p*: All you need is love!\nPair #*p* : Love is not all you need!\n```\nWhere *p* stands for the pair number (starting from 1). You should print the first message if there exists at least one valid string *L* such as both *S*1 and *S*2 can be made only of *L* . Otherwise, print the second line.\n\n\n**Sample Input**\n```\n5\n11011\n11000\n11011\n11001\n111111\n100\n1000000000\n110\n1010\n100\n\n```\n**Sample Output**\n```\nPair #1: All you need is love!\nPair #2: Love is not all you need!\nPair #3: Love is not all you need!\nPair #4: All you need is love!\nPair #5: All you need is love!\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\nusing namespace std;\n \nint mygcd(int x, int y){\n while ((x %= y) && (y %= x));\n return x + y;\n}\n \nint main() {\n int N;\n string S1, S2;\n cin >> N;\n for (int Case = 1; Case <= N; Case++){\n cin >> S1 >> S2;\n int n1 = 0, n2 = 0;\n for (int i = 0; i < S1.size(); i++){\n n1 *= 2;\n n1 += S1[i] - '0';\n }\n for (int i = 0; i < S2.size(); i++){\n n2 *= 2;\n n2 += S2[i] - '0';\n }\n cout << \"Pair #\" << Case;\n if (mygcd(n1, n2) > 1) cout << \": All you need is love!\\n\";\n else cout << \": Love is not all you need!\\n\";\n }\n return 0;\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **10221 Satellites**\n\nThe radius of earth is 6440 Kilometer. There are many Satellites and Asteroids moving around the earth. If two Satellites create an angle with the center of earth, can you find out the *distance* between them? By *distance* we mean both the *arc* and *chord* distances. Both satellites are on the same orbit (However, please consider that they are revolving on a circular path rather than an elliptical path).\n\n**Input**\n\nThe input file will contain one or more test cases.\n\nEach test case consists of one line containing two-integer *s* and *a*, and a string ‘ `min` ’ or ‘ `deg` ’. Here *s* is the distance of the satellite from the surface of the earth and *a* is the angle that the satellites make with the center of earth. It may be in minutes ( *′* ) or in degrees ( *<sup>◦</sup>* ). Remember that the same line will never contain minute and degree at a time.\n\n**Output**\n\nFor each test case, print one line containing the required distances i.e. both *arc distance* and *chord* *distance* respectively between two satellites in Kilometer. The distance will be a floating-point value with six digits after decimal point.\n\n**Sample Input**\n```\n500 30 deg\n700 60 min\n200 45 deg\n\n```\n**Sample Output**\n```\n3633.775503 3592.408346\n124.616509 124.614927\n5215.043805 5082.035982\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\n#include <iomanip>\n#include <cmath>\nusing namespace std;\n#define PI acos(0.0)*2.0\n \nint main() {\n double r, s, a;\n string unit;\n double chord, arc;\n r = 6440.0;\n while (cin >> s >> a >> unit){\n if (unit == \"min\") a /= 60.0;\n if (a > 180.0) a = 360.0 - a;\n chord = (r+s) * cos((90.0 - a/2.0)/ 180.0 * PI) * 2.0;\n arc = 2.0 * PI * (r+s) * a / 360.0;\n cout << fixed << setprecision(6) << arc << \" \" << chord << \"\\n\";\n }\n return 0;\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **10222 Decode the Mad man**\n\nOnce in BUET, an old professor had gone completely mad. He started talking with some peculiar words. Nobody could realize his speech and lectures. Finally the BUET authority fall in great trouble. There was no way left to keep that man working in university. Suddenly a student (definitely he was a registered author at UVA ACM Chapter and hold a good rank on 24 hour-Online Judge) created a program that was able to decode that professor’s speech. After his invention, everyone got comfort again and that old teacher started his everyday works as before. \nSo, if you ever visit BUET and see a teacher talking with a microphone, which is connected to a IBM computer equipped with a voice recognition software and students are taking their lecture from the computer screen, don’t get thundered! Because now your job is to write the same program which can decode that mad teacher’s speech!\n\n**Input**\n\nThe input file will contain only one test case i.e. the encoded message. The test case consists of one or more words.\n\n**Output**\n\nFor the given test case, print a line containing the decoded words. However, it is not so hard task to replace each letter or punctuation symbol by the two immediately to its left alphabet on your standard keyboard.\n\n**Sample Input**\n```\nk[r dyt I[o\n\n```\n**Sample Output**\n```\nhow are you\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\n#include <map>\nusing namespace std;\n \nint main() {\n string s[] = {\"~!@#$%^&*()_+\",\n \"`1234567890-=\",\n \"qwertyuiop[]\\\\\",\n \"asdfghjkl;'\",\n \"zxcvbnm,./\"};\n \n map <char, char> mp;\n for (int i = 0; i < 5; i++){\n for (int j = 2; j < s[i].size(); j++){\n mp[s[i][j]] = s[i][j-2];\n }\n }\n string S;\n while (getline(cin, S)){\n for (int i = 0; i < S.size(); i++){\n if (S[i] == ' ') cout << \" \";\n else cout << mp[S[i]];\n }\n cout << \"\\n\";\n }\n return 0;\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **10226 Hardwood Species**\n\nHardwoods are the botanical group of trees that have broad leaves, produce a fruit or nut, and generally go dormant in the winter. \nAmerica’s temperate climates produce forests with hundreds of hardwood species —trees that share certain biological characteristics. Although oak, maple and cherry all are types of hardwood trees, for example, they are different species. Together, all the hardwood species represent 40 percent of the trees in the United States. \nOn the other hand, softwoods, or conifers, from the Latin word meaning *“cone-bearing”*, have needles. Widely available US softwoods include cedar, fir, hemlock, pine, redwood, spruce and cypress. In a home, the softwoods are used primarily as structural lumber such as 2 *×* 4s and 2 *×* 6s, with some limited decorative applications. \nUsing satellite imaging technology, the Department of Natural Resources has compiled an inventory of every tree standing on a particular day. You are to compute the total fraction of the tree population represented by each species.\n\n**Input**\n\nThe first line is the number of test cases, followed by a blank line. \nEach test case of your program consists of a list of the species of every tree observed by the satellite; one tree per line. No species name exceeds 30 characters. \nThere are no more than 10,000 species and no more than 1,000,000 trees.\n\nThere is a blank line between each consecutive test cases.\n\n**Output**\n\nFor each test case print the name of each species represented in the population, in alphabetical order, followed by the percentage of the population it represents, to 4 decimal places.\nPrint a blank line between 2 consecutive test cases.\n\n**Sample Input**\n```\n1\n\nRed Alder\nAsh\nAspen\nBasswood\nAsh\nBeech\nYellow Birch\nAsh\nCherry\nCottonwood\nAsh\nCypress\nRed Elm\nGum\nHackberry\nWhite Oak\nHickory\nPecan\nHard Maple\nWhite Oak\nSoft Maple\nRed Oak\nRed Oak\nWhite Oak\nPoplan\nSassafras\nSycamore\nBlack Walnut\nWillow\n\n```\n**Sample Output**\n```\nAsh 13.7931\nAspen 3.4483\nBasswood 3.4483\nBeech 3.4483\nBlack Walnut 3.4483\nCherry 3.4483\nCottonwood 3.4483\nCypress 3.4483\nGum 3.4483\nHackberry 3.4483\nHard Maple 3.4483\nHickory 3.4483\nPecan 3.4483\nPoplan 3.4483\nRed Alder 3.4483\nRed Elm 3.4483\nRed Oak 6.8966\nSassafras 3.4483\nSoft Maple 3.4483\nSycamore 3.4483\nWhite Oak 10.3448\nWillow 3.4483\nYellow Birch 3.4483\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\n#include <iomanip>\n#include <map>\nusing namespace std;\n \nint main() {\n int n;\n string s;\n cin >> n;\n getline(cin, s); //clear buffer\n getline(cin, s); //blank line\n while (n--){\n map <string, int> mp;\n int sum = 0;\n while (getline(cin, s) && s != \"\"){\n mp[s]++;\n sum++;\n }\n for (auto i: mp){\n cout << i.first << \" \" <<\n fixed << setprecision(4) << (double)i.second / sum * 100 << \"\\n\";\n }\n cout << \"\\n\";\n }\n return 0;\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **10235 Simply Emirp**\n\n*An integer greater than 1 is called a prime number if its only positive divisors (factors) are 1 and itself.* Prime numbers have been studied over the years by a lot of mathematicians. Applications of prime numbers arise in Cryptography and Coding Theory among others. \nHave you tried reversing a prime? For most primes, you get a composite (43 becomes 34). *An* *Emirp (Prime spelt backwards) is a Prime that gives you a different Prime when its digits are reversed.* For example, 17 is *Emirp* because 17 as well as 71 are Prime. \nIn this problem, you have to decide whether a number *N* is Non-prime or Prime or *Emirp* . Assume that 1 *< N <* 1000000.\nInterestingly, Emirps are not new to NTU students. We have been boarding 199 and 179 buses for quite a long time!\n\n**Input**\n\nInput consists of several lines specifying values for *N* .\n\n**Output**\n\nFor each *N* given in the input, output should contain one of the following:\n\n1. ‘ *N* `is not prime.` ’, if *N* is not a Prime number.\n\n2. ‘ *N* `is prime.` ’, if *N* is Prime and *N* is not *Emirp* .\n\n3. ‘ *N* `is emirp.` ’, if *N* is *Emirp* .\n\n**Sample Input**\n```\n17\n18\n19\n179\n199\n\n```\n**Sample Output**\n```\n17 is emirp.\n18 is not prime.\n19 is prime.\n179 is emirp.\n199 is emirp.\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\nusing namespace std;\nint p[1000005];\n \nint main() {\n p[1] = 1;\n for (int i = 2; i < 1000005; i++){\n if (p[i] == 0){\n for (int j = i+i; j < 1000005; j+=i){\n p[j] = 1;\n }\n }\n }\n int N, N1, N2;\n while (cin >> N){\n N1 = N;\n N2 = 0;\n while (N1){\n N2 *= 10;\n N2 += N1 % 10;\n N1 /= 10;\n }\n if (p[N]) cout << N << \" is not prime.\\n\";\n else if (N2 != N && p[N2] == 0) cout << N << \" is emirp.\\n\";\n else cout << N << \" is prime.\\n\";\n }\n return 0;\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **10242 Fourth Point!!**\n\nGiven are the ( *x, y* ) coordinates of the endpoints of two adjacent sides of a parallelogram. Find the ( *x, y* ) coordinates of the fourth point.\n\n**Input**\n\nEach line of input contains eight floating point numbers: the ( *x, y* ) coordinates of one of the endpoints of the first side followed by the ( *x, y* ) coordinates of the other endpoint of the first side, followed by the ( *x, y* ) coordinates of one of the endpoints of the second side followed by the ( *x, y* ) coordinates of the other endpoint of the second side. All coordinates are in meters, to the nearest mm. All coordinates are between *−* 10000 and +10000. Input is terminated by end of file.\n\n**Output**\n\nFor each line of input, print the ( *x, y* ) coordinates of the fourth point of the parallelogram in meters, to the nearest mm, separated by a single space.\n\n**Sample Input**\n```\n0.000 0.000 0.000 1.000 0.000 1.000 1.000 1.000\n1.000 0.000 3.500 3.500 3.500 3.500 0.000 1.000\n1.866 0.000 3.127 3.543 3.127 3.543 1.412 3.145\n\n```\n**Sample Output**\n```\n1.000 0.000\n-2.500 -2.500\n0.151 -0.398\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\n#include <iomanip>\nusing namespace std;\n \nint main() {\n double x[4], y[4];\n double x1, y1, x2, y2, x3, y3;\n while (cin >> x[0] >> y[0] >> x[1] >> y[1] >> x[2] >> y[2] >> x[3] >> y[3]){\n if (x[1] == x[2] && y[1] == y[2]){\n x1 = x[0]; y1 = y[0];\n x2 = x[1]; y2 = y[1];\n x3 = x[3]; y3 = y[3];\n } else if (x[0] == x[2] && y[0] == y[2]){\n x1 = x[1]; y1 = y[1];\n x2 = x[0]; y2 = y[0];\n x3 = x[3]; y3 = y[3];\n } else if (x[0] == x[3] && y[0] == y[3]){\n x1 = x[1]; y1 = y[1];\n x2 = x[0]; y2 = y[0];\n x3 = x[2]; y3 = y[2];\n } else if (x[1] == x[3] && y[1] == y[3]){\n x1 = x[0]; y1 = y[0];\n x2 = x[1]; y2 = y[1];\n x3 = x[2]; y3 = y[2];\n }\n cout << fixed << setprecision(3)\n << x3 + x1 - x2 << \" \" << y3 + y1 - y2 << \"\\n\";\n }\n return 0;\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **10252 Common Permutation**\n\nGiven two strings of lowercase letters, *a* and *b*, print the longest string *x* of lowercase letters such that there is a permutation of *x* that is a subsequence of *a* and there is a permutation of *x* that is a subsequence of *b* .\n\n**Input**\n\nInput file contains several lines of input. Consecutive two lines make a set of input. That means in the input file line 1 and 2 is a set of input, line 3 and 4 is a set of input and so on. The first line of a pair contains *a* and the second contains *b* . Each string is on a separate line and consists of at most 1000 lowercase letters.\n\n**Output**\n\nFor each set of input, output a line containing *x* . If several *x* satisfy the criteria above, choose the first one in alphabetical order.\n\n**Sample Input**\n```\npretty\nwomen\nwalking\ndown\nthe\nstreet\n\n```\n**Sample Output**\n```\ne\nnw\net\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\nusing namespace std;\n \nstring a, b;\nint cnta[26], cntb[26];\n \nint main() {\n while (cin >> a >> b){\n for (int i = 0; i < 26; i++){\n cnta[i] = 0;\n cntb[i] = 0;\n }\n for (int i = 0; i < a.length(); i++){\n cnta[a[i]-'a']++;\n }\n for (int i = 0; i < b.length(); i++){\n cntb[b[i]-'a']++;\n }\n for (int i = 0; i < 26; i++){\n for (int j = min(cnta[i], cntb[i]); j > 0; j--){\n cout << (char)('a'+i);\n }\n }\n cout << \"\\n\";\n }\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **10268 498-bis**\n\nLooking throw the “Online Judge’s Problem Set Archive” I found a very interesting problem number 498, titled “Polly the Polynomial”. Frankly speaking, I did not solve it, but I derived from it this problem. \nEverything in this problem is a derivative of something from 498. In particular, 498 was “ *... designed* *to help you remember ... basic algebra skills, make the world a better place, etc., etc.”* . This problem is designed to help you remember basic derivation algebra skills, increase the speed in which world becomes a better place, etc., etc. \nIn 498 you had to evaluate the values of polynomial\n\n*a* 0 *x* <sup>n</sup> + *a* 1 *x* <sup>n-1</sup> + *. . .* + *a* *n−* 1 *x* + *a* *n* *.*\n\nIn this problem you should evaluate its derivative. Remember that derivative is defined as\n\n*a* 0 *nx* <sup>n-1</sup> + *a* 1 ( *n −* 1) *x* <sup>n-2</sup> + *. . .* + *a* *n−* 1 *.*\n\nAll the input and output data will fit into integer, i.e. its absolute value will be less than 2 [31] .\n\n**Input**\n\nYour program should accept an even number of lines of text. Each pair of lines will represent one problem. The first line will contain one integer - a value for *x* . The second line will contain a list of integers *a* 0, *a* 1, ..., *a* *n−* 1, *a* *n*, which represent a set of polynomial coefficients. \nInput is terminated by \\<EOF>.\n\n**Output**\n\nFor each pair of lines, your program should evaluate the derivative of polynomial for the given value *x* and output it in a single line.\n\n**Sample Input**\n```\n7\n1 -1\n2\n1 1 1\n\n```\n**Sample Output**\n```\n1\n5\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\n#include <string>\n#include <sstream>\n#include <vector>\n#include <algorithm>\nusing namespace std;\n \nstring s;\nint x;\nvector <int> v;\n \nint main() {\n while (cin >> x){\n getline(cin, s);\n getline(cin, s);\n //cout << \"s: \" << s << \"\\n\";\n stringstream ss(s);\n v.clear();\n while (ss >> s){\n v.push_back(stoi(s));\n }\n v.pop_back();\n reverse(v.begin(), v.end());\n long long mul = 1;\n int ans = 0;\n for (int i = 0; i < v.size(); i++){\n //cout << \"i: \" << i << \" \" << v[i] << \" \" << ans << \" \" << mul << \"\\n\";\n ans += v[i]*(i+1)*mul;\n mul *= x;\n }\n cout << ans << \"\\n\";\n }\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **10409 Die Game**\n\nLife is not easy. Sometimes it is beyond your control. Now, as contestants of ACM ICPC, you might be just tasting the bitter of life. But don’t worry! Do not look only on the dark side of life, but look also on the bright side. Life may be an enjoyable game of chance, like throwing dice. Do or die! Then, at last, you might be able to find the route to victory. \nThis problem comes from a game using a die. By the way, do you know a die? It has nothing to do with ”death.” A die is a cubic object with six faces, each of which represents a different number from one to six and is marked with the corresponding number of spots. Since it is usually used in pair, ”a die” is a rarely used word. You might have heard a famous phrase ”the die is cast,” though.\n\nWhen a game starts, a die stands still on a flat table. During the game, the die is tumbled in all directions by the dealer. You will win the game if you can predict the number seen on the top face at the time when the die stops tumbling. \nNow you are requested to write a program that simulates the rolling of a die. For simplicity, we assume that the die neither slips nor jumps but just rolls on the table in four directions, that is, north, east, south, and west. At the beginning of every game, the dealer puts the die at the center of the table and adjusts its direction so that the numbers one, two, and three are seen on the top, north, and west faces, respectively. For the other three faces, we do not explicitly specify anything but tell you the golden rule: the sum of the numbers on any pair of opposite faces is always seven. \nYour program should accept a sequence of commands, each of which is either “north”, “east”, “south”, or “west”. A “north” command tumbles the die down to north, that is, the top face becomes the new north, the north becomes the new bottom, and so on. More precisely, the die is rotated around its north bottom edge to the north direction and the rotation angle is 90 degrees. Other commands also tumble the die accordingly to their own directions. Your program should calculate the number finally shown on the top after performing the commands in the sequence. Note that the table is sufficiently large and the die never falls off during the game.\n\n**Input**\n\nThe input consists of one or more command sequences, each of which corresponds to a single game. The first line of a command sequence contains a positive integer, representing the number of the following command lines in the sequence. You may assume that this number is less than or equal to 1024. A line containing a zero indicates the end of the input. Each command line includes a command that is one of ‘ `north` ’, ‘ `east` ’, ‘ `south` ’, and ‘ `west` ’. You may assume that no white space occurs in any lines.\n\n**Output**\n\nFor each command sequence, output one line containing solely the number on the top face at the time when the game is finished.\n\n**Sample Input**\n```\n1\nnorth\n3\nnorth\neast\nsouth\n0\n\n```\n**Sample Output**\n```\n5\n1\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\n#include <map>\nusing namespace std;\n \nint main() {\n int n;\n string s;\n while (cin >> n){\n if (n == 0) break;\n map <string, int> mp;\n mp[\"top\"] = 1;\n mp[\"north\"] = 2;\n mp[\"west\"] = 3;\n mp[\"east\"] = 4;\n mp[\"south\"] = 5;\n mp[\"bottom\"] = 6;\n \n while (n--){\n cin >> s;\n if (s == \"east\"){\n int tmp = mp[\"east\"];\n mp[\"east\"] = mp[\"top\"];\n mp[\"top\"] = mp[\"west\"];\n mp[\"west\"] = mp[\"bottom\"];\n mp[\"bottom\"] = tmp;\n }\n if (s == \"south\"){\n int tmp = mp[\"south\"];\n mp[\"south\"] = mp[\"top\"];\n mp[\"top\"] = mp[\"north\"];\n mp[\"north\"] = mp[\"bottom\"];\n mp[\"bottom\"] = tmp;\n }\n if (s == \"west\"){\n int tmp = mp[\"west\"];\n mp[\"west\"] = mp[\"top\"];\n mp[\"top\"] = mp[\"east\"];\n mp[\"east\"] = mp[\"bottom\"];\n mp[\"bottom\"] = tmp;\n }\n if (s == \"north\"){\n int tmp = mp[\"north\"];\n mp[\"north\"] = mp[\"top\"];\n mp[\"top\"] = mp[\"south\"];\n mp[\"south\"] = mp[\"bottom\"];\n mp[\"bottom\"] = tmp;\n }\n }\n cout << mp[\"top\"] << \"\\n\";\n }\n return 0;\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **10415 Eb Alto Saxophone Player**\n\nDo you like saxophone? I have a Eb Alto Saxophone, shown on the right.\n\nMy fingers move A LOT when playing some music, and I’m quite interested in how many times each finger PRESS the button. Assume that the music is composed of only 8 kinds of note. They are: C D E F G A B in one octave and C D E F G A B in a higher octave. We use c,d,e,f,g,a,b,C,D,E,F,G,A,B to represent them. The fingers I use for each note are:\n\n - c: finger 2 *∼* 4, 7 *∼* 10\n\n - d: finger 2 *∼* 4, 7 *∼* 9\n\n - e: finger 2 4, 7, 8\n\n - f: finger 2 4, 7\n\n - g: finger 2 *∼* 4\n\n - a: finger 2, 3\n\n - b: finger 2\n\n - C: finger 3\n\n - D: finger 1 *∼* 4, 7 *∼* 9\n\n - E: finger 1 4, 7, 8\n\n - F: finger 1 4, 7\n\n - G: finger 1 *∼* 4\n\n - A: finger 1 *∼* 3\n\n - B: finger 1 *∼* 2\n\n(Note that every finger is controlling a specified button, different fingers are controlling different buttons.) \nWrite a program to help count the number of times each finger presses the button. A finger presses a button if it is needed in a note, but not used in the last note. Also, if it is the first note, every finger required presses the button.\n\n**Input**\n\nThe first line of the input is a single integer *t* (1 *≤* *t ≤* 1000), indicating the number of test cases. For each case, there is only one line containing the song. The only allowed characters are {‘ `c` ’,‘ `d` ’,‘ `e` ’,‘ `f` ’,‘ `g` ’,‘ `a` ’,‘ `b` ’, ‘ `C'`,‘ `D` ’,‘ `E` ’,‘ `F` ’,‘ `G` ’,‘ `A` ’,‘ `B` ’}. There are at most 200 notes in a song, and the song maybe empty.\n\n**Output**\n\nFor each test case, print 10 numbers indicating the number of presses for each finger. Numbers are separated by a single space.\n\n**Sample Input**\n```\n3\ncdefgab\nBAGFEDC\nCbCaDCbCbCCbCbabCCbCbabae\n\n```\n**Sample Output**\n```\n0 1 1 1 0 0 1 1 1 1\n1 1 1 1 0 0 1 1 1 0\n1 8 10 2 0 0 2 2 1 0\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\n#include <map>\n#include <vector>\nusing namespace std;\n \nint main() {\n map <char, vector<int> > mp;\n mp['c'] = {0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1};\n mp['d'] = {0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0};\n mp['e'] = {0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0};\n mp['f'] = {0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0};\n mp['g'] = {0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0};\n mp['a'] = {0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0};\n mp['b'] = {0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0};\n mp['C'] = {0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0};\n mp['D'] = {0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0};\n mp['E'] = {0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0};\n mp['F'] = {0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0};\n mp['G'] = {0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0};\n mp['A'] = {0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0};\n mp['B'] = {0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0};\n \n int t;\n string s;\n cin >> t;\n getline(cin, s); //clear buffer\n while (t--){\n getline(cin, s);\n int cnt[11] = {0};\n int a[11] = {0}; //status\n for (int i = 0; i < s.size(); i++){\n for (int j = 1; j <= 10; j++){\n if (mp[s[i]][j]){\n if (a[j]) continue;\n else {\n a[j] = 1;\n cnt[j]++;\n }\n } else {\n a[j] = 0;\n }\n }\n }\n for (int i = 1; i <= 10; i++){\n cout << cnt[i] << \" \";\n }\n cout << \"\\n\";\n }\n return 0;\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **10420 List of Conquests**\n\nIn Act I, Leporello is telling Donna Elvira about his master’s long list of conquests:\n\n“This is the list of the beauties my master has loved, a list I’ve made out myself: take a look, read it with me. In Italy six hundred and forty, in Germany two hundred and thirty-one, a hundred in France, ninety-one in Turkey; but in Spain already a thousand and three! Among them are country girls, waiting-maids, city beauties; there are countesses, baronesses, marchionesses, princesses: women of every rank, of every size, of every age.” (Madamina, il catalogo questo)\n\nAs Leporello records all the “beauties” Don Giovanni “loved” in chronological order, it is very troublesome for him to present his master’s conquest to others because he needs to count the number of “beauties” by their nationality each time. You are to help Leporello to count.\n\n**Input**\n\nThe input consists of at most 2000 lines. The first line contains a number *n*, indicating that there will be *n* more lines. Each following line, with at most 75 characters, contains a country (the first word) and the name of a woman (the rest of the words in the line) Giovanni loved. You may assume that the name of all countries consist of only one word.\n\n**Output**\n\nThe output consists of lines in alphabetical order. Each line starts with the name of a country, followed by the total number of women Giovanni loved in that country, separated by a space.\n\n**Sample Input**\n```\n3\nSpain Donna Elvira\nEngland Jane Doe\nSpain Donna Anna\n\n```\n**Sample Output**\n```\nEngland 1\nSpain 2\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\n#include <sstream>\n#include <map>\nusing namespace std;\n \nint main() {\n int n;\n cin >> n;\n map <string, int> mp;\n string s;\n getline(cin, s);\n while (n--) {\n getline(cin, s);\n stringstream ss(s);\n ss >> s;\n mp[s]++;\n }\n for (auto i: mp) {\n cout << i.first << \" \" << i.second << \"\\n\";\n }\n return 0;\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **10642 Can You Solve It?**\n\nFirst take a look at the following picture. In this picture, each circle has a coordinate according to Cartesian Coordinate System. You can move from one circle to another following the path denoted by forward arrow symbols. To go from a source circle to a destination circle,\n\n*total* _ *number* _ *of* _ *step* ( *s* )_ *needed* = *number* _ *of* _ *intermediate* _ *circles* _ *you* _ *pass* + 1\n\nFor example, to go from (0 *,* 3) to (3 *,* 0) you have to pass two intermediate circles (1 *,* 2) and (2 *,* 1). So, in this case, total number of steps needed is 2 + 1 = 3. In this problem, you are to calculate number of step(s) needed for a given source circle and a destination circle. You can assume that, it is not possible to go back using the reverse direction of the arrows.\n\n**Input**\n\nThe first line in the input is the number of test cases *n* (0 *< n ≤* 500) to handle. Following there are *n* lines each containing four integers (0 *≤* *each* _ *integer ≤* 100000) the first pair of which represents the coordinates of the source circle and the other represents that of the destination circle. The coordinates are listed in a form ( *x, y* ).\n\n**Output**\n\nFor each pair of integers your program should output the case number first and then the number of step(s) to reach the destination from the source. You may assume that it is always possible to reach the destination circle from the source circle.\n\n**Sample Input**\n```\n3\n0 0 0 1\n0 0 1 0\n0 0 0 2\n\n```\n**Sample Output**\n```\nCase 1: 1\nCase 2: 2\nCase 3: 3\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\nusing namespace std;\n \nint main() {\n int T;\n long long x, y, n, step1, step2;\n cin >> T;\n for (int Case = 1; Case <= T; Case++){\n cout << \"Case \" << Case << \": \";\n cin >> x >> y;\n if (x == 0 && y == 0) step1 = 0;\n else {\n n = x + y - 1;\n step1 = (n * n + 3 * n) / 2 + (x + 1);\n }\n cin >> x >> y;\n n = x + y - 1;\n if (x == 0 && y == 0) step2 = 0;\n else {\n n = x + y - 1;\n step2 = (n * n + 3 * n) / 2 + (x + 1);\n }\n cout << step2 - step1 << \"\\n\";\n }\n return 0;\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **10783 Odd Sum**\n\nGiven a range [ *a, b* ], you are to find the summation of all the odd integers in this range. For example, the summation of all the odd integers in the range [3 *,* 9] is 3 + 5 + 7 + 9 = 24.\n\n**Input**\n\nThere can be at multiple test cases. The first line of input gives you the number of test cases, *T* (1 *≤* *T ≤* 100). Then T test cases follow. Each test case consists of 2 integers *a* and *b* (0 *≤* *a ≤* *b ≤* 100) in two separate lines.\n\n**Output**\n\nFor each test case you are to print one line of output – the serial number of the test case followed by the summation of the odd integers in the range [ *a, b* ].\n\n**Sample Input**\n```\n2\n1\n5\n3\n5\n\n```\n**Sample Output**\n```\nCase 1: 9\nCase 2: 8\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include<iostream>\nusing namespace std;\n \nint main(){\n int T;\n cin >> T;\n for (int i = 1; i <= T; i++) {\n int a, b;\n cin >> a >> b;\n if (a % 2 == 0) {\n a += 1;\n }\n if (b % 2 == 0) {\n b -= 1;\n }\n int num=(b-a)/2+1;\n int total;\n total=(a+b)/2*num;\n cout << \"Case \" << i << \": \";\n cout << (a + b) / 2 * ((b - a) / 2 + 1) << \"\\n\";\n }\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **10812 Beat the Spread!**\n\nSuperbowl Sunday is nearly here. In order to pass the time waiting for the half-time commercials and wardrobe malfunctions, the local hackers have organized a betting pool on the game. Members place their bets on the sum of the two final scores, or on the absolute difference between the two scores.\n\nGiven the winning numbers for each type of bet, can you deduce the final scores?\n\n**Input**\n\nThe first line of input contains *n*, the number of test cases. *n* lines follow, each representing a test case. Each test case gives *s* and *d*, non-negative integers representing the sum and (absolute) difference between the two final scores.\n\n**Output**\n\nFor each test case, output a line giving the two final scores, largest first. If there are no such scores, output a line containing “ `impossible` ”. Recall that football scores are always non-negative integers.\n\n**Sample Input**\n```\n2\n40 20\n20 40\n\n```\n**Sample Output**\n```\n30 10\nimpossible\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\nusing namespace std;\n \nint main() {\n int T, s, d;\n cin >> T;\n while (T--){\n cin >> s >> d;\n if ((s + d) % 2 || s < d) cout << \"impossible\\n\";\n else {\n cout << (s+d)/2 << \" \" << (s-d)/2 << \"\\n\";\n }\n }\n return 0;\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **10908 Largest Square**\n\nGiven a rectangular grid of characters you have to find out the length of a side of the largest square such that all the characters of the square are same and the center [intersecting point of the two diagonals] of the square is at location ( *r, c* ). The height and width of the grid is *M* and *N* respectively. Upper left corner and lower right corner of the grid will be denoted by (0, 0) and ( *M −* 1 *, N −* 1) respectively. Consider the grid of characters given below. Given the location (1, 2) the length of a side of the largest square is 3.\n```\nabbbaaaaaa\nabbbaaaaaa\nabbbaaaaaa\naaaaaaaaaa\naaaaaaaaaa\naaccaaaaaa\naaccaaaaaa\n\n```\n**Input**\n\nThe input starts with a line containing a single integer *T* ( *<* 21). This is followed by *T* test cases. The first line of each of them will contain three integers *M*, *N* and *Q* ( *<* 21) separated by a space where *M*, *N* denotes the dimension of the grid. Next follows *M* lines each containing *N* characters. Finally, there will be *Q* lines each containing two integers *r* and *c* . The value of *M* and *N* will be at most 100.\n\n**Output**\n\nFor each test case in the input produce *Q* + 1 lines of output. In the first line print the value of *M*, *N* and *Q* in that order separated by single space. In the next *Q* lines, output the length of a side of the largest square in the corresponding grid for each ( *r, c* ) pair in the input.\n\n**Sample Input**\n```\n1\n7 10 4\nabbbaaaaaa\nabbbaaaaaa\nabbbaaaaaa\naaaaaaaaaa\naaaaaaaaaa\naaccaaaaaa\naaccaaaaaa\n1 2\n2 4\n4 6\n5 2\n\n```\n**Sample Output**\n```\n7 10 4\n3\n1\n5\n1\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\n#include <cstring>\n#include <algorithm>\nusing namespace std;\n \nint t, m, n, q, a[105][105], mx[105][105], x, y, ans;\nchar c;\n \nint main() {\n memset(a, -1, sizeof(a));\n cin >> t;\n while (t--){\n cin >> m >> n >> q;\n for (int i = 0; i < m; i++){\n for (int j = 0; j < n; j++){\n cin >> c;\n a[i][j] = (int)c;\n if (i == 0 || j == 0) mx[i][j] = 1;\n else if (a[i][j] == a[i-1][j] && a[i][j] == a[i-1][j-1] && a[i][j] == a[i][j-1]){\n mx[i][j] = min({mx[i-1][j], mx[i-1][j-1], mx[i][j-1]})+1 ;\n }\n else mx[i][j] = 1;\n }\n }\n cout << m << \" \" << n << \" \" << q << \"\\n\";\n while (q--){\n cin >> x >> y;\n ans = 1;\n for (int i = 1; i <= 100; i++){\n if (x+i > m || y+i > n) break;\n if (mx[x+i][y+i] >= ans+2) ans += 2;\n else break;\n }\n cout << ans << \"\\n\";\n }\n }\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **10922 2 the 9s**\n\nA well-known trick to know if an integer *N* is a multiple of nine is to compute the sum *S* of its digits. If *S* is a multiple of nine, then so is *N* . This is a recursive test, and the depth of the recursion needed to obtain the answer on *N* is called the 9-degree of *N* . \nYour job is, given a positive number *N*, determine if it is a multiple of nine and, if it is, its 9-degree.\n\n**Input**\n\nThe input is a file such that each line contains a positive number. A line containing the number 0 is the end of the input. The given numbers can contain up to 1000 digits.\n\n**Output**\n\nThe output of the program shall indicate, for each input number, if it is a multiple of nine, and in case it is, the value of its nine-degree. See the sample output for an example of the expected formatting of the output.\n\n**Sample Input**\n```\n999999999999999999999\n9\n9999999999999999999999999999998\n0\n\n```\n**Sample Output**\n```\n999999999999999999999 is a multiple of 9 and has 9-degree 3.\n9 is a multiple of 9 and has 9-degree 1.\n9999999999999999999999999999998 is not a multiple of 9.\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\nusing namespace std;\n \nint func(string s, int count){\n int temp = 0, total = 0;\n for (int i = 0; i < s.length(); i++){\n temp = s[i] - '0';\n total += temp;\n }\n count++;\n if (total == 9){\n return count;\n }else if(total < 9){\n return 0;\n }else{\n return func(to_string(total), count);\n }\n}\nint main(){\n int ans;\n string s;\n while (cin >> s){\n if (s == \"0\") break;\n ans = func(s, 0);\n if (ans == 0){\n cout << s << \" is not a multiple of 9.\\n\";\n }else{\n cout << s << \" is a multiple of 9 and has 9-degree \" << ans << \".\\n\";\n }\n }\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **10929 You can say 11**\n\nYour job is, given a positive number *N*, determine if it is a multiple of eleven.\n\n**Input**\n\nThe input is a file such that each line contains a positive number. A line containing the number ‘ `0` ’ is the end of the input. The given numbers can contain up to 1000 digits.\n\n**Output**\n\nThe output of the program shall indicate, for each input number, if it is a multiple of eleven or not.\n\n**Sample Input**\n```\n112233\n30800\n2937\n323455693\n5038297\n112234\n0\n\n```\n**Sample Output**\n```\n112233 is a multiple of 11.\n30800 is a multiple of 11.\n2937 is a multiple of 11.\n323455693 is a multiple of 11.\n5038297 is a multiple of 11.\n112234 is not a multiple of 11.\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\nusing namespace std;\n \nint main() {\n string s;\n while (cin >> s) {\n if (s == \"0\") break;\n int odd = 0, even = 0;\n for (int i = 0; i < s.size(); i++) {\n if (i % 2) {\n odd += s[i] - '0';\n } else {\n even += s[i] - '0';\n }\n }\n if ((odd - even) % 11 == 0) {\n cout << s << \" is a multiple of 11.\\n\";\n } else {\n cout << s << \" is not a multiple of 11.\\n\";\n }\n }\n return 0;\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **10931 Parity**\n\nWe define the parity of an integer *n* as the sum of the bits in binary representation computed modulo two. As an example, the number 21 = 10101 2 has three 1s in its binary representation so it has parity 3(mod2), or 1. \nIn this problem you have to calculate the parity of an integer 1 *≤* *I ≤* 2147483647.\n\n**Input**\n\nEach line of the input has an integer *I* and the end of the input is indicated by a line where *I* = `0` that should not be processed.\n\n**Output**\n\nFor each integer *I* in the inputt you should print a line ‘ `The parity of` *B* `is` *P* `(mod 2).` ’, where *B* is the binary representation of *I* .\n\n**Sample Input**\n```\n1\n2\n10\n21\n0\n\n```\n**Sample Output**\n```\nThe parity of 1 is 1 (mod 2).\nThe parity of 10 is 1 (mod 2).\nThe parity of 1010 is 2 (mod 2).\nThe parity of 10101 is 3 (mod 2).\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\n#include <algorithm>\nusing namespace std;\n \nint main() {\n int I, n;\n while (cin >> I) {\n if (I == 0) break;\n string B = \"\";\n n = I;\n int cnt = 0;\n while (n){\n cnt += (n & 1);\n B += '0' + (n & 1);\n n >>= 1;\n }\n reverse(B.begin(), B.end());\n cout << \"The parity of \" << B << \" is \" << cnt << \" (mod 2).\\n\";\n }\n return 0;\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **11005 Cheapest Base**\n\nWhen printing text on paper we need ink. But not every character needs the same amount of ink to print: letters such as ’W’, ’M’ and ’8’ are more expensive than thinner letters as ’i’, ’c’ and ’1’. In this problem we will evaluate the cost of printing numbers in several bases. \nAs you know, numbers can be expressed in several different bases. Well known bases are binary (base 2; digits 0 and 1), decimal (base 10; digits 0 to 9) and hexadecimal (base 16; digits 0 to 9 and letters A to F). For the general base *n* we will use the first *n* characters of the string “0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ”, which means the highest base in this problem is 36. The lowest base is of course 2.\nEvery character from this string has an associated cost, represented by an integer value between 1 and 128. The cost to print a number in a certain base is the sum of the costs of all characters needed to represent that number. For the numbers given in the input, you will have to calculate the cheapest base(s) to represent this number in. Numbers in any base are printed without leading zeros.\n\n**Input**\n\nThe input has less than 25 test cases. The first line of input file denotes this number of test cases. The description of every test case is given below: \nThe first 4 lines of every case contain 9 integers each: the costs of the 36 characters in the order given above. Then follows the number of queries on a line by itself. Every query appears on a line by itself and is formed by a number between 0 and 2000000000 in decimal format.\n\n**Output**\n\nFor every case in the input, print one line ‘ `Case` *X* `:` ’, without the quotes, where *X* is the case number starting from 1. \nFor every query within a case print one line ‘ `Cheapest base(s) for number` *Y* `:` ’ followed by the cheapest base(s) in increasing order, separated by one space. *Y* is the query in decimal format. Print a blank line between cases. \nThe numbers in the second sample output are actually all in one line just like the first sample output. Due to lack of horizontal space they are shown broken in two lines.\n\n**Sample Input**\n```\n2\n10 8 12 13 15 13 13 16 9\n11 18 24 21 23 23 23 13 15\n17 33 21 23 27 26 27 19 4\n22 18 30 30 24 16 26 21 21\n5\n98329921\n12345\n800348\n14\n873645\n1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1\n4\n0\n1\n10\n100\n\n```\n**Sample Output**\n```\nCase 1:\nCheapest base(s) for number 98329921: 24\nCheapest base(s) for number 12345: 13 31\nCheapest base(s) for number 800348: 31\nCheapest base(s) for number 14: 13\nCheapest base(s) for number 873645: 22\nCase 2:\nCheapest base(s) for number 0: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19\n20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36\nCheapest base(s) for number 1: 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19\n20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36\nCheapest base(s) for number 10: 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25\n26 27 28 29 30 31 32 33 34 35 36\nCheapest base(s) for number 100: 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25\n26 27 28 29 30 31 32 33 34 35 36\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\n#include <map>\nusing namespace std;\n \nint main() {\n int T, cost, Q, x;\n cin >> T;\n for (int Case = 1; Case <= T; Case++){\n if (Case > 1) cout << \"\\n\";\n map <int, int> mp;\n for (int i = 0; i < 36; i++){\n cin >> cost;\n mp[i] = cost;\n }\n cout << \"Case \" << Case << \":\\n\";\n cin >> Q;\n while (Q--){\n cin >> x;\n cout << \"Cheapest base(s) for number \" << x << \":\";\n int mn = 0x7FFFFFFF;\n map <int,int> ans;\n for (int i = 2; i <= 36; i++){\n int n = x;\n cost = 0;\n while (n){\n cost += mp[n % i];\n n /= i;\n }\n ans[i] = cost;\n mn = min(mn, cost);\n }\n for (int i = 2; i <= 36; i++){\n if (ans[i] == mn) cout << \" \" << i;\n }\n cout << \"\\n\";\n }\n }\n return 0;\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **11063 B2-Sequence**\n\nA B2-Sequence is a sequence of positive integers 1 *≤* *b*1 *< b*2 *< b*3 *. . .* such that all pairwise sums *bi* + *bj*, where *i ≤* *j*, are different. Your task is to determine if a given sequence is a B2-Sequence or not.\n\n**Input**\n\nEach test case starts with 2 *≤* *N ≤* 100, the number of elements in a sequence. Next line will have *N* integers, representing the value of each element in the sequence. Each element *b* *i* is an integer such that *bi* *≤* 10000. There is a blank line after each test case. The input is terminated by end of file (EOF).\n\n**Output**\n\nFor each test case you must print the number of the test case, starting from 1, and a message indicating if the corresponding sequence it is a B2-Sequence or not. See the sample output below. After each test case you must print a blank line.\n\n**Sample Input**\n```\n4\n1 2 4 8\n4\n3 7 10 14\n\n```\n**Sample Output**\n```\nCase #1: It is a B2-Sequence.\nCase #2: It is not a B2-Sequence.\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\nusing namespace std;\n#define maxn 20005\n \nint main() {\n int n, Case = 1;\n while (cin >> n) {\n int b[n], sum[maxn];\n for (int i = 0; i < n; i++) {\n cin >> b[i];\n }\n for (int i = 0; i < maxn; i++) {\n sum[i] = 0;\n }\n bool flag = true;\n for (int i = 0; i < n; i++) {\n for (int j = i; j < n; j++) {\n int x = b[i] + b[j];\n if (sum[x]) {\n flag = false;\n break;\n } else {\n sum[x] = 1;\n }\n }\n if (!flag) break;\n }\n if (flag) cout << \"Case #\" << Case++ << \": It is a B2-Sequence.\\n\\n\";\n else cout << \"Case #\" << Case++ << \": It is not a B2-Sequence.\\n\\n\";\n }\n return 0;\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **11150 Cola**\n\nYou see the following special offer by the convenience store:\n\n*“A bottle of Choco Cola for every 3 empty bottles returned”*\n\nNow you decide to buy some (say *N* ) bottles of cola from the store. You would like to know how you can get the most cola from them. \nThe figure below shows the case where *N* = 8. *Method 1* is the standard way: after finishing your 8 bottles of cola, you have 8 empty bottles. Take 6 of them and you get 2 new bottles of cola. Now after drinking them you have 4 empty bottles, so you take 3 of them to get yet another new cola. Finally, you have only 2 bottles in hand, so you cannot get new cola any more. Hence, you have enjoyed 8 + 2 + 1 = 11 bottles of cola. \nYou can actually do better! In *Method 2*, you first borrow an empty bottle from your friend (?! Or the storekeeper??), then you can enjoy 8 + 3 + 1 = 12 bottles of cola! Of course, you will have to return your remaining empty bottle back to your friend.\n\n**Input**\n\nInput consists of several lines, each containing an integer *N* (1 *≤* *N ≤* 200).\n\n**Output**\n\nFor each case, your program should output the maximum number of bottles of cola you can enjoy. You may borrow empty bottles from others, but if you do that, make sure that you have enough bottles afterwards to return to them.\n\n**Note:** Drinking too much cola is bad for your health, so... don’t try this at home!! :-)\n\n**Sample Input**\n```\n8\n\n```\n**Sample Output**\n```\n12\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\nusing namespace std;\n \nint main() {\n int N;\n while (cin >> N){\n int ans = N;\n while (N >= 3){\n ans += N / 3;\n N = N / 3 + N % 3;\n }\n ans += (N == 2);\n cout << ans << \"\\n\";\n }\n return 0;\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **11321 Sort! Sort!! And Sort!!!**\n\nHmm! Here you are asked to do a simple sorting. You will be given *N* numbers and a positive integer *M* . You will have to sort the *N* numbers in ascending order of their modulo *M* value. If there is a tie between an odd number and an even number (that is their modulo *M* value is the same) then the odd number will precede the even number. If there is a tie between two odd numbers (that is their modulo *M* value is the same) then the larger odd number will precede the smaller odd number and if there is a tie between two even numbers (that is their modulo *M* value is the same) then the smaller even number will precede the larger even number. For remainder value of negative numbers follow the rule of C programming language: A negative number can never have modulus greater than zero. E.g. `-100 MOD 3 = -1, -100 MOD 4 = 0`, etc.\n\n**Input**\n\nThe input file contains 20 sets of inputs. Each set starts with two integers *N* (0 *< N ≤* 10000) and *M* (0 *< M ≤* 10000) which denotes how many numbers are within this set. Each of the next *N* lines contains one number each. These numbers should all fit in 32-bit signed integer. Input is terminated by a line containing two zeroes.\n\n**Output**\n\nFor each set of input produce *N* + 1 lines of outputs. The first line of each set contains the value of *N* and *M* . The next *N* lines contain *N* numbers, sorted according to the rules mentioned above. Print the last two zeroes of the input file in the output file also.\n\n**Sample Input**\n```\n15 3\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n0 0\n\n```\n**Sample Output**\n```\n15 3\n15\n9\n3\n6\n12\n13\n7\n1\n4\n10\n11\n5\n2\n8\n14\n0 0\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\n#include <algorithm>\nusing namespace std;\nint N, M;\n \nbool cmp(int x, int y){\n if ((x % M) != (y % M)){\n return (x % M) < (y % M);\n } else {\n if ((x % 2) * (y % 2)){\n return x > y;\n } else if ((x % 2 == 0) && (y % 2 == 0)){\n return x < y;\n } else {\n return (x % 2);\n }\n }\n}\n \nint main() {\n while (cin >> N >> M){\n if (N == 0 && M == 0){\n cout << \"0 0\\n\";\n break;\n }\n cout << N << \" \" << M << \"\\n\";\n int a[N];\n for (int i = 0; i < N; i++){\n cin >> a[i];\n }\n sort(a, a+N, cmp);\n for (int i = 0; i < N; i++){\n cout << a[i] << '\\n';\n }\n }\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **11332 Summing Digits**\n\nFor a positive integer *n*, let *f*(*n*) denote the sum of the digits of *n* when represented in base 10. It is easy to see that the sequence of numbers *n, f*(*n*) *, f*(*f*(*n*)) *, f*(*f*(*f*(*n*))) *, . . .* eventually becomes a single digit number that repeats forever. Let this single digit be denoted *g*(*n*).\n\nFor example, consider *n* = 1234567892. Then:\n\n*f*(*n*) = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 2 = 47\n*f*(*f*(*n*)) = 4 + 7 = 11\n*f*(*f*(*f*(*n*))) = 1 + 1 = 2\n\nTherefore, *g*(1234567892) = 2.\n\n**Input**\n\nEach line of input contains a single positive integer *n* at most 2,000,000,000. Input is terminated by *n* = 0 which should not be processed.\n\n**Output**\n\nFor each such integer, you are to output a single line containing *g*(*n*).\n\n**Sample Input**\n```\n2\n11\n47\n1234567892\n0\n\n```\n**Sample Output**\n```\n2\n2\n2\n2\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\nusing namespace std;\n \nint solve(int x) {\n int ret = 0;\n while (x) {\n ret += x % 10;\n x /= 10;\n }\n if (ret < 10) return ret;\n else return solve(ret);\n}\n \nint main() {\n int n;\n while (cin >> n && n) {\n cout << solve(n) << \"\\n\";\n }\n return 0;\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **11461 Square Numbers**\n\nA square number is an integer number whose square root is also an integer. For example 1, 4, 81 are some square numbers. Given two numbers *a* and *b* you will have to find out how many square numbers are there between *a* and *b* (inclusive).\n\n**Input**\n\nThe input file contains at most 201 lines of inputs. Each line contains two integers *a* and *b* (0 *< a ≤* *b ≤* 100000). Input is terminated by a line containing two zeroes. This line should not be processed.\n\n**Output**\n\nFor each line of input produce one line of output. This line contains an integer which denotes how many square numbers are there between *a* and *b* (inclusive).\n\n**Sample Input**\n\n1 4\n\n1 10\n\n0 0\n\n**Sample Output**\n\n2\n\n3" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\n#include <cmath>\nusing namespace std;\n \nint main() {\n int a, b;\n while (cin >> a >> b && a + b){\n int n1 = sqrt(a);\n int n2 = sqrt(b);\n if (n1*n1 != a) n1++;\n cout << n2 - n1 + 1 << \"\\n\";\n }\n return 0;\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **118 Mutant Flatworld Explorers**\n\nRobotics, robot motion planning, and machine learning are areas that cross the boundaries of many of the subdisciplines that comprise Computer Science: artificial intelligence, algorithms and complexity, electrical and mechanical engineering to name a few. In addition, robots as “turtles” (inspired by work by Papert, Abelson, and diSessa) and as “beeper-pickers” (inspired by work by Pattis) have been studied and used by students as an introduction to programming for many years.\n\nThis problem involves determining the position of a robot exploring a pre-Columbian flat world.\n\nGiven the dimensions of a rectangular grid and a sequence of robot positions and instructions, you are to write a program that determines for each sequence of robot positions and instructions the final position of the robot. \n\nA robot *position* consists of a grid coordinate (a pair of integers: *x* -coordinate followed by *y* coordinate) and an orientation ( `N`, `S`, `E`, `W` for north, south, east, and west). A robot *instruction* is a string of the letters ‘ `L` ’, ‘ `R` ’, and ‘ `F` ’ which represent, respectively, the instructions:\n\n - *Left* : the robot turns left 90 degrees and remains on the current grid point.\n\n - *Right* : the robot turns right 90 degrees and remains on the current grid point.\n\n - *Forward* : the robot moves forward one grid point in the direction of the current orientation and mantains the same orientation.\n\nThe direction *North* corresponds to the direction from grid point ( *x, y* ) to grid point ( *x, y* + 1). \n\nSince the grid is rectangular and bounded, a robot that moves “off” an edge of the grid is lost forever. However, lost robots leave a robot “scent” that prohibits future robots from dropping off the world at the same grid point. The scent is left at the last grid position the robot occupied before disappearing over the edge. An instruction to move “off” the world from a grid point from which a robot has been previously lost is simply ignored by the current robot.\n\n**Input**\n\nThe first line of input is the upper-right coordinates of the rectangular world, the lower-left coordinates are assumed to be 0,0. \n\nThe remaining input consists of a sequence of robot positions and instructions (two lines per robot). A position consists of two integers specifying the initial coordinates of the robot and an orientation ( `N`, `S`, `E`, `W` ), all separated by white space on one line. A robot instruction is a string of the letters ‘ `L` ’, ‘ `R` ’, and ‘ `F` ’ on one line.\n\nEach robot is processed sequentially, i.e., finishes executing the robot instructions before the next robot begins execution. \n\nInput is terminated by end-of-file.\n\nYou may assume that all initial robot positions are within the bounds of the specified grid. The maximum value for any coordinate is 50. All instruction strings will be less than 100 characters in length.\n\n**Output**\n\nFor each robot position/instruction in the input, the output should indicate the final grid position and orientation of the robot. If a robot falls off the edge of the grid the word ‘ `LOST` ’ should be printed after the position and orientation.\n\n\n**Sample Input**\n```\n5 3\n1 1 E\nRFRFRFRF\n3 2 N\nFRRFLLFFRRFLL\n0 3 W\nLLFFFLFLFL\n\n```\n**Sample Output**\n```\n1 1 E\n3 3 N LOST\n2 3 S\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\n#include <map>\nusing namespace std;\nint a[55][55];\nint dx[] = {0, 1, 0, -1}; //N, E, S, W\nint dy[] = {1, 0, -1, 0};\n \nint main() {\n int row, col, R, C, D, nR, nC;\n char d;\n bool lost = false;\n string s;\n map <char, int> mp1;\n map <int, char> mp2;\n mp1['N'] = 0; mp2[0] = 'N';\n mp1['E'] = 1; mp2[1] = 'E';\n mp1['S'] = 2; mp2[2] = 'S';\n mp1['W'] = 3; mp2[3] = 'W';\n cin >> row >> col;\n while (cin >> R >> C >> d >> s){\n D = mp1[d];\n lost = false;\n for (int i = 0; i < s.size(); i++){\n if (s[i] == 'F'){\n nR = R + dx[D];\n nC = C + dy[D];\n if (nR >= 0 && nR <= row && nC >= 0 && nC <= col){\n R = nR;\n C = nC;\n } else {\n if (a[R][C] == 1){\n continue;\n } else {\n cout << R << \" \" << C << \" \" << mp2[D] << \" LOST\\n\";\n lost = true;\n a[R][C] = 1;\n break;\n }\n }\n } else if (s[i] == 'R'){\n D = (D + 1) % 4;\n } else {\n D = (D - 1 + 4) % 4;\n }\n }\n if (!lost) cout << R << \" \" << C << \" \" << mp2[D] << \"\\n\";\n }\n return 0;\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **12019 Doom’s Day Algorithm**\n\nNo. Doom’s day algorithm is not a method to compute which day the world will end. It is an algorithm created by the mathematician John Horton Conway, to calculate which day of the week (Monday, Tuesday, etc.) corresponds to a certain date.\n\nThis algorithm is based in the idea of the **doomsday**, a certain day of the week which always occurs in the same dates. For example, 4/4 (the 4th of April), 6/6 (the 6th of June), 8/8 (the 8th of August), 10/10 (the 10th of October) and 12/12 (the 12th of December) are dates which always occur in doomsday. All years have their own doomsday.\n\nIn year 2011, doomsday is Monday. So all of 4/4, 6/6, 8/8, 10/10 and 12/12 are Mondays. Using that information, you can easily compute any other date. For example, the 13th of December 2011 will be Tuesday, the 14th of December 2011 will be Wednesday, etc.\n\nOther days which occur on doomsday are 5/9, 9/5, 7/11 and 11/7. Also, in leap years, we have the following doomsdays: 1/11 (the 11th of January) and 2/22 (the 22nd of Febrary), and in non-leap years 1/10 and 2/21.\n\nGiven a date of year 2011, you have to compute which day of the week it occurs.\n\n**Input**\n\nThe input can contain different test cases. The first line of the input indicates the number of test cases.\n\nFor each test case, there is a line with two numbers: *M D* . *M* represents the month (from 1 to 12) and *D* represents the day (from 1 to 31). The date will always be valid.\n\n**Output**\n\nFor each test case, you have to output the day of the week where that date occurs in 2011. The days of the week will be: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday.\n\n**Sample Input**\n```\n8\n1 6\n2 28\n4 5\n5 26\n8 1\n11 1\n12 25\n12 31\n\n```\n**Sample Output**\n```\nThursday\nMonday\nTuesday\nThursday\nMonday\nTuesday\nSunday\nSaturday\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\nusing namespace std;\nint doom[13] = {-1, 10, 21, 7, 4, 9, 6, 11, 8, 5, 10, 7, 12};\nstring date[] = {\"Monday\", \"Tuesday\", \"Wednesday\",\n \"Thursday\", \"Friday\", \"Saturday\", \"Sunday\"};\n \nint main() {\n int T, m, d;\n cin >> T;\n while (T--) {\n cin >> m >> d;\n int delta = (d - doom[m]) % 7;\n if (delta >= 0){\n cout << date[delta] << \"\\n\";\n } else {\n cout << date[7 + delta] << \"\\n\";\n }\n }\n return 0;\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **272 TEX Quotes**\n\nTEX is a typesetting language developed by Donald Knuth. It takes source text together with a few typesetting instructions and produces, one hopes, a beautiful document. Beautiful documents use “ and ” to delimit quotations, rather than the mundane `\"` which is what is provided by most keyboards. Keyboards typically do not have an oriented double-quote, but they do have a left-single-quote ``` and a right-single-quote `'` . Check your keyboard now to locate the left-single-quote key ``` (sometimes called the “backquote key”) and the right-single-quote key `'` (sometimes called the “apostrophe” or just “quote”). Be careful not to confuse the left-single-quote ``` with the “backslash” key `\\` . TEX lets the user type two left-single-quotes ```` to create a left-double-quote “ and two right-single-quotes `''` to create a right-double-quote ”. Most typists, however, are accustomed to delimiting their quotations with the un-oriented double-quote `\"` .\n\nIf the source contained ``` \"To be or not to be,\" quoth the bard, \"that is the question.\"\n\n``` then the typeset document produced by TEX would not contain the desired form:\n\n“To be or not to be,” quoth the bard, “that is the question.”\n\nIn order to produce the desired form, the source file must contain the sequence: ``` ``To be or not to be,'' quoth the bard, ``that is the question.''\n\n``` You are to write a program which converts text containing double-quote ( `\"` ) characters into text that is identical except that double-quotes have been replaced by the two-character sequences required by TEX for delimiting quotations with oriented double-quotes. The double-quote ( `\"` ) characters should be replaced appropriately by either ```` if the `\"` opens a quotation and by `''` if the `\"` closes a quotation. Notice that the question of nested quotations does not arise: The first `\"` must be replaced by ````, the next by `''`, the next by ````, the next by `''`, the next by ````, the next by `''`, and so on.\n\n**Input**\n\nInput will consist of several lines of text containing an even number of double-quote ( `\"` ) characters. Input is ended with an end-of-file character.\n\n**Output**\n\nThe text must be output exactly as it was input except that:\n\n - the first `\"` in each pair is replaced by two ``` characters: ```` and\n\n - the second `\"` in each pair is replaced by two `'` characters: `''` .\n\n**Sample Input**\n```\n\"To be or not to be,\" quoth the Bard, \"that\nis the question\".\nThe programming contestant replied: \"I must disagree.\nTo `C' or not to `C', that is The Question!\"\n\n```\n\n**Sample Output**\n```\n``To be or not to be,'' quoth the Bard, ``that\nis the question''.\nThe programming contestant replied: ``I must disagree.\nTo `C' or not to `C', that is The Question!''\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\nusing namespace std;\n \nstring s;\nint cnt, blk;\n \nint main() {\n while (getline(cin, s)){\n for (int i = 0; i < s.length(); i++){\n if (s[i] == '\\\"'){\n if (cnt % 2 == 0) cout << \"``\";\n else cout << \"''\";\n cnt++;\n }\n else cout << s[i];\n }\n cout << \"\\n\";\n }\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **299 Train Swapping**\n\nAt an old railway station, you may still encounter one of the last remaining “train swappers”. A train swapper is an employee of the railroad, whose sole job it is to rearrange the carriages of trains. \n\nOnce the carriages are arranged in the optimal order, all the train driver has to do, is drop the carriages off, one by one, at the stations for which the load is meant.\n\nThe title “train swapper” stems from the first person who performed this task, at a station close to a railway bridge. Instead of opening up vertically, the bridge rotated around a pillar in the center of the river. After rotating the bridge 90 degrees, boats could pass left or right. The first train swapper had discovered that the bridge could be operated with at most two carriages on it. By rotating the bridge 180 degrees, the carriages switched place, allowing him to rearrange the carriages (as a side effect, the carriages then faced the opposite direction, but train carriages can move either way, so who cares). Now that almost all train swappers have died out, the railway company would like to automate their operation. Part of the program to be developed, is a routine which decides for a given train the least number of swaps of two adjacent carriages necessary to order the train. Your assignment is to create that routine.\n\n**Input**\n\nThe input contains on the first line the number of test cases ( *N* ). Each test case consists of two input lines. The first line of a test case contains an integer *L*, determining the length of the train (0 *≤* *L ≤* 50). The second line of a test case contains a permutation of the numbers 1 through *L*, indicating the current order of the carriages. The carriages should be ordered such that carriage 1 comes first, then 2, etc. with carriage *L* coming last.\n\n**Output**\n\nFor each test case output the sentence: ‘ `Optimal train swapping takes` *S* `swaps.` ’ where *S* is an integer.\n\n**Sample Input**\n```\n3\n3\n1 3 2\n4\n4 3 2 1\n2\n2 1\n\n```\n**Sample Output**\n```\nOptimal train swapping takes 1 swaps.\nOptimal train swapping takes 6 swaps.\nOptimal train swapping takes 1 swaps.\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\n#include <algorithm>\nusing namespace std;\n \nint main() {\n int T, N;\n cin >> T;\n while (T--){\n cin >> N;\n int a[N];\n for (int i = 0; i < N; i++){\n cin >> a[i];\n }\n int cnt = 0;\n for (int i = 0; i < N-1; i++){\n for (int j = i+1; j < N; j++){\n if (a[i] > a[j]){\n swap(a[i], a[j]);\n cnt++;\n }\n }\n }\n cout << \"Optimal train swapping takes \" << cnt << \" swaps.\\n\";\n }\n return 0;\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **490 Rotating Sentences**\n\nIn “Rotating Sentences,” you are asked to rotate a series of input sentences 90 degrees clockwise. So instead of displaying the input sentences from left to right and top to bottom, your program will display them from top to bottom and right to left.\n\n**Input**\n\nAs input to your program, you will be given a maximum of 100 sentences, each not exceeding 100 characters long. Legal characters include: newline, space, any punctuation characters, digits, and lower case or upper case English letters. (NOTE: Tabs are not legal characters.)\n\n**Output**\n\nThe output of the program should have the last sentence printed out vertically in the leftmost column; the first sentence of the input would subsequently end up at the rightmost column.\n\n**Sample Input**\n```\nRene Decartes once said,\n\"I think, therefore I am.\"\n\n```\n**Sample Output**\n```\n\"R\nIe\n n\nte\nh\niD\nne\nkc\n,a\n r\ntt\nhe\nes\nr\neo\nfn\noc\nre\ne\n s\nIa\n i\nad\nm,\n.\n\"\n\n```" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\nusing namespace std;\nstring s[105];\n \nint main() {\n int col = 0, row = 0;\n while (getline(cin, s[col])){\n row = max(row, (int)s[col].size());\n col++;\n }\n for (int i = 0; i < row; i++){\n for (int j = col-1; j >= 0; j--){\n if (i >= s[j].size()) cout << \" \";\n else cout << s[j][i];\n }\n cout << \"\\n\";\n }\n return 0;\n}" | |
| } | |
| ] | |
| }, | |
| { | |
| "conversations": [ | |
| { | |
| "role": "user", | |
| "content": "# **948 Fibonaccimal Base**\n\nThe well known Fibonacci sequence is obtained by starting with 0 and 1 and then adding the two last numbers to get the next one. For example the third number in the sequence is 1 (1=1+0), the forth is 2 (2=1+1), the fifth is 3 (3=2+1) and so on.\n\n|i|0|1|2|3|4|5|6|7|8|9|\n|---|---|---|---|---|---|---|---|---|---|---|\n|Fib(i)|0|1|1|2|3|5|8|13|21|34|\n\n\n\n**Figure 1 -** The first numbers in the Fibonacci sequence\n\nThe sequence appears on many things in our life, in nature, and has a great significance. Among other things, do you know that all positive integer numbers can be represented as a sum of numbers in the Fibonacci sequence? More than that, all positive integers can be represented as a sum of a set of Fibonacci numbers, that is, numbers from the sequence, without repetition. For example: *13* can be the sum of the sets *{13}*, *{5,8}* or *{2,3,8}* and *17* is represented by *{1,3,13}* or *{1,3,5,8}* . Since all numbers have this property (do you want to try to prove this for yourself?) this set could be a nice way to use as a \"base\" to represent the number. But, as we have seen, some numbers have more than one set whose sum is the number. How can we solve that? Simple! If we add the constraint that the sets cannot have two consecutive Fibonacci numbers, than we have a unique representation for each number! This restriction is because the sum of any two consecutive Fibonacci numbers is just the following Fibonacci number.\n\nNow that we know all this we can prepare a nice way to represent any positive integer. We will use a binary sequence (just zeros and ones) to do that. For example, *17 = 1 + 3 + 13* (remember that no two consecutive Fibonacci numbers can be used). Let’s write a zero for each Fibonacci number that is not used and one for each one that is used, starting at the right. Then, *17 = 100101* . See figure 2 for a detailed explanation. In this representation we should not have zeros at the left, this is, we should only write starting with the first one. In order for you to understand better, note that in this scheme, not using two consecutive Fibonacci numbers means that the binary sequence will not have two consecutive ones. When we use this representation for a number we say that we are using the Fibonaccimal base, and we write it like *17 = 100101 (fib)* .\n\n|17 =|1|0|0|1|0|1|\n|---|---|---|---|---|---|---|\n|13+3+1 =|13|8|5|3|2|1|\n\n\n\n**Figure 2 -** Explaining the representation of 17 in Fibonaccimal base\n\nGiven a set of numbers in decimal base, your task is to write them in the Fibonaccimal base.\n\n**Input**\n\nThe first line of input contains a single number *N*, representing the quantity of numbers that follow (1 *≤* *N ≤* 500).\n\nThan follow exactly *N* lines, each one containing a single positive integer smaller than 100 000 000. These numbers can come in any order.\n\n**Output**\n\nYou should output a single line for each of the *N* integers in the input, with the format ‘ *DEC_BASE* = *FIB_BASE* (fib)’. *DEC_BASE* is the original number in decimal base and *FIB_BASE* is its representation in Fibonaccimal base. See the sample output for an example.\n\n**Sample Input**\n\n10\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n\n**Sample Output**\n\n1 = 1 (fib)\n2 = 10 (fib)\n3 = 100 (fib)\n4 = 101 (fib)\n5 = 1000 (fib)\n6 = 1001 (fib)\n7 = 1010 (fib)\n8 = 10000 (fib)\n9 = 10001 (fib)\n10 = 10010 (fib)" | |
| }, | |
| { | |
| "role": "assistant", | |
| "content": "#include <iostream>\n#include <algorithm>\n#include <vector>\nusing namespace std;\n \nint main() {\n vector <int> fib;\n int f0 = 0, f1 = 1, f2 = 1;\n for (; f2 <= 1e8; ){\n f2 = f0 + f1;\n fib.push_back(f2);\n f0 = f1;\n f1 = f2;\n }\n reverse(fib.begin(), fib.end());\n int N, n, x;\n cin >> N;\n while (N--){\n cin >> n;\n x = n;\n vector <int> ans;\n int i = 0;\n while (fib[i] > x) i++;\n for (; i < fib.size(); i++){\n if (fib[i] <= x){\n x -= fib[i];\n ans.push_back(1);\n i++;\n if (i < fib.size()) ans.push_back(0);\n } else ans.push_back(0);\n }\n cout << n << \" = \";\n for (auto j: ans) cout << j;\n cout << \" (fib)\\n\";\n }\n return 0;\n}" | |
| } | |
| ] | |
| } | |
| ] |