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
656
Solve the following coding problem using the programming language python: The input will be provided via standard input and looks as follows: The input contains a single integer *a* (0<=≀<=*a*<=≀<=1<=000<=000). You should write the solution as standard output as follows: Output a single integer. Here are example inputs and outputs for the problem: Example Input 1: 129 Example Output 1: 1 Now solve the problem by providing the code.
n = int(input()) c = 0 while n: c += n%8 == 1 n//=8 print(c)
vfc_82493
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "129", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "0", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "4", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "6", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "16", "output": "0", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
291
Solve the following coding problem using the programming language python: Polycarpus is the director of a large corporation. There are *n* secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each other via Spyke, the Spyke network assigns a unique ID to this call, a positive integer session number. One day Polycarpus wondered which secretaries are talking via the Spyke and which are not. For each secretary, he wrote out either the session number of his call or a 0 if this secretary wasn't talking via Spyke at that moment. Help Polycarpus analyze these data and find out the number of pairs of secretaries that are talking. If Polycarpus has made a mistake in the data and the described situation could not have taken place, say so. Note that the secretaries can correspond via Spyke not only with each other, but also with the people from other places. Also, Spyke conferences aren't permitted β€” that is, one call connects exactly two people. The input will be provided via standard input and looks as follows: The first line contains integer *n* (1<=≀<=*n*<=≀<=103) β€” the number of secretaries in Polycarpus's corporation. The next line contains *n* space-separated integers: *id*1,<=*id*2,<=...,<=*id**n* (0<=≀<=*id**i*<=≀<=109). Number *id**i* equals the number of the call session of the *i*-th secretary, if the secretary is talking via Spyke, or zero otherwise. Consider the secretaries indexed from 1 to *n* in some way. You should write the solution as standard output as follows: Print a single integer β€” the number of pairs of chatting secretaries, or -1 if Polycarpus's got a mistake in his records and the described situation could not have taken place. Here are example inputs and outputs for the problem: Example Input 1: 6 0 1 7 1 7 10 Example Output 1: 2 Example Input 2: 3 1 1 1 Example Output 2: -1 Example Input 3: 1 0 Example Output 3: 0 Now solve the problem by providing the code.
def cocktail_sort(a): n = len(a) swapped = True start = 0 end = n-1 while (swapped == True): # reset the swapped flag on entering the loop, # because it might be true from a previous # iteration. swapped = False # loop from left to right same as the bubble # sort for i in range (start, end): if (a[i] > a[i + 1]) : a[i], a[i + 1]= a[i + 1], a[i] swapped = True # if nothing moved, then array is sorted. if (swapped == False): break # otherwise, reset the swapped flag so that it # can be used in the next stage swapped = False # move the end point back by one, because # item at the end is in its rightful spot end = end-1 # from right to left, doing the same # comparison as in the previous stage for i in range(end-1, start-1, -1): if (a[i] > a[i + 1]): a[i], a[i + 1] = a[i + 1], a[i] swapped = True # increase the starting point, because # the last stage would have moved the next # smallest number to its rightful spot. start = start + 1 n = int(input()) x = list(map(int, input().split())) answer = 0 cocktail_sort(x) for i in range(len(x)-1): if (i+2)>= n: if (x[i] == x[i+1]) and (x[i] != 0): answer = answer + 1 i = i+1 else: if x[i] == x[i+1] and x[i] != 0 and x[i] !=x[i+2]: answer = answer + 1 i = i + 1 elif x[i] == x[i+1] and x[i] == x[i+2] and x[i]!= 0: answer = -1 break print(answer)
vfc_82497
{ "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\n0 1 7 1 7 10", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 1 1", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n0", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n2 2 1 1 3", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1", "output": "0", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
370
Solve the following coding problem using the programming language python: Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8<=Γ—<=8 table. A field is represented by a pair of integers (*r*,<=*c*) β€” the number of the row and the number of the column (in a classical game the columns are traditionally indexed by letters). Each chess piece takes up exactly one field. To make a move is to move a chess piece, the pieces move by the following rules: - A rook moves any number of fields horizontally or vertically. - A bishop moves any number of fields diagonally. - A king moves one field in any direction β€” horizontally, vertically or diagonally. Petya is thinking about the following problem: what minimum number of moves is needed for each of these pieces to move from field (*r*1,<=*c*1) to field (*r*2,<=*c*2)? At that, we assume that there are no more pieces besides this one on the board. Help him solve this problem. The input will be provided via standard input and looks as follows: The input contains four integers *r*1,<=*c*1,<=*r*2,<=*c*2 (1<=≀<=*r*1,<=*c*1,<=*r*2,<=*c*2<=≀<=8) β€” the coordinates of the starting and the final field. The starting field doesn't coincide with the final one. You can assume that the chessboard rows are numbered from top to bottom 1 through 8, and the columns are numbered from left to right 1 through 8. You should write the solution as standard output as follows: Print three space-separated integers: the minimum number of moves the rook, the bishop and the king (in this order) is needed to move from field (*r*1,<=*c*1) to field (*r*2,<=*c*2). If a piece cannot make such a move, print a 0 instead of the corresponding number. Here are example inputs and outputs for the problem: Example Input 1: 4 3 1 6 Example Output 1: 2 1 3 Example Input 2: 5 5 5 6 Example Output 2: 1 0 1 Now solve the problem by providing the code.
def stessocolore(x1,y1,x2,y2): if (x1+y1)%2 == (x2+y2)%2: return True else: return False x1, y1, x2, y2 = map(int, input().split()) if x1 == x2 or y1 == y2: rook = 1 else: rook = 2 king = max([abs(x1-x2),abs(y1-y2)]) if stessocolore(x1,y1,x2,y2): if (x1-y1) == (x2-y2) or x1+y1 == x2+y2: bish = 1 else: bish = 2 else: bish = 0 print(rook, bish, king)
vfc_82501
{ "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 1 6", "output": "2 1 3", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5 5 6", "output": "1 0 1", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1 8 8", "output": "2 1 7", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
69
Solve the following coding problem using the programming language python: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot to complete his physics tasks. Next day the teacher got very angry at Vasya and decided to teach him a lesson. He gave the lazy student a seemingly easy task: You are given an idle body in space and the forces that affect it. The body can be considered as a material point with coordinates (0; 0; 0). Vasya had only to answer whether it is in equilibrium. "Piece of cake" β€” thought Vasya, we need only to check if the sum of all vectors is equal to 0. So, Vasya began to solve the problem. But later it turned out that there can be lots and lots of these forces, and Vasya can not cope without your help. Help him. Write a program that determines whether a body is idle or is moving by the given vectors of forces. The input will be provided via standard input and looks as follows: The first line contains a positive integer *n* (1<=≀<=*n*<=≀<=100), then follow *n* lines containing three integers each: the *x**i* coordinate, the *y**i* coordinate and the *z**i* coordinate of the force vector, applied to the body (<=-<=100<=≀<=*x**i*,<=*y**i*,<=*z**i*<=≀<=100). You should write the solution as standard output as follows: Print the word "YES" if the body is in equilibrium, or the word "NO" if it is not. Here are example inputs and outputs for the problem: Example Input 1: 3 4 1 7 -2 4 -1 1 -5 -3 Example Output 1: NO Example Input 2: 3 3 -1 7 -5 2 -4 2 -1 -3 Example Output 2: YES Now solve the problem by providing the code.
n=int(input()) a_1=[] b_1=[] c_1=[] for i in range(n): a,b,c=map(int,input().split()) a_1.append(a) b_1.append(b) c_1.append(c) if sum(a_1)==0 and sum(b_1)==0 and sum(c_1)==0: print("YES") else: print("NO")
vfc_82505
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3", "output": "NO", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
797
Solve the following coding problem using the programming language python: Given a positive integer *n*, find *k* integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to *n*. The input will be provided via standard input and looks as follows: The first line contains two integers *n* and *k* (2<=≀<=*n*<=≀<=100000, 1<=≀<=*k*<=≀<=20). You should write the solution as standard output as follows: If it's impossible to find the representation of *n* as a product of *k* numbers, print -1. Otherwise, print *k* integers in any order. Their product must be equal to *n*. If there are multiple answers, print any of them. Here are example inputs and outputs for the problem: Example Input 1: 100000 2 Example Output 1: 2 50000 Example Input 2: 100000 20 Example Output 2: -1 Example Input 3: 1024 5 Example Output 3: 2 64 2 2 2 Now solve the problem by providing the code.
from math import sqrt def eratosfen(x): arr = [True] * (x + 1) result = [] for i in range(2, x + 1): if arr[i]: result.append(i) for j in range(2 * i, x + 1, i): arr[j] = False return result n, k = map(int, input().split()) simples = eratosfen(n) divs = [] for simple in simples: while n % simple == 0: n //= simple divs.append(simple) if len(divs) < k: print(-1) else: while len(divs) > k: divs.append(divs.pop() * divs.pop()) print(*divs)
vfc_82509
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "100000 2", "output": "2 50000 ", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
600
Solve the following coding problem using the programming language python: You are given two arrays of integers *a* and *b*. For each element of the second array *b**j* you should find the number of elements in array *a* that are less than or equal to the value *b**j*. The input will be provided via standard input and looks as follows: The first line contains two integers *n*,<=*m* (1<=≀<=*n*,<=*m*<=≀<=2Β·105) β€” the sizes of arrays *a* and *b*. The second line contains *n* integers β€” the elements of array *a* (<=-<=109<=≀<=*a**i*<=≀<=109). The third line contains *m* integers β€” the elements of array *b* (<=-<=109<=≀<=*b**j*<=≀<=109). You should write the solution as standard output as follows: Print *m* integers, separated by spaces: the *j*-th of which is equal to the number of such elements in array *a* that are less than or equal to the value *b**j*. Here are example inputs and outputs for the problem: Example Input 1: 5 4 1 3 5 7 9 6 4 2 8 Example Output 1: 3 2 1 4 Example Input 2: 5 5 1 2 1 2 5 3 1 4 1 5 Example Output 2: 4 2 4 2 5 Now solve the problem by providing the code.
n, m = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) A.sort() result = [] def bb(A, num): ini = 0 final = len(A) - 1 while ini <= final: mid = (ini + final) // 2 if A[mid] <= num: ini = mid + 1 else: final = mid - 1 return ini for i in range(len(B)): count = bb(A, B[i]) result.append(count) print(count, end=' ')
vfc_82513
{ "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 4\n1 3 5 7 9\n6 4 2 8", "output": "3 2 1 4", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
451
Solve the following coding problem using the programming language python: After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of *n* horizontal and *m* vertical sticks. An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick. In the grid shown below, *n*<==<=3 and *m*<==<=3. There are *n*<=+<=*m*<==<=6 sticks in total (horizontal sticks are shown in red and vertical sticks are shown in green). There are *n*Β·*m*<==<=9 intersection points, numbered from 1 to 9. The rules of the game are very simple. The players move in turns. Akshat won gold, so he makes the first move. During his/her move, a player must choose any remaining intersection point and remove from the grid all sticks which pass through this point. A player will lose the game if he/she cannot make a move (i.e. there are no intersection points remaining on the grid at his/her move). Assume that both players play optimally. Who will win the game? The input will be provided via standard input and looks as follows: The first line of input contains two space-separated integers, *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=100). You should write the solution as standard output as follows: Print a single line containing "Akshat" or "Malvika" (without the quotes), depending on the winner of the game. Here are example inputs and outputs for the problem: Example Input 1: 2 2 Example Output 1: Malvika Example Input 2: 2 3 Example Output 2: Malvika Example Input 3: 3 3 Example Output 3: Akshat Now solve the problem by providing the code.
line = list(map(int, input().strip().split())) if(min(line)%2 == 0): print("Malvika") else: print("Akshat")
vfc_82517
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2", "output": "Malvika", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3", "output": "Malvika", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3", "output": "Akshat", "type": "stdin_stdout" }, { "fn_name": null, "input": "20 68", "output": "Malvika", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1", "output": "Akshat", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
120
Solve the following coding problem using the programming language python: As we all know, Winnie-the-Pooh just adores honey. Ones he and the Piglet found out that the Rabbit has recently gotten hold of an impressive amount of this sweet and healthy snack. As you may guess, Winnie and the Piglet asked to come at the Rabbit's place. Thus, there are *n* jars of honey lined up in front of Winnie-the-Pooh, jar number *i* contains *a**i* kilos of honey. Winnie-the-Pooh eats the honey like that: each time he chooses a jar containing most honey. If the jar has less that *k* kilos of honey or if Winnie-the-Pooh has already eaten from it three times, he gives the jar to Piglet. Otherwise he eats exactly *k* kilos of honey from the jar and puts it back. Winnie does so until he gives all jars to the Piglet. Count how much honey Piglet will overall get after Winnie satisfies his hunger. The input will be provided via standard input and looks as follows: The first line contains two integers *n* and *k* (1<=≀<=*n*<=≀<=100,<=1<=≀<=*k*<=≀<=100). The second line contains *n* integers *a*1, *a*2, ..., *a**n*, separated by spaces (1<=≀<=*a**i*<=≀<=100). You should write the solution as standard output as follows: Print a single number β€” how many kilos of honey gets Piglet. Here are example inputs and outputs for the problem: Example Input 1: 3 3 15 8 10 Example Output 1: 9 Now solve the problem by providing the code.
f=open('input.txt','r') g=open('output.txt','w') n,k=map(int,f.readline().split()) a=list(map(int,f.readline().split())) s,res=sum(a),0 for val in a: res+=int(k*min(3,val//k)) print(s-res,file=g)
vfc_82521
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\n15 8 10", "output": "9", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 3\n3", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 4\n3 8 2", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2\n95 25 49", "output": "151", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
567
Solve the following coding problem using the programming language python: All cities of Lineland are located on the *Ox* coordinate axis. Thus, each city is associated with its position *x**i* β€” a coordinate on the *Ox* axis. No two cities are located at a single point. Lineland residents love to send letters to each other. A person may send a letter only if the recipient lives in another city (because if they live in the same city, then it is easier to drop in). Strange but true, the cost of sending the letter is exactly equal to the distance between the sender's city and the recipient's city. For each city calculate two values ​​*min**i* and *max**i*, where *min**i* is the minimum cost of sending a letter from the *i*-th city to some other city, and *max**i* is the the maximum cost of sending a letter from the *i*-th city to some other city The input will be provided via standard input and looks as follows: The first line of the input contains integer *n* (2<=≀<=*n*<=≀<=105) β€” the number of cities in Lineland. The second line contains the sequence of *n* distinct integers *x*1,<=*x*2,<=...,<=*x**n* (<=-<=109<=≀<=*x**i*<=≀<=109), where *x**i* is the *x*-coordinate of the *i*-th city. All the *x**i*'s are distinct and follow in ascending order. You should write the solution as standard output as follows: Print *n* lines, the *i*-th line must contain two integers *min**i*,<=*max**i*, separated by a space, where *min**i* is the minimum cost of sending a letter from the *i*-th city, and *max**i* is the maximum cost of sending a letter from the *i*-th city. Here are example inputs and outputs for the problem: Example Input 1: 4 -5 -2 2 7 Example Output 1: 3 12 3 9 4 7 5 12 Example Input 2: 2 -1 1 Example Output 2: 2 2 2 2 Now solve the problem by providing the code.
n=int(input()) a=list(map(int, input().split())) for i in range(n): if i==0: print(abs(a[i+1]-a[i]),end=" ") elif i==n-1: print(abs(a[n-1]-a[n-2]),end=" ") else: print(min(abs(a[i]-a[i-1]),abs(a[i+1]-a[i])),end=" ") print(max(abs(a[i]-a[0]),abs(a[n-1]-a[i])))
vfc_82525
{ "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\n-5 -2 2 7", "output": "3 12\n3 9\n4 7\n5 12", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n-1 1", "output": "2 2\n2 2", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n-1 0 1", "output": "1 2\n1 1\n1 2", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n-1 0 1 3", "output": "1 4\n1 3\n1 2\n2 4", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
159
Solve the following coding problem using the programming language python: One popular website developed an unusual username editing procedure. One can change the username only by deleting some characters from it: to change the current name *s*, a user can pick number *p* and character *c* and delete the *p*-th occurrence of character *c* from the name. After the user changed his name, he can't undo the change. For example, one can change name "arca" by removing the second occurrence of character "a" to get "arc". Polycarpus learned that some user initially registered under nickname *t*, where *t* is a concatenation of *k* copies of string *s*. Also, Polycarpus knows the sequence of this user's name changes. Help Polycarpus figure out the user's final name. The input will be provided via standard input and looks as follows: The first line contains an integer *k* (1<=≀<=*k*<=≀<=2000). The second line contains a non-empty string *s*, consisting of lowercase Latin letters, at most 100 characters long. The third line contains an integer *n* (0<=≀<=*n*<=≀<=20000) β€” the number of username changes. Each of the next *n* lines contains the actual changes, one per line. The changes are written as "*p**i* *c**i*" (without the quotes), where *p**i* (1<=≀<=*p**i*<=≀<=200000) is the number of occurrences of letter *c**i*, *c**i* is a lowercase Latin letter. It is guaranteed that the operations are correct, that is, the letter to be deleted always exists, and after all operations not all letters are deleted from the name. The letters' occurrences are numbered starting from 1. You should write the solution as standard output as follows: Print a single string β€” the user's final name after all changes are applied to it. Here are example inputs and outputs for the problem: Example Input 1: 2 bac 3 2 a 1 b 2 c Example Output 1: acb Example Input 2: 1 abacaba 4 1 a 1 a 1 c 2 b Example Output 2: baa Now solve the problem by providing the code.
from collections import defaultdict k = int(input()) s = input() d = defaultdict(list) word = list(s*k) for i in range(len(word)): d[word[i]].append(i) n = int(input()) for _ in range(n): a,b = input().split() a = int(a) change = d[b].pop(a-1) word[change] = '' print(''.join(word))
vfc_82533
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "3000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\nbac\n3\n2 a\n1 b\n2 c", "output": "acb", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
298
Solve the following coding problem using the programming language python: There is a straight snowy road, divided into *n* blocks. The blocks are numbered from 1 to *n* from left to right. If one moves from the *i*-th block to the (*i*<=+<=1)-th block, he will leave a right footprint on the *i*-th block. Similarly, if one moves from the *i*-th block to the (*i*<=-<=1)-th block, he will leave a left footprint on the *i*-th block. If there already is a footprint on the *i*-th block, the new footprint will cover the old one. At the beginning, there were no footprints. Then polar bear Alice starts from the *s*-th block, makes a sequence of moves and ends in the *t*-th block. It is known that Alice never moves outside of the road. You are given the description of Alice's footprints. Your task is to find a pair of possible values of *s*,<=*t* by looking at the footprints. The input will be provided via standard input and looks as follows: The first line of the input contains integer *n* (3<=≀<=*n*<=≀<=1000). The second line contains the description of the road β€” the string that consists of *n* characters. Each character will be either "." (a block without footprint), or "L" (a block with a left footprint), "R" (a block with a right footprint). It's guaranteed that the given string contains at least one character not equal to ".". Also, the first and the last character will always be ".". It's guaranteed that a solution exists. You should write the solution as standard output as follows: Print two space-separated integers β€” the values of *s* and *t*. If there are several possible solutions you can print any of them. Here are example inputs and outputs for the problem: Example Input 1: 9 ..RRLL... Example Output 1: 3 4 Example Input 2: 11 .RRRLLLLL.. Example Output 2: 7 5 Now solve the problem by providing the code.
input(); a = input() l=a.count('L') r=a.count('R') if (r==0): print(a.rindex('L')+1,a.index('L')) elif (l==0): print( a.index('R')+1,a.rindex('R')+2,) else : print(a.index('R')+1,a.index('L'))
vfc_82537
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "11\n.RRRLLLLL..", "output": "7 5", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n.RL.", "output": "3 2", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n.L.", "output": "2 1", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n.R.", "output": "2 3", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
11
Solve the following coding problem using the programming language python: A sequence *a*0,<=*a*1,<=...,<=*a**t*<=-<=1 is called increasing if *a**i*<=-<=1<=&lt;<=*a**i* for each *i*:<=0<=&lt;<=*i*<=&lt;<=*t*. You are given a sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 and a positive integer *d*. In each move you may choose one element of the given sequence and add *d* to it. What is the least number of moves required to make the given sequence increasing? The input will be provided via standard input and looks as follows: The first line of the input contains two integer numbers *n* and *d* (2<=≀<=*n*<=≀<=2000,<=1<=≀<=*d*<=≀<=106). The second line contains space separated sequence *b*0,<=*b*1,<=...,<=*b**n*<=-<=1 (1<=≀<=*b**i*<=≀<=106). You should write the solution as standard output as follows: Output the minimal number of moves needed to make the sequence increasing. Here are example inputs and outputs for the problem: Example Input 1: 4 2 1 3 3 2 Example Output 1: 3 Now solve the problem by providing the code.
n, d = map(int, input().split()) p, v = 0, 0 for b in map(int, input().split()): if b <= p: c = (p + d - b) // d v += c b += c * d p = b print(v)
vfc_82541
{ "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\n1 3 3 2", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1\n1 1", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1\n2 5", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1\n1 2", "output": "0", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
873
Solve the following coding problem using the programming language python: Merge sort is a well-known sorting algorithm. The main function that sorts the elements of array *a* with indices from [*l*,<=*r*) can be implemented as follows: 1. If the segment [*l*,<=*r*) is already sorted in non-descending order (that is, for any *i* such that *l*<=≀<=*i*<=&lt;<=*r*<=-<=1 *a*[*i*]<=≀<=*a*[*i*<=+<=1]), then end the function call; 1. Let ; 1. Call *mergesort*(*a*,<=*l*,<=*mid*); 1. Call *mergesort*(*a*,<=*mid*,<=*r*); 1. Merge segments [*l*,<=*mid*) and [*mid*,<=*r*), making the segment [*l*,<=*r*) sorted in non-descending order. The merge algorithm doesn't call any other functions. The array in this problem is 0-indexed, so to sort the whole array, you need to call *mergesort*(*a*,<=0,<=*n*). The number of calls of function *mergesort* is very important, so Ivan has decided to calculate it while sorting the array. For example, if *a*<==<={1,<=2,<=3,<=4}, then there will be 1 call of *mergesort* β€” *mergesort*(0,<=4), which will check that the array is sorted and then end. If *a*<==<={2,<=1,<=3}, then the number of calls is 3: first of all, you call *mergesort*(0,<=3), which then sets *mid*<==<=1 and calls *mergesort*(0,<=1) and *mergesort*(1,<=3), which do not perform any recursive calls because segments (0,<=1) and (1,<=3) are sorted. Ivan has implemented the program that counts the number of *mergesort* calls, but now he needs to test it. To do this, he needs to find an array *a* such that *a* is a permutation of size *n* (that is, the number of elements in *a* is *n*, and every integer number from [1,<=*n*] can be found in this array), and the number of *mergesort* calls when sorting the array is exactly *k*. Help Ivan to find an array he wants! The input will be provided via standard input and looks as follows: The first line contains two numbers *n* and *k* (1<=≀<=*n*<=≀<=100000, 1<=≀<=*k*<=≀<=200000) β€” the size of a desired permutation and the number of *mergesort* calls required to sort it. You should write the solution as standard output as follows: If a permutation of size *n* such that there will be exactly *k* calls of *mergesort* while sorting it doesn't exist, output <=-<=1. Otherwise output *n* integer numbers *a*[0],<=*a*[1],<=...,<=*a*[*n*<=-<=1] β€” the elements of a permutation that would meet the required conditions. If there are multiple answers, print any of them. Here are example inputs and outputs for the problem: Example Input 1: 3 3 Example Output 1: 2 1 3 Example Input 2: 4 1 Example Output 2: 1 2 3 4 Example Input 3: 5 6 Example Output 3: -1 Now solve the problem by providing the code.
n, m = list(map(int, input().split())) solucao = [] def merge(inicio, fim, rem): if rem < 2: solucao.extend(range(inicio, fim)) return rem if fim - inicio == 1: solucao.append(inicio) return rem rem -= 2 mid = (inicio + fim + 1)//2 rem = merge(mid, fim, rem) rem = merge(inicio, mid, rem) return rem rem = merge(1, n + 1, m - 1) if rem == 0: print(' '.join(map(str, solucao))) else: print(-1)
vfc_82545
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3", "output": "2 1 3 ", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
624
Solve the following coding problem using the programming language python: You are given an alphabet consisting of *n* letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied: - the *i*-th letter occurs in the string no more than *a**i* times; - the number of occurrences of each letter in the string must be distinct for all the letters that occurred in the string at least once. 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*<=<=≀<=<=26)Β β€” the number of letters in the alphabet. The next line contains *n* integers *a**i* (1<=≀<=*a**i*<=≀<=109)Β β€” *i*-th of these integers gives the limitation on the number of occurrences of the *i*-th character in the string. You should write the solution as standard output as follows: Print a single integer β€” the maximum length of the string that meets all the requirements. Here are example inputs and outputs for the problem: Example Input 1: 3 2 5 5 Example Output 1: 11 Example Input 2: 3 1 1 2 Example Output 2: 3 Now solve the problem by providing the code.
#!/usr/bin/env python3 if __name__ == '__main__': N = int(input()) a = list(map(int, input().split())) res = 0 used = set() for c in sorted(a, reverse=True): while c and c in used: c -= 1 if c: used.add(c) res += c print(res)
vfc_82549
{ "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 5 5", "output": "11", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 1 2", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 1", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
110
Solve the following coding problem using the programming language python: Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky digits in it is a lucky number. He wonders whether number *n* is a nearly lucky number. The input will be provided via standard input and looks as follows: The only line contains an integer *n* (1<=≀<=*n*<=≀<=1018). Please do not use the %lld specificator to read or write 64-bit numbers in Π‘++. It is preferred to use the cin, cout streams or the %I64d specificator. You should write the solution as standard output as follows: Print on the single line "YES" if *n* is a nearly lucky number. Otherwise, print "NO" (without the quotes). Here are example inputs and outputs for the problem: Example Input 1: 40047 Example Output 1: NO Example Input 2: 7747774 Example Output 2: YES Example Input 3: 1000000000000000000 Example Output 3: NO Now solve the problem by providing the code.
x = str(input()) def isnearlucky(x): count = 0 for char in x: if char == "4" or char == "7": count += 1 continue count = str(count) count = count.replace("4","") count = count.replace("7","") if len(count) == 0: print("YES") else: print("NO") isnearlucky(x)
vfc_82553
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "40047", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "7747774", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000000000000000000", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "7", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "4", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "474404774", "output": "NO", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
139
Solve the following coding problem using the programming language python: One Sunday Petr went to a bookshop and bought a new book on sports programming. The book had exactly *n* pages. Petr decided to start reading it starting from the next day, that is, from Monday. Petr's got a very tight schedule and for each day of the week he knows how many pages he will be able to read on that day. Some days are so busy that Petr will have no time to read whatsoever. However, we know that he will be able to read at least one page a week. Assuming that Petr will not skip days and will read as much as he can every day, determine on which day of the week he will read the last page of the book. The input will be provided via standard input and looks as follows: The first input line contains the single integer *n* (1<=≀<=*n*<=≀<=1000) β€” the number of pages in the book. The second line contains seven non-negative space-separated integers that do not exceed 1000 β€” those integers represent how many pages Petr can read on Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday correspondingly. It is guaranteed that at least one of those numbers is larger than zero. You should write the solution as standard output as follows: Print a single number β€” the number of the day of the week, when Petr will finish reading the book. The days of the week are numbered starting with one in the natural order: Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday. Here are example inputs and outputs for the problem: Example Input 1: 100 15 20 20 15 10 30 45 Example Output 1: 6 Example Input 2: 2 1 0 0 0 0 0 0 Example Output 2: 1 Now solve the problem by providing the code.
pages = int(input()) days = list(map(int, input().split())) current = -1 while pages > 0: current += 1 if current == 7: current = 0 pages -= days[current] print(current + 1)
vfc_82557
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "100\n15 20 20 15 10 30 45", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 0 0 0 0 0 0", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\n100 200 100 200 300 400 500", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 1 1 1 1 1 1", "output": "3", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
709
Solve the following coding problem using the programming language python: Kolya is going to make fresh orange juice. He has *n* oranges of sizes *a*1,<=*a*2,<=...,<=*a**n*. Kolya will put them in the juicer in the fixed order, starting with orange of size *a*1, then orange of size *a*2 and so on. To be put in the juicer the orange must have size not exceeding *b*, so if Kolya sees an orange that is strictly greater he throws it away and continues with the next one. The juicer has a special section to collect waste. It overflows if Kolya squeezes oranges of the total size strictly greater than *d*. When it happens Kolya empties the waste section (even if there are no more oranges) and continues to squeeze the juice. How many times will he have to empty the waste section? The input will be provided via standard input and looks as follows: The first line of the input contains three integers *n*, *b* and *d* (1<=≀<=*n*<=≀<=100<=000, 1<=≀<=*b*<=≀<=*d*<=≀<=1<=000<=000)Β β€” the number of oranges, the maximum size of the orange that fits in the juicer and the value *d*, which determines the condition when the waste section should be emptied. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=1<=000<=000)Β β€” sizes of the oranges listed in the order Kolya is going to try to put them in the juicer. You should write the solution as standard output as follows: Print one integerΒ β€” the number of times Kolya will have to empty the waste section. Here are example inputs and outputs for the problem: Example Input 1: 2 7 10 5 6 Example Output 1: 1 Example Input 2: 1 5 10 7 Example Output 2: 0 Example Input 3: 3 10 10 5 7 7 Example Output 3: 1 Example Input 4: 1 1 1 1 Example Output 4: 0 Now solve the problem by providing the code.
cont = 0 c = 0 n,b,d = [int(i) for i in input().split()] lis = [int(i) for i in input().split()] for x in range(len(lis)): if lis[x] <= b: cont += lis[x] if cont > d: cont = 0 c+=1 print(c)
vfc_82561
{ "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 7 10\n5 6", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 5 10\n7", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 10 10\n5 7 7", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1 1\n1", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 951637 951638\n44069 951637", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "50 100 129\n55 130 91 19 116 3 63 52 104 76 75 27 151 99 149 147 39 148 84 9 132 49 40 112 124 141 144 93 36 32 146 74 48 38 150 55 94 32 107 69 77 81 33 57 62 98 78 127 154 126", "output": "12", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
258
Solve the following coding problem using the programming language python: The Little Elephant has an integer *a*, written in the binary notation. He wants to write this number on a piece of paper. To make sure that the number *a* fits on the piece of paper, the Little Elephant ought to delete exactly one any digit from number *a* in the binary record. At that a new number appears. It consists of the remaining binary digits, written in the corresponding order (possible, with leading zeroes). The Little Elephant wants the number he is going to write on the paper to be as large as possible. Help him find the maximum number that he can obtain after deleting exactly one binary digit and print it in the binary notation. The input will be provided via standard input and looks as follows: The single line contains integer *a*, written in the binary notation without leading zeroes. This number contains more than 1 and at most 105 digits. You should write the solution as standard output as follows: In the single line print the number that is written without leading zeroes in the binary notation β€” the answer to the problem. Here are example inputs and outputs for the problem: Example Input 1: 101 Example Output 1: 11 Example Input 2: 110010 Example Output 2: 11010 Now solve the problem by providing the code.
s=str(int(input())) flag=False for i in range(0,len(s)): if(s[i]=='0' and flag==False): flag=True elif(flag==False and i==len(s)-1): flag=True else: print(s[i],end='')
vfc_82565
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "101", "output": "11", "type": "stdin_stdout" }, { "fn_name": null, "input": "110010", "output": "11010", "type": "stdin_stdout" }, { "fn_name": null, "input": "10000", "output": "1000", "type": "stdin_stdout" }, { "fn_name": null, "input": "1111111110", "output": "111111111", "type": "stdin_stdout" }, { "fn_name": null, "input": "10100101011110101", "output": "1100101011110101", "type": "stdin_stdout" }, { "fn_name": null, "input": "111010010111", "output": "11110010111", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
546
Solve the following coding problem using the programming language python: A soldier wants to buy *w* bananas in the shop. He has to pay *k* dollars for the first banana, 2*k* dollars for the second one and so on (in other words, he has to pay *i*Β·*k* dollars for the *i*-th banana). He has *n* dollars. How many dollars does he have to borrow from his friend soldier to buy *w* bananas? The input will be provided via standard input and looks as follows: The first line contains three positive integers *k*,<=*n*,<=*w* (1<=<=≀<=<=*k*,<=*w*<=<=≀<=<=1000, 0<=≀<=*n*<=≀<=109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants. You should write the solution as standard output as follows: Output one integer β€” the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0. Here are example inputs and outputs for the problem: Example Input 1: 3 17 4 Example Output 1: 13 Now solve the problem by providing the code.
k,n,w=map(int,input().split()) total = k*(w*(w+1) // 2) borrow=max(0,total - n) print(borrow)
vfc_82569
{ "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 17 4", "output": "13", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 2 1", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1 1", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 5 6", "output": "16", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1000000000 1", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000 0 1000", "output": "500500000", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
493
Solve the following coding problem using the programming language python: Vasya decided to learn to play chess. Classic chess doesn't seem interesting to him, so he plays his own sort of chess. The queen is the piece that captures all squares on its vertical, horizontal and diagonal lines. If the cell is located on the same vertical, horizontal or diagonal line with queen, and the cell contains a piece of the enemy color, the queen is able to move to this square. After that the enemy's piece is removed from the board. The queen cannot move to a cell containing an enemy piece if there is some other piece between it and the queen. There is an *n*<=Γ—<=*n* chessboard. We'll denote a cell on the intersection of the *r*-th row and *c*-th column as (*r*,<=*c*). The square (1,<=1) contains the white queen and the square (1,<=*n*) contains the black queen. All other squares contain green pawns that don't belong to anyone. The players move in turns. The player that moves first plays for the white queen, his opponent plays for the black queen. On each move the player has to capture some piece with his queen (that is, move to a square that contains either a green pawn or the enemy queen). The player loses if either he cannot capture any piece during his move or the opponent took his queen during the previous move. Help Vasya determine who wins if both players play with an optimal strategy on the board *n*<=Γ—<=*n*. The input will be provided via standard input and looks as follows: The input contains a single number *n* (2<=≀<=*n*<=≀<=109) β€” the size of the board. You should write the solution as standard output as follows: On the first line print the answer to problem β€” string "white" or string "black", depending on who wins if the both players play optimally. If the answer is "white", then you should also print two integers *r* and *c* representing the cell (*r*,<=*c*), where the first player should make his first move to win. If there are multiple such cells, print the one with the minimum *r*. If there are still multiple squares, print the one with the minimum *c*. Here are example inputs and outputs for the problem: Example Input 1: 2 Example Output 1: white 1 2 Example Input 2: 3 Example Output 2: black Now solve the problem by providing the code.
from sys import stdin # main starts n = int(stdin.readline().strip()) if n% 2 == 0: print("white") print(1, 2) else: print("black")
vfc_82573
{ "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", "output": "white\n1 2", "type": "stdin_stdout" }, { "fn_name": null, "input": "3", "output": "black", "type": "stdin_stdout" }, { "fn_name": null, "input": "4", "output": "white\n1 2", "type": "stdin_stdout" }, { "fn_name": null, "input": "6", "output": "white\n1 2", "type": "stdin_stdout" }, { "fn_name": null, "input": "10", "output": "white\n1 2", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
455
Solve the following coding problem using the programming language python: Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence *a* consisting of *n* integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it *a**k*) and delete it, at that all elements equal to *a**k*<=+<=1 and *a**k*<=-<=1 also must be deleted from the sequence. That step brings *a**k* points to the player. Alex is a perfectionist, so he decided to get as many points as possible. Help him. The input will be provided via standard input and looks as follows: The first line contains integer *n* (1<=≀<=*n*<=≀<=105) that shows how many numbers are in Alex's sequence. The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≀<=*a**i*<=≀<=105). You should write the solution as standard output as follows: Print a single integer β€” the maximum number of points that Alex can earn. Here are example inputs and outputs for the problem: Example Input 1: 2 1 2 Example Output 1: 2 Example Input 2: 3 1 2 3 Example Output 2: 4 Example Input 3: 9 1 2 1 3 2 2 2 2 3 Example Output 3: 10 Now solve the problem by providing the code.
n = int(input()) read = list(map(int, input().split())) read.sort() count = {} exist = set() points = [[0] * 100001 for i in range(0, 2)] for i in range(0, n): if not read[i] in count: count[read[i]] = 1 exist.add(read[i]) else: count[read[i]] += 1 for i in range(0, read[n-1] + 1): if not (i in exist): points[0][i] = max(points[0][i-1], points[1][i-1]) points[1][i] = points[0][i] continue points[0][i] = max(points[0][i-1], points[1][i-1]) points[1][i] = points[0][i-1] + i*count[i] print(max(points[0][read[n-1]], points[1][read[n-1]])) # 荆屹焢 εŒ–ε­¦δΈŽεˆ†ε­ε·₯程学陒 2300011884
vfc_82577
{ "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\n1 2", "output": "2", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
66
Solve the following coding problem using the programming language python: Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1<=Γ—<=*n* in size, when viewed from above. This rectangle is divided into *n* equal square sections. The garden is very unusual as each of the square sections possesses its own fixed height and due to the newest irrigation system we can create artificial rain above each section. Creating artificial rain is an expensive operation. That's why we limit ourselves to creating the artificial rain only above one section. At that, the water from each watered section will flow into its neighbouring sections if their height does not exceed the height of the section. That is, for example, the garden can be represented by a 1<=Γ—<=5 rectangle, where the section heights are equal to 4, 2, 3, 3, 2. Then if we create an artificial rain over any of the sections with the height of 3, the water will flow over all the sections, except the ones with the height of 4. See the illustration of this example at the picture: As Petya is keen on programming, he decided to find such a section that if we create artificial rain above it, the number of watered sections will be maximal. Help him. The input will be provided via standard input and looks as follows: The first line contains a positive integer *n* (1<=≀<=*n*<=≀<=1000). The second line contains *n* positive integers which are the height of the sections. All the numbers are no less than 1 and not more than 1000. You should write the solution as standard output as follows: Print a single number, the maximal number of watered sections if we create artificial rain above exactly one section. Here are example inputs and outputs for the problem: Example Input 1: 1 2 Example Output 1: 1 Example Input 2: 5 1 2 1 2 1 Example Output 2: 3 Example Input 3: 8 1 2 1 1 1 3 3 4 Example Output 3: 6 Now solve the problem by providing the code.
n = int(input()) heights = [int(x) for x in input().split()] leftCounter = [0] * n rightCounter = [0] * n for i in range(1,n): if heights[i-1] <= heights[i]: leftCounter[i] = leftCounter[i-1] + 1 if heights[n-i-1] >= heights[n-i]: rightCounter[n-i-1] = rightCounter[n-i] + 1 maxSections = 0 for i in range(n): maxSections = max(maxSections,leftCounter[i]+rightCounter[i]+1) print(maxSections)
vfc_82581
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n2", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
7
Solve the following coding problem using the programming language python: A famous Berland's painter Kalevitch likes to shock the public. One of his last obsessions is chess. For more than a thousand years people have been playing this old game on uninteresting, monotonous boards. Kalevitch decided to put an end to this tradition and to introduce a new attitude to chessboards. As before, the chessboard is a square-checkered board with the squares arranged in a 8<=Γ—<=8 grid, each square is painted black or white. Kalevitch suggests that chessboards should be painted in the following manner: there should be chosen a horizontal or a vertical line of 8 squares (i.e. a row or a column), and painted black. Initially the whole chessboard is white, and it can be painted in the above described way one or more times. It is allowed to paint a square many times, but after the first time it does not change its colour any more and remains black. Kalevitch paints chessboards neatly, and it is impossible to judge by an individual square if it was painted with a vertical or a horizontal stroke. Kalevitch hopes that such chessboards will gain popularity, and he will be commissioned to paint chessboards, which will help him ensure a comfortable old age. The clients will inform him what chessboard they want to have, and the painter will paint a white chessboard meeting the client's requirements. It goes without saying that in such business one should economize on everything β€” for each commission he wants to know the minimum amount of strokes that he has to paint to fulfill the client's needs. You are asked to help Kalevitch with this task. The input will be provided via standard input and looks as follows: The input file contains 8 lines, each of the lines contains 8 characters. The given matrix describes the client's requirements, W character stands for a white square, and B character β€” for a square painted black. It is guaranteed that client's requirments can be fulfilled with a sequence of allowed strokes (vertical/column or horizontal/row). You should write the solution as standard output as follows: Output the only number β€” the minimum amount of rows and columns that Kalevitch has to paint on the white chessboard to meet the client's requirements. Here are example inputs and outputs for the problem: Example Input 1: WWWBWWBW BBBBBBBB WWWBWWBW WWWBWWBW WWWBWWBW WWWBWWBW WWWBWWBW WWWBWWBW Example Output 1: 3 Example Input 2: WWWWWWWW BBBBBBBB WWWWWWWW WWWWWWWW WWWWWWWW WWWWWWWW WWWWWWWW WWWWWWWW Example Output 2: 1 Now solve the problem by providing the code.
d=0 c=0 for i in range (0,8): a=input() if a!='BBBBBBBB' and d==0: d=1 for j in range (0,8): if a[j]=='B': c+=1 if a=='BBBBBBBB': c+=1 print(c)
vfc_82585
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "WWWBWWBW\nBBBBBBBB\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW\nWWWBWWBW", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "WWWWWWWW\nBBBBBBBB\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW\nWWWWWWWW", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
747
Solve the following coding problem using the programming language python: A big company decided to launch a new series of rectangular displays, and decided that the display must have exactly *n* pixels. Your task is to determine the size of the rectangular display β€” the number of lines (rows) of pixels *a* and the number of columns of pixels *b*, so that: - there are exactly *n* pixels on the display; - the number of rows does not exceed the number of columns, it means *a*<=≀<=*b*; - the difference *b*<=-<=*a* is as small as possible. The input will be provided via standard input and looks as follows: The first line contains the positive integer *n* (1<=≀<=*n*<=≀<=106)Β β€” the number of pixels display should have. You should write the solution as standard output as follows: Print two integersΒ β€” the number of rows and columns on the display. Here are example inputs and outputs for the problem: Example Input 1: 8 Example Output 1: 2 4 Example Input 2: 64 Example Output 2: 8 8 Example Input 3: 5 Example Output 3: 1 5 Example Input 4: 999999 Example Output 4: 999 1001 Now solve the problem by providing the code.
a = int(input()) b = int(a**0.5) while a%b: b -= 1 print(b, a//b)
vfc_82589
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8", "output": "2 4", "type": "stdin_stdout" }, { "fn_name": null, "input": "64", "output": "8 8", "type": "stdin_stdout" }, { "fn_name": null, "input": "5", "output": "1 5", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
260
Solve the following coding problem using the programming language python: Vasya has got two number: *a* and *b*. However, Vasya finds number *a* too short. So he decided to repeat the operation of lengthening number *a* *n* times. One operation of lengthening a number means adding exactly one digit to the number (in the decimal notation) to the right provided that the resulting number is divisible by Vasya's number *b*. If it is impossible to obtain the number which is divisible by *b*, then the lengthening operation cannot be performed. Your task is to help Vasya and print the number he can get after applying the lengthening operation to number *a* *n* times. The input will be provided via standard input and looks as follows: The first line contains three integers: *a*,<=*b*,<=*n* (1<=≀<=*a*,<=*b*,<=*n*<=≀<=105). You should write the solution as standard output as follows: In a single line print the integer without leading zeros, which Vasya can get when he applies the lengthening operations to number *a* *n* times. If no such number exists, then print number -1. If there are multiple possible answers, print any of them. Here are example inputs and outputs for the problem: Example Input 1: 5 4 5 Example Output 1: 524848 Example Input 2: 12 11 1 Example Output 2: 121 Example Input 3: 260 150 10 Example Output 3: -1 Now solve the problem by providing the code.
a,b,n = map(int,input().split()) check = 1 if a%b==0: print(a*(10**n)) else: check = 0 for y in range(10): if (a*10+y)%b==0: a = a*10+y check = 1 break else: pass if check==0: print(-1) else: print(a*(10**(n-1)))
vfc_82593
{ "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 4 5", "output": "524848", "type": "stdin_stdout" }, { "fn_name": null, "input": "12 11 1", "output": "121", "type": "stdin_stdout" }, { "fn_name": null, "input": "260 150 10", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "78843 5684 42717", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "93248 91435 1133", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "100000 10 64479", "output": "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
37
Solve the following coding problem using the programming language python: Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same. Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way possible. The input will be provided via standard input and looks as follows: The first line contains an integer *N* (1<=≀<=*N*<=≀<=1000) β€” the number of bars at Vasya’s disposal. The second line contains *N* space-separated integers *l**i* β€” the lengths of the bars. All the lengths are natural numbers not exceeding 1000. You should write the solution as standard output as follows: In one line output two numbers β€” the height of the largest tower and their total number. Remember that Vasya should use all the bars. Here are example inputs and outputs for the problem: Example Input 1: 3 1 2 3 Example Output 1: 1 3 Example Input 2: 4 6 5 6 7 Example Output 2: 2 3 Now solve the problem by providing the code.
n=int(input()) x=list(map(int, input().split())) y=set(x) maxx=[] for i in y: maxx.append(x.count(i)) print(max(maxx), len(y))
vfc_82597
{ "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 3", "output": "1 3", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n6 5 6 7", "output": "2 3", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n3 2 1 1", "output": "2 3", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
628
Solve the following coding problem using the programming language python: Limak is a little polar bear. He likes nice strings β€” strings of length *n*, consisting of lowercase English letters only. The distance between two letters is defined as the difference between their positions in the alphabet. For example, , and . Also, the distance between two nice strings is defined as the sum of distances of corresponding letters. For example, , and . Limak gives you a nice string *s* and an integer *k*. He challenges you to find any nice string *s*' that . Find any *s*' satisfying the given conditions, or print "-1" if it's impossible to do so. As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use gets/scanf/printf instead of getline/cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. The input will be provided via standard input and looks as follows: The first line contains two integers *n* and *k* (1<=≀<=*n*<=≀<=105, 0<=≀<=*k*<=≀<=106). The second line contains a string *s* of length *n*, consisting of lowercase English letters. You should write the solution as standard output as follows: If there is no string satisfying the given conditions then print "-1" (without the quotes). Otherwise, print any nice string *s*' that . Here are example inputs and outputs for the problem: Example Input 1: 4 26 bear Example Output 1: roar Example Input 2: 2 7 af Example Output 2: db Example Input 3: 3 1000 hey Example Output 3: -1 Now solve the problem by providing the code.
n, k = map(int, input().split()) s = input() ans = '' for j in range(n): a = ord(s[j]) - 97 z = 25 - a if a > z: v = min(a, k) ans += chr(ord(s[j]) - v) k -= v else: v = min(z, k) ans += chr(ord(s[j]) + v) k -= v print(ans if k == 0 else -1)
vfc_82601
{ "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 26\nbear", "output": "zcar", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
299
Solve the following coding problem using the programming language python: Ksusha the Squirrel is standing at the beginning of a straight road, divided into *n* sectors. The sectors are numbered 1 to *n*, from left to right. Initially, Ksusha stands in sector 1. Ksusha wants to walk to the end of the road, that is, get to sector *n*. Unfortunately, there are some rocks on the road. We know that Ksusha hates rocks, so she doesn't want to stand in sectors that have rocks. Ksusha the squirrel keeps fit. She can jump from sector *i* to any of the sectors *i*<=+<=1,<=*i*<=+<=2,<=...,<=*i*<=+<=*k*. Help Ksusha! Given the road description, say if she can reach the end of the road (note, she cannot stand on a rock)? The input will be provided via standard input and looks as follows: The first line contains two integers *n* and *k* (2<=≀<=*n*<=≀<=3Β·105,<=1<=≀<=*k*<=≀<=3Β·105). The next line contains *n* characters β€” the description of the road: the *i*-th character equals ".", if the *i*-th sector contains no rocks. Otherwise, it equals "#". It is guaranteed that the first and the last characters equal ".". You should write the solution as standard output as follows: Print "YES" (without the quotes) if Ksusha can reach the end of the road, otherwise print "NO" (without the quotes). Here are example inputs and outputs for the problem: Example Input 1: 2 1 .. Example Output 1: YES Example Input 2: 5 2 .#.#. Example Output 2: YES Example Input 3: 7 3 .#.###. Example Output 3: NO Now solve the problem by providing the code.
n,k = map(int, input().split()) print("YES" if max([len(s) for s in input().split('.')])<k else "NO")
vfc_82605
{ "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 1\n..", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 2\n.#.#.", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 3\n.#.###.", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 200\n..", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1\n..", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n..", "output": "YES", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
41
Solve the following coding problem using the programming language python: The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the Β«translationΒ». Vasya translated word *s* from Berlandish into Birlandish as *t*. Help him: find out if he translated the word correctly. The input will be provided via standard input and looks as follows: The first line contains word *s*, the second line contains word *t*. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols. You should write the solution as standard output as follows: If the word *t* is a word *s*, written reversely, print YES, otherwise print NO. Here are example inputs and outputs for the problem: Example Input 1: code edoc Example Output 1: YES Example Input 2: abb aba Example Output 2: NO Example Input 3: code code Example Output 3: NO Now solve the problem by providing the code.
s=input() g=input() r=s[::-1] if(g==r): print('YES') else: print('NO')
vfc_82609
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "code\nedoc", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "abb\naba", "output": "NO", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
303
Solve the following coding problem using the programming language python: Bike is interested in permutations. A permutation of length *n* is an integer sequence such that each integer from 0 to (*n*<=-<=1) appears exactly once in it. For example, [0,<=2,<=1] is a permutation of length 3 while both [0,<=2,<=2] and [1,<=2,<=3] is not. A permutation triple of permutations of length *n* (*a*,<=*b*,<=*c*) is called a Lucky Permutation Triple if and only if . The sign *a**i* denotes the *i*-th element of permutation *a*. The modular equality described above denotes that the remainders after dividing *a**i*<=+<=*b**i* by *n* and dividing *c**i* by *n* are equal. Now, he has an integer *n* and wants to find a Lucky Permutation Triple. Could you please help him? The input will be provided via standard input and looks as follows: The first line contains a single integer *n* (1<=≀<=*n*<=≀<=105). You should write the solution as standard output as follows: If no Lucky Permutation Triple of length *n* exists print -1. Otherwise, you need to print three lines. Each line contains *n* space-seperated integers. The first line must contain permutation *a*, the second line β€” permutation *b*, the third β€” permutation *c*. If there are multiple solutions, print any of them. Here are example inputs and outputs for the problem: Example Input 1: 5 Example Output 1: 1 4 3 2 0 1 0 2 4 3 2 4 0 1 3 Example Input 2: 2 Example Output 2: -1 Now solve the problem by providing the code.
n=int(input()) if n%2: a=[i for i in range(n)] b=[i for i in range(n)] c=[(a[i]+b[i])%n for i in range(n)] print(*a) print(*b) print(*c) else: print(-1)
vfc_82613
{ "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", "output": "1 4 3 2 0\n1 0 2 4 3\n2 4 0 1 3", "type": "stdin_stdout" }, { "fn_name": null, "input": "2", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "8", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "9", "output": "0 1 2 3 4 5 6 7 8 \n0 1 2 3 4 5 6 7 8 \n0 2 4 6 8 1 3 5 7 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "2", "output": "-1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
47
Solve the following coding problem using the programming language python: One day Vasya came across three Berland coins. They didn't have any numbers that's why Vasya didn't understand how their denominations differ. He supposed that if one coin is heavier than the other one, then it should be worth more. Vasya weighed all the three pairs of coins on pan balance scales and told you the results. Find out how the deminations of the coins differ or if Vasya has a mistake in the weighting results. No two coins are equal. The input will be provided via standard input and looks as follows: The input data contains the results of all the weighting, one result on each line. It is guaranteed that every coin pair was weighted exactly once. Vasya labelled the coins with letters Β«AΒ», Β«BΒ» and Β«CΒ». Each result is a line that appears as (letter)(&gt; or &lt; sign)(letter). For example, if coin "A" proved lighter than coin "B", the result of the weighting is A&lt;B. You should write the solution as standard output as follows: It the results are contradictory, print Impossible. Otherwise, print without spaces the rearrangement of letters Β«AΒ», Β«BΒ» and Β«CΒ» which represent the coins in the increasing order of their weights. Here are example inputs and outputs for the problem: Example Input 1: A&gt;B C&lt;B A&gt;C Example Output 1: CBA Example Input 2: A&lt;B B&gt;C C&gt;A Example Output 2: ACB Now solve the problem by providing the code.
a = b = c = 0 for i in range(3): s = input() if s[0] == "A" and s[1] == ">": a += 1 elif s[0] == "A" and s[1] == "<" and s[2] == "B": b += 1 elif s[0] == "A" and s[1] == "<" and s[2] == "C": c += 1 elif s[0] == "B" and s[1] == ">": b += 1 elif s[0] == "B" and s[1] == "<" and s[2] == "A": a += 1 elif s[0] == "B" and s[1] == "<" and s[2] == "C": c += 1 elif s[0] == "C" and s[1] == ">": c += 1 elif s[0] == "C" and s[1] == "<" and s[2] == "B": b += 1 elif s[0] == "C" and s[1] == "<" and s[2] == "A": a += 1 if a == b or a == c or b == c: print("Impossible") else: if a == max(a, b, c) and b == max(b, c): print("CBA") elif a == max(a, b, c) and c == max(b, c): print("BCA") elif b == max(a, b, c) and c == max(a, c): print("ACB") elif b == max(a, b, c) and a == max(a, c): print("CAB") elif c == max(a, b, c) and b == max(b, a): print("ABC") elif c == max(a, b, c) and a == max(b, a): print("BAC")
vfc_82617
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "5000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "A>B\nC<B\nA>C", "output": "CBA", "type": "stdin_stdout" }, { "fn_name": null, "input": "A<B\nB>C\nC>A", "output": "ACB", "type": "stdin_stdout" }, { "fn_name": null, "input": "A<C\nB<A\nB>C", "output": "Impossible", "type": "stdin_stdout" }, { "fn_name": null, "input": "A<B\nA<C\nB>C", "output": "ACB", "type": "stdin_stdout" }, { "fn_name": null, "input": "B>A\nC<B\nC>A", "output": "ACB", "type": "stdin_stdout" }, { "fn_name": null, "input": "A>B\nB>C\nC<A", "output": "CBA", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
12
Solve the following coding problem using the programming language python: The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of *m* fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most Β«luckyΒ» for him distribution of price tags) and the largest total price (in case of the most Β«unluckyΒ» for him distribution of price tags). The input will be provided via standard input and looks as follows: The first line of the input contains two integer number *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=100) β€” the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains *n* space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following *m* lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to *n*. Also it is known that the seller has in stock all fruits that Valera wants to buy. You should write the solution as standard output as follows: Print two numbers *a* and *b* (*a*<=≀<=*b*) β€” the minimum and the maximum possible sum which Valera may need to buy all fruits from his list. Here are example inputs and outputs for the problem: Example Input 1: 5 3 4 2 1 10 5 apple orange mango Example Output 1: 7 19 Example Input 2: 6 5 3 5 1 6 8 1 peach grapefruit banana orange orange Example Output 2: 11 30 Now solve the problem by providing the code.
enter1 = list(map(int, input().split())) n = enter1[0] m = enter1[1] li = list(map(int, input().split())) fruits = list() for i in range(m): fruits.append(input()) se = set(fruits) kol_vo = [] li_se = list(se) for i in range(len(li_se)): kol_vo.append(fruits.count(li_se[i])) kol_vo.sort() kol_vo.reverse() li.sort() sum1 = 0 sum2 = 0 for i in range(len(kol_vo)): sum1 += (li[i]*kol_vo[i]) li.reverse() for j in range(len(kol_vo)): sum2 += (li[j]*kol_vo[j]) print(sum1, sum2)
vfc_82621
{ "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\n4 2 1 10 5\napple\norange\nmango", "output": "7 19", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 5\n3 5 1 6 8 1\npeach\ngrapefruit\nbanana\norange\norange", "output": "11 30", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n91 82\neiiofpfpmemlakcystpun\nmcnzeiiofpfpmemlakcystpunfl", "output": "173 173", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 4\n1\nu\nu\nu\nu", "output": "4 4", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
371
Solve the following coding problem using the programming language python: This task will exclusively concentrate only on the arrays where all elements equal 1 and/or 2. Array *a* is *k*-period if its length is divisible by *k* and there is such array *b* of length *k*, that *a* is represented by array *b* written exactly times consecutively. In other words, array *a* is *k*-periodic, if it has period of length *k*. For example, any array is *n*-periodic, where *n* is the array length. Array [2,<=1,<=2,<=1,<=2,<=1] is at the same time 2-periodic and 6-periodic and array [1,<=2,<=1,<=1,<=2,<=1,<=1,<=2,<=1] is at the same time 3-periodic and 9-periodic. For the given array *a*, consisting only of numbers one and two, find the minimum number of elements to change to make the array *k*-periodic. If the array already is *k*-periodic, then the required value equals 0. The input will be provided via standard input and looks as follows: The first line of the input contains a pair of integers *n*, *k* (1<=≀<=*k*<=≀<=*n*<=≀<=100), where *n* is the length of the array and the value *n* is divisible by *k*. The second line contains the sequence of elements of the given array *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=2), *a**i* is the *i*-th element of the array. You should write the solution as standard output as follows: Print the minimum number of array elements we need to change to make the array *k*-periodic. If the array already is *k*-periodic, then print 0. Here are example inputs and outputs for the problem: Example Input 1: 6 2 2 1 2 2 2 1 Example Output 1: 1 Example Input 2: 8 4 1 1 2 1 1 1 2 1 Example Output 2: 0 Example Input 3: 9 3 2 1 1 1 2 1 1 1 2 Example Output 3: 3 Now solve the problem by providing the code.
n, k = map(int, input().split()) A = list(map(int, input().split())) ans = 0 for i in range(k): s1, s2 = 0, 0 for j in range(i, n, k): if A[j] == 1: s1+=1 else: s2+=1 ans = ans + min(s1, s2) print(ans)
vfc_82625
{ "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 2\n2 1 2 2 2 1", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "8 4\n1 1 2 1 1 1 2 1", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "9 3\n2 1 1 1 2 1 1 1 2", "output": "3", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
270
Solve the following coding problem using the programming language python: Emuskald needs a fence around his farm, but he is too lazy to build it himself. So he purchased a fence-building robot. He wants the fence to be a regular polygon. The robot builds the fence along a single path, but it can only make fence corners at a single angle *a*. Will the robot be able to build the fence Emuskald wants? In other words, is there a regular polygon which angles are equal to *a*? The input will be provided via standard input and looks as follows: The first line of input contains an integer *t* (0<=&lt;<=*t*<=&lt;<=180) β€” the number of tests. Each of the following *t* lines contains a single integer *a* (0<=&lt;<=*a*<=&lt;<=180) β€” the angle the robot can make corners at measured in degrees. You should write the solution as standard output as follows: For each test, output on a single line "YES" (without quotes), if the robot can build a fence Emuskald wants, and "NO" (without quotes), if it is impossible. Here are example inputs and outputs for the problem: Example Input 1: 3 30 60 90 Example Output 1: NO YES YES Now solve the problem by providing the code.
t = int(input()) rj = [] for i in range(t): a = int(input()) if a < 60: rj.append('NO') else: n = 3 kut = ((n-2)*180)/n while a >= kut: if a == kut: rj.append('YES') break n+=1 kut = ((n-2)*180)/n else: rj.append('NO') print(*rj, sep = "\n")
vfc_82629
{ "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\n30\n60\n90", "output": "NO\nYES\nYES", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n1\n2\n3\n170\n179\n25", "output": "NO\nNO\nNO\nYES\nYES\nNO", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
405
Solve the following coding problem using the programming language python: Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity. There are *n* columns of toy cubes in the box arranged in a line. The *i*-th column contains *a**i* cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange. Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the *n* columns after the gravity switch! The input will be provided via standard input and looks as follows: The first line of input contains an integer *n* (1<=≀<=*n*<=≀<=100), the number of the columns in the box. The next line contains *n* space-separated integer numbers. The *i*-th number *a**i* (1<=≀<=*a**i*<=≀<=100) denotes the number of cubes in the *i*-th column. You should write the solution as standard output as follows: Output *n* integer numbers separated by spaces, where the *i*-th number is the amount of cubes in the *i*-th column after the gravity switch. Here are example inputs and outputs for the problem: Example Input 1: 4 3 2 1 2 Example Output 1: 1 2 2 3 Example Input 2: 3 2 3 8 Example Output 2: 2 3 8 Now solve the problem by providing the code.
n = int(input()) m = input().split() x = '' for i in range(n): m[i] = int(m[i]) for i in sorted(m): x += str(i)+' ' print(x)
vfc_82633
{ "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\n3 2 1 2", "output": "1 2 2 3 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2 3 8", "output": "2 3 8 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n2 1 2 1 2", "output": "1 1 2 2 2 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1", "output": "1 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n4 3", "output": "3 4 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n100 40 60 20 1 80", "output": "1 20 40 60 80 100 ", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
556
Solve the following coding problem using the programming language python: Andrewid the Android is a galaxy-famous detective. In his free time he likes to think about strings containing zeros and ones. Once he thought about a string of length *n* consisting of zeroes and ones. Consider the following operation: we choose any two adjacent positions in the string, and if one them contains 0, and the other contains 1, then we are allowed to remove these two digits from the string, obtaining a string of length *n*<=-<=2 as a result. Now Andreid thinks about what is the minimum length of the string that can remain after applying the described operation several times (possibly, zero)? Help him to calculate this number. The input will be provided via standard input and looks as follows: First line of the input contains a single integer *n* (1<=≀<=*n*<=≀<=2Β·105), the length of the string that Andreid has. The second line contains the string of length *n* consisting only from zeros and ones. You should write the solution as standard output as follows: Output the minimum length of the string that may remain after applying the described operations several times. Here are example inputs and outputs for the problem: Example Input 1: 4 1100 Example Output 1: 0 Example Input 2: 5 01010 Example Output 2: 1 Example Input 3: 8 11101111 Example Output 3: 6 Now solve the problem by providing the code.
n=int(input()) str1=str(input()) a=str1.count('0') b=str1.count('1') print(abs(a-b))
vfc_82637
{ "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": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n01010", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
841
Solve the following coding problem using the programming language python: One day Kefa found *n* baloons. For convenience, we denote color of *i*-th baloon as *s**i* β€” lowercase letter of the Latin alphabet. Also Kefa has *k* friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset β€” print Β«YESΒ», if he can, and Β«NOΒ», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all. The input will be provided via standard input and looks as follows: The first line contains two integers *n* and *k* (1<=≀<=*n*,<=*k*<=≀<=100) β€” the number of baloons and friends. Next line contains string *s* β€” colors of baloons. You should write the solution as standard output as follows: Answer to the task β€” Β«YESΒ» or Β«NOΒ» in a single line. You can choose the case (lower or upper) for each letter arbitrary. Here are example inputs and outputs for the problem: Example Input 1: 4 2 aabb Example Output 1: YES Example Input 2: 6 3 aacaab Example Output 2: NO Now solve the problem by providing the code.
import string a , b = map(int , input().split()) s = input() f = True for i in string.ascii_lowercase: if s.count(i) > b: f = False break if f: print("YES") else: print("NO")
vfc_82641
{ "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\naabb", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 3\naacaab", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\nlu", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3\novvoo", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "36 13\nbzbzcffczzcbcbzzfzbbfzfzzbfbbcbfccbf", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "81 3\nooycgmvvrophvcvpoupepqllqttwcocuilvyxbyumdmmfapvpnxhjhxfuagpnntonibicaqjvwfhwxhbv", "output": "NO", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
899
Solve the following coding problem using the programming language python: There were *n* groups of students which came to write a training contest. A group is either one person who can write the contest with anyone else, or two people who want to write the contest in the same team. The coach decided to form teams of exactly three people for this training. Determine the maximum number of teams of three people he can form. It is possible that he can't use all groups to form teams. For groups of two, either both students should write the contest, or both should not. If two students from a group of two will write the contest, they should be in the same team. The input will be provided via standard input and looks as follows: The first line contains single integer *n* (2<=≀<=*n*<=≀<=2Β·105) β€” the number of groups. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=2), where *a**i* is the number of people in group *i*. You should write the solution as standard output as follows: Print the maximum number of teams of three people the coach can form. Here are example inputs and outputs for the problem: Example Input 1: 4 1 1 2 1 Example Output 1: 1 Example Input 2: 2 2 2 Example Output 2: 0 Example Input 3: 7 2 2 2 1 1 1 1 Example Output 3: 3 Example Input 4: 3 1 1 1 Example Output 4: 1 Now solve the problem by providing the code.
n = int(input()) list_ = list(map(int,input().split())) nof_2 = list_.count(2) nof_1 = list_.count(1) sum = 0 #print(nof_1,nof_2) if nof_2<=nof_1: sum+=nof_2 nof_1-=nof_2 sum+=(nof_1//3) else: sum+=nof_1 print(sum)
vfc_82645
{ "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 1 2 1", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
918
Solve the following coding problem using the programming language python: Eleven wants to choose a new name for herself. As a bunch of geeks, her friends suggested an algorithm to choose a name for her. Eleven wants her name to have exactly *n* characters. Her friend suggested that her name should only consist of uppercase and lowercase letters 'O'. More precisely, they suggested that the *i*-th letter of her name should be 'O' (uppercase) if *i* is a member of Fibonacci sequence, and 'o' (lowercase) otherwise. The letters in the name are numbered from 1 to *n*. Fibonacci sequence is the sequence *f* where - *f*1<==<=1, - *f*2<==<=1, - *f**n*<==<=*f**n*<=-<=2<=+<=*f**n*<=-<=1 (*n*<=&gt;<=2). As her friends are too young to know what Fibonacci sequence is, they asked you to help Eleven determine her new name. The input will be provided via standard input and looks as follows: The first and only line of input contains an integer *n* (1<=≀<=*n*<=≀<=1000). You should write the solution as standard output as follows: Print Eleven's new name on the first and only line of output. Here are example inputs and outputs for the problem: Example Input 1: 8 Example Output 1: OOOoOooO Example Input 2: 15 Example Output 2: OOOoOooOooooOoo Now solve the problem by providing the code.
s = "" def fibo(i): if i == 1: return 0 elif i == 2: return 0 a = 0 b = 1 c = 0 while c < i: c = a + b a = b b = c if c == i: return 0 return 1 for i in range(1,int(input())+1): if fibo(i) == 0: s += "O" else: s += "o" print(s)
vfc_82649
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8", "output": "OOOoOooO", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
755
Solve the following coding problem using the programming language python: PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer *n* that for each positive integer *m* number *n*Β·*m*<=+<=1 is a prime number". Unfortunately, PolandBall is not experienced yet and doesn't know that his hypothesis is incorrect. Could you prove it wrong? Write a program that finds a counterexample for any *n*. The input will be provided via standard input and looks as follows: The only number in the input is *n* (1<=≀<=*n*<=≀<=1000)Β β€” number from the PolandBall's hypothesis. You should write the solution as standard output as follows: Output such *m* that *n*Β·*m*<=+<=1 is not a prime number. Your answer will be considered correct if you output any suitable *m* such that 1<=≀<=*m*<=≀<=103. It is guaranteed the the answer exists. Here are example inputs and outputs for the problem: Example Input 1: 3 Example Output 1: 1 Example Input 2: 4 Example Output 2: 2 Now solve the problem by providing the code.
from math import sqrt n=int(input()) m=1 while True: x=(n*m)+1 flag=0 for _ in range(2,int(sqrt(x))+1): if x%_==0: flag=1 break if flag==1: print(m) break m+=1
vfc_82653
{ "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", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "4", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "10", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "153", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
579
Solve the following coding problem using the programming language python: You are a lover of bacteria. You want to raise some bacteria in a box. Initially, the box is empty. Each morning, you can put any number of bacteria into the box. And each night, every bacterium in the box will split into two bacteria. You hope to see exactly *x* bacteria in the box at some moment. What is the minimum number of bacteria you need to put into the box across those days? The input will be provided via standard input and looks as follows: The only line containing one integer *x* (1<=≀<=*x*<=≀<=109). You should write the solution as standard output as follows: The only line containing one integer: the answer. Here are example inputs and outputs for the problem: Example Input 1: 5 Example Output 1: 2 Example Input 2: 8 Example Output 2: 1 Now solve the problem by providing the code.
n=int(input()) s=1 while n!=1: if n%2==0: n//=2 else: s+=1 n-=1 print(s)
vfc_82657
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "8", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "536870911", "output": "29", "type": "stdin_stdout" }, { "fn_name": null, "input": "1", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
1009
Solve the following coding problem using the programming language python: Maxim wants to buy some games at the local game shop. There are $n$ games in the shop, the $i$-th game costs $c_i$. Maxim has a wallet which can be represented as an array of integers. His wallet contains $m$ bills, the $j$-th bill has value $a_j$. Games in the shop are ordered from left to right, Maxim tries to buy every game in that order. When Maxim stands at the position $i$ in the shop, he takes the first bill from his wallet (if his wallet is empty then he proceeds to the next position immediately) and tries to buy the $i$-th game using this bill. After Maxim tried to buy the $n$-th game, he leaves the shop. Maxim buys the $i$-th game if and only if the value of the first bill (which he takes) from his wallet is greater or equal to the cost of the $i$-th game. If he successfully buys the $i$-th game, the first bill from his wallet disappears and the next bill becomes first. Otherwise Maxim leaves the first bill in his wallet (this bill still remains the first one) and proceeds to the next game. For example, for array $c = [2, 4, 5, 2, 4]$ and array $a = [5, 3, 4, 6]$ the following process takes place: Maxim buys the first game using the first bill (its value is $5$), the bill disappears, after that the second bill (with value $3$) becomes the first one in Maxim's wallet, then Maxim doesn't buy the second game because $c_2 &gt; a_2$, the same with the third game, then he buys the fourth game using the bill of value $a_2$ (the third bill becomes the first one in Maxim's wallet) and buys the fifth game using the bill of value $a_3$. Your task is to get the number of games Maxim will buy. The input will be provided via standard input and looks as follows: The first line of the input contains two integers $n$ and $m$ ($1 \le n, m \le 1000$) β€” the number of games and the number of bills in Maxim's wallet. The second line of the input contains $n$ integers $c_1, c_2, \dots, c_n$ ($1 \le c_i \le 1000$), where $c_i$ is the cost of the $i$-th game. The third line of the input contains $m$ integers $a_1, a_2, \dots, a_m$ ($1 \le a_j \le 1000$), where $a_j$ is the value of the $j$-th bill from the Maxim's wallet. You should write the solution as standard output as follows: Print a single integer β€” the number of games Maxim will buy. Here are example inputs and outputs for the problem: Example Input 1: 5 4 2 4 5 2 4 5 3 4 6 Example Output 1: 3 Example Input 2: 5 2 20 40 50 20 40 19 20 Example Output 2: 0 Example Input 3: 6 4 4 8 15 16 23 42 1000 1000 1000 1000 Example Output 3: 4 Now solve the problem by providing the code.
n, m = [int(x) for x in input().split(' ')] c = [int(x) for x in input().split(' ')] a = [int(x) for x in input().split(' ')] cnt = 0 for i in range(n): if c[i] <= a[0]: a.pop(0) cnt += 1 if len(a) <= 0: break print(cnt)
vfc_82661
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1500" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 4\n2 4 5 2 4\n5 3 4 6", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 2\n20 40 50 20 40\n19 20", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 4\n4 8 15 16 23 42\n1000 1000 1000 1000", "output": "4", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
232
Solve the following coding problem using the programming language python: John Doe started thinking about graphs. After some thought he decided that he wants to paint an undirected graph, containing exactly *k* cycles of length 3. A cycle of length 3 is an unordered group of three distinct graph vertices *a*, *b* and *c*, such that each pair of them is connected by a graph edge. John has been painting for long, but he has not been a success. Help him find such graph. Note that the number of vertices there shouldn't exceed 100, or else John will have problems painting it. The input will be provided via standard input and looks as follows: A single line contains an integer *k* (1<=≀<=*k*<=≀<=105) β€” the number of cycles of length 3 in the required graph. You should write the solution as standard output as follows: In the first line print integer *n* (3<=≀<=*n*<=≀<=100) β€” the number of vertices in the found graph. In each of next *n* lines print *n* characters "0" and "1": the *i*-th character of the *j*-th line should equal "0", if vertices *i* and *j* do not have an edge between them, otherwise it should equal "1". Note that as the required graph is undirected, the *i*-th character of the *j*-th line must equal the *j*-th character of the *i*-th line. The graph shouldn't contain self-loops, so the *i*-th character of the *i*-th line must equal "0" for all *i*. Here are example inputs and outputs for the problem: Example Input 1: 1 Example Output 1: 3 011 101 110 Example Input 2: 10 Example Output 2: 5 01111 10111 11011 11101 11110 Now solve the problem by providing the code.
import sys import math c=int(input()) Ans=[] F=[1] for i in range(1,101): F.append(F[-1]*i) for i in range(100): Ans.append([0]*100) print(100) cycles=1 Ans[0][1]=1 Ans[1][0]=1 Ans[1][2]=1 Ans[2][1]=1 Ans[0][2]=1 Ans[2][0]=1 m=3 while(cycles<c): Ans[0][m]=1 Ans[m][0]=1 inc=1 for j in range(1,m): Ans[j][m]=1 Ans[m][j]=1 cycles+=inc inc+=1 if(cycles+inc>c): break m+=1 A="" for i in range(100): for j in range(100): A+=str(Ans[i][j]) A+="\n" sys.stdout.write(A)
vfc_82665
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "4000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1", "output": "3\n011\n101\n110", "type": "stdin_stdout" }, { "fn_name": null, "input": "10", "output": "5\n01111\n10111\n11011\n11101\n11110", "type": "stdin_stdout" }, { "fn_name": null, "input": "2", "output": "4\n0111\n1011\n1100\n1100", "type": "stdin_stdout" }, { "fn_name": null, "input": "3", "output": "5\n01001\n10111\n01001\n01001\n11110", "type": "stdin_stdout" }, { "fn_name": null, "input": "4", "output": "4\n0111\n1011\n1101\n1110", "type": "stdin_stdout" }, { "fn_name": null, "input": "5", "output": "5\n01001\n10111\n01011\n01101\n11110", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
559
Solve the following coding problem using the programming language python: Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to . Then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters. There the properties of the hexagon ended and Gerald decided to draw on it. He painted a few lines, parallel to the sides of the hexagon. The lines split the hexagon into regular triangles with sides of 1 centimeter. Now Gerald wonders how many triangles he has got. But there were so many of them that Gerald lost the track of his counting. Help the boy count the triangles. The input will be provided via standard input and looks as follows: The first and the single line of the input contains 6 space-separated integers *a*1,<=*a*2,<=*a*3,<=*a*4,<=*a*5 and *a*6 (1<=≀<=*a**i*<=≀<=1000) β€” the lengths of the sides of the hexagons in centimeters in the clockwise order. It is guaranteed that the hexagon with the indicated properties and the exactly such sides exists. You should write the solution as standard output as follows: Print a single integer β€” the number of triangles with the sides of one 1 centimeter, into which the hexagon is split. Here are example inputs and outputs for the problem: Example Input 1: 1 1 1 1 1 1 Example Output 1: 6 Example Input 2: 1 2 1 2 1 2 Example Output 2: 13 Now solve the problem by providing the code.
a = list(map(int, input().split(' '))) print((a[0]+a[1]+a[2])**2 - (a[0]**2 + a[2]**2 +a[4]**2))
vfc_82669
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 1 1 1 1 1", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 2 1 2 1 2", "output": "13", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 4 5 3 3 6", "output": "83", "type": "stdin_stdout" }, { "fn_name": null, "input": "45 19 48 18 46 21", "output": "6099", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
719
Solve the following coding problem using the programming language python: Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are *n* cockroaches living in Anatoly's room. Anatoly just made all his cockroaches to form a single line. As he is a perfectionist, he would like the colors of cockroaches in the line to alternate. He has a can of black paint and a can of red paint. In one turn he can either swap any two cockroaches, or take any single cockroach and change it's color. Help Anatoly find out the minimum number of turns he needs to make the colors of cockroaches in the line alternate. 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 cockroaches. The second line contains a string of length *n*, consisting of characters 'b' and 'r' that denote black cockroach and red cockroach respectively. You should write the solution as standard output as follows: Print one integerΒ β€” the minimum number of moves Anatoly has to perform in order to make the colors of cockroaches in the line to alternate. Here are example inputs and outputs for the problem: Example Input 1: 5 rbbrr Example Output 1: 1 Example Input 2: 5 bbbbb Example Output 2: 2 Example Input 3: 3 rbr Example Output 3: 0 Now solve the problem by providing the code.
N = int(input()) This, Ans = input(), [] for i in ['rb', 'br']: Should = i * (N // 2) + i[:N % 2] WasR = This.count('r') NowR = Should.count('r') Diff = sum(1 for i, j in zip(This, Should) if i != j) Ans.append((Diff - abs(WasR - NowR)) // 2 + abs(WasR - NowR)) print(min(Ans)) # Hope the best for Ravens # Never give up
vfc_82673
{ "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\nrbbrr", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\nbbbbb", "output": "2", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
275
Solve the following coding problem using the programming language python: Lenny is playing a game on a 3<=Γ—<=3 grid of lights. In the beginning of the game all lights are switched on. Pressing any of the lights will toggle it and all side-adjacent lights. The goal of the game is to switch all the lights off. We consider the toggling as follows: if the light was switched on then it will be switched off, if it was switched off then it will be switched on. Lenny has spent some time playing with the grid and by now he has pressed each light a certain number of times. Given the number of times each light is pressed, you have to print the current state of each light. The input will be provided via standard input and looks as follows: The input consists of three rows. Each row contains three integers each between 0 to 100 inclusive. The *j*-th number in the *i*-th row is the number of times the *j*-th light of the *i*-th row of the grid is pressed. You should write the solution as standard output as follows: Print three lines, each containing three characters. The *j*-th character of the *i*-th line is "1" if and only if the corresponding light is switched on, otherwise it's "0". Here are example inputs and outputs for the problem: Example Input 1: 1 0 0 0 0 0 0 0 1 Example Output 1: 001 010 100 Example Input 2: 1 0 1 8 8 8 2 0 3 Example Output 2: 010 011 100 Now solve the problem by providing the code.
arr= [] for i in range(3): l=list(map(int,input().split())) arr.append(l) ans=[["1","1","1"],["1","1","1"],["1","1","1"]] for r in range(3): for c in range(3): row=r col=c temp= arr[row][col] if row-1>=0: temp+=arr[row-1][col] if row+1<=2: temp+=arr[row+1][col] if col+1<=2: temp+=arr[row][col+1] if col-1>=0: temp+=arr[row][col-1] if temp%2 !=0: ans[r][c]='0' print(''.join(ans[0])) print(''.join(ans[1])) print(''.join(ans[2]))
vfc_82677
{ "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 0 0\n0 0 0\n0 0 1", "output": "001\n010\n100", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 0 1\n8 8 8\n2 0 3", "output": "010\n011\n100", "type": "stdin_stdout" }, { "fn_name": null, "input": "13 85 77\n25 50 45\n65 79 9", "output": "000\n010\n000", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
450
Solve the following coding problem using the programming language python: There are *n* children in Jzzhu's school. Jzzhu is going to give some candies to them. Let's number all the children from 1 to *n*. The *i*-th child wants to get at least *a**i* candies. Jzzhu asks children to line up. Initially, the *i*-th child stands at the *i*-th place of the line. Then Jzzhu start distribution of the candies. He follows the algorithm: 1. Give *m* candies to the first child of the line. 1. If this child still haven't got enough candies, then the child goes to the end of the line, else the child go home. 1. Repeat the first two steps while the line is not empty. Consider all the children in the order they go home. Jzzhu wants to know, which child will be the last in this order? The input will be provided via standard input and looks as follows: The first line contains two integers *n*,<=*m* (1<=≀<=*n*<=≀<=100;Β 1<=≀<=*m*<=≀<=100). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=100). You should write the solution as standard output as follows: Output a single integer, representing the number of the last child. Here are example inputs and outputs for the problem: Example Input 1: 5 2 1 3 1 4 2 Example Output 1: 4 Example Input 2: 6 4 1 1 2 2 3 3 Example Output 2: 6 Now solve the problem by providing the code.
n,m = map(int,input().split()) arr = [i for i in range(n)] v = list(map(int,input().split())) while len(arr)>1: # print(arr) v[arr[0]]-=m if v[arr[0]]<=0: arr.pop(0) else: n = arr.pop(0) arr.append(n) print(arr[0]+1)
vfc_82681
{ "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\n1 3 1 4 2", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 4\n1 1 2 2 3 3", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 3\n6 1 5 4 2 3 1", "output": "4", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
727
Solve the following coding problem using the programming language python: Vasily has a number *a*, which he wants to turn into a number *b*. For this purpose, he can do two types of operations: - multiply the current number by 2 (that is, replace the number *x* by 2Β·*x*); - append the digit 1 to the right of current number (that is, replace the number *x* by 10Β·*x*<=+<=1). You need to help Vasily to transform the number *a* into the number *b* using only the operations described above, or find that it is impossible. Note that in this task you are not required to minimize the number of operations. It suffices to find any way to transform *a* into *b*. The input will be provided via standard input and looks as follows: The first line contains two positive integers *a* and *b* (1<=≀<=*a*<=&lt;<=*b*<=≀<=109)Β β€” the number which Vasily has and the number he wants to have. You should write the solution as standard output as follows: If there is no way to get *b* from *a*, print "NO" (without quotes). Otherwise print three lines. On the first line print "YES" (without quotes). The second line should contain single integer *k*Β β€” the length of the transformation sequence. On the third line print the sequence of transformations *x*1,<=*x*2,<=...,<=*x**k*, where: - *x*1 should be equal to *a*, - *x**k* should be equal to *b*, - *x**i* should be obtained from *x**i*<=-<=1 using any of two described operations (1<=&lt;<=*i*<=≀<=*k*). If there are multiple answers, print any of them. Here are example inputs and outputs for the problem: Example Input 1: 2 162 Example Output 1: YES 5 2 4 8 81 162 Example Input 2: 4 42 Example Output 2: NO Example Input 3: 100 40021 Example Output 3: YES 5 100 200 2001 4002 40021 Now solve the problem by providing the code.
def fc(a,b,re,bl,tmp): if(a>b): return if(a==b): bl[0]=False # tmp.append(a) re.append(tmp) return if(bl[0]): fc(a*2,b,re,bl,tmp+[a*2]) fc(a*10+1,b,re,bl,tmp+[a*10+1]) re=[] bl=[True] # fc(2,162,re,bl,[]) a,b=map(int,input().split()) fc(a,b,re,bl,[]) if(len(re)==0): print("NO") else: print("YES") print(1+len(re[0])) ans=[[a]+re[0]] print(a,end=" ") for i in re[0]: print(i,end=" ") print()
vfc_82685
{ "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 162", "output": "YES\n5\n2 4 8 81 162 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 42", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "100 40021", "output": "YES\n5\n100 200 2001 4002 40021 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 111111111", "output": "YES\n9\n1 11 111 1111 11111 111111 1111111 11111111 111111111 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1000000000", "output": "NO", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
194
Solve the following coding problem using the programming language python: One day the Codeforces round author sat exams. He had *n* exams and he needed to get an integer from 2 to 5 for each exam. He will have to re-sit each failed exam, i.e. the exam that gets mark 2. The author would need to spend too much time and effort to make the sum of his marks strictly more than *k*. That could have spoilt the Codeforces round. On the other hand, if the sum of his marks is strictly less than *k*, the author's mum won't be pleased at all. The Codeforces authors are very smart and they always get the mark they choose themselves. Also, the Codeforces authors just hate re-sitting exams. Help the author and find the minimum number of exams he will have to re-sit if he passes the exams in the way that makes the sum of marks for all *n* exams equal exactly *k*. The input will be provided via standard input and looks as follows: The single input line contains space-separated integers *n* and *k* (1<=≀<=*n*<=≀<=50, 1<=≀<=*k*<=≀<=250) β€” the number of exams and the required sum of marks. It is guaranteed that there exists a way to pass *n* exams in the way that makes the sum of marks equal exactly *k*. You should write the solution as standard output as follows: Print the single number β€” the minimum number of exams that the author will get a 2 for, considering that the sum of marks for all exams must equal *k*. Here are example inputs and outputs for the problem: Example Input 1: 4 8 Example Output 1: 4 Example Input 2: 4 10 Example Output 2: 2 Example Input 3: 1 3 Example Output 3: 0 Now solve the problem by providing the code.
n, m = map(int, input().split()) print(max(0, n*3-m)) # FMZJMSOMPMSL
vfc_82689
{ "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 8", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 10", "output": "2", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
492
Solve the following coding problem using the programming language python: Vanya got *n* cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1<=+<=2<==<=3 cubes, the third level must have 1<=+<=2<=+<=3<==<=6 cubes, and so on. Thus, the *i*-th level of the pyramid must have 1<=+<=2<=+<=...<=+<=(*i*<=-<=1)<=+<=*i* cubes. Vanya wants to know what is the maximum height of the pyramid that he can make using the given cubes. The input will be provided via standard input and looks as follows: The first line contains integer *n* (1<=≀<=*n*<=≀<=104) β€” the number of cubes given to Vanya. You should write the solution as standard output as follows: Print the maximum possible height of the pyramid in the single line. Here are example inputs and outputs for the problem: Example Input 1: 1 Example Output 1: 1 Example Input 2: 25 Example Output 2: 4 Now solve the problem by providing the code.
n = int(input()) levels = 0 prev, current = 0, 0 add = 0 s = 0 while True: if levels % 2 == 1: add += 1 current = prev + 1 + 2 * add if levels % 2 == 0 else prev + 2 * add s += current if s > n: break prev = current levels += 1 print(levels)
vfc_82693
{ "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": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "25", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "2", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "4115", "output": "28", "type": "stdin_stdout" }, { "fn_name": null, "input": "9894", "output": "38", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
276
Solve the following coding problem using the programming language python: The little girl loves the problems on array queries very much. One day she came across a rather well-known problem: you've got an array of $n$ elements (the elements of the array are indexed starting from 1); also, there are $q$ queries, each one is defined by a pair of integers $l_i$, $r_i$ $(1 \le l_i \le r_i \le n)$. You need to find for each query the sum of elements of the array with indexes from $l_i$ to $r_i$, inclusive. The little girl found the problem rather boring. She decided to reorder the array elements before replying to the queries in a way that makes the sum of query replies maximum possible. Your task is to find the value of this maximum sum. The input will be provided via standard input and looks as follows: The first line contains two space-separated integers $n$ ($1 \le n \le 2\cdot10^5$) and $q$ ($1 \le q \le 2\cdot10^5$) β€” the number of elements in the array and the number of queries, correspondingly. The next line contains $n$ space-separated integers $a_i$ ($1 \le a_i \le 2\cdot10^5$) β€” the array elements. Each of the following $q$ lines contains two space-separated integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$) β€” the $i$-th query. You should write the solution as standard output as follows: In a single line print, a single integer β€” the maximum sum of query replies after the array elements are reordered. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. Here are example inputs and outputs for the problem: Example Input 1: 3 3 5 3 2 1 2 2 3 1 3 Example Output 1: 25 Example Input 2: 5 3 5 2 4 1 3 1 5 2 3 2 3 Example Output 2: 33 Now solve the problem by providing the code.
from sys import stdin def get_input(): # Faster IO input_str = stdin.read().strip().split('\n') n, q = map(int, input_str[0].split()) arr = list(map(int, input_str[1].split())) queries = [map(int, input_str[i].split()) for i in range(2, len(input_str))] return arr, queries def get_max(arr, queries): n = len(arr) freq = [0] * (n + 2) for l, r in queries: freq[l] += 1 freq[r + 1] -= 1 for i in range(1, n + 1): freq[i] += freq[i - 1] freq.pop(0) freq.pop() freq.sort() arr.sort() # print(arr, freq) s = 0 for i in range(n): s += arr[i] * freq[i] return s print(get_max(*get_input()))
vfc_82701
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\n5 3 2\n1 2\n2 3\n1 3", "output": "25", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3\n5 2 4 1 3\n1 5\n2 3\n2 3", "output": "33", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
614
Solve the following coding problem using the programming language python: It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, find their product. If it is turns to be too large, then the servers might have not enough time to assign tanks into teams and the whole game will collapse! There are exactly *n* distinct countries in the world and the *i*-th country added *a**i* tanks to the game. As the developers of the game are perfectionists, the number of tanks from each country is beautiful. A beautiful number, according to the developers, is such number that its decimal representation consists only of digits '1' and '0', moreover it contains at most one digit '1'. However, due to complaints from players, some number of tanks of one country was removed from the game, hence the number of tanks of this country may not remain beautiful. Your task is to write the program that solves exactly the same problem in order to verify Gena's code correctness. Just in case. The input will be provided via standard input and looks as follows: The first line of the input contains the number of countries *n* (1<=≀<=*n*<=≀<=100<=000). The second line contains *n* non-negative integers *a**i* without leading zeroesΒ β€” the number of tanks of the *i*-th country. It is guaranteed that the second line contains at least *n*<=-<=1 beautiful numbers and the total length of all these number's representations doesn't exceed 100<=000. You should write the solution as standard output as follows: Print a single number without leading zeroesΒ β€” the product of the number of tanks presented by each country. Here are example inputs and outputs for the problem: Example Input 1: 3 5 10 1 Example Output 1: 50 Example Input 2: 4 1 1 10 11 Example Output 2: 110 Example Input 3: 5 0 3 1 100 1 Example Output 3: 0 Now solve the problem by providing the code.
n = int(input()) lis = input().split() #print(lis) ans=1 zer=0 for i in lis: l=len(i) k=i.count('1') j=i.count('0') if k+j==l: if k>1: ans*=int(i) else: if j==l: print('0') exit() else: zer+=l-i.find('1')-1 # print(i.find('1'),zer) else: ans*=i p='' for i in range(zer): p+='0' print(str(ans)+p)
vfc_82705
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "500" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n5 10 1", "output": "50", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 1 10 11", "output": "110", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
731
Solve the following coding problem using the programming language python: Grigoriy, like the hero of one famous comedy film, found a job as a night security guard at the museum. At first night he received embosser and was to take stock of the whole exposition. Embosser is a special devise that allows to "print" the text of a plastic tape. Text is printed sequentially, character by character. The device consists of a wheel with a lowercase English letters written in a circle, static pointer to the current letter and a button that print the chosen letter. At one move it's allowed to rotate the alphabetic wheel one step clockwise or counterclockwise. Initially, static pointer points to letter 'a'. Other letters are located as shown on the picture: After Grigoriy add new item to the base he has to print its name on the plastic tape and attach it to the corresponding exhibit. It's not required to return the wheel to its initial position with pointer on the letter 'a'. Our hero is afraid that some exhibits may become alive and start to attack him, so he wants to print the names as fast as possible. Help him, for the given string find the minimum number of rotations of the wheel required to print it. The input will be provided via standard input and looks as follows: The only line of input contains the name of some exhibitΒ β€” the non-empty string consisting of no more than 100 characters. It's guaranteed that the string consists of only lowercase English letters. You should write the solution as standard output as follows: Print one integerΒ β€” the minimum number of rotations of the wheel, required to print the name given in the input. Here are example inputs and outputs for the problem: Example Input 1: zeus Example Output 1: 18 Example Input 2: map Example Output 2: 35 Example Input 3: ares Example Output 3: 34 Now solve the problem by providing the code.
s = 'abcdefghijklmnopqrstuvwxyz'; word = input(); result = 0; ptr = 0; for i in range(len(word)): from_st = s.index(word[i]); from_end = s[::-1].index(word[i]); if(from_st > from_end): ptr = from_end; start = s[26 - ptr-1::]; end = s[0:26-ptr-1]; else: ptr = from_st; start = s[ptr:]; end = s[0:ptr]; if(len(start) < len(end)): result += len(start); else: result += len(end); s = start + end; print(result);
vfc_82709
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "zeus", "output": "18", "type": "stdin_stdout" }, { "fn_name": null, "input": "map", "output": "35", "type": "stdin_stdout" }, { "fn_name": null, "input": "ares", "output": "34", "type": "stdin_stdout" }, { "fn_name": null, "input": "l", "output": "11", "type": "stdin_stdout" }, { "fn_name": null, "input": "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv", "output": "99", "type": "stdin_stdout" }, { "fn_name": null, "input": "gngvi", "output": "44", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
735
Solve the following coding problem using the programming language python: On the way to Rio de Janeiro Ostap kills time playing with a grasshopper he took with him in a special box. Ostap builds a line of length *n* such that some cells of this line are empty and some contain obstacles. Then, he places his grasshopper to one of the empty cells and a small insect in another empty cell. The grasshopper wants to eat the insect. Ostap knows that grasshopper is able to jump to any empty cell that is exactly *k* cells away from the current (to the left or to the right). Note that it doesn't matter whether intermediate cells are empty or not as the grasshopper makes a jump over them. For example, if *k*<==<=1 the grasshopper can jump to a neighboring cell only, and if *k*<==<=2 the grasshopper can jump over a single cell. Your goal is to determine whether there is a sequence of jumps such that grasshopper will get from his initial position to the cell with an insect. The input will be provided via standard input and looks as follows: The first line of the input contains two integers *n* and *k* (2<=≀<=*n*<=≀<=100, 1<=≀<=*k*<=≀<=*n*<=-<=1)Β β€” the number of cells in the line and the length of one grasshopper's jump. The second line contains a string of length *n* consisting of characters '.', '#', 'G' and 'T'. Character '.' means that the corresponding cell is empty, character '#' means that the corresponding cell contains an obstacle and grasshopper can't jump there. Character 'G' means that the grasshopper starts at this position and, finally, 'T' means that the target insect is located at this cell. It's guaranteed that characters 'G' and 'T' appear in this line exactly once. You should write the solution as standard output as follows: If there exists a sequence of jumps (each jump of length *k*), such that the grasshopper can get from his initial position to the cell with the insect, print "YES" (without quotes) in the only line of the input. Otherwise, print "NO" (without quotes). Here are example inputs and outputs for the problem: Example Input 1: 5 2 #G#T# Example Output 1: YES Example Input 2: 6 1 T....G Example Output 2: YES Example Input 3: 7 3 T..#..G Example Output 3: NO Example Input 4: 6 2 ..GT.. Example Output 4: NO Now solve the problem by providing the code.
n,k = map(int,input().split()) cell = list(map(str,input().strip())) a = cell.index("G") b = cell.index("T") if(a>b): if((a-b)%k != 0): print("NO") else: for i in range(1,(a-b)//k + 1): if(cell[b + k*i] == "#"): print("NO") break elif(cell[b + k*i] == "G"): print("YES") break else: if((b-a)%k != 0): print("NO") else: for i in range(1,(b-a)//k + 1): if(cell[a + k*i] == "#"): print("NO") break elif(cell[a + k*i] == "T"): print("YES") break
vfc_82713
{ "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\n#G#T#", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 1\nT....G", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 3\nT..#..G", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 2\n..GT..", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1\nGT", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "100 5\nG####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####.####T####", "output": "YES", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
421
Solve the following coding problem using the programming language python: Pasha has two hamsters: Arthur and Alexander. Pasha put *n* apples in front of them. Pasha knows which apples Arthur likes. Similarly, Pasha knows which apples Alexander likes. Pasha doesn't want any conflict between the hamsters (as they may like the same apple), so he decided to distribute the apples between the hamsters on his own. He is going to give some apples to Arthur and some apples to Alexander. It doesn't matter how many apples each hamster gets but it is important that each hamster gets only the apples he likes. It is possible that somebody doesn't get any apples. Help Pasha distribute all the apples between the hamsters. Note that Pasha wants to distribute all the apples, not just some of them. The input will be provided via standard input and looks as follows: The first line contains integers *n*, *a*, *b* (1<=≀<=*n*<=≀<=100;Β 1<=≀<=*a*,<=*b*<=≀<=*n*) β€” the number of apples Pasha has, the number of apples Arthur likes and the number of apples Alexander likes, correspondingly. The next line contains *a* distinct integers β€” the numbers of the apples Arthur likes. The next line contains *b* distinct integers β€” the numbers of the apples Alexander likes. Assume that the apples are numbered from 1 to *n*. The input is such that the answer exists. You should write the solution as standard output as follows: Print *n* characters, each of them equals either 1 or 2. If the *i*-h character equals 1, then the *i*-th apple should be given to Arthur, otherwise it should be given to Alexander. If there are multiple correct answers, you are allowed to print any of them. Here are example inputs and outputs for the problem: Example Input 1: 4 2 3 1 2 2 3 4 Example Output 1: 1 1 2 2 Example Input 2: 5 5 2 3 4 1 2 5 2 3 Example Output 2: 1 1 1 1 1 Now solve the problem by providing the code.
n, a, b = list(map(int, input().split())) aa = list(map(int, input().split())) ab = list(map(int, input().split())) ans = [0] * n for a in aa: ans[a - 1] = '1' for a in ab: ans[a - 1] = '2' print(' '.join(ans))
vfc_82717
{ "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 3\n1 2\n2 3 4", "output": "1 1 2 2", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5 2\n3 4 1 2 5\n2 3", "output": "1 1 1 1 1", "type": "stdin_stdout" }, { "fn_name": null, "input": "100 69 31\n1 3 4 5 6 7 8 9 10 11 12 14 15 16 17 18 19 20 21 24 26 27 29 31 37 38 39 40 44 46 48 49 50 51 53 55 56 57 58 59 60 61 63 64 65 66 67 68 69 70 71 72 74 76 77 78 79 80 81 82 83 89 92 94 95 97 98 99 100\n2 13 22 23 25 28 30 32 33 34 35 36 41 42 43 45 47 52 54 62 73 75 84 85 86 87 88 90 91 93 96", "output": "1 2 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 2 2 1 2 1 1 2 1 2 1 2 2 2 2 2 1 1 1 1 2 2 2 1 2 1 2 1 1 1 1 2 1 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1 2 2 2 2 2 1 2 2 1 2 1 1 2 1 1 1 1", "type": "stdin_stdout" }, { "fn_name": null, "input": "100 56 44\n1 2 5 8 14 15 17 18 20 21 23 24 25 27 30 33 34 35 36 38 41 42 44 45 46 47 48 49 50 53 56 58 59 60 62 63 64 65 68 69 71 75 76 80 81 84 87 88 90 91 92 94 95 96 98 100\n3 4 6 7 9 10 11 12 13 16 19 22 26 28 29 31 32 37 39 40 43 51 52 54 55 57 61 66 67 70 72 73 74 77 78 79 82 83 85 86 89 93 97 99", "output": "1 1 2 2 1 2 2 1 2 2 2 2 2 1 1 2 1 1 2 1 1 2 1 1 1 2 1 2 2 1 2 2 1 1 1 1 2 1 2 2 1 1 2 1 1 1 1 1 1 1 2 2 1 2 2 1 2 1 1 1 2 1 1 1 1 2 2 1 1 2 1 2 2 2 1 1 2 2 2 1 1 2 2 1 2 2 1 1 2 1 1 1 2 1 1 1 2 1 2 1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
271
Solve the following coding problem using the programming language python: It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits. Now you are suggested to solve the following problem: given a year number, find the minimum year number which is strictly larger than the given one and has only distinct digits. The input will be provided via standard input and looks as follows: The single line contains integer *y* (1000<=≀<=*y*<=≀<=9000) β€” the year number. You should write the solution as standard output as follows: Print a single integer β€” the minimum year number that is strictly larger than *y* and all it's digits are distinct. It is guaranteed that the answer exists. Here are example inputs and outputs for the problem: Example Input 1: 1987 Example Output 1: 2013 Example Input 2: 2013 Example Output 2: 2014 Now solve the problem by providing the code.
a = int(input()) + 1 while len(set(str(a))) != 4: a += 1 print(a)
vfc_82721
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1987", "output": "2013", "type": "stdin_stdout" }, { "fn_name": null, "input": "2013", "output": "2014", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
202
Solve the following coding problem using the programming language python: This problem's actual name, "Lexicographically Largest Palindromic Subsequence" is too long to fit into the page headline. You are given string *s* consisting of lowercase English letters only. Find its lexicographically largest palindromic subsequence. We'll call a non-empty string *s*[*p*1*p*2... *p**k*] = *s**p*1*s**p*2... *s**p**k* (1 <=≀<= *p*1<=&lt;<=*p*2<=&lt;<=...<=&lt;<=*p**k* <=≀<= |*s*|) a subsequence of string *s* = *s*1*s*2... *s*|*s*|, where |*s*| is the length of string *s*. For example, strings "abcb", "b" and "abacaba" are subsequences of string "abacaba". String *x* = *x*1*x*2... *x*|*x*| is lexicographically larger than string *y* = *y*1*y*2... *y*|*y*| if either |*x*| &gt; |*y*| and *x*1<==<=*y*1, *x*2<==<=*y*2, ...,<=*x*|*y*|<==<=*y*|*y*|, or there exists such number *r* (*r*<=&lt;<=|*x*|, *r*<=&lt;<=|*y*|) that *x*1<==<=*y*1, *x*2<==<=*y*2, ..., *x**r*<==<=*y**r* and *x**r*<=<=+<=<=1<=&gt;<=*y**r*<=<=+<=<=1. Characters in the strings are compared according to their ASCII codes. For example, string "ranger" is lexicographically larger than string "racecar" and string "poster" is lexicographically larger than string "post". String *s* = *s*1*s*2... *s*|*s*| is a palindrome if it matches string *rev*(*s*) = *s*|*s*|*s*|*s*|<=-<=1... *s*1. In other words, a string is a palindrome if it reads the same way from left to right and from right to left. For example, palindromic strings are "racecar", "refer" and "z". The input will be provided via standard input and looks as follows: The only input line contains a non-empty string *s* consisting of lowercase English letters only. Its length does not exceed 10. You should write the solution as standard output as follows: Print the lexicographically largest palindromic subsequence of string *s*. Here are example inputs and outputs for the problem: Example Input 1: radar Example Output 1: rr Example Input 2: bowwowwow Example Output 2: wwwww Example Input 3: codeforces Example Output 3: s Example Input 4: mississipp Example Output 4: ssss Now solve the problem by providing the code.
from itertools import combinations def get_subsequences(input_str): for length in range(1, len(input_str)+1): for elems in combinations(input_str, length): yield ''.join(elems) print(sorted([s for s in get_subsequences(input()) if s[::-1] == s])[-1])
vfc_82725
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "radar", "output": "rr", "type": "stdin_stdout" }, { "fn_name": null, "input": "bowwowwow", "output": "wwwww", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
300
Solve the following coding problem using the programming language python: Vitaly is a very weird man. He's got two favorite digits *a* and *b*. Vitaly calls a positive integer good, if the decimal representation of this integer only contains digits *a* and *b*. Vitaly calls a good number excellent, if the sum of its digits is a good number. For example, let's say that Vitaly's favourite digits are 1 and 3, then number 12 isn't good and numbers 13 or 311 are. Also, number 111 is excellent and number 11 isn't. Now Vitaly is wondering, how many excellent numbers of length exactly *n* are there. As this number can be rather large, he asks you to count the remainder after dividing it by 1000000007 (109<=+<=7). A number's length is the number of digits in its decimal representation without leading zeroes. The input will be provided via standard input and looks as follows: The first line contains three integers: *a*, *b*, *n* (1<=≀<=*a*<=&lt;<=*b*<=≀<=9,<=1<=≀<=*n*<=≀<=106). You should write the solution as standard output as follows: Print a single integer β€” the answer to the problem modulo 1000000007 (109<=+<=7). Here are example inputs and outputs for the problem: Example Input 1: 1 3 3 Example Output 1: 1 Example Input 2: 2 3 10 Example Output 2: 165 Now solve the problem by providing the code.
import sys, threading import math from os import path from collections import deque, defaultdict, Counter from bisect import * from string import ascii_lowercase from functools import cmp_to_key from random import randint from heapq import * from array import array from types import GeneratorType def readInts(): x = list(map(int, (sys.stdin.readline().rstrip().split()))) return x[0] if len(x) == 1 else x def readList(type=int): x = sys.stdin.readline() x = list(map(type, x.rstrip('\n\r').split())) return x def readStr(): x = sys.stdin.readline().rstrip('\r\n') return x write = sys.stdout.write read = sys.stdin.readline MAXN = 1123456 def bootstrap(f, stack=[]): def wrappedfunc(*args, **kwargs): if stack: return f(*args, **kwargs) else: to = f(*args, **kwargs) while True: if type(to) is GeneratorType: stack.append(to) to = next(to) else: stack.pop() if not stack: break to = stack[-1].send(to) return to return wrappedfunc class mydict: def __init__(self, func=lambda: 0): self.random = randint(0, 1 << 32) self.default = func self.dict = {} def __getitem__(self, key): mykey = self.random ^ key if mykey not in self.dict: self.dict[mykey] = self.default() return self.dict[mykey] def get(self, key, default): mykey = self.random ^ key if mykey not in self.dict: return default return self.dict[mykey] def __setitem__(self, key, item): mykey = self.random ^ key self.dict[mykey] = item def getkeys(self): return [self.random ^ i for i in self.dict] def __str__(self): return f'{[(self.random ^ i, self.dict[i]) for i in self.dict]}' def lcm(a, b): return (a*b)//(math.gcd(a,b)) def mod(n): return n%(1000000007) def power(bas, exp): if (exp == 0): return 1 if (exp == 1): return bas if (exp % 2 == 0): t = power(bas, exp // 2) t = mod(t * t) return t else: return mod(power(bas, exp-1)*bas) factr = [] factr = [1] fact = 1 for i in range(1, MAXN): fact = mod(mod(fact)*mod(i)) factr.append(fact) def nCr(n, r): if r > n: return 0 n1 = factr[n] d1 = power(factr[r], 1000000005) d2 = power(factr[n-r], 1000000005) return mod(mod(n1)*mod(d1)*mod(d2)) def solve(t): # print(f'Case #{t}: ', end = '') a, b, n = readInts() ans = 0 for i in range(n+1): sm = i*a + b*(n-i) st = set(str(sm)) st.discard(str(a)) st.discard(str(b)) if len(st) > 0: continue ans = mod(ans + nCr(n, i)) print(ans) def main(): t = 1 if path.exists("/Users/arijitbhaumik/Library/Application Support/Sublime Text/Packages/User/input.txt"): sys.stdin = open("/Users/arijitbhaumik/Library/Application Support/Sublime Text/Packages/User/input.txt", 'r') sys.stdout = open("/Users/arijitbhaumik/Library/Application Support/Sublime Text/Packages/User/output.txt", 'w') # sys.setrecursionlimit(100000) # t = readInts() for i in range(t): solve(i+1) if __name__ == '__main__': main()
vfc_82729
{ "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 3", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3 10", "output": "165", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 8 14215", "output": "651581472", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
535
Solve the following coding problem using the programming language python: Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you." The problem is: You are given a lucky number *n*. Lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. If we sort all lucky numbers in increasing order, what's the 1-based index of *n*? Tavas is not as smart as SaDDas, so he asked you to do him a favor and solve this problem so he can have his headphones back. The input will be provided via standard input and looks as follows: The first and only line of input contains a lucky number *n* (1<=≀<=*n*<=≀<=109). You should write the solution as standard output as follows: Print the index of *n* among all lucky numbers. Here are example inputs and outputs for the problem: Example Input 1: 4 Example Output 1: 1 Example Input 2: 7 Example Output 2: 2 Example Input 3: 77 Example Output 3: 6 Now solve the problem by providing the code.
def count_lucky_numbers(n): d = len(n) s = "" for i in range(d): if n[i] == '4': s += '0' else: s += '1' return 2*(2**(d-1)-1)+int(s,2)+1 n = input() # Input lucky number index = count_lucky_numbers(n) print(index)
vfc_82737
{ "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", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "7", "output": "2", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
682
Solve the following coding problem using the programming language python: Someone gave Alyona an array containing *n* positive integers *a*1,<=*a*2,<=...,<=*a**n*. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular, she may not apply any operation to the array at all. Formally, after applying some operations Alyona will get an array of *n* positive integers *b*1,<=*b*2,<=...,<=*b**n* such that 1<=≀<=*b**i*<=≀<=*a**i* for every 1<=≀<=*i*<=≀<=*n*. Your task is to determine the maximum possible value of mex of this array. Mex of an array in this problem is the minimum positive integer that doesn't appear in this array. For example, mex of the array containing 1, 3 and 4 is equal to 2, while mex of the array containing 2, 3 and 2 is equal to 1. 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 elements in the Alyona's array. The second line of the input contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=109)Β β€” the elements of the array. You should write the solution as standard output as follows: Print one positive integerΒ β€” the maximum possible value of mex of the array after Alyona applies some (possibly none) operations. Here are example inputs and outputs for the problem: Example Input 1: 5 1 3 3 3 6 Example Output 1: 5 Example Input 2: 2 2 1 Example Output 2: 3 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 = int(input()) a = list(map(int, input().split())) a.sort() ans = 1 for i in a: if ans <= i: ans += 1 print(ans)
vfc_82741
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 3 3 3 6", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2 1", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1000000000", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n2", "output": "2", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
92
Solve the following coding problem using the programming language python: There are *n* walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus number 1 sits to the left of the walrus number *n*. The presenter has *m* chips. The presenter stands in the middle of the circle and starts giving the chips to the walruses starting from walrus number 1 and moving clockwise. The walrus number *i* gets *i* chips. If the presenter can't give the current walrus the required number of chips, then the presenter takes the remaining chips and the process ends. Determine by the given *n* and *m* how many chips the presenter will get in the end. The input will be provided via standard input and looks as follows: The first line contains two integers *n* and *m* (1<=≀<=*n*<=≀<=50, 1<=≀<=*m*<=≀<=104) β€” the number of walruses and the number of chips correspondingly. You should write the solution as standard output as follows: Print the number of chips the presenter ended up with. Here are example inputs and outputs for the problem: Example Input 1: 4 11 Example Output 1: 0 Example Input 2: 17 107 Example Output 2: 2 Example Input 3: 3 8 Example Output 3: 1 Now solve the problem by providing the code.
m,n=map(int,input().split()) t=False while not t: for x in range(m): if n>=x+1: n-=x+1 else: t=True break print(n)
vfc_82745
{ "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 11", "output": "0", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
849
Solve the following coding problem using the programming language python: Where do odds begin, and where do they end? Where does hope emerge, and will they ever break? Given an integer sequence *a*1,<=*a*2,<=...,<=*a**n* of length *n*. Decide whether it is possible to divide it into an odd number of non-empty subsegments, the each of which has an odd length and begins and ends with odd numbers. A subsegment is a contiguous slice of the whole sequence. For example, {3,<=4,<=5} and {1} are subsegments of sequence {1,<=2,<=3,<=4,<=5,<=6}, while {1,<=2,<=4} and {7} are not. The input will be provided via standard input and looks as follows: The first line of input contains a non-negative integer *n* (1<=≀<=*n*<=≀<=100) β€” the length of the sequence. The second line contains *n* space-separated non-negative integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≀<=*a**i*<=≀<=100) β€” the elements of the sequence. You should write the solution as standard output as follows: Output "Yes" if it's possible to fulfill the requirements, and "No" otherwise. You can output each letter in any case (upper or lower). Here are example inputs and outputs for the problem: Example Input 1: 3 1 3 5 Example Output 1: Yes Example Input 2: 5 1 0 1 5 1 Example Output 2: Yes Example Input 3: 3 4 3 1 Example Output 3: No Example Input 4: 4 3 9 9 3 Example Output 4: No Now solve the problem by providing the code.
# coding: utf-8 # 849A - Odds and Ends (http://codeforces.com/contest/849/problem/A) n = int(input()) arr = list(map(int, input().split())) if n % 2 and arr[0] % 2 and arr[-1] % 2: print("Yes") else: print("No")
vfc_82749
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 3 5", "output": "Yes", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 0 1 5 1", "output": "Yes", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n4 3 1", "output": "No", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n3 9 9 3", "output": "No", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1", "output": "Yes", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n100 99 100 99 99", "output": "No", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
245
Solve the following coding problem using the programming language python: Polycarpus is a system administrator. There are two servers under his strict guidance β€” *a* and *b*. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to the server specified in the argument of the command. Executing a program results in two integers *x* and *y* (*x*<=+<=*y*<==<=10;Β *x*,<=*y*<=β‰₯<=0). These numbers mean that *x* packets successfully reached the corresponding server through the network and *y* packets were lost. Today Polycarpus has performed overall *n* ping commands during his workday. Now for each server Polycarpus wants to know whether the server is "alive" or not. Polycarpus thinks that the server is "alive", if at least half of the packets that we send to this server reached it successfully along the network. Help Polycarpus, determine for each server, whether it is "alive" or not by the given commands and their results. 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 commands Polycarpus has fulfilled. Each of the following *n* lines contains three integers β€” the description of the commands. The *i*-th of these lines contains three space-separated integers *t**i*, *x**i*, *y**i* (1<=≀<=*t**i*<=≀<=2;Β *x**i*,<=*y**i*<=β‰₯<=0;Β *x**i*<=+<=*y**i*<==<=10). If *t**i*<==<=1, then the *i*-th command is "ping a", otherwise the *i*-th command is "ping b". Numbers *x**i*, *y**i* represent the result of executing this command, that is, *x**i* packets reached the corresponding server successfully and *y**i* packets were lost. It is guaranteed that the input has at least one "ping a" command and at least one "ping b" command. You should write the solution as standard output as follows: In the first line print string "LIVE" (without the quotes) if server *a* is "alive", otherwise print "DEAD" (without the quotes). In the second line print the state of server *b* in the similar format. Here are example inputs and outputs for the problem: Example Input 1: 2 1 5 5 2 6 4 Example Output 1: LIVE LIVE Example Input 2: 3 1 0 10 2 0 10 1 10 0 Example Output 2: LIVE DEAD Now solve the problem by providing the code.
n=int(input()) server1x = 0 server2x = 0 server1y = 0 server2y = 0 for _ in range(n): t, x, y = list(map(int, input().split())) if t == 1: server1x += x server1y += y else: server2x += x server2y += y if server1x >= server1y: print("LIVE") else: print("DEAD") if server2x >= server2y: print("LIVE") else: print("DEAD")
vfc_82753
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "5000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1 5 5\n2 6 4", "output": "LIVE\nLIVE", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 0 10\n2 0 10\n1 10 0", "output": "LIVE\nDEAD", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n1 3 7\n2 4 6\n1 2 8\n2 5 5\n2 10 0\n2 10 0\n1 8 2\n2 2 8\n2 10 0\n1 1 9", "output": "DEAD\nLIVE", "type": "stdin_stdout" }, { "fn_name": null, "input": "11\n1 8 2\n1 6 4\n1 9 1\n1 7 3\n2 0 10\n2 0 10\n1 8 2\n2 2 8\n2 6 4\n2 7 3\n2 9 1", "output": "LIVE\nDEAD", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
884
Solve the following coding problem using the programming language python: A one-dimensional Japanese crossword can be represented as a binary string of length *x*. An encoding of this crossword is an array *a* of size *n*, where *n* is the number of segments formed completely of 1's, and *a**i* is the length of *i*-th segment. No two segments touch or intersect. For example: - If *x*<==<=6 and the crossword is 111011, then its encoding is an array {3,<=2}; - If *x*<==<=8 and the crossword is 01101010, then its encoding is an array {2,<=1,<=1}; - If *x*<==<=5 and the crossword is 11111, then its encoding is an array {5}; - If *x*<==<=5 and the crossword is 00000, then its encoding is an empty array. Mishka wants to create a new one-dimensional Japanese crossword. He has already picked the length and the encoding for this crossword. And now he needs to check if there is exactly one crossword such that its length and encoding are equal to the length and encoding he picked. Help him to check it! The input will be provided via standard input and looks as follows: The first line contains two integer numbers *n* and *x* (1<=≀<=*n*<=≀<=100000, 1<=≀<=*x*<=≀<=109) β€” the number of elements in the encoding and the length of the crossword Mishka picked. The second line contains *n* integer numbers *a*1, *a*2, ..., *a**n* (1<=≀<=*a**i*<=≀<=10000) β€” the encoding. You should write the solution as standard output as follows: Print YES if there exists exaclty one crossword with chosen length and encoding. Otherwise, print NO. Here are example inputs and outputs for the problem: Example Input 1: 2 4 1 3 Example Output 1: NO Example Input 2: 3 10 3 3 2 Example Output 2: YES Example Input 3: 2 10 1 3 Example Output 3: NO Now solve the problem by providing the code.
n,x=list(map(int,input().split())) a=list(map(int,input().split())) if sum(a) + n - 1 == x: print('Yes') else: print('No')
vfc_82757
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 4\n1 3", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 10\n3 3 2", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 10\n1 3", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n1", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 10\n10", "output": "YES", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
236
Solve the following coding problem using the programming language python: Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network. But yesterday, he came to see "her" in the real world and found out "she" is actually a very strong man! Our hero is very sad and he is too tired to love again now. So he came up with a way to recognize users' genders by their user names. This is his method: if the number of distinct characters in one's user name is odd, then he is a male, otherwise she is a female. You are given the string that denotes the user name, please help our hero to determine the gender of this user by his method. The input will be provided via standard input and looks as follows: The first line contains a non-empty string, that contains only lowercase English letters β€” the user name. This string contains at most 100 letters. You should write the solution as standard output as follows: If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes). Here are example inputs and outputs for the problem: Example Input 1: wjmzbmr Example Output 1: CHAT WITH HER! Example Input 2: xiaodao Example Output 2: IGNORE HIM! Example Input 3: sevenkplus Example Output 3: CHAT WITH HER! Now solve the problem by providing the code.
d=dict() n=input() for ch in n: if(ch in d): d[ch]=d[ch]+1 else: d[ch]=0 count=len(d) if(count%2==0): print("CHAT WITH HER!") else: print("IGNORE HIM!")
vfc_82761
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "wjmzbmr", "output": "CHAT WITH HER!", "type": "stdin_stdout" }, { "fn_name": null, "input": "xiaodao", "output": "IGNORE HIM!", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
334
Solve the following coding problem using the programming language python: Gerald has *n* younger brothers and their number happens to be even. One day he bought *n*2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer *k* from 1 to *n*2 he has exactly one bag with *k* candies. Help him give *n* bags of candies to each brother so that all brothers got the same number of candies. The input will be provided via standard input and looks as follows: The single line contains a single integer *n* (*n* is even, 2<=≀<=*n*<=≀<=100) β€” the number of Gerald's brothers. You should write the solution as standard output as follows: Let's assume that Gerald indexes his brothers with numbers from 1 to *n*. You need to print *n* lines, on the *i*-th line print *n* integers β€” the numbers of candies in the bags for the *i*-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to *n*2. You can print the numbers in the lines in any order. It is guaranteed that the solution exists at the given limits. Here are example inputs and outputs for the problem: Example Input 1: 2 Example Output 1: 1 4 2 3 Now solve the problem by providing the code.
n=int(input()) n=n**2 for i in range (0,n//2): print(i+1,n-i)
vfc_82765
{ "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 4\n2 3", "type": "stdin_stdout" }, { "fn_name": null, "input": "4", "output": "1 16 2 15\n3 14 4 13\n5 12 6 11\n7 10 8 9", "type": "stdin_stdout" }, { "fn_name": null, "input": "6", "output": "1 36 2 35 3 34\n4 33 5 32 6 31\n7 30 8 29 9 28\n10 27 11 26 12 25\n13 24 14 23 15 22\n16 21 17 20 18 19", "type": "stdin_stdout" }, { "fn_name": null, "input": "8", "output": "1 64 2 63 3 62 4 61\n5 60 6 59 7 58 8 57\n9 56 10 55 11 54 12 53\n13 52 14 51 15 50 16 49\n17 48 18 47 19 46 20 45\n21 44 22 43 23 42 24 41\n25 40 26 39 27 38 28 37\n29 36 30 35 31 34 32 33", "type": "stdin_stdout" }, { "fn_name": null, "input": "10", "output": "1 100 2 99 3 98 4 97 5 96\n6 95 7 94 8 93 9 92 10 91\n11 90 12 89 13 88 14 87 15 86\n16 85 17 84 18 83 19 82 20 81\n21 80 22 79 23 78 24 77 25 76\n26 75 27 74 28 73 29 72 30 71\n31 70 32 69 33 68 34 67 35 66\n36 65 37 64 38 63 39 62 40 61\n41 60 42 59 43 58 44 57 45 56\n46 55 47 54 48 53 49 52 50 51", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
124
Solve the following coding problem using the programming language python: Petr stands in line of *n* people, but he doesn't know exactly which position he occupies. He can say that there are no less than *a* people standing in front of him and no more than *b* people standing behind him. Find the number of different positions Petr can occupy. The input will be provided via standard input and looks as follows: The only line contains three integers *n*, *a* and *b* (0<=≀<=*a*,<=*b*<=&lt;<=*n*<=≀<=100). You should write the solution as standard output as follows: Print the single number β€” the number of the sought positions. Here are example inputs and outputs for the problem: Example Input 1: 3 1 1 Example Output 1: 2 Example Input 2: 5 2 3 Example Output 2: 3 Now solve the problem by providing the code.
# cook your dish here n,a,b = input().split() n = int(n) a = int(a) b = int(b) count = 0 for i in range(1,n+1): if i>a and n-i<=b: count = count + 1 print(count)
vfc_82769
{ "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 1", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 2 3", "output": "3", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
115
Solve the following coding problem using the programming language python: A company has *n* employees numbered from 1 to *n*. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee *A* is said to be the superior of another employee *B* if at least one of the following is true: - Employee *A* is the immediate manager of employee *B* - Employee *B* has an immediate manager employee *C* such that employee *A* is the superior of employee *C*. The company will not have a managerial cycle. That is, there will not exist an employee who is the superior of his/her own immediate manager. Today the company is going to arrange a party. This involves dividing all *n* employees into several groups: every employee must belong to exactly one group. Furthermore, within any single group, there must not be two employees *A* and *B* such that *A* is the superior of *B*. What is the minimum number of groups that must be formed? The input will be provided via standard input and looks as follows: The first line contains integer *n* (1<=≀<=*n*<=≀<=2000) β€” the number of employees. The next *n* lines contain the integers *p**i* (1<=≀<=*p**i*<=≀<=*n* or *p**i*<==<=-1). Every *p**i* denotes the immediate manager for the *i*-th employee. If *p**i* is -1, that means that the *i*-th employee does not have an immediate manager. It is guaranteed, that no employee will be the immediate manager of him/herself (*p**i*<=β‰ <=*i*). Also, there will be no managerial cycles. You should write the solution as standard output as follows: Print a single integer denoting the minimum number of groups that will be formed in the party. Here are example inputs and outputs for the problem: Example Input 1: 5 -1 1 2 1 -1 Example Output 1: 3 Now solve the problem by providing the code.
n=int(input()); maxx=-1; a=[-1]; for i in range(n): a.append(int(input())); for i in range(1,n+1): j=i;c=1; while(a[j]!=-1):c+=1;j=a[j]; maxx=max(c,maxx); print(maxx);
vfc_82773
{ "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\n-1\n1\n2\n1\n-1", "output": "3", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
928
Solve the following coding problem using the programming language python: When registering in a social network, users are allowed to create their own convenient login to make it easier to share contacts, print it on business cards, etc. Login is an arbitrary sequence of lower and uppercase latin letters, digits and underline symbols (Β«_Β»). However, in order to decrease the number of frauds and user-inattention related issues, it is prohibited to register a login if it is similar with an already existing login. More precisely, two logins *s* and *t* are considered similar if we can transform *s* to *t* via a sequence of operations of the following types: - transform lowercase letters to uppercase and vice versa; - change letter Β«OΒ» (uppercase latin letter) to digit Β«0Β» and vice versa; - change digit Β«1Β» (one) to any letter among Β«lΒ» (lowercase latin Β«LΒ»), Β«IΒ» (uppercase latin Β«iΒ») and vice versa, or change one of these letters to other. For example, logins Β«CodeforcesΒ» and Β«codef0rcesΒ» as well as Β«OO0OOO00O0OOO0O00OOO0OO_lolΒ» and Β«OO0OOO0O00OOO0O00OO0OOO_1oIΒ» are considered similar whereas Β«CodeforcesΒ» and Β«Code_forcesΒ» are not. You're given a list of existing logins with no two similar amonst and a newly created user login. Check whether this new login is similar with any of the existing ones. The input will be provided via standard input and looks as follows: The first line contains a non-empty string *s* consisting of lower and uppercase latin letters, digits and underline symbols (Β«_Β») with length not exceeding 50 Β β€” the login itself. The second line contains a single integer *n* (1<=≀<=*n*<=≀<=1<=000)Β β€” the number of existing logins. The next *n* lines describe the existing logins, following the same constraints as the user login (refer to the first line of the input). It's guaranteed that no two existing logins are similar. You should write the solution as standard output as follows: Print Β«YesΒ» (without quotes), if user can register via this login, i.e. none of the existing logins is similar with it. Otherwise print Β«NoΒ» (without quotes). Here are example inputs and outputs for the problem: Example Input 1: 1_wat 2 2_wat wat_1 Example Output 1: Yes Example Input 2: 000 3 00 ooA oOo Example Output 2: No Example Input 3: _i_ 3 __i_ _1_ I Example Output 3: No Example Input 4: La0 3 2a0 La1 1a0 Example Output 4: No Example Input 5: abc 1 aBc Example Output 5: No Example Input 6: 0Lil 2 LIL0 0Ril Example Output 6: Yes Now solve the problem by providing the code.
ss = input() st = "" for j in range(len(ss)): c = ss[j] if 'A' <= c <= 'Z': c = chr(ord(c) + ord('a') - ord('A')) if c == 'o': c = '0' if c == 'l' or c == 'i': c = '1' st += c s = st n = int(input()) for i in range(n): ss = input() st = "" for j in range(len(ss)): c = ss[j] if 'A' <= c <= 'Z': c = chr(ord(c) + ord('a') - ord('A')) if c == 'o': c = '0' if c == 'l' or c == 'i': c = '1' st += c if s == st: print("No") exit() print("Yes")
vfc_82777
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "4000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1_wat\n2\n2_wat\nwat_1", "output": "Yes", "type": "stdin_stdout" }, { "fn_name": null, "input": "000\n3\n00\nooA\noOo", "output": "No", "type": "stdin_stdout" }, { "fn_name": null, "input": "_i_\n3\n__i_\n_1_\nI", "output": "No", "type": "stdin_stdout" }, { "fn_name": null, "input": "La0\n3\n2a0\nLa1\n1a0", "output": "No", "type": "stdin_stdout" }, { "fn_name": null, "input": "abc\n1\naBc", "output": "No", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
766
Solve the following coding problem using the programming language python: While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem. Given two strings *a* and *b*, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of one of them and not a subsequence of the other. A subsequence of some string is a sequence of characters that appears in the same order in the string, The appearances don't have to be consecutive, for example, strings "ac", "bc", "abc" and "a" are subsequences of string "abc" while strings "abbc" and "acb" are not. The empty string is a subsequence of any string. Any string is a subsequence of itself. The input will be provided via standard input and looks as follows: The first line contains string *a*, and the second lineΒ β€” string *b*. Both of these strings are non-empty and consist of lowercase letters of English alphabet. The length of each string is not bigger than 105 characters. You should write the solution as standard output as follows: If there's no uncommon subsequence, print "-1". Otherwise print the length of the longest uncommon subsequence of *a* and *b*. Here are example inputs and outputs for the problem: Example Input 1: abcd defgh Example Output 1: 5 Example Input 2: a a Example Output 2: -1 Now solve the problem by providing the code.
s1 = input() s2 = input() if s1 == s2: print(-1) elif len(s1) > len(s2): print(len(s1)) elif len(s2) > len(s1): print(len(s2)) else: print(len(s1))
vfc_82781
{ "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\ndefgh", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "a\na", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaacccccccccccccccccccccccccccccccccccccccccccccccccc\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaadddddddddddddddddddddddddddddddddddddddddddddddddd", "output": "100", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
611
Solve the following coding problem using the programming language python: They say "years are like dominoes, tumbling one after the other". But would a year fit into a grid? I don't think so. Limak is a little polar bear who loves to play. He has recently got a rectangular grid with *h* rows and *w* columns. Each cell is a square, either empty (denoted by '.') or forbidden (denoted by '#'). Rows are numbered 1 through *h* from top to bottom. Columns are numbered 1 through *w* from left to right. Also, Limak has a single domino. He wants to put it somewhere in a grid. A domino will occupy exactly two adjacent cells, located either in one row or in one column. Both adjacent cells must be empty and must be inside a grid. Limak needs more fun and thus he is going to consider some queries. In each query he chooses some rectangle and wonders, how many way are there to put a single domino inside of the chosen rectangle? The input will be provided via standard input and looks as follows: The first line of the input contains two integers *h* and *w* (1<=≀<=*h*,<=*w*<=≀<=500) – the number of rows and the number of columns, respectively. The next *h* lines describe a grid. Each line contains a string of the length *w*. Each character is either '.' or '#'Β β€” denoting an empty or forbidden cell, respectively. The next line contains a single integer *q* (1<=≀<=*q*<=≀<=100<=000)Β β€” the number of queries. Each of the next *q* lines contains four integers *r*1*i*, *c*1*i*, *r*2*i*, *c*2*i* (1<=≀<=*r*1*i*<=≀<=*r*2*i*<=≀<=*h*,<=1<=≀<=*c*1*i*<=≀<=*c*2*i*<=≀<=*w*)Β β€” the *i*-th query. Numbers *r*1*i* and *c*1*i* denote the row and the column (respectively) of the upper left cell of the rectangle. Numbers *r*2*i* and *c*2*i* denote the row and the column (respectively) of the bottom right cell of the rectangle. You should write the solution as standard output as follows: Print *q* integers, *i*-th should be equal to the number of ways to put a single domino inside the *i*-th rectangle. Here are example inputs and outputs for the problem: Example Input 1: 5 8 ....#..# .#...... ##.#.... ##..#.## ........ 4 1 1 2 3 4 1 4 1 1 2 4 5 2 5 5 8 Example Output 1: 4 0 10 15 Example Input 2: 7 39 ....................................... .###..###..#..###.....###..###..#..###. ...#..#.#..#..#.........#..#.#..#..#... .###..#.#..#..###.....###..#.#..#..###. .#....#.#..#....#.....#....#.#..#..#.#. .###..###..#..###.....###..###..#..###. ....................................... 6 1 1 3 20 2 10 6 30 2 10 7 30 2 2 7 7 1 7 7 7 1 8 7 8 Example Output 2: 53 89 120 23 0 2 Now solve the problem by providing the code.
read = lambda: map(int, input().split()) h, w = read() a = [input() for i in range(h)] N = 501 vr = [[0] * N for i in range(N)] hr = [[0] * N for i in range(N)] for i in range(h): for j in range(w): vr[j + 1][i + 1] = vr[j][i + 1] + vr[j + 1][i] - vr[j][i] hr[j + 1][i + 1] = hr[j][i + 1] + hr[j + 1][i] - hr[j][i] if a[i][j] == '#': continue if i != h - 1 and a[i + 1][j] == '.': vr[j + 1][i + 1] += 1 if j != w - 1 and a[i][j + 1] == '.': hr[j + 1][i + 1] += 1 q = int(input()) for i in range(q): r1, c1, r2, c2 = read() p1 = hr[c2 - 1][r2] - hr[c1 - 1][r2] - hr[c2 - 1][r1 - 1] + hr[c1 - 1][r1 - 1] p2 = vr[c2][r2 - 1] - vr[c1 - 1][r2 - 1] - vr[c2][r1 - 1] + vr[c1 - 1][r1 - 1] ans = p1 + p2 print(ans)
vfc_82785
{ "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 8\n....#..#\n.#......\n##.#....\n##..#.##\n........\n4\n1 1 2 3\n4 1 4 1\n1 2 4 5\n2 5 5 8", "output": "4\n0\n10\n15", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 39\n.......................................\n.###..###..#..###.....###..###..#..###.\n...#..#.#..#..#.........#..#.#..#..#...\n.###..#.#..#..###.....###..#.#..#..###.\n.#....#.#..#....#.....#....#.#..#..#.#.\n.###..###..#..###.....###..###..#..###.\n.......................................\n6\n1 1 3 20\n2 10 6 30\n2 10 7 30\n2 2 7 7\n1 7 7 7\n1 8 7 8", "output": "53\n89\n120\n23\n0\n2", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 20\n.#..................\n....................\n15\n1 3 1 13\n1 11 2 14\n1 17 1 20\n1 2 2 3\n1 7 1 10\n1 7 2 17\n1 4 1 9\n2 6 2 8\n1 8 2 20\n2 7 2 16\n1 4 2 16\n1 6 1 9\n1 4 2 7\n1 9 1 20\n2 2 2 12", "output": "10\n10\n3\n2\n3\n31\n5\n2\n37\n9\n37\n3\n10\n11\n10", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
29
Solve the following coding problem using the programming language python: In a Berland's zoo there is an enclosure with camels. It is known that camels like to spit. Bob watched these interesting animals for the whole day and registered in his notepad where each animal spitted. Now he wants to know if in the zoo there are two camels, which spitted at each other. Help him to solve this task. The trajectory of a camel's spit is an arc, i.e. if the camel in position *x* spits *d* meters right, he can hit only the camel in position *x*<=+<=*d*, if such a camel exists. The input will be provided via standard input and looks as follows: The first line contains integer *n* (1<=≀<=*n*<=≀<=100) β€” the amount of camels in the zoo. Each of the following *n* lines contains two integers *x**i* and *d**i* (<=-<=104<=≀<=*x**i*<=≀<=104,<=1<=≀<=|*d**i*|<=≀<=2Β·104) β€” records in Bob's notepad. *x**i* is a position of the *i*-th camel, and *d**i* is a distance at which the *i*-th camel spitted. Positive values of *d**i* correspond to the spits right, negative values correspond to the spits left. No two camels may stand in the same position. You should write the solution as standard output as follows: If there are two camels, which spitted at each other, output YES. Otherwise, output NO. Here are example inputs and outputs for the problem: Example Input 1: 2 0 1 1 -1 Example Output 1: YES Example Input 2: 3 0 1 1 1 2 -2 Example Output 2: NO Example Input 3: 5 2 -10 3 10 0 5 5 -5 10 1 Example Output 3: YES Now solve the problem by providing the code.
n = int(input()) A = set() for _ in range(n): x, d = map(int, input().split()) A.add((x, d)) found = False for x, d in A: if (x + d, -d) in A: found = True if found: print("YES") else: print("NO")
vfc_82793
{ "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\n0 1\n1 -1", "output": "YES", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
853
Solve the following coding problem using the programming language python: Country of Metropolia is holding Olympiad of Metrpolises soon. It mean that all jury members of the olympiad should meet together in Metropolis (the capital of the country) for the problem preparation process. There are *n*<=+<=1 cities consecutively numbered from 0 to *n*. City 0 is Metropolis that is the meeting point for all jury members. For each city from 1 to *n* there is exactly one jury member living there. Olympiad preparation is a long and demanding process that requires *k* days of work. For all of these *k* days each of the *n* jury members should be present in Metropolis to be able to work on problems. You know the flight schedule in the country (jury members consider themselves important enough to only use flights for transportation). All flights in Metropolia are either going to Metropolis or out of Metropolis. There are no night flights in Metropolia, or in the other words, plane always takes off at the same day it arrives. On his arrival day and departure day jury member is not able to discuss the olympiad. All flights in Megapolia depart and arrive at the same day. Gather everybody for *k* days in the capital is a hard objective, doing that while spending the minimum possible money is even harder. Nevertheless, your task is to arrange the cheapest way to bring all of the jury members to Metrpolis, so that they can work together for *k* days and then send them back to their home cities. Cost of the arrangement is defined as a total cost of tickets for all used flights. It is allowed for jury member to stay in Metropolis for more than *k* days. The input will be provided via standard input and looks as follows: The first line of input contains three integers *n*, *m* and *k* (1<=≀<=*n*<=≀<=105, 0<=≀<=*m*<=≀<=105, 1<=≀<=*k*<=≀<=106). The *i*-th of the following *m* lines contains the description of the *i*-th flight defined by four integers *d**i*, *f**i*, *t**i* and *c**i* (1<=≀<=*d**i*<=≀<=106, 0<=≀<=*f**i*<=≀<=*n*, 0<=≀<=*t**i*<=≀<=*n*, 1<=≀<=*c**i*<=≀<=106, exactly one of *f**i* and *t**i* equals zero), the day of departure (and arrival), the departure city, the arrival city and the ticket cost. You should write the solution as standard output as follows: Output the only integer that is the minimum cost of gathering all jury members in city 0 for *k* days and then sending them back to their home cities. If it is impossible to gather everybody in Metropolis for *k* days and then send them back to their home cities, output "-1" (without the quotes). Here are example inputs and outputs for the problem: Example Input 1: 2 6 5 1 1 0 5000 3 2 0 5500 2 2 0 6000 15 0 2 9000 9 0 1 7000 8 0 2 6500 Example Output 1: 24500 Example Input 2: 2 4 5 1 2 0 5000 2 1 0 4500 2 1 0 3000 8 0 1 6000 Example Output 2: -1 Now solve the problem by providing the code.
g = lambda: map(int, input().split()) n, m, k = g() F, T = [], [] e = int(3e11) for i in range(m): d, f, t, c = g() if f: F.append((d, f, c)) else: T.append((-d, t, c)) for p in [F, T]: C = [e] * (n + 1) s = n * e q = [] p.sort() for d, t, c in p: if C[t] > c: s += c - C[t] C[t] = c if s < e: q.append((s, d)) p.clear() p += q s, t = e, (0, 0) for f in F: while f: if t[1] + f[1] + k < 0: s = min(s, f[0] + t[0]) elif T: t = T.pop() continue f = 0 print(s if s < e else -1)
vfc_82805
{ "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 6 5\n1 1 0 5000\n3 2 0 5500\n2 2 0 6000\n15 0 2 9000\n9 0 1 7000\n8 0 2 6500", "output": "24500", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 4 5\n1 2 0 5000\n2 1 0 4500\n2 1 0 3000\n8 0 1 6000", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 5 5\n1 1 0 1\n2 2 0 100\n3 2 0 10\n9 0 1 1000\n10 0 2 10000", "output": "11011", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 4 5\n1 1 0 1\n2 2 0 10\n8 0 1 100\n9 0 2 1000", "output": "1111", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 2 1\n10 1 0 16\n20 0 1 7", "output": "23", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 2 10\n20 0 1 36\n10 1 0 28", "output": "-1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
877
Solve the following coding problem using the programming language python: One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems. But there are too many problems, to do it manually. Alex asks you to write a program, which will determine if a problem is from this contest by its name. It is known, that problem is from this contest if and only if its name contains one of Alex's friends' name exactly once. His friends' names are "Danil", "Olya", "Slava", "Ann" and "Nikita". Names are case sensitive. The input will be provided via standard input and looks as follows: The only line contains string from lowercase and uppercase letters and "_" symbols of length, not more than 100 β€” the name of the problem. You should write the solution as standard output as follows: Print "YES", if problem is from this contest, and "NO" otherwise. Here are example inputs and outputs for the problem: Example Input 1: Alex_and_broken_contest Example Output 1: NO Example Input 2: NikitaAndString Example Output 2: YES Example Input 3: Danil_and_Olya Example Output 3: NO Now solve the problem by providing the code.
s=input() cnt=s.count("Danil")+s.count("Olya")+s.count("Slava")+s.count("Nikita")+s.count("Ann") print("YES" if cnt == 1 else "NO")
vfc_82809
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "Alex_and_broken_contest", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "NikitaAndString", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "Danil_and_Olya", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "Slava____and_the_game", "output": "YES", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
762
Solve the following coding problem using the programming language python: You are given two integers *n* and *k*. Find *k*-th smallest divisor of *n*, or report that it doesn't exist. Divisor of *n* is any such natural number, that *n* can be divided by it without remainder. The input will be provided via standard input and looks as follows: The first line contains two integers *n* and *k* (1<=≀<=*n*<=≀<=1015, 1<=≀<=*k*<=≀<=109). You should write the solution as standard output as follows: If *n* has less than *k* divisors, output -1. Otherwise, output the *k*-th smallest divisor of *n*. Here are example inputs and outputs for the problem: Example Input 1: 4 2 Example Output 1: 2 Example Input 2: 5 3 Example Output 2: -1 Example Input 3: 12 5 Example Output 3: 6 Now solve the problem by providing the code.
import sys import math from collections import Counter # n = int(input()) # a = list(map(int, input().split())) n, k = map(int, input().split()) less = [] more = [] i = 1 count = 0 root = int(math.sqrt(n)) while i <= root : if n % i == 0 : less.append(i) if i * i != n: more.append(n // i) if len(less) >= k : break i += 1 if k > len(less) + len(more) : print(-1) else : if k > len(less) : print(more[-(k - len(less))]) else : print(less[k - 1])
vfc_82813
{ "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": "5 3", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "12 5", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "866421317361600 26880", "output": "866421317361600", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
220
Solve the following coding problem using the programming language python: The Little Elephant has got a problem β€” somebody has been touching his sorted by non-decreasing array *a* of length *n* and possibly swapped some elements of the array. The Little Elephant doesn't want to call the police until he understands if he could have accidentally changed the array himself. He thinks that he could have accidentally changed array *a*, only if array *a* can be sorted in no more than one operation of swapping elements (not necessarily adjacent). That is, the Little Elephant could have accidentally swapped some two elements. Help the Little Elephant, determine if he could have accidentally changed the array *a*, sorted by non-decreasing, himself. The input will be provided via standard input and looks as follows: The first line contains a single integer *n* (2<=≀<=*n*<=≀<=105) β€” the size of array *a*. The next line contains *n* positive integers, separated by single spaces and not exceeding 109, β€” array *a*. Note that the elements of the array are not necessarily distinct numbers. You should write the solution as standard output as follows: In a single line print "YES" (without the quotes) if the Little Elephant could have accidentally changed the array himself, and "NO" (without the quotes) otherwise. Here are example inputs and outputs for the problem: Example Input 1: 2 1 2 Example Output 1: YES Example Input 2: 3 3 2 1 Example Output 2: YES Example Input 3: 4 4 3 2 1 Example Output 3: NO Now solve the problem by providing the code.
from sys import stdin from collections import deque,Counter,defaultdict import sys import math import operator import random from fractions import Fraction import functools import bisect import itertools from heapq import * import time n = int(input()) arr = list(map(int,input().split())) c = 0 for i,j in zip(arr,sorted(arr)): if i!=j: c+=1 print('YES' if c == 0 or c == 2 else 'NO')
vfc_82817
{ "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 2", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n3 2 1", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n4 3 2 1", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 3 2", "output": "YES", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
486
Solve the following coding problem using the programming language python: For a positive integer *n* let's define a function *f*: *f*(*n*)<==<=<=-<=1<=+<=2<=-<=3<=+<=..<=+<=(<=-<=1)*n**n* Your task is to calculate *f*(*n*) for a given integer *n*. The input will be provided via standard input and looks as follows: The single line contains the positive integer *n* (1<=≀<=*n*<=≀<=1015). You should write the solution as standard output as follows: Print *f*(*n*) in a single line. Here are example inputs and outputs for the problem: Example Input 1: 4 Example Output 1: 2 Example Input 2: 5 Example Output 2: -3 Now solve the problem by providing the code.
S0l=int(input()) if S0l%2==0: print(S0l//2) else: print(S0l//2-S0l)
vfc_82821
{ "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", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "5", "output": "-3", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000000000", "output": "500000000", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000000001", "output": "-500000001", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000000000000000", "output": "500000000000000", "type": "stdin_stdout" }, { "fn_name": null, "input": "100", "output": "50", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
1004
Solve the following coding problem using the programming language python: Sonya decided that having her own hotel business is the best way of earning money because she can profit and rest wherever she wants. The country where Sonya lives is an endless line. There is a city in each integer coordinate on this line. She has $n$ hotels, where the $i$-th hotel is located in the city with coordinate $x_i$. Sonya is a smart girl, so she does not open two or more hotels in the same city. Sonya understands that her business needs to be expanded by opening new hotels, so she decides to build one more. She wants to make the minimum distance from this hotel to all others to be equal to $d$. The girl understands that there are many possible locations to construct such a hotel. Thus she wants to know the number of possible coordinates of the cities where she can build a new hotel. Because Sonya is lounging in a jacuzzi in one of her hotels, she is asking you to find the number of cities where she can build a new hotel so that the minimum distance from the original $n$ hotels to the new one is equal to $d$. The input will be provided via standard input and looks as follows: The first line contains two integers $n$ and $d$ ($1\leq n\leq 100$, $1\leq d\leq 10^9$)Β β€” the number of Sonya's hotels and the needed minimum distance from a new hotel to all others. The second line contains $n$ different integers in strictly increasing order $x_1, x_2, \ldots, x_n$ ($-10^9\leq x_i\leq 10^9$)Β β€” coordinates of Sonya's hotels. You should write the solution as standard output as follows: Print the number of cities where Sonya can build a new hotel so that the minimum distance from this hotel to all others is equal to $d$. Here are example inputs and outputs for the problem: Example Input 1: 4 3 -3 2 9 16 Example Output 1: 6 Example Input 2: 5 2 4 8 11 18 19 Example Output 2: 5 Now solve the problem by providing the code.
n, d = map(int, input().split()) li = list(map(int, input().split())) c = 2 for i in range(1, n): if (li[i] - li[i-1]) == 2*d: c = c + 1 if (li[i] - li[i-1]) > 2*d: c = c + 2 print(c)
vfc_82825
{ "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\n-3 2 9 16", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 2\n4 8 11 18 19", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 10\n-67 -59 -49 -38 -8 20 41 59 74 83", "output": "8", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 10\n0 20 48 58 81 95 111 137 147 159", "output": "9", "type": "stdin_stdout" }, { "fn_name": null, "input": "100 1\n0 1 2 3 4 5 7 8 10 11 12 13 14 15 16 17 19 21 22 23 24 25 26 27 28 30 32 33 36 39 40 41 42 46 48 53 54 55 59 60 61 63 65 68 70 71 74 75 76 79 80 81 82 84 88 89 90 91 93 94 96 97 98 100 101 102 105 106 107 108 109 110 111 113 114 115 116 117 118 120 121 122 125 126 128 131 132 133 134 135 137 138 139 140 143 144 146 147 148 149", "output": "47", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1000000000\n-1000000000", "output": "2", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
858
Solve the following coding problem using the programming language python: For a given positive integer *n* denote its *k*-rounding as the minimum positive integer *x*, such that *x* ends with *k* or more zeros in base 10 and is divisible by *n*. For example, 4-rounding of 375 is 375Β·80<==<=30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375. Write a program that will perform the *k*-rounding of *n*. The input will be provided via standard input and looks as follows: The only line contains two integers *n* and *k* (1<=≀<=*n*<=≀<=109, 0<=≀<=*k*<=≀<=8). You should write the solution as standard output as follows: Print the *k*-rounding of *n*. Here are example inputs and outputs for the problem: Example Input 1: 375 4 Example Output 1: 30000 Example Input 2: 10000 1 Example Output 2: 10000 Example Input 3: 38101 0 Example Output 3: 38101 Example Input 4: 123456789 8 Example Output 4: 12345678900000000 Now solve the problem by providing the code.
import math n,k = map(int,input().split()) m =(n * (10**k)) / math.gcd(n, (10**k)) print(int(m))
vfc_82829
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "375 4", "output": "30000", "type": "stdin_stdout" }, { "fn_name": null, "input": "10000 1", "output": "10000", "type": "stdin_stdout" }, { "fn_name": null, "input": "38101 0", "output": "38101", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
610
Solve the following coding problem using the programming language python: Pasha has a wooden stick of some positive integer length *n*. He wants to perform exactly three cuts to get four parts of the stick. Each part must have some positive integer length and the sum of these lengths will obviously be *n*. Pasha likes rectangles but hates squares, so he wonders, how many ways are there to split a stick into four parts so that it's possible to form a rectangle using these parts, but is impossible to form a square. Your task is to help Pasha and count the number of such ways. Two ways to cut the stick are considered distinct if there exists some integer *x*, such that the number of parts of length *x* in the first way differ from the number of parts of length *x* in the second way. The input will be provided via standard input and looks as follows: The first line of the input contains a positive integer *n* (1<=≀<=*n*<=≀<=2Β·109) β€” the length of Pasha's stick. You should write the solution as standard output as follows: The output should contain a single integerΒ β€” the number of ways to split Pasha's stick into four parts of positive integer length so that it's possible to make a rectangle by connecting the ends of these parts, but is impossible to form a square. Here are example inputs and outputs for the problem: Example Input 1: 6 Example Output 1: 1 Example Input 2: 20 Example Output 2: 4 Now solve the problem by providing the code.
n = int(input()) if n % 2 != 0 or n < 6: print(0) else: k = n // 2 if n % 4 == 0: print(k//2-1) else: print(k//2)
vfc_82833
{ "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", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
381
Solve the following coding problem using the programming language python: Sereja and Dima play a game. The rules of the game are very simple. The players have *n* cards in a row. Each card contains a number, all numbers on the cards are distinct. The players take turns, Sereja moves first. During his turn a player can take one card: either the leftmost card in a row, or the rightmost one. The game ends when there is no more cards. The player who has the maximum sum of numbers on his cards by the end of the game, wins. Sereja and Dima are being greedy. Each of them chooses the card with the larger number during his move. Inna is a friend of Sereja and Dima. She knows which strategy the guys are using, so she wants to determine the final score, given the initial state of the game. Help her. The input will be provided via standard input and looks as follows: The first line contains integer *n* (1<=≀<=*n*<=≀<=1000) β€” the number of cards on the table. The second line contains space-separated numbers on the cards from left to right. The numbers on the cards are distinct integers from 1 to 1000. You should write the solution as standard output as follows: On a single line, print two integers. The first number is the number of Sereja's points at the end of the game, the second number is the number of Dima's points at the end of the game. Here are example inputs and outputs for the problem: Example Input 1: 4 4 1 2 10 Example Output 1: 12 5 Example Input 2: 7 1 2 3 4 5 6 7 Example Output 2: 16 12 Now solve the problem by providing the code.
n=int(input()) l=[] Sereja , Dima, i = 0, 0, 0 t=map(int,input().split()) l+=t y=len(l) a=True while(y!=0): if(l[0]>=l[y-1]): x=l[0] l.pop(0) else: x=l[y-1] l.pop(y-1) if(a==True): Sereja+=x a=False else: Dima+=x a=True y-=1 print(Sereja,Dima)
vfc_82837
{ "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\n4 1 2 10", "output": "12 5", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n1 2 3 4 5 6 7", "output": "16 12", "type": "stdin_stdout" }, { "fn_name": null, "input": "42\n15 29 37 22 16 5 26 31 6 32 19 3 45 36 33 14 25 20 48 7 42 11 24 28 9 18 8 21 47 17 38 40 44 4 35 1 43 39 41 27 12 13", "output": "613 418", "type": "stdin_stdout" }, { "fn_name": null, "input": "43\n32 1 15 48 38 26 25 14 20 44 11 30 3 42 49 19 18 46 5 45 10 23 34 9 29 41 2 52 6 17 35 4 50 22 33 51 7 28 47 13 39 37 24", "output": "644 500", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
353
Solve the following coding problem using the programming language python: Valera has 2Β·*n* cubes, each cube contains an integer from 10 to 99. He arbitrarily chooses *n* cubes and puts them in the first heap. The remaining cubes form the second heap. Valera decided to play with cubes. During the game he takes a cube from the first heap and writes down the number it has. Then he takes a cube from the second heap and write out its two digits near two digits he had written (to the right of them). In the end he obtained a single fourdigit integer β€” the first two digits of it is written on the cube from the first heap, and the second two digits of it is written on the second cube from the second heap. Valera knows arithmetic very well. So, he can easily count the number of distinct fourdigit numbers he can get in the game. The other question is: how to split cubes into two heaps so that this number (the number of distinct fourdigit integers Valera can get) will be as large as possible? The input will be provided via standard input and looks as follows: The first line contains integer *n* (1<=≀<=*n*<=≀<=100). The second line contains 2Β·*n* space-separated integers *a**i* (10<=≀<=*a**i*<=≀<=99), denoting the numbers on the cubes. You should write the solution as standard output as follows: In the first line print a single number β€” the maximum possible number of distinct four-digit numbers Valera can obtain. In the second line print 2Β·*n* numbers *b**i* (1<=≀<=*b**i*<=≀<=2). The numbers mean: the *i*-th cube belongs to the *b**i*-th heap in your division. If there are multiple optimal ways to split the cubes into the heaps, print any of them. Here are example inputs and outputs for the problem: Example Input 1: 1 10 99 Example Output 1: 1 2 1 Example Input 2: 2 13 24 13 45 Example Output 2: 4 1 2 2 1 Now solve the problem by providing the code.
from sys import stdin n = int(stdin.readline()) a = [int(x) for x in stdin.readline().split()] a = sorted([(a[x], x) for x in range(n*2)]) group = {} for x,ind in a: if x in group: group[x].append(ind) else: group[x] = [ind] g2 = [] for x in group: g2.append([len(group[x]), group[x]]) g2.sort() left = 0 right = 0 board = [0 for x in range(n*2)] ind = 0 for x,l in g2: if x == 1: ind += 1 if left <= right: left += 1 board[l[0]] = '1' else: right += 1 board[l[0]] = '2' else: break if right > left: turn = True else: turn = False for x,l in g2[ind:]: left += 1 right += 1 if x%2 == 1: last = l.pop() if turn: board[last] = '1' else: board[last] = '2' turn = not turn for n in l[::2]: board[n] = '1' for n in l[1::2]: board[n] = '2' print(left*right) print(' '.join(board))
vfc_82841
{ "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\n10 99", "output": "1\n2 1 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n13 24 13 45", "output": "4\n1 2 2 1 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n21 60 18 21 17 39 58 74 62 34", "output": "25\n1 1 1 2 2 1 2 1 2 2 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n26 43 29 92 22 27 95 56 72 55 93 51 91 30 70 77 32 69 87 98", "output": "100\n1 2 1 2 2 2 2 1 2 2 1 1 1 2 1 1 1 2 2 1 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "20\n80 56 58 61 75 60 25 49 59 15 43 39 21 73 67 13 75 31 18 87 32 44 53 15 53 76 79 94 85 80 27 25 48 78 32 18 20 78 46 37", "output": "400\n1 2 1 2 1 1 1 1 2 1 1 2 2 2 1 2 2 2 1 2 1 2 1 2 2 1 2 1 1 2 1 2 2 1 2 2 1 2 1 1 ", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
734
Solve the following coding problem using the programming language python: Anton likes to play chess, and so does his friend Danik. Once they have played *n* games in a row. For each game it's known who was the winnerΒ β€” Anton or Danik. None of the games ended with a tie. Now Anton wonders, who won more games, he or Danik? Help him determine this. 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 games played. The second line contains a string *s*, consisting of *n* uppercase English letters 'A' and 'D'Β β€” the outcome of each of the games. The *i*-th character of the string is equal to 'A' if the Anton won the *i*-th game and 'D' if Danik won the *i*-th game. You should write the solution as standard output as follows: If Anton won more games than Danik, print "Anton" (without quotes) in the only line of the output. If Danik won more games than Anton, print "Danik" (without quotes) in the only line of the output. If Anton and Danik won the same number of games, print "Friendship" (without quotes). Here are example inputs and outputs for the problem: Example Input 1: 6 ADAAAA Example Output 1: Anton Example Input 2: 7 DDDAADA Example Output 2: Danik Example Input 3: 6 DADADA Example Output 3: Friendship Now solve the problem by providing the code.
n=int(input()) a=d=0 s=input() for i in range(n): if s[i]=='A': a+=1 else: d+=1 if a==d: print('Friendship') elif a>d: print('Anton') else: print('Danik')
vfc_82845
{ "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\nADAAAA", "output": "Anton", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
900
Solve the following coding problem using the programming language python: You have *n* distinct points on a plane, none of them lie on *OY* axis. Check that there is a point after removal of which the remaining points are located on one side of the *OY* axis. The input will be provided via standard input and looks as follows: The first line contains a single positive integer *n* (2<=≀<=*n*<=≀<=105). The following *n* lines contain coordinates of the points. The *i*-th of these lines contains two single integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≀<=109, *x**i*<=β‰ <=0). No two points coincide. You should write the solution as standard output as follows: Print "Yes" if there is such a point, "No" β€” otherwise. You can print every letter in any case (upper or lower). Here are example inputs and outputs for the problem: Example Input 1: 3 1 1 -1 -1 2 -1 Example Output 1: Yes Example Input 2: 4 1 1 2 2 -1 1 -2 2 Example Output 2: No Example Input 3: 3 1 2 2 1 4 60 Example Output 3: Yes Now solve the problem by providing the code.
n = int(input()) p , nn = 0 ,0 for i in range(n): x,y = map(int,input().split()) if x > 0: p += 1 else: nn += 1 if p > 1 and nn > 1: print('NO') elif p <= 1 or nn <= 1: print('YES')
vfc_82849
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 1\n-1 -1\n2 -1", "output": "Yes", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 1\n2 2\n-1 1\n-2 2", "output": "No", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
343
Solve the following coding problem using the programming language python: Mad scientist Mike does not use slow hard disks. His modification of a hard drive has not one, but *n* different heads that can read data in parallel. When viewed from the side, Mike's hard drive is an endless array of tracks. The tracks of the array are numbered from left to right with integers, starting with 1. In the initial state the *i*-th reading head is above the track number *h**i*. For each of the reading heads, the hard drive's firmware can move the head exactly one track to the right or to the left, or leave it on the current track. During the operation each head's movement does not affect the movement of the other heads: the heads can change their relative order; there can be multiple reading heads above any of the tracks. A track is considered read if at least one head has visited this track. In particular, all of the tracks numbered *h*1, *h*2, ..., *h**n* have been read at the beginning of the operation. Mike needs to read the data on *m* distinct tracks with numbers *p*1, *p*2, ..., *p**m*. Determine the minimum time the hard drive firmware needs to move the heads and read all the given tracks. Note that an arbitrary number of other tracks can also be read. The input will be provided via standard input and looks as follows: The first line of the input contains two space-separated integers *n*, *m* (1<=≀<=*n*,<=*m*<=≀<=105) β€” the number of disk heads and the number of tracks to read, accordingly. The second line contains *n* distinct integers *h**i* in ascending order (1<=≀<=*h**i*<=≀<=1010, *h**i*<=&lt;<=*h**i*<=+<=1) β€” the initial positions of the heads. The third line contains *m* distinct integers *p**i* in ascending order (1<=≀<=*p**i*<=≀<=1010, *p**i*<=&lt;<=*p**i*<=+<=1) - the numbers of tracks to read. Please, do not use the %lld specifier to read or write 64-bit integers in Π‘++. It is recommended to use the cin, cout streams or the %I64d specifier. You should write the solution as standard output as follows: Print a single number β€” the minimum time required, in seconds, to read all the needed tracks. Here are example inputs and outputs for the problem: Example Input 1: 3 4 2 5 6 1 3 6 8 Example Output 1: 2 Example Input 2: 3 3 1 2 3 1 2 3 Example Output 2: 0 Example Input 3: 1 2 165 142 200 Example Output 3: 81 Now solve the problem by providing the code.
# Read Time import sys input = sys.stdin.buffer.readline n, m = map(int, input().split()) h = list(map(int, input().split())) p = list(map(int, input().split())) # minimmum time for h_i to cover all p_s...p_e def min_t(h_i, p_s, p_e): return min(abs(h[h_i]-p[p_s]),abs(h[h_i]-p[p_e])) + (p[p_e]-p[p_s]) # if all the heads can read all the tracks in <= mx_t time # we use greedy :) def check(mx_t): h_i = 0 p_i = 0 while p_i < m and h_i < n: p_j = p_i while p_j+1 < m and min_t(h_i, p_i, p_j+1) <= mx_t: p_j += 1 if min_t(h_i, p_i, p_j) <= mx_t: p_i = p_j+1 h_i += 1 return p_i == m l = 0 r = 10**11 while l != r: mt = (l+r)//2 if check(mt): r = mt else: l = mt+1 print(l)
vfc_82853
{ "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 4\n2 5 6\n1 3 6 8", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n1 2 3\n1 2 3", "output": "0", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
678
Solve the following coding problem using the programming language python: Consider a linear function *f*(*x*)<==<=*Ax*<=+<=*B*. Let's define *g*(0)(*x*)<==<=*x* and *g*(*n*)(*x*)<==<=*f*(*g*(*n*<=-<=1)(*x*)) for *n*<=&gt;<=0. For the given integer values *A*, *B*, *n* and *x* find the value of *g*(*n*)(*x*) modulo 109<=+<=7. The input will be provided via standard input and looks as follows: The only line contains four integers *A*, *B*, *n* and *x* (1<=≀<=*A*,<=*B*,<=*x*<=≀<=109,<=1<=≀<=*n*<=≀<=1018) β€” the parameters from the problem statement. Note that the given value *n* can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type. You should write the solution as standard output as follows: Print the only integer *s* β€” the value *g*(*n*)(*x*) modulo 109<=+<=7. Here are example inputs and outputs for the problem: Example Input 1: 3 4 1 1 Example Output 1: 7 Example Input 2: 3 4 2 1 Example Output 2: 25 Example Input 3: 3 4 3 1 Example Output 3: 79 Now solve the problem by providing the code.
import sys,math def power(x, y, p): res = 1; x = x % p; while (y > 0): if (y & 1): res = (res * x) % p; y = y >> 1; x = (x * x) % p; return res; def modInverse(b,m): g = math.gcd(b, m) if (g != 1): return -1 else: return pow(b, m - 2, m) def modDivide(a,b,m): a = a % m inv = modInverse(b,m) if(inv == -1): print("Division not defined") else: return (inv*a) % m #using sum of GP series A,B,n,X=map(int,sys.stdin.readline().split()) m=10**9+7 if A==1: print(((n%m)*B+X)%m) else: temp=power(A,n,m) s=(temp*(X%m))%m s=(s%m+((modDivide(B*(temp-1),A-1,m)%m)%m)%m)%m print(s%m)
vfc_82857
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "500" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 4 1 1", "output": "7", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 4 2 1", "output": "25", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 4 3 1", "output": "79", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1 1 1", "output": "2", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
424
Solve the following coding problem using the programming language python: Pasha has many hamsters and he makes them work out. Today, *n* hamsters (*n* is even) came to work out. The hamsters lined up and each hamster either sat down or stood up. For another exercise, Pasha needs exactly hamsters to stand up and the other hamsters to sit down. In one minute, Pasha can make some hamster ether sit down or stand up. How many minutes will he need to get what he wants if he acts optimally well? The input will be provided via standard input and looks as follows: The first line contains integer *n* (2<=≀<=*n*<=≀<=200; *n* is even). The next line contains *n* characters without spaces. These characters describe the hamsters' position: the *i*-th character equals 'X', if the *i*-th hamster in the row is standing, and 'x', if he is sitting. You should write the solution as standard output as follows: In the first line, print a single integer β€” the minimum required number of minutes. In the second line, print a string that describes the hamsters' position after Pasha makes the required changes. If there are multiple optimal positions, print any of them. Here are example inputs and outputs for the problem: Example Input 1: 4 xxXx Example Output 1: 1 XxXx Example Input 2: 2 XX Example Output 2: 1 xX Example Input 3: 6 xXXxXx Example Output 3: 0 xXXxXx Now solve the problem by providing the code.
def main(): input() s = input() ta = t = (s.count('x') - s.count('X')) // 2 res = [] if t > 0: for c in s: if t and c == 'x': c = 'X' t -= 1 res.append(c) else: for c in s: if t and c == 'X': c = 'x' t += 1 res.append(c) print(abs(ta)) print(''.join(res)) if __name__ == '__main__': main()
vfc_82861
{ "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\nxxXx", "output": "1\nXxXx", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\nXX", "output": "1\nxX", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\nxXXxXx", "output": "0\nxXXxXx", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\nxXXX", "output": "1\nxxXX", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
456
Solve the following coding problem using the programming language python: One day Dima and Alex had an argument about the price and quality of laptops. Dima thinks that the more expensive a laptop is, the better it is. Alex disagrees. Alex thinks that there are two laptops, such that the price of the first laptop is less (strictly smaller) than the price of the second laptop but the quality of the first laptop is higher (strictly greater) than the quality of the second laptop. Please, check the guess of Alex. You are given descriptions of *n* laptops. Determine whether two described above laptops exist. The input will be provided via standard input and looks as follows: The first line contains an integer *n* (1<=≀<=*n*<=≀<=105) β€” the number of laptops. Next *n* lines contain two integers each, *a**i* and *b**i* (1<=≀<=*a**i*,<=*b**i*<=≀<=*n*), where *a**i* is the price of the *i*-th laptop, and *b**i* is the number that represents the quality of the *i*-th laptop (the larger the number is, the higher is the quality). All *a**i* are distinct. All *b**i* are distinct. You should write the solution as standard output as follows: If Alex is correct, print "Happy Alex", otherwise print "Poor Alex" (without the quotes). Here are example inputs and outputs for the problem: Example Input 1: 2 1 2 2 1 Example Output 1: Happy Alex Now solve the problem by providing the code.
def solve(): x = int(input()) l = [] for i in range(x): a, b = map(int, input().split()) l.append((a, b)) l.sort(key=lambda p: p[0]) for i in range(1, x): if l[i][1]-l[i-1][1] < 0: print('Happy Alex') return print('Poor Alex') # t = int(input()) t = 1 while t: solve() t -= 1
vfc_82865
{ "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\n1 2\n2 1", "output": "Happy Alex", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 1\n2 2", "output": "Poor Alex", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2 2\n3 3\n1 1", "output": "Poor Alex", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n3 3\n1 2\n2 1", "output": "Happy Alex", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
677
Solve the following coding problem using the programming language python: Vanya and his friends are walking along the fence of height *h* and they do not want the guard to notice them. In order to achieve this the height of each of the friends should not exceed *h*. If the height of some person is greater than *h* he can bend down and then he surely won't be noticed by the guard. The height of the *i*-th person is equal to *a**i*. Consider the width of the person walking as usual to be equal to 1, while the width of the bent person is equal to 2. Friends want to talk to each other while walking, so they would like to walk in a single row. What is the minimum width of the road, such that friends can walk in a row and remain unattended by the guard? The input will be provided via standard input and looks as follows: The first line of the input contains two integers *n* and *h* (1<=≀<=*n*<=≀<=1000, 1<=≀<=*h*<=≀<=1000)Β β€” the number of friends and the height of the fence, respectively. The second line contains *n* integers *a**i* (1<=≀<=*a**i*<=≀<=2*h*), the *i*-th of them is equal to the height of the *i*-th person. You should write the solution as standard output as follows: Print a single integerΒ β€” the minimum possible valid width of the road. Here are example inputs and outputs for the problem: Example Input 1: 3 7 4 5 14 Example Output 1: 4 Example Input 2: 6 1 1 1 1 1 1 1 Example Output 2: 6 Example Input 3: 6 5 7 6 8 9 10 5 Example Output 3: 11 Now solve the problem by providing the code.
friends_num, fence_height = map(int, input().split()) friends_heights = [int(height) for height in input().split()] road_width = sum( 1 if height <= fence_height else 2 for height in friends_heights ) print(road_width)
vfc_82869
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1500" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 7\n4 5 14", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 1\n1 1 1 1 1 1", "output": "6", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
52
Solve the following coding problem using the programming language python: There is a given sequence of integers *a*1,<=*a*2,<=...,<=*a**n*, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. The input will be provided via standard input and looks as follows: The first line contains an integer *n* (1<=≀<=*n*<=≀<=106). The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=3). You should write the solution as standard output as follows: Print the minimum number of replacements needed to be performed to make all the numbers in the sequence equal. Here are example inputs and outputs for the problem: Example Input 1: 9 1 3 2 2 2 1 1 2 3 Example Output 1: 5 Now solve the problem by providing the code.
n = int(input()) s = input().split() max_ = 0 for el in range(1,4): if s.count(str(el)) > max_: max_ = s.count(str(el)) print(len(s) - max_)
vfc_82873
{ "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\n1 3 2 2 2 1 1 2 3", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n3 3 2 2 1 3", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "12\n3 1 3 1 2 1 3 2 2 1 2 1", "output": "7", "type": "stdin_stdout" }, { "fn_name": null, "input": "15\n3 2 1 1 1 1 3 2 2 3 3 1 2 3 2", "output": "10", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2 1", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n3 2", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
155
Solve the following coding problem using the programming language python: Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him. One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For each contest where this coder participated, he wrote out a single non-negative number β€” the number of points his favorite coder earned in the contest. Vasya wrote out the points for the contest in the order, in which the contests run (naturally, no two contests ran simultaneously). Vasya considers a coder's performance in a contest amazing in two situations: he can break either his best or his worst performance record. First, it is amazing if during the contest the coder earns strictly more points that he earned on each past contest. Second, it is amazing if during the contest the coder earns strictly less points that he earned on each past contest. A coder's first contest isn't considered amazing. Now he wants to count the number of amazing performances the coder had throughout his whole history of participating in contests. But the list of earned points turned out long and Vasya can't code... That's why he asks you to help him. The input will be provided via standard input and looks as follows: The first line contains the single integer *n* (1<=≀<=*n*<=≀<=1000) β€” the number of contests where the coder participated. The next line contains *n* space-separated non-negative integer numbers β€” they are the points which the coder has earned. The points are given in the chronological order. All points do not exceed 10000. You should write the solution as standard output as follows: Print the single number β€” the number of amazing performances the coder has had during his whole history of participating in the contests. Here are example inputs and outputs for the problem: Example Input 1: 5 100 50 200 150 200 Example Output 1: 2 Example Input 2: 10 4664 6496 5814 7010 5762 5736 6944 4850 3698 7242 Example Output 2: 4 Now solve the problem by providing the code.
n = int(input()) numbers = list(map(int, input().split())) best = worst = numbers[0] amazing = 0 for current in numbers[1:]: if current < worst: worst = current amazing += 1 if current > best: best = current amazing += 1 print(amazing)
vfc_82877
{ "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\n100 50 200 150 200", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n6", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2 1", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n100 36 53 7 81", "output": "2", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
780
Solve the following coding problem using the programming language python: Andryusha is an orderly boy and likes to keep things in their place. Today he faced a problem to put his socks in the wardrobe. He has *n* distinct pairs of socks which are initially in a bag. The pairs are numbered from 1 to *n*. Andryusha wants to put paired socks together and put them in the wardrobe. He takes the socks one by one from the bag, and for each sock he looks whether the pair of this sock has been already took out of the bag, or not. If not (that means the pair of this sock is still in the bag), he puts the current socks on the table in front of him. Otherwise, he puts both socks from the pair to the wardrobe. Andryusha remembers the order in which he took the socks from the bag. Can you tell him what is the maximum number of socks that were on the table at the same time? The input will be provided via standard input and looks as follows: The first line contains the single integer *n* (1<=≀<=*n*<=≀<=105)Β β€” the number of sock pairs. The second line contains 2*n* integers *x*1,<=*x*2,<=...,<=*x*2*n* (1<=≀<=*x**i*<=≀<=*n*), which describe the order in which Andryusha took the socks from the bag. More precisely, *x**i* means that the *i*-th sock Andryusha took out was from pair *x**i*. It is guaranteed that Andryusha took exactly two socks of each pair. You should write the solution as standard output as follows: Print single integerΒ β€” the maximum number of socks that were on the table at the same time. Here are example inputs and outputs for the problem: Example Input 1: 1 1 1 Example Output 1: 1 Example Input 2: 3 2 1 1 3 2 3 Example Output 2: 2 Now solve the problem by providing the code.
input() k=set() ans=0 for i in tuple(map(int,input().split())): if i not in k: k.add(i) ans=max(len(k),ans) else: k.remove(i) print(ans)
vfc_82881
{ "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 1", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2 1 1 3 2 3", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n5 1 3 2 4 3 1 2 4 5", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n4 2 6 3 4 8 7 1 1 5 2 10 6 8 3 5 10 9 9 7", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "50\n30 47 31 38 37 50 36 43 9 23 2 2 15 31 14 49 9 16 6 44 27 14 5 6 3 47 25 26 1 35 3 15 24 19 8 46 49 41 4 26 40 28 42 11 34 35 46 18 7 28 18 40 19 42 4 41 38 48 50 12 29 39 33 17 25 22 22 21 36 45 27 30 20 7 13 29 39 44 21 8 37 45 34 1 20 10 11 17 33 12 43 13 10 16 48 24 32 5 23 32", "output": "25", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
313
Solve the following coding problem using the programming language python: Ilya is a very clever lion, he lives in an unusual city ZooVille. In this city all the animals have their rights and obligations. Moreover, they even have their own bank accounts. The state of a bank account is an integer. The state of a bank account can be a negative number. This means that the owner of the account owes the bank money. Ilya the Lion has recently had a birthday, so he got a lot of gifts. One of them (the gift of the main ZooVille bank) is the opportunity to delete the last digit or the digit before last from the state of his bank account no more than once. For example, if the state of Ilya's bank account is -123, then Ilya can delete the last digit and get his account balance equal to -12, also he can remove its digit before last and get the account balance equal to -13. Of course, Ilya is permitted not to use the opportunity to delete a digit from the balance. Ilya is not very good at math, and that's why he asks you to help him maximize his bank account. Find the maximum state of the bank account that can be obtained using the bank's gift. The input will be provided via standard input and looks as follows: The single line contains integer *n* (10<=≀<=|*n*|<=≀<=109) β€” the state of Ilya's bank account. You should write the solution as standard output as follows: In a single line print an integer β€” the maximum state of the bank account that Ilya can get. Here are example inputs and outputs for the problem: Example Input 1: 2230 Example Output 1: 2230 Example Input 2: -10 Example Output 2: 0 Example Input 3: -100003 Example Output 3: -10000 Now solve the problem by providing the code.
n=str(input()) m = n if n[0] == '-': if int(n[-2]) <= int(n[-1]): m=n[:-1] else: m=n[:-2]+n[-1] m=int(m) print(m)
vfc_82889
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2230", "output": "2230", "type": "stdin_stdout" }, { "fn_name": null, "input": "-10", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "-100003", "output": "-10000", "type": "stdin_stdout" }, { "fn_name": null, "input": "544883178", "output": "544883178", "type": "stdin_stdout" }, { "fn_name": null, "input": "-847251738", "output": "-84725173", "type": "stdin_stdout" }, { "fn_name": null, "input": "423654797", "output": "423654797", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
907
Solve the following coding problem using the programming language python: Two bears are playing tic-tac-toe via mail. It's boring for them to play usual tic-tac-toe game, so they are a playing modified version of this game. Here are its rules. The game is played on the following field. Players are making moves by turns. At first move a player can put his chip in any cell of any small field. For following moves, there are some restrictions: if during last move the opposite player put his chip to cell with coordinates (*x**l*,<=*y**l*) in some small field, the next move should be done in one of the cells of the small field with coordinates (*x**l*,<=*y**l*). For example, if in the first move a player puts his chip to lower left cell of central field, then the second player on his next move should put his chip into some cell of lower left field (pay attention to the first test case). If there are no free cells in the required field, the player can put his chip to any empty cell on any field. You are given current state of the game and coordinates of cell in which the last move was done. You should find all cells in which the current player can put his chip. A hare works as a postman in the forest, he likes to foul bears. Sometimes he changes the game field a bit, so the current state of the game could be unreachable. However, after his changes the cell where the last move was done is not empty. You don't need to find if the state is unreachable or not, just output possible next moves according to the rules. The input will be provided via standard input and looks as follows: First 11 lines contains descriptions of table with 9 rows and 9 columns which are divided into 9 small fields by spaces and empty lines. Each small field is described by 9 characters without spaces and empty lines. character "x" (ASCII-code 120) means that the cell is occupied with chip of the first player, character "o" (ASCII-code 111) denotes a field occupied with chip of the second player, character "." (ASCII-code 46) describes empty cell. The line after the table contains two integers *x* and *y* (1<=≀<=*x*,<=*y*<=≀<=9). They describe coordinates of the cell in table where the last move was done. Rows in the table are numbered from up to down and columns are numbered from left to right. It's guaranteed that cell where the last move was done is filled with "x" or "o". Also, it's guaranteed that there is at least one empty cell. It's not guaranteed that current state of game is reachable. You should write the solution as standard output as follows: Output the field in same format with characters "!" (ASCII-code 33) on positions where the current player can put his chip. All other cells should not be modified. Here are example inputs and outputs for the problem: Example Input 1: ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... x.. ... ... ... ... ... ... ... ... ... ... 6 4 Example Output 1: ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... x.. ... !!! ... ... !!! ... ... !!! ... ... Example Input 2: xoo x.. x.. ooo ... ... ooo ... ... x.. x.. x.. ... ... ... ... ... ... x.. x.. x.. ... ... ... ... ... ... 7 4 Example Output 2: xoo x!! x!! ooo !!! !!! ooo !!! !!! x!! x!! x!! !!! !!! !!! !!! !!! !!! x!! x!! x!! !!! !!! !!! !!! !!! !!! Example Input 3: o.. ... ... ... ... ... ... ... ... ... xxx ... ... xox ... ... ooo ... ... ... ... ... ... ... ... ... ... 5 5 Example Output 3: o!! !!! !!! !!! !!! !!! !!! !!! !!! !!! xxx !!! !!! xox !!! !!! ooo !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! Now solve the problem by providing the code.
field = [[""]*9 for i in range(9)] z = 0 for i in range(3): temp2 = input() for z2 in range(len(temp2)): if temp2[z2] != " ": field[i][z] = temp2[z2] z+= 1 z = 0 input() for i in range(3,6): temp2 = input() for z2 in range(len(temp2)): if temp2[z2] != " ": field[i][z] = temp2[z2] z+= 1 z = 0 input() for i in range(6,9): temp2 = input() for z2 in range(len(temp2)): if temp2[z2] != " ": field[i][z] = temp2[z2] z+= 1 z = 0 x, y = map(int,input().split()) x2 = ((y-1) % 3) * 3 y2 = ((x-1) % 3) * 3 temp = 0 for i in range(3): for j in range(3): if field[y2+i][x2+j] == ".": field[y2+i][x2+j] = "!" temp += 1 if temp == 0: for i in range(9): for j in range(9): if field[i][j] == ".": field[i][j] = "!" for i in range(9): for j in range(9): if j % 3 == 0 and j != 0: print("",end=" ") print(field[i][j],end="") if i % 3 == 2 and i != 8: print() print()
vfc_82893
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "... ... ...\n... ... ...\n... ... ...\n\n... ... ...\n... ... ...\n... x.. ...\n\n... ... ...\n... ... ...\n... ... ...\n6 4", "output": "... ... ... \n... ... ... \n... ... ... \n\n... ... ... \n... ... ... \n... x.. ... \n\n!!! ... ... \n!!! ... ... \n!!! ... ... ", "type": "stdin_stdout" }, { "fn_name": null, "input": "xoo x.. x..\nooo ... ...\nooo ... ...\n\nx.. x.. x..\n... ... ...\n... ... ...\n\nx.. x.. x..\n... ... ...\n... ... ...\n7 4", "output": "xoo x!! x!! \nooo !!! !!! \nooo !!! !!! \n\nx!! x!! x!! \n!!! !!! !!! \n!!! !!! !!! \n\nx!! x!! x!! \n!!! !!! !!! \n!!! !!! !!! ", "type": "stdin_stdout" }, { "fn_name": null, "input": "o.. ... ...\n... ... ...\n... ... ...\n\n... xxx ...\n... xox ...\n... ooo ...\n\n... ... ...\n... ... ...\n... ... ...\n5 5", "output": "o!! !!! !!! \n!!! !!! !!! \n!!! !!! !!! \n\n!!! xxx !!! \n!!! xox !!! \n!!! ooo !!! \n\n!!! !!! !!! \n!!! !!! !!! \n!!! !!! !!! ", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
137
Solve the following coding problem using the programming language python: "Hey, it's homework time" β€” thought Polycarpus and of course he started with his favourite subject, IT. Polycarpus managed to solve all tasks but for the last one in 20 minutes. However, as he failed to solve the last task after some considerable time, the boy asked you to help him. The sequence of *n* integers is called a permutation if it contains all integers from 1 to *n* exactly once. You are given an arbitrary sequence *a*1,<=*a*2,<=...,<=*a**n* containing *n* integers. Each integer is not less than 1 and not greater than 5000. Determine what minimum number of elements Polycarpus needs to change to get a permutation (he should not delete or add numbers). In a single change he can modify any single sequence element (i. e. replace it with another integer). The input will be provided via standard input and looks as follows: The first line of the input data contains an integer *n* (1<=≀<=*n*<=≀<=5000) which represents how many numbers are in the sequence. The second line contains a sequence of integers *a**i* (1<=≀<=*a**i*<=≀<=5000,<=1<=≀<=*i*<=≀<=*n*). You should write the solution as standard output as follows: Print the only number β€” the minimum number of changes needed to get the permutation. Here are example inputs and outputs for the problem: Example Input 1: 3 3 1 2 Example Output 1: 0 Example Input 2: 2 2 2 Example Output 2: 1 Example Input 3: 5 5 3 3 3 1 Example Output 3: 2 Now solve the problem by providing the code.
n = int(input()) a = input().split() d = {} for i in a: t = int(i) if t in d: d[t] += 1 else: d[t] = 1 res = 0 for i in range(1, n+1): if i not in d: res += 1 print(res)
vfc_82897
{ "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\n3 1 2", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2 2", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
713
Solve the following coding problem using the programming language python: Sonya was unable to think of a story for this problem, so here comes the formal description. You are given the array containing *n* positive integers. At one turn you can pick any element and increase or decrease it by 1. The goal is the make the array strictly increasing by making the minimum possible number of operations. You are allowed to change elements in any way, they can become negative or equal to 0. 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*<=≀<=3000)Β β€” the length of the array. Next line contains *n* integer *a**i* (1<=≀<=*a**i*<=≀<=109). You should write the solution as standard output as follows: Print the minimum number of operation required to make the array strictly increasing. Here are example inputs and outputs for the problem: Example Input 1: 7 2 1 5 11 5 9 11 Example Output 1: 9 Example Input 2: 5 5 4 3 2 1 Example Output 2: 12 Now solve the problem by providing the code.
from bisect import bisect_left as BL n = int(input()) graph = [(-99**9, 0)] # x, slope ans = 0 for i,a in enumerate(map(int,input().split())): a-= i new = [] turnj = BL(graph, (a,99**9)) - 1 if turnj != len(graph)-1: ans+= graph[-1][0] - a # add |x-a| for j in range(turnj): x, sl = graph[j] new.append((x, sl-1)) for j in range(turnj, len(graph)): x, sl = graph[j] if j == turnj: new.append((x, sl-1)) new.append((a, sl+1)) else: new.append((x, sl+1)) # remove positive slopes graph = new while graph[-1][1] > 0: x, sl = graph.pop() if graph[-1][1] != 0: graph.append((x, 0)) print(ans)
vfc_82901
{ "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\n2 1 5 11 5 9 11", "output": "9", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n5 4 3 2 1", "output": "12", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 1000", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1000 1", "output": "1000", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n100 80 60 70 90", "output": "54", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n10 16 17 11 1213 1216 1216 1209 3061 3062", "output": "16", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
348
Solve the following coding problem using the programming language python: One day *n* friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other *n*<=-<=1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the *i*-th person wants to play *a**i* rounds. What is the minimum number of rounds of the "Mafia" game they need to play to let each person play at least as many rounds as they want? The input will be provided via standard input and looks as follows: The first line contains integer *n* (3<=≀<=*n*<=≀<=105). The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a**i*<=≀<=109) β€” the *i*-th number in the list is the number of rounds the *i*-th person wants to play. You should write the solution as standard output as follows: In a single line print a single integer β€” the minimum number of game rounds the friends need to let the *i*-th person play at least *a**i* rounds. 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. Here are example inputs and outputs for the problem: Example Input 1: 3 3 2 2 Example Output 1: 4 Example Input 2: 4 2 2 2 2 Example Output 2: 3 Now solve the problem by providing the code.
from cmath import inf import math import sys from os import path #import bisect #import math from functools import reduce import collections import sys if (path.exists('CP/input.txt')): sys.stdout = open('CP/output.txt', 'w') sys.stdin = open('CP/input.txt', 'r') def ok(mid,arr,maxi): d = 0 for x in arr: d += (mid - x) #print(d) if(d>=mid): return True return False def answer(): n = int(input()) arr = list(map(int,input().split())) l,r = 0,(2**31 - 1) for x in arr: l = max(l,x) maxi = l ans=-1 while(l<=r): #print(l," ",r) mid = (l+r)//2 #print(mid) if(ok(mid,arr,maxi)): ans = mid r=mid-1 else: l=mid+1 print(ans) #t = int(input()) t=1 for _ in range(t): answer()
vfc_82905
{ "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\n3 2 2", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n2 2 2 2", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n9 7 7 8 8 7 8", "output": "9", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
387
Solve the following coding problem using the programming language python: George decided to prepare a Codesecrof round, so he has prepared *m* problems for the round. Let's number the problems with integers 1 through *m*. George estimates the *i*-th problem's complexity by integer *b**i*. To make the round good, he needs to put at least *n* problems there. Besides, he needs to have at least one problem with complexity exactly *a*1, at least one with complexity exactly *a*2, ..., and at least one with complexity exactly *a**n*. Of course, the round can also have problems with other complexities. George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity *c* to any positive integer complexity *d* (*c*<=β‰₯<=*d*), by changing limits on the input data. However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the *m* he's prepared in order to make a good round. Note that George can come up with a new problem of any complexity. The input will be provided via standard input and looks as follows: The first line contains two integers *n* and *m* (1<=≀<=*n*,<=*m*<=≀<=3000) β€” the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≀<=*a*1<=&lt;<=*a*2<=&lt;<=...<=&lt;<=*a**n*<=≀<=106) β€” the requirements for the complexity of the problems in a good round. The third line contains space-separated integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≀<=*b*1<=≀<=*b*2...<=≀<=*b**m*<=≀<=106) β€” the complexities of the problems prepared by George. 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 5 1 2 3 1 2 2 3 3 Example Output 1: 0 Example Input 2: 3 5 1 2 3 1 1 1 1 1 Example Output 2: 2 Example Input 3: 3 1 2 3 4 1 Example Output 3: 3 Now solve the problem by providing the code.
n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) jb = 0 cnt = 0 for ai in a: while jb < m and b[jb] < ai: jb += 1 if jb == m: break cnt += 1 jb += 1 print(len(a) - cnt)
vfc_82909
{ "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 5\n1 2 3\n1 2 2 3 3", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 5\n1 2 3\n1 1 1 1 1", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1\n2 3 4\n1", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "29 100\n20 32 41 67 72 155 331 382 399 412 465 470 484 511 515 529 616 637 679 715 733 763 826 843 862 903 925 979 989\n15 15 15 17 18 19 19 20 21 21 22 24 25 26 26 27 28 31 32 32 37 38 38 39 39 40 41 42 43 43 45 45 46 47 49 49 50 50 50 51 52 53 53 55 56 57 59 59 59 60 60 62 62 63 63 64 64 64 66 67 69 69 70 70 72 72 73 74 75 76 77 78 80 80 81 81 83 83 83 84 86 86 86 86 87 88 89 91 91 91 92 93 94 94 96 97 97 97 98 98", "output": "24", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
527
Solve the following coding problem using the programming language python: One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular *a* mm <=Γ—<= *b* mm sheet of paper (*a*<=&gt;<=*b*). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting the excess part. After making a paper ship from the square piece, Vasya looked on the remaining (*a*<=-<=*b*) mm <=Γ—<= *b* mm strip of paper. He got the idea to use this strip of paper in the same way to make an origami, and then use the remainder (if it exists) and so on. At the moment when he is left with a square piece of paper, he will make the last ship from it and stop. Can you determine how many ships Vasya will make during the lesson? The input will be provided via standard input and looks as follows: The first line of the input contains two integers *a*, *b* (1<=≀<=*b*<=&lt;<=*a*<=≀<=1012) β€” the sizes of the original sheet of paper. You should write the solution as standard output as follows: Print a single integer β€” the number of ships that Vasya will make. Here are example inputs and outputs for the problem: Example Input 1: 2 1 Example Output 1: 2 Example Input 2: 10 7 Example Output 2: 6 Example Input 3: 1000000000000 1 Example Output 3: 1000000000000 Now solve the problem by providing the code.
a,b = list(map(int,input().split())) ans = 0 while True: if b>a: a,b = b,a if a%b==0: ans+=a//b break else: ans+=a//b a = a%b print(ans)
vfc_82913
{ "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 1", "output": "2", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
125
Solve the following coding problem using the programming language python: Lengths are measures in Baden in inches and feet. To a length from centimeters it is enough to know that an inch equals three centimeters in Baden and one foot contains 12 inches. You are given a length equal to *n* centimeters. Your task is to convert it to feet and inches so that the number of feet was maximum. The result should be an integer rounded to the closest value containing an integral number of inches. Note that when you round up, 1 cm rounds up to 0 inches and 2 cm round up to 1 inch. The input will be provided via standard input and looks as follows: The only line contains an integer *n* (1<=≀<=*n*<=≀<=10000). You should write the solution as standard output as follows: Print two non-negative space-separated integers *a* and *b*, where *a* is the numbers of feet and *b* is the number of inches. Here are example inputs and outputs for the problem: Example Input 1: 42 Example Output 1: 1 2 Example Input 2: 5 Example Output 2: 0 2 Now solve the problem by providing the code.
x = int(input()) x = (x+1)//3 print(x//12, x%12)
vfc_82917
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "42", "output": "1 2", "type": "stdin_stdout" }, { "fn_name": null, "input": "5", "output": "0 2", "type": "stdin_stdout" }, { "fn_name": null, "input": "24", "output": "0 8", "type": "stdin_stdout" }, { "fn_name": null, "input": "1", "output": "0 0", "type": "stdin_stdout" }, { "fn_name": null, "input": "2", "output": "0 1", "type": "stdin_stdout" } ] }