source
stringclasses
4 values
task_type
stringclasses
1 value
in_source_id
stringlengths
0
138
problem
stringlengths
219
13.2k
gold_standard_solution
stringlengths
0
413k
problem_id
stringlengths
5
10
metadata
dict
verification_info
dict
codeforces
verifiable_code
758
Solve the following coding problem using the programming language python: In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are *n* citizens, the welfare of each of them is estimated as the integer in *a**i* burles (burle is the currency in Berland). You are the royal treasurer, which needs to count the minimum charges of the kingdom on the king's present. The king can only give money, he hasn't a power to take away them. The input will be provided via standard input and looks as follows: The first line contains the integer *n* (1<=≤<=*n*<=≤<=100) — the number of citizens in the kingdom. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* (0<=≤<=*a**i*<=≤<=106) — the welfare of the *i*-th citizen. You should write the solution as standard output as follows: In the only line print the integer *S* — the minimum number of burles which are had to spend. Here are example inputs and outputs for the problem: Example Input 1: 5 0 1 2 3 4 Example Output 1: 10 Example Input 2: 5 1 1 0 1 1 Example Output 2: 1 Example Input 3: 3 1 3 1 Example Output 3: 4 Example Input 4: 1 12 Example Output 4: 0 Now solve the problem by providing the code.
n = int(input()) l = list(map(int,input().split())) p = max(l) v=0 r=0 for i in l: v = p-i r+=v print(r)
vfc_82049
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n0 1 2 3 4", "output": "10", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 1 0 1 1", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 3 1", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n12", "output": "0", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
996
Solve the following coding problem using the programming language python: Allen has a LOT of money. He has $n$ dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are $1$, $5$, $10$, $20$, $100$. What is the minimum number of bills Allen could receive after withdrawing his entire balance? The input will be provided via standard input and looks as follows: The first and only line of input contains a single integer $n$ ($1 \le n \le 10^9$). You should write the solution as standard output as follows: Output the minimum number of bills that Allen could receive. Here are example inputs and outputs for the problem: Example Input 1: 125 Example Output 1: 3 Example Input 2: 43 Example Output 2: 5 Example Input 3: 1000000000 Example Output 3: 10000000 Now solve the problem by providing the code.
t=int(input()) x=[100,20,10,5,1] count=0 for i in x: count+=t//i t%=i print(count)
vfc_82053
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "125", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "43", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000000000", "output": "10000000", "type": "stdin_stdout" }, { "fn_name": null, "input": "4", "output": "4", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
834
Solve the following coding problem using the programming language python: It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to be disclosed to the general public: the information can cause discord in the kingdom of Sweetland in case it turns out to reach the wrong hands. So it's a necessity to not let any uninvited guests in. There are 26 entrances in Jelly Castle, enumerated with uppercase English letters from A to Z. Because of security measures, each guest is known to be assigned an entrance he should enter the castle through. The door of each entrance is opened right before the first guest's arrival and closed right after the arrival of the last guest that should enter the castle through this entrance. No two guests can enter the castle simultaneously. For an entrance to be protected from possible intrusion, a candy guard should be assigned to it. There are *k* such guards in the castle, so if there are more than *k* opened doors, one of them is going to be left unguarded! Notice that a guard can't leave his post until the door he is assigned to is closed. Slastyona had a suspicion that there could be uninvited guests at the evening. She knows the order in which the invited guests entered the castle, and wants you to help her check whether there was a moment when more than *k* doors were opened. The input will be provided via standard input and looks as follows: Two integers are given in the first string: the number of guests *n* and the number of guards *k* (1<=≤<=*n*<=≤<=106, 1<=≤<=*k*<=≤<=26). In the second string, *n* uppercase English letters *s*1*s*2... *s**n* are given, where *s**i* is the entrance used by the *i*-th guest. You should write the solution as standard output as follows: Output «YES» if at least one door was unguarded during some time, and «NO» otherwise. You can output each letter in arbitrary case (upper or lower). Here are example inputs and outputs for the problem: Example Input 1: 5 1 AABBB Example Output 1: NO Example Input 2: 5 1 ABABB Example Output 2: YES Now solve the problem by providing the code.
n, k = map(int, input().split()) s = input() d = {} op = set() for i in range(len(s)): d[s[i]] = i ans = 0 doors = 0 for i in range(len(s)): if s[i] not in op: doors += 1 op.add(s[i]) ans = max(ans, doors) if i == d[s[i]]: doors -= 1 print(('YES','NO')[ans <= k])
vfc_82057
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 1\nAABBB", "output": "NO", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
78
Solve the following coding problem using the programming language python: Haiku is a genre of Japanese traditional poetry. A haiku poem consists of 17 syllables split into three phrases, containing 5, 7 and 5 syllables correspondingly (the first phrase should contain exactly 5 syllables, the second phrase should contain exactly 7 syllables, and the third phrase should contain exactly 5 syllables). A haiku masterpiece contains a description of a moment in those three phrases. Every word is important in a small poem, which is why haiku are rich with symbols. Each word has a special meaning, a special role. The main principle of haiku is to say much using a few words. To simplify the matter, in the given problem we will consider that the number of syllable in the phrase is equal to the number of vowel letters there. Only the following letters are regarded as vowel letters: "a", "e", "i", "o" and "u". Three phases from a certain poem are given. Determine whether it is haiku or not. The input will be provided via standard input and looks as follows: The input data consists of three lines. The length of each line is between 1 and 100, inclusive. The *i*-th line contains the *i*-th phrase of the poem. Each phrase consists of one or more words, which are separated by one or more spaces. A word is a non-empty sequence of lowercase Latin letters. Leading and/or trailing spaces in phrases are allowed. Every phrase has at least one non-space character. See the example for clarification. You should write the solution as standard output as follows: Print "YES" (without the quotes) if the poem is a haiku. Otherwise, print "NO" (also without the quotes). Here are example inputs and outputs for the problem: Example Input 1: on codeforces beta round is running a rustling of keys Example Output 1: YES Example Input 2: how many gallons of edo s rain did you drink cuckoo Example Output 2: NO Now solve the problem by providing the code.
a = input() damn = 0 damn += a.count('a') damn += a.count('e') damn += a.count('i') damn += a.count('o') damn += a.count('u') if damn != 5: print('NO') exit() damn = 0 b = input() damn += b.count('a') damn += b.count('e') damn += b.count('i') damn += b.count('o') damn += b.count('u') if damn != 7: print('NO') exit() damn = 0 c = input() damn += c.count('a') damn += c.count('e') damn += c.count('i') damn += c.count('o') damn += c.count('u') if damn != 5: print('NO') exit() else: print('YES')
vfc_82065
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "on codeforces \nbeta round is running\n a rustling of keys ", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "how many gallons\nof edo s rain did you drink\n cuckoo", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": " hatsu shigure\n saru mo komino wo\nhoshige nari", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "o vetus stagnum\n rana de ripa salit\n ac sonant aquae", "output": "NO", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
81
Solve the following coding problem using the programming language python: Polycarp thinks about the meaning of life very often. He does this constantly, even when typing in the editor. Every time he starts brooding he can no longer fully concentrate and repeatedly presses the keys that need to be pressed only once. For example, instead of the phrase "how are you" he can type "hhoow aaaare yyoouu". Polycarp decided to automate the process of correcting such errors. He decided to write a plug-in to the text editor that will remove pairs of identical consecutive letters (if there are any in the text). Of course, this is not exactly what Polycarp needs, but he's got to start from something! Help Polycarp and write the main plug-in module. Your program should remove from a string all pairs of identical letters, which are consecutive. If after the removal there appear new pairs, the program should remove them as well. Technically, its work should be equivalent to the following: while the string contains a pair of consecutive identical letters, the pair should be deleted. Note that deleting of the consecutive identical letters can be done in any order, as any order leads to the same result. The input will be provided via standard input and looks as follows: The input data consists of a single line to be processed. The length of the line is from 1 to 2·105 characters inclusive. The string contains only lowercase Latin letters. You should write the solution as standard output as follows: Print the given string after it is processed. It is guaranteed that the result will contain at least one character. Here are example inputs and outputs for the problem: Example Input 1: hhoowaaaareyyoouu Example Output 1: wre Example Input 2: reallazy Example Output 2: rezy Example Input 3: abacabaabacabaa Example Output 3: a Now solve the problem by providing the code.
n = input() st = [] for i in range(len(n)): st.append(n[i]) while len(st) > 1 and st[-1] == st[-2]: st.pop() st.pop() print(''.join(st))
vfc_82069
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "hhoowaaaareyyoouu", "output": "wre", "type": "stdin_stdout" }, { "fn_name": null, "input": "reallazy", "output": "rezy", "type": "stdin_stdout" }, { "fn_name": null, "input": "abacabaabacabaa", "output": "a", "type": "stdin_stdout" }, { "fn_name": null, "input": "xraccabccbry", "output": "xy", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
917
Solve the following coding problem using the programming language python: As Will is stuck in the Upside Down, he can still communicate with his mom, Joyce, through the Christmas lights (he can turn them on and off with his mind). He can't directly tell his mom where he is, because the monster that took him to the Upside Down will know and relocate him. Thus, he came up with a puzzle to tell his mom his coordinates. His coordinates are the answer to the following problem. A string consisting only of parentheses ('(' and ')') is called a bracket sequence. Some bracket sequence are called correct bracket sequences. More formally: - Empty string is a correct bracket sequence. - if *s* is a correct bracket sequence, then (*s*) is also a correct bracket sequence. - if *s* and *t* are correct bracket sequences, then *st* (concatenation of *s* and *t*) is also a correct bracket sequence. A string consisting of parentheses and question marks ('?') is called pretty if and only if there's a way to replace each question mark with either '(' or ')' such that the resulting string is a non-empty correct bracket sequence. Will gave his mom a string *s* consisting of parentheses and question marks (using Morse code through the lights) and his coordinates are the number of pairs of integers (*l*,<=*r*) such that 1<=≤<=*l*<=≤<=*r*<=≤<=|*s*| and the string *s**l**s**l*<=+<=1... *s**r* is pretty, where *s**i* is *i*-th character of *s*. Joyce doesn't know anything about bracket sequences, so she asked for your help. The input will be provided via standard input and looks as follows: The first and only line of input contains string *s*, consisting only of characters '(', ')' and '?' (2<=≤<=|*s*|<=≤<=5000). You should write the solution as standard output as follows: Print the answer to Will's puzzle in the first and only line of output. Here are example inputs and outputs for the problem: Example Input 1: ((?)) Example Output 1: 4 Example Input 2: ??()?? Example Output 2: 7 Now solve the problem by providing the code.
st=input() le=len(st) ans=0 for i in range(le): l=0 w=0 for j in range(i,le): if(st[j]=="("): l+=1 elif(st[j]==")"): l-=1 else: w+=1 if(l+w<0): break elif(w>l): xx=l l=w w=xx elif(l==w): ans+=1 print(ans)
vfc_82073
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "((?))", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "??()??", "output": "7", "type": "stdin_stdout" }, { "fn_name": null, "input": "?????)(???", "output": "21", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
749
Solve the following coding problem using the programming language python: Bachgold problem is very easy to formulate. Given a positive integer *n* represent it as a sum of maximum possible number of prime numbers. One can prove that such representation exists for any integer greater than 1. Recall that integer *k* is called prime if it is greater than 1 and has exactly two positive integer divisors — 1 and *k*. The input will be provided via standard input and looks as follows: The only line of the input contains a single integer *n* (2<=≤<=*n*<=≤<=100<=000). You should write the solution as standard output as follows: The first line of the output contains a single integer *k* — maximum possible number of primes in representation. The second line should contain *k* primes with their sum equal to *n*. You can print them in any order. If there are several optimal solution, print any of them. Here are example inputs and outputs for the problem: Example Input 1: 5 Example Output 1: 2 2 3 Example Input 2: 6 Example Output 2: 3 2 2 2 Now solve the problem by providing the code.
def main(): a = int(input()) b = [2] * (a // 2) print(a // 2) if a % 2 != 0: b[-1] = 3 print(*b) main()
vfc_82077
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5", "output": "2\n2 3", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
573
Solve the following coding problem using the programming language python: Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are *n* players (including Limak himself) and right now all of them have bids on the table. *i*-th of them has bid with size *a**i* dollars. Each player can double his bid any number of times and triple his bid any number of times. The casino has a great jackpot for making all bids equal. Is it possible that Limak and his friends will win a jackpot? The input will be provided via standard input and looks as follows: First line of input contains an integer *n* (2<=≤<=*n*<=≤<=105), the number of players. The second line contains *n* integer numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the bids of players. You should write the solution as standard output as follows: Print "Yes" (without the quotes) if players can make their bids become equal, or "No" otherwise. Here are example inputs and outputs for the problem: Example Input 1: 4 75 150 75 50 Example Output 1: Yes Example Input 2: 3 100 150 250 Example Output 2: No Now solve the problem by providing the code.
n = int(input()) m=list(map(int,input().split())) for i in range(n): while(m[i]%2==0): m[i]//=2 while(m[i]%3==0): m[i]//=3 if(len(set(m))==1): print('Yes') else: print('No')
vfc_82081
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n75 150 75 50", "output": "Yes", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n100 150 250", "output": "No", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n34 34 68 34 34 68 34", "output": "Yes", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n72 96 12 18 81 20 6 2 54 1", "output": "No", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
998
Solve the following coding problem using the programming language python: There are a lot of things which could be cut — trees, paper, "the rope". In this problem you are going to cut a sequence of integers. There is a sequence of integers, which contains the equal number of even and odd numbers. Given a limited budget, you need to make maximum possible number of cuts such that each resulting segment will have the same number of odd and even integers. Cuts separate a sequence to continuous (contiguous) segments. You may think about each cut as a break between two adjacent elements in a sequence. So after cutting each element belongs to exactly one segment. Say, $[4, 1, 2, 3, 4, 5, 4, 4, 5, 5]$ $\to$ two cuts $\to$ $[4, 1 | 2, 3, 4, 5 | 4, 4, 5, 5]$. On each segment the number of even elements should be equal to the number of odd elements. The cost of the cut between $x$ and $y$ numbers is $|x - y|$ bitcoins. Find the maximum possible number of cuts that can be made while spending no more than $B$ bitcoins. The input will be provided via standard input and looks as follows: First line of the input contains an integer $n$ ($2 \le n \le 100$) and an integer $B$ ($1 \le B \le 100$) — the number of elements in the sequence and the number of bitcoins you have. Second line contains $n$ integers: $a_1$, $a_2$, ..., $a_n$ ($1 \le a_i \le 100$) — elements of the sequence, which contains the equal number of even and odd numbers You should write the solution as standard output as follows: Print the maximum possible number of cuts which can be made while spending no more than $B$ bitcoins. Here are example inputs and outputs for the problem: Example Input 1: 6 4 1 2 5 10 15 20 Example Output 1: 1 Example Input 2: 4 10 1 3 2 4 Example Output 2: 0 Example Input 3: 6 100 1 2 3 4 5 6 Example Output 3: 2 Now solve the problem by providing the code.
n,b=map(int,input().split()) a=list(map(int,input().split())) q,w,l,m=0,0,[],0 for i in range(n-1): if a[i]&1:q+=1 else:w+=1 if q==w:l.append(abs(a[i]-a[i+1])) l.sort() for i in l: if i<=b:m+=1;b-=i else:break print(m)
vfc_82085
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 4\n1 2 5 10 15 20", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 10\n1 3 2 4", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 100\n1 2 3 4 5 6", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 100\n13 78", "output": "0", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
215
Solve the following coding problem using the programming language python: Vasya's bicycle chain drive consists of two parts: *n* stars are attached to the pedal axle, *m* stars are attached to the rear wheel axle. The chain helps to rotate the rear wheel by transmitting the pedal rotation. We know that the *i*-th star on the pedal axle has *a**i* (0<=&lt;<=*a*1<=&lt;<=*a*2<=&lt;<=...<=&lt;<=*a**n*) teeth, and the *j*-th star on the rear wheel axle has *b**j* (0<=&lt;<=*b*1<=&lt;<=*b*2<=&lt;<=...<=&lt;<=*b**m*) teeth. Any pair (*i*,<=*j*) (1<=≤<=*i*<=≤<=*n*; 1<=≤<=*j*<=≤<=*m*) is called a gear and sets the indexes of stars to which the chain is currently attached. Gear (*i*,<=*j*) has a gear ratio, equal to the value . Since Vasya likes integers, he wants to find such gears (*i*,<=*j*), that their ratios are integers. On the other hand, Vasya likes fast driving, so among all "integer" gears (*i*,<=*j*) he wants to choose a gear with the maximum ratio. Help him to find the number of such gears. In the problem, fraction denotes division in real numbers, that is, no rounding is performed. The input will be provided via standard input and looks as follows: The first input line contains integer *n* (1<=≤<=*n*<=≤<=50) — the number of stars on the bicycle's pedal axle. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) in the order of strict increasing. The third input line contains integer *m* (1<=≤<=*m*<=≤<=50) — the number of stars on the rear wheel axle. The fourth line contains *m* integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**i*<=≤<=104) in the order of strict increasing. It is guaranteed that there exists at least one gear (*i*,<=*j*), that its gear ratio is an integer. The numbers on the lines are separated by spaces. You should write the solution as standard output as follows: Print the number of "integer" gears with the maximum ratio among all "integer" gears. Here are example inputs and outputs for the problem: Example Input 1: 2 4 5 3 12 13 15 Example Output 1: 2 Example Input 2: 4 1 2 3 4 5 10 11 12 13 14 Example Output 2: 1 Now solve the problem by providing the code.
import math n=int(input()) arr=[int(x) for x in input().split()] m=int(input()) brr=[int(x) for x in input().split()] mx=0 for i in range(n): for j in range(m): if int(math.ceil(brr[j]/arr[i]))==brr[j]//arr[i]: if brr[j]//arr[i]>mx: mx=brr[j]//arr[i] c=0 for i in range(n): for j in range(m): if int(math.ceil(brr[j]/arr[i]))==brr[j]//arr[i]: if brr[j]//arr[i]==mx: c+=1 print(c)
vfc_82089
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4 5\n3\n12 13 15", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 2 3 4\n5\n10 11 12 13 14", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1\n1\n1", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 2\n1\n1", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1\n2\n1 2", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n3 7 11 13\n4\n51 119 187 221", "output": "4", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
617
Solve the following coding problem using the programming language python: An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point *x*(*x*<=&gt;<=0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forward. Determine, what is the minimum number of steps he need to make in order to get to his friend's house. The input will be provided via standard input and looks as follows: The first line of the input contains an integer *x* (1<=≤<=*x*<=≤<=1<=000<=000) — The coordinate of the friend's house. You should write the solution as standard output as follows: Print the minimum number of steps that elephant needs to make to get from point 0 to point *x*. Here are example inputs and outputs for the problem: Example Input 1: 5 Example Output 1: 1 Example Input 2: 12 Example Output 2: 3 Now solve the problem by providing the code.
n = int(input()) moves = 0 while n >0 : if n >=5: n-=5 elif n>=4: n-=4 elif n>=3: n-=3 elif n>=2: n-=2 elif n>= 1: n-=1 moves+=1 print(moves)
vfc_82093
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "12", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "999999", "output": "200000", "type": "stdin_stdout" }, { "fn_name": null, "input": "41", "output": "9", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000000", "output": "200000", "type": "stdin_stdout" }, { "fn_name": null, "input": "1", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
964
Solve the following coding problem using the programming language python: There are *n* incoming messages for Vasya. The *i*-th message is going to be received after *t**i* minutes. Each message has a cost, which equals to *A* initially. After being received, the cost of a message decreases by *B* each minute (it can become negative). Vasya can read any message after receiving it at any moment of time. After reading the message, Vasya's bank account receives the current cost of this message. Initially, Vasya's bank account is at 0. Also, each minute Vasya's bank account receives *C*·*k*, where *k* is the amount of received but unread messages. Vasya's messages are very important to him, and because of that he wants to have all messages read after *T* minutes. Determine the maximum amount of money Vasya's bank account can hold after *T* minutes. The input will be provided via standard input and looks as follows: The first line contains five integers *n*, *A*, *B*, *C* and *T* (1<=≤<=*n*,<=*A*,<=*B*,<=*C*,<=*T*<=≤<=1000). The second string contains *n* integers *t**i* (1<=≤<=*t**i*<=≤<=*T*). You should write the solution as standard output as follows: Output one integer  — the answer to the problem. Here are example inputs and outputs for the problem: Example Input 1: 4 5 5 3 5 1 5 5 4 Example Output 1: 20 Example Input 2: 5 3 1 1 3 2 2 2 1 1 Example Output 2: 15 Example Input 3: 5 5 3 4 5 1 2 3 4 5 Example Output 3: 35 Now solve the problem by providing the code.
n,a,b,c,t=[int(i) for i in (input().split(" "))] ans=0 lis=[int(i) for i in input().split(" ")] if(b>=c): ans=n*a else: for i in lis: ans+=(c*(t-i)+a-b*(t-i)) print(ans)
vfc_82105
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 5 5 3 5\n1 5 5 4", "output": "20", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3 1 1 3\n2 2 2 1 1", "output": "15", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5 3 4 5\n1 2 3 4 5", "output": "35", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 6 4 3 9\n2", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 9 7 5 3\n3 3 3 3 2 3 2 2 3 3", "output": "90", "type": "stdin_stdout" }, { "fn_name": null, "input": "44 464 748 420 366\n278 109 293 161 336 9 194 203 13 226 303 303 300 131 134 47 235 110 263 67 185 337 360 253 270 97 162 190 143 267 18 311 329 138 322 167 324 33 3 104 290 260 349 89", "output": "20416", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
514
Solve the following coding problem using the programming language python: Luke Skywalker gave Chewbacca an integer number *x*. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit *t* means replacing it with digit 9<=-<=*t*. Help Chewbacca to transform the initial number *x* to the minimum possible positive number by inverting some (possibly, zero) digits. The decimal representation of the final number shouldn't start with a zero. The input will be provided via standard input and looks as follows: The first line contains a single integer *x* (1<=≤<=*x*<=≤<=1018) — the number that Luke Skywalker gave to Chewbacca. You should write the solution as standard output as follows: Print the minimum possible positive number that Chewbacca can obtain after inverting some digits. The number shouldn't contain leading zeroes. Here are example inputs and outputs for the problem: Example Input 1: 27 Example Output 1: 22 Example Input 2: 4545 Example Output 2: 4444 Now solve the problem by providing the code.
s=input() ss="" for i in range(len(s)): if i==0 and s[i]=='9': ss+=s[i] continue if int(s[i])>9-int(s[i]): ss+=str(9-int(s[i])) else: ss+=s[i] print(ss)
vfc_82109
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "3000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "27", "output": "22", "type": "stdin_stdout" }, { "fn_name": null, "input": "4545", "output": "4444", "type": "stdin_stdout" }, { "fn_name": null, "input": "1", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "9", "output": "9", "type": "stdin_stdout" }, { "fn_name": null, "input": "8772", "output": "1222", "type": "stdin_stdout" }, { "fn_name": null, "input": "81", "output": "11", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
467
Solve the following coding problem using the programming language python: George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory. George and Alex want to live in the same room. The dormitory has *n* rooms in total. At the moment the *i*-th room has *p**i* people living in it and the room can accommodate *q**i* people in total (*p**i*<=≤<=*q**i*). Your task is to count how many rooms has free place for both George and Alex. The input will be provided via standard input and looks as follows: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of rooms. The *i*-th of the next *n* lines contains two integers *p**i* and *q**i* (0<=≤<=*p**i*<=≤<=*q**i*<=≤<=100) — the number of people who already live in the *i*-th room and the room's capacity. You should write the solution as standard output as follows: Print a single integer — the number of rooms where George and Alex can move in. Here are example inputs and outputs for the problem: Example Input 1: 3 1 1 2 2 3 3 Example Output 1: 0 Example Input 2: 3 1 10 0 10 10 10 Example Output 2: 2 Now solve the problem by providing the code.
n = int(input()) accomodation = [] available = 0 for i in range(n): inhabitants, capacity = list(map(int, input().split())) accomodation.append((inhabitants, capacity)) if capacity - inhabitants >= 2: available += 1 else: continue print(available)
vfc_82113
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 1\n2 2\n3 3", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 10\n0 10\n10 10", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n36 67\n61 69", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n21 71\n10 88\n43 62", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 2\n2 3\n3 4", "output": "0", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
268
Solve the following coding problem using the programming language python: Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different. There are *n* teams taking part in the national championship. The championship consists of *n*·(*n*<=-<=1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number. You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question. The input will be provided via standard input and looks as follows: The first line contains an integer *n* (2<=≤<=*n*<=≤<=30). Each of the following *n* lines contains a pair of distinct space-separated integers *h**i*, *a**i* (1<=≤<=*h**i*,<=*a**i*<=≤<=100) — the colors of the *i*-th team's home and guest uniforms, respectively. You should write the solution as standard output as follows: In a single line print the number of games where the host team is going to play in the guest uniform. Here are example inputs and outputs for the problem: Example Input 1: 3 1 2 2 4 3 4 Example Output 1: 1 Example Input 2: 4 100 42 42 100 5 42 100 5 Example Output 2: 5 Example Input 3: 2 1 2 1 2 Example Output 3: 0 Now solve the problem by providing the code.
n = int(input()) ho = [] gst = [] for i in range(n): team = input().split() ho.append(team[0]) gst.append(team[1]) count = 0 for c in ho: count += gst.count(c) print(count)
vfc_82117
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 2\n2 4\n3 4", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n100 42\n42 100\n5 42\n100 5", "output": "5", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
777
Solve the following coding problem using the programming language python: Of course you have heard the famous task about Hanoi Towers, but did you know that there is a special factory producing the rings for this wonderful game? Once upon a time, the ruler of the ancient Egypt ordered the workers of Hanoi Factory to create as high tower as possible. They were not ready to serve such a strange order so they had to create this new tower using already produced rings. There are *n* rings in factory's stock. The *i*-th ring has inner radius *a**i*, outer radius *b**i* and height *h**i*. The goal is to select some subset of rings and arrange them such that the following conditions are satisfied: - Outer radiuses form a non-increasing sequence, i.e. one can put the *j*-th ring on the *i*-th ring only if *b**j*<=≤<=*b**i*. - Rings should not fall one into the the other. That means one can place ring *j* on the ring *i* only if *b**j*<=&gt;<=*a**i*. - The total height of all rings used should be maximum possible. The input will be provided via standard input and looks as follows: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the number of rings in factory's stock. The *i*-th of the next *n* lines contains three integers *a**i*, *b**i* and *h**i* (1<=≤<=*a**i*,<=*b**i*,<=*h**i*<=≤<=109, *b**i*<=&gt;<=*a**i*) — inner radius, outer radius and the height of the *i*-th ring respectively. You should write the solution as standard output as follows: Print one integer — the maximum height of the tower that can be obtained. Here are example inputs and outputs for the problem: Example Input 1: 3 1 5 1 2 6 2 3 7 3 Example Output 1: 6 Example Input 2: 4 1 2 1 1 3 3 4 6 2 5 7 1 Example Output 2: 4 Now solve the problem by providing the code.
read = input n = int(read()) c = [] for i in range(n): a, b, h = map(int, read().split()) c.append((b, a, h)) c.append((1e18, 0, 0)) c.sort() c.reverse() s, p = [0], [0] * (n + 1) for i in range(1, n + 1): while c[s[-1]][1] >= c[i][0]: s.pop() p[i] = p[s[-1]] + c[i][2] s.append(i) print(max(p))
vfc_82125
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 5 1\n2 6 2\n3 7 3", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 2 1\n1 3 3\n4 6 2\n5 7 1", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1 2 1", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n6 10 4\n9 20 19\n8 11 18\n18 20 1\n19 20 8", "output": "50", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n21 25 26\n14 30 22\n6 29 30\n13 23 21\n10 11 5", "output": "99", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
551
Solve the following coding problem using the programming language python: Professor GukiZ likes programming contests. He especially likes to rate his students on the contests he prepares. Now, he has decided to prepare a new contest. In total, *n* students will attend, and before the start, every one of them has some positive integer rating. Students are indexed from 1 to *n*. Let's denote the rating of *i*-th student as *a**i*. After the contest ends, every student will end up with some positive integer position. GukiZ expects that his students will take places according to their ratings. He thinks that each student will take place equal to . In particular, if student *A* has rating strictly lower then student *B*, *A* will get the strictly better position than *B*, and if two students have equal ratings, they will share the same position. GukiZ would like you to reconstruct the results by following his expectations. Help him and determine the position after the end of the contest for each of his students if everything goes as expected. The input will be provided via standard input and looks as follows: The first line contains integer *n* (1<=≤<=*n*<=≤<=2000), number of GukiZ's students. The second line contains *n* numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=2000) where *a**i* is the rating of *i*-th student (1<=≤<=*i*<=≤<=*n*). You should write the solution as standard output as follows: In a single line, print the position after the end of the contest for each of *n* students in the same order as they appear in the input. Here are example inputs and outputs for the problem: Example Input 1: 3 1 3 3 Example Output 1: 3 1 1 Example Input 2: 1 1 Example Output 2: 1 Example Input 3: 5 3 5 3 4 5 Example Output 3: 4 1 4 3 1 Now solve the problem by providing the code.
wwe=int(input()) s=list(map(int,input().split())) p=sorted(s,reverse=True) k={} for i in s: if i in k: print(k[i],end=' ') else: for j in range(len(p)): if p[j]==i: print(j+1,end=' ') k[i]=j+1 break
vfc_82129
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 3 3", "output": "3 1 1", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n3 5 3 4 5", "output": "4 1 4 3 1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
981
Solve the following coding problem using the programming language python: A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not. A substring $s[l \ldots r]$ ($1<=\leq<=l<=\leq<=r<=\leq<=|s|$) of a string $s<==<=s_{1}s_{2} \ldots s_{|s|}$ is the string $s_{l}s_{l<=+<=1} \ldots s_{r}$. Anna does not like palindromes, so she makes her friends call her Ann. She also changes all the words she reads in a similar way. Namely, each word $s$ is changed into its longest substring that is not a palindrome. If all the substrings of $s$ are palindromes, she skips the word at all. Some time ago Ann read the word $s$. What is the word she changed it into? The input will be provided via standard input and looks as follows: The first line contains a non-empty string $s$ with length at most $50$ characters, containing lowercase English letters only. You should write the solution as standard output as follows: If there is such a substring in $s$ that is not a palindrome, print the maximum length of such a substring. Otherwise print $0$. Note that there can be multiple longest substrings that are not palindromes, but their length is unique. Here are example inputs and outputs for the problem: Example Input 1: mew Example Output 1: 3 Example Input 2: wuffuw Example Output 2: 5 Example Input 3: qqqqqqqq Example Output 3: 0 Now solve the problem by providing the code.
def is_pal(S): for i in range(0, len(S)): if S[i] != S[-(i+1)]: return False return True while True: S = input() if not is_pal(S): print(len(S)) else: if S.count(S[0]) == len(S): print(0) else: print(len(S)-1) break
vfc_82133
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "mew", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "wuffuw", "output": "5", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
581
Solve the following coding problem using the programming language python: One day Vasya the Hipster decided to count how many socks he had. It turned out that he had *a* red socks and *b* blue socks. According to the latest fashion, hipsters should wear the socks of different colors: a red one on the left foot, a blue one on the right foot. Every day Vasya puts on new socks in the morning and throws them away before going to bed as he doesn't want to wash them. Vasya wonders, what is the maximum number of days when he can dress fashionable and wear different socks, and after that, for how many days he can then wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Can you help him? The input will be provided via standard input and looks as follows: The single line of the input contains two positive integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100) — the number of red and blue socks that Vasya's got. You should write the solution as standard output as follows: Print two space-separated integers — the maximum number of days when Vasya can wear different socks and the number of days when he can wear the same socks until he either runs out of socks or cannot make a single pair from the socks he's got. Keep in mind that at the end of the day Vasya throws away the socks that he's been wearing on that day. Here are example inputs and outputs for the problem: Example Input 1: 3 1 Example Output 1: 1 1 Example Input 2: 2 3 Example Output 2: 2 0 Example Input 3: 7 3 Example Output 3: 3 2 Now solve the problem by providing the code.
def main(): (red_socks, blue_socks) = input().split() count = 0 (red_socks, blue_socks) = int(red_socks), int(blue_socks) while int(red_socks) > 0 and int(blue_socks) > 0: count += 1 (red_socks, blue_socks) = red_socks - 1, blue_socks - 1 print(count, red_socks // 2 + blue_socks // 2) main()
vfc_82137
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 1", "output": "1 1", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3", "output": "2 0", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
886
Solve the following coding problem using the programming language python: Vlad likes to eat in cafes very much. During his life, he has visited cafes *n* times. Unfortunately, Vlad started to feel that his last visits are not any different from each other. To fix that Vlad had a small research. First of all, Vlad assigned individual indices to all cafes. Then, he wrote down indices of cafes he visited in a row, in order of visiting them. Now, Vlad wants to find such a cafe that his last visit to that cafe was before his last visits to every other cafe. In other words, he wants to find such a cafe that he hasn't been there for as long as possible. Help Vlad to find that cafe. The input will be provided via standard input and looks as follows: In first line there is one integer *n* (1<=≤<=*n*<=≤<=2·105) — number of cafes indices written by Vlad. In second line, *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=2·105) are written — indices of cafes in order of being visited by Vlad. Vlad could visit some cafes more than once. Note that in numeration, some indices could be omitted. You should write the solution as standard output as follows: Print one integer — index of the cafe that Vlad hasn't visited for as long as possible. Here are example inputs and outputs for the problem: Example Input 1: 5 1 3 2 1 2 Example Output 1: 3 Example Input 2: 6 2 1 2 2 4 1 Example Output 2: 2 Now solve the problem by providing the code.
n = input() stol = input() stol = stol.split(' ') nums = {} for i in range(0,len(stol)): nums[stol[i]] = [i, len(stol)-i] dif = [] max = -1 imax = 0 fl = 0 for num in nums: if max<nums[num][1]: max = nums[num][1] imax = num print(imax)
vfc_82141
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 3 2 1 2", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n2 1 2 2 4 1", "output": "2", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
859
Solve the following coding problem using the programming language python: You may have heard of the pie rule before. It states that if two people wish to fairly share a slice of pie, one person should cut the slice in half, and the other person should choose who gets which slice. Alice and Bob have many slices of pie, and rather than cutting the slices in half, each individual slice will be eaten by just one person. The way Alice and Bob decide who eats each slice is as follows. First, the order in which the pies are to be handed out is decided. There is a special token called the "decider" token, initially held by Bob. Until all the pie is handed out, whoever has the decider token will give the next slice of pie to one of the participants, and the decider token to the other participant. They continue until no slices of pie are left. All of the slices are of excellent quality, so each participant obviously wants to maximize the total amount of pie they get to eat. Assuming both players make their decisions optimally, how much pie will each participant receive? The input will be provided via standard input and looks as follows: Input will begin with an integer *N* (1<=≤<=*N*<=≤<=50), the number of slices of pie. Following this is a line with *N* integers indicating the sizes of the slices (each between 1 and 100000, inclusive), in the order in which they must be handed out. You should write the solution as standard output as follows: Print two integers. First, the sum of the sizes of slices eaten by Alice, then the sum of the sizes of the slices eaten by Bob, assuming both players make their decisions optimally. Here are example inputs and outputs for the problem: Example Input 1: 3 141 592 653 Example Output 1: 653 733 Example Input 2: 5 10 21 10 21 10 Example Output 2: 31 41 Now solve the problem by providing the code.
import math from random import random def getInt(): return(int(input())) def getInts(): line = input().split() return [int(l) for l in line] def getFloat(): return(float(input())) def getFloats(): line = input().split() return [float(l) for l in line] def getStrings(): line = input().split() return(line) N = getInt() values = getInts() nConsidered = 0 # nC, nO bestForChooserSoFar = [0, 0] for i in range(len(values)): v = values[len(values) - i - 1] qsIfTaken = [v + bestForChooserSoFar[1], bestForChooserSoFar[0]] qsIfGiven = [bestForChooserSoFar[0], v + bestForChooserSoFar[1]] if(qsIfTaken[0] >= qsIfGiven[0]): bestForChooserSoFar = qsIfTaken else: bestForChooserSoFar = qsIfGiven print(str(bestForChooserSoFar[1]) + ' ' + str(bestForChooserSoFar[0]))
vfc_82145
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n141 592 653", "output": "653 733", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n10 21 10 21 10", "output": "31 41", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n100000", "output": "0 100000", "type": "stdin_stdout" }, { "fn_name": null, "input": "50\n100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000", "output": "2500000 2500000", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 100000", "output": "1 100000", "type": "stdin_stdout" }, { "fn_name": null, "input": "17\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536", "output": "65535 65536", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
811
Solve the following coding problem using the programming language python: At regular competition Vladik and Valera won *a* and *b* candies respectively. Vladik offered 1 his candy to Valera. After that Valera gave Vladik 2 his candies, so that no one thought that he was less generous. Vladik for same reason gave 3 candies to Valera in next turn. More formally, the guys take turns giving each other one candy more than they received in the previous turn. This continued until the moment when one of them couldn’t give the right amount of candy. Candies, which guys got from each other, they don’t consider as their own. You need to know, who is the first who can’t give the right amount of candy. The input will be provided via standard input and looks as follows: Single line of input data contains two space-separated integers *a*, *b* (1<=≤<=*a*,<=*b*<=≤<=109) — number of Vladik and Valera candies respectively. You should write the solution as standard output as follows: Pring a single line "Vladik’’ in case, if Vladik first who can’t give right amount of candy, or "Valera’’ otherwise. Here are example inputs and outputs for the problem: Example Input 1: 1 1 Example Output 1: Valera Example Input 2: 7 6 Example Output 2: Vladik Now solve the problem by providing the code.
import math while True: try: a,b=map(int,input().split()) except: break n=math.sqrt(a) n=int(n) bt=(n+1)*n if b>=bt: print("Vladik") else: print("Valera")
vfc_82149
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 1", "output": "Valera", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 6", "output": "Vladik", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
545
Solve the following coding problem using the programming language python: Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are *n* people in the queue. For each person we know time *t**i* needed to serve him. A person will be disappointed if the time he waits is more than the time needed to serve him. The time a person waits is the total time when all the people who stand in the queue in front of him are served. Susie thought that if we swap some people in the queue, then we can decrease the number of people who are disappointed. Help Susie find out what is the maximum number of not disappointed people can be achieved by swapping people in the queue. The input will be provided via standard input and looks as follows: The first line contains integer *n* (1<=≤<=*n*<=≤<=105). The next line contains *n* integers *t**i* (1<=≤<=*t**i*<=≤<=109), separated by spaces. You should write the solution as standard output as follows: Print a single number — the maximum number of not disappointed people in the queue. Here are example inputs and outputs for the problem: Example Input 1: 5 15 2 1 5 3 Example Output 1: 4 Now solve the problem by providing the code.
n = int(input()) tlist = list(map(int, input().split())) tlist.sort() count = 0 sum1 = tlist[0] for i in range(1,n): if sum1 <= tlist[i]: count += 1 sum1 += tlist[i] print(count+1)
vfc_82153
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n15 2 1 5 3", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "15\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n13 2 5 55 21 34 1 8 1 3", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n8 256 16 1 2 1 64 4 128 32", "output": "10", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n10000 40000 10000 50000 20000 100000 10000 100 30000 500", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1000000000", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
490
Solve the following coding problem using the programming language python: The School №0 of the capital of Berland has *n* children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value *t**i*: - *t**i*<==<=1, if the *i*-th child is good at programming, - *t**i*<==<=2, if the *i*-th child is good at maths, - *t**i*<==<=3, if the *i*-th child is good at PE Each child happens to be good at exactly one of these three subjects. The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team. What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? The input will be provided via standard input and looks as follows: The first line contains integer *n* (1<=≤<=*n*<=≤<=5000) — the number of children in the school. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=3), where *t**i* describes the skill of the *i*-th child. You should write the solution as standard output as follows: In the first line output integer *w* — the largest possible number of teams. Then print *w* lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to *n* in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value *w* equal to 0. Here are example inputs and outputs for the problem: Example Input 1: 7 1 3 1 3 2 1 2 Example Output 1: 2 3 5 2 6 7 4 Example Input 2: 4 2 1 1 2 Example Output 2: 0 Now solve the problem by providing the code.
n = int(input()) x = list(map(int, input().split())) a = [i + 1 for i, j in enumerate(x) if j == 1] b = [i + 1 for i, j in enumerate(x) if j == 2] c = [i + 1 for i, j in enumerate(x) if j == 3] if not a or not b or not c: print(0) else: print(min(len(a), len(b), len(c))) for i, j, k in zip(a, b, c): print(i, j, k)
vfc_82157
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\n1 3 1 3 2 1 2", "output": "2\n3 5 2\n6 7 4", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n2 1 1 2", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n2", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n3 1", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2 1 2", "output": "0", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
222
Solve the following coding problem using the programming language python: One day shooshuns found a sequence of *n* integers, written on a blackboard. The shooshuns can perform one operation with it, the operation consists of two steps: 1. Find the number that goes *k*-th in the current sequence and add the same number to the end of the sequence; 1. Delete the first number of the current sequence. The shooshuns wonder after how many operations all numbers on the board will be the same and whether all numbers will ever be the same. The input will be provided via standard input and looks as follows: The first line contains two space-separated integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105). The second line contains *n* space-separated integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the sequence that the shooshuns found. You should write the solution as standard output as follows: Print the minimum number of operations, required for all numbers on the blackboard to become the same. If it is impossible to achieve, print -1. Here are example inputs and outputs for the problem: Example Input 1: 3 2 3 1 1 Example Output 1: 1 Example Input 2: 3 1 3 1 1 Example Output 2: -1 Now solve the problem by providing the code.
n,k=map(int,input().split()) a=list(map(int,input().split())) while n and a[n-1]==a[-1]: n-=1 if k>n: print(n) else: print(-1)
vfc_82161
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "3000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n3 1 1", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1\n3 1 1", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n1", "output": "0", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
746
Solve the following coding problem using the programming language python: Polycarp is mad about coding, that is why he writes Sveta encoded messages. He calls the median letter in a word the letter which is in the middle of the word. If the word's length is even, the median letter is the left of the two middle letters. In the following examples, the median letter is highlighted: contest, info. If the word consists of single letter, then according to above definition this letter is the median letter. Polycarp encodes each word in the following way: he writes down the median letter of the word, then deletes it and repeats the process until there are no letters left. For example, he encodes the word volga as logva. You are given an encoding *s* of some word, your task is to decode it. The input will be provided via standard input and looks as follows: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=2000) — the length of the encoded word. The second line contains the string *s* of length *n* consisting of lowercase English letters — the encoding. You should write the solution as standard output as follows: Print the word that Polycarp encoded. Here are example inputs and outputs for the problem: Example Input 1: 5 logva Example Output 1: volga Example Input 2: 2 no Example Output 2: no Example Input 3: 4 abba Example Output 3: baba Now solve the problem by providing the code.
n = int(input()) a=input() if (n-1)%2==0: c = '' i = n - 2 while i % 2 != 0 and i > 0: c = c + a[i] i = i - 2 i = 0 while i % 2 == 0 and i < n: c = c + a[i] i = i + 2 else: c = '' i = n - 2 while i % 2 == 0 and i >= 0: c = c + a[i] i = i - 2 i = 1 while i % 2 != 0 and i < n: c = c + a[i] i = i + 2 print(c)
vfc_82165
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\nlogva", "output": "volga", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\nno", "output": "no", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\nabba", "output": "baba", "type": "stdin_stdout" }, { "fn_name": null, "input": "51\nkfsmpaeviowvkdbuhdagquxxqniselafnfbrgbhmsugcbbnlrvv", "output": "vlbcumbrfflsnxugdudvovamfkspeiwkbhaqxqieanbghsgbnrv", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\nw", "output": "w", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
Solve the following coding problem using the programming language python: Little Artem found a grasshopper. He brought it to his house and constructed a jumping area for him. The area looks like a strip of cells 1<=×<=*n*. Each cell contains the direction for the next jump and the length of that jump. Grasshopper starts in the first cell and follows the instructions written on the cells. Grasshopper stops immediately if it jumps out of the strip. Now Artem wants to find out if this will ever happen. The input will be provided via standard input and looks as follows: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=100<=000) — length of the strip. Next line contains a string of length *n* which consists of characters "&lt;" and "&gt;" only, that provide the direction of the jump from the corresponding cell. Next line contains *n* integers *d**i* (1<=≤<=*d**i*<=≤<=109) — the length of the jump from the *i*-th cell. You should write the solution as standard output as follows: Print "INFINITE" (without quotes) if grasshopper will continue his jumps forever. Otherwise print "FINITE" (without quotes). Here are example inputs and outputs for the problem: Example Input 1: 2 &gt;&lt; 1 2 Example Output 1: FINITE Example Input 2: 3 &gt;&gt;&lt; 2 1 1 Example Output 2: INFINITE Now solve the problem by providing the code.
n = int(input()) s = str(input()) L = list(map(int, input().split())) D = [0 for _ in range(n)] r = 0 ok = 1 while r >= 0 and r < n: if D[r]: ok = 0 break else: D[r] = 1 if s[r] == "<": r = r - L[r] else: r = r + L[r] if ok: print("FINITE") else: print("INFINITE")
vfc_82169
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n><\n1 2", "output": "FINITE", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n>><\n2 1 1", "output": "INFINITE", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n>\n1000000000", "output": "FINITE", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n<\n1000000000", "output": "FINITE", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n>>\n1 1", "output": "FINITE", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n>><><\n1 2 3 1 2", "output": "FINITE", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
114
Solve the following coding problem using the programming language python: When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmyschaya" (which literally means "the tma of tmas") used to stand for a million. Petya wanted to modernize the words we use for numbers and invented a word petricium that represents number *k*. Moreover, petricium la petricium stands for number *k*2, petricium la petricium la petricium stands for *k*3 and so on. All numbers of this form are called petriciumus cifera, and the number's importance is the number of articles la in its title. Petya's invention brought on a challenge that needed to be solved quickly: does some number *l* belong to the set petriciumus cifera? As Petya is a very busy schoolboy he needs to automate the process, he asked you to solve it. The input will be provided via standard input and looks as follows: The first input line contains integer number *k*, the second line contains integer number *l* (2<=≤<=*k*,<=*l*<=≤<=231<=-<=1). You should write the solution as standard output as follows: You should print in the first line of the output "YES", if the number belongs to the set petriciumus cifera and otherwise print "NO". If the number belongs to the set, then print on the seconds line the only number — the importance of number *l*. Here are example inputs and outputs for the problem: Example Input 1: 5 25 Example Output 1: YES 1 Example Input 2: 3 8 Example Output 2: NO Now solve the problem by providing the code.
import math k=int(input()) l=int(input()) n=0 tmp=k while(l>tmp and l!=tmp): tmp=tmp*k n+=1 if(l==tmp): print("YES") print(n) else: print("NO")
vfc_82173
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n25", "output": "YES\n1", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n8", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "123\n123", "output": "YES\n0", "type": "stdin_stdout" }, { "fn_name": null, "input": "99\n970300", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000\n6666666", "output": "NO", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
4
Solve the following coding problem using the programming language python: One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest and the ripest one, in their opinion. After that the watermelon was weighed, and the scales showed *w* kilos. They rushed home, dying of thirst, and decided to divide the berry, however they faced a hard problem. Pete and Billy are great fans of even numbers, that's why they want to divide the watermelon in such a way that each of the two parts weighs even number of kilos, at the same time it is not obligatory that the parts are equal. The boys are extremely tired and want to start their meal as soon as possible, that's why you should help them and find out, if they can divide the watermelon in the way they want. For sure, each of them should get a part of positive weight. The input will be provided via standard input and looks as follows: The first (and the only) input line contains integer number *w* (1<=≤<=*w*<=≤<=100) — the weight of the watermelon bought by the boys. You should write the solution as standard output as follows: Print YES, if the boys can divide the watermelon into two parts, each of them weighing even number of kilos; and NO in the opposite case. Here are example inputs and outputs for the problem: Example Input 1: 8 Example Output 1: YES Now solve the problem by providing the code.
weight = input() w = int(weight) a = 0 b = w - a while True: a += 1 b = w - a if a % 2 == 0 and b % 2 == 0 and b != 0: print('YES') break elif a > w: print('NO') break else: continue
vfc_82177
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "5000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "5", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "4", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "3", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "2", "output": "NO", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
49
Solve the following coding problem using the programming language python: Vasya plays the sleuth with his friends. The rules of the game are as follows: those who play for the first time, that is Vasya is the sleuth, he should investigate a "crime" and find out what is happening. He can ask any questions whatsoever that can be answered with "Yes" or "No". All the rest agree beforehand to answer the questions like that: if the question’s last letter is a vowel, they answer "Yes" and if the last letter is a consonant, they answer "No". Of course, the sleuth knows nothing about it and his task is to understand that. Unfortunately, Vasya is not very smart. After 5 hours of endless stupid questions everybody except Vasya got bored. That’s why Vasya’s friends ask you to write a program that would give answers instead of them. The English alphabet vowels are: A, E, I, O, U, Y The English alphabet consonants are: B, C, D, F, G, H, J, K, L, M, N, P, Q, R, S, T, V, W, X, Z The input will be provided via standard input and looks as follows: The single line contains a question represented by a non-empty line consisting of large and small Latin letters, spaces and a question mark. The line length does not exceed 100. It is guaranteed that the question mark occurs exactly once in the line — as the last symbol and that the line contains at least one letter. You should write the solution as standard output as follows: Print answer for the question in a single line: YES if the answer is "Yes", NO if the answer is "No". Remember that in the reply to the question the last letter, not the last character counts. I. e. the spaces and the question mark do not count as letters. Here are example inputs and outputs for the problem: Example Input 1: Is it a melon? Example Output 1: NO Example Input 2: Is it an apple? Example Output 2: YES Example Input 3: Is it a banana ? Example Output 3: YES Example Input 4: Is it an apple and a banana simultaneouSLY? Example Output 4: YES Now solve the problem by providing the code.
n=input() n=list(n) n=n[::-1] l=['A','E','I','O','U','Y','a','e','i','o','u','y'] i=1 while(n[i]==' '): i=i+1 continue #print(n,i) if(n[i] not in l): print("NO") else: print("YES")
vfc_82181
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "Is it a melon?", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "Is it an apple?", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": " Is it a banana ?", "output": "YES", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
939
Solve the following coding problem using the programming language python: As you could know there are no male planes nor female planes. However, each plane on Earth likes some other plane. There are *n* planes on Earth, numbered from 1 to *n*, and the plane with number *i* likes the plane with number *f**i*, where 1<=≤<=*f**i*<=≤<=*n* and *f**i*<=≠<=*i*. We call a love triangle a situation in which plane *A* likes plane *B*, plane *B* likes plane *C* and plane *C* likes plane *A*. Find out if there is any love triangle on Earth. The input will be provided via standard input and looks as follows: The first line contains a single integer *n* (2<=≤<=*n*<=≤<=5000) — the number of planes. The second line contains *n* integers *f*1,<=*f*2,<=...,<=*f**n* (1<=≤<=*f**i*<=≤<=*n*, *f**i*<=≠<=*i*), meaning that the *i*-th plane likes the *f**i*-th. You should write the solution as standard output as follows: Output «YES» if there is a love triangle consisting of planes on Earth. Otherwise, output «NO». You can output any letter in lower case or in upper case. Here are example inputs and outputs for the problem: Example Input 1: 5 2 4 5 1 3 Example Output 1: YES Example Input 2: 5 5 5 5 5 1 Example Output 2: NO Now solve the problem by providing the code.
n = int(input()) f = [int(i) for i in input().split()] D = {} for i in range(1, n + 1): D[i] = f[i - 1] res = 'NO' for ver in D.keys(): chel = ver for _ in range(3): ver = D[ver] if ver == chel: res = 'YES' print(res)
vfc_82185
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n2 4 5 1 3", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n5 5 5 5 1", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n3 1 2", "output": "YES", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
38
Solve the following coding problem using the programming language python: The Berland Armed Forces System consists of *n* ranks that are numbered using natural numbers from 1 to *n*, where 1 is the lowest rank and *n* is the highest rank. One needs exactly *d**i* years to rise from rank *i* to rank *i*<=+<=1. Reaching a certain rank *i* having not reached all the previous *i*<=-<=1 ranks is impossible. Vasya has just reached a new rank of *a*, but he dreams of holding the rank of *b*. Find for how many more years Vasya should serve in the army until he can finally realize his dream. The input will be provided via standard input and looks as follows: The first input line contains an integer *n* (2<=≤<=*n*<=≤<=100). The second line contains *n*<=-<=1 integers *d**i* (1<=≤<=*d**i*<=≤<=100). The third input line contains two integers *a* and *b* (1<=≤<=*a*<=&lt;<=*b*<=≤<=*n*). The numbers on the lines are space-separated. You should write the solution as standard output as follows: Print the single number which is the number of years that Vasya needs to rise from rank *a* to rank *b*. Here are example inputs and outputs for the problem: Example Input 1: 3 5 6 1 2 Example Output 1: 5 Example Input 2: 3 5 6 1 3 Example Output 2: 11 Now solve the problem by providing the code.
a = int(input()) b = list(map(int,input().split())) c , d = list(map(int,input().split())) count = 0 for i in range(c,d): count += b[i-1] print(count)
vfc_82189
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n5 6\n1 2", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n5 6\n1 3", "output": "11", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n55\n1 2", "output": "55", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
208
Solve the following coding problem using the programming language python: Vasya works as a DJ in the best Berland nightclub, and he often uses dubstep music in his performance. Recently, he has decided to take a couple of old songs and make dubstep remixes from them. Let's assume that a song consists of some number of words. To make the dubstep remix of this song, Vasya inserts a certain number of words "WUB" before the first word of the song (the number may be zero), after the last word (the number may be zero), and between words (at least one between any pair of neighbouring words), and then the boy glues together all the words, including "WUB", in one string and plays the song at the club. For example, a song with words "I AM X" can transform into a dubstep remix as "WUBWUBIWUBAMWUBWUBX" and cannot transform into "WUBWUBIAMWUBX". Recently, Petya has heard Vasya's new dubstep track, but since he isn't into modern music, he decided to find out what was the initial song that Vasya remixed. Help Petya restore the original song. The input will be provided via standard input and looks as follows: The input consists of a single non-empty string, consisting only of uppercase English letters, the string's length doesn't exceed 200 characters. It is guaranteed that before Vasya remixed the song, no word contained substring "WUB" in it; Vasya didn't change the word order. It is also guaranteed that initially the song had at least one word. You should write the solution as standard output as follows: Print the words of the initial song that Vasya used to make a dubsteb remix. Separate the words with a space. Here are example inputs and outputs for the problem: Example Input 1: WUBWUBABCWUB Example Output 1: ABC Example Input 2: WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB Example Output 2: WE ARE THE CHAMPIONS MY FRIEND Now solve the problem by providing the code.
s = input() for x in s.split('WUB'): if ((x != ' ') and (x != '')): print(x,end=' ')
vfc_82193
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "WUBWUBABCWUB", "output": "ABC ", "type": "stdin_stdout" }, { "fn_name": null, "input": "WUBWEWUBAREWUBWUBTHEWUBCHAMPIONSWUBMYWUBFRIENDWUB", "output": "WE ARE THE CHAMPIONS MY FRIEND ", "type": "stdin_stdout" }, { "fn_name": null, "input": "WUBWUBWUBSR", "output": "SR ", "type": "stdin_stdout" }, { "fn_name": null, "input": "RWUBWUBWUBLWUB", "output": "R L ", "type": "stdin_stdout" }, { "fn_name": null, "input": "ZJWUBWUBWUBJWUBWUBWUBL", "output": "ZJ J L ", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
224
Solve the following coding problem using the programming language python: You've got an array *a*, consisting of *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. Your task is to find a minimal by inclusion segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that among numbers *a**l*,<= *a**l*<=+<=1,<= ...,<= *a**r* there are exactly *k* distinct numbers. Segment [*l*,<=*r*] (1<=≤<=*l*<=≤<=*r*<=≤<=*n*; *l*,<=*r* are integers) of length *m*<==<=*r*<=-<=*l*<=+<=1, satisfying the given property, is called minimal by inclusion, if there is no segment [*x*,<=*y*] satisfying the property and less then *m* in length, such that 1<=≤<=*l*<=≤<=*x*<=≤<=*y*<=≤<=*r*<=≤<=*n*. Note that the segment [*l*,<=*r*] doesn't have to be minimal in length among all segments, satisfying the given property. The input will be provided via standard input and looks as follows: The first line contains two space-separated integers: *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* — elements of the array *a* (1<=≤<=*a**i*<=≤<=105). You should write the solution as standard output as follows: Print a space-separated pair of integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such, that the segment [*l*,<=*r*] is the answer to the problem. If the sought segment does not exist, print "-1 -1" without the quotes. If there are multiple correct answers, print any of them. Here are example inputs and outputs for the problem: Example Input 1: 4 2 1 2 2 3 Example Output 1: 1 2 Example Input 2: 8 3 1 1 2 2 3 3 4 5 Example Output 2: 2 5 Example Input 3: 7 4 4 7 7 4 7 4 7 Example Output 3: -1 -1 Now solve the problem by providing the code.
import sys import os.path if(os.path.exists('input.txt')) : sys.stdin = open("input.txt", "r") sys.stdout = open("output.txt", "w") sys.stderr = open("error.txt", "w") depth = 1000005 mod = 1000000007 lim = mod * mod sys.setrecursionlimit(depth) linp = lambda: list(minp()) minp = lambda: map(int, input().split()) from math import inf, ceil, sqrt, log2 from collections import defaultdict, deque dd = lambda x: defaultdict(lambda: x) (n, k), a = minp(), linp() c, s = dd(0), set(a) for e in a : c[e] += 1 i, j = 0, n while len(s) > k : j -= 1 c[a[j]] -= 1 if c[a[j]] == 0 : s.remove(a[j]) j -= 1 while len(s) == k : if c[a[j]] > 1 : c[a[j]] -= 1 j -= 1 elif c[a[i]] > 1 : c[a[i]] -= 1 i += 1 else : break if len(set(a)) < k : print("-1 -1") else : print(i+1, j+1)
vfc_82197
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2\n1 2 2 3", "output": "1 2", "type": "stdin_stdout" }, { "fn_name": null, "input": "8 3\n1 1 2 2 3 3 4 5", "output": "2 5", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
440
Solve the following coding problem using the programming language python: Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has *n* episodes, numbered with integers from 1 to *n*. Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which episode has Polycaprus forgotten to watch? The input will be provided via standard input and looks as follows: The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100000) — the number of episodes in a season. Assume that the episodes are numbered by integers from 1 to *n*. The second line contains *n*<=-<=1 integer *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*n*) — the numbers of episodes that Polycarpus has watched. All values of *a**i* are distinct. You should write the solution as standard output as follows: Print the number of the episode that Polycarpus hasn't watched. Here are example inputs and outputs for the problem: Example Input 1: 10 3 8 10 1 7 9 6 5 2 Example Output 1: 4 Now solve the problem by providing the code.
n = int(input()) s = n * (n + 1) // 2 for x in input().split(): s -= int(x) print(s)
vfc_82201
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "500" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\n3 8 10 1 7 9 6 5 2", "output": "4", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
554
Solve the following coding problem using the programming language python: Ohana Matsumae is trying to clean a room, which is divided up into an *n* by *n* grid of squares. Each square is initially either clean or dirty. Ohana can sweep her broom over columns of the grid. Her broom is very strange: if she sweeps over a clean square, it will become dirty, and if she sweeps over a dirty square, it will become clean. She wants to sweep some columns of the room to maximize the number of rows that are completely clean. It is not allowed to sweep over the part of the column, Ohana can only sweep the whole column. Return the maximum number of rows that she can make completely clean. The input will be provided via standard input and looks as follows: The first line of input will be a single integer *n* (1<=≤<=*n*<=≤<=100). The next *n* lines will describe the state of the room. The *i*-th line will contain a binary string with *n* characters denoting the state of the *i*-th row of the room. The *j*-th character on this line is '1' if the *j*-th square in the *i*-th row is clean, and '0' if it is dirty. You should write the solution as standard output as follows: The output should be a single line containing an integer equal to a maximum possible number of rows that are completely clean. Here are example inputs and outputs for the problem: Example Input 1: 4 0101 1000 1111 0101 Example Output 1: 2 Example Input 2: 3 111 111 111 Example Output 2: 3 Now solve the problem by providing the code.
n = int(input()) p = [] for i in range(n): p.append(list(input())) max = 0 for i in range(n): q = p for t in range(n): if q[i][t] == '0': for k in range(n): if q[k][t] == '0': q[k][t] = '1' else: q[k][t] = '0' col = 0 for t in range(n): sum = 0 for e in range(n): if q[t][e] == '1': sum += 1 if sum == n: col += 1 if col > max: max = col print(max)
vfc_82205
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n0101\n1000\n1111\n0101", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n111\n111\n111", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n0100000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000\n0000000000", "output": "9", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n0111010011\n0111010011\n1010010001\n0111010011\n0000110000\n0111010011\n0111010011\n0000110000\n1010010001\n0111010011", "output": "6", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
43
Solve the following coding problem using the programming language python: One day Vasya decided to have a look at the results of Berland 1910 Football Championship’s finals. Unfortunately he didn't find the overall score of the match; however, he got hold of a profound description of the match's process. On the whole there are *n* lines in that description each of which described one goal. Every goal was marked with the name of the team that had scored it. Help Vasya, learn the name of the team that won the finals. It is guaranteed that the match did not end in a tie. The input will be provided via standard input and looks as follows: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) — the number of lines in the description. Then follow *n* lines — for each goal the names of the teams that scored it. The names are non-empty lines consisting of uppercase Latin letters whose lengths do not exceed 10 symbols. It is guaranteed that the match did not end in a tie and the description contains no more than two different teams. You should write the solution as standard output as follows: Print the name of the winning team. We remind you that in football the team that scores more goals is considered the winner. Here are example inputs and outputs for the problem: Example Input 1: 1 ABC Example Output 1: ABC Example Input 2: 5 A ABA ABA A A Example Output 2: A Now solve the problem by providing the code.
n = int(input()) scores = {} for i in range(n): team = input() scores[team] = scores.get(team, 0) + 1 print(max(scores.items(), key=lambda x: x[1])[0])
vfc_82209
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\nABC", "output": "ABC", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\nA\nABA\nABA\nA\nA", "output": "A", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\nXTSJEP\nXTSJEP", "output": "XTSJEP", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\nXZYDJAEDZ\nXZYDJAEDZ\nXZYDJAEDZ", "output": "XZYDJAEDZ", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\nQCCYXL\nQCCYXL\nAXGLFQDD", "output": "QCCYXL", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
515
Solve the following coding problem using the programming language python: Drazil is playing a math game with Varda. Let's define for positive integer *x* as a product of factorials of its digits. For example, . First, they choose a decimal number *a* consisting of *n* digits that contains at least one digit larger than 1. This number may possibly start with leading zeroes. Then they should find maximum positive number *x* satisfying following two conditions: 1. *x* doesn't contain neither digit 0 nor digit 1. 2. = . Help friends find such number. The input will be provided via standard input and looks as follows: The first line contains an integer *n* (1<=≤<=*n*<=≤<=15) — the number of digits in *a*. The second line contains *n* digits of *a*. There is at least one digit in *a* that is larger than 1. Number *a* may possibly contain leading zeroes. You should write the solution as standard output as follows: Output a maximum possible integer satisfying the conditions above. There should be no zeroes and ones in this number decimal representation. Here are example inputs and outputs for the problem: Example Input 1: 4 1234 Example Output 1: 33222 Example Input 2: 3 555 Example Output 2: 555 Now solve the problem by providing the code.
answer = { "7": [7], "8": [7, 2, 2, 2], "9": [7, 3, 3, 2], "6": [5, 3], "5": [5], "4": [3, 2, 2], "3": [3], "2": [2], "1": [], "0": [] } def main(): _ = input() inp = str(input()) ans = [] for i in inp: ans += answer[i] ans.sort() for i in reversed(ans): print(i, end="") main()
vfc_82213
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1234", "output": "33222", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n555", "output": "555", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
499
Solve the following coding problem using the programming language python: You have a new professor of graph theory and he speaks very quickly. You come up with the following plan to keep up with his lecture and make notes. You know two languages, and the professor is giving the lecture in the first one. The words in both languages consist of lowercase English characters, each language consists of several words. For each language, all words are distinct, i.e. they are spelled differently. Moreover, the words of these languages have a one-to-one correspondence, that is, for each word in each language, there exists exactly one word in the other language having has the same meaning. You can write down every word the professor says in either the first language or the second language. Of course, during the lecture you write down each word in the language in which the word is shorter. In case of equal lengths of the corresponding words you prefer the word of the first language. You are given the text of the lecture the professor is going to read. Find out how the lecture will be recorded in your notes. The input will be provided via standard input and looks as follows: The first line contains two integers, *n* and *m* (1<=≤<=*n*<=≤<=3000, 1<=≤<=*m*<=≤<=3000) — the number of words in the professor's lecture and the number of words in each of these languages. The following *m* lines contain the words. The *i*-th line contains two strings *a**i*, *b**i* meaning that the word *a**i* belongs to the first language, the word *b**i* belongs to the second language, and these two words have the same meaning. It is guaranteed that no word occurs in both languages, and each word occurs in its language exactly once. The next line contains *n* space-separated strings *c*1,<=*c*2,<=...,<=*c**n* — the text of the lecture. It is guaranteed that each of the strings *c**i* belongs to the set of strings {*a*1,<=*a*2,<=... *a**m*}. All the strings in the input are non-empty, each consisting of no more than 10 lowercase English letters. You should write the solution as standard output as follows: Output exactly *n* words: how you will record the lecture in your notebook. Output the words of the lecture in the same order as in the input. Here are example inputs and outputs for the problem: Example Input 1: 4 3 codeforces codesecrof contest round letter message codeforces contest letter contest Example Output 1: codeforces round letter round Example Input 2: 5 3 joll wuqrd euzf un hbnyiyc rsoqqveh hbnyiyc joll joll euzf joll Example Output 2: hbnyiyc joll joll un joll Now solve the problem by providing the code.
a,b = (map(int,input().split())) dic = {} for i in range(b): a = input().split(' ') if(len(a[0])>len(a[1])): dic[a[0]] = a[1] dic[a[1]] = a[1] else: dic[a[0]] = a[0] dic[a[1]] = a[0] t = input().split() for i in range(len(t)): print(dic[t[i]],end = ' ')
vfc_82217
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 3\ncodeforces codesecrof\ncontest round\nletter message\ncodeforces contest letter contest", "output": "codeforces round letter round", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3\njoll wuqrd\neuzf un\nhbnyiyc rsoqqveh\nhbnyiyc joll joll euzf joll", "output": "hbnyiyc joll joll un joll", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5\nqueyqj f\nb vn\ntabzvk qpfzoqx\nytnyonoc hnxsd\njpggvr lchinjmt\nqueyqj jpggvr b ytnyonoc b", "output": "f jpggvr b hnxsd b", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 22\nazbrll oen\ngh vdyayei\njphveblohx vfglv\nmfyxib jepnvhcuwo\nrpikazqj uam\nl rx\nokjenof qpnyi\nj tixqrno\nod itozmfct\nikkdxmirx ev\nqexftojc p\nkdazb zjs\nmbk ykvqjrxaxu\nhbcwhouzq pwt\nmirpsz zfaegpl\nuhkkvcj rlvwj\nef iqnnwtolrc\npjzfcpmeag ecdayth\nsa qcthz\ncbfhfxi qrnbvdryz\nwqel tj\natx smkbid\nef hbcwhouzq cbfhfxi hbcwhouzq mirpsz cbfhfxi cbfhfxi okjenof pjzfcpmeag kdazb", "output": "ef pwt cbfhfxi pwt mirpsz cbfhfxi cbfhfxi qpnyi ecdayth zjs", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\namit am\namit", "output": "am", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
1008
Solve the following coding problem using the programming language python: Vitya has just started learning Berlanese language. It is known that Berlanese uses the Latin alphabet. Vowel letters are "a", "o", "u", "i", and "e". Other letters are consonant. In Berlanese, there has to be a vowel after every consonant, but there can be any letter after any vowel. The only exception is a consonant "n"; after this letter, there can be any letter (not only a vowel) or there can be no letter at all. For example, the words "harakiri", "yupie", "man", and "nbo" are Berlanese while the words "horse", "king", "my", and "nz" are not. Help Vitya find out if a word $s$ is Berlanese. The input will be provided via standard input and looks as follows: The first line of the input contains the string $s$ consisting of $|s|$ ($1\leq |s|\leq 100$) lowercase Latin letters. You should write the solution as standard output as follows: Print "YES" (without quotes) if there is a vowel after every consonant except "n", otherwise print "NO". You can print each letter in any case (upper or lower). Here are example inputs and outputs for the problem: Example Input 1: sumimasen Example Output 1: YES Example Input 2: ninja Example Output 2: YES Example Input 3: codeforces Example Output 3: NO Now solve the problem by providing the code.
s=input() answer='yes' if s[-1] not in "naeiou": answer='no' for i in range(len(s)-1): if s[i] not in "naeiou" and s[i+1] not in "aeiou": answer='no' print(answer)
vfc_82221
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "sumimasen", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "ninja", "output": "YES", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
255
Solve the following coding problem using the programming language python: Greg is a beginner bodybuilder. Today the gym coach gave him the training plan. All it had was *n* integers *a*1,<=*a*2,<=...,<=*a**n*. These numbers mean that Greg needs to do exactly *n* exercises today. Besides, Greg should repeat the *i*-th in order exercise *a**i* times. Greg now only does three types of exercises: "chest" exercises, "biceps" exercises and "back" exercises. Besides, his training is cyclic, that is, the first exercise he does is a "chest" one, the second one is "biceps", the third one is "back", the fourth one is "chest", the fifth one is "biceps", and so on to the *n*-th exercise. Now Greg wonders, which muscle will get the most exercise during his training. We know that the exercise Greg repeats the maximum number of times, trains the corresponding muscle the most. Help Greg, determine which muscle will get the most training. The input will be provided via standard input and looks as follows: The first line contains integer *n* (1<=≤<=*n*<=≤<=20). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=25) — the number of times Greg repeats the exercises. You should write the solution as standard output as follows: Print word "chest" (without the quotes), if the chest gets the most exercise, "biceps" (without the quotes), if the biceps gets the most exercise and print "back" (without the quotes) if the back gets the most exercise. It is guaranteed that the input is such that the answer to the problem is unambiguous. Here are example inputs and outputs for the problem: Example Input 1: 2 2 8 Example Output 1: biceps Example Input 2: 3 5 1 10 Example Output 2: back Example Input 3: 7 3 3 2 7 9 6 8 Example Output 3: chest Now solve the problem by providing the code.
n = int(input()) l_n = list(map(int, input().split())) a_t = [0]*3 for i in range(n): a_t[i % 3] += l_n[i] if a_t[0] > a_t[1] and a_t[0] > a_t[2]: print("chest") elif a_t[1] > a_t[2]: print("biceps") else: print("back")
vfc_82225
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2 8", "output": "biceps", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n5 1 10", "output": "back", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n3 3 2 7 9 6 8", "output": "chest", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n5 6 6 2", "output": "chest", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
664
Solve the following coding problem using the programming language python: Greatest common divisor *GCD*(*a*,<=*b*) of two positive integers *a* and *b* is equal to the biggest integer *d* such that both integers *a* and *b* are divisible by *d*. There are many efficient algorithms to find greatest common divisor *GCD*(*a*,<=*b*), for example, Euclid algorithm. Formally, find the biggest integer *d*, such that all integers *a*,<=*a*<=+<=1,<=*a*<=+<=2,<=...,<=*b* are divisible by *d*. To make the problem even more complicated we allow *a* and *b* to be up to googol, 10100 — such number do not fit even in 64-bit integer type! The input will be provided via standard input and looks as follows: The only line of the input contains two integers *a* and *b* (1<=≤<=*a*<=≤<=*b*<=≤<=10100). You should write the solution as standard output as follows: Output one integer — greatest common divisor of all integers from *a* to *b* inclusive. Here are example inputs and outputs for the problem: Example Input 1: 1 2 Example Output 1: 1 Example Input 2: 61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576 Example Output 2: 61803398874989484820458683436563811772030917980576 Now solve the problem by providing the code.
a, b = list(input().split()) if a == b: print(a) else: print("1")
vfc_82229
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 2", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576", "output": "61803398874989484820458683436563811772030917980576", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 100", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "100 100000", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "12345 67890123456789123457", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
148
Solve the following coding problem using the programming language python: «One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine. However, just counting dragons was boring as well, so she entertained herself at best she could. Tonight she imagined that all dragons were here to steal her, and she was fighting them off. Every *k*-th dragon got punched in the face with a frying pan. Every *l*-th dragon got his tail shut into the balcony door. Every *m*-th dragon got his paws trampled with sharp heels. Finally, she threatened every *n*-th dragon to call her mom, and he withdrew in panic. How many imaginary dragons suffered moral or physical damage tonight, if the princess counted a total of *d* dragons? The input will be provided via standard input and looks as follows: Input data contains integer numbers *k*,<=*l*,<=*m*,<=*n* and *d*, each number in a separate line (1<=≤<=*k*,<=*l*,<=*m*,<=*n*<=≤<=10, 1<=≤<=*d*<=≤<=105). You should write the solution as standard output as follows: Output the number of damaged dragons. Here are example inputs and outputs for the problem: Example Input 1: 1 2 3 4 12 Example Output 1: 12 Example Input 2: 2 3 4 5 24 Example Output 2: 17 Now solve the problem by providing the code.
a=int(input()) b=int(input()) c=int(input()) d=int(input()) y=int(input()) if a==1 or b==1 or d==1 or c==1: print(y) else: h=set() for i in range(1,y+1): if i%a!=0 and i%b!=0 and i%c!=0 and i%d!=0 : h.add(i) print(y-len(h))
vfc_82233
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n2\n3\n4\n12", "output": "12", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
18
Solve the following coding problem using the programming language python: Last year Bob earned by selling memory sticks. During each of *n* days of his work one of the two following events took place: - A customer came to Bob and asked to sell him a 2*x* MB memory stick. If Bob had such a stick, he sold it and got 2*x* berllars. - Bob won some programming competition and got a 2*x* MB memory stick as a prize. Bob could choose whether to present this memory stick to one of his friends, or keep it. Bob never kept more than one memory stick, as he feared to mix up their capacities, and deceive a customer unintentionally. It is also known that for each memory stick capacity there was at most one customer, who wanted to buy that memory stick. Now, knowing all the customers' demands and all the prizes won at programming competitions during the last *n* days, Bob wants to know, how much money he could have earned, if he had acted optimally. The input will be provided via standard input and looks as follows: The first input line contains number *n* (1<=≤<=*n*<=≤<=5000) — amount of Bob's working days. The following *n* lines contain the description of the days. Line sell x stands for a day when a customer came to Bob to buy a 2*x* MB memory stick (0<=≤<=*x*<=≤<=2000). It's guaranteed that for each *x* there is not more than one line sell x. Line win x stands for a day when Bob won a 2*x* MB memory stick (0<=≤<=*x*<=≤<=2000). You should write the solution as standard output as follows: Output the maximum possible earnings for Bob in berllars, that he would have had if he had known all the events beforehand. Don't forget, please, that Bob can't keep more than one memory stick at a time. Here are example inputs and outputs for the problem: Example Input 1: 7 win 10 win 5 win 3 sell 5 sell 3 win 10 sell 10 Example Output 1: 1056 Example Input 2: 3 win 5 sell 6 sell 4 Example Output 2: 0 Now solve the problem by providing the code.
max_x = 2001 n = int(input()) income = [0]*n win = {} for i in range(n): s, a = input().split() a = int(a) if (i > 0): income[i] = income[i-1] if (s[0] == 'w'): win[a] = i; elif (win.get(a) != None): income[i] = max(income[i], income[win.get(a)] + 2**a) print(income[n-1]) # Sun Mar 22 2020 14:51:06 GMT+0300 (MSK)
vfc_82237
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\nwin 10\nwin 5\nwin 3\nsell 5\nsell 3\nwin 10\nsell 10", "output": "1056", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\nwin 5\nsell 6\nsell 4", "output": "0", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
254
Solve the following coding problem using the programming language python: Petya has got 2*n* cards, each card contains some integer. The numbers on the cards can be the same. Let's index all cards by consecutive integers from 1 to 2*n*. We'll denote the number that is written on a card with number *i*, as *a**i*. In order to play one entertaining game with his friends, Petya needs to split the cards into pairs so that each pair had equal numbers on the cards. Help Petya do that. The input will be provided via standard input and looks as follows: The first line contains integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains the sequence of 2*n* positive integers *a*1,<=*a*2,<=...,<=*a*2*n* (1<=≤<=*a**i*<=≤<=5000) — the numbers that are written on the cards. The numbers on the line are separated by single spaces. You should write the solution as standard output as follows: If it is impossible to divide the cards into pairs so that cards in each pair had the same numbers, print on a single line integer -1. But if the required partition exists, then print *n* pairs of integers, a pair per line — the indices of the cards that form the pairs. Separate the numbers on the lines by spaces. You can print the pairs and the numbers in the pairs in any order. If there are multiple solutions, print any of them. Here are example inputs and outputs for the problem: Example Input 1: 3 20 30 10 30 20 10 Example Output 1: 4 2 1 5 6 3 Example Input 2: 1 1 2 Example Output 2: -1 Now solve the problem by providing the code.
import sys sys.stdin = open("input.txt", "r") sys.stdout = open("output.txt", "w") n=int(input()) d={} for x,y in enumerate(input().split(),1): d.setdefault(y,[]).append(x) if any(len(d[i])%2!=0 for i in d): print(-1) exit(0) for i in d: print("\n".join("{0} {1}".format(*k) for k in zip(d[i][::2],d[i][1::2])))
vfc_82241
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n20 30 10 30 20 10", "output": "4 2\n1 5\n6 3", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
784
Solve the following coding problem using the programming language python: In this problem you will write a simple generator of Brainfuck ([https://en.wikipedia.org/wiki/Brainfuck](https://en.wikipedia.org/wiki/Brainfuck)) calculators. You are given an arithmetic expression consisting of integers from 0 to 255 and addition/subtraction signs between them. Output a Brainfuck program which, when executed, will print the result of evaluating this expression. We use a fairly standard Brainfuck interpreter for checking the programs: - 30000 memory cells.- memory cells store integers from 0 to 255 with unsigned 8-bit wraparound.- console input (, command) is not supported, but it's not needed for this problem. The input will be provided via standard input and looks as follows: The only line of input data contains the arithmetic expression. The expression will contain between 2 and 10 operands, separated with arithmetic signs plus and/or minus. Each operand will be an integer between 0 and 255, inclusive. The calculations result is guaranteed to be an integer between 0 and 255, inclusive (results of intermediary calculations might be outside of these boundaries). You should write the solution as standard output as follows: Output a Brainfuck program which, when executed, will print the result of evaluating this expression. The program must be at most 5000000 characters long (including the non-command characters), and its execution must be complete in at most 50000000 steps. Here are example inputs and outputs for the problem: Example Input 1: 2+3 Example Output 1: ++&gt; +++&gt; &lt;[&lt;+&gt;-]&lt; ++++++++++++++++++++++++++++++++++++++++++++++++. Example Input 2: 9-7 Example Output 2: +++++++++&gt; +++++++&gt; &lt;[&lt;-&gt;-]&lt; ++++++++++++++++++++++++++++++++++++++++++++++++. Now solve the problem by providing the code.
a = input() b = int(eval(a)) res = '+' * 48; if b >= 200: res += "++.--"; b -= 200; elif b >= 100: res += "+.-"; b -= 100; k = b // 10 b %= 10 if k > 0: res += ("+" * k + '.' + '-' * k) res += ('+' * b + '.') print(res)
vfc_82245
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2+3", "output": "+++++++++++++++++++++++++++++++++++++++++++++++++++++.>", "type": "stdin_stdout" }, { "fn_name": null, "input": "9-7", "output": "++++++++++++++++++++++++++++++++++++++++++++++++++.>", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
460
Solve the following coding problem using the programming language python: Vasya has *n* pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every *m*-th day (at days with numbers *m*,<=2*m*,<=3*m*,<=...) mom buys a pair of socks to Vasya. She does it late in the evening, so that Vasya cannot put on a new pair of socks before the next day. How many consecutive days pass until Vasya runs out of socks? The input will be provided via standard input and looks as follows: The single line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=100; 2<=≤<=*m*<=≤<=100), separated by a space. You should write the solution as standard output as follows: Print a single integer — the answer to the problem. Here are example inputs and outputs for the problem: Example Input 1: 2 2 Example Output 1: 3 Example Input 2: 9 3 Example Output 2: 13 Now solve the problem by providing the code.
a,b=map(int,input().split()) c=0 d=0 while a>0: d+=1 c+=1 if c==b: a+=1 c=0 a-=1 print(d)
vfc_82249
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "9 3", "output": "13", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 2", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 99", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 4", "output": "5", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
282
Solve the following coding problem using the programming language python: The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called *x*. Also, there are two operations: - Operation ++ increases the value of variable *x* by 1. - Operation -- decreases the value of variable *x* by 1. A statement in language Bit++ is a sequence, consisting of exactly one operation and one variable *x*. The statement is written without spaces, that is, it can only contain characters "+", "-", "X". Executing a statement means applying the operation it contains. A programme in Bit++ is a sequence of statements, each of them needs to be executed. Executing a programme means executing all the statements it contains. You're given a programme in language Bit++. The initial value of *x* is 0. Execute the programme and find its final value (the value of the variable when this programme is executed). The input will be provided via standard input and looks as follows: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=150) — the number of statements in the programme. Next *n* lines contain a statement each. Each statement contains exactly one operation (++ or --) and exactly one variable *x* (denoted as letter «X»). Thus, there are no empty statements. The operation and the variable can be written in any order. You should write the solution as standard output as follows: Print a single integer — the final value of *x*. Here are example inputs and outputs for the problem: Example Input 1: 1 ++X Example Output 1: 1 Example Input 2: 2 X++ --X Example Output 2: 0 Now solve the problem by providing the code.
x = int(input()) resultaat = 0 for y in range(0,x,1): z = input() if z == "++X" or z == "X++": resultaat += 1 if z == "--X" or z == "X--": resultaat -= 1 print(resultaat)
vfc_82253
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n++X", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\nX++\n--X", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n++X\n++X\n++X", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n--X\n--X", "output": "-2", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
507
Solve the following coding problem using the programming language python: Amr is a young coder who likes music a lot. He always wanted to learn how to play music but he was busy coding so he got an idea. Amr has *n* instruments, it takes *a**i* days to learn *i*-th instrument. Being busy, Amr dedicated *k* days to learn how to play the maximum possible number of instruments. Amr asked for your help to distribute his free days between instruments so that he can achieve his goal. The input will be provided via standard input and looks as follows: The first line contains two numbers *n*, *k* (1<=≤<=*n*<=≤<=100, 0<=≤<=*k*<=≤<=10<=000), the number of instruments and number of days respectively. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=100), representing number of days required to learn the *i*-th instrument. You should write the solution as standard output as follows: In the first line output one integer *m* representing the maximum number of instruments Amr can learn. In the second line output *m* space-separated integers: the indices of instruments to be learnt. You may output indices in any order. if there are multiple optimal solutions output any. It is not necessary to use all days for studying. Here are example inputs and outputs for the problem: Example Input 1: 4 10 4 3 1 2 Example Output 1: 4 1 2 3 4 Example Input 2: 5 6 4 3 1 1 2 Example Output 2: 3 1 3 4 Example Input 3: 1 3 4 Example Output 3: 0 Now solve the problem by providing the code.
n,m=map(int,input().split()) a=list(map(int,input().split())) #a.sort() l=[] for i in range(n): l.append((a[i],i+1)) l.sort() cnt=0 p=[] s=0 k=0 #print(l) for i in range(n): s=s+l[i][0] if s<=m: cnt+=1 p.append(l[i][1]) else: print(cnt) print(*p) k=1 break if k==0: print(cnt) print(*p)
vfc_82257
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 10\n4 3 1 2", "output": "4\n1 2 3 4", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 6\n4 3 1 1 2", "output": "3\n3 4 5", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 3\n4", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 100\n100 100", "output": "1\n1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
703
Solve the following coding problem using the programming language python: Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game. Rules of the game are very simple: at first number of rounds *n* is defined. In every round each of the players throws a cubical dice with distinct numbers from 1 to 6 written on its faces. Player, whose value after throwing the dice is greater, wins the round. In case if player dice values are equal, no one of them is a winner. In average, player, who won most of the rounds, is the winner of the game. In case if two players won the same number of rounds, the result of the game is draw. Mishka is still very little and can't count wins and losses, so she asked you to watch their game and determine its result. Please help her! The input will be provided via standard input and looks as follows: The first line of the input contains single integer *n* *n* (1<=≤<=*n*<=≤<=100) — the number of game rounds. The next *n* lines contains rounds description. *i*-th of them contains pair of integers *m**i* and *c**i* (1<=≤<=*m**i*,<=<=*c**i*<=≤<=6) — values on dice upper face after Mishka's and Chris' throws in *i*-th round respectively. You should write the solution as standard output as follows: If Mishka is the winner of the game, print "Mishka" (without quotes) in the only line. If Chris is the winner of the game, print "Chris" (without quotes) in the only line. If the result of the game is draw, print "Friendship is magic!^^" (without quotes) in the only line. Here are example inputs and outputs for the problem: Example Input 1: 3 3 5 2 1 4 2 Example Output 1: Mishka Example Input 2: 2 6 1 1 6 Example Output 2: Friendship is magic!^^ Example Input 3: 3 1 5 3 3 2 2 Example Output 3: Chris Now solve the problem by providing the code.
n=int(input()) x=0 y=0 z=0 for i in range(n): a,b=map(int,input().split()) if(a>b): x=x+1 elif(a<b): y=y+1 elif(a==b): z=z+1 if(x>y): print("Mishka") elif(x<y): print("Chris") elif(x==y or z>0): print("Friendship is magic!^^")
vfc_82261
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3 5\n2 1\n4 2", "output": "Mishka", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
863
Solve the following coding problem using the programming language python: Vadim is really keen on travelling. Recently he heard about kayaking activity near his town and became very excited about it, so he joined a party of kayakers. Now the party is ready to start its journey, but firstly they have to choose kayaks. There are 2·*n* people in the group (including Vadim), and they have exactly *n*<=-<=1 tandem kayaks (each of which, obviously, can carry two people) and 2 single kayaks. *i*-th person's weight is *w**i*, and weight is an important matter in kayaking — if the difference between the weights of two people that sit in the same tandem kayak is too large, then it can crash. And, of course, people want to distribute their seats in kayaks in order to minimize the chances that kayaks will crash. Formally, the instability of a single kayak is always 0, and the instability of a tandem kayak is the absolute difference between weights of the people that are in this kayak. Instability of the whole journey is the total instability of all kayaks. Help the party to determine minimum possible total instability! The input will be provided via standard input and looks as follows: The first line contains one number *n* (2<=≤<=*n*<=≤<=50). The second line contains 2·*n* integer numbers *w*1, *w*2, ..., *w*2*n*, where *w**i* is weight of person *i* (1<=≤<=*w**i*<=≤<=1000). You should write the solution as standard output as follows: Print minimum possible total instability. Here are example inputs and outputs for the problem: Example Input 1: 2 1 2 3 4 Example Output 1: 1 Example Input 2: 4 1 3 4 6 3 4 100 200 Example Output 2: 5 Now solve the problem by providing the code.
inf = float('inf') def solve(A, N): A.sort() N *= 2 ans = inf for i in range(N): for j in range(i + 1, N): B = [] for k in range(N): if k != i and k != j: B.append(A[k]) total = sum(B[i + 1] - B[i] for i in range(0, N - 2, 2)) ans = min(ans, total) return ans N = int(input()) A = list(map(int, input().split())) print(solve(A, N))
vfc_82265
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1 2 3 4", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 3 4 6 3 4 100 200", "output": "5", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
810
Solve the following coding problem using the programming language python: Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one. In school, where Noora is studying, teachers are putting down marks to the online class register, which are integers from 1 to *k*. The worst mark is 1, the best is *k*. Mark that is going to the certificate, is calculated as an average of all the marks, rounded to the closest integer. If several answers are possible, rounding up is produced. For example, 7.3 is rounded to 7, but 7.5 and 7.8784 — to 8. For instance, if Noora has marks [8,<=9], then the mark to the certificate is 9, because the average is equal to 8.5 and rounded to 9, but if the marks are [8,<=8,<=9], Noora will have graduation certificate with 8. To graduate with «A» certificate, Noora has to have mark *k*. Noora got *n* marks in register this year. However, she is afraid that her marks are not enough to get final mark *k*. Noora decided to ask for help in the internet, where hacker Leha immediately responded to her request. He is ready to hack class register for Noora and to add Noora any number of additional marks from 1 to *k*. At the same time, Leha want his hack be unseen to everyone, so he decided to add as less as possible additional marks. Please help Leha to calculate the minimal number of marks he has to add, so that final Noora's mark will become equal to *k*. The input will be provided via standard input and looks as follows: The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*k*<=≤<=100) denoting the number of marks, received by Noora and the value of highest possible mark. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*k*) denoting marks received by Noora before Leha's hack. You should write the solution as standard output as follows: Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to *k*. Here are example inputs and outputs for the problem: Example Input 1: 2 10 8 9 Example Output 1: 4 Example Input 2: 3 5 4 4 4 Example Output 2: 3 Now solve the problem by providing the code.
n, k = map(int, input().split()) marks = list(map(int, input().split())) s = sum(marks) q = 0 while s < n * (k - 0.5): q += 1 s += k n += 1 print(q)
vfc_82269
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 10\n8 9", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 5\n4 4 4", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 10\n10 8 9", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 23\n21 23", "output": "2", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
588
Solve the following coding problem using the programming language python: Duff is addicted to meat! Malek wants to keep her happy for *n* days. In order to be happy in *i*-th day, she needs to eat exactly *a**i* kilograms of meat. There is a big shop uptown and Malek wants to buy meat for her from there. In *i*-th day, they sell meat for *p**i* dollars per kilogram. Malek knows all numbers *a*1,<=...,<=*a**n* and *p*1,<=...,<=*p**n*. In each day, he can buy arbitrary amount of meat, also he can keep some meat he has for the future. Malek is a little tired from cooking meat, so he asked for your help. Help him to minimize the total money he spends to keep Duff happy for *n* days. The input will be provided via standard input and looks as follows: The first line of input contains integer *n* (1<=≤<=*n*<=≤<=105), the number of days. In the next *n* lines, *i*-th line contains two integers *a**i* and *p**i* (1<=≤<=*a**i*,<=*p**i*<=≤<=100), the amount of meat Duff needs and the cost of meat in that day. You should write the solution as standard output as follows: Print the minimum money needed to keep Duff happy for *n* days, in one line. Here are example inputs and outputs for the problem: Example Input 1: 3 1 3 2 2 3 1 Example Output 1: 10 Example Input 2: 3 1 3 2 1 3 2 Example Output 2: 8 Now solve the problem by providing the code.
from math import inf min_p = inf ans = 0 for _ in range(int(input())): ai, pi = map(int, input().split()) min_p = min(min_p, pi) ans += ai * min_p print(ans)
vfc_82273
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 3\n2 2\n3 1", "output": "10", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 3\n2 1\n3 2", "output": "8", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n39 52", "output": "2028", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n25 56\n94 17", "output": "2998", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n39 21\n95 89\n73 90\n9 55\n85 32", "output": "6321", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
814
Solve the following coding problem using the programming language python: A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed. To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long time, but now Kaiki provides an opportunity. Hitagi's sequence *a* has a length of *n*. Lost elements in it are denoted by zeros. Kaiki provides another sequence *b*, whose length *k* equals the number of lost elements in *a* (i.e. the number of zeros). Hitagi is to replace each zero in *a* with an element from *b* so that each element in *b* should be used exactly once. Hitagi knows, however, that, apart from 0, no integer occurs in *a* and *b* more than once in total. If the resulting sequence is not an increasing sequence, then it has the power to recover Hitagi from the oddity. You are to determine whether this is possible, or Kaiki's sequence is just another fake. In other words, you should detect whether it is possible to replace each zero in *a* with an integer from *b* so that each integer from *b* is used exactly once, and the resulting sequence is not increasing. The input will be provided via standard input and looks as follows: The first line of input contains two space-separated positive integers *n* (2<=≤<=*n*<=≤<=100) and *k* (1<=≤<=*k*<=≤<=*n*) — the lengths of sequence *a* and *b* respectively. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=200) — Hitagi's broken sequence with exactly *k* zero elements. The third line contains *k* space-separated integers *b*1,<=*b*2,<=...,<=*b**k* (1<=≤<=*b**i*<=≤<=200) — the elements to fill into Hitagi's sequence. Input guarantees that apart from 0, no integer occurs in *a* and *b* more than once in total. You should write the solution as standard output as follows: Output "Yes" if it's possible to replace zeros in *a* with elements in *b* and make the resulting sequence not increasing, and "No" otherwise. Here are example inputs and outputs for the problem: Example Input 1: 4 2 11 0 0 14 5 4 Example Output 1: Yes Example Input 2: 6 1 2 3 0 8 9 10 5 Example Output 2: No Example Input 3: 4 1 8 94 0 4 89 Example Output 3: Yes Example Input 4: 7 7 0 0 0 0 0 0 0 1 2 3 4 5 6 7 Example Output 4: Yes Now solve the problem by providing the code.
n,k= map(int,input().split()) arr = list(map(int,input().split())) b = list(map(int,input().split())) if k >= 2: print("Yes") else: if k == 1: arr[arr.index(0)] = b[0] x = [i for i in arr] x.sort() if x == arr: print("No") else: print("Yes") else: print("No")
vfc_82277
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2\n11 0 0 14\n5 4", "output": "Yes", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 1\n2 3 0 8 9 10\n5", "output": "No", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
231
Solve the following coding problem using the programming language python: One day three best friends Petya, Vasya and Tonya decided to form a team and take part in programming contests. Participants are usually offered several problems during programming contests. Long before the start the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, the friends won't write the problem's solution. This contest offers *n* problems to the participants. For each problem we know, which friend is sure about the solution. Help the friends find the number of problems for which they will write a solution. The input will be provided via standard input and looks as follows: The first input line contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the number of problems in the contest. Then *n* lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Petya is sure about the problem's solution, otherwise he isn't sure. The second number shows Vasya's view on the solution, the third number shows Tonya's view. The numbers on the lines are separated by spaces. You should write the solution as standard output as follows: Print a single integer — the number of problems the friends will implement on the contest. Here are example inputs and outputs for the problem: Example Input 1: 3 1 1 0 1 1 1 1 0 0 Example Output 1: 2 Example Input 2: 2 1 0 0 0 1 1 Example Output 2: 1 Now solve the problem by providing the code.
n = int(input()) k = 0 for i in range(n): arr = [int(i) for i in input().split()] if arr.count(1) > 1: k += 1 print(k)
vfc_82281
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 1 0\n1 1 1\n1 0 0", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 0 0\n0 1 1", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1 0 0", "output": "0", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
757
Solve the following coding problem using the programming language python: The gym leaders were fascinated by the evolutions which took place at Felicity camp. So, they were curious to know about the secret behind evolving Pokemon. The organizers of the camp gave the gym leaders a PokeBlock, a sequence of *n* ingredients. Each ingredient can be of type 0 or 1. Now the organizers told the gym leaders that to evolve a Pokemon of type *k* (*k*<=≥<=2), they need to make a valid set of *k* cuts on the PokeBlock to get smaller blocks. Suppose the given PokeBlock sequence is *b*0*b*1*b*2... *b**n*<=-<=1. You have a choice of making cuts at *n*<=+<=1 places, i.e., Before *b*0, between *b*0 and *b*1, between *b*1 and *b*2, ..., between *b**n*<=-<=2 and *b**n*<=-<=1, and after *b**n*<=-<=1. The *n*<=+<=1 choices of making cuts are as follows (where a | denotes a possible cut): Consider a sequence of *k* cuts. Now each pair of consecutive cuts will contain a binary string between them, formed from the ingredient types. The ingredients before the first cut and after the last cut are wasted, which is to say they are not considered. So there will be exactly *k*<=-<=1 such binary substrings. Every substring can be read as a binary number. Let *m* be the maximum number out of the obtained numbers. If all the obtained numbers are positive and the set of the obtained numbers contains all integers from 1 to *m*, then this set of cuts is said to be a valid set of cuts. For example, suppose the given PokeBlock sequence is 101101001110 and we made 5 cuts in the following way: So the 4 binary substrings obtained are: 11, 010, 01 and 1, which correspond to the numbers 3, 2, 1 and 1 respectively. Here *m*<==<=3, as it is the maximum value among the obtained numbers. And all the obtained numbers are positive and we have obtained all integers from 1 to *m*. Hence this set of cuts is a valid set of 5 cuts. A Pokemon of type *k* will evolve only if the PokeBlock is cut using a valid set of *k* cuts. There can be many valid sets of the same size. Two valid sets of *k* cuts are considered different if there is a cut in one set which is not there in the other set. Let *f*(*k*) denote the number of valid sets of *k* cuts. Find the value of . Since the value of *s* can be very large, output *s* modulo 109<=+<=7. The input will be provided via standard input and looks as follows: The input consists of two lines. The first line consists an integer *n* (1<=≤<=*n*<=≤<=75) — the length of the PokeBlock. The next line contains the PokeBlock, a binary string of length *n*. You should write the solution as standard output as follows: Output a single integer, containing the answer to the problem, i.e., the value of *s* modulo 109<=+<=7. Here are example inputs and outputs for the problem: Example Input 1: 4 1011 Example Output 1: 10 Example Input 2: 2 10 Example Output 2: 1 Now solve the problem by providing the code.
mo = 10**9+7 def calc(l, r, si): res = 0 for i in range(l, r + 1): res = res * 2 + int(si[i]) return res def main(): n, si = int(input()), input() si = chr(0)+si f = [[0]*(1<<20) for i in range(6)] res, r, f[0][0]= 0, 0, 1 for i in range(1, n+1): r=(r+1)%6 f[r] = [0]*(1<<20) for j in range(1, min(5, i) + 1): if si[i-j+1] != '0': c, p = calc(i-j+1, i, si), (r-j+6)%6 if(c>20 or c<1): break for s in range(1<<20): if(f[p][s]): f[r][s|(1<<(c-1))] = (f[r][s|(1<<(c-1))] + f[p][s]) % mo for s in range(1, 21): res = (res + f[r][(1<<s)-1]) % mo f[r][0] = (f[r][0] + 1) % mo if(si[i]=='0'): p=(r-1+6)%6 for s in range(1<<20): if(f[p][s]): f[r][s] = (f[r][s] + f[p][s]) % mo print(res) main()
vfc_82285
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1011", "output": "10", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n10", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n0110011", "output": "28", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n0100011101", "output": "80", "type": "stdin_stdout" }, { "fn_name": null, "input": "12\n010010101011", "output": "298", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
128
Solve the following coding problem using the programming language python: In this task Anna and Maria play a game with a very unpleasant rival. Anna and Maria are in the opposite squares of a chessboard (8<=×<=8): Anna is in the upper right corner, and Maria is in the lower left one. Apart from them, the board has several statues. Each statue occupies exactly one square. A square that contains a statue cannot have anything or anyone — neither any other statues, nor Anna, nor Maria. Anna is present on the board as a figurant (she stands still and never moves), and Maria has been actively involved in the game. Her goal is — to come to Anna's square. Maria and statues move in turn, Maria moves first. During one move Maria can go to any adjacent on the side or diagonal cell in which there is no statue, or she can stay in the cell where she is. The statues during their move must go one square down simultaneously, and those statues that were in the bottom row fall from the board and are no longer appeared. At that moment, when one of the statues is in the cell in which the Maria is, the statues are declared winners. At the moment when Maria comes into the cell where Anna has been waiting, Maria is declared the winner. Obviously, nothing depends on the statues, so it all depends on Maria. Determine who will win, if Maria does not make a strategic error. The input will be provided via standard input and looks as follows: You are given the 8 strings whose length equals 8, describing the initial position on the board. The first line represents the top row of the board, the next one — for the second from the top, and so on, the last line represents the bottom row. Each character string matches a single cell board in the appropriate row, and the characters are in the same manner as that of the corresponding cell. If the cell is empty, the corresponding character is ".". If a cell has Maria, then it is represented by character "M". If a cell has Anna, it is represented by the character "A". If a cell has a statue, then the cell is represented by character "S". It is guaranteed that the last character of the first row is always "A", the first character of the last line is always "M". The remaining characters are "." or "S". You should write the solution as standard output as follows: If Maria wins, print string "WIN". If the statues win, print string "LOSE". Here are example inputs and outputs for the problem: Example Input 1: .......A ........ ........ ........ ........ ........ ........ M....... Example Output 1: WIN Example Input 2: .......A ........ ........ ........ ........ ........ SS...... M....... Example Output 2: LOSE Example Input 3: .......A ........ ........ ........ ........ .S...... S....... MS...... Example Output 3: LOSE Now solve the problem by providing the code.
r, s = [63], ''.join(input() + 'T' for i in range(8)) + 'T' * 9 for i in range(0, 72, 9): t = set() for x in r: for y in (x, x - 1, x + 1, x - 9, x + 9, x - 10, x - 8, x + 10, x + 8): if s[y] == 'T': continue if (y < i or s[y - i] != 'S') and (y < i + 9 or s[y - i - 9] != 'S'): t.add(y) r = t print('WIN' if r else 'LOSE')
vfc_82289
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": ".SSSSSSA\n.SSSSSSS\n.SSSSSSS\n.SSSSSSS\n.SSSSSSS\n.SSSSSSS\n.SSSSSSS\nMSSSSSSS", "output": "WIN", "type": "stdin_stdout" }, { "fn_name": null, "input": "SSSSSSSA\nSSSSSSSS\nSSSSSSSS\nSSSSSSSS\nSSSSSSSS\nSSSSSSSS\nSSSSSSSS\nMSSSSSSS", "output": "LOSE", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
910
Solve the following coding problem using the programming language python: A frog lives on the axis *Ox* and needs to reach home which is in the point *n*. She starts from the point 1. The frog can jump to the right at a distance not more than *d*. So, after she jumped from the point *x* she can reach the point *x*<=+<=*a*, where *a* is an integer from 1 to *d*. For each point from 1 to *n* is known if there is a lily flower in it. The frog can jump only in points with a lilies. Guaranteed that there are lilies in the points 1 and *n*. Determine the minimal number of jumps that the frog needs to reach home which is in the point *n* from the point 1. Consider that initially the frog is in the point 1. If the frog can not reach home, print -1. The input will be provided via standard input and looks as follows: The first line contains two integers *n* and *d* (2<=≤<=*n*<=≤<=100, 1<=≤<=*d*<=≤<=*n*<=-<=1) — the point, which the frog wants to reach, and the maximal length of the frog jump. The second line contains a string *s* of length *n*, consisting of zeros and ones. If a character of the string *s* equals to zero, then in the corresponding point there is no lily flower. In the other case, in the corresponding point there is a lily flower. Guaranteed that the first and the last characters of the string *s* equal to one. You should write the solution as standard output as follows: If the frog can not reach the home, print -1. In the other case, print the minimal number of jumps that the frog needs to reach the home which is in the point *n* from the point 1. Here are example inputs and outputs for the problem: Example Input 1: 8 4 10010101 Example Output 1: 2 Example Input 2: 4 2 1001 Example Output 2: -1 Example Input 3: 8 4 11100101 Example Output 3: 3 Example Input 4: 12 3 101111100101 Example Output 4: 4 Now solve the problem by providing the code.
#10010101 n,e = map(int,input().split()) s = input() i = 0 d = e ans = -1 flag = 0 while(i<n-1): if(n-i-1 < e): e = n - i - 1 d = e if(d==0): flag = 1 print("-1") break if(s[i+d]=='1'): i = i + d ans+=1 d = e else: d-=1 if(flag==0): print(ans+1)
vfc_82293
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8 4\n10010101", "output": "2", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
433
Solve the following coding problem using the programming language python: Kuriyama Mirai has killed many monsters and got many (namely *n*) stones. She numbers the stones from 1 to *n*. The cost of the *i*-th stone is *v**i*. Kuriyama Mirai wants to know something about these stones so she will ask you two kinds of questions: 1. She will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), and you should tell her . 1. Let *u**i* be the cost of the *i*-th cheapest stone (the cost that will be on the *i*-th place if we arrange all the stone costs in non-decreasing order). This time she will tell you two numbers, *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), and you should tell her . For every question you should give the correct answer, or Kuriyama Mirai will say "fuyukai desu" and then become unhappy. The input will be provided via standard input and looks as follows: The first line contains an integer *n* (1<=≤<=*n*<=≤<=105). The second line contains *n* integers: *v*1,<=*v*2,<=...,<=*v**n* (1<=≤<=*v**i*<=≤<=109) — costs of the stones. The third line contains an integer *m* (1<=≤<=*m*<=≤<=105) — the number of Kuriyama Mirai's questions. Then follow *m* lines, each line contains three integers *type*, *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*; 1<=≤<=*type*<=≤<=2), describing a question. If *type* equal to 1, then you should output the answer for the first question, else you should output the answer for the second one. You should write the solution as standard output as follows: Print *m* lines. Each line must contain an integer — the answer to Kuriyama Mirai's question. Print the answers to the questions in the order of input. Here are example inputs and outputs for the problem: Example Input 1: 6 6 4 2 7 2 7 3 2 3 6 1 3 4 1 1 6 Example Output 1: 24 9 28 Example Input 2: 4 5 5 2 3 10 1 2 4 2 1 4 1 1 1 2 1 4 2 1 2 1 1 1 1 3 3 1 1 3 1 4 4 1 2 2 Example Output 2: 10 15 5 15 5 5 2 12 3 5 Now solve the problem by providing the code.
import sys import threading from sys import stdin, stdout from itertools import accumulate input = stdin.readline print = stdout.write if __name__ == "__main__": n = int(input().strip()) arr = list(map(int, input().strip().split())) arr_sort = sorted(arr) #this is the t = O(nlogn) step cumulative_orig = list(accumulate(arr)) #this is t = O(n) cumulative_sort = list(accumulate(arr_sort)) m = int(input().strip()) for query in range(m): type, left_index, right_index = map(int, input().strip().split()) left_index -= 1 #Our code assumes 0-indexing of lists but question expects 1-indexing (nonsense!) right_index -= 1 if type == 1: print(f"{cumulative_orig[right_index] - cumulative_orig[left_index] + arr[left_index]}\n") else: print(f"{cumulative_sort[right_index] - cumulative_sort[left_index] + arr_sort[left_index]}\n")
vfc_82297
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n6 4 2 7 2 7\n3\n2 3 6\n1 3 4\n1 1 6", "output": "24\n9\n28", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n5 5 2 3\n10\n1 2 4\n2 1 4\n1 1 1\n2 1 4\n2 1 2\n1 1 1\n1 3 3\n1 1 3\n1 4 4\n1 2 2", "output": "10\n15\n5\n15\n5\n5\n2\n12\n3\n5", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n2 2 3 6\n9\n2 2 3\n1 1 3\n2 2 3\n2 2 3\n2 2 2\n1 1 3\n1 1 3\n2 1 4\n1 1 2", "output": "5\n7\n5\n5\n2\n7\n7\n13\n4", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
82
Solve the following coding problem using the programming language python: Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on. This process continues ad infinitum. For example, Penny drinks the third can of cola and the queue will look like this: Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny. Write a program that will print the name of a man who will drink the *n*-th can. Note that in the very beginning the queue looks like that: Sheldon, Leonard, Penny, Rajesh, Howard. The first person is Sheldon. The input will be provided via standard input and looks as follows: The input data consist of a single integer *n* (1<=≤<=*n*<=≤<=109). It is guaranteed that the pretests check the spelling of all the five names, that is, that they contain all the five possible answers. You should write the solution as standard output as follows: Print the single line — the name of the person who drinks the *n*-th can of cola. The cans are numbered starting from 1. Please note that you should spell the names like this: "Sheldon", "Leonard", "Penny", "Rajesh", "Howard" (without the quotes). In that order precisely the friends are in the queue initially. Here are example inputs and outputs for the problem: Example Input 1: 1 Example Output 1: Sheldon Example Input 2: 6 Example Output 2: Sheldon Example Input 3: 1802 Example Output 3: Penny Now solve the problem by providing the code.
n=int(input()) a=["Sheldon","Leonard","Penny","Rajesh","Howard"] R=1 while(R*5<n): n-=R*5 R*=2 print(a[(n-1)//R])
vfc_82301
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1", "output": "Sheldon", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
608
Solve the following coding problem using the programming language python: Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only move down, and has infinite capacity. Floors are numbered from 0 to *s* and elevator initially starts on floor *s* at time 0. The elevator takes exactly 1 second to move down exactly 1 floor and negligible time to pick up passengers. Genos is given a list detailing when and on which floor passengers arrive. Please determine how long in seconds it will take Genos to bring all passengers to floor 0. The input will be provided via standard input and looks as follows: The first line of input contains two integers *n* and *s* (1<=≤<=*n*<=≤<=100, 1<=≤<=*s*<=≤<=1000) — the number of passengers and the number of the top floor respectively. The next *n* lines each contain two space-separated integers *f**i* and *t**i* (1<=≤<=*f**i*<=≤<=*s*, 1<=≤<=*t**i*<=≤<=1000) — the floor and the time of arrival in seconds for the passenger number *i*. You should write the solution as standard output as follows: Print a single integer — the minimum amount of time in seconds needed to bring all the passengers to floor 0. Here are example inputs and outputs for the problem: Example Input 1: 3 7 2 1 3 8 5 2 Example Output 1: 11 Example Input 2: 5 10 2 77 3 33 8 21 9 12 10 64 Example Output 2: 79 Now solve the problem by providing the code.
n,s=(map(int,input().split())) x=[] for i in range(n): a,b=(map(int,input().split())) x.append([a,b]) x.sort(key=lambda i:i[0],reverse=True) c=0 p=s for i in x: c=max(i[1],c+p-i[0]) p=i[0] c+=i[0] print(c)
vfc_82305
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 7\n2 1\n3 8\n5 2", "output": "11", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
876
Solve the following coding problem using the programming language python: You are given a multiset of *n* integers. You should select exactly *k* of them in a such way that the difference between any two of them is divisible by *m*, or tell that it is impossible. Numbers can be repeated in the original multiset and in the multiset of selected numbers, but number of occurrences of any number in multiset of selected numbers should not exceed the number of its occurrences in the original multiset. The input will be provided via standard input and looks as follows: First line contains three integers *n*, *k* and *m* (2<=≤<=*k*<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=100<=000) — number of integers in the multiset, number of integers you should select and the required divisor of any pair of selected integers. Second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — the numbers in the multiset. You should write the solution as standard output as follows: If it is not possible to select *k* numbers in the desired way, output «No» (without the quotes). Otherwise, in the first line of output print «Yes» (without the quotes). In the second line print *k* integers *b*1,<=*b*2,<=...,<=*b**k* — the selected numbers. If there are multiple possible solutions, print any of them. Here are example inputs and outputs for the problem: Example Input 1: 3 2 3 1 8 4 Example Output 1: Yes 1 4 Example Input 2: 3 3 3 1 8 4 Example Output 2: No Example Input 3: 4 3 5 2 7 7 7 Example Output 3: Yes 2 7 7 Now solve the problem by providing the code.
n,k,m=map(int,input().split()) a=list(map(int,input().split())) mods=[0]*m mod=0 for i in range(n): mod=a[i]%m mods[mod]+=1 if mods[mod]==k: break else: print('No') exit() print('Yes') results=[None]*k count=0 for i in range(n): cur=a[i] if cur%m==mod: results[count]=cur count+=1 if count==k: print(' '.join(map(str,results))) break
vfc_82309
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2 3\n1 8 4", "output": "Yes\n1 4 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3 3\n1 8 4", "output": "No", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 3 5\n2 7 7 7", "output": "Yes\n2 7 7 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "9 9 5\n389149775 833127990 969340400 364457730 48649145 316121525 640054660 924273385 973207825", "output": "Yes\n389149775 833127990 969340400 364457730 48649145 316121525 640054660 924273385 973207825 ", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
715
Solve the following coding problem using the programming language python: ZS the Coder has drawn an undirected graph of *n* vertices numbered from 0 to *n*<=-<=1 and *m* edges between them. Each edge of the graph is weighted, each weight is a positive integer. The next day, ZS the Coder realized that some of the weights were erased! So he wants to reassign positive integer weight to each of the edges which weights were erased, so that the length of the shortest path between vertices *s* and *t* in the resulting graph is exactly *L*. Can you help him? The input will be provided via standard input and looks as follows: The first line contains five integers *n*,<=*m*,<=*L*,<=*s*,<=*t* (2<=≤<=*n*<=≤<=1000,<=<=1<=≤<=*m*<=≤<=10<=000,<=<=1<=≤<=*L*<=≤<=109,<=<=0<=≤<=*s*,<=*t*<=≤<=*n*<=-<=1,<=<=*s*<=≠<=*t*) — the number of vertices, number of edges, the desired length of shortest path, starting vertex and ending vertex respectively. Then, *m* lines describing the edges of the graph follow. *i*-th of them contains three integers, *u**i*,<=*v**i*,<=*w**i* (0<=≤<=*u**i*,<=*v**i*<=≤<=*n*<=-<=1,<=<=*u**i*<=≠<=*v**i*,<=<=0<=≤<=*w**i*<=≤<=109). *u**i* and *v**i* denote the endpoints of the edge and *w**i* denotes its weight. If *w**i* is equal to 0 then the weight of the corresponding edge was erased. It is guaranteed that there is at most one edge between any pair of vertices. You should write the solution as standard output as follows: Print "NO" (without quotes) in the only line if it's not possible to assign the weights in a required way. Otherwise, print "YES" in the first line. Next *m* lines should contain the edges of the resulting graph, with weights assigned to edges which weights were erased. *i*-th of them should contain three integers *u**i*, *v**i* and *w**i*, denoting an edge between vertices *u**i* and *v**i* of weight *w**i*. The edges of the new graph must coincide with the ones in the graph from the input. The weights that were not erased must remain unchanged whereas the new weights can be any positive integer not exceeding 1018. The order of the edges in the output doesn't matter. The length of the shortest path between *s* and *t* must be equal to *L*. If there are multiple solutions, print any of them. Here are example inputs and outputs for the problem: Example Input 1: 5 5 13 0 4 0 1 5 2 1 2 3 2 3 1 4 0 4 3 4 Example Output 1: YES 0 1 5 2 1 2 3 2 3 1 4 8 4 3 4 Example Input 2: 2 1 123456789 0 1 0 1 0 Example Output 2: YES 0 1 123456789 Example Input 3: 2 1 999999999 1 0 0 1 1000000000 Example Output 3: NO Now solve the problem by providing the code.
import heapq import random import sys from math import inf from types import GeneratorType RANDOM = random.randint(1, 10 ** 9) class FastIO: def __init__(self): return @staticmethod def read_str(): return sys.stdin.readline() def read_int(self): return int(self.read_str()) def read_float(self): return float(self.read_str()) def read_ints(self): return map(int, self.read_str().split()) def read_floats(self): return map(float, self.read_str().split()) def read_ints_minus_one(self): return map(lambda x: int(x) - 1, self.read_str().split()) def read_list_ints(self): return list(map(int, self.read_str().split())) def read_list_floats(self): return list(map(float, self.read_str().split())) def read_list_ints_minus_one(self): return list(map(lambda x: int(x) - 1, self.read_str().split())) def read_list_strs(self): return self.read_str().split() def read_list_str(self): return list(self.read_str()) @staticmethod def st(x): return print(x) @staticmethod def lst(x): return print(*x) @staticmethod def round_5(f): res = int(f) if f - res >= 0.5: res += 1 return res @staticmethod def max(a, b): return a if a > b else b @staticmethod def min(a, b): return a if a < b else b @staticmethod def bootstrap(f, queue=[]): def wrappedfunc(*args, **kwargs): if queue: return f(*args, **kwargs) else: to = f(*args, **kwargs) while True: if isinstance(to, GeneratorType): queue.append(to) to = next(to) else: queue.pop() if not queue: break to = queue[-1].send(to) return to return wrappedfunc def ask(self, lst): self.lst(lst) sys.stdout.flush() res = self.read_int() return res @staticmethod def accumulate(nums): n = len(nums) pre = [0] * (n + 1) for i in range(n): pre[i + 1] = pre[i] + nums[i] return pre class Wrapper(int): # 用来规避 py 哈希碰撞的问题和进行加速 def __init__(self, x): int.__init__(x) # 原理是异或一个随机种子 def __hash__(self): # 也可以将数组排序后进行哈希计数 return super(Wrapper, self).__hash__() ^ RANDOM class Solution: def __init__(self): return @staticmethod def main(ac=FastIO()): n, m, target, source, destination = ac.read_ints() edges = [] dct = [[] for _ in range(n)] book = [0] * m for ind in range(m): i, j, w = ac.read_list_ints() if w == 0: w = 1 book[ind] = 1 edges.append([i, j, w]) dct[i].append([ind, j]) dct[j].append([ind, i]) # 第一遍最短路计算最小情况下的距离 dis0 = [inf] * n stack = [[0, source]] dis0[source] = 0 while stack: d, i = heapq.heappop(stack) if dis0[i] < d: continue for ind, j in dct[i]: dj = edges[ind][2] + d if dj < dis0[j]: dis0[j] = dj heapq.heappush(stack, [dj, j]) if dis0[destination] > target: ac.st("NO") return # 第二遍最短路 dis1 = [inf] * n stack = [[0, source]] dis1[source] = 0 while stack: d, i = heapq.heappop(stack) if dis1[i] < d: continue for ind, j in dct[i]: if book[ind]: # 假设 (i, j) 是最短路上的边 if (edges[ind][2] + dis1[i]) + (dis0[destination] - dis0[j]) < target: # 此时还有一些增长空间即(当前到达 j 的距离)加上(剩余 j 到 destination)的距离仍旧小于 target x = target - (edges[ind][2] + dis1[i]) - (dis0[destination] - dis0[j]) edges[ind][2] += x book[ind] = 0 dj = edges[ind][2] + d if dj < dis1[j]: dis1[j] = dj heapq.heappush(stack, [dj, j]) if dis1[destination] == target: ac.st("YES") for e in edges: ac.lst(e) else: ac.st("NO") return Solution().main()
vfc_82317
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "4000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 5 13 0 4\n0 1 5\n2 1 2\n3 2 3\n1 4 0\n4 3 4", "output": "YES\n0 1 5\n2 1 2\n3 2 3\n1 4 8\n4 3 4", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1 123456789 0 1\n0 1 0", "output": "YES\n0 1 123456789", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1 999999999 1 0\n0 1 1000000000", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 5 10 1 2\n0 1 3\n1 2 0\n1 3 4\n2 3 4\n2 0 6", "output": "NO", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
667
Solve the following coding problem using the programming language python: A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you, enjoy freshness, think about big deeds you have to do. Today everything had changed quietly. You went on the street with a cup contained water, your favorite drink. In a moment when you were drinking a water you noticed that the process became quite long: the cup still contained water because of rain. You decided to make a formal model of what was happening and to find if it was possible to drink all water in that situation. Thus, your cup is a cylinder with diameter equals *d* centimeters. Initial level of water in cup equals *h* centimeters from the bottom. You drink a water with a speed equals *v* milliliters per second. But rain goes with such speed that if you do not drink a water from the cup, the level of water increases on *e* centimeters per second. The process of drinking water from the cup and the addition of rain to the cup goes evenly and continuously. Find the time needed to make the cup empty or find that it will never happen. It is guaranteed that if it is possible to drink all water, it will happen not later than after 104 seconds. Note one milliliter equals to one cubic centimeter. The input will be provided via standard input and looks as follows: The only line of the input contains four integer numbers *d*,<=*h*,<=*v*,<=*e* (1<=≤<=*d*,<=*h*,<=*v*,<=*e*<=≤<=104), where: - *d* — the diameter of your cylindrical cup, - *h* — the initial level of water in the cup, - *v* — the speed of drinking process from the cup in milliliters per second, - *e* — the growth of water because of rain if you do not drink from the cup. You should write the solution as standard output as follows: If it is impossible to make the cup empty, print "NO" (without quotes). Otherwise print "YES" (without quotes) in the first line. In the second line print a real number — time in seconds needed the cup will be empty. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=4. It is guaranteed that if the answer exists, it doesn't exceed 104. Here are example inputs and outputs for the problem: Example Input 1: 1 2 3 100 Example Output 1: NO Example Input 2: 1 1 1 1 Example Output 2: YES 3.659792366325 Now solve the problem by providing the code.
from math import pi X = list(map(int, input().split())) RainPouring = X[-1] * (X[0] / 2) ** 2 * pi if RainPouring >= X[-2]: print("NO");exit() X[-2] -= RainPouring Volume = X[1] * (X[0] / 2) ** 2 * pi print("YES", Volume / X[-2], sep='\n') # Caption: With the help of ARPA
vfc_82321
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 2 3 100", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1 1 1", "output": "YES\n3.659792366325", "type": "stdin_stdout" }, { "fn_name": null, "input": "48 7946 7992 72", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "72 6791 8546 46", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "100 5635 9099 23", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "20 287 3845 5", "output": "YES\n39.646277165210", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
991
Solve the following coding problem using the programming language python: Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system. The term is coming to an end and students start thinking about their grades. Today, a professor told his students that the grades for his course would be given out automatically  — he would calculate the simple average (arithmetic mean) of all grades given out for lab works this term and round to the nearest integer. The rounding would be done in favour of the student — $4.5$ would be rounded up to $5$ (as in example 3), but $4.4$ would be rounded down to $4$. This does not bode well for Vasya who didn't think those lab works would influence anything, so he may receive a grade worse than $5$ (maybe even the dreaded $2$). However, the professor allowed him to redo some of his works of Vasya's choosing to increase his average grade. Vasya wants to redo as as few lab works as possible in order to get $5$ for the course. Of course, Vasya will get $5$ for the lab works he chooses to redo. Help Vasya — calculate the minimum amount of lab works Vasya has to redo. The input will be provided via standard input and looks as follows: The first line contains a single integer $n$ — the number of Vasya's grades ($1 \leq n \leq 100$). The second line contains $n$ integers from $2$ to $5$ — Vasya's grades for his lab works. You should write the solution as standard output as follows: Output a single integer — the minimum amount of lab works that Vasya has to redo. It can be shown that Vasya can always redo enough lab works to get a $5$. Here are example inputs and outputs for the problem: Example Input 1: 3 4 4 4 Example Output 1: 2 Example Input 2: 4 5 4 5 5 Example Output 2: 0 Example Input 3: 4 5 3 3 5 Example Output 3: 1 Now solve the problem by providing the code.
from sys import * def main(): n = int(stdin.readline()) target = 4.5*n currentTotal = 0 minimumRetakes = 0 listOfScores = [int(x) for x in stdin.readline().split()] for x in listOfScores: currentTotal+=x listOfScores.sort() while(currentTotal < target): currentTotal+=(5-listOfScores[minimumRetakes]) minimumRetakes += 1 print(minimumRetakes) if __name__ == '__main__': main()
vfc_82325
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n4 4 4", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n5 4 5 5", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n5 3 3 5", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
30
Solve the following coding problem using the programming language python: A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income *A* of his kingdom during 0-th year is known, as well as the total income *B* during *n*-th year (these numbers can be negative — it means that there was a loss in the correspondent year). King wants to show financial stability. To do this, he needs to find common coefficient *X* — the coefficient of income growth during one year. This coefficient should satisfy the equation: Surely, the king is not going to do this job by himself, and demands you to find such number *X*. It is necessary to point out that the fractional numbers are not used in kingdom's economy. That's why all input numbers as well as coefficient *X* must be integers. The number *X* may be zero or negative. The input will be provided via standard input and looks as follows: The input contains three integers *A*, *B*, *n* (|*A*|,<=|*B*|<=≤<=1000, 1<=≤<=*n*<=≤<=10). You should write the solution as standard output as follows: Output the required integer coefficient *X*, or «No solution», if such a coefficient does not exist or it is fractional. If there are several possible solutions, output any of them. Here are example inputs and outputs for the problem: Example Input 1: 2 18 2 Example Output 1: 3 Example Input 2: -1 8 3 Example Output 2: -2 Example Input 3: 0 0 10 Example Output 3: 5 Example Input 4: 1 16 5 Example Output 4: No solution Now solve the problem by providing the code.
import sys q,w,num = map(int,input().split()) for p in range(-1000,1001): if q*(p**num)== w: print(p) sys.exit() print("No solution")
vfc_82329
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 18 2", "output": "3", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
285
Solve the following coding problem using the programming language python: Permutation *p* is an ordered set of integers *p*1,<=<=*p*2,<=<=...,<=<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. We'll denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size or the length of permutation *p*1,<=<=*p*2,<=<=...,<=<=*p**n*. The decreasing coefficient of permutation *p*1,<=*p*2,<=...,<=*p**n* is the number of such *i* (1<=≤<=*i*<=&lt;<=*n*), that *p**i*<=&gt;<=*p**i*<=+<=1. You have numbers *n* and *k*. Your task is to print the permutation of length *n* with decreasing coefficient *k*. The input will be provided via standard input and looks as follows: The single line contains two space-separated integers: *n*,<=*k* (1<=≤<=*n*<=≤<=105,<=0<=≤<=*k*<=&lt;<=*n*) — the permutation length and the decreasing coefficient. You should write the solution as standard output as follows: In a single line print *n* space-separated integers: *p*1,<=*p*2,<=...,<=*p**n* — the permutation of length *n* with decreasing coefficient *k*. If there are several permutations that meet this condition, print any of them. It is guaranteed that the permutation with the sought parameters exists. Here are example inputs and outputs for the problem: Example Input 1: 5 2 Example Output 1: 1 5 2 4 3 Example Input 2: 3 0 Example Output 2: 1 2 3 Example Input 3: 3 2 Example Output 3: 3 2 1 Now solve the problem by providing the code.
a, b = map(int, input().split()) m = [] j = 0 for i in range(a, 1, -1): if j != b: m.append(i) j += 1 if j == b: break print(*m, end = ' ') v = [] for i in range(1, a-b+1): v.append(i) print(*v)
vfc_82333
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 2", "output": "1 5 2 4 3", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 0", "output": "1 2 3", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2", "output": "3 2 1", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 0", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 0", "output": "1 2", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
653
Solve the following coding problem using the programming language python: Limak is a little polar bear. He has *n* balls, the *i*-th ball has size *t**i*. Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make friends happy: - No two friends can get balls of the same size. - No two friends can get balls of sizes that differ by more than 2. For example, Limak can choose balls with sizes 4, 5 and 3, or balls with sizes 90, 91 and 92. But he can't choose balls with sizes 5, 5 and 6 (two friends would get balls of the same size), and he can't choose balls with sizes 30, 31 and 33 (because sizes 30 and 33 differ by more than 2). Your task is to check whether Limak can choose three balls that satisfy conditions above. The input will be provided via standard input and looks as follows: The first line of the input contains one integer *n* (3<=≤<=*n*<=≤<=50) — the number of balls Limak has. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=1000) where *t**i* denotes the size of the *i*-th ball. You should write the solution as standard output as follows: Print "YES" (without quotes) if Limak can choose three balls of distinct sizes, such that any two of them differ by no more than 2. Otherwise, print "NO" (without quotes). Here are example inputs and outputs for the problem: Example Input 1: 4 18 55 16 17 Example Output 1: YES Example Input 2: 6 40 41 43 44 44 44 Example Output 2: NO Example Input 3: 8 5 972 3 4 1 4 970 971 Example Output 3: YES Now solve the problem by providing the code.
#http://codeforces.com/contest/653/problem/A import sys len_input = input() seq_input = input().split() #seq_input = '18 55 16 17'.split() # seq_input = '40 41 43 44 44 44'.split() # seq_input = '5 972 3 4 1 4 970 971'.split() # seq_input = ''.split() # seq_input = '998 30 384 289 505 340 872 223 663 31 929 625 864 699 735 589 676 399 745 635 963 381 75 97 324 612 597 797 103 382 25 894 219 458 337 572 201 355 294 275 278 311 586 573 965 704 936 237 715 543'.split() seq = sorted([int(x) for x in seq_input]) seq_red = sorted([int(x) for x in list(set(seq))]) # print(seq) # print(seq_red) if len(seq_red) < 3: print('NO') #less than two distinct options sys.exit() seq_sub = [seq_red[i] - seq_red[i+2] for i in range(len(seq_red)-2)] seq_truth = [1 if abs(x) < 3 else 0 for x in seq_sub] seq_sum = sum(seq_truth) if seq_sum == 0: print('NO') #all values are too far apart elif seq_sum > 0: print('YES')
vfc_82337
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n18 55 16 17", "output": "YES", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
471
Solve the following coding problem using the programming language python: Two polar bears Menshykov and Uslada from the St.Petersburg zoo and elephant Horace from the Kiev zoo got six sticks to play with and assess the animals' creativity. Menshykov, Uslada and Horace decided to make either an elephant or a bear from those sticks. They can make an animal from sticks in the following way: - Four sticks represent the animal's legs, these sticks should have the same length. - Two remaining sticks represent the animal's head and body. The bear's head stick must be shorter than the body stick. The elephant, however, has a long trunk, so his head stick must be as long as the body stick. Note that there are no limits on the relations between the leg sticks and the head and body sticks. Your task is to find out which animal can be made from the given stick set. The zoo keeper wants the sticks back after the game, so they must never be broken, even bears understand it. The input will be provided via standard input and looks as follows: The single line contains six space-separated integers *l**i* (1<=≤<=*l**i*<=≤<=9) — the lengths of the six sticks. It is guaranteed that the input is such that you cannot make both animals from the sticks. You should write the solution as standard output as follows: If you can make a bear from the given set, print string "Bear" (without the quotes). If you can make an elephant, print string "Elephant" (wıthout the quotes). If you can make neither a bear nor an elephant, print string "Alien" (without the quotes). Here are example inputs and outputs for the problem: Example Input 1: 4 2 5 4 4 4 Example Output 1: Bear Example Input 2: 4 4 5 4 4 5 Example Output 2: Elephant Example Input 3: 1 2 3 4 5 6 Example Output 3: Alien Now solve the problem by providing the code.
sticks = input().split() four = False two = False for stick in sticks: if sticks.count(stick) >= 4: four = True if sticks.count(stick) == 2 or sticks.count(stick) == 6: two = True if four: if two: print("Elephant") else: print("Bear") else: print("Alien")
vfc_82341
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2 5 4 4 4", "output": "Bear", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
801
Solve the following coding problem using the programming language python: You found a mysterious function *f*. The function takes two strings *s*1 and *s*2. These strings must consist only of lowercase English letters, and must be the same length. The output of the function *f* is another string of the same length. The *i*-th character of the output is equal to the minimum of the *i*-th character of *s*1 and the *i*-th character of *s*2. For example, *f*("ab", "ba") = "aa", and *f*("nzwzl", "zizez") = "niwel". You found two strings *x* and *y* of the same length and consisting of only lowercase English letters. Find any string *z* such that *f*(*x*,<=*z*)<==<=*y*, or print -1 if no such string *z* exists. The input will be provided via standard input and looks as follows: The first line of input contains the string *x*. The second line of input contains the string *y*. Both *x* and *y* consist only of lowercase English letters, *x* and *y* have same length and this length is between 1 and 100. You should write the solution as standard output as follows: If there is no string *z* such that *f*(*x*,<=*z*)<==<=*y*, print -1. Otherwise, print a string *z* such that *f*(*x*,<=*z*)<==<=*y*. If there are multiple possible answers, print any of them. The string *z* should be the same length as *x* and *y* and consist only of lowercase English letters. Here are example inputs and outputs for the problem: Example Input 1: ab aa Example Output 1: ba Example Input 2: nzwzl niwel Example Output 2: xiyez Example Input 3: ab ba Example Output 3: -1 Now solve the problem by providing the code.
x = [i for i in input()] y = [i for i in input()] z = [] possible = True for i in range(len(x)): if x[i] == y[i]: z.append('z') elif x[i] > y[i]: z.append(y[i]) else: possible = False break if possible: print("".join(z)) else: print(-1)
vfc_82345
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "ab\naa", "output": "ba", "type": "stdin_stdout" }, { "fn_name": null, "input": "nzwzl\nniwel", "output": "xiyez", "type": "stdin_stdout" }, { "fn_name": null, "input": "ab\nba", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "r\nl", "output": "l", "type": "stdin_stdout" }, { "fn_name": null, "input": "d\ny", "output": "-1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
698
Solve the following coding problem using the programming language python: Vasya has *n* days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this *n* days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the *i*-th day there are four options: 1. on this day the gym is closed and the contest is not carried out; 1. on this day the gym is closed and the contest is carried out; 1. on this day the gym is open and the contest is not carried out; 1. on this day the gym is open and the contest is carried out. On each of days Vasya can either have a rest or write the contest (if it is carried out on this day), or do sport (if the gym is open on this day). Find the minimum number of days on which Vasya will have a rest (it means, he will not do sport and write the contest at the same time). The only limitation that Vasya has — he does not want to do the same activity on two consecutive days: it means, he will not do sport on two consecutive days, and write the contest on two consecutive days. The input will be provided via standard input and looks as follows: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of days of Vasya's vacations. The second line contains the sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=3) separated by space, where: - *a**i* equals 0, if on the *i*-th day of vacations the gym is closed and the contest is not carried out; - *a**i* equals 1, if on the *i*-th day of vacations the gym is closed, but the contest is carried out; - *a**i* equals 2, if on the *i*-th day of vacations the gym is open and the contest is not carried out; - *a**i* equals 3, if on the *i*-th day of vacations the gym is open and the contest is carried out. You should write the solution as standard output as follows: Print the minimum possible number of days on which Vasya will have a rest. Remember that Vasya refuses: - to do sport on any two consecutive days, - to write the contest on any two consecutive days. Here are example inputs and outputs for the problem: Example Input 1: 4 1 3 2 0 Example Output 1: 2 Example Input 2: 7 1 3 3 2 1 2 3 Example Output 2: 0 Example Input 3: 2 2 2 Example Output 3: 1 Now solve the problem by providing the code.
n=int(input()) dp=[[0 for i in range(3)]for j in range(n+1)] ar=tuple(map(str,input().split())) for i in range(1,n+1): x=ar[i-1] dp[i][0]=min(dp[i-1])+1 if(x=='1' or x=='3'): dp[i][1]=min(dp[i-1][0],dp[i-1][2]) else: dp[i][1]=dp[i-1][1]+1 if(x=='2' or x=='3'): dp[i][2]=min(dp[i-1][0],dp[i-1][1]) else: dp[i][2]=dp[i-1][2]+1 print(min(dp[-1]))
vfc_82353
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 3 2 0", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n1 3 3 2 1 2 3", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2 2", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n0", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n0 0 1 1 0 0 0 0 1 0", "output": "8", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\n3 2 3 3 3 2 3 1 3 2 2 3 2 3 3 3 3 3 3 1 2 2 3 1 3 3 2 2 2 3 1 0 3 3 3 2 3 3 1 1 3 1 3 3 3 1 3 1 3 0 1 3 2 3 2 1 1 3 2 3 3 3 2 3 1 3 3 3 3 2 2 2 1 3 1 3 3 3 3 1 3 2 3 3 0 3 3 3 3 3 1 0 2 1 3 3 0 2 3 3", "output": "16", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
182
Solve the following coding problem using the programming language python: Vasya has recently bought some land and decided to surround it with a wooden fence. He went to a company called "Wooden board" that produces wooden boards for fences. Vasya read in the catalog of products that the company has at its disposal *n* different types of wood. The company uses the *i*-th type of wood to produce a board of this type that is a rectangular *a**i* by *b**i* block. Vasya decided to order boards in this company and build a fence from them. It turned out that the storehouse of the company is so large that Vasya can order arbitrary number of boards of every type. Note that Vasya is allowed to turn the boards as he builds the fence. However, Vasya cannot turn square boards. Vasya is required to construct a fence of length *l*, however, an arbitrary fence won't do. Vasya wants his fence to look beautiful. We'll say that a fence is beautiful if and only if the following two conditions are fulfilled: - there are no two successive boards of the same type - the first board of the fence has an arbitrary length, and the length of each subsequent board equals the width of the previous one In other words, the fence is considered beautiful, if the type of the *i*-th board in the fence is different from the *i*<=-<=1-th board's type; besides, the *i*-th board's length is equal to the *i*<=-<=1-th board's width (for all *i*, starting from 2). Now Vasya wonders, how many variants of arranging a fence for his land exist. Your task is to count the number of different beautiful fences of length *l*. Two fences will be considered the same if the corresponding sequences of fence boards types and rotations are the same, otherwise the fences are different. Since the sought number can be large enough, you need to calculate the answer modulo 1000000007 (109<=+<=7). The input will be provided via standard input and looks as follows: The first line contains two integers *n* and *l* (1<=≤<=*n*<=≤<=100,<=1<=≤<=*l*<=≤<=3000) — the number of different board types and the fence length, correspondingly. Next *n* lines contain descriptions of board types: the *i*-th line contains two integers *a**i* and *b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=100) — the sizes of the board of the *i*-th type. All numbers on the lines are separated by spaces. You should write the solution as standard output as follows: Print a single integer — the sought number of variants modulo 1000000007 (109<=+<=7). Here are example inputs and outputs for the problem: Example Input 1: 2 3 1 2 2 3 Example Output 1: 2 Example Input 2: 1 2 2 2 Example Output 2: 1 Example Input 3: 6 6 2 1 3 2 2 5 3 3 5 1 2 1 Example Output 3: 20 Now solve the problem by providing the code.
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def f(u, v): return 2 * n * u + v n, l = map(int, input().split()) mod = pow(10, 9) + 7 a, b = [], [] for _ in range(n): a0, b0 = map(int, input().split()) a.append(a0) b.append(b0) if a0 == b0: a0, b0 = l + 1, l + 1 a.append(b0) b.append(a0) G = [[] for _ in range(2 * n)] for i in range(2 * n): for j in range(2 * n): if i // 2 == j // 2: continue if b[i] == a[j]: G[i].append(j) m = 2 * n * (l + 1) dp = [0] * m for i in range(2 * n): if a[i] <= l: dp[f(a[i], i)] = 1 for i in range(1, l): for j in range(2 * n): u = f(i, j) if not dp[u]: continue for k in G[j]: if i + a[k] <= l: dp[f(i + a[k], k)] += dp[u] dp[f(i + a[k], k)] %= mod ans = 0 for i in range(2 * n): ans += dp[f(l, i)] ans %= mod print(ans)
vfc_82361
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 3\n1 2\n2 3", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 2\n2 2", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
895
Solve the following coding problem using the programming language python: Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into *n* pieces. The *i*-th piece is a sector of angle equal to *a**i*. Vasya and Petya want to divide all pieces of pizza into two continuous sectors in such way that the difference between angles of these sectors is minimal. Sector angle is sum of angles of all pieces in it. Pay attention, that one of sectors can be empty. The input will be provided via standard input and looks as follows: The first line contains one integer *n* (1<=≤<=*n*<=≤<=360)  — the number of pieces into which the delivered pizza was cut. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=360)  — the angles of the sectors into which the pizza was cut. The sum of all *a**i* is 360. You should write the solution as standard output as follows: Print one integer  — the minimal difference between angles of sectors that will go to Vasya and Petya. Here are example inputs and outputs for the problem: Example Input 1: 4 90 90 90 90 Example Output 1: 0 Example Input 2: 3 100 100 160 Example Output 2: 40 Example Input 3: 1 360 Example Output 3: 360 Example Input 4: 4 170 30 150 10 Example Output 4: 0 Now solve the problem by providing the code.
n=int(input()) a=[int (i) for i in input().split()] min=361 for i in range(n): for j in range(i, n): if -min<sum(a[0:i])+sum(a[j:])-sum(a[i:j])<min: min=sum(a[0:i])+sum(a[j:])-sum(a[i:j]) if min<0: min*=-1 print(min)
vfc_82365
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "4000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n90 90 90 90", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n100 100 160", "output": "40", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n360", "output": "360", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n170 30 150 10", "output": "0", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
855
Solve the following coding problem using the programming language python: Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as he suspected a Horcrux to be present there. He saw Marvolo Gaunt's Ring and identified it as a Horcrux. Although he destroyed it, he is still affected by its curse. Professor Snape is helping Dumbledore remove the curse. For this, he wants to give Dumbledore exactly *x* drops of the potion he made. Value of *x* is calculated as maximum of *p*·*a**i*<=+<=*q*·*a**j*<=+<=*r*·*a**k* for given *p*,<=*q*,<=*r* and array *a*1,<=*a*2,<=... *a**n* such that 1<=≤<=*i*<=≤<=*j*<=≤<=*k*<=≤<=*n*. Help Snape find the value of *x*. Do note that the value of *x* may be negative. The input will be provided via standard input and looks as follows: First line of input contains 4 integers *n*,<=*p*,<=*q*,<=*r* (<=-<=109<=≤<=*p*,<=*q*,<=*r*<=≤<=109,<=1<=≤<=*n*<=≤<=105). Next line of input contains *n* space separated integers *a*1,<=*a*2,<=... *a**n* (<=-<=109<=≤<=*a**i*<=≤<=109). You should write the solution as standard output as follows: Output a single integer the maximum value of *p*·*a**i*<=+<=*q*·*a**j*<=+<=*r*·*a**k* that can be obtained provided 1<=≤<=*i*<=≤<=*j*<=≤<=*k*<=≤<=*n*. Here are example inputs and outputs for the problem: Example Input 1: 5 1 2 3 1 2 3 4 5 Example Output 1: 30 Example Input 2: 5 1 2 -3 -1 -2 -3 -4 -5 Example Output 2: 12 Now solve the problem by providing the code.
def main(): n, p, q, r = map(int, input().split()) a = list(map(int, input().split())) ans = -float('inf') mx = -float('inf') mx1 = -float('inf') for i in range(n): mx = max(mx, a[i] * p) mx1 = max(mx1, mx + a[i] * q) ans = max(ans, mx1 + a[i] * r) print(ans) if __name__ == '__main__': main()
vfc_82369
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 1 2 3\n1 2 3 4 5", "output": "30", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 1 2 -3\n-1 -2 -3 -4 -5", "output": "12", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 886327859 82309257 -68295239\n-731225382 354766539 -48222231 -474691998 360965777", "output": "376059240645059046", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 -96405765 -495906217 625385006\n-509961652 392159235 -577128498 -744548876", "output": "547306902373544674", "type": "stdin_stdout" }, { "fn_name": null, "input": "43 959134961 -868367850 142426380\n921743429 63959718 -797293233 122041422 -407576197 700139744 299598010 168207043 362252658 591926075 941946099 812263640 -76679927 -824267725 89529990 -73303355 83596189 -982699817 -235197848 654773327 125211479 -497091570 -2301804 203486596 -126652024 309810546 -581289415 -740125230 64425927 -501018049 304730559 34930193 -762964086 723645139 -826821494 495947907 816331024 9932423 -876541603 -782692568 322360800 841436938 40787162", "output": "1876641179289775029", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
785
Solve the following coding problem using the programming language python: Anton's favourite geometric figures are regular polyhedrons. Note that there are five kinds of regular polyhedrons: - Tetrahedron. Tetrahedron has 4 triangular faces. - Cube. Cube has 6 square faces. - Octahedron. Octahedron has 8 triangular faces. - Dodecahedron. Dodecahedron has 12 pentagonal faces. - Icosahedron. Icosahedron has 20 triangular faces. All five kinds of polyhedrons are shown on the picture below: Anton has a collection of *n* polyhedrons. One day he decided to know, how many faces his polyhedrons have in total. Help Anton and find this number! The input will be provided via standard input and looks as follows: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of polyhedrons in Anton's collection. Each of the following *n* lines of the input contains a string *s**i* — the name of the *i*-th polyhedron in Anton's collection. The string can look like this: - "Tetrahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is a tetrahedron. - "Cube" (without quotes), if the *i*-th polyhedron in Anton's collection is a cube. - "Octahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is an octahedron. - "Dodecahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is a dodecahedron. - "Icosahedron" (without quotes), if the *i*-th polyhedron in Anton's collection is an icosahedron. You should write the solution as standard output as follows: Output one number — the total number of faces in all the polyhedrons in Anton's collection. Here are example inputs and outputs for the problem: Example Input 1: 4 Icosahedron Cube Tetrahedron Dodecahedron Example Output 1: 42 Example Input 2: 3 Dodecahedron Octahedron Octahedron Example Output 2: 28 Now solve the problem by providing the code.
lists=[] for _ in range(int(input())): lists.append(input()) s=0 for i in lists: if i=='Tetrahedron': s+=4 elif i=='Cube': s+=6 elif i=='Octahedron': s+=8 elif i=='Dodecahedron': s+=12 elif i=='Icosahedron': s+=20 print(s)
vfc_82377
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\nIcosahedron\nCube\nTetrahedron\nDodecahedron", "output": "42", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\nDodecahedron\nOctahedron\nOctahedron", "output": "28", "type": "stdin_stdout" }, { "fn_name": null, "input": "25\nIcosahedron\nOctahedron\nTetrahedron\nDodecahedron\nCube\nIcosahedron\nOctahedron\nCube\nTetrahedron\nIcosahedron\nIcosahedron\nTetrahedron\nOctahedron\nDodecahedron\nIcosahedron\nOctahedron\nIcosahedron\nTetrahedron\nDodecahedron\nTetrahedron\nOctahedron\nCube\nCube\nDodecahedron\nTetrahedron", "output": "256", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\nTetrahedron", "output": "4", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
699
Solve the following coding problem using the programming language python: There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. *n* particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the distance in meters from the center of the collider, *x**i* is the coordinate of the *i*-th particle and its position in the collider at the same time. All coordinates of particle positions are even integers. You know the direction of each particle movement — it will move to the right or to the left after the collider's launch start. All particles begin to move simultaneously at the time of the collider's launch start. Each particle will move straight to the left or straight to the right with the constant speed of 1 meter per microsecond. The collider is big enough so particles can not leave it in the foreseeable time. Write the program which finds the moment of the first collision of any two particles of the collider. In other words, find the number of microseconds before the first moment when any two particles are at the same point. The input will be provided via standard input and looks as follows: The first line contains the positive integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of particles. The second line contains *n* symbols "L" and "R". If the *i*-th symbol equals "L", then the *i*-th particle will move to the left, otherwise the *i*-th symbol equals "R" and the *i*-th particle will move to the right. The third line contains the sequence of pairwise distinct even integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=109) — the coordinates of particles in the order from the left to the right. It is guaranteed that the coordinates of particles are given in the increasing order. You should write the solution as standard output as follows: In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion. Print the only integer -1, if the collision of particles doesn't happen. Here are example inputs and outputs for the problem: Example Input 1: 4 RLRL 2 4 6 10 Example Output 1: 1 Example Input 2: 3 LLR 40 50 60 Example Output 2: -1 Now solve the problem by providing the code.
n = int(input()) s = input() arr = list(map(int, input().split())) ans = [] for i in range(n): if(i == n-1): break if((s[i] == "R" and s[i+1] == "L")): ans.append(arr[i+1]-arr[i]) for i in range(len(ans)): ans[i] = int(ans[i]/2) if not ans: print(-1) else: print(min(ans))
vfc_82381
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\nRLRL\n2 4 6 10", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\nLLR\n40 50 60", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\nRLLR\n46 230 264 470", "output": "92", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
729
Solve the following coding problem using the programming language python: Polycarp has interviewed Oleg and has written the interview down without punctuation marks and spaces to save time. Thus, the interview is now a string *s* consisting of *n* lowercase English letters. There is a filler word ogo in Oleg's speech. All words that can be obtained from ogo by adding go several times to the end of it are also considered to be fillers. For example, the words ogo, ogogo, ogogogo are fillers, but the words go, og, ogog, ogogog and oggo are not fillers. The fillers have maximal size, for example, for ogogoo speech we can't consider ogo a filler and goo as a normal phrase. We should consider ogogo as a filler here. To print the interview, Polycarp has to replace each of the fillers with three asterisks. Note that a filler word is replaced with exactly three asterisks regardless of its length. Polycarp has dealt with this problem in no time. Can you do the same? The clock is ticking! The input will be provided via standard input and looks as follows: The first line contains a positive integer *n* (1<=≤<=*n*<=≤<=100) — the length of the interview. The second line contains the string *s* of length *n*, consisting of lowercase English letters. You should write the solution as standard output as follows: Print the interview text after the replacement of each of the fillers with "***". It is allowed for the substring "***" to have several consecutive occurences. Here are example inputs and outputs for the problem: Example Input 1: 7 aogogob Example Output 1: a***b Example Input 2: 13 ogogmgogogogo Example Output 2: ***gmg*** Example Input 3: 9 ogoogoogo Example Output 3: ********* Now solve the problem by providing the code.
import sys, io, os import math import bisect import heapq import string from collections import defaultdict,Counter,deque input = sys.stdin.readline def I(): return input() def II(): return int(input()) def MII(): return map(int, input().split()) def LI(): return list(input().split()) def LII(): return list(map(int, input().split())) def GMI(): return map(lambda x: int(x) - 1, input().split()) def LGMI(): return list(map(lambda x: int(x) - 1, input().split())) def WRITE(out): return print('\n'.join(map(str, out))) def WS(out): return print(' '.join(map(str, out))) def WNS(out): return print(''.join(map(str, out))) ''' n%4 == 0 and all_cnts <= n//4 ''' def solve(): n = II() s = I().strip() ans = [] l = 0 while l < n: # print(l, s[l:]) if l+2 < n and s[l:l+3] == 'ogo': l += 3 for i in range(l, n-1, 2): if s[i:i+2] == 'go': l = i+2 else: break ans.append('***') else: ans.append(s[l]) l += 1 WNS(ans) solve()
vfc_82385
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\naogogob", "output": "a***b", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
34
Solve the following coding problem using the programming language python: Once Bob got to a sale of old TV sets. There were *n* TV sets at that sale. TV set with index *i* costs *a**i* bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets he wants. Though he's very strong, Bob can carry at most *m* TV sets, and he has no desire to go to the sale for the second time. Please, help Bob find out the maximum sum of money that he can earn. The input will be provided via standard input and looks as follows: The first line contains two space-separated integers *n* and *m* (1<=≤<=*m*<=≤<=*n*<=≤<=100) — amount of TV sets at the sale, and amount of TV sets that Bob can carry. The following line contains *n* space-separated integers *a**i* (<=-<=1000<=≤<=*a**i*<=≤<=1000) — prices of the TV sets. You should write the solution as standard output as follows: Output the only number — the maximum sum of money that Bob can earn, given that he can carry at most *m* TV sets. Here are example inputs and outputs for the problem: Example Input 1: 5 3 -6 0 35 -2 4 Example Output 1: 8 Example Input 2: 4 2 7 0 0 -7 Example Output 2: 7 Now solve the problem by providing the code.
n, m = [int(x) for x in input().split(' ')] a = [int(x) for x in input().split(' ') if int(x) < 0] a.sort() print(-sum(a[:min(len(a), m)]))
vfc_82389
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 3\n-6 0 35 -2 4", "output": "8", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 2\n7 0 0 -7", "output": "7", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 6\n756 -611 251 -66 572 -818", "output": "1495", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
331
Solve the following coding problem using the programming language python: Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar. The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on it. The translation from Old Beaverish is as follows: "May the Great Beaver bless you! May your chacres open and may your third eye never turn blind from beholding the Truth! Take the magic number, subtract a digit from it (the digit must occur in the number) and get a new magic number. Repeat this operation until a magic number equals zero. The Earth will stand on Three Beavers for the time, equal to the number of subtractions you perform!" Distinct subtraction sequences can obviously get you different number of operations. But the Smart Beaver is ready to face the worst and is asking you to count the minimum number of operations he needs to reduce the magic number to zero. The input will be provided via standard input and looks as follows: The single line contains the magic integer *n*, 0<=≤<=*n*. - to get 20 points, you need to solve the problem with constraints: *n*<=≤<=106 (subproblem C1); - to get 40 points, you need to solve the problem with constraints: *n*<=≤<=1012 (subproblems C1+C2); - to get 100 points, you need to solve the problem with constraints: *n*<=≤<=1018 (subproblems C1+C2+C3). You should write the solution as standard output as follows: Print a single integer — the minimum number of subtractions that turns the magic number to a zero. Here are example inputs and outputs for the problem: Example Input 1: 24 Example Output 1: 5 Now solve the problem by providing the code.
n=int(input()) l=list(str(n)) n=int(n) c=0 while n!=0: m=max(list(str(n))) n-=int(m) c+=1 print(c)
vfc_82393
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "24", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "0", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "3", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "8", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "9", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
16
Solve the following coding problem using the programming language python: A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are *m* containers, in the *i*-th container there are *a**i* matchboxes, and each matchbox contains *b**i* matches. All the matchboxes are of the same size. The burglar's rucksack can hold *n* matchboxes exactly. Your task is to find out the maximum amount of matches that a burglar can carry away. He has no time to rearrange matches in the matchboxes, that's why he just chooses not more than *n* matchboxes so that the total amount of matches in them is maximal. The input will be provided via standard input and looks as follows: The first line of the input contains integer *n* (1<=≤<=*n*<=≤<=2·108) and integer *m* (1<=≤<=*m*<=≤<=20). The *i*<=+<=1-th line contains a pair of numbers *a**i* and *b**i* (1<=≤<=*a**i*<=≤<=108,<=1<=≤<=*b**i*<=≤<=10). All the input numbers are integer. You should write the solution as standard output as follows: Output the only number — answer to the problem. Here are example inputs and outputs for the problem: Example Input 1: 7 3 5 10 2 5 3 6 Example Output 1: 62 Example Input 2: 3 3 1 3 2 2 3 1 Example Output 2: 7 Now solve the problem by providing the code.
n,m=map(int,input().split()) l=[] for i in range(m): a,b=map(int,input().split()) l.append([b,a]) l.sort(reverse=True) i=c=0 while n>0 and i<len(l): if l[i][1]<n: n-=l[i][1] c+=l[i][0]*l[i][1] i+=1 else: # print(n) d=n n-=d c+=l[i][0]*d print(c)
vfc_82397
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "500" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7 3\n5 10\n2 5\n3 6", "output": "62", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n1 3\n2 2\n3 1", "output": "7", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n1 2", "output": "2", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
413
Solve the following coding problem using the programming language python: Not so long ago company R2 bought company R1 and consequently, all its developments in the field of multicore processors. Now the R2 laboratory is testing one of the R1 processors. The testing goes in *n* steps, at each step the processor gets some instructions, and then its temperature is measured. The head engineer in R2 is keeping a report record on the work of the processor: he writes down the minimum and the maximum measured temperature in his notebook. His assistant had to write down all temperatures into his notebook, but (for unknown reasons) he recorded only *m*. The next day, the engineer's assistant filed in a report with all the *m* temperatures. However, the chief engineer doubts that the assistant wrote down everything correctly (naturally, the chief engineer doesn't doubt his notes). So he asked you to help him. Given numbers *n*, *m*, *min*, *max* and the list of *m* temperatures determine whether you can upgrade the set of *m* temperatures to the set of *n* temperatures (that is add *n*<=-<=*m* temperatures), so that the minimum temperature was *min* and the maximum one was *max*. The input will be provided via standard input and looks as follows: The first line contains four integers *n*,<=*m*,<=*min*,<=*max* (1<=≤<=*m*<=&lt;<=*n*<=≤<=100; 1<=≤<=*min*<=&lt;<=*max*<=≤<=100). The second line contains *m* space-separated integers *t**i* (1<=≤<=*t**i*<=≤<=100) — the temperatures reported by the assistant. Note, that the reported temperatures, and the temperatures you want to add can contain equal temperatures. You should write the solution as standard output as follows: If the data is consistent, print 'Correct' (without the quotes). Otherwise, print 'Incorrect' (without the quotes). Here are example inputs and outputs for the problem: Example Input 1: 2 1 1 2 1 Example Output 1: Correct Example Input 2: 3 1 1 3 2 Example Output 2: Correct Example Input 3: 2 1 1 3 2 Example Output 3: Incorrect Now solve the problem by providing the code.
a,b,c,d=map(int,input().split()) z=list(map(int,input().split())) k=z.copy() if c in k:k.remove(c) if d in k:k.remove(d) if (max(z)>d or min(z)<c or len(k)+2>a ):print("Incorrect") else:print("Correct")
vfc_82405
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 1 1 2\n1", "output": "Correct", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1 1 3\n2", "output": "Correct", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1 1 3\n2", "output": "Incorrect", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1 1 5\n3", "output": "Correct", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
401
Solve the following coding problem using the programming language python: Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed *x* in the absolute value. Natasha doesn't like when Vanya spends a long time playing, so she hid all of his cards. Vanya became sad and started looking for the cards but he only found *n* of them. Vanya loves the balance, so he wants the sum of all numbers on found cards equal to zero. On the other hand, he got very tired of looking for cards. Help the boy and say what is the minimum number of cards does he need to find to make the sum equal to zero? You can assume that initially Vanya had infinitely many cards with each integer number from <=-<=*x* to *x*. The input will be provided via standard input and looks as follows: The first line contains two integers: *n* (1<=≤<=*n*<=≤<=1000) — the number of found cards and *x* (1<=≤<=*x*<=≤<=1000) — the maximum absolute value of the number on a card. The second line contains *n* space-separated integers — the numbers on found cards. It is guaranteed that the numbers do not exceed *x* in their absolute value. You should write the solution as standard output as follows: Print a single number — the answer to the problem. Here are example inputs and outputs for the problem: Example Input 1: 3 2 -1 1 2 Example Output 1: 1 Example Input 2: 2 3 -2 -2 Example Output 2: 2 Now solve the problem by providing the code.
n,x=map(int,input().split()) l=list(map(int,input().split())) import math as m print(m.ceil(abs(sum(l))/x))
vfc_82413
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n-1 1 2", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3\n-2 -2", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 4\n1 2 3 4", "output": "3", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
181
Solve the following coding problem using the programming language python: The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang. The Berland capital's map is represented by an *n*<=×<=*m* rectangular table. Each cell of the table on the map represents some districts of the capital. The capital's main detective Polycarpus took a map and marked there the districts where the first three robberies had been committed as asterisks. Deduction tells Polycarpus that the fourth robbery will be committed in such district, that all four robbed districts will form the vertices of some rectangle, parallel to the sides of the map. Polycarpus is good at deduction but he's hopeless at math. So he asked you to find the district where the fourth robbery will be committed. The input will be provided via standard input and looks as follows: The first line contains two space-separated integers *n* and *m* (2<=≤<=*n*,<=*m*<=≤<=100) — the number of rows and columns in the table, correspondingly. Each of the next *n* lines contains *m* characters — the description of the capital's map. Each character can either be a "." (dot), or an "*" (asterisk). A character equals "*" if the corresponding district has been robbed. Otherwise, it equals ".". It is guaranteed that the map has exactly three characters "*" and we can always find the fourth district that meets the problem requirements. You should write the solution as standard output as follows: Print two integers — the number of the row and the number of the column of the city district that is the fourth one to be robbed. The rows are numbered starting from one from top to bottom and the columns are numbered starting from one from left to right. Here are example inputs and outputs for the problem: Example Input 1: 3 2 .* .. ** Example Output 1: 1 1 Example Input 2: 3 3 *.* *.. ... Example Output 2: 2 3 Now solve the problem by providing the code.
r,c = map(int,input().split()) ind_c =[] ind = None for i in range(r): s = input() if s.count('*') == 1: ind = [i,s.index('*')] elif s.count('*')>1: for j in range(c): if s[j] == '*': ind_c.append(j) if ind[1] == ind_c[1]: print(ind[0]+1,ind_c[0]+1) else: print(ind[0]+1,ind_c[1]+1)
vfc_82417
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n.*\n..\n**", "output": "1 1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
548
Solve the following coding problem using the programming language python: While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string *s*. He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly *k* messages in his own bag, each was a palindrome string and all those strings had the same length. He asked you to help him and tell him if he has worn his own back-bag. Check if the given string *s* is a concatenation of *k* palindromes of the same length. The input will be provided via standard input and looks as follows: The first line of input contains string *s* containing lowercase English letters (1<=≤<=|*s*|<=≤<=1000). The second line contains integer *k* (1<=≤<=*k*<=≤<=1000). You should write the solution as standard output as follows: Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise. Here are example inputs and outputs for the problem: Example Input 1: saba 2 Example Output 1: NO Example Input 2: saddastavvat 2 Example Output 2: YES Now solve the problem by providing the code.
string = input() partskitnekarnehai = int(input()) if len(string)%partskitnekarnehai!=0: print('NO') exit() nayalength = len(string) // partskitnekarnehai # o is length of part for j in range(partskitnekarnehai): seedha_part = string[ j*nayalength : (j + 1)*nayalength] # print(seedha_part) ulta_part=reversed(seedha_part) # print("".join(ulta_part)) if seedha_part != "".join(ulta_part): print("NO") exit() print("YES") ''' https://codeforces.com/problemset/problem/548/A 1. Aaj exit() seekha, kaafi useful, i always thought agar aise kuch karna hai to i'll have to define a function, fir use return to get out of the code. 4. Abe yaar mai bhi kya gadha hu, like agar NO hai answer, to exit karna chahiye, i exited on YES wala case 3. Are bhai yaaar wo sabse upar wala block mai bhool hi gaya tha, gahdam ek aur wrong submission 2. Also line 7 me agar -1 kia to it only check first part of string '''
vfc_82421
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "saba\n2", "output": "NO", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
937
Solve the following coding problem using the programming language python: The recent All-Berland Olympiad in Informatics featured *n* participants with each scoring a certain amount of points. As the head of the programming committee, you are to determine the set of participants to be awarded with diplomas with respect to the following criteria: - At least one participant should get a diploma. - None of those with score equal to zero should get awarded. - When someone is awarded, all participants with score not less than his score should also be awarded. Determine the number of ways to choose a subset of participants that will receive the diplomas. The input will be provided via standard input and looks as follows: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of participants. The next line contains a sequence of *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=600) — participants' scores. It's guaranteed that at least one participant has non-zero score. You should write the solution as standard output as follows: Print a single integer — the desired number of ways. Here are example inputs and outputs for the problem: Example Input 1: 4 1 3 3 2 Example Output 1: 3 Example Input 2: 3 1 1 1 Example Output 2: 1 Example Input 3: 4 42 0 0 42 Example Output 3: 1 Now solve the problem by providing the code.
n=int(input()) a=list(map(int,input().split())) sa=set(a) arr=list(sa) count=0 for i in sa: if i!=0: count+=1 print(count)
vfc_82425
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 3 3 2", "output": "3", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
990
Solve the following coding problem using the programming language python: You have a Petri dish with bacteria and you are preparing to dive into the harsh micro-world. But, unfortunately, you don't have any microscope nearby, so you can't watch them. You know that you have $n$ bacteria in the Petri dish and size of the $i$-th bacteria is $a_i$. Also you know intergalactic positive integer constant $K$. The $i$-th bacteria can swallow the $j$-th bacteria if and only if $a_i &gt; a_j$ and $a_i \le a_j + K$. The $j$-th bacteria disappear, but the $i$-th bacteria doesn't change its size. The bacteria can perform multiple swallows. On each swallow operation any bacteria $i$ can swallow any bacteria $j$ if $a_i &gt; a_j$ and $a_i \le a_j + K$. The swallow operations go one after another. For example, the sequence of bacteria sizes $a=[101, 53, 42, 102, 101, 55, 54]$ and $K=1$. The one of possible sequences of swallows is: $[101, 53, 42, 102, \underline{101}, 55, 54]$ $\to$ $[101, \underline{53}, 42, 102, 55, 54]$ $\to$ $[\underline{101}, 42, 102, 55, 54]$ $\to$ $[42, 102, 55, \underline{54}]$ $\to$ $[42, 102, 55]$. In total there are $3$ bacteria remained in the Petri dish. Since you don't have a microscope, you can only guess, what the minimal possible number of bacteria can remain in your Petri dish when you finally will find any microscope. The input will be provided via standard input and looks as follows: The first line contains two space separated positive integers $n$ and $K$ ($1 \le n \le 2 \cdot 10^5$, $1 \le K \le 10^6$) — number of bacteria and intergalactic constant $K$. The second line contains $n$ space separated integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^6$) — sizes of bacteria you have. You should write the solution as standard output as follows: Print the only integer — minimal possible number of bacteria can remain. Here are example inputs and outputs for the problem: Example Input 1: 7 1 101 53 42 102 101 55 54 Example Output 1: 3 Example Input 2: 6 5 20 15 10 15 20 25 Example Output 2: 1 Example Input 3: 7 1000000 1 1 1 1 1 1 1 Example Output 3: 7 Now solve the problem by providing the code.
n, K = map(int, input().split()) a = sorted(list(map(int, input().split()))) num = 0 for i in a: while a[num] < i: if i <= K+a[num]: n-=1 num += 1 print(n)
vfc_82429
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7 1\n101 53 42 102 101 55 54", "output": "3", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
265
Solve the following coding problem using the programming language python: There is a sequence of colorful stones. The color of each stone is one of red, green, or blue. You are given a string *s*. The *i*-th (1-based) character of *s* represents the color of the *i*-th stone. If the character is "R", "G", or "B", the color of the corresponding stone is red, green, or blue, respectively. Initially Squirrel Liss is standing on the first stone. You perform instructions one or more times. Each instruction is one of the three types: "RED", "GREEN", or "BLUE". After an instruction *c*, if Liss is standing on a stone whose colors is *c*, Liss will move one stone forward, else she will not move. You are given a string *t*. The number of instructions is equal to the length of *t*, and the *i*-th character of *t* represents the *i*-th instruction. Calculate the final position of Liss (the number of the stone she is going to stand on in the end) after performing all the instructions, and print its 1-based position. It is guaranteed that Liss don't move out of the sequence. The input will be provided via standard input and looks as follows: The input contains two lines. The first line contains the string *s* (1<=≤<=|*s*|<=≤<=50). The second line contains the string *t* (1<=≤<=|*t*|<=≤<=50). The characters of each string will be one of "R", "G", or "B". It is guaranteed that Liss don't move out of the sequence. You should write the solution as standard output as follows: Print the final 1-based position of Liss in a single line. Here are example inputs and outputs for the problem: Example Input 1: RGB RRR Example Output 1: 2 Example Input 2: RRRBGBRBBB BBBRR Example Output 2: 3 Example Input 3: BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB BBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB Example Output 3: 15 Now solve the problem by providing the code.
#A. Colorful Stones from tkinter import S s = input() t = input() i = 0 j = 0 counter = 1 while j < len(t): if s[i] != t[j]: j += 1 elif s[i] == t[j]: i += 1 j += 1 counter += 1 print(counter)
vfc_82433
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "RGB\nRRR", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "RRRBGBRBBB\nBBBRR", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB\nBBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB", "output": "15", "type": "stdin_stdout" }, { "fn_name": null, "input": "G\nRRBBRBRRBR", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "RRRRRBRRBRRGRBGGRRRGRBBRBBBBBRGRBGBRRGBBBRBBGBRGBB\nB", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "RRGGBRGRBG\nBRRGGBBGGR", "output": "7", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
616
Solve the following coding problem using the programming language python: You are given a rectangular field of *n*<=×<=*m* cells. Each cell is either empty or impassable (contains an obstacle). Empty cells are marked with '.', impassable cells are marked with '*'. Let's call two empty cells adjacent if they share a side. Let's call a connected component any non-extendible set of cells such that any two of them are connected by the path of adjacent cells. It is a typical well-known definition of a connected component. For each impassable cell (*x*,<=*y*) imagine that it is an empty cell (all other cells remain unchanged) and find the size (the number of cells) of the connected component which contains (*x*,<=*y*). You should do it for each impassable cell independently. The answer should be printed as a matrix with *n* rows and *m* columns. The *j*-th symbol of the *i*-th row should be "." if the cell is empty at the start. Otherwise the *j*-th symbol of the *i*-th row should contain the only digit —- the answer modulo 10. The matrix should be printed without any spaces. To make your output faster it is recommended to build the output as an array of *n* strings having length *m* and print it as a sequence of lines. It will be much faster than writing character-by-character. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. The input will be provided via standard input and looks as follows: The first line contains two integers *n*,<=*m* (1<=≤<=*n*,<=*m*<=≤<=1000) — the number of rows and columns in the field. Each of the next *n* lines contains *m* symbols: "." for empty cells, "*" for impassable cells. You should write the solution as standard output as follows: Print the answer as a matrix as described above. See the examples to precise the format of the output. Here are example inputs and outputs for the problem: Example Input 1: 3 3 *.* .*. *.* Example Output 1: 3.3 .5. 3.3 Example Input 2: 4 5 **..* ..*** .*.*. *.*.* Example Output 2: 46..3 ..732 .6.4. 5.4.3 Now solve the problem by providing the code.
# n=int(input()) # n,k=map(int,input().split()) # arr=list(map(int,input().split())) #ls=list(map(int,input().split())) #for i in range(m): # for _ in range(int(input())): from collections import Counter #from fractions import Fraction #n=int(input()) #arr=list(map(int,input().split())) #ls = [list(map(int, input().split())) for i in range(n)] from math import log2 #for _ in range(int(input())): #n, m = map(int, input().split()) # for _ in range(int(input())): from math import gcd #n=int(input()) # for i in range(m): # for i in range(int(input())): # n,k= map(int, input().split()) # arr=list(map(int,input().split())) # n=sys.stdin.readline() # n=int(n) # n,k= map(int, input().split()) # arr=list(map(int,input().split())) # n=int(inaput()) #for _ in range(int(input())): #arr=list(map(int,input().split())) from collections import deque dx=[-1,0,0,1] dy=[0,-1,1,0] def bfs(x,y): global total total+=1 q=deque([(x,y)]) v[x][y]=True h[x][y]=comp #q.append() while q: x,y=q.pop() for i in range(4): nx=x+dx[i] ny=y+dy[i] #print("nx,y",nx, ny) if (nx>=0 and nx<n) and (ny>=0 and ny<m) and (v[nx][ny]==False) and (g[nx][ny]=="."): q.appendleft((nx,ny)) total+=1 v[nx][ny]=True h[nx][ny]=comp #global g,h,r,comp,total n, m = map(int, input().split()) h=[[-1 for i in range(m)] for j in range(n)] g=[] v=[[False for i in range(m)]for j in range(n)] for i in range(n): g.append(list(input())) component=[] for i in range(n): for j in range(m): if v[i][j]==False and g[i][j]==".":############ comp=len(component) #global total total=0 bfs(i,j) component.append(total) #print(component) for x in range(n): for y in range(m): if g[x][y] == "*": ans = 0 s = set() for k in range(4): nx = x + dx[k] ny = y + dy[k] if nx >= 0 and nx < n and ny >= 0 and ny < m and g[nx][ny] == ".": s.add(h[nx][ny]) for itm in s: ans += component[itm] ans += 1 ans %= 10 g[x][y] = str(ans) for i in range(n): print("".join(g[i]))
vfc_82437
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\n*.*\n.*.\n*.*", "output": "3.3\n.5.\n3.3", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 5\n**..*\n..***\n.*.*.\n*.*.*", "output": "46..3\n..732\n.6.4.\n5.4.3", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n*", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n.", "output": ".", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
361
Solve the following coding problem using the programming language python: Levko loves tables that consist of *n* rows and *n* columns very much. He especially loves beautiful tables. A table is beautiful to Levko if the sum of elements in each row and column of the table equals *k*. Unfortunately, he doesn't know any such table. Your task is to help him to find at least one of them. The input will be provided via standard input and looks as follows: The single line contains two integers, *n* and *k* (1<=≤<=*n*<=≤<=100, 1<=≤<=*k*<=≤<=1000). You should write the solution as standard output as follows: Print any beautiful table. Levko doesn't like too big numbers, so all elements of the table mustn't exceed 1000 in their absolute value. If there are multiple suitable tables, you are allowed to print any of them. Here are example inputs and outputs for the problem: Example Input 1: 2 4 Example Output 1: 1 3 3 1 Example Input 2: 4 7 Example Output 2: 2 1 0 4 4 0 2 1 1 3 3 0 0 3 2 2 Now solve the problem by providing the code.
n, k = map(int, input().split()); a = list(range(n)); for i in range (0, n): a[i] = list(range(n)); for j in range (0, n): if j == i: a[i][j] = k; else: a[i][j] = 0; print(*a[i], sep=" ")
vfc_82445
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 4", "output": "4 0 \n0 4 ", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
582
Solve the following coding problem using the programming language python: The GCD table *G* of size *n*<=×<=*n* for an array of positive integers *a* of length *n* is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers *x* and *y* is the greatest integer that is divisor of both *x* and *y*, it is denoted as . For example, for array *a*<==<={4,<=3,<=6,<=2} of length 4 the GCD table will look as follows: Given all the numbers of the GCD table *G*, restore array *a*. The input will be provided via standard input and looks as follows: The first line contains number *n* (1<=≤<=*n*<=≤<=500) — the length of array *a*. The second line contains *n*2 space-separated numbers — the elements of the GCD table of *G* for array *a*. All the numbers in the table are positive integers, not exceeding 109. Note that the elements are given in an arbitrary order. It is guaranteed that the set of the input data corresponds to some array *a*. You should write the solution as standard output as follows: In the single line print *n* positive integers — the elements of array *a*. If there are multiple possible solutions, you are allowed to print any of them. Here are example inputs and outputs for the problem: Example Input 1: 4 2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2 Example Output 1: 4 3 6 2 Example Input 2: 1 42 Example Output 2: 42 Example Input 3: 2 1 1 1 1 Example Output 3: 1 1 Now solve the problem by providing the code.
import math as ma import sys input=sys.stdin.readline def fu(b): for i in b: if b[i]!=0: return i return -1 def gcd(a,b): if a%b==0: return b else: return gcd(b,a%b) n=int(input()) a=list(map(int,input().split())) a.sort(reverse=True) b={} for i in range(n*n): if a[i] in b.keys(): b[a[i]]+=1 else: b[a[i]]=1 c=[] for i in b: c.append(i) b[i]-=1 break while 1>0: if len(c)<n: a=fu(b) if a==-1: break else: b[a]-=1 for i in range(len(c)): b[gcd(a,c[i])]-=2 c.append(a) else: break print(*c)
vfc_82449
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n2 1 2 3 4 3 2 6 1 1 2 2 1 2 3 2", "output": "2 3 4 6 ", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
102
Solve the following coding problem using the programming language python: Having watched the last Harry Potter film, little Gerald also decided to practice magic. He found in his father's magical book a spell that turns any number in the sum of its digits. At the moment Gerald learned that, he came across a number *n*. How many times can Gerald put a spell on it until the number becomes one-digit? The input will be provided via standard input and looks as follows: The first line contains the only integer *n* (0<=≤<=*n*<=≤<=10100000). It is guaranteed that *n* doesn't contain any leading zeroes. You should write the solution as standard output as follows: Print the number of times a number can be replaced by the sum of its digits until it only contains one digit. Here are example inputs and outputs for the problem: Example Input 1: 0 Example Output 1: 0 Example Input 2: 10 Example Output 2: 1 Example Input 3: 991 Example Output 3: 3 Now solve the problem by providing the code.
s=input() c=0 while(len(s)>1): sum=0 for i in s: sum+=int(i) s=str(sum) c+=1 print(c)
vfc_82453
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "0", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "10", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "991", "output": "3", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
764
Solve the following coding problem using the programming language python: Comrade Dujikov is busy choosing artists for Timofey's birthday and is recieving calls from Taymyr from Ilia-alpinist. Ilia-alpinist calls every *n* minutes, i.e. in minutes *n*, 2*n*, 3*n* and so on. Artists come to the comrade every *m* minutes, i.e. in minutes *m*, 2*m*, 3*m* and so on. The day is *z* minutes long, i.e. the day consists of minutes 1,<=2,<=...,<=*z*. How many artists should be killed so that there are no artists in the room when Ilia calls? Consider that a call and a talk with an artist take exactly one minute. The input will be provided via standard input and looks as follows: The only string contains three integers — *n*, *m* and *z* (1<=≤<=*n*,<=*m*,<=*z*<=≤<=104). You should write the solution as standard output as follows: Print single integer — the minimum number of artists that should be killed so that there are no artists in the room when Ilia calls. Here are example inputs and outputs for the problem: Example Input 1: 1 1 10 Example Output 1: 10 Example Input 2: 1 2 5 Example Output 2: 2 Example Input 3: 2 3 9 Example Output 3: 1 Now solve the problem by providing the code.
n, m, z = (int(i) for i in input().split()) calls = set(i for i in range(0, z + 1, n)) art = set(i for i in range(0, z + 1, m)) print(len(calls & art) - 1)
vfc_82457
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 1 10", "output": "10", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
96
Solve the following coding problem using the programming language python: Petya loves football very much. One day, as he was watching a football match, he was writing the players' current positions on a piece of paper. To simplify the situation he depicted it as a string consisting of zeroes and ones. A zero corresponds to players of one team; a one corresponds to players of another team. If there are at least 7 players of some team standing one after another, then the situation is considered dangerous. For example, the situation 00100110111111101 is dangerous and 11110111011101 is not. You are given the current situation. Determine whether it is dangerous or not. The input will be provided via standard input and looks as follows: The first input line contains a non-empty string consisting of characters "0" and "1", which represents players. The length of the string does not exceed 100 characters. There's at least one player from each team present on the field. You should write the solution as standard output as follows: Print "YES" if the situation is dangerous. Otherwise, print "NO". Here are example inputs and outputs for the problem: Example Input 1: 001001 Example Output 1: NO Example Input 2: 1000000001 Example Output 2: YES Now solve the problem by providing the code.
line = input() ans = "NO" for i in range(len(line) - 6): if line[i: i + 7].count('0') == 7 or line[i: i + 7].count('1') == 7: ans = "YES" break print(ans)
vfc_82461
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "001001", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000000001", "output": "YES", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
560
Solve the following coding problem using the programming language python: A magic island Geraldion, where Gerald lives, has its own currency system. It uses banknotes of several values. But the problem is, the system is not perfect and sometimes it happens that Geraldionians cannot express a certain sum of money with any set of banknotes. Of course, they can use any number of banknotes of each value. Such sum is called unfortunate. Gerald wondered: what is the minimum unfortunate sum? The input will be provided via standard input and looks as follows: The first line contains number *n* (1<=≤<=*n*<=≤<=1000) — the number of values of the banknotes that used in Geraldion. The second line contains *n* distinct space-separated numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=106) — the values of the banknotes. You should write the solution as standard output as follows: Print a single line — the minimum unfortunate sum. If there are no unfortunate sums, print <=-<=1. Here are example inputs and outputs for the problem: Example Input 1: 5 1 2 3 4 5 Example Output 1: -1 Now solve the problem by providing the code.
n = int(input()) num = map(int, input().rstrip().split()) if 1 in num: print(-1) else: print(1)
vfc_82465
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 2 3 4 5", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n2", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n371054 506438 397130 1 766759 208409 769264 549213 641270 771837", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n635370 154890 909382 220996 276501 716105 538714 140162 171960 271264", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "50\n110876 835020 859879 999908 712969 788264 287153 921820 330355 499311 209594 484829 296329 940051 174081 931503 1 780512 390075 97866 124255 950067 697612 244256 782385 789882 37608 82153 399889 598867 416717 377988 535636 511221 792568 683271 131077 290194 496712 330720 587436 563481 645817 942562 654093 980561 382937 48293 582608 116156", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "50\n474421 421097 217233 156339 27075 733996 281778 863492 184707 956857 288561 70997 393786 337382 663642 131184 637 273801 799870 295017 392338 842567 161819 297705 102013 930684 375703 838048 154915 138503 629056 256591 893619 19263 787927 684541 320265 841090 421423 490879 394582 493952 619247 633202 612928 50907 276653 407819 489945 153173", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
186
Solve the following coding problem using the programming language python: Some dwarves that are finishing the StUDY (State University for Dwarven Youngsters) Bachelor courses, have been told "no genome, no degree". That means that all dwarves should write a thesis on genome. Dwarven genome is far from simple. It is represented by a string that consists of lowercase Latin letters. Dwarf Misha has already chosen the subject for his thesis: determining by two dwarven genomes, whether they belong to the same race. Two dwarves belong to the same race if we can swap two characters in the first dwarf's genome and get the second dwarf's genome as a result. Help Dwarf Misha and find out whether two gnomes belong to the same race or not. The input will be provided via standard input and looks as follows: The first line contains the first dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The second line contains the second dwarf's genome: a non-empty string, consisting of lowercase Latin letters. The number of letters in each genome doesn't exceed 105. It is guaranteed that the strings that correspond to the genomes are different. The given genomes may have different length. You should write the solution as standard output as follows: Print "YES", if the dwarves belong to the same race. Otherwise, print "NO". Here are example inputs and outputs for the problem: Example Input 1: ab ba Example Output 1: YES Example Input 2: aa ab Example Output 2: NO Now solve the problem by providing the code.
a = input() b = input() d = 0 f = [] if not len(a) == len(b): print('NO') else: for i in range(len(a)): if not a[i] == b[i]: d += 1 if d == 3: break f.append([a[i], b[i]]) if d == 2: print('YES' if f[0][0] == f[1][1] and f[0][1] == f[1][0] else 'NO') else: print('NO')
vfc_82469
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "ab\nba", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "aa\nab", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "a\nza", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "vvea\nvvae", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "rtfabanpc\natfabrnpc", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "mt\ntm", "output": "YES", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
358
Solve the following coding problem using the programming language python: Seryozha has a very changeable character. This time he refused to leave the room to Dima and his girlfriend (her hame is Inna, by the way). However, the two lovebirds can always find a way to communicate. Today they are writing text messages to each other. Dima and Inna are using a secret code in their text messages. When Dima wants to send Inna some sentence, he writes out all words, inserting a heart before each word and after the last word. A heart is a sequence of two characters: the "less" characters (&lt;) and the digit three (3). After applying the code, a test message looks like that: &lt;3*word*1&lt;3*word*2&lt;3 ... *word**n*&lt;3. Encoding doesn't end here. Then Dima inserts a random number of small English characters, digits, signs "more" and "less" into any places of the message. Inna knows Dima perfectly well, so she knows what phrase Dima is going to send her beforehand. Inna has just got a text message. Help her find out if Dima encoded the message correctly. In other words, find out if a text message could have been received by encoding in the manner that is described above. The input will be provided via standard input and looks as follows: The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of words in Dima's message. Next *n* lines contain non-empty words, one word per line. The words only consist of small English letters. The total length of all words doesn't exceed 105. The last line contains non-empty text message that Inna has got. The number of characters in the text message doesn't exceed 105. A text message can contain only small English letters, digits and signs more and less. You should write the solution as standard output as follows: In a single line, print "yes" (without the quotes), if Dima decoded the text message correctly, and "no" (without the quotes) otherwise. Here are example inputs and outputs for the problem: Example Input 1: 3 i love you &lt;3i&lt;3love&lt;23you&lt;3 Example Output 1: yes Example Input 2: 7 i am not main in the family &lt;3i&lt;&gt;3am&lt;3the&lt;3&lt;main&lt;3in&lt;3the&lt;3&gt;&lt;3family&lt;3 Example Output 2: no Now solve the problem by providing the code.
s = [] for i in range(int(input())): s.append(input()) s = "<3" + '<3'.join(s) + "<3" cur = 0 t = input() for i in t: if i == s[cur]: cur += 1 if cur == len(s): break print('yes' if cur == len(s) else 'no')
vfc_82473
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\ni\nlove\nyou\n<3i<3love<23you<3", "output": "yes", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\ni\nam\nnot\nmain\nin\nthe\nfamily\n<3i<>3am<3the<3<main<3in<3the<3><3family<3", "output": "no", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\ni\nlove\nyou\n<3i<3lo<3ve<3y<<<<<<<ou3<3", "output": "yes", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\na\nb\nc\nd\n<3a<3b<3c<3d", "output": "no", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
250
Solve the following coding problem using the programming language python: Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as *n* days. Right now his task is to make a series of reports about the company's performance for the last *n* days. We know that the main information in a day report is value *a**i*, the company's profit on the *i*-th day. If *a**i* is negative, then the company suffered losses on the *i*-th day. Polycarpus should sort the daily reports into folders. Each folder should include data on the company's performance for several consecutive days. Of course, the information on each of the *n* days should be exactly in one folder. Thus, Polycarpus puts information on the first few days in the first folder. The information on the several following days goes to the second folder, and so on. It is known that the boss reads one daily report folder per day. If one folder has three or more reports for the days in which the company suffered losses (*a**i*<=&lt;<=0), he loses his temper and his wrath is terrible. Therefore, Polycarpus wants to prepare the folders so that none of them contains information on three or more days with the loss, and the number of folders is minimal. Write a program that, given sequence *a**i*, will print the minimum number of folders. The input will be provided via standard input and looks as follows: The first line contains integer *n* (1<=≤<=*n*<=≤<=100), *n* is the number of days. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (|*a**i*|<=≤<=100), where *a**i* means the company profit on the *i*-th day. It is possible that the company has no days with the negative *a**i*. You should write the solution as standard output as follows: Print an integer *k* — the required minimum number of folders. In the second line print a sequence of integers *b*1, *b*2, ..., *b**k*, where *b**j* is the number of day reports in the *j*-th folder. If there are multiple ways to sort the reports into *k* days, print any of them. Here are example inputs and outputs for the problem: Example Input 1: 11 1 2 3 -4 -5 -6 5 -5 -6 -7 6 Example Output 1: 3 5 3 3 Example Input 2: 5 0 -1 100 -1 0 Example Output 2: 1 5 Now solve the problem by providing the code.
days = int(input()) sequence = input().split() folder = 1 bad_rep = 0 rep = 0 ans = "" for profit in sequence: rep += 1 if int(profit) < 0: bad_rep += 1 if bad_rep == 3: folder += 1 ans = ans + str(rep - 1) + " " bad_rep = 1 rep = 1 ans += str(rep) print(folder) print(ans)
vfc_82477
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "11\n1 2 3 -4 -5 -6 5 -5 -6 -7 6", "output": "3\n5 3 3 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n0 -1 100 -1 0", "output": "1\n5 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n0", "output": "1\n1 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n-1", "output": "1\n1 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n0 0", "output": "1\n2 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n-2 2", "output": "1\n2 ", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
394
Solve the following coding problem using the programming language python: When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our teachers decided to teach us arithmetics from the start. And what is the best way to teach students add and subtract? — That's right, using counting sticks! An here's our new task: An expression of counting sticks is an expression of type: Sign + consists of two crossed sticks: one vertical and one horizontal. Sign = consists of two horizontal sticks. The expression is arithmetically correct if *A*<=+<=*B*<==<=*C*. We've got an expression that looks like *A*<=+<=*B*<==<=*C* given by counting sticks. Our task is to shift at most one stick (or we can shift nothing) so that the expression became arithmetically correct. Note that we cannot remove the sticks from the expression, also we cannot shift the sticks from the signs + and =. We really aren't fabulous at arithmetics. Can you help us? The input will be provided via standard input and looks as follows: The single line contains the initial expression. It is guaranteed that the expression looks like *A*<=+<=*B*<==<=*C*, where 1<=≤<=*A*,<=*B*,<=*C*<=≤<=100. You should write the solution as standard output as follows: If there isn't a way to shift the stick so the expression becomes correct, print on a single line "Impossible" (without the quotes). If there is a way, print the resulting expression. Follow the format of the output from the test samples. Don't print extra space characters. If there are multiple correct answers, print any of them. For clarifications, you are recommended to see the test samples. Here are example inputs and outputs for the problem: Example Input 1: ||+|=||||| Example Output 1: |||+|=|||| Example Input 2: |||||+||=|| Example Output 2: Impossible Example Input 3: |+|=|||||| Example Output 3: Impossible Example Input 4: ||||+||=|||||| Example Output 4: ||||+||=|||||| Now solve the problem by providing the code.
n = input() lth = len(n) a = n.find('+') b = n.find('=') - a - 1 c = len(n) - n.find('=') - 1 if a + b == c: print(n) elif a + b == c - 2: print('|',n[:lth-1],sep="") elif a + b == c + 2: if a >= 2: print(n[1:],'|',sep="") else: print(n[:a+1],n[a+2:],'|',sep="") else: print('Impossible')
vfc_82481
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "||+|=|||||", "output": "|||+|=||||", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
912
Solve the following coding problem using the programming language python: During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals. Grisha needs to obtain some yellow, green and blue balls. It's known that to produce a yellow ball one needs two yellow crystals, green — one yellow and one blue, and for a blue ball, three blue crystals are enough. Right now there are *A* yellow and *B* blue crystals in Grisha's disposal. Find out how many additional crystals he should acquire in order to produce the required number of balls. The input will be provided via standard input and looks as follows: The first line features two integers *A* and *B* (0<=≤<=*A*,<=*B*<=≤<=109), denoting the number of yellow and blue crystals respectively at Grisha's disposal. The next line contains three integers *x*, *y* and *z* (0<=≤<=*x*,<=*y*,<=*z*<=≤<=109) — the respective amounts of yellow, green and blue balls to be obtained. You should write the solution as standard output as follows: Print a single integer — the minimum number of crystals that Grisha should acquire in addition. Here are example inputs and outputs for the problem: Example Input 1: 4 3 2 1 1 Example Output 1: 2 Example Input 2: 3 9 1 1 3 Example Output 2: 1 Example Input 3: 12345678 87654321 43043751 1000000000 53798715 Example Output 3: 2147483648 Now solve the problem by providing the code.
a, b = map(int, input().split()) x, y, z = map(int, input().split()) need_yellow = x * 2 + y need_blue = y + z * 3 yellow_diff = max(0, need_yellow - a) blue_diff = max(0, need_blue - b) total_diff = yellow_diff + blue_diff print(total_diff)
vfc_82485
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 3\n2 1 1", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 9\n1 1 3", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "12345678 87654321\n43043751 1000000000 53798715", "output": "2147483648", "type": "stdin_stdout" }, { "fn_name": null, "input": "12 12\n3 5 2", "output": "0", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
501
Solve the following coding problem using the programming language python: Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point. Misha has a list of handle change requests. After completing the requests he wants to understand the relation between the original and the new handles of the users. Help him to do that. The input will be provided via standard input and looks as follows: The first line contains integer *q* (1<=≤<=*q*<=≤<=1000), the number of handle change requests. Next *q* lines contain the descriptions of the requests, one per line. Each query consists of two non-empty strings *old* and *new*, separated by a space. The strings consist of lowercase and uppercase Latin letters and digits. Strings *old* and *new* are distinct. The lengths of the strings do not exceed 20. The requests are given chronologically. In other words, by the moment of a query there is a single person with handle *old*, and handle *new* is not used and has not been used by anyone. You should write the solution as standard output as follows: In the first line output the integer *n* — the number of users that changed their handles at least once. In the next *n* lines print the mapping between the old and the new handles of the users. Each of them must contain two strings, *old* and *new*, separated by a space, meaning that before the user had handle *old*, and after all the requests are completed, his handle is *new*. You may output lines in any order. Each user who changes the handle must occur exactly once in this description. Here are example inputs and outputs for the problem: Example Input 1: 5 Misha ILoveCodeforces Vasya Petrov Petrov VasyaPetrov123 ILoveCodeforces MikeMirzayanov Petya Ivanov Example Output 1: 3 Petya Ivanov Misha MikeMirzayanov Vasya VasyaPetrov123 Now solve the problem by providing the code.
n=int(input()) a=[] for i in range(n): b=input().split() if b[0] in a: ind=a.index(b[0]) a.insert(ind,b[1]) a.pop(ind+1) else: a.append(b[0]) a.append(b[1]) print(len(a)//2) for i in range(len(a)//2): print(*a[:2]) a=a[2:]
vfc_82489
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\nMisha ILoveCodeforces\nVasya Petrov\nPetrov VasyaPetrov123\nILoveCodeforces MikeMirzayanov\nPetya Ivanov", "output": "3\nPetya Ivanov\nMisha MikeMirzayanov\nVasya VasyaPetrov123", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\nMisha Vasya", "output": "1\nMisha Vasya", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\na b\nb c\nc d\nd e\ne f\nf g\ng h\nh i\ni j\nj k", "output": "1\na k", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n123abc abc123\nabc123 a1b2c3\na1b2c3 1A2B3C\n1 2\n2 Misha", "output": "2\n123abc 1A2B3C\n1 Misha", "type": "stdin_stdout" }, { "fn_name": null, "input": "8\nM F\nS D\n1 2\nF G\n2 R\nD Q\nQ W\nW e", "output": "3\nM G\n1 R\nS e", "type": "stdin_stdout" } ] }