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
338_A. Quiz_31625
Manao is taking part in a quiz. The quiz consists of n consecutive questions. A correct answer gives one point to the player. The game also has a counter of consecutive correct answers. When the player answers a question correctly, the number on this counter increases by 1. If the player answers a question incorrectly,...
def chk(x): d = (m - x) // (k - 1) * k if (m - x) % (k - 1): d += 1 + (m - x) % (k - 1) if d <= n - x: return True else: return False def calc(e): if e == 1: return 2 if e & 1: d = 2 else: d = 1 f = calc(e >> 1) d = d * f % D * f % D ...
{ "input": [ "5 3 2\n", "5 4 2\n", "250000000 250000000 2\n", "1000000000 999998304 7355\n", "999998212 999998211 499998210\n", "778562195 708921647 4\n", "23888888 23862367 812\n", "901024556 901000000 1000\n", "901024556 900000000 91\n", "120009 70955 2\n", "512871295 512...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Manao is taking part in a quiz. The quiz consists of n consecutive questions. A correct answer gives one point to the player. The game also has a counter of consecutive correct answer...
384_A. Coder_31631
Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is located at position (x, y), he can move to (or attack) positions (x + 1, y), (x–1, y), (x, y + 1) and (x, y–1). Iahub wants to know how many ...
""" ██╗ ██████╗ ██╗ ██████╗ ██████╗ ██╗ █████╗ ██║██╔═══██╗██║ ╚════██╗██╔═████╗███║██╔══██╗ ██║██║ ██║██║ █████╔╝██║██╔██║╚██║╚██████║ ██║██║ ██║██║ ██╔═══╝ ████╔╝██║ ██║ ╚═══██║ ██║╚██████╔╝██║ ███████╗╚██████╔╝ ██║ █████╔╝ ╚═╝ ╚═════╝ ╚═╝ ╚══════╝ ╚═════╝ ╚═╝ ╚════╝ """ ...
{ "input": [ "2\n", "15\n", "101\n", "3\n", "4\n", "10\n", "1\n", "100\n", "111\n", "6\n", "11\n", "13\n", "110\n", "010\n", "21\n", "001\n", "5\n", "9\n", "7\n", "30\n", "8\n", "12\n", "16\n", "28\n", "26\n", "18\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Iahub likes chess very much. He even invented a new chess piece named Coder. A Coder can move (and attack) one square horizontally or vertically. More precisely, if the Coder is locat...
432_A. Choosing Teams_31637
The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has n students. For each student you know the number of times he/she has participated in the ACM ICPC world programming championship. According to the ACM ICPC rules, each person can participate in the world championship at most 5 times. The ...
n, k = [int(x) for x in input().split()] pros = [int(x) for x in input().split()] teams=0 for i in range(n): z = pros[i]+k if z <= 5: teams+=1 print(int(teams/3))
{ "input": [ "6 4\n0 1 2 3 4 5\n", "6 5\n0 0 0 0 0 0\n", "5 2\n0 4 5 1 0\n", "12 2\n0 1 2 3 4 0 1 2 3 4 0 1\n", "3 4\n0 2 0\n", "3 4\n0 1 0\n", "20 1\n5 0 4 2 2 3 2 1 2 4 1 3 5 5 5 4 4 1 3 0\n", "13 1\n5 0 5 0 1 5 0 4 1 1 1 4 1\n", "1 4\n1\n", "6 3\n4 4 4 4 4 4\n", "2 3\n0 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: The Saratov State University Olympiad Programmers Training Center (SSU OPTC) has n students. For each student you know the number of times he/she has participated in the ACM ICPC worl...
454_C. Little Pony and Expected Maximum_31641
Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in the dice that were used in the game. The dice has m faces: the first face of the dice contains a dot, the second one contains two dots, ...
n,m = map(int, input().split()) s=0 for i in range(n): s+=(i+1)*(pow((i+1)/n,m)-pow(i/n,m)) print(s)
{ "input": [ "6 1\n", "2 2\n", "6 3\n", "50000 100000\n", "53033 3\n", "99999 99999\n", "99999 1111\n", "94444 9\n", "5 8\n", "50323 7\n", "53513 34040\n", "3 6\n", "26946 99523\n", "5 4\n", "24236 90163\n", "1 100000\n", "100000 555\n", "51520 7...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in ...
477_A. Dreamoon and Sums_31645
Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occasionally. He wants to calculate the sum of all nice integers. Positive integer x is called nice if <image> and <image>, where k is some integer number in range [1, a]. By <image> we denote the quotient of integer division of...
import sys import math MAXNUM = math.inf MINNUM = -1 * math.inf ASCIILOWER = 97 ASCIIUPPER = 65 MODMAX = 1000000007 def getInt(): return int(sys.stdin.readline().rstrip()) def getInts(): return map(int, sys.stdin.readline().rstrip().split(" ")) def getString(): return sys.stdin.readline().rstrip() ...
{ "input": [ "2 2\n", "1 1\n", "2 4\n", "2 9999999\n", "10000000 2\n", "6407688 3000816\n", "861392 6200826\n", "999999 92321\n", "4108931 211273\n", "999999 999999\n", "1507925 5483803\n", "4 1\n", "1001 1500126\n", "1 10000000\n", "9900111 1082917\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occasionally. He wants to calculate the sum of all nice integers. Positive integer x is call...
4_B. Before an Exam_31648
Tomorrow Peter has a Biology exam. He does not like this subject much, but d days ago he learnt that he would have to take this exam. Peter's strict parents made him prepare for the exam immediately, for this purpose he has to study not less than minTimei and not more than maxTimei hours per each i-th day. Moreover, th...
def print_arr(arr): for a in arr: print(a, end=' ') def solution(): d, hr = input().split() d, hr = int(d), int(hr) intervals = [] first = [] for _ in range(d): vmin, vmax = input().split() vmin, vmax = int(vmin), int(vmax) intervals.append((vmin, vmax)) ...
{ "input": [ "2 5\n0 1\n3 5\n", "1 48\n5 7\n", "30 189\n0 8\n3 8\n5 8\n2 2\n7 7\n2 8\n7 8\n2 5\n1 7\n0 1\n3 4\n1 7\n1 6\n5 6\n3 7\n4 7\n4 7\n4 7\n5 5\n0 5\n4 7\n3 5\n0 6\n4 8\n2 5\n5 6\n5 6\n2 8\n0 7\n7 8\n", "30 71\n1 3\n0 6\n3 5\n3 6\n2 4\n2 8\n2 4\n3 8\n3 5\n2 4\n2 3\n3 7\n0 0\n5 7\n0 2\n5 8\n0 8\n...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Tomorrow Peter has a Biology exam. He does not like this subject much, but d days ago he learnt that he would have to take this exam. Peter's strict parents made him prepare for the e...
525_A. Vitaliy and Pie_31651
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third ro...
n = int(input()) knowledge = input() count = 0 keyHash = {} for i in range((2*n) -2): if i%2 == 0: key = knowledge[i] if key in keyHash: keyHash[key]+=1 else: keyHash[key] = 1 else: door = knowledge[i] reqKey = chr(ord(door)+ 32) if reqKey in keyHash ...
{ "input": [ "3\naAbB\n", "4\naBaCaB\n", "5\nxYyXzZaZ\n", "10\nhNcMeXsSlHsUwYeMcA\n", "5\naArRaRaR\n", "26\nzAyBxCwDvEuFtGsHrIqJpKoLnMmNlOkPjQiRhSgTfUeVdWcXbY\n", "2\ndE\n", "2\ndD\n", "2\ndA\n", "3\ndDdD\n", "3\ndEeF\n", "100\nqDpInBmCrFwXpDbFgOzVvOcEmJrUcToAdEwEgTvBvB...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line a...
550_B. Preparing Olympiad_31655
You have n problems. You have estimated the difficulty of the i-th one as integer ci. Now you want to prepare a problemset for a contest, using some of the problems you've made. A problemset for the contest must consist of at least two problems. You think that the total difficulty of the problems of the contest must b...
vet = [] aux = [] cont = 0 def fa(i, f): global aux, cont if i<=f: aux.append(vet[i]) #print(aux, menor, sum(aux), maior, max(aux), min(aux), diff) if len(aux) >=2 and menor<=sum(aux)<=maior and max(aux) - min(aux)>=diff: #print('Entrei', aux) cont+=1 for ...
{ "input": [ "4 40 50 10\n10 20 30 25\n", "5 25 35 10\n10 10 20 10 20\n", "3 5 6 1\n1 2 3\n", "15 2572491 5084070 823435\n570344 78552 775918 501843 844935 71141 331498 636557 435494 715447 992666 831188 28969 171046 989614\n", "10 159699 10967276 3542\n998862 999751 995306 992648 992661 991407 99...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You have n problems. You have estimated the difficulty of the i-th one as integer ci. Now you want to prepare a problemset for a contest, using some of the problems you've made. A pr...
577_C. Vasya and Petya's Game_31659
Vasya and Petya are playing a simple game. Vasya thought of number x between 1 and n, and Petya tries to guess the number. Petya can ask questions like: "Is the unknown number divisible by number y?". The game is played by the following rules: first Petya asks all the questions that interest him (also, he can ask no ...
def get_primes(n): numbers = set(range(n, 1, -1)) primes = [] while numbers: p = numbers.pop() primes.append(p) numbers.difference_update(set(range(p*2, n+1, p))) return primes n = int(input()) l = get_primes(n+1) ans = [] for x in l: p = x while(p<=n): ans.app...
{ "input": [ "4\n", "6\n", "784\n", "19\n", "400\n", "31\n", "557\n", "900\n", "625\n", "160\n", "15\n", "729\n", "37\n", "44\n", "953\n", "998\n", "20\n", "30\n", "211\n", "322\n", "1\n", "894\n", "1000\n", "289\n", "...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Vasya and Petya are playing a simple game. Vasya thought of number x between 1 and n, and Petya tries to guess the number. Petya can ask questions like: "Is the unknown number divisi...
59_A. Word_31663
Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would change the letters' register in every word so that it either only consisted of lowercase letters or, vice versa, only of uppercase ones. At th...
n = input() a=0 b=0 for i in n: if(i.isupper()): a+=1 else: b+=1 if(a>b): print(n.upper()) else: print(n.lower())
{ "input": [ "ViP\n", "maTRIx\n", "HoUse\n", "AORNNDKTRLRVGDPXJKXFTPFpopuzrlqumrxssskvbm\n", "ERPZGrodyu\n", "EBWOVSNLYTWWXrnovgugogtjahnmatomubebyxakas\n", "Ur\n", "XHRPXZEGHSOCJPICUIXSKFUZUPYTSGJSDIYBCMNMNBPNDBXLXBzhbfnqvwcffvrdhtickyqhupmcehlsyvncqmfhautvxudqdhgg\n", "RJIQZMJCIM...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Vasya is very upset that many people on the Net mix uppercase and lowercase letters in one word. That's why he decided to invent an extension for his favorite browser that would chang...
641_D. Little Artem and Random Variable_31668
Little Artyom decided to study probability theory. He found a book with a lot of nice exercises and now wants you to help him with one of them. Consider two dices. When thrown each dice shows some integer from 1 to n inclusive. For each dice the probability of each outcome is given (of course, their sum is 1), and dif...
n = int(input()) M = list(map(float, input().split())) m = list(map(float, input().split())) a = [] sa = [0] b = [] sb = [0] for i in range(0, n): p = sa[i] - sb[i] - M[i] - m[i] q = M[i] - sa[i]*(M[i] + m[i]) d = p*p - 4*q if d < 0: d = -d a.append((-p + (d ** 0.5))/2) b.append(M[i] + ...
{ "input": [ "3\n0.125 0.25 0.625\n0.625 0.25 0.125\n", "2\n0.25 0.75\n0.75 0.25\n", "8\n0.09597231 0.11315755 0.32077119 0.22643005 0.03791746 0.04296694 0.10284494 0.05993956\n0.52402769 0.19814245 0.20452881 0.06686995 0.00468254 0.00103306 0.00055506 0.00016044\n", "10\n0 0 0 0 0 0 0 0 0 1.0\n1.0 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Little Artyom decided to study probability theory. He found a book with a lot of nice exercises and now wants you to help him with one of them. Consider two dices. When thrown each d...
66_B. Petya and Countryside_31672
Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1 × n in size, when viewed from above. This rectangle is divided into n equal square sections. The garden is very unusual as each of the square sections possesses its own fixed h...
num = input() sec = list(map(int, input().split(' '))) ans = 0 def check(index): total = 1 #print(sec[index]) for i in range(len(sec)): #print(i) if index-i-1 < 0: break if sec[index-i-1] <= sec[index-i]: #print(i) total = total +1 else: ...
{ "input": [ "8\n1 2 1 1 1 3 3 4\n", "5\n1 2 1 2 1\n", "1\n2\n", "10\n1 2 3 4 5 6 7 8 9 10\n", "10\n10 9 8 7 6 5 4 3 2 1\n", "100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 1 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Little Petya often travels to his grandmother in the countryside. The grandmother has a large garden, which can be represented as a rectangle 1 × n in size, when viewed from above. Th...
715_D. Create a Maze_31677
ZS the Coder loves mazes. Your job is to create one so that he can play with it. A maze consists of n × m rooms, and the rooms are arranged in n rows (numbered from the top to the bottom starting from 1) and m columns (numbered from the left to the right starting from 1). The room in the i-th row and j-th column is den...
corr = lambda x, y: 1 <= x <= n and 1 <= y <= m T = int(input()) a = [] while T: a.append(T % 6) T //= 6 L = len(a) n = m = L * 2 + 2 ans = [(1, 2, 2, 2), (2, 1, 2, 2)] f = [[1] * 9 for i in range(7)] f[1][2] = f[2][2] = f[2][6] = f[3][5] = 0 f[4][5] = f[4][6] = f[5][2] = f[5][5] = f[5][6] = 0 p = [0] * 9 p[1]...
{ "input": [ "4\n", "3\n", "977109881915691245\n", "258705984061064258\n", "149046408559208370\n", "832895302932804104\n", "576460752303423488\n", "486418831096175146\n", "863617562997108966\n", "3\n", "797292600336026807\n", "447305350011531169\n", "513630312672613...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: ZS the Coder loves mazes. Your job is to create one so that he can play with it. A maze consists of n × m rooms, and the rooms are arranged in n rows (numbered from the top to the bot...
736_A. Tennis Championship_31680
Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately. Organizers are stil...
n = int(input()) an = 0 a = 1 b = 0 c = 2 while(n >= c): b = a a = c c = a + b an+=1 print(an)
{ "input": [ "3\n", "4\n", "2\n", "10\n", "61824012598535\n", "679891637638612258\n", "690000\n", "262406072477\n", "232\n", "1240723548\n", "12\n", "2500\n", "7\n", "1000\n", "11\n", "19204385325853\n", "123456789123456789\n", "16\n", "9\n",...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow kno...
760_A. Petr and a calendar_31684
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture: <image> Petr ...
def read_input(): line = input().strip().split() m = int(line[0]) week = int(line[1]) days31 = {1,3,5,7,8,10,12} if m == 2: days = 28 elif m in days31: days = 31 else: days = 30 z = (days + week - 1) return z//7 if z % 7 == 0 else z//7 + 1 if __name__ == "__m...
{ "input": [ "1 7\n", "1 1\n", "11 6\n", "3 1\n", "11 3\n", "1 2\n", "6 4\n", "3 5\n", "4 4\n", "9 7\n", "4 5\n", "2 6\n", "7 5\n", "10 6\n", "12 1\n", "9 1\n", "5 1\n", "12 2\n", "6 5\n", "1 3\n", "12 6\n", "4 7\n", "4 2\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows c...
804_B. Minimum number of steps_31690
We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If we have no "ab" as a substring, our job is done. Print the minimum number of steps we should perform to make our job done modulo 109 + 7...
MOD = 10**9 + 7 s = input() bcount, count = 0, 0 for c in reversed(s): if c == 'b': bcount += 1 else: count += bcount bcount *= 2 if bcount > 2**62: bcount %= MOD print(count % MOD)
{ "input": [ "ab\n", "aab\n", "abbbbababbabbbbbabaabbbaabbbbbbbaaab\n", "abbaa\n", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbaaaaaaaaabaabaaababaabaababaaabababaabbbbbbb\n", "aaabaaaabbababbaabbababbbbaaaaaaabbabbba\n", "aaaaabaabababaaaaaba\n", "abbbbbbbbbbbbbbbbbbbbbbb...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each step we choose one of substrings "ab" in the string and replace it with the string "bba". If...
82_A. Double Cola_31694
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, d...
n=int(input()) #L=["Sheldon","Leonard","Penny","Rajesh","Howard"] i=1 val=5 while n>val: if i%2==0 or i==1: n=n-5*i val=2*val i=2*i if 1<=n<=i: print("Sheldon") elif i<=n<=2*i: print("Leonard") elif 2*i<=n<=3*i: print("Penny") elif 3*i<=n<=4*i: print("Rajesh") elif 4*i<=n<=5*i: print("Howard")
{ "input": [ "6\n", "1802\n", "1\n", "184518\n", "9266286\n", "3961838\n", "4\n", "5\n", "534\n", "159222638\n", "8302\n", "24\n", "999999999\n", "300\n", "121580142\n", "10010\n", "999999998\n", "282798\n", "63\n", "3\n", "1154414\n"...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buy...
850_C. Arpa and a game with Mojtaba_31697
Mojtaba and Arpa are playing a game. They have a list of n numbers in the game. In a player's turn, he chooses a number pk (where p is a prime number and k is a positive integer) such that pk divides at least one number in the list. For each number in the list divisible by pk, call it x, the player will delete x and a...
import sys input = sys.stdin.buffer.readline from collections import Counter games = Counter() # prime : bitmask of if that power of the prime exists def add_primes(a): i = 2 while i*i <= a: cnt = 0 while a % i == 0: a //= i cnt += 1 if cnt: games[i...
{ "input": [ "4\n1 1 17 17\n", "4\n1 1 1 1\n", "4\n1 1 17 289\n", "5\n1 2 3 4 5\n", "1\n270983380\n", "1\n877739788\n", "100\n44 188 149 152 200 131 152 1 15 101 15 64 51 48 5 189 65 105 90 143 60 54 82 149 66 89 191 182 46 92 51 19 77 88 175 192 89 4 135 126 89 68 116 92 159 71 160 97 200...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Mojtaba and Arpa are playing a game. They have a list of n numbers in the game. In a player's turn, he chooses a number pk (where p is a prime number and k is a positive integer) suc...
899_D. Shovel Sale_31703
There are n shovels in Polycarp's shop. The i-th shovel costs i burles, that is, the first shovel costs 1 burle, the second shovel costs 2 burles, the third shovel costs 3 burles, and so on. Polycarps wants to sell shovels in pairs. Visitors are more likely to buy a pair of shovels if their total cost ends with severa...
n = int(input()) if n < 5: print((n*(n-1))//2) else: x = n+n-1 if str(x).count('9') == len(str(x)): print(1) else: ans = 0 x = len(str(x)) x = x-1 z = 10**x y = int('9'*x) while y <= (n+(n-1)): if n >= y: ans += y//2 ...
{ "input": [ "50\n", "14\n", "7\n", "23\n", "15\n", "4999\n", "27\n", "2\n", "16\n", "25\n", "37\n", "9999999\n", "26\n", "36\n", "47\n", "499999\n", "46\n", "20\n", "802030518\n", "45\n", "99999999\n", "13\n", "685146646\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are n shovels in Polycarp's shop. The i-th shovel costs i burles, that is, the first shovel costs 1 burle, the second shovel costs 2 burles, the third shovel costs 3 burles, and...
948_C. Producing Snow_31709
Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift — a large snow maker. He plans to make some amount of snow every day. On day i he will make a pile of snow of volume Vi and put it in her garden. Each day, every pile w...
import heapq heap = [] n = int(input()) V = list(map(int, input().split())) T = list(map(int, input().split())) tmp = 0 for i in range(n): ans = 0 heapq.heappush(heap, tmp+V[i]) while len(heap) and heap[0]<=tmp+T[i]: ans += heapq.heappop(heap)-tmp tmp += T[i] ans += T[i]*len(heap) print(...
{ "input": [ "3\n10 10 5\n5 7 2\n", "5\n30 25 20 15 10\n9 10 12 4 13\n", "1\n4\n5\n", "4\n0 0 0 0\n1 2 3 4\n", "1\n5\n4\n", "1\n5\n5\n", "13\n1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1\n", "2\n9 3\n8 2\n", "2\n9 3\n4 4\n", "10\n11 39 16 34 25 3 12 11 31 16\n10 0 4 9 8...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Alice likes snow a lot! Unfortunately, this year's winter is already over, and she can't expect to have any more of it. Bob has thus bought her a gift — a large snow maker. He plans t...
976_C. Nested Segments_31713
You are given a sequence a1, a2, ..., an of one-dimensional segments numbered 1 through n. Your task is to find two distinct indices i and j such that segment ai lies within segment aj. Segment [l1, r1] lies within segment [l2, r2] iff l1 ≥ l2 and r1 ≤ r2. Print indices i and j. If there are multiple answers, print a...
n = int(input()) otr = [tuple(map(int, input().split())) for i in range(n)] left = sorted(otr, key=lambda x: (x[0], x[1])) for i, el in enumerate(left[1:]): one, two = left[i], el if one[0] == two[0]: print(f'{otr.index(one) + 1} {n - otr[::-1].index(two)}') exit() elif one[1] >= two[1]:...
{ "input": [ "3\n1 5\n2 6\n6 20\n", "5\n1 10\n2 9\n3 9\n2 3\n2 9\n", "10\n1 2\n2 3\n3 4\n4 5\n5 6\n6 6\n6 7\n7 8\n8 9\n9 10\n", "3\n1 10\n10 20\n9 11\n", "3\n11 12\n11 15\n43 45\n", "3\n1 1000\n1001 1003\n1 1\n", "2\n2 9\n1 10\n", "2\n1 1\n1 3\n", "3\n2 9\n1 7\n2 8\n", "4\n1 3\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given a sequence a1, a2, ..., an of one-dimensional segments numbered 1 through n. Your task is to find two distinct indices i and j such that segment ai lies within segment a...
996_A. Hit the Lottery_31717
Allen has a LOT of money. He has n dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bills are 1, 5, 10, 20, 100. What is the minimum number of bills Allen could receive after withdrawing his entire balance? Input The first...
money=int(input()) number=0 alist=[100,20,10,5,1] for i in alist: number+=money//i money=money%i print(int(number))
{ "input": [ "43\n", "125\n", "1000000000\n", "31\n", "265145\n", "82655\n", "2521\n", "1\n", "1132\n", "671704\n", "152541908\n", "5\n", "27035533\n", "24403439\n", "22717528\n", "74\n", "6364\n", "7\n", "719\n", "668439837\n", "9140...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Allen has a LOT of money. He has n dollars in the bank. For security reasons, he wants to withdraw it in cash (we will not disclose the reasons here). The denominations for dollar bil...
p02647 Tokio Marine & Nichido Fire Insurance Programming Contest 2020 - Lamps_31731
We have N bulbs arranged on a number line, numbered 1 to N from left to right. Bulb i is at coordinate i. Each bulb has a non-negative integer parameter called intensity. When there is a bulb of intensity d at coordinate x, the bulb illuminates the segment from coordinate x-d-0.5 to x+d+0.5. Initially, the intensity o...
n, k = map(int, input().split()) A = list(map(int, input().split())) for i in range(min(50, k)): DP = [0] * (n+1) for j in range(n): light = A[j] DP[max(0, j-light)] += 1 DP[min(n, j+light+1)] -= 1 for j in range(1, n): DP[j] += DP[j-1] A = DP[:-1] print(*A)
{ "input": [ "5 1\n1 0 0 1 0", "5 2\n1 0 0 1 0", "5 1\n0 0 0 1 0", "5 2\n0 0 0 1 0", "5 2\n0 0 0 0 0", "5 2\n1 0 0 0 0", "5 2\n0 0 0 0 1", "5 0\n0 0 0 0 1", "5 2\n1 0 0 2 0", "5 2\n0 0 0 2 0", "5 3\n0 0 0 0 0", "5 2\n0 1 0 0 1", "5 0\n0 1 0 0 1", "5 2\n0 2 0 0 2...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: We have N bulbs arranged on a number line, numbered 1 to N from left to right. Bulb i is at coordinate i. Each bulb has a non-negative integer parameter called intensity. When there ...
p02776 AtCoder Beginner Contest 155 - Perils in Parallel_31734
After being invaded by the Kingdom of AlDebaran, bombs are planted throughout our country, AtCoder Kingdom. Fortunately, our military team called ABC has managed to obtain a device that is a part of the system controlling the bombs. There are N bombs, numbered 1 to N, planted in our country. Bomb i is planted at the ...
from bisect import bisect_left, bisect_right from sys import setrecursionlimit setrecursionlimit(10 ** 6) class UnionFind: def __init__(self, size): self.data = [-1] * size def find(self, x): if self.data[x] < 0: return x else: self.data[x] = self.find(self.data...
{ "input": [ "4 2\n2 0\n3 1\n5 1\n7 0\n1 4\n4 7", "3 2\n5 0\n10 0\n8 0\n6 9\n66 99", "3 4\n5 1\n10 1\n8 0\n1 10\n4 5\n6 7\n8 9", "12 20\n536130100 1\n150049660 1\n79245447 1\n132551741 0\n89484841 1\n328129089 0\n623467741 0\n248785745 0\n421631475 0\n498966877 0\n43768791 1\n112237273 0\n21499042 142...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: After being invaded by the Kingdom of AlDebaran, bombs are planted throughout our country, AtCoder Kingdom. Fortunately, our military team called ABC has managed to obtain a device t...
p02911 AtCoder Beginner Contest 141 - Attack Survival_31738
Takahashi has decided to hold fastest-finger-fast quiz games. Kizahashi, who is in charge of making the scoreboard, is struggling to write the program that manages the players' scores in a game, which proceeds as follows. A game is played by N players, numbered 1 to N. At the beginning of a game, each player has K poi...
N, K, Q = list(map(int, input().split())) P = [K-Q]*N for _ in range(Q): P[int(input())-1]+=1 for p in P: print('Yes' if p>0 else 'No')
{ "input": [ "6 5 4\n3\n1\n3\n2", "10 13 15\n3\n1\n4\n1\n5\n9\n2\n6\n5\n3\n5\n8\n9\n7\n9", "6 3 4\n3\n1\n3\n2", "6 1 4\n3\n1\n3\n2", "10 8 15\n3\n1\n4\n1\n5\n9\n2\n6\n5\n3\n5\n8\n9\n7\n9", "6 3 4\n3\n1\n3\n4", "19 8 15\n3\n1\n4\n1\n5\n0\n2\n6\n5\n3\n5\n8\n9\n7\n9", "37 8 15\n3\n0\n4\n1...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Takahashi has decided to hold fastest-finger-fast quiz games. Kizahashi, who is in charge of making the scoreboard, is struggling to write the program that manages the players' scores...
p03047 diverta 2019 Programming Contest - Consecutive Integers_31742
Snuke has N integers: 1,2,\ldots,N. He will choose K of them and give those to Takahashi. How many ways are there to choose K consecutive integers? Constraints * All values in input are integers. * 1 \leq K \leq N \leq 50 Input Input is given from Standard Input in the following format: N K Output Print the a...
n, m = list(map(int, input().split())) print(n-m+1)
{ "input": [ "13 3", "3 2", "13 6", "6 2", "13 1", "13 0", "23 1", "19 1", "2 1", "2 0", "2 -1", "0 0", "0 1", "15 1", "13 2", "6 1", "19 2", "30 1", "11 1", "9 0", "6 0", "24 1", "32 1", "17 1", "32 0", "6 -2", ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Snuke has N integers: 1,2,\ldots,N. He will choose K of them and give those to Takahashi. How many ways are there to choose K consecutive integers? Constraints * All values in inpu...
p03188 AtCoder Grand Contest 030 - Coloring Torus_31746
For an n \times n grid, let (r, c) denote the square at the (r+1)-th row from the top and the (c+1)-th column from the left. A good coloring of this grid using K colors is a coloring that satisfies the following: * Each square is painted in one of the K colors. * Each of the K colors is used for some squares. * Let us...
def solve(k): if k == 1: print(1) print(1) return n = ((k - 1) // 4 + 1) * 2 ans = [[0] * n for _ in [0] * n] dub = 2 * (k - n) for m in range(n * 2): l = m + 1 if m < dub else dub + (m - dub) // 2 + 1 i = m % 2 j = (m // 2 + m % 2) % n for _...
{ "input": [ "9", "2", "4", "0", "7", "3", "6", "10", "8", "19", "5", "13", "26", "11", "29", "15", "14", "12", "22", "32", "-7", "-11", "-15", "-19", "27", "21", "20", "31", "18", "24", "36", ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: For an n \times n grid, let (r, c) denote the square at the (r+1)-th row from the top and the (c+1)-th column from the left. A good coloring of this grid using K colors is a coloring ...
p03496 AtCoder Beginner Contest 081 - Non-decreasing_31752
Snuke has an integer sequence, a, of length N. The i-th element of a (1-indexed) is a_{i}. He can perform the following operation any number of times: * Operation: Choose integers x and y between 1 and N (inclusive), and add a_x to a_y. He would like to perform this operation between 0 and 2N times (inclusive) so ...
N = int(input()) A = list(map(int, input().split())) mina = min(A) mini = A.index(mina) maxa = max(A) maxi = A.index(maxa) if mina >= 0: print(N-1) for i in range(N-1): print("{} {}".format(i+1, i+2)) elif maxa < 0: print(N-1) for i in range(N-1): print("{} {}".format(N-i, N-i-1)) else: if -mina < m...
{ "input": [ "3\n-2 5 -1", "2\n-1 -3", "5\n0 0 0 0 0", "2\n-2 -3", "2\n1 -11", "3\n-3 5 -1", "2\n0 0", "2\n1 0", "2\n2 -1", "3\n-2 5 0", "2\n0 -3", "2\n0 -4", "2\n0 -7", "2\n0 -14", "2\n0 -27", "2\n0 -22", "2\n-1 -22", "2\n0 -11", "2\n1 -19",...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Snuke has an integer sequence, a, of length N. The i-th element of a (1-indexed) is a_{i}. He can perform the following operation any number of times: * Operation: Choose integers x...
p03812 AtCoder Grand Contest 010 - Tree Game_31757
There is a tree with N vertices, numbered 1 through N. The i-th of the N-1 edges connects vertices a_i and b_i. Currently, there are A_i stones placed on vertex i. Takahashi and Aoki will play a game using this tree. First, Takahashi will select a vertex and place a piece on it. Then, starting from Takahashi, they wi...
import sys input = sys.stdin.readline from collections import deque n = int(input()) stone = [0]+list(map(int,input().split())) ab = [list(map(int,input().split())) for i in range(n-1)] graph = [[] for i in range(n+1)] deg = [0]*(n+1) for a,b in ab: if stone[a] < stone[b]: graph[a].append(b) deg[b] += 1 eli...
{ "input": [ "3\n1 2 3\n1 2\n2 3", "5\n5 4 1 2 3\n1 2\n1 3\n2 4\n2 5", "3\n1 1 1\n1 2\n2 3", "5\n2 4 1 2 3\n1 2\n1 3\n2 4\n2 5", "3\n1 2 1\n1 2\n2 3", "3\n1 2 3\n1 2\n1 3", "5\n5 4 1 2 3\n1 2\n1 3\n1 4\n3 5", "3\n1 2 2\n1 4\n1 3", "3\n0 1 1\n1 0\n1 3", "5\n1 1 1 3 3\n1 2\n1 3\n...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There is a tree with N vertices, numbered 1 through N. The i-th of the N-1 edges connects vertices a_i and b_i. Currently, there are A_i stones placed on vertex i. Takahashi and Aoki...
p00069 Drawing Lots II_31763
There are n vertical lines in the Amidakuji. This Amidakuji meets the following conditions. * Draw a horizontal line right next to it. Do not pull diagonally. * Horizontal lines always connect adjacent vertical lines. In other words, the horizontal line does not cross the vertical line. * For any vertical line, horizo...
# AOJ 0069: Drawing Lots II # Python3 2018.6.28 bal4u while True: n = int(input()) if n == 0: break m, p, d = [int(input()) for i in range(3)] m -= 1 p -= 1 a = [[] for i in range(d+1)] for i in range(d): a[i] = list(map(int, input())) s = [[0 for j in range(n)] for i in range(d+1)] s[d] = [i for i in range(n...
{ "input": [ "5\n2\n3\n9\n1010\n1001\n0100\n1001\n0010\n1000\n0100\n0101\n1010\n0", "5\n2\n3\n9\n1010\n1001\n0100\n1001\n0010\n1000\n0000\n0101\n1010\n0", "5\n2\n3\n9\n1010\n1001\n0100\n1001\n0010\n1000\n0000\n0101\n1000\n0", "5\n2\n3\n9\n1010\n1001\n0000\n1001\n0010\n1000\n0000\n0101\n1001\n0", "...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are n vertical lines in the Amidakuji. This Amidakuji meets the following conditions. * Draw a horizontal line right next to it. Do not pull diagonally. * Horizontal lines alwa...
p00201 Wrought Gold Master_31767
You finally got a magic pot, an alchemy pot. You can create a new item by putting multiple items in the alchemy pot. Newly created items can also be placed in alchemy pots to make other items. A list of items needed to make an item will be called an alchemy recipe. The following three are examples of alchemy recipes. ...
# from pprint import pprint as pprint import copy def findrecipe(rec,ite,obj): # pprint(rec) # print("obj: ",obj) # print("=-") try: mat = rec[obj] rec2 = copy.copy(rec) del rec2[obj] price = min(ite[obj],sum([findrecipe(rec2,ite,m) for m in mat])) # print(price,...
{ "input": [ "8\nwood 3000\nstring 800\nrice 36\nwater 0\nracket 5000\nmicrophone 9800\nonigiri 140\nguitar 98000\n3\nracket 2 wood string\nonigiri 2 rice water\nguitar 3 racket microphone onigiri\nguitar\n1\ncomputer 300000\n0\ncomputer\n0", "8\nwood 3000\nstring 800\nrice 36\nwater 0\nracket 5000\nmicrophon...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You finally got a magic pot, an alchemy pot. You can create a new item by putting multiple items in the alchemy pot. Newly created items can also be placed in alchemy pots to make oth...
p00356 Wire_31770
I am a craftsman specialized in interior works. A customer asked me to perform wiring work on a wall whose entire rectangular surface is tightly pasted with pieces of panels. The panels are all of the same size (2 m in width, 1 m in height) and the wall is filled with an x (horizontal) by y (vertical) array of the pane...
a, b = map(int, input().split()) cnt = 0 for x in range(0, a*2+1, 2): if((b*x) % (2*a) == 0): cnt += 1 print(a + b - cnt + 2)
{ "input": [ "4 6", "4 4", "2 4", "1 8", "5 6", "1 0", "9 6", "4 13", "9 3", "6 1", "2 13", "7 1", "2 29", "17 2", "20 2", "21 1", "1 3", "2 2", "2 22", "17 1", "15 1", "33 1", "27 1", "11 1", "2 25", "1 1", "2...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: I am a craftsman specialized in interior works. A customer asked me to perform wiring work on a wall whose entire rectangular surface is tightly pasted with pieces of panels. The pane...
p00715 Name the Crossing_31774
The city of Kyoto is well-known for its Chinese plan: streets are either North-South or East-West. Some streets are numbered, but most of them have real names. Crossings are named after the two streets crossing there, e.g. Kawaramachi-Sanjo is the crossing of Kawaramachi street and Sanjo street. But there is a problem:...
from collections import deque import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): N = int(readline()) if N == 0: return False L = 0 n_map = {} def get(s): nonlocal L if s in n_map: return n_map[s] n_map[s] = L L += 1 ...
{ "input": [ "7\nShijo-Kawaramachi\nKarasuma-Imadegawa\nKawaramachi-Imadegawa\nNishioji-Shijo\nKarasuma-Gojo\nTorimaru-Rokujo\nRokujo-Karasuma\n6\nShijo-Karasuma\nImadegawa-Nishioji\nNishioji-Gojo\nShijo-Torimaru\nTorimaru-Gojo\nShijo-Kawabata\n4\n1jo-Midosuji\nMidosuji-2jo\n2jo-Omotesando\nOmotesando-1jo\n4\nMid...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: The city of Kyoto is well-known for its Chinese plan: streets are either North-South or East-West. Some streets are numbered, but most of them have real names. Crossings are named aft...
p00855 Prime Gap_31778
The sequence of n - 1 consecutive composite numbers (positive integers that are not prime and not equal to 1) lying between two successive prime numbers p and p + n is called a prime gap of length n. For example, (24, 25, 26, 27, 28) between 23 and 29 is a prime gap of length 6. Your mission is to write a program to c...
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 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF...
{ "input": [ "10\n11\n27\n2\n492170\n0", "10\n11\n27\n2\n296421\n0", "10\n11\n27\n2\n338424\n0", "10\n11\n27\n2\n525306\n0", "10\n11\n27\n2\n245198\n0", "10\n11\n27\n2\n199792\n0", "10\n11\n47\n2\n199792\n0", "10\n15\n55\n2\n199792\n0", "10\n15\n55\n2\n76071\n0", "10\n11\n53\n2...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: The sequence of n - 1 consecutive composite numbers (positive integers that are not prime and not equal to 1) lying between two successive prime numbers p and p + n is called a prime ...
p01118 On-Screen Keyboard_31783
<!-- Problem B --> On-Screen Keyboard You are to input a string with an OSK (on-screen keyboard). A remote control with five buttons, four arrows and an OK (Fig. B-1), is used for the OSK. Find the minimum number of button presses required to input a given string with the given OSK. <image> Fig. B-1 Remote control...
# coding=utf-8 ### ### for python program ### import sys import math # math class class mymath: ### pi pi = 3.14159265358979323846264338 ### Prime Number def pnum_eratosthenes(self, n): ptable = [0 for i in range(n+1)] plist = [] for i in range(2, n+1): if ptable...
{ "input": [ "3 9\nABCDEFGHI\nJKLMNOPQR\nSTUVWXYZ_\nICPC\n5 11\n___________\n____A______\n________M__\n___________\n_C_________\nACM\n4 21\n1_2_3_4_5_6_7_8_9_0_-\nQqWwEeRrTtYyUuIiOoPp@\nAaSsDdFfGgHhJjKkLl;_:\nZzXxCcVvBbNnMm,_._/__\nICPC2019,AsiaYokohamaRegional,QualificationRound\n0 0", "3 9\nABCDEFGHI\nJKLMN...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: <!-- Problem B --> On-Screen Keyboard You are to input a string with an OSK (on-screen keyboard). A remote control with five buttons, four arrows and an OK (Fig. B-1), is used for...
p01417 Calender Colors_31789
Taro is a member of a programming contest circle. In this circle, the members manage their schedules in the system called Great Web Calender. Taro has just added some of his friends to his calendar so that he can browse their schedule on his calendar. Then he noticed that the system currently displays all the schedule...
import itertools N,M = map(int,input().split()) src = [tuple(map(float,input().split())) for i in range(N)] if M <= 1: print(0) exit() dists = [[None for j in range(N)] for i in range(N)] for i in range(N-1): for j in range(i+1,N): l1,a1,b1 = src[i] l2,a2,b2 = src[j] dist = 0 ...
{ "input": [ "2 1\n1.0 1.0 1.0\n0.0 0.0 0.0", "5 3\n12.0 15.0 9.0\n10.0 -3.0 2.2\n3.5 6.8 9.0\n2.1 4.4 5.9\n1.2 4.0 -5.4", "3 2\n0 0 0\n10 10 10\n100 100 100", "2 1\n1.0 1.0 1.0\n0.6914210799445369 0.0 0.0", "5 3\n12.0 15.0 9.0\n10.0 -3.0 2.2\n3.5 6.8 9.0\n2.1 4.4 5.9\n1.5075343707499678 4.0 -5.4"...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Taro is a member of a programming contest circle. In this circle, the members manage their schedules in the system called Great Web Calender. Taro has just added some of his friends ...
p01733 Fox Observation_31795
Ievan Ritola is a researcher of behavioral ecology. Her group visited a forest to analyze an ecological system of some kinds of foxes. The forest can be expressed as a two-dimensional plane. With her previous research, foxes in the forest are known to live at lattice points. Here, lattice points are the points whose x...
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 = 10**9+7 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.stdin....
{ "input": [ "2\n1 1 2\n2 2 3", "2\n1 1 4\n2 2 3", "2\n1 1 3\n2 2 3", "2\n1 1 4\n2 0 0", "2\n0 1 1\n2 0 0", "2\n1 1 2\n2 0 0", "2\n1 1 0\n3 0 0", "2\n1 1 2\n3 2 3", "2\n1 1 4\n2 2 5", "2\n1 0 5\n2 1 3", "2\n1 1 4\n4 2 5", "2\n1 0 8\n1 -1 3", "2\n1 1 7\n2 2 6", "...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Ievan Ritola is a researcher of behavioral ecology. Her group visited a forest to analyze an ecological system of some kinds of foxes. The forest can be expressed as a two-dimensiona...
p01872 My Number_31798
A: My Number-My Number- problem I'm sorry! Late late! Ah! I'm starting to work for this company I've been longing for today! Even so, I've been oversleeping since the first day ...! ?? Today is an important day when I have to tell my number to the company ...! I think everyone knows, but I'll explain my number fo...
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import array def is_valid_number(sequence): q = lambda n: (n + 1) if 1 <= n <= 6 else (n - 5) sum_pq = 0 for index in range(1, 12): sum_pq += sequence[index] * q(index) rem_pq = sum_pq % 11 check_digit = 0 if rem_pq <= 1 else (11 - rem_pq) ...
{ "input": [ "?12345678901", "?123456789/1", "1/987654321?", "1.987654321?", "1.687954321?", "1/587954321?", "1/687954321?", "6/478851321?", "?1/315887426", "634788413/1?", "?12345678900", "?123456789.1", "1.587954321?", "4/687951321?", "4/678951321?", "...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: A: My Number-My Number- problem I'm sorry! Late late! Ah! I'm starting to work for this company I've been longing for today! Even so, I've been oversleeping since the first day .....
p02293 Parallel/Orthogonal_31804
For given two lines s1 and s2, print "2" if they are parallel, "1" if they are orthogonal, or "0" otherwise. s1 crosses points p0 and p1, and s2 crosses points p2 and p3. Constraints * 1 ≤ q ≤ 1000 * -10000 ≤ xpi, ypi ≤ 10000 * p0 ≠ p1 and p2 ≠ p3. Input The entire input looks like: q (the number of queries) 1st...
import math EPS = 1e-10 class Point(): def __init__(self, x, y): self.x = x self.y = y def __add__(self, point): # + 演算子での挙動を指定 return Point(self.x+point.x, self.y+point.y) def __sub__(self, point): # - 演算子での挙動を指定 return Point(self.x-point.x, self.y-point....
{ "input": [ "3\n0 0 3 0 0 2 3 2\n0 0 3 0 1 1 1 4\n0 0 3 0 1 1 2 2", "3\n0 0 3 0 0 2 3 2\n0 0 3 0 1 1 1 7\n0 0 3 0 1 1 2 2", "3\n0 0 3 1 0 2 3 2\n0 0 3 0 1 1 1 7\n0 0 3 0 1 1 2 2", "3\n0 0 3 0 0 2 3 2\n0 0 3 -1 1 1 1 4\n0 0 3 0 1 1 2 2", "3\n0 0 3 1 0 2 3 2\n0 1 3 0 1 1 1 7\n0 0 3 0 1 1 2 2", ...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: For given two lines s1 and s2, print "2" if they are parallel, "1" if they are orthogonal, or "0" otherwise. s1 crosses points p0 and p1, and s2 crosses points p2 and p3. Constraint...
p02440 Min-Max Element_31807
Write a program which manipulates a sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$ by the following operations: * min($b, e$): report the minimum element in $a_b, a_{b+1}, ..., a_{e-1}$ * max($b, e$): report the maximum element in $a_b, a_{b+1}, ..., a_{e-1}$ Constraints * $1 \leq n \leq 1,000$ * $-1,000,000,000 \leq a...
N = int(input()) A = list(map(int,input().split())) Q = int(input()) for _ in range(Q): q = list(map(int,input().split())) if q[0] == 0: print(min(A[q[1]:q[2]])) else: print(max(A[q[1]:q[2]]))
{ "input": [ "7\n8 3 7 1 9 1 4\n3\n0 0 3\n0 1 5\n1 0 7", "7\n8 3 0 1 9 1 4\n3\n0 0 3\n0 1 5\n1 0 7", "7\n8 3 0 0 9 1 4\n3\n0 0 3\n1 1 5\n1 0 7", "7\n8 3 0 0 9 1 4\n6\n0 0 3\n1 1 5\n1 0 7", "7\n8 3 0 1 14 1 4\n3\n0 1 3\n0 1 5\n1 0 7", "7\n2 2 -1 2 9 1 0\n3\n0 0 3\n0 1 5\n1 0 7", "7\n8 3 7 1...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Write a program which manipulates a sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$ by the following operations: * min($b, e$): report the minimum element in $a_b, a_{b+1}, ..., a_{e-1}$...
1025_G. Company Acquisitions_31819
There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup. The following steps happen ...
m = 1000000007 n = int(input()) a = list(map(int, input().split())) print((pow(2,n-1,m)-1 - sum(pow(2,a.count(x),m)-1 for x in set(a) if x != -1)) % m)
{ "input": [ "40\n3 3 -1 -1 4 4 -1 -1 -1 -1 -1 10 10 10 10 10 10 4 20 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 3 3 3 3 3 3 3 3\n", "2\n2 -1\n", "3\n-1 -1 -1\n", "10\n-1 6 6 6 -1 -1 -1 -1 6 -1\n", "10\n-1 -1 -1 -1 -1 -1 -1 -1 -1 -1\n", "10\n3 -1 -1 -1 -1 -1 -1 -1 2 2\n", "10\n7 7 7 7 7 7 -1 7...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are n startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have ...
1045_I. Palindrome Pairs_31823
After learning a lot about space exploration, a little girl named Ana wants to change the subject. Ana is a girl who loves palindromes (string that can be read the same backwards as forward). She has learned how to check for a given string whether it's a palindrome or not, but soon she grew tired of this problem, so s...
# Fast IO (only use in integer input) import os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline MOD1 = 100000007 MOD2 = 1000000007 evenStrDict = {} oddStrDict = {} cnt = 0 N = int(input()) for _ in range(N): p = input() countList = [0] * 26 for elem in p: if elem < 97: ...
{ "input": [ "3\naa\nbb\ncd\n", "6\naab\nabcac\ndffe\ned\naa\naade\n", "20\niw\nix\nudb\nbg\noi\nuo\njsm\num\ns\nquy\nqo\nbxct\nng\nrmr\nnu\nps\nio\nkh\nw\nk\n", "17\npo\nuej\ndtc\nj\ncnj\ncn\nbt\nnrj\nyye\nkol\nz\ntm\narb\ne\nzq\nj\nk\n", "20\nhw\nix\nudb\nbg\noi\nuo\njsm\num\ns\nquy\nqo\nbxct\nn...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: After learning a lot about space exploration, a little girl named Ana wants to change the subject. Ana is a girl who loves palindromes (string that can be read the same backwards as ...
106_C. Buns_31827
Lavrenty, a baker, is going to make several buns with stuffings and sell them. Lavrenty has n grams of dough as well as m different stuffing types. The stuffing types are numerated from 1 to m. Lavrenty knows that he has ai grams left of the i-th stuffing. It takes exactly bi grams of stuffing i and ci grams of dough ...
from sys import stdin, setrecursionlimit def arr_inp(n): if n == 1: return [int(x) for x in stdin.readline().split()] elif n == 2: return [float(x) for x in stdin.readline().split()] else: return list(stdin.readline()[:-1]) def dp(i, rem): if rem == 0: return 0 if...
{ "input": [ "100 1 25 50\n15 5 20 10\n", "10 2 2 1\n7 3 2 100\n12 3 1 10\n", "2 1 2 1\n1 2 1 1\n", "100 5 8 80\n25 8 2 70\n27 6 7 30\n26 1 6 5\n7 1 1 86\n18 8 4 54\n", "1000 3 67 88\n90 86 66 17\n97 38 63 17\n55 78 39 51\n", "1000 10 1 87\n100 1 1 38\n100 1 1 45\n100 1 1 73\n100 1 1 89\n100 1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Lavrenty, a baker, is going to make several buns with stuffings and sell them. Lavrenty has n grams of dough as well as m different stuffing types. The stuffing types are numerated f...
1091_B. New Year and the Treasure Geolocation_31831
Bob is a pirate looking for the greatest treasure the world has ever seen. The treasure is located at the point T, which coordinates to be found out. Bob travelled around the world and collected clues of the treasure location at n obelisks. These clues were in an ancient language, and he has only decrypted them at hom...
n = int(input().strip()) xm,ym = (0,0) for i in range(2*n): x,y = list(map(int,input().strip().split())) xm+=x ym+=y print(xm//(n), ym//(n))
{ "input": [ "2\n2 5\n-6 4\n7 -2\n-1 -3\n", "4\n2 2\n8 2\n-7 0\n-2 6\n1 -14\n16 -12\n11 -18\n7 -14\n", "4\n5 -10\n-7 7\n1 0\n8 3\n7 -6\n0 -9\n15 -13\n3 4\n", "10\n-52 25\n21 25\n76 -22\n-98 -56\n87 22\n-20 95\n45 -7\n30 89\n82 -97\n2 -3\n-144 32\n-70 13\n-98 -79\n-16 -15\n-150 107\n-113 17\n30 66\n-48...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Bob is a pirate looking for the greatest treasure the world has ever seen. The treasure is located at the point T, which coordinates to be found out. Bob travelled around the world a...
110_E. Lucky Tree_31835
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya encountered a tree with n vertexes. Besides, the tree was weighted, i. e. each edge of...
from sys import stdin, stdout import re from random import randrange from pprint import PrettyPrinter pprint = PrettyPrinter(width=55).pprint def is_lucky(num): return re.fullmatch("[47]+", num) is not None gr = None def topo_order(u): res = [(u, None, None)] i = 0 while i < len(res): u, p, _ ...
{ "input": [ "4\n1 2 4\n1 3 47\n1 4 7447\n", "4\n1 2 4\n3 1 2\n1 4 7\n", "10\n9 2 6\n5 3 7\n7 8 9\n2 1 7\n8 6 3\n1 4 5\n3 10 7\n7 4 3\n6 3 5\n", "7\n1 2 4\n2 3 7\n3 4 44\n4 5 47\n5 6 74\n6 7 77\n", "9\n1 2 1\n1 3 7\n3 4 19\n3 5 2\n4 6 46\n7 4 25\n5 8 64\n5 9 73\n", "2\n1 2 7\n", "7\n1 2 47...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, ...
113_B. Petr#_31839
Long ago, when Petya was a schoolboy, he was very much interested in the Petr# language grammar. During one lesson Petya got interested in the following question: how many different continuous substrings starting with the sbegin and ending with the send (it is possible sbegin = send), the given string t has. Substrings...
from functools import cmp_to_key def calc_lcp(s, sa): rank = [0 for _ in range(len(s))] for i in range(len(s)): rank[sa[i]] = i lcp = [0 for _ in range(len(s) - 1)] h = 0 for i in range(len(s)): if rank[i] < len(s) - 1: while max(i, sa[rank[i] + 1]) + h < len(s) and s[i...
{ "input": [ "codeforces\ncode\nforca\n", "abababab\na\nb\n", "round\nro\nou\n", "aba\nab\nba\n", "yrbqsdlzrjprklpcaahhhfpkaohwwavwcsookezigzufcfvkmawptgdcdzkprxazchdaquvizhtmsfdpyrsjqtvjepssrqqhzsjpjfvihgojqfgbeudgmgjrgeqykytuswbahfw\njqfgbeudgmgjr\nojqfgbeudgmg\n", "codecppforfood\nc\nd\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Long ago, when Petya was a schoolboy, he was very much interested in the Petr# language grammar. During one lesson Petya got interested in the following question: how many different c...
1158_A. The Party and Sweets_31843
n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are numbered with integers from 1 to m. For all 1 ≤ i ≤ n the minimal number of sweets, which i-th boy presented to some girl is equal to b_i an...
n, m = map(int, input().split()) a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] a.sort() b.sort() if a[-1] > b[0]: print(-1) exit() if a[-1] == b[0]: print(sum(b) + sum(a[:-1]) * m) else: print(sum(b) + a[-1] + sum(a[:-1]) * m - a[-2])
{ "input": [ "3 2\n1 2 1\n3 4\n", "2 3\n1 0\n1 1 2\n", "2 2\n0 1\n1 0\n", "2 2\n89164828 36174769\n90570286 89164829\n", "2 2\n217361 297931\n297930 83550501\n", "2 2\n14419485 34715515\n45193875 34715515\n", "2 2\n0 0\n100000000 100000000\n", "2 2\n23720786 67248252\n89244428 67248253...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: n boys and m girls came to the party. Each boy presented each girl some integer number of sweets (possibly zero). All boys are numbered with integers from 1 to n and all girls are num...
1198_F. GCD Groups 2_31848
You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in the second group is equal to one. The GCD of a group of integers is the largest non-negative integer that divides all the integers in th...
import sys def gcd(l): if len(l)==0: return 0 if len(l)==1: return l[0] if len(l)==2: if l[1]==0: return l[0] return gcd([l[1],l[0]%l[1]]) return gcd([gcd(l[:-1]),l[-1]]) def brute_force(l1,l2,l,sol): if len(l)==0: g1=gcd(l1) g2=gcd(l2) r...
{ "input": [ "5\n6 15 35 77 22\n", "5\n6 10 15 1000 75\n", "4\n2 3 6 7\n", "40\n1067430 223092870 223092870 223092870 44618574 223092870 1874730 223092870 223092870 223092870 223092870 746130 44618574 111546435 20281170 223092870 223092870 223092870 570570 74364290 223092870 223092870 223092870 223092...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given an array of n integers. You need to split all integers into two groups so that the GCD of all integers in the first group is equal to one and the GCD of all integers in ...
1215_E. Marbles_31851
Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles of the same color form a contiguos segment (and there is only one such segment for each color). In other words, Monocarp wants to rearra...
import sys n = int(sys.stdin.readline().strip()) a = list(map(int, sys.stdin.readline().strip().split())) M = [[0 for i in range (0, 21)] for j in range (0, 21)] F = [0 for i in range (0, 21)] for i in range (0, n): x = int(a[i]) for j in range (0, 21): if j != x: M[j][x] = M[j][x] + F[j] ...
{ "input": [ "7\n3 4 2 3 4 2 2\n", "13\n5 5 4 4 3 5 7 6 5 4 4 6 5\n", "5\n20 1 14 10 2\n", "6\n1 2 3 1 1 2\n", "100\n5 16 6 5 16 5 5 8 6 8 8 5 16 8 16 8 5 6 16 5 6 5 16 16 5 6 16 5 8 5 5 5 8 5 5 5 6 16 5 5 5 5 8 6 5 16 5 5 16 5 5 5 8 16 5 5 5 8 16 6 16 5 6 16 16 5 5 16 8 5 16 16 5 16 8 5 6 5 5 16 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Monocarp has arranged n colored marbles in a row. The color of the i-th marble is a_i. Monocarp likes ordered things, so he wants to rearrange marbles in such a way that all marbles o...
1257_B. Magic Stick_31857
Recently Petya walked in the forest and found a magic stick. Since Petya really likes numbers, the first thing he learned was spells for changing numbers. So far, he knows only two spells that can be applied to a positive integer: 1. If the chosen number a is even, then the spell will turn it into 3a/2; 2. If t...
t=int(input()) s=[] a=[1,2,3] for jngg in range(0,t): x=input() xx=x.split( ) x=int(xx[0]) y=int(xx[1]) if x==y: s.append('yes') elif x in a and y in a and x!=1: s.append('yes') elif x in a and y not in a: s.append('no') elif x==1: s.append('no') else:...
{ "input": [ "7\n2 3\n1 1\n3 6\n6 8\n1 2\n4 1\n31235 6578234\n", "1\n1000 23222\n", "1\n2 3\n", "1\n5 1000000000\n", "1\n858993461 1000000000\n", "1\n4 1000000000\n", "1\n98989876 98989877\n", "1\n1100 23222\n", "7\n4 3\n1 1\n3 6\n6 8\n1 2\n4 1\n31235 6578234\n", "1\n2 4\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Recently Petya walked in the forest and found a magic stick. Since Petya really likes numbers, the first thing he learned was spells for changing numbers. So far, he knows only two s...
1280_C. Jeremy Bearimy_31861
Welcome! Everything is fine. You have arrived in The Medium Place, the place between The Good Place and The Bad Place. You are assigned a task that will either make people happier or torture them for eternity. You have a list of k pairs of people who have arrived in a new inhabited neighborhood. You need to assign ea...
import sys input = sys.stdin.buffer.readline for T in range(int(input())): k = int(input()) counts = [0] * (2 * k + 1) adjacencies = [list() for i in range(2 * k + 1)] for _ in range(2 * k - 1): a, b, weight = map(int, input().split()) counts[a] += 1; counts[b] += 1 adjacencies[...
{ "input": [ "2\n3\n1 2 3\n3 2 4\n2 4 3\n4 5 6\n5 6 5\n2\n1 2 1\n1 3 2\n1 4 3\n", "1\n1\n2 1 4\n", "1\n1\n2 1 1\n", "1\n1\n2 1 0\n", "1\n1\n2 1 2\n", "2\n3\n1 2 3\n3 2 4\n2 4 3\n4 5 6\n5 6 5\n2\n1 2 1\n1 3 0\n1 4 3\n", "1\n1\n2 1 3\n", "1\n1\n1 2 5\n", "2\n3\n1 2 3\n3 2 4\n2 4 3\n4...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Welcome! Everything is fine. You have arrived in The Medium Place, the place between The Good Place and The Bad Place. You are assigned a task that will either make people happier or...
1300_B. Assigning to Classes_31865
Reminder: the [median](https://en.wikipedia.org/wiki/Median) of the array [a_1, a_2, ..., a_{2k+1}] of odd number of elements is defined as follows: let [b_1, b_2, ..., b_{2k+1}] be the elements of the array in the sorted order. Then median of this array is equal to b_{k+1}. There are 2n students, the i-th student has...
import sys T = int(sys.stdin.readline().strip()) for t in range (0, T): n = int(sys.stdin.readline().strip()) a = list(map(int, sys.stdin.readline().strip().split())) a.sort() print(a[n]-a[n-1])
{ "input": [ "3\n1\n1 1\n3\n6 5 4 1 2 3\n5\n13 4 20 13 2 5 8 3 17 16\n", "3\n1\n1 1\n3\n6 5 4 1 2 3\n5\n13 4 7 13 2 5 8 3 17 16\n", "3\n1\n1 1\n3\n6 5 4 1 2 3\n5\n13 4 7 13 2 5 10 3 17 16\n", "3\n1\n1 1\n3\n6 5 4 1 2 3\n5\n13 4 7 22 2 5 1 3 16 16\n", "3\n1\n1 1\n3\n6 5 4 1 2 3\n5\n13 4 10 22 2 5 1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Reminder: the [median](https://en.wikipedia.org/wiki/Median) of the array [a_1, a_2, ..., a_{2k+1}] of odd number of elements is defined as follows: let [b_1, b_2, ..., b_{2k+1}] be t...
1324_C. Frog Jumps_31869
There is a frog staying to the left of the string s = s_1 s_2 … s_n consisting of n characters (to be more precise, the frog initially stays at the cell 0). Each character of s is either 'L' or 'R'. It means that if the frog is staying at the i-th cell and the i-th character is 'L', the frog can jump only to the left. ...
for i in range(int(input())): print(max(map(len,input().split("R")))+1)
{ "input": [ "6\nLRLRRLL\nL\nLLR\nRRRR\nLLLLLL\nR\n", "6\nRRLRLLL\nL\nLLR\nRRRR\nLLLLLL\nR\n", "6\nMRLRRLL\nL\nLLR\nRRRR\nLLLLLL\nR\n", "6\nLLLRLRR\nL\nLRL\nRRRR\nLLLLLL\nR\n", "6\nLRLRLRL\nL\nLLR\nRRRR\nLLLLLL\nR\n", "6\nLLLLRRR\nL\nLRL\nRRRR\nLLLLLL\nR\n", "6\nRLLLLRQ\nL\nLLR\nRRRR\nLLLL...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There is a frog staying to the left of the string s = s_1 s_2 … s_n consisting of n characters (to be more precise, the frog initially stays at the cell 0). Each character of s is eit...
1343_B. Balanced Array_31873
You are given a positive integer n, it is guaranteed that n is even (i.e. divisible by 2). You want to construct the array a of length n such that: * The first n/2 elements of a are even (divisible by 2); * the second n/2 elements of a are odd (not divisible by 2); * all elements of a are distinct and positi...
if __name__ == '__main__': test_case = int(input()) for _ in range(test_case): n = int(input()) if n%4!=0: print("NO") else: print("YES") res = [] for i in range(0,n//2): res.append((i+1)*2) for i in range(1,n//2...
{ "input": [ "5\n2\n4\n6\n8\n10\n", "1\n7876\n", "1\n199998\n", "3\n2\n4\n6\n", "4\n4 2\n1 2 1 2\n4 3\n1 2 2 1\n8 7\n6 1 1 7 6 3 4 6\n6 6\n5 2 6 1 3 4\n", "1\n12876\n", "3\n2\n4\n12\n", "4\n4 2\n1 2 1 2\n4 3\n1 2 2 1\n8 7\n6 1 1 7 6 3 4 6\n6 6\n5 0 6 1 3 4\n", "1\n5288\n", "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 positive integer n, it is guaranteed that n is even (i.e. divisible by 2). You want to construct the array a of length n such that: * The first n/2 elements of a ...
1365_C. Rotation Matching_31877
After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented by a permutation of size n. Let's call them a and b. Note that a permutation of n elements is a sequence of numbers a_1, a_2, …, a_n, in ...
n=int(input()) arr1=[int(c) for c in input().split()] arr2=[int(c) for c in input().split()] dic1={} dic2={} for i in range(n): dic1[arr1[i]] = i dic2[arr2[i]] = i lshift=[0 for i in range(n)] rshift=[0 for i in range(n)] lcount={} rcount={} for i in range(n): dig=arr1[i] ind=dic2[dig] if ind <...
{ "input": [ "5\n1 2 3 4 5\n2 3 4 5 1\n", "4\n1 3 2 4\n4 2 3 1\n", "5\n5 4 3 2 1\n1 2 3 4 5\n", "18\n11 16 18 3 7 12 10 6 14 15 5 13 9 17 4 8 1 2\n16 9 8 7 4 13 6 17 3 18 14 11 5 1 15 12 10 2\n", "5\n1 5 2 4 3\n5 4 2 1 3\n", "1\n1\n1\n", "8\n6 7 1 3 5 4 8 2\n2 8 3 1 7 6 5 4\n", "12\n8 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: After the mysterious disappearance of Ashish, his two favourite disciples Ishika and Hriday, were each left with one half of a secret message. These messages can each be represented b...
1385_C. Make It Good_31881
You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall that the prefix of the array a=[a_1, a_2, ..., a_n] is a subarray consisting several first elements: the prefix of the array a of length k...
t = int(input()) for _ in range(t): n = int(input()) a = list(int(x) for x in input().split()) start = 0 end = n-1 while end>0 and a[end]<=a[end-1]: end-=1 start=end while start>0 and a[start]>=a[start-1]: start-=1 print(start)
{ "input": [ "5\n4\n1 2 3 4\n7\n4 3 3 8 4 5 2\n3\n1 1 1\n7\n1 3 1 4 5 3 2\n5\n5 4 3 2 3\n", "5\n4\n1 2 3 4\n7\n4 3 3 8 4 5 2\n3\n1 1 1\n7\n1 3 1 7 5 3 2\n5\n5 4 3 2 3\n", "5\n4\n1 2 3 4\n7\n4 3 3 8 4 5 2\n3\n1 1 1\n7\n1 3 1 0 5 3 2\n5\n5 4 3 2 3\n", "5\n4\n1 2 3 4\n7\n4 5 3 8 4 5 2\n3\n1 1 1\n7\n1 3 1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given an array a consisting of n integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from a to make it a good array. Recall t...
1407_A. Ahahahahahahahaha_31885
Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of array) in the way that alternating sum of the array will be equal 0 (i.e. a_1 - a_2 + a_3 - a_4 + ... = 0). In other words, Alexandra wants s...
##while True: ## N = int(input()) ## a = [i+1 for i in range(N)] #### a = [2, 7, 12, 3, 8] ## ## ans = 0 ## ## for i in a: ## ans ^= i ## ## print(a) ## ## x = int(input()) ## ## r = [] ## ## for i in range(len(a)): ## r.append(a[i]^x) ## ## print(r) ## ## res = 0 ## ## ...
{ "input": [ "4\n2\n1 0\n2\n0 0\n4\n0 1 1 1\n4\n1 1 0 0\n", "4\n2\n1 0\n2\n0 0\n4\n0 1 1 1\n4\n1 1 0 0\n", "4\n2\n1 0\n2\n0 0\n4\n0 1 1 0\n4\n1 1 0 0\n", "4\n2\n1 0\n2\n0 0\n4\n0 1 1 0\n4\n1 1 1 0\n", "4\n2\n1 1\n2\n0 0\n4\n0 1 1 1\n4\n1 1 0 0\n", "4\n2\n1 0\n2\n1 0\n4\n0 1 1 1\n4\n1 1 0 0\n",...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Alexandra has an even-length array a, consisting of 0s and 1s. The elements of the array are enumerated from 1 to n. She wants to remove at most n/2 elements (where n — length of arra...
1474_E. What Is It?_31892
Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should make p an identity permutation (make p_i = i for all i). Unfortunately, scientists can't control the robot. Thus the only way to make p ...
def main(): n=int(*input().split()) L=[x for x in range(n+1)];ans=[] def swp(x,y): L[x],L[y]=L[y],L[x] swp(1,n);ans.append((1,n)) for i in range(2,(n+1)//2+1): swp(i,n);ans.append((i,n)) if not n-i+1==i: swp(n-i+1,1);ans.append((n-i+1,1)) val=sum((i-j)*(i-j) for i,j in ans) print(val) for x in range(...
{ "input": [ "3\n2\n3\n3\n", "3\n2\n3\n3\n", "3\n3\n3\n3\n", "3\n2\n2\n3\n", "3\n3\n2\n3\n", "3\n2\n3\n2\n", "3\n2\n2\n2\n", "3\n3\n2\n2\n", "3\n3\n3\n2\n" ], "output": [ "\n1\n2 1\n1\n2 1\n5\n2 3 1\n2\n1 3\n3 2\n5\n2 3 1\n2\n1 3\n2 3", "1\n2 1\n1\n1 2\n5\n2 3 1\n2\n2 1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Lunar rover finally reached planet X. After landing, he met an obstacle, that contains permutation p of length n. Scientists found out, that to overcome an obstacle, the robot should ...
14_B. Young Photographer_31896
Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrack and got ready to take pictures. But the problem was that not all the runners passed him. The total amount of sportsmen, training at tha...
#***************14B - Young Photographer***************# #author - @Divyesh Chhabra from math import * import os import random import re import sys from itertools import * n,a = map(int,input().split()) sp = [] xp = [] yp = [] f = 1 while n != 0: x,y = map(int,input().split()) if x>y: x,y = y,x xp...
{ "input": [ "3 3\n0 7\n14 2\n4 6\n", "20 1\n35 8\n40 6\n49 5\n48 18\n46 16\n45 16\n44 10\n16 44\n8 46\n2 45\n38 3\n42 1\n13 35\n35 18\n12 33\n32 11\n31 3\n50 20\n47 6\n38 2\n", "50 118\n83 55\n101 33\n89 17\n97 56\n105 7\n65 12\n14 72\n57 89\n84 28\n96 22\n93 12\n17 102\n51 103\n18 100\n92 25\n50 103\n14...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Among other things, Bob is keen on photography. Especially he likes to take pictures of sportsmen. That was the reason why he placed himself in position x0 of a long straight racetrac...
156_A. Message_31901
Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the string s. For example, string "aba" has six substrings: "a", "b", "a", "ab", "ba", "aba". Dr. Moriarty plans to take string s and cut out som...
from sys import stdin, stdout first, second = stdin.readline().strip(), stdin.readline().strip() n, m = len(first), len(second) first = '#' * m + first + '#' * m ans = float('inf') for i in range(n + m): cnt = 0 for j in range(m): if first[i + j] != second[j]: cnt += 1 ans =...
{ "input": [ "abcdef\nklmnopq\n", "aaaaa\naaa\n", "abcabc\nbcd\n", "a\na\n", "bwhvaanyxupicwobeevcwewhcriwowfovnylalpuhxzqxtzyjrzlxcmejujvliomdfedgtaioauwrcluhfxtzu\nplinvtsvytepojsecnjisxlmqkfhgknitvuw\n", "ladfasxt\ncpvtd\n", "ibdjtvgaveujdyidqldrxgwhsammmfpgxwljkptmeyejdvudhctmqjazalyzm...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Dr. Moriarty is about to send a message to Sherlock Holmes. He has a string s. String p is called a substring of string s if you can read it starting from some position in the strin...
177_E2. Space Voyage_31905
The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an alien tourist is allowed to bring to the planet, and bi is the number of citizens on the planet. The Smart Beaver is going to bring som...
# by the authority of GOD author: manhar singh sachdev # import os,sys from io import BytesIO, IOBase def check(a,b,tar,x): ans = 0 for i in range(len(a)): ans += (a[i]*x)//b[i] if ans == tar: return 0 elif ans > tar: return 1 else: return -1 def main(): n,c ...
{ "input": [ "2 5\n1 5\n2 4\n", "1 1000000000\n1 1000000000\n", "8 97\n23 45\n91 20\n100 18\n11 82\n33 58\n11 99\n3 9\n75 55\n", "7 45\n1 1\n1 2\n1 4\n1 8\n1 16\n1 32\n1 64\n", "2 2\n1 2\n1 3\n", "55 100\n1 87\n2 84\n1 83\n3 88\n3 94\n1 82\n4 86\n4 96\n2 93\n1 98\n2 98\n4 93\n1 87\n1 81\n4 85\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: The Smart Beaver from ABBYY plans a space travel on an ultramodern spaceship. During the voyage he plans to visit n planets. For planet i ai is the maximum number of suitcases that an...
199_B. Special Olympics_31909
A renowned abstract artist Sasha, drawing inspiration from nowhere, decided to paint a picture entitled "Special Olympics". He justly thought that, if the regular Olympic games have five rings, then the Special ones will do with exactly two rings just fine. Let us remind you that a ring is a region located between two...
import os import sys from io import BytesIO, IOBase from collections import Counter 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...
{ "input": [ "50 50 35 45\n90 50 35 45\n", "60 60 45 55\n80 60 15 25\n", "60 60 45 55\n80 80 8 32\n", "70 92 20 40\n99 92 9 49\n", "0 73 20 40\n59 73 39 100\n", "39 90 20 40\n47 90 28 31\n", "-46 55 20 40\n-17 55 7 11\n", "31 40 37 76\n48 65 66 98\n", "-81 -55 20 40\n19 20 83 85\n"...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: A renowned abstract artist Sasha, drawing inspiration from nowhere, decided to paint a picture entitled "Special Olympics". He justly thought that, if the regular Olympic games have f...
222_C. Reducing Fractions_31912
To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first set gives the fraction numerator, the product of numbers from the second set gives the fraction denominator. However, it turned out that t...
from collections import defaultdict import bisect from itertools import accumulate import os import sys import math from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writabl...
{ "input": [ "4 3\n2 5 10 20\n100 1 3\n", "3 2\n100 5 2\n50 10\n", "2 3\n50 10\n100 5 2\n", "1 5\n99\n3 55 18 1 19\n", "5 3\n16 24 36 54 81\n4 6 9\n", "3 2\n100 5 2\n10 100\n", "5 5\n2 9 8 3 5\n5 7 8 1 1\n", "10 11\n7 43 39 13 25 23 33 40 5 2\n42 22 39 1 23 37 12 48 46 2 2\n", "1 1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: To confuse the opponents, the Galactic Empire represents fractions in an unusual format. The fractions are represented as two sets of integers. The product of numbers from the first s...
246_A. Buggy Sorting_31916
Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array of n integers a1, a2, ..., an in the non-decreasing order. The pseudocode of the program, written by Valera, is given below. The input of ...
def s(a): k = len(a) for i in range(k-1): for j in range(i,k-1): if a[j] > a[j+1]: a[j],a[j+1] = a[j+1],a[j] return a def main(): n = int(input()) if n <= 2: v = [-1] else: v = [int(i) for i in range(n,0,-1)] print(*v,sep = ' ') if __name__...
{ "input": [ "1\n", "2\n", "4\n", "26\n", "5\n", "7\n", "38\n", "6\n", "18\n", "30\n", "8\n", "9\n", "34\n", "50\n", "3\n", "12\n", "46\n", "22\n", "32\n", "17\n", "14\n", "25\n", "42\n", "11\n", "10\n", "20\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Little boy Valera studies an algorithm of sorting an integer array. After studying the theory, he went on to the practical tasks. As a result, he wrote a program that sorts an array o...
271_B. Prime Matrix_31920
You've got an n × m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times. You are really curious about prime numbers. Let us remind you that a...
# coding: utf-8 matrix_params = input() params = matrix_params.split(" ") rows = int(params[0]) cols = int(params[1]) initial_matrix = [] count_r = [] count_c = [] curr_row = [] def is_prime(n): if n <= 3: return n > 1 if n % 2 == 0 or n % 3 == 0: return False i = 5 while i ** 2 <= n: if n % i == ...
{ "input": [ "3 3\n1 2 3\n5 6 1\n4 4 1\n", "2 2\n1 3\n4 2\n", "2 3\n4 8 8\n9 2 9\n", "1 1\n99992\n", "1 5\n14 14 8 14 14\n", "3 3\n1 7 6\n4 6 2\n3 3 3\n", "1 1\n14\n", "6 5\n8 8 8 8 20\n13 8 16 13 9\n11 5 3 14 18\n13 8 6 18 6\n6 8 9 14 7\n2 14 14 9 3\n", "8 5\n11 29 11 1 27\n24 16 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You've got an n × m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase i...
318_B. Strings of Power_31927
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
from functools import reduce from operator import * from math import * from sys import * from string import * from collections import * setrecursionlimit(10**7) dX= [-1, 1, 0, 0,-1, 1,-1, 1] dY= [ 0, 0,-1, 1, 1,-1,-1, 1] RI=lambda: list(map(int,input().split())) RS=lambda: input().rstrip().split() #####################...
{ "input": [ "heavymetalisheavymetal\n", "trueheavymetalissotruewellitisalsosoheavythatyoucanalmostfeeltheweightofmetalonyou\n", "heavymetalismetal\n", "fpgzbvhheavymheheavyzmheavyavyebknkhheavyhsbqmmetheavyalmetalheavyyomtua\n", "hg\n", "metametaheavyetalalmetalavylkeoheavyhemetaleavycdk\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string po...
342_B. Xenia and Spies_31931
Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right. Spy s has an important note. He has to pass the note to spy f. Xenia interrogates the spies in several steps. During one step the spy keeping the important note can pass the ...
R = lambda: map(int, input().split()) n, m, s, f = R() if s < f: d = 1 c = 'R' else: d = -1 c = 'L' res = "" i = 1 j = s t, l, r = R() k = 1 while j != f: if i > t and k < m: t, l, r = R() k += 1 if i == t and (l <= j <= r or l <= j + d <= r): res += 'X' else: res...
{ "input": [ "3 5 1 3\n1 1 2\n2 2 3\n3 3 3\n4 1 1\n10 1 3\n", "20 20 17 20\n1 16 20\n2 12 13\n3 14 16\n4 13 15\n5 3 15\n6 2 11\n7 18 18\n8 5 15\n9 6 12\n10 19 19\n11 9 11\n12 14 17\n13 19 19\n14 12 20\n15 1 1\n16 11 17\n17 13 14\n18 5 17\n19 2 10\n20 19 20\n", "7 5 7 6\n1 4 5\n2 7 7\n3 6 6\n4 3 4\n5 1 3\n...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Xenia the vigorous detective faced n (n ≥ 2) foreign spies lined up in a row. We'll consider the spies numbered from 1 to n from left to right. Spy s has an important note. He has t...
389_C. Fox and Box Accumulation_31937
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For exampl...
#------------------------template--------------------------# import os import sys from math import * from collections import * from fractions import * from bisect import * from heapq import* from io import BytesIO, IOBase def vsInput(): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') BUF...
{ "input": [ "3\n0 0 10\n", "4\n0 0 0 0\n", "9\n0 1 0 2 0 1 1 2 10\n", "5\n0 1 2 3 4\n", "5\n4 1 1 1 1\n", "100\n3 4 4 4 3 3 3 3 3 4 4 4 3 3 3 4 3 4 4 4 3 4 3 4 3 4 3 3 4 4 3 4 4 3 4 4 4 4 4 3 4 3 3 3 4 3 3 4 3 4 3 4 3 3 4 4 4 3 3 3 3 3 4 4 3 4 4 3 4 3 3 3 4 4 3 3 3 3 3 4 3 4 4 3 3 4 3 4 3 4 4...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the stre...
409_F. 000001_31941
Input The input contains a single integer a (1 ≤ a ≤ 64). Output Output a single integer. Examples Input 2 Output 1 Input 4 Output 2 Input 27 Output 5 Input 42 Output 6
print([0,1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51,1,2,1,14,1,2,2,14,1,6,1,4,2,2,1,52,2,5,1,5,1,15,2,13,2,2,1,13,1,2,4,267,1,4,1,5,1,4,1,50,1,2,3,4,1,6,1,52,15,2,1,15,1][int(input())])
{ "input": [ "27\n", "4\n", "2\n", "42\n", "46\n", "51\n", "61\n", "11\n", "29\n", "32\n", "44\n", "19\n", "41\n", "18\n", "48\n", "12\n", "6\n", "40\n", "15\n", "59\n", "23\n", "63\n", "30\n", "17\n", "43\n", "54\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Input The input contains a single integer a (1 ≤ a ≤ 64). Output Output a single integer. Examples Input 2 Output 1 Input 4 Output 2 Input 27 Output 5 Input ...
437_A. The Child and Homework_31945
Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a description, and the child should find out the only one that is correct. Fortunately the child knows how to solve such complicated test. The chi...
a = input()[2:] b = input()[2:] c = input()[2:] d = input()[2:] zc = 0 z = -100 if (len(a)*2 <= len(b) and len(a)*2 <= len(c) and len(a)*2 <= len(d)) or (len(a) >= len(b)*2 and len(a) >= len(c)*2 and len(a) >= len(d)*2): zc += 1 z = 'A' if (len(b)*2 <= len(a) and len(b)*2 <= len(c) and len(b)*2 <= len(d)) or...
{ "input": [ "A.VFleaKing_is_the_author_of_this_problem\nB.Picks_is_the_author_of_this_problem\nC.Picking_is_the_author_of_this_problem\nD.Ftiasch_is_cute\n", "A.ab\nB.abcde\nC.ab\nD.abc\n", "A.c\nB.cc\nC.c\nD.c\n", "A.____JGWsfiU\nB.S_LMq__MpE_oFBs_P\nC.U_Rph_VHpUr____X_jWXbk__ElJTu_Z_wlBpKLTD\nD.p_y...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Once upon a time a child got a test consisting of multiple-choice questions as homework. A multiple-choice question consists of four choices: A, B, C and D. Each choice has a descript...
45_C. Dancing Lessons_31949
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
from heapq import heapify,heappush,heappop n = int(input()) sex = input() a = [int(i) for i in input().split()] cp = [] r = [] b = sex.count('B') N = min(n-b,b) for i in range(1,len(a)): if sex[i] != sex[i-1]: cp.append((abs(a[i]-a[i-1]),i-1,i)) heapify(cp) prev = [i for i in range(-1,len(sex))] nxt = [i f...
{ "input": [ "4\nBGBG\n4 2 4 3\n", "4\nBGBB\n1 1 2 3\n", "4\nBBGG\n4 6 1 5\n", "2\nBB\n2518190 6313112\n", "10\nGGGGBGGGBB\n2853026 3310290 2843753 8559868 1089557 6446421 8976433 3755381 2966918 3322276\n", "1\nB\n490297\n", "10\nBGGBBGBGBG\n9892816 3514007 5425956 5241945 9171176 3351177...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at...
482_B. Interesting Array_31952
We'll call an array of n non-negative integers a[1], a[2], ..., a[n] interesting, if it meets m constraints. The i-th of the m constraints consists of three integers li, ri, qi (1 ≤ li ≤ ri ≤ n) meaning that value <image> should be equal to qi. Your task is to find any interesting array of n elements or state that su...
import sys input = sys.stdin.readline n, m = map(int, input().split()) a = [] for _ in range(m): l, r, q = map(int, input().split()) l -= 1 r -= 1 a.append((l, r, q)) res = [0] * n bad = False for i in range(30): events = [0] * (n + 1) for l, r, q in a: if q & (1 << i): eve...
{ "input": [ "3 1\n1 3 3\n", "3 2\n1 3 3\n1 3 2\n", "1 2\n1 1 10\n1 1 5\n", "3 2\n1 2 536870912\n2 3 536870911\n", "1 1\n1 1 10\n", "1 2\n1 1 1\n1 1 3\n", "3 2\n1 2 536870912\n2 3 942984520\n", "2 2\n1 1 1\n1 1 3\n", "6 1\n1 3 3\n", "6 1\n1 6 3\n", "6 1\n1 6 6\n", "6 1\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: We'll call an array of n non-negative integers a[1], a[2], ..., a[n] interesting, if it meets m constraints. The i-th of the m constraints consists of three integers li, ri, qi (1 ≤ l...
506_B. Mr. Kitayuta's Technology_31956
Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finally become possible to construct teleportation pipes between two cities. A teleportation pipe will connect two cities unidirectionally, tha...
def main(): n, m = map(int, input().split()) n += 1 cluster, dest, avail, ab = list(range(n)), [0] * n, [True] * n, [[] for _ in range(n)] def getroot(x): while x != cluster[x]: x = cluster[x] return x def setroot(x, r): if r < x != cluster[x]: setro...
{ "input": [ "4 6\n1 2\n1 4\n2 3\n2 4\n3 2\n3 4\n", "4 5\n1 2\n1 3\n1 4\n2 3\n2 4\n", "10 4\n8 4\n9 8\n2 8\n8 1\n", "9 10\n6 4\n7 5\n9 3\n7 6\n4 8\n4 2\n9 8\n1 3\n5 1\n4 7\n", "10 10\n10 6\n9 4\n7 8\n1 5\n3 10\n2 1\n4 9\n5 2\n10 3\n6 3\n", "8 12\n6 1\n7 5\n2 5\n4 1\n6 3\n4 3\n5 7\n1 3\n5 2\n2 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Shuseki Kingdom is the world's leading nation for innovation and technology. There are n cities in the kingdom, numbered from 1 to n. Thanks to Mr. Kitayuta's research, it has finall...
52_A. 123-sequence_31960
There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers in the sequence are equal to each other. Input The first line contains an integer n (1 ≤ n ≤ 106). The second line contains a sequence o...
from collections import deque from math import ceil,floor,sqrt,gcd def ii(): return int(input()) def mi(): return map(int,input().split()) def li(): return list(mi()) def si():return input() n=ii() a=li() m={} for i in a: if i not in m: m[i]=1 else: m[i]+=1 b=[] for i in m.keys(): b.append(m...
{ "input": [ "9\n1 3 2 2 2 1 1 2 3\n", "1\n1\n", "2\n3 2\n", "15\n3 2 1 1 1 1 3 2 2 3 3 1 2 3 2\n", "6\n3 3 2 2 1 3\n", "12\n3 1 3 1 2 1 3 2 2 1 2 1\n", "1\n3\n", "2\n2 1\n", "18\n2 3 2 1 2 3 2 1 2 3 3 3 1 2 3 3 3 2\n", "30\n2 1 3 2 3 2 2 2 2 3 2 2 3 2 1 1 3 1 3 2 1 2 3 1 1 3 3...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There is a given sequence of integers a1, a2, ..., an, where every number is from 1 to 3 inclusively. You have to replace the minimum number of numbers in it so that all the numbers i...
555_C. Case of Chocolate_31964
Andrewid the Android is a galaxy-known detective. Now he does not investigate any case and is eating chocolate out of boredom. A bar of chocolate can be presented as an n × n table, where each cell represents one piece of chocolate. The columns of the table are numbered from 1 to n from left to right and the rows are ...
import sys from bisect import bisect def input(): return sys.stdin.readline().strip() def solve(): n, q = map(int, input().split()) was = set() Q = [None]*q all = [0]*(2*q) for i in range(q): x, y, t = input().split() x, y = int(x), int(y) Q[i] = (x, y, t) all[2*i] = x all[2*i+1] = y all.sort() sz =...
{ "input": [ "6 5\n3 4 U\n6 1 L\n2 5 L\n1 6 U\n4 3 U\n", "10 6\n2 9 U\n10 1 U\n1 10 U\n8 3 L\n10 1 L\n6 5 U\n", "15 7\n8 8 U\n6 10 L\n9 7 L\n3 13 L\n15 1 L\n13 3 U\n1 15 L\n", "1000000000 1\n117117117 882882884 U\n", "10 10\n5 6 U\n4 7 U\n8 3 L\n8 3 L\n1 10 U\n9 2 U\n10 1 L\n10 1 L\n8 3 U\n8 3 U\n...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Andrewid the Android is a galaxy-known detective. Now he does not investigate any case and is eating chocolate out of boredom. A bar of chocolate can be presented as an n × n table, ...
581_B. Luxurious Houses_31968
The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses from left to right, starting with one. A house is considered to be luxurious if the number of floors in it is strictly greater than in all...
n = int(input()) hs = list(map(int, input().split())) maxx = 0 ans = [] for h in reversed(hs): if h > maxx: ans.append(0) else: ans.append(maxx-h+1) maxx = max(maxx, h) print(' '.join(map(str, reversed(ans))))
{ "input": [ "5\n1 2 3 1 2\n", "4\n3 2 1 4\n", "100\n1 8 3 8 10 8 5 3 10 3 5 8 4 5 5 5 10 3 6 6 6 6 6 7 2 7 2 4 7 8 3 8 7 2 5 6 1 5 5 7 9 7 6 9 1 8 1 3 6 5 1 3 6 9 5 6 8 4 8 6 10 9 2 9 3 8 7 5 2 10 2 10 3 6 5 5 3 5 10 2 3 7 10 8 8 4 3 4 9 6 10 7 6 6 6 4 9 9 8 9\n", "1\n100\n", "1\n2\n", "2\n2 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: The capital of Berland has n multifloor buildings. The architect who built up the capital was very creative, so all the houses were built in one row. Let's enumerate all the houses f...
603_A. Alternative Thinking_31972
Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string represents Kevin's score on one of the n questions of the olympiad—'1' for a correctly identified cow and '0' otherwise. However, all is not...
input() a = input() s = [] for c in a: if not s or s[-1][0] != c: s.append([c, 1]) else: s[-1][1] += 1 s2 = sorted(s, key=lambda x: x[1]) delta = 0 if s2[-1][1] >= 3 or len(s2) > 1 and s2[-2][1] >= 2: delta = 2 elif s2[-1][1] >= 2: delta = 1 print(len(s) + delta)
{ "input": [ "2\n01\n", "8\n10000011\n", "5\n11110\n", "85\n1010101010101010101010101010010101010101010101101010101010101010101011010101010101010\n", "11\n00000000000\n", "89\n01010101010101010101010101010101010101010101010101010101101010101010101010100101010101010\n", "4\n0110\n", "4\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Kevin has just recevied his disappointing results on the USA Identification of Cows Olympiad (USAICO) in the form of a binary string of length n. Each character of Kevin's string repr...
625_D. Finals in arithmetic_31976
Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's denote a flip operation of an integer as follows: number is considered...
def digits(n): rd = [] while n: n, d = divmod(n, 10) rd.append(d) return list(reversed(rd)) def _ifs(dn, i, j, ci, cj, al, ar): while i < j: di = dn[i] + 10*ci dj = dn[j] - cj for (ci, cj) in ((0, 0), (0, 1), (1, 0), (1, 1)): d = di - ci ...
{ "input": [ "5\n", "11\n", "4\n", "33\n", "110401\n", "1738464936\n", "9009890098\n", "189108\n", "9012332098\n", "3031371285404035821731303\n", "643303246\n", "230021\n", "970068\n", "10000000000\n", "891297\n", "4602332064\n", "1094093901\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and...
699_A. Launch of Collider_31981
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the dista...
import sys def main(arr): curr = None m = float("inf") for d, pos in arr: if d == 'L': if curr is not None: m = min(m, pos - curr) elif d == 'R': curr = pos print(m // 2 if m != float("inf") else -1) if __name__ == "__main__": arr = [] fo...
{ "input": [ "4\nRLRL\n2 4 6 10\n", "3\nLLR\n40 50 60\n", "2\nRL\n0 2\n", "2\nRL\n200 400400\n", "24\nLLRLRRLLRLRRRRLLRRLRLRRL\n100 360 864 1078 1360 1384 1438 2320 2618 3074 3874 3916 3964 5178 5578 6278 6630 6992 8648 8738 8922 8930 9276 9720\n", "2\nRL\n2 200000000\n", "2\nRL\n0 199998\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a str...
71_C. Round Table Knights_31985
There are n knights sitting at the Round Table at an equal distance from each other. Each of them is either in a good or in a bad mood. Merlin, the wizard predicted to King Arthur that the next month will turn out to be particularly fortunate if the regular polygon can be found. On all vertices of the polygon knights ...
def gen_prime(n): prime = [] prime.append(2) prime.append(3) prime.append(4) for i in range(5, n+1): div = False for j in prime: if not i%j: div = True break if not div: prime.append(i) return prime n = int(input()) prime = gen_prime(n) prime = prime[1:] prime.append(n) a = [int(i) for i i...
{ "input": [ "6\n1 0 0 1 0 1\n", "6\n1 0 1 1 1 0\n", "3\n1 1 1\n", "6\n0 1 0 0 0 0\n", "7\n1 1 1 1 1 1 1\n", "10\n1 0 1 1 1 0 1 0 1 0\n", "7\n0 0 1 0 0 0 1\n", "30\n1 0 0 0 1 0 1 1 1 1 0 0 1 0 0 0 1 0 1 0 0 0 0 1 0 0 1 0 0 0\n", "113\n1 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: There are n knights sitting at the Round Table at an equal distance from each other. Each of them is either in a good or in a bad mood. Merlin, the wizard predicted to King Arthur th...
764_D. Timofey and rectangles_31991
One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rectangles have odd length. Rectangles cannot intersect, but they can touch each other. Help Timofey to color his rectangles in 4 different...
'''plan noticed that if both upperle ''' from sys import stdin, stdout # n = int(stdin.readline().rstrip()) # n = int(input()) all_lines = stdin.read().split('\n') stdout.write('YES\n') for line in all_lines[1:-1]: x1, y1, x2, y2 = (int(x) % 2 for x in line.split()) num = 2 * x2 + y2 + 1 # stdout.write...
{ "input": [ "8\n0 0 5 3\n2 -1 5 0\n-3 -4 2 -1\n-1 -1 2 0\n-3 0 0 5\n5 2 10 3\n7 -3 10 2\n4 -2 7 -1\n", "1\n0 0 1 1\n", "3\n0 0 1 3\n1 0 4 1\n1 1 2 2\n", "28\n0 0 3 1\n0 1 1 6\n0 6 1 9\n0 9 1 12\n0 12 1 13\n0 13 3 14\n1 1 2 4\n1 4 2 7\n1 7 2 10\n1 10 2 13\n2 1 3 2\n2 2 3 5\n2 5 3 8\n2 8 3 13\n3 0 6 1\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: One of Timofey's birthday presents is a colourbook in a shape of an infinite plane. On the plane n rectangles with sides parallel to coordinate axes are situated. All sides of the rec...
788_A. Functions again_31995
Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as...
n=int(input()) l=list(map(int,input().split())) ma=0 p1=0 p2=0 for i in range(n-1) : if (i+1)%2!=0 : p1=p1+abs(l[i]-l[i+1]) p2=p2-abs(l[i]-l[i+1]) if p2<0 : p2=0 ma=max(p1,ma) else : p2=p2+abs(l[i]-l[i+1]) p1=p1-abs(l[i]-l[i+1]) if p1<0 : ...
{ "input": [ "5\n1 4 2 3 1\n", "4\n1 5 4 7\n", "4\n1000000000 0 0 -1000000000\n", "10\n1000000000 -1000000000 -1000000000 1000000000 1000000000 -1000000000 -1000000000 1000000000 1000000000 -1000000000\n", "5\n0 10 20 30 40\n", "9\n1000000000 0 0 1000000000 1000000000 0 0 1000000000 1000000000...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situat...
809_C. Find a car_31999
After a wonderful evening in the restaurant the time to go home came. Leha as a true gentlemen suggested Noora to give her a lift. Certainly the girl agreed with pleasure. Suddenly one problem appeared: Leha cannot find his car on a huge parking near the restaurant. So he decided to turn to the watchman for help. Form...
mod = 1000000007 def sum(x,y,k,add) : if k<add:return 0 up=x+add if up>k:up=k add=add+1 return y*(((add+up)*(up-add+1)//2)%mod)%mod def solve(x,y,k,add=0) : if x==0 or y==0:return 0 if x>y:x,y=y,x pw = 1 while (pw<<1)<=y:pw<<=1 if pw<=x:return (sum(pw,pw,k,add)+sum(pw,x+y-pw-pw,k...
{ "input": [ "4\n1 1 1 1 1\n3 2 5 4 5\n1 1 5 5 10000\n1 4 2 5 2\n", "10\n1 1 1000000000 1000000000 1477070720\n1 1 1000000000 1000000000 1378704784\n1 1 1000000000 1000000000 782520772\n1 1 1000000000 1000000000 1377211731\n1 1 1000000000 1000000000 623332716\n1 1 1000000000 1000000000 497630560\n1 1 10000000...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: After a wonderful evening in the restaurant the time to go home came. Leha as a true gentlemen suggested Noora to give her a lift. Certainly the girl agreed with pleasure. Suddenly on...
834_A. The Useless Toy_32003
<image> Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays – caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption. Spinners in Sweetland have the form of V-shaped pieces of carame...
a, b = input().split() t = int(input()) d = dict() d["^"] = 0 d[">"] = 1 d["v"] = 2 d["<"] = 3 a, b = d[a], d[b] t = t % 4 if t == 2 or t == 0: print("undefined") else: if t == 1: if (b-1) % 4 == a: print("CW".lower()) else: print("CCW".lower()) elif t == 3: ...
{ "input": [ "^ v\n6\n", "^ &gt;\n1\n", "&lt; ^\n3\n", "> >\n0\n", "> >\n1000000000\n", "^ <\n467441155\n", "> >\n12\n", "^ >\n999999999\n", "v >\n3\n", "v <\n3\n", "^ >\n861895563\n", "^ <\n821690113\n", "^ <\n3\n", "^ <\n1\n", "^ <\n7\n", "< v\n3\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: <image> Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays – caramel spinner! Wanting...
854_D. Jury Meeting_32007
Country of Metropolia is holding Olympiad of Metrpolises soon. It mean that all jury members of the olympiad should meet together in Metropolis (the capital of the country) for the problem preparation process. There are n + 1 cities consecutively numbered from 0 to n. City 0 is Metropolis that is the meeting point for...
R=lambda :map(int,input().split()) n,m,k=R() F,T=[],[] ans=int(1e12) for i in range(m): d,f,t,c=R() if f:F.append((d,f,c)) else:T.append((-d,t,c)) for p in [F,T]: cost=[ans]*(n+1) s=n*ans q=[] p.sort() for d,t,c in p: #print(p) if c<cost[t]: #print(c,cost[t]) ...
{ "input": [ "2 4 5\n1 2 0 5000\n2 1 0 4500\n2 1 0 3000\n8 0 1 6000\n", "2 6 5\n1 1 0 5000\n3 2 0 5500\n2 2 0 6000\n15 0 2 9000\n9 0 1 7000\n8 0 2 6500\n", "5 10 1\n132 0 4 7\n803 0 2 8\n280 3 0 5\n175 4 0 6\n196 1 0 7\n801 0 4 6\n320 0 5 7\n221 0 4 6\n446 4 0 8\n699 0 5 9\n", "1 2 1\n5 0 1 91\n1 1 0 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Country of Metropolia is holding Olympiad of Metrpolises soon. It mean that all jury members of the olympiad should meet together in Metropolis (the capital of the country) for the pr...
879_B. Table Tennis_32011
n people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with the next person from the line, and so on. They play until someone wins k games in a row. This player becomes the winner. For each of the p...
n,k=[int(i) for i in input().split()] a=[int(i) for i in input().split()] d=a[0] t=0 h=0 for i in range(1,n): if d>a[i]: t+=1 if t>=k: print(d) h=1 break else: t=1 d=a[i] if h==0: print(max(a))
{ "input": [ "2 10000000000\n2 1\n", "6 2\n6 5 3 1 2 4\n", "2 2\n1 2\n", "4 2\n3 1 2 4\n", "5 2\n1 4 3 5 2\n", "2 1000000000000\n1 2\n", "5 4294967298\n3 2 1 4 5\n", "10 2\n1 2 3 4 5 6 7 8 9 10\n", "3 4294967297\n2 1 3\n", "4 2\n1 3 2 4\n", "5 2\n1 3 2 4 5\n", "5 2\n2 1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: n people are standing in a line to play table tennis. At first, the first two players in the line play a game. Then the loser goes to the end of the line, and the winner plays with th...
902_D. GCD of Polynomials_32015
Suppose you have two polynomials <image> and <image>. Then polynomial <image> can be uniquely represented in the following way: <image> This can be done using [long division](https://en.wikipedia.org/wiki/Polynomial_long_division). Here, <image> denotes the degree of polynomial P(x). <image> is called the remainder o...
class polynomial: def __init__(self, data): self.data = data def __lshift__(self, x): return polynomial([0] * x + self.data) def __len__(self): return len(self.data) def __sub__(self, other): newData = [y - x for y, x in zip(self.data, other.data + [0] * 10...
{ "input": [ "2\n", "1\n", "101\n", "14\n", "102\n", "39\n", "51\n", "58\n", "122\n", "126\n", "11\n", "96\n", "117\n", "131\n", "24\n", "109\n", "21\n", "116\n", "60\n", "36\n", "4\n", "43\n", "46\n", "61\n", "130\n",...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Suppose you have two polynomials <image> and <image>. Then polynomial <image> can be uniquely represented in the following way: <image> This can be done using [long division](https:...
954_A. Diagonal Walking_32020
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible. In the given sequence moving up is described by character U and moving right is described by character R. Mikhail can replace an...
n = int(input()) s = str(input()) l = len(s) prev = ''; for i in s: if prev=='': prev = i continue if (i=='U' and prev =='R') or (i=='R' and prev =='U'): l=l-1 prev = '' else: prev = i print(l)
{ "input": [ "17\nUUURRRRRUUURURUUU\n", "5\nRUURU\n", "1\nR\n", "3\nRUR\n", "2\nUR\n", "100\nRRURRUUUURURRRURRRRURRRRRRURRUURRRUUURUURURRURUURUURRUURUURRURURUUUUURUUUUUURRUUURRRURRURRRUURRUUUUR\n", "23\nUUUUUUUUUUUUUUUUUUUUUUU\n", "100\nUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as po...
p02543 ACL Contest 1 - Keep Distances_32036
There are N points on a number line, i-th of which is placed on coordinate X_i. These points are numbered in the increasing order of coordinates. In other words, for all i (1 \leq i \leq N-1), X_i < X_{i+1} holds. In addition to that, an integer K is given. Process Q queries. In the i-th query, two integers L_i and R...
import sys readline = sys.stdin.buffer.readline n,k = map(int,readline().split()) vs = list(map(int,readline().split())) L=18 xid=[0]*(n*L) xsum=[0]*(n*L) yid=[0]*(n*L) ysum=[0]*(n*L) j=n for i in reversed(range(n)): while i<j and vs[i]+k<=vs[j-1]: j-=1 xid[i*L+0]=j xsum[i*L+0]=j for lv in range(1,L): a=xid[...
{ "input": [ "5 3\n1 2 4 7 8\n2\n1 5\n1 2", "15 220492538\n4452279 12864090 23146757 31318558 133073771 141315707 263239555 350278176 401243954 418305779 450172439 560311491 625900495 626194585 891960194\n5\n6 14\n1 8\n1 13\n7 12\n4 12", "5 3\n1 2 4 4 8\n2\n1 5\n1 2", "5 3\n1 4 4 4 8\n2\n1 5\n1 2", ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are N points on a number line, i-th of which is placed on coordinate X_i. These points are numbered in the increasing order of coordinates. In other words, for all i (1 \leq i \...
p02674 AtCoder Grand Contest 044 - Name-Preserving Clubs_32039
There are N people (with different names) and K clubs. For each club you know the list of members (so you have K unordered lists). Each person can be a member of many clubs (and also 0 clubs) and two different clubs might have exactly the same members. The value of the number K is the minimum possible such that the fol...
# # File : F.py # Author : Kazune Takahashi # Created : 5/24/2020, 3:07:25 AM # Powered by Visual Studio Code # dic = { 1: 1, 2: 1, 3: 1, 4: 7, 5: 4, 6: 1, 7: 336, 8: 384, 9: 334, 10: 220, 11: 108, 12: 36, 13: 6, 27: 976, 28: 108, 29: 4, 60: 220, ...
{ "input": [ "123456789123456789", "2", "26", "4", "3", "13", "119107271329329921", "27", "5", "9", "7", "8", "11", "6", "10", "12", "20", "33213408621377322", "45", "26939847318901699", "12809773843701327", "15368855316243065", ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are N people (with different names) and K clubs. For each club you know the list of members (so you have K unordered lists). Each person can be a member of many clubs (and also ...
p02802 AtCoder Beginner Contest 151 - Welcome to AtCoder_32042
Takahashi participated in a contest on AtCoder. The contest had N problems. Takahashi made M submissions during the contest. The i-th submission was made for the p_i-th problem and received the verdict S_i (`AC` or `WA`). The number of Takahashi's correct answers is the number of problems on which he received an `A...
N,M=map(int,input().split()) PS=[input().split() for i in range(M)] wa,ac=[0]*N,[0]*N for p,s in PS: p=int(p)-1 if s=='WA' and ac[p]==0: wa[p]+=1 elif s=='AC': ac[p]=1 for i in range(N): if ac[i]==0: wa[i]=0 print(sum(ac),sum(wa))
{ "input": [ "6 0", "2 5\n1 WA\n1 AC\n2 WA\n2 AC\n2 WA", "100000 3\n7777 AC\n7777 AC\n7777 AC", "100000 3\n7777 AC\n7777 AC\n7777 CA", "100000 3\n12676 AC\n7777 AC\n7777 CA", "1 0", "4 5\n1 WA\n1 AC\n2 WA\n2 AC\n2 WA", "4 5\n1 WA\n1 AC\n0 WA\n2 AC\n2 WA", "100000 3\n6234 AC\n7777 A...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Takahashi participated in a contest on AtCoder. The contest had N problems. Takahashi made M submissions during the contest. The i-th submission was made for the p_i-th problem and...
p02938 AtCoder Beginner Contest 138 - Coincidence_32046
Given are integers L and R. Find the number, modulo 10^9 + 7, of pairs of integers (x, y) (L \leq x \leq y \leq R) such that the remainder when y is divided by x is equal to y \mbox{ XOR } x. What is \mbox{ XOR }? The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows: * When A \mbox{ XOR } B is writte...
def i1(): return int(input()) def i2(): return [int(i) for i in input().split()] [l,r]=i2() z=10**9+7 dp=[[[[0 for l in range(2)]for k in range(2)]for j in range(2)]for i in range(61)] dp[60][0][0][0]=1 for n in range(60)[::-1]: lb=l>>n&1 rb=r>>n&1 for x in range(2): for y in range(2): for i in range(2): ...
{ "input": [ "2 3", "10 100", "1 1000000000000000000", "3 3", "10 110", "1 1000000100000000000", "3 0", "10 111", "4 110", "4 100", "6 110", "6 111", "5 111", "9 111", "16 111", "1 011", "3 100", "6 100", "2 5", "15 100", "1 100000000...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Given are integers L and R. Find the number, modulo 10^9 + 7, of pairs of integers (x, y) (L \leq x \leq y \leq R) such that the remainder when y is divided by x is equal to y \mbox{ ...
p03075 AtCoder Beginner Contest 123 - Five Antennas_32050
In AtCoder city, there are five antennas standing in a straight line. They are called Antenna A, B, C, D and E from west to east, and their coordinates are a, b, c, d and e, respectively. Two antennas can communicate directly if the distance between them is k or less, and they cannot if the distance is greater than k. ...
a,*_,e,k=[int(input())for x in' '*6];print([':(','Yay!'][e-a<=k])
{ "input": [ "1\n2\n4\n8\n9\n15", "15\n18\n26\n35\n36\n18", "1\n0\n4\n8\n9\n15", "15\n18\n26\n35\n36\n2", "1\n0\n8\n8\n9\n15", "15\n18\n26\n35\n34\n2", "1\n0\n5\n8\n9\n15", "15\n18\n13\n35\n34\n2", "1\n0\n5\n8\n4\n15", "15\n5\n13\n35\n34\n2", "1\n0\n5\n8\n8\n15", "15\n5...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: In AtCoder city, there are five antennas standing in a straight line. They are called Antenna A, B, C, D and E from west to east, and their coordinates are a, b, c, d and e, respectiv...
p03217 Dwango Programming Contest V - Square Rotation_32053
Niwango-kun, an employee of Dwango Co., Ltd., likes Niconico TV-chan, so he collected a lot of soft toys of her and spread them on the floor. Niwango-kun has N black rare soft toys of Niconico TV-chan and they are spread together with ordinary ones. He wanted these black rare soft toys to be close together, so he deci...
n,d = map(int,input().split()) num = [[0]*d for i in range(d)] a = 0 for i in range(n): x,y = map(int,input().split()) x %=d y%=d num[x][y] += 1 a = max(a,num[x][y]) x=1 while x*x<a: x += 1 r = (x-1)*d a = x-1 dai = d-1 syo = 0 anum = [[[0]*d for i in range(d)]for i in range(3)] rui = [[[0]*(2*d+1) for i in...
{ "input": [ "19 2\n1 3\n2 3\n0 1\n1 1\n2 1\n3 1\n4 4\n5 4\n6 4\n7 4\n8 4\n8 3\n8 2\n8 1\n8 0\n7 0\n6 0\n5 0\n4 0", "3 1\n0 0\n1 0\n2 0", "8 3\n0 0\n0 3\n3 0\n3 3\n2 2\n2 5\n5 2\n5 5", "19 2\n1 3\n2 3\n0 1\n1 1\n2 1\n3 1\n4 4\n5 4\n6 4\n7 4\n8 4\n8 1\n8 2\n8 1\n8 0\n7 0\n6 0\n5 0\n4 0", "3 2\n0 0\...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Niwango-kun, an employee of Dwango Co., Ltd., likes Niconico TV-chan, so he collected a lot of soft toys of her and spread them on the floor. Niwango-kun has N black rare soft toys o...
p03366 AtCoder Grand Contest 023 - Go Home_32057
There are N apartments along a number line, numbered 1 through N. Apartment i is located at coordinate X_i. Also, the office of AtCoder Inc. is located at coordinate S. Every employee of AtCoder lives in one of the N apartments. There are P_i employees who are living in Apartment i. All employees of AtCoder are now le...
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**15 mod = 10**9+7 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF()...
{ "input": [ "15 409904902\n94198000 15017\n117995501 7656764\n275583856 313263626\n284496300 356635175\n324233841 607\n360631781 148\n472103717 5224\n497641071 34695\n522945827 816241\n554305668 32\n623788284 22832\n667409501 124410641\n876731548 12078\n904557302 291749534\n918215789 5", "3 2\n1 3\n3 4\n4 2"...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are N apartments along a number line, numbered 1 through N. Apartment i is located at coordinate X_i. Also, the office of AtCoder Inc. is located at coordinate S. Every employee...
p03526 CODE FESTIVAL 2017 Final - Zabuton_32061
In the final of CODE FESTIVAL in some year, there are N participants. The height and power of Participant i is H_i and P_i, respectively. Ringo is hosting a game of stacking zabuton (cushions). The participants will line up in a row in some order, and they will in turn try to add zabuton to the stack of zabuton. Init...
N = int(input()) men = [] for _ in range(N): H,P = map(int,input().split()) men.append((H,P,H+P)) men.sort(key=lambda x: x[2]) maxH = max(men)[0] inf = maxH+1 #dp[i][j] -> i人目までみたとき、j人が座布団を積む場合の最小枚数 dp = [[-1]*(N+1) for _ in range(N+1)] dp[0][0] = 0 for i in range(1,N+1): h,p,a = men[i-1] for j in rang...
{ "input": [ "3\n2 4\n3 1\n4 1", "10\n1 3\n8 4\n8 3\n9 1\n6 4\n2 3\n4 2\n9 2\n8 3\n0 1", "3\n0 2\n1 3\n3 4", "3\n2 4\n3 1\n4 2", "10\n1 3\n8 4\n8 3\n10 1\n6 4\n2 3\n4 2\n9 2\n8 3\n0 1", "3\n0 2\n1 0\n3 4", "10\n1 3\n8 4\n8 3\n10 1\n12 4\n2 3\n4 2\n9 2\n8 3\n0 1", "10\n1 3\n0 4\n15 3\n1...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: In the final of CODE FESTIVAL in some year, there are N participants. The height and power of Participant i is H_i and P_i, respectively. Ringo is hosting a game of stacking zabuton ...
p03689 AtCoder Grand Contest 016 - +/- Rectangle_32065
You are given four integers: H, W, h and w (1 ≤ h ≤ H, 1 ≤ w ≤ W). Determine whether there exists a matrix such that all of the following conditions are held, and construct one such matrix if the answer is positive: * The matrix has H rows and W columns. * Each element of the matrix is an integer between -10^9 and 10^...
#設定 import sys input = sys.stdin.buffer.readline #ライブラリインポート from collections import defaultdict #入力受け取り def getlist(): return list(map(int, input().split())) #処理内容 def main(): H, W, h, w = getlist() L = [[1] * W for i in range(H)] if h * w != 1: x = (10 ** 9 - 1) // (h * w - 1) for i in range(H): for j i...
{ "input": [ "2 4 1 2", "3 4 2 3", "3 3 2 2", "0 4 1 2", "3 4 4 3", "4 3 2 2", "4 3 3 2", "3 6 4 2", "3 10 4 2", "5 10 6 2", "5 10 2 2", "2 4 4 1", "4 2 3 2", "1 4 4 2", "3 11 4 2", "3 15 4 2", "3 2 6 2", "9 10 6 2", "5 10 2 4", "2 5 1 4"...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given four integers: H, W, h and w (1 ≤ h ≤ H, 1 ≤ w ≤ W). Determine whether there exists a matrix such that all of the following conditions are held, and construct one such m...
p00095 Surf Smelt Fishing Contest_32073
A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt. Create a program that reads the list of participant numbers and the number of fish caught and outputs the number of winners and the number of fish caught. If there are multiple winners, output the one with the lowest par...
d={} for _ in[0]*int(input()): a,v=map(int,input().split()) d.setdefault(v,[]) d[v]+=[a] m=max(d) print(min(d[m]),m)
{ "input": [ "6\n1 14\n2 25\n3 42\n4 11\n5 40\n6 37", "6\n1 14\n4 25\n3 42\n4 11\n5 40\n6 37", "6\n1 14\n4 25\n3 42\n4 11\n5 60\n6 37", "6\n1 14\n2 25\n3 81\n4 11\n5 40\n6 37", "6\n1 14\n4 25\n3 72\n4 11\n5 60\n6 37", "6\n1 14\n2 25\n3 63\n4 11\n5 40\n6 37", "6\n1 14\n2 25\n3 55\n4 11\n4 4...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: A smelt fishing tournament was held at Lake Hibara. The winner is the one who wins the most smelt. Create a program that reads the list of participant numbers and the number of fish ...
p00227 Thanksgiving_32077
As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices. One day, a group of three good friends living in the Matsunaga housing complex bloomed with a...
# -*- coding: utf-8 -*- """ Thanksgiving http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0227 """ import sys def solve(n, m, prices): ans = 0 for i in range(0, n, m): t = prices[i:i+m] if len(t) == m: t[-1] = 0 ans += sum(t) return ans def main(args): wh...
{ "input": [ "4 2\n50 40 100 80\n7 3\n400 300 100 700 200 600 500\n0 0", "4 2\n50 40 100 80\n7 3\n400 300 100 700 200 600 57\n0 0", "4 2\n50 40 100 80\n7 3\n400 300 100 700 352 600 57\n0 0", "4 3\n50 40 100 80\n7 3\n400 300 100 700 352 600 57\n0 0", "4 3\n50 40 100 80\n7 3\n400 290 100 700 352 600...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are ha...
p00389 Pilling Blocks_32080
We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing. We have to build the tower abiding by the following ...
n,k = map(int, input().split()) res = 0 row = 1 w = 0 while n >= row : if row*k >= w : res += 1 w += row n -= row elif n >= row+1 : row += 1 else : break print(res)
{ "input": [ "5 2", "4 2", "5 4", "4 8", "6 8", "10 8", "10 4", "15 3", "29 3", "29 5", "3 7", "1 14", "2 11", "29 6", "18 7", "51 6", "58 6", "11 16", "31 16", "27 16", "24 8", "51 7", "23 60", "44 6", "31 23", "2...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is to...