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
1368_B. Codeforces Subsequences_33989
Karl likes Codeforces and subsequences. He wants to find a string of lowercase English letters that contains at least k subsequences codeforces. Out of all possible strings, Karl wants to find a shortest one. Formally, a codeforces subsequence of a string s is a subset of ten characters of s that read codeforces from ...
k = int(input()) cur = 10**18 best = [] for p in range(1, 41): for q in range(1, 41): for i in range(1, 10): res = (p**i)*(q**(10-i)) if res >= k: temp = p*i+q*(10-i)-10 if temp <= cur: cur = temp best = (p, q, ...
{ "input": [ "1\n", "3\n", "5\n", "10000000001\n", "31\n", "666666\n", "1537\n", "256\n", "6131066257802\n", "9728000000001\n", "600\n", "6131066257801\n", "7\n", "512\n", "128\n", "10000000000\n", "6\n", "421654016\n", "16\n", "8\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Karl likes Codeforces and subsequences. He wants to find a string of lowercase English letters that contains at least k subsequences codeforces. Out of all possible strings, Karl want...
1389_D. Segment Intersections_33993
You are given two lists of segments [al_1, ar_1], [al_2, ar_2], ..., [al_n, ar_n] and [bl_1, br_1], [bl_2, br_2], ..., [bl_n, br_n]. Initially, all segments [al_i, ar_i] are equal to [l_1, r_1] and all segments [bl_i, br_i] are equal to [l_2, r_2]. In one step, you can choose one segment (either from the first or fro...
from bisect import * from collections import * from math import gcd,ceil,sqrt,floor,inf from heapq import * from itertools import * from operator import add,mul,sub,xor,truediv,floordiv from functools import * #------------------------------------------------------------------------ import os import sys from io import...
{ "input": [ "3\n3 5\n1 2\n3 4\n2 1000000000\n1 1\n999999999 999999999\n10 3\n5 10\n7 8\n", "1\n10 10\n1 1\n1 1\n", "1\n1 1\n3 3\n1 1\n", "1\n2 10\n1 1\n1 1\n", "1\n4 52\n3 5\n3 5\n", "1\n3 100\n1 1\n1 1\n", "2\n3 5\n1 2\n1 2\n3 5\n1 1\n1 1\n", "1\n1 1\n1 1\n1 1\n", "1\n200000 8863...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given two lists of segments [al_1, ar_1], [al_2, ar_2], ..., [al_n, ar_n] and [bl_1, br_1], [bl_2, br_2], ..., [bl_n, br_n]. Initially, all segments [al_i, ar_i] are equal to...
140_A. New Year Table_33997
Gerald is setting the New Year table. The table has the form of a circle; its radius equals R. Gerald invited many guests and is concerned whether the table has enough space for plates for all those guests. Consider all plates to be round and have the same radii that equal r. Each plate must be completely inside the ta...
import math x=[int(i) for i in input().split()] n,R,r=x[0],x[1],x[2] if r>R: print('NO') raise SystemExit if 2*r>R: if n>1: print('NO') raise SystemExit else: print('YES') raise SystemExit z=2*n*math.asin(r/(R-r)) if z>2*math.pi+0.0000000001: print('NO') else: ...
{ "input": [ "1 10 10\n", "4 10 4\n", "5 10 4\n", "2 100 50\n", "100 821 25\n", "2 10 10\n", "10 72 17\n", "100 100 5\n", "10 1000 237\n", "2 2 1\n", "59 486 43\n", "7 997 332\n", "1 100 45\n", "13 927 179\n", "85 449 16\n", "93 857 28\n", "2 1000 50...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Gerald is setting the New Year table. The table has the form of a circle; its radius equals R. Gerald invited many guests and is concerned whether the table has enough space for plate...
1430_E. String Reversal_34001
You are given a string s. You have to reverse it — that is, the first letter should become equal to the last letter before the reversal, the second letter should become equal to the second-to-last letter before the reversal — and so on. For example, if your goal is to reverse the string "abddea", you should get the str...
import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.wri...
{ "input": [ "5\naaaza\n", "6\ncbaabc\n", "9\nicpcsguru\n", "5\nababa\n", "100\nzzzzzxxxyyyytttttssssssggggdddddjjjjjkkksssssjjjjrdddzzzzxxxxaaaaarrryjjjjddderehhhqazzzzzgdgseryydr\n", "50\nfhakqhdhrgfjruxndgfhdvcxhsrjfgdhsyrhfjcbfgdvrtdysf\n", "100\nrxxxrrxrxxxxxrrrrrxxxxrrrrxrxxrxxrxrxrr...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given a string s. You have to reverse it — that is, the first letter should become equal to the last letter before the reversal, the second letter should become equal to the s...
1454_A. Special Permutation_34005
You are given one integer n (n > 1). Recall that a permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2, 3, 1, 5, 4] is a permutation of length 5, but [1, 2, 2] is not a permutation (2 appears twice in the array) and [1, 3, 4] is also not a permutation (...
def lip(): return list(map(int,input().split())) def splip(): return map(int,input().split()) def intip(): return int(input()) for _ in range(intip()): n = intip() l = [i for i in range(1,n+1)] l = l[::-1] mid = n//2 if n==2: print(*l) elif n%2!=0: l[mid] , l[mid-1] = l[mid-1],...
{ "input": [ "2\n2\n5\n", "100\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\n63\n64\n65\n66\n67\n68\n69\n70\n71\n72\n73...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given one integer n (n > 1). Recall that a permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2, 3, 1, 5, 4] ...
1505_A. Is it rated - 2_34010
Interaction This is an interactive problem. You need to read participants' queries from standard input and print your responses to standard output. You don't know the number of queries upfront, so you'll need to process them as you get them; you'll know you're done once you reach the end of the file. In each query,...
try: while(1): a=input() print("NO") except EOFError as e: pass
{ "input": [ "Is it rated?\nIs it rated?\nIs it rated?\n", "Is it rated?\nIs it rated?\nIs it rated?\n" ], "output": [ "\nNO\nNO\nNO", "Correct!" ] }
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Interaction This is an interactive problem. You need to read participants' queries from standard input and print your responses to standard output. You don't know the number of que...
1528_B. Kavi on Pairing Duty_34014
Kavi has 2n points lying on the OX axis, i-th of which is located at x = i. Kavi considers all ways to split these 2n points into n pairs. Among those, he is interested in good pairings, which are defined as follows: Consider n segments with ends at the points in correspondent pairs. The pairing is called good, if fo...
import sys, math import io, os #data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline #from bisect import bisect_left as bl, bisect_right as br, insort #from heapq import heapify, heappush, heappop #from collections import defaultdict as dd, deque, Counter #from itertools import permutations,combinations def data(...
{ "input": [ "3\n", "1\n", "2\n", "100\n", "333625\n", "693549\n", "757606\n", "1000000\n", "999228\n", "443013\n", "825195\n", "160945\n", "489857\n", "563368\n", "372544\n", "315936\n", "446167\n", "797112\n", "75417\n", "119444\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Kavi has 2n points lying on the OX axis, i-th of which is located at x = i. Kavi considers all ways to split these 2n points into n pairs. Among those, he is interested in good pairi...
15_A. Cottage Village_34018
A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» n square houses with the centres on the Оx-axis. The houses' sides are parallel to the coordinate axes. It's known that no two houses overlap, but they can touch each other. The architect bureau, where Pe...
n,t=list(map(int,input().split())) amount=2 houses=[] for i in range(n): c,l=list(map(int,input().split())) l=l/2 start,end=c-l,c+l houses.append([start,end]) houses.sort(key=lambda x:x[0]) prev_end=houses[0][0] for start,end in houses: gap=start-prev_end if gap>t: amount+=2 elif ga...
{ "input": [ "2 3\n0 4\n5 2\n", "2 2\n0 4\n6 2\n", "2 2\n0 4\n5 2\n", "2 2\n0 4\n7 4\n", "50 1\n-967 7\n696 7\n-366 4\n557 1\n978 2\n800 4\n-161 2\n-773 2\n-248 2\n134 3\n869 6\n-932 2\n-262 14\n191 3\n669 2\n72 5\n0 1\n757 8\n859 2\n-131 8\n-169 3\n543 10\n-120 2\n-87 8\n-936 6\n-620 3\n-281 11\n...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: A new cottage village called «Flatville» is being built in Flatland. By now they have already built in «Flatville» n square houses with the centres on the Оx-axis. The houses' sides a...
201_D. Brand New Problem_34024
A widely known among some people Belarusian sport programmer Lesha decided to make some money to buy a one square meter larger flat. To do this, he wants to make and carry out a Super Rated Match (SRM) on the site Torcoder.com. But there's a problem — a severe torcoder coordinator Ivan does not accept any Lesha's probl...
import itertools def count_inversions(enumerate_seq): tmp = list(enumerate_seq[:]) result = 0 for i in range(len(tmp)): for j in range(len(tmp) - 1): if tmp[j][0] > tmp[j + 1][0]: result += 1 tmp[j], tmp[j + 1] = tmp[j + 1], tmp[j] return result de...
{ "input": [ "4\nfind the next palindrome\n1\n10 find the previous palindrome or print better luck next time\n", "3\nadd two decimals\n5\n4 please two decimals add\n5 decimals want to be added\n4 two add decimals add\n4 add one two three\n7 one plus two plus three equals six\n", "3\nadd two numbers\n3\n1 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: A widely known among some people Belarusian sport programmer Lesha decided to make some money to buy a one square meter larger flat. To do this, he wants to make and carry out a Super...
250_A. Paper Work_34031
Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's performance for the last n days. We know that the main information in a day report is value ai, the company's profit on the i-th day. If ai is n...
from math import ceil n=int(input()) reports = list(map(int,input().split())) k=0 count=0 lst=[] for i in reports: count += 1 if i<0: if k+1 > 2: lst.append(count-1) count=1 k=1 else: k+=1 lst.append(count) print(len(lst)) for i in lst: print(...
{ "input": [ "5\n0 -1 100 -1 0\n", "11\n1 2 3 -4 -5 -6 5 -5 -6 -7 6\n", "3\n-3 -4 -5\n", "100\n-63 20 79 73 18 82 23 -93 55 8 -31 37 33 24 30 41 70 77 14 34 84 79 -94 88 54 81 7 90 74 35 29 3 75 71 14 28 -61 63 90 79 71 97 -90 74 -33 10 27 34 46 31 9 90 100 -73 58 2 73 51 5 46 -27 -9 30 65 73 28 15 14...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Polycarpus has been working in the analytic department of the "F.R.A.U.D." company for as much as n days. Right now his task is to make a series of reports about the company's perform...
275_B. Convex Shape_34035
Consider an n × m grid. Initially all the cells of the grid are colored white. Lenny has painted some of the cells (at least one) black. We call a painted grid convex if one can walk from any black cell to any another black cell using a path of side-adjacent black cells changing his direction at most once during the pa...
n,m = map(int, input().split()) row, col_sum, row_sum, black = [], [], [], [] for i in range(n): row.append(input()) t = [0] for j in range(m): t += [t[j] + (row[i][j] == 'B')] row_sum += [t] d = [[0,1], [1,0], [-1,0], [0,-1]] for i in range(n): for j in range(m): if row[i][j] is '...
{ "input": [ "3 1\nB\nB\nW\n", "3 4\nWWBW\nBWWW\nWWWB\n", "5 5\nWWBWW\nWWBWW\nWWBBB\nBBBBB\nWWWWW\n", "5 5\nWWBBB\nWWBBB\nWWBBB\nWWBBB\nWWBBW\n", "5 5\nWWWWW\nWWWWW\nWWWWW\nWWWWW\nWWBWW\n", "5 5\nWWWBB\nBBBBB\nWWWBB\nWWWBB\nWWWBW\n", "5 5\nWWWWB\nWWWWB\nWBBBB\nWWWWW\nWWWWW\n", "5 5\nWB...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Consider an n × m grid. Initially all the cells of the grid are colored white. Lenny has painted some of the cells (at least one) black. We call a painted grid convex if one can walk ...
298_D. Fish Weight_34039
It is known that there are k fish species in the polar ocean, numbered from 1 to k. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight of the i-th type of fish be wi, then 0 < w1 ≤ w2 ≤ ... ≤ wk holds. Polar bears Alice and Bob each have caught some fish, and they are g...
n, m, k = [int(x) for x in input().split()] alice = [int(x) for x in input().split()] bob = [int(x) for x in input().split()] alice.sort() bob.sort() balance = 0 i = n - 1 j = m - 1 while i >= 0 and j >= 0: if alice[i] > bob[j]: balance += 1 i -= 1 elif alice[i] < bob[j]: balance -= 1...
{ "input": [ "3 3 3\n2 2 2\n1 1 3\n", "4 7 9\n5 2 7 3\n3 5 2 7 3 8 7\n", "100 50 10\n7 8 7 1 6 7 9 2 4 6 7 7 3 9 4 5 1 7 8 10 4 1 3 6 8 10 4 6 6 1 6 6 7 4 10 3 10 1 3 2 10 6 9 9 5 2 9 2 9 8 10 2 10 3 3 2 3 8 6 2 7 10 7 2 7 2 8 9 6 2 5 4 4 5 3 3 9 10 9 4 9 3 9 5 3 6 6 1 3 6 10 3 10 2 6 10 10 10 4 8\n3 3 2 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: It is known that there are k fish species in the polar ocean, numbered from 1 to k. They are sorted by non-decreasing order of their weight, which is a positive number. Let the weight...
321_B. Ciel and Duel_34043
Fox Ciel is playing a card game with her friend Jiro. Jiro has n cards, each one has two attributes: position (Attack or Defense) and strength. Fox Ciel has m cards, each one has these two attributes too. It's known that position of all Ciel's cards is Attack. Now is Ciel's battle phase, Ciel can do the following ope...
n, m = map(int, input().split()) (a, d, my) = ([], [], []) for i in range(n): t, val = input().split() (a if t == 'ATK' else d).append(int(val)) my = sorted([int(input()) for i in range(m)]) a.sort() d.sort() def solve1(): ret = 0 used = [False] * m for val in d: for i in range(m): ...
{ "input": [ "2 3\nATK 2000\nDEF 1700\n2500\n2500\n2500\n", "3 4\nATK 10\nATK 100\nATK 1000\n1\n11\n101\n1001\n", "2 4\nDEF 0\nATK 0\n0\n0\n1\n1\n", "34 9\nDEF 7295\nDEF 7017\nDEF 7483\nDEF 7509\nDEF 7458\nDEF 7434\nDEF 6981\nDEF 7090\nDEF 7298\nDEF 7134\nATK 737\nDEF 7320\nDEF 7228\nDEF 7323\nATK 786...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Fox Ciel is playing a card game with her friend Jiro. Jiro has n cards, each one has two attributes: position (Attack or Defense) and strength. Fox Ciel has m cards, each one has the...
391_C3. The Tournament_34048
This problem consists of three subproblems: for solving subproblem C1 you will receive 4 points, for solving subproblem C2 you will receive 4 points, and for solving subproblem C3 you will receive 8 points. Manao decided to pursue a fighter's career. He decided to begin with an ongoing tournament. Before Manao joined,...
m = 301000 ns = [0] * m es = [0] * m c = [0] * m b = [0] * m t = [0] * m P = 0 def add(b, k): k = t[k] while k: e = es[k] if b[-1] > e: b[-1] = e b[e] += 1 k = ns[k] def delete(b): for i in range(b[m - 1], m + 1): if b[i]: b[i] -= 1 b[-1] = i ...
{ "input": [ "5 2\n2 10\n2 10\n1 1\n3 1\n3 1\n", "3 2\n1 1\n1 4\n2 2\n", "2 1\n3 2\n4 0\n", "15 12\n2 77\n8 79\n5 70\n0 1\n0 4\n6 10\n4 38\n3 36\n9 1\n2 9\n0 72\n10 17\n5 93\n7 10\n3 49\n", "15 3\n2 39237\n6 42209\n8 99074\n2 140949\n3 33788\n15 7090\n13 29599\n1 183967\n6 20161\n7 157097\n10 1732...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: This problem consists of three subproblems: for solving subproblem C1 you will receive 4 points, for solving subproblem C2 you will receive 4 points, and for solving subproblem C3 you...
440_A. Forgotten Episode_34055
Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has n episodes, numbered with integers from 1 to n. Polycarpus watches episodes not one by one but in a random order. He has already watched all the episodes except for one. Which epi...
import sys input=sys.stdin.buffer.readline n=int(input()) arr=list(map(int,input().split())) arr.sort() z=0 for i in range(0,n-1): if arr[i]==i+1: continue else: print(i+1) z=1 break if z==0: print(n)
{ "input": [ "10\n3 8 10 1 7 9 6 5 2\n", "5\n5 2 4 3\n", "2\n1\n", "5\n5 4 3 2\n", "3\n2 3\n", "3\n2 1\n", "5\n1 5 3 4\n", "3\n3 2\n", "3\n1 3\n", "5\n4 3 2 1\n", "5\n1 4 5 2\n", "3\n3 1\n", "2\n2\n", "3\n1 2\n", "5\n1 2 3 4\n", "5\n2 3 4 5\n", "5\n2...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Polycarpus adores TV series. Right now he is ready to finish watching a season of a popular sitcom "Graph Theory". In total, the season has n episodes, numbered with integers from 1 t...
462_C. Appleman and Toastman_34059
Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: * Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. * Each time Applema...
import heapq n=int(input()) a=list(map(lambda x:-int(x),input().split())) heapq.heapify(a) ans=0 for i in range(n-1): x=heapq.heappop(a) y=heapq.heappop(a) ans+=x+y heapq.heappush(a,x+y) print(-ans-sum(a))
{ "input": [ "1\n10\n", "3\n3 1 5\n", "2\n2 3\n", "10\n171308 397870 724672 431255 228496 892002 542924 718337 888642 161821\n", "2\n1 1\n", "10\n888642 724672 724672 431255 431255 397870 397870 397870 397870 228496\n", "10\n228496 397870 397870 397870 397870 431255 431255 724672 724672 88...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: 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 gro...
486_B. OR in Matrix_34063
Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0, 1}) that is equal to 1 if either or both of the logical values is set to 1, otherwise it is 0. We can define logical OR of three or more logical values in the same manner: <image> where <image> is equal to 1 if some ...
from sys import stdin input = stdin.readline from heapq import heapify,heappush,heappop,heappushpop from collections import defaultdict as dd, deque as dq,Counter as C from math import factorial as f ,ceil,gcd,sqrt,log from bisect import bisect_left as bl ,bisect_right as br from itertools import combinations as c,perm...
{ "input": [ "2 3\n1 1 1\n1 1 1\n", "2 2\n1 0\n0 0\n", "2 3\n0 1 0\n1 1 1\n", "7 10\n1 0 1 0 0 0 1 0 1 0\n1 0 1 0 0 0 1 0 1 0\n1 1 1 1 1 1 1 1 1 1\n1 0 1 0 0 0 1 0 1 0\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1\n", "5 5\n1 1 1 0 1\n1 1 0 0 1\n0 0 1 1 1\n1 1 1 1 0\n1 0 1 1 1\n",...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Let's define logical OR as an operation on two logical values (i. e. values that belong to the set {0, 1}) that is equal to 1 if either or both of the logical values is set to 1, othe...
50_A. Domino piling_34067
You are given a rectangular board of M × N squares. Also you are given an unlimited number of standard domino pieces of 2 × 1 squares. You are allowed to rotate the pieces. You are asked to place as many dominoes as possible on the board so as to meet the following conditions: 1. Each domino completely covers two squa...
#domino piling M,N=map(int,input().split()) d=(M*N)//2 print(d)
{ "input": [ "2 4\n", "3 3\n", "2 6\n", "1 5\n", "3 6\n", "2 5\n", "3 16\n", "2 7\n", "3 10\n", "14 16\n", "1 16\n", "5 16\n", "4 4\n", "15 16\n", "5 7\n", "2 16\n", "2 2\n", "1 6\n", "1 1\n", "16 16\n", "14 15\n", "1 4\n", "2...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given a rectangular board of M × N squares. Also you are given an unlimited number of standard domino pieces of 2 × 1 squares. You are allowed to rotate the pieces. You are as...
534_C. Polycarpus' Dice_34071
Polycarp has n dice d1, d2, ..., dn. The i-th dice shows numbers from 1 to di. Polycarp rolled all the dice and the sum of numbers they showed is A. Agrippina didn't see which dice showed what number, she knows only the sum A and the values d1, d2, ..., dn. However, she finds it enough to make a series of statements of...
n, a = [int(i) for i in input().split()] t = [int(i) for i in input().split()] s = 0 for i in t: s+=i k = [] for i in range(n): k.append(0) if s-a < t[i]: k[i]+=t[i]-s+a-1 if t[i] - (a - n+1) > 0: k[i]+=(t[i] - (a - n+1)) print(*k)
{ "input": [ "1 3\n5\n", "2 8\n4 4\n", "2 3\n2 3\n", "3 7\n5 1 5\n", "3 6\n5 1 5\n", "10 79\n9 9 6 9 10 4 5 10 8 9\n", "10 40\n1 5 6 1 6 4 1 2 9 5\n", "3 5\n5 1 5\n", "1 1\n3\n", "1 2\n3\n", "2 4\n2 3\n", "10 41\n4 1 8 3 3 3 4 3 6 6\n", "10 48\n8 1 9 8 4 1 1 8 6 2\n...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Polycarp has n dice d1, d2, ..., dn. The i-th dice shows numbers from 1 to di. Polycarp rolled all the dice and the sum of numbers they showed is A. Agrippina didn't see which dice sh...
559_C. Gerald and Giant Chess_34075
Giant chess is quite common in Geraldion. We will not delve into the rules of the game, we'll just say that the game takes place on an h × w field, and it is painted in two colors, but not like in chess. Almost all cells of the field are white and only some of them are black. Currently Gerald is finishing a game of gia...
from sys import stdin input = stdin.buffer.readline f, inv = [1], [1, 1] mod = 1000000007 def c(n, k): return f[n] * inv[k] * inv[n - k] % mod h, w, n = map(int, input().split()) for i in range(1, 200001): f.append(f[i - 1] * i % mod) for i in range(2, 200001): inv.append((-(mod // i) * inv[mod % i]) % mod) for i in...
{ "input": [ "3 4 2\n2 2\n2 3\n", "100 100 3\n15 16\n16 15\n99 88\n", "1000 1000 4\n50 50\n51 50\n50 51\n51 51\n", "100000 100000 4\n50001 50001\n50000 50000\n50000 50001\n50001 50000\n", "2 2 2\n2 1\n1 2\n", "100000 100000 3\n99998 100000\n99999 99999\n100000 99998\n", "100 10 30\n40 4\n1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Giant chess is quite common in Geraldion. We will not delve into the rules of the game, we'll just say that the game takes place on an h × w field, and it is painted in two colors, bu...
585_A. Gennady the Dentist_34079
Gennady is one of the best child dentists in Berland. Today n children got an appointment with him, they lined up in front of his office. All children love to cry loudly at the reception at the dentist. We enumerate the children with integers from 1 to n in the order they go in the line. Every child is associated with...
from sys import stdin def input(): return stdin.readline() from collections import deque as d class Child: def __init__(self, cry, leave, cond): self.cry = cry self.leave = leave self.cond = cond self.alive = True N = int(input()) queue = d() for i in range(N): lst = [ ...
{ "input": [ "5\n4 5 1\n5 3 9\n4 1 2\n2 1 8\n4 1 9\n", "5\n4 2 2\n4 1 2\n5 2 4\n3 3 5\n5 1 2\n", "10\n5 6 3\n7 4 10\n9 1 17\n2 8 23\n9 10 24\n6 8 18\n3 2 35\n7 6 6\n1 3 12\n9 9 5\n", "10\n10 3 3\n8 6 17\n9 5 26\n10 7 17\n3 10 29\n3 1 27\n3 3 7\n8 10 28\n1 3 23\n3 4 6\n", "2\n5 1 1\n1 1 5\n", "...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Gennady is one of the best child dentists in Berland. Today n children got an appointment with him, they lined up in front of his office. All children love to cry loudly at the recep...
607_A. Chain Reaction_34083
There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within distance bi inclusive. The beacon itself is not destroyed however. Saitama will acti...
import sys input = sys.stdin.readline from bisect import * n = int(input()) ab = [tuple(map(int, input().split())) for _ in range(n)] ab.sort(key=lambda k: k[0]) a = [-10**18]+[ai for ai, _ in ab] dp = [0]*(n+1) for i in range(1, n+1): j = bisect_left(a, ab[i-1][0]-ab[i-1][1])-1 dp[i] = dp[j]+i-j-1 ans = 10*...
{ "input": [ "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n", "4\n1 9\n3 1\n6 1\n7 4\n", "5\n1 1\n3 1\n5 1\n7 10\n8 10\n", "11\n110 90\n100 70\n90 10\n80 10\n70 1\n60 1\n50 10\n40 1\n30 1\n10 1\n20 1\n", "1\n0 1000000\n", "1\n1000000 1000000\n", "7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 6\n7 7\n", "1\n0...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are n beacons located at distinct positions on a number line. The i-th beacon has position ai and power level bi. When the i-th beacon is activated, it destroys all beacons to i...
653_A. Bear and Three Balls_34089
Limak is a little polar bear. He has n balls, the i-th ball has size ti. Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Limak must obey to make friends happy: * No two friends can get balls of the same size. * No two friends can get balls of sizes that di...
n = int(input()) s = map(int, input().split()) l = [] a = 'NO' for i in s: if i not in l: l += [i] l = sorted(l) if len(l) >= 3: for i in range(len(l) - 2): if l[i] + 2 == l[i + 1] + 1 == l[i + 2]: a = 'YES' print(a)
{ "input": [ "6\n40 41 43 44 44 44\n", "8\n5 972 3 4 1 4 970 971\n", "4\n18 55 16 17\n", "11\n325 325 324 324 324 325 325 324 324 324 324\n", "3\n998 999 1000\n", "6\n1 1 2 2 6 6\n", "3\n2 3 2\n", "50\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Limak is a little polar bear. He has n balls, the i-th ball has size ti. Limak wants to give one ball to each of his three friends. Giving gifts isn't easy — there are two rules Lima...
678_E. Another Sith Tournament_34093
The rules of Sith Tournament are well known to everyone. n Sith take part in the Tournament. The Tournament starts with the random choice of two Sith who will fight in the first battle. As one of them loses, his place is taken by the next randomly chosen Sith who didn't fight before. Does it need to be said that each b...
# by the authority of GOD author: manhar singh sachdev # import os,sys from io import BytesIO, IOBase def main(): n = int(input()) p = [list(map(float,input().split())) for _ in range(n)] y = 1<<n dp = [[0]*y for _ in range(n)] # dp[i][j] is prob of 0 win when j fought and i left dp[0][y-1...
{ "input": [ "3\n0.0 0.5 0.8\n0.5 0.0 0.4\n0.2 0.6 0.0\n", "4\n0.0 1.0 1.0 1.0\n0.0 0.0 0.0 0.0\n0.0 1.0 0.0 0.0\n0.0 1.0 1.0 0.0\n", "6\n0.000000 0.433864 0.631347 0.597596 0.794426 0.713555\n0.566136 0.000000 0.231193 0.396458 0.723050 0.146212\n0.368653 0.768807 0.000000 0.465978 0.546227 0.309438\n0.4...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: The rules of Sith Tournament are well known to everyone. n Sith take part in the Tournament. The Tournament starts with the random choice of two Sith who will fight in the first battl...
723_A. The New Year: Meeting Friends_34098
There are three friend living on the straight line Ox in Lineland. The first friend lives at the point x1, the second friend lives at the point x2, and the third friend lives at the point x3. They plan to celebrate the New Year together, so they need to meet at one point. What is the minimum total distance they have to...
a=list(map(int,input().split())) a.sort() if len(a)%2!=0: s=a[int(len(a)/2)] count=0 for x in a: count+=abs(x-s) print(count)
{ "input": [ "7 1 4\n", "30 20 10\n", "41 28 98\n", "86 97 68\n", "25 97 93\n", "71 85 88\n", "87 85 37\n", "1 4 100\n", "8 1 9\n", "69 46 82\n", "1 100 2\n", "6 9 3\n", "1 2 3\n", "43 92 30\n", "12 4 8\n", "1 53 51\n", "76 50 9\n", "100 1 91\n",...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are three friend living on the straight line Ox in Lineland. The first friend lives at the point x1, the second friend lives at the point x2, and the third friend lives at the p...
768_B. Code For 1_34104
Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to become a maester, so he can return and take the deceased Aemon's place as maester of Castle Black. Jon agrees to Sam's proposal and Sam s...
''' Auther: ghoshashis545 Ashis Ghosh College: jalpaiguri Govt Enggineering College Date:08/06/2020 ''' from os import path import sys from functools import cmp_to_key as ctk from collections import deque,defaultdict as dd from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right ...
{ "input": [ "7 2 5\n", "10 3 10\n", "11586121 15337246 15397874\n", "950099012 175922161 176000556\n", "9056 336 896\n", "903316762502 354723010040 354723105411\n", "95173251245550 106288351347530 106288351372022\n", "281474976710656 17179869184 17179869186\n", "542 321 956\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Jon fought bravely to rescue the wildlings who were attacked by the white-walkers at Hardhome. On his arrival, Sam tells him that he wants to go to Oldtown to train at the Citadel to ...
792_A. New Bus Route_34108
There are n cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers a1, a2, ..., an. All coordinates are pairwise distinct. It is possible to get from one city to another only by bus. But all buses and roads are very old, so the Minister of Transport decided to bui...
n = int(input()) array = list(map(int, input().split())) array = sorted(array) mink = array[-1] - array[0] count = 0 for i in range(1, len(array)): if mink > array[i] - array[i-1]: mink = array[i] - array[i-1] count = 1 elif mink == array[i] - array[i-1]: count += 1 print(mink, count)
{ "input": [ "3\n-2 0 2\n", "4\n6 -3 0 4\n", "5\n-979619606 -979619602 -979619604 -979619605 -979619603\n", "9\n-9 -8 -7 -6 -5 -4 -3 -2 -1\n", "20\n553280626 553280623 553280627 553280624 553280625 553280618 553280620 553280629 553280637 553280631 553280628 553280636 553280635 553280632 553280634 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are n cities situated along the main road of Berland. Cities are represented by their coordinates — integer numbers a1, a2, ..., an. All coordinates are pairwise distinct. It i...
812_C. Sagheer and Nubian Market_34112
On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules. It contains n different items numbered from 1 to n. The i-th item has base cost ai Egyptian pounds. If Sagheer buys k items with indices x1, x2, ..., xk, then the cost ...
n,m1=map(int,input().split()) lp=list(map(int,input().split())) l=0 r=n while l<r : m=(l+r+1)//2 l1=lp[::] for i in range(n) : l1[i]=lp[i]+((i+1)*m) l1=sorted(l1) s=sum(l1[:m]) if s>m1 : r=m-1 else : l=m l1=lp[::] for i in range(n) : l1[i]=lp[i]+((i+1)*l) l1=sorte...
{ "input": [ "4 100\n1 2 5 6\n", "3 11\n2 3 5\n", "1 7\n7\n", "37 5271\n368 6194 4856 8534 944 4953 2085 5350 788 7772 9786 1321 4310 4453 7078 9912 5799 4066 5471 5079 5161 9773 1300 5474 1202 1353 9499 9694 9020 6332 595 7619 1271 7430 1199 3127 8867\n", "39 43\n22166 81842 15513 80979 39645 601...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules. It contains n different items n...
908_A. New Year and Counting Cards_34121
Your friend has n cards. You know that each card has a lowercase English letter on one side and a digit on the other. Currently, your friend has laid out the cards on a table so only one side of each card is visible. You would like to know if the following statement is true for cards that your friend owns: "If a car...
s = list(input()) d = {'a', 'u', 'o', 'e', 'i', '1', '3', '5', '7', '9'} ans = 0 for i in s: if i in d: ans += 1 print(ans)
{ "input": [ "ee\n", "z\n", "0ay1\n", "w\n", "13579\n", "kaq7jyialrfp4ilkni90eq8v3amcbygon7py0hb8z26fbl8ss1\n", "1357\n", "l3rw91a4m25l8iytxyeuixsegzcbm4h41ornf3pixkrmwznrzc\n", "0\n", "0a0a9e9e2i2i9o9o6u6u9z9z4x4x9b9b\n", "gabieurat\n", "0abcdefghijklmnopqrstuvwxyz1234...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Your friend has n cards. You know that each card has a lowercase English letter on one side and a digit on the other. Currently, your friend has laid out the cards on a table so onl...
928_D. Autocompletion_34124
Arcady is a copywriter. His today's task is to type up an already well-designed story using his favorite text editor. Arcady types words, punctuation signs and spaces one after another. Each letter and each sign (including line feed) requires one keyboard click in order to be printed. Moreover, when Arcady has a non-e...
# python3 # utf-8 class Trie: def __init__(self): self.letter___node = {} self.words_nr = 0 def add_word(self, word): word = word + '$' curr_node = self for letter in word: if letter not in curr_node.letter___node: curr_node.letter___node[let...
{ "input": [ "'co-co-co, codeforces?!'\n", "snow affects sports such as skiing, snowboarding, and snowmachine travel.\nsnowboarding is a recreational activity and olympic and paralympic sport.\n", "thun-thun-thunder, thunder, thunder\nthunder, thun-, thunder\nthun-thun-thunder, thunder\nthunder, feel the ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Arcady is a copywriter. His today's task is to type up an already well-designed story using his favorite text editor. Arcady types words, punctuation signs and spaces one after anoth...
958_A1. Death Stars (easy)_34128
The stardate is 1977 and the science and art of detecting Death Stars is in its infancy. Princess Heidi has received information about the stars in the nearby solar system from the Rebel spies and now, to help her identify the exact location of the Death Star, she needs to know whether this information is correct. Tw...
n=int(input()) a=[] b=[] for i in range(n): a.append(input()) for i in range(n): b.append(input()) def h(d): c=[] for i in range(n): c.append(d[n-i-1]) return c def r(d): c=[] for i in range(n): temp="" for j in range(n): temp+=d[j][n-i-1] c.appen...
{ "input": [ "4\nXOOO\nXXOO\nOOOO\nXXXX\nXOOO\nXOOO\nXOXO\nXOXX\n", "2\nXX\nOO\nXO\nOX\n", "10\nXXXOXOOXXX\nOOXXOXXOXO\nOOOOXOOXOX\nXOOXOXOOXX\nXOXXOXOOXX\nOOOXXOXOXX\nOOOXOOOOXO\nOOXOOXXOXX\nXXOXOOXOOX\nOXXXOOXOXX\nXXOXOOXXXO\nXOOXOOXOXX\nXXOXXOOXOO\nOXOOOOXOOO\nXXOXOXXOOO\nXXOOXOXXOX\nXXOOXOXOOX\nXOXOOX...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: The stardate is 1977 and the science and art of detecting Death Stars is in its infancy. Princess Heidi has received information about the stars in the nearby solar system from the Re...
p02563 AtCoder Library Practice Contest - Convolution_34141
You are given two integer arrays a_0, a_1, ..., a_{N - 1} and b_0, b_1, ..., b_{M - 1}. Calculate the array c_0, c_1, ..., c_{(N - 1) + (M - 1)}, defined by c_i = \sum_{j = 0}^i a_j b_{i - j} \bmod 998244353. Constraints * 1 \leq N, M \leq 524288 * 0 \leq a_i, b_i < 998244353 * All values in Input are integer. Input...
#Convolution_998244353 MOD = 998244353 ROOT = 3 sum_e = (911660635, 509520358, 369330050, 332049552, 983190778, 123842337, 238493703, 975955924, 603855026, 856644456, 131300601, 842657263, 730768835, 942482514, 806263778, 151565301, 510815449, 503497456, 743006876, 741047443, 56250497, 0, 0, 0, 0, 0, 0, 0, 0, 0) sum_...
{ "input": [ "4 5\n1 2 3 4\n5 6 7 8 9", "1 1\n10000000\n10000000", "4 5\n1 2 3 4\n5 6 12 8 9", "1 1\n10000000\n10100000", "1 1\n10001000\n10100000", "4 5\n1 2 3 4\n5 6 7 4 9", "4 5\n1 2 3 4\n5 6 12 8 18", "1 1\n10001000\n10110000", "4 5\n1 1 3 4\n5 6 7 4 9", "4 5\n1 2 3 4\n5 0 ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given two integer arrays a_0, a_1, ..., a_{N - 1} and b_0, b_1, ..., b_{M - 1}. Calculate the array c_0, c_1, ..., c_{(N - 1) + (M - 1)}, defined by c_i = \sum_{j = 0}^i a_j b...
p02694 AtCoder Beginner Contest 165 - 1%_34145
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or abo...
x=int(input()) a=100 b=0 while a<x: b=b+1 a=(a*1.01)//1 print(b)
{ "input": [ "1333333333", "103", "1000000000000000000", "1925339908", "121", "1000010000000000000", "2918372355", "1100010000000000000", "1759180116", "314793131", "385473767", "693073999", "463707925", "620557412", "55916268", "29927702", "12264538...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is disc...
p02823 AtCoder Grand Contest 041 - Table Tennis Training_34149
2N players are running a competitive table tennis training on N tables numbered from 1 to N. The training consists of rounds. In each round, the players form N pairs, one pair per table. In each pair, competitors play a match against each other. As a result, one of them wins and the other one loses. The winner of the...
N,A,B=map(int,input().split()) if (A+B)%2==0: ans=(B-A)//2 else: ans=min(A-1,N-B)+1+(B-A-1)//2 print(ans)
{ "input": [ "5 2 3", "5 2 4", "4 2 3", "5 2 8", "6 3 3", "6 3 5", "1 2 5", "0 3 4", "2 -1 0", "5 2 16", "5 2 27", "10 4 5", "5 1 27", "10 4 7", "6 0 28", "2 4 11", "0 2 27", "1 3 8", "0 3 27", "7 1 28", "7 0 12", "6 -1 36", "...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: 2N players are running a competitive table tennis training on N tables numbered from 1 to N. The training consists of rounds. In each round, the players form N pairs, one pair per ta...
p02959 AtCoder Beginner Contest 135 - City Savers_34153
There are N+1 towns. The i-th town is being attacked by A_i monsters. We have N heroes. The i-th hero can defeat monsters attacking the i-th or (i+1)-th town, for a total of at most B_i monsters. What is the maximum total number of monsters the heroes can cooperate to defeat? Constraints * All values in input are i...
N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) res = 0 for n in range(N): b = min(A[n], B[n]) B[n] -= b b2 = min(A[n + 1], B[n]) A[n + 1] -= b2 res += b + b2 print(res)
{ "input": [ "3\n5 6 3 8\n5 100 8", "2\n100 1 1\n1 100", "2\n3 5 2\n4 5", "3\n5 6 3 8\n2 100 8", "2\n100 0 1\n1 100", "2\n3 5 2\n7 5", "3\n0 6 3 8\n2 100 8", "2\n100 -1 1\n1 100", "2\n3 5 1\n7 5", "3\n0 4 3 8\n2 100 8", "2\n000 -1 1\n1 100", "2\n3 5 1\n0 5", "3\n0 4...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are N+1 towns. The i-th town is being attacked by A_i monsters. We have N heroes. The i-th hero can defeat monsters attacking the i-th or (i+1)-th town, for a total of at most ...
p03095 AtCoder Grand Contest 031 - Colorful Subsequence_34157
You are given a string S of length N. Among its subsequences, count the ones such that all characters are different, modulo 10^9+7. Two subsequences are considered different if their characters come from different positions in the string, even if they are the same as strings. Here, a subsequence of a string is a conca...
from collections import Counter n = int(input()) s = input() mod = 10**9+7 s_c = Counter(s) ans = 1 for c in s_c.values(): ans*=c+1 print((ans-1)%mod)
{ "input": [ "3\nbaa", "4\nabcd", "5\nabcab", "3\naab", "4\ndcba", "4\nbbcd", "3\nbac", "5\nbbbba", "5\naabbc", "3\naaa", "4\nadda", "5\nabcda", "4\nbbbb", "5\nbdacf", "5\nabcaa", "3\nabb", "5\nabbaa", "3\nbab", "4\ndcbb", "5\naabba", ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given a string S of length N. Among its subsequences, count the ones such that all characters are different, modulo 10^9+7. Two subsequences are considered different if their ...
p03241 AtCoder Beginner Contest 112 - Partition_34161
You are given integers N and M. Consider a sequence a of length N consisting of positive integers such that a_1 + a_2 + ... + a_N = M. Find the maximum possible value of the greatest common divisor of a_1, a_2, ..., a_N. Constraints * All values in input are integers. * 1 \leq N \leq 10^5 * N \leq M \leq 10^9 Input...
N ,M = map(int,input().split()) L = [] ans = 0 for i in range(1,int(M**(1/2)+1)): if M % i == 0: if i >= N: ans = max(ans,M//i) if M // i >= N: ans = max(ans,i) print(ans)
{ "input": [ "10 123", "3 14", "100000 1000000000", "5 123", "100000 1010000000", "110000 1010000000", "100100 1010000000", "5 16", "100100 1010010001", "101100 1010110000", "101100 1000110000", "101000 1000110010", "101000 1100110010", "101000 1100110011", ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given integers N and M. Consider a sequence a of length N consisting of positive integers such that a_1 + a_2 + ... + a_N = M. Find the maximum possible value of the greatest...
p03394 AtCoder Grand Contest 022 - GCD Sequence_34165
Nagase is a top student in high school. One day, she's analyzing some properties of special sets of positive integers. She thinks that a set S = \\{a_{1}, a_{2}, ..., a_{N}\\} of distinct positive integers is called special if for all 1 \leq i \leq N, the gcd (greatest common divisor) of a_{i} and the sum of the remai...
N = int(input()) M = 30001 if N == 3: print(2, 5, 63) exit() L = [3, 9] N -= 2 if N % 2 == 1: L.append(6) N -= 1 if N != 0: for i in range(2, M, 2): if i % 6 == 0: continue L.append(i) N -= 1 if N == 0: break if N % 2 == 1: N += 1 L.pop() if N != 0: for i in range(15, M, ...
{ "input": [ "3", "4" ], "output": [ "2 5 63", "2 5 20 63" ] }
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Nagase is a top student in high school. One day, she's analyzing some properties of special sets of positive integers. She thinks that a set S = \\{a_{1}, a_{2}, ..., a_{N}\\} of dis...
p03558 AtCoder Beginner Contest 077 - Small Multiple_34169
Find the smallest possible sum of the digits in the decimal notation of a positive multiple of K. Constraints * 2 \leq K \leq 10^5 * K is an integer. Input Input is given from Standard Input in the following format: K Output Print the smallest possible sum of the digits in the decimal notation of a positive mu...
from collections import deque k = int(input()) d = deque() mat = [] for i in range(k): mat.append([]) #mark = [False]*k dis = [10**18]*k dis[1] = 0 for i in range(k): mat[i].append(((i+1)%k,True)) if (10*i)%k != i: mat[i].append(((10*i)%k,False)) #bfs 1->0 d.append(1) res = 0 while d: left = d...
{ "input": [ "41", "6", "79992", "40", "37450", "70620", "9", "14", "11849", "48730", "198", "478", "10989", "10", "78", "8", "155", "45794", "100", "101", "25", "31", "47", "20", "17", "21", "4", "24", ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Find the smallest possible sum of the digits in the decimal notation of a positive multiple of K. Constraints * 2 \leq K \leq 10^5 * K is an integer. Input Input is given from Sta...
p03712 AtCoder Beginner Contest 062 - Picture Frame_34173
You are given a image with a height of H pixels and a width of W pixels. Each pixel is represented by a lowercase English letter. The pixel at the i-th row from the top and j-th column from the left is a_{ij}. Put a box around this image and output the result. The box should consist of `#` and have a thickness of 1. ...
h,w=list(map(int,input().split())) print('#'*(w+2)) for i in range(h): print('#'+input()+'#') print('#'*(w+2))
{ "input": [ "2 3\nabc\narc", "1 1\nz", "2 3\nabc\nbrc", "1 1\ny", "2 3\nabc\nbqc", "0 1\ny", "2 1\nabc\nbrc", "1 1\nx", "1 2\nz", "0 2\nz", "-2 0\nz", "-2 -1\nz", "1 -1\nz", "1 0\nz", "-20 3\nx", "-20 5\nx", "-20 6\nx", "1 0\nv", "2 3\nabc\n...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given a image with a height of H pixels and a width of W pixels. Each pixel is represented by a lowercase English letter. The pixel at the i-th row from the top and j-th colum...
p04034 AtCoder Grand Contest 002 - Box and Ball_34179
We have N boxes, numbered 1 through N. At first, box 1 contains one red ball, and each of the other boxes contains one white ball. Snuke will perform the following M operations, one by one. In the i-th operation, he randomly picks one ball from box x_i, then he puts it into box y_i. Find the number of boxes that may ...
n,m=map(int,input().split()) cnt=[1]*n res=[0]*n res[0]=1 for i in range(m): x,y=map(int,input().split()) if res[x-1]==1: res[y-1]=1 if cnt[x-1]==1: res[x-1]=0 cnt[x-1]-=1 cnt[y-1]+=1 print(sum(res))
{ "input": [ "3 2\n1 2\n2 3", "4 4\n1 2\n2 3\n4 1\n3 4", "3 3\n1 2\n2 3\n2 3", "6 2\n1 2\n2 3", "4 4\n1 2\n2 3\n4 1\n3 0", "6 2\n1 0\n2 6", "6 2\n1 2\n2 6", "6 2\n2 0\n2 6", "3 2\n1 0\n2 3", "4 4\n2 2\n2 3\n4 1\n3 4", "4 4\n1 2\n2 3\n4 1\n1 0", "6 2\n1 2\n4 6", "3 2...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: We have N boxes, numbered 1 through N. At first, box 1 contains one red ball, and each of the other boxes contains one white ball. Snuke will perform the following M operations, one ...
p00116 Rectangular Searching_34183
There are a total of W x H squares, with H rows vertically and W columns horizontally. Some squares are marked. Create a program that reads the marked state of each square and outputs the maximum rectangular area consisting of only the unmarked squares. The input data consists of one line of W characters, given H line...
while True: h, w = map(int, input().split()) if h == 0: break mp = [] for _ in range(h): lst = list(input()) cum = [] acc = 0 for i in lst: acc = acc + 1 if i == "." else 0 cum.append(acc) mp.append(cum) mp.append([-1] * w) ans = 0 for i in range(w): stack = [] ...
{ "input": [ "10 10\n...*....**\n..........\n**....**..\n........*.\n..*.......\n**........\n.*........\n..........\n....*..***\n.*....*...\n10 10\n..*....*..\n.*.*...*..\n*****..*..\n*...*..*..\n*...*..*..\n..........\n****.*...*\n..*..*...*\n.*...*...*\n****..***.\n2 3\n...\n...\n0 0", "10 10\n...*....**\n....
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are a total of W x H squares, with H rows vertically and W columns horizontally. Some squares are marked. Create a program that reads the marked state of each square and outputs...
p00430 Square_34188
There are n sheets of square paper of the same size. Align the bottom of these papers horizontally and arrange them in several rows. However, adjacent rows must be arranged so that the left side is not lower than the right side. For example, n When = 5, the following 7 ways of arranging are possible. <image> We wil...
def solve(): answers = [] def square(ans, rest, limit): if rest == 0: print(*ans) else: for i in range(rest, 0, -1): if i > limit: continue square(ans + [i], rest - i, i) import sys for n in map(int, sys.std...
{ "input": [ "5\n5\n0", "5\n8\n0", "5\n6\n0", "5\n7\n0", "5\n4\n0", "5\n3\n0", "5\n0\n0", "5\n9\n0", "5\n14\n0", "5\n1\n0", "5\n2\n0", "5\n12\n0", "5\n13\n0", "5\n10\n0", "5\n11\n0", "5\n26\n0", "5\n16\n0", "5\n24\n0", "5\n21\n0", "5\n20\...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are n sheets of square paper of the same size. Align the bottom of these papers horizontally and arrange them in several rows. However, adjacent rows must be arranged so that th...
p00901 ASCII Expression_34195
Mathematical expressions appearing in old papers and old technical articles are printed with typewriter in several lines, where a fixed-width or monospaced font is required to print characters (digits, symbols and spaces). Let us consider the following mathematical expression. <image> It is printed in the following f...
MOD = 2011 while 1: n = int(input()) if n == 0: break S = [input() for i in range(n)] w = len(S[0]) def parse(bcur, bright, top, bottom): #print("parse", bcur, bright, top, bottom) base = -1 for i in range(bcur, bright): for j in range(top, bottom+1): ...
{ "input": [ "4\n........4...2..........\n(.1.-.----.)..*.-.5.+.6\n........2..............\n.......3...............\n3\n...3.\n-.---\n...4.\n4\n.3.+.4.*.-.2.\n-------------\n..........2..\n...-.1.-.2...\n2\n...2..3\n(.4..).\n1\n2.+.3.*.5.-.7.+.9\n1\n(.2.+.3.).*.(.5.-.7.).+.9\n3\n.2....3.\n4..+.---\n......5.\n3\n....
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Mathematical expressions appearing in old papers and old technical articles are printed with typewriter in several lines, where a fixed-width or monospaced font is required to print c...
p01304 Heian-Kyo Walking_34201
Heiankyo is known as a town with a grid of roads. Hokusai, a cat who lives in Heiankyo, has to go from his home to a secret place on the outskirts of town every day for patrol. However, I get tired of following the same path every day, and there is a risk of being followed, so Hokusai wants to use a different route ev...
L = int(input().strip()) for _ in range(0,L): gx,gy = map(int,input().strip().split(" ")) heiankyo = [[0 for j in range(0,gx+1)] for i in range(0,gy+1)] heiankyo[0][0] = 1 P = int(input()) matatabi = [] for p in range(P): x1,y1,x2,y2 = map(int,input().strip().split(" ")) l = [[y1...
{ "input": [ "4\n2 2\n0\n1 1\n2\n0 0 0 1\n0 0 1 0\n4 3\n4\n1 0 0 0\n3 3 4 3\n4 1 4 0\n0 2 0 3\n15 15\n0", "4\n2 2\n0\n1 2\n2\n0 0 0 1\n0 0 1 0\n4 3\n4\n1 0 0 0\n3 3 4 3\n4 1 4 0\n0 2 0 3\n15 15\n0", "4\n2 2\n0\n1 2\n2\n0 0 0 1\n0 0 1 0\n4 3\n4\n1 0 0 0\n3 3 4 3\n4 0 4 0\n0 2 0 3\n15 3\n0", "4\n2 2\n0\...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Heiankyo is known as a town with a grid of roads. Hokusai, a cat who lives in Heiankyo, has to go from his home to a secret place on the outskirts of town every day for patrol. Howev...
p01473 Palindromic Anagram_34205
Problem statement Given the string $ S $. Find the number of all anagrams in $ S $ that are palindromic. An anagram of the string $ X $ is an anagram of $ Y $, which means that $ X $ is equal to $ Y $, or that the rearranged characters of $ X $ are equal to $ Y $. For example, for the string abcd, abcd and cbda are a...
import collections from math import * s=input() a=collections.Counter(s) o=0 for x in a: if a[x]&1: o+=1 if o>1:print(0);break a[x]-=1 else: b=factorial(len(s)//2) for x in a.values(): b//=factorial(x//2) print(b)
{ "input": [ "ab", "abba", "ac", "cbcb", "cc", "abca", "bc", "aaca", "cb", "aacb", "ca", "bacb", "bbca", "bcca", "accb", "ccca", "accc", "accd", "acce", "ecca", "edca", "acde", "`cde", "`bde", "`ade", "`dbe", "...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Problem statement Given the string $ S $. Find the number of all anagrams in $ S $ that are palindromic. An anagram of the string $ X $ is an anagram of $ Y $, which means that $ X ...
p02058 Tree_34211
G: Tree problem Given a tree consisting of N vertices. Each vertex of the tree is numbered from 1 to N. Of the N-1 edges, the i \ (= 1, 2, ..., N-1) edge connects the vertex u_i and the vertex v_i. Write a program to find the number of K non-empty subgraph sets of this tree, each of which is concatenated and no two ...
import sys def getpar(Edge, p): N = len(Edge) par = [0]*N par[0] = -1 par[p] -1 stack = [p] visited = set([p]) while stack: vn = stack.pop() for vf in Edge[vn]: if vf in visited: continue visited.add(vf) par[vf] = ...
{ "input": [ "3 2\n1 2\n1 3", "3 4\n1 2\n1 3", "3 2\n1 2\n2 3", "3 2\n2 2\n1 3", "3 1\n1 2\n2 3", "3 1\n1 2\n3 3", "1 2\n1 2\n2 3", "3 4\n1 2\n2 3", "1 1\n1 2\n2 3", "1 1\n2 2\n2 3", "1 1\n2 3\n2 3", "1 1\n2 3\n1 3", "1 2\n2 3\n1 3", "1 2\n2 3\n1 2", "1 2\n2...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: G: Tree problem Given a tree consisting of N vertices. Each vertex of the tree is numbered from 1 to N. Of the N-1 edges, the i \ (= 1, 2, ..., N-1) edge connects the vertex u_i and...
p02200 Today's Random Number_34213
Today's Random Number E869120 You ran a campaign called "Today's Random Numbers" for N days. This is a project to generate a random number once a day and post the value on Twitter. The "random numbers of the day" on day $ 1, 2, 3, \ dots, N $ were $ A_1, A_2, A_3, \ dots, A_N $, respectively. E869120 You would be ha...
N = int(input()) A = [int(i) for i in input().split()] ret = 0 for i in range(1, N) : if A[i] > A[i - 1] : ret += 1 print(ret)
{ "input": [ "5\n8 6 9 1 20", "5\n8 0 9 1 20", "5\n10 -2 3 1 0", "5\n3 -2 1 2 4", "5\n1 1 0 0 0", "5\n8 0 11 1 20", "5\n12 0 11 1 20", "5\n15 0 11 1 20", "5\n15 0 21 1 20", "5\n15 0 21 0 20", "5\n15 -1 21 0 20", "5\n15 -1 21 0 22", "5\n15 -1 3 0 22", "5\n15 -1 3...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Today's Random Number E869120 You ran a campaign called "Today's Random Numbers" for N days. This is a project to generate a random number once a day and post the value on Twitter. ...
p02354 The Smallest Window I_34217
For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $S$, find the smallest sub-array size (smallest window length) where the sum of the sub-array is greater than or equal to $S$. If there is not such sub-array, report 0. Constraints * $1 \leq N \leq 10^5$ * $1 \leq S \leq 10^9$ * $1 \leq a_i \...
#import pysnooper #import numpy #import os,re,sys,operator #from collections import Counter,deque #from operator import itemgetter #from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations from sys import stdin,setrecursionlimit from bisect import bisect_left #from copy import de...
{ "input": [ "6 4\n1 2 1 2 3 2", "6 6\n1 2 1 2 3 2", "3 7\n1 2 3", "6 4\n1 2 0 2 3 2", "6 6\n1 2 1 2 1 2", "6 5\n1 2 0 2 2 2", "6 5\n1 2 0 0 2 2", "6 5\n1 0 0 0 2 2", "6 5\n0 0 0 0 2 2", "6 4\n1 2 1 2 6 2", "6 5\n1 2 0 2 3 2", "6 6\n1 1 1 2 1 2", "6 5\n0 0 0 1 2 2",...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: For a given array $a_1, a_2, a_3, ... , a_N$ of $N$ elements and an integer $S$, find the smallest sub-array size (smallest window length) where the sum of the sub-array is greater th...
1010_D. Mars rover_34226
Natasha travels around Mars in the Mars rover. But suddenly it broke down, namely — the logical scheme inside it. The scheme is an undirected tree (connected acyclic graph) with a root in the vertex 1, in which every leaf (excluding root) is an input, and all other vertices are logical elements, including the root, whi...
import sys input=sys.stdin.readline n=int(input()) stack=[] children=[] for i in range(n): children.append([]) parent=[-1]*n nodes=[-1]*n inputs=[] functions=[-1]*n for i in range(n): a=list(map(str,input().split())) r=a[0] if r=='IN': stack.append((i,int(a[1]))) inputs.append(i) elif r=='NOT': pa...
{ "input": [ "10\nAND 9 4\nIN 1\nIN 1\nXOR 6 5\nAND 3 7\nIN 0\nNOT 10\nIN 1\nIN 1\nAND 2 8\n", "20\nOR 17 10\nIN 0\nIN 0\nNOT 6\nOR 18 14\nIN 1\nOR 16 3\nXOR 5 4\nIN 0\nXOR 11 9\nNOT 15\nAND 20 19\nIN 0\nIN 1\nIN 1\nNOT 8\nNOT 12\nIN 1\nAND 13 7\nNOT 2\n", "2\nNOT 2\nIN 1\n", "3\nXOR 2 3\nIN 0\nIN 0\n...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Natasha travels around Mars in the Mars rover. But suddenly it broke down, namely — the logical scheme inside it. The scheme is an undirected tree (connected acyclic graph) with a roo...
1057_A. Bmail Computer Network_34232
Once upon a time there was only one router in the well-known company Bmail. Years went by and over time new routers were purchased. Every time they bought a new router, they connected it to one of the routers bought before it. You are given the values p_i — the index of the router to which the i-th router was connected...
n=int(input()) a=list(map(int,input().split())) if len(set(a))==n: a.append(n) print(*a) else: a.insert(0,0) b=[n] x=n while x!=1: b.append(a[x-1]) x=a[x-1] print(*b[::-1])
{ "input": [ "8\n1 1 2 2 3 2 5\n", "6\n1 2 3 4 5\n", "7\n1 1 2 3 4 3\n", "7\n1 1 3 4 1 2\n", "3\n1 1\n", "4\n1 1 2\n", "6\n1 1 1 4 1\n", "9\n1 2 2 4 1 2 4 4\n", "4\n1 2 2\n", "10\n1 1 1 3 3 5 6 8 3\n", "7\n1 1 1 1 1 2\n", "10\n1 2 2 4 5 5 6 4 7\n", "8\n1 1 1 1 2 1 3...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Once upon a time there was only one router in the well-known company Bmail. Years went by and over time new routers were purchased. Every time they bought a new router, they connected...
109_D. Lucky Sorting_34238
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya got an array consisting of n numbers, it is the gift for his birthday. Now he wants to sort it...
#!/usr/bin/env python3 def is_lucky(v): while v > 0: r = v % 10 if r != 4 and r != 7: return False v //= 10 return True n = int(input()) arr = list(map(int, input().split())) arr_with_pos = sorted([[a, i] for i, a in enumerate(arr)]) pos, tpos = None, None # pos and targ...
{ "input": [ "3\n4 2 1\n", "7\n77 66 55 44 33 22 11\n", "2\n4 7\n", "10\n8 4 7 5 9 5 8 5 10 1000\n", "50\n6 2 5 6 5 5 1 5 7 2 3 7 3 1 9 1 6 6 8 1 4 7 1 7 6 2 6 2 6 4 2 9 8 2 3 2 4 3 2 4 6 4 4 9 8 2 8 8 1 5\n", "5\n4 7 47 744 1\n", "100\n3 2 4 2 2 2 3 1 2 3 1 4 1 4 1 2 3 3 3 2 3 1 2 1 2 3 3...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, ...
1169_B. Pairs_34246
Toad Ivan has m pairs of integers, each integer is between 1 and n, inclusive. The pairs are (a_1, b_1), (a_2, b_2), …, (a_m, b_m). He asks you to check if there exist two integers x and y (1 ≤ x < y ≤ n) such that in each given pair at least one integer is equal to x or y. Input The first line contains two space-s...
bound, m = [int(x) for x in input().split()] if m == 1: print("YES") exit(0) pairs_uniq = set() for _ in range(m): x = [int(x) for x in input().split()] x.sort() pairs_uniq.add((x[0], x[1])) if len(pairs_uniq) == 1: print("YES") exit(0) pairs = [x for x in pairs_uniq] # Choose the first...
{ "input": [ "300000 5\n1 2\n1 2\n1 2\n1 2\n1 2\n", "5 4\n1 2\n2 3\n3 4\n4 5\n", "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n", "6 9\n6 2\n4 2\n3 6\n4 6\n2 6\n1 4\n2 6\n4 5\n4 2\n", "5 8\n1 2\n1 3\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5\n", "4 4\n1 2\n2 3\n3 1\n1 4\n", "4 3\n1 2\n2 3\n3 4\n", "4 3\n1 2\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Toad Ivan has m pairs of integers, each integer is between 1 and n, inclusive. The pairs are (a_1, b_1), (a_2, b_2), …, (a_m, b_m). He asks you to check if there exist two integers ...
1187_D. Subarray Sorting_34250
You are given an array a_1, a_2, ..., a_n and an array b_1, b_2, ..., b_n. For one operation you can sort in non-decreasing order any subarray a[l ... r] of the array a. For example, if a = [4, 2, 2, 1, 3, 1] and you choose subbarray a[2 ... 5], then the array turns into [4, 1, 2, 2, 3, 1]. You are asked to determi...
from sys import stdin, stdout from collections import defaultdict t = int(stdin.readline()) inf = 10**6 def merge_sort(order, a): if len(order) == 1: return order, a mid = (len(order) + 1) // 2 left_o, left_a = merge_sort(order[:mid], a[:mid]) right_o, right_a = merge_sort(order[mid:], a[mid:]...
{ "input": [ "4\n7\n1 7 1 4 4 5 6\n1 1 4 4 5 7 6\n5\n1 1 3 3 5\n1 1 3 3 5\n2\n1 1\n1 2\n3\n1 2 3\n3 2 1\n", "1\n5\n4 4 4 4 4\n5 5 5 5 5\n", "1\n8\n7 8 6 4 6 4 2 3\n2 4 7 6 4 8 3 6\n", "1\n9\n5 4 3 2 1 3 2 2 1\n1 2 3 4 1 2 2 3 5\n", "1\n5\n3 1 2 4 5\n2 5 4 3 1\n", "1\n10\n10 9 8 7 6 5 4 3 2 1\n...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given an array a_1, a_2, ..., a_n and an array b_1, b_2, ..., b_n. For one operation you can sort in non-decreasing order any subarray a[l ... r] of the array a. For example...
1206_C. Almost Equal_34254
You are given integer n. You have to arrange numbers from 1 to 2n, using each of them exactly once, on the circle, so that the following condition would be satisfied: For every n consecutive numbers on the circle write their sum on the blackboard. Then any two of written on the blackboard 2n numbers differ not more th...
n=int(input()) if n%2==0: print('NO') else: print('YES') ans=1 c=3 for i in range(n): if i==0: print(ans,end=' ') else: print(ans+c,end=' ') ans=ans+c c=1 if c==3 else 3 ans=2 c=1 for i in range(n): if i==0: ...
{ "input": [ "4\n", "3\n", "100000\n", "64\n", "2\n", "11\n", "4097\n", "6\n", "1024\n", "9\n", "14786\n", "78946\n", "10\n", "5\n", "65\n", "14785\n", "63\n", "4096\n", "1\n", "80\n", "4045\n", "7\n", "831\n", "95\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given integer n. You have to arrange numbers from 1 to 2n, using each of them exactly once, on the circle, so that the following condition would be satisfied: For every n con...
1249_B2. Books Exchange (hard version)_34260
The only difference between easy and hard versions is constraints. There are n kids, each of them is reading a unique book. At the end of any day, the i-th kid will give his book to the p_i-th kid (in case of i = p_i the kid will give his book to himself). It is guaranteed that all values of p_i are distinct integers ...
q = int(input()) for _ in range(q): n = int(input()) succ = list(map(lambda x: int(x) -1 ,input().split())) cycle_belong = [-1 for k in range(n)] cycle_size = [] for k in range(n): if cycle_belong[k] == -1 : # not visited yet start = k current = k cycle_be...
{ "input": [ "6\n5\n1 2 3 4 5\n3\n2 3 1\n6\n4 6 2 1 5 3\n1\n1\n4\n3 4 1 2\n5\n5 1 2 4 3\n", "20\n6\n3 6 4 2 5 1\n6\n2 4 1 3 5 6\n7\n5 2 1 4 6 7 3\n6\n3 6 4 2 5 1\n9\n5 8 2 6 4 7 9 1 3\n9\n3 2 6 8 5 7 9 1 4\n8\n8 4 6 5 2 1 7 3\n5\n3 1 2 5 4\n10\n2 4 3 5 6 10 7 9 1 8\n2\n2 1\n1\n1\n5\n3 2 5 4 1\n3\n1 3 2\n8\n2 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: The only difference between easy and hard versions is constraints. There are n kids, each of them is reading a unique book. At the end of any day, the i-th kid will give his book to ...
128_C. Games with Rectangle_34265
In this task Anna and Maria play the following game. Initially they have a checkered piece of paper with a painted n × m rectangle (only the border, no filling). Anna and Maria move in turns and Anna starts. During each move one should paint inside the last-painted rectangle a new lesser rectangle (along the grid lines...
from math import factorial MOD = 1000000007 def c(n, k): if k > n: return 0 return factorial(n) //(factorial(k) * factorial(n - k)) n, m, k = map(int, input().split()) print ((c(n - 1, 2 * k) * c(m - 1, 2 * k)) % MOD)
{ "input": [ "6 7 2\n", "4 4 1\n", "3 3 1\n", "307 190 52\n", "456 876 1000\n", "705 155 490\n", "711 390 95\n", "840 474 207\n", "999 996 247\n", "277 939 15\n", "5 5 3\n", "580 1000 203\n", "340 124 41\n", "351 286 60\n", "897 301 47\n", "980 811 236\n...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: In this task Anna and Maria play the following game. Initially they have a checkered piece of paper with a painted n × m rectangle (only the border, no filling). Anna and Maria move i...
1332_D. Walk on Matrix_34269
Bob is playing a game named "Walk on Matrix". In this game, player is given an n × m matrix A=(a_{i,j}), i.e. the element in the i-th row in the j-th column is a_{i,j}. Initially, player is located at position (1,1) with score a_{1,1}. To reach the goal, position (n,m), player can move right or down, i.e. move from ...
k = int(input()) arr = [[0, k, 0], [0, 0, k]] length = 0 t = k while t > 0: t >>= 1 length += 1 # print(((1 << length) - 1) ^ k) arr[1][1] = (1 << length) + k arr[1][0] = (1 << length) + (((1 << length) - 1) ^ k) arr[0][0] = (1 << (length + 1)) - 1 print(2, 3) for i in arr: print(*i)
{ "input": [ "1\n", "0\n", "79585\n", "66536\n", "66518\n", "66529\n", "66517\n", "36871\n", "66521\n", "66549\n", "66539\n", "66537\n", "99996\n", "66547\n", "96046\n", "66525\n", "48716\n", "76\n", "139\n", "357\n", "99993\n", "...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Bob is playing a game named "Walk on Matrix". In this game, player is given an n × m matrix A=(a_{i,j}), i.e. the element in the i-th row in the j-th column is a_{i,j}. Initially, pl...
1352_G. Special Permutation_34273
A permutation of length n is an array p=[p_1,p_2,...,p_n], which contains every integer from 1 to n (inclusive) and, moreover, each number appears exactly once. For example, p=[3,1,4,2,5] is a permutation of length 5. For a given number n (n ≥ 2), find a permutation p in which absolute difference (that is, the absolut...
""" Author: guiferviz Time: 2020-05-09 16:35:02 """ def solve(): n = int(input()) if n < 4: print(-1) elif n == 4: print("3 1 4 2") else: sol = [] i = 1 while i <= n: sol.append(i) i += 2 i = sol[-1] val = i - 3 i +...
{ "input": [ "6\n10\n2\n4\n6\n7\n13\n", "7\n4\n3\n5\n4\n4\n4\n4\n", "100\n105\n191\n182\n133\n132\n175\n177\n154\n131\n187\n152\n118\n156\n199\n121\n164\n163\n160\n151\n114\n185\n139\n144\n123\n115\n184\n138\n190\n106\n102\n135\n186\n107\n162\n192\n147\n153\n165\n119\n140\n113\n146\n172\n104\n136\n142\n17...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: A permutation of length n is an array p=[p_1,p_2,...,p_n], which contains every integer from 1 to n (inclusive) and, moreover, each number appears exactly once. For example, p=[3,1,4,...
1372_E. Omkar and Last Floor_34276
Omkar is building a house. He wants to decide how to make the floor plan for the last floor. Omkar's floor starts out as n rows of m zeros (1 ≤ n,m ≤ 100). Every row is divided into intervals such that every 0 in the row is in exactly 1 interval. For every interval for every row, Omkar can change exactly one of the 0s...
from bisect import * import sys int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number...
{ "input": [ "4 5\n2\n1 2\n3 5\n2\n1 3\n4 5\n3\n1 1\n2 4\n5 5\n3\n1 1\n2 2\n3 5\n", "7 8\n1\n1 8\n2\n1 5\n6 8\n4\n1 1\n2 2\n3 4\n5 8\n4\n1 3\n4 4\n5 5\n6 8\n2\n1 7\n8 8\n2\n1 6\n7 8\n3\n1 1\n2 2\n3 8\n", "3 3\n3\n1 1\n2 2\n3 3\n3\n1 1\n2 2\n3 3\n3\n1 1\n2 2\n3 3\n", "1 100\n10\n1 3\n4 10\n11 17\n18 48...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Omkar is building a house. He wants to decide how to make the floor plan for the last floor. Omkar's floor starts out as n rows of m zeros (1 ≤ n,m ≤ 100). Every row is divided into ...
1395_D. Boboniu Chats with Du_34280
Have you ever used the chat application QQ? Well, in a chat group of QQ, administrators can muzzle a user for days. In Boboniu's chat group, there's a person called Du Yi who likes to make fun of Boboniu every day. Du will chat in the group for n days. On the i-th day: * If Du can speak, he'll make fun of Boboniu ...
n, d, m = map(int, input().split()) a = list(map(int, input().split())) less = [] more = [] for i in a: if i>m: more.append(i) else: less.append(i) less.sort(reverse = True) more.sort(reverse = True) lessp = [] if len(less)>0: lessp = [less[0]] for i in less[1:]: lessp.append(lessp[-1]+i) morep = [] ...
{ "input": [ "20 2 16\n20 5 8 2 18 16 2 16 16 1 5 16 2 13 6 16 4 17 21 7\n", "5 2 11\n8 10 15 23 5\n", "1 1 0\n0\n", "10 3 10\n17 17 17 8 7 6 5 4 1 1\n", "100 61 71\n11 18 0 47 33 75 91 13 8 21 73 64 50 97 62 50 2 36 68 32 64 74 32 77 81 41 23 44 40 36 45 33 21 68 57 79 75 23 67 37 99 27 30 56 75 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Have you ever used the chat application QQ? Well, in a chat group of QQ, administrators can muzzle a user for days. In Boboniu's chat group, there's a person called Du Yi who likes t...
1419_F. Rain of Fire_34283
There are n detachments on the surface, numbered from 1 to n, the i-th detachment is placed in a point with coordinates (x_i, y_i). All detachments are placed in different points. Brimstone should visit each detachment at least once. You can choose the detachment where Brimstone starts. To move from one detachment to...
# import numpy as npy import functools import math n=int(input()) x=[0 for i in range(n+2)] y=[0 for i in range(n+2)] adj=[[] for i in range(n+2)] idx=[] idy=[] for i in range(n): x[i],y[i]=map(int,input().split()) idx.append(i) idy.append(i) def cmpx(a,b): if x[a]!=x[b]: if x[a]<x[b]: ...
{ "input": [ "7\n0 2\n1 0\n-3 0\n0 -2\n-1 -1\n-1 -3\n-2 -3\n", "5\n0 0\n2 0\n0 -1\n-2 0\n-2 1\n", "4\n100 0\n0 100\n-100 0\n0 -100\n", "5\n0 0\n0 -1\n3 0\n-2 0\n-2 1\n", "5\n1626381 1696233\n1626265 1696001\n1626381 1696117\n1626497 1696001\n1626381 1695885\n", "6\n-954200 -227581\n-954261 -22...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are n detachments on the surface, numbered from 1 to n, the i-th detachment is placed in a point with coordinates (x_i, y_i). All detachments are placed in different points. Br...
1462_E1. Close Tuples (easy version)_34289
This is the easy version of this problem. The only difference between easy and hard versions is the constraints on k and m (in this version k=2 and m=3). Also, in this version of the problem, you DON'T NEED to output the answer by modulo. You are given a sequence a of length n consisting of integers from 1 to n. The s...
#input = sys.stdin.readline import os import sys from io import BytesIO, IOBase import heapq as h import bisect from types import GeneratorType BUFSIZE = 8192 class SortedList: def __init__(self, iterable=[], _load=200): """Initialize sorted list instance.""" values = sorted(itera...
{ "input": [ "4\n4\n1 2 4 3\n4\n1 1 1 1\n1\n1\n10\n5 6 1 3 2 9 8 1 2 4\n", "3\n1\n1\n1\n1\n1\n1\n", "2\n5\n1 1 1 1 1\n4\n1 1 1 1\n", "10\n3\n1 1 1\n1\n1\n4\n3 4 3 3\n1\n1\n7\n7 1 1 5 3 6 5\n3\n2 2 1\n9\n4 1 7 1 1 6 7 1 7\n5\n2 5 3 4 3\n1\n1\n9\n8 9 5 7 4 1 2 5 4\n", "2\n2\n2 2\n1\n1\n", "10\n3...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: This is the easy version of this problem. The only difference between easy and hard versions is the constraints on k and m (in this version k=2 and m=3). Also, in this version of the ...
1487_F. Ones_34293
You are given a positive (greater than zero) integer n. You have to represent n as the sum of integers (possibly negative) consisting only of ones (digits '1'). For example, 24 = 11 + 11 + 1 + 1 and 102 = 111 - 11 + 1 + 1. Among all possible representations, you have to find the one that uses the minimum number of o...
def ones(a): return (10 ** a - 1) // 9 def add_in_dict(dct, key, val): if key in dct: dct[key] = min(dct[key], val) else: dct[key] = val _s = input() _n = len(_s) _x = int(_s) cur_dict = {} cur_dict[_x] = 0 for i in range(_n + 1, 0, -1): ns = ones(i) new_dict = {} for x i...
{ "input": [ "24\n", "102\n", "1\n", "25011428282808773575\n", "7361918244654780790014643\n", "412686535537807118767857480321109460298267404\n", "1538780506138269474552303704695154678\n", "61728395061728395061728395061728395061345382132589\n", "8046050617632588469774950623387168521...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given a positive (greater than zero) integer n. You have to represent n as the sum of integers (possibly negative) consisting only of ones (digits '1'). For example, 24 = 11 ...
1511_C. Yet Another Card Deck_34297
You have a card deck of n cards, numbered from top to bottom, i. e. the top card has index 1 and bottom card — index n. Each card has its color: the i-th card has color a_i. You should process q queries. The j-th query is described by integer t_j. For each query you should: * find the highest card in the deck with...
N, Q = map(int, input().split()) A = list(map(int, input().split())) T = list(map(int, input().split())) inds = [0]*51 for i in range(N): if inds[A[i]]==0: inds[A[i]] = i+1 ans = [] for i in range(Q): ans.append(inds[T[i]]) for c in range(1,51): if inds[c]<inds[T[i]]: inds[c] += 1 inds[T[i]] = 1 p...
{ "input": [ "7 5\n2 1 1 4 3 3 1\n3 2 1 1 4\n", "5 2\n6 4 3 2 1\n1 6\n", "5 1\n1 2 3 4 5\n1\n", "7 5\n20 10 10 40 30 30 10\n30 20 10 10 40\n", "5 15\n1 2 3 4 5\n5 5 5 5 5 5 5 5 5 5 5 5 5 5 5\n", "5 4\n3 15 50 50 3\n50 15 3 50\n", "7 5\n20 10 20 40 30 30 10\n30 20 10 10 40\n", "5 15\n1 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You have a card deck of n cards, numbered from top to bottom, i. e. the top card has index 1 and bottom card — index n. Each card has its color: the i-th card has color a_i. You shou...
1539_A. Contest Start_34301
There are n people participating in some contest, they start participating in x minutes intervals. That means the first participant starts at time 0, the second participant starts at time x, the third — at time 2 ⋅ x, and so on. Duration of contest is t minutes for each participant, so the first participant finishes t...
def solve(n, x, t): d = min(t // x, n) print(d * (n - d) + d * (d - 1) // 2) def main(): for _ in range(int(input())): solve(*map(int, input().split())) if __name__ == '__main__': main()
{ "input": [ "4\n4 2 5\n3 1 2\n3 3 10\n2000000000 1 2000000000\n", "1\n8627 2 2\n", "10\n2000000000 2000000000 2000000000\n2000000000 1 2000000000\n2000000000 1 1999999998\n1999999990 1 2000000000\n2000000000 3 2000000000\n2000000000 2000000000 1999999998\n1 1 1\n99990 10 1000000\n100000 20000 2000000000\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are n people participating in some contest, they start participating in x minutes intervals. That means the first participant starts at time 0, the second participant starts at ...
165_C. Another Problem on Strings_34305
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
def main(): k, s = lie(), input() n = len(s) dp = [-1] for i in range(n): if s[i] == '1': dp.append(i) dp.append(n) if len(dp) - 2 < k: print(0) elif k == 0: ans = 0 for i in range(1, len(dp)): ans += (dp[i] - dp[i - 1] - 1) * (dp[i] - ...
{ "input": [ "2\n01010\n", "1\n1010\n", "100\n01010\n", "0\n0010100011\n", "0\n00\n", "94\n111111111111010111100111111111111011011111111011111111111011111111111111101111101111110111011111111110011111111001111101111\n", "1\n00\n", "0\n11\n", "2\n00\n", "0\n000\n", "0\n01010\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in stri...
186_D. Mushroom Scientists_34309
As you very well know, the whole Universe traditionally uses three-dimensional Cartesian system of coordinates. In this system each point corresponds to three real coordinates (x, y, z). In this coordinate system, the distance between the center of the Universe and the point is calculated by the following formula: <ima...
S = int(input()) v = [int(x) for x in input().strip().split()] zeroes = v.count(0) total = sum(v) ans = [] if zeroes == 0: ans = [S * v[i] / total for i in range(3)] elif zeroes == 1: for i in range(3): if v[i] == 0: total -= v[i] for i in range(3): if v[i] != 0: ans....
{ "input": [ "3\n2 0 0\n", "3\n1 1 1\n", "1000\n1 0 1\n", "1\n1000 1000 1000\n", "3\n0 0 0\n", "10\n0 0 0\n", "173\n0 0 374\n", "492\n971 305 807\n", "239\n995 385 267\n", "624\n553 828 109\n", "814\n711 408 545\n", "9\n8 2 0\n", "1000\n999 998 997\n", "422\n215...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: As you very well know, the whole Universe traditionally uses three-dimensional Cartesian system of coordinates. In this system each point corresponds to three real coordinates (x, y, ...
258_D. Little Elephant and Broken Sorting_34317
The Little Elephant loves permutations of integers from 1 to n very much. But most of all he loves sorting them. To sort a permutation, the Little Elephant repeatedly swaps some elements. As a result, he must receive a permutation 1, 2, 3, ..., n. This time the Little Elephant has permutation p1, p2, ..., pn. Its sort...
inp = input().split(' ') val=[]; totNums = int(inp[0]); totOpt = int(inp[1]); inp = input().split(' '); #assert(len(inp) == totNums); for it in inp: val.append(int(it)) dp = [[0.0 for _ in range(0,totNums)] for __ in range(0,totNums)] for i in range(0,totNums): for j in range(0,totNums): if val[i]>val[j]:...
{ "input": [ "4 3\n1 3 2 4\n1 2\n2 3\n1 4\n", "2 1\n1 2\n1 2\n", "125 8\n111 69 3 82 24 38 4 39 42 22 92 6 16 10 8 45 17 91 84 53 5 46 124 47 18 57 43 73 114 102 121 105 118 95 104 98 72 20 56 60 123 80 103 70 65 107 67 112 101 108 99 49 12 94 2 68 119 109 59 40 86 116 88 63 110 14 13 120 41 64 89 71 15 3...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: The Little Elephant loves permutations of integers from 1 to n very much. But most of all he loves sorting them. To sort a permutation, the Little Elephant repeatedly swaps some eleme...
281_D. Maximum Xor Secondary_34321
Bike loves looking for the second maximum element in the sequence. The second maximum element in the sequence of distinct numbers x1, x2, ..., xk (k > 1) is such maximum element xj, that the following inequality holds: <image>. The lucky number of the sequence of distinct positive integers x1, x2, ..., xk (k > 1) is t...
#https://codeforces.com/problemset/problem/281/D def empty(l): return len(l) == 0 def lucky_number(arr): st = [] l = 0 for d in arr: while not empty(st) and st[-1] < d: l = max(l, st.pop() ^ d) if not empty(st): l = max(l, st[-1] ^ d) st.append(d) ...
{ "input": [ "5\n9 8 3 5 7\n", "5\n5 2 1 4 3\n", "10\n4547989 39261040 94929326 38131456 26174500 7152864 71295827 77784626 89898294 68006331\n", "10\n3106954 3413954 3854371 85952704 17834583 20954227 58810981 7460648 97908613 97965110\n", "10\n73622246 45316865 2066146 61168230 1258786 69603039 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Bike loves looking for the second maximum element in the sequence. The second maximum element in the sequence of distinct numbers x1, x2, ..., xk (k > 1) is such maximum element xj, t...
304_C. Lucky Permutation Triple_34325
Bike is interested in permutations. A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] is not. A permutation triple of permutations of length n (a, b, c) is called a...
r = int(input()) if r % 2 == 0: print (-1) elif r == 1: print(0) print(0) print(0) else: for i in range(r): print(i,end=" ") print() i = r - 1 while i >= 0: print(i,end=" ") i -= 2 i = r - 2 while i >= 0: print(i,end=" ") i -= 2 print(...
{ "input": [ "2\n", "5\n", "11805\n", "46684\n", "87\n", "74320\n", "5014\n", "54\n", "16586\n", "41904\n", "1\n", "5684\n", "39\n", "77\n", "34\n", "99998\n", "16968\n", "32\n", "52\n", "99182\n", "72\n", "72598\n", "6\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Bike is interested in permutations. A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, [0, 2, 1] is a p...
352_B. Jeff and Periods_34332
One day Jeff got hold of an integer sequence a1, a2, ..., an of length n. The boy immediately decided to analyze the sequence. For that, he needs to find all values of x, for which these conditions hold: * x occurs in sequence a. * Consider all positions of numbers x in the sequence a (such i, that ai = x). These...
le = int(input()) integers = [int(i) for i in str(input()).split(" ")] d = {} for index, ele in enumerate(integers): # should already be sorted if ele in d: d[ele].append(index) else: d[ele] = [index] ans = [] for key, items in d.items(): if len(items) == 1: ans.append((key, 0))...
{ "input": [ "8\n1 2 1 3 1 2 1 5\n", "1\n2\n", "9\n2 3 3 3 2 1 2 3 2\n", "10\n3 1 1 1 1 3 1 2 2 1\n", "4\n9 9 3 5\n", "7\n2 1 2 1 2 1 2\n", "12\n10 9 8 7 7 8 9 10 10 9 8 7\n", "8\n1 1 1 1 1 1 1 1\n", "3\n1 10 5\n", "6\n2 6 3 8 7 2\n", "6\n1 2 2 1 1 2\n", "10\n6 1 1 1 1 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: One day Jeff got hold of an integer sequence a1, a2, ..., an of length n. The boy immediately decided to analyze the sequence. For that, he needs to find all values of x, for which th...
376_C. Divisible by Seven_34336
You have number a, whose decimal representation quite luckily contains digits 1, 6, 8, 9. Rearrange the digits in its decimal representation so that the resulting number will be divisible by 7. Number a doesn't contain any leading zeroes and contains digits 1, 6, 8, 9 (it also can contain another digits). The resultin...
a=input() cnt=[0]*10 for i in (1,6,8,9): cnt[i]=-1 for i in a: cnt[int(i)]+=1 mod = [1869, 1968, 9816, 6198, 1698, 1986, 1896, 1869] modCnt=0 for i in range(1,10): for j in range(cnt[i]): modCnt= (modCnt*3 + i)%7 print(str(i)*cnt[i], end='') modCnt=(10000*modCnt)%7 print(str(mod[7-modCnt])+'0'*cnt[0]...
{ "input": [ "1689\n", "18906\n", "100000000689\n", "2717172350336955863014903670481525170997949309274087058935108848979319747543008692128164875210350026\n", "91111168\n", "9883291673084\n", "16896\n", "98259956560402867931280060472685476100686992144778429958732866073466398163149080213...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You have number a, whose decimal representation quite luckily contains digits 1, 6, 8, 9. Rearrange the digits in its decimal representation so that the resulting number will be divis...
421_A. Pasha and Hamsters_34341
Pasha has two hamsters: Arthur and Alexander. Pasha put n apples in front of them. Pasha knows which apples Arthur likes. Similarly, Pasha knows which apples Alexander likes. Pasha doesn't want any conflict between the hamsters (as they may like the same apple), so he decided to distribute the apples between the hamste...
n, a, b = map(int, input().split()) x = set(map(int, input().split())) y = set(map(int, input().split())) y -= x s = "" for i in range(1, n + 1, 1): if i in x: s += str(1) + " " else: s += str(2) + " " print(s)
{ "input": [ "5 5 2\n3 4 1 2 5\n2 3\n", "4 2 3\n1 2\n2 3 4\n", "98 88 10\n1 2 4 5 6 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 33 34 35 36 38 39 40 41 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 62 63 64 65 66 67 68 69 71 72 73 74 75 76 77 79 80 81 83 84 85 86 87 88 89...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Pasha has two hamsters: Arthur and Alexander. Pasha put n apples in front of them. Pasha knows which apples Arthur likes. Similarly, Pasha knows which apples Alexander likes. Pasha do...
469_E. Hack it!_34347
Little X has met the following problem recently. Let's define f(x) as the sum of digits in decimal representation of number x (for example, f(1234) = 1 + 2 + 3 + 4). You are to calculate <image> Of course Little X has solved this problem quickly, has locked it, and then has tried to hack others. He has seen the foll...
m = int(input()) x,t=10**100-1,m-100*45*10**99%m print(t,t+x)
{ "input": [ "46\n", "126444381000032\n", "450000000000000000\n", "81696185182\n", "85058261498638\n", "10000000000000000\n", "3\n", "100000000000000\n", "22881472397923\n", "1\n", "5\n", "8\n", "11\n", "69645082595\n", "2\n", "3\n", "999999999999999...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Little X has met the following problem recently. Let's define f(x) as the sum of digits in decimal representation of number x (for example, f(1234) = 1 + 2 + 3 + 4). You are to calc...
492_A. Vanya and Cubes_34351
Vanya got n cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1 + 2 = 3 cubes, the third level must have 1 + 2 + 3 = 6 cubes, and so on. Thus, the i-th level of the pyramid must have 1 + 2 + ...
n=int(input()) i=1;x=0 while 1: x+=(i*(i+1)/2) if x==n: print(i) break elif x>n: print(i-1) break i+=1
{ "input": [ "25\n", "1\n", "219\n", "6560\n", "19\n", "9999\n", "9880\n", "7769\n", "9894\n", "7590\n", "10000\n", "20\n", "2925\n", "220\n", "3\n", "4115\n", "9879\n", "4\n", "7142\n", "5\n", "1014\n", "2\n", "7770\n", "...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Vanya got n cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must con...
542_F. Quest_34357
Polycarp is making a quest for his friends. He has already made n tasks, for each task the boy evaluated how interesting it is as an integer qi, and the time ti in minutes needed to complete the task. An interesting feature of his quest is: each participant should get the task that is best suited for him, depending o...
from collections import defaultdict if __name__ == '__main__': n, T = [int(_) for _ in input().split()] data = defaultdict(list) for i in range(n): t, q = [int(_) for _ in input().split()] data[T - t].append(q) prev_level = [] for level_id in range(1, T + 1): level = sorte...
{ "input": [ "5 5\n1 1\n1 1\n2 2\n3 3\n4 4\n", "5 5\n4 1\n4 2\n4 3\n4 4\n4 5\n", "2 2\n1 1\n2 10\n", "10 9\n1 518\n3 971\n5 862\n2 71\n8 138\n4 121\n6 967\n1 518\n9 754\n7 607\n", "17 1\n1 632\n1 996\n1 665\n1 432\n1 565\n1 350\n1 857\n1 183\n1 982\n1 910\n1 938\n1 155\n1 176\n1 168\n1 419\n1 814\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Polycarp is making a quest for his friends. He has already made n tasks, for each task the boy evaluated how interesting it is as an integer qi, and the time ti in minutes needed to c...
56_B. Spoilt Permutation_34361
Vasya collects coins: he has exactly one coin for every year from 1 to n. Naturally, Vasya keeps all the coins in his collection in the order in which they were released. Once Vasya's younger brother made a change — he took all the coins whose release year dated from l to r inclusively and put them in the reverse order...
n = int(input()) l = list(map(int,input().split())) v = l.copy() v.sort() i = 0 j = 0 l1 = [] l2 = [] ans = [] while i<n and j<n: if l[i] == v[j]: i+=1 j+=1 else: l1.append(v[j]) l2.append(l[i]) ans.append(j) j+=1 i+=1 l2.reverse() if l1 == l2 and len(a...
{ "input": [ "8\n1 6 5 4 3 2 7 8\n", "4\n2 3 4 1\n", "4\n1 2 3 4\n", "8\n1 3 2 4 6 5 7 8\n", "1\n1\n", "8\n1 3 4 2 6 5 7 8\n", "2\n1 2\n", "2\n2 1\n", "4\n1 2 4 3\n", "35\n7 33 34 15 16 24 5 27 1 19 17 22 29 3 4 23 31 11 21 35 32 2 12 20 8 9 6 28 18 26 30 14 13 10 25\n", "1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Vasya collects coins: he has exactly one coin for every year from 1 to n. Naturally, Vasya keeps all the coins in his collection in the order in which they were released. Once Vasya's...
612_D. The Union of k-Segments_34366
You are given n segments on the coordinate axis Ox and the number k. The point is satisfied if it belongs to at least k segments. Find the smallest (by the number of segments) set of segments on the coordinate axis Ox which contains all satisfied points and no others. Input The first line contains two integers n and ...
#### IMPORTANT LIBRARY #### ############################ ### DO NOT USE import random --> 250ms to load the library ############################ ### In case of extra libraries: https://github.com/cheran-senthil/PyRival ###################### ####### IMPORT ####### ###################### from functools import cmp_to...
{ "input": [ "3 2\n0 5\n-3 2\n3 8\n", "3 2\n0 5\n-3 3\n3 8\n", "1 1\n-990637865 387517231\n", "10 10\n-92 87\n-100 -67\n-88 80\n-82 -59\n-72 81\n-50 30\n30 77\n65 92\n-76 -60\n-29 -15\n", "10 8\n-749560329 759073394\n-186423470 816422576\n-674251064 742056817\n-342947007 954589677\n-306243234 9992...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given n segments on the coordinate axis Ox and the number k. The point is satisfied if it belongs to at least k segments. Find the smallest (by the number of segments) set of ...
632_D. Longest Subsequence_34370
You are given array a with n elements and the number m. Consider some subsequence of a and the value of least common multiple (LCM) of its elements. Denote LCM as l. Find any longest subsequence of a with the value l ≤ m. A subsequence of a is an array we can get by erasing some elements of a. It is allowed to erase z...
import bisect from itertools import accumulate import os import sys import math from decimal import * from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in fi...
{ "input": [ "7 8\n6 2 9 2 7 2 3\n", "6 4\n2 2 2 3 3 3\n", "1 1\n2000\n", "2 1\n2 2\n", "3 5\n5 7 9\n", "1 1\n333\n", "1 1\n2222\n", "1 3\n5\n", "1 1\n1234\n", "3 1\n3 3 3\n", "7 1\n6 2 9 2 7 2 3\n", "2 10\n14 15\n", "1 1\n1024\n", "1 5\n4321\n", "1 1\n2\n",...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given array a with n elements and the number m. Consider some subsequence of a and the value of least common multiple (LCM) of its elements. Denote LCM as l. Find any longest ...
685_A. Robbers' watch_34374
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hour...
from sys import exit from itertools import permutations as prm def to_base(n, base): ans = [] while n // base > 0: ans.append(n % base) n //= base ans.append(n % base) ans.reverse() return ans def le(l, n, m): prev_eq = True for i in range(len(n)): if l[i] == n[i]:...
{ "input": [ "2 3\n", "8 2\n", "123 456\n", "421414245 4768815\n", "8 7\n", "16808 8\n", "3 16808\n", "50 50\n", "1 1\n", "2402 50\n", "2400 342\n", "117650 5\n", "2402 49\n", "343 2401\n", "8 8\n", "2400 227\n", "117648 5\n", "50 3\n", "1 10...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as t...
750_C. New Year and Rating_34380
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating ch...
I = lambda: list(map(int, input().split())) n = I()[0] c, d = [[0] * n for _ in range(2)] for i in range(n): _c, _d = I() c[i] = _c d[i] = _d lb, ub, change = -1e100, 1e100, 0 for i in range(n)[::-1]: change -= c[i] if d[i] == 1: lb = max(lb, 1900 - change) else: ub = min(ub, 18...
{ "input": [ "1\n-5 1\n", "2\n57 1\n22 2\n", "3\n-7 1\n5 2\n8 2\n", "4\n27 2\n13 1\n-50 1\n8 2\n", "3\n-10 2\n-20 2\n-30 2\n", "2\n100 2\n100 2\n", "21\n100 2\n100 2\n100 2\n100 2\n100 2\n100 2\n100 2\n100 2\n100 2\n100 2\n100 2\n100 2\n100 2\n100 2\n100 2\n100 2\n100 2\n100 2\n100 2\n1 2\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or high...
774_A. Amusement Park_34383
Pupils decided to go to amusement park. Some of them were with parents. In total, n people came to the park and they all want to get to the most extreme attraction and roll on it exactly once. Tickets for group of x people are sold on the attraction, there should be at least one adult in each group (it is possible tha...
n, c1, c2 = [int(x) for x in input().split(' ')] s = input() cnt = s.count('1') def price(x): return c1 + c2 * (x - 1) ** 2 prices = [] for i in range(1, cnt + 1): bigGroupsPeople = n // i + 1 numBigGroups = n % i smallGroupsPeople = n // i numSmallGroups = i - n % i totalPrice = numBigGroup...
{ "input": [ "4 7 2\n1101\n", "3 4 1\n011\n", "100 1000 1000\n0000010100101100110100101111001111111111100101111100111011110001011110110111111010000000101000111000\n", "50 13 44\n11101110100110111100010110001111001001110010111011\n", "2 3 10\n01\n", "5 10 3\n11100\n", "20 3 13\n011111100111...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Pupils decided to go to amusement park. Some of them were with parents. In total, n people came to the park and they all want to get to the most extreme attraction and roll on it exac...
799_A. Carrot Cakes_34387
In some game by Playrix it takes t minutes for an oven to bake k carrot cakes, all cakes are ready at the same moment t minutes after they started baking. Arkady needs at least n cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady can bui...
n,t,k,d=[int(i) for i in input().split()] a = (n+k-1)//k*t b=1000000000 for i in range(n//k+1): b=min(b,max(d+i*t,(n-i*k+k-1)//k*t)) if b<a: print('YES') else: print('NO')
{ "input": [ "10 3 11 4\n", "4 2 1 4\n", "8 6 4 6\n", "8 6 4 5\n", "1000 49 50 995\n", "304 635 304 257\n", "3 2 1 1\n", "982 13 5 198\n", "60 69 9 438\n", "611 16 8 153\n", "1000 1000 1 400\n", "942 42 3 69\n", "214 9 9 412\n", "246 69 36 432\n", "342 69 50...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: In some game by Playrix it takes t minutes for an oven to bake k carrot cakes, all cakes are ready at the same moment t minutes after they started baking. Arkady needs at least n cake...
819_A. Mister B and Boring Game_34391
Sometimes Mister B has free evenings when he doesn't know what to do. Fortunately, Mister B found a new game, where the player can play against aliens. All characters in this game are lowercase English letters. There are two players: Mister B and his competitor. Initially the players have a string s consisting of the...
def main(a, b, l, r): qL = (l - 1) // (2 * a + 2 * b) rL = (l - 1) % (2 * a + 2 * b) + 1 qR = (r - 1) // (2 * a + 2 * b) rR = (r - 1) % (2 * a + 2 * b) + 1 #print(qL, qR, rL, rR) if qL == qR: #In b segment if a < rL <= a + b and a < rR <= a + b: return 1 ...
{ "input": [ "4 2 2 6\n", "1 1 1 8\n", "3 7 4 6\n", "6 1 1 10000\n", "2 1 288 300\n", "5 8 654321103 654321106\n", "5 6 1000000000 1000000000\n", "3 4 999999999 1000000000\n", "10 5 1 1000000000\n", "3 3 3 8\n", "12 1 1 1000000\n", "6 2 654321113 654321123\n", "3 8 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Sometimes Mister B has free evenings when he doesn't know what to do. Fortunately, Mister B found a new game, where the player can play against aliens. All characters in this game ar...
844_D. Interactive LowerBound_34395
This is an interactive problem. You are given a sorted in increasing order singly linked list. You should find the minimum integer in the list which is greater than or equal to x. More formally, there is a singly liked list built on an array of n elements. Element with index i contains two integers: valuei is the int...
from random import sample def R(): return map(int, input().split()) def ask(i): print('?', i, flush=True) v, nxt = R() if v < 0: exit() return v, nxt def ans(v): print('!', v) exit() n, s, x = R() mv = -1 i = s S = 800 q = range(1, n + 1) if n > S: q = sample(q, S) if s n...
{ "input": [ "5 3 80\n97 -1\n58 5\n16 2\n81 1\n79 4\n", "10 3 2\n3 9\n9 -1\n0 7\n6 8\n5 4\n8 2\n1 10\n7 6\n4 5\n2 1\n", "1 1 0\n0 -1\n", "5 1 6\n1 2\n2 3\n3 4\n4 5\n5 -1\n", "5 3 974128233\n547205043 5\n318213550 1\n122625404 4\n184874700 2\n669820978 -1\n", "1 1 2\n0 -1\n", "1 1 100000000...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: This is an interactive problem. You are given a sorted in increasing order singly linked list. You should find the minimum integer in the list which is greater than or equal to x. M...
865_A. Save the problem!_34399
Attention: we lost all the test cases for this problem, so instead of solving the problem, we need you to generate test cases. We're going to give you the answer, and you need to print a test case that produces the given answer. The original problem is in the following paragraph. People don't use cash as often as they...
print(int(input())*2-1,2,1,2)
{ "input": [ "314\n", "3\n", "18\n", "16\n", "20\n", "1023\n", "99991\n", "8\n", "7\n", "99992\n", "239\n", "13\n", "1\n", "99971\n", "2\n", "17\n", "4\n", "99990\n", "4063\n", "6\n", "100000\n", "65537\n", "65536\n", "12\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Attention: we lost all the test cases for this problem, so instead of solving the problem, we need you to generate test cases. We're going to give you the answer, and you need to prin...
891_A. Pride_34403
You have an array a with length n, you can perform operations. Each operation is like this: choose two adjacent elements from a, say x and y, and replace one of them with gcd(x, y), where gcd denotes the [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor). What is the minimum number of ope...
import math,sys,bisect,heapq,os from collections import defaultdict,Counter,deque from itertools import groupby,accumulate from functools import lru_cache #sys.setrecursionlimit(200000000) int1 = lambda x: int(x) - 1 def input(): return sys.stdin.readline().rstrip('\r\n') #input = iter(sys.stdin.buffer.read().decode()....
{ "input": [ "5\n2 2 3 4 6\n", "3\n2 6 9\n", "4\n2 4 6 8\n", "4\n2 6 9 1\n", "5\n1 1 1 2 2\n", "4\n1 1 1 2\n", "9\n10 10 10 10 10 10 10 10 21\n", "13\n10 10 10 15 15 15 15 15 15 15 15 21 21\n", "15\n10 10 10 10 10 10 10 10 10 10 10 10 15 15 21\n", "4\n1 1 1 1\n", "6\n6 15 1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You have an array a with length n, you can perform operations. Each operation is like this: choose two adjacent elements from a, say x and y, and replace one of them with gcd(x, y), w...
913_D. Too Easy Problems_34407
You are preparing for an exam on scheduling theory. The exam will last for exactly T milliseconds and will consist of n problems. You can either solve problem i in exactly ti milliseconds or ignore it and spend no time. You don't need time to rest after solving a problem, either. Unfortunately, your teacher considers ...
# -*- coding: utf-8 -*- """ Created on Fri Jan 12 18:46:09 2018 @author: Sand Boa """ import itertools if __name__ == "__main__": n:int T:int n, T = list(map(int,input().split())) listi:list = [] tsum:int = 0 csum:int = 0 k:int k = 1 a:int b:int t:int ind:int for i ...
{ "input": [ "2 100\n1 787\n2 788\n", "5 300\n3 100\n4 150\n4 80\n2 90\n2 300\n", "2 100\n2 42\n2 58\n", "5 100\n1 10\n1 10\n1 10\n1 10\n1 10\n", "5 66\n2 64\n4 91\n5 91\n1 79\n3 85\n", "10 481\n4 25\n3 85\n6 96\n6 13\n1 9\n4 27\n2 7\n3 42\n9 66\n9 70\n", "5 300\n3 100\n4 150\n4 80\n2 90\n...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are preparing for an exam on scheduling theory. The exam will last for exactly T milliseconds and will consist of n problems. You can either solve problem i in exactly ti millisec...
935_D. Fafa and Ancient Alphabet_34411
Ancient Egyptians are known to have used a large set of symbols <image> to write on the walls of the temples. Fafa and Fifa went to one of the temples and found two non-empty words S1 and S2 of equal lengths on the wall of temple written one below the other. Since this temple is very ancient, some symbols from the word...
n, m = [int(x) for x in input().split()] a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] mult = 1 mod = 10 ** 9 + 7 res = 0 m_inv = pow(m, mod - 2, mod) for x, y in zip(a, b): if x and y: if x > y: res += mult res %= mod break elif ...
{ "input": [ "7 26\n0 15 12 9 13 0 14\n11 1 0 13 15 12 0\n", "1 2\n0\n1\n", "1 2\n1\n0\n", "6 26\n14 5 19 18 9 14\n0 0 0 0 0 0\n", "10 90086\n41910 22500 6101 0 0 0 34790 9614 0 83351\n11155 21861 0 19394 81349 53888 33712 3834 17500 48357\n", "5 1\n1 1 1 1 1\n0 0 0 0 0\n", "4 26\n0 0 0 0\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Ancient Egyptians are known to have used a large set of symbols <image> to write on the walls of the temples. Fafa and Fifa went to one of the temples and found two non-empty words S1...
961_C. Chessboard_34415
Magnus decided to play a classic chess game. Though what he saw in his locker shocked him! His favourite chessboard got broken into 4 pieces, each of size n by n, n is always odd. And what's even worse, some squares were of wrong color. j-th square of the i-th row of k-th piece of the board has color ak, i, j; 1 being ...
import itertools n = int(input()) a = [] for i in range(4): a.append([input() for _ in range(n)]) if i < 3: assert input() == '' best = 4*n*n for p in itertools.permutations(a): for s in range(2): count = 0 for i in range(4): for r in range(n): for c in ...
{ "input": [ "3\n101\n010\n101\n\n101\n000\n101\n\n010\n101\n011\n\n010\n101\n010\n", "1\n0\n\n0\n\n1\n\n0\n", "3\n101\n010\n101\n\n101\n010\n101\n\n101\n010\n101\n\n101\n010\n101\n", "1\n0\n\n0\n\n0\n\n0\n", "3\n000\n000\n000\n\n111\n111\n111\n\n111\n111\n111\n\n000\n000\n000\n", "1\n0\n\n0\n...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Magnus decided to play a classic chess game. Though what he saw in his locker shocked him! His favourite chessboard got broken into 4 pieces, each of size n by n, n is always odd. And...
989_B. A Tide of Riverscape_34419
Walking along a riverside, Mino silently takes a note of something. "Time," Mino thinks aloud. "What?" "Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this." "And what are you recording?" "You see it, tide. Everything has its own period, and I think I've figured...
n, p = [int(i) for i in input().split()] s = list(input()) k = 0 for index in range(n - p): if k != 0: break if s[index] == s[index + p] and s[index] == ".": s[index] = str(0) s[index + p] = str(1) k += 1 elif s[index] != s[index + p] and s[index] != "." and s[index + p] != "...
{ "input": [ "10 7\n1.0.1.0.1.\n", "10 9\n1........1\n", "10 6\n1.0.1.1000\n", "128 108\n01100.110...000.0001.1.11.11.010010.01100.0.1.01.0.0011.11001.000101...1.0.0..100.0110.0110.0.0101.0.0.0001.01100.110...100.0001\n", "3 3\n1..\n", "3 1\n01.\n", "4 1\n111.\n", "10 7\n000....111\n",...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Walking along a riverside, Mino silently takes a note of something. "Time," Mino thinks aloud. "What?" "Time and tide wait for no man," explains Mino. "My name, taken from the rive...
p02600 M-SOLUTIONS Programming Contest 2020 - Kyu in AtCoder_34433
M-kun is a competitor in AtCoder, whose highest rating is X. In this site, a competitor is given a kyu (class) according to his/her highest rating. For ratings from 400 through 1999, the following kyus are given: * From 400 through 599: 8-kyu * From 600 through 799: 7-kyu * From 800 through 999: 6-kyu * From 1000 thro...
X = int(input()) print(8-(X-400)//200)
{ "input": [ "725", "1600", "1359", "543", "1855", "609", "982", "1485", "1125", "1764", "554", "417", "979", "424", "470", "826", "1596", "885", "1543", "969", "412", "654", "646", "915", "512", "456", "1815",...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: M-kun is a competitor in AtCoder, whose highest rating is X. In this site, a competitor is given a kyu (class) according to his/her highest rating. For ratings from 400 through 1999, ...
p02731 AtCoder Beginner Contest 159 - Maximum Volume_34437
Given is a positive integer L. Find the maximum possible volume of a rectangular cuboid whose sum of the dimensions (not necessarily integers) is L. Constraints * 1 ≤ L ≤ 1000 * L is an integer. Input Input is given from Standard Input in the following format: L Output Print the maximum possible volume of a re...
N=int(input()) print((N**3)/27)
{ "input": [ "999", "3", "5", "8", "0", "1", "2", "4", "7", "13", "6", "11", "-1", "-2", "-3", "-4", "-5", "-8", "-6", "-7", "-11", "-16", "-17", "14", "17", "26", "9", "12", "21", "24", "19", ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Given is a positive integer L. Find the maximum possible volume of a rectangular cuboid whose sum of the dimensions (not necessarily integers) is L. Constraints * 1 ≤ L ≤ 1000 * L i...
p02864 AtCoder Beginner Contest 145 - Laminate_34440
We will create an artwork by painting black some squares in a white square grid with 10^9 rows and N columns. The current plan is as follows: for the i-th column from the left, we will paint the H_i bottommost squares and will not paint the other squares in that column. Before starting to work, you can choose at most K...
N, K = map(int, input().split()) H = [0] + [int(a) for a in input().split()] X = [[1<<100] * (N-K+1) for _ in range(N+1)] X[0][0] = 0 for i in range(1, N+1): for j in range(1, min(i+1, N-K+1)): X[i][j] = min([X[ii][j-1] + max(H[i] - H[ii], 0) for ii in range(i)]) print(min([x[-1] for x in X]))
{ "input": [ "10 0\n1 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000", "6 2\n8 6 9 1 2 1", "4 1\n2 3 4 1", "10 0\n2 1000000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000", "6 2\n8 3 9 1 2 1", "10 0\n2 1001000000 1 1000000000 1 1000000000 1 1000000000 1 1000000000", ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: We will create an artwork by painting black some squares in a white square grid with 10^9 rows and N columns. The current plan is as follows: for the i-th column from the left, we wil...
p02999 AtCoder Beginner Contest 130 - Rounding_34444
X and A are integers between 0 and 9 (inclusive). If X is less than A, print 0; if X is not less than A, print 10. Constraints * 0 \leq X, A \leq 9 * All values in input are integers. Input Input is given from Standard Input in the following format: X A Output If X is less than A, print 0; if X is not less th...
a,b=map(int,input().split());print('100'[a<b::2])
{ "input": [ "6 6", "7 5", "3 5", "0 6", "7 0", "3 0", "0 8", "11 0", "0 0", "0 3", "11 -1", "0 -1", "-1 3", "9 0", "1 -1", "-2 3", "6 0", "1 0", "-2 6", "6 -1", "1 1", "-3 6", "5 -1", "0 1", "-5 6", "5 0", "0 ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: X and A are integers between 0 and 9 (inclusive). If X is less than A, print 0; if X is not less than A, print 10. Constraints * 0 \leq X, A \leq 9 * All values in input are intege...
p03140 NIKKEI Programming Contest 2019 - Touitsu_34448
You are given three strings A, B and C. Each of these is a string of length N consisting of lowercase English letters. Our objective is to make all these three strings equal. For that, you can repeatedly perform the following operation: * Operation: Choose one of the strings A, B and C, and specify an integer i betwe...
N=int(input()) A=input() B=input() C=input() ans=0 for i in range(N): if A[i]==B[i]==C[i]: ans+=0 elif A[i]==B[i] or B[i]==C[i] or C[i]==A[i]: ans+=1 else: ans+=2 print(ans)
{ "input": [ "9\ndifferent\ndifferent\ndifferent", "4\nwest\neast\nwait", "7\nzenkoku\ntouitsu\nprogram", "9\ncifferent\ndifferent\ndifferent", "4\nwest\neast\nw`it", "7\nukoknez\ntouitsu\nprogram", "9\ncjfferent\ndifferent\ndifferent", "4\nwesu\neast\nw`it", "9\ncjfferent\ndiffere...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given three strings A, B and C. Each of these is a string of length N consisting of lowercase English letters. Our objective is to make all these three strings equal. For tha...
p03284 AtCoder Beginner Contest 105 - AtCoder Crackers_34452
Takahashi has decided to distribute N AtCoder Crackers to K users of as evenly as possible. When all the crackers are distributed, find the minimum possible (absolute) difference between the largest number of crackers received by a user and the smallest number received by a user. Constraints * 1 \leq N,K \leq 100 * A...
N,M=map(int,input().split()) print(0 if N % M == 0 else 1)
{ "input": [ "100 10", "1 1", "7 3", "100 13", "2 1", "1 2", "10 3", "100 9", "6 3", "000 9", "3 1", "7 4", "000 16", "0 1", "000 26", "4 1", "001 26", "011 26", "111 26", "111 37", "011 37", "010 37", "110 37", "110 59", ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Takahashi has decided to distribute N AtCoder Crackers to K users of as evenly as possible. When all the crackers are distributed, find the minimum possible (absolute) difference betw...
p03440 AtCoder Petrozavodsk Contest 001 - Forest_34456
You are given a forest with N vertices and M edges. The vertices are numbered 0 through N-1. The edges are given in the format (x_i,y_i), which means that Vertex x_i and y_i are connected by an edge. Each vertex i has a value a_i. You want to add edges in the given forest so that the forest becomes connected. To add a...
# -*- coding: utf-8 -*- from collections import defaultdict from heapq import merge import sys sys.setrecursionlimit(10**7) def inpl(): return tuple(map(int, input().split())) N, M = inpl() A = inpl() tree = [[-1, 1] for _ in range(N)] # [next, rank] def find(i): if tree[i][0] == -1: group = i else...
{ "input": [ "1 0\n5", "7 5\n1 2 3 4 5 6 7\n3 0\n4 0\n1 2\n1 3\n5 6", "5 0\n3 1 4 1 5", "7 5\n1 2 3 4 5 6 10\n3 0\n4 0\n1 2\n1 3\n5 6", "5 0\n3 0 4 1 5", "1 0\n3 0 4 1 2", "7 5\n1 2 3 4 5 6 0\n3 0\n4 0\n1 2\n1 3\n5 6", "7 5\n1 2 3 4 5 6 10\n3 0\n4 0\n1 2\n1 3\n5 0", "2 0\n3 -1 4 1 ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given a forest with N vertices and M edges. The vertices are numbered 0 through N-1. The edges are given in the format (x_i,y_i), which means that Vertex x_i and y_i are conne...
p03598 AtCoder Beginner Contest 074 - Collecting Balls (Easy Version)_34460
There are N balls in the xy-plane. The coordinates of the i-th of them is (x_i, i). Thus, we have one ball on each of the N lines y = 1, y = 2, ..., y = N. In order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B. Then, he placed the i-th type-A robot at coordinates (0, i), and the i-th t...
n=int(input()) k=int(input()) x=list(map(int,input().split())) ans=0 for i in range(n): ans+=2*min(x[i],k-x[i]) print(ans)
{ "input": [ "1\n10\n2", "2\n9\n3 6", "5\n20\n11 12 9 17 12", "1\n18\n2", "2\n9\n2 6", "5\n20\n11 12 9 17 15", "1\n23\n1", "1\n23\n0", "1\n25\n-1", "1\n10\n3", "5\n20\n11 12 9 17 1", "2\n9\n1 6", "5\n20\n8 12 9 17 15", "1\n18\n-2", "5\n19\n11 12 9 17 1", ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are N balls in the xy-plane. The coordinates of the i-th of them is (x_i, i). Thus, we have one ball on each of the N lines y = 1, y = 2, ..., y = N. In order to collect these ...