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
p01925 Quiz_11340
quiz You are the director of a quiz show. N people will appear in the quiz show as answerers, each numbered from 1 to N. Questions will be M + 1 questions, and each question is numbered from 1 to M + 1. Questions are given in numerical order, and points are given only to the person who answers correctly first by pres...
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 = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin....
{ "input": [ "3 2\n5 2 1 3\n8 2 2 3\n2 3\n8 2 1 2\n3 1 1\n5 1 2\n2 5\n100 1 1\n100 1 1\n100 1 1\n100 1 1\n100 1 1\n3 4\n5 1 1\n5 1 2\n100 2 1 3\n100 2 2 3\n0 0", "3 2\n5 2 1 3\n8 2 2 3\n2 3\n8 2 1 2\n3 1 1\n5 1 2\n2 5\n100 1 1\n000 1 1\n100 1 1\n100 1 1\n100 1 1\n3 4\n5 1 1\n5 1 2\n100 2 1 3\n100 2 2 3\n0 0",...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: quiz You are the director of a quiz show. N people will appear in the quiz show as answerers, each numbered from 1 to N. Questions will be M + 1 questions, and each question is numb...
p02063 Is Greedy Optimal?_11343
D: Is greed the best? story In Japan, where there are 1, 5, 10, 50, 100, 500 yen coins, it is known that the number of coins can be minimized by using as many coins as possible when paying a certain amount. .. If the amount of coins is different from that of Japan, it is not always possible to minimize it by paying ...
A,B=map(int,input().split()) if A>B: A,B=B,A if B%A==0: print(-1) else: for i in range(((B//A+1)*A),B+A*2,A): if i//A < i//B+(i-i//B*B)//A+(i-i//B*B)%A: print(i) break else: print(-1)
{ "input": [ "4 6", "2 6", "6 7", "5 7", "10 11", "4 5", "9 64", "8 11", "7 9", "7 16", "10 31", "14 61", "23 64", "17 31", "23 70", "12 49", "24 78", "45 78", "68 78", "16 75", "3 4", "16 102", "5 11", "8 17", "9 37",...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: D: Is greed the best? story In Japan, where there are 1, 5, 10, 50, 100, 500 yen coins, it is known that the number of coins can be minimized by using as many coins as possible when...
p02205 Calculation Training_11346
Tashizan Hikizan (Calculation Training) square1001 You gave E869120 two numbers, $ A $ and $ B $, as birthday presents. E869120 You decided to use these two numbers for calculation training. Specifically, E869120 does the following for these numbers exactly $ N $ times: * Replace $ A $ with $ A-B $ on odd-numbered ...
N = int(input()) A, B = map(int,input().split()) N = N%12 for k in range(1,N+1): if k%2 == 1: A -= B else: B += A print(A,B)
{ "input": [ "3\n3 4", "3\n4 4", "3\n4 3", "3\n5 3", "3\n9 3", "3\n7 3", "3\n0 3", "3\n0 5", "3\n0 6", "3\n0 0", "3\n1 0", "3\n-1 0", "3\n-2 0", "3\n0 -1", "3\n-1 -1", "3\n-1 -2", "3\n-1 -3", "3\n-1 -6", "3\n-2 -6", "3\n-2 -10", "3\n-...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Tashizan Hikizan (Calculation Training) square1001 You gave E869120 two numbers, $ A $ and $ B $, as birthday presents. E869120 You decided to use these two numbers for calculation ...
p02359 The Maximum Number of Customers_11350
$N$ persons visited a restaurant. The restaurant is open from 0 to $T$. The $i$-th person entered the restaurant at $l_i$ and left at $r_i$. Find the maximum number of persons during the business hours. Constraints * $ 1 \leq N \leq 10^5 $ * $ 1 \leq T \leq 10^5 $ * $ 0 \leq l_i < r_i \leq T $ Input The input is gi...
def main(): n,t = map(int,input().split()) t+=1 T = [0]*t for _ in range(n): l,r = map(int,input().split()) T[l]+=1 T[r]-=1 num = 0 res = 0 for i in range(t): num += T[i] res = max(num,res) print (res) if __name__ == '__main__': main()
{ "input": [ "2 2\n0 1\n1 2", "6 10\n0 2\n1 3\n2 6\n3 8\n4 10\n5 10", "2 4\n0 1\n1 2", "2 10\n0 2\n1 3\n2 6\n3 8\n4 10\n5 10", "0 10\n0 2\n1 3\n2 6\n3 8\n4 10\n5 10", "6 16\n0 2\n1 3\n2 6\n3 8\n4 10\n5 10", "6 16\n0 2\n1 3\n2 6\n0 8\n8 15\n5 10", "2 2\n0 0\n1 2", "2 4\n0 1\n1 3", ...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: $N$ persons visited a restaurant. The restaurant is open from 0 to $T$. The $i$-th person entered the restaurant at $l_i$ and left at $r_i$. Find the maximum number of persons during ...
1004_B. Sonya and Exhibition_11360
Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition. There are n flowers in a row in the exhibition. Sonya can put either a rose or a lily in the i-th position. Thus each of n positions should cont...
def calc(s): presum = [0] for ch in s: presum.append(presum[-1]) if ch == '1': presum[-1] += 1 ans = 0 for (l,r) in points: ans += ((r-l+1) - (presum[r] - presum[l-1])) * (presum[r] - presum[l-1]) return ans n, m = list(map(int, input().split())) """ points = [] for _ in range(m): points...
{ "input": [ "6 3\n5 6\n1 4\n4 6\n", "5 3\n1 3\n2 4\n2 5\n", "1000 10\n3 998\n2 1000\n1 999\n2 1000\n3 998\n2 1000\n3 998\n1 1000\n2 1000\n3 999\n", "1 1\n1 1\n", "1000 20\n50 109\n317 370\n710 770\n440 488\n711 757\n236 278\n314 355\n131 190\n115 162\n784 834\n16 56\n677 730\n802 844\n632 689\n23...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition. There a...
1028_B. Unnatural Conditions_11364
Let s(x) be sum of digits in decimal representation of positive integer x. Given two integers n and m, find some positive integers a and b such that * s(a) ≥ n, * s(b) ≥ n, * s(a + b) ≤ m. Input The only line of input contain two integers n and m (1 ≤ n, m ≤ 1129). Output Print two lines, one for decimal...
def sum_digit(n): c=0 x=n while x>0: c+=(x%10) x=x//10 return c n,m=map(int,input().split()) r='5' su=5 while su<n: r='4'+r su+=4 r=r[0:len(r)-1] r+='5' t1="" for i in range(len(r)): t1+='5' print(int(t1)) print(int(r))
{ "input": [ "8 16\n", "6 5\n", "578 3\n", "20 2\n", "1000 1\n", "4 1\n", "10 1\n", "843 152\n", "1 1\n", "3 10\n", "1 1000\n", "9 1\n", "1000 1000\n", "123 5\n", "1 1129\n", "999 999\n", "1129 1129\n", "1129 1\n", "321 1129\n", "123 1000...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Let s(x) be sum of digits in decimal representation of positive integer x. Given two integers n and m, find some positive integers a and b such that * s(a) ≥ n, * s(b) ≥ n, ...
1046_H. Palindrome Pairs_11368
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...
# -*- coding:utf-8 -*- """ created by shuangquan.huang at 11/20/18 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...
{ "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\niw\nix\nudb\nbg\noi\nuo\njsm\nmu\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 ...
1070_G. Monsters and Potions_11371
Polycarp is an introvert person. In fact he is so much of an introvert that he plays "Monsters and Potions" board game alone. The board of the game is a row of n cells. The cells are numbered from 1 to n from left to right. There are three types of cells: a cell containing a single monster, a cell containing a single p...
import sys n, m = tuple(int(x) for x in sys.stdin.readline().split()) heroes = [] for i in range(m): s, h = tuple(int(x) for x in sys.stdin.readline().split()) heroes.append((s - 1, h, i)) heroes = tuple(sorted(heroes)) a = tuple(int(x) for x in sys.stdin.readline().split()) def move_right(heroes, a): a...
{ "input": [ "8 3\n8 2\n1 3\n4 9\n0 3 -5 0 -5 -4 -1 0\n", "1 1\n1 1\n0\n", "8 3\n1 15\n5 10\n8 1\n0 -5 -5 -5 0 -5 -5 0\n", "3 2\n1 1\n3 1\n0 -5000 0\n", "4 2\n1 1\n4 1\n0 -2 1 0\n", "5 2\n1 1\n5 1\n0 1 -3 1 0\n", "10 2\n1 1\n10 1\n0 1 1 1 1 1 1 1 -8 0\n", "100 2\n1 1\n100 1\n0 -98 1 1 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Polycarp is an introvert person. In fact he is so much of an introvert that he plays "Monsters and Potions" board game alone. The board of the game is a row of n cells. The cells are ...
1092_C. Prefixes and Suffixes_11375
Ivan wants to play a game with you. He picked some string s of length n consisting only of lowercase Latin letters. You don't know this string. Ivan has informed you about all its improper prefixes and suffixes (i.e. prefixes and suffixes of lengths from 1 to n-1), but he didn't tell you which strings are prefixes an...
def is_suffix(par,child): l=len(child) if par[n-l-1:] == child: return 1 return 0 def is_prefix(par,child): l=len(child) if par[:l] ==child: return 1 return 0 def make(pri_par,sec_par,f,s): ans=[0 for i in range(2*n-2)] ans[f]='P' ans[s]='S' for i in range(2, 2 ...
{ "input": [ "3\na\naa\naa\na\n", "5\nba\na\nabab\na\naba\nbaba\nab\naba\n", "2\na\nc\n", "5\na\na\nab\nba\naba\naba\nbaba\nabab\n", "4\nab\na\nb\nbab\nab\naba\n", "5\na\naa\naaa\naaaa\nb\nba\nbaa\nbaaa\n", "4\na\nba\naba\nb\nba\nbab\n", "4\na\nb\nab\nab\nbab\naba\n", "5\nbaba\naba...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Ivan wants to play a game with you. He picked some string s of length n consisting only of lowercase Latin letters. You don't know this string. Ivan has informed you about all its i...
1111_A. Superhero Transformation_11379
We all know that a superhero can transform to certain other superheroes. But not all Superheroes can transform to any other superhero. A superhero with name s can transform to another superhero with name t if s can be made equal to t by changing any vowel in s to any other vowel and any consonant in s to any other cons...
import math # n=int(input()) s=input() t=input() c = ['a','e','i','o','u'] if len(s)!=len(t): print("No") exit(0) for i in range(len(s)): if(s[i] in c and not(t[i] in c)): print("No") exit(0) elif(t[i] in c and not (s[i] in c)): print("No") exit(0) print("Yes")
{ "input": [ "akm\nua\n", "a\nu\n", "abc\nukm\n", "b\na\n", "abcdef\ncdabef\n", "ka\nak\n", "aabcd\nbcaad\n", "aabb\nabab\n", "zenudggmyopddhszhrbmftgzmjorabhgojdtfnzxjkayjlkgczsyshczutkdchiytqlfsevymipufxkxojlvkkqxvjhpjmcxeiluua\nblcdiwjphlpzwvknsyvbcodpyktizgatrlieiikktghixbikehs...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: We all know that a superhero can transform to certain other superheroes. But not all Superheroes can transform to any other superhero. A superhero with name s can transform to another...
1159_D. The minimal unique substring_11385
Let s be some string consisting of symbols "0" or "1". Let's call a string t a substring of string s, if there exists such number 1 ≤ l ≤ |s| - |t| + 1 that t = s_l s_{l+1} … s_{l + |t| - 1}. Let's call a substring t of string s unique, if there exist only one such l. For example, let s = "1010111". A string t = "010...
n, k = map(int, input().split()) strr = "" while len(strr) < n: strr += "0" * ((n-k) // 2) + "1" strr = strr[:n] print(strr)
{ "input": [ "4 4\n", "7 3\n", "5 3\n", "100000 33334\n", "81 1\n", "99999 3\n", "99985 45273\n", "3 3\n", "99997 64685\n", "87 43\n", "6 4\n", "3 1\n", "99999 1\n", "100000 99992\n", "99999 99991\n", "99999 99999\n", "99999 50719\n", "22359 1593...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Let s be some string consisting of symbols "0" or "1". Let's call a string t a substring of string s, if there exists such number 1 ≤ l ≤ |s| - |t| + 1 that t = s_l s_{l+1} … s_{l + |...
1181_D. Irrigation_11389
Misha was interested in water delivery from childhood. That's why his mother sent him to the annual Innovative Olympiad in Irrigation (IOI). Pupils from all Berland compete there demonstrating their skills in watering. It is extremely expensive to host such an olympiad, so after the first n olympiads the organizers int...
from bisect import bisect_left as bl import sys N, M, Q = map(int, sys.stdin.readline().split()) count = [0] * (M + 1) A = [] for a in sys.stdin.readline().split(): a = int(a) A.append(count[a] * M + a) count[a] += 1 A.sort() A = [a - i for i, a in enumerate(A, 1)] for _ in range(Q): q = int(sys.stdin....
{ "input": [ "4 5 4\n4 4 5 1\n15\n9\n13\n6\n", "6 4 10\n3 1 1 1 2 2\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n", "100 21 20\n11 17 21 14 7 15 18 6 17 11 21 3 17 21 21 7 21 17 14 21 14 14 3 6 18 21 17 17 18 14 14 21 15 13 3 15 11 11 16 11 6 10 15 17 11 15 13 13 21 16 21 13 11 14 21 21 13 18 16 3 21 16 13 16 15...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Misha was interested in water delivery from childhood. That's why his mother sent him to the annual Innovative Olympiad in Irrigation (IOI). Pupils from all Berland compete there demo...
119_C. Education Reform_11393
Yet another education system reform has been carried out in Berland recently. The innovations are as follows: An academic year now consists of n days. Each day pupils study exactly one of m subjects, besides, each subject is studied for no more than one day. After the lessons of the i-th subject pupils get the home ta...
class Subject: def __init__(self, id, low, high, complexity): self.id = id self.low = low self.high = high self.complexity = complexity self.day_links = [ {} for i in range(high - low + 1) ] def add_link(self, link): day = link.day links = self.day_links[...
{ "input": [ "4 5 2\n1 10 1\n1 10 2\n1 10 3\n1 20 4\n1 100 5\n", "3 4 3\n1 3 1\n2 4 4\n2 3 3\n2 2 2\n", "50 50 1\n1 1 1\n1 1 2\n1 1 3\n1 1 4\n1 1 5\n1 1 6\n1 1 7\n1 1 8\n1 1 9\n1 1 10\n1 1 11\n1 1 12\n1 1 13\n1 1 14\n1 1 15\n1 1 16\n1 1 17\n1 1 18\n1 1 19\n1 1 20\n1 1 21\n1 1 22\n1 1 23\n1 1 24\n1 1 25\n1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Yet another education system reform has been carried out in Berland recently. The innovations are as follows: An academic year now consists of n days. Each day pupils study exactly o...
1217_A. Creating a Character_11397
You play your favourite game yet another time. You chose the character you didn't play before. It has str points of strength and int points of intelligence. Also, at start, the character has exp free experience points you can invest either in strength or in intelligence (by investing one point you can either raise stre...
from sys import stdin input=stdin.readline R=lambda:map(int,input().split()) I=lambda:int(input()) S=lambda:input().rstrip('\n') for _ in range(I()): a,b,c=R() ans=0 l=0;r=c while l<=r: m=(l+r)//2 if a+m>b+(c-m):ans=c-m+1;r=m-1 else:l=m+1 print(ans)
{ "input": [ "4\n5 3 4\n2 1 0\n3 5 5\n4 10 6\n", "5\n1 1 100000000\n100000000 100000000 100000000\n100000000 1 100000000\n1 100000000 100000000\n100000000 100000000 1\n", "5\n0 1 100000000\n100000000 100000000 100000000\n100000000 1 100000000\n1 100000000 100000000\n100000000 100000000 1\n", "4\n5 3 4...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You play your favourite game yet another time. You chose the character you didn't play before. It has str points of strength and int points of intelligence. Also, at start, the charac...
1325_F. Ehab's Last Theorem_11408
It's the year 5555. You have a graph, and you want to find a long cycle and a huge independent set, just because you can. But for now, let's just stick with finding either. Given a connected graph with n vertices, you can choose to either: * find an independent set that has exactly ⌈√{n}⌉ vertices. * find a simpl...
from collections import deque from sys import stdin import sys from math import ceil sys.setrecursionlimit(3*10**5) n,m = map(int,stdin.readline().split()) rn = ceil(n**0.5) lis = [ [] for i in range(n) ] for i in range(m): u,v = map(int,stdin.readline().split()) u -= 1 v -= 1 lis[u].append(v) lis...
{ "input": [ "6 6\n1 3\n3 4\n4 2\n2 6\n5 6\n5 1\n", "6 8\n1 3\n3 4\n4 2\n2 6\n5 6\n5 1\n1 4\n2 5\n", "5 4\n1 2\n1 3\n2 4\n2 5\n", "5 5\n1 2\n1 3\n2 3\n1 4\n4 5\n", "17 51\n3 12\n6 13\n15 1\n3 10\n13 2\n17 8\n3 14\n13 17\n2 6\n16 2\n1 10\n3 17\n3 15\n9 12\n7 8\n2 8\n7 13\n9 2\n2 14\n5 6\n12 8\n15 1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: It's the year 5555. You have a graph, and you want to find a long cycle and a huge independent set, just because you can. But for now, let's just stick with finding either. Given a c...
1366_E. Two Arrays_11413
You are given two arrays a_1, a_2, ... , a_n and b_1, b_2, ... , b_m. Array b is sorted in ascending order (b_i < b_{i + 1} for each i from 1 to m - 1). You have to divide the array a into m consecutive subarrays so that, for each i from 1 to m, the minimum on the i-th subarray is equal to b_i. Note that each element ...
import math n, m = tuple(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) ai = n - 1 bi = m - 1 num_split = [0] * (m - 1) while bi > 0: while a[ai] > b[bi]: ai -= 1 while ai >= 0 and a[ai] >= b[bi]: num_split[bi - 1] += 1 ai -= 1 bi...
{ "input": [ "6 3\n12 10 20 20 25 30\n10 20 30\n", "8 2\n1 2 2 2 2 2 2 2\n1 2\n", "4 2\n1 3 3 7\n3 7\n", "71 4\n9 9 6 9 8 2 10 9 2 5 10 1 9 7 5 6 4 9 3 7 3 8 5 3 4 10 5 9 9 1 2 1 10 1 10 8 2 9 2 2 8 8 2 4 10 1 6 9 7 2 7 5 1 1 8 6 7 9 5 6 8 2 3 4 3 1 3 7 2 7 4\n1 2 3 7\n", "2 2\n10 7\n5 7\n", "...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given two arrays a_1, a_2, ... , a_n and b_1, b_2, ... , b_m. Array b is sorted in ascending order (b_i < b_{i + 1} for each i from 1 to m - 1). You have to divide the array ...
1387_B1. Village (Minimum)_11417
This problem is split into two tasks. In this task, you are required to find the minimum possible answer. In the task Village (Maximum) you are required to find the maximum possible answer. Each task is worth 50 points. There are N houses in a certain village. A single villager lives in each of the houses. The houses ...
import os import sys from io import BytesIO, IOBase # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.wri...
{ "input": [ "4\n1 2\n2 3\n3 4\n", "7\n4 2\n5 7\n3 4\n6 3\n1 3\n4 5\n", "10\n9 8\n1 3\n7 5\n8 6\n8 10\n6 4\n1 6\n10 2\n6 5\n", "10\n5 7\n4 1\n10 5\n9 3\n7 9\n8 2\n6 1\n8 6\n2 7\n", "2\n1 2\n", "10\n10 2\n4 10\n1 10\n5 10\n10 7\n9 10\n3 10\n1 6\n8 1\n", "7\n4 1\n7 6\n7 5\n1 3\n3 2\n1 6\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: This problem is split into two tasks. In this task, you are required to find the minimum possible answer. In the task Village (Maximum) you are required to find the maximum possible a...
1408_E. Avoid Rainbow Cycles_11420
You are given m sets of integers A_1, A_2, …, A_m; elements of these sets are integers between 1 and n, inclusive. There are two arrays of positive integers a_1, a_2, …, a_m and b_1, b_2, …, b_n. In one operation you can delete an element j from the set A_i and pay a_i + b_j coins for that. You can make several (ma...
import sys;input=sys.stdin.readline def root(x): if x == p[x]:return x p[x] = y = root(p[x]);return y def unite(x, y): px = root(x); py = root(y) if px == py:return 0 rx = rank[px]; ry = rank[py] if ry < rx:p[py] = px elif rx < ry:p[px] = py else:p[py] = px;rank[px] += 1 return M, N ...
{ "input": [ "7 8\n3 6 7 9 10 7 239\n8 1 9 7 10 2 6 239\n3 2 1 3\n2 4 1\n3 1 3 7\n2 4 3\n5 3 4 5 6 7\n2 5 7\n1 8\n", "3 2\n1 2 3\n4 5\n2 1 2\n2 1 2\n2 1 2\n", "2 2\n1 1\n1 1\n2 1 2\n2 1 2\n", "2 2\n1 2\n1 1\n2 1 2\n2 1 2\n", "7 8\n3 6 7 9 10 7 239\n8 1 9 7 10 2 6 92\n3 2 1 3\n2 4 1\n3 1 3 7\n2 4 3...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given m sets of integers A_1, A_2, …, A_m; elements of these sets are integers between 1 and n, inclusive. There are two arrays of positive integers a_1, a_2, …, a_m and b_1,...
1452_C. Two Brackets_11426
You are given a string s, consisting of brackets of two types: '(', ')', '[' and ']'. A string is called a regular bracket sequence (RBS) if it's of one of the following types: * empty string; * '(' + RBS + ')'; * '[' + RBS + ']'; * RBS + RBS. where plus is a concatenation of two strings. In one move...
import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.wri...
{ "input": [ "5\n()\n[]()\n([)]\n)]([\n)[(]\n", "4\n()\n()\n()\n()\n", "7\n()\n()\n()\n()\n()\n()\n()\n", "4\n[()]\n[]\n[]\n()\n", "4\n)(\n()\n()\n()\n", "4\n[()]\n][\n[]\n()\n", "4\n)(\n()\n((\n()\n", "4\n()\n()\n)(\n()\n", "5\n)(\n[]()\n([)]\n)]([\n)[(]\n", "4\n)(\n))\n()\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 string s, consisting of brackets of two types: '(', ')', '[' and ']'. A string is called a regular bracket sequence (RBS) if it's of one of the following types: *...
1476_A. K-divisible Sum_11430
You are given two integers n and k. You should create an array of n positive integers a_1, a_2, ..., a_n such that the sum (a_1 + a_2 + ... + a_n) is divisible by k and maximum element in a is minimum possible. What is the minimum possible maximum element in a? Input The first line contains a single integer t (1 ≤ ...
import sys import math import itertools import functools import collections import operator import fileinput import copy from collections import * ORDA = 97 # a def ii(): return int(input()) def mi(): return map(int, input().split()) def li(): return [int(i) for i in input().split()] def lcm(a, b): return abs(a * b)...
{ "input": [ "4\n1 5\n4 3\n8 8\n8 17\n", "10\n1000000000 3\n1000000000 3\n1000000000 3\n1000000000 3\n1000000000 3\n1000000000 3\n1000000000 3\n1000000000 3\n1000000000 3\n1000000000 3\n", "12\n1000000000 1\n1000000000 1\n1000000000 1\n1000000000 1\n1000000000 1\n1000000000 1\n1000000000 1\n1000000000 1\n...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given two integers n and k. You should create an array of n positive integers a_1, a_2, ..., a_n such that the sum (a_1 + a_2 + ... + a_n) is divisible by k and maximum eleme...
1526_B. I Hate 1111_11435
You are given an integer x. Can you make x by summing up some number of 11, 111, 1111, 11111, …? (You can use any number among them any number of times). For instance, * 33=11+11+11 * 144=111+11+11+11 Input The first line of input contains a single integer t (1 ≤ t ≤ 10000) — the number of testcases. The fi...
for i in range(int(input())): n=int(input()) if(n>=111*(n%11)): print("YES") else : print("NO")
{ "input": [ "3\n33\n144\n69\n", "1\n1\n", "3\n29\n144\n69\n", "3\n29\n100\n69\n", "3\n33\n100\n29\n", "1\n2\n", "3\n33\n144\n103\n", "3\n33\n144\n143\n", "3\n17\n010\n254\n", "3\n29\n101\n69\n", "3\n29\n100\n51\n", "3\n29\n100\n18\n", "3\n29\n100\n29\n", "3\n11...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given an integer x. Can you make x by summing up some number of 11, 111, 1111, 11111, …? (You can use any number among them any number of times). For instance, * 33=11+11...
1_A. Theatre Square_11443
Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size a × a. What is the least number of flagstones needed to pave the Square? It'...
import math def main(): n, m, a = map(int, input().split()) sq_area = n * m stone_area = a * a if stone_area > sq_area: return 1 return math.ceil(m / a) * math.ceil(n / a) if __name__ == '__main__': print(main())
{ "input": [ "6 6 4\n", "1 1 3\n", "1000000000 1000000000 1\n", "2 1 2\n", "222 332 5\n", "2 2 1\n", "456784567 1000000000 51\n", "1001 1000 10\n", "2 3 4\n", "1000000000 1000000000 999999999\n", "2 1 1\n", "100 10001 1000000000\n", "39916800 134217728 40320\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters. On the occasion of the city's anniversary, a decision was taken to pave the Square wi...
224_B. Array_11447
You've got an array a, consisting of n integers: a1, a2, ..., an. Your task is to find a minimal by inclusion segment [l, r] (1 ≤ l ≤ r ≤ n) such, that among numbers al, al + 1, ..., ar there are exactly k distinct numbers. Segment [l, r] (1 ≤ l ≤ r ≤ n; l, r are integers) of length m = r - l + 1, satisfying the given...
MAX_N = 100005 n, k = map(int, input().split(' ')) a = list(map(int, input().split(' '))) cnt = [0 for i in range(MAX_N)] l = 0 count = 0 for i in range(n): cnt[a[i]] += 1 if cnt[a[i]] == 1: count += 1 if count == k: while l <= i: cnt[a[l]] -= 1 if cnt[a[l]] == 0: print(l + 1, end = ' ') print(...
{ "input": [ "7 4\n4 7 7 4 7 4 7\n", "4 2\n1 2 2 3\n", "8 3\n1 1 2 2 3 3 4 5\n", "10 4\n1 2 3 1 2 3 4 3 2 1\n", "4 2\n3 3 4 3\n", "5 3\n1 2 1 2 3\n", "10 4\n1 1 2 2 3 3 4 4 4 4\n", "5 3\n1 3 1 3 4\n", "9 3\n1 2 1 2 1 2 2 3 1\n", "4 3\n4 4 4 2\n", "5 1\n1 7 2 3 2\n", "10...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You've got an array a, consisting of n integers: a1, a2, ..., an. Your task is to find a minimal by inclusion segment [l, r] (1 ≤ l ≤ r ≤ n) such, that among numbers al, al + 1, ..., ...
273_A. Dima and Staircase_11453
Dima's got a staircase that consists of n stairs. The first stair is at height a1, the second one is at a2, the last one is at an (1 ≤ a1 ≤ a2 ≤ ... ≤ an). Dima decided to play with the staircase, so he is throwing rectangular boxes at the staircase from above. The i-th box has width wi and height hi. Dima throws eac...
n, t, d, p = input(), [0] + list(map(int, input().split())), 0, [] for i in range(int(input())): w, h = map(int, input().split()) p.append(max(d, t[w])) d = p[i] + h print(*p)
{ "input": [ "1\n1\n5\n1 2\n1 10\n1 10\n1 10\n1 10\n", "3\n1 2 3\n2\n1 1\n3 1\n", "5\n1 2 3 6 6\n4\n1 1\n3 1\n1 1\n4 3\n", "7\n8 13 19 21 25 30 32\n3\n5 4\n6 5\n1 2\n", "3\n1 6 8\n5\n3 4\n3 9\n3 3\n1 2\n1 6\n", "2\n1 6\n5\n2 6\n1 2\n1 1\n1 2\n1 7\n", "1\n9\n8\n1 4\n1 10\n1 9\n1 9\n1 7\n1 1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Dima's got a staircase that consists of n stairs. The first stair is at height a1, the second one is at a2, the last one is at an (1 ≤ a1 ≤ a2 ≤ ... ≤ an). Dima decided to play with...
296_C. Greg and Array_11457
Greg has an array a = a1, a2, ..., an and m operations. Each operation looks as: li, ri, di, (1 ≤ li ≤ ri ≤ n). To apply operation i to the array means to increase all array elements with numbers li, li + 1, ..., ri by value di. Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, ...
n, m, k = [int(n) for n in input().split()] a = [int(n) for n in input().split()] instructions = [] temp = [] for i in range(n+1): temp.append(0) for i in range(m): instructions.append([int(n) for n in input().split()]) queries = [] for i in range(m+1): queries.append(0) for i in range(k): x, y = [int(n) for n in i...
{ "input": [ "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3\n", "1 1 1\n1\n1 1 1\n1 1\n", "3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3\n", "1 1 1\n0\n1 1 0\n1 1\n", "4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 3\n1 3\n2 3\n1 2\n1 3\n2 3\n", "3 3 3\n1 2 3\n1 2 1\n2 3 2\n2 3 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Greg has an array a = a1, a2, ..., an and m operations. Each operation looks as: li, ri, di, (1 ≤ li ≤ ri ≤ n). To apply operation i to the array means to increase all array elements ...
31_A. Worms Evolution_11461
Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are n forms of worms. Worms of these forms have lengths a1, a2, ..., an. To prove his theory, professor needs to find 3 different forms that the length of the first form is equal to sum of len...
n = int(input()) line = list(map(int,input().split())) for i in range(n-1): for j in range(i+1,n): if line[i] + line[j] in line: print(line.index(line[i] + line[j])+1, i+1, j+1) exit(0) print('-1')
{ "input": [ "5\n1 2 3 5 7\n", "5\n1 8 1 5 1\n", "100\n611 697 572 770 603 870 128 245 49 904 468 982 788 943 549 288 668 796 803 515 999 735 912 49 298 80 412 841 494 434 543 298 17 571 271 105 70 313 178 755 194 279 585 766 412 164 907 841 776 556 731 268 735 880 176 267 287 65 239 588 155 658 821 47 78...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are n forms of worms. Worms of these forms have lengths...
344_A. Magnets_11465
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the oppo...
s=0 prev='' for i in range(int(input())): kk=input() if kk!=prev: s+=1 prev=kk print(s)
{ "input": [ "4\n01\n01\n10\n10\n", "6\n10\n10\n10\n01\n10\n10\n", "1\n10\n", "3\n10\n01\n10\n", "3\n10\n10\n01\n", "115\n10\n10\n10\n10\n01\n01\n10\n10\n10\n01\n01\n10\n01\n01\n10\n10\n10\n01\n10\n01\n10\n10\n01\n01\n10\n10\n10\n10\n01\n10\n01\n01\n10\n10\n10\n10\n01\n10\n10\n10\n01\n10\n01\n...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plu...
367_C. Sereja and the Arrangement of Numbers_11469
Let's call an array consisting of n integer numbers a1, a2, ..., an, beautiful if it has the following property: * consider all pairs of numbers x, y (x ≠ y), such that number x occurs in the array a and number y occurs in the array a; * for each pair x, y must exist some position j (1 ≤ j < n), such that at leas...
def readdata(): #fread = open('input.txt', 'r') global n, m, w, q n, m = [int(x) for x in input().split()] q = [0] * m w = [0] * m for i in range(m): q[i], w[i] = [int(x) for x in input().split()] def podg(): global summ w.sort(reverse = True) summ ...
{ "input": [ "100 3\n1 2\n2 1\n3 1\n", "1 2\n1 1\n2 100\n", "5 2\n1 2\n2 3\n", "58 38\n6384 48910\n97759 90589\n28947 5031\n45169 32592\n85656 26360\n88538 42484\n44042 88351\n42837 79021\n96022 59200\n485 96735\n98000 3939\n3789 64468\n10894 58484\n26422 26618\n25515 95617\n37452 5250\n39557 66304\n7...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Let's call an array consisting of n integer numbers a1, a2, ..., an, beautiful if it has the following property: * consider all pairs of numbers x, y (x ≠ y), such that number x oc...
411_A. Password Check_11475
You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password isn't complex enough, a message is displayed. Today your task is to implement such an automatic che...
n=input() d=[] sp="!?.,_" for i in n: if len(n)>=5: d.append(1) if i.isupper()==True: d.append(2) if i.islower()==True: d.append(3) if i.isdigit()==True: d.append(4) if i in sp: d.append(5) s=set(d) if s=={1,2,3,4} or s=={1,2,3,4,5}: print("Correct") else:...
{ "input": [ "X12345\n", "CONTEST_is_STARTED!!11\n", "abacaba\n", "Vu7jQU8.!FvHBYTsDp6AphaGfnEmySP9te\n", "P1H\n", "c7jqaudcqmv8o7zvb5x_gp6zcgl6nwr7tz5or!28.tj8s1m2.wxz5a4id03!rq07?662vy.7.p5?vk2f2mc7ag8q3861rgd0rmbr\n", "Hi7zYuVXCPhaho68YgCMzzgLILM6toQTJq8akMqqrnUn6ZCD36iA1yVVpvlsIiMpCu!1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's cry...
460_B. Little Dima and Equation_11481
Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment. Find all integer solutions x (0 < x < 109) of the equation: x = b·s(x)a + c, where a, b, c are some predetermined constant values and function s(x) determines the sum of all digits in...
a,b,c=map(int,input().split()) L=[] for i in range(1,82): val=b*(i**a)+c check=0 if val>0 and val<10**9: s=str(val) for j in s: check+=int(j) if check==i: L.append(val) if len(L)==0: print(0) else: print(len(L)) print(*L)
{ "input": [ "3 2 8\n", "2 2 -1\n", "1 2 -18\n", "5 10000 9\n", "3 1139 6335\n", "2 8468 -3666\n", "5 5 13\n", "5 3903 153\n", "5 9999 9999\n", "1 3034 -9234\n", "1 1 0\n", "5 12 3\n", "2 28 12\n", "5 10000 0\n", "5 1 0\n", "3 2570 4109\n", "5 19 -66...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment. Find all integer solutions x (0 < x < 109) of the...
484_A. Bits_11485
Let's denote as <image> the number of bits set ('1' bits) in the binary representation of the non-negative integer x. You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l ≤ x ≤ r, and <image> is maximum possible. If there are multiple such numbers find the sma...
n = int(input()) for i in range(n): l,r=map(int,input().split()) while(l|(l+1)<=r): # or make like max function here . l|=l+1 # or here like equal print(l)
{ "input": [ "3\n1 2\n2 4\n1 10\n", "18\n1 10\n1 100\n1 1000\n1 10000\n1 100000\n1 1000000\n1 10000000\n1 100000000\n1 1000000000\n1 10000000000\n1 100000000000\n1 1000000000000\n1 10000000000000\n1 100000000000000\n1 1000000000000000\n1 10000000000000000\n1 100000000000000000\n1 1000000000000000000\n", "...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Let's denote as <image> the number of bits set ('1' bits) in the binary representation of the non-negative integer x. You are given multiple queries consisting of pairs of integers l...
508_A. Pasha and Pixels_11489
Pasha loves his phone and also putting his hair up... But the hair is now irrelevant. Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of n row with m pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choose an...
n,m,k = map(int,input().split()) l = [] for i in range(n+2): l.append([0 for i in range(m+2)]) ans = 0 done = 'no' for i in range(k): x,y = map(int,input().split()) l[x][y] = 1 if done == 'no' and ((l[x][y-1] == 1 and l[x-1][y] == 1 and l[x-1][y-1] == 1) or (l[x][y-1] == 1 and l[x+1][y] == 1 and l[x+1][...
{ "input": [ "2 2 4\n1 1\n1 2\n2 1\n2 2\n", "5 3 7\n2 3\n1 2\n1 1\n4 1\n3 1\n5 3\n3 2\n", "2 3 6\n2 3\n2 2\n1 3\n2 2\n1 2\n1 1\n", "3 3 11\n2 1\n3 1\n1 1\n1 3\n1 2\n2 3\n3 3\n3 2\n2 2\n1 3\n3 3\n", "1000 1000 4\n1000 1000\n999 999\n1000 999\n999 1000\n", "1 1 5\n1 1\n1 1\n1 1\n1 1\n1 1\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Pasha loves his phone and also putting his hair up... But the hair is now irrelevant. Pasha has installed a new game to his phone. The goal of the game is following. There is a recta...
557_B. Pasha and Tea_11493
Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of w milliliters and 2n tea cups, each cup is for one of Pasha's friends. The i-th cup can hold at most ai milliliters of water. It turned out that among Pasha's friends there are exactly n boys and exactly n...
import sys def fastio(): from io import StringIO from atexit import register global input sys.stdin = StringIO(sys.stdin.read()) input = lambda : sys.stdin.readline().rstrip('\r\n') sys.stdout = StringIO() register(lambda : sys.__stdout__.write(sys.stdout.getvalue())) fastio() def debug(*va...
{ "input": [ "1 5\n2 3\n", "2 4\n1 1 1 1\n", "3 18\n4 4 4 2 2 2\n", "4 1000000000\n1 1 1 1 2 2 2 2\n", "4 30\n3 3 3 3 4 5 6 7\n", "2 19\n3 3 5 5\n", "4 1000000000\n1 1 1 1 1 1 1 1\n", "4 1\n3 3 3 3 4 4 4 4\n", "1 100\n1 200\n", "1 1\n1 1\n", "2 100\n1 1 1 10\n", "2 4\n1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of w milliliters and 2n tea cups, each cup is for one of Pasha's friends...
604_E. Lieges of Legendre_11499
Kevin and Nicky Sun have invented a new game called Lieges of Legendre. In this game, two players take turns modifying the game state with Kevin moving first. Initially, the game is set up so that there are n piles of cows, with the i-th pile containing ai cows. During each player's turn, that player calls upon the pow...
G_EVEN = {0:0, 1:1, 2:2} G_ODD = {0:0, 1:1, 2:0, 3:1} def grundy(k, ai): if k % 2: if ai <= 3: return G_ODD[ai] elif ai % 2: return 0 else: p = 0 j = ai while not j & 1: p += 1 j >>= 1 i...
{ "input": [ "1 2\n3\n", "2 1\n3 4\n", "2 1\n24 1\n", "1 1\n1\n", "5 1\n1 7 7 6 6\n", "2 3\n12345678 23456789\n", "2 1\n160 150\n", "2 3\n7 7\n", "2 2\n2 5\n", "9 2\n8 2 9 4 7 5 2 4 9\n", "6 2\n5 3 5 6 2 2\n", "7 2\n9 1 7 6 10 3 5\n", "2 2\n2 4\n", "6 1\n1 4 4 4...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Kevin and Nicky Sun have invented a new game called Lieges of Legendre. In this game, two players take turns modifying the game state with Kevin moving first. Initially, the game is s...
627_A. XOR Equation_11503
Two positive integers a and b have a sum of s and a bitwise XOR of x. How many possible values are there for the ordered pair (a, b)? Input The first line of the input contains two integers s and x (2 ≤ s ≤ 1012, 0 ≤ x ≤ 1012), the sum and bitwise xor of the pair of positive integers, respectively. Output Print a s...
R = lambda: map(int, input().split()) s, x = R() if s < x or (s - x) & 1: print(0) exit(0) u, d = (s - x) // 2, x res = 1 while u or d: uu, dd = u & 1, d & 1 if uu and dd: res *= 0 elif uu == 0 and dd == 1: res *= 2 u, d = u >> 1, d >> 1 if s == x: res = max(0, res - 2) print...
{ "input": [ "5 2\n", "9 5\n", "3 3\n", "3 1\n", "322373798090 322373798090\n", "1000000000000 999999999999\n", "32576550340 504864993495\n", "1000000000000 4096\n", "4 6\n", "297044970199 121204864\n", "274869346299 274869346299\n", "80 12\n", "552972910589 5465303...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Two positive integers a and b have a sum of s and a bitwise XOR of x. How many possible values are there for the ordered pair (a, b)? Input The first line of the input contains two ...
651_A. Joysticks_11507
Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at a1 percent and second one is charged at a2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if not c...
import sys input = sys.stdin.readline def inp(): return (int(input())) def inlt(): return (list(map(int, input().split()))) def insr(): s = input() return (list(s[:len(s) - 1])) def invr(): return list((map(int, input().split()))) hash_map = {} def solve(a1, a2): if a1 <= 0 or a2 <=...
{ "input": [ "4 4\n", "3 5\n", "1 4\n", "7 2\n", "100 25\n", "29 1\n", "3 73\n", "14 15\n", "1 1\n", "24 57\n", "1 2\n", "3 2\n", "24 15\n", "2 97\n", "15 31\n", "15 25\n", "2 3\n", "8 8\n", "2 99\n", "59 45\n", "23 12\n", "3 1\n"...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at a1 percent and second one is charged at a2 percent. Yo...
69_D. Dot_11514
Anton and Dasha like to play different games during breaks on checkered paper. By the 11th grade they managed to play all the games of this type and asked Vova the programmer to come up with a new game. Vova suggested to them to play a game under the code name "dot" with the following rules: * On the checkered pape...
import sys from array import array # noqa: F401 def input(): return sys.stdin.buffer.readline().decode('utf-8') x, y, n, d = map(int, input().split()) vector = [list(map(int, input().split())) for _ in range(n)] dp = [[-1] * (d * 2 + 1) for _ in range(d * 2 + 1)] for i in range(d * 2 + 1): for j in range(...
{ "input": [ "0 0 2 4\n1 1\n1 2\n", "0 0 2 3\n1 1\n1 2\n", "3 -1 20 200\n19 12\n24 121\n25 32\n28 19\n28 87\n29 49\n32 88\n33 70\n37 77\n54 33\n56 27\n61 59\n67 42\n73 15\n76 40\n80 73\n83 39\n91 34\n91 112\n95 95\n", "0 0 5 100\n17 3\n42 24\n72 22\n72 25\n120 25\n", "0 0 5 100\n12 105\n15 59\n21 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Anton and Dasha like to play different games during breaks on checkered paper. By the 11th grade they managed to play all the games of this type and asked Vova the programmer to come ...
721_A. One-dimensional Japanese Crossword_11518
Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized a × b squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers represents...
n=int(input()) s=input() arr,k=[],0 for i in range(len(s)): if(s[i]=='B'): k+=1 else: if(k>0): arr.append(k) k=0 if(k>0): arr.append(k) print(len(arr)) print(*arr,sep=' ')
{ "input": [ "3\nBBW\n", "5\nBWBWB\n", "4\nWWWW\n", "13\nWBBBBWWBWBBBW\n", "4\nBBBB\n", "50\nBBBBBWBWBWWBWBWWWWWWBWBWBWWWWWWWWWWWWWBWBWWWWBWWWB\n", "50\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\n", "10\nBBBBBWWBBB\n", "100\nBBBBWWWWWWWWWWWWWWWWWWWWWWWWWBWBWWWWWBWBWWWWWWBB...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized a × b squares, and each square is colored white or black. There are inte...
742_D. Arpa's weak amphitheater and Mehrdad's valuable Hoses_11522
Just to remind, girls in Arpa's land are really nice. Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight wi and some beauty bi. Also each Hos may have some friends. Hoses are divided in some friendship groups. Two Hoses x and y are in the same friendship group if and only if...
from sys import stdin, stdout from collections import defaultdict as dd read, write = stdin.readline, stdout.write class DisjointSetUnion: def __init__(self, n): self.parent = list(range(n)) self.size = [1] * n self.num_sets = n def find(self, a): acopy = a while a != s...
{ "input": [ "4 2 11\n2 4 6 6\n6 4 2 1\n1 2\n2 3\n", "3 1 5\n3 2 5\n2 4 2\n1 2\n", "10 5 100\n64 90 3 94 96 97 52 54 82 31\n796554 444893 214351 43810 684158 555762 686198 339093 383018 699152\n6 8\n8 3\n3 9\n2 3\n10 3\n", "10 5 100\n48 73 30 46 95 19 98 73 94 24\n501216 675859 843572 565104 879875 82...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Just to remind, girls in Arpa's land are really nice. Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight wi and some beauty bi. Also each ...
766_A. Mahmoud and Longest Uncommon Subsequence_11526
While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem. Given two strings a and b, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of o...
def uncommon(a, b): if (a == b): return -1 return max(len(a), len(b)) A = input() B = input() print(uncommon(A, B))
{ "input": [ "abcd\ndefgh\n", "a\na\n", "abb\nabb\n", "abcde\nbbcde\n", "abc\ncba\n", "aaa\naaa\n", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nbbbbbbbbbbbbbbbbbbb\n", "mmmmm\nmnmmm\n", "mo\nmomo\n", "abcdefgh\nabdcefgh\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem. ...
789_E. The Great Mixing_11530
Sasha and Kolya decided to get drunk with Coke, again. This time they have k types of Coke. i-th type is characterised by its carbon dioxide concentration <image>. Today, on the party in honour of Sergiy of Vancouver they decided to prepare a glass of Coke with carbon dioxide concentration <image>. The drink should als...
from collections import deque MAX_A = 1000 def main(): n, k = map(int, input().split()) a = set(int(x) - n for x in input().split()) visited = [False] * (2 * MAX_A + 1) visited[n] = True Q = deque() Q.append((n, 0)) result = None while Q: u, l = Q.popleft() l += 1 ...
{ "input": [ "50 2\n100 25\n", "400 4\n100 300 450 500\n", "852 10\n668 1000 1000 1000 1000 1000 1000 639 213 1000\n", "314 15\n160 769 201 691 358 724 248 47 420 432 667 601 596 370 469\n", "834 10\n921 995 1000 285 1000 166 1000 999 991 983\n", "971 108\n706 706 991 706 988 997 996 997 991 9...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Sasha and Kolya decided to get drunk with Coke, again. This time they have k types of Coke. i-th type is characterised by its carbon dioxide concentration <image>. Today, on the party...
810_B. Summer sell-off_11534
Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant. Shop, where Noora is working, has a plan on the following n days. For each day sales manager...
def get_line(): return [int(s) for s in input().strip().split()] n, f = get_line() kl = [] for _ in range(n): kl.append(get_line()) def get_extra(k, l): if l <= k: return 0 if l <= 2*k: return l - k return k extras = [get_extra(k, l) for k, l in kl] if f == 0: extras_sum = ...
{ "input": [ "4 1\n0 2\n0 3\n3 5\n0 6\n", "4 2\n2 1\n3 5\n2 3\n1 5\n", "2 1\n2 4\n4 4\n", "2 1\n10 11\n9 20\n", "2 1\n3 7\n5 7\n", "2 1\n1 2\n1000 1000\n", "2 1\n14 28\n15 28\n", "3 1\n10 11\n12 13\n8 10\n", "2 1\n5 7\n6 7\n", "3 1\n1 4\n2 4\n3 4\n", "2 1\n7 8\n3 6\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money...
856_A. Set Theory_11540
Masha and Grisha like studying sets of positive integers. One day Grisha has written a set A containing n different integers ai on a blackboard. Now he asks Masha to create a set B containing n different integers bj such that all n2 integers that can be obtained by summing up ai and bj for all possible pairs of i and ...
from random import randint def solve(): n, a = int(input()), list(map(int, input().split())) bb, ab = set(), set() while True: b = randint(1, 1000000) for i in a: if i + b in ab: break else: bb.add(b) if len(bb) == n: break for i in a: ab.add(b + i) print('YES') print(' '.join(map(str...
{ "input": [ "3\n3\n1 10 100\n1\n1\n2\n2 4\n", "1\n100\n74 14 24 45 22 9 49 78 79 20 60 1 31 91 32 39 90 5 42 57 30 58 64 68 12 11 86 8 3 38 76 17 98 26 85 92 56 65 89 66 36 87 23 67 13 48 15 47 81 73 63 50 34 93 82 44 77 69 96 100 41 19 35 16 88 27 99 40 62 95 70 18 46 21 53 59 37 6 61 71 2 4 52 28 97 25 29 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Masha and Grisha like studying sets of positive integers. One day Grisha has written a set A containing n different integers ai on a blackboard. Now he asks Masha to create a set B c...
883_A. Automatic Door_11544
There is an automatic door at the entrance of a factory. The door works in the following way: * when one or several people come to the door and it is closed, the door immediately opens automatically and all people immediately come inside, * when one or several people come to the door and it is open, all people im...
BigNum = 10 ** 20 n, m, a, d = map(int, input().split(' ')) ts = [0] + list(map(int, input().split(' '))) + [BigNum] def empsInRange(l, r): em1 = l // a + 1 em2 = r // a return (em1, min(em2, n)) empDoorGroup = d // a + 1 def moveEmps(emps, last): em1, em2 = emps if em1 > em2: return las...
{ "input": [ "1 1 3 4\n7\n", "4 3 4 2\n7 9 11\n", "100 30 36 47\n44 155 275 390 464 532 1186 1205 1345 1349 1432 1469 1482 1775 1832 1856 1869 2049 2079 2095 2374 2427 2577 2655 2792 2976 3020 3317 3482 3582\n", "100 20 49 52\n224 380 690 1585 1830 1973 2490 2592 3240 3341 3406 3429 3549 3560 3895 394...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There is an automatic door at the entrance of a factory. The door works in the following way: * when one or several people come to the door and it is closed, the door immediately o...
906_A. Shockers_11548
Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected letter, he receives an electric shock. He can make guesses which letter is selected, but for eac...
n = int(input()) alphabet = "abcdefghijklmnopqrstuvwxyz" possible = set(alphabet[i] for i in range(len(alphabet))) i = 0 while i < n: signal, word = input().split() if signal == '!': possible = possible & set(word[j] for j in range(len(word))) elif signal == '.' or (signal == '?' and i != n-1): possible =...
{ "input": [ "8\n! hello\n! codeforces\n? c\n. o\n? d\n? h\n. l\n? e\n", "7\n! ababahalamaha\n? a\n? b\n? a\n? b\n? a\n? h\n", "5\n! abc\n. ad\n. b\n! cd\n? c\n", "3\n. abcdefghijklmnopqrstuvwxy\n? a\n? z\n", "3\n. abcdefghijklmnopqrstuvwxy\n! z\n? z\n", "1\n? q\n", "4\n! abcd\n! cdef\n? d...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pron...
926_C. Is This a Zebra?_11552
A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of n zeros and ones, where 0 means that the corresponding column is all white, and 1 means...
n = int(input()) a = input().split() for j in range(n): a[j] = int(a[j]) i = 1 last = a[0] count = 1; while (i < n and last == a[i]): i+=1 count+=1 if (i < n): last = a[i] buf = 1 i += 1 flag = 1 while (i < n): if (last == a[i]): buf += 1 else: if (count != buf): flag = 0 break else: ...
{ "input": [ "9\n1 1 0 1 1 0 1 1 0\n", "8\n1 1 1 0 0 0 1 1\n", "7\n0 0 0 1 1 1 1\n", "9\n0 0 0 1 1 1 0 0 0\n", "5\n1 1 1 1 1\n", "7\n0 0 0 1 1 1 0\n", "11\n0 1 0 1 0 1 0 0 0 1 0\n", "5\n1 0 0 0 1\n", "100\n1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. ...
955_A. Feed the cat_11556
After waking up at hh:mm, Andrew realised that he had forgotten to feed his only cat for yet another time (guess why there's only one cat). The cat's current hunger level is H points, moreover each minute without food increases his hunger by D points. At any time Andrew can visit the store where tasty buns are sold (y...
h,m = map(int,input().split()) hu,d,c,n = map(int,input().split()) if h >= 20: if hu % n != 0: hu = hu + n-hu%n print((hu*4*c)/(5*n)) else: lhu = hu p = float('inf') if hu % n != 0: hu = hu + n-hu%n p = min(p,hu*c/n) #print(p) hu = lhu+((19-h)*60+(60-m))*d if hu % n !...
{ "input": [ "19 00\n255 1 100 1\n", "17 41\n1000 6 15 11\n", "00 10\n33077 21 40 22\n", "17 31\n9603 53 73 74\n", "01 38\n70542 27 74 26\n", "14 53\n76530 92 4 22\n", "18 06\n88580 22 35 59\n", "10 44\n66449 67 90 83\n", "00 00\n100000 100 100 100\n", "20 58\n93398 43 86 99\n"...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: After waking up at hh:mm, Andrew realised that he had forgotten to feed his only cat for yet another time (guess why there's only one cat). The cat's current hunger level is H points,...
981_C. Useful Decomposition_11560
Ramesses knows a lot about problems involving trees (undirected connected graphs without cycles)! He created a new useful tree decomposition, but he does not know how to construct it, so he asked you for help! The decomposition is the splitting the edges of the tree in some simple paths in such a way that each two pa...
n = int(input()) flag = True f = [0] * (n - 1) t = [0] * (n - 1) co = [0] * n for i in range(n - 1): f[i], t[i] = map(int, input().split()) co[f[i] - 1] += 1 co[t[i] - 1] += 1 mid = 0 en = [] for i in range(n): if co[i] == 1: en.append(i + 1) elif co[i] > 2: if mid == 0: ...
{ "input": [ "6\n1 2\n2 3\n3 4\n2 5\n3 6\n", "4\n1 2\n2 3\n3 4\n", "5\n1 2\n1 3\n1 4\n1 5\n", "9\n1 2\n1 3\n1 4\n1 5\n1 6\n6 7\n7 8\n7 9\n", "8\n1 2\n1 3\n1 4\n1 8\n7 8\n6 8\n5 8\n", "3\n2 3\n1 2\n", "2\n1 2\n", "9\n1 2\n2 3\n1 4\n1 5\n1 6\n6 7\n7 8\n7 9\n", "3\n3 3\n1 2\n", "5...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Ramesses knows a lot about problems involving trees (undirected connected graphs without cycles)! He created a new useful tree decomposition, but he does not know how to construct it...
p02552 AtCoder Beginner Contest 178 - Not_11574
Given is an integer x that is greater than or equal to 0, and less than or equal to 1. Output 1 if x is equal to 0, or 0 if x is equal to 1. Constraints * 0 \leq x \leq 1 * x is an integer Input Input is given from Standard Input in the following format: x Output Print 1 if x is equal to 0, or 0 if x is equal ...
x = int(input()) print(x * -1 + 1)
{ "input": [ "1", "0", "000", "000" ], "output": [ "0", "1", "1\n", "1\n" ] }
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Given is an integer x that is greater than or equal to 0, and less than or equal to 1. Output 1 if x is equal to 0, or 0 if x is equal to 1. Constraints * 0 \leq x \leq 1 * x is an ...
p02683 AtCoder Beginner Contest 167 - Skill Up_11578
Constraints * All values in input are integers. * 1\leq N, M\leq 12 * 1\leq X\leq 10^5 * 1\leq C_i \leq 10^5 * 0\leq A_{i, j} \leq 10^5 Input Input is given from Standard Input in the following format: N M X C_1 A_{1,1} A_{1,2} \cdots A_{1,M} C_2 A_{2,1} A_{2,2} \cdots A_{2,M} \vdots C_N A_{N,1} A_{N,2} \cdots A_{...
from itertools import combinations n, m, x = map(int, input().split()) ca = [list(map(int, input().split())) for _ in range(n)] ans = 10**9 for i in range(1,n+1): for j in combinations(ca, i): s = [0]*(m+1) for k in j: for l in range(m+1): s[l] += k[l] if min(s[1:]) >= x: ans = min(an...
{ "input": [ "3 3 10\n100 3 1 4\n100 1 5 9\n100 2 6 5", "3 3 10\n60 2 2 4\n70 8 7 9\n50 2 3 9", "8 5 22\n100 3 7 5 3 1\n164 4 5 2 7 8\n334 7 2 7 2 9\n234 4 7 2 8 2\n541 5 4 3 3 6\n235 4 8 6 9 7\n394 3 6 1 6 2\n872 8 4 3 7 2", "2 3 10\n100 3 1 4\n100 1 5 9\n100 2 6 5", "3 3 10\n60 2 2 4\n70 8 7 2\n...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Constraints * All values in input are integers. * 1\leq N, M\leq 12 * 1\leq X\leq 10^5 * 1\leq C_i \leq 10^5 * 0\leq A_{i, j} \leq 10^5 Input Input is given from Standard Input in ...
p02811 AtCoder Beginner Contest 150 - 500 Yen Coins_11582
Takahashi has K 500-yen coins. (Yen is the currency of Japan.) If these coins add up to X yen or more, print `Yes`; otherwise, print `No`. Constraints * 1 \leq K \leq 100 * 1 \leq X \leq 10^5 Input Input is given from Standard Input in the following format: K X Output If the coins add up to X yen or more, prin...
k,x=map(int,input().split());print('YNeos'[500*k<x::2])
{ "input": [ "1 501", "4 2000", "2 900", "0 501", "4 1282", "0 900", "0 588", "8 1282", "0 50", "0 192", "13 1282", "-1 50", "0 379", "10 1282", "0 88", "1 379", "10 333", "0 165", "2 379", "10 53", "1 165", "0 246", "10 96", ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Takahashi has K 500-yen coins. (Yen is the currency of Japan.) If these coins add up to X yen or more, print `Yes`; otherwise, print `No`. Constraints * 1 \leq K \leq 100 * 1 \leq X...
p02948 AtCoder Beginner Contest 137 - Summer Vacation_11586
There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it. You can take and complete at most one of these jobs in a day. However, you cannot retake a job that you have already done. Find the maximum total reward that you can ea...
import heapq N, M = map(int,input().split()) J = [[] for k in range(M+1)] for k in range(N): A, B = map(int,input().split()) if A <= M: J[A].append(B) Q = [] ans = 0 for d in range(1,M+1): for e in J[d]: heapq.heappush(Q,-e) if len(Q) > 0: ans += -heapq.heappop(Q) print(ans)
{ "input": [ "5 3\n1 2\n1 3\n1 4\n2 1\n2 3", "1 1\n2 1", "3 4\n4 3\n4 1\n2 2", "5 3\n1 2\n1 3\n1 4\n1 1\n2 3", "3 4\n4 3\n4 1\n3 2", "5 3\n1 2\n1 0\n1 4\n1 1\n2 3", "1 3\n1 2\n1 0\n1 4\n1 1\n2 3", "3 4\n4 3\n3 0\n3 4", "3 4\n4 3\n3 1\n2 4", "3 0\n4 3\n3 1\n2 4", "1 1\n1 21\...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it. You can take and complete at most...
p03229 Tenka1 Programmer Beginner Contest - Align_11591
You are given N integers; the i-th of them is A_i. Find the maximum possible sum of the absolute differences between the adjacent elements after arranging these integers in a row in any order you like. Constraints * 2 \leq N \leq 10^5 * 1 \leq A_i \leq 10^9 * All values in input are integers. Input Input is given f...
N = int(input()) A = sorted([int(input()) for i in range(N)]) if N % 2 == 0: print(2 * (sum(A[N // 2:]) - sum(A[:N // 2])) - (A[N // 2] - A[N // 2 - 1])) else: print(2 * (sum(A[N // 2 + 1:]) - sum(A[:N // 2])) - min(A[N // 2] - A[N // 2 - 1], A[N // 2 + 1] - A[N // 2]))
{ "input": [ "3\n5\n5\n1", "6\n3\n1\n4\n1\n5\n9", "5\n6\n8\n1\n2\n3", "3\n5\n6\n1", "6\n6\n1\n4\n1\n5\n9", "5\n6\n8\n1\n1\n3", "3\n5\n3\n1", "6\n6\n1\n4\n1\n1\n9", "5\n6\n4\n1\n1\n3", "3\n0\n3\n1", "6\n6\n1\n7\n1\n1\n9", "5\n6\n4\n1\n2\n3", "3\n0\n0\n1", "6\n6\n...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given N integers; the i-th of them is A_i. Find the maximum possible sum of the absolute differences between the adjacent elements after arranging these integers in a row in a...
p03377 AtCoder Beginner Contest 094 - Cats and Dogs_11595
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are exactly X cats among these A + B animals. Constraints * 1 \leq A \leq 100 * 1 \leq B \leq 100 * 1 \leq X \leq 200 * All values in input...
a,b,x=map(int,input().split()) print("YES" if a+b-x>=0 and x>=a else "NO")
{ "input": [ "2 2 6", "3 5 4", "5 3 2", "2 0 6", "2 5 4", "5 3 3", "2 -1 6", "4 5 4", "2 3 3", "2 0 0", "5 5 4", "2 3 5", "2 0 1", "2 5 8", "2 3 9", "3 0 1", "2 2 8", "4 3 9", "1 0 1", "2 0 8", "0 3 9", "3 0 2", "2 -1 8", ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs. Determine if it is possible that there are ...
p03544 AtCoder Beginner Contest 079 - Lucas Number_11599
It is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers. You are given an integer N. Find the N-th Lucas number. Here, the i-th Lucas number L_i is defined as follows: * L_0=2 * L_1=1 * L_i=L_{i-1}+L_{i-2} (i≥2) Constraints * 1≤N≤86 * It is guaranteed that the answer is less than 10^{18}. ...
n = int(input()) l = [2, 1] for i in range(n-1): l.append(l[i]+l[i+1]) print(l[-1])
{ "input": [ "5", "86", "1", "2", "4", "3", "30", "49", "6", "8", "7", "58", "9", "13", "14", "55", "12", "19", "20", "16", "24", "21", "10", "28", "56", "17", "27", "50", "81", "34", "44", ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: It is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers. You are given an integer N. Find the N-th Lucas number. Here, the i-th Lucas number L_i is defined ...
p03698 AtCoder Beginner Contest 063 - Varied_11603
You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different. Constraints * 2 ≤ |S| ≤ 26, where |S| denotes the length of S. * S consists of lowercase English letters. Input Input is given from Standard Input in the following format: S Output If all ...
s=input();print("yneos"[len(set(s))<len(s)::2])
{ "input": [ "uncopyrightable", "different", "no", "uncopyrightacle", "np", "tnereffid", "elcathgirypocnu", "dnereffit", "mp", "elcathgirxpocnu", "enereffit", "pm", "elcathgiqxpocnu", "emereffit", "pl", "elcathgiqxcopnu", "fmereffit", "ol", "...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different. Constraints * 2 ≤ |S| ≤ 26, where |S| denotes the length o...
p03853 AtCoder Beginner Contest 049 - Thin_11607
There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either `.` or `*`. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}. Extend this image vertically so that its height is doubled. That is, p...
h,w=map(int,input().split()) for i in range(h): a=input() print('{}\n{}'.format(a,a))
{ "input": [ "9 20\n.....***....***.....\n....*...*..*...*....\n...*.....**.....*...\n...*.....*......*...\n....*.....*....*....\n.....**..*...**.....\n.......*..*.*.......\n........**.*........\n.........**.........", "2 2\n*.\n.*", "1 4\n***.", "9 20\n.....***....***.....\n....*...*..*...*....\n...*...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either `.` or `*`. The character representing the pixel at the i-th row from ...
p04020 AtCoder Grand Contest 003 - Simplified mahjong_11611
Snuke has a large collection of cards. Each card has an integer between 1 and N, inclusive, written on it. He has A_i cards with an integer i. Two cards can form a pair if the absolute value of the difference of the integers written on them is at most 1. Snuke wants to create the maximum number of pairs from his card...
a = int(input()) count = 0 mod = 0 for i in range(a): b = int(input()) if b == 0: mod = 0 c = b + mod if not c==0: count += c//2 mod = c%2 print(count)
{ "input": [ "8\n2\n0\n1\n6\n0\n8\n2\n1", "4\n4\n0\n3\n2", "8\n2\n0\n1\n6\n1\n8\n2\n1", "4\n4\n0\n3\n1", "8\n2\n0\n1\n9\n1\n8\n2\n1", "4\n3\n0\n3\n1", "4\n0\n0\n3\n1", "8\n1\n0\n1\n9\n1\n5\n2\n1", "8\n1\n0\n1\n1\n1\n5\n1\n1", "8\n0\n0\n1\n4\n1\n5\n1\n1", "8\n0\n0\n1\n4\n1\n...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Snuke has a large collection of cards. Each card has an integer between 1 and N, inclusive, written on it. He has A_i cards with an integer i. Two cards can form a pair if the absolu...
p00104 Magical Tiles_11615
There is a magic room in a homestead. The room is paved with H × W tiles. There are five different tiles: * Tile with a east-pointing arrow * Tile with a west-pointing arrow * Tile with a south-pointing arrow * Tile with a north-pointing arrow * Tile with nothing Once a person steps onto a tile which has an arrow, ...
while True: h,w = map(int,input().split()) if (h,w) == (0,0): break l = [] for i in range(h): l.append(input()) x,y = 0,0 l1 = [] while True: if (x,y) in l1: print('LOOP') break l1.append((x,y)) pos = l[y][x] if pos == '.': print(x,y) break elif pos == '...
{ "input": [ "10 10\n>>>v..>>>v\n...v..^..v\n>>>>>>^..v\n.........v\n.v", "10 10\n>>>v..>>>v\n...v..^..v\n>>>>>>^..v\n.........v\n.v<<<<...v\n.v.v.^...v\n.v.v.^<<<<\n.v.v.....v\n.v...^...v\n.>>>>^....\n6 10\n>>>>>>>>>v\n.........v\n.........v\n>>>>v....v\n^...v....v\n^<<<<<<<<<\n0 0", "10 10\n>>>.v.>>>v\n...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There is a magic room in a homestead. The room is paved with H × W tiles. There are five different tiles: * Tile with a east-pointing arrow * Tile with a west-pointing arrow * Tile w...
p00238 Time to Study_11619
Based on the information of the time when study started and the time when study ended, check whether the total time studied in one day is t or more, and if not, create a program to find the shortage time. Time is one unit per hour, and minutes and seconds are not considered. The time is expressed in 24-hour notation in...
import sys f = sys.stdin while True: t = int(f.readline()) if t == 0: break n = int(f.readline()) sf = (map(int, f.readline().split()) for _ in range(n)) rest = t - sum(f - s for s, f in sf) print('OK' if rest <= 0 else rest)
{ "input": [ "10\n3\n6 11\n12 15\n18 22\n14\n2\n6 11\n13 20\n0", "10\n3\n6 11\n12 15\n18 22\n14\n2\n6 14\n13 20\n0", "10\n3\n8 11\n12 19\n18 38\n14\n2\n6 14\n5 6\n0", "10\n3\n8 11\n12 19\n18 38\n8\n2\n6 6\n5 6\n0", "10\n3\n6 11\n12 15\n18 22\n14\n2\n6 1\n13 20\n0", "10\n3\n6 11\n12 15\n34 22\n...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Based on the information of the time when study started and the time when study ended, check whether the total time studied in one day is t or more, and if not, create a program to fi...
p00614 ICPC: Ideal Coin Payment and Change_11624
Taro, a boy who hates any inefficiencies, pays coins so that the number of coins to be returned as change is minimized in order to do smoothly when he buys something. One day, however, he doubt if this way is really efficient. When he pays more number of coins, a clerk consumes longer time to find the total value. May...
price = [1, 5, 10, 50, 100, 500] while True: values = list(map(int, input().split())) p, n = values[0], values[1:] ans = 1e100 if p == 0: break p_sum = sum(map(lambda s: s[0] * s[1], zip(price, n))) for change in range(1000): total = p + change pay = [0] * 6 fo...
{ "input": [ "123 3 0 2 0 1 1\n999 9 9 9 9 9 9\n0 0 0 0 0 0 0", "123 3 0 2 0 1 1\n999 9 9 9 9 9 10\n0 0 0 0 0 0 0", "123 3 1 2 0 1 1\n1315 8 9 9 9 14 10\n0 0 0 0 0 0 0", "105 3 1 2 1 2 1\n999 9 9 9 1 15 10\n0 0 0 0 0 0 0", "123 5 1 2 2 0 1\n999 21 9 9 1 9 10\n0 0 0 0 0 0 0", "105 3 1 2 1 2 1\n...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Taro, a boy who hates any inefficiencies, pays coins so that the number of coins to be returned as change is minimized in order to do smoothly when he buys something. One day, howeve...
p00890 Test Case Tweaking_11628
You are a judge of a programming contest. You are preparing a dataset for a graph problem to seek for the cost of the minimum cost path. You've generated some random cases, but they are not interesting. You want to produce a dataset whose answer is a desired value such as the number representing this year 2010. So you ...
import sys from heapq import heappush, heappop readline = sys.stdin.buffer.readline write = sys.stdout.write def solve(): N, M, C = map(int, readline().split()) if N == M == C == 0: return False G = [[] for i in range(N)] for i in range(M): f, t, c = map(int, readline().split()); f -= 1...
{ "input": [ "3 3 3\n1 2 3\n2 3 3\n1 3 8\n12 12 2010\n1 2 0\n2 3 3000\n3 4 0\n4 5 3000\n5 6 3000\n6 12 2010\n2 7 100\n7 8 200\n8 9 300\n9 10 400\n10 11 500\n11 6 512\n10 18 1\n1 2 9\n1 3 2\n1 4 6\n2 5 0\n2 6 10\n2 7 2\n3 5 10\n3 6 3\n3 7 10\n4 7 6\n5 8 10\n6 8 2\n6 9 11\n7 9 3\n8 9 9\n8 10 8\n9 10 1\n8 2 1\n0 0 0...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are a judge of a programming contest. You are preparing a dataset for a graph problem to seek for the cost of the minimum cost path. You've generated some random cases, but they a...
p01293 Whist_11634
Whist is a game played by four players with a standard deck of playing cards. The players seat around a table, namely, in north, east, south, and west. This game is played in a team-play basis: the players seating opposite to each other become a team. In other words, they make two teams we could call the north-south te...
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 998244353 dd = [(0,-1),(1,0),(0,1),(-1,0)] ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)] def LI(): return [int(x) for x in sys.stdi...
{ "input": [ "H\n4C 8H QS 5D JD KS 8S AH 6H 7H 3S 7S 6D\nTC JC JS KD AC QC QD 2H QH 3H 3C 7C 4D\n6C 9C AS TD 5H 6S 5S KH TH AD 9S 8D 2D\n8C 5C 2S 7D KC 4S TS JH 4H 9H 2C 9D 3D\nD\n8D 9D 9S QS 4H 5H JD JS 9H 6S TH 6H QH\nQD 9C 5S 7S 7H AC 2D KD 6C 3D 8C TC 7C\n5D QC 3S 4S 3H 3C 6D KS JC AS 5C 8H TS\n4D 4C 8S 2S 2H...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Whist is a game played by four players with a standard deck of playing cards. The players seat around a table, namely, in north, east, south, and west. This game is played in a team-p...
p01462 Network Reliability_11637
An undirected graph is given. Each edge of the graph disappears with a constant probability. Calculate the probability with which the remained graph is connected. Input The first line contains three integers N (1 \leq N \leq 14), M (0 \leq M \leq 100) and P (0 \leq P \leq 100), separated by a single space. N is the...
from collections import deque import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): N, M, P = map(int, readline().split()) G = [[] for i in range(N)] for i in range(M): u, v = map(int, readline().split()) G[u-1].append(v-1) G[v-1].append(u-1) N1 = 1 << N ...
{ "input": [ "3 3 10\n1 2\n2 3\n3 1", "4 5 50\n1 2\n2 3\n3 4\n4 1\n1 3", "3 3 50\n1 2\n2 3\n3 1", "4 5 50\n1 2\n2 3\n3 4\n4 2\n1 3", "3 0 50\n1 2\n2 3\n3 1", "3 3 10\n1 2\n3 3\n3 1", "4 5 50\n2 2\n2 3\n3 4\n4 1\n1 3", "1 0 31\n1 2\n2 3\n3 0", "2 3 10\n1 2\n3 3\n3 1", "3 0 31\n1...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: An undirected graph is given. Each edge of the graph disappears with a constant probability. Calculate the probability with which the remained graph is connected. Input The first ...
p01908 Password_11644
problem AOR Ika wants to create a strong password that consists only of lowercase letters. AOR Ika-chan, who was given an example of $ N $ of dangerous passwords by a friend, decided to create a password that meets all of the following conditions. 1. The length is at least one character. 2. Different from any contigu...
# coding:utf-8 # AOJ 2808 RUPC 2017 Password import itertools INF = float('inf') MOD = 10 ** 9 + 7 def inpl(): return list(map(int, input().split())) class RollingHash: def __init__(self, s, base, mod): self.s = s self.length = length = len(s) self.base = base self.mod = mod ...
{ "input": [ "5\npassword\nlogin\nadmin\nroot\nmaster", "5\npassword\nlogin\nnimda\nroot\nmaster", "5\nbraprswp\nlofho\nojdma\nsnnt\nfuarsm", "5\nbraprsxp\noofhk\nojcma\nsnnt\nfuarsm", "5\napssword\nlogin\nnimda\nroot\nmaster", "5\nopssward\nlogin\nnimda\nroot\nmaster", "5\ndrawsspo\nlogin...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: problem AOR Ika wants to create a strong password that consists only of lowercase letters. AOR Ika-chan, who was given an example of $ N $ of dangerous passwords by a friend, decided...
p02189 Min Element_11648
Min Element Given the sequence a_1, a_2, .., a_N. Find the minimum number in this sequence. If the minimum value is in more than one place, answer the one with the lowest number. input N a_1 a_2 ... a_N output Output the smallest i such that a_i is the minimum value in the sequence. Constraint * 1 \ leq N \ ...
N = int(input()) a = [int(x) for x in input().split()] print(a.index(min(a)) + 1)
{ "input": [ "6\n8 6 9 1 2 1", "6\n8 6 9 0 2 1", "6\n8 6 9 1 2 0", "6\n3 33 0 2 10 0", "6\n3 18 3 4 0 0", "6\n6 0 9 1 2 1", "6\n1 6 9 1 2 0", "6\n1 6 9 0 2 0", "6\n8 3 9 1 2 1", "6\n6 6 9 0 2 1", "6\n8 6 9 2 2 0", "6\n1 6 9 1 3 0", "6\n2 6 9 0 2 0", "6\n8 3 9 1 ...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Min Element Given the sequence a_1, a_2, .., a_N. Find the minimum number in this sequence. If the minimum value is in more than one place, answer the one with the lowest number. ...
p02343 Disjoint Set: Union Find Tree_11652
Write a program which manipulates a disjoint set S = {S1, S2, . . . , Sk}. First of all, the program should read an integer n, then make a disjoint set where each element consists of 0, 1, ... n−1 respectively. Next, the program should read an integer q and manipulate the set for q queries. There are two kinds of que...
# class UnionFind: # # def __init__(self,n): # self.roots = range(n) # # def def root(i): if par[i] == i: return i par[i]=root(par[i]) return par[i] def unite(x,y): xr = root(x) yr = root(y) par[yr] = xr def same(x,y): return root(x)==root(y) n,q = map(int,inpu...
{ "input": [ "5 12\n0 1 4\n0 2 3\n1 1 2\n1 3 4\n1 1 4\n1 3 2\n0 1 3\n1 2 4\n1 3 0\n0 0 4\n1 0 2\n1 3 0", "5 12\n0 2 4\n0 2 3\n1 1 2\n1 3 4\n1 1 4\n1 3 2\n0 1 3\n1 2 4\n1 3 0\n0 0 4\n1 0 2\n1 3 0", "5 12\n0 1 4\n0 2 3\n1 1 2\n1 3 4\n1 1 4\n1 2 2\n0 1 3\n1 2 4\n1 3 0\n0 0 4\n1 0 2\n1 3 0", "5 12\n0 1 4\...
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 disjoint set S = {S1, S2, . . . , Sk}. First of all, the program should read an integer n, then make a disjoint set where each element consists of...
p02476 Remainder of Big Integers_11656
Remainder of Big Integers Given two integers $A$ and $B$, compute the remainder of $\frac{A}{B}$. Input Two integers $A$ and $B$ separated by a space character are given in a line. Output Print the remainder in a line. Constraints * $0 \leq A, B \leq 10^{1000}$ * $B \ne 0$ Sample Input 1 5 8 Sample Output...
import math n, m = map(int, input().split()) print(n % m)
{ "input": [ "5 8", "5 3", "9 3", "9 6", "16 6", "4 3", "5 7", "6 7", "8 13", "10 16", "11 12", "18 11", "9 54", "12 47", "14 28", "9 1", "5 1", "4 1", "4 2", "6 2", "8 2", "8 3", "0 8", "5 5", "10 6", "18 1", ...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Remainder of Big Integers Given two integers $A$ and $B$, compute the remainder of $\frac{A}{B}$. Input Two integers $A$ and $B$ separated by a space character are given in a line....
1020_C. Elections_11666
As you know, majority of students and teachers of Summer Informatics School live in Berland for the most part of the year. Since corruption there is quite widespread, the following story is not uncommon. Elections are coming. You know the number of voters and the number of parties — n and m respectively. For each vote...
import sys f=sys.stdin out=sys.stdout n,m=map(int,f.readline().rstrip('\r\n').split()) cos={} cost=[] nvot=[0 for i in range(m+1)] party=[[] for i in range(m+1)] for i in range(n): p,c=map(int,f.readline().rstrip('\r\n').split()) if p!=1: if c in cos: cos[c]+=1 else: cos[c]=1 cost.append(c) party[p...
{ "input": [ "1 2\n1 100\n", "5 5\n2 100\n3 200\n4 300\n5 800\n5 900\n", "5 5\n2 100\n3 200\n4 300\n5 400\n5 900\n", "1 3000\n2006 226621946\n", "10 2\n1 1\n1 1\n1 1\n1 1\n1 1\n2 1\n2 1\n2 1\n2 1\n2 1\n", "10 10\n1 73\n2 8\n3 88\n1 5\n2 100\n1 29\n1 57\n3 37\n7 46\n3 21\n", "5 5\n1 3\n1 6\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: As you know, majority of students and teachers of Summer Informatics School live in Berland for the most part of the year. Since corruption there is quite widespread, the following st...
1066_D. Boxes Packing_11672
Maksim has n objects and m boxes, each box has size exactly k. Objects are numbered from 1 to n in order from left to right, the size of the i-th object is a_i. Maksim wants to pack his objects into the boxes and he will pack objects by the following algorithm: he takes one of the empty boxes he has, goes from left to...
from sys import stdin input=stdin.readline def check(a,m,mx): t=mx for i in a: if t-i>=0: t-=i else: if m-1>0: m-=1 t=mx-i else: return False return True def f(n,m,mx,a): hi=len(a) lo=0 res=0 while lo<=hi: mid=(lo+hi)//2 if check(a[mid:],m,mx): hi=mid-1 res=n-mid else: lo...
{ "input": [ "5 3 3\n1 2 3 1 1\n", "5 1 4\n4 2 3 4 1\n", "5 2 6\n5 2 1 4 2\n", "5 4 2\n1 2 1 2 1\n", "5 5 5\n5 5 5 5 5\n", "1 1 1\n1\n", "5 4 2\n1 2 2 2 1\n", "1 1 1\n0\n", "5 3 3\n1 2 3 1 2\n", "5 3 3\n1 3 3 1 3\n", "5 1 3\n1 3 3 1 2\n", "1 1 1\n-1\n", "5 3 3\n1 3 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Maksim has n objects and m boxes, each box has size exactly k. Objects are numbered from 1 to n in order from left to right, the size of the i-th object is a_i. Maksim wants to pack ...
1089_G. Guest Student_11676
Berland State University invites people from all over the world as guest students. You can come to the capital of Berland and study with the best teachers in the country. Berland State University works every day of the week, but classes for guest students are held on the following schedule. You know the sequence of se...
t = int(input()) while t: k = int(input()) a = [int(i) for i in input().split()] da = [999] * 8 cnt = sum(a) for i in range(0, 7): if not a[i]: continue tmp_cnt = 0 for j in range(0, 7): x = (i + j) % 7 if not a[x]: continue...
{ "input": [ "3\n2\n0 1 0 0 0 0 0\n100000000\n1 0 0 0 1 0 1\n1\n1 0 0 0 0 0 0\n", "1\n13131313\n1 0 1 0 1 1 1\n", "3\n2\n0 1 0 0 0 0 0\n100000000\n1 0 1 0 1 0 1\n1\n1 0 0 0 0 0 0\n", "1\n13131313\n1 0 1 0 0 1 1\n", "3\n4\n0 1 0 0 0 0 0\n100000000\n1 0 0 0 1 0 1\n1\n1 0 0 0 0 0 0\n", "1\n131313...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Berland State University invites people from all over the world as guest students. You can come to the capital of Berland and study with the best teachers in the country. Berland Sta...
1108_B. Divisors of Two Integers_11680
Recently you have received two positive integer numbers x and y. You forgot them, but you remembered a shuffled list containing all divisors of x (including 1 and x) and all divisors of y (including 1 and y). If d is a divisor of both numbers x and y at the same time, there are two occurrences of d in the list. For ex...
t=int(input()) lis=list(map(int,input().split())) maxnum=max(lis) lis.remove(maxnum) for x in range (1,maxnum//2+1): if maxnum%x==0: lis.remove(x) maxnum2=max(lis) print("{} {}".format(maxnum,maxnum2))
{ "input": [ "10\n10 2 8 1 2 4 1 20 4 5\n", "4\n1 2 53 1\n", "6\n1 58 29 1 2 2\n", "6\n29 29 1 1 58 2\n", "9\n7 49 1 1 98 14 49 7 2\n", "3\n1 2 1\n", "3\n5 1 1\n", "6\n1 2 4 8 1 16\n", "18\n10 1 4 5 20 10 40 16 20 8 2 5 8 40 2 80 1 4\n", "5\n7 49 2 1 1\n", "6\n6 1 3 3 2 1\n...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Recently you have received two positive integer numbers x and y. You forgot them, but you remembered a shuffled list containing all divisors of x (including 1 and x) and all divisors ...
1178_C. Tiles_11688
Bob is decorating his kitchen, more precisely, the floor. He has found a prime candidate for the tiles he will use. They come in a simple form factor — a square tile that is diagonally split into white and black part as depicted in the figure below. <image> The dimension of this tile is perfect for this kitchen, as h...
def powmod(x, k, m): res = 1 s = 1 while s <= k: if k & s: res = res * x % m x = x * x % m s <<= 1 return res m = 998244353 w, h = map(int, input().split()) print(powmod(2, w + h, m))
{ "input": [ "2 4\n", "2 2\n", "2 1\n", "2 3\n", "17 23\n", "2 5\n", "1 1000\n", "3 16\n", "843 134\n", "1000 1000\n", "15 22\n", "1 2\n", "1 1\n", "912 584\n", "432 333\n", "20 10\n", "88 88\n", "1000 122\n", "3 1\n", "4 3\n", "1 5\n...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Bob is decorating his kitchen, more precisely, the floor. He has found a prime candidate for the tiles he will use. They come in a simple form factor — a square tile that is diagonall...
1196_C. Robot Breakout_11692
n robots have escaped from your laboratory! You have to find them as soon as possible, because these robots are experimental, and their behavior is not tested yet, so they may be really dangerous! Fortunately, even though your robots have escaped, you still have some control over them. First of all, you know the locat...
def solve(): n = int(input()) x_d = [-100000, 100000] y_d = [-100000, 100000] robots = [] for i in range(n): robots.append([int(i) for i in input().split(' ')]) for r in robots: x, y, l, u, r, d = r # if l == 0 and r == 0: # if x_d[0] > x or x_d[1] < x: ...
{ "input": [ "4\n2\n-1 -2 0 0 0 0\n-1 -2 0 0 0 0\n3\n1 5 1 1 1 1\n2 5 0 1 0 1\n3 5 1 0 0 0\n2\n1337 1337 0 1 1 1\n1336 1337 1 1 0 1\n1\n3 5 1 1 1 1\n", "4\n2\n-1 -2 0 0 0 0\n-1 -2 0 0 0 0\n3\n1 5 1 1 1 1\n2 5 0 0 0 1\n3 5 1 0 0 0\n2\n1337 1337 0 1 1 1\n1336 1337 1 1 0 1\n1\n3 5 1 1 1 1\n", "4\n2\n-1 -2 0 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: n robots have escaped from your laboratory! You have to find them as soon as possible, because these robots are experimental, and their behavior is not tested yet, so they may be real...
1213_D2. Equalizing by Division (hard version)_11696
The only difference between easy and hard versions is the number of elements in the array. You are given an array a consisting of n integers. In one move you can choose any a_i and divide it by 2 rounding down (in other words, in one move you can set a_i := ⌊(a_i)/(2)⌋). You can perform such an operation any (possibl...
from sys import stdin n, k = [int(i) for i in stdin.readline().strip().split()] a = [int(i) for i in stdin.readline().strip().split()] p = [19 * [0] for _ in range(max(a) + 1)] nums = set() for m in a: for i in range(19): p[m >> i][i] += 1 nums.add(m >> i) if (m >> i) == 0: ...
{ "input": [ "5 3\n1 2 3 3 3\n", "5 3\n1 2 3 4 5\n", "5 3\n1 2 2 4 5\n", "50 7\n199961 199990 199995 199997 199963 199995 199985 199994 199974 199974 199997 199991 199993 199982 199991 199982 199963 200000 199994 199997 199963 199991 199947 199996 199994 199995 199995 199990 199972 199973 199980 19995...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: The only difference between easy and hard versions is the number of elements in the array. You are given an array a consisting of n integers. In one move you can choose any a_i and d...
1278_D. Segment Tree_11704
As the name of the task implies, you are asked to do some work with segments and trees. Recall that a tree is a connected undirected graph such that there is exactly one simple path between every pair of its vertices. You are given n segments [l_1, r_1], [l_2, r_2], ..., [l_n, r_n], l_i < r_i for every i. It is guara...
import sys class segmTree(): def __init__(self, size=None, array=None): if array is not None: size = len(array) N = 1 while N < size: N <<= 1 self.N = N self.tree = [0] * (2*self.N) if array is not None: for i in range(size): ...
{ "input": [ "5\n5 8\n3 6\n2 9\n7 10\n1 4\n", "5\n1 3\n2 4\n5 9\n6 8\n7 10\n", "6\n9 12\n2 11\n1 3\n6 10\n5 7\n4 8\n", "4\n1 2\n3 6\n4 7\n5 8\n", "8\n2 16\n7 13\n12 14\n4 15\n8 9\n1 11\n3 6\n5 10\n", "5\n4 6\n2 5\n3 9\n8 10\n1 7\n", "5\n1 4\n2 5\n3 10\n6 8\n7 9\n", "6\n9 12\n2 3\n6 10\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: As the name of the task implies, you are asked to do some work with segments and trees. Recall that a tree is a connected undirected graph such that there is exactly one simple path ...
1299_A. Anu Has a Function_11708
Anu has created her own function f: f(x, y) = (x | y) - y where | denotes the [bitwise OR operation](https://en.wikipedia.org/wiki/Bitwise_operation#OR). For example, f(11, 6) = (11|6) - 6 = 15 - 6 = 9. It can be proved that for any nonnegative numbers x and y value of f(x, y) is also nonnegative. She would like to r...
t=1 import sys input=sys.stdin.readline while t>0: t-=1 n=int(input()) a=[int(x) for x in input().split()] d={} l=[0 for i in range(40)] for i in range(n): u=bin(a[i])[2:] #print(a[i],"0"*(40-len(u))+u) for k in range(len(u)): if u[k]=='1': l[len(u)-k-1]+=1 a.sort(reverse=True) maxi=-1 #print(l)...
{ "input": [ "1\n13\n", "4\n4 0 11 6\n", "10\n268439624 335544469 2491136 151142938 168395872 536905856 17833986 35939360 617678852 13111553\n", "4\n4 0 11 6\n", "5\n315479581 954336048 124252105 880492165 179952043\n", "10\n268439624 335544469 2491136 151142938 168395872 536905856 17833986 35...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Anu has created her own function f: f(x, y) = (x | y) - y where | denotes the [bitwise OR operation](https://en.wikipedia.org/wiki/Bitwise_operation#OR). For example, f(11, 6) = (11|6...
1321_E. World of Darkraft: Battle for Azathoth_11711
Roma is playing a new expansion for his favorite game World of Darkraft. He made a new character and is going for his first grind. Roma has a choice to buy exactly one of n different weapons and exactly one of m different armor sets. Weapon i has attack modifier a_i and is worth ca_i coins, and armor set j has defense...
# quick input by @c1729 and @pajenegod import io,os input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline from bisect import bisect_right from operator import itemgetter class SegmTree: ''' - increment on interval - get max on interval ''' def __init__(self, size): N = 1 h =...
{ "input": [ "2 3 3\n2 3\n4 7\n2 4\n3 2\n5 11\n1 2 4\n2 1 6\n3 4 6\n", "4 4 5\n5 10\n6 2\n10 3\n9 5\n7 7\n4 3\n9 2\n3 6\n7 1 6\n8 3 2\n2 6 9\n3 8 2\n1 2 9\n", "1 1 1\n1 100\n1 100\n2 2 1\n", "1 2 1\n2 2\n2 1\n2 2\n1 1 1\n", "3 3 3\n6 1010\n9 1153\n9 1159\n9 1150\n7 1058\n9 1159\n7 3 172\n10 3 167\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Roma is playing a new expansion for his favorite game World of Darkraft. He made a new character and is going for his first grind. Roma has a choice to buy exactly one of n different...
1362_D. Johnny and Contribution_11718
Today Johnny wants to increase his contribution. His plan assumes writing n blogs. One blog covers one topic, but one topic can be covered by many blogs. Moreover, some blogs have references to each other. Each pair of blogs that are connected by a reference has to cover different topics because otherwise, the readers ...
import sys try: sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') except: pass input = lambda: sys.stdin.buffer.readline().rstrip() n,m=map(int,input().split()) g=[[] for i in range(n)] for i in range(m): q,w=map(int,input().split()) g[q-1].append(w-1) g[w-1].append(q-1) a=list(map(int,i...
{ "input": [ "5 3\n1 2\n2 3\n4 5\n2 1 2 2 1\n", "3 3\n1 2\n2 3\n3 1\n1 1 1\n", "3 3\n1 2\n2 3\n3 1\n2 1 3\n", "5 10\n1 3\n4 1\n1 2\n1 5\n3 4\n3 2\n5 2\n4 2\n3 5\n4 5\n3 5 2 1 4\n", "4 3\n1 2\n2 3\n3 4\n1 3 3 1\n", "5 3\n1 3\n2 3\n4 2\n1 2 3 1 4\n", "4 4\n1 2\n1 3\n2 4\n3 4\n1 2 2 3\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Today Johnny wants to increase his contribution. His plan assumes writing n blogs. One blog covers one topic, but one topic can be covered by many blogs. Moreover, some blogs have ref...
1382_E. Mastermind_11721
In the game of Mastermind, there are two players — Alice and Bob. Alice has a secret code, which Bob tries to guess. Here, a code is defined as a sequence of n colors. There are exactly n+1 colors in the entire universe, numbered from 1 to n+1 inclusive. When Bob guesses a code, Alice tells him some information about ...
from collections import defaultdict from heapq import heapify, heappop, heappush def solve(): n, s, y = map(int, input().split()) a = input().split() d = defaultdict(list) for i, x in enumerate(a): d[x].append(i) for i in range(1, n + 2): e = str(i) if e not in d: ...
{ "input": [ "7\n5 2 4\n3 1 1 2 5\n5 3 4\n1 1 2 1 2\n4 0 4\n5 5 3 3\n4 1 4\n2 3 2 3\n6 1 2\n3 2 1 1 1 1\n6 2 4\n3 3 2 1 1 1\n6 2 6\n1 1 3 2 1 1\n", "6\n1 0 0\n1\n1 0 0\n2\n1 0 1\n1\n1 0 1\n2\n1 1 1\n1\n1 1 1\n2\n", "7\n5 2 4\n3 1 1 2 5\n5 3 4\n1 1 2 1 2\n4 0 4\n5 5 3 3\n4 1 4\n2 3 2 3\n6 1 2\n3 2 1 1 1 1\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: In the game of Mastermind, there are two players — Alice and Bob. Alice has a secret code, which Bob tries to guess. Here, a code is defined as a sequence of n colors. There are exact...
1425_E. Excitation of Atoms_11724
Mr. Chanek is currently participating in a science fair that is popular in town. He finds an exciting puzzle in the fair and wants to solve it. There are N atoms numbered from 1 to N. These atoms are especially quirky. Initially, each atom is in normal state. Each atom can be in an excited. Exciting atom i requires D_...
n, k = map(int, input().split()) a = list(map(int, input().split())) d = list(map(int, input().split())) pref=[0] for i in range(n): pref.append(pref[-1]+a[i]) if k==0: ans=0 for i in range(1,n+1): ans=max(ans,pref[-1]-pref[i-1]-d[i-1]) print(ans) elif k == 1: best = sum(a[:n-1]) - min(d[:n...
{ "input": [ "6 1\n5 6 7 8 10 2\n3 5 6 7 1 10\n", "4 1\n1 12 13 20\n10 5 4 100\n", "6 1\n1 10 10 5 20 100\n1000000 1 10 10 100 1000000\n", "5 0\n1 1 1 1 1\n10 10 10 10 10\n", "4 3\n1 2 4 8\n5 1 3 5\n", "4 3\n1 2 4 8\n17 15 16 1\n", "6 1\n1 10 10 20 5 100\n1000000 1 10 100 10 1000000\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Mr. Chanek is currently participating in a science fair that is popular in town. He finds an exciting puzzle in the fair and wants to solve it. There are N atoms numbered from 1 to N...
1447_C. Knapsack_11728
You have a knapsack with the capacity of W. There are also n items, the i-th one has weight w_i. You want to put some of these items into the knapsack in such a way that their total weight C is at least half of its size, but (obviously) does not exceed it. Formally, C should satisfy: ⌈ W/2⌉ ≤ C ≤ W. Output the list...
t=int(input()) for h in range(t): n,w=map(int,input().split()) Wt=w arr=[int(x) for x in input().split()] arr3=[ [arr[i],i+1] for i in range(n)] arr3.sort(key= lambda x:x[0],reverse=True) ans=[] sumi=0 for i in range(n): if arr3[i][0] <= w: w-=arr3[i][0] ...
{ "input": [ "3\n1 3\n3\n6 2\n19 8 19 69 9 4\n7 12\n1 1 1 17 1 1 1\n", "2\n1 2000000001\n1000000000\n1 1000000000000000000\n1\n", "3\n1 3\n3\n6 2\n19 8 19 69 9 4\n7 12\n1 1 1 17 1 1 1\n", "1\n1 900000000\n494311454\n", "1\n1 1\n2\n", "1\n1 1\n1\n", "1\n1 2000000001\n1000000000\n", "3\n...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You have a knapsack with the capacity of W. There are also n items, the i-th one has weight w_i. You want to put some of these items into the knapsack in such a way that their total...
1472_C. Long Jumps_11732
Polycarp found under the Christmas tree an array a of n elements and instructions for playing with it: * At first, choose index i (1 ≤ i ≤ n) — starting position in the array. Put the chip at the index i (on the value a_i). * While i ≤ n, add a_i to your score and move the chip a_i positions to the right (i.e. r...
for _ in range(int(input())): n = int(input()) array = list(map(int, input().split())) for i in range(n-1, -1, -1): if i+array[i]<=n-1: array[i] += array[i+array[i]] print(max(array))
{ "input": [ "4\n5\n7 3 1 2 3\n3\n2 1 4\n6\n2 1000 2 3 995 1\n5\n1 1 1 1 1\n", "1\n7\n5 1 1 1 1 14 15\n", "2\n3\n1 1 234872\n3\n1 1 234872\n", "1\n4\n100 1 1 200\n", "1\n21\n5 5 5 5 5 5 5 5 5 5 1 1 1 1 2 5 20 1 1 1 1000000\n", "2\n3\n2 1 234872\n3\n1 1 234872\n", "1\n4\n101 1 1 200\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Polycarp found under the Christmas tree an array a of n elements and instructions for playing with it: * At first, choose index i (1 ≤ i ≤ n) — starting position in the array. Put...
1498_D. Bananas in a Microwave_11736
You have a malfunctioning microwave in which you want to put some bananas. You have n time-steps before the microwave stops working completely. At each time-step, it displays a new operation. Let k be the number of bananas in the microwave currently. Initially, k = 0. In the i-th operation, you are given three paramet...
#!/usr/bin/env python from __future__ import division, print_function import math import os import sys from io import BytesIO, IOBase if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins import ascii, filter, hex, map, oct, zip BASE = int(10**5) def main(): n, m = map...
{ "input": [ "3 20\n1 399999 2\n2 412345 2\n1 1000001 3\n", "3 20\n1 300000 2\n2 400000 2\n1 1000000 3\n", "3 20\n1 100000 1\n2 200000 1\n2 200000 1\n", "1 10000\n1 1000000 20\n", "1 2\n1 1 1\n", "1 2\n1 1 2\n", "1 10000\n2 1000000 10\n", "1 10001\n1 1000000 20\n", "3 20\n1 300000 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You have a malfunctioning microwave in which you want to put some bananas. You have n time-steps before the microwave stops working completely. At each time-step, it displays a new op...
1520_C. Not Adjacent Matrix_11740
We will consider the numbers a and b as adjacent if they differ by exactly one, that is, |a-b|=1. We will consider cells of a square matrix n × n as adjacent if they have a common side, that is, for cell (r, c) cells (r, c-1), (r, c+1), (r-1, c) and (r+1, c) are adjacent to it. For a given number n, construct a squar...
'''Author- Akshit Monga''' from sys import stdin, stdout input = stdin.readline t = int(input()) for _ in range(t): n=int(input()) mat=[[-1 for i in range(n)] for j in range(n)] k=1 for i in range(n): for j in range(n): mat[i][j]=k k+=2 if k>n*n: ...
{ "input": [ "3\n1\n2\n3\n", "3\n1\n2\n3\n", "5\n2\n2\n2\n2\n2\n", "3\n2\n2\n3\n", "5\n2\n2\n3\n2\n2\n", "5\n2\n1\n2\n2\n2\n", "3\n3\n2\n3\n", "3\n2\n2\n5\n", "5\n3\n2\n3\n2\n2\n", "3\n1\n3\n3\n", "5\n2\n2\n1\n2\n2\n", "3\n2\n1\n3\n", "5\n2\n2\n3\n3\n2\n", "3\n3...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: We will consider the numbers a and b as adjacent if they differ by exactly one, that is, |a-b|=1. We will consider cells of a square matrix n × n as adjacent if they have a common si...
154_A. Hometask_11744
Sergey attends lessons of the N-ish language. Each lesson he receives a hometask. This time the task is to translate some sentence to the N-ish language. Sentences of the N-ish language can be represented as strings consisting of lowercase Latin letters without spaces or punctuation marks. Sergey totally forgot about ...
ans = 0 t = [] x = input() y = int(input()) for i in range(y): z = input() t.append(z) #x = codeforces #y = 2 #t = [do, cs] pt = -1 ln = len(x) for i in t: a = i[0] b = i[1] pt = 0 for j in range(ln): ded1=0 ded2=0 if j >= pt: if x[j] in [a,b]: ...
{ "input": [ "ababa\n1\nab\n", "codeforces\n2\ndo\ncs\n", "vefneyamdzoytemupniw\n13\nve\nfg\noi\nan\nck\nwx\npq\nml\nbt\nud\nrz\nsj\nhy\n", "pgpgppgggpbbnnn\n2\npg\nnb\n", "mbmxuuuuxuuuuhhooooxxxuxxxuxuuxuuuxxjvjvjjjjvvvjjjjjvvjvjjjvvvjjvjjvvvjjjvjvvjvjjjjjmmbmbbbbbmbbbbmm\n5\nmb\nho\nxu\njv\nyp\n...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Sergey attends lessons of the N-ish language. Each lesson he receives a hometask. This time the task is to translate some sentence to the N-ish language. Sentences of the N-ish langua...
196_A. Lexicographically Maximum Subsequence_11750
You've got string s, consisting of only lowercase English letters. Find its lexicographically maximum subsequence. We'll call a non-empty string s[p1p2... pk] = sp1sp2... spk(1 ≤ p1 < p2 < ... < pk ≤ |s|) a subsequence of string s = s1s2... s|s|. String x = x1x2... x|x| is lexicographically larger than string y = y1y...
s = input() n = len(s) temp = list(set(s)) x = {} temp = sorted(temp,reverse=True) i = 0 while(i < n ): x[s[i]] = i i +=1 string = "" i = 0 j = 0 while(i< n and j < len(temp)): if i <= x[temp[j]]: if s[i]== temp[j]: string += temp[j] if i== x[temp[j]]: j += 1 if(l...
{ "input": [ "ababba\n", "abbcbccacbbcbaaba\n", "b\n", "abcdeabcd\n", "aza\n", "abcdedcba\n", "aa\n", "zzyzyy\n", "cantouristsolveitlessthaninoneminute\n", "aababb\n", "zz\n", "whyareyoulookingfortestsdoyouhavewa\n", "z\n", "arepretestsstrongforthisproblem\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You've got string s, consisting of only lowercase English letters. Find its lexicographically maximum subsequence. We'll call a non-empty string s[p1p2... pk] = sp1sp2... spk(1 ≤ p1 ...
21_A. Jabber ID_11754
Jabber ID on the national Berland service «Babber» has a form <username>@<hostname>[/resource], where * <username> — is a sequence of Latin letters (lowercase or uppercase), digits or underscores characters «_», the length of <username> is between 1 and 16, inclusive. * <hostname> — is a sequence of word separat...
s = input() if s.count('@') != 1 or s.count('/') > 1: print('NO') exit() p1 = s.find('@') p2 = s.find('/') if p2 == -1: p2 = len(s) import re u = re.compile('(\w){1,16}$') h = re.compile('(\w{1,16}\.)*\w{1,16}$') k1 = h.match(s[p1 + 1 : p2]) k2 = u.match(s[0:p1]) k3 = u.match(s[p2 + 1 : len(s)]) if len(s[p1 + 1...
{ "input": [ "mike@codeforces.com\n", "john.smith@codeforces.ru/contest.icpc/12\n", "@ops\n", "xLEctap0T@22U9W_fA/7iQeJGFu1lSgMZ\n", "lNC9D1L5U@.L!_!CcAOEEx.0z.aiW/S430sbQT\n", "test@test.\n", "kKUXy6@0WefbXz39ywP.Q3r7uF\n", "Cz1U1xjg6iW0U@.97HoVA.YG.Qd.eI.DCXxtibi6HG.GV/0sN\n", "I...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Jabber ID on the national Berland service «Babber» has a form <username>@<hostname>[/resource], where * <username> — is a sequence of Latin letters (lowercase or uppercase), digit...
269_A. Magical Boxes_11760
Emuskald is a well-known illusionist. One of his trademark tricks involves a set of magical boxes. The essence of the trick is in packing the boxes inside other boxes. From the top view each magical box looks like a square with side length equal to 2k (k is an integer, k ≥ 0) units. A magical box v can be put inside a...
from math import * n = int(input()) mx = 0 for i in range(n): k, a = map(int, input().split()) mx = max(mx, 2*k + log2(a)) mx = max(mx, 2*(k+1)) print(int(ceil(mx/2)))
{ "input": [ "2\n0 3\n1 5\n", "1\n0 4\n", "2\n1 10\n2 2\n", "10\n11 69\n7 56\n8 48\n2 56\n12 6\n9 84\n1 81\n4 80\n3 9\n5 18\n", "2\n0 16\n1 4\n", "14\n0 268435456\n1 67108864\n2 16777216\n3 4194305\n4 1048576\n5 262144\n6 65536\n7 16384\n8 4096\n9 1024\n10 256\n11 64\n12 16\n13 4\n", "1\n0...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Emuskald is a well-known illusionist. One of his trademark tricks involves a set of magical boxes. The essence of the trick is in packing the boxes inside other boxes. From the top v...
291_C. Network Mask_11764
The problem uses a simplified TCP/IP address model, please make sure you've read the statement attentively. Polycarpus has found a job, he is a system administrator. One day he came across n IP addresses. Each IP address is a 32 bit number, represented as a group of four 8-bit numbers (without leading zeroes), separat...
def f(t): a, b, c, d = map(int, t.split('.')) return d + (c << 8) + (b << 16) + (a << 24) def g(x): p = [0] * 4 for i in range(4): p[3 - i] = str(x % 256) x //= 256 return '.'.join(p) n, k = map(int, input().split()) t = [f(input()) for i in range(n)] p = [0] * n x = 1 << 31 for i ...
{ "input": [ "5 3\n0.0.0.1\n0.1.1.2\n0.0.2.1\n0.1.1.0\n0.0.2.3\n", "2 1\n255.0.0.1\n0.0.0.2\n", "5 2\n0.0.0.1\n0.1.1.2\n0.0.2.1\n0.1.1.0\n0.0.2.3\n", "12 5\n211.200.83.75\n9.64.213.241\n143.23.121.155\n212.121.142.193\n24.184.86.27\n176.131.70.228\n64.47.67.24\n255.241.229.181\n246.34.183.253\n65.121....
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: The problem uses a simplified TCP/IP address model, please make sure you've read the statement attentively. Polycarpus has found a job, he is a system administrator. One day he came ...
316_D3. PE Lesson_11767
Smart Beaver decided to be not only smart, but also a healthy beaver! And so he began to attend physical education classes at school X. In this school, physical education has a very creative teacher. One of his favorite warm-up exercises is throwing balls. Students line up. Each one gets a single ball in the beginning....
m = 1000000007 n = int(input()) a = map(int, input().split()) t1, t2 = 0, 0 for i in a: if i == 1: t1 += 1 else: t2 += 1 a = [1, 2] for i in range(3, t1+1): a = a[::-1] a[1] = (a[0]+(i-1)*a[1])%m if not t1 or t1 == 1: a[1] = 1 for i in range(t1+1, n+1): a[1] = a[1]*i%m print(a[1])
{ "input": [ "8\n1 2 2 1 2 1 1 2\n", "5\n1 2 2 1 2\n", "10\n2 2 2 2 2 2 2 2 2 2\n", "100\n2 2 2 2 1 1 2 2 1 2 2 1 1 2 2 2 2 2 2 1 1 2 2 2 2 1 2 1 1 2 2 1 2 2 1 2 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 1 2 2 2 2 2 1 2 1 1 2 1 1 2 2 2 2 1 2 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 1 2 2 2 2\n", "2\n...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Smart Beaver decided to be not only smart, but also a healthy beaver! And so he began to attend physical education classes at school X. In this school, physical education has a very c...
33_A. What is for dinner?_11771
In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valerie's distinguishing features is that while eating one crucian she uses only one row of her teeth, the rest of the teeth are "relaxing". ...
n, m, k = list(map(int,input().split())) tooth = [[0,True]] * n for i in range(n): r, c = list(map(int,input().split())) if tooth[r-1][0] > c or tooth[r-1][1] == True: tooth[r-1] = [c,False] ad = 0 for i in tooth: ad += i[0] print(min(ad,k))
{ "input": [ "2 2 13\n1 13\n2 12\n", "4 3 18\n2 3\n1 2\n3 6\n2 3\n", "10 4 14\n2 6\n1 5\n2 8\n2 6\n2 5\n4 1\n4 0\n2 4\n3 4\n1 0\n", "4 2 8\n1 9\n1 10\n1 4\n2 6\n", "1 1 0\n1 3\n", "5 4 8\n4 6\n4 5\n1 3\n2 0\n3 3\n", "4 3 181818\n3 1299\n1 1694\n3 1164\n2 1278\n", "1 1 1000000\n1 100000...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: In one little known, but very beautiful country called Waterland, lives a lovely shark Valerie. Like all the sharks, she has several rows of teeth, and feeds on crucians. One of Valer...
362_C. Insertion Sort_11774
Petya is a beginner programmer. He has already mastered the basics of the C++ language and moved on to learning algorithms. The first algorithm he encountered was insertion sort. Petya has already written the code that implements this algorithm and sorts the given integer zero-indexed array a of size n in the non-decre...
arr = [0 for i in range(5001)] def insertion_sort(n, a): def modify(t): while t > 0: arr[t] += 1 t -= t & (-t) def query(t): res = 0 while t < 5001: res += arr[t] t += t & (-t) return res s = 0 ans = 0 way = 0 f...
{ "input": [ "5\n1 2 3 4 0\n", "5\n4 0 3 1 2\n", "13\n5 11 12 10 3 8 4 0 7 9 6 1 2\n", "3\n2 0 1\n", "8\n1 5 4 0 2 7 3 6\n", "3\n0 2 1\n", "3\n1 0 2\n", "100\n73 98 9 92 43 77 32 2 29 5 58 59 61 17 10 94 60 12 80 16 24 91 8 70 62 99 47 23 78 19 22 30 44 96 63 74 48 18 69 45 33 88 97 11...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Petya is a beginner programmer. He has already mastered the basics of the C++ language and moved on to learning algorithms. The first algorithm he encountered was insertion sort. Pety...
386_A. Second-Price Auction_11778
In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction n bidders place a bid which is price a bidder ready to pay. The auction is closed, that is, each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the auct...
a=int(input()) a=list(map(int,input().split())) ind=a.index(max(a)) a.sort() print(str(ind+1)+' '+str(a[-2]))
{ "input": [ "6\n3 8 2 9 4 14\n", "2\n5 7\n", "3\n10 2 8\n", "3\n30 20 10\n", "3\n3 4 1\n", "3\n30 10 20\n", "100\n2515 3324 7975 6171 4240 1217 4829 5203 8603 6900 3031 4699 4732 6070 4221 3228 6497 7359 9130 4346 4619 1109 3945 5442 3271 16 9711 2045 6410 2301 3406 8125 6003 1892 1260 96...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: In this problem we consider a special type of an auction, which is called the second-price auction. As in regular auction n bidders place a bid which is price a bidder ready to pay. T...
434_A. Ryouko's Memory Note_11784
Ryouko is an extremely forgetful girl, she could even forget something that has just happened. So in order to remember, she takes a notebook with her, called Ryouko's Memory Note. She writes what she sees and what she hears on the notebook, and the notebook became her memory. Though Ryouko is forgetful, she is also bo...
def median(a): if len(a) == 0: return 0 if len(a) % 2 == 1: return a[len(a) // 2] else: return (a[len(a) // 2] + a[(len(a) // 2) - 1]) // 2 def profit(a, old_val): a.sort() med = median(a) sum_old = 0 sum_new = 0 for i in a: sum_old += abs(i - old_val) ...
{ "input": [ "4 6\n1 2 3 4 3 2\n", "10 5\n9 4 3 8 8\n", "5 10\n2 5 2 2 3 5 3 2 1 3\n", "1000 10\n1 1 1 1 1 1000 1000 1000 1000 1000\n", "10 20\n6 3 9 6 1 9 1 9 8 2 7 6 9 8 4 7 1 2 4 2\n", "100000 1\n14542\n", "100000 50\n43104 45692 17950 43454 99127 33540 80887 7990 116 79790 66870 61322 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Ryouko is an extremely forgetful girl, she could even forget something that has just happened. So in order to remember, she takes a notebook with her, called Ryouko's Memory Note. She...
456_C. Boredom_11788
Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence a consisting of n integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it ak) and...
#!/usr/bin/env python3 # -*- coding: utf-8 -*- s=0 n = int(input()) dp=[0]*(10**5+1) sec = [int(x) for x in input().split()] ls = [0]*(10**5+1) for x in sec: ls[x]+=1 dp[1]=ls[1] for i in range(2,10**5+1): dp[i]=max(dp[i-1],dp[i-2]+ls[i]*i) print(dp[10**5])
{ "input": [ "9\n1 2 1 3 2 2 2 2 3\n", "3\n1 2 3\n", "2\n1 2\n", "5\n3 3 4 5 4\n", "10\n8 9 6 5 6 4 10 9 1 4\n", "100\n6 6 8 9 7 9 6 9 5 7 7 4 5 3 9 1 10 3 4 5 8 9 6 5 6 4 10 9 1 4 1 7 1 4 9 10 8 2 9 9 10 5 8 9 5 6 8 7 2 8 7 6 2 6 10 8 6 2 5 5 3 2 8 8 5 3 6 2 1 4 7 2 7 3 7 4 10 10 7 5 4 7 5 10...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it. Given a sequence a consis...
479_A. Expression_11792
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting e...
a1 = int(input()) a2 = int(input()) a3 = int(input()) listValue = [a1*a2*a3, a1*(a2+a3), a1*a2+a3, a1+a2*a3, (a1+a2)*a3, a1+a2+a3] maxValue = listValue[0] for x in listValue: if x > maxValue: maxValue = x print(maxValue)
{ "input": [ "2\n10\n3\n", "1\n2\n3\n", "2\n1\n2\n", "5\n6\n1\n", "10\n10\n10\n", "8\n9\n7\n", "9\n2\n1\n", "6\n7\n1\n", "1\n2\n1\n", "9\n7\n2\n", "1\n9\n1\n", "10\n1\n1\n", "1\n3\n1\n", "2\n6\n1\n", "2\n8\n3\n", "1\n10\n1\n", "4\n2\n10\n", "3\n1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers a, b, c on the blackboar...
501_A. Contest_11796
Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the problem that costs a points and Vasya solved the problem that costs b points. Besides, Misha submitted the problem c minutes after the contes...
a,b,c,d=map(int,input().split()) x=max((3*a//10),(a-(a//250*c))) y=max((3*b//10),(b-((b//250)*d))) # print(x,y) if y>x: print('Vasya') elif x>y: print('Misha') else: print('Tie')
{ "input": [ "1000 1000 1 1\n", "1500 1000 176 177\n", "500 1000 20 30\n", "1250 2000 101 180\n", "3000 3250 16 34\n", "250 3500 0 180\n", "3500 250 0 180\n", "3250 250 175 173\n", "1500 1000 74 177\n", "750 2500 175 178\n", "1750 2250 178 53\n", "1250 2500 100 176\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Misha and Vasya participated in a Codeforces contest. Unfortunately, each of them solved only one problem, though successfully submitted it at the first attempt. Misha solved the prob...
552_B. Vanya and Books_11802
Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the n books should be assigned with a number from 1 to n. Naturally, distinct books should be assigned distinct numbers. Vanya wants to know how many digits he will have to write down as he labels the bo...
n = input() s = len(n) ''' 9 - 1 1 1 1 1 1 1 1 1 90 - 11 11 11 11 11 11 11 11 11 11 ... 11 11 900 - 111 111 111 111 111 111 111 ... 111 111 9000 - 1111 1111 1111 ... 1111 1111 ''' q = 0 if s > 2: for c in range(s-1): v = int('9' + c*'0') q += v*(c+1) k = int(n) - (int('1' + (s-1)*'0') - 1) q += k * s ...
{ "input": [ "13\n", "4\n", "995\n", "100000\n", "10000\n", "99995\n", "100001\n", "1\n", "10001\n", "36123011\n", "290092\n", "10\n", "999999998\n", "35\n", "996\n", "999\n", "999999999\n", "349463\n", "30660\n", "96482216\n", "9999\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Vanya got an important task — he should enumerate books in the library and label each book with its number. Each of the n books should be assigned with a number from 1 to n. Naturally...
579_B. Finding Team Member_11806
There is a programing contest named SnakeUp, 2n people want to compete for it. In order to attend this contest, people need to form teams of exactly two people. You are given the strength of each possible combination of two people. All the values of the strengths are distinct. Every contestant hopes that he can find a...
def main(): mode="filee" if mode=="file":f=open("test.txt","r") if mode=="file":n=int(f.readline()) else:n=int(input()) w=[] for i in range(2,2*n+1): if mode=="file":g=[int(x) for x in f.readline().split()] else:g=[int(x) for x in input().split()] for j in range(1,i): ...
{ "input": [ "2\n6\n1 2\n3 4 5\n", "3\n487060\n3831 161856\n845957 794650 976977\n83847 50566 691206 498447\n698377 156232 59015 382455 626960\n", "3\n8\n1 6\n14 13 15\n4 2 11 9\n12 5 3 7 10\n", "3\n1000000\n999999 999998\n999997 999996 999995\n999994 999993 999992 999991\n999990 999989 999988 999987 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There is a programing contest named SnakeUp, 2n people want to compete for it. In order to attend this contest, people need to form teams of exactly two people. You are given the stre...