id
stringlengths
14
117
description
stringlengths
29
13k
code
stringlengths
10
49.8k
test_samples
dict
source
class label
3 classes
prompt
stringlengths
391
104k
328_B. Sheldon and Ice Pieces_38253
Do you remember how Kai constructed the word "eternity" using pieces of ice as components? Little Sheldon plays with pieces of ice, each piece has exactly one digit between 0 and 9. He wants to construct his favourite number t. He realized that digits 6 and 9 are very similar, so he can rotate piece of ice with 6 to u...
def c(a, b): a = a.replace('6', '9') a = a.replace('2', '5') b = b.replace('6', '9') b = b.replace('2', '5') n = 10000 for i in '01345789': t = a.count(i) if t != 0: n = min(n, b.count(i)//t) return n a = input() b = input() print(c(a, b))
{ "input": [ "42\n23454\n", "169\n12118999\n", "5518\n9827108589585181118358352282425981568508825302611217254345831149357236227288533838583629451589201341265988858338548185158221291825821019993179835186961954871454\n", "533\n355233333332\n", "9\n666969\n", "2559\n5252555622565626\n", "2569...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Do you remember how Kai constructed the word "eternity" using pieces of ice as components? Little Sheldon plays with pieces of ice, each piece has exactly one digit between 0 and 9. ...
34_C. Page Numbers_38257
«Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, like many other text editors, should be able to print out multipage documents. A user keys a sequence of the document page numbers that he wants to print out (separates them with a comma, without spaces). Your task is to w...
A=[int(num) for num in input().split(',')] s_a=sorted(set(A)) prev=None string="" count=0 for i in s_a: if prev is None: prev=i string+=str(prev) count+=1 else: if i-(prev+count)==0: count+=1 else: if count>1: string+='-'+str(prev+c...
{ "input": [ "30,20,10\n", "3,2,1\n", "1,2,3,1,1,2,6,6,2\n", "511,32\n", "684,698,429,694,956,812,594,170,937,764\n", "744,359,230,586,944,442\n", "37\n", "996,999,998,984,989,1000,996,993,1000,983,992,999,999,1000,979,992,987,1000,996,1000,1000,989,981,996,995,999,999,989,999,1000\n",...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: «Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, like many other text editors, should be able to print out multipage documents. A user ...
396_A. On Number of Decompositions into Multipliers_38263
You are given an integer m as a product of integers a1, a2, ... an <image>. Your task is to find the number of distinct decompositions of number m into the product of n ordered positive integers. Decomposition into n products, given in the input, must also be considered in the answer. As the answer can be very large, ...
# Made By Mostafa_Khaled bot = True Mod = 1000000007 MAX = 33000 n = int( input() ) A = list( map( int, input().split() ) ) B = [0] * MAX bePrime = [0] * MAX; primNum = [] C = [] fac=[1] for j in range(1, MAX): fac.append( fac[-1] * j % Mod ) def calc( M, N ): return fac[M] * pow( fac[N] * f...
{ "input": [ "1\n15\n", "3\n1 1 2\n", "2\n5 7\n", "3\n8 10 8\n", "1\n536870912\n", "1\n111546435\n", "10\n2097152 67108864 65536 262144 262144 131072 8388608 536870912 65536 2097152\n", "23\n77 12 25 7 44 75 80 92 49 77 56 93 59 45 45 39 86 83 99 91 4 70 83\n", "50\n675 25000 2025 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given an integer m as a product of integers a1, a2, ... an <image>. Your task is to find the number of distinct decompositions of number m into the product of n ordered positi...
444_E. DZY Loves Planting_38268
DZY loves planting, and he enjoys solving tree problems. DZY has a weighted tree (connected undirected graph without cycles) containing n nodes (they are numbered from 1 to n). He defines the function g(x, y) (1 ≤ x, y ≤ n) as the longest edge in the shortest path between nodes x and y. Specially g(z, z) = 0 for every...
n = int(input()) edges = [[int(x) for x in input().split()] for i in range(n-1)] edges = sorted(edges) use_count = [0]+[int(input()) for i in range(n)] lo,hi = 0,10000 def getpar(par,u): if par[par[u]] == par[u]: return par[u] par[u] = getpar(par,par[u]) return par[u] def unite(par,sz,use,u,v): ...
{ "input": [ "4\n1 2 1\n2 3 2\n3 4 3\n1\n1\n1\n1\n", "4\n1 2 1\n2 3 2\n3 4 3\n4\n4\n4\n4\n", "1\n1\n", "10\n2 1 559\n3 1 5707\n4 2 9790\n5 3 1591\n6 1 7113\n7 6 2413\n8 6 3006\n9 4 1935\n10 6 5954\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n", "10\n2 1 8760\n3 1 3705\n4 1 1862\n5 2 7332\n6 3 7015\n7 5 4866\n8 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: DZY loves planting, and he enjoys solving tree problems. DZY has a weighted tree (connected undirected graph without cycles) containing n nodes (they are numbered from 1 to n). He de...
467_A. George and Accommodation_38272
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory. George and Alex want to live in the same room. The dormitory has n rooms in total. At the moment the i-th room has pi people living...
c = 0 for _ in range(int(input())): n = [int(x) for x in input().split()] n,m = n[0],n[1] if m - n >= 2: c += 1 print(c)
{ "input": [ "3\n1 1\n2 2\n3 3\n", "3\n1 10\n0 10\n10 10\n", "17\n68 69\n47 48\n30 31\n52 54\n41 43\n33 35\n38 40\n56 58\n45 46\n92 93\n73 74\n61 63\n65 66\n37 39\n67 68\n77 78\n28 30\n", "26\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormito...
48_D. Permutations_38276
A permutation is a sequence of integers from 1 to n of length n containing each number exactly once. For example, (1), (4, 3, 5, 1, 2), (3, 2, 1) are permutations, and (1, 1), (4, 3, 1), (2, 3, 4) are not. There are many tasks on permutations. Today you are going to solve one of them. Let’s imagine that somebody took...
def fail(): print(-1) import sys sys.exit() n = int(input()) count = (n + 1) * [ 0 ] assign = n * [ None ] for i, x in enumerate(map(int, input().split())): if x > n: fail() count[x] += 1 assign[i] = count[x] for i in range(2, n): if count[i - 1] < count[i]: fail() print(count[1]) print(' '.joi...
{ "input": [ "9\n1 2 3 1 2 1 4 2 5\n", "4\n4 3 2 1\n", "4\n1 2 2 3\n", "2\n1000 1\n", "5\n2 2 1 1 3\n", "100\n12 18 1 1 14 23 1 1 22 5 7 9 7 1 1 1 3 8 4 2 1 6 9 1 3 2 11 1 11 2 3 2 1 4 2 7 1 16 3 4 2 13 3 1 5 11 2 10 20 24 3 21 5 2 6 2 1 10 10 5 17 1 1 4 19 8 5 5 3 9 4 2 7 8 10 4 9 1 3 3 9 7 6...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: A permutation is a sequence of integers from 1 to n of length n containing each number exactly once. For example, (1), (4, 3, 5, 1, 2), (3, 2, 1) are permutations, and (1, 1), (4, 3, ...
53_B. Blog Photo_38282
One popular blog site edits the uploaded photos like this. It cuts a rectangular area out of them so that the ratio of height to width (i.e. the height / width quotient) can vary from 0.8 to 1.25 inclusively. Besides, at least one side of the cut area should have a size, equal to some power of number 2 (2x for some int...
from math import ceil,floor l = [] for i in range(39): l.append(2**i) h,w = map(int,input().split()) h1 = 0 w1 = 0 maxi = 0 for i in l: if i<=w: a = ceil(i*0.8) b = floor(i*1.25) if a<=h<=b: if i*h>=maxi: maxi = i * h h1 = h ...
{ "input": [ "2 1\n", "2 2\n", "5 5\n", "15 13\n", "9 10\n", "47 46\n", "49829224 49889315\n", "483242 484564\n", "644590722 593296648\n", "971840165 826141527\n", "49728622 49605627\n", "99692141 99232337\n", "48298903 49928606\n", "792322809 775058858\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: One popular blog site edits the uploaded photos like this. It cuts a rectangular area out of them so that the ratio of height to width (i.e. the height / width quotient) can vary from...
567_D. One-Dimensional Battle Ships_38286
Alice and Bob love playing one-dimensional battle ships. They play on the field in the form of a line consisting of n square cells (that is, on a 1 × n table). At the beginning of the game Alice puts k ships on the field without telling their positions to Bob. Each ship looks as a 1 × a rectangle (that is, it occupies...
import sys def minp(): return sys.stdin.readline().strip() def mint(): return int(minp()) def mints(): return map(int, minp().split()) def solve(): n, k, a = mints() a += 1 m = mint() x = list(mints()) l = 0 r = m + 1 while r - l > 1: c = (l + r) // 2 b = x[:c] b.sort() last = 0 cnt = 0 for i ...
{ "input": [ "11 3 3\n5\n4 8 6 1 11\n", "5 1 3\n1\n3\n", "5 1 3\n2\n1 5\n", "200000 1 199999\n2\n2 200000\n", "5000 1660 2\n20\n1 100 18 102 300 81 19 25 44 88 1337 4999 1054 1203 91 16 164 914 1419 1487\n", "50 1 1\n50\n1 13 21 37 30 48 23 19 6 49 36 14 9 24 44 10 41 28 20 2 15 11 45 3 25 33 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Alice and Bob love playing one-dimensional battle ships. They play on the field in the form of a line consisting of n square cells (that is, on a 1 × n table). At the beginning of th...
610_C. Harmony Analysis_38291
The semester is already ending, so Danil made an effort and decided to visit a lesson on harmony analysis to know how does the professor look like, at least. Danil was very bored on this lesson until the teacher gave the group a simple task: find 4 vectors in 4-dimensional space, such that every coordinate of every vec...
p = [[0]] for i in range(int(input())): p = [t + t for t in p] + [[1 - q for q in t] + t for t in p] for t in p: print(''.join('+*'[q] for q in t))
{ "input": [ "2\n", "2\n", "4\n", "1\n", "5\n", "7\n", "8\n", "6\n", "0\n", "3\n" ], "output": [ "++++\n+*+*\n++**\n+**+\n", "++++\n+*+*\n++**\n+**+\n", "++++++++++++++++\n+*+*+*+*+*+*+*+*\n++**++**++**++**\n+**++**++**++**+\n++++****++++****\n+*+**+*++*+**+*+\n...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: The semester is already ending, so Danil made an effort and decided to visit a lesson on harmony analysis to know how does the professor look like, at least. Danil was very bored on t...
630_M. Turn_38295
Vasya started working in a machine vision company of IT City. Vasya's team creates software and hardware for identification of people by their face. One of the project's know-how is a camera rotating around its optical axis on shooting. People see an eye-catching gadget — a rotating camera — come up to it to see it be...
import math, re, sys, string, operator, functools, fractions, collections sys.setrecursionlimit(10**7) dX= [-1, 1, 0, 0,-1, 1,-1, 1] dY= [ 0, 0,-1, 1, 1,-1,-1, 1] RI=lambda x=' ': list(map(int,input().split(x))) RS=lambda x=' ': input().rstrip().split(x) mod=int(1e9+7) eps=1e-6 #########################################...
{ "input": [ "-60\n", "60\n", "6678504591813508\n", "44\n", "225\n", "-45\n", "-358\n", "46\n", "-999999999999999415\n", "-999999999999999639\n", "-44\n", "-999999999999999325\n", "999999999999999326\n", "316\n", "359\n", "999999999999999416\n", "-13...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Vasya started working in a machine vision company of IT City. Vasya's team creates software and hardware for identification of people by their face. One of the project's know-how is ...
659_E. New Reform_38299
Berland has n cities connected by m bidirectional roads. No road connects a city to itself, and each pair of cities is connected by no more than one road. It is not guaranteed that you can get from any city to any other one, using only the existing roads. The President of Berland decided to make changes to the road sy...
import sys from math import sqrt, gcd, ceil, log # from bisect import bisect, bisect_left from collections import defaultdict, Counter, deque # from heapq import heapify, heappush, heappop input = sys.stdin.readline read = lambda: list(map(int, input().strip().split())) sys.setrecursionlimit(200000) def main(): n,...
{ "input": [ "5 5\n2 1\n1 3\n2 3\n2 5\n4 3\n", "4 3\n2 1\n1 3\n4 3\n", "6 5\n1 2\n2 3\n4 5\n4 6\n5 6\n", "10 45\n3 5\n2 3\n4 8\n2 5\n6 8\n5 7\n2 1\n3 7\n5 10\n6 1\n9 4\n3 6\n9 10\n6 7\n1 7\n7 9\n6 9\n9 3\n4 2\n2 6\n5 6\n5 8\n3 4\n10 8\n7 8\n4 6\n9 1\n5 9\n7 4\n1 10\n9 2\n2 8\n6 10\n9 8\n1 5\n7 2\n10 3...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Berland has n cities connected by m bidirectional roads. No road connects a city to itself, and each pair of cities is connected by no more than one road. It is not guaranteed that yo...
682_B. Alyona and Mex_38303
Someone gave Alyona an array containing n positive integers a1, a2, ..., an. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular, she may not ...
import sys n = int(input()) arr = list(map(int,input().split())) arr.sort() ans = 1 for i in range(1,n+1): if arr[i-1]>=ans: ans+=1 print(ans)
{ "input": [ "5\n1 3 3 3 6\n", "2\n2 1\n", "4\n1 2 2 3\n", "4\n1 4 1 1\n", "2\n3 3\n", "4\n1 2 1 2\n", "3\n3 3 1\n", "3\n2 4 1\n", "2\n1 1\n", "3\n2 2 2\n", "4\n2 2 2 1\n", "4\n2 2 2 3\n", "7\n1 2 2 2 5 5 1\n", "4\n1 4 4 3\n", "4\n2 2 3 2\n", "4\n2 4 1 2...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Someone gave Alyona an array containing n positive integers a1, a2, ..., an. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positi...
705_A. Hulk_38307
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings. Hulk likes the Inception so much, and like that his feelings are complicated. They have n layers. The first layer is hate, seco...
x = int(input()) feelings = '' for _ in range(x): if _ == x - 1: if _ % 2 != 0: feelings = feelings + 'I love it ' else: feelings = feelings + 'I hate it ' else: if _ % 2 != 0: feelings = feelings + 'I love that ' else: feelings = feelings + 'I hate that ' print(feelings)
{ "input": [ "2\n", "1\n", "3\n", "18\n", "57\n", "100\n", "86\n", "34\n", "82\n", "99\n", "81\n", "19\n", "10\n", "98\n", "5\n", "4\n", "85\n", "76\n", "77\n", "33\n", "12\n", "41\n", "60\n", "24\n", "27\n", "88\n...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his f...
727_D. T-shirts Distribution_38311
The organizers of a programming contest have decided to present t-shirts to participants. There are six different t-shirts sizes in this problem: S, M, L, XL, XXL, XXXL (sizes are listed in increasing order). The t-shirts are already prepared. For each size from S to XXXL you are given the number of t-shirts of this si...
from math import * from sys import * def conv(s): if s=="S" or s=="S\n": return 1 if s=="M" or s=="M\n": return 2 if s=="L" or s=="L\n": return 3 if s=="XL" or s=="XL\n": return 4 if s=="XXL" or s=="XXL\n": return 5 return 6 def uncon(x): if x==1: return "S" if x==2: return "M" if x==3: retu...
{ "input": [ "0 1 0 1 1 0\n3\nXL\nS,M\nXL,XXL\n", "1 1 2 0 1 1\n5\nS\nM\nS,M\nXXL,XXXL\nXL,XXL\n", "5 1 5 2 4 3\n20\nL,XL\nS,M\nL,XL\nXXL,XXXL\nS,M\nS,M\nXL,XXL\nL,XL\nS,M\nL,XL\nS,M\nM,L\nXXL,XXXL\nXXL,XXXL\nL\nXXL,XXXL\nXL,XXL\nM,L\nS,M\nXXL\n", "1 2 4 4 1 1\n10\nXL\nXL\nS,M\nL\nM,L\nL\nS,M\nM\nXL,X...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: The organizers of a programming contest have decided to present t-shirts to participants. There are six different t-shirts sizes in this problem: S, M, L, XL, XXL, XXXL (sizes are lis...
771_D. Bear and Company_38317
Bear Limak prepares problems for a programming competition. Of course, it would be unprofessional to mention the sponsor name in the statement. Limak takes it seriously and he is going to change some words. To make it still possible to read, he will try to modify each word as little as possible. Limak has a string s t...
# http://codeforces.com/contest/771/problem/D """ DP-solution. For each state (v, k, x, v_is_last_letter) we trial a step along the v, k and x axes and check that dp[future_state] = min(dp[future_state], dp[state] + cost_of_move) Hence this implicitly reults in the one with least cost. V, K, X are arrays that contain...
{ "input": [ "4\nVKVK\n", "7\nVVKEVKK\n", "5\nLIMAK\n", "20\nVKVKVVVKVOVKVQKKKVVK\n", "5\nBVVKV\n", "15\nVKKHKKKKZVKKVKV\n", "52\nVAVBVCVDVEVFVGVHVIVJVKVLVMVNVOVPVQVRVSVTVUVVVWVXVYVZ\n", "75\nVAKKVKVKKZVVZAVKKVKVZKKVKVVKKAVKKKVVZVKVKVKKKKVVVVKKVZKVVKKKVAKKZVKKVKVVKVK\n", "51\nAVVVV...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Bear Limak prepares problems for a programming competition. Of course, it would be unprofessional to mention the sponsor name in the statement. Limak takes it seriously and he is goin...
796_D. Police Stations_38320
Inzane finally found Zane with a lot of money to spare, so they together decided to establish a country of their own. Ruling a country is not an easy job. Thieves and terrorists are always ready to ruin the country's peace. To fight back, Zane and Inzane have enacted a very effective law: from each city it must be pos...
import os, sys, bisect, copy from collections import defaultdict, Counter, deque from functools import lru_cache #use @lru_cache(None) if os.path.exists('in.txt'): sys.stdin=open('in.txt','r') if os.path.exists('out.txt'): sys.stdout=open('out.txt', 'w') # def input(): return sys.stdin.readline() def mapi(arg=0): ret...
{ "input": [ "6 3 2\n1 5 6\n1 2\n1 3\n1 4\n1 5\n5 6\n", "6 2 4\n1 6\n1 2\n2 3\n3 4\n4 5\n5 6\n", "6 2 4\n1 6\n1 2\n2 3\n3 4\n4 5\n5 6\n", "2 1 1\n1\n1 2\n", "11 1 5\n6\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n", "10 1 5\n5\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n", "10 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Inzane finally found Zane with a lot of money to spare, so they together decided to establish a country of their own. Ruling a country is not an easy job. Thieves and terrorists are ...
888_D. Almost Identity Permutations_38330
A permutation p of size n is an array such that every integer from 1 to n occurs exactly once in this array. Let's call a permutation an almost identity permutation iff there exist at least n - k indices i (1 ≤ i ≤ n) such that pi = i. Your task is to count the number of almost identity permutations for given numbers...
import math nk=input().split() n=int(nk[0]) k=int(nk[1]) L=[0]*5 L[1]=1 L[2]=(n*(n-1))//2 L[3]=(n*(n-1)*(n-2))//3 L[4]=(3*n*(n-1)*(n-2)*(n-3))//8 s=0 for i in range(0,k+1): s+=L[i] print(s)
{ "input": [ "4 2\n", "4 1\n", "5 4\n", "5 3\n", "1000 2\n", "400 4\n", "200 3\n", "400 3\n", "800 3\n", "200 1\n", "600 3\n", "200 2\n", "400 2\n", "800 4\n", "1000 4\n", "1000 1\n", "1000 3\n", "200 4\n", "400 1\n", "600 2\n", "800 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: A permutation p of size n is an array such that every integer from 1 to n occurs exactly once in this array. Let's call a permutation an almost identity permutation iff there exist a...
911_B. Two Cakes_38334
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 plat...
#problem 911b n,a,b=list(map(int,input().split())) print(max(min(a//i,b//(n-i)) for i in range(1,n)))
{ "input": [ "4 7 10\n", "5 2 3\n", "5 2 8\n", "6 12 6\n", "5 5 8\n", "26 93 76\n", "8 7 10\n", "6 75 91\n", "12 97 13\n", "4 3 2\n", "3 2 5\n", "9 4 6\n", "4 5 1\n", "5 20 8\n", "3 9 9\n", "41 67 34\n", "2 1 1\n", "99 99 99\n", "2 90 95\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: 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, a...
95_B. Lucky Numbers_38340
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. Fo...
from itertools import permutations as p def ck(num,arr): for i in arr: if i>=num: print(i) return x = input() z = len(x) if z == 1: print(47) elif z == 2 : if int(x) <= 74: arr = [47,74] ck(int(x),arr) else: print(4477) elif z == 3: print(447...
{ "input": [ "47\n", "4500\n", "73\n", "444000000\n", "447777\n", "3696\n", "12\n", "100\n", "1024\n", "123\n", "74777443\n", "1007\n", "4\n", "7748\n", "474\n", "74710000\n", "19\n", "70070077\n", "888999577\n", "2145226\n", "7474747...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 ...
p02586 AtCoder Beginner Contest 175 - Picking Goods_38356
There are K items placed on a grid of squares with R rows and C columns. Let (i, j) denote the square at the i-th row (1 \leq i \leq R) and the j-th column (1 \leq j \leq C). The i-th item is at (r_i, c_i) and has the value v_i. Takahashi will begin at (1, 1), the start, and get to (R, C), the goal. When he is at (i, ...
import sys input = sys.stdin.readline R, C, k = map(int, input().split()) xs = [[0] * C for _ in range(R)] for _ in range(k): r, c, v = map(int, input().split()) xs[r - 1][c - 1] = v dp = [[[0] * (C + 1) for _ in range(R + 1)] for _ in range(4)] for i in range(R): for j in range(C): for k in range...
{ "input": [ "2 5 5\n1 1 3\n2 4 20\n1 2 1\n1 3 4\n1 4 2", "2 2 3\n1 1 3\n2 1 4\n1 2 5", "4 5 10\n2 5 12\n1 5 12\n2 3 15\n1 2 20\n1 1 28\n2 4 26\n3 2 27\n4 5 21\n3 5 10\n1 3 10", "2 5 5\n1 1 3\n2 4 20\n2 2 1\n1 3 4\n1 4 2", "4 5 3\n2 5 12\n1 5 12\n2 3 15\n1 2 20\n1 1 28\n2 4 26\n3 2 27\n4 5 21\n3 5...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are K items placed on a grid of squares with R rows and C columns. Let (i, j) denote the square at the i-th row (1 \leq i \leq R) and the j-th column (1 \leq j \leq C). The i-th...
p02717 AtCoder Beginner Contest 161 - ABC Swap_38360
We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C C...
X, Y, Z = map(int,input().split()) print(Z, X, Y)
{ "input": [ "100 100 100", "41 59 31", "1 2 3", "000 100 100", "41 82 31", "2 2 3", "010 100 100", "41 82 46", "2 2 5", "010 000 100", "41 18 46", "2 2 7", "010 000 110", "41 5 46", "3 2 7", "010 010 110", "41 5 7", "3 2 12", "011 010 110", ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations belo...
p02846 Sumitomo Mitsui Trust Bank Programming Contest 2019 - Interval Running_38364
Takahashi and Aoki are training for long-distance races in an infinitely long straight course running from west to east. They start simultaneously at the same point and moves as follows towards the east: * Takahashi runs A_1 meters per minute for the first T_1 minutes, then runs at A_2 meters per minute for the subse...
t = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) x = t[0] * (a[0] - b[0]) y = x + t[1] * (a[1] - b[1]) if x*y > 0: print(0) elif x*y == 0: print('infinity') elif abs(x) % abs(y) == 0: print(2 * (abs(x) // abs(y))) else: print(2 * (abs(x) // abs(y)) + 1)
{ "input": [ "1 2\n10 10\n12 4", "100 1\n101 101\n102 1", "12000 15700\n3390000000 3810000000\n5550000000 2130000000", "1 2\n10 10\n12 5", "100 1\n111 101\n102 1", "100 2\n100 101\n102 1", "1 1\n1 20\n12 5", "100 2\n100 101\n102 0", "1 1\n2 20\n12 5", "100 2\n100 111\n102 0", ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Takahashi and Aoki are training for long-distance races in an infinitely long straight course running from west to east. They start simultaneously at the same point and moves as foll...
p02983 AtCoder Beginner Contest 133 - Remainder Minimization 2019_38368
You are given two non-negative integers L and R. We will choose two integers i and j such that L \leq i < j \leq R. Find the minimum possible value of (i \times j) \mbox{ mod } 2019. Constraints * All values in input are integers. * 0 \leq L < R \leq 2 \times 10^9 Input Input is given from Standard Input in the fol...
l,r = map(int,input().split()) r = min(r, l+4038) ans = 2018 for i in range(l,r): for j in range(l+1,r+1): if ans > i*j%2019: ans = i*j%2019 print(ans)
{ "input": [ "4 5", "2020 2040", "3 5", "4 10", "2020 3053", "1 5", "8 10", "2845 3053", "2 5", "6 8", "5 12", "9 10", "543 3053", "1 8", "1022 3053", "0 8", "1022 2650", "-1 8", "1022 4340", "-1 15", "0 15", "-2 15", "-4 15",...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given two non-negative integers L and R. We will choose two integers i and j such that L \leq i < j \leq R. Find the minimum possible value of (i \times j) \mbox{ mod } 2019. ...
p03125 AtCoder Beginner Contest 118 - B +/- A_38372
You are given positive integers A and B. If A is a divisor of B, print A + B; otherwise, print B - A. Constraints * All values in input are integers. * 1 \leq A \leq B \leq 20 Input Input is given from Standard Input in the following format: A B Output If A is a divisor of B, print A + B; otherwise, print B -...
a,b = list(map(int,input().split())) print(a+b if b%a == 0 else b-a)
{ "input": [ "4 12", "8 20", "1 1", "1 12", "4 20", "1 0", "1 2", "4 24", "1 -1", "6 24", "6 36", "6 10", "6 17", "6 32", "5 32", "5 52", "5 10", "2 16", "1 16", "3 19", "5 19", "4 28", "8 28", "22 28", "22 14", "1...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given positive integers A and B. If A is a divisor of B, print A + B; otherwise, print B - A. Constraints * All values in input are integers. * 1 \leq A \leq B \leq 20 Inp...
p03267 AtCoder Beginner Contest 108 - All Your Paths are Different Lengths_38376
You are given an integer L. Construct a directed graph that satisfies the conditions below. The graph may contain multiple edges between the same pair of vertices. It can be proved that such a graph always exists. * The number of vertices, N, is at most 20. The vertices are given ID numbers from 1 to N. * The number o...
#解説参照 l=int(input()) r=0 while 2**(r+1)<=l: r+=1 n=r+1 ans=[] for i in range(r): ans.append((i+1,i+2,0)) ans.append((i+1,i+2,2**i)) for t in range(n-1,0,-1): if l-2**(t-1)>=2**r: ans.append((t,n,l-2**(t-1))) l-=2**(t-1) print(n,len(ans)) for a in ans: print(*a)
{ "input": [ "4", "5", "8", "2", "1", "9", "6", "3", "10", "17", "18", "33", "16", "12", "20", "40", "36", "32", "65", "24", "34", "66", "48", "68", "72", "129", "64", "130", "136", "80", "160",...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given an integer L. Construct a directed graph that satisfies the conditions below. The graph may contain multiple edges between the same pair of vertices. It can be proved th...
p03425 AtCoder Beginner Contest 089 - March_38380
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choo...
import itertools N = int(input()) # N=10^5 count={} for i in range(N): c = input()[0] count[c] = count.get(c, 0)+1 s = 0 for a,b,c in itertools.combinations("MARCH", 3): s += count.get(a,0)*count.get(b,0)*count.get(c,0) print(s)
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ", "5\nMASHIKE\nRUMOI\nOBIRA\nOROBAH\nHOROKANAI", "5\nCHOKUD@I\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZY\nZZZ\nZ\nZZZZZZZZZZ", "5\nDHOKUD@I\nRNG\nMAKOTO\nAOKI\nRINGN", ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with ...
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift_38384
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exact...
a,b,c = map(int,input().split()) L = [[0] for _ in range(a)] + [[1] for _ in range(b)] + [[2] for _ in range(c)] while len(L) > 1: L[0] += L.pop() L.sort() print(''.join(('a','b','c')[i] for i in L[0]))
{ "input": [ "2 2 0", "1 1 1", "2 1 0", "1 1 0", "0 2 0", "1 0 1", "2 0 0", "1 0 0", "2 2 1", "2 0 1", "3 2 0", "3 0 1", "3 3 0", "3 1 1", "6 3 0", "2 1 1", "6 3 1", "4 1 1", "6 3 2", "4 2 1", "6 0 2", "5 2 1", "6 0 1", "7...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`...
p03739 AtCoder Beginner Contest 059 - Sequence_38388
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
n=int(input()) a=list(map(int,input().split())) u=0 s=1 x=0 y=0 for i in a: u+=i if s*u<=0: x+=1-s*u u=s s=s*(-1) s=-1 u=0 for i in a: u+=i if s*u<=0: y+=1-s*u u=s s=-1*s print(min(x,y))
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4", "5\n3 -6 4 -8 7", "4\n1 -3 1 -1", "6\n-1 4 3 2 -5 0", "4\n1 -5 1 -1", "6\n-1 4 2 2 -5 0", "5\n3 -8 4 -12 7", "4\n1 -5 0 -1", "6\n-1 4 1 2 -5 0", "5\n3 -5 4 -12 7", "6\n-1 8 1 2 -5 0", "6\n-1 8 2 2...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how...
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!_38391
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneou...
#!/usr/bin/env python3 import math x = int(input()) p = int(input())/100 print(math.ceil(x / 2) / p)
{ "input": [ "6\n40", "101\n80", "3\n100", "6\n36", "101\n141", "3\n101", "6\n38", "101\n233", "3\n111", "6\n59", "101\n416", "3\n001", "6\n106", "101\n221", "3\n011", "6\n174", "101\n27", "3\n010", "6\n95", "101\n37", "3\n110", "...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate...
p00007 Debt Hell_38395
Your friend who lives in undisclosed country is involved in debt. He is borrowing 100,000-yen from a loan shark. The loan shark adds 5% interest of the debt and rounds it to the nearest 1,000 above week by week. Write a program which computes the amount of the debt in n weeks. Input An integer n (0 ≤ n ≤ 100) is g...
import math n = int(input()) a = 100000 for _ in range(n): a *= 1.05 a = 1000 * math.ceil(a / 1000) print(a)
{ "input": [ "5", "1", "4", "2", "3", "8", "11", "10", "7", "6", "12", "14", "9", "19", "16", "15", "13", "23", "32", "58", "99", "34", "54", "35", "40", "67", "41", "62", "49", "24", "17", ...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Your friend who lives in undisclosed country is involved in debt. He is borrowing 100,000-yen from a loan shark. The loan shark adds 5% interest of the debt and rounds it to the neare...
p00139 Snakes_38399
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends w...
import re SNAKE_A = re.compile(r">'(=+)#\1~") SNAKE_B = re.compile(r">\^(Q=)+~~") def answer(regex, string, output): result = regex.fullmatch(string) if result is not None: print(output) else: print("NA") for _ in range(int(input())): snake = input() if snake[1] == "'": ...
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~", "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#===>~", "3\n>'======#======~\n>QQ=^=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#===>~", "3\n>(======#======~\n~~=Q=Q=Q=Q=Q=Q=Q=^=QQ>\n>'===#==~>=", "3\n>'======#======~\n>QQ=^=Q=Q=Q=Q=Q=Q=Q=~~\...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after "...
p00272 Ticket Sales_38403
Today is the ticket release date for Aizu Entertainment's recommended idol group "Akabeko & Koboushi". There are four types of tickets: S seat 6000 yen A seat 4000 yen B seat 3000 yen C seat 2000 yen You, the sales manager, are excitedly waiting for the launch. Finally on sale. It's selling very well! Shortly after ...
for i in range(4): t,n=map(int,input().split()) if t==1: print(f'{6000*n}') elif t==2: print(f'{4000*n}') elif t==3: print(f'{3000*n}') elif t==4: print(f'{2000*n}')
{ "input": [ "3 10\n1 4\n4 1\n2 5", "3 10\n1 4\n4 1\n1 5", "3 13\n1 4\n4 1\n1 5", "3 13\n1 4\n1 1\n1 5", "3 13\n1 4\n1 2\n1 5", "2 13\n1 4\n1 2\n1 5", "2 13\n1 4\n1 2\n1 3", "2 13\n1 6\n1 2\n1 3", "3 10\n1 0\n4 1\n2 5", "3 10\n1 4\n2 1\n1 5", "3 16\n1 4\n1 1\n1 5", "3 1...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Today is the ticket release date for Aizu Entertainment's recommended idol group "Akabeko & Koboushi". There are four types of tickets: S seat 6000 yen A seat 4000 yen B seat 3000 ye...
p00460 Bingo_38407
problem In one programming contest, it is customary to play a bingo game at a social gathering after the competition. However, the bingo card used in this bingo game is a little special and is created according to the following conditions. * The Bingo card is divided into squares of N rows and N columns, and one posi...
import itertools while 1: n,m,s=map(int,input().split()) if n==0:break dp=[[0 for _ in range(s+1)] for _ in range(n*n+1)] dp[0][0]=1 for i,j in itertools.product(range(1,n*n+1),range(s+1)): if j>=i:dp[i][j]+=dp[i-1][j-i]+dp[i][j-i] if j-m>=1:dp[i][j]+=100000-dp[i-1][j-m-1] dp...
{ "input": [ "3 9 45\n3 100 50\n5 50 685\n0 0 0", "3 9 45\n3 100 50\n5 50 308\n0 0 0", "3 12 45\n3 100 75\n5 50 308\n0 0 0", "3 12 45\n3 100 69\n5 50 308\n0 0 0", "3 12 45\n3 100 69\n5 90 548\n0 0 0", "3 12 45\n3 100 50\n5 50 331\n0 0 0", "3 3 45\n3 100 69\n5 50 308\n0 0 0", "3 12 60\n...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: problem In one programming contest, it is customary to play a bingo game at a social gathering after the competition. However, the bingo card used in this bingo game is a little spec...
p00650 The House of Huge Family_38410
Mr. Dango's family has an extremely huge number of members. Once it had about 100 members, and now it has as many as population of a city. It is jokingly guessed that the member might fill this planet in the near future. Mr. Dango's family, the huge family, is getting their new house. Scale of the house is as large as...
# AOJ 1065 The House of Huge Family # Python3 2018.7.10 bal4u # UNION-FIND library class UnionSet: def __init__(self, nmax): self.size = [1]*nmax self.id = [i for i in range(nmax+1)] def root(self, i): while i != self.id[i]: self.id[i] = self.id[self.id[i]] i = self.id[i] return i def connected(self, ...
{ "input": [ "3 2\n0 1 2\n1 2 1\n2 1\n0 1 100\n2 1\n0 1 0\n2 1\n0 1 -1\n0 0", "3 2\n0 1 2\n1 2 1\n2 1\n0 1 100\n2 1\n0 0 0\n2 1\n0 1 -1\n0 0", "3 2\n0 1 2\n1 2 1\n2 1\n1 1 100\n2 1\n0 0 0\n2 1\n0 1 -1\n0 0", "3 2\n0 2 2\n0 2 1\n2 1\n0 1 100\n2 1\n0 1 0\n2 1\n0 1 -1\n0 0", "3 2\n0 1 2\n1 2 1\n2 1\n...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Mr. Dango's family has an extremely huge number of members. Once it had about 100 members, and now it has as many as population of a city. It is jokingly guessed that the member might...
p00926 Shopping_38416
Example Input 10 3 3 7 8 9 2 5 Output 23
import sys reader=(token for line in sys.stdin for token in line.split()) while 1: try: n=int(next(reader)) m=int(next(reader)) except: break a=[1]*(n+1) for i in range(m): c=int(next(reader))-1 d=int(next(reader))-1 for i in range(c,d): a[i]=3 print(sum(a))
{ "input": [ "10 3\n3 7\n8 9\n2 5", "10 3\n3 7\n8 9\n3 5", "10 3\n3 7\n8 9\n3 8", "10 3\n2 8\n8 9\n3 8", "10 3\n3 7\n8 9\n1 8", "9 3\n3 7\n8 9\n1 5", "10 3\n3 10\n8 9\n1 5", "10 3\n3 4\n8 9\n4 5", "18 3\n3 7\n7 9\n2 5", "18 3\n3 7\n7 9\n1 5", "18 3\n3 7\n7 17\n1 5", "15...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Example Input 10 3 3 7 8 9 2 5 Output 23 ### Input: 10 3 3 7 8 9 2 5 ### Output: 23 ### Input: 10 3 3 7 8 9 3 5 ### Output: 21 ### Code: import sys reader=(token for line in ...
p01059 Gossip_38419
Problem N idols, numbered from 1 to n in order, are lined up in a row. Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit information only to idol 2, and idol n can transmit information only to idol n-1. At time 0, m idols with numbers a1, a2, ..., am have secret i...
n, m = map(int, input().split()) a =list(map(int, input().split())) t = max(a[0] - 1, n - a[-1]) for i in range(1, m):t = max(t, (a[i] - a[i - 1]) // 2) print(t)
{ "input": [ "10 3\n2 5 7", "100000 1\n1", "10 5\n2 5 6 8 10", "3 2\n1 3", "10 3\n2 5 8", "10 3\n3 5 7", "100001 1\n1", "110001 1\n1", "10 1\n2 2 8", "3 1\n2 2 12", "1 1\n1 3 12", "10 3\n2 5 6 8 10", "10 1\n1 4 8", "8 1\n2 2 7", "10 1\n3 0 8", "17 2\n2 2...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Problem N idols, numbered from 1 to n in order, are lined up in a row. Idle i can transmit information to idle i-1 and idle i + 1 in a unit time. However, idol 1 can transmit informa...
p01496 Bicube_38425
Mary Thomas has a number of sheets of squared paper. Some of squares are painted either in black or some colorful color (such as red and blue) on the front side. Cutting off the unpainted part, she will have eight opened-up unit cubes. A unit cube here refers to a cube of which each face consists of one square. She is...
from collections import deque from string import ascii_lowercase, ascii_uppercase, digits import sys readline = sys.stdin.readline write = sys.stdout.write D = [ (1, 5, 2, 3, 0, 4), # 'U' (3, 1, 0, 5, 4, 2), # 'R' (4, 0, 2, 3, 5, 1), # 'D' (2, 1, 5, 0, 4, 3), # 'L' ] p_dice = (0, 0, 0, 1, 1, 2, 2, 3)*3...
{ "input": [ "3 40\n.a....a....a....a....f....f....f....f...\nbc#.#cd#.#de#.#eb#.#cb#.#dc#.#ed#.#eb#.\n.#....#....#....#....#....#....#....#...", "3 40\n.a....a....a....a....f....f....f....f...\nbc#.#cd#.#de#.#eb#.#cb#.#dc#.#ed#.#be#.\n.#....#....#....#....#....#....#....#...", "3 40\n.a....a....a....a......
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Mary Thomas has a number of sheets of squared paper. Some of squares are painted either in black or some colorful color (such as red and blue) on the front side. Cutting off the unpai...
p01809 Let's Solve Geometric Problems_38429
Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-point error is the error caused by the rounding that occurs when representing a number in binary finite decimal numbers. For example, 0.1 in...
def gcd(m, n): r = m % n return gcd(n, r) if r else n p, q = map(int, input().split()) q //= gcd(p, q) x = q; y = 1; k = 2 while k*k <= x: if x % k == 0: while x % k == 0: x //= k y *= k k += 1 y *= x print(y)
{ "input": [ "1 2", "1 3", "1 6", "3 2", "4 5", "3 10", "3 14", "2 14", "2 17", "3 11", "2 39", "2 13", "3 19", "2 15", "3 38", "3 23", "2 31", "3 55", "3 29", "1 42", "2 35", "2 41", "3 26", "3 47", "2 65", "1 30"...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Let's solve the geometric problem Mr. A is still solving geometric problems today. It is important to be aware of floating point errors when solving geometric problems. Floating-poi...
p02377 Minimum Cost Flow_38436
Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output
# ノードをtupleで渡す from collections import defaultdict from heapq import * class MinCostFlow: def __init__(self): self.inf=10**9 self.to = defaultdict(dict) def add_edge(self, u, v, cap, cost): self.to[u][v]=[cap, cost] self.to[v][u]=[0, -cost] # s...source,t...sink,f...flow ...
{ "input": [ "4 5 2\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "", "4 5 2\n0 0 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "4 5 2\n0 1 2 0\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "4 5 2\n0 1 2 0\n0 2 1 2\n1 2 2 1\n0 3 1 3\n2 3 2 1", "4 5 3\n0 1 2 1\n0 2 1 2\n1 2 1 1\n1 3 1 3\n2 3 2 1", "4 ...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Examples Input 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 Output 6 Input Output ### Input: 4 5 2 0 1 2 1 0 2 1 2 1 2 1 1 1 3 1 3 2 3 2 1 ### Output: 6 ### Input: ### ...