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
8
Solve the following coding problem using the programming language python: Peter likes to travel by train. He likes it so much that on the train he falls asleep. Once in summer Peter was going by train from city A to city B, and as usual, was sleeping. Then he woke up, started to look through the window and noticed that every railway station has a flag of a particular colour. The boy started to memorize the order of the flags' colours that he had seen. But soon he fell asleep again. Unfortunately, he didn't sleep long, he woke up and went on memorizing the colours. Then he fell asleep again, and that time he slept till the end of the journey. At the station he told his parents about what he was doing, and wrote two sequences of the colours that he had seen before and after his sleep, respectively. Peter's parents know that their son likes to fantasize. They give you the list of the flags' colours at the stations that the train passes sequentially on the way from A to B, and ask you to find out if Peter could see those sequences on the way from A to B, or from B to A. Remember, please, that Peter had two periods of wakefulness. Peter's parents put lowercase Latin letters for colours. The same letter stands for the same colour, different letters — for different colours. The input will be provided via standard input and looks as follows: The input data contains three lines. The first line contains a non-empty string, whose length does not exceed 105, the string consists of lowercase Latin letters — the flags' colours at the stations on the way from A to B. On the way from B to A the train passes the same stations, but in reverse order. The second line contains the sequence, written by Peter during the first period of wakefulness. The third line contains the sequence, written during the second period of wakefulness. Both sequences are non-empty, consist of lowercase Latin letters, and the length of each does not exceed 100 letters. Each of the sequences is written in chronological order. You should write the solution as standard output as follows: Output one of the four words without inverted commas: - «forward» — if Peter could see such sequences only on the way from A to B; - «backward» — if Peter could see such sequences on the way from B to A; - «both» — if Peter could see such sequences both on the way from A to B, and on the way from B to A; - «fantasy» — if Peter could not see such sequences. Here are example inputs and outputs for the problem: Example Input 1: atob a b Example Output 1: forward Example Input 2: aaacaaa aca aa Example Output 2: both Now solve the problem by providing the code.
f = input() b = f[::-1] s1 = input() s2 = input() i = -1 j = -1 try: i = f.index(s1) j = f.index(s2, i+len(s1)) except: pass forward = bool(j > -1) i = -1 j = -1 try: i = b.index(s1) j = b.index(s2, i+len(s1)) except: pass backward = bool(j > -1) if forward: if backward: print('both') else: print('forward') elif backward: print('backward') else: print('fantasy')
vfc_83773
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "atob\na\nb", "output": "forward", "type": "stdin_stdout" }, { "fn_name": null, "input": "aaacaaa\naca\naa", "output": "both", "type": "stdin_stdout" }, { "fn_name": null, "input": "aaa\naa\naa", "output": "fantasy", "type": "stdin_stdout" }, { "fn_name": null, "input": "astalavista\nastla\nlavista", "output": "fantasy", "type": "stdin_stdout" }, { "fn_name": null, "input": "abacabadabacaba\nabacaba\nabacaba", "output": "both", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
622
Solve the following coding problem using the programming language python: You are given the current time in 24-hour format hh:mm. Find and print the time after *a* minutes. Note that you should find only the time after *a* minutes, see the examples to clarify the problem statement. You can read more about 24-hour format here [https://en.wikipedia.org/wiki/24-hour_clock](https://en.wikipedia.org/wiki/24-hour_clock). The input will be provided via standard input and looks as follows: The first line contains the current time in the format hh:mm (0<=≤<=*hh*<=&lt;<=24,<=0<=≤<=*mm*<=&lt;<=60). The hours and the minutes are given with two digits (the hours or the minutes less than 10 are given with the leading zeroes). The second line contains integer *a* (0<=≤<=*a*<=≤<=104) — the number of the minutes passed. You should write the solution as standard output as follows: The only line should contain the time after *a* minutes in the format described in the input. Note that you should print exactly two digits for the hours and the minutes (add leading zeroes to the numbers if needed). See the examples to check the input/output format. Here are example inputs and outputs for the problem: Example Input 1: 23:59 10 Example Output 1: 00:09 Example Input 2: 20:20 121 Example Output 2: 22:21 Example Input 3: 10:10 0 Example Output 3: 10:10 Now solve the problem by providing the code.
# -*- coding: utf-8 -*- """codeforces 622B Automatically generated by Colaboratory. Original file is located at https://colab.research.google.com/drive/1fnRVrX6kGGXBPnaZduqeU_eo6w87jUi5 """ T=input() a=int(input()) h=int(T[ :-3]) m=int(T[-2: ]) x=a//60 y=a%60 hour=h+x min=m+y if min>=60: min=min-60 hour=hour+1 z=hour//24 if hour>=24: hour=hour-(24*z) if len(str(hour))==2 and len(str(min))==1: print(f"{hour}:0{min}") elif len(str(hour))==1 and len(str(min))==2: print(f"0{hour}:{min}") elif len(str(hour))==1 and len(str(min))==1: print(f"0{hour}:0{min}") else: print(f"{hour}:{min}")
vfc_83777
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "23:59\n10", "output": "00:09", "type": "stdin_stdout" }, { "fn_name": null, "input": "20:20\n121", "output": "22:21", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
349
Solve the following coding problem using the programming language python: The new "Die Hard" movie has just been released! There are *n* people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells the tickets strictly in the order people follow in the line? The input will be provided via standard input and looks as follows: The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of people in the line. The next line contains *n* integers, each of them equals 25, 50 or 100 — the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line. You should write the solution as standard output as follows: Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO". Here are example inputs and outputs for the problem: Example Input 1: 4 25 25 50 50 Example Output 1: YES Example Input 2: 2 25 100 Example Output 2: NO Example Input 3: 4 50 50 25 25 Example Output 3: NO Now solve the problem by providing the code.
n = int(input()) bills = list(map(int, input().split())) change_25 = 0 change_50 = 0 for bill in bills: if bill == 25: change_25 += 1 elif bill == 50: if change_25 >= 1: change_25 -= 1 change_50 += 1 else: print("NO") break elif bill == 100: if change_50 >= 1 and change_25 >= 1: change_50 -= 1 change_25 -= 1 elif change_25 >= 3: change_25 -= 3 else: print("NO") break else: print("YES")
vfc_83781
{ "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\n25 25 50 50", "output": "YES", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
70
Solve the following coding problem using the programming language python: Fangy collects cookies. Once he decided to take a box and put cookies into it in some way. If we take a square *k*<=×<=*k* in size, divided into blocks 1<=×<=1 in size and paint there the main diagonal together with cells, which lie above it, then the painted area will be equal to the area occupied by one cookie *k* in size. Fangy also has a box with a square base 2*n*<=×<=2*n*, divided into blocks 1<=×<=1 in size. In a box the cookies should not overlap, and they should not be turned over or rotated. See cookies of sizes 2 and 4 respectively on the figure: To stack the cookies the little walrus uses the following algorithm. He takes out of the repository the largest cookie which can fit in some place in the box and puts it there. Everything could be perfect but alas, in the repository the little walrus has infinitely many cookies of size 2 and larger, and there are no cookies of size 1, therefore, empty cells will remain in the box. Fangy wants to know how many empty cells will be left in the end. The input will be provided via standard input and looks as follows: The first line contains a single integer *n* (0<=≤<=*n*<=≤<=1000). You should write the solution as standard output as follows: Print the single number, equal to the number of empty cells in the box. The answer should be printed modulo 106<=+<=3. Here are example inputs and outputs for the problem: Example Input 1: 3 Example Output 1: 9 Now solve the problem by providing the code.
n = int(input()) if n == 0: print(1) else: ans = 1 for i in range(n - 1): ans *= 3 print(ans % 1000003)
vfc_83785
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1500" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3", "output": "9", "type": "stdin_stdout" }, { "fn_name": null, "input": "1", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
626
Solve the following coding problem using the programming language python: Calvin the robot lies in an infinite rectangular grid. Calvin's source code contains a list of *n* commands, each either 'U', 'R', 'D', or 'L' — instructions to move a single square up, right, down, or left, respectively. How many ways can Calvin execute a non-empty contiguous substrings of commands and return to the same square he starts in? Two substrings are considered different if they have different starting or ending indices. The input will be provided via standard input and looks as follows: The first line of the input contains a single positive integer, *n* (1<=≤<=*n*<=≤<=200) — the number of commands. The next line contains *n* characters, each either 'U', 'R', 'D', or 'L' — Calvin's source code. You should write the solution as standard output as follows: Print a single integer — the number of contiguous substrings that Calvin can execute and return to his starting square. Here are example inputs and outputs for the problem: Example Input 1: 6 URLLDR Example Output 1: 2 Example Input 2: 4 DLUU Example Output 2: 0 Example Input 3: 7 RLRLRLR Example Output 3: 12 Now solve the problem by providing the code.
n=int(input()) a=input() ans=0 for i in range(n+1): for j in range(i): l=a[j:i].count("L") r=a[j:i].count("R") u=a[j:i].count("U") d=a[j:i].count("D") if l==r and u==d: ans+=1 print(ans)
vfc_83789
{ "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\nURLLDR", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\nDLUU", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\nRLRLRLR", "output": "12", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
33
Solve the following coding problem using the programming language python: Boy Valera likes strings. And even more he likes them, when they are identical. That's why in his spare time Valera plays the following game. He takes any two strings, consisting of lower case Latin letters, and tries to make them identical. According to the game rules, with each move Valera can change one arbitrary character *A**i* in one of the strings into arbitrary character *B**i*, but he has to pay for every move a particular sum of money, equal to *W**i*. He is allowed to make as many moves as he needs. Since Valera is a very economical boy and never wastes his money, he asked you, an experienced programmer, to help him answer the question: what minimum amount of money should Valera have to get identical strings. The input will be provided via standard input and looks as follows: The first input line contains two initial non-empty strings *s* and *t*, consisting of lower case Latin letters. The length of each string doesn't exceed 105. The following line contains integer *n* (0<=≤<=*n*<=≤<=500) — amount of possible changings. Then follow *n* lines, each containing characters *A**i* and *B**i* (lower case Latin letters) and integer *W**i* (0<=≤<=*W**i*<=≤<=100), saying that it's allowed to change character *A**i* into character *B**i* in any of the strings and spend sum of money *W**i*. You should write the solution as standard output as follows: If the answer exists, output the answer to the problem, and the resulting string. Otherwise output -1 in the only line. If the answer is not unique, output any. Here are example inputs and outputs for the problem: Example Input 1: uayd uxxd 3 a x 8 x y 13 d c 3 Example Output 1: 21 uxyd Example Input 2: a b 3 a b 2 a b 3 b a 5 Example Output 2: 2 b Example Input 3: abc ab 6 a b 4 a b 7 b a 8 c b 11 c a 3 a c 0 Example Output 3: -1 Now solve the problem by providing the code.
import math import random import time from decimal import * from collections import defaultdict from bisect import bisect_left as lower_bound from bisect import bisect_right as upper_bound import sys,threading #sys.setrecursionlimit(5*(10**5)+2) #threading.stack_size(99000000) alfabet = {'a': 1, 'b': 2,'c': 3,'d': 4,'e': 5,'f': 6,'g': 7,'h': 8,'i': 9,'j': 10,'k': 11,'l': 12,'m': 13,'n': 14,'o': 15,'p': 16,'q': 17,'r': 18,'s': 19,'t': 20,'u': 21,'v': 22,'w': 23,'x': 24,'y': 25,'z': 26} alfabet_2={'1':"a", '2':"b", '3':"c", '4':"d", '5':"e", '6':"f", '7':"g", '8':"h", '9':"i", '10':"j", '11':"k", '12':"l", '13':"m", '14':"n", '15':"o", '16':"p", '17':"q", '18':"r", '19':"s", '20':"t", '21':"u", '22':"v", '23':"w", '24':"x", '25':"y", '26':"z"} class FenwickTree: def __init__(self, x): bit = self.bit = list(x) size = self.size = len(bit) for i in range(size): j = i | (i + 1) if j < size: bit[j] += bit[i] def update(self, idx, x): """updates bit[idx] += x""" while idx < self.size: self.bit[idx] += x idx |= idx + 1 def __call__(self, end): """calc sum(bit[:end])""" x = 0 while end: x += self.bit[end - 1] end &= end - 1 return x def find_kth(self, k): """Find largest idx such that sum(bit[:idx]) <= k""" idx = -1 for d in reversed(range(self.size.bit_length())): right_idx = idx + (1 << d) if right_idx < self.size and self.bit[right_idx] <= k: idx = right_idx k -= self.bit[idx] return idx + 1, k class SortedList: block_size = 700 def __init__(self, iterable=()): self.macro = [] self.micros = [[]] self.micro_size = [0] self.fenwick = FenwickTree([0]) self.size = 0 for item in iterable: self.insert(item) def insert(self, x): i = lower_bound(self.macro, x) j = upper_bound(self.micros[i], x) self.micros[i].insert(j, x) self.size += 1 self.micro_size[i] += 1 self.fenwick.update(i, 1) if len(self.micros[i]) >= self.block_size: self.micros[i:i + 1] = self.micros[i][:self.block_size >> 1], self.micros[i][self.block_size >> 1:] self.micro_size[i:i + 1] = self.block_size >> 1, self.block_size >> 1 self.fenwick = FenwickTree(self.micro_size) self.macro.insert(i, self.micros[i + 1][0]) def pop(self, k=-1): i, j = self._find_kth(k) self.size -= 1 self.micro_size[i] -= 1 self.fenwick.update(i, -1) return self.micros[i].pop(j) def __getitem__(self, k): i, j = self._find_kth(k) return self.micros[i][j] def count(self, x): return self.upper_bound(x) - self.lower_bound(x) def __contains__(self, x): return self.count(x) > 0 def lower_bound(self, x): i = lower_bound(self.macro, x) return self.fenwick(i) + lower_bound(self.micros[i], x) def upper_bound(self, x): i = upper_bound(self.macro, x) return self.fenwick(i) + upper_bound(self.micros[i], x) def _find_kth(self, k): return self.fenwick.find_kth(k + self.size if k < 0 else k) def __len__(self): return self.size def __iter__(self): return (x for micro in self.micros for x in micro) def __repr__(self): return str(list(self)) #A = SortedList() #A.insert(30) #A.insert(50) #A.insert(20) #A.insert(30) #A.insert(30) #print(A) # prints [20, 30, 30, 30, 50] #print(A.lower_bound(30), A.upper_bound(30)) # prints 1 4 #print(A[-1]) # prints 50 #print(A.pop(1)) # prints 30 #print(A) # prints [20, 30, 30, 50] #print(A.count(30)) # prints 2 def binary_search(vector,valoarea): left=0 right=len(vector)-1 while left<=right: centru=(left+right)//2 # print(left,right,centru,vector[centru]) if vector[centru]<=valoarea: left=centru+1 else: right=centru-1 # print(left,right,centru,vector[centru]) return left def functie(element,dist,full,graph,vizitat,partial,initialul): initial=alfabet[element] vizitat[initial]=1 for elemente in graph[element]: pozitie=alfabet[elemente] if vizitat[pozitie]==0: partial[pozitie]=min(partial[pozitie],partial[initial]+dist[(element,elemente)]) val_partiala=min(partial[pozitie],partial[initial]+dist[(element,elemente)]) # print("element=",element," to =" ,elemente, " part=",val_partiala) minimul=10**18 target='' for i in range(1,27): new_element=alfabet_2[str(i)] if vizitat[i]==0: if minimul>partial[i]: minimul=partial[i] target=new_element vizitat[initial]=1 if target!='': # print("target=",target) functie(target,dist,full,graph,vizitat,partial,initialul) else: # print("part=",partial) for dd in range(1,27): if partial[dd]<10**18: full[(initialul,alfabet_2[str(dd)])]=partial[dd] def functie_nod(nodul,oprire,distantele,graficul,vizitatul,rezultatul,initial): pp=10**18 partial=pp gasit=0 # print("n=",nodul) ex=0 for vecini in graficul[nodul]: if vizitatul[vecini]==0: ex=1 # print("vec=",vecini) rezultatul[vecini]=min(rezultatul[vecini],rezultatul[nodul]+distantele[(nodul,vecini)]) # print("vec=",vecini,"rez=",rezultatul[vecini]) if partial>=rezultatul[vecini]: next_one=vecini partial=rezultatul[vecini] # print("vec=",next_one, rezultate[next_one],rezultate[nodul],distantele[(nodul,next_one)]) # print(rezultate) vizitatul[nodul]=1 if ex==0: # print("ex=",ex,rezultatul[oprire]) #print(rezultatul) return rezultatul[oprire] else: # print("?=",rezultatul[oprire]) functie(next_one,oprire,distantele,graficul,vizitatul,rezultatul) def main(): #answ=[] pp=10**18 restul=998244353 # teste=int(input()) #answ=[] printare=[] for gg in range(1): # pp=-1 cate=0 string_unu=input() string_doi=input() n=int(input()) distante={} full_distante={} sume=0 graficul=defaultdict(list) for i in range(n): lista=list(map(str,input().split())) if (lista[0],lista[1]) not in distante: distante[(lista[0],lista[1])]=int(lista[2]) graficul[lista[0]].append(lista[1]) else: distante[(lista[0],lista[1])]=min(distante[(lista[0],lista[1])],int(lista[2])) # print(graficul) # print(distante) #for element in graficul['a']: # print("el=",element) for i in range(1,27): vizitatul=[0] *27 partialul=[pp] *27 partialul[i]=0 functie(alfabet_2[str(i)],distante,full_distante,graficul,vizitatul,partialul,alfabet_2[str(i)]) # print(full_distante) great_book={} results={} for i in range(1,27): for j in range(1,27): minimul=pp targetul='' for c in range(1,27): unu=alfabet_2[str(i)] doi=alfabet_2[str(j)] trei=alfabet_2[str(c)] if (unu,trei) in full_distante and (doi,trei) in full_distante: if full_distante[(unu,trei)]+full_distante[(doi,trei)]<minimul: minimul=full_distante[(unu,trei)]+full_distante[(doi,trei)] targetul=trei if targetul!='': great_book[(unu,doi)]=targetul results[(unu,doi)]=minimul # print(great_book) #print(results) sume=0 adev=1 answer='' if len(string_unu)!=len(string_doi): adev=0 # print("ff") else: for i in range(len(string_unu)): unu=string_unu[i] doi=string_doi[i] if unu!=doi: if (unu,doi) not in great_book: adev=0 break else: sume+=results[(unu,doi)] answer+=great_book[(unu,doi)] else: answer+=unu # print("adev=",adev) if adev==1: print(sume) print(answer) else: print(-1) main() #t=threading.Thread(target=main) #t.start() #t.join()
vfc_83793
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "uayd\nuxxd\n3\na x 8\nx y 13\nd c 3", "output": "21\nuxyd", "type": "stdin_stdout" }, { "fn_name": null, "input": "a\nb\n3\na b 2\na b 3\nb a 5", "output": "2\nb", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
217
Solve the following coding problem using the programming language python: Bajtek is learning to skate on ice. He's a beginner, so his only mode of transportation is pushing off from a snow drift to the north, east, south or west and sliding until he lands in another snow drift. He has noticed that in this way it's impossible to get from some snow drifts to some other by any sequence of moves. He now wants to heap up some additional snow drifts, so that he can get from any snow drift to any other one. He asked you to find the minimal number of snow drifts that need to be created. We assume that Bajtek can only heap up snow drifts at integer coordinates. The input will be provided via standard input and looks as follows: The first line of input contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of snow drifts. Each of the following *n* lines contains two integers *x**i* and *y**i* (1<=≤<=*x**i*,<=*y**i*<=≤<=1000) — the coordinates of the *i*-th snow drift. Note that the north direction coinсides with the direction of *Oy* axis, so the east direction coinсides with the direction of the *Ox* axis. All snow drift's locations are distinct. You should write the solution as standard output as follows: Output the minimal number of snow drifts that need to be created in order for Bajtek to be able to reach any snow drift from any other one. Here are example inputs and outputs for the problem: Example Input 1: 2 2 1 1 2 Example Output 1: 1 Example Input 2: 2 2 1 4 1 Example Output 2: 0 Now solve the problem by providing the code.
n=int(input()) q={} l=[] r=[] def f(a): while q[a]!=a: a=q[a] return a for i in range(n): a,b=map(str,input().split()) o,p="x"+a,"y"+b l+=[[o,p]] r+=[o,p] q[o]=o q[p]=p for i in range(n): l[i][0]=f(l[i][0]) l[i][1]=f(l[i][1]) q[l[i][1]]=q[l[i][0]] for i in r: q[i]=f(i) print(len(set(q.values()))-1)
vfc_83797
{ "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 1\n1 2", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2 1\n4 1", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "24\n171 35\n261 20\n4 206\n501 446\n961 912\n581 748\n946 978\n463 514\n841 889\n341 466\n842 967\n54 102\n235 261\n925 889\n682 672\n623 636\n268 94\n635 710\n474 510\n697 794\n586 663\n182 184\n806 663\n468 459", "output": "21", "type": "stdin_stdout" }, { "fn_name": null, "input": "17\n660 646\n440 442\n689 618\n441 415\n922 865\n950 972\n312 366\n203 229\n873 860\n219 199\n344 308\n169 176\n961 992\n153 84\n201 230\n987 938\n834 815", "output": "16", "type": "stdin_stdout" }, { "fn_name": null, "input": "11\n798 845\n722 911\n374 270\n629 537\n748 856\n831 885\n486 641\n751 829\n609 492\n98 27\n654 663", "output": "10", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n321 88", "output": "0", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
500
Solve the following coding problem using the programming language python: New Year is coming in Line World! In this world, there are *n* cells numbered by integers from 1 to *n*, as a 1<=×<=*n* board. People live in cells. However, it was hard to move between distinct cells, because of the difficulty of escaping the cell. People wanted to meet people who live in other cells. So, user tncks0121 has made a transportation system to move between these cells, to celebrate the New Year. First, he thought of *n*<=-<=1 positive integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1. For every integer *i* where 1<=≤<=*i*<=≤<=*n*<=-<=1 the condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* holds. Next, he made *n*<=-<=1 portals, numbered by integers from 1 to *n*<=-<=1. The *i*-th (1<=≤<=*i*<=≤<=*n*<=-<=1) portal connects cell *i* and cell (*i*<=+<=*a**i*), and one can travel from cell *i* to cell (*i*<=+<=*a**i*) using the *i*-th portal. Unfortunately, one cannot use the portal backwards, which means one cannot move from cell (*i*<=+<=*a**i*) to cell *i* using the *i*-th portal. It is easy to see that because of condition 1<=≤<=*a**i*<=≤<=*n*<=-<=*i* one can't leave the Line World using portals. Currently, I am standing at cell 1, and I want to go to cell *t*. However, I don't know whether it is possible to go there. Please determine whether I can go to cell *t* by only using the construted transportation system. The input will be provided via standard input and looks as follows: The first line contains two space-separated integers *n* (3<=≤<=*n*<=≤<=3<=×<=104) and *t* (2<=≤<=*t*<=≤<=*n*) — the number of cells, and the index of the cell which I want to go to. The second line contains *n*<=-<=1 space-separated integers *a*1,<=*a*2,<=...,<=*a**n*<=-<=1 (1<=≤<=*a**i*<=≤<=*n*<=-<=*i*). It is guaranteed, that using the given transportation system, one cannot leave the Line World. You should write the solution as standard output as follows: If I can go to cell *t* using the transportation system, print "YES". Otherwise, print "NO". Here are example inputs and outputs for the problem: Example Input 1: 8 4 1 2 1 2 1 2 1 Example Output 1: YES Example Input 2: 8 5 1 2 1 2 1 1 1 Example Output 2: NO Now solve the problem by providing the code.
n,t=map(int,input().split()) ai=list(map(int,input().split())) ai.insert(0,0) visited=False currentcell=1 while currentcell<=t: currentcell=currentcell+ai[currentcell] if currentcell==t: visited=True break if visited: print("YES") else: print("NO")
vfc_83801
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8 4\n1 2 1 2 1 2 1", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "8 5\n1 2 1 2 1 1 1", "output": "NO", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
393
Solve the following coding problem using the programming language python: Alice likes word "nineteen" very much. She has a string *s* and wants the string to contain as many such words as possible. For that reason she can rearrange the letters of the string. For example, if she has string "xiineteenppnnnewtnee", she can get string "xnineteenppnineteenw", containing (the occurrences marked) two such words. More formally, word "nineteen" occurs in the string the number of times you can read it starting from some letter of the string. Of course, you shouldn't skip letters. Help her to find the maximum number of "nineteen"s that she can get in her string. The input will be provided via standard input and looks as follows: The first line contains a non-empty string *s*, consisting only of lowercase English letters. The length of string *s* doesn't exceed 100. You should write the solution as standard output as follows: Print a single integer — the maximum number of "nineteen"s that she can get in her string. Here are example inputs and outputs for the problem: Example Input 1: nniinneetteeeenn Example Output 1: 2 Example Input 2: nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii Example Output 2: 2 Example Input 3: nineteenineteen Example Output 3: 2 Now solve the problem by providing the code.
import math s = input() count_n = -1 count_i = 0 count_e = 0 count_t = 0 for char in s: if char == 'n': count_n += 1 elif char == 'i': count_i += 1 elif char == 'e': count_e += 1 elif char == 't': count_t += 1 print(min(int(count_n / 2), int(count_i), int(count_e / 3), int(count_t)))
vfc_83805
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "nniinneetteeeenn", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "nneteenabcnneteenabcnneteenabcnneteenabcnneteenabcii", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "nineteenineteen", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "nssemsnnsitjtihtthij", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "eehihnttehtherjsihihnrhimihrjinjiehmtjimnrss", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
778
Solve the following coding problem using the programming language python: Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word *t* and wants to get the word *p* out of it. Nastya removes letters in a certain order (one after another, in this order strictly), which is specified by permutation of letters' indices of the word *t*: *a*1... *a*|*t*|. We denote the length of word *x* as |*x*|. Note that after removing one letter, the indices of other letters don't change. For example, if *t*<==<="nastya" and *a*<==<=[4,<=1,<=5,<=3,<=2,<=6] then removals make the following sequence of words "nastya" "nastya" "nastya" "nastya" "nastya" "nastya" "nastya". Sergey knows this permutation. His goal is to stop his sister at some point and continue removing by himself to get the word *p*. Since Nastya likes this activity, Sergey wants to stop her as late as possible. Your task is to determine, how many letters Nastya can remove before she will be stopped by Sergey. It is guaranteed that the word *p* can be obtained by removing the letters from word *t*. The input will be provided via standard input and looks as follows: The first and second lines of the input contain the words *t* and *p*, respectively. Words are composed of lowercase letters of the Latin alphabet (1<=≤<=|*p*|<=&lt;<=|*t*|<=≤<=200<=000). It is guaranteed that the word *p* can be obtained by removing the letters from word *t*. Next line contains a permutation *a*1,<=*a*2,<=...,<=*a*|*t*| of letter indices that specifies the order in which Nastya removes letters of *t* (1<=≤<=*a**i*<=≤<=|*t*|, all *a**i* are distinct). You should write the solution as standard output as follows: Print a single integer number, the maximum number of letters that Nastya can remove. Here are example inputs and outputs for the problem: Example Input 1: ababcba abb 5 3 4 1 7 6 2 Example Output 1: 3 Example Input 2: bbbabb bb 1 6 3 4 2 5 Example Output 2: 4 Now solve the problem by providing the code.
s = input() small = input() nums = [int(x)-1 for x in input().split()] n = len(s) lo = 0 ans = 0 hi = n-1 def check(x): copy = [1]*n index = 0 for i in range(x): copy[nums[i]]=0 for i in range(n): if s[i]==small[index] and copy[i]: index+=1 if index >= len(small): return True return False while lo <= hi: mid = (lo+hi)//2 if check(mid): ans = mid lo=mid+1 else: hi=mid-1 print(ans)
vfc_83809
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "ababcba\nabb\n5 3 4 1 7 6 2", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "bbbabb\nbb\n1 6 3 4 2 5", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "cacaccccccacccc\ncacc\n10 9 14 5 1 7 15 3 6 12 4 8 11 13 2", "output": "9", "type": "stdin_stdout" }, { "fn_name": null, "input": "aaaabaaabaabaaaaaaaa\naaaa\n18 5 4 6 13 9 1 3 7 8 16 10 12 19 17 15 14 11 20 2", "output": "16", "type": "stdin_stdout" }, { "fn_name": null, "input": "aaaaaaaadbaaabbbbbddaaabdadbbbbbdbbabbbabaabdbbdababbbddddbdaabbddbbbbabbbbbabadaadabaaaadbbabbbaddb\naaaaaaaaaaaaaa\n61 52 5 43 53 81 7 96 6 9 34 78 79 12 8 63 22 76 18 46 41 56 3 20 57 21 75 73 100 94 35 69 32 4 70 95 88 44 68 10 71 98 23 89 36 62 28 51 24 30 74 55 27 80 38 48 93 1 19 84 13 11 86 60 87 33 39 29 83 91 67 72 54 2 17 85 82 14 15 90 64 50 99 26 66 65 31 49 40 45 77 37 25 42 97 47 58 92 59 16", "output": "57", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
577
Solve the following coding problem using the programming language python: Let's consider a table consisting of *n* rows and *n* columns. The cell located at the intersection of *i*-th row and *j*-th column contains number *i*<=×<=*j*. The rows and columns are numbered starting from 1. You are given a positive integer *x*. Your task is to count the number of cells in a table that contain number *x*. The input will be provided via standard input and looks as follows: The single line contains numbers *n* and *x* (1<=≤<=*n*<=≤<=105, 1<=≤<=*x*<=≤<=109) — the size of the table and the number that we are looking for in the table. You should write the solution as standard output as follows: Print a single number: the number of times *x* occurs in the table. Here are example inputs and outputs for the problem: Example Input 1: 10 5 Example Output 1: 2 Example Input 2: 6 12 Example Output 2: 4 Example Input 3: 5 13 Example Output 3: 0 Now solve the problem by providing the code.
n,x=map(int,input().split()) ans=0 for i in range(1,n+1): if x%i==0 and x//i<=n: ans+=1 print(ans)
vfc_83813
{ "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", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 12", "output": "4", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
875
Solve the following coding problem using the programming language python: Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number *n*. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that *n* is the answer to the arithmetic task for first-graders. In the textbook, a certain positive integer *x* was given. The task was to add *x* to the sum of the digits of the number *x* written in decimal numeral system. Since the number *n* on the board was small, Vova quickly guessed which *x* could be in the textbook. Now he wants to get a program which will search for arbitrary values of the number *n* for all suitable values of *x* or determine that such *x* does not exist. Write such a program for Vova. The input will be provided via standard input and looks as follows: The first line contains integer *n* (1<=≤<=*n*<=≤<=109). You should write the solution as standard output as follows: In the first line print one integer *k* — number of different values of *x* satisfying the condition. In next *k* lines print these values in ascending order. Here are example inputs and outputs for the problem: Example Input 1: 21 Example Output 1: 1 15 Example Input 2: 20 Example Output 2: 0 Now solve the problem by providing the code.
# Author: lizi # Email: [email protected] import sys import math n = int(input()) ans = [] for i in range(min(n,100)): p = n - i s = p while p > 0: s += p % 10 p = p // 10 #print(s,' ',p) if s == n: ans.append( n - i ); print(len(ans)) ans.sort() for x in ans: print(x)
vfc_83817
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "21", "output": "1\n15", "type": "stdin_stdout" }, { "fn_name": null, "input": "20", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "1", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "2", "output": "1\n1", "type": "stdin_stdout" }, { "fn_name": null, "input": "3", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "100000001", "output": "2\n99999937\n100000000", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
74
Solve the following coding problem using the programming language python: A stowaway and a controller play the following game. The train is represented by *n* wagons which are numbered with positive integers from 1 to *n* from the head to the tail. The stowaway and the controller are initially in some two different wagons. Every minute the train can be in one of two conditions — moving or idle. Every minute the players move. The controller's move is as follows. The controller has the movement direction — to the train's head or to its tail. During a move the controller moves to the neighbouring wagon correspondingly to its movement direction. If at the end of his move the controller enters the 1-st or the *n*-th wagon, that he changes the direction of his movement into the other one. In other words, the controller cyclically goes from the train's head to its tail and back again during all the time of a game, shifting during each move by one wagon. Note, that the controller always have exactly one possible move. The stowaway's move depends from the state of the train. If the train is moving, then the stowaway can shift to one of neighbouring wagons or he can stay where he is without moving. If the train is at a station and is idle, then the stowaway leaves the train (i.e. he is now not present in any train wagon) and then, if it is not the terminal train station, he enters the train again into any of *n* wagons (not necessarily into the one he's just left and not necessarily into the neighbouring one). If the train is idle for several minutes then each such minute the stowaway leaves the train and enters it back. Let's determine the order of the players' moves. If at the given minute the train is moving, then first the stowaway moves and then the controller does. If at this minute the train is idle, then first the stowaway leaves the train, then the controller moves and then the stowaway enters the train. If at some point in time the stowaway and the controller happen to be in one wagon, then the controller wins: he makes the stowaway pay fine. If after a while the stowaway reaches the terminal train station, then the stowaway wins: he simply leaves the station during his move and never returns there again. At any moment of time the players know each other's positions. The players play in the optimal way. Specifically, if the controller wins, then the stowaway plays so as to lose as late as possible. As all the possible moves for the controller are determined uniquely, then he is considered to play optimally always. Determine the winner. The input will be provided via standard input and looks as follows: The first line contains three integers *n*, *m* and *k*. They represent the number of wagons in the train, the stowaway's and the controller's initial positions correspondingly (2<=≤<=*n*<=≤<=50, 1<=≤<=*m*,<=*k*<=≤<=*n*, *m*<=≠<=*k*). The second line contains the direction in which a controller moves. "to head" means that the controller moves to the train's head and "to tail" means that the controller moves to its tail. It is guaranteed that in the direction in which the controller is moving, there is at least one wagon. Wagon 1 is the head, and wagon *n* is the tail. The third line has the length from 1 to 200 and consists of symbols "0" and "1". The *i*-th symbol contains information about the train's state at the *i*-th minute of time. "0" means that in this very minute the train moves and "1" means that the train in this very minute stands idle. The last symbol of the third line is always "1" — that's the terminal train station. You should write the solution as standard output as follows: If the stowaway wins, print "Stowaway" without quotes. Otherwise, print "Controller" again without quotes, then, separated by a space, print the number of a minute, at which the stowaway will be caught. Here are example inputs and outputs for the problem: Example Input 1: 5 3 2 to head 0001001 Example Output 1: Stowaway Example Input 2: 3 2 1 to tail 0001 Example Output 2: Controller 2 Now solve the problem by providing the code.
from sys import stdin, stdout, exit n, m, k = map(int, stdin.readline().split()) d = 1 if stdin.readline()[6] == 'l' else -1 m = 1 if m < k else n for i, c in enumerate(stdin.readline(), 1): if c == '0': if k == 1: k, d = 2, 1 elif k == n: k, d = n - 1, -1 else: k += d if m == k: stdout.write('Controller ' + str(i)) exit(0) else: if k == 1: k, d, m = 2, 1, 1 elif k == n: k, d, m = n - 1, -1, n elif d == 1: k += 1 m = 1 else: k -= 1 m = n stdout.write('Stowaway')
vfc_83821
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 3 2\nto head\n0001001", "output": "Stowaway", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
248
Solve the following coding problem using the programming language python: One foggy Stockholm morning, Karlsson decided to snack on some jam in his friend Lillebror Svantenson's house. Fortunately for Karlsson, there wasn't anybody in his friend's house. Karlsson was not going to be hungry any longer, so he decided to get some food in the house. Karlsson's gaze immediately fell on *n* wooden cupboards, standing in the kitchen. He immediately realized that these cupboards have hidden jam stocks. Karlsson began to fly greedily around the kitchen, opening and closing the cupboards' doors, grab and empty all the jars of jam that he could find. And now all jars of jam are empty, Karlsson has had enough and does not want to leave traces of his stay, so as not to let down his friend. Each of the cupboards has two doors: the left one and the right one. Karlsson remembers that when he rushed to the kitchen, all the cupboards' left doors were in the same position (open or closed), similarly, all the cupboards' right doors were in the same position (open or closed). Karlsson wants the doors to meet this condition as well by the time the family returns. Karlsson does not remember the position of all the left doors, also, he cannot remember the position of all the right doors. Therefore, it does not matter to him in what position will be all left or right doors. It is important to leave all the left doors in the same position, and all the right doors in the same position. For example, all the left doors may be closed, and all the right ones may be open. Karlsson needs one second to open or close a door of a cupboard. He understands that he has very little time before the family returns, so he wants to know the minimum number of seconds *t*, in which he is able to bring all the cupboard doors in the required position. Your task is to write a program that will determine the required number of seconds *t*. The input will be provided via standard input and looks as follows: The first input line contains a single integer *n* — the number of cupboards in the kitchen (2<=≤<=*n*<=≤<=104). Then follow *n* lines, each containing two integers *l**i* and *r**i* (0<=≤<=*l**i*,<=*r**i*<=≤<=1). Number *l**i* equals one, if the left door of the *i*-th cupboard is opened, otherwise number *l**i* equals zero. Similarly, number *r**i* equals one, if the right door of the *i*-th cupboard is opened, otherwise number *r**i* equals zero. The numbers in the lines are separated by single spaces. You should write the solution as standard output as follows: In the only output line print a single integer *t* — the minimum number of seconds Karlsson needs to change the doors of all cupboards to the position he needs. Here are example inputs and outputs for the problem: Example Input 1: 5 0 1 1 0 0 1 1 1 0 1 Example Output 1: 3 Now solve the problem by providing the code.
n = int(input()) countofopenleft = 0 countofopenright = 0 for _ in range(n): l,r = input().split() if l=='1': countofopenleft +=1 if r=='1': countofopenright+=1 countofcloseleft = n- countofopenleft countofcloseright = n - countofopenright totalmoves = min(countofcloseleft,countofopenleft)+min(countofopenright, countofcloseright) print(totalmoves)
vfc_83825
{ "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\n0 1\n1 0\n0 1\n1 1\n0 1", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n0 0\n0 0", "output": "0", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
234
Solve the following coding problem using the programming language python: Scientists say a lot about the problems of global warming and cooling of the Earth. Indeed, such natural phenomena strongly influence all life on our planet. Our hero Vasya is quite concerned about the problems. He decided to try a little experiment and observe how outside daily temperature changes. He hung out a thermometer on the balcony every morning and recorded the temperature. He had been measuring the temperature for the last *n* days. Thus, he got a sequence of numbers *t*1,<=*t*2,<=...,<=*t**n*, where the *i*-th number is the temperature on the *i*-th day. Vasya analyzed the temperature statistics in other cities, and came to the conclusion that the city has no environmental problems, if first the temperature outside is negative for some non-zero number of days, and then the temperature is positive for some non-zero number of days. More formally, there must be a positive integer *k* (1<=≤<=*k*<=≤<=*n*<=-<=1) such that *t*1<=&lt;<=0,<=*t*2<=&lt;<=0,<=...,<=*t**k*<=&lt;<=0 and *t**k*<=+<=1<=&gt;<=0,<=*t**k*<=+<=2<=&gt;<=0,<=...,<=*t**n*<=&gt;<=0. In particular, the temperature should never be zero. If this condition is not met, Vasya decides that his city has environmental problems, and gets upset. You do not want to upset Vasya. Therefore, you want to select multiple values of temperature and modify them to satisfy Vasya's condition. You need to know what the least number of temperature values needs to be changed for that. The input will be provided via standard input and looks as follows: The first line contains a single integer *n* (2<=≤<=*n*<=≤<=105) — the number of days for which Vasya has been measuring the temperature. The second line contains a sequence of *n* integers *t*1,<=*t*2,<=...,<=*t**n* (|*t**i*|<=≤<=109) — the sequence of temperature values. Numbers *t**i* are separated by single spaces. You should write the solution as standard output as follows: Print a single integer — the answer to the given task. Here are example inputs and outputs for the problem: Example Input 1: 4 -1 1 -2 1 Example Output 1: 1 Example Input 2: 5 0 -1 1 2 -5 Example Output 2: 2 Now solve the problem by providing the code.
with open('input.txt', 'r') as f: n = int(f.readline()) g = list(map(int, f.readline().split())) a = sum(x <= 0 for x in g) for i in g[:-1]: a += (i > 0) - (i < 0) n = min(n, a) print(n, file=open("output.txt", "w"))
vfc_83829
{ "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-1 1 -2 1", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n0 -1 1 2 -5", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n0 0 0 0 0 0", "output": "6", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
461
Solve the following coding problem using the programming language python: Appleman and Toastman play a game. Initially Appleman gives one group of *n* numbers to the Toastman, then they start to complete the following tasks: - Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. - Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman. After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get? The input will be provided via standard input and looks as follows: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=3·105). The second line contains *n* integers *a*1, *a*2, ..., *a**n* (1<=≤<=*a**i*<=≤<=106) — the initial group that is given to Toastman. You should write the solution as standard output as follows: Print a single integer — the largest possible score. Here are example inputs and outputs for the problem: Example Input 1: 3 3 1 5 Example Output 1: 26 Example Input 2: 1 10 Example Output 2: 10 Now solve the problem by providing the code.
n=int(input()) s=input() x=list() x=s.split() y=sorted(x,key=int) ans=0 for i in range(n): ans+=int(y[i])*(i+2) ans-=int(y[n-1]) print(ans)
vfc_83833
{ "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 5", "output": "26", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n10", "output": "10", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n8 10 2 5 6 2 4 7 2 1", "output": "376", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n171308 397870 724672 431255 228496 892002 542924 718337 888642 161821", "output": "40204082", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
864
Solve the following coding problem using the programming language python: Petya and Vasya decided to play a game. They have *n* cards (*n* is an even number). A single integer is written on each card. Before the game Petya will choose an integer and after that Vasya will choose another integer (different from the number that Petya chose). During the game each player takes all the cards with number he chose. For example, if Petya chose number 5 before the game he will take all cards on which 5 is written and if Vasya chose number 10 before the game he will take all cards on which 10 is written. The game is considered fair if Petya and Vasya can take all *n* cards, and the number of cards each player gets is the same. Determine whether Petya and Vasya can choose integer numbers before the game so that the game is fair. The input will be provided via standard input and looks as follows: The first line contains a single integer *n* (2<=≤<=*n*<=≤<=100) — number of cards. It is guaranteed that *n* is an even number. The following *n* lines contain a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (one integer per line, 1<=≤<=*a**i*<=≤<=100) — numbers written on the *n* cards. You should write the solution as standard output as follows: If it is impossible for Petya and Vasya to choose numbers in such a way that the game will be fair, print "NO" (without quotes) in the first line. In this case you should not print anything more. In the other case print "YES" (without quotes) in the first line. In the second line print two distinct integers — number that Petya should choose and the number that Vasya should choose to make the game fair. If there are several solutions, print any of them. Here are example inputs and outputs for the problem: Example Input 1: 4 11 27 27 11 Example Output 1: YES 11 27 Example Input 2: 2 6 6 Example Output 2: NO Example Input 3: 6 10 20 30 20 10 20 Example Output 3: NO Example Input 4: 6 1 1 2 2 3 3 Example Output 4: NO Now solve the problem by providing the code.
n = int(input()) a = [] for i in range(n): a.append(int(input())) p = 0 v = 0 a = sorted(a) flag = True for i in range(n//2): p = a[i] v = a[-1] m = a.count(p) z = a.count(v) if m+z != n: break if m == z and p != v: print("YES") print(f"{p} {v}") flag = False break if flag: print("NO")
vfc_83837
{ "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\n11\n27\n27\n11", "output": "YES\n11 27", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n6\n6", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n10\n20\n30\n20\n10\n20", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n1\n1\n2\n2\n3\n3", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1\n100", "output": "YES\n1 100", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1\n1", "output": "NO", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
435
Solve the following coding problem using the programming language python: It's that time of the year when the Russians flood their countryside summer cottages (dachas) and the bus stop has a lot of people. People rarely go to the dacha on their own, it's usually a group, so the people stand in queue by groups. The bus stop queue has *n* groups of people. The *i*-th group from the beginning has *a**i* people. Every 30 minutes an empty bus arrives at the bus stop, it can carry at most *m* people. Naturally, the people from the first group enter the bus first. Then go the people from the second group and so on. Note that the order of groups in the queue never changes. Moreover, if some group cannot fit all of its members into the current bus, it waits for the next bus together with other groups standing after it in the queue. Your task is to determine how many buses is needed to transport all *n* groups to the dacha countryside. The input will be provided via standard input and looks as follows: The first line contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100). The next line contains *n* integers: *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=*m*). You should write the solution as standard output as follows: Print a single integer — the number of buses that is needed to transport all *n* groups to the dacha countryside. Here are example inputs and outputs for the problem: Example Input 1: 4 3 2 3 2 1 Example Output 1: 3 Example Input 2: 3 4 1 2 1 Example Output 2: 1 Now solve the problem by providing the code.
from sys import stdin def main(): n, m = map(int, stdin.readline().strip().split()) it = iter(map(int, stdin.readline().strip().split())) try: cnt = vol = 0 while True: x = next(it) if vol < x: cnt += 1 vol = m vol -= x except StopIteration: return cnt print(main())
vfc_83841
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 3\n2 3 2 1", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 4\n1 2 1", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 5\n4", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 1\n1 1 1 1 1", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 4\n1 3 2 3 4 1", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 8\n6 1 1 1 4 5", "output": "3", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
452
Solve the following coding problem using the programming language python: Alex enjoys performing magic tricks. He has a trick that requires a deck of *n* cards. He has *m* identical decks of *n* different cards each, which have been mixed together. When Alex wishes to perform the trick, he grabs *n* cards at random and performs the trick with those. The resulting deck looks like a normal deck, but may have duplicates of some cards. The trick itself is performed as follows: first Alex allows you to choose a random card from the deck. You memorize the card and put it back in the deck. Then Alex shuffles the deck, and pulls out a card. If the card matches the one you memorized, the trick is successful. You don't think Alex is a very good magician, and that he just pulls a card randomly from the deck. Determine the probability of the trick being successful if this is the case. The input will be provided via standard input and looks as follows: First line of the input consists of two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=1000), separated by space — number of cards in each deck, and number of decks. You should write the solution as standard output as follows: On the only line of the output print one floating point number – probability of Alex successfully performing the trick. Relative or absolute error of your answer should not be higher than 10<=-<=6. Here are example inputs and outputs for the problem: Example Input 1: 2 2 Example Output 1: 0.6666666666666666 Example Input 2: 4 4 Example Output 2: 0.4000000000000000 Example Input 3: 1 2 Example Output 3: 1.0000000000000000 Now solve the problem by providing the code.
def cal(m,n,i): tot=1 for j in range(1,n-i+1): tot=tot*(n*m-m-n+i+j)/(n*m-n+i+j) for j in range(1,i+1): tot=tot*(m-i+j)/(n*m-n+j) for j in range(1,i+1): tot=tot/j*(n-i+j) return tot n,m = input().split() n = int(n) m = int(m) ans = 0 for i in range(1, min(n,m)+1): ans += i * i /n * cal(m,n,i) print(ans)
vfc_83845
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2", "output": "0.6666666666666666", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 4", "output": "0.4000000000000000", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 2", "output": "1.0000000000000000", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
911
Solve the following coding problem using the programming language python: It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into *a* pieces, and the second one — into *b* pieces. Ivan knows that there will be *n* people at the celebration (including himself), so Ivan has set *n* plates for the cakes. Now he is thinking about how to distribute the cakes between the plates. Ivan wants to do it in such a way that all following conditions are met: 1. Each piece of each cake is put on some plate; 1. Each plate contains at least one piece of cake; 1. No plate contains pieces of both cakes. To make his guests happy, Ivan wants to distribute the cakes in such a way that the minimum number of pieces on the plate is maximized. Formally, Ivan wants to know the maximum possible number *x* such that he can distribute the cakes according to the aforementioned conditions, and each plate will contain at least *x* pieces of cake. Help Ivan to calculate this number *x*! The input will be provided via standard input and looks as follows: The first line contains three integers *n*, *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100, 2<=≤<=*n*<=≤<=*a*<=+<=*b*) — the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively. You should write the solution as standard output as follows: Print the maximum possible number *x* such that Ivan can distribute the cake in such a way that each plate will contain at least *x* pieces of cake. Here are example inputs and outputs for the problem: Example Input 1: 5 2 3 Example Output 1: 1 Example Input 2: 4 7 10 Example Output 2: 3 Now solve the problem by providing the code.
import sys,math #sys.stdin=open('input.txt','r') #sys.stdout=open('output.txt','w') def solve(): n,a,b=map(int,input().split()) ans=0 for i in range(1,n): mina=a//i minb=b//(n-i) ans1=min(mina,minb) ans=max(ans,ans1) print(ans) solve()
vfc_83853
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 2 3", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 7 10", "output": "3", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
932
Solve the following coding problem using the programming language python: You are given a string *A*. Find a string *B*, where *B* is a palindrome and *A* is a subsequence of *B*. A subsequence of a string is a string that can be derived from it by deleting some (not necessarily consecutive) characters without changing the order of the remaining characters. For example, "cotst" is a subsequence of "contest". A palindrome is a string that reads the same forward or backward. The length of string *B* should be at most 104. It is guaranteed that there always exists such string. You do not need to find the shortest answer, the only restriction is that the length of string *B* should not exceed 104. The input will be provided via standard input and looks as follows: First line contains a string *A* (1<=≤<=|*A*|<=≤<=103) consisting of lowercase Latin letters, where |*A*| is a length of *A*. You should write the solution as standard output as follows: Output single line containing *B* consisting of only lowercase Latin letters. You do not need to find the shortest answer, the only restriction is that the length of string *B* should not exceed 104. If there are many possible *B*, print any of them. Here are example inputs and outputs for the problem: Example Input 1: aba Example Output 1: aba Example Input 2: ab Example Output 2: aabaa Now solve the problem by providing the code.
a=input() a1,c=a[::-1],-1 if a==a1: print(a) quit() for i in range(len(a)): if a[i:]==a1[:-i]: c=i break if c==-1: print(a+a1) quit() print(a+a[:c][::-1])
vfc_83857
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "aba", "output": "abaaba", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
225
Solve the following coding problem using the programming language python: A dice is a cube, its faces contain distinct integers from 1 to 6 as black points. The sum of numbers at the opposite dice faces always equals 7. Please note that there are only two dice (these dices are mirror of each other) that satisfy the given constraints (both of them are shown on the picture on the left). Alice and Bob play dice. Alice has built a tower from *n* dice. We know that in this tower the adjacent dice contact with faces with distinct numbers. Bob wants to uniquely identify the numbers written on the faces of all dice, from which the tower is built. Unfortunately, Bob is looking at the tower from the face, and so he does not see all the numbers on the faces. Bob sees the number on the top of the tower and the numbers on the two adjacent sides (on the right side of the picture shown what Bob sees). Help Bob, tell whether it is possible to uniquely identify the numbers on the faces of all the dice in the tower, or not. The input will be provided via standard input and looks as follows: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=100) — the number of dice in the tower. The second line contains an integer *x* (1<=≤<=*x*<=≤<=6) — the number Bob sees at the top of the tower. Next *n* lines contain two space-separated integers each: the *i*-th line contains numbers *a**i*,<=*b**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=6; *a**i*<=≠<=*b**i*) — the numbers Bob sees on the two sidelong faces of the *i*-th dice in the tower. Consider the dice in the tower indexed from top to bottom from 1 to *n*. That is, the topmost dice has index 1 (the dice whose top face Bob can see). It is guaranteed that it is possible to make a dice tower that will look as described in the input. You should write the solution as standard output as follows: Print "YES" (without the quotes), if it is possible to to uniquely identify the numbers on the faces of all the dice in the tower. If it is impossible, print "NO" (without the quotes). Here are example inputs and outputs for the problem: Example Input 1: 3 6 3 2 5 4 2 4 Example Output 1: YES Example Input 2: 3 3 2 6 4 1 5 3 Example Output 2: NO Now solve the problem by providing the code.
import sys f = sys.stdin #f = open("input.txt", "r") n = int(f.readline().strip()) u = int(f.readline().strip()) a, b = [], [] for i in f: a.append(int(i.split()[0])) b.append(int(i.split()[1])) c = [[1, 2, 3, 4, 5, 6] for i in range(n)] for i in range(n): c[i].remove(a[i]) c[i].remove(b[i]) c[i].remove(7-a[i]) c[i].remove(7-b[i]) for i in range(n-1): if c[i] != c[i+1]: print("NO") break else: print("YES")
vfc_83861
{ "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\n6\n3 2\n5 4\n2 4", "output": "YES", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
769
Solve the following coding problem using the programming language python: There is the faculty of Computer Science in Berland. In the social net "TheContact!" for each course of this faculty there is the special group whose name equals the year of university entrance of corresponding course of students at the university. Each of students joins the group of his course and joins all groups for which the year of student's university entrance differs by no more than *x* from the year of university entrance of this student, where *x* — some non-negative integer. A value *x* is not given, but it can be uniquely determined from the available data. Note that students don't join other groups. You are given the list of groups which the student Igor joined. According to this information you need to determine the year of Igor's university entrance. The input will be provided via standard input and looks as follows: The first line contains the positive odd integer *n* (1<=≤<=*n*<=≤<=5) — the number of groups which Igor joined. The next line contains *n* distinct integers *a*1,<=*a*2,<=...,<=*a**n* (2010<=≤<=*a**i*<=≤<=2100) — years of student's university entrance for each group in which Igor is the member. It is guaranteed that the input data is correct and the answer always exists. Groups are given randomly. You should write the solution as standard output as follows: Print the year of Igor's university entrance. Here are example inputs and outputs for the problem: Example Input 1: 3 2014 2016 2015 Example Output 1: 2015 Example Input 2: 1 2050 Example Output 2: 2050 Now solve the problem by providing the code.
n = int(input()) g = list(map(int, input().split())) print(sum(g) // n)
vfc_83869
{ "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\n2014 2016 2015", "output": "2015", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n2050", "output": "2050", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n2010", "output": "2010", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n2011", "output": "2011", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
645
Solve the following coding problem using the programming language python: It is a balmy spring afternoon, and Farmer John's *n* cows are ruminating about link-cut cacti in their stalls. The cows, labeled 1 through *n*, are arranged so that the *i*-th cow occupies the *i*-th stall from the left. However, Elsie, after realizing that she will forever live in the shadows beyond Bessie's limelight, has formed the Mischievous Mess Makers and is plotting to disrupt this beautiful pastoral rhythm. While Farmer John takes his *k* minute long nap, Elsie and the Mess Makers plan to repeatedly choose two distinct stalls and swap the cows occupying those stalls, making no more than one swap each minute. Being the meticulous pranksters that they are, the Mischievous Mess Makers would like to know the maximum messiness attainable in the *k* minutes that they have. We denote as *p**i* the label of the cow in the *i*-th stall. The messiness of an arrangement of cows is defined as the number of pairs (*i*,<=*j*) such that *i*<=&lt;<=*j* and *p**i*<=&gt;<=*p**j*. The input will be provided via standard input and looks as follows: The first line of the input contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=100<=000) — the number of cows and the length of Farmer John's nap, respectively. You should write the solution as standard output as follows: Output a single integer, the maximum messiness that the Mischievous Mess Makers can achieve by performing no more than *k* swaps. Here are example inputs and outputs for the problem: Example Input 1: 5 2 Example Output 1: 10 Example Input 2: 1 10 Example Output 2: 0 Now solve the problem by providing the code.
n, k = map(int, input().split()) ans = 0 d = n for i in range(min(k, n // 2)): ans += (d*2-3) d -= 2 print(ans)
vfc_83877
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 2", "output": "10", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 10", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "100000 2", "output": "399990", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "8 3", "output": "27", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 1", "output": "11", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
253
Solve the following coding problem using the programming language python: There are *n* boys and *m* girls studying in the class. They should stand in a line so that boys and girls alternated there as much as possible. Let's assume that positions in the line are indexed from left to right by numbers from 1 to *n*<=+<=*m*. Then the number of integers *i* (1<=≤<=*i*<=&lt;<=*n*<=+<=*m*) such that positions with indexes *i* and *i*<=+<=1 contain children of different genders (position *i* has a girl and position *i*<=+<=1 has a boy or vice versa) must be as large as possible. Help the children and tell them how to form the line. The input will be provided via standard input and looks as follows: The single line of the input contains two integers *n* and *m* (1<=≤<=*n*,<=*m*<=≤<=100), separated by a space. You should write the solution as standard output as follows: Print a line of *n*<=+<=*m* characters. Print on the *i*-th position of the line character "B", if the *i*-th position of your arrangement should have a boy and "G", if it should have a girl. Of course, the number of characters "B" should equal *n* and the number of characters "G" should equal *m*. If there are multiple optimal solutions, print any of them. Here are example inputs and outputs for the problem: Example Input 1: 3 3 Example Output 1: GBGBGB Example Input 2: 4 2 Example Output 2: BGBGBB Now solve the problem by providing the code.
f = open('input.txt', 'r') line = f.readline() n, m = map(int, line.split()) f.close() ans = '' cur = 'B' if n > m else 'G' while n and m: ans += cur if cur == 'B': n -= 1 cur = 'G' else: m -= 1 cur = 'B' while n: ans += 'B' n -= 1 while m: ans += 'G' m -= 1 f = open('output.txt', 'w') f.write(ans)
vfc_83881
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3", "output": "GBGBGB", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 2", "output": "BGBGBB", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5", "output": "GBGBGBGBGB", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
174
Solve the following coding problem using the programming language python: A group of *n* merry programmers celebrate Robert Floyd's birthday. Polucarpus has got an honourable task of pouring Ber-Cola to everybody. Pouring the same amount of Ber-Cola to everybody is really important. In other words, the drink's volume in each of the *n* mugs must be the same. Polycarpus has already began the process and he partially emptied the Ber-Cola bottle. Now the first mug has *a*1 milliliters of the drink, the second one has *a*2 milliliters and so on. The bottle has *b* milliliters left and Polycarpus plans to pour them into the mugs so that the main equation was fulfilled. Write a program that would determine what volume of the drink Polycarpus needs to add into each mug to ensure that the following two conditions were fulfilled simultaneously: - there were *b* milliliters poured in total. That is, the bottle need to be emptied; - after the process is over, the volumes of the drink in the mugs should be equal. The input will be provided via standard input and looks as follows: The first line contains a pair of integers *n*, *b* (2<=≤<=*n*<=≤<=100,<=1<=≤<=*b*<=≤<=100), where *n* is the total number of friends in the group and *b* is the current volume of drink in the bottle. The second line contains a sequence of integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=100), where *a**i* is the current volume of drink in the *i*-th mug. You should write the solution as standard output as follows: Print a single number "-1" (without the quotes), if there is no solution. Otherwise, print *n* float numbers *c*1,<=*c*2,<=...,<=*c**n*, where *c**i* is the volume of the drink to add in the *i*-th mug. Print the numbers with no less than 6 digits after the decimal point, print each *c**i* on a single line. Polycarpus proved that if a solution exists then it is unique. Russian locale is installed by default on the testing computer. Make sure that your solution use the point to separate the integer part of a real number from the decimal, not a comma. Here are example inputs and outputs for the problem: Example Input 1: 5 50 1 2 3 4 5 Example Output 1: 12.000000 11.000000 10.000000 9.000000 8.000000 Example Input 2: 2 2 1 100 Example Output 2: -1 Now solve the problem by providing the code.
# import sys # sys.stdin = open("test.txt", 'r') n, b = list(map(int, input().split())) a = list(map(int, input().split())) ans = [] t = sum(a) + b p = t/n for v in a: s = p-v if s < 0: print(-1) break else: ans.append(s) else: for s in ans: print(f'{s:.6f}')
vfc_83885
{ "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 50\n1 2 3 4 5", "output": "12.000000\n11.000000\n10.000000\n9.000000\n8.000000", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n1 100", "output": "-1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
832
Solve the following coding problem using the programming language python: It's one more school day now. Sasha doesn't like classes and is always bored at them. So, each day he invents some game and plays in it alone or with friends. Today he invented one simple game to play with Lena, with whom he shares a desk. The rules are simple. Sasha draws *n* sticks in a row. After that the players take turns crossing out exactly *k* sticks from left or right in each turn. Sasha moves first, because he is the inventor of the game. If there are less than *k* sticks on the paper before some turn, the game ends. Sasha wins if he makes strictly more moves than Lena. Sasha wants to know the result of the game before playing, you are to help him. The input will be provided via standard input and looks as follows: The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=1018, *k*<=≤<=*n*) — the number of sticks drawn by Sasha and the number *k* — the number of sticks to be crossed out on each turn. You should write the solution as standard output as follows: If Sasha wins, print "YES" (without quotes), otherwise print "NO" (without quotes). You can print each letter in arbitrary case (upper of lower). Here are example inputs and outputs for the problem: Example Input 1: 1 1 Example Output 1: YES Example Input 2: 10 4 Example Output 2: NO Now solve the problem by providing the code.
import sys toks = (tok for tok in sys.stdin.read().split()) n = int(next(toks)) k = int(next(toks)) total = n // k if total % 2 == 0: print('NO') else: print('YES')
vfc_83889
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 1", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 4", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "251656215122324104 164397544865601257", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "963577813436662285 206326039287271924", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000000000000000000 1", "output": "NO", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
630
Solve the following coding problem using the programming language python: The numbers of all offices in the new building of the Tax Office of IT City will have lucky numbers. Lucky number is a number that consists of digits 7 and 8 only. Find the maximum number of offices in the new building of the Tax Office given that a door-plate can hold a number not longer than *n* digits. The input will be provided via standard input and looks as follows: The only line of input contains one integer *n* (1<=≤<=*n*<=≤<=55) — the maximum length of a number that a door-plate can hold. You should write the solution as standard output as follows: Output one integer — the maximum number of offices, than can have unique lucky numbers not longer than *n* digits. Here are example inputs and outputs for the problem: Example Input 1: 2 Example Output 1: 6 Now solve the problem by providing the code.
a=int(input()) print(2*((2**a)-1))
vfc_83893
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "500" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2", "output": "6", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
670
Solve the following coding problem using the programming language python: On the planet Mars a year lasts exactly *n* days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of days off per year on Mars. The input will be provided via standard input and looks as follows: The first line of the input contains a positive integer *n* (1<=≤<=*n*<=≤<=1<=000<=000) — the number of days in a year on Mars. You should write the solution as standard output as follows: Print two integers — the minimum possible and the maximum possible number of days off per year on Mars. Here are example inputs and outputs for the problem: Example Input 1: 14 Example Output 1: 4 4 Example Input 2: 2 Example Output 2: 0 2 Now solve the problem by providing the code.
w,e=divmod(int(input()),7) print(w*2+int(e==6),w*2+min(e,2))
vfc_83897
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "14", "output": "4 4", "type": "stdin_stdout" }, { "fn_name": null, "input": "2", "output": "0 2", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
1007
Solve the following coding problem using the programming language python: You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers. For instance, if we are given an array $[10, 20, 30, 40]$, we can permute it so that it becomes $[20, 40, 10, 30]$. Then on the first and the second positions the integers became larger ($20&gt;10$, $40&gt;20$) and did not on the third and the fourth, so for this permutation, the number that Vasya wants to maximize equals $2$. Read the note for the first example, there is one more demonstrative test case. Help Vasya to permute integers in such way that the number of positions in a new array, where integers are greater than in the original one, is maximal. The input will be provided via standard input and looks as follows: The first line contains a single integer $n$ ($1 \leq n \leq 10^5$) — the length of the array. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) — the elements of the array. You should write the solution as standard output as follows: Print a single integer — the maximal number of the array's elements which after a permutation will stand on the position where a smaller element stood in the initial array. Here are example inputs and outputs for the problem: Example Input 1: 7 10 1 1 1 5 5 3 Example Output 1: 4 Example Input 2: 5 1 1 1 1 1 Example Output 2: 0 Now solve the problem by providing the code.
from collections import Counter n=int(input()) p=list(map(int, input().split(' '))) s=Counter(p) y=[s[i] for i in s] y.sort() y=[0]+y m=len(y) ans=0 tem=0 for i in range (0,m): if y[i]>tem: ans=ans+(m-i-1)*(y[i]-tem) tem=y[i] print(ans)
vfc_83901
{ "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\n10 1 1 1 5 5 3", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 1 1 1 1", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n300000000 200000000 300000000 200000000 1000000000 300000000", "output": "3", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
363
Solve the following coding problem using the programming language python: There is a fence in front of Polycarpus's home. The fence consists of *n* planks of the same width which go one after another from left to right. The height of the *i*-th plank is *h**i* meters, distinct planks can have distinct heights. Polycarpus has bought a posh piano and is thinking about how to get it into the house. In order to carry out his plan, he needs to take exactly *k* consecutive planks from the fence. Higher planks are harder to tear off the fence, so Polycarpus wants to find such *k* consecutive planks that the sum of their heights is minimal possible. Write the program that finds the indexes of *k* consecutive planks with minimal total height. Pay attention, the fence is not around Polycarpus's home, it is in front of home (in other words, the fence isn't cyclic). The input will be provided via standard input and looks as follows: The first line of the input contains integers *n* and *k* (1<=≤<=*n*<=≤<=1.5·105,<=1<=≤<=*k*<=≤<=*n*) — the number of planks in the fence and the width of the hole for the piano. The second line contains the sequence of integers *h*1,<=*h*2,<=...,<=*h**n* (1<=≤<=*h**i*<=≤<=100), where *h**i* is the height of the *i*-th plank of the fence. You should write the solution as standard output as follows: Print such integer *j* that the sum of the heights of planks *j*, *j*<=+<=1, ..., *j*<=+<=*k*<=-<=1 is the minimum possible. If there are multiple such *j*'s, print any of them. Here are example inputs and outputs for the problem: Example Input 1: 7 3 1 2 6 1 1 7 1 Example Output 1: 3 Now solve the problem by providing the code.
from sys import stdin, stdout def input(): return stdin.readline().strip() def print(string): return stdout.write(str(string) + "\n") def main(): n, k = map(int, input().split()) h = [int(x) for x in input().split()] dp = [None] * n dp[0] = sum(h[:k]) smallest_i = 0 for i in range(n-k): dp[i+1] = dp[i] - h[i] + h[i+k] if dp[i+1] < dp[smallest_i]: smallest_i = i+1 print(smallest_i+1) if __name__ == "__main__": main()
vfc_83905
{ "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\n1 2 6 1 1 7 1", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n100", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
333
Solve the following coding problem using the programming language python: Gerald has been selling state secrets at leisure. All the secrets cost the same: *n* marks. The state which secrets Gerald is selling, has no paper money, only coins. But there are coins of all positive integer denominations that are powers of three: 1 mark, 3 marks, 9 marks, 27 marks and so on. There are no coins of other denominations. Of course, Gerald likes it when he gets money without the change. And all buyers respect him and try to give the desired sum without change, if possible. But this does not always happen. One day an unlucky buyer came. He did not have the desired sum without change. Then he took out all his coins and tried to give Gerald a larger than necessary sum with as few coins as possible. What is the maximum number of coins he could get? The formal explanation of the previous paragraph: we consider all the possible combinations of coins for which the buyer can not give Gerald the sum of *n* marks without change. For each such combination calculate the minimum number of coins that can bring the buyer at least *n* marks. Among all combinations choose the maximum of the minimum number of coins. This is the number we want. The input will be provided via standard input and looks as follows: The single line contains a single integer *n* (1<=≤<=*n*<=≤<=1017). Please, do not use the %lld specifier to read or write 64 bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. You should write the solution as standard output as follows: In a single line print an integer: the maximum number of coins the unlucky buyer could have paid with. Here are example inputs and outputs for the problem: Example Input 1: 1 Example Output 1: 1 Example Input 2: 4 Example Output 2: 2 Now solve the problem by providing the code.
n=int(input()) while n%3==0: n//=3 print((n-1)//3+1)
vfc_83913
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "4", "output": "2", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
384
Solve the following coding problem using the programming language python: Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (*x*,<=*y*), he can move to (or attack) positions (*x*<=+<=1,<=*y*), (*x*–1,<=*y*), (*x*,<=*y*<=+<=1) and (*x*,<=*y*–1). Iahub wants to know how many Coders can be placed on an *n*<=×<=*n* chessboard, so that no Coder attacks any other Coder. The input will be provided via standard input and looks as follows: The first line contains an integer *n* (1<=≤<=*n*<=≤<=1000). You should write the solution as standard output as follows: On the first line print an integer, the maximum number of Coders that can be placed on the chessboard. On each of the next *n* lines print *n* characters, describing the configuration of the Coders. For an empty cell print an '.', and for a Coder print a 'C'. If there are multiple correct answers, you can print any. Here are example inputs and outputs for the problem: Example Input 1: 2 Example Output 1: 2 C. .C Now solve the problem by providing the code.
k=0 c=0 s='' ss='' n=int(input()) for i in range(n): if k%2==0: s+='C' ss+='.' else: s+='.' ss+='C' k+=1 k=0 for i in range(n): if k%2==0: c+=s.count('C') else: c+=ss.count('C') k+=1 k=0 print(c) for i in range(n): if k%2==0: print(s) else: print(ss) k+=1
vfc_83917
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2", "output": "2\nC.\n.C", "type": "stdin_stdout" }, { "fn_name": null, "input": "3", "output": "5\nC.C\n.C.\nC.C", "type": "stdin_stdout" }, { "fn_name": null, "input": "4", "output": "8\nC.C.\n.C.C\nC.C.\n.C.C", "type": "stdin_stdout" }, { "fn_name": null, "input": "10", "output": "50\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C\nC.C.C.C.C.\n.C.C.C.C.C", "type": "stdin_stdout" }, { "fn_name": null, "input": "15", "output": "113\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C\n.C.C.C.C.C.C.C.\nC.C.C.C.C.C.C.C", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
90
Solve the following coding problem using the programming language python: A group of university students wants to get to the top of a mountain to have a picnic there. For that they decided to use a cableway. A cableway is represented by some cablecars, hanged onto some cable stations by a cable. A cable is scrolled cyclically between the first and the last cable stations (the first of them is located at the bottom of the mountain and the last one is located at the top). As the cable moves, the cablecar attached to it move as well. The number of cablecars is divisible by three and they are painted three colors: red, green and blue, in such manner that after each red cablecar goes a green one, after each green cablecar goes a blue one and after each blue cablecar goes a red one. Each cablecar can transport no more than two people, the cablecars arrive with the periodicity of one minute (i. e. every minute) and it takes exactly 30 minutes for a cablecar to get to the top. All students are divided into three groups: *r* of them like to ascend only in the red cablecars, *g* of them prefer only the green ones and *b* of them prefer only the blue ones. A student never gets on a cablecar painted a color that he doesn't like, The first cablecar to arrive (at the moment of time 0) is painted red. Determine the least time it will take all students to ascend to the mountain top. The input will be provided via standard input and looks as follows: The first line contains three integers *r*, *g* and *b* (0<=≤<=*r*,<=*g*,<=*b*<=≤<=100). It is guaranteed that *r*<=+<=*g*<=+<=*b*<=&gt;<=0, it means that the group consists of at least one student. You should write the solution as standard output as follows: Print a single number — the minimal time the students need for the whole group to ascend to the top of the mountain. Here are example inputs and outputs for the problem: Example Input 1: 1 3 2 Example Output 1: 34 Example Input 2: 3 2 1 Example Output 2: 33 Now solve the problem by providing the code.
import math m = 0 p = 0 for pos, i in enumerate(map(int, input().split())): if math.ceil(i/2) >= m: m = math.ceil(i/2) p = pos res = 0 m -= 1 while m > 0: res += 3 m -= 1 print(res + p + 30)
vfc_83921
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 3 2", "output": "34", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2 1", "output": "33", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 5 2", "output": "37", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 10 10", "output": "44", "type": "stdin_stdout" }, { "fn_name": null, "input": "29 7 24", "output": "72", "type": "stdin_stdout" }, { "fn_name": null, "input": "28 94 13", "output": "169", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
56
Solve the following coding problem using the programming language python: According to Berland laws it is only allowed to sell alcohol to people not younger than 18 years. Vasya's job is to monitor the law's enforcement. Tonight he entered a bar and saw *n* people sitting there. For every one of them Vasya happened to determine either the age or the drink the person is having. Vasya can check any person, i.e. learn his age and the drink he is having at the same time. What minimal number of people should Vasya check additionally to make sure that there are no clients under 18 having alcohol drinks? The list of all alcohol drinks in Berland is: ABSINTH, BEER, BRANDY, CHAMPAGNE, GIN, RUM, SAKE, TEQUILA, VODKA, WHISKEY, WINE The input will be provided via standard input and looks as follows: The first line contains an integer *n* (1<=≤<=*n*<=≤<=100) which is the number of the bar's clients. Then follow *n* lines, each describing one visitor. A line either contains his age (an integer from 0 to 1000) or his drink (a string of capital Latin letters from 1 to 100 in length). It is guaranteed that the input data does not contain spaces and other unnecessary separators. Only the drinks from the list given above should be considered alcohol. You should write the solution as standard output as follows: Print a single number which is the number of people Vasya should check to guarantee the law enforcement. Here are example inputs and outputs for the problem: Example Input 1: 5 18 VODKA COKE 19 17 Example Output 1: 2 Now solve the problem by providing the code.
a='ABSINTH BEER BRANDY CHAMPAGNE GIN RUM SAKE TEQUILA VODKA WHISKEY WINE'.split() n=int(input()) ans=0 for i in range(n): x=input() if x in a or x.isdigit() and int(x)<18:ans+=1 print(ans)
vfc_83925
{ "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\n18\nVODKA\nCOKE\n19\n17", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2\nGIN", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\nWHISKEY\n3\nGIN", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n813\nIORBQITQXMPTFAEMEQDQIKFGKGOTNKTOSZCBRPXJLUKVLVHJYNRUJXK\nRUM\nRHVRWGODYWWTYZFLFYKCVUFFRTQDINKNWPKFHZBFWBHWINWJW", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\nSAKE\nSAKE\n13\n2", "output": "4", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
31
Solve the following coding problem using the programming language python: Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are *n* forms of worms. Worms of these forms have lengths *a*1, *a*2, ..., *a**n*. To prove his theory, professor needs to find 3 different forms that the length of the first form is equal to sum of lengths of the other two forms. Help him to do this. The input will be provided via standard input and looks as follows: The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of worm's forms. The second line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000) — lengths of worms of each form. You should write the solution as standard output as follows: Output 3 distinct integers *i* *j* *k* (1<=≤<=*i*,<=*j*,<=*k*<=≤<=*n*) — such indexes of worm's forms that *a**i*<==<=*a**j*<=+<=*a**k*. If there is no such triple, output -1. If there are several solutions, output any of them. It possible that *a**j*<==<=*a**k*. Here are example inputs and outputs for the problem: Example Input 1: 5 1 2 3 5 7 Example Output 1: 3 2 1 Example Input 2: 5 1 8 1 5 1 Example Output 2: -1 Now solve the problem by providing the code.
n = int(input()) data = list(input().split()) numbers_list = list(map(int, data)) numbers = sorted(numbers_list) i = 0 j = 1 while i != n - 1: if numbers[i] + numbers[j] not in numbers: if i == n - 2: print("-1") break if j != n - 1: j += 1 else: i += 1 j = i + 1 else: target = numbers[i] + numbers[j] if numbers[i] != numbers[j]: first = numbers[i] second = numbers[j] print(f"{numbers_list.index(target) + 1} {numbers_list.index(second) + 1} {numbers_list.index(first) + 1}") break else: twin = numbers[i] first = [i for i, n in enumerate(numbers) if n == twin][0] second = [i for i, n in enumerate(numbers) if n == twin][1] print(f"{numbers_list.index(target) + 1} {second + 1} {first + 1}") break
vfc_83929
{ "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 5 7", "output": "3 2 1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
400
Solve the following coding problem using the programming language python: There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusual upgrade of this game. The rules of the game are given below: There is one person playing the game. Before the beginning of the game he puts 12 cards in a row on the table. Each card contains a character: "X" or "O". Then the player chooses two positive integers *a* and *b* (*a*·*b*<==<=12), after that he makes a table of size *a*<=×<=*b* from the cards he put on the table as follows: the first *b* cards form the first row of the table, the second *b* cards form the second row of the table and so on, the last *b* cards form the last (number *a*) row of the table. The player wins if some column of the table contain characters "X" on all cards. Otherwise, the player loses. Inna has already put 12 cards on the table in a row. But unfortunately, she doesn't know what numbers *a* and *b* to choose. Help her win the game: print to her all the possible ways of numbers *a*,<=*b* that she can choose and win. The input will be provided via standard input and looks as follows: The first line of the input contains integer *t* (1<=≤<=*t*<=≤<=100). This value shows the number of sets of test data in the input. Next follows the description of each of the *t* tests on a separate line. The description of each test is a string consisting of 12 characters, each character is either "X", or "O". The *i*-th character of the string shows the character that is written on the *i*-th card from the start. You should write the solution as standard output as follows: For each test, print the answer to the test on a single line. The first number in the line must represent the number of distinct ways to choose the pair *a*,<=*b*. Next, print on this line the pairs in the format *a*x*b*. Print the pairs in the order of increasing first parameter (*a*). Separate the pairs in the line by whitespaces. Here are example inputs and outputs for the problem: Example Input 1: 4 OXXXOXOOXOOX OXOXOXOXOXOX XXXXXXXXXXXX OOOOOOOOOOOO Example Output 1: 3 1x12 2x6 4x3 4 1x12 2x6 3x4 6x2 6 1x12 2x6 3x4 4x3 6x2 12x1 0 Now solve the problem by providing the code.
T=int(input()) while T>=1: T-=1 a=input() list=[] for i in range(1,13): if 12 % i==0: l=12//i for j in range(0,l): for k in range(0,i): if a[k*l+j]!='X': break else: break else: continue list.append(i) print(len(list),end=' ') for i in range(0,len(list)): print(str(list[i])+'x'+str(12//list[i]),end=' ') print()
vfc_83933
{ "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\nOXXXOXOOXOOX\nOXOXOXOXOXOX\nXXXXXXXXXXXX\nOOOOOOOOOOOO", "output": "3 1x12 2x6 4x3\n4 1x12 2x6 3x4 6x2\n6 1x12 2x6 3x4 4x3 6x2 12x1\n0", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\nOOOOOOOOOOOO\nXXXXXXXXXXXX", "output": "0\n6 1x12 2x6 3x4 4x3 6x2 12x1", "type": "stdin_stdout" }, { "fn_name": null, "input": "13\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX\nXXXXXXXXXXXX", "output": "6 1x12 2x6 3x4 4x3 6x2 12x1\n6 1x12 2x6 3x4 4x3 6x2 12x1\n6 1x12 2x6 3x4 4x3 6x2 12x1\n6 1x12 2x6 3x4 4x3 6x2 12x1\n6 1x12 2x6 3x4 4x3 6x2 12x1\n6 1x12 2x6 3x4 4x3 6x2 12x1\n6 1x12 2x6 3x4 4x3 6x2 12x1\n6 1x12 2x6 3x4 4x3 6x2 12x1\n6 1x12 2x6 3x4 4x3 6x2 12x1\n6 1x12 2x6 3x4 4x3 6x2 12x1\n6 1x12 2x6 3x4 4x3 6x2 12x1\n6 1x12 2x6 3x4 4x3 6x2 12x1\n6 1x12 2x6 3x4 4x3 6x2 12x1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
959
Solve the following coding problem using the programming language python: Mahmoud and Ehab play a game called the even-odd game. Ehab chooses his favorite integer *n* and then they take turns, starting from Mahmoud. In each player's turn, he has to choose an integer *a* and subtract it from *n* such that: - 1<=≤<=*a*<=≤<=*n*. - If it's Mahmoud's turn, *a* has to be even, but if it's Ehab's turn, *a* has to be odd. If the current player can't choose any number satisfying the conditions, he loses. Can you determine the winner if they both play optimally? The input will be provided via standard input and looks as follows: The only line contains an integer *n* (1<=≤<=*n*<=≤<=109), the number at the beginning of the game. You should write the solution as standard output as follows: Output "Mahmoud" (without quotes) if Mahmoud wins and "Ehab" (without quotes) otherwise. Here are example inputs and outputs for the problem: Example Input 1: 1 Example Output 1: Ehab Example Input 2: 2 Example Output 2: Mahmoud Now solve the problem by providing the code.
if __name__ == '__main__': n = int(input()) if n == 1: print("Ehab") elif n % 2 == 0 and n >= 2: print('Mahmoud') else: print('Ehab')
vfc_83937
{ "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": "Ehab", "type": "stdin_stdout" }, { "fn_name": null, "input": "2", "output": "Mahmoud", "type": "stdin_stdout" }, { "fn_name": null, "input": "10000", "output": "Mahmoud", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
121
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. Let *next*(*x*) be the minimum lucky number which is larger than or equals *x*. Petya is interested what is the value of the expression *next*(*l*)<=+<=*next*(*l*<=+<=1)<=+<=...<=+<=*next*(*r*<=-<=1)<=+<=*next*(*r*). Help him solve this problem. The input will be provided via standard input and looks as follows: The single line contains two integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=109) — the left and right interval limits. You should write the solution as standard output as follows: In the single line print the only number — the sum *next*(*l*)<=+<=*next*(*l*<=+<=1)<=+<=...<=+<=*next*(*r*<=-<=1)<=+<=*next*(*r*). Please do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specificator. Here are example inputs and outputs for the problem: Example Input 1: 2 7 Example Output 1: 33 Example Input 2: 7 7 Example Output 2: 7 Now solve the problem by providing the code.
# Author Name: Ajay Meena # Codeforce : https://codeforces.com/profile/majay1638 import sys import math import bisect import heapq from bisect import bisect_right from sys import stdin, stdout # -------------- INPUT FUNCTIONS ------------------ def get_ints_in_variables(): return map( int, sys.stdin.readline().strip().split()) def get_int(): return int(sys.stdin.readline()) def get_ints_in_list(): return list( map(int, sys.stdin.readline().strip().split())) def get_list_of_list(n): return [list( map(int, sys.stdin.readline().strip().split())) for _ in range(n)] def get_string(): return sys.stdin.readline().strip() # -------- SOME CUSTOMIZED FUNCTIONS----------- def myceil(x, y): return (x + y - 1) // y # -------------- SOLUTION FUNCTION ------------------ def luckyNumbers(n, r, lucky_nums): lucky_nums.append(n) if n > r*10: return luckyNumbers((10*n)+4, r, lucky_nums) luckyNumbers((10*n)+7, r, lucky_nums) def helper(n, res): ans = 0 for i in range(1, len(res)): ans += (res[i]*(min(res[i], n)-min(res[i-1], n))) return ans def Solution(l, r): # Write Your Code Here luckyNums = [] luckyNumbers(0, r, luckyNums) luckyNums = sorted(luckyNums) # print(luckyNums) print(helper(r, luckyNums)-helper(l-1, luckyNums)) def main(): # Take input Here and Call solution function l, r = get_ints_in_variables() Solution(l, r) # calling main Function if __name__ == '__main__': main()
vfc_83941
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 7", "output": "33", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 7", "output": "7", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 9", "output": "125", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
601
Solve the following coding problem using the programming language python: In Absurdistan, there are *n* towns (numbered 1 through *n*) and *m* bidirectional railways. There is also an absurdly simple road network — for each pair of different towns *x* and *y*, there is a bidirectional road between towns *x* and *y* if and only if there is no railway between them. Travelling to a different town using one railway or one road always takes exactly one hour. A train and a bus leave town 1 at the same time. They both have the same destination, town *n*, and don't make any stops on the way (but they can wait in town *n*). The train can move only along railways and the bus can move only along roads. You've been asked to plan out routes for the vehicles; each route can use any road/railway multiple times. One of the most important aspects to consider is safety — in order to avoid accidents at railway crossings, the train and the bus must not arrive at the same town (except town *n*) simultaneously. Under these constraints, what is the minimum number of hours needed for both vehicles to reach town *n* (the maximum of arrival times of the bus and the train)? Note, that bus and train are not required to arrive to the town *n* at the same moment of time, but are allowed to do so. 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*<=≤<=400, 0<=≤<=*m*<=≤<=*n*(*n*<=-<=1)<=/<=2) — the number of towns and the number of railways respectively. Each of the next *m* lines contains two integers *u* and *v*, denoting a railway between towns *u* and *v* (1<=≤<=*u*,<=*v*<=≤<=*n*, *u*<=≠<=*v*). You may assume that there is at most one railway connecting any two towns. You should write the solution as standard output as follows: Output one integer — the smallest possible time of the later vehicle's arrival in town *n*. If it's impossible for at least one of the vehicles to reach town *n*, output <=-<=1. Here are example inputs and outputs for the problem: Example Input 1: 4 2 1 3 3 4 Example Output 1: 2 Example Input 2: 4 6 1 2 1 3 1 4 2 3 2 4 3 4 Example Output 2: -1 Example Input 3: 5 5 4 2 3 5 4 5 5 1 1 2 Example Output 3: 3 Now solve the problem by providing the code.
n,m=map(int,input().split()) graph=[[0]*(n+1) for _ in range(n+1)] for i in range(m): x,y=map(int,input().split()) graph[x][y]=graph[y][x]=1 vis=[-1]*(n+1) vis[1]=0 q=[1] while q: x=q.pop(0) for y in range(1,n+1): if graph[x][y]!=graph[1][n] and vis[y]==-1: vis[y]=vis[x]+1 q.append(y) print(vis[-1])
vfc_83945
{ "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 3\n3 4", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5\n4 2\n3 5\n4 5\n5 1\n1 2", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 4\n1 2\n3 2\n3 4\n5 4", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1\n1 2", "output": "-1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
913
Solve the following coding problem using the programming language python: Consider a rooted tree. A rooted tree has one special vertex called the root. All edges are directed from the root. Vertex *u* is called a child of vertex *v* and vertex *v* is called a parent of vertex *u* if there exists a directed edge from *v* to *u*. A vertex is called a leaf if it doesn't have children and has a parent. Let's call a rooted tree a spruce if its every non-leaf vertex has at least 3 leaf children. You are given a rooted tree, check whether it's a spruce. The definition of a rooted tree can be found [here](https://goo.gl/1dqvzz). The input will be provided via standard input and looks as follows: The first line contains one integer *n* — the number of vertices in the tree (3<=≤<=*n*<=≤<=1<=000). Each of the next *n*<=-<=1 lines contains one integer *p**i* (1<=≤<=*i*<=≤<=*n*<=-<=1) — the index of the parent of the *i*<=+<=1-th vertex (1<=≤<=*p**i*<=≤<=*i*). Vertex 1 is the root. It's guaranteed that the root has at least 2 children. You should write the solution as standard output as follows: Print "Yes" if the tree is a spruce and "No" otherwise. Here are example inputs and outputs for the problem: Example Input 1: 4 1 1 1 Example Output 1: Yes Example Input 2: 7 1 1 1 2 2 2 Example Output 2: No Example Input 3: 8 1 1 1 1 3 3 3 Example Output 3: Yes Now solve the problem by providing the code.
n = int(input()) nodes = {1: []} yes_or_no = "Yes" for i in range(2,n+1): p = int(input()) nodes[p].append(i) nodes[i] = [] for i in nodes: no_of_leaves = 0 for child in nodes[i]: if len(nodes[child]) == 0: no_of_leaves += 1 if 0 < no_of_leaves < 3 or (len(nodes[i]) > 0 and no_of_leaves == 0): yes_or_no = "No" break def dfs(tree: dict) -> dict: pass print(f"{yes_or_no}") ''' Faulty test case result 13 --- 1 2 2 2 1 6 6 6 1 10 10 10 '''
vfc_83949
{ "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\n1\n1", "output": "Yes", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n1\n1\n1\n2\n2\n2", "output": "No", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
523
Solve the following coding problem using the programming language python: Polycarp is writing the prototype of a graphic editor. He has already made up his mind that the basic image transformations in his editor will be: rotate the image 90 degrees clockwise, flip the image horizontally (symmetry relative to the vertical line, that is, the right part of the image moves to the left, and vice versa) and zooming on the image. He is sure that that there is a large number of transformations that can be expressed through these three. He has recently stopped implementing all three transformations for monochrome images. To test this feature, he asked you to write a code that will consecutively perform three actions with a monochrome image: first it will rotate the image 90 degrees clockwise, then it will flip the image horizontally and finally, it will zoom in twice on the image (that is, it will double all the linear sizes). Implement this feature to help Polycarp test his editor. The input will be provided via standard input and looks as follows: The first line contains two integers, *w* and *h* (1<=≤<=*w*,<=*h*<=≤<=100) — the width and height of an image in pixels. The picture is given in *h* lines, each line contains *w* characters — each character encodes the color of the corresponding pixel of the image. The line consists only of characters "." and "*", as the image is monochrome. You should write the solution as standard output as follows: Print 2*w* lines, each containing 2*h* characters — the result of consecutive implementing of the three transformations, described above. Here are example inputs and outputs for the problem: Example Input 1: 3 2 .*. .*. Example Output 1: .... .... **** **** .... .... Example Input 2: 9 20 **....... ****..... ******... *******.. ..******. ....****. ......*** *.....*** ********* ********* ********* ********* ....**... ...****.. ..******. .******** ****..*** ***...*** **.....** *.......* Example Output 2: ********......**********........******** ********......**********........******** ********........********......********.. ********........********......********.. ..********......********....********.... ..********......********....********.... ..********......********..********...... ..********......********..********...... ....********....****************........ ....********....****************........ ....********....****************........ ....********....****************........ ......******************..**********.... ......******************..**********.... ........****************....**********.. ........****************....**********.. ............************......********** ............************......********** Now solve the problem by providing the code.
w, h = map(int, input().split()) a = [] for i in range(h): a.append(list(input())) b = [[0 for j in range(h)] for i in range(w)] for i in range(h): for j in range(w): b[j][i] = a[i][j] for i in range(w): x = '' for j in range(h): x = x + b[i][j] + b[i][j] print(x) print(x)
vfc_83953
{ "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 2\n.*.\n.*.", "output": "....\n....\n****\n****\n....\n....", "type": "stdin_stdout" }, { "fn_name": null, "input": "9 20\n**.......\n****.....\n******...\n*******..\n..******.\n....****.\n......***\n*.....***\n*********\n*********\n*********\n*********\n....**...\n...****..\n..******.\n.********\n****..***\n***...***\n**.....**\n*.......*", "output": "********......**********........********\n********......**********........********\n********........********......********..\n********........********......********..\n..********......********....********....\n..********......********....********....\n..********......********..********......\n..********......********..********......\n....********....****************........\n....********....****************........\n....********....****************........\n....********....****************........\n......*...", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 100\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.\n.", "output": "........................................................................................................................................................................................................\n........................................................................................................................................................................................................", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
650
Solve the following coding problem using the programming language python: Watchmen are in a danger and Doctor Manhattan together with his friend Daniel Dreiberg should warn them as soon as possible. There are *n* watchmen on a plane, the *i*-th watchman is located at point (*x**i*,<=*y**i*). They need to arrange a plan, but there are some difficulties on their way. As you know, Doctor Manhattan considers the distance between watchmen *i* and *j* to be |*x**i*<=-<=*x**j*|<=+<=|*y**i*<=-<=*y**j*|. Daniel, as an ordinary person, calculates the distance using the formula . The success of the operation relies on the number of pairs (*i*,<=*j*) (1<=≤<=*i*<=&lt;<=*j*<=≤<=*n*), such that the distance between watchman *i* and watchmen *j* calculated by Doctor Manhattan is equal to the distance between them calculated by Daniel. You were asked to compute the number of such pairs. The input will be provided via standard input and looks as follows: The first line of the input contains the single integer *n* (1<=≤<=*n*<=≤<=200<=000) — the number of watchmen. Each of the following *n* lines contains two integers *x**i* and *y**i* (|*x**i*|,<=|*y**i*|<=≤<=109). Some positions may coincide. You should write the solution as standard output as follows: Print the number of pairs of watchmen such that the distance between them calculated by Doctor Manhattan is equal to the distance calculated by Daniel. Here are example inputs and outputs for the problem: Example Input 1: 3 1 1 7 5 1 5 Example Output 1: 2 Example Input 2: 6 0 0 0 1 0 2 -1 1 0 1 1 1 Example Output 2: 11 Now solve the problem by providing the code.
from operator import itemgetter n=int(input().strip()) ans=0 l=[] for i in range(n): l.append([int(x) for x in input().strip().split()]) l.sort(key=itemgetter(1)) x=l[0][1] y=1 for i in range(1,len(l)): if l[i][1]!=x: ans=ans+(y*(y-1))//2 x=l[i][1] y=1 else: y=y+1 ans=ans+(y*(y-1))//2 l.sort() x=l[0][0] y=1 for i in range(1,len(l)): if l[i][0]!=x: ans=ans+(y*(y-1))//2 x=l[i][0] y=1 else: y=y+1 ans=ans+(y*(y-1))//2 x0,x1=l[0][0],l[0][1] y=1 for i in range(1,len(l)): if l[i][0]!=x0 or l[i][1]!=x1: ans=ans-(y*(y-1))//2 x0,x1=l[i][0],l[i][1] y=1 else: y=y+1 ans=ans-(y*(y-1))//2 print(ans)
vfc_83957
{ "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\n7 5\n1 5", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n0 0\n0 1\n0 2\n-1 1\n0 1\n1 1", "output": "11", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
929
Solve the following coding problem using the programming language python: Как известно, в теплую погоду многие жители крупных городов пользуются сервисами городского велопроката. Вот и Аркадий сегодня будет добираться от школы до дома, используя городские велосипеды. Школа и дом находятся на одной прямой улице, кроме того, на той же улице есть *n* точек, где можно взять велосипед в прокат или сдать его. Первый велопрокат находится в точке *x*1 километров вдоль улицы, второй — в точке *x*2 и так далее, *n*-й велопрокат находится в точке *x**n*. Школа Аркадия находится в точке *x*1 (то есть там же, где и первый велопрокат), а дом — в точке *x**n* (то есть там же, где и *n*-й велопрокат). Известно, что *x**i*<=&lt;<=*x**i*<=+<=1 для всех 1<=≤<=*i*<=&lt;<=*n*. Согласно правилам пользования велопроката, Аркадий может брать велосипед в прокат только на ограниченное время, после этого он должен обязательно вернуть его в одной из точек велопроката, однако, он тут же может взять новый велосипед, и отсчет времени пойдет заново. Аркадий может брать не более одного велосипеда в прокат одновременно. Если Аркадий решает взять велосипед в какой-то точке проката, то он сдаёт тот велосипед, на котором он до него доехал, берёт ровно один новый велосипед и продолжает на нём своё движение. За отведенное время, независимо от выбранного велосипеда, Аркадий успевает проехать не больше *k* километров вдоль улицы. Определите, сможет ли Аркадий доехать на велосипедах от школы до дома, и если да, то какое минимальное число раз ему необходимо будет взять велосипед в прокат, включая первый велосипед? Учтите, что Аркадий не намерен сегодня ходить пешком. The input will be provided via standard input and looks as follows: В первой строке следуют два целых числа *n* и *k* (2<=≤<=*n*<=≤<=1<=000, 1<=≤<=*k*<=≤<=100<=000) — количество велопрокатов и максимальное расстояние, которое Аркадий может проехать на одном велосипеде. В следующей строке следует последовательность целых чисел *x*1,<=*x*2,<=...,<=*x**n* (0<=≤<=*x*1<=&lt;<=*x*2<=&lt;<=...<=&lt;<=*x**n*<=≤<=100<=000) — координаты точек, в которых находятся велопрокаты. Гарантируется, что координаты велопрокатов заданы в порядке возрастания. You should write the solution as standard output as follows: Если Аркадий не сможет добраться от школы до дома только на велосипедах, выведите -1. В противном случае, выведите минимальное количество велосипедов, которые Аркадию нужно взять в точках проката. Here are example inputs and outputs for the problem: Example Input 1: 4 4 3 6 8 10 Example Output 1: 2 Example Input 2: 2 9 10 20 Example Output 2: -1 Example Input 3: 12 3 4 6 7 9 10 11 13 15 17 18 20 21 Example Output 3: 6 Now solve the problem by providing the code.
n, k = map(int, input().split()) cor = [int(x) for x in input().split()] N = 1 kon = n tek = 0 while tek!=kon-1: for i in range(tek+1,kon): if cor[i]-cor[tek]>k: break if cor[kon-1] - cor[tek] <= k: break if i==tek+1: N=-1 break tek=i-1 N+=1 print (N)
vfc_83961
{ "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\n3 6 8 10", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 9\n10 20", "output": "-1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
55
Solve the following coding problem using the programming language python: Recently, Vladimir got bad mark in algebra again. To avoid such unpleasant events in future he decided to train his arithmetic skills. He wrote four integer numbers *a*, *b*, *c*, *d* on the blackboard. During each of the next three minutes he took two numbers from the blackboard (not necessarily adjacent) and replaced them with their sum or their product. In the end he got one number. Unfortunately, due to the awful memory he forgot that number, but he remembers four original numbers, sequence of the operations and his surprise because of the very small result. Help Vladimir remember the forgotten number: find the smallest number that can be obtained from the original numbers by the given sequence of operations. The input will be provided via standard input and looks as follows: First line contains four integers separated by space: 0<=≤<=*a*,<=*b*,<=*c*,<=*d*<=≤<=1000 — the original numbers. Second line contains three signs ('+' or '*' each) separated by space — the sequence of the operations in the order of performing. ('+' stands for addition, '*' — multiplication) You should write the solution as standard output as follows: Output one integer number — the minimal result which can be obtained. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cin (also you may use %I64d). Here are example inputs and outputs for the problem: Example Input 1: 1 1 1 1 + + * Example Output 1: 3 Example Input 2: 2 2 2 2 * * + Example Output 2: 8 Example Input 3: 1 2 3 4 * + + Example Output 3: 9 Now solve the problem by providing the code.
def solve(index): if index==3: for x in arr: if x>=0: ans[0]=min(ans[0],x) return for i in range(4): if arr[i] !=-1: for j in range(4): if i==j or arr[j]==-1: continue a,b=arr[i],arr[j] if s[index]=='+': arr[j]=a+b arr[i]=-1 solve(index+1) arr[j]=b arr[i]=a elif s[index]=='*': arr[j]=a*b arr[i]=-1 solve(index+1) arr[j]=b arr[i]=a else: continue ans=[float('inf')] arr=list(map(int,input().split())) s=input().split() solve(0) print(*ans)
vfc_83965
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "4000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 1 1 1\n+ + *", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2 2 2\n* * +", "output": "8", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
496
Solve the following coding problem using the programming language python: Mike is trying rock climbing but he is awful at it. There are *n* holds on the wall, *i*-th hold is at height *a**i* off the ground. Besides, let the sequence *a**i* increase, that is, *a**i*<=&lt;<=*a**i*<=+<=1 for all *i* from 1 to *n*<=-<=1; we will call such sequence a track. Mike thinks that the track *a*1, ..., *a**n* has difficulty . In other words, difficulty equals the maximum distance between two holds that are adjacent in height. Today Mike decided to cover the track with holds hanging on heights *a*1, ..., *a**n*. To make the problem harder, Mike decided to remove one hold, that is, remove one element of the sequence (for example, if we take the sequence (1,<=2,<=3,<=4,<=5) and remove the third element from it, we obtain the sequence (1,<=2,<=4,<=5)). However, as Mike is awful at climbing, he wants the final difficulty (i.e. the maximum difference of heights between adjacent holds after removing the hold) to be as small as possible among all possible options of removing a hold. The first and last holds must stay at their positions. Help Mike determine the minimum difficulty of the track after removing one hold. The input will be provided via standard input and looks as follows: The first line contains a single integer *n* (3<=≤<=*n*<=≤<=100) — the number of holds. The next line contains *n* space-separated integers *a**i* (1<=≤<=*a**i*<=≤<=1000), where *a**i* is the height where the hold number *i* hangs. The sequence *a**i* is increasing (i.e. each element except for the first one is strictly larger than the previous one). You should write the solution as standard output as follows: Print a single number — the minimum difficulty of the track after removing a single hold. Here are example inputs and outputs for the problem: Example Input 1: 3 1 4 6 Example Output 1: 5 Example Input 2: 5 1 2 3 4 5 Example Output 2: 2 Example Input 3: 5 1 2 3 7 8 Example Output 3: 4 Now solve the problem by providing the code.
n= int(input()) s= [int(x) for x in input().split()] a=[] b=[] for i in range(0,len(s)-2): a.append(s[i+2]-s[i]) m = a.index((min(a))) s.pop(m+1) for i in range(len(s)-1): b.append(s[i+1]-s[i]) print(max(b))
vfc_83969
{ "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 4 6", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 2 3 4 5", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 2 3 7 8", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 500 1000", "output": "999", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n1 2 3 4 5 6 7 8 9 10", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n1 4 9 16 25 36 49 64 81 100", "output": "19", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
676
Solve the following coding problem using the programming language python: High school student Vasya got a string of length *n* as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than *k* characters of the original string. What is the maximum beauty of the string he can achieve? The input will be provided via standard input and looks as follows: The first line of the input contains two integers *n* and *k* (1<=≤<=*n*<=≤<=100<=000,<=0<=≤<=*k*<=≤<=*n*) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only. You should write the solution as standard output as follows: Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than *k* characters. Here are example inputs and outputs for the problem: Example Input 1: 4 2 abba Example Output 1: 4 Example Input 2: 8 1 aabaabaa Example Output 2: 5 Now solve the problem by providing the code.
import sys from collections import defaultdict as dd from collections import deque from fractions import Fraction as f from copy import * from bisect import * from heapq import * #from math import * from itertools import permutations def eprint(*args): print(*args, file=sys.stderr) zz=1 #sys.setrecursionlimit(10**6) if zz: input=sys.stdin.readline else: sys.stdin=open('input.txt', 'r') sys.stdout=open('all.txt','w') def li(): return [int(x) for x in input().split()] def fi(): return int(input()) def si(): return list(input().rstrip()) def mi(): return map(int,input().split()) def gh(): sys.stdout.flush() def graph(n,m): for i in range(m): x,y=mi() a[x].append(y) a[y].append(x) def bo(i): return ord(i)-ord('a') def can(mid): d=[0,0] mini=n for i in range(n): if i>=mid: mini=min(d[0],min(d[1],mini)) d[bo(a[i-mid])]-=1 d[bo(a[i])]+=1 mini=min(d[0],min(d[1],mini)) return mini<=k n,k=mi() a=si() l=0 r=ans=n while l<=r: mid=(l+r)//2 if can(mid): ans=mid l=mid+1 else: r=mid-1 print(ans)
vfc_83981
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2\nabba", "output": "4", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
675
Solve the following coding problem using the programming language python: Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was stolen while he was on duty. He doesn't want to be fired, so he has to quickly restore the painting. He remembers some facts about it. - The painting is a square 3<=×<=3, each cell contains a single integer from 1 to *n*, and different cells may contain either different or equal integers. - The sum of integers in each of four squares 2<=×<=2 is equal to the sum of integers in the top left square 2<=×<=2. - Four elements *a*, *b*, *c* and *d* are known and are located as shown on the picture below. Help Vasya find out the number of distinct squares the satisfy all the conditions above. Note, that this number may be equal to 0, meaning Vasya remembers something wrong. Two squares are considered to be different, if there exists a cell that contains two different integers in different squares. The input will be provided via standard input and looks as follows: The first line of the input contains five integers *n*, *a*, *b*, *c* and *d* (1<=≤<=*n*<=≤<=100<=000, 1<=≤<=*a*,<=*b*,<=*c*,<=*d*<=≤<=*n*) — maximum possible value of an integer in the cell and four integers that Vasya remembers. You should write the solution as standard output as follows: Print one integer — the number of distinct valid squares. Here are example inputs and outputs for the problem: Example Input 1: 2 1 1 1 2 Example Output 1: 2 Example Input 2: 3 3 1 2 3 Example Output 2: 6 Now solve the problem by providing the code.
#!/usr/bin/env python3 (n, a, b, c, d) = input().split() n = int(n) a = int(a) b = int(b) c = int(c) d = int(d) diff2 = b - c diff4 = a - d diff5 = a + b - c - d (lower, _, upper) = sorted((diff2, diff4, diff5)) lower_bound = 1 - min(0, lower) upper_bound = n - max(0, upper) if lower_bound > upper_bound: print(0) else: print((upper_bound - lower_bound + 1) * n)
vfc_83985
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 1 1 1 2", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3 1 2 3", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1 1 1 1", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000 522 575 426 445", "output": "774000", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
787
Solve the following coding problem using the programming language python: A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times *b*,<=*b*<=+<=*a*,<=*b*<=+<=2*a*,<=*b*<=+<=3*a*,<=... and Morty screams at times *d*,<=*d*<=+<=*c*,<=*d*<=+<=2*c*,<=*d*<=+<=3*c*,<=.... The Monster will catch them if at any point they scream at the same time, so it wants to know when it will catch them (the first time they scream at the same time) or that they will never scream at the same time. The input will be provided via standard input and looks as follows: The first line of input contains two integers *a* and *b* (1<=≤<=*a*,<=*b*<=≤<=100). The second line contains two integers *c* and *d* (1<=≤<=*c*,<=*d*<=≤<=100). You should write the solution as standard output as follows: Print the first time Rick and Morty will scream at the same time, or <=-<=1 if they will never scream at the same time. Here are example inputs and outputs for the problem: Example Input 1: 20 2 9 19 Example Output 1: 82 Example Input 2: 2 1 16 12 Example Output 2: -1 Now solve the problem by providing the code.
#!/usr/bin/python3 a,b = [int(x) for x in input().split()] c,d = [int(x) for x in input().split()] i = 0 j = 0 flag = 0 for i in range(1000000): s1 = b + a*i if (s1 >= d and 0 == (s1-d)%c): print(s1) flag = 1 break if (not flag): print("-1")
vfc_83989
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "20 2\n9 19", "output": "82", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
869
Solve the following coding problem using the programming language python: Even if the world is full of counterfeits, I still regard it as wonderful. Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this. The phoenix has a rather long lifespan, and reincarnates itself once every *a*! years. Here *a*! denotes the factorial of integer *a*, that is, *a*!<==<=1<=×<=2<=×<=...<=×<=*a*. Specifically, 0!<==<=1. Koyomi doesn't care much about this, but before he gets into another mess with oddities, he is interested in the number of times the phoenix will reincarnate in a timespan of *b*! years, that is, . Note that when *b*<=≥<=*a* this value is always integer. As the answer can be quite large, it would be enough for Koyomi just to know the last digit of the answer in decimal representation. And you're here to provide Koyomi with this knowledge. The input will be provided via standard input and looks as follows: The first and only line of input contains two space-separated integers *a* and *b* (0<=≤<=*a*<=≤<=*b*<=≤<=1018). You should write the solution as standard output as follows: Output one line containing a single decimal digit — the last digit of the value that interests Koyomi. Here are example inputs and outputs for the problem: Example Input 1: 2 4 Example Output 1: 2 Example Input 2: 0 10 Example Output 2: 0 Example Input 3: 107 109 Example Output 3: 2 Now solve the problem by providing the code.
l = input().split(" ") n =int(l[0]) m = int(l[1]) res=1 if m-n>=10: print(0) else: while m>n: res = ((m%10)*res)%10 m-=1 print(res)
vfc_83993
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 4", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "0 10", "output": "0", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
264
Solve the following coding problem using the programming language python: Squirrel Liss lived in a forest peacefully, but unexpected trouble happens. Stones fall from a mountain. Initially Squirrel Liss occupies an interval [0,<=1]. Next, *n* stones will fall and Liss will escape from the stones. The stones are numbered from 1 to *n* in order. The stones always fall to the center of Liss's interval. When Liss occupies the interval [*k*<=-<=*d*,<=*k*<=+<=*d*] and a stone falls to *k*, she will escape to the left or to the right. If she escapes to the left, her new interval will be [*k*<=-<=*d*,<=*k*]. If she escapes to the right, her new interval will be [*k*,<=*k*<=+<=*d*]. You are given a string *s* of length *n*. If the *i*-th character of *s* is "l" or "r", when the *i*-th stone falls Liss will escape to the left or to the right, respectively. Find the sequence of stones' numbers from left to right after all the *n* stones falls. The input will be provided via standard input and looks as follows: The input consists of only one line. The only line contains the string *s* (1<=≤<=|*s*|<=≤<=106). Each character in *s* will be either "l" or "r". You should write the solution as standard output as follows: Output *n* lines — on the *i*-th line you should print the *i*-th stone's number from the left. Here are example inputs and outputs for the problem: Example Input 1: llrlr Example Output 1: 3 5 4 2 1 Example Input 2: rrlll Example Output 2: 1 2 5 4 3 Example Input 3: lrlrr Example Output 3: 2 4 5 3 1 Now solve the problem by providing the code.
def main(): line = input() l = [None] * len(line) ptr1 = 0 ptr2 = len(line)-1 counter = 0 for c in line: counter += 1 if c == 'l': l[ptr2] = counter ptr2 -= 1 else: l[ptr1] = counter ptr1 += 1 for n in l: print(n) if __name__ == "__main__": main()
vfc_83997
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "llrlr", "output": "3\n5\n4\n2\n1", "type": "stdin_stdout" }, { "fn_name": null, "input": "rrlll", "output": "1\n2\n5\n4\n3", "type": "stdin_stdout" }, { "fn_name": null, "input": "lrlrr", "output": "2\n4\n5\n3\n1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
476
Solve the following coding problem using the programming language python: Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them. Each command is one of the following two types: 1. Go 1 unit towards the positive direction, denoted as '+' 1. Go 1 unit towards the negative direction, denoted as '-' But the Wi-Fi condition is so poor that Dreamoon's smartphone reports some of the commands can't be recognized and Dreamoon knows that some of them might even be wrong though successfully recognized. Dreamoon decides to follow every recognized command and toss a fair coin to decide those unrecognized ones (that means, he moves to the 1 unit to the negative or positive direction with the same probability 0.5). You are given an original list of commands sent by Drazil and list received by Dreamoon. What is the probability that Dreamoon ends in the position originally supposed to be final by Drazil's commands? The input will be provided via standard input and looks as follows: The first line contains a string *s*1 — the commands Drazil sends to Dreamoon, this string consists of only the characters in the set {'+', '-'}. The second line contains a string *s*2 — the commands Dreamoon's smartphone recognizes, this string consists of only the characters in the set {'+', '-', '?'}. '?' denotes an unrecognized command. Lengths of two strings are equal and do not exceed 10. You should write the solution as standard output as follows: Output a single real number corresponding to the probability. The answer will be considered correct if its relative or absolute error doesn't exceed 10<=-<=9. Here are example inputs and outputs for the problem: Example Input 1: ++-+- +-+-+ Example Output 1: 1.000000000000 Example Input 2: +-+- +-?? Example Output 2: 0.500000000000 Example Input 3: +++ ??- Example Output 3: 0.000000000000 Now solve the problem by providing the code.
#from heapq import heappop,heappush,heapify #heappop(hq), heapify(list) #from collections import deque as dq #deque e.g. myqueue=dq(list) #append/appendleft/appendright/pop/popleft #from bisect import bisect as bis #a=[1,3,4,6,7,8] #bis(a,5)-->3 #import bisect #bisect.bisect_left(a,4)-->2 #bisect.bisect(a,4)-->3 #import statistics as stat # stat.median(a), mode, mean #from itertools import permutations(p,r)#combinations(p,r) #combinations(p,r) gives r-length tuples #combinations_with_replacement #every element can be repeated import sys, threading import math import time from os import path from collections import defaultdict, Counter, deque from bisect import * from string import ascii_lowercase from functools import cmp_to_key import heapq # # # # # # # # # # # # # # # # # JAI SHREE RAM # # # # # # # # # # # # # # # # # def lcm(a, b): return (a*b)//(math.gcd(a,b)) si= lambda:str(input()) ii = lambda: int(input()) mii = lambda: map(int, input().split()) lmii = lambda: list(map(int, input().split())) i2c = lambda n: chr(ord('a') + n) c2i = lambda c: ord(c) - ord('a') def factorial(n): if n==1: return 1 else: return n*factorial(n-1) def solve(): s1=si() s2=si() q=0 final_pos=0 till_now =0 for i in range(len(s1)): if s1[i]=="+": final_pos+=1 else: final_pos-=1 for i in range(len(s2)): if s2[i]=="+": till_now+=1 elif s2[i]=="-": till_now-=1 elif s2[i]=="?": q+=1 t=abs(final_pos-till_now) if t>q or (q-t)%2: print(0.000000000000) else: numerator = math.comb(q,t+((q-t)//2)) denominator = pow(2,q) ans = (numerator*1.0)/denominator print("{:.11f}".format(ans)) def main(): t = 1 if path.exists("/Users/nitishkumar/Documents/Template_Codes/Python/CP/Codeforces/input.txt"): sys.stdin = open("/Users/nitishkumar/Documents/Template_Codes/Python/CP/Codeforces/input.txt", 'r') sys.stdout = open("/Users/nitishkumar/Documents/Template_Codes/Python/CP/Codeforces/output.txt", 'w') start_time = time.time() print("--- %s seconds ---" % (time.time() - start_time)) sys.setrecursionlimit(10**5) solve() if __name__ == '__main__': main()
vfc_84001
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1500" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "++-+-\n+-+-+", "output": "1.000000000000", "type": "stdin_stdout" }, { "fn_name": null, "input": "+-+-\n+-??", "output": "0.500000000000", "type": "stdin_stdout" }, { "fn_name": null, "input": "+++\n??-", "output": "0.000000000000", "type": "stdin_stdout" }, { "fn_name": null, "input": "++++++++++\n+++??++?++", "output": "0.125000000000", "type": "stdin_stdout" }, { "fn_name": null, "input": "--+++---+-\n??????????", "output": "0.205078125000", "type": "stdin_stdout" }, { "fn_name": null, "input": "+--+++--+-\n??????????", "output": "0.246093750000", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
789
Solve the following coding problem using the programming language python: Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise. You are given geometric progression *b* defined by two integers *b*1 and *q*. Remind that a geometric progression is a sequence of integers *b*1,<=*b*2,<=*b*3,<=..., where for each *i*<=&gt;<=1 the respective term satisfies the condition *b**i*<==<=*b**i*<=-<=1·*q*, where *q* is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both *b*1 and *q* can equal 0. Also, Dvastan gave Masha *m* "bad" integers *a*1,<=*a*2,<=...,<=*a**m*, and an integer *l*. Masha writes all progression terms one by one onto the board (including repetitive) while condition |*b**i*|<=≤<=*l* is satisfied (|*x*| means absolute value of *x*). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term. But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers. The input will be provided via standard input and looks as follows: The first line of input contains four integers *b*1, *q*, *l*, *m* (-109<=≤<=*b*1,<=*q*<=≤<=109, 1<=≤<=*l*<=≤<=109, 1<=≤<=*m*<=≤<=105) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively. The second line contains *m* distinct integers *a*1,<=*a*2,<=...,<=*a**m* (-109<=≤<=*a**i*<=≤<=109) — numbers that will never be written on the board. You should write the solution as standard output as follows: Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise. Here are example inputs and outputs for the problem: Example Input 1: 3 2 30 4 6 14 25 48 Example Output 1: 3 Example Input 2: 123 1 2143435 4 123 11 -5453 141245 Example Output 2: 0 Example Input 3: 123 1 2143435 4 54343 -13 6 124 Example Output 3: inf Now solve the problem by providing the code.
def main(): b1, q, l, m = map(int, input().split()) a = set(map(int, input().split())) if b1 == 0: if 0 in a: return 0 else: return 'inf' if q == 0: if abs(b1) > l: return 0 if b1 in a: if 0 in a: return 0 else: return 'inf' else: if 0 in a: return 1 else: return 'inf' if q == 1: if abs(b1) > l or b1 in a: return 0 else: return 'inf' if q == -1: if abs(b1) > l or b1 in a and -b1 in a: return 0 else: return 'inf' result = 0 b = b1 while True: if abs(b) > l: break if b not in a: result += 1 b *= q return result if __name__ == '__main__': # import sys # sys.stdin = open("B.txt") print(main())
vfc_84005
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2 30 4\n6 14 25 48", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "123 1 2143435 4\n123 11 -5453 141245", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "123 1 2143435 4\n54343 -13 6 124", "output": "inf", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2 25 2\n379195692 -69874783", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2 30 3\n-691070108 -934106649 -220744807", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3 104 17\n9 -73896485 -290898562 5254410 409659728 -916522518 -435516126 94354167 262981034 -375897180 -80186684 -173062070 -288705544 -699097793 -11447747 320434295 503414250", "output": "3", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
320
Solve the following coding problem using the programming language python: A magic number is a number formed by concatenation of numbers 1, 14 and 144. We can use each of these numbers any number of times. Therefore 14144, 141414 and 1411 are magic numbers but 1444, 514 and 414 are not. You're given a number. Determine if it is a magic number or not. The input will be provided via standard input and looks as follows: The first line of input contains an integer *n*, (1<=≤<=*n*<=≤<=109). This number doesn't contain leading zeros. You should write the solution as standard output as follows: Print "YES" if *n* is a magic number or print "NO" if it's not. Here are example inputs and outputs for the problem: Example Input 1: 114114 Example Output 1: YES Example Input 2: 1111 Example Output 2: YES Example Input 3: 441231 Example Output 3: NO Now solve the problem by providing the code.
s = input() flag = 1 p = '' if(s[0] != '1'): print('NO') else: for i in range(len(s)): if( s[i] == '4' and ((i>=1 and s[i-1] != '1') and (i>=2 and s[i-2:i] != '14'))): flag = 0 break if(s[i] != '4' and s[i] != '1'): flag = 0 break if(flag == 1): print('YES') else: print('NO')
vfc_84009
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "114114", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "1111", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "441231", "output": "NO", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
350
Solve the following coding problem using the programming language python: Valera's finally decided to go on holiday! He packed up and headed for a ski resort. Valera's fancied a ski trip but he soon realized that he could get lost in this new place. Somebody gave him a useful hint: the resort has *n* objects (we will consider the objects indexed in some way by integers from 1 to *n*), each object is either a hotel or a mountain. Valera has also found out that the ski resort had multiple ski tracks. Specifically, for each object *v*, the resort has at most one object *u*, such that there is a ski track built from object *u* to object *v*. We also know that no hotel has got a ski track leading from the hotel to some object. Valera is afraid of getting lost on the resort. So he wants you to come up with a path he would walk along. The path must consist of objects *v*1,<=*v*2,<=...,<=*v**k* (*k*<=≥<=1) and meet the following conditions: 1. Objects with numbers *v*1,<=*v*2,<=...,<=*v**k*<=-<=1 are mountains and the object with number *v**k* is the hotel. 1. For any integer *i* (1<=≤<=*i*<=&lt;<=*k*), there is exactly one ski track leading from object *v**i*. This track goes to object *v**i*<=+<=1. 1. The path contains as many objects as possible (*k* is maximal). Help Valera. Find such path that meets all the criteria of our hero! The input will be provided via standard input and looks as follows: The first line contains integer *n* (1<=≤<=*n*<=≤<=105) — the number of objects. The second line contains *n* space-separated integers *type*1,<=*type*2,<=...,<=*type**n* — the types of the objects. If *type**i* equals zero, then the *i*-th object is the mountain. If *type**i* equals one, then the *i*-th object is the hotel. It is guaranteed that at least one object is a hotel. The third line of the input contains *n* space-separated integers *a*1,<=*a*2,<=...,<=*a**n* (0<=≤<=*a**i*<=≤<=*n*) — the description of the ski tracks. If number *a**i* equals zero, then there is no such object *v*, that has a ski track built from *v* to *i*. If number *a**i* doesn't equal zero, that means that there is a track built from object *a**i* to object *i*. You should write the solution as standard output as follows: In the first line print *k* — the maximum possible path length for Valera. In the second line print *k* integers *v*1,<=*v*2,<=...,<=*v**k* — the path. If there are multiple solutions, you can print any of them. Here are example inputs and outputs for the problem: Example Input 1: 5 0 0 0 0 1 0 1 2 3 4 Example Output 1: 5 1 2 3 4 5 Example Input 2: 5 0 0 1 0 1 0 1 2 2 4 Example Output 2: 2 4 5 Example Input 3: 4 1 0 0 0 2 3 4 2 Example Output 3: 1 1 Now solve the problem by providing the code.
def solve(): n = int(input()) arr = list(map(int,input().split())) parent = list(map(int,input().split())) degree = [0]*n for i in range(n): parent[i] -=1 if parent[i]!=-1: degree[parent[i]]+=1 ans = [] visited = [False]*n for i in range(n): if arr[i]==1: s = i tmp = [] while parent[s]!=-1 and degree[parent[s]]<=1: tmp.append(s) s = parent[s] tmp.append(s) if len(tmp)>len(ans): ans = tmp ans = ans[::-1] print(len(ans)) for i in ans: print(i+1,end=' ') # number of test cases t = 1 #t = int(input()) for i in range(t): solve()
vfc_84013
{ "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\n0 0 0 0 1\n0 1 2 3 4", "output": "5\n1 2 3 4 5", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n0 0 1 0 1\n0 1 2 2 4", "output": "2\n4 5", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 0 0 0\n2 3 4 2", "output": "1\n1", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n0 0 0 0 0 0 0 0 0 1\n4 0 8 4 7 8 5 5 7 2", "output": "2\n2 10", "type": "stdin_stdout" }, { "fn_name": null, "input": "50\n0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 1 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1 1 0 0 0 1 0\n28 4 33 22 4 35 36 31 42 25 50 33 25 36 18 23 23 28 43 3 18 31 1 2 15 22 40 43 29 32 28 35 18 27 48 40 14 36 27 50 40 5 48 14 36 24 32 33 26 50", "output": "2\n3 20", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0\n86 12 47 46 45 31 20 47 58 79 23 70 35 72 37 20 16 64 46 87 57 7 84 72 70 3 14 40 17 42 30 99 12 20 38 98 14 40 4 83 10 15 47 30 83 58 12 7 97 46 17 6 41 13 87 37 36 12 7 25 26 35 69 13 18 5 9 53 72 28 13 51 5 57 14 64 28 25 91 96 57 69 9 12 97 7 56 42 31 15 88 16 41 88 86 13 89 81 3 42", "output": "1\n44", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
347
Solve the following coding problem using the programming language python: You want to arrange *n* integers *a*1,<=*a*2,<=...,<=*a**n* in some order in a row. Let's define the value of an arrangement as the sum of differences between all pairs of adjacent integers. More formally, let's denote some arrangement as a sequence of integers *x*1,<=*x*2,<=...,<=*x**n*, where sequence *x* is a permutation of sequence *a*. The value of such an arrangement is (*x*1<=-<=*x*2)<=+<=(*x*2<=-<=*x*3)<=+<=...<=+<=(*x**n*<=-<=1<=-<=*x**n*). Find the largest possible value of an arrangement. Then, output the lexicographically smallest sequence *x* that corresponds to an arrangement of the largest possible value. The input will be provided via standard input and looks as follows: The first line of the input contains integer *n* (2<=≤<=*n*<=≤<=100). The second line contains *n* space-separated integers *a*1, *a*2, ..., *a**n* (|*a**i*|<=≤<=1000). You should write the solution as standard output as follows: Print the required sequence *x*1,<=*x*2,<=...,<=*x**n*. Sequence *x* should be the lexicographically smallest permutation of *a* that corresponds to an arrangement of the largest possible value. Here are example inputs and outputs for the problem: Example Input 1: 5 100 -100 50 0 -50 Example Output 1: 100 -50 0 50 -100 Now solve the problem by providing the code.
def main(): n = int(input()) nums = sorted(list(map(int, input().split(' ')))) temp = nums[0] nums[0] = nums[-1] nums[-1] = temp print(' '.join(map(str, nums))) main()
vfc_84017
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n100 -100 50 0 -50", "output": "100 -50 0 50 -100 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n764 -367 0 963 -939 -795 -26 -49 948 -282", "output": "963 -795 -367 -282 -49 -26 0 764 948 -939 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "20\n262 -689 -593 161 -678 -555 -633 -697 369 258 673 50 833 737 -650 198 -651 -621 -396 939", "output": "939 -689 -678 -651 -650 -633 -621 -593 -555 -396 50 161 198 258 262 369 673 737 833 -697 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "50\n-262 -377 -261 903 547 759 -800 -53 670 92 758 109 547 877 152 -901 -318 -527 -388 24 139 -227 413 -135 811 -886 -22 -526 -643 -431 284 609 -745 -62 323 -441 743 -800 86 862 587 -513 -468 -651 -760 197 141 -414 -909 438", "output": "903 -901 -886 -800 -800 -760 -745 -651 -643 -527 -526 -513 -468 -441 -431 -414 -388 -377 -318 -262 -261 -227 -135 -62 -53 -22 24 86 92 109 139 141 152 197 284 323 413 438 547 547 587 609 670 743 758 759 811 862 877 -909 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\n144 -534 -780 -1 -259 -945 -992 -967 -679 -239 -22 387 130 -908 140 -270 16 646 398 599 -631 -231 687 -505 89 77 584 162 124 132 33 271 212 734 350 -678 969 43 487 -689 -432 -225 -603 801 -828 -684 349 318 109 723 33 -247 719 368 -286 217 260 77 -618 955 408 994 -313 -341 578 609 60 900 222 -779 -507 464 -147 -789 -477 -235 -407 -432 35 300 -53 -896 -476 927 -293 -869 -852 -566 -759 95 506 -914 -405 -621 319 -622 -49 -334 328 -104", "output": "994 -967 -945 -914 -908 -896 -869 -852 -828 -789 -780 -779 -759 -689 -684 -679 -678 -631 -622 -621 -618 -603 -566 -534 -507 -505 -477 -476 -432 -432 -407 -405 -341 -334 -313 -293 -286 -270 -259 -247 -239 -235 -231 -225 -147 -104 -53 -49 -22 -1 16 33 33 35 43 60 77 77 89 95 109 124 130 132 140 144 162 212 217 222 260 271 300 318 319 328 349 350 368 387 398 408 464 487 506 578 584 599 609 646 687 719 723 734 801 900 927 955 969 -992 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\n-790 341 910 905 -779 279 696 -375 525 -21 -2 751 -887 764 520 -844 850 -537 -882 -183 139 -397 561 -420 -991 691 587 -93 -701 -957 -89 227 233 545 934 309 -26 454 -336 -994 -135 -840 -320 -387 -943 650 628 -583 701 -708 -881 287 -932 -265 -312 -757 695 985 -165 -329 -4 -462 -627 798 -124 -539 843 -492 -967 -782 879 -184 -351 -385 -713 699 -477 828 219 961 -170 -542 877 -718 417 152 -905 181 301 920 685 -502 518 -115 257 998 -112 -234 -223 -396", "output": "998 -991 -967 -957 -943 -932 -905 -887 -882 -881 -844 -840 -790 -782 -779 -757 -718 -713 -708 -701 -627 -583 -542 -539 -537 -502 -492 -477 -462 -420 -397 -396 -387 -385 -375 -351 -336 -329 -320 -312 -265 -234 -223 -184 -183 -170 -165 -135 -124 -115 -112 -93 -89 -26 -21 -4 -2 139 152 181 219 227 233 257 279 287 301 309 341 417 454 518 520 525 545 561 587 628 650 685 691 695 696 699 701 751 764 798 828 843 850 877 879 905 910 920 934 961 985 -994 ", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
35
Solve the following coding problem using the programming language python: After a terrifying forest fire in Berland a forest rebirth program was carried out. Due to it *N* rows with *M* trees each were planted and the rows were so neat that one could map it on a system of coordinates so that the *j*-th tree in the *i*-th row would have the coordinates of (*i*,<=*j*). However a terrible thing happened and the young forest caught fire. Now we must find the coordinates of the tree that will catch fire last to plan evacuation. The burning began in *K* points simultaneously, which means that initially *K* trees started to burn. Every minute the fire gets from the burning trees to the ones that aren’t burning and that the distance from them to the nearest burning tree equals to 1. Find the tree that will be the last to start burning. If there are several such trees, output any. The input will be provided via standard input and looks as follows: The first input line contains two integers *N*,<=*M* (1<=≤<=*N*,<=*M*<=≤<=2000) — the size of the forest. The trees were planted in all points of the (*x*,<=*y*) (1<=≤<=*x*<=≤<=*N*,<=1<=≤<=*y*<=≤<=*M*) type, *x* and *y* are integers. The second line contains an integer *K* (1<=≤<=*K*<=≤<=10) — amount of trees, burning in the beginning. The third line contains *K* pairs of integers: *x*1,<=*y*1,<=*x*2,<=*y*2,<=...,<=*x**k*,<=*y**k* (1<=≤<=*x**i*<=≤<=*N*,<=1<=≤<=*y**i*<=≤<=*M*) — coordinates of the points from which the fire started. It is guaranteed that no two points coincide. You should write the solution as standard output as follows: Output a line with two space-separated integers *x* and *y* — coordinates of the tree that will be the last one to start burning. If there are several such trees, output any. Here are example inputs and outputs for the problem: Example Input 1: 3 3 1 2 2 Example Output 1: 1 1 Example Input 2: 3 3 1 1 1 Example Output 2: 3 3 Example Input 3: 3 3 2 1 1 3 3 Example Output 3: 2 2 Now solve the problem by providing the code.
import sys sys.stdin = open("input.txt", "r") sys.stdout = open("output.txt", "w") input = sys.stdin.buffer.readline n, m = map(int, input().split()) k = int(input()) xy = list(map(int, input().split())) ma, u, v = 0, 1, 1 for i in range(1, n + 1): for j in range(1, m + 1): c = n + m for l in range(k): x, y = xy[2 * l], xy[2 * l + 1] c = min(c, abs(x - i) + abs(y - j)) if ma < c: ma, u, v = c, i, j ans = " ".join(map(str, (u, v))) print(ans)
vfc_84029
{ "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\n1\n2 2", "output": "1 1", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n1\n1 1", "output": "3 3", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n2\n1 1 3 3", "output": "1 3", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n1\n1 1", "output": "1 1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
598
Solve the following coding problem using the programming language python: In this problem you are to calculate the sum of all integers from 1 to *n*, but you should take all powers of two with minus in the sum. For example, for *n*<==<=4 the sum is equal to <=-<=1<=-<=2<=+<=3<=-<=4<==<=<=-<=4, because 1, 2 and 4 are 20, 21 and 22 respectively. Calculate the answer for *t* values of *n*. The input will be provided via standard input and looks as follows: The first line of the input contains a single integer *t* (1<=≤<=*t*<=≤<=100) — the number of values of *n* to be processed. Each of next *t* lines contains a single integer *n* (1<=≤<=*n*<=≤<=109). You should write the solution as standard output as follows: Print the requested sum for each of *t* integers *n* given in the input. Here are example inputs and outputs for the problem: Example Input 1: 2 4 1000000000 Example Output 1: -4 499999998352516354 Now solve the problem by providing the code.
t = int(input()) for _ in range(t): x = int(input()) s = (x * (x+1)) // 2 y = 1 z = 0 while y <= x: z += y y *= 2 print(s - z*2)
vfc_84033
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4\n1000000000", "output": "-4\n499999998352516354", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
952
Solve the following coding problem using the programming language python: Not to be confused with [chessboard](https://en.wikipedia.org/wiki/Chessboard). The input will be provided via standard input and looks as follows: The first line of input contains a single integer *N* (1<=≤<=*N*<=≤<=100) — the number of cheeses you have. The next *N* lines describe the cheeses you have. Each line contains two space-separated strings: the name of the cheese and its type. The name is a string of lowercase English letters between 1 and 10 characters long. The type is either "soft" or "hard. All cheese names are distinct. You should write the solution as standard output as follows: Output a single number. Here are example inputs and outputs for the problem: Example Input 1: 9 brie soft camembert soft feta soft goat soft muenster soft asiago hard cheddar hard gouda hard swiss hard Example Output 1: 3 Example Input 2: 6 parmesan hard emmental hard edam hard colby hard gruyere hard asiago hard Example Output 2: 4 Now solve the problem by providing the code.
from math import * t = input n = int(t()) a = sum(t()[-4] == 'h' for i in 'i' * n) print(ceil(max(max(n - a, a) * 2 - 1, n) ** .5))
vfc_84041
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "9\nbrie soft\ncamembert soft\nfeta soft\ngoat soft\nmuenster soft\nasiago hard\ncheddar hard\ngouda hard\nswiss hard", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\nparmesan hard\nemmental hard\nedam hard\ncolby hard\ngruyere hard\nasiago hard", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "9\ngorgonzola soft\ncambozola soft\nmascarpone soft\nricotta soft\nmozzarella soft\nbryndza soft\njarlsberg soft\nhavarti soft\nstilton soft", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\nprovolone hard", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\nemmental hard\nfeta soft\ngoat soft\nroquefort hard", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\ncamembert soft", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
289
Solve the following coding problem using the programming language python: Little penguin Polo adores integer segments, that is, pairs of integers [*l*; *r*] (*l*<=≤<=*r*). He has a set that consists of *n* integer segments: [*l*1; *r*1],<=[*l*2; *r*2],<=...,<=[*l**n*; *r**n*]. We know that no two segments of this set intersect. In one move Polo can either widen any segment of the set 1 unit to the left or 1 unit to the right, that is transform [*l*; *r*] to either segment [*l*<=-<=1; *r*], or to segment [*l*; *r*<=+<=1]. The value of a set of segments that consists of *n* segments [*l*1; *r*1],<=[*l*2; *r*2],<=...,<=[*l**n*; *r**n*] is the number of integers *x*, such that there is integer *j*, for which the following inequality holds, *l**j*<=≤<=*x*<=≤<=*r**j*. Find the minimum number of moves needed to make the value of the set of Polo's segments divisible by *k*. The input will be provided via standard input and looks as follows: The first line contains two integers *n* and *k* (1<=≤<=*n*,<=*k*<=≤<=105). Each of the following *n* lines contain a segment as a pair of integers *l**i* and *r**i* (<=-<=105<=≤<=*l**i*<=≤<=*r**i*<=≤<=105), separated by a space. It is guaranteed that no two segments intersect. In other words, for any two integers *i*,<=*j* (1<=≤<=*i*<=&lt;<=*j*<=≤<=*n*) the following inequality holds, *min*(*r**i*,<=*r**j*)<=&lt;<=*max*(*l**i*,<=*l**j*). You should write the solution as standard output as follows: In a single line print a single integer — the answer to the problem. Here are example inputs and outputs for the problem: Example Input 1: 2 3 1 2 3 4 Example Output 1: 2 Example Input 2: 3 7 1 2 3 3 4 7 Example Output 2: 0 Now solve the problem by providing the code.
myMap = map(int , input().split()) myMap = list(myMap) n , k , sum = myMap[0] , myMap[1] , 0 for i in range(n) : temp = map(int , input().split()) temp = list(temp) sum+= (temp[1] - temp[0]) + 1 sum = sum%k if sum !=0 : sum = k - sum print(sum)
vfc_84045
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 3\n1 2\n3 4", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 7\n1 2\n3 3\n4 7", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 7\n1 10\n11 47\n74 128", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 4\n1 1\n2 2\n3 3\n4 4\n5 5", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 4\n2 2\n-1 -1\n0 1\n7 8\n-3 -2\n9 9\n4 6", "output": "0", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
104
Solve the following coding problem using the programming language python: One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one! Why not make her own Codeforces, with blackjack and other really cool stuff? Many people will surely be willing to visit this splendid shrine of high culture. In Mainframe a standard pack of 52 cards is used to play blackjack. The pack contains cards of 13 values: 2, 3, 4, 5, 6, 7, 8, 9, 10, jacks, queens, kings and aces. Each value also exists in one of four suits: hearts, diamonds, clubs and spades. Also, each card earns some value in points assigned to it: cards with value from two to ten earn from 2 to 10 points, correspondingly. An ace can either earn 1 or 11, whatever the player wishes. The picture cards (king, queen and jack) earn 10 points. The number of points a card earns does not depend on the suit. The rules of the game are very simple. The player gets two cards, if the sum of points of those cards equals *n*, then the player wins, otherwise the player loses. The player has already got the first card, it's the queen of spades. To evaluate chances for victory, you should determine how many ways there are to get the second card so that the sum of points exactly equals *n*. The input will be provided via standard input and looks as follows: The only line contains *n* (1<=≤<=*n*<=≤<=25) — the required sum of points. You should write the solution as standard output as follows: Print the numbers of ways to get the second card in the required way if the first card is the queen of spades. Here are example inputs and outputs for the problem: Example Input 1: 12 Example Output 1: 4 Example Input 2: 20 Example Output 2: 15 Example Input 3: 10 Example Output 3: 0 Now solve the problem by providing the code.
#!/usr/bin/python3 def readln(): return tuple(map(int, input().split())) print([0,4,4,4,4,4,4,4,4,4,15,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0][readln()[0] - 10])
vfc_84049
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "12", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "20", "output": "15", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
2
Solve the following coding problem using the programming language python: The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game there is only one player with the maximum number of points, he is the winner. The situation becomes more difficult if the number of such players is more than one. During each round a player gains or loses a particular number of points. In the course of the game the number of points is registered in the line "name score", where name is a player's name, and score is the number of points gained in this round, which is an integer number. If score is negative, this means that the player has lost in the round. So, if two or more players have the maximum number of points (say, it equals to *m*) at the end of the game, than wins the one of them who scored at least *m* points first. Initially each player has 0 points. It's guaranteed that at the end of the game at least one player has a positive number of points. The input will be provided via standard input and looks as follows: The first line contains an integer number *n* (1<=<=≤<=<=*n*<=<=≤<=<=1000), *n* is the number of rounds played. Then follow *n* lines, containing the information about the rounds in "name score" format in chronological order, where name is a string of lower-case Latin letters with the length from 1 to 32, and score is an integer number between -1000 and 1000, inclusive. You should write the solution as standard output as follows: Print the name of the winner. Here are example inputs and outputs for the problem: Example Input 1: 3 mike 3 andrew 5 mike 2 Example Output 1: andrew Example Input 2: 3 andrew 3 andrew 2 mike 5 Example Output 2: andrew Now solve the problem by providing the code.
n=int(input()) d={} l=[] for test in range(n): a,b=input().split() l.append((a,b)) d[a]=int(b)+d.get(a,0) m=0 for item in d.items(): m=max(m,item[1]) d={} x=[] for a,b in l: c=int(b)+d.get(a,0) d[a]=c if(c>=m): x.append(a) r="" for c in x: if d[c]==m: r=c break print(r)
vfc_84053
{ "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\nmike 3\nandrew 5\nmike 2", "output": "andrew", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\nandrew 3\nandrew 2\nmike 5", "output": "andrew", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
284
Solve the following coding problem using the programming language python: The cows have just learned what a primitive root is! Given a prime *p*, a primitive root is an integer *x* (1<=≤<=*x*<=&lt;<=*p*) such that none of integers *x*<=-<=1,<=*x*2<=-<=1,<=...,<=*x**p*<=-<=2<=-<=1 are divisible by *p*, but *x**p*<=-<=1<=-<=1 is. Unfortunately, computing primitive roots can be time consuming, so the cows need your help. Given a prime *p*, help the cows find the number of primitive roots . The input will be provided via standard input and looks as follows: The input contains a single line containing an integer *p* (2<=≤<=*p*<=&lt;<=2000). It is guaranteed that *p* is a prime. You should write the solution as standard output as follows: Output on a single line the number of primitive roots . Here are example inputs and outputs for the problem: Example Input 1: 3 Example Output 1: 1 Example Input 2: 5 Example Output 2: 2 Now solve the problem by providing the code.
p=int(input()) g=0 for x in range(1,p): i=x u=1 o=0 while u<p-1: x%=p if (x-1)%p==0: break x*=i u+=1 else: if (x-1)%p==0: g+=1 print(g)
vfc_84057
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "5", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "7", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "11", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "17", "output": "8", "type": "stdin_stdout" }, { "fn_name": null, "input": "19", "output": "6", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
820
Solve the following coding problem using the programming language python: On one quiet day all of sudden Mister B decided to draw angle *a* on his field. Aliens have already visited his field and left many different geometric figures on it. One of the figures is regular convex *n*-gon (regular convex polygon with *n* sides). That's why Mister B decided to use this polygon. Now Mister B must find three distinct vertices *v*1, *v*2, *v*3 such that the angle (where *v*2 is the vertex of the angle, and *v*1 and *v*3 lie on its sides) is as close as possible to *a*. In other words, the value should be minimum possible. If there are many optimal solutions, Mister B should be satisfied with any of them. The input will be provided via standard input and looks as follows: First and only line contains two space-separated integers *n* and *a* (3<=≤<=*n*<=≤<=105, 1<=≤<=*a*<=≤<=180) — the number of vertices in the polygon and the needed angle, in degrees. You should write the solution as standard output as follows: Print three space-separated integers: the vertices *v*1, *v*2, *v*3, which form . If there are multiple optimal solutions, print any of them. The vertices are numbered from 1 to *n* in clockwise order. Here are example inputs and outputs for the problem: Example Input 1: 3 15 Example Output 1: 1 2 3 Example Input 2: 4 67 Example Output 2: 2 1 3 Example Input 3: 4 68 Example Output 3: 4 1 2 Now solve the problem by providing the code.
n, alp = map(int, input().split()) a = 180 / n if alp >= (n-2)*180/n: print("1 2 3") else: k1 = int(alp / a) if (k1 + 1) * a - alp < alp - k1 * a: k1 += 1 if k1 == 0: print("2 1 3") else: print(1, 2, n + 1 - k1)
vfc_84061
{ "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 15", "output": "2 1 3", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 67", "output": "2 1 3", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 68", "output": "2 1 4", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
189
Solve the following coding problem using the programming language python: Polycarpus has a ribbon, its length is *n*. He wants to cut the ribbon in a way that fulfils the following two conditions: - After the cutting each ribbon piece should have length *a*, *b* or *c*. - After the cutting the number of ribbon pieces should be maximum. Help Polycarpus and find the number of ribbon pieces after the required cutting. The input will be provided via standard input and looks as follows: The first line contains four space-separated integers *n*, *a*, *b* and *c* (1<=≤<=*n*,<=*a*,<=*b*,<=*c*<=≤<=4000) — the length of the original ribbon and the acceptable lengths of the ribbon pieces after the cutting, correspondingly. The numbers *a*, *b* and *c* can coincide. You should write the solution as standard output as follows: Print a single number — the maximum possible number of ribbon pieces. It is guaranteed that at least one correct ribbon cutting exists. Here are example inputs and outputs for the problem: Example Input 1: 5 5 3 2 Example Output 1: 2 Example Input 2: 7 5 5 2 Example Output 2: 2 Now solve the problem by providing the code.
n, a, b, c = map(int, input().split()) temp = 0 for i in range(n+1): for j in range(n+1): if i*a + j*b <= n: if (n - (i*a + j*b)) % c == 0: flag = i + j + (n - (i*a + j*b)) // c if flag > temp and flag != 0: temp = flag print(temp)
vfc_84065
{ "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 5 3 2", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 5 5 2", "output": "2", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
134
Solve the following coding problem using the programming language python: You are given a sequence of positive integers *a*1,<=*a*2,<=...,<=*a**n*. Find all such indices *i*, that the *i*-th element equals the arithmetic mean of all other elements (that is all elements except for this one). The input will be provided via standard input and looks as follows: The first line contains the integer *n* (2<=≤<=*n*<=≤<=2·105). The second line contains elements of the sequence *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=1000). All the elements are positive integers. You should write the solution as standard output as follows: Print on the first line the number of the sought indices. Print on the second line the sought indices in the increasing order. All indices are integers from 1 to *n*. If the sought elements do not exist, then the first output line should contain number 0. In this case you may either not print the second line or print an empty line. Here are example inputs and outputs for the problem: Example Input 1: 5 1 2 3 4 5 Example Output 1: 1 3 Example Input 2: 4 50 50 50 50 Example Output 2: 4 1 2 3 4 Now solve the problem by providing the code.
from math import gcd,lcm,sqrt,factorial def solve(): s=sum(a) AVG=s//n if s%n:print(0);return li,ans=[],0 for i in range(n): if AVG==a[i]: li.append(i+1) ans+=1 print(ans) print(*li) if __name__ == '__main__': n=int(input()) a=[int(x) for x in input().split()] solve()
vfc_84073
{ "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 2 3 4 5", "output": "1\n3 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n50 50 50 50", "output": "4\n1 2 3 4 ", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
505
Solve the following coding problem using the programming language python: Mr. Kitayuta has kindly given you a string *s* consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into *s* to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "test" and "kitayuta" are not. You can choose any lowercase English letter, and insert it to any position of *s*, possibly to the beginning or the end of *s*. You have to insert a letter even if the given string is already a palindrome. If it is possible to insert one lowercase English letter into *s* so that the resulting string will be a palindrome, print the string after the insertion. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one palindrome that can be obtained, you are allowed to print any of them. The input will be provided via standard input and looks as follows: The only line of the input contains a string *s* (1<=≤<=|*s*|<=≤<=10). Each character in *s* is a lowercase English letter. You should write the solution as standard output as follows: If it is possible to turn *s* into a palindrome by inserting one lowercase English letter, print the resulting string in a single line. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one solution, any of them will be accepted. Here are example inputs and outputs for the problem: Example Input 1: revive Example Output 1: reviver Example Input 2: ee Example Output 2: eye Example Input 3: kitayuta Example Output 3: NA Now solve the problem by providing the code.
s = input() def chk(s): for i in range(len(s)): if s[i] != s[len(s) - i - 1]: return False return True for i in range(len(s) + 1): for j in range(26): ns = s[:i] + chr(ord('a') + j) + s[i:] if chk(ns): print(ns) exit(0) print('NA')
vfc_84077
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "revive", "output": "reviver", "type": "stdin_stdout" }, { "fn_name": null, "input": "ee", "output": "eee", "type": "stdin_stdout" }, { "fn_name": null, "input": "kitayuta", "output": "NA", "type": "stdin_stdout" }, { "fn_name": null, "input": "evima", "output": "NA", "type": "stdin_stdout" }, { "fn_name": null, "input": "a", "output": "aa", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
488
Solve the following coding problem using the programming language python: Giga Tower is the tallest and deepest building in Cyberland. There are 17<=777<=777<=777 floors, numbered from <=-<=8<=888<=888<=888 to 8<=888<=888<=888. In particular, there is floor 0 between floor <=-<=1 and floor 1. Every day, thousands of tourists come to this place to enjoy the wonderful view. In Cyberland, it is believed that the number "8" is a lucky number (that's why Giga Tower has 8<=888<=888<=888 floors above the ground), and, an integer is lucky, if and only if its decimal notation contains at least one digit "8". For example, 8,<=<=-<=180,<=808 are all lucky while 42,<=<=-<=10 are not. In the Giga Tower, if you write code at a floor with lucky floor number, good luck will always be with you (Well, this round is #278, also lucky, huh?). Tourist Henry goes to the tower to seek good luck. Now he is at the floor numbered *a*. He wants to find the minimum positive integer *b*, such that, if he walks *b* floors higher, he will arrive at a floor with a lucky number. The input will be provided via standard input and looks as follows: The only line of input contains an integer *a* (<=-<=109<=≤<=*a*<=≤<=109). You should write the solution as standard output as follows: Print the minimum *b* in a line. Here are example inputs and outputs for the problem: Example Input 1: 179 Example Output 1: 1 Example Input 2: -1 Example Output 2: 9 Example Input 3: 18 Example Output 3: 10 Now solve the problem by providing the code.
def c(a): if str(a).find("8")==-1: return False else: return True a=int(input()) k=0 while True: a+=1; k+=1 if c(a):break print(k)
vfc_84081
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "179", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "-1", "output": "9", "type": "stdin_stdout" }, { "fn_name": null, "input": "18", "output": "10", "type": "stdin_stdout" }, { "fn_name": null, "input": "-410058385", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
754
Solve the following coding problem using the programming language python: Ilya is an experienced player in tic-tac-toe on the 4<=×<=4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by making single turn or not. The rules of tic-tac-toe on the 4<=×<=4 field are as follows. Before the first turn all the field cells are empty. The two players take turns placing their signs into empty cells (the first player places Xs, the second player places Os). The player who places Xs goes first, the another one goes second. The winner is the player who first gets three of his signs in a row next to each other (horizontal, vertical or diagonal). The input will be provided via standard input and looks as follows: The tic-tac-toe position is given in four lines. Each of these lines contains four characters. Each character is '.' (empty cell), 'x' (lowercase English letter x), or 'o' (lowercase English letter o). It is guaranteed that the position is reachable playing tic-tac-toe, and it is Ilya's turn now (in particular, it means that the game is not finished). It is possible that all the cells are empty, it means that the friends left without making single turn. You should write the solution as standard output as follows: Print single line: "YES" in case Ilya could have won by making single turn, and "NO" otherwise. Here are example inputs and outputs for the problem: Example Input 1: xx.. .oo. x... oox. Example Output 1: YES Example Input 2: x.ox ox.. x.o. oo.x Example Output 2: NO Example Input 3: x..x ..oo o... x.xo Example Output 3: YES Example Input 4: o.x. o... .x.. ooxx Example Output 4: NO Now solve the problem by providing the code.
def check(i, j): if field[i][j] == '.': if field[i - 1][j] == field[i + 1][j] and field[i - 1][j] == 'x': return True elif field[i - 2][j] == field[i - 1][j] and field[i - 1][j] == 'x': return True elif field[i + 2][j] == field[i + 1][j] and field[i + 1][j] == 'x': return True elif field[i][j + 1] == field[i][j - 1] and field[i][j - 1] == 'x': return True elif field[i][j + 2] == field[i][j + 1] and field[i][j + 1] == 'x': return True elif field[i][j - 2] == field[i][j - 1] and field[i][j - 1] == 'x': return True elif field[i - 1][j - 1] == field[i + 1][j + 1] and field[i - 1][j - 1] == 'x': return True elif field[i - 1][j - 1] == field[i - 2][j - 2] and field[i - 1][j - 1] == 'x': return True elif field[i + 2][j + 2] == field[i + 1][j + 1] and field[i + 1][j + 1] == 'x': return True elif field[i - 1][j + 1] == field[i + 1][j - 1] and field[i - 1][j + 1] == 'x': return True elif field[i - 2][j + 2] == field[i - 1][j + 1] and field[i - 1][j + 1] == 'x': return True elif field[i + 1][j - 1] == field[i + 2][j - 2] and field[i + 1][j - 1] == 'x': return True return False field = [['o', 'o', 'o', 'o', 'o', 'o', 'o', 'o'], ['o', 'o', 'o', 'o', 'o', 'o', 'o', 'o']] + [['o', 'o'] + [i for i in input()] + ['o', 'o'] for i in range(4)] + [['o', 'o', 'o', 'o', 'o', 'o', 'o', 'o'], ['o', 'o', 'o', 'o', 'o', 'o', 'o', 'o']] i = 2 j = 2 while j < 6 and not check(i, j): i += 1 if i == 6: i = 2 j += 1 if j == 6: print('NO') else: print('YES')
vfc_84085
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "xx..\n.oo.\nx...\noox.", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "x.ox\nox..\nx.o.\noo.x", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "x..x\n..oo\no...\nx.xo", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "o.x.\no...\n.x..\nooxx", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": ".xox\no.x.\nx.o.\n..o.", "output": "YES", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
495
Solve the following coding problem using the programming language python: Last week, Hamed learned about a new type of equations in his math class called Modular Equations. Lets define *i* modulo *j* as the remainder of division of *i* by *j* and denote it by . A Modular Equation, as Hamed's teacher described, is an equation of the form in which *a* and *b* are two non-negative integers and *x* is a variable. We call a positive integer *x* for which a solution of our equation. Hamed didn't pay much attention to the class since he was watching a movie. He only managed to understand the definitions of these equations. Now he wants to write his math exercises but since he has no idea how to do that, he asked you for help. He has told you all he knows about Modular Equations and asked you to write a program which given two numbers *a* and *b* determines how many answers the Modular Equation has. The input will be provided via standard input and looks as follows: In the only line of the input two space-separated integers *a* and *b* (0<=≤<=*a*,<=*b*<=≤<=109) are given. You should write the solution as standard output as follows: If there is an infinite number of answers to our equation, print "infinity" (without the quotes). Otherwise print the number of solutions of the Modular Equation . Here are example inputs and outputs for the problem: Example Input 1: 21 5 Example Output 1: 2 Example Input 2: 9435152 272 Example Output 2: 282 Example Input 3: 10 10 Example Output 3: infinity Now solve the problem by providing the code.
arr = [int(x) for x in input().split()] a = arr[0] b = arr[1] resp = 0 if a == b: resp = 'infinity' if resp != 'infinity': x = a - b i = 1 c = 0 while i**2 < x: c += 1 if x % i == 0: if i > b: resp += 1 if x/i > b: resp += 1 i += 1 if i**2 == x and i > b: resp += 1 print (resp)
vfc_84089
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "21 5", "output": "2", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
798
Solve the following coding problem using the programming language python: Mike has a string *s* consisting of only lowercase English letters. He wants to change exactly one character from the string so that the resulting one is a palindrome. A palindrome is a string that reads the same backward as forward, for example strings "z", "aaa", "aba", "abccba" are palindromes, but strings "codeforces", "reality", "ab" are not. The input will be provided via standard input and looks as follows: The first and single line contains string *s* (1<=≤<=|*s*|<=≤<=15). You should write the solution as standard output as follows: Print "YES" (without quotes) if Mike can change exactly one character so that the resulting string is palindrome or "NO" (without quotes) otherwise. Here are example inputs and outputs for the problem: Example Input 1: abccaa Example Output 1: YES Example Input 2: abbcca Example Output 2: NO Example Input 3: abcda Example Output 3: YES Now solve the problem by providing the code.
text=input() n=len(text) c=0 for i in range(n): if text[i]!=text[n-i-1]: c=c+1 if (n%2==0): if(c==2): print("yes") else: print("no") elif(n%2==1): if (c==2 or c==0): print("yes") else: print("no")
vfc_84097
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "abccaa", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "abbcca", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "abcda", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "kyw", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "fccf", "output": "NO", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
487
Solve the following coding problem using the programming language python: Consider a sequence [*a*1,<=*a*2,<=... ,<=*a**n*]. Define its prefix product sequence . Now given *n*, find a permutation of [1,<=2,<=...,<=*n*], such that its prefix product sequence is a permutation of [0,<=1,<=...,<=*n*<=-<=1]. The input will be provided via standard input and looks as follows: The only input line contains an integer *n* (1<=≤<=*n*<=≤<=105). You should write the solution as standard output as follows: In the first output line, print "YES" if such sequence exists, or print "NO" if no such sequence exists. If any solution exists, you should output *n* more lines. *i*-th line contains only an integer *a**i*. The elements of the sequence should be different positive integers no larger than *n*. If there are multiple solutions, you are allowed to print any of them. Here are example inputs and outputs for the problem: Example Input 1: 7 Example Output 1: YES 1 4 3 6 5 2 7 Example Input 2: 6 Example Output 2: NO Now solve the problem by providing the code.
def comp(x): for i in range(2, x): if x % i == 0: return True return False N = int(input()) if N == 4: print('YES', '1', '3', '2', '4', sep = '\n') elif comp(N): print('NO') else: print('YES', '1', sep = '\n') if N > 1: for i in range(2, N): print((i - 1) * pow(i, N - 2, N) % N) print(N)
vfc_84101
{ "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", "output": "YES\n1\n2\n5\n6\n3\n4\n7", "type": "stdin_stdout" }, { "fn_name": null, "input": "6", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "7137", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "10529", "output": "YES\n1\n2\n5266\n3511\n7898\n2107\n1756\n9026\n9214\n1171\n1054\n4787\n6143\n811\n9778\n703\n9872\n8672\n586\n3326\n5792\n6519\n2394\n6410\n3072\n2528\n406\n391\n10154\n5084\n352\n5775\n10201\n5106\n9601\n1806\n5558\n1993\n6928\n271\n8161\n9246\n3260\n8816\n6462\n235\n8470\n10306\n6801\n8811\n6529\n6401\n5468\n597\n196\n3064\n10342\n4619\n7807\n4284\n5441\n4834\n2888\n9193\n5101\n163\n7818\n3144\n4801\n5647\n6168\n4005\n8044\n4328\n997\n4353\n8729\n3693\n136\n8131\n4081\n131\n9888\n889\n6895\n3841\n9673\n5...", "type": "stdin_stdout" }, { "fn_name": null, "input": "34211", "output": "YES\n1\n2\n17107\n11405\n8554\n27370\n5703\n14663\n21383\n15206\n30791\n31102\n2852\n21054\n7332\n9124\n10692\n24150\n24709\n21608\n15396\n16292\n32657\n23800\n18532\n12317\n27633\n16473\n20772\n15337\n21668\n13244\n22452\n10368\n29181\n23460\n12355\n7398\n27910\n29826\n24804\n10014\n25252\n30234\n16329\n3042\n29006\n13831\n26372\n26532\n6159\n30858\n13817\n1292\n8237\n33590\n27492\n18607\n7669\n26674\n27940\n30847\n23728\n16835\n28332\n17896\n22290\n25021\n14591\n7934\n28836\n6265\n6178\n27651\n20805\n155...", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
485
Solve the following coding problem using the programming language python: One industrial factory is reforming working plan. The director suggested to set a mythical detail production norm. If at the beginning of the day there were *x* details in the factory storage, then by the end of the day the factory has to produce (remainder after dividing *x* by *m*) more details. Unfortunately, no customer has ever bought any mythical detail, so all the details produced stay on the factory. The board of directors are worried that the production by the given plan may eventually stop (that means that there will be а moment when the current number of details on the factory is divisible by *m*). Given the number of details *a* on the first day and number *m* check if the production stops at some moment. The input will be provided via standard input and looks as follows: The first line contains two integers *a* and *m* (1<=≤<=*a*,<=*m*<=≤<=105). You should write the solution as standard output as follows: Print "Yes" (without quotes) if the production will eventually stop, otherwise print "No". Here are example inputs and outputs for the problem: Example Input 1: 1 5 Example Output 1: No Example Input 2: 3 6 Example Output 2: Yes Now solve the problem by providing the code.
a, m = map(int, input().split()) s = set() while True: a %= m if a in s: print('Yes' if 0 in s else 'No') break s.add(a) a *= 2
vfc_84105
{ "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", "output": "No", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 6", "output": "Yes", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 8", "output": "Yes", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3", "output": "No", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 24", "output": "Yes", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
354
Solve the following coding problem using the programming language python: Vasya's got a birthday coming up and his mom decided to give him an array of positive integers *a* of length *n*. Vasya thinks that an array's beauty is the greatest common divisor of all its elements. His mom, of course, wants to give him as beautiful an array as possible (with largest possible beauty). Unfortunately, the shop has only one array *a* left. On the plus side, the seller said that he could decrease some numbers in the array (no more than by *k* for each number). The seller can obtain array *b* from array *a* if the following conditions hold: *b**i*<=&gt;<=0; 0<=≤<=*a**i*<=-<=*b**i*<=≤<=*k* for all 1<=≤<=*i*<=≤<=*n*. Help mom find the maximum possible beauty of the array she will give to Vasya (that seller can obtain). The input will be provided via standard input and looks as follows: The first line contains two integers *n* and *k* (1<=≤<=*n*<=≤<=3·105;<=1<=≤<=*k*<=≤<=106). The second line contains *n* integers *a**i* (1<=≤<=*a**i*<=≤<=106) — array *a*. You should write the solution as standard output as follows: In the single line print a single number — the maximum possible beauty of the resulting array. Here are example inputs and outputs for the problem: Example Input 1: 6 1 3 6 10 12 13 16 Example Output 1: 3 Example Input 2: 5 3 8 21 52 15 77 Example Output 2: 7 Now solve the problem by providing the code.
n, k = map(int, input().split()) t = set(map(int, input().split())) y = x = min(t) t = list(t) while True: for i in t: if i % x > k: x = i // (i // x + 1) if y == x: break y = x print(y)
vfc_84109
{ "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\n3 6 10 12 13 16", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3\n8 21 52 15 77", "output": "7", "type": "stdin_stdout" }, { "fn_name": null, "input": "13 11\n55 16 26 40 84 80 48 52 25 43 75 21 58", "output": "16", "type": "stdin_stdout" }, { "fn_name": null, "input": "18 9\n85 29 29 15 17 71 46 69 48 80 44 73 40 55 61 57 22 68", "output": "13", "type": "stdin_stdout" }, { "fn_name": null, "input": "25 7\n67 18 36 85 64 22 32 66 17 64 66 65 82 36 16 52 19 70 38 51 17 32 85 16 64", "output": "16", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
494
Solve the following coding problem using the programming language python: Malek has recently found a treasure map. While he was looking for a treasure he found a locked door. There was a string *s* written on the door consisting of characters '(', ')' and '#'. Below there was a manual on how to open the door. After spending a long time Malek managed to decode the manual and found out that the goal is to replace each '#' with one or more ')' characters so that the final string becomes beautiful. Below there was also written that a string is called beautiful if for each *i* (1<=≤<=*i*<=≤<=|*s*|) there are no more ')' characters than '(' characters among the first *i* characters of *s* and also the total number of '(' characters is equal to the total number of ')' characters. Help Malek open the door by telling him for each '#' character how many ')' characters he must replace it with. The input will be provided via standard input and looks as follows: The first line of the input contains a string *s* (1<=≤<=|*s*|<=≤<=105). Each character of this string is one of the characters '(', ')' or '#'. It is guaranteed that *s* contains at least one '#' character. You should write the solution as standard output as follows: If there is no way of replacing '#' characters which leads to a beautiful string print <=-<=1. Otherwise for each character '#' print a separate line containing a positive integer, the number of ')' characters this character must be replaced with. If there are several possible answers, you may output any of them. Here are example inputs and outputs for the problem: Example Input 1: (((#)((#) Example Output 1: 1 2 Example Input 2: ()((#((#(#() Example Output 2: 2 2 1 Example Input 3: # Example Output 3: -1 Example Input 4: (#) Example Output 4: -1 Now solve the problem by providing the code.
s = input() n = len(s) p, curr = n - 1, 0 while s[p] != '#': if s[p] == ')': curr += 1 else: curr -= 1 p -= 1 if curr < 0: print(-1) exit() cnt_hash, curr = s.count('#'), 0 for i in range(p): if s[i] == '(': curr += 1 else: curr -= 1 if curr < 0: print(-1) exit() res = s.count('(') - s.count(')') - (cnt_hash - 1) if res <= 0: print(-1) exit() cnt_hash -= 1 print('\n'.join('1'*cnt_hash)) print(s.count('(') - s.count(')') - cnt_hash)
vfc_84113
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "(((#)((#)", "output": "1\n2", "type": "stdin_stdout" }, { "fn_name": null, "input": "()((#((#(#()", "output": "1\n1\n3", "type": "stdin_stdout" }, { "fn_name": null, "input": "#", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "(#)", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "(((((#(#(#(#()", "output": "1\n1\n1\n5", "type": "stdin_stdout" }, { "fn_name": null, "input": "#))))", "output": "-1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
753
Solve the following coding problem using the programming language python: Santa Claus has *n* candies, he dreams to give them as gifts to children. What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer number of candies. Santa Class wants to give all *n* candies he has. The input will be provided via standard input and looks as follows: The only line contains positive integer number *n* (1<=≤<=*n*<=≤<=1000) — number of candies Santa Claus has. You should write the solution as standard output as follows: Print to the first line integer number *k* — maximal number of kids which can get candies. Print to the second line *k* distinct integer numbers: number of candies for each of *k* kid. The sum of *k* printed numbers should be exactly *n*. If there are many solutions, print any of them. Here are example inputs and outputs for the problem: Example Input 1: 5 Example Output 1: 2 2 3 Example Input 2: 9 Example Output 2: 3 3 5 1 Example Input 3: 2 Example Output 3: 1 2 Now solve the problem by providing the code.
a=int(input()) c=[] d=0 for i in range(1,a+1): c.append(i) sum=0 for j in range(a): if sum+c[j]>a: sum+=c[j] d+=1 break else: sum+=c[j] d+=1 sum=0 e=[] for i in range(d-2): e.append(c[i]) sum+=c[i] e.append(a-sum) print(len(e)) print(*e)
vfc_84117
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5", "output": "2\n1 4 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "9", "output": "3\n1 2 6 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "2", "output": "1\n2 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "1", "output": "1\n1 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "3", "output": "2\n1 2 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000", "output": "44\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 54 ", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
87
Solve the following coding problem using the programming language python: Vasya the programmer lives in the middle of the Programming subway branch. He has two girlfriends: Dasha and Masha, who live at the different ends of the branch, each one is unaware of the other one's existence. When Vasya has some free time, he goes to one of his girlfriends. He descends into the subway at some time, waits the first train to come and rides on it to the end of the branch to the corresponding girl. However, the trains run with different frequencies: a train goes to Dasha's direction every *a* minutes, but a train goes to Masha's direction every *b* minutes. If two trains approach at the same time, Vasya goes toward the direction with the lower frequency of going trains, that is, to the girl, to whose directions the trains go less frequently (see the note to the third sample). We know that the trains begin to go simultaneously before Vasya appears. That is the train schedule is such that there exists a moment of time when the two trains arrive simultaneously. Help Vasya count to which girlfriend he will go more often. The input will be provided via standard input and looks as follows: The first line contains two integers *a* and *b* (*a*<=≠<=*b*,<=1<=≤<=*a*,<=*b*<=≤<=106). You should write the solution as standard output as follows: Print "Dasha" if Vasya will go to Dasha more frequently, "Masha" if he will go to Masha more frequently, or "Equal" if he will go to both girlfriends with the same frequency. Here are example inputs and outputs for the problem: Example Input 1: 3 7 Example Output 1: Dasha Example Input 2: 5 3 Example Output 2: Masha Example Input 3: 2 3 Example Output 3: Equal Now solve the problem by providing the code.
import sys def gcd(a, b): if(b == 0): return a r = a % b return gcd(b, r) a, b = [int(x) for x in (sys.stdin.readline()).split()] t = gcd(a, b) a /= t b /= t if(a > b): if(a != b + 1): print("Masha") else: print("Equal") else: if(b != a + 1): print("Dasha") else: print("Equal")
vfc_84121
{ "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", "output": "Dasha", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3", "output": "Masha", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3", "output": "Equal", "type": "stdin_stdout" }, { "fn_name": null, "input": "31 88", "output": "Dasha", "type": "stdin_stdout" }, { "fn_name": null, "input": "8 75", "output": "Dasha", "type": "stdin_stdout" }, { "fn_name": null, "input": "32 99", "output": "Dasha", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
739
Solve the following coding problem using the programming language python: Gosha is hunting. His goal is to catch as many Pokemons as possible. Gosha has *a* Poke Balls and *b* Ultra Balls. There are *n* Pokemons. They are numbered 1 through *n*. Gosha knows that if he throws a Poke Ball at the *i*-th Pokemon he catches it with probability *p**i*. If he throws an Ultra Ball at the *i*-th Pokemon he catches it with probability *u**i*. He can throw at most one Ball of each type at any Pokemon. The hunting proceeds as follows: at first, Gosha chooses no more than *a* Pokemons at which he will throw Poke Balls and no more than *b* Pokemons at which he will throw Ultra Balls. After that, he throws the chosen Balls at the chosen Pokemons. If he throws both Ultra Ball and Poke Ball at some Pokemon, he is caught if and only if he is caught by any of these Balls. The outcome of a throw doesn't depend on the other throws. Gosha would like to know what is the expected number of the Pokemons he catches if he acts in an optimal way. In other words, he would like to know the maximum possible expected number of Pokemons can catch. The input will be provided via standard input and looks as follows: The first line contains three integers *n*, *a* and *b* (2<=≤<=*n*<=≤<=2000, 0<=≤<=*a*,<=*b*<=≤<=*n*) — the number of Pokemons, the number of Poke Balls and the number of Ultra Balls. The second line contains *n* real values *p*1,<=*p*2,<=...,<=*p**n* (0<=≤<=*p**i*<=≤<=1), where *p**i* is the probability of catching the *i*-th Pokemon if Gosha throws a Poke Ball to it. The third line contains *n* real values *u*1,<=*u*2,<=...,<=*u**n* (0<=≤<=*u**i*<=≤<=1), where *u**i* is the probability of catching the *i*-th Pokemon if Gosha throws an Ultra Ball to it. All the probabilities are given with exactly three digits after the decimal separator. You should write the solution as standard output as follows: Print the maximum possible expected number of Pokemons Gosha can catch. The answer is considered correct if it's absolute or relative error doesn't exceed 10<=-<=4. Here are example inputs and outputs for the problem: Example Input 1: 3 2 2 1.000 0.000 0.500 0.000 1.000 0.500 Example Output 1: 2.75 Example Input 2: 4 1 3 0.100 0.500 0.500 0.600 0.100 0.500 0.900 0.400 Example Output 2: 2.16 Example Input 3: 3 2 0 0.412 0.198 0.599 0.612 0.987 0.443 Example Output 3: 1.011 Now solve the problem by providing the code.
import sys readline=sys.stdin.readline def Bisect_Float(ok,ng,is_ok,eps=1e-12,cnt=0): if cnt: for _ in range(cnt): mid=(ok+ng)/2 if is_ok(mid): ok=mid else: ng=mid else: while abs(ok-ng)/max(ok,ng,1)>eps: mid=(ok+ng)/2 if is_ok(mid): ok=mid else: ng=mid return ok N,A,B=map(int,readline().split()) inf=4 maximum_slope=inf minimum_slope=-inf P=list(map(float,readline().split())) U=list(map(float,readline().split())) def is_ok(c): dp=[0]*(A+1) cnt=[0]*(A+1) for n in range(1,N+1): prev_dp,prev_cnt=dp,cnt dp=[0]*(A+1) cnt=[0]*(A+1) dp[0],cnt[0]=max((prev_dp[0],prev_cnt[0]),(prev_dp[0]+U[n-1]-c,prev_cnt[0]+1)) for a in range(1,A+1): dp[a],cnt[a]=max((prev_dp[a],prev_cnt[a]),(prev_dp[a]+U[n-1]-c,prev_cnt[a]+1),(prev_dp[a-1]+P[n-1],prev_cnt[a-1]),(prev_dp[a-1]+P[n-1]+U[n-1]-P[n-1]*U[n-1]-c,prev_cnt[a-1]+1)) return cnt[A]>=B c=Bisect_Float(minimum_slope,maximum_slope,is_ok,1e-6) dp=[0]*(A+1) cnt=[0]*(A+1) for n in range(1,N+1): prev_dp,prev_cnt=dp,cnt dp=[0]*(A+1) cnt=[0]*(A+1) dp[0],cnt[0]=max((prev_dp[0],prev_cnt[0]),(prev_dp[0]+U[n-1]-c,prev_cnt[0]+1)) for a in range(1,A+1): dp[a],cnt[a]=max((prev_dp[a],prev_cnt[a]),(prev_dp[a]+U[n-1]-c,prev_cnt[a]+1),(prev_dp[a-1]+P[n-1],prev_cnt[a-1]),(prev_dp[a-1]+P[n-1]+U[n-1]-P[n-1]*U[n-1]-c,prev_cnt[a-1]+1)) ans=dp[A]+c*B print(ans)
vfc_84125
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2 2\n1.000 0.000 0.500\n0.000 1.000 0.500", "output": "2.75", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
171
Solve the following coding problem using the programming language python: The input contains two integers *a*1,<=*a*2 (0<=≤<=*a**i*<=≤<=109), separated by a single space. Output a single integer. The input will be provided via standard input and looks as follows: The input contains two integers *a*1,<=*a*2 (0<=≤<=*a**i*<=≤<=109), separated by a single space. You should write the solution as standard output as follows: Output a single integer. Here are example inputs and outputs for the problem: Example Input 1: 3 14 Example Output 1: 44 Example Input 2: 27 12 Example Output 2: 48 Example Input 3: 100 200 Example Output 3: 102 Now solve the problem by providing the code.
# LUOGU_RID: 101709040 a=input().split() a[1]=a[1][-1::-1] print(int(a[0])+int(a[1]))
vfc_84129
{ "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 14", "output": "44", "type": "stdin_stdout" }, { "fn_name": null, "input": "27 12", "output": "48", "type": "stdin_stdout" }, { "fn_name": null, "input": "100 200", "output": "102", "type": "stdin_stdout" }, { "fn_name": null, "input": "0 0", "output": "0", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
372
Solve the following coding problem using the programming language python: There are *n* kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is held. Each kangaroo can hold at most one kangaroo, and the kangaroo who is held by another kangaroo cannot hold any kangaroos. The kangaroo who is held by another kangaroo cannot be visible from outside. Please, find a plan of holding kangaroos with the minimal number of kangaroos who is visible. The input will be provided via standard input and looks as follows: The first line contains a single integer — *n* (1<=≤<=*n*<=≤<=5·105). Each of the next *n* lines contains an integer *s**i* — the size of the *i*-th kangaroo (1<=≤<=*s**i*<=≤<=105). You should write the solution as standard output as follows: Output a single integer — the optimal number of visible kangaroos. Here are example inputs and outputs for the problem: Example Input 1: 8 2 5 7 6 9 8 4 2 Example Output 1: 5 Example Input 2: 8 9 1 6 2 6 5 8 3 Example Output 2: 5 Now solve the problem by providing the code.
import sys, math n=int(input()) a=sorted(int(x) for x in sys.stdin) i=(n//2)-1 j=n-1 k=0 while j>((n//2)-1) and i>=0: if 2*a[i]<=a[j]: j-=1 k+=1 i-=1 #print(a) print(n-k)
vfc_84133
{ "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\n2\n5\n7\n6\n9\n8\n4\n2", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "8\n9\n1\n6\n2\n6\n5\n8\n3", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "12\n3\n99\n24\n46\n75\n63\n57\n55\n10\n62\n34\n52", "output": "7", "type": "stdin_stdout" }, { "fn_name": null, "input": "12\n55\n75\n1\n98\n63\n64\n9\n39\n82\n18\n47\n9", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\n678\n771\n96\n282\n135\n749\n168\n668\n17\n658\n979\n446\n998\n331\n606\n756\n37\n515\n538\n205\n647\n547\n904\n842\n647\n286\n774\n414\n267\n791\n595\n465\n8\n327\n855\n174\n339\n946\n184\n250\n807\n422\n679\n980\n64\n530\n312\n351\n676\n911\n803\n991\n669\n50\n293\n841\n545\n598\n737\n894\n231\n754\n588\n83\n873\n767\n833\n482\n905\n903\n970\n571\n715\n59\n777\n697\n537\n861\n339\n212\n149\n889\n905\n70\n970\n307\n830\n465\n968\n291\n430\n317\n942\n944\n330\n235\n814\n880\n415\n76", "output": "58", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
318
Solve the following coding problem using the programming language python: Being a nonconformist, Volodya is displeased with the current state of things, particularly with the order of natural numbers (natural number is positive integer number). He is determined to rearrange them. But there are too many natural numbers, so Volodya decided to start with the first *n*. He writes down the following sequence of numbers: firstly all odd integers from 1 to *n* (in ascending order), then all even integers from 1 to *n* (also in ascending order). Help our hero to find out which number will stand at the position number *k*. The input will be provided via standard input and looks as follows: The only line of input contains integers *n* and *k* (1<=≤<=*k*<=≤<=*n*<=≤<=1012). Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier. You should write the solution as standard output as follows: Print the number that will stand at the position number *k* after Volodya's manipulations. Here are example inputs and outputs for the problem: Example Input 1: 10 3 Example Output 1: 5 Example Input 2: 7 7 Example Output 2: 6 Now solve the problem by providing the code.
n, k = map(int, input().split()) if(n%2==0): half = n/2 if(k>half): dif = int(abs(k - half)) print(2*dif) else: print(2*k-1) else: half = (n-1)/2 +1 if(k>half): dif = int(abs(k- half)) print(2*dif) else: print(2*k-1)
vfc_84141
{ "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 3", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 7", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 1", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 2", "output": "3", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
982
Solve the following coding problem using the programming language python: You're given a row with $n$ chairs. We call a seating of people "maximal" if the two following conditions hold: 1. There are no neighbors adjacent to anyone seated. 1. It's impossible to seat one more person without violating the first rule. The seating is given as a string consisting of zeros and ones ($0$ means that the corresponding seat is empty, $1$ — occupied). The goal is to determine whether this seating is "maximal". Note that the first and last seats are not adjacent (if $n \ne 2$). The input will be provided via standard input and looks as follows: The first line contains a single integer $n$ ($1 \leq n \leq 1000$) — the number of chairs. The next line contains a string of $n$ characters, each of them is either zero or one, describing the seating. You should write the solution as standard output as follows: Output "Yes" (without quotation marks) if the seating is "maximal". Otherwise print "No". You are allowed to print letters in whatever case you'd like (uppercase or lowercase). Here are example inputs and outputs for the problem: Example Input 1: 3 101 Example Output 1: Yes Example Input 2: 4 1011 Example Output 2: No Example Input 3: 5 10001 Example Output 3: No Now solve the problem by providing the code.
val=input() s=input() s='0'+s+'0' if '11' in s or '000' in s: print('NO') else: print('YES')
vfc_84145
{ "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\n101", "output": "Yes", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1011", "output": "No", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n10001", "output": "No", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
172
Solve the following coding problem using the programming language python: Polycarpus has *n* friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they are strings *s*1,<=*s*2,<=...,<=*s**n*. All these strings consist only of digits and have the same length. Once Polycarpus needed to figure out Tarasov city phone code. He assumed that the phone code of the city is the longest common prefix of all phone numbers of his friends. In other words, it is the longest string *c* which is a prefix (the beginning) of each *s**i* for all *i* (1<=≤<=*i*<=≤<=*n*). Help Polycarpus determine the length of the city phone code. The input will be provided via standard input and looks as follows: The first line of the input contains an integer *n* (2<=≤<=*n*<=≤<=3·104) — the number of Polycarpus's friends. The following *n* lines contain strings *s*1,<=*s*2,<=...,<=*s**n* — the phone numbers of Polycarpus's friends. It is guaranteed that all strings consist only of digits and have the same length from 1 to 20, inclusive. It is also guaranteed that all strings are different. You should write the solution as standard output as follows: Print the number of digits in the city phone code. Here are example inputs and outputs for the problem: Example Input 1: 4 00209 00219 00999 00909 Example Output 1: 2 Example Input 2: 2 1 2 Example Output 2: 0 Example Input 3: 3 77012345678999999999 77012345678901234567 77012345678998765432 Example Output 3: 12 Now solve the problem by providing the code.
t=int(input()) l=[] for _ in range(t): s=input() l.append(s) m=l[0] c=0 for k in range(len(m)): flag=1 for i in range(1,len(l)): if l[i][k]!=m[k]: flag=0 break if flag==1: c+=1 else: break print(c)
vfc_84149
{ "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\n00209\n00219\n00999\n00909", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1\n2", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n77012345678999999999\n77012345678901234567\n77012345678998765432", "output": "12", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n4491183345\n4491184811\n4491162340\n4491233399\n4491449214", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n15424\n10953\n19176\n15514\n16284\n18680\n19305\n13816\n16168\n15924", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
923
Solve the following coding problem using the programming language python: Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift — a large snow maker. He plans to make some amount of snow every day. On day *i* he will make a pile of snow of volume *V**i* and put it in her garden. Each day, every pile will shrink a little due to melting. More precisely, when the temperature on a given day is *T**i*, each pile will reduce its volume by *T**i*. If this would reduce the volume of a pile to or below zero, it disappears forever. All snow piles are independent of each other. Note that the pile made on day *i* already loses part of its volume on the same day. In an extreme case, this may mean that there are no piles left at the end of a particular day. You are given the initial pile sizes and the temperature on each day. Determine the total volume of snow melted on each day. 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 days. The second line contains *N* integers *V*1,<=*V*2,<=...,<=*V**N* (0<=≤<=*V**i*<=≤<=109), where *V**i* is the initial size of a snow pile made on the day *i*. The third line contains *N* integers *T*1,<=*T*2,<=...,<=*T**N* (0<=≤<=*T**i*<=≤<=109), where *T**i* is the temperature on the day *i*. You should write the solution as standard output as follows: Output a single line with *N* integers, where the *i*-th integer represents the total volume of snow melted on day *i*. Here are example inputs and outputs for the problem: Example Input 1: 3 10 10 5 5 7 2 Example Output 1: 5 12 4 Example Input 2: 5 30 25 20 15 10 9 10 12 4 13 Example Output 2: 9 20 35 11 25 Now solve the problem by providing the code.
n = int(input()) vs = [int(x) for x in input().split()] ts = [int(x) for x in input().split()] sumt = 0 for i, t in enumerate(ts): vs[i]+=sumt sumt+=t vs.sort() tl, tr = 0, 0 il, ir = 0, 0 for ind, t in enumerate(ts): #check tl = tr tr += t while ir < n and vs[ir] <= tr: ir += 1 cur_sum = 0 while il < ir: cur_sum += vs[il]-tl il+=1 ## print(ir, tl, tr, cur_sum) cur_sum += t * ((n-ir) - (n-ind-1)) print(cur_sum, end=" ")
vfc_84153
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "3500" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n10 10 5\n5 7 2", "output": "5 12 4", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n30 25 20 15 10\n9 10 12 4 13", "output": "9 20 35 11 25", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n0 0 0 0\n1 2 3 4", "output": "0 0 0 0", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n11 39 16 34 25 3 12 11 31 16\n10 0 4 9 8 9 7 8 9 2", "output": "10 0 9 27 27 30 28 17 12 4", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
992
Solve the following coding problem using the programming language python: Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties: - In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to zero. - When all elements of the array become equal to zero, the array explodes. Nastya is always busy, so she wants to explode the array as fast as possible. Compute the minimum time in which the array can be exploded. The input will be provided via standard input and looks as follows: The first line contains a single integer *n* (1<=≤<=*n*<=≤<=105) — the size of the array. The second line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (<=-<=105<=≤<=*a**i*<=≤<=105) — the elements of the array. You should write the solution as standard output as follows: Print a single integer — the minimum number of seconds needed to make all elements of the array equal to zero. Here are example inputs and outputs for the problem: Example Input 1: 5 1 1 1 1 1 Example Output 1: 1 Example Input 2: 3 2 0 -1 Example Output 2: 2 Example Input 3: 4 5 -6 -5 1 Example Output 3: 4 Now solve the problem by providing the code.
n = int(input()) s = [int(i) for i in input().split() if int(i) != 0] print(len(set(s)))
vfc_84157
{ "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 1 1 1", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2 0 -1", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n5 -6 -5 1", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n0", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n21794 -79194", "output": "2", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
979
Solve the following coding problem using the programming language python: Katie, Kuro and Shiro are best friends. They have known each other since kindergarten. That's why they often share everything with each other and work together on some very hard problems. Today is Shiro's birthday. She really loves pizza so she wants to invite her friends to the pizza restaurant near her house to celebrate her birthday, including her best friends Katie and Kuro. She has ordered a very big round pizza, in order to serve her many friends. Exactly $n$ of Shiro's friends are here. That's why she has to divide the pizza into $n + 1$ slices (Shiro also needs to eat). She wants the slices to be exactly the same size and shape. If not, some of her friends will get mad and go home early, and the party will be over. Shiro is now hungry. She wants to cut the pizza with minimum of straight cuts. A cut is a straight segment, it might have ends inside or outside the pizza. But she is too lazy to pick up the calculator. As usual, she will ask Katie and Kuro for help. But they haven't come yet. Could you help Shiro with this problem? The input will be provided via standard input and looks as follows: A single line contains one non-negative integer $n$ ($0 \le n \leq 10^{18}$) — the number of Shiro's friends. The circular pizza has to be sliced into $n + 1$ pieces. You should write the solution as standard output as follows: A single integer — the number of straight cuts Shiro needs. Here are example inputs and outputs for the problem: Example Input 1: 3 Example Output 1: 2 Example Input 2: 4 Example Output 2: 5 Now solve the problem by providing the code.
x=int(input()) print( 0 if x==0 else (x+1)//2 if (x+1)%2==0 else x+1 ) # My code says who am i # red is love # love is not in logic
vfc_84165
{ "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": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "4", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "10", "output": "11", "type": "stdin_stdout" }, { "fn_name": null, "input": "10000000000", "output": "10000000001", "type": "stdin_stdout" }, { "fn_name": null, "input": "1234567891", "output": "617283946", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
3
Solve the following coding problem using the programming language python: This is yet another problem on regular bracket sequences. A bracket sequence is called regular, if by inserting "+" and "1" into it we get a correct mathematical expression. For example, sequences "(())()", "()" and "(()(()))" are regular, while ")(", "(()" and "(()))(" are not. You have a pattern of a bracket sequence that consists of characters "(", ")" and "?". You have to replace each character "?" with a bracket so, that you get a regular bracket sequence. For each character "?" the cost of its replacement with "(" and ")" is given. Among all the possible variants your should choose the cheapest. The input will be provided via standard input and looks as follows: The first line contains a non-empty pattern of even length, consisting of characters "(", ")" and "?". Its length doesn't exceed 5·104. Then there follow *m* lines, where *m* is the number of characters "?" in the pattern. Each line contains two integer numbers *a**i* and *b**i* (1<=≤<=*a**i*,<=<=*b**i*<=≤<=106), where *a**i* is the cost of replacing the *i*-th character "?" with an opening bracket, and *b**i* — with a closing one. You should write the solution as standard output as follows: Print the cost of the optimal regular bracket sequence in the first line, and the required sequence in the second. Print -1, if there is no answer. If the answer is not unique, print any of them. Here are example inputs and outputs for the problem: Example Input 1: (??) 1 2 2 8 Example Output 1: 4 ()() Now solve the problem by providing the code.
s=[] cost,pre,pq=0,0,[] from heapq import heappop, heappush for i, c in enumerate(input()): if c=='?': c=')' x,y=map(int,input().split()) cost+=y heappush(pq, (x-y,i)) s.append(c) if c=='(': pre+=1 else: if pre==0: if not pq: pre=-1 break x,y=heappop(pq) cost+=x s[y]='(' pre+=1 else: pre-=1 if pre: print(-1) else: print(cost) print("".join(s))
vfc_84169
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "(??)\n1 2\n2 8", "output": "4\n()()", "type": "stdin_stdout" }, { "fn_name": null, "input": "??\n1 1\n1 1", "output": "2\n()", "type": "stdin_stdout" }, { "fn_name": null, "input": "(???\n1 1\n1 1\n1 1", "output": "3\n(())", "type": "stdin_stdout" }, { "fn_name": null, "input": "(??)\n2 1\n1 1", "output": "2\n()()", "type": "stdin_stdout" }, { "fn_name": null, "input": "(???)?\n3 3\n3 1\n3 3\n2 3", "output": "10\n(()())", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
986
Solve the following coding problem using the programming language python: You are working as an analyst in a company working on a new system for big data storage. This system will store $n$ different objects. Each object should have a unique ID. To create the system, you choose the parameters of the system — integers $m \ge 1$ and $b_{1}, b_{2}, \ldots, b_{m}$. With these parameters an ID of some object in the system is an array of integers $[a_{1}, a_{2}, \ldots, a_{m}]$ where $1 \le a_{i} \le b_{i}$ holds for every $1 \le i \le m$. Developers say that production costs are proportional to $\sum_{i=1}^{m} b_{i}$. You are asked to choose parameters $m$ and $b_{i}$ so that the system will be able to assign unique IDs to $n$ different objects and production costs are minimized. Note that you don't have to use all available IDs. The input will be provided via standard input and looks as follows: In the only line of input there is one positive integer $n$. The length of the decimal representation of $n$ is no greater than $1.5 \cdot 10^{6}$. The integer does not contain leading zeros. You should write the solution as standard output as follows: Print one number — minimal value of $\sum_{i=1}^{m} b_{i}$. Here are example inputs and outputs for the problem: Example Input 1: 36 Example Output 1: 10 Example Input 2: 37 Example Output 2: 11 Example Input 3: 12345678901234567890123456789 Example Output 3: 177 Now solve the problem by providing the code.
import decimal from math import ceil, floor, inf, log n = input() if n=='1': print(1) exit() decimal.getcontext().prec = len(n)+6 decimal.getcontext().Emax = len(n)+6 log3 = log(10)*(len(n)-1)/log(3) pref = n if len(pref)>20: pref = pref[:20] pref = pref[0] + '.' + pref[1:] log3 += log(float(pref))/log(3) log3+=1e-8 full = max(0, floor(log3)) small=0 if full>=1 and log3-full<=log(2)/log(3)*2-1: small=2 full-=1 elif log3-full<=log(2)/log(3): small = 1 else: full+=1 n = decimal.Decimal(n) ans = full*3 + small*2 def check(f,s): global ans res = decimal.Decimal(3)**f * (2**s) if res>=n: ans = min(ans,f*3+s*2) if small==0 and full>=1: full-=1 small+=1 check(full,small) elif small==1 and full>=1: full-=1 small+=1 check(full,small) elif small==2: small-=2 full+=1 check(full,small) print(ans)
vfc_84173
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "36", "output": "10", "type": "stdin_stdout" }, { "fn_name": null, "input": "37", "output": "11", "type": "stdin_stdout" }, { "fn_name": null, "input": "12345678901234567890123456789", "output": "177", "type": "stdin_stdout" }, { "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": "3", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
230
Solve the following coding problem using the programming language python: Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all *n* dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the duel between two opponents the duel's outcome is determined by their strength. Initially, Kirito's strength equals *s*. If Kirito starts duelling with the *i*-th (1<=≤<=*i*<=≤<=*n*) dragon and Kirito's strength is not greater than the dragon's strength *x**i*, then Kirito loses the duel and dies. But if Kirito's strength is greater than the dragon's strength, then he defeats the dragon and gets a bonus strength increase by *y**i*. Kirito can fight the dragons in any order. Determine whether he can move on to the next level of the game, that is, defeat all dragons without a single loss. The input will be provided via standard input and looks as follows: The first line contains two space-separated integers *s* and *n* (1<=≤<=*s*<=≤<=104, 1<=≤<=*n*<=≤<=103). Then *n* lines follow: the *i*-th line contains space-separated integers *x**i* and *y**i* (1<=≤<=*x**i*<=≤<=104, 0<=≤<=*y**i*<=≤<=104) — the *i*-th dragon's strength and the bonus for defeating it. You should write the solution as standard output as follows: On a single line print "YES" (without the quotes), if Kirito can move on to the next level and print "NO" (without the quotes), if he can't. Here are example inputs and outputs for the problem: Example Input 1: 2 2 1 99 100 0 Example Output 1: YES Example Input 2: 10 1 100 100 Example Output 2: NO Now solve the problem by providing the code.
s, n = map(int, input().split()) data = [] for i in range(n): dragonStrength, gain = map(int, input().split()) data.append((dragonStrength, gain)) data = sorted(data) Won = True for i in data: if s > i[0]: s += i[1] else: print("NO") Won = False break if Won: print("YES")
vfc_84177
{ "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\n1 99\n100 0", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 1\n100 100", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "123 2\n78 10\n130 0", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "999 2\n1010 10\n67 89", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 5\n5 1\n2 1\n3 1\n1 1\n4 1", "output": "YES", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
332
Solve the following coding problem using the programming language python: Everybody knows that the Berland citizens are keen on health, especially students. Berland students are so tough that all they drink is orange juice! Yesterday one student, Vasya and his mates made some barbecue and they drank this healthy drink only. After they ran out of the first barrel of juice, they decided to play a simple game. All *n* people who came to the barbecue sat in a circle (thus each person received a unique index *b**i* from 0 to *n*<=-<=1). The person number 0 started the game (this time it was Vasya). All turns in the game were numbered by integers starting from 1. If the *j*-th turn was made by the person with index *b**i*, then this person acted like that: 1. he pointed at the person with index (*b**i*<=+<=1) *mod* *n* either with an elbow or with a nod (*x* *mod* *y* is the remainder after dividing *x* by *y*); 1. if *j*<=≥<=4 and the players who had turns number *j*<=-<=1, *j*<=-<=2, *j*<=-<=3, made during their turns the same moves as player *b**i* on the current turn, then he had drunk a glass of juice; 1. the turn went to person number (*b**i*<=+<=1) *mod* *n*. The person who was pointed on the last turn did not make any actions. The problem was, Vasya's drunk too much juice and can't remember the goal of the game. However, Vasya's got the recorded sequence of all the participants' actions (including himself). Now Vasya wants to find out the maximum amount of juice he could drink if he played optimally well (the other players' actions do not change). Help him. You can assume that in any scenario, there is enough juice for everybody. The input will be provided via standard input and looks as follows: The first line contains a single integer *n* (4<=≤<=*n*<=≤<=2000) — the number of participants in the game. The second line describes the actual game: the *i*-th character of this line equals 'a', if the participant who moved *i*-th pointed at the next person with his elbow, and 'b', if the participant pointed with a nod. The game continued for at least 1 and at most 2000 turns. You should write the solution as standard output as follows: Print a single integer — the number of glasses of juice Vasya could have drunk if he had played optimally well. Here are example inputs and outputs for the problem: Example Input 1: 4 abbba Example Output 1: 1 Example Input 2: 4 abbab Example Output 2: 0 Now solve the problem by providing the code.
import sys input = sys.stdin.readline n = int(input()) s = input()[:-1] c = 0 for i in range(len(s))[n::n]: if s[i-1] == s[i-2] == s[i-3]: c += 1 print(c)
vfc_84181
{ "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\nabbba", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\nabbab", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\naaa", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\naab", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\naabaabbba", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\naaaaaaaaaaaaaaaa", "output": "2", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
922
Solve the following coding problem using the programming language python: Imp is in a magic forest, where xorangles grow (wut?) A xorangle of order *n* is such a non-degenerate triangle, that lengths of its sides are integers not exceeding *n*, and the xor-sum of the lengths is equal to zero. Imp has to count the number of distinct xorangles of order *n* to get out of the forest. Formally, for a given integer *n* you have to find the number of such triples (*a*,<=*b*,<=*c*), that: - 1<=≤<=*a*<=≤<=*b*<=≤<=*c*<=≤<=*n*; - , where denotes the [bitwise xor](https://en.wikipedia.org/wiki/Bitwise_operation#XOR) of integers *x* and *y*. - (*a*,<=*b*,<=*c*) form a non-degenerate (with strictly positive area) triangle. The input will be provided via standard input and looks as follows: The only line contains a single integer *n* (1<=≤<=*n*<=≤<=2500). You should write the solution as standard output as follows: Print the number of xorangles of order *n*. Here are example inputs and outputs for the problem: Example Input 1: 6 Example Output 1: 1 Example Input 2: 10 Example Output 2: 2 Now solve the problem by providing the code.
n=int(input()) k=0 for a in range(1,n+1): for b in range(a,n+1): c=a^b if b<=c and c<=n and a+b>c and b+c>a and a+c>b: k+=1 print(k)
vfc_84185
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "10", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "3", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "4", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "5", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "2500", "output": "700393", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
983
Solve the following coding problem using the programming language python: You are given several queries. Each query consists of three integers $p$, $q$ and $b$. You need to answer whether the result of $p/q$ in notation with base $b$ is a finite fraction. A fraction in notation with base $b$ is finite if it contains finite number of numerals after the decimal point. It is also possible that a fraction has zero numerals after the decimal point. The input will be provided via standard input and looks as follows: The first line contains a single integer $n$ ($1 \le n \le 10^5$) — the number of queries. Next $n$ lines contain queries, one per line. Each line contains three integers $p$, $q$, and $b$ ($0 \le p \le 10^{18}$, $1 \le q \le 10^{18}$, $2 \le b \le 10^{18}$). All numbers are given in notation with base $10$. You should write the solution as standard output as follows: For each question, in a separate line, print Finite if the fraction is finite and Infinite otherwise. Here are example inputs and outputs for the problem: Example Input 1: 2 6 12 10 4 3 10 Example Output 1: Finite Infinite Example Input 2: 4 1 1 2 9 36 2 4 12 3 3 5 4 Example Output 2: Finite Finite Finite Infinite Now solve the problem by providing the code.
input() print('\n'.join(['Infinite' if p * pow(b, 99, q) % q else 'Finite' for p, q, b in map(lambda l: map(int, l.split()), __import__('sys').stdin.readlines())]))
vfc_84189
{ "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\n6 12 10\n4 3 10", "output": "Finite\nInfinite", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 1 2\n9 36 2\n4 12 3\n3 5 4", "output": "Finite\nFinite\nFinite\nInfinite", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n10 5 3\n1 7 10\n7 5 7\n4 4 9\n6 5 2\n6 7 5\n9 9 7\n7 5 5\n6 6 4\n10 8 2", "output": "Finite\nInfinite\nInfinite\nFinite\nInfinite\nInfinite\nFinite\nFinite\nFinite\nFinite", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
168
Solve the following coding problem using the programming language python: Some country is populated by wizards. They want to organize a demonstration. There are *n* people living in the city, *x* of them are the wizards who will surely go to the demonstration. Other city people (*n*<=-<=*x* people) do not support the wizards and aren't going to go to the demonstration. We know that the city administration will react only to the demonstration involving at least *y* percent of the city people. Having considered the matter, the wizards decided to create clone puppets which can substitute the city people on the demonstration. So all in all, the demonstration will involve only the wizards and their puppets. The city administration cannot tell the difference between a puppet and a person, so, as they calculate the percentage, the administration will consider the city to be consisting of only *n* people and not containing any clone puppets. Help the wizards and find the minimum number of clones to create to that the demonstration had no less than *y* percent of the city people. The input will be provided via standard input and looks as follows: The first line contains three space-separated integers, *n*, *x*, *y* (1<=≤<=*n*,<=*x*,<=*y*<=≤<=104,<=*x*<=≤<=*n*) — the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly. Please note that *y* can exceed 100 percent, that is, the administration wants to see on a demonstration more people that actually live in the city (<=&gt;<=*n*). You should write the solution as standard output as follows: Print a single integer — the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than *y* percent of *n* (the real total city population). Here are example inputs and outputs for the problem: Example Input 1: 10 1 14 Example Output 1: 1 Example Input 2: 20 10 50 Example Output 2: 0 Example Input 3: 1000 352 146 Example Output 3: 1108 Now solve the problem by providing the code.
import math n,x,y=map(int,input().split()) k=math.ceil(y*n/100) if k>x: print(k-x) else: print(0)
vfc_84193
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 1 14", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "20 10 50", "output": "0", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
374
Solve the following coding problem using the programming language python: Inna loves digit 9 very much. That's why she asked Dima to write a small number consisting of nines. But Dima must have misunderstood her and he wrote a very large number *a*, consisting of digits from 1 to 9. Inna wants to slightly alter the number Dima wrote so that in the end the number contained as many digits nine as possible. In one move, Inna can choose two adjacent digits in a number which sum equals 9 and replace them by a single digit 9. For instance, Inna can alter number 14545181 like this: 14545181<=→<=1945181<=→<=194519<=→<=19919. Also, she can use this method to transform number 14545181 into number 19991. Inna will not transform it into 149591 as she can get numbers 19919 and 19991 which contain more digits nine. Dima is a programmer so he wants to find out how many distinct numbers containing as many digits nine as possible Inna can get from the written number. Help him with this challenging task. The input will be provided via standard input and looks as follows: The first line of the input contains integer *a* (1<=≤<=*a*<=≤<=10100000). Number *a* doesn't have any zeroes. You should write the solution as standard output as follows: In a single line print a single integer — the answer to the problem. It is guaranteed that the answer to the problem doesn't exceed 263<=-<=1. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. Here are example inputs and outputs for the problem: Example Input 1: 369727 Example Output 1: 2 Example Input 2: 123456789987654321 Example Output 2: 1 Example Input 3: 1 Example Output 3: 1 Now solve the problem by providing the code.
R=lambda:map(int,input().split()) import math as m s=input() a=[] f='' for i in range(1,len(s)): if(int(s[i])+int(s[i-1])==9): f+=s[i-1] else: f+=s[i-1] if(len(f)>=2): if((f[0]=='0' and f[1]=='9') or (f[0]=='9' and f[1]=='0')): a.append(len(f)) elif(len(f)%2==0): a.append(1) else: a.append((len(f)+1)//2) f='' f+=s[-1] if(len(f)>=2): if((f[0]=='0' and f[1]=='9') or (f[0]=='9' and f[1]=='0')): a.append(len(f)) elif(len(f)%2==0): a.append(1) else: a.append((len(f)+1)//2) ans=1 for i in a: ans=ans*i print(ans)
vfc_84197
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "369727", "output": "2", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
79
Solve the following coding problem using the programming language python: After Fox Ciel won an onsite round of a programming contest, she took a bus to return to her castle. The fee of the bus was 220 yen. She met Rabbit Hanako in the bus. They decided to play the following game because they got bored in the bus. - Initially, there is a pile that contains *x* 100-yen coins and *y* 10-yen coins. - They take turns alternatively. Ciel takes the first turn. - In each turn, they must take exactly 220 yen from the pile. In Ciel's turn, if there are multiple ways to take 220 yen, she will choose the way that contains the maximal number of 100-yen coins. In Hanako's turn, if there are multiple ways to take 220 yen, she will choose the way that contains the maximal number of 10-yen coins. - If Ciel or Hanako can't take exactly 220 yen from the pile, she loses. Determine the winner of the game. The input will be provided via standard input and looks as follows: The first line contains two integers *x* (0<=≤<=*x*<=≤<=106) and *y* (0<=≤<=*y*<=≤<=106), separated by a single space. You should write the solution as standard output as follows: If Ciel wins, print "Ciel". Otherwise, print "Hanako". Here are example inputs and outputs for the problem: Example Input 1: 2 2 Example Output 1: Ciel Example Input 2: 3 22 Example Output 2: Hanako Now solve the problem by providing the code.
import sys import string from collections import Counter, defaultdict from math import fsum, sqrt, gcd, ceil, factorial from operator import add from itertools import accumulate inf = float('inf') # input = sys.stdin.readline flush = lambda : sys.stdout.flush comb = lambda x , y : (factorial(x) // factorial(y)) // factorial(x - y) #inputs # ip = lambda : input().rstrip() ip = lambda : input() ii = lambda : int(input()) r = lambda : map(int, input().split()) rr = lambda : list(r()) a , b =r() c = 1 while a or b: x = 220 while a and x>=100: a-=1 x-=100 while b and x: b-=1 x-=10 if c%2==0: if b>9: a+=1 b-=10 if b>9: a+=1 b-=10 if x: print("Hanako" if c%2 else "Ciel") exit() c+=1 print("Hanako" if c%2 else "Ciel")
vfc_84201
{ "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": "Ciel", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
774
Solve the following coding problem using the programming language python: Stepan has the newest electronic device with a display. Different digits can be shown on it. Each digit is shown on a seven-section indicator like it is shown on the picture below. So, for example, to show the digit 3 on the display, 5 sections must be highlighted; and for the digit 6, 6 sections must be highlighted. The battery of the newest device allows to highlight at most *n* sections on the display. Stepan wants to know the maximum possible integer number which can be shown on the display of his newest device. Your task is to determine this number. Note that this number must not contain leading zeros. Assume that the size of the display is enough to show any integer. The input will be provided via standard input and looks as follows: The first line contains the integer *n* (2<=≤<=*n*<=≤<=100<=000) — the maximum number of sections which can be highlighted on the display. You should write the solution as standard output as follows: Print the maximum integer which can be shown on the display of Stepan's newest device. Here are example inputs and outputs for the problem: Example Input 1: 2 Example Output 1: 1 Example Input 2: 3 Example Output 2: 7 Now solve the problem by providing the code.
a = int(input()) if ( a % 2 ): print('7', end='') a -= 3 while (a > 0) : a -= 2 print('1', end='')
vfc_84205
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "3000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "3", "output": "7", "type": "stdin_stdout" }, { "fn_name": null, "input": "4", "output": "11", "type": "stdin_stdout" }, { "fn_name": null, "input": "5", "output": "71", "type": "stdin_stdout" }, { "fn_name": null, "input": "6", "output": "111", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
24
Solve the following coding problem using the programming language python: Nowadays the one-way traffic is introduced all over the world in order to improve driving safety and reduce traffic jams. The government of Berland decided to keep up with new trends. Formerly all *n* cities of Berland were connected by *n* two-way roads in the ring, i. e. each city was connected directly to exactly two other cities, and from each city it was possible to get to any other city. Government of Berland introduced one-way traffic on all *n* roads, but it soon became clear that it's impossible to get from some of the cities to some others. Now for each road is known in which direction the traffic is directed at it, and the cost of redirecting the traffic. What is the smallest amount of money the government should spend on the redirecting of roads so that from every city you can get to any other? The input will be provided via standard input and looks as follows: The first line contains integer *n* (3<=≤<=*n*<=≤<=100) — amount of cities (and roads) in Berland. Next *n* lines contain description of roads. Each road is described by three integers *a**i*, *b**i*, *c**i* (1<=≤<=*a**i*,<=*b**i*<=≤<=*n*,<=*a**i*<=≠<=*b**i*,<=1<=≤<=*c**i*<=≤<=100) — road is directed from city *a**i* to city *b**i*, redirecting the traffic costs *c**i*. You should write the solution as standard output as follows: Output single integer — the smallest amount of money the government should spend on the redirecting of roads so that from every city you can get to any other. Here are example inputs and outputs for the problem: Example Input 1: 3 1 3 1 1 2 1 3 2 1 Example Output 1: 1 Example Input 2: 3 1 3 1 1 2 5 3 2 1 Example Output 2: 2 Example Input 3: 6 1 5 4 5 3 8 2 4 15 1 6 16 2 3 23 4 6 42 Example Output 3: 39 Example Input 4: 4 1 2 9 2 3 8 3 4 7 4 1 5 Example Output 4: 0 Now solve the problem by providing the code.
n = int(input()) road = [map(int,input().split()) for i in range(n)] graf = [[] for i in range(n + 1)] s = 0 for a,b,c in road: graf[a].append((b,0)) graf[b].append((a,c)) s += c vis = [0] * (n + 1) def dfs(u,p): d = 0 for v,c in graf[u]: if v != p and vis[v] == 0: vis[v] = 1 d += dfs(v,u) + c return d d = dfs(1,-1) print(min(d,s - d))
vfc_84209
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1500" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 3 1\n1 2 1\n3 2 1", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
914
Solve the following coding problem using the programming language python: Edogawa Conan got tired of solving cases, and invited his friend, Professor Agasa, over. They decided to play a game of cards. Conan has *n* cards, and the *i*-th card has a number *a**i* written on it. They take turns playing, starting with Conan. In each turn, the player chooses a card and removes it. Also, he removes all cards having a number strictly lesser than the number on the chosen card. Formally, if the player chooses the *i*-th card, he removes that card and removes the *j*-th card for all *j* such that *a**j*<=&lt;<=*a**i*. A player loses if he cannot make a move on his turn, that is, he loses if there are no cards left. Predict the outcome of the game, assuming both players play optimally. The input will be provided via standard input and looks as follows: The first line contains an integer *n* (1<=≤<=*n*<=≤<=105) — the number of cards Conan has. The next line contains *n* integers *a*1,<=*a*2,<=...,<=*a**n* (1<=≤<=*a**i*<=≤<=105), where *a**i* is the number on the *i*-th card. You should write the solution as standard output as follows: If Conan wins, print "Conan" (without quotes), otherwise print "Agasa" (without quotes). Here are example inputs and outputs for the problem: Example Input 1: 3 4 5 7 Example Output 1: Conan Example Input 2: 2 1 1 Example Output 2: Agasa Now solve the problem by providing the code.
input() d={} c=0 for i in input().split(): d[i] = d.get(i,0)+1;c+=d[i]%2*2-1 print(["Conan","Agasa"][not c])
vfc_84213
{ "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\n4 5 7", "output": "Conan", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 1", "output": "Agasa", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n38282 53699 38282 38282 38282 38282 38282 38282 38282 38282", "output": "Conan", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n50165 50165 50165 50165 50165 50165 50165 50165 50165 50165", "output": "Agasa", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n83176 83176 83176 23495 83176 8196 83176 23495 83176 83176", "output": "Conan", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n32093 36846 32093 32093 36846 36846 36846 36846 36846 36846", "output": "Conan", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
633
Solve the following coding problem using the programming language python: Mr. Santa asks all the great programmers of the world to solve a trivial problem. He gives them an integer *m* and asks for the number of positive integers *n*, such that the factorial of *n* ends with exactly *m* zeroes. Are you among those great programmers who can solve this problem? The input will be provided via standard input and looks as follows: The only line of input contains an integer *m* (1<=≤<=*m*<=≤<=100<=000) — the required number of trailing zeroes in factorial. You should write the solution as standard output as follows: First print *k* — the number of values of *n* such that the factorial of *n* ends with *m* zeroes. Then print these *k* integers in increasing order. Here are example inputs and outputs for the problem: Example Input 1: 1 Example Output 1: 5 5 6 7 8 9 Example Input 2: 5 Example Output 2: 0 Now solve the problem by providing the code.
#n,m,k = map(int, input().strip().split(' ')) m=int(input()) #a = list(map(int, input().strip().split(' '))) l=[1] i=1 l1=[i] l2=0 #building the array while(i<100000): i+=1 l2=5*i c=0 while(l2%5==0): l2=l2//5 c+=1 l.append(l[-1]+c) l1.append(i) #print(l) if m not in l: print(0) else: print(5) ind=l.index(m) i1=5*l1[ind] print(i1,i1+1,i1+2,i1+3,i1+4,end=" ")
vfc_84217
{ "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": "5\n5 6 7 8 9 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "5", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "2", "output": "5\n10 11 12 13 14 ", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
794
Solve the following coding problem using the programming language python: Igor the analyst has adopted *n* little bunnies. As we all know, bunnies love carrots. Thus, Igor has bought a carrot to be shared between his bunnies. Igor wants to treat all the bunnies equally, and thus he wants to cut the carrot into *n* pieces of equal area. Formally, the carrot can be viewed as an isosceles triangle with base length equal to 1 and height equal to *h*. Igor wants to make *n*<=-<=1 cuts parallel to the base to cut the carrot into *n* pieces. He wants to make sure that all *n* pieces have the same area. Can you help Igor determine where to cut the carrot so that each piece have equal area? The input will be provided via standard input and looks as follows: The first and only line of input contains two space-separated integers, *n* and *h* (2<=≤<=*n*<=≤<=1000, 1<=≤<=*h*<=≤<=105). You should write the solution as standard output as follows: The output should contain *n*<=-<=1 real numbers *x*1,<=*x*2,<=...,<=*x**n*<=-<=1. The number *x**i* denotes that the *i*-th cut must be made *x**i* units away from the apex of the carrot. In addition, 0<=&lt;<=*x*1<=&lt;<=*x*2<=&lt;<=...<=&lt;<=*x**n*<=-<=1<=&lt;<=*h* must hold. Your output will be considered correct if absolute or relative error of every number in your output doesn't exceed 10<=-<=6. Formally, let your answer be *a*, and the jury's answer be *b*. Your answer is considered correct if . Here are example inputs and outputs for the problem: Example Input 1: 3 2 Example Output 1: 1.154700538379 1.632993161855 Example Input 2: 2 100000 Example Output 2: 70710.678118654752 Now solve the problem by providing the code.
from math import sqrt n, h = map(int, input().split()) for i in range(1, n): print(h*sqrt(i/n), end=' ' if i +1 < n else '\n')
vfc_84221
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2", "output": "1.154700538379 1.632993161855", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 100000", "output": "70710.678118654752", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000 100000", "output": "3162.277660168379 4472.135954999579 5477.225575051661 6324.555320336759 7071.067811865475 7745.966692414834 8366.600265340755 8944.271909999159 9486.832980505138 10000.000000000000 10488.088481701515 10954.451150103322 11401.754250991380 11832.159566199232 12247.448713915890 12649.110640673517 13038.404810405297 13416.407864998738 13784.048752090222 14142.135623730950 14491.376746189439 14832.396974191326 15165.750888103101 15491.933384829668 15811.388300841897 16124.515496597099 16431.676725154983 16733.2...", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1", "output": "0.707106781187", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000 1", "output": "0.031622776602 0.044721359550 0.054772255751 0.063245553203 0.070710678119 0.077459666924 0.083666002653 0.089442719100 0.094868329805 0.100000000000 0.104880884817 0.109544511501 0.114017542510 0.118321595662 0.122474487139 0.126491106407 0.130384048104 0.134164078650 0.137840487521 0.141421356237 0.144913767462 0.148323969742 0.151657508881 0.154919333848 0.158113883008 0.161245154966 0.164316767252 0.167332005307 0.170293863659 0.173205080757 0.176068168617 0.178885438200 0.181659021246 0.184390889146 0...", "type": "stdin_stdout" } ] }