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
1428_A. Box is Pull_26450
Wabbit is trying to move a box containing food for the rest of the zoo in the coordinate plane from the point (x_1,y_1) to the point (x_2,y_2). He has a rope, which he can use to pull the box. He can only pull the box if he stands exactly 1 unit away from the box in the direction of one of two coordinate axes. He will...
for i in range(int(input())): x1,y1,x2,y2=map(int,input().split()) q=abs(x1-x2)+abs(y1-y2) print(q if x1==x2 or y1==y2 else q+2)
{ "input": [ "2\n1 2 2 2\n1 1 2 2\n", "1\n69 69 69 69\n", "1\n3 2 4 7\n", "5\n1 1 1000000000 1000000000\n1 1 1000000000 1000000000\n1 1 1000000000 1000000000\n1 1 1000000000 1000000000\n1 1 65537 65537\n", "1\n1 1 131073 131073\n", "1\n69 69 34 69\n", "1\n3 2 4 1\n", "5\n1 1 1000000000...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Wabbit is trying to move a box containing food for the rest of the zoo in the coordinate plane from the point (x_1,y_1) to the point (x_2,y_2). He has a rope, which he can use to pul...
1451_A. Subtract or Divide_26454
Ridbit starts with an integer n. In one move, he can perform one of the following operations: * divide n by one of its proper divisors, or * subtract 1 from n if n is greater than 1. A proper divisor is a divisor of a number, excluding itself. For example, 1, 2, 4, 5, and 10 are proper divisors of 20, but 2...
for _ in range(int(input())): k = 3 n = int(input()) if n == 1: print("0") elif n == 2: print("1") elif n == 3: print("2") elif n%2==0: print("2") else: print("3")
{ "input": [ "6\n1\n2\n3\n4\n6\n9\n", "6\n1\n2\n3\n4\n6\n16\n", "6\n1\n2\n3\n7\n6\n16\n", "6\n1\n2\n3\n7\n1\n30\n", "6\n1\n2\n3\n4\n11\n9\n", "6\n1\n3\n3\n4\n6\n16\n", "6\n1\n2\n3\n7\n6\n45\n", "6\n1\n2\n3\n7\n1\n17\n", "6\n1\n2\n3\n4\n1\n9\n", "6\n1\n2\n3\n7\n1\n1\n", "6\n...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Ridbit starts with an integer n. In one move, he can perform one of the following operations: * divide n by one of its proper divisors, or * subtract 1 from n if n is greater ...
1475_A. Odd Divisor_26458
You are given an integer n. Check if n has an odd divisor, greater than one (does there exist such a number x (x > 1) that n is divisible by x and x is odd). For example, if n=6, then there is x=3. If n=4, then such a number does not exist. Input The first line contains one integer t (1 ≤ t ≤ 10^4) — the number of t...
test_cases = 1 test_cases = int(input()) for ttttt in range(test_cases): n = int(input()) while n%2==0: n/=2 if n==1: print("NO") else: print("YES")
{ "input": [ "6\n2\n3\n4\n5\n998244353\n1099511627776\n", "4\n4\n4\n4\n147862179\n", "2\n1234567\n1234567\n", "4\n4\n4\n4\n171787042\n", "2\n1234567\n17471\n", "6\n2\n6\n4\n5\n998244353\n1099511627776\n", "4\n5\n4\n8\n44823782\n", "2\n97\n64\n", "6\n3\n3\n4\n5\n998244353\n109951162...
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 n. Check if n has an odd divisor, greater than one (does there exist such a number x (x > 1) that n is divisible by x and x is odd). For example, if n=6, the...
14_D. Two Paths_26462
As you know, Bob's brother lives in Flatland. In Flatland there are n cities, connected by n - 1 two-way roads. The cities are numbered from 1 to n. You can get from one city to another moving along the roads. The «Two Paths» company, where Bob's brother works, has won a tender to repair two paths in Flatland. A path ...
import os import sys from io import BytesIO, IOBase from types import GeneratorType from collections import defaultdict 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" ...
{ "input": [ "6\n1 2\n2 3\n2 4\n5 4\n6 4\n", "7\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n", "4\n1 2\n2 3\n3 4\n", "4\n3 2\n3 4\n1 4\n", "6\n1 2\n2 5\n4 5\n4 6\n3 2\n", "8\n8 6\n1 8\n7 8\n3 1\n2 6\n5 3\n8 4\n", "8\n7 2\n7 1\n6 7\n4 1\n7 3\n6 8\n2 5\n", "2\n2 1\n", "15\n10 12\n12 4\n15 12\n15 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: As you know, Bob's brother lives in Flatland. In Flatland there are n cities, connected by n - 1 two-way roads. The cities are numbered from 1 to n. You can get from one city to anoth...
1525_A. Potion-making_26466
You have an initially empty cauldron, and you want to brew a potion in it. The potion consists of two ingredients: magic essence and water. The potion you want to brew should contain exactly k\ \% magic essence and (100 - k)\ \% water. In one step, you can pour either one liter of magic essence or one liter of water i...
import math for i in range(int(input())): n=int(input()) a=100-n b=n if n==100: print(1) else: g=math.gcd(a,b) print(a//g+b//g)
{ "input": [ "3\n3\n100\n25\n", "100\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\n3\n7\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You have an initially empty cauldron, and you want to brew a potion in it. The potion consists of two ingredients: magic essence and water. The potion you want to brew should contain ...
156_C. Cipher_26470
Sherlock Holmes found a mysterious correspondence of two VIPs and made up his mind to read it. But there is a problem! The correspondence turned out to be encrypted. The detective tried really hard to decipher the correspondence, but he couldn't understand anything. At last, after some thought, he thought of somethin...
S, N = 2501, 101 m = 1000000007 k = 26 p = [[0] * (S + k) for i in range(N)] p[0][0] = 1 for n in range(1, N): for s in range(S): p[n][s] = (p[n][s - 1] + p[n - 1][s] - p[n - 1][s - k]) % m r = [] for j in range(int(input())): t = input() s = sum(ord(q) - 97 for q in t) print(p[len(t)][s] - 1)
{ "input": [ "1\naaaaaaaaaaa\n", "1\nab\n", "2\nya\nklmbfxzb\n", "1\nz\n", "1\na\n", "19\nqhovyphr\nttymgy\nqbed\nidxitl\nusbrx\nqevvydqdb\nltyjljj\ncgv\nsruvudcu\naqjbqjybyq\nrhtwwtthhh\nh\nksktyyst\npmwmnzswlw\nm\nuwaup\nxhvk\nj\nvii\n", "15\nieqqe\nwwbnobrb\ngyftfg\nclrn\nzwtviipwww\nms...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Sherlock Holmes found a mysterious correspondence of two VIPs and made up his mind to read it. But there is a problem! The correspondence turned out to be encrypted. The detective tri...
199_D. Jumping on Walls_26476
Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon. The canyon consists of two vertical parallel walls, their height is n meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to n from bottom to top. Some...
from collections import deque l, j = [int(i) for i in input().split(' ')] wallA = list(input()) wallB = list(input()) g = {} for i in range(l): # Each 4-tuple represents: (Visited?, Current Height, Current Water Height, Drowned?) if wallA[i] == '-': g[(1,i+1)] = (-1, 0, 0, False) if wallB[i] == '...
{ "input": [ "6 2\n--X-X-\nX--XX-\n", "7 3\n---X--X\n-X--XX-\n", "5 4\n-X---\n----X\n", "10 1\n-X-X-X-X-X\nX-X-X-X-X-\n", "50 4\n-X-X-X--X--X--X-XX-----XX--X--------------XXX-X-X-\n--XX---XXXXXXX----XX--X--XXX--XXXX-XX--X--X--X----\n", "6 2\n--X--X\nXX-X-X\n", "100 10\n-X------XXX--XXX-XXX...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon. The canyon consists of two vertical parallel walls, their height is n meters. Le...
222_E. Decoding Genome_26480
Recently a top secret mission to Mars has taken place. As a result, scientists managed to obtain some information about the Martian DNA. Now we know that any Martian DNA contains at most m different nucleotides, numbered from 1 to m. Special characteristics of the Martian DNA prevent some nucleotide pairs from followin...
import sys def pyes_no(condition) : if condition : print ("YES") else : print ("NO") def plist(a, s = ' ') : print (s.join(map(str, a))) def rint() : return int(sys.stdin.readline()) def rints() : return map(int, sys.stdin.readline().split()) def rfield(n, m = None) : if m == None : m = n ...
{ "input": [ "3 3 0\n", "2 1 1\naa\n", "3 3 2\nab\nba\n", "3 3 6\naa\nab\nac\nbb\nbc\ncc\n", "1000000000000000 52 26\naa\nbb\ncc\ndd\nee\nff\ngg\nhh\nii\njj\nkk\nll\nmm\nnn\noo\npp\nqq\nrr\nss\ntt\nuu\nvv\nww\nxx\nyy\nzz\n", "50000 52 10\nAa\naA\nBy\ntS\nzA\nZu\nyy\nUU\nen\neq\n", "3 3 7\n...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Recently a top secret mission to Mars has taken place. As a result, scientists managed to obtain some information about the Martian DNA. Now we know that any Martian DNA contains at m...
246_C. Beauty Pageant_26484
General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now he has choose the participants. All soldiers in the battalion have different beauty that is represented by a positive integer. The value...
n, k = map(int, input().split()) p = list(map(int, input().split())) p.sort() t = [[i] for i in p] for i in range(1, n): t += [t[-1] + i for i in t[: n - i]] print('\n'.join(str(len(i)) + ' ' + ' '.join(map(str, i)) for i in t[: k]))
{ "input": [ "2 1\n7 12\n", "3 3\n1 2 3\n", "10 9\n5 10 2 14 15 6 3 11 4 1\n", "1 1\n1000\n", "50 263\n110 98 17 54 76 31 195 77 207 168 104 229 37 88 29 164 130 156 261 181 8 113 232 234 132 53 179 59 3 141 178 61 276 152 163 85 148 129 235 79 135 94 108 69 117 2 18 158 275 174\n", "50 144\n9...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: General Payne has a battalion of n soldiers. The soldiers' beauty contest is coming up, it will last for k days. Payne decided that his battalion will participate in the pageant. Now ...
271_D. Good Substrings_26488
You've got string s, consisting of small English letters. Some of the English letters are good, the rest are bad. A substring s[l...r] (1 ≤ l ≤ r ≤ |s|) of string s = s1s2...s|s| (where |s| is the length of string s) is string slsl + 1...sr. The substring s[l...r] is good, if among the letters sl, sl + 1, ..., sr t...
import collections as cc import sys input=sys.stdin.readline I=lambda:list(map(int,input().split())) S=lambda :list(input().strip()) s=S() t=S() k,=I() ans=0 prev='' ss=sorted([s[i:] for i in range(len(s))]) for j in ss: now=0 f=0 for i in range(len(j)): if i>=len(prev) or j[i]!=prev[i]: f=1 now+=t[ord(j[i])-...
{ "input": [ "acbacbacaa\n00000000000000000000000000\n2\n", "ababab\n01000000000000000000000000\n1\n", "aaaabaababbbbbbbbbaaabaaabbbababbbbbbabbaaabaabaabaaabaaaabbababbaaaaaaababbaababbabbaabbbabaabbbbababaaabbabbbabaaabbbabbbbbbbbabababaaaaaabaababbbbbaaaaaaaaaaaaaaababbbbabbbbbbababaabbabbbaababaabaaaa...
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 small English letters. Some of the English letters are good, the rest are bad. A substring s[l...r] (1 ≤ l ≤ r ≤ |s|) of string s = s1s2...s|s| (wh...
295_A. Greg and Array_26492
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, ...
import sys input=sys.stdin.readline n,m,k=map(int,input().split()) a=list(map(int,input().split())) query=[] times=[] x=[0]*(m+2) y=[0]*(n+2) for i in range(m): query.append(list(map(int,input().split()))) for i in range(k): times.append(list(map(int,input().split()))) for i in range(k): l,r=times[i] x[...
{ "input": [ "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\n1\n1 1 1\n1 1\n", "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\n0\n1 1 0\n1 1\n", "3 3 3\n1 2 3\n1 2 1\n2 3 2\n2 3 4\n1 2\n1 3\n2 3\n", "4 3 6\n2 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 ...
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 ...
366_A. Dima and Guards_26501
Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards... There are four guardposts in Dima's dorm. Each post contains two guards (in Russia they are usually elderly women). You can b...
import itertools as it n = int(input()) res = None for i in range(4): a = list(map(int, input().split())) for v in list(it.product(a[:2], a[2:])): if sum(v) <= n: res = [i + 1, v[0], n - v[0]] break if res is not None: break print(-1 if res is None else ' '.join(ma...
{ "input": [ "10\n6 6 6 6\n7 7 7 7\n4 4 4 4\n8 8 8 8\n", "10\n5 6 5 6\n6 6 7 7\n5 8 6 6\n9 9 9 9\n", "5\n3 3 3 3\n3 3 3 3\n3 3 3 3\n3 3 3 3\n", "100000\n25000 75000 80000 80000\n99999 99999 2 2\n99999 2 99999 99999\n2 99999 99999 99999\n", "100000\n25000 50000 50001 75001\n25000 50000 50001 75001\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm...
389_E. Fox and Card Game_26505
Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card. The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom o...
n = int(input()) lista = [] aux = [] somaA = 0 somaB = 0 for i in range(n): a = [int(i) for i in input().split()][1:] if len(a) > 1: somaA += sum(a[0:len(a)//2]) somaB += sum(a[-(len(a)//2):]) if len(a) % 2 == 1: aux.append(a[len(a)//2]) aux.sort(reverse=True) for i in range(...
{ "input": [ "3\n3 1000 1000 1000\n6 1000 1000 1000 1000 1000 1000\n5 1000 1000 1000 1000 1000\n", "2\n1 100\n2 1 10\n", "3\n3 1 3 2\n3 5 4 6\n2 8 7\n", "1\n9 2 8 6 5 9 4 7 1 3\n", "5\n1 3\n1 2\n1 8\n1 1\n1 4\n", "2\n2 200 1\n3 1 100 2\n", "4\n3 1 5 100\n3 1 5 100\n3 100 1 1\n3 100 1 1\n",...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card. The players take turns and Ciel takes...
409_H. A + B Strikes Back_26509
A + B is often used as an example of the easiest problem possible to show some contest platform. However, some scientists have observed that sometimes this problem is not so easy to get accepted. Want to try? Input The input contains two integers a and b (0 ≤ a, b ≤ 103), separated by a single space. Output Output ...
import sys import os a,b=input().split() a=int(a) b=int(b) print(a+b)
{ "input": [ "381 492\n", "5 14\n", "629 657\n", "536 298\n", "441 915\n", "522 92\n", "723 350\n", "339 433\n", "953 553\n", "433 126\n", "399 280\n", "538 261\n", "740 519\n", "242 86\n", "117 399\n", "632 264\n", "143 522\n", "923 488\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: A + B is often used as an example of the easiest problem possible to show some contest platform. However, some scientists have observed that sometimes this problem is not so easy to g...
437_C. The Child and Toy_26513
On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy. The toy consists of n parts and m ropes. Each rope links two parts, but every pair of parts is linked by at most one rope. To split the toy, the child must remove all its parts. The...
def mlt(): return map(int, input().split()) x, y = mlt() s = [0] + list(mlt()) res = 0 for n in range(y): a, b = mlt() res += min(s[a], s[b]) print(res)
{ "input": [ "4 4\n100 100 100 100\n1 2\n2 3\n2 4\n3 4\n", "4 3\n10 20 30 40\n1 4\n1 2\n2 3\n", "7 10\n40 10 20 10 20 80 40\n1 5\n4 7\n4 5\n5 2\n5 7\n6 4\n1 6\n1 3\n4 3\n1 4\n", "1 0\n23333\n", "3 3\n1 1 1\n1 2\n2 3\n3 1\n", "5 4\n1 2 2 2 2\n1 2\n1 3\n1 4\n1 5\n", "10 30\n3 6 17 15 13 15 6...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: On Children's Day, the child got a toy from Delayyy as a present. However, the child is so naughty that he can't wait to destroy the toy. The toy consists of n parts and m ropes. Eac...
506_D. Mr. Kitayuta's Colorful Graph_26522
Mr. Kitayuta has just bought an undirected graph with n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, connecting vertex ai and bi. Mr. Kitayuta wants you to process the following q queries. In the i-th query, he gives you two integers - ui and vi. ...
#make a table n,m = map(int,input().split()) arr = [[] for i in range(n+1)] for i in range(1,m+1): l = list(map(int,input().split())) arr[l[0]].append((l[1],l[2])) arr[l[1]].append((l[0],l[2])) #dfs def dfs(a,b,k): if a == b: return True seen.append(a) for i in arr[a]: x,c = i...
{ "input": [ "4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4\n", "5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4\n", "2 1\n1 2 1\n1\n1 2\n", "2 5\n1 2 1\n1 2 2\n1 2 3\n1 2 4\n1 2 5\n1\n1 2\n", "2 3\n1 2 3\n1 2 2\n1 2 1\n1\n1 2\n", "5 7\n1 5 1\n3 5 1\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Mr. Kitayuta has just bought an undirected graph with n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, connecting ...
52_C. Circular RMQ_26525
You are given circular array a0, a1, ..., an - 1. There are two types of operations with it: * inc(lf, rg, v) — this operation increases each element on the segment [lf, rg] (inclusively) by v; * rmq(lf, rg) — this operation returns minimal value on the segment [lf, rg] (inclusively). Assume segments to be c...
import math,sys,bisect,heapq,os from collections import defaultdict,Counter,deque from itertools import groupby,accumulate from functools import lru_cache #sys.setrecursionlimit(200000000) int1 = lambda x: int(x) - 1 def input(): return sys.stdin.readline().rstrip('\r\n') #input = iter(sys.stdin.buffer.read().decode()....
{ "input": [ "4\n1 2 3 4\n4\n3 0\n3 0 -1\n0 1\n2 1\n", "2\n-1 -1\n10\n0 0\n0 0\n0 0 1\n0 0\n1 1\n0 0 -1\n0 0 0\n0 0 1\n1 1 0\n0 0 -1\n", "1\n-1\n10\n0 0 -1\n0 0\n0 0 1\n0 0\n0 0 1\n0 0\n0 0 0\n0 0\n0 0 -1\n0 0 1\n", "1\n1\n1\n0 0 0\n" ], "output": [ "1\n0\n0\n", "-1\n-1\n0\n-1\n", "-2\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given circular array a0, a1, ..., an - 1. There are two types of operations with it: * inc(lf, rg, v) — this operation increases each element on the segment [lf, rg] (incl...
581_D. Three Logos_26531
Three companies decided to order a billboard with pictures of their logos. A billboard is a big square board. A logo of each company is a rectangle of a non-zero area. Advertisers will put up the ad only if it is possible to place all three logos on the billboard so that they do not overlap and the billboard has no e...
#------------------------template--------------------------# import os import sys from math import * from collections import * # from fractions import * # from heapq import* from bisect import * from io import BytesIO, IOBase def vsInput(): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w')...
{ "input": [ "4 4 2 6 4 2\n", "5 1 2 5 5 2\n", "2 5 6 7 3 4\n", "100 12 88 61 39 88\n", "13 68 100 87 13 32\n", "70 7 70 2 70 62\n", "100 20 96 80 80 4\n", "70 10 47 59 23 59\n", "75 100 19 100 6 100\n", "100 100 100 1 100 100\n", "2 3 2 5 5 8\n", "2 3 2 3 2 2\n", "...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Three companies decided to order a billboard with pictures of their logos. A billboard is a big square board. A logo of each company is a rectangle of a non-zero area. Advertisers w...
603_C. Lieges of Legendre_26535
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...
def grundy(n, k): if k % 2 == 0: if n <= 2: return n else: return n % 2 == 0 else: if n <= 4: return [0, 1, 0, 1, 2][n] elif n % 2 == 1: return 0 else: return 2 if grundy(n // 2, k) == 1 else 1 if __name__ == "...
{ "input": [ "1 2\n3\n", "2 1\n3 4\n", "6 1\n1 4 4 4 2 2\n", "4 5\n20 21 22 25\n", "9 2\n8 2 9 4 7 5 2 4 9\n", "2 2\n2 4\n", "9 2\n2 8 4 2 5 7 1 8 10\n", "10 1\n2 3 5 2 7 4 7 7 4 2\n", "2 3\n1000000000 1000000000\n", "2 1\n160 150\n", "7 1\n8 6 10 10 1 5 8\n", "2 3\n7 7...
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...
626_A. Robot Sequence_26539
Calvin the robot lies in an infinite rectangular grid. Calvin's source code contains a list of n commands, each either 'U', 'R', 'D', or 'L' — instructions to move a single square up, right, down, or left, respectively. How many ways can Calvin execute a non-empty contiguous substrings of commands and return to the sam...
import io import sys import time import random start = time.clock() #~ test = '''6 #~ URLLDR''' #~ test = '''7 #~ RLRLRLR''' #~ test = '''200 #~ ''' #~ for i in range(200): #~ test += random.choice("UDLR") #~ print(test) #~ test = '10 15' #~ test = '1 1000000' #28733372 #~ test = '1 11' #55 #~ test = '1 21' #130 ...
{ "input": [ "6\nURLLDR\n", "4\nDLUU\n", "7\nRLRLRLR\n", "197\nDUUDUDUDUDUUDUUDUUUDDDDUUUDUUUDUUUUUDUUUDDUDDDUUDUDDDUUDDUUUUUUUDUDDDDDUUUUUDDDDDDUUUUDDUDDUDDDUDUUUDUUDUDUDUUUDUDDDDUUDDUDDDDUDDDUDUUUDUUDUUUDDDDUUUDUUDDUUUUUDDDDUUDUUDDDDUDDUUDUUUDDDDUDUUUDDDUUDU\n", "20\nLDURLDURRLRUDLRRUDLU\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Calvin the robot lies in an infinite rectangular grid. Calvin's source code contains a list of n commands, each either 'U', 'R', 'D', or 'L' — instructions to move a single square up,...
675_B. Restoring Painting_26543
Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was stolen while he was on duty. He doesn't want to be fired, so he has to quickly restore the painting. He remembers some facts about it. * The painting is a square 3 × 3, each cell contains a single integer from 1 to n, an...
n,a,b,c,d=map(int,input().split()) count=0 for x in range(1,n+1): y=x+b-c z=x+a-d w=y+a-d if (y>=1 and y<=n) and(z>=1 and z<=n) and (w>=1 and w<=n): count+=1 print(count*n)
{ "input": [ "3 3 1 2 3\n", "2 1 1 1 2\n", "100000 64022 49026 55956 88430\n", "10 9 10 8 10\n", "100000 100000 1 1 1\n", "5 1 1 5 5\n", "100000 1 100000 100000 100000\n", "100000 87223 66046 27153 40823\n", "100000 100000 1 100000 100000\n", "100000 83958 32567 91083 95317\n",...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Vasya works as a watchman in the gallery. Unfortunately, one of the most expensive paintings was stolen while he was on duty. He doesn't want to be fired, so he has to quickly restore...
699_C. Vacations_26547
Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whether a contest was carried out in the Internet on that day. For the i-th day there are four options: 1. on this day the gym is closed and...
size = int(input()) days = [int(a) for a in input().split()] daysoff = 0 yesterday = 0 if days[0] == 0: daysoff += 1 yesterday = 0 elif days[0] == 3: yesterday = 0 else: yesterday = days[0] for i in range(1, size): if days[i] == 0: yesterday = 0 daysoff += 1 elif days[i] == y...
{ "input": [ "4\n1 3 2 0\n", "7\n1 3 3 2 1 2 3\n", "2\n2 2\n", "70\n1 0 0 0 1 0 1 0 0 0 1 1 0 1 0 0 1 1 1 0 1 1 0 0 1 1 1 3 1 1 0 1 2 0 2 1 0 0 0 1 1 1 1 1 0 0 1 0 0 0 1 1 1 3 0 0 1 0 0 0 1 0 0 0 0 0 1 0 1 1\n", "25\n2 3 1 3 3 2 1 3 3 3 1 3 3 1 3 2 3 3 1 3 3 3 2 3 3\n", "30\n1 2 3 2 2 3 3 3 3 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Vasya has n days of vacations! So he decided to improve his IT skills and do sport. Vasya knows the following information about each of this n days: whether that gym opened and whethe...
71_E. Nuclear Fusion_26551
There is the following puzzle popular among nuclear physicists. A reactor contains a set of n atoms of some chemical elements. We shall understand the phrase "atomic number" as the number of this atom's element in the periodic table of the chemical elements. You are allowed to take any two different atoms and fuse a ...
numbersDict = { "1": "H", "2": "He", "3": "Li", "4": "Be", "5": "B", "6": "C", "7": "N", "8": "O", "9": "F", "10": "Ne", "11": "Na", "12": "Mg", "13": "Al", "14": "Si", "15": "P", "16": "S", "17": "Cl", "18": "Ar", "19": "K", "20": "Ca", "21": "Sc", "22": "Ti", "23": "V", "24": "Cr", "25": "Mn", "26": "Fe", "27": "Co",...
{ "input": [ "2 2\nBk Fm\nCf Es\n", "2 1\nH H\nHe\n", "10 3\nMn Co Li Mg C P F Zn Sc K\nSn Pt Y\n", "17 7\nH H H H H H H H H H H H H H H H B\nLi Li Li Li Li Li Li\n", "16 9\nB Zn Mn Li Li B Na Mg Sc Ne Mn Cr V N Ne Cr\nB V Cd Sc Al Fm B Cl C\n", "17 13\nHe Ru Cu Sr P Br Ar Cr Na In Kr In Ca K ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There is the following puzzle popular among nuclear physicists. A reactor contains a set of n atoms of some chemical elements. We shall understand the phrase "atomic number" as the n...
741_B. Arpa's weak amphitheater and Mehrdad's valuable Hoses_26555
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...
n, m, k = map(int, input().split()) a = map(int, input().split()) b = map(int, input().split()) ab = [(0, 0)] + list(zip(a, b)) l = list(range(n + 1)) def f(x): if x == l[x]: return x l[x] = f(l[x]) return l[x] for i in range(m): x, y = map(int, input().split()) x, y = f(x), f(y) ...
{ "input": [ "3 1 5\n3 2 5\n2 4 2\n1 2\n", "4 2 11\n2 4 6 6\n6 4 2 1\n1 2\n2 3\n", "10 5 100\n78 89 3 2 95 96 87 11 13 60\n694709 921 799687 428614 221900 536251 117674 36488 219932 771513\n4 5\n3 4\n6 2\n2 3\n8 3\n", "10 5 100\n64 90 3 94 96 97 52 54 82 31\n796554 444893 214351 43810 684158 555762 68...
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 ...
765_A. Neverending competitions_26559
There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back. Jinotega's best friends, team ...
import sys,math from collections import deque #input = sys.stdin.buffer.readline def solve(): return; # for _ in range(int(input())): # solve() n = int(input()) h = input() cnt=0 for i in range(n): s = input() if h==s[:3] or h==s[-3:]: cnt+=1 if cnt%2==0: print("home") else: print("contest")
{ "input": [ "3\nSVO\nSVO-&gt;HKT\nHKT-&gt;SVO\nSVO-&gt;RAP\n", "4\nSVO\nSVO-&gt;CDG\nLHR-&gt;SVO\nSVO-&gt;LHR\nCDG-&gt;SVO\n", "1\nESJ\nESJ->TSJ\n", "1\nAAK\nAAK->ABA\n", "3\nZIZ\nDWJ->ZIZ\nZIZ->DWJ\nZIZ->DWJ\n", "3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP\n", "11\nFGH\nFGH->BRZ\nUBK->FGH\nQRE-...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes pl...
788_C. The Great Mixing_26563
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...
## ## ## import sys def line(): return sys.stdin.readline() def numbers(): return list(map(int, line().split())) def number(): return int(line()) adjlist = {} n, k = 0, 0 mark = [False]*2010 edges = [False]*1010 # bfs for "ssph" def bfs(s): i = 0 frontier = [s] while frontier: ...
{ "input": [ "400 4\n100 300 450 500\n", "50 2\n100 25\n", "998 2\n1 1000\n", "995 5\n996 997 998 999 1000\n", "917 21\n999 998 1000 997 1000 998 78 991 964 985 987 78 985 999 83 987 1000 999 999 78 83\n", "134 6\n505 10 1 363 344 162\n", "500 3\n499 1000 300\n", "500 1\n1000\n", "...
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...
834_C. The Meaningless Game_26568
<image> Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting. The game consists of multiple rounds. Its rules are very simple: in each round, a natural number k is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's s...
# ---------------------------iye ha aam zindegi--------------------------------------------- import math import heapq, bisect import sys from collections import deque, defaultdict from fractions import Fraction mod = 10 ** 9 + 7 mod1 = 998244353 # ------------------------------warmup---------------------------- impor...
{ "input": [ "6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000\n", "1\n6 12\n", "1\n1062961 1031\n", "1\n16 8\n", "1\n9907 98148649\n", "1\n12004 18012002\n", "1\n3 10\n", "1\n31159 970883281\n", "3\n1 1\n8 27\n1000 1331\n", "1\n2 3\n", "1\n3331 11095561\n", "1\n3...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: <image> Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting. The game consists of multiple rounds. Its rules are very simple: in each r...
855_A. Tom Riddle's Diary_26572
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they ...
l = [] for _ in range(int(input())): s = input() if s not in l: print('NO') l.append(s) else: print('YES')
{ "input": [ "6\ntom\nlucius\nginny\nharry\nginny\nharry\n", "3\na\na\na\n", "9\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnbqovtziuhwvyrqwmskx\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnbogaclckfnbqovtziuhwvyrqwmskx\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujr...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and i...
879_D. Teams Formation_26576
This time the Berland Team Olympiad in Informatics is held in a remote city that can only be reached by one small bus. Bus has n passenger seats, seat i can be occupied only by a participant from the city ai. Today the bus has completed m trips, each time bringing n participants. The participants were then aligned in ...
def main(): _, k, m = [int(x) for x in input().split()] a = [] last = ("-1", 0) a.append(last) for ai in input().split(): if last[0] == ai: last = (ai, last[1]+1) a[-1] = last else: last = (ai, 1) a.append(last) if last[1] == k...
{ "input": [ "1 9 10\n1\n", "4 2 5\n1 2 3 1\n", "3 2 10\n1 2 1\n", "5 3 2\n1 1 2 1 1\n", "5 3 3\n1 2 2 1 1\n", "10 5 1000000000\n1 1 1 2 2 1 2 2 2 2\n", "2 4 1\n1 1\n", "1 10 10\n1\n", "5 2 4\n1 2 3 2 1\n", "1 1000000000 1000000000\n100000\n", "5 3 2\n1 1 2 1 2\n", "10 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: This time the Berland Team Olympiad in Informatics is held in a remote city that can only be reached by one small bus. Bus has n passenger seats, seat i can be occupied only by a part...
903_A. Hungry Student Problem_26580
Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken. CFK sells chicken chunks in small and large portions. A small portion contains 3 chunks; a large one — 7 chunks. Ivan wants to eat exactly x chunks. Now he wonders whether he can buy exactly th...
t = int(input()) for i in range(0,t): flag = 0 x = int(input()) b = 0 temp = x while temp >= 0 : if(temp%3 == 0): flag = 1 break b = b+1 temp = x-7*b if flag == 1 : print("YES") else: print("NO")
{ "input": [ "2\n6\n5\n", "100\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\n63\n64\n65\n66\n67\n68\n69\n70\n71\n72\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Ivan's classes at the university have just finished, and now he wants to go to the local CFK cafe and eat some fried chicken. CFK sells chicken chunks in small and large portions. A ...
925_B. Resource Distribution_26584
One department of some software company has n servers of different specifications. Servers are indexed with consecutive integers from 1 to n. Suppose that the specifications of the j-th server may be expressed with a single integer number c_j of artificial resource units. In order for production to work, it is needed ...
def fin(c, x): return (x + c - 1) // c def ck(x, b): r = (n, n) for i in range(b, n): r = min(r, (i + fin(c[i][0], x), i)) return r def sol(r, l): if r[0] <= n and l[0] <= n and r[1] < n and l[1] < n : print("Yes") print(r[0] - r[1], l[0]- l[1]) print(' '.join([str...
{ "input": [ "6 8 16\n3 5 2 9 8 7\n", "4 20 32\n21 11 11 12\n", "4 11 32\n5 5 16 16\n", "5 12 20\n7 8 4 11 9\n", "2 1 1\n1 1000000\n", "4 12 11\n4 4 6 11\n", "15 250 200\n71 2 77 69 100 53 54 40 73 32 82 58 24 82 41\n", "2 1 1\n1000000000 1000000000\n", "2 1 1\n1 1\n", "6 8 16\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: One department of some software company has n servers of different specifications. Servers are indexed with consecutive integers from 1 to n. Suppose that the specifications of the j-...
954_C. Matrix Walk_26588
There is a matrix A of size x × y filled with integers. For every <image>, <image> Ai, j = y(i - 1) + j. Obviously, every integer from [1..xy] occurs exactly once in this matrix. You have traversed some path in this matrix. Your path can be described as a sequence of visited cells a1, a2, ..., an denoting that you st...
def main(): int(input()) a = list(map(int, input().split())) ds = [i - j for i, j in zip(a[1:], a)] dss = set(abs(x) for x in ds) if 0 in dss: return False try: dss.remove(1) except KeyError: pass if len(dss) > 1: return False if not dss: retu...
{ "input": [ "6\n1 2 1 2 5 3\n", "2\n1 10\n", "8\n1 2 3 6 9 8 5 2\n", "5\n3 4 5 6 2\n", "2\n999999999 1000000000\n", "7\n550 555 554 553 554 555 560\n", "3\n9 7 5\n", "2\n999999998 1000000000\n", "2\n500000000 1000000000\n", "2\n1 10\n", "23\n92 34 58 40 76 3 38 66 76 23 85...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There is a matrix A of size x × y filled with integers. For every <image>, <image> Ai, j = y(i - 1) + j. Obviously, every integer from [1..xy] occurs exactly once in this matrix. Yo...
980_B. Marlin_26592
The city of Fishtopia can be imagined as a grid of 4 rows and an odd number of columns. It has two main villages; the first is located at the top-left cell (1,1), people who stay there love fishing at the Tuna pond at the bottom-right cell (4, n). The second village is located at (4, 1) and its people love the Salmon p...
EMPTY = "." HOTEL = "#" def main(): n, k = map(int, input().split()) print("YES") print(EMPTY * n) if k % 2 == 0: m = k // 2 s = EMPTY + HOTEL * m + EMPTY * (n - m - 1) print(s) print(s) elif k < n - 1: s = (HOTEL * k).center(n, EMPTY) print(s) ...
{ "input": [ "7 2\n", "5 3\n", "33 57\n", "99 55\n", "37 19\n", "31 32\n", "99 20\n", "37 39\n", "7 10\n", "57 15\n", "99 177\n", "99 193\n", "19 12\n", "13 21\n", "57 67\n", "23 39\n", "97 100\n", "99 99\n", "69 17\n", "55 55\n", "39...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: The city of Fishtopia can be imagined as a grid of 4 rows and an odd number of columns. It has two main villages; the first is located at the top-left cell (1,1), people who stay ther...
9_B. Running Student_26596
And again a misfortune fell on Poor Student. He is being late for an exam. Having rushed to a bus stop that is in point (0, 0), he got on a minibus and they drove along a straight line, parallel to axis OX, in the direction of increasing x. Poor Student knows the following: * during one run the minibus makes n st...
# -*- coding: utf - 8 -*- """"""""""""""""""""""""""""""""""""""""""""" | author: mr.math - Hakimov Rahimjon | | e-mail: mr.math0777@gmail.com | | created: 27.01.2018 9:50 | """"""""""""""""""""""""""""""""""""""""""""" # inp = open("input.txt", "r"); input = inp.readline; out = open...
{ "input": [ "4 5 2\n0 2 4 6\n4 1\n", "2 1 1\n0 100000\n100000 100000\n", "2 1 1\n0 100000\n-100000 -100000\n", "55 11 44\n0 3343 3387 3470 3825 3832 3971 4026 4043 4389 4492 4886 5015 5084 5161 5436 5595 5616 5677 5987 6251 6312 6369 6469 6487 6493 6507 6641 6928 7067 7159 7280 7303 7385 7387 7465 75...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: And again a misfortune fell on Poor Student. He is being late for an exam. Having rushed to a bus stop that is in point (0, 0), he got on a minibus and they drove along a straight li...
p02545 ACL Contest 1 - Center Rearranging_26608
Given are integer sequences A and B of length 3N. Each of these two sequences contains three copies of each of 1, 2, \dots, N. In other words, A and B are both arrangements of (1, 1, 1, 2, 2, 2, \dots, N, N, N). Tak can perform the following operation to the sequence A arbitrarily many times: * Pick a value from 1, 2...
import sys readline = sys.stdin.buffer.readline class E: def __init__(self,to,nx): self.to=to self.nx=nx class Graph: def __init__(self,n): self.n=n self.head=[None]*n def ae(self,a,b): head=self.head head[a]=E(b,head[a]) #head[b]=E(a,head[b]) return head[a] def scc(g): n=g.n cur=g.head last=...
{ "input": [ "8\n3 6 7 5 4 8 4 1 1 3 8 7 3 8 2 4 7 5 2 2 6 5 6 1\n7 5 8 1 3 6 7 5 4 8 1 3 3 8 2 4 2 6 5 6 1 4 7 2", "3\n1 1 1 2 2 2 3 3 3\n1 1 1 2 2 2 3 3 3", "3\n2 3 3 1 1 1 2 2 3\n3 2 2 1 1 1 3 3 2", "3\n2 3 1 1 3 2 2 1 3\n1 2 2 3 1 2 3 1 3", "3\n2 3 3 1 2 1 2 1 3\n3 2 2 1 1 1 3 3 2", "3\n1 ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Given are integer sequences A and B of length 3N. Each of these two sequences contains three copies of each of 1, 2, \dots, N. In other words, A and B are both arrangements of (1, 1, ...
p02676 AtCoder Beginner Contest 168 - ... (Triple Dots)_26611
We have a string S consisting of lowercase English letters. If the length of S is at most K, print S without change. If the length of S exceeds K, extract the first K characters in S, append `...` to the end of them, and print the result. Constraints * K is an integer between 1 and 100 (inclusive). * S is a string ...
K = int(input()) S = input() print(S[:K] + "...") if len(S) > K else print(S)
{ "input": [ "7\nnikoandsolstice", "40\nferelibenterhominesidquodvoluntcredunt", "7\necitslosdnaokin", "40\nferelibenterhominesidquodvomuntcredunt", "7\nnikoandrolstice", "40\nferelibenterhominesidquodvonuntcredunt", "7\noikoandrolstice", "40\nferelibenterhominesidquodvonuntcreudnt", ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: We have a string S consisting of lowercase English letters. If the length of S is at most K, print S without change. If the length of S exceeds K, extract the first K characters in ...
p02804 AtCoder Beginner Contest 151 - Max-Min Sums_26615
For a finite set of integers X, let f(X)=\max X - \min X. Given are N integers A_1,...,A_N. We will choose K of them and let S be the set of the integers chosen. If we distinguish elements with different indices even when their values are the same, there are {}_N C_K ways to make this choice. Find the sum of f(S) ove...
N,K = map(int,input().split()) A = list(map(int,input().split())) mod = 10**9+7 A = sorted(A) bikkuri = [1] for i in range(1,N+1): bikkuri.append((bikkuri[-1]*i)%mod) bikkuri2 = [1] for i in range(1,N+1): bikkuri2.append(pow(bikkuri[i],mod-2,mod)) def comb(n,r): if n<r: return 0 else: ...
{ "input": [ "3 1\n1 1 1", "4 2\n1 1 3 4", "10 6\n1000000000 1000000000 1000000000 1000000000 1000000000 0 0 0 0 0", "6 3\n10 10 10 -10 -10 -10", "3 1\n1 1 2", "4 2\n1 1 2 4", "10 5\n1000000000 1000000000 1000000000 1000000000 1000000000 0 0 0 0 0", "6 4\n10 10 10 -10 -10 -10", "4 ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: For a finite set of integers X, let f(X)=\max X - \min X. Given are N integers A_1,...,A_N. We will choose K of them and let S be the set of the integers chosen. If we distinguish e...
p02940 AtCoder Grand Contest 037 - RGB Balls_26618
We have 3N colored balls with IDs from 1 to 3N. A string S of length 3N represents the colors of the balls. The color of Ball i is red if S_i is `R`, green if S_i is `G`, and blue if S_i is `B`. There are N red balls, N green balls, and N blue balls. Takahashi will distribute these 3N balls to N people so that each pe...
MOD = 998244353 N = int(input()) Ss = input() convs = {'R': 0, 'G': 1, 'B': 2} num0 = N num1s = [0] * 3 num2s = [0] * 3 ans = 1 for S in Ss: c = convs[S] if num2s[c]: ans *= num2s[c] num2s[c] -= 1 else: for i in range(3): if i == c: continue if num1s[i]: ...
{ "input": [ "3\nRRRGGGBBB", "5\nBBRGRRGRGGRBBGB", "3\nBBBGGGRRR", "3\nRRRBGGBGB", "3\nBRRGGGRBB", "5\nBGRGRRBRGGRBBGB", "3\nBGRGGRRBB", "5\nBGBBRGGRGRRGRBB", "3\nRGRBGRBGB", "5\nBGRGRRBBGGRBRGB", "5\nBRRBRGGBBGRGRGB", "5\nBRRBRBGBGGRGRGB", "3\nBBBGGRRGR", "5\nB...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: We have 3N colored balls with IDs from 1 to 3N. A string S of length 3N represents the colors of the balls. The color of Ball i is red if S_i is `R`, green if S_i is `G`, and blue if ...
p03077 AtCoder Beginner Contest 123 - Five Transportations_26622
In 2028 and after a continuous growth, AtCoder Inc. finally built an empire with six cities (City 1, 2, 3, 4, 5, 6)! There are five means of transport in this empire: * Train: travels from City 1 to 2 in one minute. A train can occupy at most A people. * Bus: travels from City 2 to 3 in one minute. A bus can occupy a...
n = int(input()) l = [int(input()) for _ in range(5)] print(-(-n//min(l))+4)
{ "input": [ "5\n3\n2\n4\n3\n5", "10\n123\n123\n123\n123\n123", "10000000007\n2\n3\n5\n7\n11", "5\n3\n2\n4\n3\n6", "10\n123\n219\n123\n123\n123", "10000000007\n2\n3\n5\n3\n11", "10000000007\n2\n3\n1\n3\n11", "10\n123\n633\n27\n9\n123", "5\n3\n2\n4\n1\n6", "10\n31\n457\n1\n123\n...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: In 2028 and after a continuous growth, AtCoder Inc. finally built an empire with six cities (City 1, 2, 3, 4, 5, 6)! There are five means of transport in this empire: * Train: trave...
p03219 AtCoder Beginner Contest 113 - Discount Fare_26626
There is a train going from Station A to Station B that costs X yen (the currency of Japan). Also, there is a bus going from Station B to Station C that costs Y yen. Joisino got a special ticket. With this ticket, she can take the bus for half the fare if she travels from Station A to Station B by train and then trav...
L = list(map(int,input().split())) print(L[0]+L[1]//2)
{ "input": [ "81 58", "4 54", "35 58", "3 54", "68 58", "3 34", "88 58", "5 34", "88 51", "5 0", "88 27", "5 -1", "51 11", "51 1", "2 -2", "95 1", "2 -4", "54 1", "4 -1", "47 0", "7 -1", "47 -1", "10 -1", "77 1", "15 -...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There is a train going from Station A to Station B that costs X yen (the currency of Japan). Also, there is a bus going from Station B to Station C that costs Y yen. Joisino got a s...
p03691 AtCoder Grand Contest 016 - Poor Turkeys_26632
There are N turkeys. We number them from 1 through N. M men will visit here one by one. The i-th man to visit will take the following action: * If both turkeys x_i and y_i are alive: selects one of them with equal probability, then eats it. * If either turkey x_i or y_i is alive (but not both): eats the alive one. * ...
import sys from itertools import combinations def solve(n, pairs): survivors = {v: {v} for v in range(1, n + 1)} for x, y in reversed(pairs): for v, srv in survivors.copy().items(): if x in srv: if y in srv: del survivors[v] else: ...
{ "input": [ "3 2\n1 2\n1 2", "4 3\n1 2\n3 4\n2 3", "10 10\n8 9\n2 8\n4 6\n4 9\n7 8\n2 8\n1 8\n3 4\n3 4\n2 7", "3 1\n1 2", "4 1\n1 2\n3 4\n2 3", "10 10\n8 9\n2 8\n4 6\n4 9\n7 8\n2 9\n1 8\n3 4\n3 4\n2 7", "3 2\n1 2\n2 2", "4 3\n1 2\n3 4\n2 2", "6 1\n1 2", "1 1\n1 2\n3 4\n2 3", ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are N turkeys. We number them from 1 through N. M men will visit here one by one. The i-th man to visit will take the following action: * If both turkeys x_i and y_i are alive...
p03844 AtCoder Beginner Contest 050 - Addition and Subtraction Easy_26636
Joisino wants to evaluate the formula "A op B". Here, A and B are integers, and the binary operator op is either `+` or `-`. Your task is to evaluate the formula instead of her. Constraints * 1≦A,B≦10^9 * op is either `+` or `-`. Input The input is given from Standard Input in the following format: A op B Outpu...
a,b,c=input().split();print(int(a)+int(c)if b=='+'else int(a)-int(c))
{ "input": [ "1 + 2", "5 - 7", "0 + 2", "5 - 13", "-1 + 2", "5 - 14", "1 - 14", "1 - 1", "1 - 7", "-1 + 0", "5 - 20", "2 - 7", "1 - 4", "3 - 7", "9 - 4", "0 - 7", "7 - 4", "7 - 3", "0 + -2", "5 - 23", "3 - 14", "1 - 27", "5 - ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Joisino wants to evaluate the formula "A op B". Here, A and B are integers, and the binary operator op is either `+` or `-`. Your task is to evaluate the formula instead of her. Cons...
p04011 AtCoder Beginner Contest 044 - Tak and Hotels (ABC Edit)_26640
There is a hotel with the following accommodation fee: * X yen (the currency of Japan) per night, for the first K nights * Y yen per night, for the (K+1)-th and subsequent nights Tak is staying at this hotel for N consecutive nights. Find his total accommodation fee. Constraints * 1 \leq N, K \leq 10000 * 1 \leq ...
a,b,c,d=[int(input()) for i in range(4)] if a<=b: print(a*c) else: print(b*c+(a-b)*d)
{ "input": [ "2\n3\n10000\n9000", "5\n3\n10000\n9000", "2\n3\n10000\n2613", "5\n3\n10010\n9000", "2\n3\n10010\n2613", "5\n3\n10010\n10766", "5\n3\n10010\n18306", "2\n3\n10110\n4944", "5\n6\n10010\n18306", "5\n6\n00010\n18306", "2\n0\n10110\n4944", "2\n-1\n10110\n4944", ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There is a hotel with the following accommodation fee: * X yen (the currency of Japan) per night, for the first K nights * Y yen per night, for the (K+1)-th and subsequent nights ...
p00097 Sum of Integers II_26644
Write a program that extracts n different numbers from the numbers 0 to 100 and outputs the number of combinations that add up to s. Each n number is from 0 to 100, and the same number cannot be used in one combination. For example, if n is 3 and s is 6, the combination of the three numbers totaling 6 is 1 + 2 + 3 = ...
dp = [[0 for _ in range(1001)] for _ in range(10)] dp[1][0] = dp[0][0] = 1 for now in range(1, 101): for used in range(9, 0, -1): dpu = dp[used] dpu_1 = dp[used - 1] for s in range(now, 1001): dpu[s] = dpu_1[s - now] + dpu[s] while True: n, s = map(int, input().split()) if not n: break p...
{ "input": [ "3 6\n3 1\n0 0", "3 12\n3 1\n0 0", "5 12\n3 0\n0 0", "5 23\n3 0\n0 0", "5 28\n3 0\n0 0", "6 6\n3 1\n0 0", "3 12\n3 3\n0 0", "6 23\n3 0\n0 0", "3 11\n3 3\n0 0", "3 19\n3 -1\n0 0", "6 19\n3 0\n0 0", "3 11\n3 2\n0 0", "6 26\n3 0\n0 0", "3 22\n3 1\n0 0"...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Write a program that extracts n different numbers from the numbers 0 to 100 and outputs the number of combinations that add up to s. Each n number is from 0 to 100, and the same numbe...
p00229 Big Hit !_26648
Ataru Oafoot of Aizu Gakuen University High School decided to play with a slot machine. When you insert a medal on this machine, three reels will start spinning and each reel will stop automatically. In a normal game (normal game), 3 medals are inserted, and when the symbols are aligned, the following medals are obtai...
while 1: b, r, g, c, s, t = map(int, input().split()) if t == 0: break ans = 100 ans += (15 - 2) * (5*b) + (15 - 3) * b t -= 6*b ans += (15 - 2) * (3*r) + (15 - 3) * r t -= 4*r ans += (7 - 3) * g t -= g ans += (2 - 3) * c t -= c t -= s ans += (0 - 3) * t...
{ "input": [ "3 2 30 3 26 226\n9 0 18 3 20 118\n5 5 12 2 15 203\n7 4 19 2 22 197\n7 4 24 4 17 209\n0 0 0 0 0 0", "3 2 30 3 26 226\n9 0 18 3 20 118\n5 5 12 0 15 203\n7 4 19 2 22 197\n7 4 24 4 17 209\n0 0 0 0 0 0", "3 2 30 3 41 226\n9 0 18 3 20 118\n5 5 12 0 15 203\n7 4 19 2 22 197\n7 4 24 4 17 209\n0 0 0 0...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Ataru Oafoot of Aizu Gakuen University High School decided to play with a slot machine. When you insert a medal on this machine, three reels will start spinning and each reel will st...
p00391 Treasure Map_26651
Mr. Kobou found a bundle of old paper when he was cleaning his family home. On each paper, two series of numbers are written. Strange as it appeared to him, Mr. Kobou further went through the storehouse and found out a note his ancestor left. According to it, the bundle of paper is a treasure map, in which the two sequ...
import sys,heapq _,a,q=[[-int(e) for e in sys.stdin.readline().split() if e!='0'] for _ in[0]*3] heapq.heapify(q) for e in a: t=[] for _ in [0]*-e: if not q:print(0);exit() if q[0]!=-1:heapq.heappush(t,q[0]+1) heapq.heappop(q) while t:heapq.heappush(q,t[0]);heapq.heappop(t) print(int(not q))
{ "input": [ "5 5\n3 2 3 0 0\n4 2 0 0 2", "5 4\n0 2 2 1 1\n1 1 1 3", "5 3\n3 2 3 0 0\n4 2 0 0 2", "4 4\n0 1 1 1 1\n1 0 1 4", "5 3\n3 2 5 0 0\n4 2 0 0 2", "4 3\n3 2 5 0 0\n4 2 0 0 2", "4 3\n3 2 5 0 0\n4 2 0 0 4", "4 3\n3 2 6 0 0\n4 2 0 0 4", "4 3\n3 1 6 0 0\n4 2 0 0 4", "5 5\n3 ...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Mr. Kobou found a bundle of old paper when he was cleaning his family home. On each paper, two series of numbers are written. Strange as it appeared to him, Mr. Kobou further went thr...
p00607 Emacs-like Editor_26654
Emacs is a text editor which is widely used by many programmers. The advantage of Emacs is that we can move a cursor without arrow keys and the mice. For example, the cursor can be moved right, left, down, and up by pushing f, b, n, p with the Control Key respectively. In addition, cut-and-paste can be performed witho...
class Editer: def __init__(self, text): # カーソルの位置 self.row = 0 #行 self.col = 0 #列 # 編集中のテキスト self.text = [list(t) + ['\n'] for t in text] # バッファー self.buffer = [] def row_head(self): return 0 def row_tail(self): return len(self.text)...
{ "input": [ "hyo\nni\nEND_OF_TEXT\nf\nd\nf\nf\nk\np\np\ne\ny\na\nk\ny\ny\nn\ny\n-", "oyh\nni\nEND_OF_TEXT\nf\nd\nf\nf\nk\np\np\ne\ny\na\nk\ny\ny\nn\ny\n-", "hyo\nnh\nEND_OF_TEXT\nf\nd\nf\nf\nk\np\np\ne\ny\na\nk\ny\ny\nn\ny\n-", "hyo\nni\nEND_OF_TEXT\nf\nd\ng\nf\nk\np\np\ne\ny\na\nk\ny\ny\nn\ny\n-", ...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Emacs is a text editor which is widely used by many programmers. The advantage of Emacs is that we can move a cursor without arrow keys and the mice. For example, the cursor can be m...
p00744 Cards_26658
There are many blue cards and red cards on the table. For each card, an integer number greater than 1 is printed on its face. The same number may be printed on several cards. A blue card and a red card can be paired when both of the numbers printed on them have a common divisor greater than 1. There may be more than o...
import collections import math class Dinic: """Dinic Algorithm: find max-flow complexity: O(EV^2) used in GRL6A(AOJ) """ class edge: def __init__(self, to, cap, rev): self.to, self.cap, self.rev = to, cap, rev def __init__(self, V, E, source, sink): """ V: th...
{ "input": [ "4 3\n2 6 6 15\n2 3 5\n2 3\n4 9\n8 16 32\n4 2\n4 9 11 13\n5 7\n5 5\n2 3 5 1001 1001\n7 11 13 30 30\n10 10\n2 3 5 7 9 11 13 15 17 29\n4 6 10 14 18 22 26 30 34 38\n20 20\n195 144 903 63 137 513 44 626 75 473\n876 421 568 519 755 840 374 368 570 872\n363 650 155 265 64 26 426 391 15 421\n373 984 564 54 ...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are many blue cards and red cards on the table. For each card, an integer number greater than 1 is printed on its face. The same number may be printed on several cards. A blue ...
p00883 Infected Land_26661
The earth is under an attack of a deadly virus. Luckily, prompt actions of the Ministry of Health against this emergency successfully confined the spread of the infection within a square grid of areas. Recently, public health specialists found an interesting pattern with regard to the transition of infected areas. At e...
from collections import deque import sys readline = sys.stdin.readline write = sys.stdout.write dd0 = ((-1, 0), (-1, -1), (0, -1), (1, -1), (1, 0), (1, 1), (0, 1), (-1, 1)) DD = [] for k in range(6): ddk = [] for y in range(k): for x in range(k): v = 0 for dx, dy in dd0: ...
{ "input": [ "3\n...\n.@.\n...\n3\n.##\n.#.\n@##\n3\n##.\n#..\n@..\n5\n....@\n##...\n#....\n...#.\n##.##\n5\n#...#\n...#.\n#....\n...##\n..@..\n5\n#....\n.....\n.....\n.....\n..@..\n5\n#..#.\n#.#.#\n.#.#.\n....#\n.#@##\n5\n..##.\n..#..\n#....\n#....\n.#@..\n0", "3\n...\n.@.\n...\n3\n.##\n.#.\n@##\n3\n.\n..\n@...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: The earth is under an attack of a deadly virus. Luckily, prompt actions of the Ministry of Health against this emergency successfully confined the spread of the infection within a squ...
p01285 Find the Point_26667
We understand that reading English is a great pain to many of you. So we’ll keep this problem statememt simple. Write a program that reports the point equally distant from a set of lines given as the input. In case of no solutions or multiple solutions, your program should report as such. Input The input consists o...
import sys readline = sys.stdin.readline write = sys.stdout.write EPS = 1e-9 def line_cross_point(P1, P2, Q1, Q2): x0, y0 = P1; x1, y1 = P2 x2, y2 = Q1; x3, y3 = Q2 dx0 = x1 - x0; dy0 = y1 - y0 dx1 = x3 - x2; dy1 = y3 - y2 s = (y0-y2)*dx1 - (x0-x2)*dy1 sm = dx0*dy1 - dy0*dx1 if -EPS < sm ...
{ "input": [ "2\n-35 -35 100 100\n-49 49 2000 -2000\n4\n0 0 0 3\n0 0 3 0\n0 3 3 3\n3 0 3 3\n4\n0 3 -4 6\n3 0 6 -4\n2 3 6 6\n-1 2 -4 6\n0", "2\n-35 -35 100 100\n-49 49 2000 -2000\n4\n0 0 0 3\n0 0 3 0\n0 3 3 3\n6 0 3 3\n4\n0 3 -4 6\n3 0 6 -4\n2 3 6 6\n-1 2 -4 6\n0", "2\n-35 -35 100 100\n-49 49 1588 -2000\n4...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: We understand that reading English is a great pain to many of you. So we’ll keep this problem statememt simple. Write a program that reports the point equally distant from a set of li...
p01767 RUPC_26673
Problem statement A programming contest will be held in the Russian Federation. The contest has N questions and has M participants. Question i has a score a_i, and it is known that participant j's ability is b_j. For problem i and participant j, participant j can always solve problem i if a_i ≤ b_j and only then. The ...
import bisect n=int(input()) a=sorted(list(map(int,input().split()))) d=[0]*(n+1) for i in range(1,n+1):d[i]=d[i-1]+a[i-1] m=int(input()) b,c=[list(map(int,input().split())) for _ in [0,0]] for i in range(m): p=bisect.bisect_right(a,b[i]) print(['Yes','No'][d[p]<c[i]])
{ "input": [ "6\n1 2 1 3 4 5\n7\n1 3 4 5 3 1 0\n2 4 5 3 4 5 3", "6\n1 2 1 3 4 5\n7\n1 3 4 5 3 1 0\n2 8 5 3 4 5 3", "6\n1 2 1 3 4 5\n7\n1 3 4 10 3 1 0\n2 4 5 3 4 5 3", "6\n1 2 1 5 4 5\n7\n1 3 4 7 3 1 0\n2 8 5 3 7 5 3", "6\n1 2 2 5 4 5\n7\n1 3 4 7 3 1 0\n2 8 5 3 7 5 3", "6\n2 0 1 3 3 5\n7\n1 1 4...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Problem statement A programming contest will be held in the Russian Federation. The contest has N questions and has M participants. Question i has a score a_i, and it is known that p...
p01901 Suntan_26676
D: Sunburn-Suntan- story Aizunyan is a second-year student who belongs to the programming contest club of Wakagamatsu High School, commonly known as the Prokon club. Cute like an angel. Aizu Nyan is planning to participate in this summer festival, so I made a schedule for the band to go to listen to. I'm worried abou...
# AOJ 2801: Suntan # Python3 2018.7.11 bal4u from bisect import bisect_left T, N = int(input()), int(input()) a, s, t = [0], [0], [0] for i in range(N): _s, _t = map(int, input().split()) s.append(_s) t.append(_t) a.append(a[-1]+_t-_s) s.append(1<<62) t.append(1<<62) ans = 0 k = bisect_left(t, T, 0)-1 for i in ra...
{ "input": [ "20\n1\n0 10", "20\n1\n1 10", "20\n1\n0 7", "20\n1\n2 10", "20\n1\n3 7", "20\n1\n0 19", "20\n1\n0 12", "20\n1\n2 7", "20\n1\n4 10", "20\n1\n0 28", "20\n0\n0 12", "20\n1\n0 3", "20\n1\n4 6", "20\n1\n1 15", "20\n1\n-1 12", "20\n1\n6 7", "2...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: D: Sunburn-Suntan- story Aizunyan is a second-year student who belongs to the programming contest club of Wakagamatsu High School, commonly known as the Prokon club. Cute like an an...
p02038 Tanuki and Fox_26680
problem There is a mysterious device $ M $, and if you put Tanuki and Fox in this device, one animal will come out from the device (hereinafter, Tanuki will be $ T $ and Fox will be $ F $). $ M (x, y) $ represents an animal that came out by putting animals in the device $ M $ in the order of $ x, y $. As a result of...
from functools import reduce def M(x, y): if x == 'T' and y == 'T': return 'T' elif x == 'T' and y == 'F': return 'F' elif x == 'F' and y == 'T': return 'T' else: return 'T' _ = input() P = input().split() print(reduce(M, P))
{ "input": [ "3\nF T T", "3\nF S T", "3\nF R T", "3\nG S T", "3\nG R T", "3\nH R T", "3\nF U T", "3\nE S T", "3\nE T T", "3\nD T T", "3\nI R T", "3\nG Q T", "3\nE U T", "3\nE R T", "3\nD S T", "3\nE V T", "3\nF Q T", "3\nE W T", "3\nD V T", ...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: problem There is a mysterious device $ M $, and if you put Tanuki and Fox in this device, one animal will come out from the device (hereinafter, Tanuki will be $ T $ and Fox will be ...
p02182 Spot The Difference_26683
A: Find the difference problem Given rectangular boards A and B with N squares vertically and M squares horizontally. For each board, each square is painted white or black. The color of the square in the i-th row and j-th column of the board X is written as C (i, j, X). Count how many pairs of integers (i, j) meet ...
N, M = map(int, input().split()) table1 = '' table2 = '' for i in range(2 * N): if i < N: table1 += input() else: table2 += input() count = 0 for i, j in zip(table1, table2): if i != j: count+=1 print(count)
{ "input": [ "2 3\n..#\n##.\n.##\n#..", "2 3\n..\"\n##.\n.##\n#..", "2 3\n..\"\n.##\n.##\n#..", "2 3\n..#\n#\".\n.##\n$./", "2 1\n..\"\n.##\n.##\n#./", "2 3\n..#\n#\".\n##.\n$./", "0 3\n..#\n.\"#\n##.\n$./", "3 3\n#..\n.#\"\n##.\n$./", "2 3\n.#.\n##.\n##.\n#..", "4 3\n..\"\n##....
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: A: Find the difference problem Given rectangular boards A and B with N squares vertically and M squares horizontally. For each board, each square is painted white or black. The col...
p02324 Chinese Postman Problem_26687
For a given weighted undirected graph G(V, E), find the distance of the shortest route that meets the following criteria: * It is a closed cycle where it ends at the same point it starts. * The route must go through every edge at least once. Constraints * 2 ≤ |V| ≤ 15 * 0 ≤ |E| ≤ 1,000 * 0 ≤ di ≤ 1,000 * si ≠ ti * T...
import sys f_i = sys.stdin V, E = map(int, f_i.readline().split()) # adjacency matrix no_edge = float("inf") adj = [[no_edge] * V for i in range(V)] for i in range(V): adj[i][i] = 0 odd_b = 0 # bit DP to record odd vertex ans = 0 # acceptance of input for l_i in f_i: s, t, d = map(int, l_i.split()) ...
{ "input": [ "4 5\n0 1 1\n0 2 2\n1 3 3\n2 3 4\n1 2 5", "4 4\n0 1 1\n0 2 2\n1 3 3\n2 3 4", "2 3\n0 1 1\n0 1 2\n0 1 3", "4 5\n0 1 1\n0 2 2\n1 3 3\n2 3 4\n1 3 5", "4 4\n0 1 1\n1 2 2\n1 3 3\n2 3 4", "6 5\n0 1 1\n0 2 2\n1 3 3\n2 3 7\n1 3 5", "6 4\n0 1 0\n1 2 2\n1 3 3\n2 3 4", "6 4\n0 1 0\n1...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: For a given weighted undirected graph G(V, E), find the distance of the shortest route that meets the following criteria: * It is a closed cycle where it ends at the same point it st...
p02469 Least Common Multiple_26691
Find the least common multiple (LCM) of given n integers. Constraints * 2 ≤ n ≤ 10 * 1 ≤ ai ≤ 1000 * Product of given integers ai(i = 1, 2, ... n) does not exceed 231-1 Input n a1 a2 ... an n is given in the first line. Then, n integers are given in the second line. Output Print the least common multiple of th...
from functools import reduce import math n = int(input()) def lcm_base(x, y): return (x * y) // math.gcd(x, y) def lcm_list(numbers): return reduce(lcm_base, numbers, 1) numlis = [int(a) for a in input().split()] print(lcm_list(numlis))
{ "input": [ "4\n1 2 3 5", "3\n3 4 6", "4\n1 2 5 5", "3\n3 4 3", "4\n1 2 5 7", "3\n3 7 3", "4\n1 2 1 7", "3\n3 10 3", "3\n3 13 3", "4\n1 2 2 11", "3\n6 13 3", "3\n4 13 3", "3\n4 13 4", "3\n4 13 5", "3\n4 6 5", "3\n4 6 7", "3\n4 4 7", "3\n5 4 7", ...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Find the least common multiple (LCM) of given n integers. Constraints * 2 ≤ n ≤ 10 * 1 ≤ ai ≤ 1000 * Product of given integers ai(i = 1, 2, ... n) does not exceed 231-1 Input n a...
1033_C. Permutation Game_26701
After a long day, Alice and Bob decided to play a little game. The game board consists of n cells in a straight line, numbered from 1 to n, where each cell contains a number a_i between 1 and n. Furthermore, no two cells contain the same number. A token is placed in one of the cells. They take alternating turns of mo...
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.wr...
{ "input": [ "15\n3 11 2 5 10 9 7 13 15 8 4 12 6 1 14\n", "8\n3 6 5 4 2 7 1 8\n", "7\n1 2 3 6 7 4 5\n", "15\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\n", "3\n2 3 1\n", "40\n5 40 6 27 39 37 17 34 3 30 28 13 12 8 11 10 31 4 1 16 38 22 29 35 33 23 7 9 24 14 18 26 19 21 15 36 2 20 32 25\n", "6\n5 3...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: After a long day, Alice and Bob decided to play a little game. The game board consists of n cells in a straight line, numbered from 1 to n, where each cell contains a number a_i betwe...
1056_A. Determine Line_26705
Arkady's morning seemed to be straight of his nightmare. He overslept through the whole morning and, still half-asleep, got into the tram that arrived the first. Some time after, leaving the tram, he realized that he was not sure about the line number of the tram he was in. During his ride, Arkady woke up several time...
n = int(input()) def intersect(a, b): x = [] for i in a: if i in b: x.append(i) return x things = [input().split()[1:] for i in range(n)] ans = things[0] for i in range(1, n): ans = intersect(ans, things[i]) print(" ".join(ans))
{ "input": [ "3\n3 1 4 6\n2 1 4\n5 10 5 6 4 1\n", "5\n1 1\n10 10 9 8 7 100 5 4 3 99 1\n5 1 2 3 4 5\n5 4 1 3 2 5\n4 10 1 5 3\n", "2\n1 2\n1 2\n", "6\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n", "2\n35 35 15 89 27 51 72 54 41 58 97 18 93 86 16 44 99 92 29 2 4 26 19 61 21 81 23 10 33 76 83 46 39 32 17 14\n20 90...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Arkady's morning seemed to be straight of his nightmare. He overslept through the whole morning and, still half-asleep, got into the tram that arrived the first. Some time after, leav...
1078_B. The Unbearable Lightness of Weights_26709
You have a set of n weights. You know that their masses are a_1, a_2, ..., a_n grams, but you don't know which of them has which mass. You can't distinguish the weights. However, your friend does know the mass of each weight. You can ask your friend to give you exactly k weights with the total mass m (both parameters ...
from collections import defaultdict def calcBinomials(N): global binom N += 1 binom = [[0]*N for _ in range(N)] for n in range(N): binom[n][0] = binom[n][n] = 1 for k in range(1, n): binom[n][k] = binom[n-1][k] + binom[n-1][k-1] n = int(input()) a = list(map(int, input().sp...
{ "input": [ "6\n1 2 4 4 4 9\n", "4\n1 4 2 2\n", "50\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50\n", "100\n50 50 50 50 50 50 87 87 87 46 46 46 96 96 96 96 94 94 94 47 47 47 42 84 86 84 84 93 49 49 49 49 8...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You have a set of n weights. You know that their masses are a_1, a_2, ..., a_n grams, but you don't know which of them has which mass. You can't distinguish the weights. However, you...
1099_B. Squares and Segments_26713
Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw n squares in the snow with a side length of 1. For simplicity, we assume that Sofia lives on a plane and can draw only segments of length 1, parallel to the coordinate axes, with ve...
# cook your dish here t=int(input()) l=int(t**(0.5)) if l==(t**(0.5)): print(2*l) else: if abs((l**2)-t) < ((l+1)**2)-t: print(2*l+1) else: print(2*(l+1))
{ "input": [ "4\n", "1\n", "2\n", "10\n", "87341\n", "204575811\n", "605551861\n", "8\n", "776\n", "864918\n", "377684528\n", "15\n", "972\n", "1000000000\n", "8795795\n", "423353776\n", "16\n", "9\n", "772168\n", "11\n", "306495050\n...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Little Sofia is in fourth grade. Today in the geometry lesson she learned about segments and squares. On the way home, she decided to draw n squares in the snow with a side length of ...
111_A. Petya and Inequiations_26717
Little Petya loves inequations. Help him find n positive integers a1, a2, ..., an, such that the following two conditions are satisfied: * a12 + a22 + ... + an2 ≥ x * a1 + a2 + ... + an ≤ y Input The first line contains three space-separated integers n, x and y (1 ≤ n ≤ 105, 1 ≤ x ≤ 1012, 1 ≤ y ≤ 106). Please d...
from math import sqrt, ceil n, x, y = map(int, input().split()) t = 1 if x < n else ceil(sqrt(x - n + 1)) if t + n - 1 > y: print(-1) else: print(str(t), '\n1' * (n - 1))
{ "input": [ "5 15 15\n", "1 99 11\n", "2 3 2\n", "99976 664640815001 915230\n", "7 937519681542 968262\n", "100000 1 1\n", "99999 681508136225 925533\n", "100000 1000000000000 1000000\n", "1 1 1\n", "10 3 8\n", "1 860113420929 927423\n", "4 324 77\n", "5 37 10\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Little Petya loves inequations. Help him find n positive integers a1, a2, ..., an, such that the following two conditions are satisfied: * a12 + a22 + ... + an2 ≥ x * a1 + a2 + ....
1167_F. Scalar Queries_26723
You are given an array a_1, a_2, ..., a_n. All a_i are pairwise distinct. Let's define function f(l, r) as follows: * let's define array b_1, b_2, ..., b_{r - l + 1}, where b_i = a_{l - 1 + i}; * sort array b in increasing order; * result of the function f(l, r) is ∑_{i = 1}^{r - l + 1}{b_i ⋅ i}. Calcula...
import sys MOD = (int)(1e9+7) def add(a, b): a += b if a >= MOD: a -= MOD return a def mul(a, b): return (a * b) % MOD class fenwickTree: def __init__(self, max_val): self.max_val = max_val + 5 self.tree = [0] * self.max_val def update(self, idx, value): idx += 1 while idx < self.max_val: self.t...
{ "input": [ "3\n123456789 214365879 987654321\n", "4\n5 2 4 7\n", "8\n9 1 4 10 7 5 8 6\n", "8\n3 8 10 6 7 5 2 9\n", "8\n9 8 4 5 6 1 7 10\n", "8\n2 5 4 9 7 1 6 3\n", "8\n10 8 5 1 4 2 3 6\n", "2\n1 1000000000\n", "8\n2 3 10 5 9 1 4 7\n", "8\n8 5 2 3 7 1 6 10\n", "1\n1\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given an array a_1, a_2, ..., a_n. All a_i are pairwise distinct. Let's define function f(l, r) as follows: * let's define array b_1, b_2, ..., b_{r - l + 1}, where b_i =...
1186_A. Vus the Cossack and a Contest_26727
Vus the [Cossack](https://en.wikipedia.org/wiki/Cossacks) holds a programming competition, in which n people participate. He decided to award them all with pens and notebooks. It is known that Vus has exactly m pens and k notebooks. Determine whether the Cossack can reward all participants, giving each of them at leas...
def solve(n, m, k): if min(m,k) >= n: return "Yes" else: return "No" def main(): n, m, k = list(map(int, input().split())) print(solve(n, m, k)) if __name__ == '__main__': main()
{ "input": [ "8 5 20\n", "3 9 3\n", "5 8 6\n", "5 3 2\n", "20 61 100\n", "44 2 53\n", "100 1 1\n", "100 100 100\n", "68 73 96\n", "92 35 39\n", "2 2 2\n", "68 91 90\n", "54 82 100\n", "1 1 1\n", "2 1 1\n", "2 1 2\n", "2 2 1\n", "100 99 99\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Vus the [Cossack](https://en.wikipedia.org/wiki/Cossacks) holds a programming competition, in which n people participate. He decided to award them all with pens and notebooks. It is k...
1205_A. Almost Equal_26731
You are given integer n. You have to arrange numbers from 1 to 2n, using each of them exactly once, on the circle, so that the following condition would be satisfied: For every n consecutive numbers on the circle write their sum on the blackboard. Then any two of written on the blackboard 2n numbers differ not more th...
n = int(input()) if n%2 == 0: print("NO") exit(0) arr = [] for i in range(1, n+1): if i%2 == 1: arr.append(2*i-1) else: arr.append(2*i) for i in range(n): if arr[i] % 2 == 1: arr.append(arr[i]+1) else: arr.append(arr[i]-1) print("YES") print(*arr)
{ "input": [ "4\n", "3\n", "11\n", "2\n", "6\n", "10\n", "65\n", "9\n", "4096\n", "5\n", "64\n", "14786\n", "4097\n", "78946\n", "100000\n", "14785\n", "1\n", "1024\n", "63\n", "13\n", "58\n", "7\n", "85\n", "463\n", "...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given integer n. You have to arrange numbers from 1 to 2n, using each of them exactly once, on the circle, so that the following condition would be satisfied: For every n con...
1221_E. Game With String_26735
Alice and Bob play a game. Initially they have a string s_1, s_2, ..., s_n, consisting of only characters . and X. They take alternating turns, and Alice is moving first. During each turn, the player has to select a contiguous substring consisting only of characters . and replaces each of them with X. Alice must select...
q = int(input()) for i in range(q): a, b = [int(item) for item in input().split()] s = input().rstrip() + "#" cnt = 0 bob_world = 0 alice_world = 0 length = 0 bob_winning = False for ch in s: if ch == ".": cnt += 1 else: if cnt < b: ...
{ "input": [ "3\n3 2\nXX......XX...X\n4 2\nX...X.X..X\n5 3\n.......X..X\n", "6\n5 4\n...............\n5 4\n...............X.....\n5 4\n...............X....\n5 4\n...............X.....X....\n5 4\n...................\n5 4\n...................X.....\n", "7\n240501 42869\nXX.X.X.X.X.X...\n251441 50561\nX\n247...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Alice and Bob play a game. Initially they have a string s_1, s_2, ..., s_n, consisting of only characters . and X. They take alternating turns, and Alice is moving first. During each ...
1248_B. Grow The Tree_26739
Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them. The tree looks like a polyline on the plane, consisting o...
a=int(input());b=sorted(list(map(int,input().split())),reverse=True);from math import ceil as c;print(sum(b[:c(len(b)/2)])**2+sum(b[c(len(b)/2):])**2)
{ "input": [ "4\n1 1 2 2\n", "3\n1 2 3\n", "1\n2359\n", "10\n9381 6234 2965 9236 4685 3101 5832 7369 5233 5308\n", "10\n5957 94 8220 2463 9623 7028 9656 677 8373 1126\n", "10\n9906 9903 10000 9998 9936 9952 9924 9939 9917 9966\n", "11\n15 12 9915 40 63 9984 9968 9924 9925 11 9991\n", "...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where...
1288_A. Deadline_26745
Adilbek was assigned to a special project. For Adilbek it means that he has n days to run a special program and provide its results. But there is a problem: the program needs to run for d days to calculate the results. Fortunately, Adilbek can optimize the program. If he spends x (x is a non-negative integer) days opt...
import math for _ in range(int(input())): n,d = map(int,input().split()) if ((1-n)**2) - (4*(d-n)) >= 0: print('YES') else: print('NO')
{ "input": [ "3\n1 1\n4 5\n5 11\n", "1\n1000000 1000000\n", "2\n63242 999919263\n63242 999919264\n", "5\n1000000000 1000000000\n1000000000 1000000000\n1000000000 1000000000\n1000000000 1000000000\n1000000000 1000000000\n", "5\n998244353 999999998\n998244353 999999999\n998244353 999999978\n99824435...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Adilbek was assigned to a special project. For Adilbek it means that he has n days to run a special program and provide its results. But there is a problem: the program needs to run f...
1331_D. Again?_26749
Input The only line of the input contains a 7-digit hexadecimal number. The first "digit" of the number is letter A, the rest of the "digits" are decimal digits 0-9. Output Output a single integer. Examples Input A278832 Output 0 Input A089956 Output 0 Input A089957 Output 1 Input A1440...
value = input() print(int(value, 16)%2)
{ "input": [ "A089956\n", "A089957\n", "A144045\n", "A278832\n", "A089946\n", "A144035\n", "A378822\n", "A089947\n", "A378282\n", "A079948\n", "A388282\n", "A079848\n", "A388822\n", "A079849\n", "B388822\n", "A079749\n", "B398822\n", "A079759\n",...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Input The only line of the input contains a 7-digit hexadecimal number. The first "digit" of the number is letter A, the rest of the "digits" are decimal digits 0-9. Output Outpu...
1351_B. Square?_26753
Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular parts. You need to check whether Vasya originally had a square. In other words, check if it is possible to make a square using two given rec...
for t in range(int(input())): a, b = map(int, input().split()) c, d = map(int, input().split()) a, b = min(a, b), max(a, b) c, d = min(c, d), max(c, d) if a + c == b == d: print("YES") else: print("NO")
{ "input": [ "3\n2 3\n3 1\n3 2\n1 3\n3 3\n1 3\n", "1\n64 9\n41 36\n", "1\n64 9\n41 14\n", "3\n2 3\n3 1\n3 2\n1 3\n3 6\n1 3\n", "3\n2 3\n3 1\n3 0\n1 3\n3 6\n1 3\n", "3\n2 4\n3 1\n3 0\n1 3\n3 6\n1 3\n", "1\n59 9\n41 14\n", "1\n5 9\n41 14\n", "1\n5 14\n41 14\n", "3\n3 3\n3 1\n3 0\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Vasya claims that he had a paper square. He cut it into two rectangular parts using one vertical or horizontal cut. Then Vasya informed you the dimensions of these two rectangular par...
1371_D. Grid-00100_26757
A mad scientist Dr.Jubal has made a competitive programming task. Try to solve it! You are given integers n,k. Construct a grid A with size n × n consisting of integers 0 and 1. The very important condition should be satisfied: the sum of all elements in the grid is exactly k. In other words, the number of 1 in the gr...
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...
{ "input": [ "4\n2 2\n3 8\n1 0\n4 16\n", "2\n297 47297\n103 6336\n", "2\n79 4902\n292 64563\n", "1\n297 66454\n", "2\n300 8182\n100 1998\n", "2\n201 28281\n201 22388\n", "1\n300 90000\n", "2\n296 52649\n104 10109\n", "6\n46 1953\n149 14272\n70 3514\n98 8445\n124 4555\n196 26273\n",...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: A mad scientist Dr.Jubal has made a competitive programming task. Try to solve it! You are given integers n,k. Construct a grid A with size n × n consisting of integers 0 and 1. The ...
1394_A. Boboniu Chats with Du_26761
Have you ever used the chat application QQ? Well, in a chat group of QQ, administrators can muzzle a user for days. In Boboniu's chat group, there's a person called Du Yi who likes to make fun of Boboniu every day. Du will chat in the group for n days. On the i-th day: * If Du can speak, he'll make fun of Boboniu ...
#! /usr/bin/python3 n, d, m = [int(inp) for inp in input().split()] aArr = sorted([int(inp) for inp in input().split()], reverse = True) i = sum([j > m for j in aArr]) aU = aArr[:i] aL = aArr[i:] aUS = aU for i in range(1, len(aU)): aUS[i] += aUS[i - 1] aUS = [0] + aUS aLS = aL for i in range(1, len(aL)): aLS[i]...
{ "input": [ "20 2 16\n20 5 8 2 18 16 2 16 16 1 5 16 2 13 6 16 4 17 21 7\n", "5 2 11\n8 10 15 23 5\n", "10 1 73\n46 83 26 98 96 83 87 42 10 17\n", "10 3 10\n17 17 17 8 7 6 5 4 1 1\n", "39 37 39\n38 56 198 166 86 51 13 54 101 143 82 138 122 146 86 198 81 177 92 56 107 58 124 82 41 126 79 47 191 41 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Have you ever used the chat application QQ? Well, in a chat group of QQ, administrators can muzzle a user for days. In Boboniu's chat group, there's a person called Du Yi who likes t...
1436_E. Complicated Computations_26767
In this problem MEX of a certain array is the smallest positive integer not contained in this array. Everyone knows this definition, including Lesha. But Lesha loves MEX, so he comes up with a new problem involving MEX every day, including today. You are given an array a of length n. Lesha considers all the non-empty...
class SegmentTree: def __init__(self, init_val, segfunc, ide_ele): n = len(init_val) self.segfunc = segfunc self.ide_ele = ide_ele self.num = 1 << (n - 1).bit_length() self.tree = [ide_ele] * 2 * self.num self.range = [(-1,n)] * 2 * self.num # 配列の値を葉にセット ...
{ "input": [ "5\n1 4 3 1 2\n", "3\n1 3 2\n", "94\n23 8 25 27 33 16 8 8 15 11 33 23 13 18 26 20 21 10 18 15 6 11 21 14 27 16 5 1 33 11 31 33 3 21 31 7 28 32 19 16 20 22 23 18 24 16 24 18 22 12 31 9 14 29 25 29 29 16 12 15 21 6 30 21 28 11 2 33 7 12 33 16 28 32 28 27 21 18 27 17 24 22 23 4 16 2 5 23 2 21 3 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: In this problem MEX of a certain array is the smallest positive integer not contained in this array. Everyone knows this definition, including Lesha. But Lesha loves MEX, so he comes...
1461_C. Random Events_26771
Ron is a happy owner of a permutation a of length n. A permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array) and [1,3,4] is also not a permutation (n=3 but there is...
# by the authority of GOD author: manhar singh sachdev # import os,sys from io import BytesIO, IOBase def main(): for _ in range(int(input())): n,m = map(int,input().split()) a = list(map(int,input().split())) j = n-1 while j != -1 and a[j] == j+1: j -= 1 if...
{ "input": [ "4\n4 3\n4 3 2 1\n1 0.3\n3 1\n4 0.6\n5 3\n4 2 1 3 5\n3 0.8\n4 0.6\n5 0.3\n6 5\n1 3 2 4 5 6\n4 0.9\n5 0.3\n2 0.4\n6 0.7\n3 0.5\n4 2\n1 2 3 4\n2 0.5\n4 0.1\n", "1\n5 5\n1 2 3 5 4\n5 0.5\n5 0.5\n5 0.5\n5 0.5\n5 0.5\n", "4\n9 1\n1 2 3 4 5 6 7 8 9\n6 0.000000\n6 1\n1 2 3 4 5 6\n1 0.000033\n4 1\n1 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Ron is a happy owner of a permutation a of length n. A permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] ...
1486_D. Max Median_26775
You are a given an array a of length n. Find a subarray a[l..r] with length at least k with the largest median. A median in an array of length n is an element which occupies position number ⌊ (n + 1)/(2) ⌋ after we sort the elements in non-decreasing order. For example: median([1, 2, 3, 4]) = 2, median([3, 2, 1]) = 2,...
import collections def solveTestCase(): n, k = [int(i) for i in input().split()] a = [int(i) for i in input().split()] r = n + 1 l = 1 while r - l > 1: m = (r+l)//2 b = [1 if i >= m else -1 for i in a] for i in range(1, len(b)): b[i] += b[i - 1] ans = False if b[k-1] > 0: ans = True mm = 0 fo...
{ "input": [ "5 3\n1 2 3 2 1\n", "4 2\n1 2 3 4\n", "100 99\n11 9 99 37 72 48 71 61 19 75 41 94 71 86 7 35 2 83 77 72 71 60 32 38 5 35 28 61 46 31 70 33 96 70 75 64 44 81 95 71 62 70 83 21 98 55 40 42 59 64 86 13 90 81 78 55 15 78 76 62 68 9 69 23 45 75 2 36 78 16 75 99 40 34 9 32 13 42 73 63 98 83 86 28 7...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are a given an array a of length n. Find a subarray a[l..r] with length at least k with the largest median. A median in an array of length n is an element which occupies position...
1510_D. Digits_26778
Diana loves playing with numbers. She's got n cards with positive integer numbers a_i written on them. She spends her free time multiplying the numbers on the cards. She picks a non-empty subset of the cards and multiplies all the numbers a_i written on them. Diana is happy when the product of the numbers ends with he...
import math;n, d = map(int, input().split());a = [int(_) for _ in input().split()];dp = [[-1e10] * 10 for _ in range(n + 1)] come = [[(0, 0, 0) for i in range(10)] for j in range(n + 1)];dp[0][1] = 0 for i in range(n): for j in range(10): val = dp[i][j] + math.log(a[i]) if dp[i + 1][(j * a[i]) % 10]...
{ "input": [ "5 7\n1 3 1 5 3\n", "6 4\n4 11 8 2 1 13\n", "6 3\n8 9 4 17 11 5\n", "5 6\n2 2 2 2 2\n", "3 1\n2 4 6\n", "10 9\n6 4 1 6 4 9 2 2 10 5\n", "10 7\n5 10 4 3 8 10 6 1 6 2\n", "8 2\n65 77 69 91 4 5 79 52\n", "3 8\n2 9 108\n", "10 2\n9 4 6 3 10 6 6 4 10 2\n", "10 1\n9 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Diana loves playing with numbers. She's got n cards with positive integer numbers a_i written on them. She spends her free time multiplying the numbers on the cards. She picks a non-e...
1536_F. Omkar and Akmar_26781
Omkar and Akmar are playing a game on a circular board with n (2 ≤ n ≤ 10^6) cells. The cells are numbered from 1 to n so that for each i (1 ≤ i ≤ n-1) cell i is adjacent to cell i+1 and cell 1 is adjacent to cell n. Initially, each cell is empty. Omkar and Akmar take turns placing either an A or a B on the board, wit...
import sys input = sys.stdin.readline n = int(input()) mod = 10 ** 9 + 7 F = [0] * (n + 1) F[0] = 1 for i in range(1, n + 1): F[i] = i * F[i - 1] % mod iF = [0] * (n + 1) iF[-1] = pow(F[-1], mod - 2, mod) for i in range(n - 1, -1, -1): iF[i] = iF[i + 1] * (i + 1) % mod def C(n, k): if k > n: return 0 ...
{ "input": [ "69420\n", "42069\n", "2\n", "24\n", "38\n", "999993\n", "31\n", "999989\n", "27\n", "46\n", "999972\n", "5\n", "41\n", "999996\n", "999994\n", "19\n", "999975\n", "35\n", "4\n", "33\n", "23\n", "45\n", "37\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Omkar and Akmar are playing a game on a circular board with n (2 ≤ n ≤ 10^6) cells. The cells are numbered from 1 to n so that for each i (1 ≤ i ≤ n-1) cell i is adjacent to cell i+1 ...
185_A. Plant_26787
Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides into four triangle plants: three of them will point "upwards" and one will point "downwards". After another year, each triangle plant divide...
n=int(input()) e=10**9+7 print(1if n==0else(pow(2,n-1,e)+pow(2,n*2-1,e))%e) # Made By Mostafa_Khaled
{ "input": [ "1\n", "2\n", "7\n", "84324827171274022\n", "74859961358140080\n", "10\n", "5\n", "148049062285906746\n", "615812227854199662\n", "585335721566249104\n", "791809296233191092\n", "522842183413115087\n", "819875140559301751\n", "16\n", "9313565017...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Dwarfs have planted a very interesting plant, which is a triangle directed "upwards". This plant has an amusing feature. After one year a triangle plant directed "upwards" divides int...
231_B. Magic, Wizardry and Wonders_26793
Vasya the Great Magician and Conjurer loves all kinds of miracles and wizardry. In one wave of a magic wand he can turn an object into something else. But, as you all know, there is no better magic in the Universe than the magic of numbers. That's why Vasya adores math and spends a lot of time turning some numbers into...
n, d, L = map(int, input().split()) sp = [] for _ in range(n - 1): if d <= 0: sp.append(1) d = 1 - d else: sp.append(L) d = L - d if 1 <= d <= L: sp.append(d) print(*sp) else: print(-1)
{ "input": [ "3 3 2\n", "5 -4 4\n", "5 -4 3\n", "100 -1000 100\n", "20 97 13\n", "100 1000 3\n", "100 -1000 100\n", "50 231 39\n", "60 -728 29\n", "5 2 2\n", "2 1 1\n", "100 -1000 1\n", "100 1000 100\n", "100 -1000 3\n", "100 -10000 100\n", "70 2335 100\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Vasya the Great Magician and Conjurer loves all kinds of miracles and wizardry. In one wave of a magic wand he can turn an object into something else. But, as you all know, there is n...
257_A. Sockets_26797
Vasya has got many devices that work on electricity. He's got n supply-line filters to plug the devices, the i-th supply-line filter has ai sockets. Overall Vasya has got m devices and k electrical sockets in his flat, he can plug the devices or supply-line filters directly. Of course, he can plug the supply-line filt...
n,m,k=map(int,input().split(" ")) li=list(map(int,input().split(" ",n)[:n])) li.sort(reverse=True) fl=0 a,s=0,0 if m<=k: print(0) else: while fl==0 and a<n: s+=li[a] a+=1 if a!=1: s-=1 if s+k-1>=m and a!=0: fl=1 break if fl!=1: prin...
{ "input": [ "4 7 2\n3 3 2 4\n", "3 5 3\n3 1 2\n", "5 5 1\n1 3 1 2 1\n", "10 49 11\n5 18 1 19 11 11 16 5 6 6\n", "1 1 1\n1\n", "13 20 9\n2 9 2 2 5 11 10 10 13 4 6 11 14\n", "15 26 4\n3 6 7 1 5 2 4 4 7 3 8 7 2 4 8\n", "5 50 6\n2 1 3 1 3\n", "50 50 2\n2 2 4 5 2 1 5 4 5 4 5 2 1 2 3 3 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Vasya has got many devices that work on electricity. He's got n supply-line filters to plug the devices, the i-th supply-line filter has ai sockets. Overall Vasya has got m devices a...
280_A. Rectangle Puzzle_26801
You are given two rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle's sides are parallel to the coordinate axes: the length of the side that is parallel to the Ox axis, equals w, the length of the side tha...
from math import radians, cos, sin, atan2 def rotate(point, alpha): x = point[0] y = point[1] return (x * cos(alpha) - y * sin(alpha), x * sin(alpha) + y * cos(alpha)) def crs(a, b): return a[0] * b[1] - a[1] * b[0] def m(end, start): return (end[0] - start[0], end[1] - start[1]) def area(poly):...
{ "input": [ "6 4 30\n", "1 1 45\n", "938133 287232 156\n", "143003 283714 102\n", "2 100 90\n", "129842 930245 115\n", "646084 979010 45\n", "659245 591935 32\n", "991245 527535 69\n", "100 100 30\n", "44247 849307 176\n", "34989 23482 180\n", "606243 819219 106\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 rectangles on a plane. The centers of both rectangles are located in the origin of coordinates (meaning the center of the rectangle's symmetry). The first rectangle'...
32_A. Reconnaissance_26808
According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ by at most d centimeters. Captain Bob has n soldiers in his detachment. Their heights are a1, a2, ..., an centimeters. Some soldiers are ...
n, d = [int(i) for i in input().split()] S = sorted([int(i) for i in input().split()]) k = 0 for i in range(n): for j in range(i+1, n): if(S[j]-S[i]<=d): k += 1 else: break print(k*2)
{ "input": [ "5 1\n55 30 29 31 55\n", "5 10\n10 20 50 60 65\n", "100 100\n51 93 101 960 2 477 213 129 663 925 254 78 1486 274 160 481 132 156 412 372 5 57 152 298 1771 7 359 468 254 406 202 929 221 366 552 97 555 29 822 118 539 140 992 854 7 163 134 103 940 30 409 1003 398 43 555 79 107 40 23 103 643 171 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: According to the regulations of Berland's army, a reconnaissance unit should consist of exactly two soldiers. Since these two soldiers shouldn't differ much, their heights can differ ...
397_B. On Corruption and Numbers_26816
Alexey, a merry Berland entrant, got sick of the gray reality and he zealously wants to go to university. There are a lot of universities nowadays, so Alexey is getting lost in the diversity — he has not yet decided what profession he wants to get. At school, he had bad grades in all subjects, and it's only thanks to w...
t = int(input()) for _ in range(t): n, l, r = map(int, input().split()) print("No" if n // l * r < n else "Yes")
{ "input": [ "2\n5 2 3\n6 4 5\n", "50\n69 6 6\n22 1 1\n23 3 3\n60 13 13\n13 3 3\n7 4 7\n6 1 1\n49 7 9\n68 8 8\n20 2 2\n34 1 1\n79 5 5\n22 1 1\n77 58 65\n10 3 3\n72 5 5\n47 1 1\n82 3 3\n92 8 8\n34 1 1\n42 9 10\n63 14 14\n10 3 3\n38 2 2\n80 6 6\n79 5 5\n53 5 5\n44 7 7\n85 2 2\n24 2 2\n57 3 3\n95 29 81\n77 6 6\n...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Alexey, a merry Berland entrant, got sick of the gray reality and he zealously wants to go to university. There are a lot of universities nowadays, so Alexey is getting lost in the di...
41_C. Email address_26820
Sometimes one has to spell email addresses over the phone. Then one usually pronounces a dot as dot, an at sign as at. As a result, we get something like vasyaatgmaildotcom. Your task is to transform it into a proper email address (vasya@gmail.com). It is known that a proper email address contains only such symbols a...
a = input() b = '' if a[0] + a[1] + a[2] == 'dot': b += 'dot' i = 3 elif a[0] + a[1] == 'at': b += 'at' i = 2 else: i = 0 at = 0 while i < len(a) - 3: if a[i] == 'd' and a[i + 1] == 'o' and a[i + 2] == 't': b += '.' i += 3 elif a[i] == 'a' and a[i + 1] == 't' and at == 0: ...
{ "input": [ "vasyaatgmaildotcom\n", "aatt\n", "dotdotdotatdotdotat\n", "dotdotdotdotdotdotdotdotdotdotdotdoatdotdotdotdotdotdotdotdotdotdotdotdotdotdotdotdotdotdotdotdotdot\n", "zdotdotatdotz\n", "hatatatdotcatqatdotwhvdotatdotsatattatatcdotddotdotvasatdottxdotatatdotatmdotvvatkatdotxatcdotdo...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Sometimes one has to spell email addresses over the phone. Then one usually pronounces a dot as dot, an at sign as at. As a result, we get something like vasyaatgmaildotcom. Your task...
446_A. DZY Loves Sequences_26824
DZY has a sequence a, consisting of n integers. We'll call a sequence ai, ai + 1, ..., aj (1 ≤ i ≤ j ≤ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment. Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one numb...
def ii(): return int(input()) def si(): return input() def mi(): return map(int,input().split()) def msi(): return map(str,input().split()) def li(): return list(mi()) n=ii() a=li() pre,suf = [1]*n,[1]*n for i in range(1,n): if a[i]>a[i-1]: pre[i]+=pre[i-1] for i in range(n-2,-1,-1): if a[i]...
{ "input": [ "6\n7 2 3 1 5 6\n", "5\n2 3 7 5 6\n", "5\n1 3 3 4 5\n", "3\n81 33 64\n", "5\n1 2 3 4 1\n", "3\n5 1 2\n", "3\n20 1 9\n", "4\n1 5 3 4\n", "10\n1 1 5 3 2 9 9 7 7 6\n", "5\n2 4 7 6 8\n", "10\n1 2 3 4 5 10 10 11 12 13\n", "1\n1\n", "5\n1 2 5 3 4\n", "2\n...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: DZY has a sequence a, consisting of n integers. We'll call a sequence ai, ai + 1, ..., aj (1 ≤ i ≤ j ≤ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of ...
468_B. Two Sets_26828
Little X has n distinct integers: p1, p2, ..., pn. He wants to divide all of them into two sets A and B. The following two conditions must be satisfied: * If number x belongs to set A, then number a - x must also belong to set A. * If number x belongs to set B, then number b - x must also belong to set B. Hel...
import sys import queue sys.setrecursionlimit(100000) # global constant INF = int(1e7+1) MAX = 100005 # For testing #sys.stdin = open("INP.txt", 'r') #sys.stdout = open("OUT.txt", 'w') # global variables parents = [] ranks = [] size = [] n = 0 # classes class Pair: def __init__(self, a, b): self.first...
{ "input": [ "3 3 4\n1 2 4\n", "4 5 9\n2 3 4 5\n", "4 10 9\n6 5 4 3\n", "1 1 1\n1\n", "2 2 3\n1 2\n", "70 416035 416023\n70034 70322 345689 345965 345701 70046 345737 345713 70166 345821 70010 345749 345677 345725 69962 345869 70178 70310 345785 69998 70070 69974 70058 346001 70106 345953 7022...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Little X has n distinct integers: p1, p2, ..., pn. He wants to divide all of them into two sets A and B. The following two conditions must be satisfied: * If number x belongs to se...
490_B. Queue_26832
During the lunch break all n Berland State University students lined up in the food court. However, it turned out that the food court, too, has a lunch break and it temporarily stopped working. Standing in a queue that isn't being served is so boring! So, each of the students wrote down the number of the student ID of...
import math from collections import deque class Empty(Exception): pass class _DoublyLinkedBase: """A base class providing a doubly linked list representation.""" #-------------------------- nested _Node class -------------------------- # nested _Node class class _Node: """Lightweight, nonpublic class ...
{ "input": [ "4\n92 31\n0 7\n31 0\n7 141\n", "6\n10001 0\n0 10005\n10003 10001\n10002 10000\n10005 10002\n10004 10003\n", "3\n0 2\n1 3\n2 0\n", "9\n308992 348750\n0 6496\n487447 676506\n874677 985199\n260782 487447\n985199 260782\n348750 0\n570981 308992\n6496 570981\n", "6\n341637 51795\n0 809471...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: During the lunch break all n Berland State University students lined up in the food court. However, it turned out that the food court, too, has a lunch break and it temporarily stoppe...
514_B. Han Solo and Lazer Gun_26836
There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plane. Han Solo has the newest duplex lazer gun to fight these stormtroopers. It is situated at the point (x0, y0). In one shot it can can ...
n, x0, y0 = map(int, input().split()) slopes = {} # key: (num, den), val: count for i in range(n): x, y = map(int, input().split()) num = y - y0 den = x - x0 # print(num, den) if den == 0 and "inf" in slopes: slopes["inf"] += 1 elif den == 0: slopes["inf"] = 1 else: ...
{ "input": [ "2 1 2\n1 1\n1 0\n", "4 0 0\n1 1\n2 2\n2 0\n-1 -1\n", "2 -10000 -10000\n9998 9999\n9999 10000\n", "10 -4 -4\n2 -4\n2 0\n-4 2\n5 -4\n-3 -5\n1 4\n-4 2\n-3 5\n0 -3\n2 4\n", "2 -10000 -10000\n10000 10000\n10000 9999\n", "2 0 0\n10000 -10000\n10000 10000\n", "2 0 0\n0 2\n1 90\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are n Imperial stormtroopers on the field. The battle field is a plane with Cartesian coordinate system. Each stormtrooper is associated with his coordinates (x, y) on this plan...
540_C. Ice Cave_26840
You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is to fall through the ice. The level of the cave where you are is a rectangular square grid of n rows and m columns. Each cell consists e...
import queue MAX = 500 dr = [0,0,1,-1] dc = [1,-1,0,0] def isValid(r, c): return r in range(m) and c in range(n) def BFS(sr, sc, fr, fc): q = [0] * (MAX * MAX) left = right = 0 q[0] = (sr, sc) while left <= right: ur, uc = q[left] left += 1 for i in range(4): vr = ur + dr[i] vc = uc ...
{ "input": [ "5 4\n.X..\n...X\nX.X.\n....\n.XX.\n5 3\n1 1\n", "4 7\n..X.XX.\n.XX..X.\nX...X..\nX......\n2 2\n1 6\n", "4 6\nX...XX\n...XX.\n.X..X.\n......\n1 6\n2 2\n", "1 2\nX.\n1 1\n1 2\n", "2 1\nX\nX\n2 1\n2 1\n", "4 3\n..X\n..X\n.XX\n.XX\n4 2\n2 2\n", "2 2\n..\nXX\n2 1\n1 1\n", "2 2...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You play a computer game. Your character stands on some level of a multilevel ice cave. In order to move on forward, you need to descend one level lower and the only way to do this is...
58_B. Coins_26847
In Berland a money reform is being prepared. New coins are being introduced. After long economic calculations was decided that the most expensive coin should possess the denomination of exactly n Berland dollars. Also the following restriction has been introduced for comfort: the denomination of each coin should be div...
def O(x): l=[] if x==1: return 1 for i in range(1,x//2+1): if x%i==0: l.append(i) print(x) return O(l[len(l)-1]) x=int(input()) O(x) print(1)
{ "input": [ "3\n", "4\n", "10\n", "473273\n", "784653\n", "8\n", "1000000\n", "20\n", "10000\n", "25\n", "627251\n", "7\n", "2430\n", "12\n", "733035\n", "893193\n", "1331\n", "648\n", "600\n", "21\n", "999999\n", "36\n", "10...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: In Berland a money reform is being prepared. New coins are being introduced. After long economic calculations was decided that the most expensive coin should possess the denomination ...
631_A. Interview_26854
Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following problem. We define function f(x, l, r) as a bitwise OR of integers xl, xl + 1, ...
read = lambda: map(int, input().split()) n = int(input()) a = list(read()) b = list(read()) f1 = f2 = 0 for i in a: f1 |= i for i in b: f2 |= i print(f1 + f2)
{ "input": [ "10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6\n", "5\n1 2 4 3 2\n2 3 3 12 1\n", "25\n12 30 38 109 81 124 80 33 38 48 29 78 96 48 96 27 80 77 102 65 80 113 31 118 35\n25 64 95 13 12 6 111 80 85 16 61 119 23 65 73 65 20 95 124 18 28 79 125 106 116\n", "1\n0\n0\n", "8\n1 2 4 8 16 32 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to p...
706_B. Interesting drink_26861
Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in n different shops in the city. It's known that the price of one bottle in the shop i is equal to xi coins. Vasiliy plans to buy his favorite drink fo...
def binary(t,s): fir=0 last=len(t)-1 mid=0 while(fir<=last): mid=(fir+last)//2 if t[mid]>s: last=mid-1 else: fir=mid+1 return last+1 n=int(input()) t=list(map(int,input().split())) m=int(input()) p=0 t.sort() for i in range(m): s=int(inp...
{ "input": [ "5\n3 10 8 6 11\n4\n1\n10\n3\n11\n", "3\n1 2 3\n1\n100005\n", "5\n3 10 8 6 11\n1\n10000000\n", "12\n35345 58181 32223 84621 35905 73863 99537 30666 67771 39229 36847 29038\n23\n55052824\n82504840\n35160556\n78141700\n73401989\n86305919\n39430705\n31939373\n23501765\n4406029\n61436920\n142...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Vasiliy likes to rest after a hard work, so you may often meet him in some bar nearby. As all programmers do, he loves the famous drink "Beecola", which can be bought in n different s...
729_D. Sea Battle_26865
Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two ships, however, the ships can touch each other. Galya doesn't know the ships location. She can shoot to some cells and after each shot ...
n,a,b,k = map(int, input().split()) open = 0 must = 0 must_arr = [] for i,c in enumerate(input()): if c == '1': open = 0 else: open += 1 if open == b: open = 0 must += 1 if must >= a: must_arr.append(i+1) must -= a - 1 print(must) ...
{ "input": [ "5 1 2 1\n00100\n", "13 3 2 3\n1000000010001\n", "13 3 2 3\n1000000010001\n", "100 17 4 11\n0100000100000000000000001000000000010001100000000000101000000000000000000000001000001000010000000000\n", "5 1 2 1\n00100\n", "2 2 1 0\n00\n", "10 2 2 0\n0000000000\n", "1 1 1 0\n0\n...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships consists of b consecutive cells. No cell can be part of two...
749_E. Inversions After Shuffle_26868
You are given a permutation of integers from 1 to n. Exactly once you apply the following operation to this permutation: pick a random segment and shuffle its elements. Formally: 1. Pick a random segment (continuous subsequence) from l to r. All <image> segments are equiprobable. 2. Let k = r - l + 1, i.e. the le...
# Python3 program to count inversions using # Binary Indexed Tree # Returns sum of arr[0..index]. This function # assumes that the array is preprocessed and # partial sums of array elements are stored # in BITree[]. def getSum( BITree, index): sum = 0 # Initialize result # Traverse anc...
{ "input": [ "3\n2 3 1\n", "3\n1 2 3\n", "100\n39 8 87 59 49 19 6 64 81 26 90 58 30 93 51 94 91 10 37 68 14 86 75 41 15 73 76 85 13 84 34 25 54 92 23 11 99 53 80 74 22 29 20 79 7 66 62 72 28 71 12 48 18 9 78 38 43 47 5 50 77 82 52 96 97 65 55 88 16 45 69 4 61 42 60 100 24 32 57 21 89 70 27 35 98 83 56 40 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given a permutation of integers from 1 to n. Exactly once you apply the following operation to this permutation: pick a random segment and shuffle its elements. Formally: 1...
797_D. Broken BST_26874
Let T be arbitrary binary tree — tree, every vertex of which has no more than two children. Given tree is rooted, so there exists only one vertex which doesn't have a parent — it's the root of a tree. Every vertex has an integer number written on it. Following algorithm is run on every value from the tree T: 1. Set ...
from collections import deque nodes = [] parents = [] values = [] broken = [] upperBound = [] lowerBound = [] n = int(input()) for _ in range(n): v, l, r = map(int, input().split()) nodes.append((v, l - 1, r - 1)) parents.append(-1) values.append(v) broken.append(False) upperBound.append(10 *...
{ "input": [ "8\n6 2 3\n3 4 5\n12 6 7\n1 -1 8\n4 -1 -1\n5 -1 -1\n14 -1 -1\n2 -1 -1\n", "3\n15 -1 -1\n10 1 3\n5 -1 -1\n", "10\n911605217 -1 -1\n801852416 -1 -1\n140035920 -1 9\n981454947 10 2\n404988051 6 3\n307545107 8 7\n278188888 4 1\n523010786 -1 -1\n441817740 -1 -1\n789680429 -1 -1\n", "4\n1 2 3\n...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Let T be arbitrary binary tree — tree, every vertex of which has no more than two children. Given tree is rooted, so there exists only one vertex which doesn't have a parent — it's th...
843_A. Sorting by Subsequences_26880
You are given a sequence a1, a2, ..., an consisting of different integers. It is required to split this sequence into the maximum number of subsequences such that after sorting integers in each of them in increasing order, the total sequence also will be sorted in increasing order. Sorting integers in a subsequence is...
n = int(input()) d = list(map(int, input().split())) temp = d[:] d.sort() from bisect import bisect_left A = [bisect_left(d,i) for i in temp] del d,temp f = [False]*len(A) result = [] for i in range(n): if not f[i]: L = [i+1] f[i] = True j = A[i] while j != i: L.append(j+1) f[j] = ...
{ "input": [ "6\n83 -75 -49 11 37 62\n", "6\n3 2 1 6 5 4\n", "10\n3 7 10 1 9 5 4 8 6 2\n", "100\n39 77 67 25 81 26 50 11 73 95 86 16 90 33 14 79 12 100 68 64 60 27 41 15 34 24 3 61 83 47 57 65 99 43 40 21 94 72 82 85 23 71 76 32 10 17 30 18 44 59 35 89 6 63 7 69 62 70 4 29 92 87 31 48 36 28 45 97 93 9...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given a sequence a1, a2, ..., an consisting of different integers. It is required to split this sequence into the maximum number of subsequences such that after sorting intege...
863_F. Almost Permutation_26883
Recently Ivan noticed an array a while debugging his code. Now Ivan can't remember this array, but the bug he was trying to fix didn't go away, so Ivan thinks that the data from this array might help him to reproduce the bug. Ivan clearly remembers that there were n elements in the array, and each element was not less...
import sys def is_feasible(cnt,L,R): n = len(R) inter = [(L[i],R[i]) for i in range(n)] AUX = [] feasible = True for x in range(n): for p in inter: if p[0] == x: AUX.append(p[1]) while AUX and min(AUX) < x: AUX.remove(min(AUX)) for quantity in range(cnt[x]): if AUX: AUX.remove(min(AUX)...
{ "input": [ "3 0\n", "3 2\n1 1 3 2\n2 1 3 2\n", "3 1\n1 1 3 2\n", "3 2\n1 1 3 2\n2 1 3 1\n", "3 6\n1 1 1 2\n2 1 1 2\n1 2 2 2\n2 2 2 2\n1 3 3 2\n2 3 3 3\n", "7 3\n2 1 2 2\n1 3 7 2\n2 3 7 3\n", "50 2\n2 1 33 1\n2 14 50 1\n", "29 5\n2 4 9 27\n1 25 29 14\n1 9 10 18\n2 13 13 5\n2 1 19 23\n...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Recently Ivan noticed an array a while debugging his code. Now Ivan can't remember this array, but the bug he was trying to fix didn't go away, so Ivan thinks that the data from this ...
912_A. Tricky Alchemy_26889
During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing magic crystals. Grisha needs to obtain some yellow, green and blue balls. It's known that to produce a yellow ball one needs two yellow ...
y,b=input().split(' ') ay,ag,ab=input().split(' ') y=int(y) b=int(b) ay=int(ay) ag=int(ag) ab=int(ab) b=b-(ab*3) y=y-(ay*2) b=b-ag y=y-ag br=0 if(y<0): br=br-y if(b<0): br=br-b print(br)
{ "input": [ "4 3\n2 1 1\n", "3 9\n1 1 3\n", "12345678 87654321\n43043751 1000000000 53798715\n", "25 5\n3 3 3\n", "612127849 669475006\n271630930 676010757 22959739\n", "100 10\n2 3 4\n", "626115781 966381948\n395190569 820194184 229233367\n", "48 27\n22 39 20\n", "198066417 82522...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: During the winter holidays, the demand for Christmas balls is exceptionally high. Since it's already 2018, the advances in alchemy allow easy and efficient ball creation by utilizing ...
934_A. A Compatible Pair_26893
Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villages with red colour, light, and cracking noise, all of which frighten the monster out of coming. Little Tommy has n lanterns and Big Ban...
n, m = [int(x) for x in input().split()] lstT = [int(x) for x in input().split()] lstB = [int(x) for x in input().split()] z=-9999999999999999999999999999 T=0 B=0 for i in range(n): for j in range(m): if z<lstT[i]*lstB[j]: T=i B=j ...
{ "input": [ "2 2\n20 18\n2 14\n", "5 3\n-1 0 1 2 3\n-1 0 1\n", "14 8\n-1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000 -1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Nian is a monster which lives deep in the oceans. Once a year, it shows up on the land, devouring livestock and even people. In order to keep the monster away, people fill their villa...
960_C. Subsequence Counting_26897
Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2n - 1 non-empty subsequences in it. Pikachu being mischievous as he always is, removed all the subsequences in which Maximum_element_of_the_subsequence - Minimum_element_of_subsequence...
X, d = map(int, input().split()) x = X ans = list() ln = 0 last = 1 while x > 0: if last >= 10 ** 18: print(-1) exit() i = 0 while 2 ** (i + 1) - 1 <= x: i += 1 t = 2 ** i - 1 x -= t if ln + i > 10000: print(-1) exit() for _ in range(i): a...
{ "input": [ "10 5\n", "4 2\n", "985629174 189232688\n", "21537803 166017060\n", "863230070 895037311\n", "641009859 54748096\n", "248004555 280013594\n", "1048576 1\n", "1 1\n", "702209411 496813081\n", "890 553\n", "1000000000 1\n", "691688417 162011045\n", "1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Pikachu had an array with him. He wrote down all the non-empty subsequences of the array on paper. Note that an array of size n has 2n - 1 non-empty subsequences in it. Pikachu bein...
p02592 AtCoder Grand Contest 047 - Product Simulation_26912
This is an output-only problem. You shouldn't read anything from the input. In short, your task is to simulate multiplication by using only comparison (x < y) and addition (x + y). There is no input in this problem, you just print a sequence of operations. Imagine that there is a big array a[0], a[1], ..., a[N-1] of ...
n=97 p=print r=range def a(i,j,k,l=0):p(chr(43+l*17),i,j,k) def b(i):a(i,i,i+1) def d(x,i,j): for t in r(30): b(j+t-1);a(j+t,n,j+t) for s in r(j+t,j+29):b(s) a(j+29,x,i+t,1);b(j+t-1);a(j+t,i+t,j+t) p(3933) a(0,1,n) a(2,n,n,1) a(0,n,3) a(1,n,4) d(3,5,36) d(4,36,67) for t in r(59): a(2,2,2) for s in r(t+1): if...
{ "input": [ "" ], "output": [ "" ] }
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: This is an output-only problem. You shouldn't read anything from the input. In short, your task is to simulate multiplication by using only comparison (x < y) and addition (x + y). T...