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
510
Solve the following coding problem using the programming language python: Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead. A snake is a pattern on a *n* by *m* table. Denote *c*-th cell of *r*-th row as (*r*,<=*c*). The tail of the snake is located at (1,<=1), then it's body extends to (1,<=*m*), then goes down 2 rows to (3,<=*m*), then goes left to (3,<=1) and so on. Your task is to draw this snake for Fox Ciel: the empty cells should be represented as dot characters ('.') and the snake cells should be filled with number signs ('#'). Consider sample tests in order to understand the snake pattern. The input will be provided via standard input and looks as follows: The only line contains two integers: *n* and *m* (3<=≤<=*n*,<=*m*<=≤<=50). *n* is an odd number. You should write the solution as standard output as follows: Output *n* lines. Each line should contain a string consisting of *m* characters. Do not output spaces. Here are example inputs and outputs for the problem: Example Input 1: 3 3 Example Output 1: ### ..# ### Example Input 2: 3 4 Example Output 2: #### ...# #### Example Input 3: 5 3 Example Output 3: ### ..# ### #.. ### Example Input 4: 9 9 Example Output 4: ######### ........# ######### #........ ######### ........# ######### #........ ######### Now solve the problem by providing the code.
def Fox_and_Snake(r,c): next_ = 3 next_2 = 1 for i in range(r): for j in range(c): if i %2 == 0: print('#', end = '') else: if i == next_2 and j == (c-1): print('#', end = '') next_2 +=4 elif i == next_ and j ==0: print('#', end = '') next_ +=4 else : print('.', end = '') print() r, c = map( int, input().split()) Fox_and_Snake(r,c)
vfc_83341
{ "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 3", "output": "###\n..#\n###", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
618
Solve the following coding problem using the programming language python: Your friend recently gave you some slimes for your birthday. You have *n* slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other *n*<=-<=1 slimes one by one. When you add a slime, you place it at the right of all already placed slimes. Then, while the last two slimes in the row have the same value *v*, you combine them together to create a slime with value *v*<=+<=1. You would like to see what the final state of the row is after you've added all *n* slimes. Please print the values of the slimes in the row from left to right. The input will be provided via standard input and looks as follows: The first line of the input will contain a single integer, *n* (1<=≤<=*n*<=≤<=100<=000). You should write the solution as standard output as follows: Output a single line with *k* integers, where *k* is the number of slimes in the row after you've finished the procedure described in the problem statement. The *i*-th of these numbers should be the value of the *i*-th slime from the left. Here are example inputs and outputs for the problem: Example Input 1: 1 Example Output 1: 1 Example Input 2: 2 Example Output 2: 2 Example Input 3: 3 Example Output 3: 2 1 Example Input 4: 8 Example Output 4: 4 Now solve the problem by providing the code.
N = int(input()) ans = [] i = 0 while N >> i: if (N >> i) & 1: ans.append(i + 1) i += 1 print(*ans[::-1])
vfc_83345
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "2", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "3", "output": "2 1", "type": "stdin_stdout" }, { "fn_name": null, "input": "8", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "100000", "output": "17 16 11 10 8 6", "type": "stdin_stdout" }, { "fn_name": null, "input": "12345", "output": "14 13 6 5 4 1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
621
Solve the following coding problem using the programming language python: Today, Wet Shark is given *n* integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark. Note, that if Wet Shark uses no integers from the *n* integers, the sum is an even integer 0. The input will be provided via standard input and looks as follows: The first line of the input contains one integer, *n* (1<=≤<=*n*<=≤<=100<=000). The next line contains *n* space separated integers given to Wet Shark. Each of these integers is in range from 1 to 109, inclusive. You should write the solution as standard output as follows: Print the maximum possible even sum that can be obtained if we use some of the given integers. Here are example inputs and outputs for the problem: Example Input 1: 3 1 2 3 Example Output 1: 6 Example Input 2: 5 999999999 999999999 999999999 999999999 999999999 Example Output 2: 3999999996 Now solve the problem by providing the code.
def isOdd (x): return x%2==1 def isEven (x): return x%2==0 input() arr = [int(z) for z in input().split()] oddA = list(filter(isOdd,arr)) oddA.sort() evenSum = sum(filter(isEven,arr)) if(isOdd(len(oddA))): print(evenSum+sum(oddA[1:])) else: print(evenSum+sum(oddA))
vfc_83349
{ "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": "6", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
748
Solve the following coding problem using the programming language python: Santa Claus decided to disassemble his keyboard to clean it. After he returned all the keys back, he suddenly realized that some pairs of keys took each other's place! That is, Santa suspects that each key is either on its place, or on the place of another key, which is located exactly where the first key should be. In order to make sure that he's right and restore the correct order of keys, Santa typed his favorite patter looking only to his keyboard. You are given the Santa's favorite patter and the string he actually typed. Determine which pairs of keys could be mixed. Each key must occur in pairs at most once. The input will be provided via standard input and looks as follows: The input consists of only two strings *s* and *t* denoting the favorite Santa's patter and the resulting string. *s* and *t* are not empty and have the same length, which is at most 1000. Both strings consist only of lowercase English letters. You should write the solution as standard output as follows: If Santa is wrong, and there is no way to divide some of keys into pairs and swap keys in each pair so that the keyboard will be fixed, print «-1» (without quotes). Otherwise, the first line of output should contain the only integer *k* (*k*<=≥<=0) — the number of pairs of keys that should be swapped. The following *k* lines should contain two space-separated letters each, denoting the keys which should be swapped. All printed letters must be distinct. If there are several possible answers, print any of them. You are free to choose the order of the pairs and the order of keys in a pair. Each letter must occur at most once. Santa considers the keyboard to be fixed if he can print his favorite patter without mistakes. Here are example inputs and outputs for the problem: Example Input 1: helloworld ehoolwlroz Example Output 1: 3 h e l o d z Example Input 2: hastalavistababy hastalavistababy Example Output 2: 0 Example Input 3: merrychristmas christmasmerry Example Output 3: -1 Now solve the problem by providing the code.
s = input() t = input() w1, w2 = set(), set() for i in range(len(s)): l1, l2 = min(s[i], t[i]), max(s[i], t[i]) if (s[i] in w2 or t[i] in w2) and (l1, l2) not in w1: print(-1) exit() else: w2.add(s[i]) w2.add(t[i]) w1.add((l1, l2)) result = [elem for elem in w1 if elem[0] != elem[1]] print(len(result)) for elem in result: print(*elem)
vfc_83357
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "helloworld\nehoolwlroz", "output": "3\nh e\nl o\nd z", "type": "stdin_stdout" }, { "fn_name": null, "input": "hastalavistababy\nhastalavistababy", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "merrychristmas\nchristmasmerry", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "kusyvdgccw\nkusyvdgccw", "output": "0", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
235
Solve the following coding problem using the programming language python: Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it. But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be distinct) which are not greater than *n*. Can you help me to find the maximum possible least common multiple of these three integers? The input will be provided via standard input and looks as follows: The first line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the *n* mentioned in the statement. You should write the solution as standard output as follows: Print a single integer — the maximum possible LCM of three not necessarily distinct positive integers that are not greater than *n*. Here are example inputs and outputs for the problem: Example Input 1: 9 Example Output 1: 504 Example Input 2: 7 Example Output 2: 210 Now solve the problem by providing the code.
import math def main(): n = int(input()) if n <= 3: ans = 1 for i in range(1,n+1): ans *= i print(ans) return if n%2 == 0: #print(n,n-1,n-3) if n%3 == 0: print((n-3)*(n-1)*(n-2)) else: print(n*(n-1)*(n-3)) else: print(n*(n-1)*(n-2)) main()
vfc_83361
{ "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", "output": "504", "type": "stdin_stdout" }, { "fn_name": null, "input": "7", "output": "210", "type": "stdin_stdout" }, { "fn_name": null, "input": "1", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "5", "output": "60", "type": "stdin_stdout" }, { "fn_name": null, "input": "6", "output": "60", "type": "stdin_stdout" }, { "fn_name": null, "input": "33", "output": "32736", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
239
Solve the following coding problem using the programming language python: Valera had two bags of potatoes, the first of these bags contains *x* (*x*<=≥<=1) potatoes, and the second — *y* (*y*<=≥<=1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains *x* potatoes) Valera lost. Valera remembers that the total amount of potatoes (*x*<=+<=*y*) in the two bags, firstly, was not gerater than *n*, and, secondly, was divisible by *k*. Help Valera to determine how many potatoes could be in the first bag. Print all such possible numbers in ascending order. The input will be provided via standard input and looks as follows: The first line of input contains three integers *y*, *k*, *n* (1<=≤<=*y*,<=*k*,<=*n*<=≤<=109; <=≤<=105). You should write the solution as standard output as follows: Print the list of whitespace-separated integers — all possible values of *x* in ascending order. You should print each possible value of *x* exactly once. If there are no such values of *x* print a single integer -1. Here are example inputs and outputs for the problem: Example Input 1: 10 1 10 Example Output 1: -1 Example Input 2: 10 6 40 Example Output 2: 2 8 14 20 26 Now solve the problem by providing the code.
y,k,n=map(int,input().split()) x=k*(1+y//k)-y flag=0 while x+y<=n: flag=1 print(x,end=" ") x+=k if flag==0: print(-1)
vfc_83365
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 1 10", "output": "-1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
687
Solve the following coding problem using the programming language python: Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting. Suppose the graph *G* is given. Subset *A* of its vertices is called a vertex cover of this graph, if for each edge *uv* there is at least one endpoint of it in this set, i.e. or (or both). Pari and Arya have won a great undirected graph as an award in a team contest. Now they have to split it in two parts, but both of them want their parts of the graph to be a vertex cover. They have agreed to give you their graph and you need to find two disjoint subsets of its vertices *A* and *B*, such that both *A* and *B* are vertex cover or claim it's impossible. Each vertex should be given to no more than one of the friends (or you can even keep it for yourself). The input will be provided via standard input and looks as follows: The first line of the input contains two integers *n* and *m* (2<=≤<=*n*<=≤<=100<=000, 1<=≤<=*m*<=≤<=100<=000) — the number of vertices and the number of edges in the prize graph, respectively. Each of the next *m* lines contains a pair of integers *u**i* and *v**i* (1<=<=≤<=<=*u**i*,<=<=*v**i*<=<=≤<=<=*n*), denoting an undirected edge between *u**i* and *v**i*. It's guaranteed the graph won't contain any self-loops or multiple edges. You should write the solution as standard output as follows: If it's impossible to split the graph between Pari and Arya as they expect, print "-1" (without quotes). If there are two disjoint sets of vertices, such that both sets are vertex cover, print their descriptions. Each description must contain two lines. The first line contains a single integer *k* denoting the number of vertices in that vertex cover, and the second line contains *k* integers — the indices of vertices. Note that because of *m*<=≥<=1, vertex cover cannot be empty. Here are example inputs and outputs for the problem: Example Input 1: 4 2 1 2 2 3 Example Output 1: 1 2 2 1 3 Example Input 2: 3 3 1 2 2 3 1 3 Example Output 2: -1 Now solve the problem by providing the code.
n,m = list(map(int,input().split())) graph = [[]for _ in range(n)] color = [0]*n for i in range(m): a,b = list(map(int,input().split())) graph[a-1].append(b-1) graph[b-1].append(a-1) for i in range(n): if color[i]: continue color[i] = 1 queue = [i] while queue: u = queue.pop() for v in graph[u]: if color[v]: if color[v]==color[u]: print(-1) exit(0) else: color[v] = 3-color[u] queue.append(v) arr1 = [] arr2 = [] for i in range(len(color)): if color[i]==1: arr1.append(i+1) else: arr2.append(i+1) print(len(arr1)) print(*arr1) print(len(arr2)) print(*arr2)
vfc_83369
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2\n1 2\n2 3", "output": "1\n2 \n2\n1 3 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n1 2\n2 3\n1 3", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 7\n3 2\n5 4\n3 4\n1 3\n1 5\n1 4\n2 5", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 11\n4 10\n8 10\n2 3\n2 4\n7 1\n8 5\n2 8\n7 2\n1 2\n2 9\n6 8", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 9\n2 5\n2 4\n2 7\n2 9\n2 3\n2 8\n2 6\n2 10\n2 1", "output": "1\n2 \n9\n1 5 4 7 9 3 8 6 10 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 16\n6 10\n5 2\n6 4\n6 8\n5 3\n5 4\n6 2\n5 9\n5 7\n5 1\n6 9\n5 8\n5 10\n6 1\n6 7\n6 3", "output": "2\n5 6 \n8\n1 2 10 4 8 9 7 3 ", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
644
Solve the following coding problem using the programming language python: In this problem you have to simulate the workflow of one-thread server. There are *n* queries to process, the *i*-th will be received at moment *t**i* and needs to be processed for *d**i* units of time. All *t**i* are guaranteed to be distinct. When a query appears server may react in three possible ways: 1. If server is free and query queue is empty, then server immediately starts to process this query. 1. If server is busy and there are less than *b* queries in the queue, then new query is added to the end of the queue. 1. If server is busy and there are already *b* queries pending in the queue, then new query is just rejected and will never be processed. As soon as server finished to process some query, it picks new one from the queue (if it's not empty, of course). If a new query comes at some moment *x*, and the server finishes to process another query at exactly the same moment, we consider that first query is picked from the queue and only then new query appears. For each query find the moment when the server will finish to process it or print -1 if this query will be rejected. The input will be provided via standard input and looks as follows: The first line of the input contains two integers *n* and *b* (1<=≤<=*n*,<=*b*<=≤<=200<=000) — the number of queries and the maximum possible size of the query queue. Then follow *n* lines with queries descriptions (in chronological order). Each description consists of two integers *t**i* and *d**i* (1<=≤<=*t**i*,<=*d**i*<=≤<=109), where *t**i* is the moment of time when the *i*-th query appears and *d**i* is the time server needs to process it. It is guaranteed that *t**i*<=-<=1<=&lt;<=*t**i* for all *i*<=&gt;<=1. You should write the solution as standard output as follows: Print the sequence of *n* integers *e*1,<=*e*2,<=...,<=*e**n*, where *e**i* is the moment the server will finish to process the *i*-th query (queries are numbered in the order they appear in the input) or <=-<=1 if the corresponding query will be rejected. Here are example inputs and outputs for the problem: Example Input 1: 5 1 2 9 4 8 10 9 15 2 19 1 Example Output 1: 11 19 -1 21 22 Example Input 2: 4 1 2 8 4 8 10 9 15 2 Example Output 2: 10 18 27 -1 Now solve the problem by providing the code.
n, b = [int(i) for i in input().split()] q = [0] * n bg = 0 en = 0 time = 0 res = [-1] * n for it in range(n): ev = [int(i) for i in input().split()] ev.append(it) while bg < en and max(time, q[bg][0]) <= ev[0]: time = max(time, q[bg][0]) res[q[bg][2]] = time + q[bg][1] time += q[bg][1] bg += 1 if en - bg < b: q[en] = ev en += 1 while bg < en: time = max(time, q[bg][0]) res[q[bg][2]] = time + q[bg][1] time += q[bg][1] bg += 1 for i in range(n): print(res[i], end=' ')
vfc_83373
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "5000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 1\n2 9\n4 8\n10 9\n15 2\n19 1", "output": "11 19 -1 21 22 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 1\n2 8\n4 8\n10 9\n15 2", "output": "10 18 27 -1 ", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
975
Solve the following coding problem using the programming language python: Ivar the Boneless is a great leader. He is trying to capture Kattegat from Lagertha. The war has begun and wave after wave Ivar's warriors are falling in battle. Ivar has $n$ warriors, he places them on a straight line in front of the main gate, in a way that the $i$-th warrior stands right after $(i-1)$-th warrior. The first warrior leads the attack. Each attacker can take up to $a_i$ arrows before he falls to the ground, where $a_i$ is the $i$-th warrior's strength. Lagertha orders her warriors to shoot $k_i$ arrows during the $i$-th minute, the arrows one by one hit the first still standing warrior. After all Ivar's warriors fall and all the currently flying arrows fly by, Thor smashes his hammer and all Ivar's warriors get their previous strengths back and stand up to fight again. In other words, if all warriors die in minute $t$, they will all be standing to fight at the end of minute $t$. The battle will last for $q$ minutes, after each minute you should tell Ivar what is the number of his standing warriors. The input will be provided via standard input and looks as follows: The first line contains two integers $n$ and $q$ ($1 \le n, q \leq 200\,000$) — the number of warriors and the number of minutes in the battle. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) that represent the warriors' strengths. The third line contains $q$ integers $k_1, k_2, \ldots, k_q$ ($1 \leq k_i \leq 10^{14}$), the $i$-th of them represents Lagertha's order at the $i$-th minute: $k_i$ arrows will attack the warriors. You should write the solution as standard output as follows: Output $q$ lines, the $i$-th of them is the number of standing warriors after the $i$-th minute. Here are example inputs and outputs for the problem: Example Input 1: 5 5 1 2 1 2 1 3 10 1 1 1 Example Output 1: 3 5 4 4 3 Example Input 2: 4 4 1 2 3 4 9 1 10 6 Example Output 2: 1 4 4 1 Now solve the problem by providing the code.
def get_pos(curr, strength_left, arrow): l = curr h = n - 1 while (l < h): m = (l + h) // 2 strength_req = strength[m] - strength[curr] + strength_left if strength_req > arrow: h = m elif strength_req == arrow: return m else: if m == n - 1: return m l = m + 1 return l n, minutes = map(int, input().split()) strength = [int(x) for x in input().split()] arrows = [int(x) for x in input().split()] res = [0] * minutes for i in range(1, n): strength[i] = strength[i] + strength[i - 1] curr = 0 strength_left = strength[0] for i in range(minutes): arrow = arrows[i] new_pos = get_pos(curr, strength_left, arrow) temp = strength[new_pos] - strength[curr] + strength_left if temp > arrow: curr = new_pos strength_left = temp - arrow res[i] = n - curr else: curr = (new_pos + 1) % n if curr: strength_left = strength[curr] - strength[curr - 1] else: strength_left = strength[curr] res[i] = n - curr print(*res, sep='\n')
vfc_83377
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 5\n1 2 1 2 1\n3 10 1 1 1", "output": "3\n5\n4\n4\n3", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 4\n1 2 3 4\n9 1 10 6", "output": "1\n4\n4\n1", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 3\n1 1 1 1 1 1 1 1 1 1\n10 10 5", "output": "10\n10\n5", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n56563128\n897699770", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "100 55\n1 2 4 4 3 5 5 2 3 4 2 1 1 2 3 5 1 5 4 2 5 4 4 3 3 5 3 4 4 5 5 2 3 3 4 4 3 4 5 5 5 5 3 5 1 2 4 3 4 5 3 3 2 1 4 5 3 4 4 1 5 1 5 2 2 1 4 5 3 3 1 4 2 5 4 5 3 2 5 5 2 3 2 3 2 2 3 4 4 4 1 4 2 4 5 3 1 3 3 1\n5 2 1 4 3 4 3 1 4 4 1 2 3 2 1 5 5 4 5 4 2 5 2 1 5 1 4 4 3 5 4 5 1 4 4 1 5 3 1 5 2 4 1 3 2 5 4 5 4 3 4 2 2 4 3", "output": "98\n97\n97\n96\n95\n94\n94\n94\n92\n91\n91\n90\n87\n86\n86\n85\n83\n82\n80\n80\n79\n78\n77\n77\n75\n75\n74\n73\n72\n71\n70\n69\n69\n67\n66\n66\n65\n64\n63\n62\n62\n61\n61\n60\n60\n59\n58\n57\n54\n54\n52\n52\n51\n51\n50", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
119
Solve the following coding problem using the programming language python: Simon and Antisimon play a game. Initially each player receives one fixed positive integer that doesn't change throughout the game. Simon receives number *a* and Antisimon receives number *b*. They also have a heap of *n* stones. The players take turns to make a move and Simon starts. During a move a player should take from the heap the number of stones equal to the greatest common divisor of the fixed number he has received and the number of stones left in the heap. A player loses when he cannot take the required number of stones (i. e. the heap has strictly less stones left than one needs to take). Your task is to determine by the given *a*, *b* and *n* who wins the game. The input will be provided via standard input and looks as follows: The only string contains space-separated integers *a*, *b* and *n* (1<=≤<=*a*,<=*b*,<=*n*<=≤<=100) — the fixed numbers Simon and Antisimon have received correspondingly and the initial number of stones in the pile. You should write the solution as standard output as follows: If Simon wins, print "0" (without the quotes), otherwise print "1" (without the quotes). Here are example inputs and outputs for the problem: Example Input 1: 3 5 9 Example Output 1: 0 Example Input 2: 1 1 100 Example Output 2: 1 Now solve the problem by providing the code.
import math a , b, n= [int(i) for i in input().split()] ans = False while True: if ans == False: g = math.gcd(a,n) n -=g if n <=0: print(int(ans)) break ans = not ans else: g = math.gcd(b,n) n -=g if n <=0: print(int(ans)) break ans = not ans
vfc_83381
{ "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 5 9", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1 100", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "23 12 16", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
448
Solve the following coding problem using the programming language python: Bizon the Champion isn't just a bison. He also is a favorite of the "Bizons" team. At a competition the "Bizons" got the following problem: "You are given two distinct words (strings of English letters), *s* and *t*. You need to transform word *s* into word *t*". The task looked simple to the guys because they know the suffix data structures well. Bizon Senior loves suffix automaton. By applying it once to a string, he can remove from this string any single character. Bizon Middle knows suffix array well. By applying it once to a string, he can swap any two characters of this string. The guys do not know anything about the suffix tree, but it can help them do much more. Bizon the Champion wonders whether the "Bizons" can solve the problem. Perhaps, the solution do not require both data structures. Find out whether the guys can solve the problem and if they can, how do they do it? Can they solve it either only with use of suffix automaton or only with use of suffix array or they need both structures? Note that any structure may be used an unlimited number of times, the structures may be used in any order. The input will be provided via standard input and looks as follows: The first line contains a non-empty word *s*. The second line contains a non-empty word *t*. Words *s* and *t* are different. Each word consists only of lowercase English letters. Each word contains at most 100 letters. You should write the solution as standard output as follows: In the single line print the answer to the problem. Print "need tree" (without the quotes) if word *s* cannot be transformed into word *t* even with use of both suffix array and suffix automaton. Print "automaton" (without the quotes) if you need only the suffix automaton to solve the problem. Print "array" (without the quotes) if you need only the suffix array to solve the problem. Print "both" (without the quotes), if you need both data structures to solve the problem. It's guaranteed that if you can solve the problem only with use of suffix array, then it is impossible to solve it only with use of suffix automaton. This is also true for suffix automaton. Here are example inputs and outputs for the problem: Example Input 1: automaton tomat Example Output 1: automaton Example Input 2: array arary Example Output 2: array Example Input 3: both hot Example Output 3: both Example Input 4: need tree Example Output 4: need tree Now solve the problem by providing the code.
def main(): s = input() t = input() ans_list = ['automaton', 'array', 'both', 'need tree'] ans = '' if s == t: ans = ans_list[0] elif sorted(s) == sorted(t): ans = ans_list[1] elif len(s) < len(t): ans = ans_list[3] if ans != '': print(ans) return ls = [0 for _ in range(26)] lt = ls.copy() for c in s: ls[ord(c) - ord('a')] += 1 for c in t: lt[ord(c) - ord('a')] += 1 chk = True for i in range(26): if ls[i] < lt[i]: chk = False if not chk: print(ans_list[3]) return x, y, n, m = 0, 0, len(s), len(t) while y < m: while x < n: x += 1 if s[x-1] == t[y]: y += 1 break if x == n: break if y < m: print(ans_list[2]) else: print(ans_list[0]) if __name__ == '__main__': main()
vfc_83385
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "automaton\ntomat", "output": "automaton", "type": "stdin_stdout" }, { "fn_name": null, "input": "array\narary", "output": "array", "type": "stdin_stdout" }, { "fn_name": null, "input": "both\nhot", "output": "both", "type": "stdin_stdout" }, { "fn_name": null, "input": "need\ntree", "output": "need tree", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
930
Solve the following coding problem using the programming language python: In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are *n* inflorescences, numbered from 1 to *n*. Inflorescence number 1 is situated near base of tree and any other inflorescence with number *i* (*i*<=&gt;<=1) is situated at the top of branch, which bottom is *p**i*-th inflorescence and *p**i*<=&lt;<=*i*. Once tree starts fruiting, there appears exactly one apple in each inflorescence. The same moment as apples appear, they start to roll down along branches to the very base of tree. Each second all apples, except ones in first inflorescence simultaneously roll down one branch closer to tree base, e.g. apple in *a*-th inflorescence gets to *p**a*-th inflorescence. Apples that end up in first inflorescence are gathered by Arcady in exactly the same moment. Second peculiarity of this tree is that once two apples are in same inflorescence they annihilate. This happens with each pair of apples, e.g. if there are 5 apples in same inflorescence in same time, only one will not be annihilated and if there are 8 apples, all apples will be annihilated. Thus, there can be no more than one apple in each inflorescence in each moment of time. Help Arcady with counting number of apples he will be able to collect from first inflorescence during one harvest. The input will be provided via standard input and looks as follows: First line of input contains single integer number *n* (2<=≤<=*n*<=≤<=100<=000)  — number of inflorescences. Second line of input contains sequence of *n*<=-<=1 integer numbers *p*2,<=*p*3,<=...,<=*p**n* (1<=≤<=*p**i*<=&lt;<=*i*), where *p**i* is number of inflorescence into which the apple from *i*-th inflorescence rolls down. You should write the solution as standard output as follows: Single line of output should contain one integer number: amount of apples that Arcady will be able to collect from first inflorescence during one harvest. Here are example inputs and outputs for the problem: Example Input 1: 3 1 1 Example Output 1: 1 Example Input 2: 5 1 2 2 2 Example Output 2: 3 Example Input 3: 18 1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4 Example Output 3: 4 Now solve the problem by providing the code.
n = int(input()) a = [int(e) for e in input().split()] d = {1:0} for k, v in enumerate(a): d[k+2] = d[v] + 1 d2 = {} for k, v in d.items(): d2[v] = d2.get(v,0) + 1 s = sum([v%2 for v in d2.values()]) print(s)
vfc_83389
{ "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", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 2 2 2", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "18\n1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4", "output": "4", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
558
Solve the following coding problem using the programming language python: Amr has got a large array of size *n*. Amr doesn't like large arrays so he intends to make it smaller. Amr doesn't care about anything in the array except the beauty of it. The beauty of the array is defined to be the maximum number of times that some number occurs in this array. He wants to choose the smallest subsegment of this array such that the beauty of it will be the same as the original array. Help Amr by choosing the smallest subsegment possible. The input will be provided via standard input and looks as follows: The first line contains one number *n* (1<=≤<=*n*<=≤<=105), the size of the array. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=106), representing elements of the array. You should write the solution as standard output as follows: Output two integers *l*,<=*r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*), the beginning and the end of the subsegment chosen respectively. If there are several possible answers you may output any of them. Here are example inputs and outputs for the problem: Example Input 1: 5 1 1 2 2 1 Example Output 1: 1 5 Example Input 2: 5 1 2 2 3 1 Example Output 2: 2 3 Example Input 3: 6 1 2 2 1 1 2 Example Output 3: 1 5 Now solve the problem by providing the code.
def bin_search(n,a): l = 0 r = len(a)-1 while l<=r: m = (l+r)//2 if n>a[m][0]: l = m+1 if n<a[m][0]: r = m-1 if n == a[m][0]: return m return -1 n = int(input()) a = input().split() def ke(n): return n[1] def f(n): return abs(n[2]-n[3]) cnt = {} mx = 0 for i in range(n): a[i] = int(a[i]) if a[i] in cnt: cnt[a[i]][1] += 1 cnt[a[i]][3] = i else: cnt[a[i]] = [a[i],1,i,0] for m in cnt.values(): if m[1]>mx: mx = m[1] v = [] for m in cnt.values(): if m[1]==mx: v.append(m) v.sort(key=f) print(v[0][2]+1,v[0][3]+1)
vfc_83393
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 1 2 2 1", "output": "1 5", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 2 2 3 1", "output": "2 3", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n1 2 2 1 1 2", "output": "1 5", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n1 1000000 2 1000000 3 2 1000000 1 2 1", "output": "2 7", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
388
Solve the following coding problem using the programming language python: Fox Ciel has *n* boxes in her room. They have the same size and weight, but they might have different strength. The *i*-th box can hold at most *x**i* boxes on its top (we'll call *x**i* the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than *x**i* boxes on the top of *i*-th box. What is the minimal number of piles she needs to construct? The input will be provided via standard input and looks as follows: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100). The next line contains *n* integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=≤<=100). You should write the solution as standard output as follows: Output a single integer — the minimal possible number of piles. Here are example inputs and outputs for the problem: Example Input 1: 3 0 0 10 Example Output 1: 2 Example Input 2: 5 0 1 2 3 4 Example Output 2: 1 Example Input 3: 4 0 0 0 0 Example Output 3: 4 Example Input 4: 9 0 1 0 2 0 1 1 2 10 Example Output 4: 3 Now solve the problem by providing the code.
n = int(input()) a = list(map(int, input().split())) a.sort() h = [0] * 101 for i in range(n): for j in range(101): if(a[i] >= h[j]): h[j] += 1 break c = 101 - h.count(0) print(c)
vfc_83397
{ "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\n0 0 10", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n0 1 2 3 4", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n0 0 0 0", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "9\n0 1 0 2 0 1 1 2 10", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n0", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n0 0", "output": "2", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
688
Solve the following coding problem using the programming language python: Arya has *n* opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Arya will beat all present opponents. Otherwise, if all opponents are present, then they will beat Arya. For each opponent Arya knows his schedule — whether or not he is going to present on each particular day. Tell him the maximum number of consecutive days that he will beat all present opponents. Note, that if some day there are no opponents present, Arya still considers he beats all the present opponents. The input will be provided via standard input and looks as follows: The first line of the input contains two integers *n* and *d* (1<=≤<=*n*,<=*d*<=≤<=100) — the number of opponents and the number of days, respectively. The *i*-th of the following *d* lines contains a string of length *n* consisting of characters '0' and '1'. The *j*-th character of this string is '0' if the *j*-th opponent is going to be absent on the *i*-th day. You should write the solution as standard output as follows: Print the only integer — the maximum number of consecutive days that Arya will beat all present opponents. Here are example inputs and outputs for the problem: Example Input 1: 2 2 10 00 Example Output 1: 2 Example Input 2: 4 1 0100 Example Output 2: 1 Example Input 3: 4 5 1101 1111 0110 1011 1111 Example Output 3: 2 Now solve the problem by providing the code.
n,d=map(int,input().split()) m=[] a=0 for i in range(d): l=input()[:n] if "0" in l: a=a+1 else: m.append(a) a=0 if i==d-1: m.append(a) print(max(m))
vfc_83401
{ "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\n10\n00", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 1\n0100", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 5\n1101\n1111\n0110\n1011\n1111", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2\n110\n110", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 6\n1111111111\n0100110101\n1111111111\n0000011010\n1111111111\n1111111111", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
160
Solve the following coding problem using the programming language python: Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like. Now let's imagine a typical morning in your family. You haven't woken up yet, and Mom is already going to work. She has been so hasty that she has nearly forgotten to leave the two of her darling children some money to buy lunches in the school cafeteria. She fished in the purse and found some number of coins, or to be exact, *n* coins of arbitrary values *a*1,<=*a*2,<=...,<=*a**n*. But as Mom was running out of time, she didn't split the coins for you two. So she scribbled a note asking you to split the money equally. As you woke up, you found Mom's coins and read her note. "But why split the money equally?" — you thought. After all, your twin is sleeping and he won't know anything. So you decided to act like that: pick for yourself some subset of coins so that the sum of values of your coins is strictly larger than the sum of values of the remaining coins that your twin will have. However, you correctly thought that if you take too many coins, the twin will suspect the deception. So, you've decided to stick to the following strategy to avoid suspicions: you take the minimum number of coins, whose sum of values is strictly more than the sum of values of the remaining coins. On this basis, determine what minimum number of coins you need to take to divide them in the described manner. The input will be provided via standard input and looks as follows: The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of coins. The second line contains a sequence of *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=100) — the coins' values. All numbers are separated with spaces. You should write the solution as standard output as follows: In the single line print the single number — the minimum needed number of coins. Here are example inputs and outputs for the problem: Example Input 1: 2 3 3 Example Output 1: 2 Example Input 2: 3 2 1 2 Example Output 2: 2 Now solve the problem by providing the code.
n = int(input()) coins = list(map(int, input().split())) coins.sort(reverse=True) total_sum = sum(coins) my_sum = 0 count = 0 for i in range(n): my_sum += coins[i] count += 1 if my_sum > total_sum - my_sum: break print(count)
vfc_83405
{ "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\n3 3", "output": "2", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
27
Solve the following coding problem using the programming language python: «Polygon» is a system which allows to create programming tasks in a simple and professional way. When you add a test to the problem, the corresponding form asks you for the test index. As in most cases it is clear which index the next test will have, the system suggests the default value of the index. It is calculated as the smallest positive integer which is not used as an index for some previously added test. You are to implement this feature. Create a program which determines the default index of the next test, given the indexes of the previously added tests. The input will be provided via standard input and looks as follows: The first line contains one integer *n* (1<=≤<=*n*<=≤<=3000) — the amount of previously added tests. The second line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=3000) — indexes of these tests. You should write the solution as standard output as follows: Output the required default value for the next test index. Here are example inputs and outputs for the problem: Example Input 1: 3 1 7 2 Example Output 1: 3 Now solve the problem by providing the code.
def main(): n = int(input()) arr = list(map(int, input().split())) count = 1 arr.sort() for i in arr: if i != count: print(count) exit() count += 1 print(count) main()
vfc_83409
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n1", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2 1", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n3 4 1", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n6 4 3 5", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
916
Solve the following coding problem using the programming language python: Jamie loves sleeping. One day, he decides that he needs to wake up at exactly *hh*:<=*mm*. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky time. He will then press the snooze button every *x* minutes until *hh*:<=*mm* is reached, and only then he will wake up. He wants to know what is the smallest number of times he needs to press the snooze button. A time is considered lucky if it contains a digit '7'. For example, 13:<=07 and 17:<=27 are lucky, while 00:<=48 and 21:<=34 are not lucky. Note that it is not necessary that the time set for the alarm and the wake-up time are on the same day. It is guaranteed that there is a lucky time Jamie can set so that he can wake at *hh*:<=*mm*. Formally, find the smallest possible non-negative integer *y* such that the time representation of the time *x*·*y* minutes before *hh*:<=*mm* contains the digit '7'. Jamie uses 24-hours clock, so after 23:<=59 comes 00:<=00. The input will be provided via standard input and looks as follows: The first line contains a single integer *x* (1<=≤<=*x*<=≤<=60). The second line contains two two-digit integers, *hh* and *mm* (00<=≤<=*hh*<=≤<=23,<=00<=≤<=*mm*<=≤<=59). You should write the solution as standard output as follows: Print the minimum number of times he needs to press the button. Here are example inputs and outputs for the problem: Example Input 1: 3 11 23 Example Output 1: 2 Example Input 2: 5 01 07 Example Output 2: 0 Now solve the problem by providing the code.
import datetime n = int(input()) a , b = input().split() x = datetime.timedelta(hours= int(a) , minutes=int(b)) c = 0 while '7' not in str(x): x -= datetime.timedelta(hours= 0 , minutes=n) c +=1 print(c)
vfc_83413
{ "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\n11 23", "output": "2", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
821
Solve the following coding problem using the programming language python: Okabe needs to renovate the Future Gadget Laboratory after he tried doing some crazy experiments! The lab is represented as an *n* by *n* square grid of integers. A good lab is defined as a lab in which every number not equal to 1 can be expressed as the sum of a number in the same row and a number in the same column. In other words, for every *x*,<=*y* such that 1<=≤<=*x*,<=*y*<=≤<=*n* and *a**x*,<=*y*<=≠<=1, there should exist two indices *s* and *t* so that *a**x*,<=*y*<==<=*a**x*,<=*s*<=+<=*a**t*,<=*y*, where *a**i*,<=*j* denotes the integer in *i*-th row and *j*-th column. Help Okabe determine whether a given lab is good! The input will be provided via standard input and looks as follows: The first line of input contains the integer *n* (1<=≤<=*n*<=≤<=50) — the size of the lab. The next *n* lines contain *n* space-separated integers denoting a row of the grid. The *j*-th integer in the *i*-th row is *a**i*,<=*j* (1<=≤<=*a**i*,<=*j*<=≤<=105). You should write the solution as standard output as follows: Print "Yes" if the given lab is good and "No" otherwise. You can output each letter in upper or lower case. Here are example inputs and outputs for the problem: Example Input 1: 3 1 1 2 2 3 1 6 4 1 Example Output 1: Yes Example Input 2: 3 1 5 2 1 1 1 1 2 3 Example Output 2: No Now solve the problem by providing the code.
n=int(input()) l=[list(map(int,input().split())) for _ in range(n)] flag=0 for i in range(n): for j in range(n): if( l[i][j]==1 )or any(l[i][j]-l[x][j] in l[i] for x in range(n)): continue else: print('No') flag=1 break if(flag==1): break else: print('Yes')
vfc_83417
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "3000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 1 2\n2 3 1\n6 4 1", "output": "Yes", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
221
Solve the following coding problem using the programming language python: The Little Elephant enjoys recursive functions. This time he enjoys the sorting function. Let *a* is a permutation of an integers from 1 to *n*, inclusive, and *a**i* denotes the *i*-th element of the permutation. The Little Elephant's recursive function *f*(*x*), that sorts the first *x* permutation's elements, works as follows: - If *x*<==<=1, exit the function. - Otherwise, call *f*(*x*<=-<=1), and then make *swap*(*a**x*<=-<=1,<=*a**x*) (swap the *x*-th and (*x*<=-<=1)-th elements of *a*). The Little Elephant's teacher believes that this function does not work correctly. But that-be do not get an F, the Little Elephant wants to show the performance of its function. Help him, find a permutation of numbers from 1 to *n*, such that after performing the Little Elephant's function (that is call *f*(*n*)), the permutation will be sorted in ascending order. The input will be provided via standard input and looks as follows: A single line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the size of permutation. You should write the solution as standard output as follows: In a single line print *n* distinct integers from 1 to *n* — the required permutation. Numbers in a line should be separated by spaces. It is guaranteed that the answer exists. Here are example inputs and outputs for the problem: Example Input 1: 1 Example Output 1: 1 Example Input 2: 2 Example Output 2: 2 1 Now solve the problem by providing the code.
# Bismillahir Rahmanir Rahim # Abu Hurayra - Handle: HurayraIIT import sys import math def mp(): return map(int, sys.stdin.readline().split()) def rs(): return sys.stdin.readline().rstrip() def ri(): return int(sys.stdin.readline()) def ria(): return list(map(int, sys.stdin.readline().split())) def ws(s): sys.stdout.write(s + '\n') def wi(n): sys.stdout.write(str(n) + '\n') def wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\n') #a = list(map(int, input().split())) def main(): n = ri() if n==1: print("1") return elif n==2: print("2 1") return print(n, end=" ") for i in range(1,n): print(i, end=" ") print() if __name__ == '__main__': t = 1 for _ in range(t): main()
vfc_83421
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1", "output": "1 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "2", "output": "2 1 ", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
342
Solve the following coding problem using the programming language python: A girl named Xenia has a cupboard that looks like an arc from ahead. The arc is made of a semicircle with radius *r* (the cupboard's top) and two walls of height *h* (the cupboard's sides). The cupboard's depth is *r*, that is, it looks like a rectangle with base *r* and height *h*<=+<=*r* from the sides. The figure below shows what the cupboard looks like (the front view is on the left, the side view is on the right). Xenia got lots of balloons for her birthday. The girl hates the mess, so she wants to store the balloons in the cupboard. Luckily, each balloon is a sphere with radius . Help Xenia calculate the maximum number of balloons she can put in her cupboard. You can say that a balloon is in the cupboard if you can't see any part of the balloon on the left or right view. The balloons in the cupboard can touch each other. It is not allowed to squeeze the balloons or deform them in any way. You can assume that the cupboard's walls are negligibly thin. The input will be provided via standard input and looks as follows: The single line contains two integers *r*,<=*h* (1<=≤<=*r*,<=*h*<=≤<=107). You should write the solution as standard output as follows: Print a single integer — the maximum number of balloons Xenia can put in the cupboard. Here are example inputs and outputs for the problem: Example Input 1: 1 1 Example Output 1: 3 Example Input 2: 1 2 Example Output 2: 5 Example Input 3: 2 1 Example Output 3: 2 Now solve the problem by providing the code.
r, h = map(int, input().split()) a = 1 + 2 * h // r if h % r >=3 ** 0.5 * r / 2: a += 1 print(a)
vfc_83425
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 1", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 2", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 1", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
887
Solve the following coding problem using the programming language python: Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills. Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some digits in such a way, that remaining number is a representation of some positive integer, divisible by 64, in the binary numerical system. The input will be provided via standard input and looks as follows: In the only line given a non-empty binary string *s* with length up to 100. You should write the solution as standard output as follows: Print «yes» (without quotes) if it's possible to remove digits required way and «no» otherwise. Here are example inputs and outputs for the problem: Example Input 1: 100010001 Example Output 1: yes Example Input 2: 100 Example Output 2: no Now solve the problem by providing the code.
a=int(input()) s=str(a) count=0 for i in s: if i=="0": count+=1 if (count>=6): print("yes") else: print("no")
vfc_83429
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "100010001", "output": "yes", "type": "stdin_stdout" }, { "fn_name": null, "input": "100", "output": "no", "type": "stdin_stdout" }, { "fn_name": null, "input": "0000001000000", "output": "yes", "type": "stdin_stdout" }, { "fn_name": null, "input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "output": "no", "type": "stdin_stdout" }, { "fn_name": null, "input": "1111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111111111", "output": "no", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
837
Solve the following coding problem using the programming language python: You are given a text of single-space separated words, consisting of small and capital Latin letters. Volume of the word is number of capital letters in the word. Volume of the text is maximum volume of all words in the text. Calculate the volume of the given text. The input will be provided via standard input and looks as follows: The first line contains one integer number *n* (1<=≤<=*n*<=≤<=200) — length of the text. The second line contains text of single-space separated words *s*1,<=*s*2,<=...,<=*s**i*, consisting only of small and capital Latin letters. You should write the solution as standard output as follows: Print one integer number — volume of text. Here are example inputs and outputs for the problem: Example Input 1: 7 NonZERO Example Output 1: 5 Example Input 2: 24 this is zero answer text Example Output 2: 0 Example Input 3: 24 Harbour Space University Example Output 3: 1 Now solve the problem by providing the code.
a = set() a.add(0) n = int(input()) s = input().split() c = 0 for i in s: for j in i: if j.isupper(): c+=1 a.add(c) c = 0 a = sorted(a) print(a[-1])
vfc_83433
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\nNonZERO", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "24\nthis is zero answer text", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "24\nHarbour Space University", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\nWM", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "200\nLBmJKQLCKUgtTxMoDsEerwvLOXsxASSydOqWyULsRcjMYDWdDCgaDvBfATIWPVSXlbcCLHPYahhxMEYUiaxoCebghJqvmRnaNHYTKLeOiaLDnATPZAOgSNfBzaxLymTGjfzvTegbXsAthTxyDTcmBUkqyGlVGZhoazQzVSoKbTFcCRvYsgSCwjGMxBfWEwMHuagTBxkz", "output": "105", "type": "stdin_stdout" }, { "fn_name": null, "input": "199\no A r v H e J q k J k v w Q F p O R y R Z o a K R L Z E H t X y X N y y p b x B m r R S q i A x V S u i c L y M n N X c C W Z m S j e w C w T r I S X T D F l w o k f t X u n W w p Z r A k I Y E h s g", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
578
Solve the following coding problem using the programming language python: You are given *n* numbers *a*1,<=*a*2,<=...,<=*a**n*. You can perform at most *k* operations. For each operation you can multiply one of the numbers by *x*. We want to make as large as possible, where denotes the bitwise OR. Find the maximum possible value of after performing at most *k* operations optimally. The input will be provided via standard input and looks as follows: The first line contains three integers *n*, *k* and *x* (1<=≤<=*n*<=≤<=200<=000, 1<=≤<=*k*<=≤<=10, 2<=≤<=*x*<=≤<=8). The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109). You should write the solution as standard output as follows: Output the maximum value of a bitwise OR of sequence elements after performing operations. Here are example inputs and outputs for the problem: Example Input 1: 3 1 2 1 1 1 Example Output 1: 3 Example Input 2: 4 2 3 1 2 4 8 Example Output 2: 79 Now solve the problem by providing the code.
n, k, x = map(int, input().split()) x = x**k left_or = [None]*(n) right_or = [None]*(n) a = list(map(int, input().split())) current_or = 0 for i in range(n): current_or |= a[i] left_or[i] = current_or current_or = 0 for i in range(n-1, -1, -1): current_or |= a[i] right_or[i] = current_or best_res = 0 for i in range(n): res = a[i]*x if i != 0: res |= left_or[i-1] if i != n-1: res |= right_or[i+1] best_res = max(res, best_res) print(best_res)
vfc_83437
{ "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 1 2\n1 1 1", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 2 3\n1 2 4 8", "output": "79", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
569
Solve the following coding problem using the programming language python: Companies always have a lot of equipment, furniture and other things. All of them should be tracked. To do this, there is an inventory number assigned with each item. It is much easier to create a database by using those numbers and keep the track of everything. During an audit, you were surprised to find out that the items are not numbered sequentially, and some items even share the same inventory number! There is an urgent need to fix it. You have chosen to make the numbers of the items sequential, starting with 1. Changing a number is quite a time-consuming process, and you would like to make maximum use of the current numbering. You have been given information on current inventory numbers for *n* items in the company. Renumber items so that their inventory numbers form a permutation of numbers from 1 to *n* by changing the number of as few items as possible. Let us remind you that a set of *n* numbers forms a permutation if all the numbers are in the range from 1 to *n*, and no two numbers are equal. The input will be provided via standard input and looks as follows: The first line contains a single integer *n* — the number of items (1<=≤<=*n*<=≤<=105). The second line contains *n* numbers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105) — the initial inventory numbers of the items. You should write the solution as standard output as follows: Print *n* numbers — the final inventory numbers of the items in the order they occur in the input. If there are multiple possible answers, you may print any of them. Here are example inputs and outputs for the problem: Example Input 1: 3 1 3 2 Example Output 1: 1 3 2 Example Input 2: 4 2 2 3 3 Example Output 2: 2 1 3 4 Example Input 3: 1 2 Example Output 3: 1 Now solve the problem by providing the code.
n = int(input()) a = list(map(int, input().split())) s = set(a) k = set(range(1, n+1)) need = k-s vis = set() for i in range(n): if a[i] in vis: a[i] = need.pop() else: if a[i] not in k: a[i] = need.pop() vis.add(a[i]) else: vis.add(a[i]) print(*a)
vfc_83445
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 3 2", "output": "1 3 2 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n2 2 3 3", "output": "2 1 3 4 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n2", "output": "1 ", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
629
Solve the following coding problem using the programming language python: Door's family is going celebrate Famil Doors's birthday party. They love Famil Door so they are planning to make his birthday cake weird! The cake is a *n*<=×<=*n* square consisting of equal squares with side length 1. Each square is either empty or consists of a single chocolate. They bought the cake and randomly started to put the chocolates on the cake. The value of Famil Door's happiness will be equal to the number of pairs of cells with chocolates that are in the same row or in the same column of the cake. Famil Doors's family is wondering what is the amount of happiness of Famil going to be? Please, note that any pair can be counted no more than once, as two different cells can't share both the same row and the same column. The input will be provided via standard input and looks as follows: In the first line of the input, you are given a single integer *n* (1<=≤<=*n*<=≤<=100) — the length of the side of the cake. Then follow *n* lines, each containing *n* characters. Empty cells are denoted with '.', while cells that contain chocolates are denoted by 'C'. You should write the solution as standard output as follows: Print the value of Famil Door's happiness, i.e. the number of pairs of chocolate pieces that share the same row or the same column. Here are example inputs and outputs for the problem: Example Input 1: 3 .CC C.. C.C Example Output 1: 4 Example Input 2: 4 CC.. C..C .CC. .CC. Example Output 2: 9 Now solve the problem by providing the code.
import math size = int(input()) matrix = [] def ncr(x): if x>=2: y = math.factorial(x) y = y/((math.factorial(x-2))*2) return y else: return 0 for i in range(0,size): array = list(str(input())) matrix.append(array) rows = 0 cols = 0 for i in range(0,size): buffer = 0 for j in range(0,size): if matrix[i][j] == 'C': buffer += 1 y = ncr(buffer) rows += y for i in range(0,size): buffer = 0 for j in range(0,size): if matrix[j][i] == 'C': buffer += 1 y = ncr(buffer) cols += y print(int(cols)+int(rows))
vfc_83449
{ "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\n.CC\nC..\nC.C", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\nCC..\nC..C\n.CC.\n.CC.", "output": "9", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n.CCCC\nCCCCC\n.CCC.\nCC...\n.CC.C", "output": "46", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n.CC..CC\nCC.C..C\nC.C..C.\nC...C.C\nCCC.CCC\n.CC...C\n.C.CCC.", "output": "84", "type": "stdin_stdout" }, { "fn_name": null, "input": "8\n..C....C\nC.CCC.CC\n.C..C.CC\nCC......\nC..C..CC\nC.C...C.\nC.C..C..\nC...C.C.", "output": "80", "type": "stdin_stdout" }, { "fn_name": null, "input": "9\n.C...CCCC\nC.CCCC...\n....C..CC\n.CC.CCC..\n.C.C..CC.\nC...C.CCC\nCCC.C...C\nCCCC....C\n..C..C..C", "output": "144", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
205
Solve the following coding problem using the programming language python: The Little Elephant loves Ukraine very much. Most of all he loves town Rozdol (ukr. "Rozdil"). However, Rozdil is dangerous to settle, so the Little Elephant wants to go to some other town. The Little Elephant doesn't like to spend much time on travelling, so for his journey he will choose a town that needs minimum time to travel to. If there are multiple such cities, then the Little Elephant won't go anywhere. For each town except for Rozdil you know the time needed to travel to this town. Find the town the Little Elephant will go to or print "Still Rozdil", if he stays in Rozdil. The input will be provided via standard input and looks as follows: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of cities. The next line contains *n* integers, separated by single spaces: the *i*-th integer represents the time needed to go from town Rozdil to the *i*-th town. The time values are positive integers, not exceeding 109. You can consider the cities numbered from 1 to *n*, inclusive. Rozdil is not among the numbered cities. You should write the solution as standard output as follows: Print the answer on a single line — the number of the town the Little Elephant will go to. If there are multiple cities with minimum travel time, print "Still Rozdil" (without the quotes). Here are example inputs and outputs for the problem: Example Input 1: 2 7 4 Example Output 1: 2 Example Input 2: 7 7 4 47 100 4 9 12 Example Output 2: Still Rozdil Now solve the problem by providing the code.
n=int(input()) l=input().split(" ") l=[int(x) for x in l] square_dict = {n: 1 for n in l} s={} minNum=min(l) for i in l: # for j in range(len(l[i])): if i in s: key=i s[key]=s.setdefault(key, 0) + 1 else: key=i s[key]=s.setdefault(key, 1) k=minNum if(s.get(k)>1): print("Still Rozdil") else: print(l.index(minNum)+1)
vfc_83453
{ "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\n7 4", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n7 4 47 100 4 9 12", "output": "Still Rozdil", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n47", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1000000000 1000000000", "output": "Still Rozdil", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
681
Solve the following coding problem using the programming language python: Codeforces user' handle color depends on his rating — it is red if his rating is greater or equal to 2400; it is orange if his rating is less than 2400 but greater or equal to 2200, etc. Each time participant takes part in a rated contest, his rating is changed depending on his performance. Anton wants the color of his handle to become red. He considers his performance in the rated contest to be good if he outscored some participant, whose handle was colored red before the contest and his rating has increased after it. Anton has written a program that analyses contest results and determines whether he performed good or not. Are you able to do the same? 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) — the number of participants Anton has outscored in this contest . The next *n* lines describe participants results: the *i*-th of them consists of a participant handle *name**i* and two integers *before**i* and *after**i* (<=-<=4000<=≤<=*before**i*,<=*after**i*<=≤<=4000) — participant's rating before and after the contest, respectively. Each handle is a non-empty string, consisting of no more than 10 characters, which might be lowercase and uppercase English letters, digits, characters «_» and «-» characters. It is guaranteed that all handles are distinct. You should write the solution as standard output as follows: Print «YES» (quotes for clarity), if Anton has performed good in the contest and «NO» (quotes for clarity) otherwise. Here are example inputs and outputs for the problem: Example Input 1: 3 Burunduk1 2526 2537 BudAlNik 2084 2214 subscriber 2833 2749 Example Output 1: YES Example Input 2: 3 Applejack 2400 2400 Fluttershy 2390 2431 Pinkie_Pie -2500 -2450 Example Output 2: NO Now solve the problem by providing the code.
n = int(input()) flag = False for i in range(n): name, before, after = map(str, input().split()) if flag is False: if int(before) >= 2400 and int(after) > int(before): flag = True continue print('YES' if flag is True else 'NO')
vfc_83457
{ "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\nBurunduk1 2526 2537\nBudAlNik 2084 2214\nsubscriber 2833 2749", "output": "YES", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
994
Solve the following coding problem using the programming language python: You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits. Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subsequence of the sequence you have that only contains digits with fingerprints on the corresponding keys. Find such code. The input will be provided via standard input and looks as follows: The first line contains two integers $n$ and $m$ ($1 \le n, m \le 10$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints. The next line contains $n$ distinct space-separated integers $x_1, x_2, \ldots, x_n$ ($0 \le x_i \le 9$) representing the sequence. The next line contains $m$ distinct space-separated integers $y_1, y_2, \ldots, y_m$ ($0 \le y_i \le 9$) — the keys with fingerprints. You should write the solution as standard output as follows: In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable. Here are example inputs and outputs for the problem: Example Input 1: 7 3 3 5 7 1 6 2 8 1 2 7 Example Output 1: 7 1 2 Example Input 2: 4 4 3 4 1 0 0 1 7 9 Example Output 2: 1 0 Now solve the problem by providing the code.
n,m=[int(x) for x in input().split()] num=[int(x) for x in input().split()] op=[int(x) for x in input().split()] fin=[] for x in num: if x in op: fin.append(str(x)) print(' '.join(fin))
vfc_83461
{ "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 3\n3 5 7 1 6 2 8\n1 2 7", "output": "7 1 2", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 4\n3 4 1 0\n0 1 7 9", "output": "1 0", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
967
Solve the following coding problem using the programming language python: These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $1$ minute. He was asked to insert one takeoff in the schedule. The takeoff takes $1$ minute itself, but for safety reasons there should be a time space between the takeoff and any landing of at least $s$ minutes from both sides. Find the earliest time when Arkady can insert the takeoff. The input will be provided via standard input and looks as follows: The first line of input contains two integers $n$ and $s$ ($1 \le n \le 100$, $1 \le s \le 60$) — the number of landings on the schedule and the minimum allowed time (in minutes) between a landing and a takeoff. Each of next $n$ lines contains two integers $h$ and $m$ ($0 \le h \le 23$, $0 \le m \le 59$) — the time, in hours and minutes, when a plane will land, starting from current moment (i. e. the current time is $0$ $0$). These times are given in increasing order. You should write the solution as standard output as follows: Print two integers $h$ and $m$ — the hour and the minute from the current moment of the earliest time Arkady can insert the takeoff. Here are example inputs and outputs for the problem: Example Input 1: 6 60 0 0 1 20 3 21 5 0 19 30 23 40 Example Output 1: 6 1 Example Input 2: 16 50 0 30 1 20 3 0 4 30 6 10 7 50 9 30 11 10 12 50 14 30 16 10 17 50 19 30 21 10 22 50 23 59 Example Output 2: 24 50 Example Input 3: 3 17 0 30 1 0 12 0 Example Output 3: 0 0 Now solve the problem by providing the code.
def next(h1, m1, minutes): return (h1 + (m1 + minutes) // 60, (m1 + minutes) % 60) n, s = map(int, input().split()) schedule = [] for i in range(n): schedule.append(tuple(map(int, input().split()))) if schedule[0][0] * 60 + schedule[0][1] >= s + 1: print('0 0') else: for i in range(1, len(schedule)): if (schedule[i][0] - schedule[i-1][0]) * 60 + (schedule[i][1] - schedule[i-1][1]) >= 2 * s + 2: res = next(schedule[i-1][0], schedule[i-1][1], s + 1) print(str(res[0]) + ' ' + str(res[1])) break; else: res = next(schedule[i][0], schedule[i][1], s + 1) print(str(res[0]) + ' ' + str(res[1]))
vfc_83465
{ "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 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40", "output": "6 1", "type": "stdin_stdout" }, { "fn_name": null, "input": "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59", "output": "24 50", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 17\n0 30\n1 0\n12 0", "output": "0 0", "type": "stdin_stdout" }, { "fn_name": null, "input": "24 60\n0 21\n2 21\n2 46\n3 17\n4 15\n5 43\n6 41\n7 50\n8 21\n9 8\n10 31\n10 45\n12 30\n14 8\n14 29\n14 32\n14 52\n15 16\n16 7\n16 52\n18 44\n20 25\n21 13\n22 7", "output": "23 8", "type": "stdin_stdout" }, { "fn_name": null, "input": "20 60\n0 9\n0 19\n0 57\n2 42\n3 46\n3 47\n5 46\n8 1\n9 28\n9 41\n10 54\n12 52\n13 0\n14 49\n17 28\n17 39\n19 34\n20 52\n21 35\n23 22", "output": "6 47", "type": "stdin_stdout" }, { "fn_name": null, "input": "57 20\n0 2\n0 31\n1 9\n1 42\n1 58\n2 4\n2 35\n2 49\n3 20\n3 46\n4 23\n4 52\n5 5\n5 39\n6 7\n6 48\n6 59\n7 8\n7 35\n8 10\n8 46\n8 53\n9 19\n9 33\n9 43\n10 18\n10 42\n11 0\n11 26\n12 3\n12 5\n12 30\n13 1\n13 38\n14 13\n14 54\n15 31\n16 5\n16 44\n17 18\n17 30\n17 58\n18 10\n18 34\n19 13\n19 49\n19 50\n19 59\n20 17\n20 23\n20 40\n21 18\n21 57\n22 31\n22 42\n22 56\n23 37", "output": "23 58", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
596
Solve the following coding problem using the programming language python: Wilbur the pig is tinkering with arrays again. He has the array *a*1,<=*a*2,<=...,<=*a**n* initially consisting of *n* zeros. At one step, he can choose any index *i* and either add 1 to all elements *a**i*,<=*a**i*<=+<=1,<=... ,<=*a**n* or subtract 1 from all elements *a**i*,<=*a**i*<=+<=1,<=...,<=*a**n*. His goal is to end up with the array *b*1,<=*b*2,<=...,<=*b**n*. Of course, Wilbur wants to achieve this goal in the minimum number of steps and asks you to compute this value. The input will be provided via standard input and looks as follows: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the length of the array *a**i*. Initially *a**i*<==<=0 for every position *i*, so this array is not given in the input. The second line of the input contains *n* integers *b*1,<=*b*2,<=...,<=*b**n* (<=-<=109<=≤<=*b**i*<=≤<=109). You should write the solution as standard output as follows: Print the minimum number of steps that Wilbur needs to make in order to achieve *a**i*<==<=*b**i* for all *i*. Here are example inputs and outputs for the problem: Example Input 1: 5 1 2 3 4 5 Example Output 1: 5 Example Input 2: 4 1 2 2 1 Example Output 2: 3 Now solve the problem by providing the code.
a=int(input()) x=list(map(int,input().split())) t=abs(x[0]) if a>1: for i in range(1,a): t+=abs(x[i-1]-x[i]) print(t)
vfc_83469
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 2 3 4 5", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 2 2 1", "output": "3", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
984
Solve the following coding problem using the programming language python: Two players play a game. Initially there are $n$ integers $a_1, a_2, \ldots, a_n$ written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. $n - 1$ turns are made. The first player makes the first move, then players alternate turns. The first player wants to minimize the last number that would be left on the board, while the second player wants to maximize it. You want to know what number will be left on the board after $n - 1$ turns if both players make optimal moves. The input will be provided via standard input and looks as follows: The first line contains one integer $n$ ($1 \le n \le 1000$) — the number of numbers on the board. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^6$). You should write the solution as standard output as follows: Print one number that will be left on the board. Here are example inputs and outputs for the problem: Example Input 1: 3 2 1 3 Example Output 1: 2 Example Input 2: 3 2 2 2 Example Output 2: 2 Now solve the problem by providing the code.
n = int(input()) l = list(map(int,input().split())) l.sort() for i in range(n-1): if i % 2 == 0: l.pop() else: l.pop(0) for i in l: print(i)
vfc_83473
{ "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 1 3", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2 2 2", "output": "2", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
389
Solve the following coding problem using the programming language python: Fox Ciel has a board with *n* rows and *n* columns. So, the board consists of *n*<=×<=*n* cells. Each cell contains either a symbol '.', or a symbol '#'. A cross on the board is a connected set of exactly five cells of the board that looks like a cross. The picture below shows how it looks. Ciel wants to draw several (may be zero) crosses on the board. Each cross must cover exactly five cells with symbols '#', and any cell with symbol '#' must belong to some cross. No two crosses can share a cell. Please, tell Ciel if she can draw the crosses in the described way. The input will be provided via standard input and looks as follows: The first line contains an integer *n* (3<=≤<=*n*<=≤<=100) — the size of the board. Each of the next *n* lines describes one row of the board. The *i*-th line describes the *i*-th row of the board and consists of *n* characters. Each character is either a symbol '.', or a symbol '#'. You should write the solution as standard output as follows: Output a single line with "YES" if Ciel can draw the crosses in the described way. Otherwise output a single line with "NO". Here are example inputs and outputs for the problem: Example Input 1: 5 .#... ####. .#### ...#. ..... Example Output 1: YES Example Input 2: 4 #### #### #### #### Example Output 2: NO Example Input 3: 6 .#.... ####.. .####. .#.##. ###### .#..#. Example Output 3: YES Example Input 4: 6 .#..#. ###### .####. .####. ###### .#..#. Example Output 4: NO Example Input 5: 3 ... ... ... Example Output 5: YES Now solve the problem by providing the code.
def check(a, b, n): return a>=0 and b>=0 and a<n and b<n def solve(): n = int(input()) ar = [] for i in range(n): ar.append(input()) cross = [[0]*n for _ in range(n)] addc = [(1, 0), (2, 0), (1, -1), (1, 1)] for i in range(n): for j in range(n): if ar[i][j] == "#" and cross[i][j] == 0: cross[i][j] = 1 for a, b in addc: if check(i+a, j+b, n): #print(ar[i+a][j+b], cross[i+a][j+b]) if ar[i+a][j+b] == "#" and cross[i+a][j+b] == 0: cross[i+a][j+b] = 1 else: print("NO") return else: print("NO") return print("YES") solve()
vfc_83477
{ "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\n####\n####\n####\n####", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n.#....\n####..\n.####.\n.#.##.\n######\n.#..#.", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n.#..#.\n######\n.####.\n.####.\n######\n.#..#.", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n.....\n.#...\n####.\n.####\n...#.", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n#....\n###..\n.###.\n..##.\n..##.", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n....#...#.\n.#.###.###\n#####.#.#.\n.#######..\n.#.##.#.#.\n######.###\n.#..#.#.#.\n.#..#####.\n##########\n.#..#...#.", "output": "YES", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
180
Solve the following coding problem using the programming language python: Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them were uppercase. Patrick believes that a message is fancy if any uppercase letter stands to the left of any lowercase one. In other words, this rule describes the strings where first go zero or more uppercase letters, and then — zero or more lowercase letters. To make the message fancy, Patrick can erase some letter and add the same letter in the same place in the opposite case (that is, he can replace an uppercase letter with the lowercase one and vice versa). Patrick got interested in the following question: what minimum number of actions do we need to make a message fancy? Changing a letter's case in the message counts as one action. Patrick cannot perform any other actions. The input will be provided via standard input and looks as follows: The only line of the input contains a non-empty string consisting of uppercase and lowercase letters. The string's length does not exceed 105. You should write the solution as standard output as follows: Print a single number — the least number of actions needed to make the message fancy. Here are example inputs and outputs for the problem: Example Input 1: PRuvetSTAaYA Example Output 1: 5 Example Input 2: OYPROSTIYAOPECHATALSYAPRIVETSTASYA Example Output 2: 0 Example Input 3: helloworld Example Output 3: 0 Now solve the problem by providing the code.
s=input() mina=c=0 for i in range(len(s)): if ord(s[i])>=97: mina=min(c+1,mina) c+=1 else: mina=min(mina+1,c) print(mina)
vfc_83481
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "PRuvetSTAaYA", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "OYPROSTIYAOPECHATALSYAPRIVETSTASYA", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "helloworld", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "P", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "t", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "XdJ", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
631
Solve the following coding problem using the programming language python: Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following problem. We define function *f*(*x*,<=*l*,<=*r*) as a bitwise OR of integers *x**l*,<=*x**l*<=+<=1,<=...,<=*x**r*, where *x**i* is the *i*-th element of the array *x*. You are given two arrays *a* and *b* of length *n*. You need to determine the maximum value of sum *f*(*a*,<=*l*,<=*r*)<=+<=*f*(*b*,<=*l*,<=*r*) among all possible 1<=≤<=*l*<=≤<=*r*<=≤<=*n*. The input will be provided via standard input and looks as follows: The first line of the input contains a single integer *n* (1<=≤<=*n*<=≤<=1000) — the length of the arrays. The second line contains *n* integers *a**i* (0<=≤<=*a**i*<=≤<=109). The third line contains *n* integers *b**i* (0<=≤<=*b**i*<=≤<=109). You should write the solution as standard output as follows: Print a single integer — the maximum value of sum *f*(*a*,<=*l*,<=*r*)<=+<=*f*(*b*,<=*l*,<=*r*) among all possible 1<=≤<=*l*<=≤<=*r*<=≤<=*n*. Here are example inputs and outputs for the problem: Example Input 1: 5 1 2 4 3 2 2 3 3 12 1 Example Output 1: 22 Example Input 2: 10 13 2 7 11 8 4 9 8 5 1 5 7 18 9 2 3 0 11 8 6 Example Output 2: 46 Now solve the problem by providing the code.
n = int(input()) a = input().split() b = input().split() or_a = 0 or_b = 0 for i in range(n): or_a |= int(a[i]) or_b |= int(b[i]) print(or_a + or_b)
vfc_83485
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 2 4 3 2\n2 3 3 12 1", "output": "22", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6", "output": "46", "type": "stdin_stdout" }, { "fn_name": null, "input": "25\n12 30 38 109 81 124 80 33 38 48 29 78 96 48 96 27 80 77 102 65 80 113 31 118 35\n25 64 95 13 12 6 111 80 85 16 61 119 23 65 73 65 20 95 124 18 28 79 125 106 116", "output": "254", "type": "stdin_stdout" }, { "fn_name": null, "input": "20\n64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64\n64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64 64", "output": "128", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
883
Solve the following coding problem using the programming language python: Polycarp takes part in a quadcopter competition. According to the rules a flying robot should: - start the race from some point of a field, - go around the flag, - close cycle returning back to the starting point. Polycarp knows the coordinates of the starting point (*x*1,<=*y*1) and the coordinates of the point where the flag is situated (*x*2,<=*y*2). Polycarp’s quadcopter can fly only parallel to the sides of the field each tick changing exactly one coordinate by 1. It means that in one tick the quadcopter can fly from the point (*x*,<=*y*) to any of four points: (*x*<=-<=1,<=*y*), (*x*<=+<=1,<=*y*), (*x*,<=*y*<=-<=1) or (*x*,<=*y*<=+<=1). Thus the quadcopter path is a closed cycle starting and finishing in (*x*1,<=*y*1) and containing the point (*x*2,<=*y*2) strictly inside. What is the minimal length of the quadcopter path? The input will be provided via standard input and looks as follows: The first line contains two integer numbers *x*1 and *y*1 (<=-<=100<=≤<=*x*1,<=*y*1<=≤<=100) — coordinates of the quadcopter starting (and finishing) point. The second line contains two integer numbers *x*2 and *y*2 (<=-<=100<=≤<=*x*2,<=*y*2<=≤<=100) — coordinates of the flag. It is guaranteed that the quadcopter starting point and the flag do not coincide. You should write the solution as standard output as follows: Print the length of minimal path of the quadcopter to surround the flag and return back. Here are example inputs and outputs for the problem: Example Input 1: 1 5 5 2 Example Output 1: 18 Example Input 2: 0 1 0 0 Example Output 2: 8 Now solve the problem by providing the code.
x1, y1 = map(int, input().split()) x2, y2 = map(int, input().split()) a, b = abs(x2-x1), abs(y2-y1) if a == 0: print(4 + 2 * (b + 1)) elif b == 0: print(2 * (a + 1) + 4) else: print(2*(a+1)+2*(b+1))
vfc_83489
{ "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 5\n5 2", "output": "18", "type": "stdin_stdout" }, { "fn_name": null, "input": "0 1\n0 0", "output": "8", "type": "stdin_stdout" }, { "fn_name": null, "input": "-100 -100\n100 100", "output": "804", "type": "stdin_stdout" }, { "fn_name": null, "input": "-100 -100\n-100 100", "output": "406", "type": "stdin_stdout" }, { "fn_name": null, "input": "-100 -100\n100 -100", "output": "406", "type": "stdin_stdout" }, { "fn_name": null, "input": "100 -100\n-100 -100", "output": "406", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
109
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. Petya wonders eagerly what minimum lucky number has the sum of digits equal to *n*. Help him cope with the task. The input will be provided via standard input and looks as follows: The single line contains an integer *n* (1<=≤<=*n*<=≤<=106) — the sum of digits of the required lucky number. You should write the solution as standard output as follows: Print on the single line the result — the minimum lucky number, whose sum of digits equals *n*. If such number does not exist, print -1. Here are example inputs and outputs for the problem: Example Input 1: 11 Example Output 1: 47 Example Input 2: 10 Example Output 2: -1 Now solve the problem by providing the code.
a=int(input()) for i in range(a): for x in range(a): if 4*i+7*x==a: print('4'*i+'7'*x) exit() print(-1)
vfc_83497
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "11", "output": "47", "type": "stdin_stdout" }, { "fn_name": null, "input": "10", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "64", "output": "4477777777", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
722
Solve the following coding problem using the programming language python: You are given a text consisting of *n* lines. Each line contains some space-separated words, consisting of lowercase English letters. We define a syllable as a string that contains exactly one vowel and any arbitrary number (possibly none) of consonants. In English alphabet following letters are considered to be vowels: 'a', 'e', 'i', 'o', 'u' and 'y'. Each word of the text that contains at least one vowel can be divided into syllables. Each character should be a part of exactly one syllable. For example, the word "mamma" can be divided into syllables as "ma" and "mma", "mam" and "ma", and "mamm" and "a". Words that consist of only consonants should be ignored. The verse patterns for the given text is a sequence of *n* integers *p*1,<=*p*2,<=...,<=*p**n*. Text matches the given verse pattern if for each *i* from 1 to *n* one can divide words of the *i*-th line in syllables in such a way that the total number of syllables is equal to *p**i*. You are given the text and the verse pattern. Check, if the given text matches the given verse pattern. 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) — the number of lines in the text. The second line contains integers *p*1,<=...,<=*p**n* (0<=≤<=*p**i*<=≤<=100) — the verse pattern. Next *n* lines contain the text itself. Text consists of lowercase English letters and spaces. It's guaranteed that all lines are non-empty, each line starts and ends with a letter and words are separated by exactly one space. The length of each line doesn't exceed 100 characters. You should write the solution as standard output as follows: If the given text matches the given verse pattern, then print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes). Here are example inputs and outputs for the problem: Example Input 1: 3 2 2 3 intel code ch allenge Example Output 1: YES Example Input 2: 4 1 2 3 1 a bcdefghi jklmnopqrstu vwxyz Example Output 2: NO Example Input 3: 4 13 11 15 15 to be or not to be that is the question whether tis nobler in the mind to suffer the slings and arrows of outrageous fortune or to take arms against a sea of troubles Example Output 3: YES Now solve the problem by providing the code.
vowels = ['a','e','i','o','u','y'] N = int(input()) P = list(map(int, input().split())) ans = True for n in range(N): s = input() vc = len(list(True for c in s if c in vowels)) if vc != P[n]: ans = False print("YES" if ans else "NO")
vfc_83501
{ "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 2 3\nintel\ncode\nch allenge", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 2 3 1\na\nbcdefghi\njklmnopqrstu\nvwxyz", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n13 11 15 15\nto be or not to be that is the question\nwhether tis nobler in the mind to suffer\nthe slings and arrows of outrageous fortune\nor to take arms against a sea of troubles", "output": "YES", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
767
Solve the following coding problem using the programming language python: According to an old legeng, a long time ago Ankh-Morpork residents did something wrong to miss Fortune, and she cursed them. She said that at some time *n* snacks of distinct sizes will fall on the city, and the residents should build a Snacktower of them by placing snacks one on another. Of course, big snacks should be at the bottom of the tower, while small snacks should be at the top. Years passed, and once different snacks started to fall onto the city, and the residents began to build the Snacktower. However, they faced some troubles. Each day exactly one snack fell onto the city, but their order was strange. So, at some days the residents weren't able to put the new stack on the top of the Snacktower: they had to wait until all the bigger snacks fell. Of course, in order to not to anger miss Fortune again, the residents placed each snack on the top of the tower immediately as they could do it. Write a program that models the behavior of Ankh-Morpork residents. The input will be provided via standard input and looks as follows: The first line contains single integer *n* (1<=≤<=*n*<=≤<=100<=000) — the total number of snacks. The second line contains *n* integers, the *i*-th of them equals the size of the snack which fell on the *i*-th day. Sizes are distinct integers from 1 to *n*. You should write the solution as standard output as follows: Print *n* lines. On the *i*-th of them print the sizes of the snacks which the residents placed on the top of the Snacktower on the *i*-th day in the order they will do that. If no snack is placed on some day, leave the corresponding line empty. Here are example inputs and outputs for the problem: Example Input 1: 3 3 1 2 Example Output 1: 3   2 1 Example Input 2: 5 4 5 1 2 3 Example Output 2: 5 4     3 2 1 Now solve the problem by providing the code.
n = int(input()) snacks = {int(num): day for day, num in enumerate(input().split(" "))} days = [[] for _ in range(n)] sorted_snacks = sorted(snacks, reverse=True) current_day = None for snack in sorted_snacks: snack_day = snacks[snack] if current_day is None: current_day = snack_day if snack_day > current_day: current_day = snack_day days[current_day].append(snack) for day in days: if not day: print("") else: print(" ".join([str(snack) for snack in day]))
vfc_83505
{ "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": "3 \n\n2 1 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n4 5 1 2 3", "output": "5 4 \n\n\n3 2 1 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1", "output": "1 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 2", "output": "2 1 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n5 1 6 2 8 3 4 10 9 7", "output": "10 \n9 8 \n7 6 5 4 3 2 1 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "30\n16 10 4 29 5 28 12 21 11 30 18 6 14 3 17 22 20 15 9 1 27 19 24 26 13 25 2 23 8 7", "output": "30 29 28 \n\n\n\n\n\n\n\n\n\n\n27 \n\n\n26 \n\n25 24 \n\n23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 \n8 \n7 6 5 4 3 2 1 ", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
660
Solve the following coding problem using the programming language python: You are given an array of *n* elements, you must make it a co-prime array in as few moves as possible. In each move you can insert any positive integral number you want not greater than 109 in any place in the array. An array is co-prime if any two adjacent numbers of it are co-prime. In the number theory, two integers *a* and *b* are said to be co-prime if the only positive integer that divides both of them is 1. The input will be provided via standard input and looks as follows: The first line contains integer *n* (1<=≤<=*n*<=≤<=1000) — the number of elements in the given array. The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=109) — the elements of the array *a*. You should write the solution as standard output as follows: Print integer *k* on the first line — the least number of elements needed to add to the array *a* to make it co-prime. The second line should contain *n*<=+<=*k* integers *a**j* — the elements of the array *a* after adding *k* elements to it. Note that the new array should be co-prime, so any two adjacent values should be co-prime. Also the new array should be got from the original array *a* by adding *k* elements to it. If there are multiple answers you can print any one of them. Here are example inputs and outputs for the problem: Example Input 1: 3 2 7 28 Example Output 1: 1 2 7 9 28 Now solve the problem by providing the code.
def primeFactors(n): factors = [] i = 2 while n > 1: while n % i == 0: factors.append(i) n //= i i += 1 if i * i > n : break if n > 1: factors.append(n) return factors def areCoprime(n1,n2): n1Factors = primeFactors(n1) areCoprime = True for f in n1Factors: if n2 % f == 0: areCoprime = False break return areCoprime def sieve(n): primes = [True for i in range(n+1)] primeNums = [] p = 2 while p * p <= n: if primes[p]: for i in range(p*p,n+1,p): primes[i] = False p += 1 for i in range(2,n+1): if primes[i]: primeNums.append(i) return primeNums n = int(input()) A = list(map(int,input().split())) k = 0 added = {} primes = sieve(10**5) # esse valor foi um chute, n dá pra gerar todos os fatores até 10^9 for i in range(1,len(A)): checkCoprime = areCoprime(A[i],A[i-1]) factor = -1 if not checkCoprime: k += 1 for p in primes: if A[i] % p != 0 and A[i-1] % p != 0: factor = p break added[i] = factor print(k) out = f"{A[0]} " for i in range(1,len(A)): if i in added: out += f"{str(added[i])} " out += str(A[i]) if i < len(A) - 1: out += " " print(out)
vfc_83509
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "4000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2 7 28", "output": "1\n2 7 1 28", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1", "output": "0\n1", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n548", "output": "0\n548", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n963837006", "output": "0\n963837006", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
666
Solve the following coding problem using the programming language python: First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, which sometimes are not related to each other. For example, you should know linguistics very well. You learn a structure of Reberland language as foreign language. In this language words are constructed according to the following rules. First you need to choose the "root" of the word — some string which has more than 4 letters. Then several strings with the length 2 or 3 symbols are appended to this word. The only restriction — it is not allowed to append the same string twice in a row. All these strings are considered to be suffixes of the word (this time we use word "suffix" to describe a morpheme but not the few last characters of the string as you may used to). Here is one exercise that you have found in your task list. You are given the word *s*. Find all distinct strings with the length 2 or 3, which can be suffixes of this word according to the word constructing rules in Reberland language. Two strings are considered distinct if they have different length or there is a position in which corresponding characters do not match. Let's look at the example: the word *abacabaca* is given. This word can be obtained in the following ways: , where the root of the word is overlined, and suffixes are marked by "corners". Thus, the set of possible suffixes for this word is {*aca*,<=*ba*,<=*ca*}. The input will be provided via standard input and looks as follows: The only line contains a string *s* (5<=≤<=|*s*|<=≤<=104) consisting of lowercase English letters. You should write the solution as standard output as follows: On the first line print integer *k* — a number of distinct possible suffixes. On the next *k* lines print suffixes. Print suffixes in lexicographical (alphabetical) order. Here are example inputs and outputs for the problem: Example Input 1: abacabaca Example Output 1: 3 aca ba ca Example Input 2: abaca Example Output 2: 0 Now solve the problem by providing the code.
t = input() s, d = set(), set() p = {(len(t), 2)} while p: m, x = p.pop() r = m + x for y in [x, 5 - x]: l = m - y q = (l, y) if q in d or l < 5 or t[l:m] == t[m:r]: continue s.add(t[l:m]) d.add(q) p.add(q) print(len(s)) print('\n'.join(sorted(s)))
vfc_83513
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "abacabaca", "output": "3\naca\nba\nca", "type": "stdin_stdout" }, { "fn_name": null, "input": "abaca", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "gzqgchv", "output": "1\nhv", "type": "stdin_stdout" }, { "fn_name": null, "input": "iosdwvzerqfi", "output": "9\ner\nerq\nfi\nqfi\nrq\nvz\nvze\nze\nzer", "type": "stdin_stdout" }, { "fn_name": null, "input": "oawtxikrpvfuzugjweki", "output": "25\neki\nfu\nfuz\ngj\ngjw\nik\nikr\njw\njwe\nki\nkr\nkrp\npv\npvf\nrp\nrpv\nug\nugj\nuz\nuzu\nvf\nvfu\nwe\nzu\nzug", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
62
Solve the following coding problem using the programming language python: Statistics claims that students sleep no more than three hours a day. But even in the world of their dreams, while they are snoring peacefully, the sense of impending doom is still upon them. A poor student is dreaming that he is sitting the mathematical analysis exam. And he is examined by the most formidable professor of all times, a three times Soviet Union Hero, a Noble Prize laureate in student expulsion, venerable Petr Palych. The poor student couldn't answer a single question. Thus, instead of a large spacious office he is going to apply for a job to thorium mines. But wait a minute! Petr Palych decided to give the student the last chance! Yes, that is possible only in dreams. So the professor began: "Once a Venusian girl and a Marsian boy met on the Earth and decided to take a walk holding hands. But the problem is the girl has *a**l* fingers on her left hand and *a**r* fingers on the right one. The boy correspondingly has *b**l* and *b**r* fingers. They can only feel comfortable when holding hands, when no pair of the girl's fingers will touch each other. That is, they are comfortable when between any two girl's fingers there is a boy's finger. And in addition, no three fingers of the boy should touch each other. Determine if they can hold hands so that the both were comfortable." The boy any the girl don't care who goes to the left and who goes to the right. The difference is only that if the boy goes to the left of the girl, he will take her left hand with his right one, and if he goes to the right of the girl, then it is vice versa. The input will be provided via standard input and looks as follows: The first line contains two positive integers not exceeding 100. They are the number of fingers on the Venusian girl's left and right hand correspondingly. The second line contains two integers not exceeding 100. They are the number of fingers on the Marsian boy's left and right hands correspondingly. You should write the solution as standard output as follows: Print YES or NO, that is, the answer to Petr Palych's question. Here are example inputs and outputs for the problem: Example Input 1: 5 1 10 5 Example Output 1: YES Example Input 2: 4 5 3 3 Example Output 2: YES Example Input 3: 1 2 11 6 Example Output 3: NO Now solve the problem by providing the code.
al, ar = list(map(int, input().split())) bl, br = list(map(int, input().split())) if (br >= al-1 and br <= (al+1)*2) or (bl <= (ar+1)*2 and bl >= ar-1): print('YES') else: print('NO')
vfc_83517
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 1\n10 5", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 5\n3 3", "output": "YES", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
391
Solve the following coding problem using the programming language python: You will receive 3 points for solving this problem. Manao is designing the genetic code for a new type of algae to efficiently produce fuel. Specifically, Manao is focusing on a stretch of DNA that encodes one protein. The stretch of DNA is represented by a string containing only the characters 'A', 'T', 'G' and 'C'. Manao has determined that if the stretch of DNA contains a maximal sequence of consecutive identical nucleotides that is of even length, then the protein will be nonfunctional. For example, consider a protein described by DNA string "GTTAAAG". It contains four maximal sequences of consecutive identical nucleotides: "G", "TT", "AAA", and "G". The protein is nonfunctional because sequence "TT" has even length. Manao is trying to obtain a functional protein from the protein he currently has. Manao can insert additional nucleotides into the DNA stretch. Each additional nucleotide is a character from the set {'A', 'T', 'G', 'C'}. Manao wants to determine the minimum number of insertions necessary to make the DNA encode a functional protein. The input will be provided via standard input and looks as follows: The input consists of a single line, containing a string *s* of length *n* (1<=≤<=*n*<=≤<=100). Each character of *s* will be from the set {'A', 'T', 'G', 'C'}. This problem doesn't have subproblems. You will get 3 points for the correct submission. You should write the solution as standard output as follows: The program should print on one line a single integer representing the minimum number of 'A', 'T', 'G', 'C' characters that are required to be inserted into the input string in order to make all runs of identical characters have odd length. Here are example inputs and outputs for the problem: Example Input 1: GTTAAAG Example Output 1: 1 Example Input 2: AACCAACCAAAAC Example Output 2: 5 Now solve the problem by providing the code.
R = lambda: map(int, input().split()) s = input() cc, c = 0, 0 for r in range(len(s)): if r == 0 or s[r] == s[r - 1]: c += 1 else: cc += (c % 2 == 0) c = 1 cc += (c % 2 == 0) print(cc)
vfc_83521
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "3000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "GTTAAAG", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
828
Solve the following coding problem using the programming language python: In a small restaurant there are *a* tables for one person and *b* tables for two persons. It it known that *n* groups of people come today, each consisting of one or two people. If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group. If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group. You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to. The input will be provided via standard input and looks as follows: The first line contains three integers *n*, *a* and *b* (1<=≤<=*n*<=≤<=2·105, 1<=≤<=*a*,<=*b*<=≤<=2·105) — the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables. The second line contains a sequence of integers *t*1,<=*t*2,<=...,<=*t**n* (1<=≤<=*t**i*<=≤<=2) — the description of clients in chronological order. If *t**i* is equal to one, then the *i*-th group consists of one person, otherwise the *i*-th group consists of two people. You should write the solution as standard output as follows: Print the total number of people the restaurant denies service to. Here are example inputs and outputs for the problem: Example Input 1: 4 1 2 1 2 1 1 Example Output 1: 0 Example Input 2: 4 1 1 1 1 2 1 Example Output 2: 2 Now solve the problem by providing the code.
n, a, b = map(int, input().split()) c = 0 ans = 0 for v in map(int, input().split()): if v == 1: if a: a -= 1 elif b: b -= 1 c += 1 elif c: c -= 1 else: ans += 1 else: if b: b -= 1 else: ans += 2 print(ans)
vfc_83525
{ "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 1 2\n1 2 1 1", "output": "0", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
817
Solve the following coding problem using the programming language python: After returning from the army Makes received a gift — an array *a* consisting of *n* positive integer numbers. He hadn't been solving problems for a long time, so he became interested to answer a particular question: how many triples of indices (*i*,<= *j*,<= *k*) (*i*<=&lt;<=*j*<=&lt;<=*k*), such that *a**i*·*a**j*·*a**k* is minimum possible, are there in the array? Help him with it! The input will be provided via standard input and looks as follows: The first line of input contains a positive integer number *n* (3<=≤<=*n*<=≤<=105) — the number of elements in array *a*. The second line contains *n* positive integer numbers *a**i* (1<=≤<=*a**i*<=≤<=109) — the elements of a given array. You should write the solution as standard output as follows: Print one number — the quantity of triples (*i*,<= *j*,<= *k*) such that *i*,<= *j* and *k* are pairwise distinct and *a**i*·*a**j*·*a**k* is minimum possible. Here are example inputs and outputs for the problem: Example Input 1: 4 1 1 1 1 Example Output 1: 4 Example Input 2: 5 1 3 2 3 4 Example Output 2: 2 Example Input 3: 6 1 3 3 1 3 2 Example Output 3: 1 Now solve the problem by providing the code.
n = int(input()) a = list(map(int, input().strip().split())) d = dict() for i in range(n): try: d[a[i]] += 1 except: d[a[i]] = 1 l = list(d.keys()) l.sort() n = len(l) if n == 1: a = d[l[0]] print(a*(a-1)*(a-2) // 6) elif n == 2: a, b = d[l[0]], d[l[1]] if a >= 3: print(a*(a-1)*(a-2) // 6) elif a == 2: print(b) else: print(b*(b-1)//2) else: a,b,c = d[l[0]], d[l[1]], d[l[2]] if a >= 3: print(a*(a-1)*(a-2) // 6) elif a == 2: print(b) else: if b >= 2: print(b*(b-1) // 2) else: print(c)
vfc_83529
{ "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 1 1", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 3 2 3 4", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n1 3 3 1 3 2", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1000000000 1000000000 1000000000", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 1 2 2", "output": "2", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
459
Solve the following coding problem using the programming language python: Pashmak has fallen in love with an attractive girl called Parmida since one year ago... Today, Pashmak set up a meeting with his partner in a romantic garden. Unfortunately, Pashmak has forgotten where the garden is. But he remembers that the garden looks like a square with sides parallel to the coordinate axes. He also remembers that there is exactly one tree on each vertex of the square. Now, Pashmak knows the position of only two of the trees. Help him to find the position of two remaining ones. The input will be provided via standard input and looks as follows: The first line contains four space-separated *x*1,<=*y*1,<=*x*2,<=*y*2 (<=-<=100<=≤<=*x*1,<=*y*1,<=*x*2,<=*y*2<=≤<=100) integers, where *x*1 and *y*1 are coordinates of the first tree and *x*2 and *y*2 are coordinates of the second tree. It's guaranteed that the given points are distinct. You should write the solution as standard output as follows: If there is no solution to the problem, print -1. Otherwise print four space-separated integers *x*3,<=*y*3,<=*x*4,<=*y*4 that correspond to the coordinates of the two other trees. If there are several solutions you can output any of them. Note that *x*3,<=*y*3,<=*x*4,<=*y*4 must be in the range (<=-<=1000<=≤<=*x*3,<=*y*3,<=*x*4,<=*y*4<=≤<=1000). Here are example inputs and outputs for the problem: Example Input 1: 0 0 0 1 Example Output 1: 1 0 1 1 Example Input 2: 0 0 1 1 Example Output 2: 0 1 1 0 Example Input 3: 0 0 1 2 Example Output 3: -1 Now solve the problem by providing the code.
#https://codeforces.com/contest/459/problem/A x1,y1,x2,y2 = [int(elem) for elem in input().split()] if y1 == y2: print(x1, y1+(x2-x1), x2, y2+(x2-x1)) elif x1 == x2: print(x1+(y2-y1), y1, x2+(y2-y1), y2) elif abs(y2 - y1) != abs(x2 - x1): print(-1) else: print(x1,y2,x2,y1)
vfc_83533
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "0 0 0 1", "output": "1 0 1 1", "type": "stdin_stdout" }, { "fn_name": null, "input": "0 0 1 1", "output": "0 1 1 0", "type": "stdin_stdout" }, { "fn_name": null, "input": "0 0 1 2", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "-100 -100 100 100", "output": "-100 100 100 -100", "type": "stdin_stdout" }, { "fn_name": null, "input": "-100 -100 99 100", "output": "-1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
22
Solve the following coding problem using the programming language python: Once Bob needed to find the second order statistics of a sequence of integer numbers. Lets choose each number from the sequence exactly once and sort them. The value on the second position is the second order statistics of the given sequence. In other words it is the smallest element strictly greater than the minimum. Help Bob solve this problem. The input will be provided via standard input and looks as follows: The first input line contains integer *n* (1<=≤<=*n*<=≤<=100) — amount of numbers in the sequence. The second line contains *n* space-separated integer numbers — elements of the sequence. These numbers don't exceed 100 in absolute value. You should write the solution as standard output as follows: If the given sequence has the second order statistics, output this order statistics, otherwise output NO. Here are example inputs and outputs for the problem: Example Input 1: 4 1 2 2 -4 Example Output 1: 1 Example Input 2: 5 1 2 3 1 1 Example Output 2: 2 Now solve the problem by providing the code.
n = int(input()) a = list(map(int,input().split())) a = set(a) a = list(a) a.sort() if not len(a) ==1: print(a[1]) else: print('NO')
vfc_83537
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 2 2 -4", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 2 3 1 1", "output": "2", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
346
Solve the following coding problem using the programming language python: It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of *n* distinct integers. And then they take turns to make the following moves. During each move, either Alice or Bob (the player whose turn is the current) can choose two distinct integers *x* and *y* from the set, such that the set doesn't contain their absolute difference |*x*<=-<=*y*|. Then this player adds integer |*x*<=-<=*y*| to the set (so, the size of the set increases by one). If the current player has no valid move, he (or she) loses the game. The question is who will finally win the game if both players play optimally. Remember that Alice always moves first. The input will be provided via standard input and looks as follows: The first line contains an integer *n* (2<=≤<=*n*<=≤<=100) — the initial number of elements in the set. The second line contains *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) — the elements of the set. You should write the solution as standard output as follows: Print a single line with the winner's name. If Alice wins print "Alice", otherwise print "Bob" (without quotes). Here are example inputs and outputs for the problem: Example Input 1: 2 2 3 Example Output 1: Alice Example Input 2: 2 5 3 Example Output 2: Alice Example Input 3: 3 5 6 7 Example Output 3: Bob Now solve the problem by providing the code.
from math import gcd n = int(input()) a = list(map(int, input().split())) g = a[0] max = a[0] for i in a: if i > max: max = i g = gcd(g, i) ans = (max // g) - n if ans % 2 == 0: print("Bob") else: print("Alice")
vfc_83541
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2 3", "output": "Alice", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
957
Solve the following coding problem using the programming language python: Overlooking the captivating blend of myriads of vernal hues, Arkady the painter lays out a long, long canvas. Arkady has a sufficiently large amount of paint of three colours: cyan, magenta, and yellow. On the one-dimensional canvas split into *n* consecutive segments, each segment needs to be painted in one of the colours. Arkady has already painted some (possibly none or all) segments and passes the paintbrush to you. You are to determine whether there are at least two ways of colouring all the unpainted segments so that no two adjacent segments are of the same colour. Two ways are considered different if and only if a segment is painted in different colours in them. The input will be provided via standard input and looks as follows: The first line contains a single positive integer *n* (1<=≤<=*n*<=≤<=100) — the length of the canvas. The second line contains a string *s* of *n* characters, the *i*-th of which is either 'C' (denoting a segment painted in cyan), 'M' (denoting one painted in magenta), 'Y' (one painted in yellow), or '?' (an unpainted one). You should write the solution as standard output as follows: If there are at least two different ways of painting, output "Yes"; otherwise output "No" (both without quotes). You can print each character in any case (upper or lower). Here are example inputs and outputs for the problem: Example Input 1: 5 CY??Y Example Output 1: Yes Example Input 2: 5 C?C?Y Example Output 2: Yes Example Input 3: 5 ?CYC? Example Output 3: Yes Example Input 4: 5 C??MM Example Output 4: No Example Input 5: 3 MMY Example Output 5: No Now solve the problem by providing the code.
n=int(input()) s=list(input()) if s.count("?")==0: print("No") exit(0) f=0 a=s[0] for i in range(1,n): if s[i]==s[i-1] and s[i]!="?": f=1 print("No") exit(0) s=["*"]+s+["&"] #print(s) y=list("CMY") #print(y) for i in range(1,n+1): g=0 if (s[i-1] in y) and (s[i+1] in y): g=1 if (s[i]=="?" and s[i-1]==s[i+1] and g==1) or (g==0 and s[i]=="?"): print("Yes") exit(0) #print(i,s[i-1],s[i],s[i+1],g) print("No")
vfc_83545
{ "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\nCY??Y", "output": "Yes", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\nC?C?Y", "output": "Yes", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n?CYC?", "output": "Yes", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
76
Solve the following coding problem using the programming language python: You are given *N* points on a plane. Write a program which will find the sum of squares of distances between all pairs of points. The input will be provided via standard input and looks as follows: The first line of input contains one integer number *N* (1<=≤<=*N*<=≤<=100<=000) — the number of points. Each of the following *N* lines contain two integer numbers *X* and *Y* (<=-<=10<=000<=≤<=*X*,<=*Y*<=≤<=10<=000) — the coordinates of points. Two or more points may coincide. You should write the solution as standard output as follows: The only line of output should contain the required sum of squares of distances between all pairs of points. Here are example inputs and outputs for the problem: Example Input 1: 4 1 1 -1 -1 1 -1 -1 1 Example Output 1: 32 Now solve the problem by providing the code.
"""**************************************************************\ BISMILLAHIR RAHMANIR RAHIM **************************************************************** AUTHOR NAME: MD. TAHURUZZOHA TUHIN \**************************************************************""" T = int(input()) x = 0 y = 0 s = 0 sx = 0 sy = 0 for _ in range(T): # n = int(input()) x,y = [int(x) for x in input().split(' ')] s+=(x*x+y*y) sx+=x sy+=y print(s*T-(sx*sx+sy*sy))
vfc_83549
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 1\n-1 -1\n1 -1\n-1 1", "output": "32", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n6 3", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "30\n-7 -12\n-2 5\n14 8\n9 17\n15 -18\n20 6\n20 8\n-13 12\n-4 -20\n-11 -16\n-6 16\n1 -9\n5 -12\n13 -17\n11 5\n8 -9\n-13 5\n19 -13\n-19 -8\n-14 10\n10 3\n-16 -8\n-17 16\n-14 -15\n5 1\n-13 -9\n13 17\n-14 -8\n2 5\n18 5", "output": "265705", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
337
Solve the following coding problem using the programming language python: The end of the school year is near and Ms. Manana, the teacher, will soon have to say goodbye to a yet another class. She decided to prepare a goodbye present for her *n* students and give each of them a jigsaw puzzle (which, as wikipedia states, is a tiling puzzle that requires the assembly of numerous small, often oddly shaped, interlocking and tessellating pieces). The shop assistant told the teacher that there are *m* puzzles in the shop, but they might differ in difficulty and size. Specifically, the first jigsaw puzzle consists of *f*1 pieces, the second one consists of *f*2 pieces and so on. Ms. Manana doesn't want to upset the children, so she decided that the difference between the numbers of pieces in her presents must be as small as possible. Let *A* be the number of pieces in the largest puzzle that the teacher buys and *B* be the number of pieces in the smallest such puzzle. She wants to choose such *n* puzzles that *A*<=-<=*B* is minimum possible. Help the teacher and find the least possible value of *A*<=-<=*B*. The input will be provided via standard input and looks as follows: The first line contains space-separated integers *n* and *m* (2<=≤<=*n*<=≤<=*m*<=≤<=50). The second line contains *m* space-separated integers *f*1,<=*f*2,<=...,<=*f**m* (4<=≤<=*f**i*<=≤<=1000) — the quantities of pieces in the puzzles sold in the shop. You should write the solution as standard output as follows: Print a single integer — the least possible difference the teacher can obtain. Here are example inputs and outputs for the problem: Example Input 1: 4 6 10 12 10 7 5 22 Example Output 1: 5 Now solve the problem by providing the code.
n, m = map(int, input().split()) puzzles = sorted(list(map(int, input().split()))) min_diff = float('inf') diff = 0 for a, _ in enumerate(range(m - n + 1 )): diff = puzzles[n-1] - puzzles[a] min_diff = min(min_diff, diff) # print(diff) n+=1 min_diff = min(min_diff, diff) print(min_diff)
vfc_83553
{ "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 6\n10 12 10 7 5 22", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n4 4", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 10\n4 5 6 7 8 9 10 11 12 12", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 5\n818 136 713 59 946", "output": "759", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
122
Solve the following coding problem using the programming language python: Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya calls a number almost lucky if it could be evenly divided by some lucky number. Help him find out if the given number *n* is almost lucky. The input will be provided via standard input and looks as follows: The single line contains an integer *n* (1<=≤<=*n*<=≤<=1000) — the number that needs to be checked. You should write the solution as standard output as follows: In the only line print "YES" (without the quotes), if number *n* is almost lucky. Otherwise, print "NO" (without the quotes). Here are example inputs and outputs for the problem: Example Input 1: 47 Example Output 1: YES Example Input 2: 16 Example Output 2: YES Example Input 3: 78 Example Output 3: NO Now solve the problem by providing the code.
n=int(input("")) while not(1<=n<=1000): n=int(input("")) l=[4,7,47,74,477,447,444,44,77,777,774,744,474] p=len(l) i=0 test=False while not test and i<p: if n%l[i]==0: test=True else: i+=1 if test: print("YES") else: print("NO")
vfc_83557
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "47", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "16", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "78", "output": "NO", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
997
Solve the following coding problem using the programming language python: You've got a string $a_1, a_2, \dots, a_n$, consisting of zeros and ones. Let's call a sequence of consecutive elements $a_i, a_{i<=+<=1}, \ldots,<=a_j$ ($1\leq<=i\leq<=j\leq<=n$) a substring of string $a$. You can apply the following operations any number of times: - Choose some substring of string $a$ (for example, you can choose entire string) and reverse it, paying $x$ coins for it (for example, «0101101» $\to$ «0111001»); - Choose some substring of string $a$ (for example, you can choose entire string or just one symbol) and replace each symbol to the opposite one (zeros are replaced by ones, and ones — by zeros), paying $y$ coins for it (for example, «0101101» $\to$ «0110001»). You can apply these operations in any order. It is allowed to apply the operations multiple times to the same substring. What is the minimum number of coins you need to spend to get a string consisting only of ones? The input will be provided via standard input and looks as follows: The first line of input contains integers $n$, $x$ and $y$ ($1<=\leq<=n<=\leq<=300\,000, 0 \leq x, y \leq 10^9$) — length of the string, cost of the first operation (substring reverse) and cost of the second operation (inverting all elements of substring). The second line contains the string $a$ of length $n$, consisting of zeros and ones. You should write the solution as standard output as follows: Print a single integer — the minimum total cost of operations you need to spend to get a string consisting only of ones. Print $0$, if you do not need to perform any operations. Here are example inputs and outputs for the problem: Example Input 1: 5 1 10 01000 Example Output 1: 11 Example Input 2: 5 10 1 01000 Example Output 2: 2 Example Input 3: 7 2 3 1111111 Example Output 3: 0 Now solve the problem by providing the code.
import math import sys import queue def solve(): n, x, y = map(int, input().split()) s = str(input()) subsq = 1 zeros = int(s[0] == "0") for i in range(1, n): if s[i] != s[i - 1]: subsq += 1 if s[i] == "0": zeros += 1 res = 0 if subsq == 1: if s[0] == "0": res = y else: res = 0 elif subsq == 2: res = y else: if s[0] == "0": res = ((subsq - 1) // 2 * x + y) else: if subsq == 3: res = (x + y) else: res = ((subsq - 2) // 2 * x + y) res = min(res, zeros * y) print(res) if __name__ == '__main__': multi_test = 0 if multi_test: t = int(input()) for _ in range(t): solve() else: solve()
vfc_83561
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "4000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 1 10\n01000", "output": "11", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 10 1\n01000", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 2 3\n1111111", "output": "0", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
549
Solve the following coding problem using the programming language python: The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them. In this problem an image is a rectangular table that consists of lowercase Latin letters. A face on the image is a 2<=×<=2 square, such that from the four letters of this square you can make word "face". You need to write a program that determines the number of faces on the image. The squares that correspond to the faces can overlap. The input will be provided via standard input and looks as follows: The first line contains two space-separated integers, *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50) — the height and the width of the image, respectively. Next *n* lines define the image. Each line contains *m* lowercase Latin letters. You should write the solution as standard output as follows: In the single line print the number of faces on the image. Here are example inputs and outputs for the problem: Example Input 1: 4 4 xxxx xfax xcex xxxx Example Output 1: 1 Example Input 2: 4 2 xx cf ae xx Example Output 2: 1 Example Input 3: 2 3 fac cef Example Output 3: 2 Example Input 4: 1 4 face Example Output 4: 0 Now solve the problem by providing the code.
n,m=map(int,input().split()) a=[list(input()) for i in range(n)] d=set(['f','a','c','e']) k=0 for i in range(n-1): for j in range(m-1): if a[i][j] in d: s=set() s.add(a[i][j]) s.add(a[i+1][j]) s.add(a[i+1][j+1]) s.add(a[i][j+1]) if s==d: k+=1 print(k)
vfc_83565
{ "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 4\nxxxx\nxfax\nxcex\nxxxx", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 2\nxx\ncf\nae\nxx", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3\nfac\ncef", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 4\nface", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5\nwmmwn\nlurcm\nkeetd\nfokon\ncxxgx", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5\nkjxbw\neacra\nxefhx\nucmcz\npgtjk", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
765
Solve the following coding problem using the programming language python: There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back. Jinotega's best friends, team Base have found a list of their itinerary receipts with information about departure and arrival airports. Now they wonder, where is Jinotega now: at home or at some competition far away? They know that: - this list contains all Jinotega's flights in this year (in arbitrary order), - Jinotega has only flown from his hometown to a snooker contest and back, - after each competition Jinotega flies back home (though they may attend a competition in one place several times), - and finally, at the beginning of the year Jinotega was at home. Please help them to determine Jinotega's location! The input will be provided via standard input and looks as follows: In the first line of input there is a single integer *n*: the number of Jinotega's flights (1<=≤<=*n*<=≤<=100). In the second line there is a string of 3 capital Latin letters: the name of Jinotega's home airport. In the next *n* lines there is flight information, one flight per line, in form "XXX-&gt;YYY", where "XXX" is the name of departure airport "YYY" is the name of arrival airport. Exactly one of these airports is Jinotega's home airport. It is guaranteed that flights information is consistent with the knowledge of Jinotega's friends, which is described in the main part of the statement. You should write the solution as standard output as follows: If Jinotega is now at home, print "home" (without quotes), otherwise print "contest". Here are example inputs and outputs for the problem: Example Input 1: 4 SVO SVO-&gt;CDG LHR-&gt;SVO SVO-&gt;LHR CDG-&gt;SVO Example Output 1: home Example Input 2: 3 SVO SVO-&gt;HKT HKT-&gt;SVO SVO-&gt;RAP Example Output 2: contest Now solve the problem by providing the code.
n = int(input()) home = input() flights = [] be_in_home = 0 not_in_home = 0 for i in range(n): airport_from, airport_to = map(str, input().split('->')) flights.append([airport_from, airport_to]) for x in flights: if x[1] == home: be_in_home += 1 else: not_in_home += 1 if be_in_home != not_in_home: print('contest') else: print('home')
vfc_83569
{ "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\nSVO\nSVO->CDG\nLHR->SVO\nSVO->LHR\nCDG->SVO", "output": "home", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP", "output": "contest", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\nESJ\nESJ->TSJ", "output": "contest", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
475
Solve the following coding problem using the programming language python: Imagine a city with *n* horizontal streets crossing *m* vertical streets, forming an (*n*<=-<=1)<=×<=(*m*<=-<=1) grid. In order to increase the traffic flow, mayor of the city has decided to make each street one way. This means in each horizontal street, the traffic moves only from west to east or only from east to west. Also, traffic moves only from north to south or only from south to north in each vertical street. It is possible to enter a horizontal street from a vertical street, or vice versa, at their intersection. The mayor has received some street direction patterns. Your task is to check whether it is possible to reach any junction from any other junction in the proposed street direction pattern. The input will be provided via standard input and looks as follows: The first line of input contains two integers *n* and *m*, (2<=≤<=*n*,<=*m*<=≤<=20), denoting the number of horizontal streets and the number of vertical streets. The second line contains a string of length *n*, made of characters '&lt;' and '&gt;', denoting direction of each horizontal street. If the *i*-th character is equal to '&lt;', the street is directed from east to west otherwise, the street is directed from west to east. Streets are listed in order from north to south. The third line contains a string of length *m*, made of characters '^' and 'v', denoting direction of each vertical street. If the *i*-th character is equal to '^', the street is directed from south to north, otherwise the street is directed from north to south. Streets are listed in order from west to east. You should write the solution as standard output as follows: If the given pattern meets the mayor's criteria, print a single line containing "YES", otherwise print a single line containing "NO". Here are example inputs and outputs for the problem: Example Input 1: 3 3 &gt;&lt;&gt; v^v Example Output 1: NO Example Input 2: 4 6 &lt;&gt;&lt;&gt; v^v^v^ Example Output 2: YES Now solve the problem by providing the code.
n, m = map(int, input("").split()) row_order = [ char for char in input("")] col_order = [char for char in input("")] class Node(): def __init__(self, id): self.row_id, self.col_id = id self.children = [] def add_child(self, child_node_id): self.children.append(child_node_id) def add_horizontal_edge(row_dir, row_id, col_id): if row_dir == '>' and col_id < m-1: matrix[row_id][col_id].add_child((row_id ,col_id+1)) elif row_dir == '<' and col_id > 0: matrix[row_id][col_id].add_child((row_id, col_id-1)) def add_vertical_edge(col_dir, row_id, col_id): if col_dir == '^' and row_id > 0: matrix[row_id][col_id].add_child((row_id-1, col_id)) elif col_dir == 'v'and row_id < n-1: matrix[row_id][col_id].add_child((row_id+1, col_id)) matrix = [[Node((row_id, col_id)) for col_id in range(m)] for row_id in range(n)] for row_id in range(n): row_dir = row_order[row_id] for col_id in range(m): col_dir = col_order[col_id] add_horizontal_edge(row_dir, row_id, col_id) add_vertical_edge(col_dir, row_id, col_id) def explore(row_id, col_id, visited): if visited[row_id][col_id] == 'true': return else: visited[row_id][col_id] ='true' for child_row_id, child_col_id in matrix[row_id][col_id].children: explore(child_row_id, child_col_id, visited) return answer = 'YES' def dfs(answer): for row_id in range(n): for col_id in range(m): visited = [['false' for col_id in range(m)] for row_id in range(n)] explore(row_id, col_id, visited) for i in range(n): for j in range(m): if visited[i][j] == 'false': answer = 'NO' return answer return answer answer = dfs(answer) print(answer)
vfc_83573
{ "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 3\n><>\nv^v", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 6\n<><>\nv^v^v^", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n<>\nv^", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n>>\n^v", "output": "NO", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
131
Solve the following coding problem using the programming language python: wHAT DO WE NEED cAPS LOCK FOR? Caps lock is a computer keyboard key. Pressing it sets an input mode in which typed letters are capital by default. If it is pressed by accident, it leads to accidents like the one we had in the first passage. Let's consider that a word has been typed with the Caps lock key accidentally switched on, if: - either it only contains uppercase letters; - or all letters except for the first one are uppercase. In this case we should automatically change the case of all letters. For example, the case of the letters that form words "hELLO", "HTTP", "z" should be changed. Write a program that applies the rule mentioned above. If the rule cannot be applied, the program should leave the word unchanged. The input will be provided via standard input and looks as follows: The first line of the input data contains a word consisting of uppercase and lowercase Latin letters. The word's length is from 1 to 100 characters, inclusive. You should write the solution as standard output as follows: Print the result of the given word's processing. Here are example inputs and outputs for the problem: Example Input 1: cAPS Example Output 1: Caps Example Input 2: Lock Example Output 2: Lock Now solve the problem by providing the code.
inp = input() if inp[0]==inp[0].lower() and inp[1:]==inp[1:].upper(): print(inp.title()) elif inp==inp.upper(): print(inp.lower()) else: print(inp)
vfc_83577
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "cAPS", "output": "Caps", "type": "stdin_stdout" }, { "fn_name": null, "input": "Lock", "output": "Lock", "type": "stdin_stdout" }, { "fn_name": null, "input": "cAPSlOCK", "output": "cAPSlOCK", "type": "stdin_stdout" }, { "fn_name": null, "input": "CAPs", "output": "CAPs", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
296
Solve the following coding problem using the programming language python: Yaroslav has an array that consists of *n* integers. In one second Yaroslav can swap two neighboring array elements. Now Yaroslav is wondering if he can obtain an array where any two neighboring elements would be distinct in a finite time. Help Yaroslav. The input will be provided via standard input and looks as follows: The first line contains integer *n* (1<=≤<=*n*<=≤<=100) — the number of elements in the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000) — the array elements. You should write the solution as standard output as follows: In the single line print "YES" (without the quotes) if Yaroslav can obtain the array he needs, and "NO" (without the quotes) otherwise. Here are example inputs and outputs for the problem: Example Input 1: 1 1 Example Output 1: YES Example Input 2: 3 1 1 2 Example Output 2: YES Example Input 3: 4 7 7 7 7 Example Output 3: NO Now solve the problem by providing the code.
n = int(input()) a = list(map(int, input().split())) ok = True for val in a: if a.count(val) > (n+1)//2: ok = False break print('YES' if ok else 'NO')
vfc_83581
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n1", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 1 2", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n7 7 7 7", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n479 170 465 146", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n996 437 605 996 293", "output": "YES", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
14
Solve the following coding problem using the programming language python: A boy Bob likes to draw. Not long ago he bought a rectangular graph (checked) sheet with *n* rows and *m* columns. Bob shaded some of the squares on the sheet. Having seen his masterpiece, he decided to share it with his elder brother, who lives in Flatland. Now Bob has to send his picture by post, but because of the world economic crisis and high oil prices, he wants to send his creation, but to spend as little money as possible. For each sent square of paper (no matter whether it is shaded or not) Bob has to pay 3.14 burles. Please, help Bob cut out of his masterpiece a rectangle of the minimum cost, that will contain all the shaded squares. The rectangle's sides should be parallel to the sheet's sides. The input will be provided via standard input and looks as follows: The first line of the input data contains numbers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=50), *n* — amount of lines, and *m* — amount of columns on Bob's sheet. The following *n* lines contain *m* characters each. Character «.» stands for a non-shaded square on the sheet, and «*» — for a shaded square. It is guaranteed that Bob has shaded at least one square. You should write the solution as standard output as follows: Output the required rectangle of the minimum cost. Study the output data in the sample tests to understand the output format better. Here are example inputs and outputs for the problem: Example Input 1: 6 7 ....... ..***.. ..*.... ..***.. ..*.... ..***.. Example Output 1: *** *.. *** *.. *** Example Input 2: 3 3 *** *.* *** Example Output 2: *** *.* *** Now solve the problem by providing the code.
def main(): n, m = list(map(int, input().split())) arr = [] for _ in range(n): arr.append(input()) mn_i, mx_i, mx_j, mn_j = n, -1, -1, m for i in range(n): for j in range(m): if arr[i][j] == "*": mn_i = min(mn_i, i) mx_i = max(mx_i, i) mn_j = min(mn_j, j) mx_j = max(mx_j, j) for i in range(mn_i, mx_i + 1): print(arr[i][mn_j : mx_j + 1]) if __name__ == "__main__": main()
vfc_83585
{ "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 7\n.......\n..***..\n..*....\n..***..\n..*....\n..***..", "output": "***\n*..\n***\n*..\n***", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n***\n*.*\n***", "output": "***\n*.*\n***", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n*", "output": "*", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
954
Solve the following coding problem using the programming language python: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace any pair of consecutive moves RU or UR with a diagonal move (described as character D). After that, he can go on and do some other replacements, until there is no pair of consecutive moves RU or UR left. Your problem is to print the minimum possible length of the sequence of moves after the replacements. The input will be provided via standard input and looks as follows: The first line of the input contains one integer *n* (1<=≤<=*n*<=≤<=100) — the length of the sequence. The second line contains the sequence consisting of *n* characters U and R. You should write the solution as standard output as follows: Print the minimum possible length of the sequence of moves after all replacements are done. Here are example inputs and outputs for the problem: Example Input 1: 5 RUURU Example Output 1: 3 Example Input 2: 17 UUURRRRRUUURURUUU Example Output 2: 13 Now solve the problem by providing the code.
n=int(input()) s=input() c=[] for i in range(n): c.append(s[i]) for i in range(n-1): if c[i]=="U" and c[i+1]=="R": c[i]="D" c[i+1]="D" if c[i]=="R" and c[i+1]=="U": c[i]="D" c[i+1]="D" print(n-((c.count("D"))//2))
vfc_83589
{ "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\nRUURU", "output": "3", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
143
Solve the following coding problem using the programming language python: Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with that. The box's lock looks as follows: it contains 4 identical deepenings for gems as a 2<=×<=2 square, and some integer numbers are written at the lock's edge near the deepenings. The example of a lock is given on the picture below. The box is accompanied with 9 gems. Their shapes match the deepenings' shapes and each gem contains one number from 1 to 9 (each number is written on exactly one gem). The box will only open after it is decorated with gems correctly: that is, each deepening in the lock should be filled with exactly one gem. Also, the sums of numbers in the square's rows, columns and two diagonals of the square should match the numbers written at the lock's edge. For example, the above lock will open if we fill the deepenings with gems with numbers as is shown on the picture below. Now Vasilisa the Wise wants to define, given the numbers on the box's lock, which gems she should put in the deepenings to open the box. Help Vasilisa to solve this challenging task. The input will be provided via standard input and looks as follows: The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers *r*1 and *r*2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers *c*1 and *c*2 that define the required sums of numbers in the columns of the square. The third line contains space-separated integers *d*1 and *d*2 that define the required sums of numbers on the main and on the side diagonals of the square (1<=≤<=*r*1,<=*r*2,<=*c*1,<=*c*2,<=*d*1,<=*d*2<=≤<=20). Correspondence between the above 6 variables and places where they are written is shown on the picture below. For more clarifications please look at the second sample test that demonstrates the example given in the problem statement. You should write the solution as standard output as follows: Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes). If there are several solutions, output any. Here are example inputs and outputs for the problem: Example Input 1: 3 7 4 6 5 5 Example Output 1: 1 2 3 4 Example Input 2: 11 10 13 8 5 16 Example Output 2: 4 7 9 1 Example Input 3: 1 2 3 4 5 6 Example Output 3: -1 Example Input 4: 10 10 10 10 10 10 Example Output 4: -1 Now solve the problem by providing the code.
row1 , row2 = map(int,input().split()) col1 , col2 = map(int,input().split()) dia1 , dia2 = map(int,input().split()) message=1 b1 , b2 = 0,0 b3 , b4 = 0,0 for a in range(1,10): b1 = a for b in range(1,10): b2 = b for c in range(1,10): b3 = c for d in range(1,10): b4 = d if b1!=b2 and b1!=b3 and b1!=b4 and b2!=b3 and b2!=b4 and b3!=b4: if b1+b4==dia1 and b1+b2==row1 and b1+b3==col1 and b2+b4==col2 and b2+b3==dia2 and b3+b4==row2: print(b1,b2) print(b3,b4) message=0 if message==1: print(-1)
vfc_83593
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 7\n4 6\n5 5", "output": "1 2\n3 4", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
609
Solve the following coding problem using the programming language python: Sean is trying to save a large file to a USB flash drive. He has *n* USB flash drives with capacities equal to *a*1,<=*a*2,<=...,<=*a**n* megabytes. The file size is equal to *m* megabytes. Find the minimum number of USB flash drives needed to write Sean's file, if he can split the file between drives. The input will be provided via standard input and looks as follows: The first line contains positive integer *n* (1<=≤<=*n*<=≤<=100) — the number of USB flash drives. The second line contains positive integer *m* (1<=≤<=*m*<=≤<=105) — the size of Sean's file. Each of the next *n* lines contains positive integer *a**i* (1<=≤<=*a**i*<=≤<=1000) — the sizes of USB flash drives in megabytes. It is guaranteed that the answer exists, i. e. the sum of all *a**i* is not less than *m*. You should write the solution as standard output as follows: Print the minimum number of USB flash drives to write Sean's file, if he can split the file between drives. Here are example inputs and outputs for the problem: Example Input 1: 3 5 2 1 3 Example Output 1: 2 Example Input 2: 3 6 2 3 2 Example Output 2: 3 Example Input 3: 2 5 5 10 Example Output 3: 1 Now solve the problem by providing the code.
n = int(input()) m = int(input()) l = [] for i in range(n): s = int(input()) l.append(s) a =0 while(m>0): a+=1 k = max(l) c = l.index(k) m -=k l.pop(c) if(m<=0): break print(a)
vfc_83597
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n5\n2\n1\n3", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n6\n2\n3\n2", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n5\n5\n10", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n16\n8\n1\n3\n4\n9", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n121\n10\n37\n74\n56\n42\n39\n6\n68\n8\n100", "output": "2", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
386
Solve the following coding problem using the programming language python: In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction *n* bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the auction winner is the participant who offered the highest price. However, he pay not the price he offers, but the highest price among the offers of other participants (hence the name: the second-price auction). Write a program that reads prices offered by bidders and finds the winner and the price he will pay. Consider that all of the offered prices are different. The input will be provided via standard input and looks as follows: The first line of the input contains *n* (2<=≤<=*n*<=≤<=1000) — number of bidders. The second line contains *n* distinct integer numbers *p*1,<=*p*2,<=... *p**n*, separated by single spaces (1<=≤<=*p**i*<=≤<=10000), where *p**i* stands for the price offered by the *i*-th bidder. You should write the solution as standard output as follows: The single output line should contain two integers: index of the winner and the price he will pay. Indices are 1-based. Here are example inputs and outputs for the problem: Example Input 1: 2 5 7 Example Output 1: 2 5 Example Input 2: 3 10 2 8 Example Output 2: 1 8 Example Input 3: 6 3 8 2 9 4 14 Example Output 3: 6 9 Now solve the problem by providing the code.
n=int(input()) lst=list(map(int,input().split())) q=lst.index(max(lst))+1 lst.sort() p=lst[-2] print(q,p)
vfc_83601
{ "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\n5 7", "output": "2 5", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n10 2 8", "output": "1 8", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n3 8 2 9 4 14", "output": "6 9", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n4707 7586 4221 5842", "output": "2 5842", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n3304 4227 4869 6937 6002", "output": "4 6002", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
518
Solve the following coding problem using the programming language python: Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time. During the last lesson the teacher has provided two strings *s* and *t* to Vitaly. The strings have the same length, they consist of lowercase English letters, string *s* is lexicographically smaller than string *t*. Vitaly wondered if there is such string that is lexicographically larger than string *s* and at the same is lexicographically smaller than string *t*. This string should also consist of lowercase English letters and have the length equal to the lengths of strings *s* and *t*. Let's help Vitaly solve this easy problem! The input will be provided via standard input and looks as follows: The first line contains string *s* (1<=≤<=|*s*|<=≤<=100), consisting of lowercase English letters. Here, |*s*| denotes the length of the string. The second line contains string *t* (|*t*|<==<=|*s*|), consisting of lowercase English letters. It is guaranteed that the lengths of strings *s* and *t* are the same and string *s* is lexicographically less than string *t*. You should write the solution as standard output as follows: If the string that meets the given requirements doesn't exist, print a single string "No such string" (without the quotes). If such string exists, print it. If there are multiple valid strings, you may print any of them. Here are example inputs and outputs for the problem: Example Input 1: a c Example Output 1: b Example Input 2: aaa zzz Example Output 2: kkk Example Input 3: abcdefg abcdefh Example Output 3: No such string Now solve the problem by providing the code.
from bisect import bisect_left, bisect_right from collections import Counter, deque from functools import lru_cache from math import factorial, comb, sqrt, gcd, lcm from copy import deepcopy import heapq def num_to_str(n): chushu = (n - 1) // 26 yushu = (n - 1) % 26 if chushu == 0: return chr(yushu + ord("a")) else: return num_to_str(chushu) + chr(yushu + ord("a")) def main(): t = input() s = input() t_num = 0 s_num = 0 index = 0 for i in range(len(t) - 1, -1, -1): t_num += (ord(t[i]) - ord("a") + 1) * 26**index s_num += (ord(s[i]) - ord("a") + 1) * 26**index index += 1 if s_num > t_num + 1: print(num_to_str(t_num + 1)) else: print("No such string") if __name__ == "__main__": main()
vfc_83605
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "a\nc", "output": "b", "type": "stdin_stdout" }, { "fn_name": null, "input": "aaa\nzzz", "output": "kkk", "type": "stdin_stdout" }, { "fn_name": null, "input": "abcdefg\nabcdefh", "output": "No such string", "type": "stdin_stdout" }, { "fn_name": null, "input": "abcdefg\nabcfefg", "output": "abcdefh", "type": "stdin_stdout" }, { "fn_name": null, "input": "frt\nfru", "output": "No such string", "type": "stdin_stdout" }, { "fn_name": null, "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
603
Solve the following coding problem using the programming language python: Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length *n*. Each character of Kevin's string represents Kevin's score on one of the *n* questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not lost. Kevin is a big proponent of alternative thinking and believes that his score, instead of being the sum of his points, should be the length of the longest alternating subsequence of his string. Here, we define an alternating subsequence of a string as a not-necessarily contiguous subsequence where no two consecutive elements are equal. For example, {0,<=1,<=0,<=1}, {1,<=0,<=1}, and {1,<=0,<=1,<=0} are alternating sequences, while {1,<=0,<=0} and {0,<=1,<=0,<=1,<=1} are not. Kevin, being the sneaky little puffball that he is, is willing to hack into the USAICO databases to improve his score. In order to be subtle, he decides that he will flip exactly one substring—that is, take a contiguous non-empty substring of his score and change all '0's in that substring to '1's and vice versa. After such an operation, Kevin wants to know the length of the longest possible alternating subsequence that his string could have. The input will be provided via standard input and looks as follows: The first line contains the number of questions on the olympiad *n* (1<=≤<=*n*<=≤<=100<=000). The following line contains a binary string of length *n* representing Kevin's results on the USAICO. You should write the solution as standard output as follows: Output a single integer, the length of the longest possible alternating subsequence that Kevin can create in his string after flipping a single substring. Here are example inputs and outputs for the problem: Example Input 1: 8 10000011 Example Output 1: 5 Example Input 2: 2 01 Example Output 2: 2 Now solve the problem by providing the code.
n,s=int(input()),input() print(min(n,s.count('01')+s.count('10')+3))
vfc_83617
{ "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\n10000011", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n01", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n10101", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "75\n010101010101010101010101010101010101010101010101010101010101010101010101010", "output": "75", "type": "stdin_stdout" }, { "fn_name": null, "input": "11\n00000000000", "output": "3", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
399
Solve the following coding problem using the programming language python: User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are *n* pages numbered by integers from 1 to *n*. Assume that somebody is on the *p*-th page now. The navigation will look like this: When someone clicks the button "&lt;&lt;" he is redirected to page 1, and when someone clicks the button "&gt;&gt;" he is redirected to page *n*. Of course if someone clicks on a number, he is redirected to the corresponding page. There are some conditions in the navigation: - If page 1 is in the navigation, the button "&lt;&lt;" must not be printed. - If page *n* is in the navigation, the button "&gt;&gt;" must not be printed. - If the page number is smaller than 1 or greater than *n*, it must not be printed. You can see some examples of the navigations. Make a program that prints the navigation. The input will be provided via standard input and looks as follows: The first and the only line contains three integers *n*, *p*, *k* (3<=≤<=*n*<=≤<=100; 1<=≤<=*p*<=≤<=*n*; 1<=≤<=*k*<=≤<=*n*) You should write the solution as standard output as follows: Print the proper navigation. Follow the format of the output from the test samples. Here are example inputs and outputs for the problem: Example Input 1: 17 5 2 Example Output 1: &lt;&lt; 3 4 (5) 6 7 &gt;&gt; Example Input 2: 6 5 2 Example Output 2: &lt;&lt; 3 4 (5) 6 Example Input 3: 6 1 2 Example Output 3: (1) 2 3 &gt;&gt; Example Input 4: 6 2 2 Example Output 4: 1 (2) 3 4 &gt;&gt; Example Input 5: 9 6 3 Example Output 5: &lt;&lt; 3 4 5 (6) 7 8 9 Example Input 6: 10 6 3 Example Output 6: &lt;&lt; 3 4 5 (6) 7 8 9 &gt;&gt; Example Input 7: 8 5 4 Example Output 7: 1 2 3 4 (5) 6 7 8 Now solve the problem by providing the code.
n, p, k = map(int, input().split()) string = '' if p != 1 and p != n: if p - k <= 1: string += ' '.join(map(str, [i for i in range(1, p)])) string += ' ({}) '.format(p) else: string += '<< ' string += ' '.join(map(str, [i for i in range(p - k, p)])) string += ' ({}) '.format(p) if p + k >= n: string += ' '.join(map(str, [i for i in range(p + 1, n + 1)])) else: string += ' '.join(map(str, [i for i in range(p + 1, p + k + 1)])) string += ' >>' elif p == 1: string += '(1) ' if p + k >= n: string += ' '.join(map(str, [i for i in range(p + 1, n + 1)])) else: string += ' '.join(map(str, [i for i in range(p + 1, p + k + 1)])) string += ' >>' else: if p - k <= 1: string += ' '.join(map(str, [i for i in range(1, p)])) else: string += '<< ' string += ' '.join(map(str, [i for i in range(p - k, p)])) string += ' ({})'.format(n) print(string)
vfc_83621
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "500" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "17 5 2", "output": "<< 3 4 (5) 6 7 >> ", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 5 2", "output": "<< 3 4 (5) 6 ", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
602
Solve the following coding problem using the programming language python: After seeing the "ALL YOUR BASE ARE BELONG TO US" meme for the first time, numbers *X* and *Y* realised that they have different bases, which complicated their relations. You're given a number *X* represented in base *b**x* and a number *Y* represented in base *b**y*. Compare those two numbers. The input will be provided via standard input and looks as follows: The first line of the input contains two space-separated integers *n* and *b**x* (1<=≤<=*n*<=≤<=10, 2<=≤<=*b**x*<=≤<=40), where *n* is the number of digits in the *b**x*-based representation of *X*. The second line contains *n* space-separated integers *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x**i*<=&lt;<=*b**x*) — the digits of *X*. They are given in the order from the most significant digit to the least significant one. The following two lines describe *Y* in the same way: the third line contains two space-separated integers *m* and *b**y* (1<=≤<=*m*<=≤<=10, 2<=≤<=*b**y*<=≤<=40, *b**x*<=≠<=*b**y*), where *m* is the number of digits in the *b**y*-based representation of *Y*, and the fourth line contains *m* space-separated integers *y*1,<=*y*2,<=...,<=*y**m* (0<=≤<=*y**i*<=&lt;<=*b**y*) — the digits of *Y*. There will be no leading zeroes. Both *X* and *Y* will be positive. All digits of both numbers are given in the standard decimal numeral system. You should write the solution as standard output as follows: Output a single character (quotes for clarity): - '&lt;' if *X*<=&lt;<=*Y* - '&gt;' if *X*<=&gt;<=*Y* - '=' if *X*<==<=*Y* Here are example inputs and outputs for the problem: Example Input 1: 6 2 1 0 1 1 1 1 2 10 4 7 Example Output 1: = Example Input 2: 3 3 1 0 2 2 5 2 4 Example Output 2: &lt; Example Input 3: 7 16 15 15 4 0 0 7 10 7 9 4 8 0 3 1 5 0 Example Output 3: &gt; Now solve the problem by providing the code.
# import sys # sys.stdin = open('cf602a.in') n, bx = map(int, input().split()) x = list(map(int, input().split())) m, by = map(int, input().split()) y = list(map(int, input().split())) xx = sum(v * bx**(len(x) - i - 1) for i, v in enumerate(x)) yy = sum(v * by**(len(y) - i - 1) for i, v in enumerate(y)) if xx < yy: print('<') elif xx == yy: print('=') else: print('>')
vfc_83625
{ "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\n1 0 1 1 1 1\n2 10\n4 7", "output": "=", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n1 0 2\n2 5\n2 4", "output": "<", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
958
Solve the following coding problem using the programming language python: The Rebel fleet is afraid that the Empire might want to strike back again. Princess Heidi needs to know if it is possible to assign *R* Rebel spaceships to guard *B* bases so that every base has exactly one guardian and each spaceship has exactly one assigned base (in other words, the assignment is a perfect matching). Since she knows how reckless her pilots are, she wants to be sure that any two (straight) paths – from a base to its assigned spaceship – do not intersect in the galaxy plane (that is, in 2D), and so there is no risk of collision. The input will be provided via standard input and looks as follows: The first line contains two space-separated integers *R*,<=*B*(1<=≤<=*R*,<=*B*<=≤<=10). For 1<=≤<=*i*<=≤<=*R*, the *i*<=+<=1-th line contains two space-separated integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=10000) denoting the coordinates of the *i*-th Rebel spaceship. The following *B* lines have the same format, denoting the position of bases. It is guaranteed that no two points coincide and that no three points are on the same line. You should write the solution as standard output as follows: If it is possible to connect Rebel spaceships and bases so as satisfy the constraint, output Yes, otherwise output No (without quote). Here are example inputs and outputs for the problem: Example Input 1: 3 3 0 0 2 0 3 1 -2 1 0 3 2 2 Example Output 1: Yes Example Input 2: 2 1 1 0 2 2 3 1 Example Output 2: No Now solve the problem by providing the code.
def ccw(A, B, C): return (C[1] - A[1]) * (B[0] - A[0]) > (B[1] - A[1]) * (C[0] - A[0]) def intersect(A, B, C, D): return ccw(A, C, D) != ccw(B, C, D) and ccw(A, B, C) != ccw(A, B, D) R, B = map(int, input().split()) rs = [] bs = [] for r in range(R): rs.append(list(map(int, input().split()))) for r in range(B): bs.append(list(map(int, input().split()))) if R != B: print('No') else: def rec(at, done, remain): if at >= B: return True for b in remain: for r, d in zip(rs, done): if intersect(r, bs[d], rs[at], bs[b]): break else: ok = rec(at + 1, done + [b], remain - {b}) if ok: return True return False print(['NO', 'YES'][rec(0, [], set(range(B)))])
vfc_83633
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2500" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\n0 0\n2 0\n3 1\n-2 1\n0 3\n2 2", "output": "Yes", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1\n1 0\n2 2\n3 1", "output": "No", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n3686 4362\n-7485 5112", "output": "Yes", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 2\n1152 -7324\n-5137 -35\n-6045 -5271", "output": "No", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 3\n-8824 -9306\n-5646 -9767\n8123 9355\n-6203 -1643", "output": "No", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 5\n-8775 6730\n-3806 -6906\n-9256 -8240\n-1320 6849\n8155 746\n8284 -7317", "output": "No", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
466
Solve the following coding problem using the programming language python: Ann has recently started commuting by subway. We know that a one ride subway ticket costs *a* rubles. Besides, Ann found out that she can buy a special ticket for *m* rides (she can buy it several times). It costs *b* rubles. Ann did the math; she will need to use subway *n* times. Help Ann, tell her what is the minimum sum of money she will have to spend to make *n* rides? The input will be provided via standard input and looks as follows: The single line contains four space-separated integers *n*, *m*, *a*, *b* (1<=≤<=*n*,<=*m*,<=*a*,<=*b*<=≤<=1000) — the number of rides Ann has planned, the number of rides covered by the *m* ride ticket, the price of a one ride ticket and the price of an *m* ride ticket. You should write the solution as standard output as follows: Print a single integer — the minimum sum in rubles that Ann will need to spend. Here are example inputs and outputs for the problem: Example Input 1: 6 2 1 2 Example Output 1: 6 Example Input 2: 5 2 2 3 Example Output 2: 8 Now solve the problem by providing the code.
import math numbers = input('') numbers = numbers.split(' ') numbers = [int(i) for i in numbers] n = numbers[0] m = numbers[1] a = numbers[2] b = numbers[3] without_special = n * a with_special = ((math.ceil(n / m) * m) / m) * b hybrid = (math.floor(n / m) * b) + ((n % m) * a) print(int(min(without_special, with_special, hybrid)))
vfc_83637
{ "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 1 2", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 2 2 3", "output": "8", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 3 5 1", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000 1 1000 1000", "output": "1000000", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
985
Solve the following coding problem using the programming language python: You are given *n* switches and *m* lamps. The *i*-th switch turns on some subset of the lamps. This information is given as the matrix *a* consisting of *n* rows and *m* columns where *a**i*,<=*j*<==<=1 if the *i*-th switch turns on the *j*-th lamp and *a**i*,<=*j*<==<=0 if the *i*-th switch is not connected to the *j*-th lamp. Initially all *m* lamps are turned off. Switches change state only from "off" to "on". It means that if you press two or more switches connected to the same lamp then the lamp will be turned on after any of this switches is pressed and will remain its state even if any switch connected to this lamp is pressed afterwards. It is guaranteed that if you push all *n* switches then all *m* lamps will be turned on. Your think that you have too many switches and you would like to ignore one of them. Your task is to say if there exists such a switch that if you will ignore (not use) it but press all the other *n*<=-<=1 switches then all the *m* lamps will be turned on. 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<=≤<=*n*,<=*m*<=≤<=2000) — the number of the switches and the number of the lamps. The following *n* lines contain *m* characters each. The character *a**i*,<=*j* is equal to '1' if the *i*-th switch turns on the *j*-th lamp and '0' otherwise. It is guaranteed that if you press all *n* switches all *m* lamps will be turned on. You should write the solution as standard output as follows: Print "YES" if there is a switch that if you will ignore it and press all the other *n*<=-<=1 switches then all *m* lamps will be turned on. Print "NO" if there is no such switch. Here are example inputs and outputs for the problem: Example Input 1: 4 5 10101 01000 00111 10000 Example Output 1: YES Example Input 2: 4 5 10100 01000 00110 00101 Example Output 2: NO Now solve the problem by providing the code.
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon May 21 22:31:07 2018 @author: thomas """ integers=input() [n,m]=[int(x) for x in integers.split()] a=[] for i in range(n): row_i=input() a_i=[] for j in range(m): a_i.append(int(row_i[j])) a.append(a_i) indicator=False #all_sum=[0]*m #for i in range(n): # for j in range(m): # all_sum[j]+=a[i][j] all_sum=[sum(x) for x in zip(*a)] for i in range(n): consider=[x-y for x, y in zip(all_sum, a[i])] indicator=(sum([x>0 for x in consider])==m) if (indicator==True): break if (indicator==True): print("YES") else: print("NO")
vfc_83641
{ "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 5\n10101\n01000\n00111\n10000", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 5\n10100\n01000\n00110\n00101", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 5\n11111", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 1\n1\n0\n0\n0\n0\n0\n0\n0\n0\n1", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n1", "output": "NO", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
209
Solve the following coding problem using the programming language python: Polycarpus plays with red and blue marbles. He put *n* marbles from the left to the right in a row. As it turned out, the marbles form a zebroid. A non-empty sequence of red and blue marbles is a zebroid, if the colors of the marbles in this sequence alternate. For example, sequences (red; blue; red) and (blue) are zebroids and sequence (red; red) is not a zebroid. Now Polycarpus wonders, how many ways there are to pick a zebroid subsequence from this sequence. Help him solve the problem, find the number of ways modulo 1000000007 (109<=+<=7). The input will be provided via standard input and looks as follows: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=106) — the number of marbles in Polycarpus's sequence. You should write the solution as standard output as follows: Print a single number — the answer to the problem modulo 1000000007 (109<=+<=7). Here are example inputs and outputs for the problem: Example Input 1: 3 Example Output 1: 6 Example Input 2: 4 Example Output 2: 11 Now solve the problem by providing the code.
import sys input = lambda: sys.stdin.readline().rstrip() MOD = 10**9+7 N = int(input()) dp = [[0,0] for _ in range(N+1)] for i in range(N): dp[i+1][0]=dp[i][0] dp[i+1][1]=dp[i][1] if i%2: dp[i+1][1]+=dp[i][0]+1 else: dp[i+1][0]+=dp[i][1]+1 dp[i+1][0]%=MOD dp[i+1][1]%=MOD print(sum(dp[-1])%MOD)
vfc_83645
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "4", "output": "11", "type": "stdin_stdout" }, { "fn_name": null, "input": "1", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
892
Solve the following coding problem using the programming language python: Jafar has *n* cans of cola. Each can is described by two integers: remaining volume of cola *a**i* and can's capacity *b**i* (*a**i* <=≤<= *b**i*). Jafar has decided to pour all remaining cola into just 2 cans, determine if he can do this or not! The input will be provided via standard input and looks as follows: The first line of the input contains one integer *n* (2<=≤<=*n*<=≤<=100<=000) — number of cola cans. The second line contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) — volume of remaining cola in cans. The third line contains *n* space-separated integers that *b*1,<=*b*2,<=...,<=*b**n* (*a**i*<=≤<=*b**i*<=≤<=109) — capacities of the cans. You should write the solution as standard output as follows: Print "YES" (without quotes) if it is possible to pour all remaining cola in 2 cans. Otherwise print "NO" (without quotes). You can print each letter in any case (upper or lower). Here are example inputs and outputs for the problem: Example Input 1: 2 3 5 3 6 Example Output 1: YES Example Input 2: 3 6 8 9 6 10 12 Example Output 2: NO Example Input 3: 5 0 0 5 0 0 1 1 8 10 5 Example Output 3: YES Example Input 4: 4 4 1 0 3 5 2 2 3 Example Output 4: YES Now solve the problem by providing the code.
n=int(input()) left=[int(x) for x in input().split()] cap=[int(x) for x in input().split()] m1=max(cap) l=cap;l.remove(m1); m2=max(l) if m1+m2>=sum(left): print("YES") else: print('NO')
vfc_83653
{ "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\n3 5\n3 6", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n6 8 9\n6 10 12", "output": "NO", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
357
Solve the following coding problem using the programming language python: At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According to the results, each student got some score from 1 to *m* points. We know that *c*1 schoolchildren got 1 point, *c*2 children got 2 points, ..., *c**m* children got *m* points. Now you need to set the passing rate *k* (integer from 1 to *m*): all schoolchildren who got less than *k* points go to the beginner group and those who get at strictly least *k* points go to the intermediate group. We know that if the size of a group is more than *y*, then the university won't find a room for them. We also know that if a group has less than *x* schoolchildren, then it is too small and there's no point in having classes with it. So, you need to split all schoolchildren into two groups so that the size of each group was from *x* to *y*, inclusive. Help the university pick the passing rate in a way that meets these requirements. The input will be provided via standard input and looks as follows: The first line contains integer *m* (2<=≤<=*m*<=≤<=100). The second line contains *m* integers *c*1, *c*2, ..., *c**m*, separated by single spaces (0<=≤<=*c**i*<=≤<=100). The third line contains two space-separated integers *x* and *y* (1<=≤<=*x*<=≤<=*y*<=≤<=10000). At least one *c**i* is greater than 0. You should write the solution as standard output as follows: If it is impossible to pick a passing rate in a way that makes the size of each resulting groups at least *x* and at most *y*, print 0. Otherwise, print an integer from 1 to *m* — the passing rate you'd like to suggest. If there are multiple possible answers, print any of them. Here are example inputs and outputs for the problem: Example Input 1: 5 3 4 3 2 1 6 8 Example Output 1: 3 Example Input 2: 5 0 3 3 4 2 3 10 Example Output 2: 4 Example Input 3: 2 2 5 3 6 Example Output 3: 0 Now solve the problem by providing the code.
estudiantes = int(input()) calificaciones = list(str(input()).split()) xy = list(str(input()).split()) contador1 = 0 contador2 = 0 partitura = 0 entro = False for i in range(len(calificaciones)): calificaciones[i] = int(calificaciones[i]) xy[0] = int(xy[0]) xy[1] = int(xy[1]) for j in range(len(calificaciones)): contador1 = 0 contador2 = 0 for i in range(0,j): contador1 += calificaciones[i] for k in range(j,len(calificaciones)): contador2 += calificaciones[k] if (contador1 >= xy[0] and contador1<=xy[1])and(contador2 >= xy[0] and contador2<=xy[1]): entro = True partitura = j break if entro == True: partitura+=1 print(partitura)
vfc_83657
{ "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\n3 4 3 2 1\n6 8", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n0 3 3 4 2\n3 10", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2 5\n3 6", "output": "0", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
851
Solve the following coding problem using the programming language python: Arpa is researching the Mexican wave. There are *n* spectators in the stadium, labeled from 1 to *n*. They start the Mexican wave at time 0. - At time 1, the first spectator stands. - At time 2, the second spectator stands. - ... - At time *k*, the *k*-th spectator stands. - At time *k*<=+<=1, the (*k*<=+<=1)-th spectator stands and the first spectator sits. - At time *k*<=+<=2, the (*k*<=+<=2)-th spectator stands and the second spectator sits. - ... - At time *n*, the *n*-th spectator stands and the (*n*<=-<=*k*)-th spectator sits. - At time *n*<=+<=1, the (*n*<=+<=1<=-<=*k*)-th spectator sits. - ... - At time *n*<=+<=*k*, the *n*-th spectator sits. Arpa wants to know how many spectators are standing at time *t*. The input will be provided via standard input and looks as follows: The first line contains three integers *n*, *k*, *t* (1<=≤<=*n*<=≤<=109, 1<=≤<=*k*<=≤<=*n*, 1<=≤<=*t*<=&lt;<=*n*<=+<=*k*). You should write the solution as standard output as follows: Print single integer: how many spectators are standing at time *t*. Here are example inputs and outputs for the problem: Example Input 1: 10 5 3 Example Output 1: 3 Example Input 2: 10 5 7 Example Output 2: 5 Example Input 3: 10 5 12 Example Output 3: 3 Now solve the problem by providing the code.
mass = input().split() n = int(mass[0]) k = int(mass[1]) t = int(mass[2]) '''for i in range(1, t + 1): if i <= k: result = result + 1 elif i <= n: result = result else: result = result - 1 ''' if t <= k: print(t) elif t <= n: print(k) else: print(k - (t % n))
vfc_83661
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 5 3", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 5 7", "output": "5", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
453
Solve the following coding problem using the programming language python: Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in the dice that were used in the game. The dice has *m* faces: the first face of the dice contains a dot, the second one contains two dots, and so on, the *m*-th face contains *m* dots. Twilight Sparkle is sure that when the dice is tossed, each face appears with probability . Also she knows that each toss is independent from others. Help her to calculate the expected maximum number of dots she could get after tossing the dice *n* times. The input will be provided via standard input and looks as follows: A single line contains two integers *m* and *n* (1<=≤<=*m*,<=*n*<=≤<=105). You should write the solution as standard output as follows: Output a single real number corresponding to the expected maximum. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=<=-<=4. Here are example inputs and outputs for the problem: Example Input 1: 6 1 Example Output 1: 3.500000000000 Example Input 2: 6 3 Example Output 2: 4.958333333333 Example Input 3: 2 2 Example Output 3: 1.750000000000 Now solve the problem by providing the code.
def prob(m, n): ans = 0.0 i = m while (i): ans += (pow(i / m, n) - pow((i - 1) / m, n)) * i i = i - 1 return ans m, n = map(int, input().split()) print(prob(m, n))
vfc_83665
{ "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 1", "output": "3.500000000000", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
768
Solve the following coding problem using the programming language python: "Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher on the walls. I am the shield that guards the realms of men. I pledge my life and honor to the Night's Watch, for this night and all the nights to come." — The Night's Watch oath. With that begins the watch of Jon Snow. He is assigned the task to support the stewards. This time he has *n* stewards with him whom he has to provide support. Each steward has his own strength. Jon Snow likes to support a steward only if there exists at least one steward who has strength strictly less than him and at least one steward who has strength strictly greater than him. Can you find how many stewards will Jon support? The input will be provided via standard input and looks as follows: First line consists of a single integer *n* (1<=≤<=*n*<=≤<=105) — the number of stewards with Jon Snow. Second line consists of *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=109) representing the values assigned to the stewards. You should write the solution as standard output as follows: Output a single integer representing the number of stewards which Jon will feed. Here are example inputs and outputs for the problem: Example Input 1: 2 1 5 Example Output 1: 0 Example Input 2: 3 1 2 5 Example Output 2: 1 Now solve the problem by providing the code.
x = int(input()) s = list(map(int,input().split())) c = 0 max = max(s) min = min(s) for i in range(0,x): if s[i] != max and s[i]!=min: c = c + 1 print(c)
vfc_83669
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1 5", "output": "0", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
344
Solve the following coding problem using the programming language python: Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the opposite poles will attract each other. Mike starts by laying one magnet horizontally on the table. During each following step Mike adds one more magnet horizontally to the right end of the row. Depending on how Mike puts the magnet on the table, it is either attracted to the previous one (forming a group of multiple magnets linked together) or repelled by it (then Mike lays this magnet at some distance to the right from the previous one). We assume that a sole magnet not linked to others forms a group of its own. Mike arranged multiple magnets in a row. Determine the number of groups that the magnets formed. The input will be provided via standard input and looks as follows: The first line of the input contains an integer *n* (1<=≤<=*n*<=≤<=100000) — the number of magnets. Then *n* lines follow. The *i*-th line (1<=≤<=*i*<=≤<=*n*) contains either characters "01", if Mike put the *i*-th magnet in the "plus-minus" position, or characters "10", if Mike put the magnet in the "minus-plus" position. You should write the solution as standard output as follows: On the single line of the output print the number of groups of magnets. Here are example inputs and outputs for the problem: Example Input 1: 6 10 10 10 01 10 10 Example Output 1: 3 Example Input 2: 4 01 01 10 10 Example Output 2: 2 Now solve the problem by providing the code.
n=int(input()) m_o=[input() for _ in range(n)] grp=1 for i in range(1,n): if m_o[i]!=m_o[i-1]: grp+=1 print(grp)
vfc_83673
{ "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\n10\n10\n10\n01\n10\n10", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n01\n01\n10\n10", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n10", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
779
Solve the following coding problem using the programming language python: Igor found out discounts in a shop and decided to buy *n* items. Discounts at the store will last for a week and Igor knows about each item that its price now is *a**i*, and after a week of discounts its price will be *b**i*. Not all of sellers are honest, so now some products could be more expensive than after a week of discounts. Igor decided that buy at least *k* of items now, but wait with the rest of the week in order to save money as much as possible. Your task is to determine the minimum money that Igor can spend to buy all *n* items. The input will be provided via standard input and looks as follows: In the first line there are two positive integer numbers *n* and *k* (1<=≤<=*n*<=≤<=2·105, 0<=≤<=*k*<=≤<=*n*) — total number of items to buy and minimal number of items Igor wants to by right now. The second line contains sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=104) — prices of items during discounts (i.e. right now). The third line contains sequence of integers *b*1,<=*b*2,<=...,<=*b**n* (1<=≤<=*b**i*<=≤<=104) — prices of items after discounts (i.e. after a week). You should write the solution as standard output as follows: Print the minimal amount of money Igor will spend to buy all *n* items. Remember, he should buy at least *k* items right now. Here are example inputs and outputs for the problem: Example Input 1: 3 1 5 4 6 3 1 5 Example Output 1: 10 Example Input 2: 5 3 3 4 7 10 3 4 5 5 12 5 Example Output 2: 25 Now solve the problem by providing the code.
import sys from os import path if (path.exists('input.txt') and path.exists('output.txt')): sys.stdout = open('output.txt', 'w') sys.stdin = open('input.txt', 'r') def main(): n, k = (int(i) for i in input().split()) a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] diffs = sorted([a[i] - b[i] for i in range(n)]) ans = sum(a) for diff in diffs: if diff < 0 or k > 0: k -= 1 else: ans -= diff print(ans) main()
vfc_83677
{ "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 1\n5 4 6\n3 1 5", "output": "10", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3\n3 4 7 10 3\n4 5 5 12 5", "output": "25", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 0\n9\n8", "output": "8", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 0\n4 10\n1 2", "output": "3", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
1000
Solve the following coding problem using the programming language python: You are given $n$ segments on a coordinate line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide. Your task is the following: for every $k \in [1..n]$, calculate the number of points with integer coordinates such that the number of segments that cover these points equals $k$. A segment with endpoints $l_i$ and $r_i$ covers point $x$ if and only if $l_i \le x \le r_i$. The input will be provided via standard input and looks as follows: The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of segments. The next $n$ lines contain segments. The $i$-th line contains a pair of integers $l_i, r_i$ ($0 \le l_i \le r_i \le 10^{18}$) — the endpoints of the $i$-th segment. You should write the solution as standard output as follows: Print $n$ space separated integers $cnt_1, cnt_2, \dots, cnt_n$, where $cnt_i$ is equal to the number of points such that the number of segments that cover these points equals to $i$. Here are example inputs and outputs for the problem: Example Input 1: 3 0 3 1 3 3 8 Example Output 1: 6 2 1 Example Input 2: 3 1 3 2 4 5 7 Example Output 2: 5 2 0 Now solve the problem by providing the code.
import collections if __name__ == '__main__': n = int(input()) ans = collections.defaultdict(int) for i in range(n): l, r = list(map(int, input().strip().split())) ans[l] += 1; ans[r + 1] -= 1 ans = dict(sorted(ans.items(), key=lambda k: k[0])) keys = list(ans.keys()) tot = len(keys) for i in range(1, tot): ans[keys[i]] += ans[keys[i - 1]] res = [0] * (n + 1) for i in range(tot - 1): res[ans[keys[i]]] += keys[i + 1] - keys[i] for i in range(1, n): print(res[i], end=" ") print(res[n])
vfc_83681
{ "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\n0 3\n1 3\n3 8", "output": "6 2 1 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 3\n2 4\n5 7", "output": "5 2 0 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n0 1000000000000000000", "output": "1000000000000000001 ", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
865
Solve the following coding problem using the programming language python: Attention: we lost all the test cases for this problem, so instead of solving the problem, we need you to generate test cases. We're going to give you the answer, and you need to print a test case that produces the given answer. The original problem is in the following paragraph. People don't use cash as often as they used to. Having a credit card solves some of the hassles of cash, such as having to receive change when you can't form the exact amount of money needed to purchase an item. Typically cashiers will give you as few coins as possible in change, but they don't have to. For example, if your change is 30 cents, a cashier could give you a 5 cent piece and a 25 cent piece, or they could give you three 10 cent pieces, or ten 1 cent pieces, two 5 cent pieces, and one 10 cent piece. Altogether there are 18 different ways to make 30 cents using only 1 cent pieces, 5 cent pieces, 10 cent pieces, and 25 cent pieces. Two ways are considered different if they contain a different number of at least one type of coin. Given the denominations of the coins and an amount of change to be made, how many different ways are there to make change? As we mentioned before, we lost all the test cases for this problem, so we're actually going to give you the number of ways, and want you to produce a test case for which the number of ways is the given number. There could be many ways to achieve this (we guarantee there's always at least one), so you can print any, as long as it meets the constraints described below. The input will be provided via standard input and looks as follows: Input will consist of a single integer *A* (1<=≤<=*A*<=≤<=105), the desired number of ways. You should write the solution as standard output as follows: In the first line print integers *N* and *M* (1<=≤<=*N*<=≤<=106,<=1<=≤<=*M*<=≤<=10), the amount of change to be made, and the number of denominations, respectively. Then print *M* integers *D*1,<=*D*2,<=...,<=*D**M* (1<=≤<=*D**i*<=≤<=106), the denominations of the coins. All denominations must be distinct: for any *i*<=≠<=*j* we must have *D**i*<=≠<=*D**j*. If there are multiple tests, print any of them. You can print denominations in atbitrary order. Here are example inputs and outputs for the problem: Example Input 1: 18 Example Output 1: 30 4 1 5 10 25 Example Input 2: 3 Example Output 2: 20 2 5 2 Example Input 3: 314 Example Output 3: 183 4 6 5 2 139 Now solve the problem by providing the code.
n=int(input()) print(2*n-1, 2) print(1, 2)
vfc_83689
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "18", "output": "30 4\n1 5 10 25", "type": "stdin_stdout" }, { "fn_name": null, "input": "3", "output": "20 2\n5 2", "type": "stdin_stdout" }, { "fn_name": null, "input": "314", "output": "183 4\n6 5 2 139", "type": "stdin_stdout" }, { "fn_name": null, "input": "1023", "output": "2045 2\n1 2", "type": "stdin_stdout" }, { "fn_name": null, "input": "100000", "output": "199999 2\n1 2", "type": "stdin_stdout" }, { "fn_name": null, "input": "1", "output": "1 2\n1 2", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
161
Solve the following coding problem using the programming language python: The Two-dimensional kingdom is going through hard times... This morning the Three-Dimensional kingdom declared war on the Two-dimensional one. This (possibly armed) conflict will determine the ultimate owner of the straight line. The Two-dimensional kingdom has a regular army of *n* people. Each soldier registered himself and indicated the desired size of the bulletproof vest: the *i*-th soldier indicated size *a**i*. The soldiers are known to be unpretentious, so the command staff assumes that the soldiers are comfortable in any vests with sizes from *a**i*<=-<=*x* to *a**i*<=+<=*y*, inclusive (numbers *x*,<=*y*<=≥<=0 are specified). The Two-dimensional kingdom has *m* vests at its disposal, the *j*-th vest's size equals *b**j*. Help mobilize the Two-dimensional kingdom's army: equip with vests as many soldiers as possible. Each vest can be used only once. The *i*-th soldier can put on the *j*-th vest, if *a**i*<=-<=*x*<=≤<=*b**j*<=≤<=*a**i*<=+<=*y*. The input will be provided via standard input and looks as follows: The first input line contains four integers *n*, *m*, *x* and *y* (1<=≤<=*n*,<=*m*<=≤<=105, 0<=≤<=*x*,<=*y*<=≤<=109) — the number of soldiers, the number of vests and two numbers that specify the soldiers' unpretentiousness, correspondingly. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109) in non-decreasing order, separated by single spaces — the desired sizes of vests. The third line contains *m* integers *b*1,<=*b*2,<=...,<=*b**m* (1<=≤<=*b**j*<=≤<=109) in non-decreasing order, separated by single spaces — the sizes of the available vests. You should write the solution as standard output as follows: In the first line print a single integer *k* — the maximum number of soldiers equipped with bulletproof vests. In the next *k* lines print *k* pairs, one pair per line, as "*u**i* *v**i*" (without the quotes). Pair (*u**i*, *v**i*) means that soldier number *u**i* must wear vest number *v**i*. Soldiers and vests are numbered starting from one in the order in which they are specified in the input. All numbers of soldiers in the pairs should be pairwise different, all numbers of vests in the pairs also should be pairwise different. You can print the pairs in any order. If there are multiple optimal answers, you are allowed to print any of them. Here are example inputs and outputs for the problem: Example Input 1: 5 3 0 0 1 2 3 3 4 1 3 5 Example Output 1: 2 1 1 3 2 Example Input 2: 3 3 2 2 1 5 9 3 5 7 Example Output 2: 3 1 1 2 2 3 3 Now solve the problem by providing the code.
# 161A-sua bai >> accepted # n: num of solder # m: num of vest # x: margin duoi # y: margin tren # chu giai giai thuat: i chay tu 0>>n, neu ao vest b[j] nho hon (a[i]-x), thi tang j (xet bo ao vest tiep theo) cho toi khi tim # thay j phu hop, sau do xet xem ung voi j do, ao vest co phu hop voi soldier i ko (b[j]<(a[i]+y)), neu phu hop thi luu cap i,j # do lai, neu khong phu hop thi tang i (bang vong for) n,m,x,y = map(int,input().split()) a = list(map(int,input().split())) # list size soldier b = list(map(int,input().split())) # list cac size ao j=0 u = [] for i in range (n): if (j==m): break # print (b[j]) # print (a[i]-x) while ((b[j]<(a[i]-x))): # print ('i=',i) # print ('j=',j) j+=1 if (j==m): break if (j==m): break if (b[j]<=(a[i]+y)): u.append([i+1,j+1]) j+=1 print (len(u)) for i in range (len(u)): print ('%d %d'%(u[i][0],u[i][1]))
vfc_83693
{ "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 3 0 0\n1 2 3 3 4\n1 3 5", "output": "2\n1 1\n3 2", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3 2 2\n1 5 9\n3 5 7", "output": "3\n1 1\n2 2\n3 3", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1 0 0\n1\n1", "output": "1\n1 1", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1 0 0\n1\n2", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3 1 4\n1 5\n1 2 2", "output": "1\n1 1", "type": "stdin_stdout" }, { "fn_name": null, "input": "20 30 1 4\n1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 4 4 4 5\n1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 4 4 4 4 4 4 4 4 5 5", "output": "20\n1 1\n2 2\n3 3\n4 4\n5 5\n6 6\n7 7\n8 8\n9 9\n10 10\n11 11\n12 12\n13 15\n14 16\n15 17\n16 18\n17 19\n18 20\n19 21\n20 22", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
812
Solve the following coding problem using the programming language python: Some people leave the lights at their workplaces on when they leave that is a waste of resources. As a hausmeister of DHBW, Sagheer waits till all students and professors leave the university building, then goes and turns all the lights off. The building consists of *n* floors with stairs at the left and the right sides. Each floor has *m* rooms on the same line with a corridor that connects the left and right stairs passing by all the rooms. In other words, the building can be represented as a rectangle with *n* rows and *m*<=+<=2 columns, where the first and the last columns represent the stairs, and the *m* columns in the middle represent rooms. Sagheer is standing at the ground floor at the left stairs. He wants to turn all the lights off in such a way that he will not go upstairs until all lights in the floor he is standing at are off. Of course, Sagheer must visit a room to turn the light there off. It takes one minute for Sagheer to go to the next floor using stairs or to move from the current room/stairs to a neighboring room/stairs on the same floor. It takes no time for him to switch the light off in the room he is currently standing in. Help Sagheer find the minimum total time to turn off all the lights. Note that Sagheer does not have to go back to his starting position, and he does not have to visit rooms where the light is already switched off. The input will be provided via standard input and looks as follows: The first line contains two integers *n* and *m* (1<=≤<=*n*<=≤<=15 and 1<=≤<=*m*<=≤<=100) — the number of floors and the number of rooms in each floor, respectively. The next *n* lines contains the building description. Each line contains a binary string of length *m*<=+<=2 representing a floor (the left stairs, then *m* rooms, then the right stairs) where 0 indicates that the light is off and 1 indicates that the light is on. The floors are listed from top to bottom, so that the last line represents the ground floor. The first and last characters of each string represent the left and the right stairs, respectively, so they are always 0. You should write the solution as standard output as follows: Print a single integer — the minimum total time needed to turn off all the lights. Here are example inputs and outputs for the problem: Example Input 1: 2 2 0010 0100 Example Output 1: 5 Example Input 2: 3 4 001000 000010 000010 Example Output 2: 12 Example Input 3: 4 3 01110 01110 01110 01110 Example Output 3: 18 Now solve the problem by providing the code.
#!/usr/bin/env python3 # -*- coding: utf-8 -*- n,m=map(int,input().strip().split()) a=[] L=[] R=[] t={} for i in range(n): b=input() a.append(b) L.append(9000000) R.append(0) t[i]=0 a.reverse() for i in range(n): for j in range(m+2): if a[i][j]=='1': L[i]=min(L[i],j) R[i]=max(R[i],j) t[i]=1 L1=0 R1=9000000 ans=0 for i in range(n): if t[i]==0: L1+=1 R1+=1 continue ans=min(L1+R[i],R1+m+1-L[i]) L2=min(L1+R[i]*2+1,R1+m+2) R2=min(R1+(m+1-L[i])*2+1,m+2+L1) L1=L2 R1=R2 print(ans)
vfc_83697
{ "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 2\n0010\n0100", "output": "5", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
355
Solve the following coding problem using the programming language python: Vasya has recently found out what a digital root of a number is and he decided to share his knowledge with you. Let's assume that *S*(*n*) is the sum of digits of number *n*, for example, *S*(4098)<==<=4<=+<=0<=+<=9<=+<=8<==<=21. Then the digital root of number *n* equals to: 1. *dr*(*n*)<==<=*S*(*n*), if *S*(*n*)<=&lt;<=10; 1. *dr*(*n*)<==<=*dr*(<=*S*(*n*)<=), if *S*(*n*)<=≥<=10. For example, *dr*(4098)<=<==<=<=*dr*(21)<=<==<=<=3. Vasya is afraid of large numbers, so the numbers he works with are at most 101000. For all such numbers, he has proved that *dr*(*n*)<=<==<=<=*S*(<=*S*(<=*S*(<=*S*(*n*)<=)<=)<=) (*n*<=≤<=101000). Now Vasya wants to quickly find numbers with the given digital root. The problem is, he hasn't learned how to do that and he asked you to help him. You task is, given numbers *k* and *d*, find the number consisting of exactly *k* digits (the leading zeroes are not allowed), with digital root equal to *d*, or else state that such number does not exist. The input will be provided via standard input and looks as follows: The first line contains two integers *k* and *d* (1<=≤<=*k*<=≤<=1000; 0<=≤<=*d*<=≤<=9). You should write the solution as standard output as follows: In a single line print either any number that meets the requirements (without the leading zeroes) or "No solution" (without the quotes), if the corresponding number does not exist. The chosen number must consist of exactly *k* digits. We assume that number 0 doesn't contain any leading zeroes. Here are example inputs and outputs for the problem: Example Input 1: 4 4 Example Output 1: 5881 Example Input 2: 5 1 Example Output 2: 36172 Example Input 3: 1 0 Example Output 3: 0 Now solve the problem by providing the code.
k,d = input().split() k,d = int(k), int(d) if k==1: print(d) elif d!=0: s = '1'*(k-1) m = int(s) m = 9*m + d print(m) else: print("No solution")
vfc_83701
{ "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 4", "output": "5881", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 1", "output": "36172", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 0", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "8 7", "output": "49722154", "type": "stdin_stdout" }, { "fn_name": null, "input": "487 0", "output": "No solution", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
414
Solve the following coding problem using the programming language python: It's holiday. Mashmokh and his boss, Bimokh, are playing a game invented by Mashmokh. In this game Mashmokh writes sequence of *n* distinct integers on the board. Then Bimokh makes several (possibly zero) moves. On the first move he removes the first and the second integer from from the board, on the second move he removes the first and the second integer of the remaining sequence from the board, and so on. Bimokh stops when the board contains less than two numbers. When Bimokh removes numbers *x* and *y* from the board, he gets *gcd*(*x*,<=*y*) points. At the beginning of the game Bimokh has zero points. Mashmokh wants to win in the game. For this reason he wants his boss to get exactly *k* points in total. But the guy doesn't know how choose the initial sequence in the right way. Please, help him. Find *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* such that his boss will score exactly *k* points. Also Mashmokh can't memorize too huge numbers. Therefore each of these integers must be at most 109. The input will be provided via standard input and looks as follows: The first line of input contains two space-separated integers *n*,<=*k* (1<=≤<=*n*<=≤<=105; 0<=≤<=*k*<=≤<=108). You should write the solution as standard output as follows: If such sequence doesn't exist output -1 otherwise output *n* distinct space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=109). Here are example inputs and outputs for the problem: Example Input 1: 5 2 Example Output 1: 1 2 3 4 5 Example Input 2: 5 3 Example Output 2: 2 4 3 7 1 Example Input 3: 7 2 Example Output 3: -1 Now solve the problem by providing the code.
# 414A from sys import stdin __author__ = 'artyom' n, k = list(map(int, stdin.readline().strip().split())) if n == 1: if k == 0: print(1) else: print(-1) exit() pairs = n // 2 if k < pairs: print(-1) exit() x, y = 1, 2 if k > pairs: x = k - pairs + 1 y = x * 2 print(x, end=' ') print(y, end=' ') if n > 2: for i in range(y + 1, y + n - 2): print(i, end=' ') print(y + n - 2)
vfc_83705
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 2", "output": "1 2 3 4 5", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3", "output": "2 4 5 6 7", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 2", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1", "output": "-1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
195
Solve the following coding problem using the programming language python: After a team finished their training session on Euro football championship, Valeric was commissioned to gather the balls and sort them into baskets. Overall the stadium has *n* balls and *m* baskets. The baskets are positioned in a row from left to right and they are numbered with numbers from 1 to *m*, correspondingly. The balls are numbered with numbers from 1 to *n*. Valeric decided to sort the balls in the order of increasing of their numbers by the following scheme. He will put each new ball in the basket with the least number of balls. And if he's got several variants, he chooses the basket which stands closer to the middle. That means that he chooses the basket for which is minimum, where *i* is the number of the basket. If in this case Valeric still has multiple variants, he chooses the basket with the minimum number. For every ball print the number of the basket where it will go according to Valeric's scheme. Note that the balls are sorted into baskets in the order of increasing numbers, that is, the first ball goes first, then goes the second ball and so on. The input will be provided via standard input and looks as follows: The first line contains two space-separated integers *n*, *m* (1<=≤<=*n*,<=*m*<=≤<=105) — the number of balls and baskets, correspondingly. You should write the solution as standard output as follows: Print *n* numbers, one per line. The *i*-th line must contain the number of the basket for the *i*-th ball. Here are example inputs and outputs for the problem: Example Input 1: 4 3 Example Output 1: 2 1 3 2 Example Input 2: 3 1 Example Output 2: 1 1 1 Now solve the problem by providing the code.
#---------------------------- # Matheus de Souza Oliveira | # RA: 203407 | #---------------------------- n, m = list(map(int, input().split())) for index in range(0, n): factor = m+index%m isFactorEven = not(bool(factor%2)) if isFactorEven: result = int((m-(index%m))/2) print(result) else: result = int((factor+1)/2) print(result)
vfc_83709
{ "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 3", "output": "2\n1\n3\n2", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1", "output": "1\n1\n1", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 3", "output": "2\n1\n3\n2\n1\n3\n2\n1\n3\n2", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 5", "output": "3\n2\n4\n1\n5\n3", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
304
Solve the following coding problem using the programming language python: Calendars in widespread use today include the Gregorian calendar, which is the de facto international standard, and is used almost everywhere in the world for civil purposes. The Gregorian reform modified the Julian calendar's scheme of leap years as follows: Every year that is exactly divisible by four is a leap year, except for years that are exactly divisible by 100; the centurial years that are exactly divisible by 400 are still leap years. For example, the year 1900 is not a leap year; the year 2000 is a leap year. In this problem, you have been given two dates and your task is to calculate how many days are between them. Note, that leap years have unusual number of days in February. Look at the sample to understand what borders are included in the aswer. The input will be provided via standard input and looks as follows: The first two lines contain two dates, each date is in the format yyyy:mm:dd (1900<=≤<=*yyyy*<=≤<=2038 and yyyy:mm:dd is a legal date). 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: 1900:01:01 2038:12:31 Example Output 1: 50768 Example Input 2: 1996:03:09 1991:11:12 Example Output 2: 1579 Now solve the problem by providing the code.
import datetime d1=datetime.datetime.strptime(input(),"%Y:%m:%d") d2=datetime.datetime.strptime(input(),"%Y:%m:%d") print(abs((d2-d1).days))
vfc_83713
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "3000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1900:01:01\n2038:12:31", "output": "50768", "type": "stdin_stdout" }, { "fn_name": null, "input": "1996:03:09\n1991:11:12", "output": "1579", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
15
Solve the following coding problem using the programming language python: A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» *n* square houses with the centres on the *Оx*-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other. The architect bureau, where Peter works, was commissioned to build a new house in «Flatville». The customer wants his future house to be on the *Оx*-axis, to be square in shape, have a side *t*, and touch at least one of the already built houses. For sure, its sides should be parallel to the coordinate axes, its centre should be on the *Ox*-axis and it shouldn't overlap any of the houses in the village. Peter was given a list of all the houses in «Flatville». Would you help him find the amount of possible positions of the new house? The input will be provided via standard input and looks as follows: The first line of the input data contains numbers *n* and *t* (1<=≤<=*n*,<=*t*<=≤<=1000). Then there follow *n* lines, each of them contains two space-separated integer numbers: *x**i* *a**i*, where *x**i* — *x*-coordinate of the centre of the *i*-th house, and *a**i* — length of its side (<=-<=1000<=≤<=*x**i*<=≤<=1000, 1<=≤<=*a**i*<=≤<=1000). You should write the solution as standard output as follows: Output the amount of possible positions of the new house. Here are example inputs and outputs for the problem: Example Input 1: 2 2 0 4 6 2 Example Output 1: 4 Example Input 2: 2 2 0 4 5 2 Example Output 2: 3 Example Input 3: 2 3 0 4 5 2 Example Output 3: 2 Now solve the problem by providing the code.
from collections import deque lst = [w.rstrip() for w in open(0).readlines()] n, t = map(int, lst[0].split()) data = [tuple(map(int, x.split())) for x in lst[1:]] L, R = [], [] for x in data: L.append(x[0] - x[1] / 2) R.append(x[0] + x[1] / 2) L.sort() R.sort() d = deque() for a, b in zip(L, R): if len(d) > 0 and d[-1] == a: d[-1] = b else: d.append(a) d.append(b) d.popleft() d = list(d) r = 2 for a, b in zip(d[::2], d[1::2]): if b-a > t: r += 2 elif b-a == t: r += 1 print(r)
vfc_83717
{ "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\n0 4\n6 2", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n0 4\n5 2", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3\n0 4\n5 2", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n1 1", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 2\n2 1", "output": "2", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
651
Solve the following coding problem using the programming language python: Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at *a*1 percent and second one is charged at *a*2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if not connected to a charger) or charges by 1 percent (if connected to a charger). Game continues while both joysticks have a positive charge. Hence, if at the beginning of minute some joystick is charged by 1 percent, it has to be connected to a charger, otherwise the game stops. If some joystick completely discharges (its charge turns to 0), the game also stops. Determine the maximum number of minutes that game can last. It is prohibited to pause the game, i. e. at each moment both joysticks should be enabled. It is allowed for joystick to be charged by more than 100 percent. The input will be provided via standard input and looks as follows: The first line of the input contains two positive integers *a*1 and *a*2 (1<=≤<=*a*1,<=*a*2<=≤<=100), the initial charge level of first and second joystick respectively. You should write the solution as standard output as follows: Output the only integer, the maximum number of minutes that the game can last. Game continues until some joystick is discharged. Here are example inputs and outputs for the problem: Example Input 1: 3 5 Example Output 1: 6 Example Input 2: 4 4 Example Output 2: 5 Now solve the problem by providing the code.
a,b = [int(x) for x in input().split(" ")] time = 0 while a and b: if a==1 and b==1: break if a<b: a += 1 b -= 2 else: b += 1 a -= 2 time+=1 print(time)
vfc_83721
{ "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", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 4", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "100 100", "output": "197", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 100", "output": "98", "type": "stdin_stdout" }, { "fn_name": null, "input": "100 1", "output": "98", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
378
Solve the following coding problem using the programming language python: Two players are playing a game. First each of them writes an integer from 1 to 6, and then a dice is thrown. The player whose written number got closer to the number on the dice wins. If both payers have the same difference, it's a draw. The first player wrote number *a*, the second player wrote number *b*. How many ways to throw a dice are there, at which the first player wins, or there is a draw, or the second player wins? The input will be provided via standard input and looks as follows: The single line contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=6) — the numbers written on the paper by the first and second player, correspondingly. You should write the solution as standard output as follows: Print three integers: the number of ways to throw the dice at which the first player wins, the game ends with a draw or the second player wins, correspondingly. Here are example inputs and outputs for the problem: Example Input 1: 2 5 Example Output 1: 3 0 3 Example Input 2: 2 4 Example Output 2: 2 1 3 Now solve the problem by providing the code.
m=list(map(int,input().split())) result_a_win=result_draw=result_b_win=0 for i in range(1,7): if abs(m[0]-i)<abs(m[1]-i): result_a_win += 1 if abs(m[0]-i)==abs(m[1]-i): result_draw += 1 if abs(m[0]-i)>abs(m[1]-i): result_b_win += 1 print(result_a_win,result_draw,result_b_win)
vfc_83725
{ "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 5", "output": "3 0 3", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 4", "output": "2 1 3", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
513
Solve the following coding problem using the programming language python: You are given a permutation *p* of numbers 1,<=2,<=...,<=*n*. Let's define *f*(*p*) as the following sum: Find the lexicographically *m*-th permutation of length *n* in the set of permutations having the maximum possible value of *f*(*p*). The input will be provided via standard input and looks as follows: The single line of input contains two integers *n* and *m* (1<=≤<=*m*<=≤<=*cnt**n*), where *cnt**n* is the number of permutations of length *n* with maximum possible value of *f*(*p*). The problem consists of two subproblems. The subproblems have different constraints on the input. You will get some score for the correct submission of the subproblem. The description of the subproblems follows. - In subproblem B1 (3 points), the constraint 1<=≤<=*n*<=≤<=8 will hold. - In subproblem B2 (4 points), the constraint 1<=≤<=*n*<=≤<=50 will hold. You should write the solution as standard output as follows: Output *n* number forming the required permutation. Here are example inputs and outputs for the problem: Example Input 1: 2 2 Example Output 1: 2 1 Example Input 2: 3 2 Example Output 2: 1 3 2 Now solve the problem by providing the code.
import itertools n, m = tuple(int(x) for x in input().split()) lstN = [x for x in range(1,n+1)] def funcP(seq): res = 0 for i in range(len(seq)): for j in range(i, len(seq)): res += min(seq[i:j+1]) return res allPerm = [(perm,funcP(perm)) for perm in itertools.permutations(lstN)] allPerm.sort(key = lambda x: x[1], reverse = True) print(" ".join(str(x) for x in allPerm[m-1][0]))
vfc_83729
{ "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 2", "output": "2 1 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2", "output": "1 3 2 ", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
287
Solve the following coding problem using the programming language python: In the city of Ultima Thule job applicants are often offered an IQ test. The test is as follows: the person gets a piece of squared paper with a 4<=×<=4 square painted on it. Some of the square's cells are painted black and others are painted white. Your task is to repaint at most one cell the other color so that the picture has a 2<=×<=2 square, completely consisting of cells of the same color. If the initial picture already has such a square, the person should just say so and the test will be completed. Your task is to write a program that determines whether it is possible to pass the test. You cannot pass the test if either repainting any cell or no action doesn't result in a 2<=×<=2 square, consisting of cells of the same color. The input will be provided via standard input and looks as follows: Four lines contain four characters each: the *j*-th character of the *i*-th line equals "." if the cell in the *i*-th row and the *j*-th column of the square is painted white, and "#", if the cell is black. You should write the solution as standard output as follows: Print "YES" (without the quotes), if the test can be passed and "NO" (without the quotes) otherwise. Here are example inputs and outputs for the problem: Example Input 1: #### .#.. #### .... Example Output 1: YES Example Input 2: #### .... #### .... Example Output 2: NO Now solve the problem by providing the code.
from copy import deepcopy zoz=[] for i in range(4): zoz.append(list(input())) def check(zoz): for i in range(3): for j in range(3): if zoz[i][j]==zoz[i][j+1] and zoz[i+1][j]==zoz[i+1][j+1] and zoz[i+1][j]==zoz[i][j]: return True return False def change(z): if z=="#": return "." else: return "#" verdict="NO" if check(zoz): verdict="YES" for i in range(16): test=deepcopy(zoz) test[i//4][i%4]=change(test[i//4][i%4]) if check(test): verdict="YES" break print(verdict)
vfc_83733
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "400" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "###.\n...#\n###.\n...#", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": ".##.\n#..#\n.##.\n#..#", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": ".#.#\n#.#.\n.#.#\n#.#.", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "##..\n..##\n##..\n..##", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "#.#.\n#.#.\n.#.#\n.#.#", "output": "NO", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
961
Solve the following coding problem using the programming language python: Your friend Mishka and you attend a calculus lecture. Lecture lasts *n* minutes. Lecturer tells *a**i* theorems during the *i*-th minute. Mishka is really interested in calculus, though it is so hard to stay awake for all the time of lecture. You are given an array *t* of Mishka's behavior. If Mishka is asleep during the *i*-th minute of the lecture then *t**i* will be equal to 0, otherwise it will be equal to 1. When Mishka is awake he writes down all the theorems he is being told — *a**i* during the *i*-th minute. Otherwise he writes nothing. You know some secret technique to keep Mishka awake for *k* minutes straight. However you can use it only once. You can start using it at the beginning of any minute between 1 and *n*<=-<=*k*<=+<=1. If you use it on some minute *i* then Mishka will be awake during minutes *j* such that and will write down all the theorems lecturer tells. You task is to calculate the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up. The input will be provided via standard input and looks as follows: The first line of the input contains two integer numbers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=105) — the duration of the lecture in minutes and the number of minutes you can keep Mishka awake. The second line of the input contains *n* integer numbers *a*1,<=*a*2,<=... *a**n* (1<=≤<=*a**i*<=≤<=104) — the number of theorems lecturer tells during the *i*-th minute. The third line of the input contains *n* integer numbers *t*1,<=*t*2,<=... *t**n* (0<=≤<=*t**i*<=≤<=1) — type of Mishka's behavior at the *i*-th minute of the lecture. You should write the solution as standard output as follows: Print only one integer — the maximum number of theorems Mishka will be able to write down if you use your technique only once to wake him up. Here are example inputs and outputs for the problem: Example Input 1: 6 3 1 3 5 2 5 4 1 1 0 1 0 0 Example Output 1: 16 Now solve the problem by providing the code.
n, k = map(int, input().split()) lectures = list(map(int, input().split())) sleeping = list(map(int, input().split())) dp_ok = [0] * (n - k + 1) dp_magic = [0] * (n - k + 1) s1, s2 = 0, 0 for i in range(k): s1 += lectures[i] * sleeping[i] s2 += lectures[i] dp_ok[0] = s1 dp_magic[0] = s2 max_diff, max_index = dp_magic[0] - dp_ok[0], 0 for i in range(k, n): j = i - k dp_ok[j + 1] = dp_ok[j] - lectures[j] * sleeping[j] + lectures[i] * sleeping[i] dp_magic[j + 1] = dp_magic[j] - lectures[j] + lectures[i] diff = dp_magic[j + 1] - dp_ok[j + 1] if diff > max_diff: max_diff = diff max_index = j + 1 res = 0 for i in range(n): if i >= max_index and i < max_index + k: res += lectures[i] else: res += lectures[i] * sleeping[i] print(res)
vfc_83737
{ "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 3\n1 3 5 2 5 4\n1 1 0 1 0 0", "output": "16", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3\n1 9999 10000 10000 10000\n0 0 0 0 0", "output": "30000", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
53
Solve the following coding problem using the programming language python: Vasya is a school PE teacher. Unlike other PE teachers, Vasya doesn't like it when the students stand in line according to their height. Instead, he demands that the children stand in the following order: *a*1,<=*a*2,<=...,<=*a**n*, where *a**i* is the height of the *i*-th student in the line and *n* is the number of students in the line. The children find it hard to keep in mind this strange arrangement, and today they formed the line in the following order: *b*1,<=*b*2,<=...,<=*b**n*, which upset Vasya immensely. Now Vasya wants to rearrange the children so that the resulting order is like this: *a*1,<=*a*2,<=...,<=*a**n*. During each move Vasya can swap two people who stand next to each other in the line. Help Vasya, find the sequence of swaps leading to the arrangement Vasya needs. It is not required to minimize the number of moves. The input will be provided via standard input and looks as follows: The first line contains an integer *n* (1<=≤<=*n*<=≤<=300) which is the number of students. The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=109) which represent the height of the student occupying the *i*-th place must possess. The third line contains *n* space-separated integers *b**i* (1<=≤<=*b**i*<=≤<=109) which represent the height of the student occupying the *i*-th place in the initial arrangement. It is possible that some students possess similar heights. It is guaranteed that it is possible to arrange the children in the required order, i.e. *a* and *b* coincide as multisets. You should write the solution as standard output as follows: In the first line print an integer *k* (0<=≤<=*k*<=≤<=106) which is the number of moves. It is not required to minimize *k* but it must not exceed 106. Then print *k* lines each containing two space-separated integers. Line *p**i*, *p**i*<=+<=1 (1<=≤<=*p**i*<=≤<=*n*<=-<=1) means that Vasya should swap students occupying places *p**i* and *p**i*<=+<=1. Here are example inputs and outputs for the problem: Example Input 1: 4 1 2 3 2 3 2 1 2 Example Output 1: 4 2 3 1 2 3 4 2 3 Example Input 2: 2 1 100500 1 100500 Example Output 2: 0 Now solve the problem by providing the code.
def vasya_and_physcult(count, a_str, b_str): size = int(count) a = list(map(int, a_str.split())) b = list(map(int, b_str.split())) changes_count = 0 result = "" for i in range(size): current_index = i for j in range(i,size): if b[j] == a[i]: current_index = j break while current_index>i: b[current_index], b[current_index-1] = b[current_index-1], b[current_index-1] result += "\n" + f"{current_index} {current_index+1}" changes_count+=1 current_index-=1 return str(changes_count) + result count = input() a = input() b = input() print(vasya_and_physcult(count, a, b))
vfc_83741
{ "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 2 3 2\n3 2 1 2", "output": "4\n2 3\n1 2\n3 4\n2 3", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 100500\n1 100500", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n652586118 652586118 652586118\n652586118 652586118 652586118", "output": "3\n2 3\n1 2\n2 3", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n681106577 681106577 675077178 675077178\n675077178 681106577 681106577 675077178", "output": "4\n2 3\n1 2\n2 3\n3 4", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
707
Solve the following coding problem using the programming language python: Small, but very brave, mouse Brain was not accepted to summer school of young villains. He was upset and decided to postpone his plans of taking over the world, but to become a photographer instead. As you may know, the coolest photos are on the film (because you can specify the hashtag #film for such). Brain took a lot of colourful pictures on colored and black-and-white film. Then he developed and translated it into a digital form. But now, color and black-and-white photos are in one folder, and to sort them, one needs to spend more than one hour! As soon as Brain is a photographer not programmer now, he asks you to help him determine for a single photo whether it is colored or black-and-white. Photo can be represented as a matrix sized *n*<=×<=*m*, and each element of the matrix stores a symbol indicating corresponding pixel color. There are only 6 colors: - 'C' (cyan)- 'M' (magenta)- 'Y' (yellow)- 'W' (white)- 'G' (grey)- 'B' (black) The photo is considered black-and-white if it has only white, black and grey pixels in it. If there are any of cyan, magenta or yellow pixels in the photo then it is considered colored. 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<=≤<=*n*,<=*m*<=≤<=100) — the number of photo pixel matrix rows and columns respectively. Then *n* lines describing matrix rows follow. Each of them contains *m* space-separated characters describing colors of pixels in a row. Each character in the line is one of the 'C', 'M', 'Y', 'W', 'G' or 'B'. You should write the solution as standard output as follows: Print the "#Black&amp;White" (without quotes), if the photo is black-and-white and "#Color" (without quotes), if it is colored, in the only line. Here are example inputs and outputs for the problem: Example Input 1: 2 2 C M Y Y Example Output 1: #Color Example Input 2: 3 2 W W W W B B Example Output 2: #Black&amp;White Example Input 3: 1 1 W Example Output 3: #Black&amp;White Now solve the problem by providing the code.
n,m=map(int, input().split()) temp="" for i in range(n): temp=temp+input() if temp.count('C')>0 or temp.count('M')>0 or temp.count('Y')>0: print('#Color') else: print("#Black&White")
vfc_83745
{ "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 2\nC M\nY Y", "output": "#Color", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2\nW W\nW W\nB B", "output": "#Black&White", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
724
Solve the following coding problem using the programming language python: You are given a table consisting of *n* rows and *m* columns. Numbers in each row form a permutation of integers from 1 to *m*. You are allowed to pick two elements in one row and swap them, but no more than once for each row. Also, no more than once you are allowed to pick two columns and swap them. Thus, you are allowed to perform from 0 to *n*<=+<=1 actions in total. Operations can be performed in any order. You have to check whether it's possible to obtain the identity permutation 1,<=2,<=...,<=*m* in each row. In other words, check if one can perform some of the operation following the given rules and make each row sorted in increasing order. 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<=≤<=*n*,<=*m*<=≤<=20) — the number of rows and the number of columns in the given table. Each of next *n* lines contains *m* integers — elements of the table. It's guaranteed that numbers in each line form a permutation of integers from 1 to *m*. You should write the solution as standard output as follows: If there is a way to obtain the identity permutation in each row by following the given rules, print "YES" (without quotes) in the only line of the output. Otherwise, print "NO" (without quotes). Here are example inputs and outputs for the problem: Example Input 1: 2 4 1 3 2 4 1 3 4 2 Example Output 1: YES Example Input 2: 4 4 1 2 3 4 2 3 4 1 3 4 1 2 4 1 2 3 Example Output 2: NO Example Input 3: 3 6 2 1 3 4 5 6 1 2 4 3 5 6 1 2 3 4 6 5 Example Output 3: YES Now solve the problem by providing the code.
from sys import stdin from sys import stdout from sys import exit nm = [int(x) for x in stdin.readline()[:-1].split(' ')] n = nm[0] m = nm[1] matrice = [[] for z in range(n)] for i in range(n): matrice[i] = [int(x) for x in stdin.readline()[:-1].split(' ')] cancomplete = False a = [[0 for i in range(n)] for j in range(m)] for colonna in range(m): for riga in range(n): a[colonna][riga] = matrice[riga][colonna] for i in range(m): for j in range(i, m): o = a[:] tieni = o[i][:] o[i] = o[j][:] o[j] = tieni[:] #print(o) trycomplete = True for riga in range(n): conto = 0 for colonna in range(m): # print(colonna, o[colonna][riga], conto) if o[colonna][riga] != colonna + 1: conto += 1 #o1[riga][colonna] = 1 if conto > 2: trycomplete = False cancomplete = cancomplete or trycomplete '''for colonna in range(m): conto = 0 for riga in range(n): if o1[riga][colonna] == 1: conto += 1 if conto > 1: stdout.write('NO') exit()''' if cancomplete: stdout.write('YES') else: stdout.write('NO')
vfc_83749
{ "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 4\n1 3 2 4\n1 3 4 2", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 4\n1 2 3 4\n2 3 4 1\n3 4 1 2\n4 1 2 3", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 6\n2 1 3 4 5 6\n1 2 4 3 5 6\n1 2 3 4 6 5", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 10\n1 2 3 4 5 6 7 10 9 8\n5 2 3 4 1 6 7 8 9 10\n1 2 3 4 5 6 7 8 9 10", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 12\n1 2 3 4 5 6 7 10 9 8 11 12\n1 2 3 4 5 6 7 10 9 8 11 12\n1 2 3 8 5 6 7 10 9 4 11 12\n1 5 3 4 2 6 7 10 9 8 11 12\n1 2 3 4 5 6 7 10 9 8 11 12", "output": "YES", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
526
Solve the following coding problem using the programming language python: One day Om Nom found a thread with *n* beads of different colors. He decided to cut the first several beads from this thread to make a bead necklace and present it to his girlfriend Om Nelly. Om Nom knows that his girlfriend loves beautiful patterns. That's why he wants the beads on the necklace to form a regular pattern. A sequence of beads *S* is regular if it can be represented as *S*<==<=*A*<=+<=*B*<=+<=*A*<=+<=*B*<=+<=*A*<=+<=...<=+<=*A*<=+<=*B*<=+<=*A*, where *A* and *B* are some bead sequences, "<=+<=" is the concatenation of sequences, there are exactly 2*k*<=+<=1 summands in this sum, among which there are *k*<=+<=1 "*A*" summands and *k* "*B*" summands that follow in alternating order. Om Nelly knows that her friend is an eager mathematician, so she doesn't mind if *A* or *B* is an empty sequence. Help Om Nom determine in which ways he can cut off the first several beads from the found thread (at least one; probably, all) so that they form a regular pattern. When Om Nom cuts off the beads, he doesn't change their order. The input will be provided via standard input and looks as follows: The first line contains two integers *n*, *k* (1<=≤<=*n*,<=*k*<=≤<=1<=000<=000) — the number of beads on the thread that Om Nom found and number *k* from the definition of the regular sequence above. The second line contains the sequence of *n* lowercase Latin letters that represent the colors of the beads. Each color corresponds to a single letter. You should write the solution as standard output as follows: Print a string consisting of *n* zeroes and ones. Position *i* (1<=≤<=*i*<=≤<=*n*) must contain either number one if the first *i* beads on the thread form a regular sequence, or a zero otherwise. Here are example inputs and outputs for the problem: Example Input 1: 7 2 bcabcab Example Output 1: 0000011 Example Input 2: 21 2 ababaababaababaababaa Example Output 2: 000110000111111000011 Now solve the problem by providing the code.
def prefix_function(s: str): n = len(s) pi = [0] * n k = 0 for i in range(1, n): while k > 0 and s[i] != s[k]: k = pi[k - 1] if s[i] == s[k]: k += 1 pi[i] = k return pi def z_function(s: str): n = len(s) z = [0] * n l, r = 0, 0 for i in range(1, n): z[i] = 0 if i >= r else min(r - i, z[i - l]) while i + z[i] < n and s[z[i]] == s[i + z[i]]: z[i] += 1 if i + z[i] > r: l, r = i, i + z[i] return z n, k = map(int, input().split()) s = input() pi = prefix_function(s) ans = [0] * n for i in range(n): L = i + 1 T = L - pi[i] have, remain = divmod(L, T) # print(L, T, have, remain) len_ab = have // k * T len_a = (have % k) * T + remain if len_ab >= len_a: ans[i] = 1 print("".join(map(str, ans)))
vfc_83753
{ "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 2\nbcabcab", "output": "0000011", "type": "stdin_stdout" }, { "fn_name": null, "input": "21 2\nababaababaababaababaa", "output": "000110000111111000011", "type": "stdin_stdout" }, { "fn_name": null, "input": "321 2\nabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaabaaba", "output": "000001111001111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "type": "stdin_stdout" }, { "fn_name": null, "input": "153 2\nabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaabaaa", "output": "000000011111000111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1\nab", "output": "11", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\nab", "output": "00", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
813
Solve the following coding problem using the programming language python: Unlucky year in Berland is such a year that its number *n* can be represented as *n*<==<=*x**a*<=+<=*y**b*, where *a* and *b* are non-negative integer numbers. For example, if *x*<==<=2 and *y*<==<=3 then the years 4 and 17 are unlucky (4<==<=20<=+<=31, 17<==<=23<=+<=32<==<=24<=+<=30) and year 18 isn't unlucky as there is no such representation for it. Such interval of years that there are no unlucky years in it is called The Golden Age. You should write a program which will find maximum length of The Golden Age which starts no earlier than the year *l* and ends no later than the year *r*. If all years in the interval [*l*,<=*r*] are unlucky then the answer is 0. The input will be provided via standard input and looks as follows: The first line contains four integer numbers *x*, *y*, *l* and *r* (2<=≤<=*x*,<=*y*<=≤<=1018, 1<=≤<=*l*<=≤<=*r*<=≤<=1018). You should write the solution as standard output as follows: Print the maximum length of The Golden Age within the interval [*l*,<=*r*]. If all years in the interval [*l*,<=*r*] are unlucky then print 0. Here are example inputs and outputs for the problem: Example Input 1: 2 3 1 10 Example Output 1: 1 Example Input 2: 3 5 10 22 Example Output 2: 8 Example Input 3: 2 3 3 5 Example Output 3: 0 Now solve the problem by providing the code.
def parser(): while 1: data = list(input().split(' ')) for number in data: if len(number) > 0: yield(number) input_parser = parser() def get_word(): global input_parser return next(input_parser) def get_number(): data = get_word() try: return int(data) except ValueError: return float(data) x = get_number() y = get_number() l = get_number() r = get_number() n1 = 1; a = list() a.append(l - 1) for i in range(0, 300): if n1 > r: break n2 = 1 for j in range(0, 300): if n1 + n2 > r: break if n1 + n2 >= l and n1 + n2 <= r: a.append(n1 + n2) n2 = n2 * y n1 = n1 * x a.append(r + 1) a.sort() ans = 0 for i in range(0, len(a) - 1): ans = max(ans, a[i + 1] - a[i] - 1) print(ans)
vfc_83757
{ "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 3 1 10", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
48
Solve the following coding problem using the programming language python: Uncle Fyodor, Matroskin the Cat and Sharic the Dog live their simple but happy lives in Prostokvashino. Sometimes they receive parcels from Uncle Fyodor’s parents and sometimes from anonymous benefactors, in which case it is hard to determine to which one of them the package has been sent. A photographic rifle is obviously for Sharic who loves hunting and fish is for Matroskin, but for whom was a new video game console meant? Every one of the three friends claimed that the present is for him and nearly quarreled. Uncle Fyodor had an idea how to solve the problem justly: they should suppose that the console was sent to all three of them and play it in turns. Everybody got relieved but then yet another burning problem popped up — who will play first? This time Matroskin came up with a brilliant solution, suggesting the most fair way to find it out: play rock-paper-scissors together. The rules of the game are very simple. On the count of three every player shows a combination with his hand (or paw). The combination corresponds to one of three things: a rock, scissors or paper. Some of the gestures win over some other ones according to well-known rules: the rock breaks the scissors, the scissors cut the paper, and the paper gets wrapped over the stone. Usually there are two players. Yet there are three friends, that’s why they decided to choose the winner like that: If someone shows the gesture that wins over the other two players, then that player wins. Otherwise, another game round is required. Write a program that will determine the winner by the gestures they have shown. The input will be provided via standard input and looks as follows: The first input line contains the name of the gesture that Uncle Fyodor showed, the second line shows which gesture Matroskin showed and the third line shows Sharic’s gesture. You should write the solution as standard output as follows: Print "F" (without quotes) if Uncle Fyodor wins. Print "M" if Matroskin wins and "S" if Sharic wins. If it is impossible to find the winner, print "?". Here are example inputs and outputs for the problem: Example Input 1: rock rock rock Example Output 1: ? Example Input 2: paper rock rock Example Output 2: F Example Input 3: scissors rock rock Example Output 3: ? Example Input 4: scissors paper rock Example Output 4: ? Now solve the problem by providing the code.
F=input() M=input() S=input() Beater={"paper":"scissors","scissors":"rock","rock":"paper"} if S==Beater[F] and F==M: print("S") elif F==Beater[S] and S==M: print("F") elif M==Beater[F] and F==S: print("M") else: print("?")
vfc_83761
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "rock\nrock\nrock", "output": "?", "type": "stdin_stdout" }, { "fn_name": null, "input": "paper\nrock\nrock", "output": "F", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
960
Solve the following coding problem using the programming language python: You are given two arrays *A* and *B*, each of size *n*. The error, *E*, between these two arrays is defined . You have to perform exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. In one operation, you have to choose one element of the array and increase or decrease it by 1. Output the minimum possible value of error after *k*1 operations on array *A* and *k*2 operations on array *B* have been performed. The input will be provided via standard input and looks as follows: The first line contains three space-separated integers *n* (1<=≤<=*n*<=≤<=103), *k*1 and *k*2 (0<=≤<=*k*1<=+<=*k*2<=≤<=103, *k*1 and *k*2 are non-negative) — size of arrays and number of operations to perform on *A* and *B* respectively. Second line contains *n* space separated integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=106<=≤<=*a**i*<=≤<=106) — array *A*. Third line contains *n* space separated integers *b*1,<=*b*2,<=...,<=*b**n* (<=-<=106<=≤<=*b**i*<=≤<=106)— array *B*. You should write the solution as standard output as follows: Output a single integer — the minimum possible value of after doing exactly *k*1 operations on array *A* and exactly *k*2 operations on array *B*. Here are example inputs and outputs for the problem: Example Input 1: 2 0 0 1 2 2 3 Example Output 1: 2 Example Input 2: 2 1 0 1 2 2 2 Example Output 2: 0 Example Input 3: 2 5 7 3 4 14 4 Example Output 3: 1 Now solve the problem by providing the code.
n, k1, k2 = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = [0]*n for i in range(n): c[i] = abs(a[i] - b[i]) k = k1 + k2 while k != 0: max_value = c[0] max_index = 0 for i, v in enumerate(c): if v > max_value: max_value = v max_index = i if max_value == 0: break else: c[max_index] -= 1 k -= 1 if k == 0: sum = 0 for i in range(n): sum += c[i]*c[i] print(sum) else: if k % 2 == 0: print(0) else: print(1)
vfc_83765
{ "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 0 0\n1 2\n2 3", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1 0\n1 2\n2 2", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 5 7\n3 4\n14 4", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 0 1\n1 2\n2 2", "output": "0", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
437
Solve the following coding problem using the programming language python: Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should find out the only one that is correct. Fortunately the child knows how to solve such complicated test. The child will follow the algorithm: - If there is some choice whose description at least twice shorter than all other descriptions, or at least twice longer than all other descriptions, then the child thinks the choice is great. - If there is exactly one great choice then the child chooses it. Otherwise the child chooses C (the child think it is the luckiest choice). You are given a multiple-choice questions, can you predict child's choose? The input will be provided via standard input and looks as follows: The first line starts with "A." (without quotes), then followed the description of choice A. The next three lines contains the descriptions of the other choices in the same format. They are given in order: B, C, D. Please note, that the description goes after prefix "X.", so the prefix mustn't be counted in description's length. Each description is non-empty and consists of at most 100 characters. Each character can be either uppercase English letter or lowercase English letter, or "_". You should write the solution as standard output as follows: Print a single line with the child's choice: "A", "B", "C" or "D" (without quotes). Here are example inputs and outputs for the problem: Example Input 1: A.VFleaKing_is_the_author_of_this_problem B.Picks_is_the_author_of_this_problem C.Picking_is_the_author_of_this_problem D.Ftiasch_is_cute Example Output 1: D Example Input 2: A.ab B.abcde C.ab D.abc Example Output 2: C Example Input 3: A.c B.cc C.c D.c Example Output 3: B Now solve the problem by providing the code.
a=['0']*4 b=[""]*4 c=[0]*4 for i in range(4): a[i],b[i]=map(str,input().split('.')) c[i]=len(b[i]) c=sorted(c) x=0 if(c[0]*2<=c[1]): x=1 if(c[2]*2<=c[3]): if(x==0): x=2 else: x=0 if(x==1): for i in range(4): if(len(b[i])==c[0]): print(a[i]) break elif(x==2): for i in range(4): if(len(b[i])==c[3]): print(a[i]) break else: print('C')
vfc_83769
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute", "output": "D", "type": "stdin_stdout" }, { "fn_name": null, "input": "A.ab\nB.abcde\nC.ab\nD.abc", "output": "C", "type": "stdin_stdout" }, { "fn_name": null, "input": "A.c\nB.cc\nC.c\nD.c", "output": "B", "type": "stdin_stdout" }, { "fn_name": null, "input": "A.He_nan_de_yang_guang_zhao_yao_zhe_wo_men_mei_guo_ren_lian_shang_dou_xiao_kai_yan_wahaaaaaaaaaaaaaaaa\nB.Li_bai_li_bai_fei_liu_zhi_xia_san_qian_chi_yi_si_yin_he_luo_jiu_tian_li_bai_li_bai_li_bai_li_bai_shi\nC.Peng_yu_xiang_shi_zai_tai_shen_le_jian_zhi_jiu_shi_ye_jie_du_liu_a_si_mi_da_zhen_shi_tai_shen_le_a_a\nD.Wo_huo_le_si_shi_er_nian_zhen_de_shi_cong_lai_ye_mei_you_jian_guo_zhe_me_biao_zhun_de_yi_bai_ge_zi_a", "output": "C", "type": "stdin_stdout" } ] }