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 t...
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 b...
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, ...
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 fo...
# -*- 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 ho...
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 ...
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 ...
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, th...
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 Calvi...
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\nRL...
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. Acc...
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,'...
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 imp...
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]] f...
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": ...
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 c...
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 ...
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" }...
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...
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...
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_...
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...
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 a...
# 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...
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", "ou...
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 ...
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 ...
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...
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,count...
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 exper...
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, "inpu...
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 t...
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 ...
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 num...
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}") ...
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, ...
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 bu...
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 ...
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": ...
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 an...
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...
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": nul...
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 ...
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 changi...
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 gi...
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].re...
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 universi...
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, "...
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 r...
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", ...
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*<=+<=...
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: ...
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",...
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 ...
# 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...
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_stdou...
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 ...
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": "25165621512...
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 t...
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 ...
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 in...
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, "i...
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. Polyca...
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(...
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 t...
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) positio...
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...
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...
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 c...
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", ...
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...
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, ...
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 nee...
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 ...
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 ...
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 ...
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\nO...
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...
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", ...
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 mi...
# 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...
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", "o...
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...
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...
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_nam...
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 *...
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(n...
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 verti...
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) ...
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......**...
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 pl...
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 ...
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, 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 t...
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...
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...
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...
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 l...
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.set...
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 paint...
#!/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(...
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...
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*<=+<=...
#!/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 l...
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 number...
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...
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, ...
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...
#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 ...
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_na...
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,<...
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: ...
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" }, { ...
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. Determin...
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"...
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...
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 an...
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" }, ...
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 seq...
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 -...
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*...
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 fo...
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, "inpu...
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 ...
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 cheese...
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\nparmesa...
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 se...
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, ...
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 b...
#!/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 diffic...
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*<=-<=...
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":...
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* ...
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"...
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 pie...
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(tem...
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...
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) f...
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 backw...
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": "kitay...
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 t...
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", "outp...
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 gam...
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] == '...
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_nam...
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 e...
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 += ...
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 examp...
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"...
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 wi...
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): ...
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, "inpu...
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 produc...
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", ...
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 b...
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,...
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 sp...
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.c...
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, "...
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 want...
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", ...
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, h...
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): ...
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", ...
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 catche...
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: ...
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...
# 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", ...
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...
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_...
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...
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", "o...
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. ...
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\n10...
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...
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, ...
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 ...
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 ...
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" }, ...
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 (possi...
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": "...
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...
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"...
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, whil...
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]=...
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, ...
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...
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(floa...
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": "123456789012345...
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 opp...
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...
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, ...
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 drin...
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\naa...
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 num...
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"...
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 ...
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", "...
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...
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 n...
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)) ...
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. - ...
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) // factoria...
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...
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":...
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-...
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 += 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 Co...
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": ...
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 gre...
#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 no...
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", ...
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* pie...
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" }, { ...