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
1005
Solve the following coding problem using the programming language python: You are given two strings $s$ and $t$. In a single move, you can choose any of two strings and delete the first (that is, the leftmost) character. After a move, the length of the string decreases by $1$. You can't choose a string if it is empty. For example: - by applying a move to the string "where", the result is the string "here", - by applying a move to the string "a", the result is an empty string "". You are required to make two given strings equal using the fewest number of moves. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the initial strings. Write a program that finds the minimum number of moves to make two given strings $s$ and $t$ equal. The input will be provided via standard input and looks as follows: The first line of the input contains $s$. In the second line of the input contains $t$. Both strings consist only of lowercase Latin letters. The number of letters in each string is between 1 and $2\cdot10^5$, inclusive. You should write the solution as standard output as follows: Output the fewest number of moves required. It is possible that, in the end, both strings will be equal to the empty string, and so, are equal to each other. In this case, the answer is obviously the sum of the lengths of the given strings. Here are example inputs and outputs for the problem: Example Input 1: test west Example Output 1: 2 Example Input 2: codeforces yes Example Output 2: 9 Example Input 3: test yes Example Output 3: 7 Example Input 4: b ab Example Output 4: 1 Now solve the problem by providing the code.
string1 = input() string2 = input() same = 0 minn = min(len(string1),len(string2)) for i in range(minn): if string1[-1-i]==string2[-1-i]: same += 2 else: break print((len(string1)+len(string2))-same)
vfc_82921
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "test\nwest", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "codeforces\nyes", "output": "9", "type": "stdin_stdout" }, { "fn_name": null, "input": "test\nyes", "output": "7", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
144
Solve the following coding problem using the programming language python: A Ministry for Defense sent a general to inspect the Super Secret Military Squad under the command of the Colonel SuperDuper. Having learned the news, the colonel ordered to all *n* squad soldiers to line up on the parade ground. By the military charter the soldiers should stand in the order of non-increasing of their height. But as there's virtually no time to do that, the soldiers lined up in the arbitrary order. However, the general is rather short-sighted and he thinks that the soldiers lined up correctly if the first soldier in the line has the maximum height and the last soldier has the minimum height. Please note that the way other solders are positioned does not matter, including the case when there are several soldiers whose height is maximum or minimum. Only the heights of the first and the last soldier are important. For example, the general considers the sequence of heights (4, 3, 4, 2, 1, 1) correct and the sequence (4, 3, 1, 2, 2) wrong. Within one second the colonel can swap any two neighboring soldiers. Help him count the minimum time needed to form a line-up which the general will consider correct. The input will be provided via standard input and looks as follows: The first input line contains the only integer *n* (2<=≀<=*n*<=≀<=100) which represents the number of soldiers in the line. The second line contains integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=100) the values of the soldiers' heights in the order of soldiers' heights' increasing in the order from the beginning of the line to its end. The numbers are space-separated. Numbers *a*1,<=*a*2,<=...,<=*a**n* are not necessarily different. You should write the solution as standard output as follows: Print the only integer β€” the minimum number of seconds the colonel will need to form a line-up the general will like. Here are example inputs and outputs for the problem: Example Input 1: 4 33 44 11 22 Example Output 1: 2 Example Input 2: 7 10 10 58 31 63 40 76 Example Output 2: 10 Now solve the problem by providing the code.
n = int(input()) lst = list(map(int,input().split())) a=0 b=100 max_ind=0 min_ind=0 for i in range(n): if lst[i]>a: a=lst[i] max_ind = i if lst[i]<=b: b = lst[i] min_ind = i if max_ind<min_ind: print(max_ind+(n-min_ind)-1) else: print(max_ind+((n-min_ind)-2))
vfc_82925
{ "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\n33 44 11 22", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n10 10 58 31 63 40 76", "output": "10", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n88 89", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n100 95 100 100 88", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n48 48 48 48 45 45 45", "output": "0", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
741
Solve the following coding problem using the programming language python: Just to remind, girls in Arpa's land are really nice. Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight *w**i* and some beauty *b**i*. Also each Hos may have some friends. Hoses are divided in some friendship groups. Two Hoses *x* and *y* are in the same friendship group if and only if there is a sequence of Hoses *a*1,<=*a*2,<=...,<=*a**k* such that *a**i* and *a**i*<=+<=1 are friends for each 1<=≀<=*i*<=&lt;<=*k*, and *a*1<==<=*x* and *a**k*<==<=*y*. Arpa allowed to use the amphitheater of palace to Mehrdad for this party. Arpa's amphitheater can hold at most *w* weight on it. Mehrdad is so greedy that he wants to invite some Hoses such that sum of their weights is not greater than *w* and sum of their beauties is as large as possible. Along with that, from each friendship group he can either invite all Hoses, or no more than one. Otherwise, some Hoses will be hurt. Find for Mehrdad the maximum possible total beauty of Hoses he can invite so that no one gets hurt and the total weight doesn't exceed *w*. The input will be provided via standard input and looks as follows: The first line contains integers *n*, *m* and *w* (1<=<=≀<=<=*n*<=<=≀<=<=1000, , 1<=≀<=*w*<=≀<=1000)Β β€” the number of Hoses, the number of pair of friends and the maximum total weight of those who are invited. The second line contains *n* integers *w*1,<=*w*2,<=...,<=*w**n* (1<=≀<=*w**i*<=≀<=1000)Β β€” the weights of the Hoses. The third line contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (1<=≀<=*b**i*<=≀<=106)Β β€” the beauties of the Hoses. The next *m* lines contain pairs of friends, the *i*-th of them contains two integers *x**i* and *y**i* (1<=≀<=*x**i*,<=*y**i*<=≀<=*n*, *x**i*<=β‰ <=*y**i*), meaning that Hoses *x**i* and *y**i* are friends. Note that friendship is bidirectional. All pairs (*x**i*,<=*y**i*) are distinct. You should write the solution as standard output as follows: Print the maximum possible total beauty of Hoses Mehrdad can invite so that no one gets hurt and the total weight doesn't exceed *w*. Here are example inputs and outputs for the problem: Example Input 1: 3 1 5 3 2 5 2 4 2 1 2 Example Output 1: 6 Example Input 2: 4 2 11 2 4 6 6 6 4 2 1 1 2 2 3 Example Output 2: 7 Now solve the problem by providing the code.
def g(x): if x == t[x]: return x t[x] = g(t[x]) return t[x] f = lambda: map(int, input().split()) hoses, pairOfFriends, weight = f() weightsAndBeauties = [(0, 0)] + list(zip(f(), f())) t = list(range(hoses + 1)) for i in range(pairOfFriends): f1, f2 = f() f1, f2 = g(f1), g(f2) if f1 != f2: t[f2] = f1 p = [[] for j in range(hoses + 1)] for i in range(1, hoses + 1): p[g(i)].append(i) beauties = [1] + [0] * weight for q in p: if len(q) > 1: t = [weightsAndBeauties[i] for i in q] t.append((sum(f1[0] for f1 in t), sum(f1[1] for f1 in t))) t.sort(key=lambda f1: f1[0]) for j in range(weight, -1, -1): if beauties[j]: for w, b in t: if j + w > weight: break else: beauties[j + w] = max(beauties[j + w], beauties[j] + b) elif len(q) == 1: w, b = weightsAndBeauties[q[0]] for j in range(weight - w, -1, -1): if beauties[j]: beauties[j + w] = max(beauties[j + w], beauties[j] + b) maxBeauty = max(beauties) - 1 print(maxBeauty)
vfc_82929
{ "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 5\n3 2 5\n2 4 2\n1 2", "output": "6", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
710
Solve the following coding problem using the programming language python: The only king stands on the standard chess board. You are given his position in format "cd", where *c* is the column from 'a' to 'h' and *d* is the row from '1' to '8'. Find the number of moves permitted for the king. Check the king's moves here [https://en.wikipedia.org/wiki/King_(chess)](https://en.wikipedia.org/wiki/King_(chess)). The input will be provided via standard input and looks as follows: The only line contains the king's position in the format "cd", where 'c' is the column from 'a' to 'h' and 'd' is the row from '1' to '8'. You should write the solution as standard output as follows: Print the only integer *x* β€” the number of moves permitted for the king. Here are example inputs and outputs for the problem: Example Input 1: e4 Example Output 1: 8 Now solve the problem by providing the code.
from sys import stdin, stdout def read(): return stdin.readline().rstrip() def read_int(): return int(read()) def read_ints(): return list(map(int, read().split())) def solve(): a=read() c=0 if a[0]=='a' or a[0]=='h': c+=1 if a[1]=='1' or a[1]=='8': c+=1 if c==0: print(8) elif c==1: print(5) else: print(3) solve()
vfc_82933
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "3000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "e4", "output": "8", "type": "stdin_stdout" }, { "fn_name": null, "input": "a1", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "h8", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "a4", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "g7", "output": "8", "type": "stdin_stdout" }, { "fn_name": null, "input": "e1", "output": "5", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
807
Solve the following coding problem using the programming language python: Is it rated? Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it. Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before and after the round is known. It's known that if at least one participant's rating has changed, then the round was rated for sure. It's also known that if the round was rated and a participant with lower rating took a better place in the standings than a participant with higher rating, then at least one round participant's rating has changed. In this problem, you should not make any other assumptions about the rating system. Determine if the current round is rated, unrated, or it's impossible to determine whether it is rated of not. The input will be provided via standard input and looks as follows: The first line contains a single integer *n* (2<=≀<=*n*<=≀<=1000)Β β€” the number of round participants. Each of the next *n* lines contains two integers *a**i* and *b**i* (1<=≀<=*a**i*,<=*b**i*<=≀<=4126)Β β€” the rating of the *i*-th participant before and after the round, respectively. The participants are listed in order from the top to the bottom of the standings. You should write the solution as standard output as follows: If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe". Here are example inputs and outputs for the problem: Example Input 1: 6 3060 3060 2194 2194 2876 2903 2624 2624 3007 2991 2884 2884 Example Output 1: rated Example Input 2: 4 1500 1500 1300 1300 1200 1200 1400 1400 Example Output 2: unrated Example Input 3: 5 3123 3123 2777 2777 2246 2246 2246 2246 1699 1699 Example Output 3: maybe Now solve the problem by providing the code.
t = int(input()) left = [] right = [] for i in range(t): x , y = input().split() x , y = int(x) , int(y) left.append(x) right.append(y) if left != right :print('rated') elif left == right and sorted(left , reverse=True) != left and sorted(right , reverse=True) != right:print('unrated') else:print('maybe')
vfc_82937
{ "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\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884", "output": "rated", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400", "output": "unrated", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699", "output": "maybe", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 1\n1 1", "output": "maybe", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
379
Solve the following coding problem using the programming language python: Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles. Vasily has *a* candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make *b* went out candles into a new candle. As a result, this new candle can be used like any other new candle. Now Vasily wonders: for how many hours can his candles light up the room if he acts optimally well? Help him find this number. The input will be provided via standard input and looks as follows: The single line contains two integers, *a* and *b* (1<=≀<=*a*<=≀<=1000;Β 2<=≀<=*b*<=≀<=1000). You should write the solution as standard output as follows: Print a single integer β€” the number of hours Vasily can light up the room for. Here are example inputs and outputs for the problem: Example Input 1: 4 2 Example Output 1: 7 Example Input 2: 6 3 Example Output 2: 8 Now solve the problem by providing the code.
a,b=map(int,input().split()) c=int(a-1)/(b-1) print(int(a+c))
vfc_82941
{ "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 2", "output": "7", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 3", "output": "8", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000 1000", "output": "1001", "type": "stdin_stdout" }, { "fn_name": null, "input": "123 5", "output": "153", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
593
Solve the following coding problem using the programming language python: The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of *n* lines defined by the equations *y*<==<=*k**i*Β·*x*<=+<=*b**i*. It was necessary to determine whether there is at least one point of intersection of two of these lines, that lays strictly inside the strip between *x*1<=&lt;<=*x*2. In other words, is it true that there are 1<=≀<=*i*<=&lt;<=*j*<=≀<=*n* and *x*',<=*y*', such that: - *y*'<==<=*k**i*<=*<=*x*'<=+<=*b**i*, that is, point (*x*',<=*y*') belongs to the line number *i*; - *y*'<==<=*k**j*<=*<=*x*'<=+<=*b**j*, that is, point (*x*',<=*y*') belongs to the line number *j*; - *x*1<=&lt;<=*x*'<=&lt;<=*x*2, that is, point (*x*',<=*y*') lies inside the strip bounded by *x*1<=&lt;<=*x*2. You can't leave Anton in trouble, can you? Write a program that solves the given task. The input will be provided via standard input and looks as follows: The first line of the input contains an integer *n* (2<=≀<=*n*<=≀<=100<=000)Β β€” the number of lines in the task given to Anton. The second line contains integers *x*1 and *x*2 (<=-<=1<=000<=000<=≀<=*x*1<=&lt;<=*x*2<=≀<=1<=000<=000) defining the strip inside which you need to find a point of intersection of at least two lines. The following *n* lines contain integers *k**i*, *b**i* (<=-<=1<=000<=000<=≀<=*k**i*,<=*b**i*<=≀<=1<=000<=000)Β β€” the descriptions of the lines. It is guaranteed that all lines are pairwise distinct, that is, for any two *i*<=β‰ <=*j* it is true that either *k**i*<=β‰ <=*k**j*, or *b**i*<=β‰ <=*b**j*. You should write the solution as standard output as follows: Print "Yes" (without quotes), if there is at least one intersection of two distinct lines, located strictly inside the strip. Otherwise print "No" (without quotes). Here are example inputs and outputs for the problem: Example Input 1: 4 1 2 1 2 1 0 0 1 0 2 Example Output 1: NO Example Input 2: 2 1 3 1 0 -1 3 Example Output 2: YES Example Input 3: 2 1 3 1 0 0 2 Example Output 3: YES Example Input 4: 2 1 3 1 0 0 3 Example Output 4: NO Now solve the problem by providing the code.
n = int(input()) a = list() x1, x2 = map(int, input().split()) for i in range(n): k, b = map(int, input().split()) y1 = k * x1 + b y2 = k * x2 + b a.append((y1, y2)) a.sort() fl = 'NO' y1m = a[0][0] y2m = a[0][1] for y1, y2 in a: if y2 < y2m: fl = 'YES' else: y2m = max(y2m, y2) print(fl)
vfc_82945
{ "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 2\n1 2\n1 0\n0 1\n0 2", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 3\n1 0\n-1 3", "output": "YES", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
702
Solve the following coding problem using the programming language python: You are given array consisting of *n* integers. Your task is to find the maximum length of an increasing subarray of the given array. A subarray is the sequence of consecutive elements of the array. Subarray is called increasing if each element of this subarray strictly greater than previous. The input will be provided via standard input and looks as follows: The first line contains single positive integer *n* (1<=≀<=*n*<=≀<=105) β€” the number of integers. The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=109). You should write the solution as standard output as follows: Print the maximum length of an increasing subarray of the given array. Here are example inputs and outputs for the problem: Example Input 1: 5 1 7 2 11 15 Example Output 1: 3 Example Input 2: 6 100 100 100 100 100 100 Example Output 2: 1 Example Input 3: 3 1 2 3 Example Output 3: 3 Now solve the problem by providing the code.
n = int (input()) current = 1 max = 1 x = list(map(int,input().split())) for i in range(n-1): # 0 1 2 3 4 if x[i+1] > x[i]: # 1 7 2 11 15 current = current +1 else: current=1 if max<current:max=current print (max)
vfc_82949
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "3000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 7 2 11 15", "output": "3", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
152
Solve the following coding problem using the programming language python: One day little Vasya found mom's pocket book. The book had *n* names of her friends and unusually enough, each name was exactly *m* letters long. Let's number the names from 1 to *n* in the order in which they are written. As mom wasn't home, Vasya decided to play with names: he chose three integers *i*, *j*, *k* (1<=≀<=*i*<=&lt;<=*j*<=≀<=*n*, 1<=≀<=*k*<=≀<=*m*), then he took names number *i* and *j* and swapped their prefixes of length *k*. For example, if we take names "CBDAD" and "AABRD" and swap their prefixes with the length of 3, the result will be names "AABAD" and "CBDRD". You wonder how many different names Vasya can write instead of name number 1, if Vasya is allowed to perform any number of the described actions. As Vasya performs each action, he chooses numbers *i*, *j*, *k* independently from the previous moves and his choice is based entirely on his will. The sought number can be very large, so you should only find it modulo 1000000007 (109<=+<=7). The input will be provided via standard input and looks as follows: The first input line contains two integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=100) β€” the number of names and the length of each name, correspondingly. Then *n* lines contain names, each name consists of exactly *m* uppercase Latin letters. You should write the solution as standard output as follows: Print the single number β€” the number of different names that could end up in position number 1 in the pocket book after the applying the procedures described above. Print the number modulo 1000000007 (109<=+<=7). Here are example inputs and outputs for the problem: Example Input 1: 2 3 AAB BAA Example Output 1: 4 Example Input 2: 4 5 ABABA BCGDG AAAAA YABSA Example Output 2: 216 Now solve the problem by providing the code.
if __name__ == "__main__": modulo=10**9+7 n,m=map(int,input().split()) names=[] for i in range(n): names.append(input().strip()) res=1 for j in range(m): unique_col_char_count=0 tmp_arr=[] for i in range(n): if names[i][j] not in tmp_arr: unique_col_char_count+=1 tmp_arr.append(names[i][j]) res*=unique_col_char_count res=res%(modulo) print(res)
vfc_82953
{ "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\nAAB\nBAA", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 5\nABABA\nBCGDG\nAAAAA\nYABSA", "output": "216", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\nE", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\nNS\nPD", "output": "4", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
799
Solve the following coding problem using the programming language python: In some game by Playrix it takes *t* minutes for an oven to bake *k* carrot cakes, all cakes are ready at the same moment *t* minutes after they started baking. Arkady needs at least *n* cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady can build one more similar oven to make the process faster, it would take *d* minutes to build the oven. While the new oven is being built, only old one can bake cakes, after the new oven is built, both ovens bake simultaneously. Arkady can't build more than one oven. Determine if it is reasonable to build the second oven, i.e. will it decrease the minimum time needed to get *n* cakes or not. If the time needed with the second oven is the same as with one oven, then it is unreasonable. The input will be provided via standard input and looks as follows: The only line contains four integers *n*, *t*, *k*, *d* (1<=≀<=*n*,<=*t*,<=*k*,<=*d*<=≀<=1<=000)Β β€” the number of cakes needed, the time needed for one oven to bake *k* cakes, the number of cakes baked at the same time, the time needed to build the second oven. You should write the solution as standard output as follows: If it is reasonable to build the second oven, print "YES". Otherwise print "NO". Here are example inputs and outputs for the problem: Example Input 1: 8 6 4 5 Example Output 1: YES Example Input 2: 8 6 4 6 Example Output 2: NO Example Input 3: 10 3 11 4 Example Output 3: NO Example Input 4: 4 2 1 4 Example Output 4: YES Now solve the problem by providing the code.
n, t, k, d = map(int, input().split()) g = int((n + k - 1) / k) o1, o2 = 0, d i = 0 while i < g: if o1 <= o2: o1 += t else: o2 += t i += 1 if max(o1, o2) < g * t: print("YES") else: print("NO")
vfc_82957
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "3000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8 6 4 5", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "8 6 4 6", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 3 11 4", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 2 1 4", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "28 17 16 26", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "60 69 9 438", "output": "NO", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
909
Solve the following coding problem using the programming language python: The preferred way to generate user login in Polygon is to concatenate a prefix of the user's first name and a prefix of their last name, in that order. Each prefix must be non-empty, and any of the prefixes can be the full name. Typically there are multiple possible logins for each person. You are given the first and the last name of a user. Return the alphabetically earliest login they can get (regardless of other potential Polygon users). As a reminder, a prefix of a string *s* is its substring which occurs at the beginning of *s*: "a", "ab", "abc" etc. are prefixes of string "{abcdef}" but "b" and 'bc" are not. A string *a* is alphabetically earlier than a string *b*, if *a* is a prefix of *b*, or *a* and *b* coincide up to some position, and then *a* has a letter that is alphabetically earlier than the corresponding letter in *b*: "a" and "ab" are alphabetically earlier than "ac" but "b" and "ba" are alphabetically later than "ac". The input will be provided via standard input and looks as follows: The input consists of a single line containing two space-separated strings: the first and the last names. Each character of each string is a lowercase English letter. The length of each string is between 1 and 10, inclusive. You should write the solution as standard output as follows: Output a single stringΒ β€” alphabetically earliest possible login formed from these names. The output should be given in lowercase as well. Here are example inputs and outputs for the problem: Example Input 1: harry potter Example Output 1: hap Example Input 2: tom riddle Example Output 2: tomr Now solve the problem by providing the code.
def getprfx(s): tab = [s[0]] for i in range(1, len(s)): x = tab[i-1] + s[i] tab.append(x) return tab n, m = input().split() a, b = getprfx(n), getprfx(m) mn = a[0] + b[0] for i in a: for j in b: if i+j < mn: mn = i+j print(mn)
vfc_82961
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "harry potter", "output": "hap", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
112
Solve the following coding problem using the programming language python: Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corresponding lowercase letter. Help Petya perform the comparison. The input will be provided via standard input and looks as follows: Each of the first two lines contains a bought string. The strings' lengths range from 1 to 100 inclusive. It is guaranteed that the strings are of the same length and also consist of uppercase and lowercase Latin letters. You should write the solution as standard output as follows: If the first string is less than the second one, print "-1". If the second string is less than the first one, print "1". If the strings are equal, print "0". Note that the letters' case is not taken into consideration when the strings are compared. Here are example inputs and outputs for the problem: Example Input 1: aaaa aaaA Example Output 1: 0 Example Input 2: abs Abz Example Output 2: -1 Example Input 3: abcdefg AbCdEfF Example Output 3: 1 Now solve the problem by providing the code.
s1 = input().lower() s2 = input().lower() if s1==s2: print(0) if s1<s2: print(-1) if s1>s2: print(1)
vfc_82965
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "aaaa\naaaA", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "abs\nAbz", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "abcdefg\nAbCdEfF", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "asadasdasd\nasdwasdawd", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "aslkjlkasdd\nasdlkjdajwi", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "output": "0", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
620
Solve the following coding problem using the programming language python: Professor GukiZ makes a new robot. The robot are in the point with coordinates (*x*1,<=*y*1) and should go to the point (*x*2,<=*y*2). In a single step the robot can change any of its coordinates (maybe both of them) by one (decrease or increase). So the robot can move in one of the 8 directions. Find the minimal number of steps the robot should make to get the finish position. The input will be provided via standard input and looks as follows: The first line contains two integers *x*1,<=*y*1 (<=-<=109<=≀<=*x*1,<=*y*1<=≀<=109) β€” the start position of the robot. The second line contains two integers *x*2,<=*y*2 (<=-<=109<=≀<=*x*2,<=*y*2<=≀<=109) β€” the finish position of the robot. You should write the solution as standard output as follows: Print the only integer *d* β€” the minimal number of steps to get the finish position. Here are example inputs and outputs for the problem: Example Input 1: 0 0 4 5 Example Output 1: 5 Example Input 2: 3 4 6 1 Example Output 2: 3 Now solve the problem by providing the code.
x1, y1 = list(map(int, input().split())) x2, y2 = list(map(int, input().split())) print(max(abs(x1-x2), abs(y1-y2)))
vfc_82969
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "0 0\n4 5", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 4\n6 1", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "0 0\n4 6", "output": "6", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
436
Solve the following coding problem using the programming language python: Om Nom really likes candies and doesn't like spiders as they frequently steal candies. One day Om Nom fancied a walk in a park. Unfortunately, the park has some spiders and Om Nom doesn't want to see them at all. The park can be represented as a rectangular *n*<=Γ—<=*m* field. The park has *k* spiders, each spider at time 0 is at some cell of the field. The spiders move all the time, and each spider always moves in one of the four directions (left, right, down, up). In a unit of time, a spider crawls from his cell to the side-adjacent cell in the corresponding direction. If there is no cell in the given direction, then the spider leaves the park. The spiders do not interfere with each other as they move. Specifically, one cell can have multiple spiders at the same time. Om Nom isn't yet sure where to start his walk from but he definitely wants: - to start walking at time 0 at an upper row cell of the field (it is guaranteed that the cells in this row do not contain any spiders); - to walk by moving down the field towards the lowest row (the walk ends when Om Nom leaves the boundaries of the park). We know that Om Nom moves by jumping. One jump takes one time unit and transports the little monster from his cell to either a side-adjacent cell on the lower row or outside the park boundaries. Each time Om Nom lands in a cell he sees all the spiders that have come to that cell at this moment of time. Om Nom wants to choose the optimal cell to start the walk from. That's why he wonders: for each possible starting cell, how many spiders will he see during the walk if he starts from this cell? Help him and calculate the required value for each possible starting cell. The input will be provided via standard input and looks as follows: The first line contains three integers *n*,<=*m*,<=*k* (2<=≀<=*n*,<=*m*<=≀<=2000;Β 0<=≀<=*k*<=≀<=*m*(*n*<=-<=1)). Each of the next *n* lines contains *m* characters β€” the description of the park. The characters in the *i*-th line describe the *i*-th row of the park field. If the character in the line equals ".", that means that the corresponding cell of the field is empty; otherwise, the character in the line will equal one of the four characters: "L" (meaning that this cell has a spider at time 0, moving left), "R" (a spider moving right), "U" (a spider moving up), "D" (a spider moving down). It is guaranteed that the first row doesn't contain any spiders. It is guaranteed that the description of the field contains no extra characters. It is guaranteed that at time 0 the field contains exactly *k* spiders. You should write the solution as standard output as follows: Print *m* integers: the *j*-th integer must show the number of spiders Om Nom will see if he starts his walk from the *j*-th cell of the first row. The cells in any row of the field are numbered from left to right. Here are example inputs and outputs for the problem: Example Input 1: 3 3 4 ... R.L R.U Example Output 1: 0 2 2 Example Input 2: 2 2 2 .. RL Example Output 2: 1 1 Example Input 3: 2 2 2 .. LR Example Output 3: 0 0 Example Input 4: 3 4 8 .... RRLL UUUU Example Output 4: 1 3 3 1 Example Input 5: 2 2 2 .. UU Example Output 5: 0 0 Now solve the problem by providing the code.
import sys input = sys.stdin.readline n, m, k = map(int, input().split()) g = [input()[:-1] for _ in range(n)] d = [0]*m for i in range(1, n): for j in range(m): if g[i][j] == 'R': if j + i < m: d[j+i] += 1 elif g[i][j] == 'L': if j - i >= 0: d[j-i] += 1 elif g[i][j] == 'U': if i % 2 == 0: d[j] += 1 print(' '.join(map(str, d)))
vfc_82973
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "5000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3 4\n...\nR.L\nR.U", "output": "0 2 2 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2 2\n..\nRL", "output": "1 1 ", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
26
Solve the following coding problem using the programming language python: A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and *n*, inclusive. The input will be provided via standard input and looks as follows: Input contains one integer number *n* (1<=≀<=*n*<=≀<=3000). You should write the solution as standard output as follows: Output the amount of almost prime numbers between 1 and *n*, inclusive. Here are example inputs and outputs for the problem: Example Input 1: 10 Example Output 1: 2 Example Input 2: 21 Example Output 2: 8 Now solve the problem by providing the code.
def count_primes(num): #does not consider num as a prime number count = 0 for divisor in range(2, int(num**0.5)+1): if num % divisor == 0: count += 1 while num % divisor == 0: num /= divisor if num > 1: count += 1 #num itself is prime return count def count_almost_primes(num): count = 0 for num in range(1, num+1): if count_primes(num) == 2: count += 1 return count def main(): num = int(input()) print(count_almost_primes(num)) main()
vfc_82977
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "5000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "21", "output": "8", "type": "stdin_stdout" }, { "fn_name": null, "input": "1", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "2", "output": "0", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
740
Solve the following coding problem using the programming language python: Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the shop: it is possible to buy one copybook for *a* rubles, a pack of two copybooks for *b* rubles, and a pack of three copybooks for *c* rubles. Alyona already has *n* copybooks. What is the minimum amount of rubles she should pay to buy such number of copybooks *k* that *n*<=+<=*k* is divisible by 4? There are infinitely many packs of any type in the shop. Alyona can buy packs of different type in the same purchase. The input will be provided via standard input and looks as follows: The only line contains 4 integers *n*, *a*, *b*, *c* (1<=≀<=*n*,<=*a*,<=*b*,<=*c*<=≀<=109). You should write the solution as standard output as follows: Print the minimum amount of rubles she should pay to buy such number of copybooks *k* that *n*<=+<=*k* is divisible by 4. Here are example inputs and outputs for the problem: Example Input 1: 1 1 3 4 Example Output 1: 3 Example Input 2: 6 2 1 1 Example Output 2: 1 Example Input 3: 4 4 4 4 Example Output 3: 0 Example Input 4: 999999999 1000000000 1000000000 1000000000 Example Output 4: 1000000000 Now solve the problem by providing the code.
n, a, b, c = map(int, input().split()) to_buy = (4 - (n % 4)) % 4 b = min(a * 2, b) c = min(a * 3, a + b, c) # possibilities: if to_buy == 3: print(min(3*a, a+b, c)) elif to_buy == 2: print(min(2*a, b, 2*c)) elif to_buy == 1: print(min(a, b+c, 3*c)) else: print(0)
vfc_82981
{ "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 3 4", "output": "3", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
673
Solve the following coding problem using the programming language python: Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks. Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off. You know that there will be *n* interesting minutes *t*1,<=*t*2,<=...,<=*t**n*. Your task is to calculate for how many minutes Limak will watch the game. The input will be provided via standard input and looks as follows: The first line of the input contains one integer *n* (1<=≀<=*n*<=≀<=90)Β β€” the number of interesting minutes. The second line contains *n* integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≀<=*t*1<=&lt;<=*t*2<=&lt;<=... *t**n*<=≀<=90), given in the increasing order. You should write the solution as standard output as follows: Print the number of minutes Limak will watch the game. Here are example inputs and outputs for the problem: Example Input 1: 3 7 20 88 Example Output 1: 35 Example Input 2: 9 16 20 30 40 50 60 70 80 90 Example Output 2: 15 Example Input 3: 9 15 20 30 40 50 60 70 80 90 Example Output 3: 90 Now solve the problem by providing the code.
n=int(input()) tl = list(map(int, input().split())) time=cnt=0 while cnt <15 and time<90: time+=1 if tl.count(time)>0: cnt=0 else: cnt+=1 print(time)
vfc_82985
{ "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\n7 20 88", "output": "35", "type": "stdin_stdout" }, { "fn_name": null, "input": "9\n16 20 30 40 50 60 70 80 90", "output": "15", "type": "stdin_stdout" }, { "fn_name": null, "input": "9\n15 20 30 40 50 60 70 80 90", "output": "90", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
305
Solve the following coding problem using the programming language python: A continued fraction of height *n* is a fraction of form . You are given two rational numbers, one is represented as and the other one is represented as a finite fraction of height *n*. Check if they are equal. The input will be provided via standard input and looks as follows: The first line contains two space-separated integers *p*,<=*q* (1<=≀<=*q*<=≀<=*p*<=≀<=1018) β€” the numerator and the denominator of the first fraction. The second line contains integer *n* (1<=≀<=*n*<=≀<=90) β€” the height of the second fraction. The third line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=1018) β€” the continued fraction. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specifier. You should write the solution as standard output as follows: Print "YES" if these fractions are equal and "NO" otherwise. Here are example inputs and outputs for the problem: Example Input 1: 9 4 2 2 4 Example Output 1: YES Example Input 2: 9 4 3 2 3 1 Example Output 2: YES Example Input 3: 9 4 3 1 2 4 Example Output 3: NO Now solve the problem by providing the code.
from fractions import gcd p,q=map(int,input().split()) gc=gcd(p,q) p//=gc q//=gc n=int(input()) a=list(map(int,input().split())) def add(a,b): res=[] a[0]*=b[1] b[0]*=a[1] temp=b[1]*a[1] top=a[0]+b[0] gc=gcd(top,temp) temp//=gc top//=gc; res.append(top) res.append(temp) return res def go(i): res=[] if i==n-1: res.append(a[i]) res.append(1) return res; temp=list(go(i+1)) temp=temp[::-1] ta=[] ta.append(a[i]) ta.append(1) temp=add(ta,temp) return temp res=go(0) if(res[0]==p and res[1]==q): print("YES") else: print("NO")
vfc_82989
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "500" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "9 4\n2\n2 4", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "9 4\n3\n2 3 1", "output": "YES", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
665
Solve the following coding problem using the programming language python: zscoder loves simple strings! A string *t* is called simple if every pair of adjacent characters are distinct. For example ab, aba, zscoder are simple whereas aa, add are not simple. zscoder is given a string *s*. He wants to change a minimum number of characters so that the string *s* becomes simple. Help him with this task! The input will be provided via standard input and looks as follows: The only line contains the string *s* (1<=≀<=|*s*|<=≀<=2Β·105) β€” the string given to zscoder. The string *s* consists of only lowercase English letters. You should write the solution as standard output as follows: Print the simple string *s*' β€” the string *s* after the minimal number of changes. If there are multiple solutions, you may output any of them. Note that the string *s*' should also consist of only lowercase English letters. Here are example inputs and outputs for the problem: Example Input 1: aab Example Output 1: bab Example Input 2: caaab Example Output 2: cabab Example Input 3: zscoder Example Output 3: zscoder Now solve the problem by providing the code.
s=list(input()+'a') for i in range(len(s)-2): if s[i]==s[i+1]: s[i+1]=list({'a', 'b', 'c'}-{s[i]}-{s[i+2]})[0] print(''.join(s[:-1]))
vfc_82993
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "aab", "output": "bab", "type": "stdin_stdout" }, { "fn_name": null, "input": "caaab", "output": "cabab", "type": "stdin_stdout" }, { "fn_name": null, "input": "zscoder", "output": "zscoder", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
689
Solve the following coding problem using the programming language python: While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements? The input will be provided via standard input and looks as follows: The first line of the input contains the only integer *n* (1<=≀<=*n*<=≀<=9)Β β€” the number of digits in the phone number that Mike put in. The second line contains the string consisting of *n* digits (characters from '0' to '9') representing the number that Mike put in. You should write the solution as standard output as follows: If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line. Otherwise print "NO" (without quotes) in the first line. Here are example inputs and outputs for the problem: Example Input 1: 3 586 Example Output 1: NO Example Input 2: 2 09 Example Output 2: NO Example Input 3: 9 123456789 Example Output 3: YES Example Input 4: 3 911 Example Output 4: YES Now solve the problem by providing the code.
n = input() s = set(map(int,input())) if all(map(lambda x: x&s!=set(),({1,4,7,0},{3,6,9,0},{7,0,9},{1,2,3}))): print("YES") else: print("NO")
vfc_82997
{ "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\n586", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n09", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "9\n123456789", "output": "YES", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
39
Solve the following coding problem using the programming language python: Thumbelina has had an accident. She has found herself on a little island in the middle of a swamp and wants to get to the shore very much. One can get to the shore only by hills that are situated along a straight line that connects the little island with the shore. Let us assume that the hills are numbered from 1 to *n* and the number of a hill is equal to the distance in meters between it and the island. The distance between the *n*-th hill and the shore is also 1 meter. Thumbelina is too small to make such jumps. Fortunately, a family of frogs living in the swamp suggests to help her. Each frog agrees to give Thumbelina a ride but Thumbelina should choose only one frog. Each frog has a certain jump length. If Thumbelina agrees to accept help from a frog whose jump length is *d*, the frog will jump from the island on the hill *d*, then β€” on the hill 2*d*, then 3*d* and so on until they get to the shore (i.e. find itself beyond the hill *n*). However, there is one more problem: mosquitoes also live in the swamp. At the moment they have a siesta, and they are having a nap on some hills. If the frog jumps on a hill with a mosquito the frog will smash it. The frogs Thumbelina has met are pacifists, so they will find the death of each mosquito very much sad. Help Thumbelina choose a frog that will bring her to the shore and smash as small number of mosquitoes as possible. The input will be provided via standard input and looks as follows: The first line contains three integers *n*, *m* and *k* (1<=≀<=*n*<=≀<=109, 1<=≀<=*m*,<=*k*<=≀<=100) β€” the number of hills, frogs and mosquitoes respectively. The second line contains *m* integers *d**i* (1<=≀<=*d**i*<=≀<=109) β€” the lengths of the frogs’ jumps. The third line contains *k* integers β€” the numbers of the hills on which each mosquito is sleeping. No more than one mosquito can sleep on each hill. The numbers in the lines are separated by single spaces. You should write the solution as standard output as follows: In the first line output the number of frogs that smash the minimal number of mosquitoes, in the second line β€” their numbers in increasing order separated by spaces. The frogs are numbered from 1 to *m* in the order of the jump length given in the input data. Here are example inputs and outputs for the problem: Example Input 1: 5 3 5 2 3 4 1 2 3 4 5 Example Output 1: 2 2 3 Example Input 2: 1000000000 2 3 2 5 999999995 999999998 999999996 Example Output 2: 1 2 Now solve the problem by providing the code.
n, m, k = map(int, input().split()) x, y = n, [] a = map(int, input().split()) b = list(map(int, input().split())) for i, d in enumerate(a): c = 0 for t in b: if 0 == t % d: c += 1 if c < x: x = c y = [i + 1] elif c == x: y += i + 1, print(len(y)) print(' '.join(map(str, y)))
vfc_83001
{ "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 5\n2 3 4\n1 2 3 4 5", "output": "2\n2 3", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000000000 2 3\n2 5\n999999995 999999998 999999996", "output": "1\n2", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1 1\n1\n1", "output": "1\n1", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2 1\n2 1\n1", "output": "1\n1", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2 2\n2 4\n3 2", "output": "1\n2", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 3 6\n5 2 8\n5 6 7 8 9 10", "output": "1\n3", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
612
Solve the following coding problem using the programming language python: You are given the string *s* of length *n* and the numbers *p*,<=*q*. Split the string *s* to pieces of length *p* and *q*. For example, the string "Hello" for *p*<==<=2, *q*<==<=3 can be split to the two strings "Hel" and "lo" or to the two strings "He" and "llo". Note it is allowed to split the string *s* to the strings only of length *p* or to the strings only of length *q* (see the second sample test). The input will be provided via standard input and looks as follows: The first line contains three positive integers *n*,<=*p*,<=*q* (1<=≀<=*p*,<=*q*<=≀<=*n*<=≀<=100). The second line contains the string *s* consists of lowercase and uppercase latin letters and digits. You should write the solution as standard output as follows: If it's impossible to split the string *s* to the strings of length *p* and *q* print the only number "-1". Otherwise in the first line print integer *k* β€” the number of strings in partition of *s*. Each of the next *k* lines should contain the strings in partition. Each string should be of the length *p* or *q*. The string should be in order of their appearing in string *s* β€” from left to right. If there are several solutions print any of them. Here are example inputs and outputs for the problem: Example Input 1: 5 2 3 Hello Example Output 1: 2 He llo Example Input 2: 10 9 5 Codeforces Example Output 2: 2 Codef orces Example Input 3: 6 4 5 Privet Example Output 3: -1 Example Input 4: 8 1 1 abacabac Example Output 4: 8 a b a c a b a c Now solve the problem by providing the code.
n, p, q = map(int, input().split()) s = input() if p > q: p, q = q, p for i in range(0, n + 1, q): if (n - i) % p == 0: print(i // q + (n - i) // p) for j in range(0, i, q): print(s[j:j + q]) for j in range(i, n, p): print(s[j:j + p]) exit(0) print(-1)
vfc_83005
{ "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 2 3\nHello", "output": "2\nHe\nllo", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 9 5\nCodeforces", "output": "2\nCodef\norces", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 4 5\nPrivet", "output": "-1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
542
Solve the following coding problem using the programming language python: Some time ago Leonid have known about idempotent functions. Idempotent function defined on a set {1,<=2,<=...,<=*n*} is such function , that for any the formula *g*(*g*(*x*))<==<=*g*(*x*) holds. Let's denote as *f*(*k*)(*x*) the function *f* applied *k* times to the value *x*. More formally, *f*(1)(*x*)<==<=*f*(*x*), *f*(*k*)(*x*)<==<=*f*(*f*(*k*<=-<=1)(*x*)) for each *k*<=&gt;<=1. You are given some function . Your task is to find minimum positive integer *k* such that function *f*(*k*)(*x*) is idempotent. The input will be provided via standard input and looks as follows: In the first line of the input there is a single integer *n* (1<=≀<=*n*<=≀<=200) β€” the size of function *f* domain. In the second line follow *f*(1),<=*f*(2),<=...,<=*f*(*n*) (1<=≀<=*f*(*i*)<=≀<=*n* for each 1<=≀<=*i*<=≀<=*n*), the values of a function. You should write the solution as standard output as follows: Output minimum *k* such that function *f*(*k*)(*x*) is idempotent. Here are example inputs and outputs for the problem: Example Input 1: 4 1 2 2 4 Example Output 1: 1 Example Input 2: 3 2 3 3 Example Output 2: 2 Example Input 3: 3 2 3 1 Example Output 3: 3 Now solve the problem by providing the code.
N =int(input()) inp =input().split() F =[0 for i in range(N)] for i in range(N): F[i] =int(inp[i])-1 ans_small =[0 for i in range(N+1)] for i in range(N): x =i y =i for j in range(N): x =F[x] y =F[F[y]] if x == y: ans_small[j+1] +=1 ans =-1 for i in range(1,N+1): if ans == -1: if ans_small[i] == N: ans =i #dlhe pw =[0 for i in range(500)] for i in range(N): vis =[False for j in range(N)] vis[i] =True x =F[i] while vis[x] == False: vis[x] =True x =F[x] vis2 =[False for j in range(N)] vis2[x] =True x =F[x] while vis2[x] == False: vis2[x] =True x =F[x] c =0 for j in range(N): if vis2[j]: c +=1 j =2 while j <= c: p =0 while c%j == 0: c //=j p +=1 pw[j] =max(pw[j],p) j +=1 if ans == -1: ans =1 for i in range(1,500): for j in range(pw[i]): ans *=i ans0 =ans while ans <= N: ans +=ans0 print(ans)
vfc_83009
{ "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 2 2 4", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2 3 3", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2 3 1", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "16\n1 4 13 9 11 16 14 6 5 12 7 8 15 2 3 10", "output": "105", "type": "stdin_stdout" }, { "fn_name": null, "input": "20\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
637
Solve the following coding problem using the programming language python: After celebrating the midcourse the students of one of the faculties of the Berland State University decided to conduct a vote for the best photo. They published the photos in the social network and agreed on the rules to choose a winner: the photo which gets most likes wins. If multiple photoes get most likes, the winner is the photo that gets this number first. Help guys determine the winner photo by the records of likes. 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*<=≀<=1000) β€” the total likes to the published photoes. The second line contains *n* positive integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=1<=000<=000), where *a**i* is the identifier of the photo which got the *i*-th like. You should write the solution as standard output as follows: Print the identifier of the photo which won the elections. Here are example inputs and outputs for the problem: Example Input 1: 5 1 3 2 2 1 Example Output 1: 2 Example Input 2: 9 100 200 300 200 100 300 300 100 200 Example Output 2: 300 Now solve the problem by providing the code.
# -*- coding: utf-8 -*- """ Created on Sun Mar 13 19:40:03 2016 @author: Kostya S. """ from functools import cmp_to_key n = int(input()) d = {} a = [int(i) for i in input().split()] for i,e in enumerate(a): d[e] = (i+1,1,e) if d.get(e) == None else (i+1,d[e][1] + 1,e) t1 = sorted(list(d.values()),key = lambda x: x[1]) t2 = list(filter(lambda x: x[1] == t1[-1][1],t1)) t2 = sorted(t2,key = lambda x: x[0]) print(t2[0][-1])
vfc_83013
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "3000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 3 2 2 1", "output": "2", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
908
Solve the following coding problem using the programming language python: Your friend has *n* cards. You know that each card has a lowercase English letter on one side and a digit on the other. Currently, your friend has laid out the cards on a table so only one side of each card is visible. You would like to know if the following statement is true for cards that your friend owns: "If a card has a vowel on one side, then it has an even digit on the other side." More specifically, a vowel is one of 'a', 'e', 'i', 'o' or 'u', and even digit is one of '0', '2', '4', '6' or '8'. For example, if a card has 'a' on one side, and '6' on the other side, then this statement is true for it. Also, the statement is true, for example, for a card with 'b' and '4', and for a card with 'b' and '3' (since the letter is not a vowel). The statement is false, for example, for card with 'e' and '5'. You are interested if the statement is true for all cards. In particular, if no card has a vowel, the statement is true. To determine this, you can flip over some cards to reveal the other side. You would like to know what is the minimum number of cards you need to flip in the worst case in order to verify that the statement is true. The input will be provided via standard input and looks as follows: The first and only line of input will contain a string *s* (1<=≀<=|*s*|<=≀<=50), denoting the sides of the cards that you can see on the table currently. Each character of *s* is either a lowercase English letter or a digit. You should write the solution as standard output as follows: Print a single integer, the minimum number of cards you must turn over to verify your claim. Here are example inputs and outputs for the problem: Example Input 1: ee Example Output 1: 2 Example Input 2: z Example Output 2: 0 Example Input 3: 0ay1 Example Output 3: 2 Now solve the problem by providing the code.
from sys import stdin, stdout def need_to_check(card, vowels=['a','e','i','o','u']): return (ord(card) >= ord('0') and ord(card) <= ord('9') and int(card) % 2 == 1) or (card in vowels) def number_of_reveals(cards): count = 0 for card in cards: count = count+1 if need_to_check(card) else count return count stdout.write( str(number_of_reveals(stdin.readline())) +'\n')
vfc_83017
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "ee", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "z", "output": "0", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
625
Solve the following coding problem using the programming language python: A long time ago, in a galaxy far far away two giant IT-corporations Pineapple and Gogol continue their fierce competition. Crucial moment is just around the corner: Gogol is ready to release it's new tablet Lastus 3000. This new device is equipped with specially designed artificial intelligence (AI). Employees of Pineapple did their best to postpone the release of Lastus 3000 as long as possible. Finally, they found out, that the name of the new artificial intelligence is similar to the name of the phone, that Pineapple released 200 years ago. As all rights on its name belong to Pineapple, they stand on changing the name of Gogol's artificial intelligence. Pineapple insists, that the name of their phone occurs in the name of AI as a substring. Because the name of technology was already printed on all devices, the Gogol's director decided to replace some characters in AI name with "#". As this operation is pretty expensive, you should find the minimum number of characters to replace with "#", such that the name of AI doesn't contain the name of the phone as a substring. Substring is a continuous subsequence of a string. The input will be provided via standard input and looks as follows: The first line of the input contains the name of AI designed by Gogol, its length doesn't exceed 100<=000 characters. Second line contains the name of the phone released by Pineapple 200 years ago, its length doesn't exceed 30. Both string are non-empty and consist of only small English letters. You should write the solution as standard output as follows: Print the minimum number of characters that must be replaced with "#" in order to obtain that the name of the phone doesn't occur in the name of AI as a substring. Here are example inputs and outputs for the problem: Example Input 1: intellect tell Example Output 1: 1 Example Input 2: google apple Example Output 2: 0 Example Input 3: sirisiri sir Example Output 3: 2 Now solve the problem by providing the code.
# Description of the problem can be found at http://codeforces.com/problemset/problem/625/B x = input() s = input() print(x.count(s))
vfc_83021
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "intellect\ntell", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "google\napple", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "sirisiri\nsir", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "sirisiri\nsiri", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "aaaaaaa\naaaa", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "bbbbbb\nbb", "output": "3", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
227
Solve the following coding problem using the programming language python: Trouble came from the overseas lands: a three-headed dragon Gorynych arrived. The dragon settled at point *C* and began to terrorize the residents of the surrounding villages. A brave hero decided to put an end to the dragon. He moved from point *A* to fight with Gorynych. The hero rode from point *A* along a straight road and met point *B* on his way. The hero knows that in this land for every pair of roads it is true that they are either parallel to each other, or lie on a straight line, or are perpendicular to each other. He also knows well that points *B* and *C* are connected by a road. So the hero must either turn 90 degrees to the left or continue riding straight ahead or turn 90 degrees to the right. But he forgot where the point *C* is located. Fortunately, a Brave Falcon flew right by. It can see all three points from the sky. The hero asked him what way to go to get to the dragon's lair. If you have not got it, you are the falcon. Help the hero and tell him how to get him to point *C*: turn left, go straight or turn right. At this moment the hero is believed to stand at point *B*, turning his back to point *A*. The input will be provided via standard input and looks as follows: The first input line contains two space-separated integers *x**a*,<=*y**a* (|*x**a*|,<=|*y**a*|<=≀<=109) β€” the coordinates of point *A*. The second line contains the coordinates of point *B* in the same form, the third line contains the coordinates of point *C*. It is guaranteed that all points are pairwise different. It is also guaranteed that either point *B* lies on segment *AC*, or angle *ABC* is right. You should write the solution as standard output as follows: Print a single line. If a hero must turn left, print "LEFT" (without the quotes); If he must go straight ahead, print "TOWARDS" (without the quotes); if he should turn right, print "RIGHT" (without the quotes). Here are example inputs and outputs for the problem: Example Input 1: 0 0 0 1 1 1 Example Output 1: RIGHT Example Input 2: -1 -1 -3 -3 -4 -4 Example Output 2: TOWARDS Example Input 3: -4 -6 -3 -7 -2 -6 Example Output 3: LEFT Now solve the problem by providing the code.
xa,ya = input().split() xa = int(xa) ya = int(ya) xb,yb = input().split() xb = int(xb) yb = int(yb) xc,yc = input().split() xc = int(xc) yc = int(yc) vab_x = xb-xa vab_y = yb-ya vbc_x = xc - xb vbc_y = yc - yb produto_vetorial = (vab_x * vbc_y) - (vab_y * vbc_x) if(produto_vetorial == 0): print("TOWARDS") elif(produto_vetorial < 0): print("RIGHT") else: print("LEFT")
vfc_83025
{ "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 0\n0 1\n1 1", "output": "RIGHT", "type": "stdin_stdout" }, { "fn_name": null, "input": "-1 -1\n-3 -3\n-4 -4", "output": "TOWARDS", "type": "stdin_stdout" }, { "fn_name": null, "input": "-4 -6\n-3 -7\n-2 -6", "output": "LEFT", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
340
Solve the following coding problem using the programming language python: Iahub is a big fan of tourists. He wants to become a tourist himself, so he planned a trip. There are *n* destinations on a straight road that Iahub wants to visit. Iahub starts the excursion from kilometer 0. The *n* destinations are described by a non-negative integers sequence *a*1, *a*2, ..., *a**n*. The number *a**k* represents that the *k*th destination is at distance *a**k* kilometers from the starting point. No two destinations are located in the same place. Iahub wants to visit each destination only once. Note that, crossing through a destination is not considered visiting, unless Iahub explicitly wants to visit it at that point. Also, after Iahub visits his last destination, he doesn't come back to kilometer 0, as he stops his trip at the last destination. The distance between destination located at kilometer *x* and next destination, located at kilometer *y*, is |*x*<=-<=*y*| kilometers. We call a "route" an order of visiting the destinations. Iahub can visit destinations in any order he wants, as long as he visits all *n* destinations and he doesn't visit a destination more than once. Iahub starts writing out on a paper all possible routes and for each of them, he notes the total distance he would walk. He's interested in the average number of kilometers he would walk by choosing a route. As he got bored of writing out all the routes, he asks you to help him. The input will be provided via standard input and looks as follows: The first line contains integer *n* (2<=≀<=*n*<=≀<=105). Next line contains *n* distinct integers *a*1, *a*2, ..., *a**n* (1<=≀<=*a**i*<=≀<=107). You should write the solution as standard output as follows: Output two integers β€” the numerator and denominator of a fraction which is equal to the wanted average number. The fraction must be irreducible. Here are example inputs and outputs for the problem: Example Input 1: 3 2 3 5 Example Output 1: 22 3 Now solve the problem by providing the code.
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Wed Jun 3 11:57:46 2020 @author: shailesh """ from math import gcd def reduce_fraction(x,y): d = gcd(x,y) x = x//d y = y//d return x,y N = int(input()) A = [int(i) for i in input().split()] A.sort() d0 = A[0] sum_val = 0 for i in range(N-1): m_bf = i+2 m_af = N - i - 1 d = A[i+1]-A[i] # d = 1 sum_val +=m_af*(2*m_bf - 1)*d # print(A[i],A[i+1],sum_val) numerator = N*d0 + sum_val denominator = N numerator,denominator = reduce_fraction(numerator,denominator) print(numerator,denominator) #from itertools import permutations #perms = list(permutations([2,3,5])) # #perms = [(0,) + perm for perm in perms] # #d = {} #d['02'] = 0 #d['23'] = 0 #d['35'] = 0 #for perm in perms: # for i in range(len(perm)-1): # # start_end = [perm[i],perm[i+1]] # start_end.sort() # rng = range(start_end[0],start_end[1]+1) # if 0 in rng and 2 in rng: # d['02'] +=1 # if 2 in rng and 3 in rng: # d['23'] += 1 # if 3 in rng and 5 in rng: # d['35'] +=1
vfc_83029
{ "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\n2 3 5", "output": "22 3", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 5 77 2", "output": "547 4", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n3 3842 288 199 334", "output": "35918 5", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n1 2 3 40 52 33 86", "output": "255 1", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n1 10 100 1000 10000 1000000 10000000", "output": "139050619 7", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n3835302 971984 8706888 1080445 2224695 1093317", "output": "114053569 6", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
1006
Solve the following coding problem using the programming language python: Mishka got an integer array $a$ of length $n$ as a birthday present (what a surprise!). Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: - Replace each occurrence of $1$ in the array $a$ with $2$; - Replace each occurrence of $2$ in the array $a$ with $1$; - Replace each occurrence of $3$ in the array $a$ with $4$; - Replace each occurrence of $4$ in the array $a$ with $3$; - Replace each occurrence of $5$ in the array $a$ with $6$; - Replace each occurrence of $6$ in the array $a$ with $5$; - $\dots$ - Replace each occurrence of $10^9 - 1$ in the array $a$ with $10^9$; - Replace each occurrence of $10^9$ in the array $a$ with $10^9 - 1$. Note that the dots in the middle of this algorithm mean that Mishka applies these replacements for each pair of adjacent integers ($2i - 1, 2i$) for each $i \in\{1, 2, \ldots, 5 \cdot 10^8\}$ as described above. For example, for the array $a = [1, 2, 4, 5, 10]$, the following sequence of arrays represents the algorithm: $[1, 2, 4, 5, 10]$ $\rightarrow$ (replace all occurrences of $1$ with $2$) $\rightarrow$ $[2, 2, 4, 5, 10]$ $\rightarrow$ (replace all occurrences of $2$ with $1$) $\rightarrow$ $[1, 1, 4, 5, 10]$ $\rightarrow$ (replace all occurrences of $3$ with $4$) $\rightarrow$ $[1, 1, 4, 5, 10]$ $\rightarrow$ (replace all occurrences of $4$ with $3$) $\rightarrow$ $[1, 1, 3, 5, 10]$ $\rightarrow$ (replace all occurrences of $5$ with $6$) $\rightarrow$ $[1, 1, 3, 6, 10]$ $\rightarrow$ (replace all occurrences of $6$ with $5$) $\rightarrow$ $[1, 1, 3, 5, 10]$ $\rightarrow$ $\dots$ $\rightarrow$ $[1, 1, 3, 5, 10]$ $\rightarrow$ (replace all occurrences of $10$ with $9$) $\rightarrow$ $[1, 1, 3, 5, 9]$. The later steps of the algorithm do not change the array. Mishka is very lazy and he doesn't want to apply these changes by himself. But he is very interested in their result. Help him find it. The input will be provided via standard input and looks as follows: The first line of the input contains one integer number $n$ ($1 \le n \le 1000$) β€” the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) β€” the elements of the array. You should write the solution as standard output as follows: Print $n$ integers β€” $b_1, b_2, \dots, b_n$, where $b_i$ is the final value of the $i$-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array $a$. Note that you cannot change the order of elements in the array. Here are example inputs and outputs for the problem: Example Input 1: 5 1 2 4 5 10 Example Output 1: 1 1 3 5 9 Example Input 2: 10 10000 10 50605065 1 5 89 5 999999999 60506056 1000000000 Example Output 2: 9999 9 50605065 1 5 89 5 999999999 60506055 999999999 Now solve the problem by providing the code.
n = int(input()) a = [int(s) for s in input().split(' ')] b = [str(c - ((c + 1) % 2)) for c in a] print(' '.join(b))
vfc_83033
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "3000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 2 4 5 10", "output": "1 1 3 5 9", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000", "output": "9999 9 50605065 1 5 89 5 999999999 60506055 999999999", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n999999999", "output": "999999999", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1000000000", "output": "999999999", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n210400", "output": "210399", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n100000000 100000000 100000000 100000000 100000000", "output": "99999999 99999999 99999999 99999999 99999999", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
805
Solve the following coding problem using the programming language python: In the beginning of the new year Keivan decided to reverse his name. He doesn't like palindromes, so he changed Naviek to Navick. He is too selfish, so for a given *n* he wants to obtain a string of *n* characters, each of which is either 'a', 'b' or 'c', with no palindromes of length 3 appearing in the string as a substring. For example, the strings "abc" and "abca" suit him, while the string "aba" doesn't. He also want the number of letters 'c' in his string to be as little as possible. The input will be provided via standard input and looks as follows: The first line contains single integer *n* (1<=≀<=*n*<=≀<=2Β·105)Β β€” the length of the string. You should write the solution as standard output as follows: Print the string that satisfies all the constraints. If there are multiple answers, print any of them. Here are example inputs and outputs for the problem: Example Input 1: 2 Example Output 1: aa Example Input 2: 3 Example Output 2: bba Now solve the problem by providing the code.
n = int(input()) s = 'bbaa' * (n // 4 + 1) s = s[:n] print(s)
vfc_83037
{ "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", "output": "aa", "type": "stdin_stdout" }, { "fn_name": null, "input": "3", "output": "aab", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
242
Solve the following coding problem using the programming language python: A coordinate line has *n* segments, the *i*-th segment starts at the position *l**i* and ends at the position *r**i*. We will denote such a segment as [*l**i*,<=*r**i*]. You have suggested that one of the defined segments covers all others. In other words, there is such segment in the given set, which contains all other ones. Now you want to test your assumption. Find in the given set the segment which covers all other segments, and print its number. If such a segment doesn't exist, print -1. Formally we will assume that segment [*a*,<=*b*] covers segment [*c*,<=*d*], if they meet this condition *a*<=≀<=*c*<=≀<=*d*<=≀<=*b*. The input will be provided via standard input and looks as follows: The first line contains integer *n* (1<=≀<=*n*<=≀<=105) β€” the number of segments. Next *n* lines contain the descriptions of the segments. The *i*-th line contains two space-separated integers *l**i*,<=*r**i* (1<=≀<=*l**i*<=≀<=*r**i*<=≀<=109) β€” the borders of the *i*-th segment. It is guaranteed that no two segments coincide. You should write the solution as standard output as follows: Print a single integer β€” the number of the segment that covers all other segments in the set. If there's no solution, print -1. The segments are numbered starting from 1 in the order in which they appear in the input. Here are example inputs and outputs for the problem: Example Input 1: 3 1 1 2 2 3 3 Example Output 1: -1 Example Input 2: 6 1 5 2 3 1 10 7 10 7 7 10 10 Example Output 2: 3 Now solve the problem by providing the code.
n=int(input()) L=[] aG=0; mini = 1000000000 maxi = -1000000000; for i in range(0,n): a=input().rstrip().split(' ') L.append(a) if int(a[0])<=mini and int(a[1])>=maxi: G=int(a[0]); H=int(a[1]); S=i; mini = int(a[0]) maxi = int(a[1]) #print(S,mini,maxi) for i in range(0,len(L)): A=L[i]; # print(A) if int(A[0])>=mini and int(A[0])<=maxi and int(A[1])>=mini and int(A[1]) <= maxi: continue; else: aG=1; break; # print(i) if aG==1: print(-1) else: print(S+1);
vfc_83041
{ "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\n2 2\n3 3", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n1 5\n2 3\n1 10\n7 10\n7 7\n10 10", "output": "3", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
946
Solve the following coding problem using the programming language python: You are given a sequence *a* consisting of *n* integers. You may partition this sequence into two sequences *b* and *c* in such a way that every element belongs exactly to one of these sequences. Let *B* be the sum of elements belonging to *b*, and *C* be the sum of elements belonging to *c* (if some of these sequences is empty, then its sum is 0). What is the maximum possible value of *B*<=-<=*C*? The input will be provided via standard input and looks as follows: The first line contains one integer *n* (1<=≀<=*n*<=≀<=100) β€” the number of elements in *a*. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (<=-<=100<=≀<=*a**i*<=≀<=100) β€” the elements of sequence *a*. You should write the solution as standard output as follows: Print the maximum possible value of *B*<=-<=*C*, where *B* is the sum of elements of sequence *b*, and *C* is the sum of elements of sequence *c*. Here are example inputs and outputs for the problem: Example Input 1: 3 1 -2 0 Example Output 1: 3 Example Input 2: 6 16 23 16 15 42 8 Example Output 2: 120 Now solve the problem by providing the code.
n = int(input()) b, c = 0, 0 for i in map(int, input().split()): if i < 0: c += i else: b += i print(b - c)
vfc_83045
{ "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 -2 0", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n16 23 16 15 42 8", "output": "120", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n-1", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\n-100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100 -100", "output": "10000", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n-1 5", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n-2 0 1", "output": "3", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
988
Solve the following coding problem using the programming language python: There are $n$ students in a school class, the rating of the $i$-th student on Codehorses is $a_i$. You have to form a team consisting of $k$ students ($1 \le k \le n$) such that the ratings of all team members are distinct. If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES", and then print $k$ distinct numbers which should be the indices of students in the team you form. If there are multiple answers, print any of them. The input will be provided via standard input and looks as follows: The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 100$) β€” the number of students and the size of the team you have to form. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 100$), where $a_i$ is the rating of $i$-th student. You should write the solution as standard output as follows: If it is impossible to form a suitable team, print "NO" (without quotes). Otherwise print "YES", and then print $k$ distinct integers from $1$ to $n$ which should be the indices of students in the team you form. All the ratings of the students in the team should be distinct. You may print the indices in any order. If there are multiple answers, print any of them. Assume that the students are numbered from $1$ to $n$. Here are example inputs and outputs for the problem: Example Input 1: 5 3 15 13 15 15 12 Example Output 1: YES 1 2 5 Example Input 2: 5 4 15 13 15 15 12 Example Output 2: NO Example Input 3: 4 4 20 10 40 30 Example Output 3: YES 1 2 3 4 Now solve the problem by providing the code.
n,k=map(int,input().split()) l=list(map(int,input().split())) s=set() for i in range(len(l)): s.add(l[i]) l1=[i for i in s] l2=[] if len(s)>=k: print("YES") for i in range(k): if(l1[i] in l): l2.append(l.index(l1[i])+1) l2.sort() for i in range(len(l2)): print(l2[i],end=' ') else: print("NO")
vfc_83053
{ "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\n15 13 15 15 12", "output": "YES\n1 2 5 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 4\n15 13 15 15 12", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 4\n20 10 40 30", "output": "YES\n1 2 3 4 ", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
544
Solve the following coding problem using the programming language python: A map of some object is a rectangular field consisting of *n* rows and *n* columns. Each cell is initially occupied by the sea but you can cover some some cells of the map with sand so that exactly *k* islands appear on the map. We will call a set of sand cells to be island if it is possible to get from each of them to each of them by moving only through sand cells and by moving from a cell only to a side-adjacent cell. The cells are called to be side-adjacent if they share a vertical or horizontal side. It is easy to see that islands do not share cells (otherwise they together form a bigger island). Find a way to cover some cells with sand so that exactly *k* islands appear on the *n*<=Γ—<=*n* map, or determine that no such way exists. The input will be provided via standard input and looks as follows: The single line contains two positive integers *n*, *k* (1<=≀<=*n*<=≀<=100, 0<=≀<=*k*<=≀<=*n*2) β€” the size of the map and the number of islands you should form. You should write the solution as standard output as follows: If the answer doesn't exist, print "NO" (without the quotes) in a single line. Otherwise, print "YES" in the first line. In the next *n* lines print the description of the map. Each of the lines of the description must consist only of characters 'S' and 'L', where 'S' is a cell that is occupied by the sea and 'L' is the cell covered with sand. The length of each line of the description must equal *n*. If there are multiple answers, you may print any of them. You should not maximize the sizes of islands. Here are example inputs and outputs for the problem: Example Input 1: 5 2 Example Output 1: YES SSSSS LLLLL SSSSS LLLLL SSSSS Example Input 2: 5 25 Example Output 2: NO Now solve the problem by providing the code.
import sys input = sys.stdin.readline read_tuple = lambda _type: map(_type, input().split(' ')) def solve(): n, k = read_tuple(int) grid = [['S' for _ in range(n)] for _ in range(n)] flag = True for i in range(n): for j in range(n): if k and flag: grid[i][j] = 'L' k -= 1 flag ^= True if n % 2 == 0: flag ^= True if k == 0: print("YES") else: print("NO") if k == 0: for row in grid: print(''.join(row)) if __name__ == '__main__': solve()
vfc_83057
{ "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 2", "output": "YES\nSSSSS\nLLLLL\nSSSSS\nLLLLL\nSSSSS", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 25", "output": "NO", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
793
Solve the following coding problem using the programming language python: Oleg the bank client checks share prices every day. There are *n* share prices he is interested in. Today he observed that each second exactly one of these prices decreases by *k* rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg found this process interesting, and he asked Igor the financial analyst, what is the minimum time needed for all *n* prices to become equal, or it is impossible at all? Igor is busy right now, so he asked you to help Oleg. Can you answer this question? The input will be provided via standard input and looks as follows: The first line contains two integers *n* and *k* (1<=≀<=*n*<=≀<=105,<=1<=≀<=*k*<=≀<=109)Β β€” the number of share prices, and the amount of rubles some price decreases each second. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=109)Β β€” the initial prices. You should write the solution as standard output as follows: Print the only line containing the minimum number of seconds needed for prices to become equal, of Β«-1Β» if it is impossible. Here are example inputs and outputs for the problem: Example Input 1: 3 3 12 9 15 Example Output 1: 3 Example Input 2: 2 2 10 9 Example Output 2: -1 Example Input 3: 4 1 1 1000000000 1000000000 1000000000 Example Output 3: 2999999997 Now solve the problem by providing the code.
import math n,k=map(int,input().split()) a=list(map(int,input().split())) a.sort() r=a[0]%k;t=0 for i in range(1,n): if a[i]%k!=r: print(-1) break else: t+=(a[i]-a[0])//k else: print(t)
vfc_83061
{ "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 3\n12 9 15", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n10 9", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 1\n1 1000000000 1000000000 1000000000", "output": "2999999997", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 11\n123", "output": "0", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
552
Solve the following coding problem using the programming language python: Vanya has a table consisting of 100 rows, each row contains 100 cells. The rows are numbered by integers from 1 to 100 from bottom to top, the columns are numbered from 1 to 100 from left to right. In this table, Vanya chose *n* rectangles with sides that go along borders of squares (some rectangles probably occur multiple times). After that for each cell of the table he counted the number of rectangles it belongs to and wrote this number into it. Now he wants to find the sum of values in all cells of the table and as the table is too large, he asks you to help him find the result. The input will be provided via standard input and looks as follows: The first line contains integer *n* (1<=≀<=*n*<=≀<=100) β€” the number of rectangles. Each of the following *n* lines contains four integers *x*1,<=*y*1,<=*x*2,<=*y*2 (1<=≀<=*x*1<=≀<=*x*2<=≀<=100, 1<=≀<=*y*1<=≀<=*y*2<=≀<=100), where *x*1 and *y*1 are the number of the column and row of the lower left cell and *x*2 and *y*2 are the number of the column and row of the upper right cell of a rectangle. You should write the solution as standard output as follows: In a single line print the sum of all values in the cells of the table. Here are example inputs and outputs for the problem: Example Input 1: 2 1 1 2 3 2 2 3 3 Example Output 1: 10 Example Input 2: 2 1 1 3 3 1 1 3 3 Example Output 2: 18 Now solve the problem by providing the code.
def solve(x1, y1, x2, y2): return sum((x2[i] - x1[i] + 1) * (y2[i] - y1[i] + 1) for i in range(len(x1))) def main(): n = int(input()) x1 = [] y1 = [] x2 = [] y2 = [] for _ in range(n): x1_i, y1_i, x2_i, y2_i = map(int, input().split()) x1.append(x1_i) y1.append(y1_i) x2.append(x2_i) y2.append(y2_i) result = solve(x1, y1, x2, y2) print(result) if __name__ == "__main__": main()
vfc_83065
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "4000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1 1 2 3\n2 2 3 3", "output": "10", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 1 3 3\n1 1 3 3", "output": "18", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n4 11 20 15\n7 5 12 20\n10 8 16 12\n7 5 12 15\n2 2 20 13", "output": "510", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n4 11 20 20\n6 11 20 16\n5 2 19 15\n11 3 18 15\n3 2 14 11", "output": "694", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 1 1 100\n1 1 1 100\n1 1 1 100\n1 1 1 100\n1 1 1 100", "output": "500", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
831
Solve the following coding problem using the programming language python: Array of integers is unimodal, if: - it is strictly increasing in the beginning; - after that it is constant; - after that it is strictly decreasing. The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent. For example, the following three arrays are unimodal: [5,<=7,<=11,<=11,<=2,<=1], [4,<=4,<=2], [7], but the following three are not unimodal: [5,<=5,<=6,<=6,<=1], [1,<=2,<=1,<=2], [4,<=5,<=5,<=6]. Write a program that checks if an array is unimodal. The input will be provided via standard input and looks as follows: The first line contains integer *n* (1<=≀<=*n*<=≀<=100) β€” the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=1<=000) β€” the elements of the array. You should write the solution as standard output as follows: Print "YES" if the given array is unimodal. Otherwise, print "NO". You can output each letter in any case (upper or lower). Here are example inputs and outputs for the problem: Example Input 1: 6 1 5 5 5 4 2 Example Output 1: YES Example Input 2: 5 10 20 30 20 10 Example Output 2: YES Example Input 3: 4 1 2 1 2 Example Output 3: NO Example Input 4: 7 3 3 3 3 3 3 3 Example Output 4: YES Now solve the problem by providing the code.
# -*- coding: utf-8 -*- """831.ipynb Automatically generated by Colaboratory. Original file is located at https://colab.research.google.com/drive/1hYxPSks58iBj6lqO-ZFgsg_7bcRbm3l3 """ #https://codeforces.com/contest/831/problem/A Unimodal Array a=int(input()) b=list(map(int,input().split())) i=1 while i<a and b[i-1]<b[i]: i+=1 while i<a and b[i-1]==b[i]: i+=1 while i<a and b[i-1]>b[i]: i+=1 if i==a: print("Yes") else: print("No")
vfc_83069
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n1 5 5 5 4 2", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n10 20 30 20 10", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 2 1 2", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n3 3 3 3 3 3 3", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n5 7 11 11 2 1", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n7", "output": "YES", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
262
Solve the following coding problem using the programming language python: Roma (a popular Russian name that means 'Roman') loves the Little Lvov Elephant's lucky numbers. Let us remind you that lucky numbers are positive integers whose decimal representation only contains lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Roma's got *n* positive integers. He wonders, how many of those integers have not more than *k* lucky digits? Help him, write the program that solves the problem. The input will be provided via standard input and looks as follows: The first line contains two integers *n*, *k* (1<=≀<=*n*,<=*k*<=≀<=100). The second line contains *n* integers *a**i* (1<=≀<=*a**i*<=≀<=109) β€” the numbers that Roma has. The numbers in the lines are separated by single spaces. You should write the solution as standard output as follows: In a single line print a single integer β€” the answer to the problem. Here are example inputs and outputs for the problem: Example Input 1: 3 4 1 2 4 Example Output 1: 3 Example Input 2: 3 2 447 44 77 Example Output 2: 2 Now solve the problem by providing the code.
[n, k] = [int(x) for x in input().split()] L = [x for x in input().split()] c = 0 for i in L: if i.count('4') + i.count('7') <= k: c += 1 print(c)
vfc_83073
{ "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 4\n1 2 4", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2\n447 44 77", "output": "2", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
158
Solve the following coding problem using the programming language python: After the lessons *n* groups of schoolchildren went outside and decided to visit Polycarpus to celebrate his birthday. We know that the *i*-th group consists of *s**i* friends (1<=≀<=*s**i*<=≀<=4), and they want to go to Polycarpus together. They decided to get there by taxi. Each car can carry at most four passengers. What minimum number of cars will the children need if all members of each group should ride in the same taxi (but one taxi can take more than one group)? The input will be provided via standard input and looks as follows: The first line contains integer *n* (1<=≀<=*n*<=≀<=105) β€” the number of groups of schoolchildren. The second line contains a sequence of integers *s*1,<=*s*2,<=...,<=*s**n* (1<=≀<=*s**i*<=≀<=4). The integers are separated by a space, *s**i* is the number of children in the *i*-th group. You should write the solution as standard output as follows: Print the single number β€” the minimum number of taxis necessary to drive all children to Polycarpus. Here are example inputs and outputs for the problem: Example Input 1: 5 1 2 4 3 3 Example Output 1: 4 Example Input 2: 8 2 3 4 4 2 1 3 1 Example Output 2: 5 Now solve the problem by providing the code.
def min_taxis(groups): counts = [groups.count(i) for i in range(1, 5)] return counts[3] + counts[2] + (counts[1]*2 + max(0, counts[0] - counts[2]) + 3) // 4 # ΠŸΡ€ΠΈΠΌΠ΅Ρ€ использования n = int(input()) groups = list(map(int, input().split())) result = min_taxis(groups) print(result)
vfc_83077
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "3000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 2 4 3 3", "output": "4", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
592
Solve the following coding problem using the programming language python: Galois is one of the strongest chess players of Byteforces. He has even invented a new variant of chess, which he named Β«PawnChessΒ». This new game is played on a board consisting of 8 rows and 8 columns. At the beginning of every game some black and white pawns are placed on the board. The number of black pawns placed is not necessarily equal to the number of white pawns placed. Lets enumerate rows and columns with integers from 1 to 8. Rows are numbered from top to bottom, while columns are numbered from left to right. Now we denote as (*r*,<=*c*) the cell located at the row *r* and at the column *c*. There are always two players A and B playing the game. Player A plays with white pawns, while player B plays with black ones. The goal of player A is to put any of his pawns to the row 1, while player B tries to put any of his pawns to the row 8. As soon as any of the players completes his goal the game finishes immediately and the succeeded player is declared a winner. Player A moves first and then they alternate turns. On his move player A must choose exactly one white pawn and move it one step upward and player B (at his turn) must choose exactly one black pawn and move it one step down. Any move is possible only if the targeted cell is empty. It's guaranteed that for any scenario of the game there will always be at least one move available for any of the players. Moving upward means that the pawn located in (*r*,<=*c*) will go to the cell (*r*<=-<=1,<=*c*), while moving down means the pawn located in (*r*,<=*c*) will go to the cell (*r*<=+<=1,<=*c*). Again, the corresponding cell must be empty, i.e. not occupied by any other pawn of any color. Given the initial disposition of the board, determine who wins the game if both players play optimally. Note that there will always be a winner due to the restriction that for any game scenario both players will have some moves available. The input will be provided via standard input and looks as follows: The input consists of the board description given in eight lines, each line contains eight characters. Character 'B' is used to denote a black pawn, and character 'W' represents a white pawn. Empty cell is marked with '.'. It's guaranteed that there will not be white pawns on the first row neither black pawns on the last row. You should write the solution as standard output as follows: Print 'A' if player A wins the game on the given board, and 'B' if player B will claim the victory. Again, it's guaranteed that there will always be a winner on the given board. Here are example inputs and outputs for the problem: Example Input 1: ........ ........ .B....B. ....W... ........ ..W..... ........ ........ Example Output 1: A Example Input 2: ..B..... ..W..... ......B. ........ .....W.. ......B. ........ ........ Example Output 2: B Now solve the problem by providing the code.
grid = [] for k in range(8): grid.append(input()) bbc = [] #blocked black columns bwc = [] #blocked white columns #first processing : downwards white = 8 for k in range(8): for j in range(8): if grid[k][j] == "B": bbc.append(j) if grid[k][j] == "W" and not j in bbc and white == 8: white = k black = 8 for k in range(7,-1,-1): for j in range(8): if grid[k][j] == "W": bwc.append(j) if grid[k][j] == "B" and not j in bwc and black == 8: black = 7-k if white <= black: print("A") else: print("B")
vfc_83081
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": ".BB.B.B.\nB..B..B.\n.B.BB...\nBB.....B\nBBB....B\nB..BB...\nBB.B...B\n....WWW.", "output": "B", "type": "stdin_stdout" }, { "fn_name": null, "input": "B.B.BB.B\nW.WWW.WW\n.WWWWW.W\nW.BB.WBW\n.W..BBWB\nBB.WWBBB\n.W.W.WWB\nWWW..WW.", "output": "A", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
732
Solve the following coding problem using the programming language python: Polycarp urgently needs a shovel! He comes to the shop and chooses an appropriate one. The shovel that Policarp chooses is sold for *k* burles. Assume that there is an unlimited number of such shovels in the shop. In his pocket Polycarp has an unlimited number of "10-burle coins" and exactly one coin of *r* burles (1<=≀<=*r*<=≀<=9). What is the minimum number of shovels Polycarp has to buy so that he can pay for the purchase without any change? It is obvious that he can pay for 10 shovels without any change (by paying the requied amount of 10-burle coins and not using the coin of *r* burles). But perhaps he can buy fewer shovels and pay without any change. Note that Polycarp should buy at least one shovel. The input will be provided via standard input and looks as follows: The single line of input contains two integers *k* and *r* (1<=≀<=*k*<=≀<=1000, 1<=≀<=*r*<=≀<=9)Β β€” the price of one shovel and the denomination of the coin in Polycarp's pocket that is different from "10-burle coins". Remember that he has an unlimited number of coins in the denomination of 10, that is, Polycarp has enough money to buy any number of shovels. You should write the solution as standard output as follows: Print the required minimum number of shovels Polycarp has to buy so that he can pay for them without any change. Here are example inputs and outputs for the problem: Example Input 1: 117 3 Example Output 1: 9 Example Input 2: 237 7 Example Output 2: 1 Example Input 3: 15 2 Example Output 3: 2 Now solve the problem by providing the code.
inp = input().split() inp = [int(x) for x in inp] a=0 for i in range(15): if(i>0): if(inp[0]%10==0 or (inp[0]-inp[1])%10==0 or ((inp[0]*i)-inp[1])%10==0 or (inp[0]*i)%10==0):# : a=i break print(a)
vfc_83089
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "117 3", "output": "9", "type": "stdin_stdout" }, { "fn_name": null, "input": "237 7", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "15 2", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
441
Solve the following coding problem using the programming language python: Valera is a collector. Once he wanted to expand his collection with exactly one antique item. Valera knows *n* sellers of antiques, the *i*-th of them auctioned *k**i* items. Currently the auction price of the *j*-th object of the *i*-th seller is *s**ij*. Valera gets on well with each of the *n* sellers. He is perfectly sure that if he outbids the current price of one of the items in the auction (in other words, offers the seller the money that is strictly greater than the current price of the item at the auction), the seller of the object will immediately sign a contract with him. Unfortunately, Valera has only *v* units of money. Help him to determine which of the *n* sellers he can make a deal with. The input will be provided via standard input and looks as follows: The first line contains two space-separated integers *n*,<=*v* (1<=≀<=*n*<=≀<=50;Β 104<=≀<=*v*<=≀<=106) β€” the number of sellers and the units of money the Valera has. Then *n* lines follow. The *i*-th line first contains integer *k**i* (1<=≀<=*k**i*<=≀<=50) the number of items of the *i*-th seller. Then go *k**i* space-separated integers *s**i*1,<=*s**i*2,<=...,<=*s**ik**i* (104<=≀<=*s**ij*<=≀<=106) β€” the current prices of the items of the *i*-th seller. You should write the solution as standard output as follows: In the first line, print integer *p* β€” the number of sellers with who Valera can make a deal. In the second line print *p* space-separated integers *q*1,<=*q*2,<=...,<=*q**p* (1<=≀<=*q**i*<=≀<=*n*) β€” the numbers of the sellers with who Valera can make a deal. Print the numbers of the sellers in the increasing order. Here are example inputs and outputs for the problem: Example Input 1: 3 50000 1 40000 2 20000 60000 3 10000 70000 190000 Example Output 1: 3 1 2 3 Example Input 2: 3 50000 1 50000 3 100000 120000 110000 3 120000 110000 120000 Example Output 2: 0 Now solve the problem by providing the code.
a,b=map(int,input().split());k=[] for i in range(1,a+1): c,*d=map(int,input().split()) if min(d)<b:k+=[i] print(len(k),"\n",*k)
vfc_83093
{ "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 50000\n1 40000\n2 20000 60000\n3 10000 70000 190000", "output": "3\n1 2 3", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 50000\n1 50000\n3 100000 120000 110000\n3 120000 110000 120000", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 100001\n1 895737\n1 541571", "output": "0", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
10
Solve the following coding problem using the programming language python: Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes *P*1 watt per minute. *T*1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts and power consumption changes to *P*2 watt per minute. Finally, after *T*2 minutes from the start of the screensaver, laptop switches to the "sleep" mode and consumes *P*3 watt per minute. If Tom moves the mouse or touches the keyboard when the laptop is in the second or in the third mode, it switches to the first (normal) mode. Tom's work with the laptop can be divided into *n* time periods [*l*1,<=*r*1],<=[*l*2,<=*r*2],<=...,<=[*l**n*,<=*r**n*]. During each interval Tom continuously moves the mouse and presses buttons on the keyboard. Between the periods Tom stays away from the laptop. Find out the total amount of power consumed by the laptop during the period [*l*1,<=*r**n*]. The input will be provided via standard input and looks as follows: The first line contains 6 integer numbers *n*, *P*1, *P*2, *P*3, *T*1, *T*2 (1<=≀<=*n*<=≀<=100,<=0<=≀<=*P*1,<=*P*2,<=*P*3<=≀<=100,<=1<=≀<=*T*1,<=*T*2<=≀<=60). The following *n* lines contain description of Tom's work. Each *i*-th of these lines contains two space-separated integers *l**i* and *r**i* (0<=≀<=*l**i*<=&lt;<=*r**i*<=≀<=1440, *r**i*<=&lt;<=*l**i*<=+<=1 for *i*<=&lt;<=*n*), which stand for the start and the end of the *i*-th period of work. You should write the solution as standard output as follows: Output the answer to the problem. Here are example inputs and outputs for the problem: Example Input 1: 1 3 2 1 5 10 0 10 Example Output 1: 30 Example Input 2: 2 8 4 2 5 10 20 30 50 100 Example Output 2: 570 Now solve the problem by providing the code.
n, P1, P2, P3, T1, T2=map(int,input().split()) s=0 for i in range(n): l,r=map(int,input().split()) if i==0: t=l if T1>=(l-t): s+=(l-t)*P1 else: s+=T1*P1 if T2>=(l-T1-t): s+=(l-T1-t)*P2 else: s+=T2*P2 s+=(l-T1-T2-t)*P3 s+=(r-l)*P1 t=r print(s)
vfc_83097
{ "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 3 2 1 5 10\n0 10", "output": "30", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 8 4 2 5 10\n20 30\n50 100", "output": "570", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 15 9 95 39 19\n873 989\n1003 1137\n1172 1436", "output": "8445", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
725
Solve the following coding problem using the programming language python: A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats 'd', 'e' and 'f' are located to the right. Seats 'a' and 'f' are located near the windows, while seats 'c' and 'd' are located near the aisle. Β  It's lunch time and two flight attendants have just started to serve food. They move from the first rows to the tail, always maintaining a distance of two rows from each other because of the food trolley. Thus, at the beginning the first attendant serves row 1 while the second attendant serves row 3. When both rows are done they move one row forward: the first attendant serves row 2 while the second attendant serves row 4. Then they move three rows forward and the first attendant serves row 5 while the second attendant serves row 7. Then they move one row forward again and so on. Flight attendants work with the same speed: it takes exactly 1 second to serve one passenger and 1 second to move one row forward. Each attendant first serves the passengers on the seats to the right of the aisle and then serves passengers on the seats to the left of the aisle (if one looks in the direction of the cockpit). Moreover, they always serve passengers in order from the window to the aisle. Thus, the first passenger to receive food in each row is located in seat 'f', and the last oneΒ β€” in seat 'c'. Assume that all seats are occupied. Vasya has seat *s* in row *n* and wants to know how many seconds will pass before he gets his lunch. The input will be provided via standard input and looks as follows: The only line of input contains a description of Vasya's seat in the format *ns*, where *n* (1<=≀<=*n*<=≀<=1018) is the index of the row and *s* is the seat in this row, denoted as letter from 'a' to 'f'. The index of the row and the seat are not separated by a space. You should write the solution as standard output as follows: Print one integerΒ β€” the number of seconds Vasya has to wait until he gets his lunch. Here are example inputs and outputs for the problem: Example Input 1: 1f Example Output 1: 1 Example Input 2: 2d Example Output 2: 10 Example Input 3: 4a Example Output 3: 11 Example Input 4: 5e Example Output 4: 18 Now solve the problem by providing the code.
c=input();n,s,d=int(c[:-1]),c[-1],{'a':4,'b':5,'c':6,'d':3,'e':2,'f':1} x=(n//4*2+(n-1)%2-2*(n%4==0))*6+d[s]+n print(x-1 if (n-1)%4<2 else x-3)
vfc_83101
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1f", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "2d", "output": "10", "type": "stdin_stdout" }, { "fn_name": null, "input": "4a", "output": "11", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
574
Solve the following coding problem using the programming language python: Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland. There are *n* candidates, including Limak. We know how many citizens are going to vote for each candidate. Now *i*-th candidate would get *a**i* votes. Limak is candidate number 1. To win in elections, he must get strictly more votes than any other candidate. Victory is more important than everything else so Limak decided to cheat. He will steal votes from his opponents by bribing some citizens. To bribe a citizen, Limak must give him or her one candy - citizens are bears and bears like candies. Limak doesn't have many candies and wonders - how many citizens does he have to bribe? The input will be provided via standard input and looks as follows: The first line contains single integer *n* (2<=≀<=*n*<=≀<=100) - number of candidates. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=1000) - number of votes for each candidate. Limak is candidate number 1. Note that after bribing number of votes for some candidate might be zero or might be greater than 1000. You should write the solution as standard output as follows: Print the minimum number of citizens Limak must bribe to have strictly more votes than any other candidate. Here are example inputs and outputs for the problem: Example Input 1: 5 5 1 11 2 8 Example Output 1: 4 Example Input 2: 4 1 8 8 8 Example Output 2: 6 Example Input 3: 2 7 6 Example Output 3: 0 Now solve the problem by providing the code.
n=int(input()) arr=list(map(int,input().split())) t=ans=arr.pop(0) mx=max(arr) i=1 while (ans)<=mx: ans+=1 arr.remove(mx) arr.append(mx-1) mx=max(arr) print(ans-t)
vfc_83105
{ "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\n5 1 11 2 8", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 8 8 8", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n7 6", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 1", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n100 200 57 99 1 1000 200 200 200 500", "output": "451", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
266
Solve the following coding problem using the programming language python: There are *n* stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if there are no other stones between them. The input will be provided via standard input and looks as follows: The first line contains integer *n* (1<=≀<=*n*<=≀<=50) β€” the number of stones on the table. The next line contains string *s*, which represents the colors of the stones. We'll consider the stones in the row numbered from 1 to *n* from left to right. Then the *i*-th character *s* equals "R", if the *i*-th stone is red, "G", if it's green and "B", if it's blue. 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: 3 RRG Example Output 1: 1 Example Input 2: 5 RRRRR Example Output 2: 4 Example Input 3: 4 BRBG Example Output 3: 0 Now solve the problem by providing the code.
n = input() n = int(n) stones = input() ans = 0 for i in range(1, n): if stones[i] == stones[i-1]: ans = ans + 1 print(ans)
vfc_83109
{ "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\nRRG", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\nRRRRR", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\nBRBG", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\nB", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\nBG", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\nBGB", "output": "0", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
792
Solve the following coding problem using the programming language python: *n* children are standing in a circle and playing the counting-out game. Children are numbered clockwise from 1 to *n*. In the beginning, the first child is considered the leader. The game is played in *k* steps. In the *i*-th step the leader counts out *a**i* people in clockwise order, starting from the next person. The last one to be pointed at by the leader is eliminated, and the next player after him becomes the new leader. For example, if there are children with numbers [8,<=10,<=13,<=14,<=16] currently in the circle, the leader is child 13 and *a**i*<==<=12, then counting-out rhyme ends on child 16, who is eliminated. Child 8 becomes the leader. You have to write a program which prints the number of the child to be eliminated on every step. The input will be provided via standard input and looks as follows: The first line contains two integer numbers *n* and *k* (2<=≀<=*n*<=≀<=100, 1<=≀<=*k*<=≀<=*n*<=-<=1). The next line contains *k* integer numbers *a*1,<=*a*2,<=...,<=*a**k* (1<=≀<=*a**i*<=≀<=109). You should write the solution as standard output as follows: Print *k* numbers, the *i*-th one corresponds to the number of child to be eliminated at the *i*-th step. Here are example inputs and outputs for the problem: Example Input 1: 7 5 10 4 11 4 1 Example Output 1: 4 2 5 6 1 Example Input 2: 3 2 2 5 Example Output 2: 3 2 Now solve the problem by providing the code.
import sys input = sys.stdin.readline n, k = map(int, input().split()) l = sorted(list(range(1, n+1))) c = 0 t = [] for i in [int(j) for j in input().split()]: c = (c+i)%len(l) t.append(l[c]) l = l[:c]+l[c+1:] print(*t)
vfc_83113
{ "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 5\n10 4 11 4 1", "output": "4 2 5 6 1 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2\n2 5", "output": "3 2 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1\n1", "output": "2 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1\n2", "output": "1 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1\n3", "output": "2 ", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
412
Solve the following coding problem using the programming language python: The R1 company has recently bought a high rise building in the centre of Moscow for its main office. It's time to decorate the new office, and the first thing to do is to write the company's slogan above the main entrance to the building. The slogan of the company consists of *n* characters, so the decorators hung a large banner, *n* meters wide and 1 meter high, divided into *n* equal squares. The first character of the slogan must be in the first square (the leftmost) of the poster, the second character must be in the second square, and so on. Of course, the R1 programmers want to write the slogan on the poster themselves. To do this, they have a large (and a very heavy) ladder which was put exactly opposite the *k*-th square of the poster. To draw the *i*-th character of the slogan on the poster, you need to climb the ladder, standing in front of the *i*-th square of the poster. This action (along with climbing up and down the ladder) takes one hour for a painter. The painter is not allowed to draw characters in the adjacent squares when the ladder is in front of the *i*-th square because the uncomfortable position of the ladder may make the characters untidy. Besides, the programmers can move the ladder. In one hour, they can move the ladder either a meter to the right or a meter to the left. Drawing characters and moving the ladder is very tiring, so the programmers want to finish the job in as little time as possible. Develop for them an optimal poster painting plan! The input will be provided via standard input and looks as follows: The first line contains two integers, *n* and *k* (1<=≀<=*k*<=≀<=*n*<=≀<=100) β€” the number of characters in the slogan and the initial position of the ladder, correspondingly. The next line contains the slogan as *n* characters written without spaces. Each character of the slogan is either a large English letter, or digit, or one of the characters: '.', '!', ',', '?'. You should write the solution as standard output as follows: In *t* lines, print the actions the programmers need to make. In the *i*-th line print: - "LEFT" (without the quotes), if the *i*-th action was "move the ladder to the left"; - "RIGHT" (without the quotes), if the *i*-th action was "move the ladder to the right"; - "PRINT *x*" (without the quotes), if the *i*-th action was to "go up the ladder, paint character *x*, go down the ladder". The painting time (variable *t*) must be minimum possible. If there are multiple optimal painting plans, you can print any of them. Here are example inputs and outputs for the problem: Example Input 1: 2 2 R1 Example Output 1: PRINT 1 LEFT PRINT R Example Input 2: 2 1 R1 Example Output 2: PRINT R RIGHT PRINT 1 Example Input 3: 6 4 GO?GO! Example Output 3: RIGHT RIGHT PRINT ! LEFT PRINT O LEFT PRINT G LEFT PRINT ? LEFT PRINT O LEFT PRINT G Now solve the problem by providing the code.
n,k=map(int,input('').split()) lozung=list(input()) if n-k<k: for i in range(k,n): print('RIGHT') for i in reversed(range(0,n)): print ('PRINT ',lozung[i]) if i!=0:print('LEFT') else: # print('2') for i in reversed(range(0,k-1)): print('LEFT') for i in range(n): print ('PRINT ',lozung[i]) if i!=n-1:print('RIGHT')
vfc_83117
{ "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\nR1", "output": "PRINT 1\nLEFT\nPRINT R", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
847
Solve the following coding problem using the programming language python: Vasya came up with his own weather forecasting method. He knows the information about the average air temperature for each of the last *n* days. Assume that the average air temperature for each day is integral. Vasya believes that if the average temperatures over the last *n* days form an arithmetic progression, where the first term equals to the average temperature on the first day, the second term equals to the average temperature on the second day and so on, then the average temperature of the next (*n*<=+<=1)-th day will be equal to the next term of the arithmetic progression. Otherwise, according to Vasya's method, the temperature of the (*n*<=+<=1)-th day will be equal to the temperature of the *n*-th day. Your task is to help Vasya predict the average temperature for tomorrow, i. e. for the (*n*<=+<=1)-th day. The input will be provided via standard input and looks as follows: The first line contains a single integer *n* (2<=≀<=*n*<=≀<=100) β€” the number of days for which the average air temperature is known. The second line contains a sequence of integers *t*1,<=*t*2,<=...,<=*t**n* (<=-<=1000<=≀<=*t**i*<=≀<=1000)Β β€” where *t**i* is the average temperature in the *i*-th day. You should write the solution as standard output as follows: Print the average air temperature in the (*n*<=+<=1)-th day, which Vasya predicts according to his method. Note that the absolute value of the predicted temperature can exceed 1000. Here are example inputs and outputs for the problem: Example Input 1: 5 10 5 0 -5 -10 Example Output 1: -15 Example Input 2: 4 1 1 1 1 Example Output 2: 1 Example Input 3: 3 5 1 -5 Example Output 3: -5 Example Input 4: 2 900 1000 Example Output 4: 1100 Now solve the problem by providing the code.
n = int(input()) vals = list(map(int,(input().split()))) arith = True diff = vals[0]-vals[1] for i in range(n-1): if vals[i]-vals[i+1]!=diff: arith = False break if arith: print(vals[-1]-diff) else: print(vals[-1])
vfc_83121
{ "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\n10 5 0 -5 -10", "output": "-15", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 1 1 1", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n5 1 -5", "output": "-5", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n900 1000", "output": "1100", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 2", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2 5 8", "output": "11", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
976
Solve the following coding problem using the programming language python: String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001". You are given a correct string *s*. You can perform two different operations on this string: 1. swap any pair of adjacent characters (for example, "101" "110"); 1. replace "11" with "1" (for example, "110" "10"). Let *val*(*s*) be such a number that *s* is its binary representation. Correct string *a* is less than some other correct string *b* iff *val*(*a*)<=&lt;<=*val*(*b*). Your task is to find the minimum correct string that you can obtain from the given one using the operations described above. You can use these operations any number of times in any order (or even use no operations at all). The input will be provided via standard input and looks as follows: The first line contains integer number *n* (1<=≀<=*n*<=≀<=100) β€” the length of string *s*. The second line contains the string *s* consisting of characters "0" and "1". It is guaranteed that the string *s* is correct. You should write the solution as standard output as follows: Print one string β€” the minimum correct string that you can obtain from the given one. Here are example inputs and outputs for the problem: Example Input 1: 4 1001 Example Output 1: 100 Example Input 2: 1 1 Example Output 2: 1 Now solve the problem by providing the code.
def solve(): size = input() s = input() print('1' * ('1' in s) + '0' * s.count('0')) if __name__ == "__main__": solve()
vfc_83125
{ "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\n1001", "output": "100", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\n1110111100001111011111111010110011111111011110000111101101011100110110001011000000101010110101011100", "output": "1000000000000000000000000000000000000000", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\n1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\n1111111111111111111111111111111111111111111111111111111110111111111111111111111111111111111111111111", "output": "10", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
844
Solve the following coding problem using the programming language python: Calculate the minimum number of characters you need to change in the string *s*, so that it contains at least *k* different letters, or print that it is impossible. String *s* consists only of lowercase Latin letters, and it is allowed to change characters only to lowercase Latin letters too. The input will be provided via standard input and looks as follows: First line of input contains string *s*, consisting only of lowercase Latin letters (1<=≀<=|*s*|<=≀<=1000, |*s*| denotes the length of *s*). Second line of input contains integer *k* (1<=≀<=*k*<=≀<=26). You should write the solution as standard output as follows: Print single line with a minimum number of necessary changes, or the word Β«impossibleΒ» (without quotes) if it is impossible. Here are example inputs and outputs for the problem: Example Input 1: yandex 6 Example Output 1: 0 Example Input 2: yahoo 5 Example Output 2: 1 Example Input 3: google 7 Example Output 3: impossible Now solve the problem by providing the code.
s = input() x = int(input()) if x > len(s): print('impossible') elif x < len(set(s)): print(0) else: print(x - len(set(s)))
vfc_83129
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "yandex\n6", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "yahoo\n5", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
336
Solve the following coding problem using the programming language python: Vasily the bear has a favorite rectangle, it has one vertex at point (0,<=0), and the opposite vertex at point (*x*,<=*y*). Of course, the sides of Vasya's favorite rectangle are parallel to the coordinate axes. Vasya also loves triangles, if the triangles have one vertex at point *B*<==<=(0,<=0). That's why today he asks you to find two points *A*<==<=(*x*1,<=*y*1) and *C*<==<=(*x*2,<=*y*2), such that the following conditions hold: - the coordinates of points: *x*1, *x*2, *y*1, *y*2 are integers. Besides, the following inequation holds: *x*1<=&lt;<=*x*2; - the triangle formed by point *A*, *B* and *C* is rectangular and isosceles ( is right); - all points of the favorite rectangle are located inside or on the border of triangle *ABC*; - the area of triangle *ABC* is as small as possible. Help the bear, find the required points. It is not so hard to proof that these points are unique. The input will be provided via standard input and looks as follows: The first line contains two integers *x*,<=*y* (<=-<=109<=≀<=*x*,<=*y*<=≀<=109,<=*x*<=β‰ <=0,<=*y*<=β‰ <=0). You should write the solution as standard output as follows: Print in the single line four integers *x*1,<=*y*1,<=*x*2,<=*y*2 β€” the coordinates of the required points. Here are example inputs and outputs for the problem: Example Input 1: 10 5 Example Output 1: 0 15 15 0 Example Input 2: -10 5 Example Output 2: -15 0 0 15 Now solve the problem by providing the code.
n=input().split() x,y=int(n[0]),int(n[1]) if x>0 and y>0: print(0,x+y,x+y,0) elif x>0 and y<0: print(0,y-x,x-y,0) elif x<0 and y>0: print(x-y,0,0,y-x) else: print(x+y,0,0,x+y)
vfc_83133
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 5", "output": "0 15 15 0", "type": "stdin_stdout" }, { "fn_name": null, "input": "-10 5", "output": "-15 0 0 15", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
862
Solve the following coding problem using the programming language python: Dr. Evil kidnapped Mahmoud and Ehab in the evil land because of their performance in the Evil Olympiad in Informatics (EOI). He decided to give them some problems to let them go. Dr. Evil is interested in sets, He has a set of *n* integers. Dr. Evil calls a set of integers evil if the MEX of it is exactly *x*. the MEX of a set of integers is the minimum non-negative integer that doesn't exist in it. For example, the MEX of the set {0,<=2,<=4} is 1 and the MEX of the set {1,<=2,<=3} is 0 . Dr. Evil is going to make his set evil. To do this he can perform some operations. During each operation he can add some non-negative integer to his set or erase some element from it. What is the minimal number of operations Dr. Evil has to perform to make his set evil? The input will be provided via standard input and looks as follows: The first line contains two integers *n* and *x* (1<=≀<=*n*<=≀<=100, 0<=≀<=*x*<=≀<=100)Β β€” the size of the set Dr. Evil owns, and the desired MEX. The second line contains *n* distinct non-negative integers not exceeding 100 that represent the set. You should write the solution as standard output as follows: The only line should contain one integerΒ β€” the minimal number of operations Dr. Evil should perform. Here are example inputs and outputs for the problem: Example Input 1: 5 3 0 4 5 6 7 Example Output 1: 2 Example Input 2: 1 0 0 Example Output 2: 1 Example Input 3: 5 0 1 2 3 4 5 Example Output 3: 0 Now solve the problem by providing the code.
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n, x = map(int, input().split()) a = list(map(int, input().split())) l = 105 cnt = [0] * l for i in a: cnt[i] += 1 ans = 0 for i in range(x): if not cnt[i]: ans += 1 ans += cnt[x] print(ans)
vfc_83137
{ "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\n0 4 5 6 7", "output": "2", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
327
Solve the following coding problem using the programming language python: Iahub got bored, so he invented a game to be played on paper. He writes *n* integers *a*1,<=*a*2,<=...,<=*a**n*. Each of those integers can be either 0 or 1. He's allowed to do exactly one move: he chooses two indices *i* and *j* (1<=≀<=*i*<=≀<=*j*<=≀<=*n*) and flips all values *a**k* for which their positions are in range [*i*,<=*j*] (that is *i*<=≀<=*k*<=≀<=*j*). Flip the value of *x* means to apply operation *x*<==<=1 - *x*. The goal of the game is that after exactly one move to obtain the maximum number of ones. Write a program to solve the little game of Iahub. The input will be provided via standard input and looks as follows: The first line of the input contains an integer *n* (1<=≀<=*n*<=≀<=100). In the second line of the input there are *n* integers: *a*1,<=*a*2,<=...,<=*a**n*. It is guaranteed that each of those *n* values is either 0 or 1. You should write the solution as standard output as follows: Print an integer β€” the maximal number of 1s that can be obtained after exactly one move. Here are example inputs and outputs for the problem: Example Input 1: 5 1 0 0 1 0 Example Output 1: 4 Example Input 2: 4 1 0 0 1 Example Output 2: 4 Now solve the problem by providing the code.
n = int(input()) a = list(map(int, input().split())) max_ones = 0 for i in range(n): for j in range(i, n): temp = a.copy() for k in range(i, j+1): temp[k] = 1 - temp[k] max_ones = max(max_ones, temp.count(1)) print(max_ones)
vfc_83141
{ "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\n1 0 0 1 0", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 0 0 1", "output": "4", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
962
Solve the following coding problem using the programming language python: Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first. On the $i$-th day Polycarp will necessarily solve $a_i$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems. Determine the index of day when Polycarp will celebrate the equator. The input will be provided via standard input and looks as follows: The first line contains a single integer $n$ ($1 \le n \le 200\,000$) β€” the number of days to prepare for the programming contests. The second line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10\,000$), where $a_i$ equals to the number of problems, which Polycarp will solve on the $i$-th day. You should write the solution as standard output as follows: Print the index of the day when Polycarp will celebrate the equator. Here are example inputs and outputs for the problem: Example Input 1: 4 1 3 2 1 Example Output 1: 2 Example Input 2: 6 2 2 2 2 2 2 Example Output 2: 3 Now solve the problem by providing the code.
#k=int(input()) #n,m=map(int,input().split()) import sys #a=list(map(int,input().split())) #b=list(map(int,input().split())) import math n=int(input()) a=list(map(int,input().split())) ss=sum(a); s=0 for i in range(n): s+=a[i] if(2*s>=ss): print(i+1) sys.exit()
vfc_83145
{ "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\n1 3 2 1", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n2 2 2 2 2 2", "output": "3", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
111
Solve the following coding problem using the programming language python: Little Petya loves inequations. Help him find *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*, such that the following two conditions are satisfied: - *a*12<=+<=*a*22<=+<=...<=+<=*a**n*2<=β‰₯<=*x*- *a*1<=+<=*a*2<=+<=...<=+<=*a**n*<=≀<=*y* The input will be provided via standard input and looks as follows: The first line contains three space-separated integers *n*, *x* and *y* (1<=≀<=*n*<=≀<=105,<=1<=≀<=*x*<=≀<=1012,<=1<=≀<=*y*<=≀<=106). Please do not use the %lld specificator to read or write 64-bit integers in Π‘++. It is recommended to use cin, cout streams or the %I64d specificator. You should write the solution as standard output as follows: Print *n* positive integers that satisfy the conditions, one integer per line. If such numbers do not exist, print a single number "-1". If there are several solutions, print any of them. Here are example inputs and outputs for the problem: Example Input 1: 5 15 15 Example Output 1: 4 4 1 1 2 Example Input 2: 2 3 2 Example Output 2: -1 Example Input 3: 1 99 11 Example Output 3: 11 Now solve the problem by providing the code.
n,x,y=map(int,input().split()) import math an=n-1 if(x<=n-1): if(y>=n): for i in range(n): print(1) else: print(-1) else: me=math.sqrt(x-an) if(me==int(me)): me=int(me) if(me+an<=y): for i in range(n-1): print(1) print(me) else: print(-1) else: me=int(me) me+=1 if(me+an<=y): for i in range(n-1): print(1) print(me) else: print(-1)
vfc_83149
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "5000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 15 15", "output": "11\n1\n1\n1\n1", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3 2", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 99 11", "output": "11", "type": "stdin_stdout" }, { "fn_name": null, "input": "100000 810000099998 1000000", "output": "900001\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n...", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
157
Solve the following coding problem using the programming language python: One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides, any two neighboring parts were painted different colors, that is, the red and the blue color were alternating, i. e. followed one after the other. The outer area of the wall (the area that lied outside all circles) was painted blue. Help Sherlock Holmes determine the total area of red parts of the wall. Let us remind you that two circles are called concentric if their centers coincide. Several circles are called concentric if any two of them are concentric. The input will be provided via standard input and looks as follows: The first line contains the single integer *n* (1<=≀<=*n*<=≀<=100). The second line contains *n* space-separated integers *r**i* (1<=≀<=*r**i*<=≀<=1000) β€” the circles' radii. It is guaranteed that all circles are different. You should write the solution as standard output as follows: Print the single real number β€” total area of the part of the wall that is painted red. The answer is accepted if absolute or relative error doesn't exceed 10<=-<=4. Here are example inputs and outputs for the problem: Example Input 1: 1 1 Example Output 1: 3.1415926536 Example Input 2: 3 1 4 2 Example Output 2: 40.8407044967 Now solve the problem by providing the code.
# Description of the problem can be found at http://codeforces.com/problemset/problem/157/B import math n = int(input()) l_s = list(map(int, input().split())) l_s.sort(reverse = True) t = 0 for index in range(n): t += (-1 if index % 2 == 1 else 1) * l_s[index] ** 2 print(t * math.pi)
vfc_83153
{ "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\n1", "output": "3.1415926536", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 4 2", "output": "40.8407044967", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n4 1 3 2", "output": "31.4159265359", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n100 10 2 1", "output": "31111.1920484997", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n10 9 8 7 6 5 4 3 2 1", "output": "172.7875959474", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
938
Solve the following coding problem using the programming language python: Victor tries to write his own text editor, with word correction included. However, the rules of word correction are really strange. Victor thinks that if a word contains two consecutive vowels, then it's kinda weird and it needs to be replaced. So the word corrector works in such a way: as long as there are two consecutive vowels in the word, it deletes the first vowel in a word such that there is another vowel right before it. If there are no two consecutive vowels in the word, it is considered to be correct. You are given a word *s*. Can you predict what will it become after correction? In this problem letters a, e, i, o, u and y are considered to be vowels. The input will be provided via standard input and looks as follows: The first line contains one integer *n* (1<=≀<=*n*<=≀<=100) β€” the number of letters in word *s* before the correction. The second line contains a string *s* consisting of exactly *n* lowercase Latin letters β€” the word before the correction. You should write the solution as standard output as follows: Output the word *s* after the correction. Here are example inputs and outputs for the problem: Example Input 1: 5 weird Example Output 1: werd Example Input 2: 4 word Example Output 2: word Example Input 3: 5 aaeaa Example Output 3: a Now solve the problem by providing the code.
vowels = ['a', 'e', 'i', 'o', 'u', 'y'] def word_correction(s): result = [] result.append(s[0]) left = 0 right = 1 while right < len(s): if not s[left] in vowels or not s[right] in vowels: result.append(s[right]) left = right right += 1 return ''.join(result) n = int(input()) s = input() print(word_correction(s))
vfc_83157
{ "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\nweird", "output": "werd", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\nword", "output": "word", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\naaeaa", "output": "a", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
13
Solve the following coding problem using the programming language python: Little Petya likes numbers a lot. He found that number 123 in base 16 consists of two digits: the first is 7 and the second is 11. So the sum of digits of 123 in base 16 is equal to 18. Now he wonders what is an average value of sum of digits of the number *A* written in all bases from 2 to *A*<=-<=1. Note that all computations should be done in base 10. You should find the result as an irreducible fraction, written in base 10. The input will be provided via standard input and looks as follows: Input contains one integer number *A* (3<=≀<=*A*<=≀<=1000). You should write the solution as standard output as follows: Output should contain required average value in format Β«X/YΒ», where X is the numerator and Y is the denominator. Here are example inputs and outputs for the problem: Example Input 1: 5 Example Output 1: 7/3 Example Input 2: 3 Example Output 2: 2/1 Now solve the problem by providing the code.
N = int(input()) s = 0 def gcd(a, b): while(b): a, b = b, a%b return a for i in range(2, N): n = N while(n>0): s += n%i n = n//i t = gcd(s, N-2) print(str(s//t)+"/"+str((N-2)//t))
vfc_83165
{ "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": "7/3", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
169
Solve the following coding problem using the programming language python: Petya and Vasya are brothers. Today is a special day for them as their parents left them home alone and commissioned them to do *n* chores. Each chore is characterized by a single parameter β€” its complexity. The complexity of the *i*-th chore equals *h**i*. As Petya is older, he wants to take the chores with complexity larger than some value *x* (*h**i*<=&gt;<=*x*) to leave to Vasya the chores with complexity less than or equal to *x* (*h**i*<=≀<=*x*). The brothers have already decided that Petya will do exactly *a* chores and Vasya will do exactly *b* chores (*a*<=+<=*b*<==<=*n*). In how many ways can they choose an integer *x* so that Petya got exactly *a* chores and Vasya got exactly *b* chores? The input will be provided via standard input and looks as follows: The first input line contains three integers *n*,<=*a* and *b* (2<=≀<=*n*<=≀<=2000; *a*,<=*b*<=β‰₯<=1; *a*<=+<=*b*<==<=*n*) β€” the total number of chores, the number of Petya's chores and the number of Vasya's chores. The next line contains a sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≀<=*h**i*<=≀<=109), *h**i* is the complexity of the *i*-th chore. The numbers in the given sequence are not necessarily different. All numbers on the lines are separated by single spaces. You should write the solution as standard output as follows: Print the required number of ways to choose an integer value of *x*. If there are no such ways, print 0. Here are example inputs and outputs for the problem: Example Input 1: 5 2 3 6 2 3 100 1 Example Output 1: 3 Example Input 2: 7 3 4 1 1 9 1 1 1 1 Example Output 2: 0 Now solve the problem by providing the code.
n,a,b= map(int,input().split()) x = list(map(int,input().split())) x.sort() print(x[b]-x[b-1])
vfc_83169
{ "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 3\n6 2 3 100 1", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 3 4\n1 1 9 1 1 1 1", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1 1\n10 2", "output": "8", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1 1\n7 7", "output": "0", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
712
Solve the following coding problem using the programming language python: There are *n* integers *b*1,<=*b*2,<=...,<=*b**n* written in a row. For all *i* from 1 to *n*, values *a**i* are defined by the crows performing the following procedure: - The crow sets *a**i* initially 0. - The crow then adds *b**i* to *a**i*, subtracts *b**i*<=+<=1, adds the *b**i*<=+<=2 number, and so on until the *n*'th number. Thus, *a**i*<==<=*b**i*<=-<=*b**i*<=+<=1<=+<=*b**i*<=+<=2<=-<=*b**i*<=+<=3.... Memory gives you the values *a*1,<=*a*2,<=...,<=*a**n*, and he now wants you to find the initial numbers *b*1,<=*b*2,<=...,<=*b**n* written in the row? Can you do it? The input will be provided via standard input and looks as follows: The first line of the input contains a single integer *n* (2<=≀<=*n*<=≀<=100<=000)Β β€” the number of integers written in the row. The next line contains *n*, the *i*'th of which is *a**i* (<=-<=109<=≀<=*a**i*<=≀<=109)Β β€” the value of the *i*'th number. You should write the solution as standard output as follows: Print *n* integers corresponding to the sequence *b*1,<=*b*2,<=...,<=*b**n*. It's guaranteed that the answer is unique and fits in 32-bit integer type. Here are example inputs and outputs for the problem: Example Input 1: 5 6 -4 8 -2 3 Example Output 1: 2 4 6 1 3 Example Input 2: 5 3 -2 -1 5 6 Example Output 2: 1 -3 4 11 6 Now solve the problem by providing the code.
n=int(input()) v=[int(i) for i in input().split()] b=[v[i]+v[i+1] for i in range(n-1)] b.append(v[-1]) for i in range(n): print(b[i],end=" ")
vfc_83173
{ "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\n6 -4 8 -2 3", "output": "2 4 6 1 3 ", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
761
Solve the following coding problem using the programming language python: On her way to programming school tiger Dasha faced her first test β€” a huge staircase! The steps were numbered from one to infinity. As we know, tigers are very fond of all striped things, it is possible that it has something to do with their color. So on some interval of her way she calculated two values β€” the number of steps with even and odd numbers. You need to check whether there is an interval of steps from the *l*-th to the *r*-th (1<=≀<=*l*<=≀<=*r*), for which values that Dasha has found are correct. The input will be provided via standard input and looks as follows: In the only line you are given two integers *a*, *b* (0<=≀<=*a*,<=*b*<=≀<=100) β€” the number of even and odd steps, accordingly. You should write the solution as standard output as follows: In the only line print "YES", if the interval of steps described above exists, and "NO" otherwise. Here are example inputs and outputs for the problem: Example Input 1: 2 3 Example Output 1: YES Example Input 2: 3 1 Example Output 2: NO Now solve the problem by providing the code.
n,m=map(int,input().split()) z=abs(n-m) if((z==0 and n!=0) or z==1): print("YES") else: print("NO")
vfc_83177
{ "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": "YES", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
20
Solve the following coding problem using the programming language python: The new operating system BerOS has a nice feature. It is possible to use any number of characters '/' as a delimiter in path instead of one traditional '/'. For example, strings //usr///local//nginx/sbin// and /usr/local/nginx///sbin are equivalent. The character '/' (or some sequence of such characters) at the end of the path is required only in case of the path to the root directory, which can be represented as single character '/'. A path called normalized if it contains the smallest possible number of characters '/'. Your task is to transform a given path to the normalized form. The input will be provided via standard input and looks as follows: The first line of the input contains only lowercase Latin letters and character '/'Β β€” the path to some directory. All paths start with at least one character '/'. The length of the given line is no more than 100 characters, it is not empty. You should write the solution as standard output as follows: The path in normalized form. Here are example inputs and outputs for the problem: Example Input 1: //usr///local//nginx/sbin Example Output 1: /usr/local/nginx/sbin Now solve the problem by providing the code.
print("/"+"/".join(filter(None, input().split("/"))))
vfc_83181
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "//usr///local//nginx/sbin", "output": "/usr/local/nginx/sbin", "type": "stdin_stdout" }, { "fn_name": null, "input": "////a//b/////g", "output": "/a/b/g", "type": "stdin_stdout" }, { "fn_name": null, "input": "/a/b/c", "output": "/a/b/c", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
199
Solve the following coding problem using the programming language python: Recently, a chaotic virus Hexadecimal advanced a new theorem which will shake the Universe. She thinks that each Fibonacci number can be represented as sum of three not necessary different Fibonacci numbers. Let's remember how Fibonacci numbers can be calculated. *F*0<==<=0, *F*1<==<=1, and all the next numbers are *F**i*<==<=*F**i*<=-<=2<=+<=*F**i*<=-<=1. So, Fibonacci numbers make a sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, ... If you haven't run away from the PC in fear, you have to help the virus. Your task is to divide given Fibonacci number *n* by three not necessary different Fibonacci numbers or say that it is impossible. The input will be provided via standard input and looks as follows: The input contains of a single integer *n* (0<=≀<=*n*<=&lt;<=109) β€” the number that should be represented by the rules described above. It is guaranteed that *n* is a Fibonacci number. You should write the solution as standard output as follows: Output three required numbers: *a*, *b* and *c*. If there is no answer for the test you have to print "I'm too stupid to solve this problem" without the quotes. If there are multiple answers, print any of them. Here are example inputs and outputs for the problem: Example Input 1: 3 Example Output 1: 1 1 1 Example Input 2: 13 Example Output 2: 2 3 8 Now solve the problem by providing the code.
n = int(input()) if n == 0: print(0, 0, 0) elif n == 1: print(0, 0, 1) elif n == 2: print(0, 1, 1) else: arr = [0, 1] i = 1 while True: m = arr[i]+arr[i-1] if m <= n: arr.append(m) i += 1 else: break print(arr[-2], arr[-4], arr[-5])
vfc_83185
{ "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", "output": "1 1 1", "type": "stdin_stdout" }, { "fn_name": null, "input": "13", "output": "2 3 8", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
845
Solve the following coding problem using the programming language python: Berland annual chess tournament is coming! Organizers have gathered 2Β·*n* chess players who should be divided into two teams with *n* people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organizers should guarantee the win for the team of BerOil. Thus, organizers should divide all 2Β·*n* players into two teams with *n* people each in such a way that the first team always wins. Every chess player has its rating *r**i*. It is known that chess player with the greater rating always wins the player with the lower rating. If their ratings are equal then any of the players can win. After teams assignment there will come a drawing to form *n* pairs of opponents: in each pair there is a player from the first team and a player from the second team. Every chess player should be in exactly one pair. Every pair plays once. The drawing is totally random. Is it possible to divide all 2Β·*n* players into two teams with *n* people each so that the player from the first team in every pair wins regardless of the results of the drawing? The input will be provided via standard input and looks as follows: The first line contains one integer *n* (1<=≀<=*n*<=≀<=100). The second line contains 2Β·*n* integers *a*1,<=*a*2,<=... *a*2*n* (1<=≀<=*a**i*<=≀<=1000). You should write the solution as standard output as follows: If it's possible to divide all 2Β·*n* players into two teams with *n* people each so that the player from the first team in every pair wins regardless of the results of the drawing, then print "YES". Otherwise print "NO". Here are example inputs and outputs for the problem: Example Input 1: 2 1 3 2 4 Example Output 1: YES Example Input 2: 1 3 3 Example Output 2: NO Now solve the problem by providing the code.
n=int(input()) a=sorted(list(map(int,input().split()))) print('YES' if a[n-1]<a[n] else 'NO')
vfc_83189
{ "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 3 2 4", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n3 3", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 1 1 1 2 2 3 3 3 3", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 1 1 1 1 2 2 2 2 2", "output": "YES", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
915
Solve the following coding problem using the programming language python: Luba thinks about watering her garden. The garden can be represented as a segment of length *k*. Luba has got *n* buckets, the *i*-th bucket allows her to water some continuous subsegment of garden of length exactly *a**i* each hour. Luba can't water any parts of the garden that were already watered, also she can't water the ground outside the garden. Luba has to choose one of the buckets in order to water the garden as fast as possible (as mentioned above, each hour she will water some continuous subsegment of length *a**i* if she chooses the *i*-th bucket). Help her to determine the minimum number of hours she has to spend watering the garden. It is guaranteed that Luba can always choose a bucket so it is possible water the garden. See the examples for better understanding. The input will be provided via standard input and looks as follows: The first line of input contains two integer numbers *n* and *k* (1<=≀<=*n*,<=*k*<=≀<=100) β€” the number of buckets and the length of the garden, respectively. The second line of input contains *n* integer numbers *a**i* (1<=≀<=*a**i*<=≀<=100) β€” the length of the segment that can be watered by the *i*-th bucket in one hour. It is guaranteed that there is at least one bucket such that it is possible to water the garden in integer number of hours using only this bucket. You should write the solution as standard output as follows: Print one integer number β€” the minimum number of hours required to water the garden. Here are example inputs and outputs for the problem: Example Input 1: 3 6 2 3 5 Example Output 1: 2 Example Input 2: 6 7 1 2 3 4 5 6 Example Output 2: 7 Now solve the problem by providing the code.
def f(): num,k=map(int,input().split()) n=map(int, input().split()) maxi=0 ans=0 for i in n: if(k%i==0 and i>maxi): maxi=i ans=int(k/i) print(ans) f()
vfc_83193
{ "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 6\n2 3 5", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 7\n1 2 3 4 5 6", "output": "7", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 97\n1 10 50 97 2", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
540
Solve the following coding problem using the programming language python: Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock. The combination lock is represented by *n* rotating disks with digits from 0 to 9 written on them. Scrooge McDuck has to turn some disks so that the combination of digits on the disks forms a secret combination. In one move, he can rotate one disk one digit forwards or backwards. In particular, in one move he can go from digit 0 to digit 9 and vice versa. What minimum number of actions does he need for that? The input will be provided via standard input and looks as follows: The first line contains a single integer *n* (1<=≀<=*n*<=≀<=1000)Β β€” the number of disks on the combination lock. The second line contains a string of *n* digitsΒ β€” the original state of the disks. The third line contains a string of *n* digitsΒ β€” Scrooge McDuck's combination that opens the lock. You should write the solution as standard output as follows: Print a single integerΒ β€” the minimum number of moves Scrooge McDuck needs to open the lock. Here are example inputs and outputs for the problem: Example Input 1: 5 82195 64723 Example Output 1: 13 Now solve the problem by providing the code.
n = int(input()) comb1 = list(map(int, ' '.join(input()).split())) comb2 = list(map(int, ' '.join(input()).split())) count = 0 for i in range(n): a = abs(comb1[i] - comb2[i]) b = 10 - a count += min(a, b) print(count)
vfc_83197
{ "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\n82195\n64723", "output": "13", "type": "stdin_stdout" }, { "fn_name": null, "input": "12\n102021090898\n010212908089", "output": "16", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n8\n1", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n83\n57", "output": "7", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
669
Solve the following coding problem using the programming language python: Little Artem got *n* stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as possible. However, Masha remembers the last present she received, so Artem can't give her the same number of stones twice in a row. For example, he can give her 3 stones, then 1 stone, then again 3 stones, but he can't give her 3 stones and then again 3 stones right after that. How many times can Artem give presents to Masha? The input will be provided via standard input and looks as follows: The only line of the input contains a single integer *n* (1<=≀<=*n*<=≀<=109)Β β€” number of stones Artem received on his birthday. You should write the solution as standard output as follows: Print the maximum possible number of times Artem can give presents to Masha. Here are example inputs and outputs for the problem: Example Input 1: 1 Example Output 1: 1 Example Input 2: 2 Example Output 2: 1 Example Input 3: 3 Example Output 3: 2 Example Input 4: 4 Example Output 4: 3 Now solve the problem by providing the code.
a = int(input()) print(a // 3 * 2 + (a % 3 > 0))
vfc_83201
{ "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", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "2", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "3", "output": "2", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
192
Solve the following coding problem using the programming language python: As you very well know, this year's funkiest numbers are so called triangular numbers (that is, integers that are representable as , where *k* is some positive integer), and the coolest numbers are those that are representable as a sum of two triangular numbers. A well-known hipster Andrew adores everything funky and cool but unfortunately, he isn't good at maths. Given number *n*, help him define whether this number can be represented by a sum of two triangular numbers (not necessarily different)! The input will be provided via standard input and looks as follows: The first input line contains an integer *n* (1<=≀<=*n*<=≀<=109). You should write the solution as standard output as follows: Print "YES" (without the quotes), if *n* can be represented as a sum of two triangular numbers, otherwise print "NO" (without the quotes). Here are example inputs and outputs for the problem: Example Input 1: 256 Example Output 1: YES Example Input 2: 512 Example Output 2: NO Now solve the problem by providing the code.
import sys, os.path from collections import* from copy import* import math mod=10**9+7 if(os.path.exists('input.txt')): sys.stdin = open("input.txt","r") sys.stdout = open("output.txt","w") def bs(left,right,x): while(left<=right): mid=left+(right-left)//2 b=(mid*(mid+1))//2 if(b==x): return 1 elif(b>x): right=mid-1 else: left=mid+1 return 0 n=int(input()) n1=10**5 flag=0 for i in range(1,n1+1): a=(i*(i+1))//2 if(bs(1,n1,n-a)): flag=1 break if(flag==0): print('NO') else: print('YES')
vfc_83205
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "256", "output": "YES", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
214
Solve the following coding problem using the programming language python: Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you? You are given a system of equations: You should count, how many there are pairs of integers (*a*,<=*b*) (0<=≀<=*a*,<=*b*) which satisfy the system. The input will be provided via standard input and looks as follows: A single line contains two integers *n*,<=*m* (1<=≀<=*n*,<=*m*<=≀<=1000) β€” the parameters of the system. The numbers on the line are separated by a space. You should write the solution as standard output as follows: On a single line print the answer to the problem. Here are example inputs and outputs for the problem: Example Input 1: 9 3 Example Output 1: 1 Example Input 2: 14 28 Example Output 2: 1 Example Input 3: 4 20 Example Output 3: 0 Now solve the problem by providing the code.
import sys import math def function(): n, m = map(int, input().split()) ans = 0 for a in range(1001): for b in range(1001): if (a**2) + b == n and a + (b**2) == m: ans+=1 print(ans) return if __name__ == '__main__': function()
vfc_83209
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "9 3", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "14 28", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 20", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "18 198", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "22 326", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
63
Solve the following coding problem using the programming language python: The ship crashed into a reef and is sinking. Now the entire crew must be evacuated. All *n* crew members have already lined up in a row (for convenience let's label them all from left to right with positive integers from 1 to *n*) and await further instructions. However, one should evacuate the crew properly, in a strict order. Specifically: The first crew members to leave the ship are rats. Then women and children (both groups have the same priority) leave the ship. After that all men are evacuated from the ship. The captain leaves the sinking ship last. If we cannot determine exactly who should leave the ship first for any two members of the crew by the rules from the previous paragraph, then the one who stands to the left in the line leaves the ship first (or in other words, the one whose number in the line is less). For each crew member we know his status as a crew member, and also his name. All crew members have different names. Determine the order in which to evacuate the crew. The input will be provided via standard input and looks as follows: The first line contains an integer *n*, which is the number of people in the crew (1<=≀<=*n*<=≀<=100). Then follow *n* lines. The *i*-th of those lines contains two words β€” the name of the crew member who is *i*-th in line, and his status on the ship. The words are separated by exactly one space. There are no other spaces in the line. The names consist of Latin letters, the first letter is uppercase, the rest are lowercase. The length of any name is from 1 to 10 characters. The status can have the following values: rat for a rat, woman for a woman, child for a child, man for a man, captain for the captain. The crew contains exactly one captain. You should write the solution as standard output as follows: Print *n* lines. The *i*-th of them should contain the name of the crew member who must be the *i*-th one to leave the ship. Here are example inputs and outputs for the problem: Example Input 1: 6 Jack captain Alice woman Charlie man Teddy rat Bob child Julia woman Example Output 1: Teddy Alice Bob Julia Charlie Jack Now solve the problem by providing the code.
from functools import cmp_to_key class Info: def __init__(self, _id: int, _name: str, _status: str): self.id = _id self.name = _name self.status = _status def __str__(self): return f'id: {self.id}, name: {self.name}, status: {self.status}' def customCompare(obj1:Info, obj2:Info) -> int: if obj1.status != "rat" and obj2.status == "rat": return 1 if obj1.status == "rat" and obj2.status != "rat": return -1 if (obj1.status != "woman" and obj1.status != "child") and (obj2.status == "woman" or obj2.status == "child"): return 1 if (obj1.status == "woman" or obj1.status == "child") and (obj2.status != "woman" and obj2.status != "child"): return -1 if obj1.status != "man" and obj2.status == "man": return 1 if obj1.status == "man" and obj2.status != "man": return -1 return obj1.id - obj2.id def output(cont:list): for obj in cont: print(obj) n = int(input()) cont = [] for i in range(n): _name, _status = input().split() obj = Info(i + 1, _name, _status) cont.append(obj) cont.sort(key=cmp_to_key(customCompare)) for obj in cont: print(obj.name)
vfc_83213
{ "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\nJack captain\nAlice woman\nCharlie man\nTeddy rat\nBob child\nJulia woman", "output": "Teddy\nAlice\nBob\nJulia\nCharlie\nJack", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
638
Solve the following coding problem using the programming language python: The main street of Berland is a straight line with *n* houses built along it (*n* is an even number). The houses are located at both sides of the street. The houses with odd numbers are at one side of the street and are numbered from 1 to *n*<=-<=1 in the order from the beginning of the street to the end (in the picture: from left to right). The houses with even numbers are at the other side of the street and are numbered from 2 to *n* in the order from the end of the street to its beginning (in the picture: from right to left). The corresponding houses with even and odd numbers are strictly opposite each other, that is, house 1 is opposite house *n*, house 3 is opposite house *n*<=-<=2, house 5 is opposite house *n*<=-<=4 and so on. Vasya needs to get to house number *a* as quickly as possible. He starts driving from the beginning of the street and drives his car to house *a*. To get from the beginning of the street to houses number 1 and *n*, he spends exactly 1 second. He also spends exactly one second to drive the distance between two neighbouring houses. Vasya can park at any side of the road, so the distance between the beginning of the street at the houses that stand opposite one another should be considered the same. Your task is: find the minimum time Vasya needs to reach house *a*. The input will be provided via standard input and looks as follows: The first line of the input contains two integers, *n* and *a* (1<=≀<=*a*<=≀<=*n*<=≀<=100<=000)Β β€” the number of houses on the street and the number of the house that Vasya needs to reach, correspondingly. It is guaranteed that number *n* is even. You should write the solution as standard output as follows: Print a single integer β€” the minimum time Vasya needs to get from the beginning of the street to house *a*. Here are example inputs and outputs for the problem: Example Input 1: 4 2 Example Output 1: 2 Example Input 2: 8 5 Example Output 2: 3 Now solve the problem by providing the code.
n, a = [int(x) for x in input().split()] ans = 1 if a % 2 == 0: while n != a: n -= 2 ans += 1 else: t = 1 while t != a: t += 2 ans += 1 print(ans)
vfc_83217
{ "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", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "8 5", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
659
Solve the following coding problem using the programming language python: Vasya lives in a round building, whose entrances are numbered sequentially by integers from 1 to *n*. Entrance *n* and entrance 1 are adjacent. Today Vasya got bored and decided to take a walk in the yard. Vasya lives in entrance *a* and he decided that during his walk he will move around the house *b* entrances in the direction of increasing numbers (in this order entrance *n* should be followed by entrance 1). The negative value of *b* corresponds to moving |*b*| entrances in the order of decreasing numbers (in this order entrance 1 is followed by entrance *n*). If *b*<==<=0, then Vasya prefers to walk beside his entrance. Help Vasya to determine the number of the entrance, near which he will be at the end of his walk. The input will be provided via standard input and looks as follows: The single line of the input contains three space-separated integers *n*, *a* and *b* (1<=≀<=*n*<=≀<=100,<=1<=≀<=*a*<=≀<=*n*,<=<=-<=100<=≀<=*b*<=≀<=100)Β β€” the number of entrances at Vasya's place, the number of his entrance and the length of his walk, respectively. You should write the solution as standard output as follows: Print a single integer *k* (1<=≀<=*k*<=≀<=*n*)Β β€” the number of the entrance where Vasya will be at the end of his walk. Here are example inputs and outputs for the problem: Example Input 1: 6 2 -5 Example Output 1: 3 Example Input 2: 5 1 3 Example Output 2: 4 Example Input 3: 3 2 7 Example Output 3: 3 Now solve the problem by providing the code.
n,a,b=map(int,input().split(' ')) z=(((a+b)%n)+n)%n if(z==0): print(n) else: print(z)
vfc_83225
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 2 -5", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 1 3", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2 7", "output": "3", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
233
Solve the following coding problem using the programming language python: A permutation is a sequence of integers *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct positive integers, each of them doesn't exceed *n*. Let's denote the *i*-th element of permutation *p* as *p**i*. We'll call number *n* the size of permutation *p*1,<=*p*2,<=...,<=*p**n*. Nickolas adores permutations. He likes some permutations more than the others. He calls such permutations perfect. A perfect permutation is such permutation *p* that for any *i* (1<=≀<=*i*<=≀<=*n*) (*n* is the permutation size) the following equations hold *p**p**i*<==<=*i* and *p**i*<=β‰ <=*i*. Nickolas asks you to print any perfect permutation of size *n* for the given *n*. The input will be provided via standard input and looks as follows: A single line contains a single integer *n* (1<=≀<=*n*<=≀<=100) β€” the permutation size. You should write the solution as standard output as follows: If a perfect permutation of size *n* doesn't exist, print a single integer -1. Otherwise print *n* distinct integers from 1 to *n*, *p*1,<=*p*2,<=...,<=*p**n* β€” permutation *p*, that is perfect. Separate printed numbers by whitespaces. Here are example inputs and outputs for the problem: Example Input 1: 1 Example Output 1: -1 Example Input 2: 2 Example Output 2: 2 1 Example Input 3: 4 Example Output 3: 2 1 4 3 Now solve the problem by providing the code.
# -*- coding: utf-8 -*- """ Created on Thu Apr 14 12:45:15 2022 @author: dehon """ n = int(input()) if(n%2 == 1): print(-1) else: for i in range(1,n+1): if(i%2 == 1): print(i+1, end=' ') else: print(i-1, end=' ')
vfc_83229
{ "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", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "2", "output": "2 1 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "4", "output": "2 1 4 3 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "3", "output": "-1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
714
Solve the following coding problem using the programming language python: Today an outstanding event is going to happen in the forestΒ β€” hedgehog Filya will come to his old fried Sonya! Sonya is an owl and she sleeps during the day and stay awake from minute *l*1 to minute *r*1 inclusive. Also, during the minute *k* she prinks and is unavailable for Filya. Filya works a lot and he plans to visit Sonya from minute *l*2 to minute *r*2 inclusive. Calculate the number of minutes they will be able to spend together. The input will be provided via standard input and looks as follows: The only line of the input contains integers *l*1, *r*1, *l*2, *r*2 and *k* (1<=≀<=*l*1,<=*r*1,<=*l*2,<=*r*2,<=*k*<=≀<=1018, *l*1<=≀<=*r*1, *l*2<=≀<=*r*2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks. You should write the solution as standard output as follows: Print one integerΒ β€” the number of minutes Sonya and Filya will be able to spend together. Here are example inputs and outputs for the problem: Example Input 1: 1 10 9 20 1 Example Output 1: 2 Example Input 2: 1 100 50 200 75 Example Output 2: 50 Now solve the problem by providing the code.
import operator as op import re import sys from bisect import bisect, bisect_left, insort, insort_left from collections import Counter, defaultdict, deque from copy import deepcopy from decimal import Decimal from functools import reduce from itertools import ( accumulate, combinations, combinations_with_replacement, groupby, permutations, product) from math import (acos, asin, atan, ceil, cos, degrees, factorial, gcd, hypot, log2, pi, radians, sin, sqrt, tan) from operator import itemgetter, mul from string import ascii_lowercase, ascii_uppercase, digits def inp(): return(int(input())) def inlist(): return(list(map(int, input().split()))) def instr(): s = input() return(list(s[:len(s)])) def invr(): return(map(int, input().split())) def def_value(): return 0 # For getting input from input.txt file #sys.stdin = open('input.txt', 'r') # Printing the Output to output.txt file #sys.stdout = open('output.txt', 'w') l1, r1, l2, r2, k = invr() if r2 < l1 or l2 > r1: print(0) sys.exit() L = max(l1, l2) R = min(r1, r2) res = R - L + 1 if k >= L and k <= R: res -= 1 if res < 0: print(0) else: print(res)
vfc_83233
{ "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 10 9 20 1", "output": "2", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
995
Solve the following coding problem using the programming language python: Allen is hosting a formal dinner party. $2n$ people come to the event in $n$ pairs (couples). After a night of fun, Allen wants to line everyone up for a final picture. The $2n$ people line up, but Allen doesn't like the ordering. Allen prefers if each pair occupies adjacent positions in the line, as this makes the picture more aesthetic. Help Allen find the minimum number of swaps of adjacent positions he must perform to make it so that each couple occupies adjacent positions in the line. The input will be provided via standard input and looks as follows: The first line contains a single integer $n$ ($1 \le n \le 100$), the number of pairs of people. The second line contains $2n$ integers $a_1, a_2, \dots, a_{2n}$. For each $i$ with $1 \le i \le n$, $i$ appears exactly twice. If $a_j = a_k = i$, that means that the $j$-th and $k$-th people in the line form a couple. You should write the solution as standard output as follows: Output a single integer, representing the minimum number of adjacent swaps needed to line the people up so that each pair occupies adjacent positions. Here are example inputs and outputs for the problem: Example Input 1: 4 1 1 2 3 3 2 4 4 Example Output 1: 2 Example Input 2: 3 1 1 2 2 3 3 Example Output 2: 0 Example Input 3: 3 3 1 2 3 1 2 Example Output 3: 3 Now solve the problem by providing the code.
n=int(input()) lst = list(map(int, input().strip().split(' '))) c=0 while(len(lst)!=0): p=lst[0] del lst[0] i=lst.index(p) c+=i del lst[i] print(c)
vfc_83237
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "3000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 1 2 3 3 2 4 4", "output": "2", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
116
Solve the following coding problem using the programming language python: Linear Kingdom has exactly one tram line. It has *n* stops, numbered from 1 to *n* in the order of tram's movement. At the *i*-th stop *a**i* passengers exit the tram, while *b**i* passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty. Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram. The input will be provided via standard input and looks as follows: The first line contains a single number *n* (2<=≀<=*n*<=≀<=1000) β€” the number of the tram's stops. Then *n* lines follow, each contains two integers *a**i* and *b**i* (0<=≀<=*a**i*,<=*b**i*<=≀<=1000) β€” the number of passengers that exits the tram at the *i*-th stop, and the number of passengers that enter the tram at the *i*-th stop. The stops are given from the first to the last stop in the order of tram's movement. - The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that *a*1<==<=0. - At the last stop, all the passengers exit the tram and it becomes empty. More formally, . - No passenger will enter the train at the last stop. That is, *b**n*<==<=0. You should write the solution as standard output as follows: Print a single integer denoting the minimum possible capacity of the tram (0 is allowed). Here are example inputs and outputs for the problem: Example Input 1: 4 0 3 2 5 4 2 4 0 Example Output 1: 6 Now solve the problem by providing the code.
total_stop = int(input()) max = 0 current = 0 for i in range(total_stop): a,b = map(int,input().split()) if i == 0: max = b current = b else: current = (current - a) + b if current > max: max = current print(max)
vfc_83241
{ "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\n0 3\n2 5\n4 2\n4 0", "output": "6", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
197
Solve the following coding problem using the programming language python: You've got a rectangular table with length *a* and width *b* and the infinite number of plates of radius *r*. Two players play the following game: they take turns to put the plates on the table so that the plates don't lie on each other (but they can touch each other), and so that any point on any plate is located within the table's border. During the game one cannot move the plates that already lie on the table. The player who cannot make another move loses. Determine which player wins, the one who moves first or the one who moves second, provided that both players play optimally well. The input will be provided via standard input and looks as follows: A single line contains three space-separated integers *a*, *b*, *r* (1<=≀<=*a*,<=*b*,<=*r*<=≀<=100) β€” the table sides and the plates' radius, correspondingly. You should write the solution as standard output as follows: If wins the player who moves first, print "First" (without the quotes). Otherwise print "Second" (without the quotes). Here are example inputs and outputs for the problem: Example Input 1: 5 5 2 Example Output 1: First Example Input 2: 6 7 4 Example Output 2: Second Now solve the problem by providing the code.
A = list(map(int,input().split())) a = A[0];b = A[1];r = A[2] if 2*r <= min(a,b): print('First') else: print('Second')
vfc_83245
{ "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 5 2", "output": "First", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 7 4", "output": "Second", "type": "stdin_stdout" }, { "fn_name": null, "input": "100 100 1", "output": "First", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1 100", "output": "Second", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
599
Solve the following coding problem using the programming language python: Today Patrick waits for a visit from his friend Spongebob. To prepare for the visit, Patrick needs to buy some goodies in two stores located near his house. There is a *d*1 meter long road between his house and the first shop and a *d*2 meter long road between his house and the second shop. Also, there is a road of length *d*3 directly connecting these two shops to each other. Help Patrick calculate the minimum distance that he needs to walk in order to go to both shops and return to his house. Patrick always starts at his house. He should visit both shops moving only along the three existing roads and return back to his house. He doesn't mind visiting the same shop or passing the same road multiple times. The only goal is to minimize the total distance traveled. The input will be provided via standard input and looks as follows: The first line of the input contains three integers *d*1, *d*2, *d*3 (1<=≀<=*d*1,<=*d*2,<=*d*3<=≀<=108)Β β€” the lengths of the paths. - *d*1 is the length of the path connecting Patrick's house and the first shop; - *d*2 is the length of the path connecting Patrick's house and the second shop; - *d*3 is the length of the path connecting both shops. You should write the solution as standard output as follows: Print the minimum distance that Patrick will have to walk in order to visit both shops and return to his house. Here are example inputs and outputs for the problem: Example Input 1: 10 20 30 Example Output 1: 60 Example Input 2: 1 1 5 Example Output 2: 4 Now solve the problem by providing the code.
def good(a,b,c): return min(a,b+c)+min(c,a+b)+min(b,a+c) a,b,c=map(int,input().split()) print(good(a, b, c))
vfc_83249
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 20 30", "output": "60", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
420
Solve the following coding problem using the programming language python: Recently, a start up by two students of a state university of city F gained incredible popularity. Now it's time to start a new company. But what do we call it? The market analysts came up with a very smart plan: the name of the company should be identical to its reflection in a mirror! In other words, if we write out the name of the company on a piece of paper in a line (horizontally, from left to right) with large English letters, then put this piece of paper in front of the mirror, then the reflection of the name in the mirror should perfectly match the line written on the piece of paper. There are many suggestions for the company name, so coming up to the mirror with a piece of paper for each name wouldn't be sensible. The founders of the company decided to automatize this process. They asked you to write a program that can, given a word, determine whether the word is a 'mirror' word or not. The input will be provided via standard input and looks as follows: The first line contains a non-empty name that needs to be checked. The name contains at most 105 large English letters. The name will be written with the next sans serif font: You should write the solution as standard output as follows: Print 'YES' (without the quotes), if the given name matches its mirror reflection. Otherwise, print 'NO' (without the quotes). Here are example inputs and outputs for the problem: Example Input 1: AHA Example Output 1: YES Example Input 2: Z Example Output 2: NO Example Input 3: XO Example Output 3: NO Now solve the problem by providing the code.
import sys def check(text): legal = 'AHIMOTUVWXY' for i in text: if i not in legal: return False rev = list(text) rev.reverse() if text != ''.join(rev): return False return True if __name__ == '__main__': text = sys.stdin.readline().split()[0] if check(text): print('YES') else: print('NO')
vfc_83253
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "AHA", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "Z", "output": "NO", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
978
Solve the following coding problem using the programming language python: Petya has an array $a$ consisting of $n$ integers. He wants to remove duplicate (equal) elements. Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed. The input will be provided via standard input and looks as follows: The first line contains a single integer $n$ ($1 \le n \le 50$) β€” the number of elements in Petya's array. The following line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1\,000$) β€” the Petya's array. You should write the solution as standard output as follows: In the first line print integer $x$ β€” the number of elements which will be left in Petya's array after he removed the duplicates. In the second line print $x$ integers separated with a space β€” Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left. Here are example inputs and outputs for the problem: Example Input 1: 6 1 5 5 1 6 1 Example Output 1: 3 5 6 1 Example Input 2: 5 2 4 2 4 4 Example Output 2: 2 2 4 Example Input 3: 5 6 6 6 6 6 Example Output 3: 1 6 Now solve the problem by providing the code.
no_inputs = int(input()) nums = list(map(int, input().split())) unique_nums = [] for num in nums[::-1]: if num not in unique_nums: unique_nums.append(num) print(len(unique_nums)) print(" ".join(str(item) for item in unique_nums[::-1]))
vfc_83257
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "4000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n1 5 5 1 6 1", "output": "3\n5 6 1 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n2 4 2 4 4", "output": "2\n2 4 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n6 6 6 6 6", "output": "1\n6 ", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
525
Solve the following coding problem using the programming language python: After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with *n* room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on β€” you can go from the (*n*<=-<=1)-th room to the *n*-th room. Thus, you can go to room *x* only from room *x*<=-<=1. The potato pie is located in the *n*-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room *x* from room *x*<=-<=1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type *t* can open the door of type *T* if and only if *t* and *T* are the same letter, written in different cases. For example, key f can open door F. Each of the first *n*<=-<=1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door. Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room *n*. Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room *n*, which has a delicious potato pie. Write a program that will help Vitaly find out this number. The input will be provided via standard input and looks as follows: The first line of the input contains a positive integer *n* (2<=≀<=*n*<=≀<=105)Β β€”Β the number of rooms in the house. The second line of the input contains string *s* of length 2Β·*n*<=-<=2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string *s* contain lowercase Latin lettersΒ β€”Β the types of the keys that lie in the corresponding rooms. Thus, each odd position *i* of the given string *s* contains a lowercase Latin letter β€” the type of the key that lies in room number (*i*<=+<=1)<=/<=2. The even positions in the given string contain uppercase Latin letters β€” the types of doors between the rooms. Thus, each even position *i* of the given string *s* contains an uppercase letter β€” the type of the door that leads from room *i*<=/<=2 to room *i*<=/<=2<=+<=1. You should write the solution as standard output as follows: Print the only integer β€” the minimum number of keys that Vitaly needs to buy to surely get from room one to room *n*. Here are example inputs and outputs for the problem: Example Input 1: 3 aAbB Example Output 1: 0 Example Input 2: 4 aBaCaB Example Output 2: 3 Example Input 3: 5 xYyXzZaZ Example Output 3: 2 Now solve the problem by providing the code.
n = int(input()) s = input() D = dict() D_mins = dict() for i in range(len(s)): if i % 2 == 0: if s[i] in D: D[s[i]] += 1 else: D[s[i]] = 1 if s[i] in D_mins: D_mins[s[i]] = min(D_mins[s[i]], D[s[i]]) else: D_mins[s[i]] = 1 else: key = s[i].lower() if key in D: D[key] -= 1 else: D[key] = -1 if key in D_mins: D_mins[key] = min(D_mins[key], D[key]) else: D_mins[key] = -1 key_to_buy = 0 for elem in D_mins.values(): if elem < 0: key_to_buy += elem print(-key_to_buy)
vfc_83261
{ "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\naAbB", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\naBaCaB", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\nxYyXzZaZ", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "26\naAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyY", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "26\nzAyBxCwDvEuFtGsHrIqJpKoLnMmNlOkPjQiRhSgTfUeVdWcXbY", "output": "13", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
136
Solve the following coding problem using the programming language python: Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he organized a New Year party at his place and invited *n* his friends there. If there's one thing Petya likes more that receiving gifts, that's watching others giving gifts to somebody else. Thus, he safely hid the laptop until the next New Year and made up his mind to watch his friends exchanging gifts while he does not participate in the process. He numbered all his friends with integers from 1 to *n*. Petya remembered that a friend number *i* gave a gift to a friend number *p**i*. He also remembered that each of his friends received exactly one gift. Now Petya wants to know for each friend *i* the number of a friend who has given him a gift. The input will be provided via standard input and looks as follows: The first line contains one integer *n* (1<=≀<=*n*<=≀<=100) β€” the quantity of friends Petya invited to the party. The second line contains *n* space-separated integers: the *i*-th number is *p**i* β€” the number of a friend who gave a gift to friend number *i*. It is guaranteed that each friend received exactly one gift. It is possible that some friends do not share Petya's ideas of giving gifts to somebody else. Those friends gave the gifts to themselves. You should write the solution as standard output as follows: Print *n* space-separated integers: the *i*-th number should equal the number of the friend who gave a gift to friend number *i*. Here are example inputs and outputs for the problem: Example Input 1: 4 2 3 4 1 Example Output 1: 4 1 2 3 Example Input 2: 3 1 3 2 Example Output 2: 1 3 2 Example Input 3: 2 1 2 Example Output 3: 1 2 Now solve the problem by providing the code.
# N,M = map(int,input().split()) # N = int(input()) # A = list(map(int,input().split())) N = int(input()) A = list(map(int,input().split())) d = [0] * N for i in range(N): d[A[i]-1] = i+1 print(*d)
vfc_83265
{ "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 3 4 1", "output": "4 1 2 3", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 3 2", "output": "1 3 2", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 2", "output": "1 2", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n1 3 2 6 4 5 7 9 8 10", "output": "1 3 2 5 6 4 7 9 8 10", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
88
Solve the following coding problem using the programming language python: Vasya learns to type. He has an unusual keyboard at his disposal: it is rectangular and it has *n* rows of keys containing *m* keys in each row. Besides, the keys are of two types. Some of the keys have lowercase Latin letters on them and some of the keys work like the "Shift" key on standard keyboards, that is, they make lowercase letters uppercase. Vasya can press one or two keys with one hand. However, he can only press two keys if the Euclidean distance between the centers of the keys does not exceed *x*. The keys are considered as squares with a side equal to 1. There are no empty spaces between neighbouring keys. Vasya is a very lazy boy, that's why he tries to type with one hand as he eats chips with his other one. However, it is possible that some symbol can't be typed with one hand only, because the distance between it and the closest "Shift" key is strictly larger than *x*. In this case he will have to use his other hand. Having typed the symbol, Vasya returns other hand back to the chips. You are given Vasya's keyboard and the text. Count the minimum number of times Vasya will have to use the other hand. The input will be provided via standard input and looks as follows: The first line contains three integers *n*, *m*, *x* (1<=≀<=*n*,<=*m*<=≀<=30,<=1<=≀<=*x*<=≀<=50). Next *n* lines contain descriptions of all the keyboard keys. Each line contains the descriptions of exactly *m* keys, without spaces. The letter keys are marked with the corresponding lowercase letters. The "Shift" keys are marked with the "S" symbol. Then follow the length of the text *q* (1<=≀<=*q*<=≀<=5Β·105). The last line contains the text *T*, which consists of *q* symbols, which are uppercase and lowercase Latin letters. You should write the solution as standard output as follows: If Vasya can type the text, then print the minimum number of times he will have to use his other hand. Otherwise, print "-1" (without the quotes). Here are example inputs and outputs for the problem: Example Input 1: 2 2 1 ab cd 1 A Example Output 1: -1 Example Input 2: 2 2 1 ab cd 1 e Example Output 2: -1 Example Input 3: 2 2 1 ab cS 5 abcBA Example Output 3: 1 Example Input 4: 3 9 4 qwertyuio asdfghjkl SzxcvbnmS 35 TheQuIcKbRoWnFOXjummsovertHeLazYDOG Example Output 4: 2 Now solve the problem by providing the code.
import sys from array import array # noqa: F401 from math import hypot from collections import defaultdict def input(): return sys.stdin.buffer.readline().decode('utf-8') n, m, x = map(int, input().split()) keyboard = [input().rstrip() for _ in range(n)] keys = set() inf, eps = 10**9, 1e-9 dist = defaultdict(lambda: inf) shift = [] for i in range(n): for j in range(m): if keyboard[i][j] == 'S': shift.append((i, j)) for i in range(n): for j in range(m): if keyboard[i][j] == 'S': continue keys.add(keyboard[i][j]) for ti, tj in shift: dist[keyboard[i][j].upper()] = min(dist[keyboard[i][j].upper()], hypot(i - ti, j - tj)) q = int(input()) ans = 0 for c in input().rstrip(): if c.lower() not in keys: print(-1) exit() if 65 <= ord(c) <= 90: if not shift: print(-1) exit() if dist[c] - eps > x: ans += 1 print(ans)
vfc_83269
{ "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 1\nab\ncd\n1\nA", "output": "-1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
204
Solve the following coding problem using the programming language python: The Little Elephant very much loves sums on intervals. This time he has a pair of integers *l* and *r* (*l*<=≀<=*r*). The Little Elephant has to find the number of such integers *x* (*l*<=≀<=*x*<=≀<=*r*), that the first digit of integer *x* equals the last one (in decimal notation). For example, such numbers as 101, 477474 or 9 will be included in the answer and 47, 253 or 1020 will not. Help him and count the number of described numbers *x* for a given pair *l* and *r*. The input will be provided via standard input and looks as follows: The single line contains a pair of integers *l* and *r* (1<=≀<=*l*<=≀<=*r*<=≀<=1018) β€” the boundaries of the interval. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is preferred to use cin, cout streams or the %I64d specifier. You should write the solution as standard output as follows: On a single line print a single integer β€” the answer to the problem. Here are example inputs and outputs for the problem: Example Input 1: 2 47 Example Output 1: 12 Example Input 2: 47 1024 Example Output 2: 98 Now solve the problem by providing the code.
def f(x): if x < 10: return x if str(x)[0] > str(x)[-1]: return x // 10 + 8 else: return x // 10 + 9 l, r = map(int, input().split()) print(f(r) - f(l - 1))
vfc_83273
{ "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 47", "output": "12", "type": "stdin_stdout" }, { "fn_name": null, "input": "47 1024", "output": "98", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1000", "output": "108", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 10000", "output": "1008", "type": "stdin_stdout" }, { "fn_name": null, "input": "47 8545", "output": "849", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
770
Solve the following coding problem using the programming language python: Innokentiy decides to change the password in the social net "Contact!", but he is too lazy to invent a new password by himself. That is why he needs your help. Innokentiy decides that new password should satisfy the following conditions: - the length of the password must be equal to *n*, - the password should consist only of lowercase Latin letters, - the number of distinct symbols in the password must be equal to *k*, - any two consecutive symbols in the password must be distinct. Your task is to help Innokentiy and to invent a new password which will satisfy all given conditions. The input will be provided via standard input and looks as follows: The first line contains two positive integers *n* and *k* (2<=≀<=*n*<=≀<=100, 2<=≀<=*k*<=≀<=*min*(*n*,<=26)) β€” the length of the password and the number of distinct symbols in it. Pay attention that a desired new password always exists. You should write the solution as standard output as follows: Print any password which satisfies all conditions given by Innokentiy. Here are example inputs and outputs for the problem: Example Input 1: 4 3 Example Output 1: java Example Input 2: 6 6 Example Output 2: python Example Input 3: 5 2 Example Output 3: phphp Now solve the problem by providing the code.
n, k = map(int,input().split()) print(('abcdefghijklmnopqrstuvwxyz' [:k]*n )[:n])
vfc_83277
{ "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", "output": "abca", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 6", "output": "abcdef", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 2", "output": "ababa", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2", "output": "aba", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
935
Solve the following coding problem using the programming language python: Fafa owns a company that works on huge projects. There are *n* employees in Fafa's company. Whenever the company has a new project to start working on, Fafa has to divide the tasks of this project among all the employees. Fafa finds doing this every time is very tiring for him. So, he decided to choose the best *l* employees in his company as team leaders. Whenever there is a new project, Fafa will divide the tasks among only the team leaders and each team leader will be responsible of some positive number of employees to give them the tasks. To make this process fair for the team leaders, each one of them should be responsible for the same number of employees. Moreover, every employee, who is not a team leader, has to be under the responsibility of exactly one team leader, and no team leader is responsible for another team leader. Given the number of employees *n*, find in how many ways Fafa could choose the number of team leaders *l* in such a way that it is possible to divide employees between them evenly. The input will be provided via standard input and looks as follows: The input consists of a single line containing a positive integer *n* (2<=≀<=*n*<=≀<=105) β€” the number of employees in Fafa's company. You should write the solution as standard output as follows: Print a single integer representing the answer to the problem. Here are example inputs and outputs for the problem: Example Input 1: 2 Example Output 1: 1 Example Input 2: 10 Example Output 2: 3 Now solve the problem by providing the code.
# A. Fafa and his Company n = int(input()) i = 1 cont = 0 while i <= n/2: e = n - i if e % i == 0: cont += 1 i += 1 print(cont)
vfc_83281
{ "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", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "10", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "3", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "4", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "6", "output": "3", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
606
Solve the following coding problem using the programming language python: Carl is a beginner magician. He has *a* blue, *b* violet and *c* orange magic spheres. In one move he can transform two spheres of the same color into one sphere of any other color. To make a spell that has never been seen before, he needs at least *x* blue, *y* violet and *z* orange spheres. Can he get them (possible, in multiple actions)? The input will be provided via standard input and looks as follows: The first line of the input contains three integers *a*, *b* and *c* (0<=≀<=*a*,<=*b*,<=*c*<=≀<=1<=000<=000)Β β€” the number of blue, violet and orange spheres that are in the magician's disposal. The second line of the input contains three integers, *x*, *y* and *z* (0<=≀<=*x*,<=*y*,<=*z*<=≀<=1<=000<=000)Β β€” the number of blue, violet and orange spheres that he needs to get. You should write the solution as standard output as follows: If the wizard is able to obtain the required numbers of spheres, print "Yes". Otherwise, print "No". Here are example inputs and outputs for the problem: Example Input 1: 4 4 0 2 1 2 Example Output 1: Yes Example Input 2: 5 6 1 2 7 2 Example Output 2: No Example Input 3: 3 3 3 2 2 2 Example Output 3: Yes Now solve the problem by providing the code.
a,b,c = map(int, input().split()) x,y,z = map(int, input().split()) extra = max(0, a-x)//2 + max(0, b-y)//2 + max(0, c-z)//2 need = max(0, x-a) + max(0, y-b) + max(0, z-c) print("Yes" if need<=extra else "No")
vfc_83285
{ "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 4 0\n2 1 2", "output": "Yes", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 6 1\n2 7 2", "output": "No", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3 3\n2 2 2", "output": "Yes", "type": "stdin_stdout" }, { "fn_name": null, "input": "0 0 0\n0 0 0", "output": "Yes", "type": "stdin_stdout" }, { "fn_name": null, "input": "0 0 0\n0 0 1", "output": "No", "type": "stdin_stdout" }, { "fn_name": null, "input": "0 1 0\n0 0 0", "output": "Yes", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
950
Solve the following coding problem using the programming language python: You are at a water bowling training. There are *l* people who play with their left hand, *r* people, who play with their right hand, and *a* ambidexters, who can play with left or right hand. The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and exactly half of the players should play with their left hand. One player should use only on of his hands. Ambidexters play as well with their right hand as with their left hand. In the team, an ambidexter can play with their left hand, or with their right hand. Please find the maximum possible size of the team, where equal number of players use their left and right hands, respectively. The input will be provided via standard input and looks as follows: The only line contains three integers *l*, *r* and *a* (0<=≀<=*l*,<=*r*,<=*a*<=≀<=100) β€” the number of left-handers, the number of right-handers and the number of ambidexters at the training. You should write the solution as standard output as follows: Print a single even integerΒ β€” the maximum number of players in the team. It is possible that the team can only have zero number of players. Here are example inputs and outputs for the problem: Example Input 1: 1 4 2 Example Output 1: 6 Example Input 2: 5 5 5 Example Output 2: 14 Example Input 3: 0 2 0 Example Output 3: 0 Now solve the problem by providing the code.
def li(): return list(map(int,input().split())) def gi(n): return [list(map(int,input().split())) for _ in range(n)] # File input # import sys # sys.stdin = open('user.txt','r') l,r,a = li() if max(l,r) - min(l,r) > a: print((min(l,r)+a) * 2) else: print((max(l,r) + (a - (max(l,r) - min(l,r))) // 2) * 2)
vfc_83293
{ "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 4 2", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5 5", "output": "14", "type": "stdin_stdout" }, { "fn_name": null, "input": "0 2 0", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "30 70 34", "output": "128", "type": "stdin_stdout" }, { "fn_name": null, "input": "89 32 24", "output": "112", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
465
Solve the following coding problem using the programming language python: Sergey is testing a next-generation processor. Instead of bytes the processor works with memory cells consisting of *n* bits. These bits are numbered from 1 to *n*. An integer is stored in the cell in the following way: the least significant bit is stored in the first bit of the cell, the next significant bit is stored in the second bit, and so on; the most significant bit is stored in the *n*-th bit. Now Sergey wants to test the following instruction: "add 1 to the value of the cell". As a result of the instruction, the integer that is written in the cell must be increased by one; if some of the most significant bits of the resulting number do not fit into the cell, they must be discarded. Sergey wrote certain values ​​of the bits in the cell and is going to add one to its value. How many bits of the cell will change after the operation? 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 bits in the cell. The second line contains a string consisting of *n* characters β€” the initial state of the cell. The first character denotes the state of the first bit of the cell. The second character denotes the second least significant bit and so on. The last character denotes the state of the most significant bit. You should write the solution as standard output as follows: Print a single integer β€” the number of bits in the cell which change their state after we add 1 to the cell. Here are example inputs and outputs for the problem: Example Input 1: 4 1100 Example Output 1: 3 Example Input 2: 4 1111 Example Output 2: 4 Now solve the problem by providing the code.
n = int(input()) cells = input() if cells.find('0') == -1: print(n) else: before = int(cells[::-1], 2) after = before + 1 print(str(bin(before ^ after)).count('1'))
vfc_83297
{ "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\n1100", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1111", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n0", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
745
Solve the following coding problem using the programming language python: Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word. Hongcow has decided to try to make new words from this one. He starts by taking the word he just learned how to spell, and moves the last character of the word to the beginning of the word. He calls this a cyclic shift. He can apply cyclic shift many times. For example, consecutively applying cyclic shift operation to the word "abracadabra" Hongcow will get words "aabracadabr", "raabracadab" and so on. Hongcow is now wondering how many distinct words he can generate by doing the cyclic shift arbitrarily many times. The initial string is also counted. The input will be provided via standard input and looks as follows: The first line of input will be a single string *s* (1<=≀<=|*s*|<=≀<=50), the word Hongcow initially learns how to spell. The string *s* consists only of lowercase English letters ('a'–'z'). You should write the solution as standard output as follows: Output a single integer equal to the number of distinct strings that Hongcow can obtain by applying the cyclic shift arbitrarily many times to the given string. Here are example inputs and outputs for the problem: Example Input 1: abcd Example Output 1: 4 Example Input 2: bbb Example Output 2: 1 Example Input 3: yzyz Example Output 3: 2 Now solve the problem by providing the code.
s = input() ans = set() for l in range(len(s)): t = s[l:] + s[:l] ans.add(t) print(len(ans))
vfc_83301
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "abcd", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "bbb", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "yzyz", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy", "output": "25", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
791
Solve the following coding problem using the programming language python: Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. Right now, Limak and Bob weigh *a* and *b* respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight. Limak eats a lot and his weight is tripled after every year, while Bob's weight is doubled after every year. After how many full years will Limak become strictly larger (strictly heavier) than Bob? 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*<=≀<=10)Β β€” the weight of Limak and the weight of Bob respectively. You should write the solution as standard output as follows: Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob. Here are example inputs and outputs for the problem: Example Input 1: 4 7 Example Output 1: 2 Example Input 2: 4 9 Example Output 2: 3 Example Input 3: 1 1 Example Output 3: 1 Now solve the problem by providing the code.
# -*- coding: utf-8 -*- """ Created on Tue Sep 19 15:47:18 2023 @author: lenovo """ a,b=map(int,input().split()) s=0 while a<=b: a*=3 b*=2 s=s+1 print(s)
vfc_83305
{ "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 7", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 9", "output": "3", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
479
Solve the following coding problem using the programming language python: Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers *a*, *b*, *c* on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets: - 1+2*3=7 - 1*(2+3)=5 - 1*2*3=6 - (1+2)*3=9 Note that you can insert operation signs only between *a* and *b*, and between *b* and *c*, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2. It's easy to see that the maximum value that you can obtain is 9. Your task is: given *a*, *b* and *c* print the maximum value that you can get. The input will be provided via standard input and looks as follows: The input contains three integers *a*, *b* and *c*, each on a single line (1<=≀<=*a*,<=*b*,<=*c*<=≀<=10). You should write the solution as standard output as follows: Print the maximum value of the expression that you can obtain. Here are example inputs and outputs for the problem: Example Input 1: 1 2 3 Example Output 1: 9 Example Input 2: 2 10 3 Example Output 2: 60 Now solve the problem by providing the code.
x = int(input()) y = int(input()) z = int(input()) list_1 = [] list_1.append((x+y)*z) list_1.append(x*(y+z)) list_1.append(x+y+z) list_1.append(x*y*z) print(max(list_1))
vfc_83309
{ "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\n2\n3", "output": "9", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n10\n3", "output": "60", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
519
Solve the following coding problem using the programming language python: A and B are preparing themselves for programming contests. To train their logical thinking and solve problems better, A and B decided to play chess. During the game A wondered whose position is now stronger. For each chess piece we know its weight: - the queen's weight is 9, - the rook's weight is 5, - the bishop's weight is 3, - the knight's weight is 3, - the pawn's weight is 1, - the king's weight isn't considered in evaluating position. The player's weight equals to the sum of weights of all his pieces on the board. As A doesn't like counting, he asked you to help him determine which player has the larger position weight. The input will be provided via standard input and looks as follows: The input contains eight lines, eight characters each β€” the board's description. The white pieces on the board are marked with uppercase letters, the black pieces are marked with lowercase letters. The white pieces are denoted as follows: the queen is represented is 'Q', the rook β€” as 'R', the bishop β€” as'B', the knight β€” as 'N', the pawn β€” as 'P', the king β€” as 'K'. The black pieces are denoted as 'q', 'r', 'b', 'n', 'p', 'k', respectively. An empty square of the board is marked as '.' (a dot). It is not guaranteed that the given chess position can be achieved in a real game. Specifically, there can be an arbitrary (possibly zero) number pieces of each type, the king may be under attack and so on. You should write the solution as standard output as follows: Print "White" (without quotes) if the weight of the position of the white pieces is more than the weight of the position of the black pieces, print "Black" if the weight of the black pieces is more than the weight of the white pieces and print "Draw" if the weights of the white and black pieces are equal. Here are example inputs and outputs for the problem: Example Input 1: ...QK... ........ ........ ........ ........ ........ ........ ...rk... Example Output 1: White Example Input 2: rnbqkbnr pppppppp ........ ........ ........ ........ PPPPPPPP RNBQKBNR Example Output 2: Draw Example Input 3: rppppppr ...k.... ........ ........ ........ ........ K...Q... ........ Example Output 3: Black Now solve the problem by providing the code.
#519A valW = 0 valB = 0 for _ in range(8): a = input() for i in range(8) : if a[i] == 'Q': valW = valW + 9 elif a[i] == 'R' : valW = valW + 5 elif a[i] == 'B' : valW = valW + 3 elif a[i] == 'N' : valW = valW + 3 elif a[i] == 'P' : valW = valW + 1 elif a[i] == 'K' : valW = valW + 0 elif a[i] == 'q': valB = valB + 9 elif a[i] == 'r' : valB = valB + 5 elif a[i] == 'b' : valB = valB + 3 elif a[i] == 'n' : valB = valB + 3 elif a[i] == 'p' : valB = valB + 1 elif a[i] == 'k' : valB = valB + 0 if valW == valB : print('Draw') elif valW > valB : print('White') else : print('Black') #print(valW, valB) #96 112
vfc_83313
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "rnbqkbnr\npppppppp\n........\n........\n........\n........\nPPPPPPPP\nRNBQKBNR", "output": "Draw", "type": "stdin_stdout" }, { "fn_name": null, "input": "....bQ.K\n.B......\n.....P..\n........\n........\n........\n...N.P..\n.....R..", "output": "White", "type": "stdin_stdout" }, { "fn_name": null, "input": "b....p..\nR.......\n.pP...b.\npp......\nq.PPNpPR\n..K..rNn\nP.....p.\n...Q..B.", "output": "White", "type": "stdin_stdout" }, { "fn_name": null, "input": "...Nn...\n........\n........\n........\n.R....b.\n........\n........\n......p.", "output": "White", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
705
Solve the following coding problem using the programming language python: Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings. Hulk likes the Inception so much, and like that his feelings are complicated. They have *n* layers. The first layer is hate, second one is love, third one is hate and so on... For example if *n*<==<=1, then his feeling is "I hate it" or if *n*<==<=2 it's "I hate that I love it", and if *n*<==<=3 it's "I hate that I love that I hate it" and so on. Please help Dr. Banner. The input will be provided via standard input and looks as follows: The only line of the input contains a single integer *n* (1<=≀<=*n*<=≀<=100)Β β€” the number of layers of love and hate. You should write the solution as standard output as follows: Print Dr.Banner's feeling in one line. Here are example inputs and outputs for the problem: Example Input 1: 1 Example Output 1: I hate it Example Input 2: 2 Example Output 2: I hate that I love it Example Input 3: 3 Example Output 3: I hate that I love that I hate it Now solve the problem by providing the code.
import sys def inp(): return int(input()) def inlt(): return list(map(int, input().split())) def insr(): return input().strip() def out(x): sys.stdout.write(str(x) + "\n") def main(): count = inp() ans = "" feelings = [" I love", " I hate"] for i in range(1, count + 1): ans += feelings[i%2] if i < count: ans += " that" ans += " it" out(ans) if __name__ == "__main__": main()
vfc_83317
{ "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": "I hate it", "type": "stdin_stdout" }, { "fn_name": null, "input": "2", "output": "I hate that I love it", "type": "stdin_stdout" }, { "fn_name": null, "input": "3", "output": "I hate that I love that I hate it", "type": "stdin_stdout" }, { "fn_name": null, "input": "4", "output": "I hate that I love that I hate that I love it", "type": "stdin_stdout" }, { "fn_name": null, "input": "5", "output": "I hate that I love that I hate that I love that I hate it", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
68
Solve the following coding problem using the programming language python: Little Petya was given this problem for homework: You are given function (here represents the operation of taking the remainder). His task is to count the number of integers *x* in range [*a*;*b*] with property *f*(*x*)<==<=*x*. It is a pity that Petya forgot the order in which the remainders should be taken and wrote down only 4 numbers. Each of 24 possible orders of taking the remainder has equal probability of being chosen. For example, if Petya has numbers 1, 2, 3, 4 then he can take remainders in that order or first take remainder modulo 4, then modulo 2, 3, 1. There also are 22 other permutations of these numbers that represent orders in which remainder can be taken. In this problem 4 numbers wrote down by Petya will be pairwise distinct. Now it is impossible for Petya to complete the task given by teacher but just for fun he decided to find the number of integers with property that probability that *f*(*x*)<==<=*x* is not less than 31.4159265352718281828459045%. In other words, Petya will pick up the number *x* if there exist at least 7 permutations of numbers *p*1,<=*p*2,<=*p*3,<=*p*4, for which *f*(*x*)<==<=*x*. The input will be provided via standard input and looks as follows: First line of the input will contain 6 integers, separated by spaces: *p*1,<=*p*2,<=*p*3,<=*p*4,<=*a*,<=*b* (1<=≀<=*p*1,<=*p*2,<=*p*3,<=*p*4<=≀<=1000,<=0<=≀<=*a*<=≀<=*b*<=≀<=31415). It is guaranteed that numbers *p*1,<=*p*2,<=*p*3,<=*p*4 will be pairwise distinct. You should write the solution as standard output as follows: Output the number of integers in the given range that have the given property. Here are example inputs and outputs for the problem: Example Input 1: 2 7 1 8 2 8 Example Output 1: 0 Example Input 2: 20 30 40 50 0 100 Example Output 2: 20 Example Input 3: 31 41 59 26 17 43 Example Output 3: 9 Now solve the problem by providing the code.
import sys,math,string,bisect input=sys.stdin.readline from collections import deque L=lambda : list(map(int,input().split())) Ls=lambda : list(input().split()) M=lambda : map(int,input().split()) I=lambda :int(input()) p1,p2,p3,p4,b,a=M() k=min(p1,p2,p3,p4) c=0 for i in range(b,min(k,a+1)): c+=1 print(c)
vfc_83321
{ "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 7 1 8 2 8", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "20 30 40 50 0 100", "output": "20", "type": "stdin_stdout" }, { "fn_name": null, "input": "31 41 59 26 17 43", "output": "9", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
267
Solve the following coding problem using the programming language python: You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5). You've got some number of pairs (*a**i*,<=*b**i*). How many operations will be performed for each of them? The input will be provided via standard input and looks as follows: The first line contains the number of pairs *n* (1<=<=≀<=<=*n*<=<=≀<=<=1000). Then follow *n* lines, each line contains a pair of positive integers *a**i*,<=*b**i* (1<=<=≀<=<=*a**i*,<=<=*b**i*<=<=≀<=<=109). You should write the solution as standard output as follows: Print the sought number of operations for each pair on a single line. Here are example inputs and outputs for the problem: Example Input 1: 2 4 17 7 987654321 Example Output 1: 8 141093479 Now solve the problem by providing the code.
for _ in range(int(input())): a,b=map(int,input().split()) ans=int(0) while a and b: a,b=min(a,b),max(a,b) ans,b=ans+b//a,b%a print(ans)
vfc_83325
{ "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\n4 17\n7 987654321", "output": "8\n141093479", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321\n7 987654321", "output": "141093479\n141093479\n141093479\n141093479\n141093479\n141093479\n141093479\n141093479\n141093479\n141093479", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
691
Solve the following coding problem using the programming language python: According to rules of the Berland fashion, a jacket should be fastened by all the buttons except only one, but not necessarily it should be the last one. Also if the jacket has only one button, it should be fastened, so the jacket will not swinging open. You are given a jacket with *n* buttons. Determine if it is fastened in a right way. The input will be provided via standard input and looks as follows: The first line contains integer *n* (1<=≀<=*n*<=≀<=1000) β€” the number of buttons on the jacket. The second line contains *n* integers *a**i* (0<=≀<=*a**i*<=≀<=1). The number *a**i*<==<=0 if the *i*-th button is not fastened. Otherwise *a**i*<==<=1. You should write the solution as standard output as follows: In the only line print the word "YES" if the jacket is fastened in a right way. Otherwise print the word "NO". Here are example inputs and outputs for the problem: Example Input 1: 3 1 0 1 Example Output 1: YES Example Input 2: 3 1 0 0 Example Output 2: NO Now solve the problem by providing the code.
n = int(input()) lst = list(map(int, input().split())) if n == 1: if lst[0] == 1: print("YES") else: print("NO") else: zeros = lst.count(0) if zeros == 1: print("YES") else: print("NO")
vfc_83329
{ "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\n1 0 1", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 0 0", "output": "NO", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
898
Solve the following coding problem using the programming language python: Vasya has a non-negative integer *n*. He wants to round it to nearest integer, which ends up with 0. If *n* already ends up with 0, Vasya considers it already rounded. For example, if *n*<==<=4722 answer is 4720. If *n*<==<=5 Vasya can round it to 0 or to 10. Both ways are correct. For given *n* find out to which integer will Vasya round it. The input will be provided via standard input and looks as follows: The first line contains single integer *n* (0<=≀<=*n*<=≀<=109)Β β€” number that Vasya has. You should write the solution as standard output as follows: Print result of rounding *n*. Pay attention that in some cases answer isn't unique. In that case print any correct answer. Here are example inputs and outputs for the problem: Example Input 1: 5 Example Output 1: 0 Example Input 2: 113 Example Output 2: 110 Example Input 3: 1000000000 Example Output 3: 1000000000 Example Input 4: 5432359 Example Output 4: 5432360 Now solve the problem by providing the code.
n=int(input()) z=int(str(n)[-1]) if z>=5: print(n+10-z) else: print(n-z)
vfc_83333
{ "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": "0", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
706
Solve the following coding problem using the programming language python: Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in *n* different shops in the city. It's known that the price of one bottle in the shop *i* is equal to *x**i* coins. Vasiliy plans to buy his favorite drink for *q* consecutive days. He knows, that on the *i*-th day he will be able to spent *m**i* coins. Now, for each of the days he want to know in how many different shops he can buy a bottle of "Beecola". 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 shops in the city that sell Vasiliy's favourite drink. The second line contains *n* integers *x**i* (1<=≀<=*x**i*<=≀<=100<=000)Β β€” prices of the bottles of the drink in the *i*-th shop. The third line contains a single integer *q* (1<=≀<=*q*<=≀<=100<=000)Β β€” the number of days Vasiliy plans to buy the drink. Then follow *q* lines each containing one integer *m**i* (1<=≀<=*m**i*<=≀<=109)Β β€” the number of coins Vasiliy can spent on the *i*-th day. You should write the solution as standard output as follows: Print *q* integers. The *i*-th of them should be equal to the number of shops where Vasiliy will be able to buy a bottle of the drink on the *i*-th day. Here are example inputs and outputs for the problem: Example Input 1: 5 3 10 8 6 11 4 1 10 3 11 Example Output 1: 0 4 1 5 Now solve the problem by providing the code.
import bisect N=int(input()) x=sorted(list(map(int,input().split()))) for i in range(int(input())): print(bisect.bisect(x,int(input())))
vfc_83337
{ "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\n3 10 8 6 11\n4\n1\n10\n3\n11", "output": "0\n4\n1\n5", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n868 987 714 168 123\n10\n424\n192\n795\n873\n117\n914\n735\n158\n631\n471", "output": "2\n2\n3\n4\n0\n4\n3\n1\n2\n2", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n435 482 309\n7\n245\n241\n909\n745\n980\n29\n521", "output": "0\n0\n3\n3\n3\n0\n3", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n653\n9\n903\n980\n80\n770\n965\n874\n381\n657\n969", "output": "1\n1\n0\n1\n1\n1\n0\n1\n1", "type": "stdin_stdout" }, { "fn_name": null, "input": "12\n35345 58181 32223 84621 35905 73863 99537 30666 67771 39229 36847 29038\n23\n55052824\n82504840\n35160556\n78141700\n73401989\n86305919\n39430705\n31939373\n23501765\n4406029\n61436920\n14295390\n34275309\n28028753\n85724689\n70158847\n2396455\n66994588\n84024224\n30175981\n65622319\n76517111\n76605341", "output": "12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12\n12", "type": "stdin_stdout" } ] }