{"text": "<|system|>You are a helpful coding assistant.<|user|>Fix or complete the following code:\n\npython:\nThere are n persons who initially don't know each other. On each morning, two of them, who were not friends before, become friends.\n\nWe want to plan a trip for every evening of m days. On each trip, you have to select a group of people that will go on the trip. For every person, one of the following should hold: \n\n * Either this person does not go on the trip, \n * Or at least k of his friends also go on the trip. \n\n\n\nNote that the friendship is not transitive. That is, if a and b are friends and b and c are friends, it does not necessarily imply that a and c are friends.\n\nFor each day, find the maximum number of people that can go on the trip on that day.\nInput\n\nThe first line contains three integers n, m, and k (2 \u2264 n \u2264 2 \u22c5 10^5, 1 \u2264 m \u2264 2 \u22c5 10^5, 1 \u2264 k < n) \u2014 the number of people, the number of days and the number of friends each person on the trip should have in the group.\n\nThe i-th (1 \u2264 i \u2264 m) of the next m lines contains two integers x and y (1\u2264 x, y\u2264 n, x\u2260 y), meaning that persons x and y become friends on the morning of day i. It is guaranteed that x and y were not friends before.\n\nOutput\n\nPrint exactly m lines, where the i-th of them (1\u2264 i\u2264 m) contains the maximum number of people that can go on the trip on the evening of the day i.\n\nExamples\n\nInput\n\n4 4 2\n2 3\n1 2\n1 3\n1 4\n\n\nOutput\n\n0\n0\n3\n3\n\n\nInput\n\n5 8 2\n2 1\n4 2\n5 4\n5 2\n4 3\n5 1\n4 1\n3 2\n\n\nOutput\n\n0\n0\n0\n3\n3\n4\n4\n5\n\n\nInput\n\n5 7 2\n1 5\n3 2\n2 5\n3 4\n1 2\n5 3\n1 3\n\n\nOutput\n\n0\n0\n0\n0\n3\n4\n4\n\nNote\n\nIn the first example, \n\n * 1,2,3 can go on day 3 and 4. \n\n\n\nIn the second example, \n\n * 2,4,5 can go on day 4 and 5. \n * 1,2,4,5 can go on day 6 and 7. \n * 1,2,3,4,5 can go on day 8. \n\n\n\nIn the third example, \n\n * 1,2,5 can go on day 5. \n * 1,2,3,5 can go on day 6 and 7.<|assistant|>Here's the solution:\n\n", "tok_len": 639} {"text": "<|system|>You are a helpful coding assistant.<|user|>Fix or complete the following code:\n\npython:\nIn Byteland, there are two political parties fighting for seats in the Parliament in the upcoming elections: Wrong Answer Party and Time Limit Exceeded Party. As they want to convince as many citizens as possible to cast their votes on them, they keep promising lower and lower taxes.\n\nThere are n cities in Byteland, connected by m one-way roads. Interestingly enough, the road network has no cycles \u2014 it's impossible to start in any city, follow a number of roads, and return to that city. Last year, citizens of the i-th city had to pay h_i bourles of tax.\n\nParties will now alternately hold the election conventions in various cities. If a party holds a convention in city v, the party needs to decrease the taxes in this city to a non-negative integer amount of bourles. However, at the same time they can arbitrarily modify the taxes in each of the cities that can be reached from v using a single road. The only condition that must be fulfilled that the tax in each city has to remain a non-negative integer amount of bourles.\n\nThe first party to hold the convention is Wrong Answer Party. It's predicted that the party to hold the last convention will win the election. Can Wrong Answer Party win regardless of Time Limit Exceeded Party's moves?\nInput\n\nThe first line of the input contains two integers n, m (1 \u2264 n \u2264 200 000, 0 \u2264 m \u2264 200 000) \u2014 the number of cities and roads in Byteland.\n\nThe next line contains n space-separated integers h_1, h_2, ..., h_n (0 \u2264 h_i \u2264 10^9); h_i denotes the amount of taxes paid in the i-th city.\n\nEach of the following m lines contains two integers (1 \u2264 u, v \u2264 n, u \u2260 v), and describes a one-way road leading from the city u to the city v. There will be no cycles in the road network. No two roads will connect the same pair of cities.\n\nWe can show that the conventions cannot be held indefinitely for any correct test case.\n\nOutput\n\nIf Wrong Answer Party can win the election, output WIN in the first line of your output. In this case, you're additionally asked to produce any convention allowing the party to win regardless of the opponent's actions. The second line should contain n non-negative integers h'_1, h'_2, ..., h'_n (0 \u2264 h'_i \u2264 2 \u22c5 10^{18}) describing the amount of taxes paid in consecutive cities after the convention. If there are multiple answers, output any. We guarantee that if the party has any winning move, there exists a move after which no city has to pay more than 2 \u22c5 10^{18} bourles.\n\nIf the party cannot assure their victory, output LOSE in the first and only line of the output.\n\nExamples\n\nInput\n\n\n4 2\n2 1 1 5\n1 2\n3 4\n\n\nOutput\n\n\nWIN\n1 5 1 5 \n\n\nInput\n\n\n4 2\n1 5 1 5\n1 2\n3 4\n\n\nOutput\n\n\nLOSE\n\n\nInput\n\n\n3 3\n314 159 265\n1 2\n1 3\n3 2\n\n\nOutput\n\n\nWIN\n0 0 0 \n\n\nInput\n\n\n6 4\n2 2 5 5 6 6\n1 3\n2 4\n3 5\n4 6\n\n\nOutput\n\n\nLOSE\n\nNote\n\nIn the first example, Wrong Answer Party should hold the convention in the city 1. The party will decrease the taxes in this city to 1 bourle. As the city 2 is directly reachable from 1, we can arbitrarily modify the taxes in this city. The party should change the tax to 5 bourles. It can be easily proved that Time Limit Exceeded cannot win the election after this move if Wrong Answer Party plays optimally.\n\nThe second example test presents the situation we created after a single move in the previous test; as it's Wrong Answer Party's move now, the party cannot win.\n\nIn the third test, we should hold the convention in the first city. This allows us to change the taxes in any city to any desired value; we can for instance decide to set all the taxes to zero, which allows the Wrong Answer Party to win the election immediately.<|assistant|>Here's the solution:\n\n", "tok_len": 958} {"text": "<|system|>You are a helpful coding assistant.<|user|>Fix or complete the following code:\n\npython:\nYou are given q queries in the following form:\n\nGiven three integers l_i, r_i and d_i, find minimum positive integer x_i such that it is divisible by d_i and it does not belong to the segment [l_i, r_i].\n\nCan you answer all the queries?\n\nRecall that a number x belongs to segment [l, r] if l \u2264 x \u2264 r.\nInput\n\nThe first line contains one integer q (1 \u2264 q \u2264 500) \u2014 the number of queries.\n\nThen q lines follow, each containing a query given in the format l_i r_i d_i (1 \u2264 l_i \u2264 r_i \u2264 10^9, 1 \u2264 d_i \u2264 10^9). l_i, r_i and d_i are integers.\n\nOutput\n\nFor each query print one integer: the answer to this query.\n\nExample\n\nInput\n\n\n5\n2 4 2\n5 10 4\n3 10 1\n1 2 3\n4 6 5\n\n\nOutput\n\n\n6\n4\n1\n3\n10<|assistant|>Here's the solution:\n\n", "tok_len": 252} {"text": "<|system|>You are a helpful coding assistant.<|user|>Fix or complete the following code:\n\npython:\nVasily the Programmer loves romance, so this year he decided to illuminate his room with candles.\n\nVasily has a candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make b went out candles into a new candle. As a result, this new candle can be used like any other new candle.\n\nNow Vasily wonders: for how many hours can his candles light up the room if he acts optimally well? Help him find this number.\nInput\n\nThe single line contains two integers, a and b (1 \u2264 a \u2264 1000; 2 \u2264 b \u2264 1000).\n\nOutput\n\nPrint a single integer \u2014 the number of hours Vasily can light up the room for.\n\nExamples\n\nInput\n\n4 2\n\n\nOutput\n\n7\n\n\nInput\n\n6 3\n\n\nOutput\n\n8\n\nNote\n\nConsider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours.<|assistant|>Here's the solution:\n\n", "tok_len": 252} {"text": "<|system|>You are a helpful coding assistant.<|user|>Fix or complete the following code:\n\npython:\nYou are given an array A of size N, and Q queries to deal with. For each query, you are given an integer X, and you're supposed to find out if X is present in the array A or not.\nInput:\nThe first line contains two integers, N and Q, denoting the size of array A and number of queries. The second line contains N space separated integers, denoting the array of elements Ai. The next Q lines contain a single integer X per line.\n\nOutput:\nFor each query, print YES if the X is in the array, otherwise print NO.\n\nConstraints:\n1 \u2264 N, Q \u2264 10^5\n1 \u2264 Ai \u2264 10^9\n1 \u2264 X \u2264 10^9\n\nSAMPLE INPUT\n5 10\n50 40 30 20 10\n10\n20\n30\n40\n50\n60\n70\n80\n90\n100\n\nSAMPLE OUTPUT\nYES\nYES\nYES\nYES\nYES\nNO\nNO\nNO\nNO\nNO<|assistant|>Here's the solution:\n\n", "tok_len": 239} {"text": "<|system|>You are a helpful coding assistant.<|user|>Fix or complete the following code:\n\npython:\nRoy is going through the dark times of his life. Recently his girl friend broke up with him and to overcome the pain of acute misery he decided to restrict himself to Eat-Sleep-Code life cycle. For N days he did nothing but eat, sleep and code. \n\nA close friend of Roy kept an eye on him for last N days. For every single minute of the day, he kept track of Roy's actions and prepared a log file. \n\nThe log file contains exactly N lines, each line contains a string of length 1440 ( i.e. number of minutes in 24 hours of the day).\nThe string is made of characters E, S, and C only; representing Eat, Sleep and Code respectively. i^th character of the string represents what Roy was doing during i^th minute of the day. \n\nRoy's friend is now interested in finding out the maximum of longest coding streak of the day - X.\nHe also wants to find the longest coding streak of N days - Y.\nCoding streak means number of C's without any E or S in between. \n\nSee sample test case for clarification.\nInput:\nFirst line of each file contains N - number of days.\nFollowing N lines contains a string of exactly 1440 length representing his activity on that day. \n\nOutput:\nPrint X and Y separated by a space in a single line. \n\nConstraints:\n1 \u2264 N \u2264 365\nString consists of characters E, S, and C only.\nString length is exactly 1440.\n\nNote: The sample test case does not follow the given constraints on string length to avoid large data. It is meant only for explanation. We assure you that the hidden test files strictly follow the constraints.\n\nSAMPLE INPUT\n4\nSSSSEEEECCCCEECCCC\nCCCCCSSSSEEECCCCSS\nSSSSSEEESSCCCCCCCS\nEESSSSCCCCCCSSEEEESAMPLE OUTPUT\n7 9Explanation\n\nLongest coding streak for each day is as follows:\nDay 1: 4\nDay 2: 5\nDay 3: 7\nDay 4: 6\nMaximum of these is 7, hence X is 7. \n\nNow in order to find longest coding streak of the all days, we should also check if Roy continued his coding from previous days.\nAs in the sample test case, Roy was coding for 4 minutes at the end of Day 1 and he continued to code till 5 more minutes on Day 2. Hence the longest coding streak is 4+5 equals 9. There is no any other coding streak larger than this. So the longest coding streak of all days is 9.<|assistant|>Here's the solution:\n\n", "tok_len": 578} {"text": "<|system|>You are a helpful coding assistant.<|user|>Fix or complete the following code:\n\npython:\nAwruk is taking part in elections in his school. It is the final round. He has only one opponent \u2014 Elodreip. The are n students in the school. Each student has exactly k votes and is obligated to use all of them. So Awruk knows that if a person gives a_i votes for Elodreip, than he will get exactly k - a_i votes from this person. Of course 0 \u2264 k - a_i holds.\n\nAwruk knows that if he loses his life is over. He has been speaking a lot with his friends and now he knows a_1, a_2, ..., a_n \u2014 how many votes for Elodreip each student wants to give. Now he wants to change the number k to win the elections. Of course he knows that bigger k means bigger chance that somebody may notice that he has changed something and then he will be disqualified.\n\nSo, Awruk knows a_1, a_2, ..., a_n \u2014 how many votes each student will give to his opponent. Help him select the smallest winning number k. In order to win, Awruk needs to get strictly more votes than Elodreip.\nInput\n\nThe first line contains integer n (1 \u2264 n \u2264 100) \u2014 the number of students in the school.\n\nThe second line contains n integers a_1, a_2, \u2026, a_n (1 \u2264 a_i \u2264 100) \u2014 the number of votes each student gives to Elodreip.\n\nOutput\n\nOutput the smallest integer k (k \u2265 max a_i) which gives Awruk the victory. In order to win, Awruk needs to get strictly more votes than Elodreip.\n\nExamples\n\nInput\n\n5\n1 1 1 5 1\n\n\nOutput\n\n5\n\nInput\n\n5\n2 2 3 2 2\n\n\nOutput\n\n5\n\nNote\n\nIn the first example, Elodreip gets 1 + 1 + 1 + 5 + 1 = 9 votes. The smallest possible k is 5 (it surely can't be less due to the fourth person), and it leads to 4 + 4 + 4 + 0 + 4 = 16 votes for Awruk, which is enough to win.\n\nIn the second example, Elodreip gets 11 votes. If k = 4, Awruk gets 9 votes and loses to Elodreip.<|assistant|>Here's the solution:\n\n", "tok_len": 526} {"text": "<|system|>You are a helpful coding assistant.<|user|>Fix or complete the following code:\n\npython:\nYou are given a permutation p_1, p_2, \u2026, p_n.\n\nIn one move you can swap two adjacent values.\n\nYou want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,\u2026, k, in other words in the end there should be an integer i, 1 \u2264 i \u2264 n-k+1 such that p_i = 1, p_{i+1} = 2, \u2026, p_{i+k-1}=k.\n\nLet f(k) be the minimum number of moves that you need to make a subsegment with values 1,2,\u2026,k appear in the permutation.\n\nYou need to find f(1), f(2), \u2026, f(n).\nInput\n\nThe first line of input contains one integer n (1 \u2264 n \u2264 200 000): the number of elements in the permutation.\n\nThe next line of input contains n integers p_1, p_2, \u2026, p_n: given permutation (1 \u2264 p_i \u2264 n).\n\nOutput\n\nPrint n integers, the minimum number of moves that you need to make a subsegment with values 1,2,\u2026,k appear in the permutation, for k=1, 2, \u2026, n.\n\nExamples\n\nInput\n\n\n5\n5 4 3 2 1\n\n\nOutput\n\n\n0 1 3 6 10 \n\n\nInput\n\n\n3\n1 2 3\n\n\nOutput\n\n\n0 0 0<|assistant|>Here's the solution:\n\n", "tok_len": 328} {"text": "<|system|>You are a helpful coding assistant.<|user|>Fix or complete the following code:\n\npython:\nAdvertising has become part of our routine. And now, in the era of progressive technologies, we need your ideas to make advertising better!\n\nIn this problem we'll look at a simplified version of context advertising. You've got a text, consisting of exactly n words. A standard advertising banner has exactly r lines, each line can contain at most c characters. The potential customer always likes it when they can see lots of advertising, so you should determine which maximum number of consecutive words from the text can be written on the banner. Single words in one line of the banner should be separated by spaces. You are allowed to insert more than one space at once. Note that you are not allowed to break the words, that is, each word in the text must occupy exactly one line in the banner. Besides, you cannot change the word order, that is, if you read the banner text consecutively, from top to bottom and from left to right, you should get some consecutive part of the advertisement text.\n\nMore formally, the statement can be written like that. Let's say that all words are indexed from 1 to n in the order in which they occur in the advertisement text. Then you have to choose all words, starting from some i-th one and ending with some j-th one (1 \u2264 i \u2264 j \u2264 n), so that all of them could be written on the banner. There must be as many words as possible. See the samples for clarifications.\nInput\n\nThe first input line contains three integers n, r, c (1 \u2264 n, r, c \u2264 106; r \u00d7 c \u2264 106). The next line contains a text, consisting of n words. The words consist only of lowercase English letters and are not empty. The words in the lines are separated by single spaces. The total number of characters in all words doesn't exceed 5\u00b7106.\n\nOutput\n\nPrint at most r lines, in each line print at most c characters \u2014 the optimal advertisement banner. If there are multiple advertisement banners, print any of them. \n\nNote that some lines of the banner can be empty. You are allowed not to print such lines.\n\nExamples\n\nInput\n\n9 4 12\nthis is a sample text for croc final round\n\n\nOutput\n\nthis is a\nsample text\nfor croc\nfinal round\n\n\nInput\n\n9 1 9\nthis is a sample text for croc final round\n\n\nOutput\n\nthis is a\n\n\nInput\n\n6 2 3\ncroc a a a croc a\n\n\nOutput\n\na a\na\n\n\nInput\n\n2 2 5\nfirst second\n\n\nOutput\n\nfirst<|assistant|>Here's the solution:\n\n", "tok_len": 552} {"text": "<|system|>You are a helpful coding assistant.<|user|>Fix or complete the following code:\n\npython:\nThis is a simple game you must have played around with during your school days, calculating FLAMES of you and your crush! Given the names of two people, cancel out the common letters (repeated occurrence of a letter is treated separately, so 2A's in one name and one A in the other would cancel one A in each name), count the total number of remaining letters (n) and repeatedly cut the letter in the word FLAMES which hits at the nth number when we count from F in cyclic manner.\nFor example:\nNAME 1: SHILPA\nNAME 2: AAMIR\nAfter cutting the common letters: \nNAME 1: SHILPA \nNAME 2: AAMIR\nTotal number of letters left=7\nFLAMES, start counting from F : 1=F, 2=L, 3=A, 4=M, 5=E, 6=S,7=F...So cut F\nFLAMES: repeat this process with remaining letters of FLAMES for number 7 (start count from the letter after \nthe last letter cut) . In the end, one letter remains. Print the result corresponding to the last letter:\nF=FRIENDS\nL=LOVE\nA=ADORE\nM=MARRIAGE\nE=ENEMIES\nS=SISTER\nInput\nThe no. of test cases (\nOutput\nFLAMES result (Friends/Love/...etc) for each test case\n\n\nExample\n\nInput:\n2\nSHILPA\nAAMIR\nMATT\nDENISE\n\n\nOutput:\nENEMIES\nLOVE\n\n\n\n\n\n\n\nBy:\nChintan, Asad, Ashayam, Akanksha<|assistant|>Here's the solution:\n\n", "tok_len": 362} {"text": "<|system|>You are a helpful coding assistant.<|user|>Fix or complete the following code:\n\npython:\nAn established group of scientists are working on finding solution to NP hard problems. They claim Subset Sum as an NP-hard problem. The problem is to determine whether there exists a subset of a given set S whose sum is a given number K. \nYou are a computer engineer and you claim to solve this problem given that all numbers in the set are non-negative. Given a set S of size N of non-negative integers, find whether there exists a subset whose sum is K.\nInput\nFirst line of input contains T, the number of test cases. T test cases follow. \nEach test case contains 2 lines. First line contains two integers N and K. Next line contains N space separated non-negative integers (each less than 100000).\n0 < T < 1000\n0 < N < 1000\n0 < K < 1000\n\nOutput\nOutput T lines, one for each test case. Every line should be either 0 or 1 depending on whether such a subset exists or not.\n\nExample\n\nInput:\n2\n5 10\n3 4 6 1 9\n3 2\n1 3 4\n\nOutput:\n1\n0<|assistant|>Here's the solution:\n\n", "tok_len": 268} {"text": "<|system|>You are a helpful coding assistant.<|user|>Fix or complete the following code:\n\npython:\nYou are the God of Wind.\n\nBy moving a big cloud around, you can decide the weather: it invariably rains under the cloud, and the sun shines everywhere else.\n\nBut you are a benign God: your goal is to give enough rain to every field in the countryside, and sun to markets and festivals. Small humans, in their poor vocabulary, only describe this as \u201cweather forecast\u201d.\n\nYou are in charge of a small country, called Paccimc. This country is constituted of 4 \u00d7 4 square areas, denoted by their numbers.\n\n\n\nYour cloud is of size 2 \u00d7 2, and may not cross the borders of the country.\n\nYou are given the schedule of markets and festivals in each area for a period of time.\n\nOn the first day of the period, it is raining in the central areas (6-7-10-11), independently of the schedule.\n\nOn each of the following days, you may move your cloud by 1 or 2 squares in one of the four cardinal directions (North, West, South, and East), or leave it in the same position. Diagonal moves are not allowed. All moves occur at the beginning of the day.\n\nYou should not leave an area without rain for a full week (that is, you are allowed at most 6 consecutive days without rain). You don\u2019t have to care about rain on days outside the period you were given: i.e. you can assume it rains on the whole country the day before the period, and the day after it finishes.\nInput\n\nThe input is a sequence of data sets, followed by a terminating line containing only a zero.\n\nA data set gives the number N of days (no more than 365) in the period on a single line, followed by N lines giving the schedule for markets and festivals. The i-th line gives the schedule for the i-th day. It is composed of 16 numbers, either 0 or 1, 0 standing for a normal day, and 1 a market or festival day. The numbers are separated by one or more spaces.\n\nOutput\n\nThe answer is a 0 or 1 on a single line for each data set, 1 if you can satisfy everybody, 0 if there is no way to do it.\n\nExample\n\nInput\n\n1\n0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0\n7\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n1 0 0 0 0 0 1 0 0 0 0 1 1 0 0 1\n0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 1\n0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0\n0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0\n1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1\n0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0\n7\n0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0\n0 0 1 0 0 0 0 1 0 0 0 0 0 1 0 0\n0 0 0 1 0 0 0 0 0 0 1 0 1 0 0 0\n0 1 0 0 0 0 0 1 0 0 0 0 1 0 0 0\n0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 1 1 0 1 0 0 0 0 1\n0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0\n15\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0\n0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 1 1 0 1 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0\n0 0 1 1 0 0 0 0 0 1 0 0 0 0 0 0\n1 1 0 0 0 0 0 0 0 0 1 0 0 1 0 0\n0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0\n0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0\n1 0 0 1 1 0 0 0 0 1 0 1 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0\n0 0 0 0 0 1 0 1 0 1 0 0 0 0 0 0\n0\n\n\nOutput\n\n0\n1\n0\n1<|assistant|>Here's the solution:\n\n", "tok_len": 1024} {"text": "<|system|>You are a helpful coding assistant.<|user|>Fix or complete the following code:\n\npython:\nAt the big break Nastya came to the school dining room. There are n pupils in the school, numbered from 1 to n. Unfortunately, Nastya came pretty late, so that all pupils had already stood in the queue, i.e. Nastya took the last place in the queue. Of course, it's a little bit sad for Nastya, but she is not going to despond because some pupils in the queue can agree to change places with some other pupils.\n\nFormally, there are some pairs u, v such that if the pupil with number u stands directly in front of the pupil with number v, Nastya can ask them and they will change places. \n\nNastya asks you to find the maximal number of places in queue she can move forward.\nInput\n\nThe first line contains two integers n and m (1 \u2264 n \u2264 3 \u22c5 10^{5}, 0 \u2264 m \u2264 5 \u22c5 10^{5}) \u2014 the number of pupils in the queue and number of pairs of pupils such that the first one agrees to change places with the second one if the first is directly in front of the second.\n\nThe second line contains n integers p_1, p_2, ..., p_n \u2014 the initial arrangement of pupils in the queue, from the queue start to its end (1 \u2264 p_i \u2264 n, p is a permutation of integers from 1 to n). In other words, p_i is the number of the pupil who stands on the i-th position in the queue.\n\nThe i-th of the following m lines contains two integers u_i, v_i (1 \u2264 u_i, v_i \u2264 n, u_i \u2260 v_i), denoting that the pupil with number u_i agrees to change places with the pupil with number v_i if u_i is directly in front of v_i. It is guaranteed that if i \u2260 j, than v_i \u2260 v_j or u_i \u2260 u_j. Note that it is possible that in some pairs both pupils agree to change places with each other.\n\nNastya is the last person in the queue, i.e. the pupil with number p_n.\n\nOutput\n\nPrint a single integer \u2014 the number of places in queue she can move forward.\n\nExamples\n\nInput\n\n2 1\n1 2\n1 2\n\n\nOutput\n\n1\n\nInput\n\n3 3\n3 1 2\n1 2\n3 1\n3 2\n\n\nOutput\n\n2\n\nInput\n\n5 2\n3 1 5 4 2\n5 2\n5 4\n\n\nOutput\n\n1\n\nNote\n\nIn the first example Nastya can just change places with the first pupil in the queue.\n\nOptimal sequence of changes in the second example is \n\n * change places for pupils with numbers 1 and 3. \n * change places for pupils with numbers 3 and 2. \n * change places for pupils with numbers 1 and 2. \n\n\n\nThe queue looks like [3, 1, 2], then [1, 3, 2], then [1, 2, 3], and finally [2, 1, 3] after these operations.<|assistant|>Here's the solution:\n\n", "tok_len": 691} {"text": "<|system|>You are a helpful coding assistant.<|user|>Fix or complete the following code:\n\npython:\nA recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is a string that only consists of digits and characters \"-\".\n\nWe'll say that some date is mentioned in the Prophesy if there is a substring in the Prophesy that is the date's record in the format \"dd-mm-yyyy\". We'll say that the number of the date's occurrences is the number of such substrings in the Prophesy. For example, the Prophesy \"0012-10-2012-10-2012\" mentions date 12-10-2012 twice (first time as \"0012-10-2012-10-2012\", second time as \"0012-10-2012-10-2012\").\n\nThe date of the Apocalypse is such correct date that the number of times it is mentioned in the Prophesy is strictly larger than that of any other correct date.\n\nA date is correct if the year lies in the range from 2013 to 2015, the month is from 1 to 12, and the number of the day is strictly more than a zero and doesn't exceed the number of days in the current month. Note that a date is written in the format \"dd-mm-yyyy\", that means that leading zeroes may be added to the numbers of the months or days if needed. In other words, date \"1-1-2013\" isn't recorded in the format \"dd-mm-yyyy\", and date \"01-01-2013\" is recorded in it.\n\nNotice, that any year between 2013 and 2015 is not a leap year.\nInput\n\nThe first line contains the Prophesy: a non-empty string that only consists of digits and characters \"-\". The length of the Prophesy doesn't exceed 105 characters.\n\nOutput\n\nIn a single line print the date of the Apocalypse. It is guaranteed that such date exists and is unique.\n\nExamples\n\nInput\n\n777-444---21-12-2013-12-2013-12-2013---444-777\n\n\nOutput\n\n13-12-2013<|assistant|>Here's the solution:\n\n", "tok_len": 527} {"text": "<|system|>You are a helpful coding assistant.<|user|>Fix or complete the following code:\n\npython:\nLuba thinks about watering her garden. The garden can be represented as a segment of length k. Luba has got n buckets, the i-th bucket allows her to water some continuous subsegment of garden of length exactly ai each hour. Luba can't water any parts of the garden that were already watered, also she can't water the ground outside the garden.\n\nLuba has to choose one of the buckets in order to water the garden as fast as possible (as mentioned above, each hour she will water some continuous subsegment of length ai if she chooses the i-th bucket). Help her to determine the minimum number of hours she has to spend watering the garden. It is guaranteed that Luba can always choose a bucket so it is possible water the garden.\n\nSee the examples for better understanding.\nInput\n\nThe first line of input contains two integer numbers n and k (1 \u2264 n, k \u2264 100) \u2014 the number of buckets and the length of the garden, respectively.\n\nThe second line of input contains n integer numbers ai (1 \u2264 ai \u2264 100) \u2014 the length of the segment that can be watered by the i-th bucket in one hour.\n\nIt is guaranteed that there is at least one bucket such that it is possible to water the garden in integer number of hours using only this bucket.\n\nOutput\n\nPrint one integer number \u2014 the minimum number of hours required to water the garden.\n\nExamples\n\nInput\n\n3 6\n2 3 5\n\n\nOutput\n\n2\n\n\nInput\n\n6 7\n1 2 3 4 5 6\n\n\nOutput\n\n7\n\nNote\n\nIn the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden.\n\nIn the second test we can choose only the bucket that allows us to water the segment of length 1.<|assistant|>Here's the solution:\n\n", "tok_len": 419} {"text": "<|system|>You are a helpful coding assistant.<|user|>Fix or complete the following code:\n\npython:\nThis is an interactive problem!\n\nEhab plays a game with Laggy. Ehab has 2 hidden integers (a,b). Laggy can ask a pair of integers (c,d) and Ehab will reply with:\n\n * 1 if a \u2295 c>b \u2295 d. \n * 0 if a \u2295 c=b \u2295 d. \n * -1 if a \u2295 c