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
429_C. Guess the Tree_20796
Iahub and Iahubina went to a picnic in a forest full of trees. Less than 5 minutes passed before Iahub remembered of trees from programming. Moreover, he invented a new problem and Iahubina has to solve it, otherwise Iahub won't give her the food. Iahub asks Iahubina: can you build a rooted tree, such that * each ...
def DFS(x): for i in range(x): if(Seen[i][x]): continue if(Rem[i]>=C[x]): if(Rem[i]==C[x] and len(Children[i])==0): continue Rem[i]-=C[x] Parent[x]=i Children[i].append(x) return True for i in range(x): ...
{ "input": [ "5\n1 1 5 2 1\n", "4\n1 1 1 4\n", "24\n2 3 20 1 4 9 1 3 1 2 1 3 1 2 1 1 1 2 1 2 4 24 2 1\n", "24\n1 1 1 1 1 1 1 1 1 1 1 1 24 1 1 1 1 1 1 1 1 1 1 1\n", "2\n1 2\n", "24\n1 24 1 1 1 3 8 1 1 3 1 1 6 1 1 1 1 3 5 1 3 7 13 1\n", "21\n1 1 1 6 1 1 13 21 1 1 3 1 8 1 19 3 3 1 1 1 1\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Iahub and Iahubina went to a picnic in a forest full of trees. Less than 5 minutes passed before Iahub remembered of trees from programming. Moreover, he invented a new problem and Ia...
451_A. Game With Sticks_20800
After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of n horizontal and m vertical sticks. An intersection point is any point on the grid which is formed by the intersection of one horizontal stick and one vertical stick. In the grid shown be...
n,m = map(int, input().strip().split()) print("Akshat" if min(n,m)%2!=0 else "Malvika")
{ "input": [ "2 3\n", "3 3\n", "2 2\n", "1 1\n", "59 79\n", "2 1\n", "1 2\n", "3 2\n", "100 100\n", "3 4\n", "99 100\n", "98 98\n", "25 70\n", "20 68\n", "1 3\n", "98 100\n", "98 99\n", "100 98\n", "1 35\n", "46 6\n", "99 99\n", "...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of n horizontal and m vertical sticks. An intersection...
520_E. Pluses everywhere_20808
Vasya is sitting on an extremely boring math class. To have fun, he took a piece of paper and wrote out n numbers on a single line. After that, Vasya began to write out different ways to put pluses ("+") in the line between certain digits in the line so that the result was a correct arithmetic expression; formally, no ...
n, k = map(int, input().split()) t = list(map(int, input())) p, d = 1, 10**9 + 7 s = 0 f = [1] * n for i in range(2, n): f[i] = (i * f[i - 1]) % d c = lambda a, b: 0 if a > b else (f[b] * pow(f[a] * f[b -a], d - 2, d)) % d if k: u = [0] * (n + 1) p = [1] * (n + 1) for i in range(n): u[i] = (p[i] * c(k - 1, n...
{ "input": [ "3 1\n108\n", "3 2\n108\n", "132 104\n558881515858815818855111851188551181818185155585188885588555158518555118155511851558151188115518858811551515158155181855155181588185\n", "20 9\n34540451546587567970\n", "57 13\n177946005798852216692528643323484389368821547834013121843\n", "14 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Vasya is sitting on an extremely boring math class. To have fun, he took a piece of paper and wrote out n numbers on a single line. After that, Vasya began to write out different ways...
548_B. Mike and Fun_20812
Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mike's hands are on his ears (since he's the judge) and each bear standing in the ...
def score(R) : val = 0 ret = 0 for i in R : if i : val += 1 ret = max(ret, val) else : val = 0 return ret n, m, q = map(int, input().split()) A = [list(map(int, input().split())) for i in range(n)] B = [score(A[i]) for i in range(n)] for _ in range(q)...
{ "input": [ "5 4 5\n0 1 1 0\n1 0 0 1\n0 1 1 0\n1 0 0 1\n0 0 0 0\n1 1\n1 4\n1 1\n4 2\n4 3\n", "5 1 5\n0\n0\n0\n0\n0\n1 1\n2 1\n3 1\n4 1\n5 1\n", "2 2 1\n1 1\n1 1\n1 1\n", "1 1 3\n1\n1 1\n1 1\n1 1\n", "1 5 5\n0 0 0 0 0\n1 2\n1 1\n1 4\n1 5\n1 3\n", "1 1 1\n0\n1 1\n", "1 1 10\n0\n1 1\n1 1\n1 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear ...
574_D. Bear and Blocks_20816
Limak is a little bear who loves to play. Today he is playing by destroying block towers. He built n towers in a row. The i-th tower is made of hi identical blocks. For clarification see picture for the first sample. Limak will repeat the following operation till everything is destroyed. Block is called internal if i...
x=int(input()) mas = list(map(int,input().split(" "))) mas2=[0]*(x) mas2[0]=1 for i in range(1,x): mas2[i]=min(mas[i],mas2[i-1]+1) mas2[-1]=1 for i in range(2,x+1): mas2[-i]=min(mas[-i],mas2[-i+1]+1, mas2[-i]) print(max(mas2))
{ "input": [ "6\n2 1 4 6 2 2\n", "7\n3 3 3 1 3 3 3\n", "5\n1 2 3 2 1\n", "28\n415546599 415546599 415546599 415546599 415546599 415546599 415546599 415546599 415546599 2 802811737 802811737 802811737 802811737 802811737 802811737 802811737 802811737 1 550595901 550595901 550595901 550595901 550595901 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Limak is a little bear who loves to play. Today he is playing by destroying block towers. He built n towers in a row. The i-th tower is made of hi identical blocks. For clarification ...
596_B. Wilbur and Array_20820
Wilbur the pig is tinkering with arrays again. He has the array a1, a2, ..., an initially consisting of n zeros. At one step, he can choose any index i and either add 1 to all elements ai, ai + 1, ... , an or subtract 1 from all elements ai, ai + 1, ..., an. His goal is to end up with the array b1, b2, ..., bn. Of co...
# print("Input n") n = int(input()) # print("Input the integers") a = [int(x) for x in input().split()] answer = abs(a[0]) for i in range(1, n): answer += abs(a[i-1] - a[i]) print(answer)
{ "input": [ "4\n1 2 2 1\n", "5\n1 2 3 4 5\n", "1\n0\n", "15\n15 14 13 1 2 3 12 11 10 4 5 6 9 8 7\n", "10\n1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000\n", "6\n1000 1 2000 1 3000 1\n", "7\n12 6 12 13 4 3 2\n", "5\n10...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Wilbur the pig is tinkering with arrays again. He has the array a1, a2, ..., an initially consisting of n zeros. At one step, he can choose any index i and either add 1 to all element...
617_D. Polyline_20824
There are three points marked on the coordinate plane. The goal is to make a simple polyline, without self-intersections and self-touches, such that it passes through all these points. Also, the polyline must consist of only segments parallel to the coordinate axes. You are to find the minimum number of segments this p...
"""n=int(input()) x=list(map(int, input().split())) c=0 pro=1 for i in range(n): if x[i]==1: c+=1 if c==1: old=i elif c>1: new=i pro*=(new-old) old=new print(pro) """ a=list(map(int,input().split())) b=list(map(int,input().split())) c=list(map(...
{ "input": [ "-1 -1\n-1 3\n4 3\n", "1 -1\n1 1\n1 2\n", "1 1\n2 3\n3 2\n", "451140644 -552066345\n451140644 97091285\n643901618 -552066345\n", "755966021 -977934315\n-693932164 -977934315\n780740735 341305212\n", "-322848128 276304614\n-228010033 -361111909\n-137761352 276304614\n", "-76151...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are three points marked on the coordinate plane. The goal is to make a simple polyline, without self-intersections and self-touches, such that it passes through all these points...
638_A. Home Numbers_20828
The main street of Berland is a straight line with n houses built along it (n is an even number). The houses are located at both sides of the street. The houses with odd numbers are at one side of the street and are numbered from 1 to n - 1 in the order from the beginning of the street to the end (in the picture: from ...
[n, x] = list(map(int, input().split(' '))) answer = int (x % 2 == 0 and (n / 2 - x / 2 + 1) or( (x + 1) / 2)) print(answer)
{ "input": [ "4 2\n", "8 5\n", "5026 4697\n", "1628 274\n", "34614 27913\n", "92388 39118\n", "85766 64050\n", "100000 2\n", "59140 24272\n", "90616 32240\n", "2 1\n", "67808 61809\n", "10 10\n", "9456 3443\n", "100000 100000\n", "95522 91716\n", "28...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: The main street of Berland is a straight line with n houses built along it (n is an even number). The houses are located at both sides of the street. The houses with odd numbers are a...
712_A. Memory and Crow_20837
There are n integers b1, b2, ..., bn written in a row. For all i from 1 to n, values ai are defined by the crows performing the following procedure: * The crow sets ai initially 0. * The crow then adds bi to ai, subtracts bi + 1, adds the bi + 2 number, and so on until the n'th number. Thus, ai = bi - bi + 1 + bi...
n=int(input()) a=input().split() for i in range (n): a[i]=int(a[i]) a.reverse() b=[] b.append(a[0]) for i in range (n-1): b.append(a[i]+a[i+1]) b.reverse() print (" ".join(map(str, b)))
{ "input": [ "5\n3 -2 -1 5 6\n", "5\n6 -4 8 -2 3\n", "10\n-1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000 -1000000000 1000000000\n", "10\n124 532 -642 6482 -124 952 -235 7594 34 -12\n", "10\n1 -1 1 -1 1 -1 1 -1 1 -1\n", "10\n1294 35852 32749 537295 1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are n integers b1, b2, ..., bn written in a row. For all i from 1 to n, values ai are defined by the crows performing the following procedure: * The crow sets ai initially 0....
757_A. Gotta Catch Em' All!_20843
Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young to go out and catch Bulbasaur, he came up with his own way of catching a Bulbas...
from collections import Counter k = Counter("Bulbasaur") r = Counter(input()) print(min([r[c] // k[c] for c in k]))
{ "input": [ "Bulbbasaur\n", "F\n", "aBddulbasaurrgndgbualdBdsagaurrgndbb\n", "Bulbasua\n", "Blbbasar\n", "Bbular\n", "BBuullbbaassaauurr\n", "Bbulsr\n", "ulbasaur\n", "BulbasaurBulbasaur\n", "bulsar\n", "BulbasaurBulbasauBulbasauBulbasau\n", "BBBBBBBBBBbbbbbbbbbbbb...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fa...
802_F. Marmots (hard)_20848
Your task is the exact same as for the easy version. But this time, the marmots subtract the village's population P from their random number before responding to Heidi's request. Also, there are now villages with as few as a single inhabitant, meaning that <image>. Can you help Heidi find out whether a village follow...
for i in range(int(input())): a=list(map(int,input().split())) mx=max(list(map(abs,a))) std=(sum(list(map(lambda x:x*x,a)))/len(a))**0.5 print('poisson'if mx/std>2 else'uniform')
{ "input": [], "output": [] }
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Your task is the exact same as for the easy version. But this time, the marmots subtract the village's population P from their random number before responding to Heidi's request. Als...
825_B. Five-In-a-Row_20852
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins imm...
mat=[] n=10 m=10 for i in range(n): s=input() s=list(s) mat.append(s) f=0 def check(mat): for i in range(10): for j in range(10): #horizontal for k in range(5): if (i+k)>=10 or mat[i+k][j]!='X': break else: ...
{ "input": [ "XX.XX.....\n.....OOOO.\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n", "XXOXX.....\nOO.O......\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n", "O.........\nX.O.......\nX..O......\nX...O......
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts. In...
847_M. Weather Tomorrow_20856
Vasya came up with his own weather forecasting method. He knows the information about the average air temperature for each of the last n days. Assume that the average air temperature for each day is integral. Vasya believes that if the average temperatures over the last n days form an arithmetic progression, where the...
n=int(input()) l=list(map(int,input().split())) f=0 for i in range (2,len(l)): if l[i]==l[i-1]+(l[1]-l[0]): pass else: f=1 print(l[n-1]) break if f==0: if (l[n-1])==(l[0]+(n-1)*(l[1]-l[0])): print(l[0]+(n*(l[1]-l[0]))) else: print(l[n-1])
{ "input": [ "4\n1 1 1 1\n", "3\n5 1 -5\n", "2\n900 1000\n", "5\n10 5 0 -5 -10\n", "51\n-9 10 30 50 70 90 110 130 150 170 190 210 230 250 270 290 310 330 350 370 390 410 430 450 470 490 510 530 550 570 590 610 630 650 670 690 710 730 750 770 790 810 830 850 870 890 910 930 950 970 990\n", "4\n...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Vasya came up with his own weather forecasting method. He knows the information about the average air temperature for each of the last n days. Assume that the average air temperature ...
896_B. Ithea Plays With Chtholly_20863
This is an interactive problem. Refer to the Interaction section below for better understanding. Ithea and Chtholly want to play a game in order to determine who can use the kitchen tonight. <image> Initially, Ithea puts n clear sheets of paper in a line. They are numbered from 1 to n from left to right. This game ...
import sys n, m, c=map(int, input().split()) a=[] for i in range(n+1): a.append(0) cnt=0 while cnt<n: i=0 x=int(input()) if x*2<=c: i=1 while a[i] and a[i]<=x: i+=1 else: i=n while a[i] and a[i]>=x: i-=1 if a[i]==0: cnt+=1 a[i]...
{ "input": [ "2 4 4\n2\n1\n3\n", "3 3 2\n2\n2\n1\n", "4 4 2\n1\n2\n1\n2\n", "3 3 2\n1\n2\n1\n", "3 6 3\n2\n2\n3\n3\n1\n1\n", "4 8 3\n2\n1\n2\n1\n2\n1\n1\n1\n", "4 8 4\n4\n4\n4\n4\n4\n4\n4\n4\n", "4 8 4\n2\n3\n2\n3\n2\n3\n2\n3\n", "10 120 15\n6\n11\n9\n11\n3\n12\n11\n12\n2\n8\n3\n11...
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. Refer to the Interaction section below for better understanding. Ithea and Chtholly want to play a game in order to determine who can use the kitchen ...
93_C. Azembler_20868
After the Search Ultimate program that searched for strings in a text failed, Igor K. got to think: "Why on Earth does my program work so slowly?" As he double-checked his code, he said: "My code contains no errors, yet I know how we will improve Search Ultimate!" and took a large book from the shelves. The book read "...
n=int(input()) mn=[float('inf')]*256 ans="" done=set() def gen(vals,st): global mn,ans #print(*vals) if('|'.join([str(x) for x in vals]) in done): return done.add('|'.join([str(x) for x in vals])) if(vals[-1]==n): if(len(vals)<mn[n]): mn[n]=len(vals) ans=st ...
{ "input": [ "4\n", "2\n", "41\n", "170\n", "128\n", "201\n", "102\n", "15\n", "171\n", "137\n", "165\n", "203\n", "117\n", "190\n", "67\n", "153\n", "197\n", "238\n", "9\n", "52\n", "37\n", "11\n", "113\n", "116\n", "...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: After the Search Ultimate program that searched for strings in a text failed, Igor K. got to think: "Why on Earth does my program work so slowly?" As he double-checked his code, he sa...
967_A. Mind the Gap_20872
These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts 1 minute. He was asked to insert one takeoff in the schedule. The takeoff takes 1 minute it...
# -*- coding: utf-8 -*- # @Date : 2019-01-30 20:41:28 # @Author : raj lath (oorja.halt@gmail.com) # @Link : link # @Version : 1.0.0 from sys import stdin max_val=int(10e12) min_val=int(-10e12) def read_int() : return int(stdin.readline()) def read_ints() : return [int(x) for x in stdin.readline().spli...
{ "input": [ "3 17\n0 30\n1 0\n12 0\n", "16 50\n0 30\n1 20\n3 0\n4 30\n6 10\n7 50\n9 30\n11 10\n12 50\n14 30\n16 10\n17 50\n19 30\n21 10\n22 50\n23 59\n", "6 60\n0 0\n1 20\n3 21\n5 0\n19 30\n23 40\n", "3 25\n0 0\n1 0\n2 0\n", "1 30\n0 29\n", "2 60\n0 0\n5 0\n", "25 60\n0 0\n1 0\n2 0\n3 0\n...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landi...
993_A. Two Squares_20876
You are given two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect. The interior of the square is considered to be part of the square, i.e. if one square is completely inside another, they intersect. If the ...
a=list(map(int,input().split())) b=list(map(int,input().split())) a1 = min(a[0::2]) b1 = max(a[0::2]) c1 = min(a[1::2]) d1 = max(a[1::2]) g = sum(b[0::2])/4 h = sum(b[1::2])/4 r = abs(b[0]-g) + abs(b[1]-h) for i in range(a1,b1+1) : for j in range (c1,d1+1) : if abs(i-g) + abs(j-h)<=r : exit(pr...
{ "input": [ "6 0 6 6 0 6 0 0\n7 4 4 7 7 10 10 7\n", "0 0 6 0 6 6 0 6\n1 3 3 5 5 3 3 1\n", "0 0 6 0 6 6 0 6\n7 3 9 5 11 3 9 1\n", "0 0 1 0 1 1 0 1\n3 0 6 3 3 6 0 3\n", "-4 -8 -4 -15 3 -15 3 -8\n-10 5 -27 -12 -10 -29 7 -12\n", "-33 -64 25 -64 25 -6 -33 -6\n-5 -74 -51 -28 -5 18 41 -28\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 two squares, one with sides parallel to the coordinate axes, and another one with sides at 45 degrees to the coordinate axes. Find whether the two squares intersect. Th...
p02627 AtCoder Beginner Contest 171 - αlphabet_20890
An uppercase or lowercase English letter \alpha will be given as input. If \alpha is uppercase, print `A`; if it is lowercase, print `a`. Constraints * \alpha is an uppercase (`A` - `Z`) or lowercase (`a` - `z`) English letter. Input Input is given from Standard Input in the following format: α Output If \alph...
c = input() print('A' if ord(c)<96 else 'a')
{ "input": [ "a", "B", "b", "C", "`", "D", "c", "E", "d", "F", "e", "G", "f", "H", "_", "I", "^", "J", "]", "K", "\\", "L", "[", "A", "Z", "@", "Y", "?", "X", ">", "W", "=", "V", "<"...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: An uppercase or lowercase English letter \alpha will be given as input. If \alpha is uppercase, print `A`; if it is lowercase, print `a`. Constraints * \alpha is an uppercase (`A` -...
p02758 AtCoder Beginner Contest 158 - Removing Robots_20894
There are N robots numbered 1 to N placed on a number line. Robot i is placed at coordinate X_i. When activated, it will travel the distance of D_i in the positive direction, and then it will be removed from the number line. All the robots move at the same speed, and their sizes are ignorable. Takahashi, who is a misc...
import sys input = sys.stdin.readline class SegmentTree(object): def __init__(self, init_array, seg_func=min, seg_func_null=10 ** 9 + 7): self.seg_func = seg_func self.seg_func_null = seg_func_null self.n = 1 while self.n < len(init_array): self.n *= 2 self.d...
{ "input": [ "2\n1 5\n3 3", "3\n6 5\n-1 10\n3 3", "20\n-8 1\n26 4\n0 5\n9 1\n19 4\n22 20\n28 27\n11 8\n-3 20\n-25 17\n10 4\n-18 27\n24 28\n-11 19\n2 27\n-2 18\n-1 12\n-24 29\n31 29\n29 7", "4\n7 10\n-10 3\n4 3\n-4 3", "2\n1 5\n4 3", "3\n6 5\n-1 7\n3 3", "20\n-8 1\n26 4\n0 5\n9 1\n19 4\n22 ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are N robots numbered 1 to N placed on a number line. Robot i is placed at coordinate X_i. When activated, it will travel the distance of D_i in the positive direction, and then...
p02893 AtCoder Grand Contest 039 - Division by Two with Something_20897
Given are integers N and X. For each integer k between 0 and X (inclusive), find the answer to the following question, then compute the sum of all those answers, modulo 998244353. * Let us repeat the following operation on the integer k. Operation: if the integer is currently odd, subtract 1 from it and divide it by 2...
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify import math import bisect import random from itertools import permutations, accumulate, combinations, product import sys import string from bisect import bisect_left, bisect_right from math import factorial, ceil, floor fro...
{ "input": [ "30\n001110011011011101010111011100", "3\n111", "6\n110101", "30\n001110011011011101010101011100", "3\n011", "6\n100101", "30\n001010011011011101010101011100", "3\n001", "6\n100100", "30\n001010011010011101010101011100", "3\n000", "6\n101100", "30\n0010...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Given are integers N and X. For each integer k between 0 and X (inclusive), find the answer to the following question, then compute the sum of all those answers, modulo 998244353. * ...
p03028 M-SOLUTIONS Programming Contest - Random Tournament_20900
We will host a rock-paper-scissors tournament with N people. The participants are called Person 1, Person 2, \ldots, Person N. For any two participants, the result of the match between them is determined in advance. This information is represented by positive integers A_{i,j} ( 1 \leq j < i \leq N ) as follows: * If A...
import sys p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def SI(): return sys.stdin.readline()[:-1] def pbit(aa,L): for a in aa:print(format(a,"b").zfill(L)) print() def main(): n=II() aa=[[int(c) for c in SI()] for _ in range(n-1)] #p2D(aa) # 人iが勝てる相手をbit...
{ "input": [ "6\n0\n11\n111\n1111\n11001", "3\n0\n10", "6\n0\n11\n110\n1111\n11001", "6\n0\n11\n100\n0101\n11001", "6\n0\n11\n011\n1111\n11001", "6\n0\n11\n100\n0111\n01001", "6\n1\n11\n001\n1111\n11001", "6\n1\n11\n011\n1110\n00010", "6\n0\n11\n100\n1111\n11001", "6\n0\n11\n10...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: We will host a rock-paper-scissors tournament with N people. The participants are called Person 1, Person 2, \ldots, Person N. For any two participants, the result of the match betwee...
p03169 Educational DP Contest - Sushi_20904
There are N dishes, numbered 1, 2, \ldots, N. Initially, for each i (1 \leq i \leq N), Dish i has a_i (1 \leq a_i \leq 3) pieces of sushi on it. Taro will perform the following operation repeatedly until all the pieces of sushi are eaten: * Roll a die that shows the numbers 1, 2, \ldots, N with equal probabilities, a...
n=int(input()) k=[0,0,0] a,s,d=0,0,0 for i in input().split(): if i=="1":a+=1 elif i=="2":s+=1 else:d+=1 dp=[[ [0]*(n+1) for j in range(n+1)] for i in range(n+1)] for i in range(d+1): for j in range(d+s+1): for k in range(n+1-i-j): su=i+j+k ret=0 if su: ret+=n/su if i>=1: ...
{ "input": [ "1\n3", "2\n1 2", "3\n1 1 1", "10\n1 3 2 3 3 2 3 2 1 3", "1\n1", "3\n1 2 1", "3\n2 2 1", "2\n1 3", "1\n2", "3\n2 3 1", "2\n1 1", "10\n1 3 2 2 3 2 3 2 1 3", "2\n2 1", "3\n2 2 2", "3\n2 2 3", "3\n3 2 3", "3\n3 1 3", "10\n1 3 3 3 3 2 3 ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are N dishes, numbered 1, 2, \ldots, N. Initially, for each i (1 \leq i \leq N), Dish i has a_i (1 \leq a_i \leq 3) pieces of sushi on it. Taro will perform the following opera...
p03314 AtCoder Regular Contest 100 - Colorful Sequences_20907
You are given integers N, K, and an integer sequence A of length M. An integer sequence where each element is between 1 and K (inclusive) is said to be colorful when there exists a contiguous subsequence of length K of the sequence that contains one occurrence of each integer between 1 and K (inclusive). For every co...
MOD = 10 ** 9 + 7 n, k, m = map(int, input().split()) a = list(map(int, input().split())) def include_perm(a): for i in range(m - k + 1): seen = [False] * (k + 1) for j in range(i, i + k): if seen[a[j]]: break seen[a[j]] = True else: return...
{ "input": [ "3 2 1\n1", "4 2 2\n1 2", "5 4 3\n1 1 1", "25000 400 4\n3 7 31 127", "9954 310 12\n267 193 278 294 6 63 86 166 157 193 168 43", "10 3 5\n1 1 2 3 3", "7 4 5\n1 2 3 1 2", "3 0 1\n1", "4 2 2\n1 4", "24477 400 4\n3 7 31 127", "10 5 5\n1 1 2 3 3", "7 4 4\n1 2 3 ...
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, K, and an integer sequence A of length M. An integer sequence where each element is between 1 and K (inclusive) is said to be colorful when there exists a c...
p03471 AtCoder Beginner Contest 085 - Otoshidama_20911
The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situat...
n, y = map(int,input().split()) ans = [-1,-1,-1] for i in range(n+1): for j in range(n+1-i): if 10000*i + 5000*j + 1000*(n-i-j) == y: ans = [i,j,n-i-j] print(*ans)
{ "input": [ "1000 1234000", "9 45000", "20 196000", "2000 20000000", "0000 1234000", "6 45000", "0000 0", "20 318832", "2000 25743705", "0000 841858", "6 3463", "20 93731", "2000 40151179", "0000 383974", "6 3596", "20 119339", "0100 383974", "1...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year mo...
p03633 AtCoder Beginner Contest 070 - Multiple Clocks_20915
We have N clocks. The hand of the i-th clock (1≤i≤N) rotates through 360° in exactly T_i seconds. Initially, the hand of every clock stands still, pointing directly upward. Now, Dolphin starts all the clocks simultaneously. In how many seconds will the hand of every clock point directly upward again? Constraints * 1≤...
from fractions import gcd from functools import reduce n, *T = map(int, open(0).read().split()) print(reduce(lambda x, y:x*y//gcd(x, y), T))
{ "input": [ "5\n2\n5\n10\n1000000000000000000\n1000000000000000000", "2\n2\n3", "5\n2\n5\n10\n1000000001000000000\n1000000000000000000", "2\n2\n5", "5\n2\n6\n10\n1000000001000000000\n1000000000000000000", "2\n3\n5", "5\n2\n6\n10\n1001000001000000000\n1000000000000000000", "2\n3\n3", ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: We have N clocks. The hand of the i-th clock (1≤i≤N) rotates through 360° in exactly T_i seconds. Initially, the hand of every clock stands still, pointing directly upward. Now, Dolph...
p03791 Mujin Programming Challenge 2017 - Robot Racing_20919
You are developing frog-shaped robots, and decided to race them against each other. First, you placed N robots onto a number line. These robots are numbered 1 through N. The current coordinate of robot i is x_i. Here, all x_i are integers, and 0 < x_1 < x_2 < ... < x_N. You will repeatedly perform the following opera...
input() a=b=1 for r in input().split(): a=a*b%(10**9+7) if b*2<eval(r+'+2'):b+=1 print(a)
{ "input": [ "13\n4 6 8 9 10 12 14 15 16 18 20 21 22", "3\n1 2 3", "3\n2 3 4", "8\n1 2 3 5 7 11 13 17", "13\n4 11 8 9 10 12 14 15 16 18 20 21 22", "3\n0 2 3", "3\n2 3 8", "13\n3 16 8 9 10 19 12 24 16 18 20 21 6", "3\n9 1 14", "8\n2 2 3 5 7 11 13 17", "3\n0 0 8", "13\n4 ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are developing frog-shaped robots, and decided to race them against each other. First, you placed N robots onto a number line. These robots are numbered 1 through N. The current ...
p03959 CODE FESTIVAL 2016 qual C - Two Alpinists_20923
Mountaineers Mr. Takahashi and Mr. Aoki recently trekked across a certain famous mountain range. The mountain range consists of N mountains, extending from west to east in a straight line as Mt. 1, Mt. 2, ..., Mt. N. Mr. Takahashi traversed the range from the west and Mr. Aoki from the east. The height of Mt. i is h_i...
N=int(input()) T = list(map(int, input().split())) A = list(map(int, input().split())) a = 1 if T[0]>A[0] or A[-1]>T[-1] or T[-1]!=A[0]: a*=0 for i in range(1,N-1): if T[i-1]!=T[i]: if T[i]>A[i]: a*=0 break else: a*=1 elif A[i]!=A[i+1]: ...
{ "input": [ "5\n1 3 3 3 3\n3 3 2 2 2", "10\n1 3776 3776 8848 8848 8848 8848 8848 8848 8848\n8848 8848 8848 8848 8848 8848 8848 8848 3776 5", "1\n17\n17", "5\n1 1 1 2 2\n3 2 1 1 1", "5\n2 3 3 3 3\n3 3 2 2 2", "5\n1 1 1 2 2\n6 2 1 1 1", "5\n1 1 1 4 2\n6 2 1 1 1", "5\n1 1 1 4 2\n6 2 1 1 ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Mountaineers Mr. Takahashi and Mr. Aoki recently trekked across a certain famous mountain range. The mountain range consists of N mountains, extending from west to east in a straight ...
p00051 Differential II_20927
When you enter 8 numbers from 0 to 9, write a program that outputs the difference between the largest integer and the smallest integer that can sort the 8 numbers. The number that can be sorted may start from 0, such as 00135569. Input Given multiple datasets. The number of datasets n (n ≤ 50) is given on the first...
n=int(input()) for _ in range(n): c=[i for i in input()] Max=int("".join(sorted(c,reverse=True))) Min=int("".join(sorted(c))) print(Max-Min)
{ "input": [ "2\n65539010\n65539010", "2\n65539010\n102034250", "2\n65539010\n31390532", "2\n65539010\n31927280", "2\n65539010\n40089442", "2\n65539010\n45258123", "2\n65539010\n53937586", "2\n65539010\n66277190", "2\n124008976\n66277190", "2\n188122632\n66277190", "2\n1691...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: When you enter 8 numbers from 0 to 9, write a program that outputs the difference between the largest integer and the smallest integer that can sort the 8 numbers. The number that can...
p00181 Bookshelf_20931
Taro is addicted to a novel. The novel has n volumes in total, and each volume has a different thickness. Taro likes this novel so much that he wants to buy a bookshelf dedicated to it. However, if you put a large bookshelf in the room, it will be quite small, so you have to devise to make the width of the bookshelf as...
import bisect def main(): m,n = list(map(int,input().split())) if n==0: exit() W = [int(input()) for _ in range(n)] w_total = 0 w_sum =[] for w in W: w_total+=w w_sum.append(w_total) def judge(shelf_length): last_val = 0 for i in range(m): ...
{ "input": [ "3 9\n500\n300\n800\n200\n100\n600\n900\n700\n400\n4 3\n1000\n1000\n1000\n0 0", "3 9\n500\n300\n800\n200\n100\n600\n900\n700\n400\n4 3\n1000\n1000\n1010\n0 0", "3 9\n500\n311\n800\n335\n100\n600\n900\n700\n400\n4 3\n1000\n1000\n1010\n0 0", "3 9\n559\n311\n800\n335\n100\n563\n900\n700\n400...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Taro is addicted to a novel. The novel has n volumes in total, and each volume has a different thickness. Taro likes this novel so much that he wants to buy a bookshelf dedicated to i...
p00337 Road Planning_20934
Villages were scattered in the Wakamatsu Plain of Aizu. Several settlements are connected by straight roads that allow them to travel to and from each other, and any settlement in the plain can be traced back and forth. Each road has a lengthy maintenance fee, but all the settlements funded the road to maintain it. At...
import sys def graham_scan(vertices: list): from math import atan2 from operator import itemgetter vertices.sort(key=itemgetter(1)) base_x, base_y = vertices[0][:2] vertices = sorted(vertices[1:], key=lambda p: atan2(p[1]-base_y, p[0]-base_x)) + vertices[:1] convex = vertices[-1:] + vertices[...
{ "input": [ "5 5\n0 0\n1 1\n3 0\n3 2\n0 2\n1 2\n2 3\n2 4\n3 4\n1 5", "7 6\n0 2\n3 0\n2 2\n1 0\n4 1\n2 3\n3 5\n1 3\n2 4\n2 3\n3 5\n3 7\n6 7", "5 5\n0 0\n1 1\n3 0\n3 2\n0 2\n1 2\n3 3\n2 4\n3 4\n1 5", "7 6\n0 2\n3 0\n2 2\n1 0\n4 1\n2 3\n3 4\n1 3\n2 4\n2 3\n3 5\n3 7\n6 7", "7 6\n0 2\n3 0\n2 2\n1 0\n4...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Villages were scattered in the Wakamatsu Plain of Aizu. Several settlements are connected by straight roads that allow them to travel to and from each other, and any settlement in the...
p00528 Modern Mansion_20936
Modern Mansion You got lost in a big mansion. This mansion has a structure in which square rooms are arranged in a grid pattern from north, south, east, and west, with M columns in the east-west direction and N rows in the north-south direction, for a total of M x N. The room in the xth column (1 ≤ x ≤ M) from the wes...
from heapq import heappush, heappop M, N, K = map(int, input().split()) X = [[] for i in range(M)] Y = [[] for i in range(N)] for i in range(K): x, y = map(int, input().split()); x -= 1; y -= 1 X[x].append((y, i)) Y[y].append((x, i)) G0 = [[] for i in range(K)] G1 = [[] for i in range(K)] for x in range(...
{ "input": [ "3 2 1\n1 2", "3 2 1\n2 2", "4 2 2\n1 2", "2 2 1\n1 2", "3 2 1\n2 0", "3 2 1\n4 0", "3 2 1\n0 0", "3 1 1\n1 2", "3 2 1\n2 1", "3 0 1\n2 0", "6 2 1\n4 0", "3 1 1\n0 2", "0 0 1\n2 0", "6 2 1\n4 1", "3 1 2\n0 2", "0 0 1\n4 0", "6 2 1\n4 2",...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Modern Mansion You got lost in a big mansion. This mansion has a structure in which square rooms are arranged in a grid pattern from north, south, east, and west, with M columns in t...
p00695 Get a Rectangular Field_20939
Karnaugh is a poor farmer who has a very small field. He wants to reclaim wasteland in the kingdom to get a new field. But the king who loves regular shape made a rule that a settler can only get a rectangular land as his field. Thus, Karnaugh should get the largest rectangular land suitable for reclamation. The map o...
# AOJ 1114: Get a Rectangular Field # Python3 2018.7.8 bal4u s = [[0 for c in range(6)] for r in range(6)] for k in range(int(input())): if k > 0: input() for r in range(5): a = list(map(int, input().split())) for c in range(5): s[r+1][c+1] = s[r+1][c]+a[c] ans = 0; for r in range(1, 6): for c in range(1, 6)...
{ "input": [ "3\n1 1 0 1 0\n0 1 1 1 1\n1 0 1 0 1\n0 1 1 1 0\n0 1 1 0 0\n\n0 1 0 1 1\n0 1 0 1 0\n0 0 1 0 0\n0 0 1 1 0\n1 0 1 0 0\n\n1 1 1 1 0\n0 1 1 1 0\n0 1 1 0 1\n0 1 1 1 0\n0 0 0 0 1", "3\n1 1 0 1 0\n0 1 1 1 1\n1 0 1 0 1\n0 1 1 1 0\n0 1 1 0 0\n\n0 1 0 1 1\n0 1 0 1 0\n0 0 1 0 0\n0 0 1 1 0\n1 0 0 0 0\n\n1 1 1...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Karnaugh is a poor farmer who has a very small field. He wants to reclaim wasteland in the kingdom to get a new field. But the king who loves regular shape made a rule that a settler ...
p00836 Sum of Consecutive prime Numbers_20943
Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representations does a given positive integer have? For example, the integer 53 has two representations 5 + 7 + 11 + 13 + 17 and 53. The integer 41 has three representations 2 + 3 + 5 + 7 + 11 + 13, 11 + 13 + 17, ...
def solve(): # making a list of prime numbers primes = [2, 3] for n in range(5, 10000, 2): l = n ** 0.5 for p in primes: if n % p == 0: break if l < p: primes.append(n) break primes = [0] + primes from ...
{ "input": [ "2\n3\n17\n41\n20\n666\n12\n53\n0", "2\n3\n17\n41\n20\n666\n24\n53\n0", "2\n3\n17\n41\n20\n666\n24\n56\n0", "2\n3\n17\n41\n20\n666\n24\n20\n0", "2\n3\n17\n41\n20\n666\n46\n53\n0", "2\n3\n17\n70\n20\n666\n24\n56\n0", "2\n3\n17\n34\n20\n666\n24\n20\n0", "2\n6\n17\n34\n20\n66...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representations does a given positive integer have? For example, the integer...
p00968 Digits Are Not Just Characters_20947
Digits Are Not Just Characters Mr. Manuel Majorana Minore made a number of files with numbers in their names. He wants to have a list of the files, but the file listing command commonly used lists them in an order different from what he prefers, interpreting digit sequences in them as ASCII code sequences, not as numb...
n = int(input()) ss = [input() for _ in range(n + 1)] sp = [[s[0]] for s in ss] for i, s in enumerate(ss): for j in range(1, len(s)): if s[j - 1].isdigit() != s[j].isdigit(): sp[i].append('') sp[i][-1] += s[j] s0 = sp[0] for s in sp[1:]: p = 0 m = min(len(s0), len(s)) while p...
{ "input": [ "2\nfile10\nfile20\nfile3", "2\nfile10\nfi2el0\nfile3", "2\nfjle10\nfi2el0\niele3", "2\n01eljf\nfi2el0\niele3", "2\nflje10\nif3el0\n2elei", "2\nfile10\nfi2el0\neile3", "2\nfjle10\nfi2el0\neile3", "2\n01eljf\nfi2el0\niele2", "2\n01ejlf\nfi2el0\niele2", "2\n01ejlf\nf...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Digits Are Not Just Characters Mr. Manuel Majorana Minore made a number of files with numbers in their names. He wants to have a list of the files, but the file listing command commo...
p01100 Gift Exchange Party_20950
Gift Exchange Party A gift exchange party will be held at a school in TKB City. For every pair of students who are close friends, one gift must be given from one to the other at this party, but not the other way around. It is decided in advance the gift directions, that is, which student of each pair receives a gift....
from collections import deque import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): N, M = map(int, readline().split()) if N == M == 0: return False G = [[] for i in range(N)] cs = [0]*N for i in range(M): u, v = map(int, readline().split()) forward =...
{ "input": [ "3 3\n1 2\n2 3\n1 3\n4 3\n1 2\n1 3\n1 4\n4 6\n1 2\n1 3\n1 4\n2 3\n3 4\n2 4\n0 0", "3 3\n1 2\n2 3\n1 3\n4 3\n1 2\n1 3\n1 4\n4 6\n1 2\n1 3\n1 2\n2 3\n3 4\n2 4\n0 0", "3 3\n2 2\n2 3\n2 3\n4 3\n1 2\n1 3\n1 4\n4 6\n1 4\n1 3\n1 4\n2 3\n3 4\n2 4\n0 0", "3 3\n2 2\n2 3\n2 3\n4 3\n1 2\n1 3\n1 4\n6 ...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Gift Exchange Party A gift exchange party will be held at a school in TKB City. For every pair of students who are close friends, one gift must be given from one to the other at thi...
p01552 YAML_20956
YAML (YAML Ain't Markup Language) is one of the formats for expressing an object as a character string. You will be given an object represented by a subset of YAML and a query that specifies the property, so please answer the value of the specified property. Subset of YAML A subset of YAML follows the syntax rules e...
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**13 mod = 10**9+9 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin....
{ "input": [ ".tweets.1\nname: shimeji\nid: shimejitan\ntweets:\n1: shimejilove\n2: azupero", ".no.such.property\nobject:\nprop1: str\nprop2: str", ".tweets.1\nname: shimeji\nid: shimejitan\ntweets:\n 1: shimejilove\n 2: azupero", ".my.obj\nmy:\nstr: string value\nobj:\na: a\nb: b\nc: c", ".a\na...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: YAML (YAML Ain't Markup Language) is one of the formats for expressing an object as a character string. You will be given an object represented by a subset of YAML and a query that s...
p01708 Points and Lines_20959
Problem Statement One day, you found an old scroll with strange texts on it. You revealed that the text was actually an expression denoting the position of treasure. The expression consists of following three operations: * From two points, yield a line on which the points lie. * From a point and a line, yield a poin...
digits = "-0123456789" def cross_point(P, Q): x0, y0, x1, y1 = P x2, y2, x3, y3 = Q dx0 = x1 - x0; dy0 = y1 - y0 dx1 = x3 - x2; dy1 = y3 - y2 s = (y0-y2)*dx1 - (x0-x2)*dy1 sm = dx0*dy1 - dy0*dx1 if s < 0: s = -s sm = -sm if s == 0: x = x0 y = y0 else:...
{ "input": [ "((0,0)@(1,1))@((4,1)@(2,5))\n((0,0)@(3,1))@((1,-3)@(2,-1))\n(0,0)@(1,1)@(4,1)\n(0,0)@((1,1)@(4,1))\n(((0,0)@((10,20)@(((30,40))))))\n((0,0)@(3,1))@((1,-3)@(2,-1))@(100,-100)@(100,100)\n#", "((0,0)@(1,1))@((4,1)@(2,5))\n((0,0)@(3,1))@((1,-3)@(2,-1))\n(0,0)@(1,1)@(4,1)\n(0,0)@((1,1)@(4,1))\n(((0,0...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Problem Statement One day, you found an old scroll with strange texts on it. You revealed that the text was actually an expression denoting the position of treasure. The expression ...
p01853 Lie with Mean Value_20961
Problem statement N first-year students of the Faculty of Information Science and Technology of R University take the final exam of the lecture called Programming Exercise 1. The test is a perfect score of m. In other words, the score that one student can get is an integer between 0 and m. Since the teacher in charge...
# -*- coding: utf-8 -*- (n,m)=[int(a) for a in input().split()] for i in range(n): if i:print(" ",end="") if i<=n/2: print("0",end="") else: print("{}".format(m),end="") print("")
{ "input": [ "3 100", "5 100", "5 110", "5 111", "6 110", "9 110", "9 100", "5 101", "10 110", "14 110", "9 000", "5 000", "20 110", "11 110", "9 010", "5 001", "20 010", "15 110", "14 100", "20 000", "16 110", "14 101", "22 0...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Problem statement N first-year students of the Faculty of Information Science and Technology of R University take the final exam of the lecture called Programming Exercise 1. The tes...
p02275 Counting Sort_20967
Counting sort can be used for sorting elements in an array which each of the n input elements is an integer in the range 0 to k. The idea of counting sort is to determine, for each input element x, the number of elements less than x as C[x]. This information can be used to place element x directly into its position in ...
# 計数ソート # https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/6/ALDS1_6_A # 計算量 O(n+k) import sys input = sys.stdin.buffer.readline n = int(input()) A = [int(i) for i in input().split()] B = [None] * n C = [0] * 10001 for a in A: C[a] += 1 for i in range(10001): C[i] = C[i - 1] + C[i] for j in range(n)...
{ "input": [ "7\n2 5 1 3 2 3 0", "7\n2 5 1 3 2 3 1", "7\n2 5 1 3 4 3 1", "7\n2 5 2 3 4 3 1", "7\n4 5 2 3 4 3 1", "7\n4 9 2 3 4 3 1", "7\n4 9 2 3 4 3 2", "7\n4 9 2 1 4 3 2", "7\n4 9 2 0 4 3 3", "7\n8 9 2 0 4 3 3", "7\n8 9 2 0 6 3 3", "7\n8 9 3 0 6 3 3", "7\n5 9 3 0 6...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Counting sort can be used for sorting elements in an array which each of the n input elements is an integer in the range 0 to k. The idea of counting sort is to determine, for each in...
p02422 Transformation_20971
Transformation Write a program which performs a sequence of commands to a given string $str$. The command is one of: * print a b: print from the a-th character to the b-th character of $str$ * reverse a b: reverse from the a-th character to the b-th character of $str$ * replace a b p: replace from the a-th charact...
str = input("") q = int(input()) for i in range(q): line = input().split() c = line[0] a = int(line[1]) b = int(line[2]) + 1 if c == 'replace': str = str[:a] + line[3] + str[b:] elif c == 'reverse': str = str[:a] + str[a:b][::-1] + str[b:] else: print(str[a:b])
{ "input": [ "abcde\n3\nreplace 1 3 xyz\nreverse 0 2\nprint 1 4", "xyz\n3\nprint 0 2\nreplace 0 2 abc\nprint 0 2", "abcde\n3\nreplace 1 3 xy{\nreverse 0 2\nprint 1 4", "xyz\n3\nprint 0 2\nreplace 1 2 abc\nprint 0 2", "abcde\n3\nreplace 1 3 xy{\nreverse 0 2\nprint 1 2", "abcde\n3\nreplace 1 3 y...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Transformation Write a program which performs a sequence of commands to a given string $str$. The command is one of: * print a b: print from the a-th character to the b-th charac...
1011_D. Rocket_20980
This is an interactive problem. Natasha is going to fly to Mars. Finally, Natasha sat in the rocket. She flies, flies... but gets bored. She wishes to arrive to Mars already! So she decides to find something to occupy herself. She couldn't think of anything better to do than to calculate the distance to the red planet...
from sys import stdin from math import * from sys import stdout line = stdin.readline().rstrip().split() m = int(line[0]) n = int(line[1]) bits = [] for i in range(n): print(m) stdout.flush() line = stdin.readline().rstrip().split() res = int(line[0]) if res == 0: exit(0) if res == 1: ...
{ "input": [ "5 2\n1\n-1\n-1\n1\n0\n", "1000000000 2 999999998\n0 1\n", "1000000000 1 77000000\n0\n", "3000000 20 642518\n1 0 0 1 0 1 1 1 1 1 0 0 0 1 0 1 0 1 0 1\n", "100000 16 79154\n1 1 1 0 0 0 0 0 1 1 0 1 0 1 0 1\n", "10000000 22 8115129\n1 0 1 0 0 0 0 0 0 1 1 0 1 0 0 0 0 1 1 0 0 1\n", ...
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. Natasha is going to fly to Mars. Finally, Natasha sat in the rocket. She flies, flies... but gets bored. She wishes to arrive to Mars already! So she ...
1036_E. Covered Points_20983
You are given n segments on a Cartesian plane. Each segment's endpoints have integer coordinates. Segments can intersect with each other. No two segments lie on the same line. Count the number of distinct points with integer coordinates, which are covered by at least one segment. Input The first line contains a sing...
import sys from math import gcd class Segment: def __init__(self, x1, y1, x2, y2): self.x1 = x1 self.y1 = y1 self.x2 = x2 self.y2 = y2 def dx(self): return self.x2 - self.x1 def dy(self): return self.y2 - self.y1 def pt_cnt(self): ...
{ "input": [ "4\n-1 2 1 2\n-1 0 1 0\n-1 0 0 3\n0 3 1 0\n", "9\n0 0 4 4\n-1 5 4 0\n4 0 4 4\n5 2 11 2\n6 1 6 7\n5 6 11 6\n10 1 10 7\n7 0 9 8\n10 -1 11 -1\n", "10\n78 31 22 16\n58 8 58 44\n24 59 49 40\n97 77 39 24\n8 2 33 83\n96 11 66 59\n20 38 47 76\n8 5 47 97\n19 71 82 36\n91 29 95 95\n", "2\n454379 37...
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 a Cartesian plane. Each segment's endpoints have integer coordinates. Segments can intersect with each other. No two segments lie on the same line. Count ...
1059_D. Nature Reserve_20987
There is a forest that we model as a plane and live n rare animals. Animal number i has its lair in the point (x_{i}, y_{i}). In order to protect them, a decision to build a nature reserve has been made. The reserve must have a form of a circle containing all lairs. There is also a straight river flowing through the f...
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.wr...
{ "input": [ "2\n0 1\n1 1\n", "1\n0 1\n", "3\n0 1\n0 2\n0 -3\n", "3\n8376968 152285\n-8928555 5949944\n-4450793 4397692\n", "4\n7562857 4638477\n2230312 4253055\n-9291686 9317264\n-6643279 5426447\n", "2\n0 1\n1 1\n", "3\n1367642 1559668\n-190618 8836498\n-976468 4184452\n", "4\n-10000...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There is a forest that we model as a plane and live n rare animals. Animal number i has its lair in the point (x_{i}, y_{i}). In order to protect them, a decision to build a nature re...
10_E. Greedy Change_20993
Billy investigates the question of applying greedy algorithm to different spheres of life. At the moment he is studying the application of greedy algorithm to the problem about change. There is an amount of n coins of different face values, and the coins of each value are not limited in number. The task is to collect t...
__author__ = 'Darren' def solve(): n = int(input()) coins = list(map(int, input().split())) def greedy(amount): num = 0 for i in range(n): num += amount // coins[i] amount %= coins[i] return num result = 1 << 31 for i in range(1, n): for j ...
{ "input": [ "3\n4 3 1\n", "5\n25 10 5 2 1\n", "9\n487264 453898 452366 383095 172725 168148 164570 141228 1\n", "28\n434419 433070 431479 424448 423449 392416 368998 367310 329030 316399 311541 302510 283863 262469 257928 248272 242310 217371 183364 172064 164154 131734 131169 117466 23544 19990 1100...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Billy investigates the question of applying greedy algorithm to different spheres of life. At the moment he is studying the application of greedy algorithm to the problem about change...
1121_D. Diana and Liana_20997
At the first holiday in spring, the town Shortriver traditionally conducts a flower festival. Townsfolk wear traditional wreaths during these festivals. Each wreath contains exactly k flowers. The work material for the wreaths for all n citizens of Shortriver is cut from the longest flowered liana that grew in the tow...
def main(): m, k, n, s = map(int, input().split()) a = list(map(int, input().split())) # prevbug: input in a line! b = list(map(int, input().split())) # prevbug: convert to list b_dict = {} for x in b: b_dict.setdefault(x, 0) b_dict[x] += 1 # prevbug: b or b_dict left = 0 ...
{ "input": [ "13 4 3 3\n3 2 6 4 1 4 4 7 1 3 3 2 4\n4 3 4\n", "13 4 1 3\n3 2 6 4 1 4 4 7 1 3 3 2 4\n4 3 4\n", "7 3 2 2\n1 2 3 3 2 1 2\n2 2\n", "2 2 1 2\n1 2\n2 1\n", "13 4 1 3\n3 2 6 4 1 4 4 7 1 3 3 2 4\n4 3 4\n", "2 2 1 2\n1 2\n1 1\n", "10 5 2 2\n2 2 2 2 2 1 1 1 1 1\n3 3\n", "100 15 6 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: At the first holiday in spring, the town Shortriver traditionally conducts a flower festival. Townsfolk wear traditional wreaths during these festivals. Each wreath contains exactly k...
116_C. Party_21004
A company has n employees numbered from 1 to n. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An employee A is said to be the superior of another employee B if at least one of the following is true: * Employee A is the immediate manag...
def findDepth(a, i): depth = 1 nextLevel = a[i][:] while len(nextLevel) > 0: depth += 1 children = nextLevel[:] nextLevel = [] for child in children: nextLevel += a[child] return depth n = int(input()) a = [] for i in range(n): a.append([]) ro...
{ "input": [ "5\n-1\n1\n2\n1\n-1\n", "12\n-1\n8\n9\n-1\n4\n2\n11\n1\n-1\n6\n-1\n10\n", "5\n4\n5\n1\n-1\n4\n", "12\n-1\n9\n11\n6\n6\n-1\n6\n3\n8\n6\n1\n6\n", "4\n-1\n1\n2\n3\n", "12\n3\n8\n9\n12\n2\n8\n11\n12\n2\n9\n-1\n11\n", "5\n2\n3\n4\n5\n-1\n", "12\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n-1\n...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: A company has n employees numbered from 1 to n. Each employee either has no immediate manager or exactly one immediate manager, who is another employee with a different number. An emp...
1188_B. Count Pairs_21008
You are given a prime number p, n integers a_1, a_2, …, a_n, and an integer k. Find the number of pairs of indexes (i, j) (1 ≤ i < j ≤ n) for which (a_i + a_j)(a_i^2 + a_j^2) ≡ k mod p. Input The first line contains integers n, p, k (2 ≤ n ≤ 3 ⋅ 10^5, 2 ≤ p ≤ 10^9, 0 ≤ k ≤ p-1). p is guaranteed to be prime. The se...
def check(num1, num2, p, k): v = num1 + num2 v *= num1 * num1 + num2 * num2 v %= p v += p v %= p return v == k % p if __name__ == '__main__': n, p, k = (int(x) for x in input().split()) idx___number = [int(x) for x in input().split()] idx___precount = [((pow(x, 4, p) - k * x) % p ...
{ "input": [ "6 7 2\n1 2 3 4 5 6\n", "3 3 0\n0 1 2\n", "3 3 0\n0 2 1\n", "2 2 1\n1 0\n", "3 3 2\n0 1 2\n", "7 7 3\n4 0 5 3 1 2 6\n", "2 37 5\n30 10\n", "2 2 0\n1 0\n", "5 5 3\n3 0 4 1 2\n", "3 3 1\n0 2 1\n", "2 37 5\n56 10\n", "2 2 0\n2 0\n", "2 37 5\n76 10\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given a prime number p, n integers a_1, a_2, …, a_n, and an integer k. Find the number of pairs of indexes (i, j) (1 ≤ i < j ≤ n) for which (a_i + a_j)(a_i^2 + a_j^2) ≡ k mo...
1207_C. Gas Pipeline_21012
You are responsible for installing a gas pipeline along a road. Let's consider the road (for simplicity) as a segment [0, n] on OX axis. The road can have several crossroads, but for simplicity, we'll denote each crossroad as an interval (x, x + 1) with integer x. So we can represent the road as a binary string consist...
import math t = int(input()) for _ in range(t): (n, a, b) = [int(x) for x in input().split()] s = input() #print((n, a, b, s)) gap = math.ceil((2 * a) / b) + 1 #print((a, b, gap)) cost = b state = 0 b2 = 2 * b streak0 = 0 for i in range(n-1): if s[i] == '1': streak0 = 0 else: streak0 += 1 if...
{ "input": [ "4\n8 2 5\n00110010\n8 1 1\n00110010\n9 100000000 100000000\n010101010\n2 5 1\n00\n", "2\n2 3 5\n00\n12 4 7\n011101011100\n", "2\n8 2 5\n01111110\n6 2 5\n001010\n", "2\n2 3 8\n00\n12 4 7\n011101011100\n", "2\n8 2 5\n01101110\n6 2 5\n001010\n", "2\n8 2 5\n00101110\n6 2 5\n001010\n"...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are responsible for installing a gas pipeline along a road. Let's consider the road (for simplicity) as a segment [0, n] on OX axis. The road can have several crossroads, but for ...
1225_D. Power Products_21016
You are given n positive integers a_1, …, a_n, and an integer k ≥ 2. Count the number of pairs i, j such that 1 ≤ i < j ≤ n, and there exists an integer x such that a_i ⋅ a_j = x^k. Input The first line contains two integers n and k (2 ≤ n ≤ 10^5, 2 ≤ k ≤ 100). The second line contains n integers a_1, …, a_n (1 ≤ a_...
from collections import defaultdict import sys as _sys def main(): n, k = _read_ints() a = tuple(_read_ints()) result = find_good_pairs_n(a, k) print(result) def _read_line(): result = _sys.stdin.readline() assert result[-1] == "\n" return result[:-1] def _read_ints(): return map(i...
{ "input": [ "6 3\n1 3 9 8 24 1\n", "2 5\n49248 87211\n", "100 3\n94 94 83 27 80 73 61 38 34 95 72 96 59 36 78 15 83 78 39 22 21 57 54 59 9 32 81 64 94 90 67 41 18 57 93 76 44 62 77 61 31 70 39 73 81 57 43 31 27 85 36 26 44 26 75 23 66 53 3 14 40 67 53 19 70 81 98 12 91 15 92 90 89 86 58 30 67 73 72 69 68...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given n positive integers a_1, …, a_n, and an integer k ≥ 2. Count the number of pairs i, j such that 1 ≤ i < j ≤ n, and there exists an integer x such that a_i ⋅ a_j = x^k. ...
1249_F. Maximum Weight Subset_21020
You are given a tree, which consists of n vertices. Recall that a tree is a connected undirected graph without cycles. <image> Example of a tree. Vertices are numbered from 1 to n. All vertices have weights, the weight of the vertex v is a_v. Recall that the distance between two vertices in the tree is the number o...
n, k = map(int, input().split()) a = list(map(int, input().split())) g = {} def dfs(v, p=-1): c = [dfs(child, v) for child in g.get(v, set()) - {p}] c.sort(key=len, reverse=True) r = [] i = 0 while c: if i >= len(c[-1]): c.pop() else: o = max(i, k - i - 1) s = q = 0 for x in c: if len(x) <= o:...
{ "input": [ "7 2\n2 1 2 1 2 1 1\n6 4\n1 5\n3 1\n2 3\n7 5\n7 4\n", "5 1\n1 2 3 4 5\n1 2\n2 3\n3 4\n3 5\n", "14 2\n3 2 3 1 2 3 4 2 3 1 4 2 1 3\n12 10\n2 7\n13 12\n14 11\n10 5\n1 2\n11 4\n4 9\n14 8\n12 4\n7 9\n13 6\n10 3\n", "10 2\n4 1 4 4 2 3 2 1 1 4\n1 7\n1 3\n8 3\n3 6\n4 1\n1 2\n9 7\n8 10\n1 5\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given a tree, which consists of n vertices. Recall that a tree is a connected undirected graph without cycles. <image> Example of a tree. Vertices are numbered from 1 to n....
1268_C. K Integers_21024
You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,…, k, in other words in the end there should be an integer i, 1 ≤ i ≤ n-k+1 such that p_i = 1, p_{i+1} = 2, …, p_{i+k-1}=k. ...
import sys input = sys.stdin.buffer.readline # all operations are log(n) class bit: def __init__(self, n): self.n = n+1 self.mx_p = 0 while 1 << self.mx_p < self.n: self.mx_p += 1 self.a = [0]*(self.n) self.tot = 0 def add(self, idx, val): self.tot +...
{ "input": [ "5\n5 4 3 2 1\n", "3\n1 2 3\n", "100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given a permutation p_1, p_2, …, p_n. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a su...
1333_C. Eugene and an array_21031
Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array c is a subarray of an array b if c can be obtained from b by deletion of several (possibly, zero or all) elements from the beginning and several (possibly, zero or all) elements from the end. Let's call a nonempty...
import sys import heapq def input(): return sys.stdin.readline().strip() def iinput(): return int(input()) def rinput(): return map(int, input().split()) def rlinput(): return list(map(int, input().split())) def YES(flag): if flag: return "YES" return "NO" def main(): #n ...
{ "input": [ "3\n1 2 -3\n", "3\n41 -41 41\n", "1\n-1\n", "1\n0\n", "2\n1 1\n", "1\n1\n", "2\n1 0\n", "2\n-1 -1\n", "2\n-1 0\n", "2\n-1 1\n", "2\n0 0\n", "2\n1 -1\n", "2\n0 -1\n", "2\n0 1\n", "1\n-2\n", "2\n2 1\n", "3\n1 3 -3\n", "3\n41 -60 41\n",...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Eugene likes working with arrays. And today he needs your help in solving one challenging task. An array c is a subarray of an array b if c can be obtained from b by deletion of seve...
1353_F. Decreasing Heights_21035
You are playing one famous sandbox game with the three-dimensional world. The map of the world can be represented as a matrix of size n × m, where the height of the cell (i, j) is a_{i, j}. You are in the cell (1, 1) right now and want to get in the cell (n, m). You can move only down (from the cell (i, j) to the cell...
#!/usr/bin/env python import os import sys from io import BytesIO, IOBase def main(): for _ in range(int(input())): n,m=map(int,input().split()) a=[ [int(x) for x in input().split()] for _ in range(n)] if m>n: b=[ [a[j][i] for j in range(n)] for i in range(m)] a...
{ "input": [ "5\n3 4\n1 2 3 4\n5 6 7 8\n9 10 11 12\n5 5\n2 5 4 8 3\n9 10 11 5 1\n12 8 4 2 5\n2 2 5 4 1\n6 8 2 4 2\n2 2\n100 10\n10 1\n1 2\n123456789876543 987654321234567\n1 1\n42\n", "1\n8 6\n1 2 3 4 5 6\n7 8 9 10 11 12\n13 14 15 16 17 18\n19 20 21 22 23 24\n26 27 28 29 30 31\n33 34 35 36 34 35\n37 38 39 40 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are playing one famous sandbox game with the three-dimensional world. The map of the world can be represented as a matrix of size n × m, where the height of the cell (i, j) is a_{...
1373_E. Sum of Digits_21039
Let f(x) be the sum of digits of a decimal number x. Find the smallest non-negative integer x such that f(x) + f(x + 1) + ... + f(x + k) = n. Input The first line contains one integer t (1 ≤ t ≤ 150) — the number of test cases. Each test case consists of one line containing two integers n and k (1 ≤ n ≤ 150, 0 ≤ k ...
def generate_prefix(su): pre = "" if su >= 8: pre += '8' su -= 8 if len(pre) > 0: nu = 9 else: nu = 8 while su > 0: while su >= nu: su -= nu pre += str(nu) nu -= 1 pre = pre[::-1] return pre def get_number(su, nines, d...
{ "input": [ "7\n1 0\n1 1\n42 7\n13 7\n99 1\n99 0\n99 2\n", "2\n13 9\n17 9\n", "2\n13 9\n27 9\n", "7\n1 0\n1 1\n42 7\n13 7\n64 1\n99 0\n99 2\n", "2\n17 9\n47 9\n", "7\n1 0\n1 1\n42 7\n1 9\n64 0\n99 0\n99 2\n", "7\n1 0\n2 1\n42 7\n1 9\n64 0\n99 0\n99 2\n", "2\n20 9\n46 9\n", "7\n1 0...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Let f(x) be the sum of digits of a decimal number x. Find the smallest non-negative integer x such that f(x) + f(x + 1) + ... + f(x + k) = n. Input The first line contains one inte...
1420_A. Cubes Sorting_21045
For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for? Oh, that's funny, is it? Oh it's funny? Because we've been at this for twelve hours and you haven't solved it either, so I don't know why you're laughing. You've got ...
import sys import bisect input = sys.stdin.readline ins = lambda: input().rstrip() ini = lambda: int(input().rstrip()) inm = lambda: map(int, input().rstrip().split()) inl = lambda: list(map(int, input().split())) out = lambda x, s='\n': print(s.join(map(str, x))) t = ini() for _ in range(t): n = ini() a = inl...
{ "input": [ "3\n5\n5 3 2 1 4\n6\n2 2 2 2 2 2\n2\n2 1\n", "5\n2\n1 1\n2\n1 1000000000\n2\n1000000000 1\n2\n1000000000 1000000000\n2\n228 1337\n", "1\n3\n2 2 1\n", "1\n3\n2 2 0\n", "3\n5\n5 3 2 1 4\n6\n2 2 2 4 2 2\n2\n2 1\n", "3\n5\n5 3 2 1 4\n6\n2 2 2 4 2 2\n2\n2 2\n", "1\n3\n4 2 -2\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: For god's sake, you're boxes with legs! It is literally your only purpose! Walking onto buttons! How can you not do the one thing you were designed for? Oh, that's funny, is it? Oh i...
1463_E. Plan of Lectures_21050
Ivan is a programming teacher. During the academic year, he plans to give n lectures on n different topics. Each topic should be used in exactly one lecture. Ivan wants to choose which topic will he explain during the 1-st, 2-nd, ..., n-th lecture — formally, he wants to choose some permutation of integers from 1 to n ...
class Node: def __init__(self, value): self.value = value self.next = None self.prev = None def __repr__(self): if not self: return "{}()".format(self.__class__.__name__) return "{}({})".format(self.__class__.__name__, self.value) class LL: def __init__(...
{ "input": [ "5 2\n2 3 0 5 3\n1 5\n5 1\n", "5 4\n2 3 0 5 3\n2 1\n3 5\n5 2\n1 4\n", "5 2\n2 3 0 5 3\n1 5\n5 4\n", "5 1\n2 3 0 5 3\n4 5\n", "10 9\n8 8 9 9 7 3 2 0 5 5\n3 4\n9 3\n2 7\n10 6\n5 9\n8 2\n4 10\n1 5\n7 1\n", "10 6\n8 10 9 9 7 5 10 10 7 0\n8 1\n2 9\n5 6\n9 4\n6 2\n7 8\n", "10 8\n5 4...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Ivan is a programming teacher. During the academic year, he plans to give n lectures on n different topics. Each topic should be used in exactly one lecture. Ivan wants to choose whic...
148_E. Porcelain_21053
During her tantrums the princess usually smashes some collectable porcelain. Every furious shriek is accompanied with one item smashed. The collection of porcelain is arranged neatly on n shelves. Within each shelf the items are placed in one row, so that one can access only the outermost items — the leftmost or the r...
#!/usr/bin/env python3 import os import sys from io import BytesIO, IOBase class FastO: def __init__(self, fd=1): stream = BytesIO() self.flush = lambda: os.write(fd, stream.getvalue()) and not stream.truncate(0) and stream.seek(0) self.write = lambda b: stream.write(b.encode()) class ost...
{ "input": [ "2 3\n3 3 7 2\n3 4 1 5\n", "1 3\n4 4 3 1 2\n", "1 4\n6 5 1 10 1 1 5\n", "3 2\n1 10\n1 2\n1 5\n", "1 1\n1 100\n", "1 68\n100 26 58 15 8 69 66 49 97 18 74 27 39 19 76 37 25 4 88 75 17 79 41 21 44 39 7 42 63 82 92 87 41 85 25 30 43 80 95 70 98 88 16 15 97 74 81 76 33 19 64 3 14 72 17...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: During her tantrums the princess usually smashes some collectable porcelain. Every furious shriek is accompanied with one item smashed. The collection of porcelain is arranged neatly...
1512_C. A-B Palindrome_21057
You are given a string s consisting of the characters '0', '1', and '?'. You need to replace all the characters with '?' in the string s by '0' or '1' so that the string becomes a palindrome and has exactly a characters '0' and exactly b characters '1'. Note that each of the characters '?' is replaced independently fro...
import sys input = sys.stdin.readline for _ in range(int(input())): a,b=map(int,input().split()) s=list(input().rstrip()) l=len(s);question=s.count('?') f=0 for i in range(0,l//2): left=s[i];right=s[l-1-i] if left==right: if left=='0':a-=2 elif left=='1':b-=2 ...
{ "input": [ "9\n4 4\n01?????0\n3 3\n??????\n1 0\n?\n2 2\n0101\n2 2\n01?0\n0 1\n0\n0 3\n1?1\n2 2\n?00?\n4 3\n??010?0\n", "9\n4 4\n01?????0\n3 3\n??????\n1 0\n?\n2 2\n1101\n2 2\n01?0\n0 1\n0\n0 3\n1?1\n2 2\n?00?\n4 3\n??010?0\n", "9\n4 4\n01?????0\n3 3\n??????\n1 0\n?\n2 2\n1101\n2 2\n01?0\n0 1\n0\n0 3\n1?...
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 consisting of the characters '0', '1', and '?'. You need to replace all the characters with '?' in the string s by '0' or '1' so that the string becomes a pal...
208_C. Police Station_21064
The Berland road network consists of n cities and of m bidirectional roads. The cities are numbered from 1 to n, where the main capital city has number n, and the culture capital — number 1. The road network is set up so that it is possible to reach any city from any other one by the roads. Moving on each road in any d...
#build the graph with n cities and m roads #figure out all of the shortest paths from city 1 to city n #best=number of shortest paths (if we have police station at 1 or n) s=list(map(int,input().split())) n=s[0] m=s[1] roads=[] Adj=[] for i in range(0,n+1): roads.append([]) Adj.append([False]*(n+1)) for i in ...
{ "input": [ "11 14\n1 2\n1 3\n2 4\n3 4\n4 5\n4 6\n5 11\n6 11\n1 8\n8 9\n9 7\n11 7\n1 10\n10 4\n", "4 4\n1 2\n2 4\n1 3\n3 4\n", "34 53\n9 6\n25 28\n27 24\n15 18\n34 33\n27 30\n1 4\n4 7\n11 9\n11 8\n30 26\n15 12\n26 23\n17 15\n29 26\n11 15\n7 10\n14 12\n5 9\n8 5\n2 1\n24 21\n3 5\n14 17\n23 20\n25 22\n32 29...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: The Berland road network consists of n cities and of m bidirectional roads. The cities are numbered from 1 to n, where the main capital city has number n, and the culture capital — nu...
331_C1. The Great Julya Calendar_21077
Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar. The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plate with a magic integer on it. The translation from Old Beaverish is as follows: "May the Great Beaver bless you! May your chacres open ...
def maxx(n): l=[] while(n>0): l.append(n%10) n = int(n/10) return max(l) n =int(input()) j=0 while(n>0): n = n- maxx(n) j+=1 print(j)
{ "input": [ "24\n", "1000000\n", "47320\n", "222\n", "9\n", "1\n", "701\n", "11\n", "258634\n", "1995\n", "0\n", "77\n", "11010\n", "3\n", "5\n", "216\n", "12343\n", "31\n", "2033361\n", "1468\n", "844421\n", "7984\n", "10\n"...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Yet another Armageddon is coming! This time the culprit is the Julya tribe calendar. The beavers in this tribe knew math very well. Smart Beaver, an archaeologist, got a sacred plat...
353_C. Find Maximum_21081
Valera has array a, consisting of n integers a0, a1, ..., an - 1, and function f(x), taking an integer from 0 to 2n - 1 as its single argument. Value f(x) is calculated by formula <image>, where value bit(i) equals one if the binary representation of number x contains a 1 on the i-th position, and zero otherwise. For ...
n = int(input()) a = list(map(int, input().split())) s = input() ans = 0 sm = 0 for i in range(n): if s[i] == '1': ans = max(ans + a[i], sm) sm += a[i] print(ans)
{ "input": [ "5\n17 0 10 2 1\n11010\n", "2\n3 8\n10\n", "1\n1\n1\n", "43\n475 2165 8771 7146 8980 7209 9170 9006 6278 6661 4740 6321 7532 6869 3788 7918 1707 5070 3809 5189 2494 8255 1123 3197 190 5712 9873 3286 9997 133 9030 3067 8043 5297 5398 4240 8315 2141 1436 3297 247 8438 2300\n0111011100100011...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Valera has array a, consisting of n integers a0, a1, ..., an - 1, and function f(x), taking an integer from 0 to 2n - 1 as its single argument. Value f(x) is calculated by formula <im...
377_D. Developing Game_21084
Pavel is going to make a game of his dream. However, he knows that he can't make it on his own so he founded a development company and hired n workers of staff. Now he wants to pick n workers from the staff who will be directly responsible for developing a game. Each worker has a certain skill level vi. Besides, each ...
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": [ "6\n3 5 16\n1 6 11\n4 8 12\n7 9 16\n2 10 14\n8 13 15\n", "4\n2 8 9\n1 4 7\n3 6 8\n5 8 10\n", "18\n3 9 9\n41 42 43\n25 50 57\n51 55 57\n4 35 38\n18 26 33\n3 14 40\n36 52 55\n21 49 55\n56 56 56\n27 32 32\n16 26 47\n20 51 51\n3 19 31\n48 50 51\n56 56 56\n12 15 37\n41 48 54\n", "4\n1 1 1\n3 3...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Pavel is going to make a game of his dream. However, he knows that he can't make it on his own so he founded a development company and hired n workers of staff. Now he wants to pick n...
39_A. C*++ Calculations_21088
C*++ language is quite similar to C++. The similarity manifests itself in the fact that the programs written in C*++ sometimes behave unpredictably and lead to absolutely unexpected effects. For example, let's imagine an arithmetic expression in C*++ that looks like this (expression is the main term): * expression :...
import re n = int(input()) v = input() f1, f2 = v.count('a++'), v.count('++a') s = [] i = 0 while i < len(v) - 2: if v[i] + v[i + 1] + v[i + 2] == '++a': s.append('b') i += 3 elif v[i] + v[i + 1] + v[i + 2] == 'a++': s.append('a') i += 3 else: if i == len(v) - 2: s.extend(v[i:]) i = len(v) else: ...
{ "input": [ "3\na+++++a\n", "1\n5*a++-3*++a+a++\n", "-744\n672*a++-975*a++-394*a+++968*a+++222*a+++988*++a+504*++a-782*a++-321*++a+980*++a-483*a++-554*++a-347*++a-180*++a-390*a+++403*a++-617*a+++378*a+++544*++a-978*a+++952*a++-618*a++-516*++a-990*++a+540*++a-398*++a-187*++a+401*++a+829*a++-187*++a-185*a+...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: C*++ language is quite similar to C++. The similarity manifests itself in the fact that the programs written in C*++ sometimes behave unpredictably and lead to absolutely unexpected e...
424_B. Megacity_21092
The administration of the Tomsk Region firmly believes that it's time to become a megacity (that is, get population of one million). Instead of improving the demographic situation, they decided to achieve its goal by expanding the boundaries of the city. The city of Tomsk can be represented as point on the plane with ...
import math #t=int(input()) #lst = list(map(int, input().strip().split(' '))) n,s = map(int, input().strip().split(' ')) l=[] for i in range(n): x,y,k = map(int, input().strip().split(' ')) l1=[] l1=[math.sqrt(x*x + y*y),k] l.append(l1) l.sort(key = lambda l: l[0]) #print(l) t=-1 f=0 for i in range(n):...
{ "input": [ "4 999998\n1 1 2\n2 2 1\n3 3 1\n2 -2 1\n", "4 999998\n1 1 1\n2 2 1\n3 3 1\n2 -2 1\n", "2 1\n1 1 999997\n2 2 1\n", "10 764008\n959 32 23049\n-513 797 38979\n-603 -838 24916\n598 -430 25414\n-280 -624 18714\n330 891 21296\n-347 -68 27466\n650 -842 30125\n-314 889 35394\n275 969 5711\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: The administration of the Tomsk Region firmly believes that it's time to become a megacity (that is, get population of one million). Instead of improving the demographic situation, th...
448_E. Divisors_21095
Bizon the Champion isn't just friendly, he also is a rigorous coder. Let's define function f(a), where a is a sequence of integers. Function f(a) returns the following sequence: first all divisors of a1 go in the increasing order, then all divisors of a2 go in the increasing order, and so on till the last element of s...
import sys solSaved = {} solSavedPropios = {} def DivisorsN(n): key = solSaved.get(str(n)) if key == None : divisors = [] divisors2 = [] for i in range(1,int(n ** (1/2)) + 1): if n % i == 0 : if abs(i - (n/i)) < 10 ** (-7) : divisors.append(int(i)) ...
{ "input": [ "10 3\n", "6 1\n", "4 2\n", "963761198400 1\n", "89 4\n", "16 10\n", "1000000000000 0\n", "956722026041 10\n", "458760294782 5\n", "83 3\n", "95 5\n", "89 5\n", "252935271071 2\n", "79 1\n", "1 1000000000000000000\n", "10 0\n", "57131200...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Bizon the Champion isn't just friendly, he also is a rigorous coder. Let's define function f(a), where a is a sequence of integers. Function f(a) returns the following sequence: firs...
46_F. Hercule Poirot Problem_21098
Today you are to solve the problem even the famous Hercule Poirot can't cope with! That's why this crime has not yet been solved and this story was never included in Agatha Christie's detective story books. You are not informed on what crime was committed, when and where the corpse was found and other details. We onl...
def solve(n,m,k,edge_list,house_members): room_sets=[i for i in range(n)] valid_move=[True for i in range(n)] room_status=[ [1<<i,0,[]] for i in range(n)] # room_status[i]->informacion de todo otro cuarto,persona y llave alcanzable para el cuarto i # room_status[i][0]->los cuartos alcanzables por el...
{ "input": [ "4 4 3\n1 3\n1 2\n2 3\n3 4\nArtem 1 1 4\nDmitry 1 1 2\nEdvard 4 2 1 3\nArtem 2 0\nDmitry 1 0\nEdvard 4 4 1 2 3 4\n", "2 1 2\n1 2\nDmitry 1 1 1\nNatalia 2 0\nNatalia 1 1 1\nDmitry 2 0\n", "7 8 2\n3 7\n7 6\n1 2\n4 5\n1 3\n5 6\n4 6\n2 3\na 1 4 3 8 5 2\nb 4 4 4 6 7 1\na 3 4 3 8 5 2\nb 6 4 4 6 7 1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Today you are to solve the problem even the famous Hercule Poirot can't cope with! That's why this crime has not yet been solved and this story was never included in Agatha Christie's...
493_B. Vasya and Wrestling_21102
Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins. When the numbers of points of both wrestlers are equal, the wrestler whose sequence of points is lexicographically greater, wins. If the sequences of...
n = int(input()) a = [] b = [] for i in range(n): x = int(input()) if i == n-1: num = x if x > 0: a.append(x) else: b.append(abs(x)) sma = sum(a) smb = sum(b) if sma > smb: print("first") elif sma < smb: print("second") else: if a == b: if x > 0: ...
{ "input": [ "5\n1\n2\n-3\n-4\n3\n", "3\n-1\n-2\n3\n", "2\n4\n-4\n", "4\n16\n12\n19\n-98\n", "11\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n-1\n1\n", "10\n-1\n-2\n-3\n-4\n-5\n5\n4\n3\n2\n1\n", "5\n1000000000\n1000000000\n1000000000\n-1000000000\n-1000000000\n", "2\n-5\n6\n", "20\n1000000000\n...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Vasya has become interested in wrestling. In wrestling wrestlers use techniques for which they are awarded points by judges. The wrestler who gets the most points wins. When the numb...
518_A. Vitaly and Strings_21106
Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time. During the last lesson the teacher has provided two strings s and t to Vitaly. The strings have the same length, they consist of lowercase English l...
def f(s): return f(s[:-1])+'a' if s[-1] == 'z'else s[:-1]+chr(ord(s[-1])+1) s = f(input()) print(('No such string', s)[s < input()])
{ "input": [ "aaa\nzzz\n", "a\nc\n", "abcdefg\nabcdefh\n", "pkjlxzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\npkjlyaaaaaaaaaaaaaaaaaaaaaaaaaaaahr\n", "kexdbtpkjbwwyibjndbtmwqzolopqitgkomqggojevoankiepxirrcidxldlzsppehmoazdywltmjbxgsxgihwnwpmczjrcwpywl\nkexdbtpkjbwwyibjndbtmwqzolopqitgkomqggojevoankiepxirrcidxl...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Vitaly is a diligent student who never missed a lesson in his five years of studying in the university. He always does his homework on time and passes his exams in time. During the ...
544_A. Set of Strings_21110
You are given a string q. A sequence of k strings s1, s2, ..., sk is called beautiful, if the concatenation of these strings is string q (formally, s1 + s2 + ... + sk = q) and the first characters of these strings are distinct. Find any beautiful sequence of strings or determine that the beautiful sequence doesn't exi...
from sys import * k=int(input()) s=input() ee=set() for i in s: ee.add(i) if k>len(ee): print("NO") exit(0) print("YES") i=1 cur=s[0] num=k-1 ee.discard(s[0]) while i<len(s): if s[i] in ee and num: print(cur) ee.discard(s[i]) num-=1 cur=s[i] else: cur+=s[i] ...
{ "input": [ "1\nabca\n", "4\nabc\n", "2\naaacas\n", "2\nab\n", "1\niiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiaaaaaiiiiaiaiiiiaaiaiiiaiiaiaaiaiiaiiiiiaiiiaiiiaiaiaai\n", "25\nvobekscyadzqwnjxruplifmthg\n", "26\npjhsxjbvkqntwmsdnrguecaofylzti\n", "25\nkkrrkrkrkrsrskpskbrppdsdbgbkrbll...
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 q. A sequence of k strings s1, s2, ..., sk is called beautiful, if the concatenation of these strings is string q (formally, s1 + s2 + ... + sk = q) and the fir...
570_C. Replacement_21114
Daniel has a string s, consisting of lowercase English letters and period signs (characters '.'). Let's define the operation of replacement as the following sequence of steps: find a substring ".." (two consecutive periods) in string s, of all occurrences of the substring let's choose the first one, and replace this su...
import sys n,m = map(int,sys.stdin.readline().split()) arr = list(sys.stdin.readline()) count = cnt = 0 for i in arr: if i=='.': cnt += 1 elif cnt !=0: count += cnt-1 cnt = 0 if cnt!=0: count += cnt-1 i = m while i: x,c = sys.stdin.readline().split() x = int(x)-1 if arr[x...
{ "input": [ "10 3\n.b..bz....\n1 h\n3 c\n9 f\n", "4 4\n.cc.\n2 .\n3 .\n2 a\n1 a\n", "3 3\n...\n1 .\n2 a\n3 b\n", "5 1\n.....\n5 z\n", "2 7\nab\n1 w\n2 w\n1 c\n2 .\n2 .\n1 .\n2 b\n", "1 5\n.\n1 .\n1 w\n1 w\n1 .\n1 .\n", "5 1\n..-..\n5 z\n", "10 3\n....zb..b.\n1 h\n3 c\n9 f\n", "4 4...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Daniel has a string s, consisting of lowercase English letters and period signs (characters '.'). Let's define the operation of replacement as the following sequence of steps: find a ...
592_A. PawnChess_21118
Galois is one of the strongest chess players of Byteforces. He has even invented a new variant of chess, which he named «PawnChess». This new game is played on a board consisting of 8 rows and 8 columns. At the beginning of every game some black and white pawns are placed on the board. The number of black pawns placed...
__author__ = 'Suvasish' lst = [] a_row = 7 b_row = 0 b_lst = [] a_lst = [] for i in range(0, 8): lst.append(list(input())) # print(lst[i]) if 'W' in lst[i]: a_lst.append(i) if 'B' in lst[i]: b_lst.append(i) b_lst.reverse() # print('AL', a_lst) # print('BL', b_lst) _break = False for ...
{ "input": [ "........\n........\n.B....B.\n....W...\n........\n..W.....\n........\n........\n", "..B.....\n..W.....\n......B.\n........\n.....W..\n......B.\n........\n........\n", "........\n.......W\n........\n........\n........\n........\n.......B\n........\n", "........\n........\n.W......\n.........
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Galois is one of the strongest chess players of Byteforces. He has even invented a new variant of chess, which he named «PawnChess». This new game is played on a board consisting of ...
613_D. Kingdom and its Cities_21121
Meanwhile, the kingdom of K is getting ready for the marriage of the King's daughter. However, in order not to lose face in front of the relatives, the King should first finish reforms in his kingdom. As the King can not wait for his daughter's marriage, reforms must be finished as soon as possible. The kingdom curren...
import sys from collections import deque def solve(): sys.setrecursionlimit(10**6) readline = sys.stdin.readline writelines = sys.stdout.writelines N = int(readline()) G = [[] for i in range(N)] for i in range(N-1): u, v = map(int, readline().split()) G[u-1].append(v-1) G...
{ "input": [ "4\n1 3\n2 3\n4 3\n4\n2 1 2\n3 2 3 4\n3 1 2 4\n4 1 2 3 4\n", "7\n1 2\n2 3\n3 4\n1 5\n5 6\n5 7\n1\n4 2 4 6 7\n", "4\n1 2\n2 3\n1 4\n1\n3 1 3 4\n", "30\n1 2\n1 3\n1 4\n2 5\n2 6\n2 7\n4 8\n4 9\n6 10\n6 11\n11 30\n11 23\n30 24\n30 25\n25 26\n25 27\n27 29\n27 28\n23 20\n23 22\n20 21\n20 19\n3 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Meanwhile, the kingdom of K is getting ready for the marriage of the King's daughter. However, in order not to lose face in front of the relatives, the King should first finish reform...
633_D. Fibonacci-ish_21125
Yash has recently learnt about the Fibonacci sequence and is very excited about it. He calls a sequence Fibonacci-ish if 1. the sequence consists of at least two elements 2. f0 and f1 are arbitrary 3. fn + 2 = fn + 1 + fn for all n ≥ 0. You are given some sequence of integers a1, a2, ..., an. Your task is...
import random, math from copy import deepcopy as dc from bisect import bisect_left, bisect_right from collections import Counter # Function to call the actual solution def solution(li): ma = {} for i in range(len(li)): ma[li[i]] = ma.get(li[i], 0) + 1 # ma1 = dc(ma) ans = 0 # li = list(set(li)) for i in range...
{ "input": [ "3\n1 2 -1\n", "5\n28 35 7 14 21\n", "3\n0 -44 -49\n", "5\n-1 1 0 0 0\n", "11\n-9 -1 -10 9 7 -4 0 -8 -3 3 5\n", "3\n0 0 0\n", "4\n1 -1 0 -2\n", "10\n0 0 0 0 0 0 0 0 0 0\n", "5\n0 0 0 0 0\n", "2\n1000000000 1000000000\n", "2\n0 0\n", "5\n-7 0 -7 -7 -14\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Yash has recently learnt about the Fibonacci sequence and is very excited about it. He calls a sequence Fibonacci-ish if 1. the sequence consists of at least two elements 2. f0...
686_B. Little Robber Girl's Zoo_21129
Little Robber Girl likes to scare animals in her zoo for fun. She decided to arrange the animals in a row in the order of non-decreasing height. However, the animals were so scared that they couldn't stay in the right places. The robber girl was angry at first, but then she decided to arrange the animals herself. She ...
n = int(input()) arr = list(map(int,input().split())) check = 0 while check==0: check = 1 i = 0 while i<n-1: if arr[i]>arr[i+1]: check = 0 print(i+1,i+2) arr[i],arr[i+1] = arr[i+1],arr[i] i += 1
{ "input": [ "5\n1 2 1 2 1\n", "4\n2 1 4 3\n", "7\n36 28 57 39 66 69 68\n", "7\n36 28 57 39 66 69 68\n", "4\n2 1 4 3\n", "87\n2 2 1 2 3 1 3 2 3 2 3 3 1 3 3 3 2 2 1 1 2 3 2 1 2 2 3 3 1 1 1 3 2 3 1 2 1 3 3 3 3 3 3 2 3 2 3 3 2 1 1 3 1 1 3 3 2 3 1 1 3 3 3 2 3 1 3 2 2 2 1 3 3 3 1 1 2 3 2 3 2 1 3 3 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Little Robber Girl likes to scare animals in her zoo for fun. She decided to arrange the animals in a row in the order of non-decreasing height. However, the animals were so scared th...
709_A. Juicer_21133
Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Kolya will put them in the juicer in the fixed order, starting with orange of size a1, then orange of size a2 and so on. To be put in the juicer the orange must have size not exceeding b, so if Kolya sees an orange that is strictly gr...
""" IIIIIIIIII OOOOOOOOOOO IIIIIIIIII II OO OO II II OO OO II II OO OO II II OO OO II II OO OO II II OO OO II IIIIIIIIII OOOOOOOOOOO IIIIIIIIII """ n, b, d = map(int, input().split()) m = list(map(int, input().sp...
{ "input": [ "1 1 1\n1\n", "2 7 10\n5 6\n", "3 10 10\n5 7 7\n", "1 5 10\n7\n", "5 10 20\n10 10 10 10 1\n", "2 951637 951638\n44069 951637\n", "5 234613 716125\n642626 494941 234613 234613 234613\n", "50 100 129\n55 130 91 19 116 3 63 52 104 76 75 27 151 99 149 147 39 148 84 9 132 49 40...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Kolya is going to make fresh orange juice. He has n oranges of sizes a1, a2, ..., an. Kolya will put them in the juicer in the fixed order, starting with orange of size a1, then orang...
753_A. Santa Claus and Candies_21139
Santa Claus has n candies, he dreams to give them as gifts to children. What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get distinct positive integer number of candies. Santa Class wants to give all n candies he has. Input The only line contains positive integ...
n=int(input()) i=1 a=[] while(n>=i): a.append(i) n-=i i+=1 a[-1]+=n print(len(a)) print(*a)
{ "input": [ "2\n", "9\n", "5\n", "999\n", "16\n", "956\n", "631\n", "46\n", "981\n", "867\n", "3\n", "991\n", "15\n", "630\n", "231\n", "1000\n", "12\n", "13\n", "45\n", "44\n", "22\n", "239\n", "37\n", "4\n", "230\n"...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Santa Claus has n candies, he dreams to give them as gifts to children. What is the maximal number of children for whose he can give candies if Santa Claus want each kid should get d...
774_G. Perfectionist Arkadiy_21143
Arkadiy has lots square photos with size a × a. He wants to put some of them on a rectangular wall with size h × w. The photos which Arkadiy will put on the wall must form a rectangular grid and the distances between neighboring vertically and horizontally photos and also the distances between outside rows and column...
def gcd(x,y): if (x%y==0): return y return gcd(y,x%y) a,h,w=input().split() a=int(a) h=int(h) w=int(w) g=gcd(h+a,w+a) if (g<a or h<a or w<a): print("-1") else: print(g/(g//a)-a)
{ "input": [ "3 4 3\n", "2 18 13\n", "4 4 4\n", "77810521 953603507 953603507\n", "6 4 4\n", "3 1000000000 1000000000\n", "453145 999531525 999531525\n", "1000000000 1 1\n", "469568633 681052815 681052815\n", "452081307 790635695 790635695\n", "263288720 933114664 933114664...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Arkadiy has lots square photos with size a × a. He wants to put some of them on a rectangular wall with size h × w. The photos which Arkadiy will put on the wall must form a rectang...
81_B. Sequence Formatting_21149
Polycarp is very careful. He even types numeric sequences carefully, unlike his classmates. If he sees a sequence without a space after the comma, with two spaces in a row, or when something else does not look neat, he rushes to correct it. For example, number sequence written like "1,2 ,3,..., 10" will be corrected to...
# вводим строку s s, i, v = input() + ' ', 0, ' ' # перебираем строку while i < len(s): # если в строке запятая, поставить пробел после нее if s[i] == ',': v += ', ' # если в строке точки, заменить их на многоточия и пробел перед ними elif s[i] == '.': v += ('' if v[-1] == ' ' else ' ')...
{ "input": [ "1,2 ,3,..., 10\n", "1,,,4...5......6\n", "...,1,2,3,...\n", "1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1...1.....
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Polycarp is very careful. He even types numeric sequences carefully, unlike his classmates. If he sees a sequence without a space after the comma, with two spaces in a row, or when so...
845_E. Fire in the City_21152
The capital of Berland looks like a rectangle of size n × m of the square blocks of same size. Fire! It is known that k + 1 blocks got caught on fire (k + 1 ≤ n·m). Those blocks are centers of ignition. Moreover positions of k of these centers are known and one of these stays unknown. All k + 1 positions are distinct...
import sys from collections import Counter from operator import itemgetter from heapq import heappop, heappush n, m, k = map(int, input().split()) points = [list(map(int, line.split())) for line in sys.stdin] pts_sorted_x = sorted(points) pts_sorted_y = sorted(points, key=itemgetter(1, 0)) inf = 10**9+1 OK = (inf, inf...
{ "input": [ "10 5 1\n3 3\n", "7 7 3\n1 2\n2 1\n5 5\n", "1000 1000 10\n630 843\n959 696\n75 966\n691 982\n390 44\n863 380\n467 293\n94 96\n415 411\n161 497\n", "1000000000 1000000000 1\n243387905 466399354\n", "4 5 19\n1 1\n1 2\n1 3\n1 4\n1 5\n2 1\n2 2\n2 3\n2 5\n3 1\n3 2\n3 3\n3 4\n3 5\n4 1\n4 2\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: The capital of Berland looks like a rectangle of size n × m of the square blocks of same size. Fire! It is known that k + 1 blocks got caught on fire (k + 1 ≤ n·m). Those blocks are...
892_B. Wrath_21158
Hands that shed innocent blood! There are n guilty people in a line, the i-th of them holds a claw with length Li. The bell rings and every person kills some of people in front of him. All people kill others at the same time. Namely, the i-th person kills the j-th person if and only if j < i and j ≥ i - Li. You are g...
n=int(input()) l=[0]*n r=[0]*n len=list(map(int,input().split())) for i in range(n): a=max(0,i-len[i]) b=max(a,i) #print(' '.join(map(str,[i,a,b]))) l[a]+=1 r[b]+=1 ans=0 t=0 for i in range(n): t+=l[i] t-=r[i] #print('t='+str(t)) if t==0: #print('i='+str(i)) ans+=1 pr...
{ "input": [ "10\n1 1 3 0 0 0 2 1 0 3\n", "4\n0 1 0 10\n", "2\n0 0\n", "5\n0 0 0 1 0\n", "1\n1000000000\n", "2\n1000000000 1000000000\n", "1\n1\n", "8\n0 0 0 1 0 0 1 2\n", "11\n1 0 0 1 1 3 2 0 0 2 3\n", "10\n0 0 2 0 0 3 3 2 2 0\n", "2\n1 3\n", "1\n0\n", "6\n3 1 1 0 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Hands that shed innocent blood! There are n guilty people in a line, the i-th of them holds a claw with length Li. The bell rings and every person kills some of people in front of hi...
914_B. Conan and Agasa play a Card Game_21162
Edogawa Conan got tired of solving cases, and invited his friend, Professor Agasa, over. They decided to play a game of cards. Conan has n cards, and the i-th card has a number ai written on it. They take turns playing, starting with Conan. In each turn, the player chooses a card and removes it. Also, he removes all c...
n=int(input()) l=list(map(int,input().split())) dic={} status=True i=0 l.sort() while i<len(l): counter=0 while True: if i<len(l)-1 and l[i+1]==l[i]: i+=1 counter+=1 else: break i+=1 counter+=1 if counter%2==1: status=False print("C...
{ "input": [ "3\n4 5 7\n", "2\n1 1\n", "5\n1 4 4 5 5\n", "4\n3 3 2 1\n", "1\n100000\n", "10\n50096 50096 50096 50096 50096 50096 28505 50096 50096 50096\n", "3\n4 4 100000\n", "1\n2\n", "10\n87900 87900 5761 87900 87900 87900 5761 87900 87900 87900\n", "7\n7 7 7 7 6 6 6\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Edogawa Conan got tired of solving cases, and invited his friend, Professor Agasa, over. They decided to play a game of cards. Conan has n cards, and the i-th card has a number ai wri...
962_B. Students in Railway Carriage_21168
There are n consecutive seat places in a railway carriage. Each place is either empty or occupied by a passenger. The university team for the Olympiad consists of a student-programmers and b student-athletes. Determine the largest number of students from all a+b students, which you can put in the railway carriage so t...
n,a,b = map(int,input().split()) s=a+b ans = 0 for t in map(len, input().split('*')): if a > b: a, b = b, a a -= min(a , (t//2)) b -= min(b , (t - (t//2))) print(s-a-b)
{ "input": [ "11 3 10\n.*....**.*.\n", "5 1 1\n*...*\n", "3 2 3\n***\n", "6 2 3\n*...*.\n", "17 11 2\n.*..*..*.*.***...\n", "5 0 1\n*.*.*\n", "20 5 5\n.*.*.............*..\n", "5 1 2\n...*.\n", "10 5 1\n..........\n", "9 5 3\n*...*...*\n", "5 1 4\n.....\n", "5 2 3\n.......
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are n consecutive seat places in a railway carriage. Each place is either empty or occupied by a passenger. The university team for the Olympiad consists of a student-programme...
p02606 AIsing Programming Contest 2020 - Number of Multiples_21185
How many multiples of d are there among the integers between L and R (inclusive)? Constraints * All values in input are integers. * 1 \leq L \leq R \leq 100 * 1 \leq d \leq 100 Input Input is given from Standard Input in the following format: L R d Output Print the number of multiples of d among the integers b...
l, r, d = map(int, input().split()) ans = (r // d) - ((l - 1) // d) print(ans)
{ "input": [ "1 100 1", "6 20 7", "5 10 2", "1 100 2", "9 20 7", "5 10 1", "9 20 3", "5 4 1", "9 31 3", "2 4 1", "9 21 3", "2 3 1", "2 10 1", "2 110 2", "2 8 1", "0 100 1", "2 24 1", "0 110 1", "1 32 3", "2 110 1", "2 12 1", "1 11...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: How many multiples of d are there among the integers between L and R (inclusive)? Constraints * All values in input are integers. * 1 \leq L \leq R \leq 100 * 1 \leq d \leq 100 Inp...
p02737 AtCoder Grand Contest 043 - Giant Graph_21188
Given are simple undirected graphs X, Y, Z, with N vertices each and M_1, M_2, M_3 edges, respectively. The vertices in X, Y, Z are respectively called x_1, x_2, \dots, x_N, y_1, y_2, \dots, y_N, z_1, z_2, \dots, z_N. The edges in X, Y, Z are respectively (x_{a_i}, x_{b_i}), (y_{c_i}, y_{d_i}), (z_{e_i}, z_{f_i}). Bas...
from collections import defaultdict import sys input = lambda: sys.stdin.readline().rstrip() M = 998244353 # < (1 << 30) def mod_inv(a, M=M): x1, y1, z1 = 1, 0, a x2, y2, z2 = 0, 1, M while abs(z1) != 1: d, m = divmod(z2, z1) x1, x2 = x2-d*x1, x1 y1, y2 = y2-d*y1, y1 z1, z2 = m, z1 return x1*...
{ "input": [ "3\n3\n1 3\n1 2\n3 2\n2\n2 1\n2 3\n1\n2 1", "100000\n1\n1 2\n1\n99999 100000\n1\n1 100000", "2\n1\n1 2\n1\n1 2\n1\n1 2", "3\n3\n1 3\n2 2\n3 2\n2\n2 1\n2 3\n1\n2 1", "100000\n1\n1 3\n1\n99999 100000\n1\n1 100000", "2\n1\n1 2\n1\n1 3\n1\n1 2", "3\n3\n1 3\n2 2\n3 2\n2\n2 1\n1 3\n...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Given are simple undirected graphs X, Y, Z, with N vertices each and M_1, M_2, M_3 edges, respectively. The vertices in X, Y, Z are respectively called x_1, x_2, \dots, x_N, y_1, y_2,...
p02871 Hitachi Hokudai Labo & Hokkaido University Contest 2019-1 - Problem A_21191
Requirements * All inputs are of non-negative integer value. * T_{\text{max}} = 10000 * 200 \leq |V| \leq 400 * 1.5 |V| \leq |E| \leq 2 |V| * 1 \leq u_{i}, v_{i} \leq |V| (1 \leq i \leq |E|) * 1 \leq d_{u_i, v_i} \leq \lceil 4\sqrt{2|V|} \rceil (1 \leq i \leq |E|) * The given graph has no self-loops / multiple edges a...
#!usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS():return [list(x) for x in sys.stdin.readline().split()]...
{ "input": [ "5 7\n1 2 5\n5 3 4\n2 4 8\n1 5 1\n2 3 3\n4 5 3\n4 3 9\n4\n1\n1 2\n1\n2 5\n1\n3 4\n0", "5 7\n1 2 5\n5 3 4\n2 4 12\n1 5 1\n2 3 3\n4 5 3\n4 3 9\n4\n1\n1 2\n1\n2 5\n1\n3 4\n0", "5 7\n1 2 5\n5 3 4\n2 4 12\n1 5 1\n2 1 3\n4 5 3\n4 3 5\n7\n1\n1 1\n1\n2 5\n1\n3 4\n0", "5 7\n1 2 5\n5 3 4\n2 4 12\n1...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Requirements * All inputs are of non-negative integer value. * T_{\text{max}} = 10000 * 200 \leq |V| \leq 400 * 1.5 |V| \leq |E| \leq 2 |V| * 1 \leq u_{i}, v_{i} \leq |V| (1 \leq i \...
p03006 diverta 2019 Programming Contest 2 - Picking Up_21195
There are N balls in a two-dimensional plane. The i-th ball is at coordinates (x_i, y_i). We will collect all of these balls, by choosing two integers p and q such that p \neq 0 or q \neq 0 and then repeating the following operation: * Choose a ball remaining in the plane and collect it. Let (a, b) be the coordinates...
from collections import defaultdict as ddict d = ddict(int) d[0] = 0 n = int(input()) l = [tuple(map(int, input().split())) for _ in range(n)] l.sort() for i in range(n-1): for j in range(i+1,n): curx = l[j][0] - l[i][0] cury = l[j][1] - l[i][1] d[(curx,cury)] += 1 print(n-max(d.values()))
{ "input": [ "3\n1 4\n4 6\n7 8", "4\n1 1\n1 2\n2 1\n2 2", "2\n1 1\n2 2", "3\n1 4\n4 6\n11 8", "2\n1 2\n2 2", "4\n1 1\n1 4\n2 1\n2 2", "3\n1 4\n4 6\n11 3", "3\n0 4\n4 6\n11 3", "3\n-1 4\n4 6\n11 3", "3\n-2 4\n4 6\n11 3", "3\n-2 4\n5 6\n11 3", "3\n-2 4\n5 6\n11 4", "3...
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 a two-dimensional plane. The i-th ball is at coordinates (x_i, y_i). We will collect all of these balls, by choosing two integers p and q such that p \neq 0 or q...
p03146 AtCoder Beginner Contest 116 - Collatz Problem_21199
A sequence a=\\{a_1,a_2,a_3,......\\} is determined as follows: * The first term s is given as input. * Let f(n) be the following function: f(n) = n/2 if n is even, and f(n) = 3n+1 if n is odd. * a_i = s when i = 1, and a_i = f(a_{i-1}) when i > 1. Find the minimum integer m that satisfies the following conditio...
s=int(input()) a=[] ans=1 while True: a.append(s) if s%2==0: s//=2 else: s=s*3+1 ans+=1 if s in a: print(ans) break
{ "input": [ "54", "8", "7", "87", "11", "10", "82", "17", "20", "65", "2", "22", "43", "18", "15", "27", "6", "35", "5", "38", "31", "28", "9", "12", "25", "16", "39", "55", "44", "50", "41", ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: A sequence a=\\{a_1,a_2,a_3,......\\} is determined as follows: * The first term s is given as input. * Let f(n) be the following function: f(n) = n/2 if n is even, and f(n) = 3n+1 ...
p03290 AtCoder Beginner Contest 104 - All Green_21203
A programming competition site AtCode provides algorithmic problems. Each problem is allocated a score based on its difficulty. Currently, for each integer i between 1 and D (inclusive), there are p_i problems with a score of 100i points. These p_1 + … + p_D problems are all of the problems available on AtCode. A user...
D,G = map(int,input().split()) PC = [0]+[list(map(int,input().split()))for i in range(D)] def f(p,c): if p==0: return 10**9 m=min(c//(p*100),PC[p][0]) s=100*p*m if m==PC[p][0]: s+=PC[p][1] if s<c: m+=f(p-1,c-s) return min(m,f(p-1,c)) print(f(D,G))
{ "input": [ "5 25000\n20 1000\n40 1000\n50 1000\n30 1000\n1 1000", "2 400\n3 500\n5 800", "2 700\n3 500\n5 800", "2 2000\n3 500\n5 800", "5 25000\n20 0000\n40 1000\n50 1000\n30 1000\n1 1000", "2 431\n3 500\n5 800", "2 1328\n3 500\n5 800", "2 2000\n3 500\n7 800", "5 25000\n20 0010\...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: A programming competition site AtCode provides algorithmic problems. Each problem is allocated a score based on its difficulty. Currently, for each integer i between 1 and D (inclusiv...
p03606 AtCoder Beginner Contest 073 - Theater_21209
Joisino is working as a receptionist at a theater. The theater has 100000 seats, numbered from 1 to 100000. According to her memo, N groups of audiences have come so far, and the i-th group occupies the consecutive seats from Seat l_i to Seat r_i (inclusive). How many people are sitting at the theater now? Constrai...
print(sum(1-eval(s.replace(' ','-'))for s in open(0).readlines()[1:]))
{ "input": [ "1\n24 30", "2\n6 8\n3 3", "1\n0 30", "2\n6 12\n3 3", "1\n1 30", "2\n6 12\n0 3", "1\n2 30", "2\n6 10\n0 3", "1\n2 0", "2\n6 10\n0 1", "1\n2 -1", "2\n3 10\n0 1", "2\n3 2\n0 1", "1\n1 0", "2\n3 3\n0 1", "1\n1 1", "1\n4 0", "1\n8 0", ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Joisino is working as a receptionist at a theater. The theater has 100000 seats, numbered from 1 to 100000. According to her memo, N groups of audiences have come so far, and the i-...
p03767 AtCoder Grand Contest 012 - AtCoder Group Contest_21213
There are 3N participants in AtCoder Group Contest. The strength of the i-th participant is represented by an integer a_i. They will form N teams, each consisting of three participants. No participant may belong to multiple teams. The strength of a team is defined as the second largest strength among its members. For ...
N = int(input()) A = list(map(int, input().split())) A.sort() print(sum(A[N:3 * N:2]))
{ "input": [ "2\n5 2 8 5 1 5", "10\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are 3N participants in AtCoder Group Contest. The strength of the i-th participant is represented by an integer a_i. They will form N teams, each consisting of three participant...
p03935 square869120Contest #3 - Sum of Fibonacci Sequence_21217
E869120 defined a sequence $a$ like this: * $a_1=a_2=1$, $a_{k+2}=a_{k+1}+a_k \ (k \ge 1)$ He also defined sequences $d_1, d_2, d_3, \dots , d_n$, as the following recurrence relation : * $d_{1, j} = a_j$ * $d_{i, j} = \sum_{k = 1}^j d_{i - 1, k} \ (i \ge 2)$ You are given integers $n$ and $m$. Please calculate...
M=998244353 g=lambda a,b:[(a[0]*b[0]+a[1]*b[2])%M,(a[0]*b[1]+a[1]*b[3])%M,(a[2]*b[0]+a[3]*b[2])%M,(a[2]*b[1]+a[3]*b[3])%M] def f(n): e=[1,0,0,1];z=[1,1,1,0] while n: if n%2>0:e=g(e,z) z=g(z,z);n//=2 return e[1] n,m=map(int,input().split());I=[1,1];r=f(m+2*n-2);c=1 for i in range(2,n):I+=[(M-M//i)*I[M%i]%M] for i...
{ "input": [ "4 7", "12 20", "16 30", "6 7", "12 2", "16 38", "1 7", "12 1", "16 25", "2 7", "12 0", "16 29", "2 9", "16 46", "3 9", "16 31", "4 9", "27 31", "4 18", "27 51", "4 10", "27 102", "1 10", "42 102", "42 123...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: E869120 defined a sequence $a$ like this: * $a_1=a_2=1$, $a_{k+2}=a_{k+1}+a_k \ (k \ge 1)$ He also defined sequences $d_1, d_2, d_3, \dots , d_n$, as the following recurrence rela...
p00028 Mode Value_21221
Your task is to write a program which reads a sequence of integers and prints mode values of the sequence. The mode value is the element which occurs most frequently. Input A sequence of integers ai (1 ≤ ai ≤ 100). The number of integers is less than or equals to 100. Output Print the mode values. If there are se...
if __name__ == '__main__': ans = dict() while True: try: n = int(input()) if n not in ans: ans[n] = 1 else: ans[n] += 1 except EOFError: break a = max(ans.values()) A = [] for d in ans: if ans[d] == a: A.append(d) B = sorted(A) for i in B: print(i)
{ "input": [ "5\n6\n3\n5\n8\n7\n5\n3\n9\n7\n3\n4", "5\n6\n3\n5\n8\n7\n6\n3\n9\n7\n3\n4", "5\n5\n3\n5\n8\n7\n6\n3\n9\n7\n3\n4", "5\n3\n3\n1\n15\n7\n6\n6\n16\n2\n1\n4", "5\n3\n3\n1\n15\n7\n6\n6\n16\n1\n1\n4", "5\n3\n2\n1\n15\n7\n6\n6\n16\n2\n1\n4", "5\n5\n1\n1\n15\n7\n6\n6\n16\n2\n2\n4", ...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Your task is to write a program which reads a sequence of integers and prints mode values of the sequence. The mode value is the element which occurs most frequently. Input A sequ...
p00159 The Best Body_21225
There is BMI (Body Mass Index) as an index showing the degree of obesity. The BMI value is calculated using the following formula. BMI = weight (kg) / (height (m)) 2 The closer the BMI value is to the standard value, the more "ideal body shape" is considered. Therefore, if the standard value of BMI is 22, create a pr...
# from sys import exit while(True): N = int(input()) if N == 0: break L = [] for i in range(N): p, h, w = [int(n) for n in input().split()] L.append((p, abs(22- w/((h/100)**2)))) # print(abs(22- w/((h/100)**2))) L = sorted(L, key=lambda x: x[1]) print(L[0][0])
{ "input": [ "6\n1 165 66\n2 178 60\n3 180 72\n4 160 65\n5 185 62\n6 182 62\n3\n3 160 65\n2 180 70\n1 170 75\n0", "6\n1 165 66\n2 178 60\n3 180 72\n4 160 65\n5 185 62\n6 182 62\n3\n3 160 65\n2 180 32\n1 170 75\n0", "6\n1 165 66\n2 178 60\n3 180 72\n4 160 65\n5 185 62\n6 182 62\n3\n3 160 65\n2 180 70\n1 17...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There is BMI (Body Mass Index) as an index showing the degree of obesity. The BMI value is calculated using the following formula. BMI = weight (kg) / (height (m)) 2 The closer the ...
p00316 Investigation of Club Activities_21228
Akira, the student council president of A High School, decided to investigate which club activities the A High School students belong to. A High School has N students numbered 1 to N and M types of club activities numbered 1 to M. There is no limit to the number of people in each club activity, and there can be 0 club ...
n, m, k = map(int, input().split()) *parent, = range(n+m) def root(x): if x == parent[x]: return x parent[x] = root(parent[x]) return parent[x] def unite(x, y): px = root(x); py = root(y) if px < py: parent[py] = px else: parent[px] = py for i in range(k): a, b, c = m...
{ "input": [ "3 2 5\n1 1 2\n1 2 3\n2 1 1\n2 3 2\n2 2 1", "3 2 4\n1 1 2\n2 1 1\n2 3 2\n2 2 1", "3 2 2\n1 1 2\n2 1 1", "3 2 7\n1 1 2\n1 2 3\n2 1 1\n2 3 2\n2 2 1", "3 2 4\n1 1 2\n2 1 1\n2 3 2\n1 2 1", "3 2 4\n2 1 2\n2 1 1\n2 3 2\n2 2 1", "3 2 5\n2 1 2\n1 2 3\n2 1 1\n2 3 2\n2 2 1", "3 2 6\...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Akira, the student council president of A High School, decided to investigate which club activities the A High School students belong to. A High School has N students numbered 1 to N ...
p00486 Walking Santa_21231
At the end of last year, Santa Claus forgot to give Christmas presents to the children in JOI village. Therefore, I decided to deliver the chocolate cake to the children as an apology. The day to deliver is approaching tomorrow, so it's time to come up with a move plan. JOI village is divided into a grid shape by W ro...
from bisect import bisect_left as bl INF = 10 ** 20 def main(): w, h = map(int, input().split()) n = int(input()) xlst = [] ylst = [] appx = xlst.append appy = ylst.append for i in range(n): x, y = map(int,input().split()) appx(x) appy(y) sorted_xlst = sorted(xlst) sorted_ylst = ...
{ "input": [ "5 4\n3\n1 1\n3 4\n5 3", "5 4\n3\n1 1\n3 4\n5 6", "6 4\n3\n1 1\n1 4\n5 6", "6 4\n3\n1 1\n1 4\n5 12", "6 4\n3\n0 1\n1 4\n5 12", "5 4\n3\n1 1\n3 4\n5 2", "5 4\n3\n1 1\n3 4\n7 6", "6 4\n3\n1 0\n1 4\n5 6", "6 4\n3\n1 1\n1 3\n5 12", "6 4\n3\n0 1\n1 4\n5 0", "5 4\n3\...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: At the end of last year, Santa Claus forgot to give Christmas presents to the children in JOI village. Therefore, I decided to deliver the chocolate cake to the children as an apology...
p00815 Map of Ninja House_21236
An old document says that a Ninja House in Kanazawa City was in fact a defensive fortress, which was designed like a maze. Its rooms were connected by hidden doors in a complicated manner, so that any invader would become lost. Each room has at least two doors. The Ninja House can be modeled by a graph, as shown in Fi...
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**13 mod = 10**9+7 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin....
{ "input": [ "2\n3 3 3 3 -3 3 2 -5 3 2 -5 -3 0\n3 5 4 -2 4 -3 -2 -2 -1 0", "2\n3 3 3 3 -3 3 2 -5 3 2 -5 -3 0\n3 5 3 -2 4 -3 -2 -2 -1 0", "2\n3 3 3 3 -3 3 2 -5 3 2 -5 -3 0\n3 5 4 -2 4 -1 -2 -2 -1 0", "2\n3 3 3 3 -3 3 2 -5 3 2 -5 -3 0\n3 2 4 -2 4 -3 -2 -2 -1 0", "2\n3 3 3 3 -3 3 2 -5 3 2 -5 -3 0\n3 ...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: An old document says that a Ninja House in Kanazawa City was in fact a defensive fortress, which was designed like a maze. Its rooms were connected by hidden doors in a complicated ma...
p00946 Rearranging a Sequence_21240
Example Input 5 3 4 2 5 Output 5 2 4 1 3
n, m = map(int, input().split()) E = [int(input()) for i in range(m)] s = set() E.reverse() F = [] for e in E: if e in s: continue s.add(e) F.append(e) for i in range(1, n+1): if i in s: continue F.append(i) *_,=map(print,F)
{ "input": [ "5 3\n4\n2\n5", "5 0\n4\n2\n5", "2 0\n4\n2\n6", "5 3\n5\n2\n5", "3 0\n4\n0\n6", "7 0\n3\n0\n6", "9 0\n3\n0\n6", "9 1\n4\n0\n6", "1 0\n10\n0\n0", "10 1\n4\n0\n6", "10 1\n8\n0\n6", "5 1\n4\n1\n5", "4 0\n4\n0\n6", "11 0\n3\n0\n6", "10 0\n4\n0\n0", ...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Example Input 5 3 4 2 5 Output 5 2 4 1 3 ### Input: 5 3 4 2 5 ### Output: 5 2 4 1 3 ### Input: 5 0 4 2 5 ### Output: 1 2 3 4 5 ### Code: n, m = map(int, input().split()) E = ...
p01213 Repeated Subsequences_21245
You are a treasure hunter traveling around the world. Finally, you’ve got an ancient text indicating the place where the treasure was hidden. The ancient text looks like a meaningless string of characters at first glance. Actually, the secret place is embedded as the longest repeated subsequence of the text. Well, the...
def lcs(x, y, pre_lcs, pre_lcs_len): pm = dict((zip('ABCDEFGHIJKLMNOPQRSTUVWXYZ', [0] * 26))) for c in pm: for i, xc in enumerate(x): if c == xc: pm[c] |= (1 << i) V = (1 << len(x)) - 1 rec = [] for yc in y: V = ((V + (V & pm[yc])) | (V & ~pm[yc]...
{ "input": [ "ABCABCABAB\nZZZZZZZZZZZZ\nEND", "ABCABCABAB\nZZZZZZZZZZZZ\n#END", "ABCABCABAB\nZZZZZZZZZZZZ\nNED", "ABCABCABAB\nZZZZZZZZZZZZ\nNDD", "ABCABCACAB\nZZZZZZZZZZZZ\nNDD", "ABBABCACAB\nZZZZZZZZZZZZ\nNDD", "ABBABCACAB\nZ[ZZZZZZZZZZ\nNDD", "ABCABCABAB\nZZZZZZZZZZZZ\nNEE", "ABB...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are a treasure hunter traveling around the world. Finally, you’ve got an ancient text indicating the place where the treasure was hidden. The ancient text looks like a meaningless...
p01349 Ennichi_21249
A rabbit who came to the fair found that the prize for a game at a store was a carrot cake. The rules for this game are as follows. There is a grid-like field of vertical h squares x horizontal w squares, and each block has at most one block. Each block is a color represented by one of the uppercase letters ('A'-'Z')....
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 998244353 dd = [(0,-1),(1,0),(0,1),(-1,0)] ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)] def LI(): return [int(x) for x in sys.stdi...
{ "input": [ "4 6 3\n......\n...Y..\n...Y..\nRRYRYY", "4 6 3\n......\n...Y..\n...Y..\nRRYRY.", "4 6 3\n......\n..Y...\n...Y..\nRRYRYY", "4 6 1\n......\n...Y..\n/..Z..\nYRRRYY", "4 6 3\n......\n...Y..\n...Y..\nRRYRZ.", "4 6 3\n......\n...Y..\n/..Y..\nRRYRYY", "4 6 3\n......\n...Y..\n...Y..\...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: A rabbit who came to the fair found that the prize for a game at a store was a carrot cake. The rules for this game are as follows. There is a grid-like field of vertical h squares x...
p01531 Flick Input_21252
A: Flick input A college student who loves 2D, commonly known as 2D, replaced his long-used Galapagos mobile phone with a smartphone. 2D, who operated the smartphone for the first time, noticed that the character input method was a little different from that of old mobile phones. On smartphones, a method called flick ...
flicks = { "T": "a", "L": "i", "U": "u", "R": "e", "D": "o" } buttons = { "1": "", "2": "k", "3": "s", "4": "t", "5": "n", "6": "h", "7": "m", "8": "y", "9": "r", "0": "w" } def get_word(button, flick): if button == "0" and flick == "U": return ...
{ "input": [ "5R2D", "5R3D", "5D2R", "5T2D", "5D3R", "5U2D", "4D2R", "6T2D", "3R5D", "4R2D", "6D2T", "4R5D", "4R3D", "5D2T", "5U1D", "7T2D", "4D3R", "4R6D", "3R3D", "3D3R", "5R4D", "6R3D", "6U2D", "5D1T", "8T2D", "...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: A: Flick input A college student who loves 2D, commonly known as 2D, replaced his long-used Galapagos mobile phone with a smartphone. 2D, who operated the smartphone for the first ti...