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
315_B. Sereja and Array_10854
Sereja has got an array, consisting of n integers, a1, a2, ..., an. Sereja is an active boy, so he is now going to complete m operations. Each operation will have one of the three forms: 1. Make vi-th array element equal to xi. In other words, perform the assignment avi = xi. 2. Increase each array element by yi....
import sys,math from collections import deque,defaultdict import operator as op from functools import reduce from itertools import permutations import heapq #sys.setrecursionlimit(10**7) # OneDrive\Documents\codeforces I=sys.stdin.readline alpha="abcdefghijklmnopqrstuvwxyz" mod=10**9 + 7 """ x_move=[-1,0,1,0,-1,1...
{ "input": [ "10 11\n1 2 3 4 5 6 7 8 9 10\n3 2\n3 9\n2 10\n3 1\n3 10\n1 1 10\n2 10\n2 10\n3 1\n3 10\n3 9\n", "5 5\n286163265 724763447 761775891 215352371 491215007\n1 4 780579549\n1 2 638546757\n3 4\n1 3 38072627\n2 6119\n", "5 4\n293170637 715384768 756975575 129004053 875201151\n1 3 695181967\n3 3\n2 2...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Sereja has got an array, consisting of n integers, a1, a2, ..., an. Sereja is an active boy, so he is now going to complete m operations. Each operation will have one of the three for...
337_D. Book of Evil_10857
Paladin Manao caught the trail of the ancient Book of Evil in a swampy area. This area contains n settlements numbered from 1 to n. Moving through the swamp is very difficult, so people tramped exactly n - 1 paths. Each of these paths connects some pair of settlements and is bidirectional. Moreover, it is possible to r...
from collections import defaultdict import sys input=sys.stdin.readline class graph: def __init__(self,n,mark): self.d=defaultdict(list) self.n=n self.mark=mark def add(self,s,d): self.d[s].append(d) self.d[d].append(s) def bfs(self,s,dis): marked=s...
{ "input": [ "6 2 3\n1 2\n1 5\n2 3\n3 4\n4 5\n5 6\n", "50 2 5\n9 14\n46 34\n40 35\n44 30\n32 16\n1 38\n48 2\n17 14\n50 25\n6 1\n45 19\n21 15\n22 11\n15 33\n8 28\n2 32\n10 22\n37 3\n43 39\n25 16\n9 19\n16 3\n28 32\n20 45\n24 32\n4 18\n49 39\n13 45\n26 4\n11 33\n14 37\n42 19\n31 45\n38 3\n34 8\n18 29\n35 34\n29...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Paladin Manao caught the trail of the ancient Book of Evil in a swampy area. This area contains n settlements numbered from 1 to n. Moving through the swamp is very difficult, so peop...
360_A. Levko and Array Recovery_10860
Levko loves array a1, a2, ... , an, consisting of integers, very much. That is why Levko is playing with array a, performing all sorts of operations with it. Each operation Levko performs is of one of two types: 1. Increase all elements from li to ri by di. In other words, perform assignments aj = aj + di for all j ...
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.writa...
{ "input": [ "4 5\n1 2 3 1\n2 1 2 8\n2 3 4 7\n1 1 3 3\n2 3 4 8\n", "4 5\n1 2 3 1\n2 1 2 8\n2 3 4 7\n1 1 3 3\n2 3 4 13\n", "1 1\n2 1 1 40000000\n", "1 4\n1 1 1 2\n2 1 1 6\n1 1 1 1\n2 1 1 7\n", "97 29\n2 78 82 356152\n2 14 29 430177\n1 59 84 3680\n1 49 89 -2247\n1 92 96 3701\n2 54 89 377271\n1 62 70...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Levko loves array a1, a2, ... , an, consisting of integers, very much. That is why Levko is playing with array a, performing all sorts of operations with it. Each operation Levko perf...
383_D. Antimatter_10864
Iahub accidentally discovered a secret lab. He found there n devices ordered in a line, numbered from 1 to n from left to right. Each device i (1 ≤ i ≤ n) can create either ai units of matter or ai units of antimatter. Iahub wants to choose some contiguous subarray of devices in the lab, specify the production mode f...
import sys input = lambda : sys.stdin.readline().rstrip() sys.setrecursionlimit(2*10**5+10) write = lambda x: sys.stdout.write(x+"\n") debug = lambda x: sys.stderr.write(x+"\n") writef = lambda x: print("{:.12f}".format(x)) n = int(input()) a = list(map(int, input().split())) m = sum(a) M = 10**9+7 dp = [0]*(2*m+1) ...
{ "input": [ "4\n1 1 1 1\n", "50\n2 1 5 2 1 3 1 2 3 2 1 1 5 2 2 2 3 2 1 2 2 2 3 3 1 3 1 1 2 2 2 2 1 2 3 1 2 4 1 1 1 3 2 1 1 1 3 2 1 3\n", "250\n2 2 2 2 3 2 4 2 3 2 5 1 2 3 4 4 5 3 5 1 2 5 2 3 5 3 2 3 3 3 5 1 5 5 5 4 1 3 2 5 1 2 3 5 3 3 5 2 1 1 3 3 5 1 4 2 3 3 2 2 3 5 5 4 1 4 1 5 1 3 3 4 1 5 2 5 5 3 2 4 4 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Iahub accidentally discovered a secret lab. He found there n devices ordered in a line, numbered from 1 to n from left to right. Each device i (1 ≤ i ≤ n) can create either ai units o...
404_C. Restore Graph_10868
Valera had an undirected connected graph without self-loops and multiple edges consisting of n vertices. The graph had an interesting property: there were at most k edges adjacent to each of its vertices. For convenience, we will assume that the graph vertices were indexed by integers from 1 to n. One day Valera count...
from sys import exit n, k = map(int, input().split()) nodes = [[] for _ in range(n+1)] edges = [] for node, dist in enumerate(map(int, input().split())): nodes[dist].append(node) if len(nodes[0]) != 1 or len(nodes[1]) > k: print(-1) else: for i in range(1, n): if len(nodes[i])*(k-1) < len(nodes[...
{ "input": [ "3 2\n0 1 1\n", "3 1\n0 0 0\n", "4 2\n2 0 1 3\n", "3 1\n0 1 2\n", "5 3\n0 2 1 2 1\n", "4 3\n1 1 1 2\n", "2 1\n1 0\n", "2 1\n1 1\n", "3 2\n0 1 1\n", "9 4\n2 1 1 3 1 2 2 1 0\n", "4 2\n0 1 0 1\n", "7 3\n2 2 0 1 3 2 1\n", "2 1\n0 0\n", "5 4\n1 2 2 2 3\n...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Valera had an undirected connected graph without self-loops and multiple edges consisting of n vertices. The graph had an interesting property: there were at most k edges adjacent to ...
431_D. Random Task_10872
One day, after a difficult lecture a diligent student Sasha saw a graffitied desk in the classroom. She came closer and read: "Find such positive integer n, that among numbers n + 1, n + 2, ..., 2·n there are exactly m numbers which binary representation contains exactly k digits one". The girl got interested in the t...
def dfs(n, k, cache = {}): # if number of bits is bigger than the number's bits of the number's bits is less than 0 if k > n or k < 0: return 0 # if num bits is 0 or num bits is equivalent to the number's bits if k == 0 or k == n: return 1 # This optimization is not necessary but flips the 0s and th...
{ "input": [ "1 1\n", "3 2\n", "286 11\n", "5004844 6\n", "55 55\n", "820882585293 13\n", "427 4\n", "6 16\n", "4 20\n", "15619605006173 15\n", "3 3\n", "2518095982 9\n", "14065439 11\n", "135647 6\n", "3600 4\n", "330 8\n", "10 10\n", "20074910 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: One day, after a difficult lecture a diligent student Sasha saw a graffitied desk in the classroom. She came closer and read: "Find such positive integer n, that among numbers n + 1, ...
454_A. Little Pony and Crystal Mine_10876
Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size n (n is odd; n > 1) is an n × n matrix with a diamond inscribed into it. You are given an odd integer n. You need to draw a crystal of size n. The diamond cells of the matrix should be represented by character "D". All other cells of the matr...
n=int(input()) a=int(n/2) b=1 for i in range(int(n/2)): for j in range(a): print("*",end="") for j in range(b): print('D',end="") b=b+2 for j in range(a): print("*",end="") a=a-1 print() for i in range(b): print("D",end="") print() a=a+1 b=b-2 for i in range(int(n/2))...
{ "input": [ "5\n", "7\n", "3\n", "101\n", "11\n", "81\n", "21\n", "15\n", "57\n", "33\n", "69\n", "91\n", "9\n", "61\n", "29\n", "17\n", "19\n", "59\n", "13\n", "25\n", "47\n", "71\n", "75\n", "27\n", "23\n", "51\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size n (n is odd; n > 1) is an n × n matrix with a diamond inscribed into it. You are given an odd integer n. ...
476_D. Dreamoon and Sets_10880
Dreamoon likes to play with sets, integers and <image>. <image> is defined as the largest positive integer that divides both a and b. Let S be a set of exactly four distinct integers greater than 0. Define S to be of rank k if and only if for all pairs of distinct elements si, sj from S, <image>. Given k and n, Dream...
n,k = [int(i) for i in input().split()] print((6*n-1)*k) for a in range(n): val = 6*a print((val+1)*k,(val+2)*k,(val+3)*k,(val+5)*k)
{ "input": [ "1 1\n", "2 2\n", "3081 11\n", "4237 87\n", "113 97\n", "2 2\n", "7 7\n", "19 21\n", "13 7\n", "3844 46\n", "1 1\n", "1 10\n", "1563 15\n", "15 27\n", "770 59\n", "1171 46\n", "5422 87\n", "407 39\n", "1 100\n", "6518 18\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Dreamoon likes to play with sets, integers and <image>. <image> is defined as the largest positive integer that divides both a and b. Let S be a set of exactly four distinct integers...
49_E. Common ancestor_10884
The DNA sequence for every living creature in Berland can be represented as a non-empty line consisting of lowercase Latin letters. Berland scientists found out that all the creatures evolve by stages. During one stage exactly one symbol of the DNA line is replaced by exactly two other ones. At that overall there are n...
#!/usr/bin/env python3 import itertools import collections # Read input strings s1 = input() s2 = input() # Read evolution rules, use a mapping from the 2 target characters to the source character rules = collections.defaultdict(set) n = int(input()) for i in range(n): rule = input() target = rule[-2:] source ...
{ "input": [ "ababa\naba\n2\nc-&gt;ba\nc-&gt;cc\n", "ababa\naba\n1\nc-&gt;ba\n", "ababa\naba\n7\nc-&gt;ba\nc-&gt;cc\ne-&gt;ab\nz-&gt;ea\nb-&gt;ba\nd-&gt;dd\nd-&gt;ab\n", "caaijqulvbesqytzrjqujqhsqtzqulbvhsquqsqcmzlqswbvug\nyinccmmtvchfctzlqcsqwqlpktbjidmusqmqbfjsqwuclwfugq\n50\nw->ep\nc->ya\nj->dc\nf-...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: The DNA sequence for every living creature in Berland can be represented as a non-empty line consisting of lowercase Latin letters. Berland scientists found out that all the creatures...
577_A. Multiplication Table_10892
Let's consider a table consisting of n rows and n columns. The cell located at the intersection of i-th row and j-th column contains number i × j. The rows and columns are numbered starting from 1. You are given a positive integer x. Your task is to count the number of cells in a table that contain number x. Input T...
import sys n, x = map(int, sys.stdin.readline().split()) s = 0 for i in range(1, n + 1): if (x % i == 0 and x / i <= n): s += 1 print(s)
{ "input": [ "5 13\n", "10 5\n", "6 12\n", "100000 997920\n", "100000 989460910\n", "22740 989460910\n", "1 1000000000\n", "19999 399960001\n", "100000 1000000000\n", "100000 1\n", "100000 479001600\n", "4 4\n", "100000 25\n", "58942 936593001\n", "100000 98...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Let's consider a table consisting of n rows and n columns. The cell located at the intersection of i-th row and j-th column contains number i × j. The rows and columns are numbered st...
599_D. Spongebob and Squares_10896
Spongebob is already tired trying to reason his weird actions and calculations, so he simply asked you to find all pairs of n and m, such that there are exactly x distinct squares in the table consisting of n rows and m columns. For example, in a 3 × 5 table there are 15 squares with side one, 8 squares with side two a...
n,i,t,r=int(input()),0,0,[] while 1: i+=1 n-=i*i if n<0:break t+=i m=n//t r+=[(m+i,i),(i,m+i)][m==0:]*(m*t==n) print(len(r)) for p in sorted(r):print("%d %d"%p)
{ "input": [ "8\n", "26\n", "2\n", "10152342200\n", "6466460\n", "334344854787443885\n", "5050505060\n", "649708734844\n", "380060000009189500\n", "5000004100\n", "800800\n", "147456000000000\n", "20202582400\n", "914669606669700001\n", "600201602000\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Spongebob is already tired trying to reason his weird actions and calculations, so he simply asked you to find all pairs of n and m, such that there are exactly x distinct squares in ...
620_C. Pearls in a Row_10900
There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai. Let's call a sequence of consecutive pearls a segment. Let's call a segment good if it contains two pearls of the same type. Split the row of the pearls to the maximal number of ...
n=int(input()) d={} b=[] e=1 a=list(map(int,input().split())) for i in range(n): if a[i] in d: b.append([e,i+1]) e=i+2 d.clear() else: d[a[i]]=i+1 if len(b)==0: print(-1) exit() print(len(b)) k=b[-1] b[-1]=[k[0],n] for i in b: print(*i)
{ "input": [ "5\n1 2 3 4 1\n", "7\n1 2 1 3 1 2 1\n", "5\n1 2 3 4 5\n", "7\n13 9 19 13 3 13 12\n", "4\n1 2 1 2\n", "5\n1 2 2 2 3\n", "13\n1 1 1 1 1 1 1 1 1 1 1 1 1\n", "3\n1 1 1\n", "11\n1 1 2 1 2 1 2 1 2 1 1\n", "1\n576560149\n", "10\n522312461 21923894 21923894 544064902 4...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are n pearls in a row. Let's enumerate them with integers from 1 to n from the left to the right. The pearl number i has the type ai. Let's call a sequence of consecutive pearl...
641_B. Little Artem and Matrix_10904
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it. That element can store information about the matrix of integers size n × m. There a...
import itertools import bisect import math from collections import * import os import sys from io import BytesIO, IOBase ii = lambda: int(input()) lmii = lambda: list(map(int, input().split())) li = lambda: list(input()) mii = lambda: map(int, input().split()) msi = lambda: map(str, input().split()) def main(): ...
{ "input": [ "2 2 6\n2 1\n2 2\n3 1 1 1\n3 2 2 2\n3 1 2 8\n3 2 1 8\n", "3 3 2\n1 2\n3 2 2 5\n", "4 2 5\n2 1\n3 1 1 5\n3 2 1 6\n3 3 1 7\n3 4 1 9\n", "1 1 3\n1 1\n2 1\n3 1 1 -1000000000\n", "1 4 5\n1 1\n3 1 1 1\n3 1 2 2\n3 1 3 3\n3 1 4 4\n", "5 5 1\n1 5\n", "1 2 2\n1 1\n3 1 2 15\n", "3 10...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to...
669_E. Little Artem and Time Machine_10908
Little Artem has invented a time machine! He could go anywhere in time, but all his thoughts of course are with computer science. He wants to apply this time machine to a well-known data structure: multiset. Artem wants to create a basic multiset of integers. He wants these structure to support operations of three typ...
# by the authority of GOD author: manhar singh sachdev # import os,sys from io import BytesIO, IOBase new = lambda xx: (xx|xx-1)+1 def buildBIT(bit,n): for i in range(1,n+1): x = new(i) if x <= n: bit[x] += bit[i] def pointUpdate(bit,point,n,diff): while point <= n: bi...
{ "input": [ "3\n1 1 1\n2 2 1\n3 3 1\n", "6\n1 1 5\n3 5 5\n1 2 5\n3 6 5\n2 3 5\n3 7 5\n", "10\n1 1 1000000000\n1 4 1000000000\n2 2 1000000000\n1 5 1000000000\n1 8 1000000000\n2 15 1000000000\n3 3 1000000000\n3 10 1000000000\n3 6 1000000000\n3 7 1000000000\n", "20\n1 1 1\n1 2 2\n1 3 3\n1 4 4\n1 5 5\n2 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Little Artem has invented a time machine! He could go anywhere in time, but all his thoughts of course are with computer science. He wants to apply this time machine to a well-known d...
690_E2. Photographs (II)_10911
Zombies seem to have become much more intelligent lately – a few have somehow wandered into the base through the automatic gate. Heidi has had to beef up security, and a new gate has been installed. Unfortunately, now the questions being asked are more complicated, and even humans have trouble answering them. Can you s...
print("""2 1 2 3 1 4 3 2 1 1 3 4 2 5 1 6 11 3 10 9 15 12 7 13 2 5 4 14 8 5 1 3 11 10 7 6 9 13 15 12 4 14 2 8 9 7 2 5 1 10 8 3 4 6 2 1 4 3 4 12 8 2 9 14 5 7 1 6 10 13 15 3 11 11 5 6 8 10 12 7 2 1 4 9 3 13 14 15 11 7 8 4 5 15 13 14 3 9 12 2 1 10 6 12 7 11 4 10 2 5 14 13 1 6 3 9 8 15 16 3 2 1 4 2 1 3 5 1 8 1...
{ "input": [], "output": [] }
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Zombies seem to have become much more intelligent lately – a few have somehow wandered into the base through the automatic gate. Heidi has had to beef up security, and a new gate has ...
715_B. Complete The Graph_10915
ZS the Coder has drawn an undirected graph of n vertices numbered from 0 to n - 1 and m edges between them. Each edge of the graph is weighted, each weight is a positive integer. The next day, ZS the Coder realized that some of the weights were erased! So he wants to reassign positive integer weight to each of the edg...
import heapq from collections import defaultdict class Graph: def __init__(self, n): self.nodes = set(range(n)) self.edges = defaultdict(list) self.distances = {} def add_edge(self, from_node, to_node, distance): self.edges[from_node].append(to_node) self.edges[to_node...
{ "input": [ "5 5 13 0 4\n0 1 5\n2 1 2\n3 2 3\n1 4 0\n4 3 4\n", "2 1 999999999 1 0\n0 1 1000000000\n", "2 1 123456789 0 1\n0 1 0\n", "8 9 10 1 0\n1 2 1\n2 4 1\n1 3 0\n3 4 0\n4 5 0\n5 6 1\n6 0 1\n5 7 0\n7 0 0\n", "7 9 320 0 3\n0 1 0\n1 2 0\n2 3 0\n0 4 1\n4 1 1\n1 5 100\n5 2 100\n2 6 59\n6 3 61\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: ZS the Coder has drawn an undirected graph of n vertices numbered from 0 to n - 1 and m edges between them. Each edge of the graph is weighted, each weight is a positive integer. The...
735_D. Taxes_10919
Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to n (n ≥ 2) burles and the amount of tax he has to pay is calculated as the maximum divisor of n (not equal to n, of course). For example, if n = 6 then Funt has to pay 3 burles, while for n = 25 he ne...
def isPrime(n): i=2 while i*i<=n: if n%i==0: return False i+=1 return True n=int(input()) if isPrime(n): print(1) elif n&1==0: print(2) else: if isPrime(n-2): print(2) else: print(3)
{ "input": [ "4\n", "27\n", "101\n", "998321704\n", "200743933\n", "99990001\n", "16\n", "1999999999\n", "14\n", "10759922\n", "192483501\n", "344472101\n", "1999999927\n", "21\n", "2\n", "200000015\n", "26\n", "1000000007\n", "1908903481\n",...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to n (n ≥ 2) burles and the amount of tax he has to pay is calcul...
75_D. Big Maximum Sum_10923
Ahmed and Mostafa used to compete together in many programming contests for several years. Their coach Fegla asked them to solve one challenging problem, of course Ahmed was able to solve it but Mostafa couldn't. This problem is similar to a standard problem but it has a different format and constraints. In the stand...
import sys from array import array # noqa: F401 def input(): return sys.stdin.buffer.readline().decode('utf-8') def prepare(n, *a): acc = 0 sub_max = -10**9 left_min = 0 left_max = 0 lmin2, lmax2 = 0, -10**9 for i, x in enumerate(a): acc += x sub_max = max(sub_max, acc ...
{ "input": [ "6 1\n4 0 8 -3 -10\n8 3 -2 -5 10 8 -9 -5 -4\n1 0\n1 -3\n3 -8 5 6\n2 9 6\n1\n", "3 4\n3 1 6 -2\n2 3 3\n2 -5 1\n2 3 1 3\n", "4 8\n8 0 3 -9 -10 0 -1 6 -4\n3 -10 -7 2\n10 6 -2 -9 0 -7 -4 -7 7 -1 2\n3 -5 1 -4\n1 1 1 1 4 4 3 3\n", "2 2\n6 -1 -1 -1 1 1 1\n6 -1 -1 -1 -1 -1 -1\n1 2\n", "2 2\n6...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Ahmed and Mostafa used to compete together in many programming contests for several years. Their coach Fegla asked them to solve one challenging problem, of course Ahmed was able to s...
780_C. Andryusha and Colored Balloons_10927
Andryusha goes through a park each day. The squares and paths between them look boring to Andryusha, so he decided to decorate them. The park consists of n squares connected with (n - 1) bidirectional paths in such a way that any square is reachable from any other using these paths. Andryusha decided to hang a colored...
n=int(input()) g=[[] for i in range(n)] for _ in range(n-1): x,y=map(int,input().split()) g[x-1].append(y-1) g[y-1].append(x-1) l=0 for i in range(n): l=max(l,len(g[i])+1) q=[0] paint=[-1]*n paint[0]=1 while q: ver=q.pop() use=set() use.add(paint[ver]) for to in g[ver]: use.add(paint[to]) arr=[] ...
{ "input": [ "5\n2 3\n5 3\n4 3\n1 3\n", "5\n2 1\n3 2\n4 3\n5 4\n", "3\n2 3\n1 3\n", "10\n5 3\n9 2\n7 1\n3 8\n4 1\n1 9\n10 1\n8 9\n6 2\n", "5\n4 2\n3 1\n3 4\n3 5\n", "3\n2 1\n3 2\n", "7\n3 6\n3 1\n3 2\n3 5\n3 4\n3 7\n", "50\n45 2\n4 48\n16 4\n17 29\n29 33\n31 2\n47 41\n41 33\n22 6\n44 4...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Andryusha goes through a park each day. The squares and paths between them look boring to Andryusha, so he decided to decorate them. The park consists of n squares connected with (n ...
850_A. Five Dimensional Points_10936
You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide. We will call point a bad if there are different points b and c, not equal to a, from the given set such that angle between vectors <image> and <image> is acute (i.e. strictly less than <image>). Otherwise,...
n=int(input()) A=[] js=0 B=[] for i in range(n): A.append(list(map(int,input().split()))) def product(a,b,c): pr=0 for m in range(5): pr=pr+(A[b][m]-A[a][m])*(A[c][m]-A[a][m]) return (pr) if(n>11): print(0) else: for j in range(n): k=0 l=0 flag=0 while(k...
{ "input": [ "3\n0 0 1 2 0\n0 0 9 2 0\n0 0 5 9 0\n", "6\n0 0 0 0 0\n1 0 0 0 0\n0 1 0 0 0\n0 0 1 0 0\n0 0 0 1 0\n0 0 0 0 1\n", "10\n0 -110 68 -51 -155\n-85 -110 68 -51 -155\n85 -70 51 68 -230\n0 -40 51 68 75\n0 5 -51 -68 -190\n85 0 0 0 0\n85 -115 -68 51 35\n85 -75 -187 34 -40\n-85 -110 -136 102 -155\n85 -1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given set of n points in 5-dimensional space. The points are labeled from 1 to n. No two points coincide. We will call point a bad if there are different points b and c, not ...
873_C. Strange Game On Matrix_10940
Ivan is playing a strange game. He has a matrix a with n rows and m columns. Each element of the matrix is equal to either 0 or 1. Rows and columns are 1-indexed. Ivan can replace any number of ones in this matrix with zeroes. After that, his score in the game will be calculated as follows: 1. Initially Ivan's scor...
n,m,k=input().split() n=int(n) m=int(m) k=int(k) array=[] for x in range(n): a=input().split() fin=[] for i in a: fin.append(int(i)) array.append(fin) cumm=[[0 for x in range(m)] for y in range(n)] i=0 while(i<m): j=n-1 while(j>=0): if(j==n-1): cumm[j][i]=array[j][i] ...
{ "input": [ "3 2 1\n1 0\n0 1\n0 0\n", "4 3 2\n0 1 0\n1 0 1\n0 1 0\n1 1 1\n", "3 57 3\n1 0 0 1 1 0 1 1 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 0 0 0 1 0 0 1 1 0 1 1 1 1 0 1 1 1 0 0 0 1 1 0 0 1 0 0 0 1 1 0 0 1 0\n1 1 0 0 0 1 1 1 0 1 1 0 0 0 0 1 1 0 0 1 0 0 1 1 1 0 1 0 0 0 0 1 1 1 0 0 0 1 0 1 0 0 0 1 1 0 0 0 1 1 0 0 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Ivan is playing a strange game. He has a matrix a with n rows and m columns. Each element of the matrix is equal to either 0 or 1. Rows and columns are 1-indexed. Ivan can replace an...
899_B. Months and Years_10944
Everybody in Russia uses Gregorian calendar. In this calendar there are 31 days in January, 28 or 29 days in February (depending on whether the year is leap or not), 31 days in March, 30 days in April, 31 days in May, 30 in June, 31 in July, 31 in August, 30 in September, 31 in October, 30 in November, 31 in December. ...
a1 = '31 28 31 30 31 30 31 31 30 31 30 31 ' a2 = '31 29 31 30 31 30 31 31 30 31 30 31 ' s = a1 + a1 + a1 + a2 + a1 + a1 n = input() ss = input().strip() print(["NO",'YES'][ss in s])
{ "input": [ "4\n31 31 30 31\n", "3\n31 31 28\n", "5\n29 31 30 31 30\n", "2\n30 30\n", "3\n31 28 30\n", "17\n28 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31\n", "12\n31 29 31 30 31 30 31 30 30 31 30 31\n", "4\n31 29 29 30\n", "9\n29 31 29 31 30 31 30 31 31\n", "24\n29 31 30 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Everybody in Russia uses Gregorian calendar. In this calendar there are 31 days in January, 28 or 29 days in February (depending on whether the year is leap or not), 31 days in March,...
91_C. Ski Base_10948
A ski base is planned to be built in Walrusland. Recently, however, the project is still in the constructing phase. A large land lot was chosen for the construction. It contains n ski junctions, numbered from 1 to n. Initially the junctions aren't connected in any way. In the constructing process m bidirectional ski r...
import sys from array import array # noqa: F401 def input(): return sys.stdin.buffer.readline().decode('utf-8') class UnionFind(object): __slots__ = ['nodes'] def __init__(self, n: int): self.nodes = [-1] * n def find(self, x: int) -> int: if self.nodes[x] < 0: return ...
{ "input": [ "3 4\n1 3\n2 3\n1 2\n1 2\n", "15 29\n6 11\n14 3\n10 4\n14 7\n6 14\n7 15\n13 8\n10 13\n4 14\n15 8\n12 7\n3 5\n6 7\n8 1\n4 5\n11 5\n10 6\n11 3\n13 14\n7 10\n3 12\n7 14\n8 11\n7 15\n15 8\n12 7\n4 3\n9 4\n8 10\n", "2 40\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: A ski base is planned to be built in Walrusland. Recently, however, the project is still in the constructing phase. A large land lot was chosen for the construction. It contains n ski...
948_A. Protect Sheep_10952
Bob is a farmer. He has a large pasture with many sheep. Recently, he has lost some of them due to wolf attacks. He thus decided to place some shepherd dogs in such a way that all his sheep are protected. The pasture is a rectangle consisting of R × C cells. Each cell is either empty, contains a sheep, a wolf or a dog...
R,C=map(int, input().split()) m=[[str(j) for j in input()] for i in range(R)] row=0 for i in range(R): if row == 1: break for j in range(C): if m[i][j] == ".": m[i][j] = "D" elif m[i][j] == "S": if j > 0 and m[i][j-1] == "W": row=1 ...
{ "input": [ "1 2\nSW\n", "6 6\n..S...\n..S.W.\n.S....\n..W...\n...W..\n......\n", "5 5\n.S...\n...S.\nS....\n...S.\n.S...\n", "4 4\nW..S\nW..S\nW..S\nW..S\n", "10 10\n....W.W.W.\n.........S\n.S.S...S..\nW.......SS\n.W..W.....\n.W...W....\nS..S...S.S\n....W...S.\n..S..S.S.S\nSS.......S\n", "4 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Bob is a farmer. He has a large pasture with many sheep. Recently, he has lost some of them due to wolf attacks. He thus decided to place some shepherd dogs in such a way that all his...
976_A. Minimum Binary Number_10956
String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001". You are given a correct string s. You can perform two different operations on this string: 1. swap any pair of adjacent characters (for example, "101" <image>...
n=int(input()) a=input() count1=0 for item in a: if(item=='1'): count1=count1+1 if(count1>=1): print(1,end="") for i in range(0,len(a)-count1): print(0,end="")
{ "input": [ "4\n1001\n", "1\n1\n", "5\n11100\n", "2\n11\n", "100\n1110111100001111011111111010110011111111011110000111101101011100110110001011000000101010110101011100\n", "100\n1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n", "50\n10...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: String can be called correct if it consists of characters "0" and "1" and there are no redundant leading zeroes. Here are some examples: "0", "10", "1001". You are given a correct st...
p02645 Tokio Marine & Nichido Fire Insurance Programming Contest 2020 - Nickname_10972
When you asked some guy in your class his name, he called himself S, where S is a string of length between 3 and 20 (inclusive) consisting of lowercase English letters. You have decided to choose some three consecutive characters from S and make it his nickname. Print a string that is a valid nickname for him. Constra...
import sys s = input() print(s[:3])
{ "input": [ "naohiro", "takahashi", "maohiro", "sakahashi", "orihoam", "sbkahashi", "ihsahakbs", "hhsaiakbr", "anphiro", "rbkaiashh", "onphira", "rkbaiashh", "arihpno", "skbajashh", "nmpgira", "sgi`pmn", "ska^iashi", "nlp`igs", "nplgi`s", ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: When you asked some guy in your class his name, he called himself S, where S is a string of length between 3 and 20 (inclusive) consisting of lowercase English letters. You have decid...
p02774 AtCoder Beginner Contest 155 - Pairs_10976
We have N integers A_1, A_2, ..., A_N. There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list? Constraints * All values in input are integers. * 2 \leq N \leq 2 \times 1...
N,K,*A = map(int, open(0).read().split()) Ap = [] An = [] Az = [] for c in A: if c>0: Ap.append(c) elif c<0: An.append(c) else: Az.append(c) l = -10**20 r = 10**20 Ap.sort(reverse=True) An.sort() while l+1<r: s = (l+r)//2 cnt = 0 j = len(Ap)-1 for i in range(len(Ap)): while j>-1 and Ap[i]*...
{ "input": [ "10 40\n5 4 3 2 -1 0 0 0 0 0", "4 3\n3 3 -4 -2", "30 413\n-170202098 -268409015 537203564 983211703 21608710 -443999067 -937727165 -97596546 -372334013 398994917 -972141167 798607104 -949068442 -959948616 37909651 0 886627544 -20098238 0 -948955241 0 -214720580 277222296 -18897162 834475626 0...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: We have N integers A_1, A_2, ..., A_N. There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in...
p02909 AtCoder Beginner Contest 141 - Weather Prediction_10980
The weather in Takahashi's town changes day by day, in the following cycle: Sunny, Cloudy, Rainy, Sunny, Cloudy, Rainy, ... Given is a string S representing the weather in the town today. Predict the weather tomorrow. Constraints * S is `Sunny`, `Cloudy`, or `Rainy`. Input Input is given from Standard Input in the...
S=input() L=["Sunny","Cloudy","Rainy"] print(L[(L.index(S)+1)%3])
{ "input": [ "Rainy", "Sunny" ], "output": [ "Sunny", "Cloudy" ] }
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: The weather in Takahashi's town changes day by day, in the following cycle: Sunny, Cloudy, Rainy, Sunny, Cloudy, Rainy, ... Given is a string S representing the weather in the town t...
p03044 AtCoder Beginner Contest 126 - Even Relation_10984
We have a tree with N vertices numbered 1 to N. The i-th edge in the tree connects Vertex u_i and Vertex v_i, and its length is w_i. Your objective is to paint each vertex in the tree white or black (it is fine to paint all vertices the same color) so that the following condition is satisfied: * For any two vertices p...
n=int(input()) path=[[] for i in range(n)] for i in range(n-1): a,b,c=map(int, input().split()) path[a-1].append([b-1,c%2]) path[b-1].append([a-1,c%2]) ans=[-1]*n ans[0]=0 q=[0] while q: nq=[] for k in q: for i,j in path[k]: if ans[i]==-1: ans[i]=(ans[k]+j)%2 ...
{ "input": [ "5\n2 5 2\n2 3 10\n1 3 8\n3 4 2", "3\n1 2 2\n2 3 1", "5\n2 5 2\n2 3 18\n1 3 8\n3 4 2", "3\n1 2 2\n2 3 0", "3\n1 2 4\n2 3 1", "3\n1 2 3\n2 3 0", "3\n1 2 3\n2 3 1", "5\n2 5 3\n2 3 18\n1 3 8\n3 4 2", "5\n2 5 3\n2 3 18\n1 3 8\n3 4 3", "5\n1 5 3\n2 3 23\n1 3 8\n3 4 2", ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: We have a tree with N vertices numbered 1 to N. The i-th edge in the tree connects Vertex u_i and Vertex v_i, and its length is w_i. Your objective is to paint each vertex in the tree...
p03186 AtCoder Grand Contest 030 - Poisonous Cookies_10988
Takahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison. Eating a cookie containing poison results in a stomachache, and eating a cookie containing poison while having a stomachache results in a death. As he wants to live, he cannot eat one in su...
a,b,c=map(int,input().split()) if b+a+1>=c: print(b+c) else: print(b+a+b+1)
{ "input": [ "3 1 4", "8 8 1", "5 2 9", "0 1 4", "14 8 1", "9 2 9", "0 0 4", "14 8 2", "3 2 9", "11 15 2", "11 15 4", "3 0 12", "0 2 0", "11 15 0", "0 0 0", "16 5 0", "-2 0 0", "3 1 27", "-1 1 -4", "6 -2 0", "-1 -2 0", "-2 -2 -1",...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Takahashi has A untasty cookies containing antidotes, B tasty cookies containing antidotes and C tasty cookies containing poison. Eating a cookie containing poison results in a stoma...
p03333 AtCoder Grand Contest 025 - Interval Game_10992
Takahashi and Aoki will play a game with a number line and some segments. Takahashi is standing on the number line and he is initially at coordinate 0. Aoki has N segments. The i-th segment is [L_i,R_i], that is, a segment consisting of points with coordinates between L_i and R_i (inclusive). The game has N steps. The...
import heapq N=int(input()) rque=[] rque2=[] lque=[] lque2=[] for i in range(N): l,r=map(int,input().split()) rque.append((-l,i)) rque2.append((-l,i)) lque.append((r,i)) lque2.append((r,i)) heapq.heapify(rque) heapq.heapify(lque) used=set([]) pos=0 dir="R" ans=0 check=set([i for i in range(N)]) wh...
{ "input": [ "3\n1 2\n3 4\n5 6", "3\n-5 1\n3 7\n-4 -2", "5\n-2 0\n-2 0\n7 8\n9 10\n-2 -1", "3\n2 2\n3 4\n5 6", "3\n-10 1\n3 7\n-4 -2", "5\n-4 0\n-2 0\n7 8\n9 10\n-2 -1", "3\n2 2\n3 4\n10 6", "3\n-10 1\n5 7\n-4 -2", "3\n3 2\n3 4\n20 6", "3\n3 4\n3 4\n20 6", "3\n-10 1\n2 7\n0...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Takahashi and Aoki will play a game with a number line and some segments. Takahashi is standing on the number line and he is initially at coordinate 0. Aoki has N segments. The i-th s...
p03492 AtCoder Regular Contest 087 - Squirrel Migration_10995
There is a tree with N vertices. The vertices are numbered 1 through N. The i-th edge (1 \leq i \leq N - 1) connects Vertex x_i and y_i. For vertices v and w (1 \leq v, w \leq N), we will define the distance between v and w d(v, w) as "the number of edges contained in the path v-w". A squirrel lives in each vertex of ...
from collections import defaultdict import sys sys.setrecursionlimit(10 ** 6) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def main(): def k_fix_way(com_n, com_r): if (com_n, com_r) in kmemo: return kmemo[(com_n, com_r)] res = kmemo[(com_n, com_r)] = fac[com_n] * inv...
{ "input": [ "3\n1 2\n2 3", "6\n1 2\n1 3\n1 4\n2 5\n2 6", "7\n1 2\n6 3\n4 5\n1 7\n1 5\n2 3", "4\n1 2\n1 3\n1 4", "3\n1 2\n1 3", "6\n1 2\n1 3\n1 4\n2 5\n2 10", "6\n1 2\n1 3\n1 4\n1 5\n2 6", "7\n1 2\n6 3\n4 5\n1 7\n1 5\n2 6", "7\n1 3\n6 3\n4 5\n1 7\n1 5\n2 7", "7\n1 2\n6 1\n4 5\n...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There is a tree with N vertices. The vertices are numbered 1 through N. The i-th edge (1 \leq i \leq N - 1) connects Vertex x_i and y_i. For vertices v and w (1 \leq v, w \leq N), we ...
p03654 AtCoder Grand Contest 018 - Tree and Hamilton Path_10999
There is a tree with N vertices, numbered 1 through N. The i-th edge in this tree connects Vertices A_i and B_i and has a length of C_i. Joisino created a complete graph with N vertices. The length of the edge connecting Vertices u and v in this graph, is equal to the shortest distance between Vertices u and v in the ...
import sys input = sys.stdin.readline from collections import defaultdict n = int(input()) abd = [list(map(int,input().split())) for i in range(n-1)] if n == 2: print(abd[0][2]) exit() graph = [[] for i in range(n+1)] deg = [0 for i in range(n+1)] for a,b,d in abd: graph[a].append((b,d)) graph[b].append((a,d)) ...
{ "input": [ "8\n2 8 8\n1 5 1\n4 8 2\n2 5 4\n3 8 6\n6 8 9\n2 7 12", "5\n1 2 5\n3 4 7\n2 3 3\n2 5 2", "8\n2 8 8\n1 5 1\n4 8 2\n2 5 4\n3 8 5\n6 8 9\n2 7 12", "5\n1 2 5\n3 4 10\n2 3 3\n2 5 2", "5\n1 3 5\n3 4 10\n2 3 3\n2 5 2", "5\n1 3 5\n2 4 20\n2 3 3\n2 5 2", "8\n2 8 8\n1 5 1\n4 8 2\n2 5 7\n...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There is a tree with N vertices, numbered 1 through N. The i-th edge in this tree connects Vertices A_i and B_i and has a length of C_i. Joisino created a complete graph with N verti...
p03810 AtCoder Grand Contest 010 - Decrementing_11003
There are N integers written on a blackboard. The i-th integer is A_i, and the greatest common divisor of these integers is 1. Takahashi and Aoki will play a game using these integers. In this game, starting from Takahashi the two player alternately perform the following operation: * Select one integer on the blackbo...
#d #the niumbers of evens is important #the point is, there is no influence to odd/even if you divide them by odd numbers. #You should do simulation only in the case where there is one odd over 3 and even numbers of even numbers from fractions import gcd def count(a): odd, even = 0,0 for x in a: if x ...
{ "input": [ "3\n3 6 7", "4\n1 2 4 8", "5\n7 8 8 8 8", "3\n3 9 7", "4\n1 2 1 9", "4\n1 2 1 8", "5\n7 2 8 8 8", "3\n3 9 9", "3\n3 1 9", "4\n1 2 1 13", "3\n1 1 9", "4\n1 2 1 22", "3\n0 1 9", "4\n1 1 1 22", "3\n0 1 5", "4\n0 1 1 22", "4\n0 0 1 22", ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are N integers written on a blackboard. The i-th integer is A_i, and the greatest common divisor of these integers is 1. Takahashi and Aoki will play a game using these integer...
p00067 The Number of Island_11009
There is a plan view consisting of 12 vertical and 12 horizontal squares showing the terrain. Each square is painted white or black. White represents the sea and black represents the land. When two black squares touch each other vertically or horizontally, they are said to be continuous. In this plan view, the area cre...
c=0 def f(a,x,y): if 0<=x<12 and 0<=y<12 and a[y][x]=='1': a[y][x]='0' for dx,dy in [[-1,0],[1,0],[0,-1],[0,1]]:f(a,x+dx,y+dy) while 1: try: if c:input() except:break a = [list(input()) for _ in [0]*12] c=1;b=0 for i in range(12): for j in range(12): ...
{ "input": [ "111100001111\n111000001111\n110000001111\n100000001111\n000100010000\n000000111000\n000001111100\n100011111110\n110001111100\n111000111000\n111100010000\n000000000000\n\n010001111100\n110010000010\n010010000001\n010000000001\n010000000110\n010000111000\n010000000100\n010000000010\n010000000001\n0100...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There is a plan view consisting of 12 vertical and 12 horizontal squares showing the terrain. Each square is painted white or black. White represents the sea and black represents the ...
p00199 Chairs Where Demanding People Sit_11013
The neutral city of Eyes City, in the heart of the four countries, is home to the transcontinental train Bandai. The platform has a row of chairs for passengers waiting for the Bandai, and people who enter the platform can use the chairs freely. The Bandai is cheap, fast and comfortable, so there are a constant number...
INF = 10 ** 20 while True: n, m = map(int, input().split()) if not n: break chairs = list("#" * n) def sit(s): if s == "A": chairs[chairs.index("#")] = "A" elif s == "B": for i in range(n - 1, -1, -1): if chairs[i] == "#" and (i == 0 or chairs[i - 1] != "A") and (i == n -...
{ "input": [ "5 4\nA\nB\nC\nD\n5 4\nD\nC\nB\nA\n0 0", "5 4\nA\nC\nC\nD\n5 4\nD\nC\nB\nA\n0 0", "5 4\nA\nC\nC\nD\n5 4\nD\nD\nB\nA\n0 0", "5 4\nA\nC\nC\nD\n4 4\nD\nC\nB\nA\n0 0", "5 4\nA\nD\nC\nD\n5 4\nD\nD\nB\nA\n0 0", "5 4\nA\nC\nC\nD\n4 4\nD\nC\nC\nA\n0 0", "5 4\nA\nC\nB\nD\n4 4\nD\nC\nC\...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: The neutral city of Eyes City, in the heart of the four countries, is home to the transcontinental train Bandai. The platform has a row of chairs for passengers waiting for the Bandai...
p00353 Shopping_11016
You are now in a bookshop with your friend Alice to buy a book, "The Winning Strategy for the Programming Koshien Contest,” just released today. As you definitely want to buy it, you are planning to borrow some money from Alice in case the amount you have falls short of the price. If the amount you receive from Alice s...
m,a,b=map(int,input().split()) if m>=b: print(0) elif m+a<b: print("NA") else: print(b-m)
{ "input": [ "5000 3000 4500", "1000 3000 3000", "500 1000 2000", "5000 3000 4771", "1000 3000 1844", "20 1000 2000", "1000 3000 1508", "1000 3000 2582", "1001 6683 2582", "0001 7742 2582", "0101 7742 2582", "0011 7619 2582", "1011 7619 2582", "0011 7619 2049", ...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are now in a bookshop with your friend Alice to buy a book, "The Winning Strategy for the Programming Koshien Contest,” just released today. As you definitely want to buy it, you ...
p00560 Semiexpress_11019
The JOI Railways is the only railway company in the Kingdom of JOI. There are $N$ stations numbered from $1$ to $N$ along a railway. Currently, two kinds of trains are operated; one is express and the other one is local. A local train stops at every station. For each $i$ ($1 \leq i < N$), by a local train, it takes $A...
from heapq import heapify, heappop, heappush N, M, K = map(int, input().split()) A, B, C = map(int, input().split()) T = int(input()) S = [int(input())-1 for i in range(M)] def f(rt, rn): return min(rt // A, rn-1) ans = 0 que = [] for i in range(M-1): s0 = S[i]; s1 = S[i+1] if B*s0 <= T: rt = T - ...
{ "input": [ "10 3 5\n10 3 5\n30\n1\n6\n10", "10 3 5\n10 3 3\n30\n1\n6\n10", "10 3 1\n10 3 3\n30\n1\n6\n10", "10 3 5\n10 3 3\n32\n1\n6\n10", "10 3 1\n10 3 3\n30\n1\n8\n10", "10 3 1\n10 3 0\n51\n0\n6\n10", "10 3 5\n10 3 6\n32\n2\n6\n10", "10 3 10\n10 3 6\n8\n2\n6\n10", "10 3 10\n10 ...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: The JOI Railways is the only railway company in the Kingdom of JOI. There are $N$ stations numbered from $1$ to $N$ along a railway. Currently, two kinds of trains are operated; one i...
p00713 Circle and Points_11022
You are given N points in the xy-plane. You have a circle of radius one and move it on the xy-plane, so as to enclose as many of the points as possible. Find how many points can be simultaneously enclosed at the maximum. A point is considered enclosed by a circle when it is inside or on the circle. <image> Fig 1. Cir...
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**13 mod = 10**9+7 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin....
{ "input": [ "3\n6.47634 7.69628\n5.16828 4.79915\n6.69533 6.20378\n6\n7.15296 4.08328\n6.50827 2.69466\n5.91219 3.86661\n5.29853 4.16097\n6.10838 3.46039\n6.34060 2.41599\n8\n7.90650 4.01746\n4.10998 4.18354\n4.67289 4.01887\n6.33885 4.28388\n4.98106 3.82728\n5.12379 5.16473\n7.84664 4.67693\n4.02776 3.87990\n20...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given N points in the xy-plane. You have a circle of radius one and move it on the xy-plane, so as to enclose as many of the points as possible. Find how many points can be si...
p01415 Starting Line_11032
Training is indispensable for achieving good results at ICPC. Rabbit wants to win at ICPC, so he decided to practice today as well. Today's training is to develop physical strength and judgment by running on a straight road. The rabbit is now standing at the starting line and looking out over a long, long road. There...
N, K, T, U, V, L = map(int, input().split()) ans = 0 l = 0 t = 0 k = 0 for _ in range(N + 1): if _ == N: d = L else: d = int(input()) length = d - l l = d while t > 0 or k > 0: if t > 0: if t * V >= length: tmp = (t * V - length) / V ...
{ "input": [ "1 1 1 2 3 100\n50", "3 1 1 2 3 100\n49\n50\n51", "0 1 1 2 3 100\n50", "1 1 1 2 3 110\n50", "3 1 1 2 3 100\n49\n50\n74", "2 1 1 2 3 100\n49\n72\n74", "2 1 1 2 4 100\n49\n72\n40", "1 1 1 3 3 110\n50", "3 1 1 2 3 110\n49\n50\n51", "0 1 1 2 3 000\n50", "0 1 1 2 3 ...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Training is indispensable for achieving good results at ICPC. Rabbit wants to win at ICPC, so he decided to practice today as well. Today's training is to develop physical strength a...
p01731 Thread Tree_11038
Nathan O. Davis has been running an electronic bulletin board system named JAG-channel. He is now having hard time to add a new feature there --- threaded view. Like many other bulletin board systems, JAG-channel is thread-based. Here a thread (also called a topic) refers to a single conversation with a collection of ...
import sys sys.setrecursionlimit(1010) N = int(input()) src = [] for i in range(N): k = int(input()) s = input() src.append((s,[])) if i == 0: continue src[k-1][1].append(i) def dfs(i,depth): s,ch = src[i] print('.'*depth + s) for c in ch: dfs(c,depth+1) dfs(0,0)
{ "input": [ "1\n0\nicpc", "1\n0\nccpi", "1\n0\nipcc", "1\n0\njpcc", "1\n0\ncbpi", "1\n0\niocc", "1\n0\ncboi", "1\n0\ncdpi", "1\n0\njpbc", "1\n0\niodc", "1\n0\ncdip", "1\n0\njpcb", "1\n0\nccip", "1\n0\njccp", "1\n0\nhocc", "1\n0\ndbpi", "1\n0\ncbpj",...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Nathan O. Davis has been running an electronic bulletin board system named JAG-channel. He is now having hard time to add a new feature there --- threaded view. Like many other bulle...
p01869 28_11041
Problem statement Cards with ranks of $ 2 $ and $ 8 $ are powerful in card game millionaires. Therefore, we call an integer consisting of only the numbers $ 2 $ and $ 8 $ in $ 10 $ decimal notation a good integer. The best integers are listed from the smallest to $ 2, 8, 22, 28, 82, 88, \ cdots $. Let $ n $ be a posi...
import bisect import sys sys.setrecursionlimit(10000) a=[] def f(a,bin,n): if bin>n:return if bin:a+=[bin] f(a,bin*10+2,n) f(a,bin*10+8,n) def g(n,p): m=-1<<20 x=bisect.bisect_left(a,n) if x!=len(a) and a[x]==n:m=1 if a[p]**2>n:return m if n%a[p]==0:m=g(n//a[p],p)+1 return max(m...
{ "input": [ "1", "-1", "2", "4", "8", "32", "16", "64", "128", "256", "-2", "-4", "-5", "-8", "-7", "-10", "-11", "-15", "-26", "-49", "-36", "-58", "-75", "-62", "-14", "-13", "-9", "-12", "-3", "...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Problem statement Cards with ranks of $ 2 $ and $ 8 $ are powerful in card game millionaires. Therefore, we call an integer consisting of only the numbers $ 2 $ and $ 8 $ in $ 10 $ d...
p02150 Milk_11046
Problem If you bring an empty bottle of $ a $ milk, you can exchange it for a new bottle of $ b $ milk. How many bottles of milk can Mr. Kawabayashi, who initially has a bottle of $ x $ milk, drink? Output the remainder after dividing by $ 1000000007 $. Constraints The input satisfies the following conditions. * $ ...
a, b, x = map(int, input().split()) print((x+max(0, x-b)//(a-b)*b)%1000000007)
{ "input": [ "316250877917604 316250877917599 681260158257385", "3 1 5", "82 69 64", "3 2 5", "82 69 103", "3 2 1", "82 69 114", "3 2 0", "98 69 114", "560118409912468 316250877917599 681260158257385", "5 1 5", "82 69 30", "82 69 73", "82 78 114", "98 69 148...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Problem If you bring an empty bottle of $ a $ milk, you can exchange it for a new bottle of $ b $ milk. How many bottles of milk can Mr. Kawabayashi, who initially has a bottle of $ ...
p02291 Reflection_11050
For given three points p1, p2, p, find the reflection point x of p onto p1p2. <image> Constraints * 1 ≤ q ≤ 1000 * -10000 ≤ xi, yi ≤ 10000 * p1 and p2 are not identical. Input xp1 yp1 xp2 yp2 q xp0 yp0 xp1 yp1 ... xpq−1 ypq−1 In the first line, integer coordinates of p1 and p2 are given. Then, q queries are giv...
import math def equals(a, b): return abs(a - b) < 1e-10 class Point: def __init__(self, x=0, y=0): self.x = x self.y = y def __add__(self, p): return Point(self.x + p.x, self.y + p.y) def __sub__(self, p): return Point(self.x - p.x, self.y - p.y) def __mul__(sel...
{ "input": [ "0 0 3 4\n3\n2 5\n1 4\n0 3", "0 0 2 0\n3\n-1 1\n0 1\n1 1", "0 0 3 7\n3\n2 5\n1 4\n0 3", "0 0 1 0\n3\n-1 1\n0 1\n1 1", "0 0 3 7\n3\n2 5\n2 4\n0 3", "0 1 3 7\n3\n2 5\n2 4\n0 3", "0 1 3 7\n3\n1 5\n2 4\n0 3", "0 1 3 7\n3\n1 5\n4 4\n0 3", "0 0 3 7\n3\n1 5\n4 4\n0 3", "1...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: For given three points p1, p2, p, find the reflection point x of p onto p1p2. <image> Constraints * 1 ≤ q ≤ 1000 * -10000 ≤ xi, yi ≤ 10000 * p1 and p2 are not identical. Input x...
p02438 Splice_11053
For $n$ lists $L_i$ $(i = 0, 1, ..., n-1)$, perform a sequence of the following operations. * insert($t$, $x$): Insert an integer $x$ at the end of $L_t$. * dump($t$): Print all elements in $L_t$. * splice($s$, $t$): Transfer elements of $L_s$ to the end of $L_t$. $L_s$ becomes empty. In the initial state, $L_i$ $(...
import sys from collections import defaultdict, deque sys.stdin.readline().split() A = defaultdict(deque) ans = [] for query in sys.stdin: if query[0] == '0': t, x = query[2:].split() A[t].append(x) elif query[0] == '1': ans.append(' '.join(A[query[2:-1]]) + '\n') else: s, ...
{ "input": [ "3 10\n0 0 1\n0 0 2\n0 0 3\n0 1 4\n0 1 5\n2 1 0\n0 2 6\n1 0\n1 1\n1 2", "3 10\n0 0 1\n0 0 2\n0 0 3\n0 1 4\n0 1 5\n2 1 0\n0 2 9\n1 0\n1 1\n1 2", "3 10\n0 0 1\n0 0 2\n0 0 3\n0 1 4\n0 1 5\n2 2 0\n0 2 6\n1 0\n1 1\n1 2", "3 10\n0 0 1\n0 0 2\n0 0 3\n0 1 4\n0 1 5\n2 2 0\n0 2 6\n1 1\n1 1\n1 2", ...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: For $n$ lists $L_i$ $(i = 0, 1, ..., n-1)$, perform a sequence of the following operations. * insert($t$, $x$): Insert an integer $x$ at the end of $L_t$. * dump($t$): Print all elem...
1006_E. Military Problem_11063
In this problem you will have to help Berland army with organizing their command delivery system. There are n officers in Berland army. The first officer is the commander of the army, and he does not have any superiors. Every other officer has exactly one direct superior. If officer a is the direct superior of officer...
""" Satwik_Tiwari ;) . 30th july , 2020 - Thursday """ #=============================================================================================== #importing some useful libraries. from __future__ import division, print_function from fractions import Fraction import sys import os from io import BytesIO,...
{ "input": [ "9 6\n1 1 1 3 5 3 5 7\n3 1\n1 5\n3 4\n7 3\n1 8\n1 9\n", "2 1\n1\n1 1\n", "13 12\n1 1 1 1 1 1 1 1 1 1 1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n", "9 6\n1 1 1 3 5 3 5 7\n3 1\n1 10\n3 4\n7 3\n1 8\n1 9\n", "9 6\n1 1 1 3 5 3 5 7\n3 1\n1 10\n3 4\n7 2\n1 8\n1 9\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: In this problem you will have to help Berland army with organizing their command delivery system. There are n officers in Berland army. The first officer is the commander of the army...
102_D. Buses_11067
Little boy Gerald studies at school which is quite far from his house. That's why he has to go there by bus every day. The way from home to school is represented by a segment of a straight line; the segment contains exactly n + 1 bus stops. All of them are numbered with integers from 0 to n in the order in which they f...
a,b=map(int,input().split()) z=[] g=10**9+7 def f(): return map(int,input().split()) if b==0: print (0) else: s=set() for i in range(b): x,y=f() z.append((x,y)) s.add(x) s.add(y) s.add (0) s.add (a) s = sorted(list(s)) a=len(s)-1 s=dict([(s[j],j) for j...
{ "input": [ "2 2\n0 1\n1 2\n", "5 5\n0 1\n0 2\n0 3\n0 4\n0 5\n", "3 2\n0 1\n1 2\n", "68 74\n51 54\n3 22\n12 24\n3 27\n32 42\n36 55\n60 64\n1 4\n4 23\n11 64\n54 62\n50 56\n21 34\n27 63\n15 54\n28 61\n13 57\n39 53\n12 32\n32 40\n33 67\n55 61\n33 67\n30 37\n15 49\n27 45\n21 41\n8 42\n24 63\n40 48\n28 41...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Little boy Gerald studies at school which is quite far from his house. That's why he has to go there by bus every day. The way from home to school is represented by a segment of a str...
1051_D. Bicolorings_11071
You are given a grid, consisting of 2 rows and n columns. Each cell of this grid should be colored either black or white. Two cells are considered neighbours if they have a common border and share the same color. Two cells A and B belong to the same component if they are neighbours, or if there is a neighbour of A tha...
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": [ "4 1\n", "1 2\n", "3 4\n", "1000 1000\n", "1000 1999\n", "23 3\n", "1000 2000\n", "1000 1\n", "1 1\n", "10 15\n", "653 1305\n", "718 234\n", "1000 500\n", "816 2\n", "1000 1100\n", "27 3\n", "2 1\n", "10 10\n", "653 87\n", "2...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given a grid, consisting of 2 rows and n columns. Each cell of this grid should be colored either black or white. Two cells are considered neighbours if they have a common bo...
1073_E. Segment Sum_11074
You are given two integers l and r (l ≤ r). Your task is to calculate the sum of numbers from l to r (including l and r) such that each number contains at most k different digits, and print this sum modulo 998244353. For example, if k = 1 then you have to calculate all numbers from l to r such that each number is form...
import sys from array import array # noqa: F401 import typing as Tp # noqa: F401 def input(): return sys.stdin.buffer.readline().decode('utf-8') def main(): l, r, k = map(int, input().split()) valid_bits, is_valid_bits = [], [0] * 1024 for bit in range(1024): if bin(bit).count('1') <= k:...
{ "input": [ "10 50 2\n", "1 2345 10\n", "101 154 2\n", "99999999999999999 999999999999999999 6\n", "94010733142571570 227078148960766697 9\n", "1 999999999999999999 7\n", "772 1991 8\n", "2115 5821 2\n", "2001 3111 10\n", "267367244641009867 267367244641757963 2\n", "68831...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given two integers l and r (l ≤ r). Your task is to calculate the sum of numbers from l to r (including l and r) such that each number contains at most k different digits, and...
1095_E. Almost Regular Bracket Sequence_11078
You are given a bracket sequence s consisting of n opening '(' and closing ')' brackets. A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters '1' and '+' between the original characters of the sequence. For example, bracket sequences "()(...
n = int(input()) lis = list(input()) if n%2: print(0) else: st=[] for i in range(n): if lis[i]==')' and len(st)>0 and st[-1]=='(': st.pop() else: st.append(lis[i]) if len(st)==2 and st[0]==st[1]: if st[0]=='(': pre=[0]*(n+2) ans=0 ...
{ "input": [ "6\n()()()\n", "1\n)\n", "6\n(((())\n", "8\n)))(((((\n", "2\n)(\n", "4\n)(((\n", "6\n())(((\n", "2\n((\n", "3\n)))\n", "20\n(())(()((((()())()((\n", "10\n(()(())(((\n", "4\n))))\n", "10\n)(()()(()(\n", "12\n)())(())((((\n", "3\n(((\n", "4\n(...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given a bracket sequence s consisting of n opening '(' and closing ')' brackets. A regular bracket sequence is a bracket sequence that can be transformed into a correct arith...
1143_B. Nirvana_11084
Kurt reaches nirvana when he finds the product of all the digits of some positive integer. Greater value of the product makes the nirvana deeper. Help Kurt find the maximum possible product of digits among all integers from 1 to n. Input The only input line contains the integer n (1 ≤ n ≤ 2⋅10^9). Output Print the...
l = list(int(c) for c in str(int(input()))) def prod(l): p = 1 for d in l: p *= max(d, 1) return p m = prod(l) i = len(l) - 1 while i >= 0: while i >= 0 and l[i] == 9: i -= 1 if i < 0: break l[i] = 9 while i > 0 and l[i - 1] == 0: l[i - 1] = 9 i -= 1...
{ "input": [ "7\n", "1000000000\n", "390\n", "1\n", "9\n", "10\n", "890133136\n", "11\n", "485908655\n", "282587478\n", "1001\n", "889878787\n", "396579088\n", "791812587\n", "100\n", "25\n", "691993260\n", "389041744\n", "288\n", "268\n"...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Kurt reaches nirvana when he finds the product of all the digits of some positive integer. Greater value of the product makes the nirvana deeper. Help Kurt find the maximum possible ...
1163_B2. Cat Party (Hard Edition)_11088
This problem is same as the previous one, but has larger constraints. Shiro's just moved to the new house. She wants to invite all friends of her to the house so they can play monopoly. However, her house is too small, so she can only invite one friend at a time. For each of the n days since the day Shiro moved to th...
n = int(input()) a = list(map(int,input().split())) if(n == 1 or n == 2): print(n) exit() notpar = 0 occ = [0 for i in range(10**5 + 1)] base = 1 gotone = False leader = -1 leadby = 0 best = 0 occ[a[0]] += 1 cnt = 1 at1 = 1 for i in range(1, n): occ[a[i]] +=1 if(occ[a[i]] == 1): notpar ...
{ "input": [ "5\n10 100 20 200 1\n", "6\n1 1 1 2 2 2\n", "1\n100000\n", "13\n1 1 1 2 2 2 3 3 3 4 4 4 5\n", "7\n3 2 1 1 4 5 1\n", "10\n30518 96518 74071 59971 50121 4862 43967 73607 19138 90754\n", "10\n4 10 4 4 5 10 10 4 10 10\n", "10\n63649 14562 779 31060 84730 3390 1402 70955 27426 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: This problem is same as the previous one, but has larger constraints. Shiro's just moved to the new house. She wants to invite all friends of her to the house so they can play monopo...
1183_H. Subsequences (hard version)_11092
The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without changing the order of the remaining symbols. Characters to be deleted are not required to go successively, there can be any gaps between th...
def main(): from sys import stdin input = stdin.readline # input = open('25-B.txt', 'r').readline n, k = map(int, input().split()) s = input()[:-1] dp = [[0] * 26 for i in range(n + 1)] dp[0][0] = 1 for ch in s: j = ord(ch) - ord('a') for i in range(n, 0, -1): ...
{ "input": [ "4 5\nasdf\n", "5 6\naaaaa\n", "5 7\naaaaa\n", "10 100\najihiushda\n", "50 50\ndxldyzmsrrwzwaofkcxwehgvtrsximxgdqrhjthkgfucrjdvwl\n", "10 25\nbpehfvamul\n", "1 10\ns\n", "10 10\nhittmcsvmo\n", "30 656341937\nqrzlwlvhfatfwmlpvndtgrxyphfjnn\n", "5 50\nbhhaj\n", "...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: The only difference between the easy and the hard versions is constraints. A subsequence is a string that can be derived from another string by deleting some or no symbols without ch...
1201_C. Maximum Median_11096
You are given an array a of n integers, where n is odd. You can make the following operation with it: * Choose one of the elements of the array (for example a_i) and increase it by 1 (that is, replace it with a_i + 1). You want to make the median of the array the largest possible using at most k operations. The...
n , k =map(int,input().split()) arr = list(map(int,input().split())) arr.sort() def check(x): moves = 0 for i in range(n//2,n): if x - arr[i] > 0: moves += x - arr[i] if moves > k: return False if moves <= k: return True else: return False small =...
{ "input": [ "3 2\n1 3 5\n", "7 7\n4 1 2 4 3 4 4\n", "5 5\n1 2 1 1 1\n", "21 787008906\n335521569 160137548 807874739 723325809 995465063 693137631 646771913 971489138 603747543 801665542 882310956 163114045 892278880 371370111 459773357 909727810 630170326 940240523 886200899 882106547 953987440\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 of n integers, where n is odd. You can make the following operation with it: * Choose one of the elements of the array (for example a_i) and increase it by...
1243_B2. Character Swap (Hard Version)_11102
This problem is different from the easy version. In this version Ujan makes at most 2n swaps. In addition, k ≤ 1000, n ≤ 50 and it is necessary to print swaps themselves. You can hack this problem if you solve it. But you can hack the previous problem only if you solve both problems. After struggling and failing many ...
t = int(input()) def equal(s, t): s = [x for x in s] t = [x for x in t] # diff = [x for x in range(len(s)) if s[x] != t[x]] ans = [] for i in range(len(s)): for j in range(i+1, len(s)): if s[i] == s[j]: s[j], t[i] = t[i], s[j] ans.append([j+1, i+1...
{ "input": [ "4\n5\nsouse\nhouhe\n3\ncat\ndog\n2\naa\naz\n3\nabc\nbca\n", "4\n5\nsouse\nhouhe\n3\ncat\ndog\n2\naa\naz\n3\nabc\nbca\n", "4\n5\nsouse\nhouhe\n3\ncat\ndog\n2\naa\nza\n3\nabc\nbca\n", "4\n5\nsouse\nhouhf\n3\ncat\ndog\n2\naa\naz\n3\nabc\nbca\n", "4\n5\nsouse\nhouhe\n3\ncat\ndog\n2\nab\n...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: This problem is different from the easy version. In this version Ujan makes at most 2n swaps. In addition, k ≤ 1000, n ≤ 50 and it is necessary to print swaps themselves. You can hack...
1263_A. Sweet Problem_11106
You have three piles of candies: red, green and blue candies: * the first pile contains only red candies and there are r candies in it, * the second pile contains only green candies and there are g candies in it, * the third pile contains only blue candies and there are b candies in it. Each day Tanya eats...
from math import ceil for T in range(int(input())): r , g , b = sorted(list(map(int ,input().split()))) t = b -g if t >= r : print(r +g) else : print(r + g - ceil((r-t)/2))
{ "input": [ "6\n1 1 1\n1 2 1\n4 1 1\n7 4 10\n8 1 4\n8 2 8\n", "6\n1 1 1\n1 2 1\n4 1 1\n7 7 10\n8 1 4\n8 2 8\n", "6\n1 1 1\n1 2 1\n4 1 1\n7 7 18\n8 1 4\n8 2 8\n", "6\n1 1 1\n1 2 1\n4 1 1\n7 7 25\n8 1 4\n8 2 15\n", "6\n1 1 1\n2 2 1\n4 1 1\n7 4 10\n8 1 4\n8 2 8\n", "6\n1 1 1\n1 2 1\n4 1 1\n7 0 2...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You have three piles of candies: red, green and blue candies: * the first pile contains only red candies and there are r candies in it, * the second pile contains only green can...
1284_D. New Year and Conference_11110
Filled with optimism, Hyunuk will host a conference about how great this new year will be! The conference will have n lectures. Hyunuk has two candidate venues a and b. For each of the n lectures, the speaker specified two time intervals [sa_i, ea_i] (sa_i ≤ ea_i) and [sb_i, eb_i] (sb_i ≤ eb_i). If the conference is s...
import sys input = sys.stdin.readline import heapq n=int(input()) C=[tuple(map(int,input().split())) for i in range(n)] CA=[] CB=[] for ind,(a,b,c,d) in enumerate(C): CA.append((a,0,ind)) CA.append((b,1,ind)) CB.append((c,0,ind)) CB.append((d,1,ind)) CA.sort() CB.sort() SMAX=[] EMIN=[] FINISHED=...
{ "input": [ "3\n1 3 2 4\n4 5 6 7\n3 4 5 5\n", "6\n1 5 2 9\n2 4 5 8\n3 6 7 11\n7 10 12 16\n8 11 13 17\n9 12 14 18\n", "2\n1 2 3 6\n3 4 7 8\n", "4\n1 5 1 3\n2 6 2 4\n3 7 3 5\n4 8 4 6\n", "4\n1 5 1 5\n2 3 2 3\n4 6 6 8\n100 200 100 200\n", "4\n1 2 5 6\n2 3 1 2\n5 6 2 3\n6 7 6 7\n", "4\n1 3 5 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Filled with optimism, Hyunuk will host a conference about how great this new year will be! The conference will have n lectures. Hyunuk has two candidate venues a and b. For each of t...
138_B. Digits Permutations_11120
Andrey's favourite number is n. Andrey's friends gave him two identical numbers n as a New Year present. He hung them on a wall and watched them adoringly. Then Andrey got bored from looking at the same number and he started to swap digits first in one, then in the other number, then again in the first number and so o...
import itertools def countZeroes(s): ret = 0 for i in s: if i != '0': break ret += 1 return ret def stupid(n): ansMax = 0 bn1 = n bn2 = n for n1 in itertools.permutations(n): for n2 in itertools.permutations(n): val = str(int(''.join(n1)) + i...
{ "input": [ "500\n", "198\n", "8679647744\n", "9070901003919040000887091134838800004472724709967020097067025050205000220352709096100405900207957128\n", "3311314413231141411421432122343321141133112122342341334443214\n", "1099\n", "993522733475817\n", "3467624095736093676359443636504320...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Andrey's favourite number is n. Andrey's friends gave him two identical numbers n as a New Year present. He hung them on a wall and watched them adoringly. Then Andrey got bored from...
1454_F. Array Partition_11126
You are given an array a consisting of n integers. Let min(l, r) be the minimum value among a_l, a_{l + 1}, …, a_r and max(l, r) be the maximum value among a_l, a_{l + 1}, …, a_r. Your task is to choose three positive (greater than 0) integers x, y and z such that: * x + y + z = n; * max(1, x) = min(x + 1, x + ...
# Author : nitish420 -------------------------------------------------------------------- import math import os import sys from io import BytesIO, IOBase # mod=10**9+7 from collections import defaultdict from bisect import bisect_left def main(): for _ in range(int(input())): n=int(input()) arr=list(map(int,input...
{ "input": [ "6\n11\n1 2 3 3 3 4 4 3 4 2 1\n8\n2 9 1 7 3 9 4 1\n9\n2 1 4 2 4 3 3 1 2\n7\n4 2 1 1 4 1 4\n5\n1 1 1 1 1\n7\n4 3 4 3 3 3 4\n", "4\n3\n1 1 1\n3\n1 1 1\n3\n1 1 1\n3\n1 1 1\n", "8\n3\n1000000000 1000000000 1000000000\n3\n1 1000000000 1000000000\n3\n1000000000 1 1000000000\n3\n1 1 1000000000\n3\n1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given an array a consisting of n integers. Let min(l, r) be the minimum value among a_l, a_{l + 1}, …, a_r and max(l, r) be the maximum value among a_l, a_{l + 1}, …, a_r. Y...
1479_A. Searching Local Minimum_11129
This is an interactive problem. Homer likes arrays a lot and he wants to play a game with you. Homer has hidden from you a permutation a_1, a_2, ..., a_n of integers 1 to n. You are asked to find any index k (1 ≤ k ≤ n) which is a local minimum. For an array a_1, a_2, ..., a_n, an index i (1 ≤ i ≤ n) is said to be...
from collections import deque from typing import List from sys import stdout class ContestParser: """Helper module to read/write Commonly in programming competition input for a problem is given with space separated numbers and strings. Standard python input() functionality is clunky when dealing with suc...
{ "input": [ "5\n3\n2\n1\n4\n5\n", "31\n2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 1 22 23 24 25 26 27 28 29 30 31\n", "26\n12 8 5 1 3 4 6 7 9 10 13 14 15 16 18 19 20 2 11 17 21 22 23 24 25 26\n", "73\n14 61 69 73 59 26 8 2 65 51 68 3 22 31 30 36 5 64 60 62 9 24 48 46 12 19 18 52 39 67 42 50 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: This is an interactive problem. Homer likes arrays a lot and he wants to play a game with you. Homer has hidden from you a permutation a_1, a_2, ..., a_n of integers 1 to n. You ar...
1505_G. Encoded message_11133
Input The first line of the input contains a single integer N (1 ≤ N ≤ 24). The next N lines contain 5 space-separated integers each. The first three integers will be between 0 and 2, inclusive. The last two integers will be between 0 and 3, inclusive. The sum of the first three integers will be equal to the sum of ...
A = [ 'a 1 0 0 1 0', 'b 1 1 0 2 0', 'c 2 0 0 1 1', 'd 2 1 0 1 2', 'e 1 1 0 1 1', 'f 2 1 0 2 1', 'g 2 2 0 2 2', 'h 1 2 0 2 1', 'i 1 1 0 1 1', 'j 1 2 0 1 2', 'k 1 0 1 2 0', 'l 1 1 1 3 0', 'm 2 0 1 2 1', 'n 2 1 1 2 2', 'o 1 1 1 2 1', 'p 2 1 1 3 1', 'q 2 2 1 3 2', 'r 1 2 1 3 1', 's 1 1 1 2 1', 't 1 2 1 2 2', 'u 1 0 2 2 1',...
{ "input": [ "1\n1 0 0 1 0\n", "10\n2 0 0 1 1\n1 1 1 2 1\n2 1 0 1 2\n1 1 0 1 1\n2 1 0 2 1\n1 1 1 2 1\n1 2 1 3 1\n2 0 0 1 1\n1 1 0 1 1\n1 1 2 2 2\n", "1\n1 0 0 1 0\n", "1\n2 0 0 1 1\n", "1\n2 0 1 2 1\n", "1\n1 1 0 1 1\n", "1\n1 0 1 2 0\n", "1\n1 1 0 2 0\n", "1\n1 1 1 2 1\n", "1\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Input The first line of the input contains a single integer N (1 ≤ N ≤ 24). The next N lines contain 5 space-separated integers each. The first three integers will be between 0 and...
1529_A. Eshag Loves Big Arrays_11137
Eshag has an array a consisting of n integers. Eshag can perform the following operation any number of times: choose some subsequence of a and delete every element from it which is strictly larger than AVG, where AVG is the average of the numbers in the chosen subsequence. For example, if a = [1 , 4 , 3 , 2 , 4] and ...
import sys #import random from bisect import bisect_right as rb from collections import deque #sys.setrecursionlimit(10**8) from queue import PriorityQueue #from math import * input_ = lambda: sys.stdin.readline().strip("\r\n") ii = lambda : int(input_()) il = lambda : list(map(int, input_().split())) ilf = lambda : li...
{ "input": [ "3\n6\n1 1 1 2 2 3\n6\n9 9 9 9 9 9\n6\n6 4 1 1 4 1\n", "1\n2\n1 2\n", "1\n2\n0 2\n", "3\n6\n1 1 1 2 2 3\n6\n9 9 9 9 9 9\n6\n6 4 1 1 4 2\n", "3\n6\n1 1 1 2 2 3\n6\n9 9 9 9 9 9\n6\n6 2 1 1 4 1\n", "3\n6\n1 1 1 2 2 3\n6\n9 9 9 9 9 9\n6\n6 4 1 0 4 2\n", "3\n6\n1 1 1 2 4 3\n6\n9 9 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Eshag has an array a consisting of n integers. Eshag can perform the following operation any number of times: choose some subsequence of a and delete every element from it which is s...
160_A. Twins_11141
Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or bad. And if you do have a twin, then you very well know what it's like. Now let's imagine a typical morning in your family. You haven't w...
n = int(input()) a = sorted(list(map(int, input().split())))[::-1] b = sum(a)//2 sum1 = count = 0 for i in a: sum1+=i count+=1 if sum1>b: break print(count)
{ "input": [ "2\n3 3\n", "3\n2 1 2\n", "100\n5 5 4 3 5 1 2 5 1 1 3 5 4 4 1 1 1 1 5 4 4 5 1 5 5 1 2 1 3 1 5 1 3 3 3 2 2 2 1 1 5 1 3 4 1 1 3 2 5 2 2 5 5 4 4 1 3 4 3 3 4 5 3 3 3 1 2 1 4 2 4 4 1 5 1 3 5 5 5 5 3 4 4 3 1 2 5 2 3 5 4 2 4 5 3 2 4 2 4 3\n", "5\n2 2 2 4 4\n", "100\n85 50 17 89 65 89 5 20 86...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Imagine that you have a twin brother or sister. Having another person that looks exactly like you seems very unusual. It's hard to say if having something of an alter ego is good or b...
227_C. Flying Saucer Segments_11150
An expedition group flew from planet ACM-1 to Earth in order to study the bipedal species (its representatives don't even have antennas on their heads!). The flying saucer, on which the brave pioneers set off, consists of three sections. These sections are connected by a chain: the 1-st section is adjacent only to the...
def binpow(a,n): res = 1 while(n>0): if(n&1): res = (res*a)%m a = (a*a)%m n>>=1 return res n,m = map(int,input().split()) ans = binpow(3,n)-1 if(ans%m ==0 and ans != 0): print(m-1) else: print(ans%m)
{ "input": [ "1 10\n", "3 8\n", "8 100\n", "514853447 9\n", "7 63\n", "9 95\n", "333734901 647005907\n", "602799218 494169337\n", "6 29\n", "1 3\n", "3 1\n", "2 3\n", "6 5\n", "523061914 144515354\n", "2 81\n", "3 27\n", "357780112 9\n", "5285513...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: An expedition group flew from planet ACM-1 to Earth in order to study the bipedal species (its representatives don't even have antennas on their heads!). The flying saucer, on which ...
251_A. Points on Line_11154
Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d. Note that the order of the points inside the group of three chosen point...
from sys import stdin a,b=map(int,stdin.readline().split());a+=1 z=[1]+list(map(int,stdin.readline().split()));i,j=1,1;ans=0 r=lambda x:(x*(x+1))//2 while i<a: if j<=i:j=i while j<a and abs(z[j]-z[i])<=b:j+=1 if j-i-1>=2:ans+=r(j-i-2) i+=1 print(ans)
{ "input": [ "4 2\n-3 -2 -1 0\n", "4 3\n1 2 3 4\n", "5 19\n1 10 20 30 50\n", "1 14751211\n847188590\n", "10 90\n24 27 40 41 61 69 73 87 95 97\n", "10 50\n1 4 20 27 65 79 82 83 99 100\n", "10 5\n31 36 43 47 48 50 56 69 71 86\n", "100 100\n-98 -97 -96 -93 -92 -91 -90 -87 -86 -84 -81 -80 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that ...
276_B. Little Girl and Game_11158
The Little Girl loves problems on games very much. Here's one of them. Two players have got a string s, consisting of lowercase English letters. They play a game that is described by the following rules: * The players move in turns; In one move the player can remove an arbitrary letter from string s. * If the pl...
import sys #sys.stdin = open('in', 'r') #sys.stdout = open('out', 'w') def Out(x): sys.stdout.write(str(x) + '\n') def In(): return sys.stdin.readline().strip() def main(): s = str(input()) Map = {} for word in s: if word not in Map: Map[word] = 1 else: ...
{ "input": [ "aba\n", "abca\n", "zz\n", "aabc\n", "vqdtkbvlbdyndheoiiwqhnvcmmhnhsmwwrvesnpdfxvprqbwzbodoihrywagphlsrcbtnvppjsquuuzkjazaenienjiyctyajsqdfsdiedzugkymgzllvpxfetkwfabbiotjcknzdwsvmbbuqrxrulvgljagvxdmfsqtcczhifhoghqgffkbviphbabwiaqburerfkbqfjbptkwlahysrrfwjbqfnrgnsnsukqqcxxwqtuhvdzqmpfw...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: The Little Girl loves problems on games very much. Here's one of them. Two players have got a string s, consisting of lowercase English letters. They play a game that is described by...
322_B. Ciel and Flowers_11164
Fox Ciel has some flowers: r red flowers, g green flowers and b blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets: * To make a "red bouquet", it needs 3 red flowers. * To make a "green bouquet", it needs 3 green flowers. * To make a "blue bouquet", it needs 3 ...
a,b,c = map(int,input().split()) max_mix = min(a,b,c) res = -99999999999999 for i in range (0,min(3,max_mix)+1): pos = (i+(a-i)//3 + (b-i)//3 + (c-i)//3) res=max(res,pos) print(res)
{ "input": [ "3 6 9\n", "4 4 4\n", "0 0 0\n", "0 1 0\n", "2 2 0\n", "7 8 9\n", "666806767 385540591 357848286\n", "3 3 5\n", "494914467 356982656 757942689\n", "242854896 442432924 180395753\n", "32 62 92\n", "8 8 9\n", "139978911 5123031 935395222\n", "93798444...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Fox Ciel has some flowers: r red flowers, g green flowers and b blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets: * To make a "r...
370_A. Rook, Bishop and King_11170
Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square fields organized into an 8 × 8 table. A field is represented by a pair of integers (r, c) — the number of the row and the number of the co...
def benteng(x1,y1,x2,y2): if(x1==x2 or y1==y2): return 1 else: return 2 def mentri(x1,y1,x2,y2): if(abs(x1-x2)==abs(y1-y2)): return 1 if((abs(x1-x2)+abs(y1-y2))%2==0): return 2 return 0 def raja(x1,y1,x2,y2): a=abs(x1-x2) b=abs(y1-y2) if(a>b): re...
{ "input": [ "5 5 5 6\n", "4 3 1 6\n", "1 4 6 2\n", "8 1 1 8\n", "1 3 1 6\n", "6 7 4 1\n", "1 7 5 4\n", "1 5 2 7\n", "4 2 6 4\n", "1 2 3 2\n", "3 3 1 5\n", "1 1 8 1\n", "1 3 3 7\n", "3 8 7 2\n", "1 1 8 8\n", "8 1 1 1\n", "6 5 1 4\n", "8 1 8 8\n",...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Little Petya is learning to play chess. He has already learned how to move a king, a rook and a bishop. Let us remind you the rules of moving chess pieces. A chessboard is 64 square f...
391_F1. Stock Trading_11174
This problem consists of three subproblems: for solving subproblem F1 you will receive 8 points, for solving subproblem F2 you will receive 15 points, and for solving subproblem F3 you will receive 10 points. Manao has developed a model to predict the stock price of a company over the next n days and wants to design a...
import sys ammount_prices, days_for_trading=map(int, input().split()) stonks=[] for i in range (0, ammount_prices): price=int(sys.stdin.readline()) stonks.append(price) def get_max(days_for_trading, stonks): size_prices = len(stonks) if size_prices == 0 or size_prices == 1 or days_for_trading == 0: ...
{ "input": [ "10 2\n2\n7\n3\n9\n8\n7\n9\n7\n1\n9\n", "10 5\n2\n7\n3\n9\n8\n7\n9\n7\n1\n9\n", "2 1\n2\n1\n", "10 2\n2\n7\n3\n9\n8\n7\n9\n4\n1\n9\n", "10 5\n2\n7\n3\n9\n8\n7\n9\n7\n1\n18\n", "10 5\n2\n7\n3\n9\n8\n7\n9\n7\n1\n13\n", "2 2\n2\n1\n", "10 8\n2\n7\n3\n9\n8\n7\n9\n7\n1\n9\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: This problem consists of three subproblems: for solving subproblem F1 you will receive 8 points, for solving subproblem F2 you will receive 15 points, and for solving subproblem F3 yo...
441_B. Valera and Fruits_11180
Valera loves his garden, where n fruit trees grow. This year he will enjoy a great harvest! On the i-th tree bi fruit grow, they will ripen on a day number ai. Unfortunately, the fruit on the tree get withered, so they can only be collected on day ai and day ai + 1 (all fruits that are not collected in these two days,...
frukti_po_dnyam = {} n, resurs =map(int,input().split(' ')) for i in range(n): den, chislo_fruktov = map(int, input().split(' ')) if den in frukti_po_dnyam: frukti_po_dnyam[den] += chislo_fruktov else: frukti_po_dnyam[den] = chislo_fruktov if den + 1 not in frukti_po_dnyam: fru...
{ "input": [ "5 10\n3 20\n2 20\n1 20\n4 20\n5 20\n", "2 3\n1 5\n2 3\n", "5 3000\n5 772\n1 2522\n2 575\n4 445\n3 426\n", "2 100\n3000 100\n3000 100\n", "1 40\n3000 42\n", "1 10\n3000 20\n", "10 3000\n1 2522\n4 445\n8 1629\n5 772\n9 2497\n6 81\n3 426\n7 1447\n2 575\n10 202\n", "1 1\n3000...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Valera loves his garden, where n fruit trees grow. This year he will enjoy a great harvest! On the i-th tree bi fruit grow, they will ripen on a day number ai. Unfortunately, the fru...
463_C. Gargari and Bishops_11184
Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius. He has a n × n chessboard. Each cell of the chessboard has a number written on it. Gargari wants to place two bishops on the chessboard in such a way that there is no cell that is attacked by both of...
import sys input=sys.stdin.buffer.readline t=1 for __ in range(t): a=[] n=int(input()) for i in range(n): b=list(map(int,input().split())) a.append(b) dr={} di={} for i in range(n): for j in range(n): dr[i+j]=dr.get(i+j,0)+a[i][j] di[i+n-j+1]=d...
{ "input": [ "4\n1 1 1 1\n2 1 1 0\n1 1 1 0\n1 0 0 1\n", "8\n3 6 9 2 2 1 4 2\n1 4 10 1 1 10 1 4\n3 8 9 1 8 4 4 4\n5 8 10 5 5 6 4 7\n3 2 10 6 5 3 8 5\n6 7 5 8 8 5 4 2\n4 4 3 1 8 8 5 4\n5 6 8 9 3 1 8 5\n", "10\n48 43 75 80 32 30 65 31 18 91\n99 5 12 43 26 90 54 91 4 88\n8 87 68 95 73 37 53 46 53 90\n50 1 85 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Gargari is jealous that his friend Caisa won the game from the previous problem. He wants to prove that he is a genius. He has a n × n chessboard. Each cell of the chessboard has a n...
487_B. Strip_11188
Alexandra has a paper strip with n numbers on it. Let's call them ai from left to right. Now Alexandra wants to split it into some pieces (possibly 1). For each piece of strip, it must satisfy: * Each piece should contain at least l numbers. * The difference between the maximal and the minimal number on the piece...
def split(a,n,s,l): pieces = [] i = 1 tmpmin = a[0] tmpmax = a[0] tmppc = [a[0]] while i<n: if abs(a[i]-tmpmin)<=s and abs(a[i]-tmpmax)<=s: tmppc.append(a[i]) if a[i]<tmpmin: tmpmin=a[i] elif a[i]>tmpmax: tmpmax = a[i] else: piece...
{ "input": [ "7 2 2\n1 100 1 100 1 100 1\n", "7 2 2\n1 3 1 2 4 1 2\n", "1 0 1\n0\n", "10 3 3\n1 1 1 1 1 5 6 7 8 9\n", "2 1000000000 2\n-1000000000 1000000000\n", "6 565 2\n31 76 162 -182 -251 214\n", "1 0 1\n-1000000000\n", "2 1000000000 1\n-1000000000 1000000000\n", "1 100 2\n42\n...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Alexandra has a paper strip with n numbers on it. Let's call them ai from left to right. Now Alexandra wants to split it into some pieces (possibly 1). For each piece of strip, it mu...
510_A. Fox And Snake_11192
Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead. A snake is a pattern on a n by m table. Denote c-th cell of r-th row as (r, c). The tail of the snake is located at (1, 1), then it's body extends to (1,...
n,m=map(int,input().split()) s="."*(m-1)+"#" #print(s) for i in range(n): if i%2==0:print("#"*m) else: print(s) s=s[::-1]
{ "input": [ "9 9\n", "5 3\n", "3 3\n", "3 4\n", "45 45\n", "11 3\n", "11 15\n", "7 7\n", "5 6\n", "19 3\n", "7 5\n", "45 4\n", "45 3\n", "3 6\n", "45 49\n", "43 27\n", "33 43\n", "49 49\n", "7 3\n", "49 50\n", "5 5\n", "3 5\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Fox Ciel starts to learn programming. The first task is drawing a fox! However, that turns out to be too hard for a beginner, so she decides to draw a snake instead. A snake is a pat...
535_B. Tavas and SaDDas_11196
Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punish him! SaDDas took Tavas' headphones and told him: "If you solve the following problem, I'll return it to you." <image> The problem is:...
a = input().replace("4",'0').replace("7",'1') sumA = 0 for x in range(len(a)) : sumA += 2**x print((int(a,2)+sumA))
{ "input": [ "4\n", "77\n", "7\n", "7747\n", "447\n", "7474747\n", "77474\n", "774477\n", "774\n", "477477447\n", "777774\n", "777744747\n", "47\n", "747777\n", "7774477\n", "444\n", "7747474\n", "444444444\n", "7444\n", "4447\n", "44...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Once again Tavas started eating coffee mix without water! Keione told him that it smells awful, but he didn't stop doing that. That's why Keione told his smart friend, SaDDas to punis...
55_C. Pie or die_11200
Volodya and Vlad play the following game. There are k pies at the cells of n × m board. Each turn Volodya moves one pie to the neighbouring (by side) cell. If the pie lies at the border of the board then Volodya can move it outside the board, get the pie and win. After Volodya's move, Vlad bans some edge at the border ...
n, m, k = [int(x) for x in input().split()] canwin = False for i in range(k): x, y = [int(x) for x in input().split()] canwin |= x < 6 or n - x < 5 canwin |= y < 6 or m - y < 5 print("YES" if canwin else "NO")
{ "input": [ "100 50 2\n50 25\n50 25\n", "3 4 0\n", "2 2 1\n1 2\n", "20 20 5\n10 6\n6 8\n16 11\n11 11\n7 15\n", "66 94 26\n11 75\n46 72\n55 74\n34 10\n33 84\n25 11\n13 23\n27 73\n45 22\n54 34\n53 63\n28 8\n57 46\n26 78\n52 46\n32 38\n22 55\n17 71\n56 18\n9 60\n31 54\n6 84\n59 57\n60 81\n51 49\n41 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Volodya and Vlad play the following game. There are k pies at the cells of n × m board. Each turn Volodya moves one pie to the neighbouring (by side) cell. If the pie lies at the bord...
608_A. Saitama Destroys Hotel_11206
Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts on the top floor, can only move down, and has infinite capacity. Floors are numbered from 0 to s and elevator initially starts on floor s...
I=lambda:map(int,input().split()) n,s=I() print(max(max(sum(I()),s)for _ in '0'*n))
{ "input": [ "5 10\n2 77\n3 33\n8 21\n9 12\n10 64\n", "3 7\n2 1\n3 8\n5 2\n", "2 10\n9 10\n6 11\n", "2 7\n6 3\n1 5\n", "2 10\n9 3\n1 4\n", "2 20\n10 10\n19 9\n", "2 20\n1 1\n2 2\n", "2 100\n4 100\n7 99\n", "4 4\n4 6\n4 8\n1 7\n2 9\n", "2 100\n99 9\n1 10\n", "100 1\n1 1\n1 1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in one of its other hotels. The elevator is special — it starts ...
792_F. Mages and Monsters_11225
Vova plays a computer game known as Mages and Monsters. Vova's character is a mage. Though as he has just started, his character knows no spells. Vova's character can learn new spells during the game. Every spell is characterized by two values xi and yi — damage per second and mana cost per second, respectively. Vova ...
#!/usr/bin/env python3 # solution after hint # (instead of best hit/mana spell store convex hull of spells) # O(n^2) instead of O(n log n) [q, m] = map(int, input().strip().split()) qis = [tuple(map(int, input().strip().split())) for _ in range(q)] mod = 10**6 j = 0 spell_chull = [(0, 0)] # lower hull _/ def is_...
{ "input": [ "3 100\n1 4 9\n2 19 49\n2 19 49\n", "2 424978864039\n2 7 3\n2 10 8\n", "15 100\n1 8 8\n2 200 101\n2 10 99\n1 9 9\n2 10 99\n2 200 101\n1 14 4\n2 194 195\n2 194 194\n2 990 290\n1 2 999992\n2 6 256\n2 7 256\n1 2 999988\n2 2 252\n", "3 10\n1 1 1\n2 1 1\n2 999999 999999\n", "12 100\n1 8 8\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Vova plays a computer game known as Mages and Monsters. Vova's character is a mage. Though as he has just started, his character knows no spells. Vova's character can learn new spell...
813_C. The Tag Game_11229
Alice got tired of playing the tag game by the usual rules so she offered Bob a little modification to it. Now the game should be played on an undirected rooted tree of n vertices. Vertex 1 is the root of the tree. Alice starts at vertex 1 and Bob starts at vertex x (x ≠ 1). The moves are made in turns, Bob goes first...
import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline from collections import defaultdict,deque n,x=list(map(int,input().split())) edge=defaultdict(list) child=defaultdict(list) for i in range(n-1): u,v=list(map(int,input().split())) edge[u].append(v) edge[v].append(u) def bfsDistance(no...
{ "input": [ "4 3\n1 2\n2 3\n2 4\n", "5 2\n1 2\n2 3\n3 4\n2 5\n", "3 3\n1 2\n3 2\n", "8 3\n2 1\n3 1\n4 3\n5 1\n6 1\n7 1\n8 6\n", "10 4\n5 4\n8 3\n4 6\n5 3\n7 9\n1 3\n5 10\n2 9\n9 8\n", "2 2\n2 1\n", "3 3\n2 1\n3 1\n", "34 33\n2 1\n3 2\n4 3\n5 2\n6 3\n7 2\n8 5\n9 7\n10 8\n11 7\n12 7\n13...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Alice got tired of playing the tag game by the usual rules so she offered Bob a little modification to it. Now the game should be played on an undirected rooted tree of n vertices. Ve...
839_B. Game of the Rows_11233
Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains ai soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne. She has recently bought an airplane to carry her army through the sea. The airplane has n rows, each of them has 8 seats. We call two s...
n,m=map(int,input().split()) l=list(map(int,input().split())) p=n for i in range(m) : b=l[i]//4 l[i]=l[i]-4*min(p,l[i]//4) p=p-min(p,b) p1=n*2 for i in range(m) : b=l[i]//2 l[i]=l[i]-2*min(p1,l[i]//2) p1=p1-min(p1,b) p2=p+p1 p3=p for i in range(m) : b=l[i]//2 l[i]=l[i]-2*min(p2,l[i]//2)...
{ "input": [ "2 2\n5 8\n", "1 2\n7 1\n", "1 4\n2 2 1 2\n", "1 2\n4 4\n", "1 4\n1 2 2 2\n", "8459 91\n778 338 725 1297 115 540 1452 2708 193 1806 1496 1326 2648 176 199 93 342 3901 2393 2718 800 3434 657 4037 291 690 1957 3280 73 6011 2791 1987 440 455 444 155 261 234 829 1309 1164 616 34 627 1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains ai soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne...
859_E. Desk Disorder_11237
A new set of desks just arrived, and it's about time! Things were getting quite cramped in the office. You've been put in charge of creating a new seating chart for the engineers. The desks are numbered, and you sent out a survey to the engineering team asking each engineer the number of the desk they currently sit at,...
n = int(input()) m = 2 * n + 1 u = [[] for i in range(m)] v = [0] * m s = [0] * m d = 10 ** 9 + 7 y = 1 for j in range(n): a, b = map(int, input().split()) v[a] = b if a != b: s[b] += 1 u[b].append(a) for b in range(m): if not v[b]: x = 0 p = [b] while p: ...
{ "input": [ "4\n1 5\n5 2\n3 7\n7 3\n", "5\n1 10\n2 10\n3 10\n4 10\n5 5\n", "1\n1 2\n", "30\n22 37\n12 37\n37 58\n29 57\n43 57\n57 58\n58 53\n45 4\n1 4\n4 51\n35 31\n21 31\n31 51\n51 53\n53 48\n60 55\n52 55\n55 33\n36 9\n10 9\n9 33\n33 19\n5 23\n47 23\n23 32\n50 44\n26 44\n44 32\n32 19\n19 48\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: A new set of desks just arrived, and it's about time! Things were getting quite cramped in the office. You've been put in charge of creating a new seating chart for the engineers. The...
884_D. Boxes And Balls_11241
Ivan has n different boxes. The first of them contains some balls of n different colors. Ivan wants to play a strange game. He wants to distribute the balls into boxes in such a way that for every i (1 ≤ i ≤ n) i-th box will contain all balls with color i. In order to do this, Ivan will make some turns. Each turn he ...
from heapq import * n = int(input()) a = list(map(int, input().split())) heap = [] res = 0 for i in range(n): heappush(heap, a[i]) if n % 2 == 0: heappush(heap, 0) while n > 1: cur = heappop(heap) cur += heappop(heap) cur += heappop(heap) res += cur heappush(heap, cur) n -= 2 print(res)
{ "input": [ "3\n1 2 3\n", "4\n2 3 4 5\n", "2\n3 4\n", "8\n821407370 380061316 428719552 90851747 825473738 704702117 845629927 245820158\n", "1\n10\n", "1\n1\n", "1\n4\n", "6\n1 4 4 4 4 4\n", "1\n12312\n", "2\n2 4\n", "8\n821407370 380061316 428719552 90851747 825473738 70...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Ivan has n different boxes. The first of them contains some balls of n different colors. Ivan wants to play a strange game. He wants to distribute the balls into boxes in such a way ...
908_F. New Year and Rainbow Roads_11245
Roy and Biv have a set of n points on the infinite number line. Each point has one of 3 colors: red, green, or blue. Roy and Biv would like to connect all the points with some edges. Edges can be drawn between any of the two of the given points. The cost of an edge is equal to the distance between the two points it c...
def F1(): n = int(input()) ans = 0 allc = 0 bigr = 0 bigb = 0 lastr = -1 lastb = -1 lastg = -(1 << 60) for i in range(n): x = input().split() pos, col = int(x[0]), x[1] if col == 'R' or col == 'G': if lastr != -1: bigr = max(big...
{ "input": [ "4\n1 G\n2 R\n3 B\n10 G\n", "4\n1 G\n5 R\n10 B\n15 G\n", "4\n1 G\n123123 R\n987987987 B\n1000000000 G\n", "1\n3 R\n", "4\n1 G\n123123 R\n987987987 B\n1000000100 G\n", "1\n2 R\n", "4\n2 G\n123123 R\n987987987 B\n1000000000 G\n", "4\n1 G\n2 R\n3 B\n14 G\n", "4\n1 G\n3 R\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Roy and Biv have a set of n points on the infinite number line. Each point has one of 3 colors: red, green, or blue. Roy and Biv would like to connect all the points with some edges...
92_E. Ski Base_11249
A ski base is planned to be built in Walrusland. Recently, however, the project is still in the constructing phase. A large land lot was chosen for the construction. It contains n ski junctions, numbered from 1 to n. Initially the junctions aren't connected in any way. In the constructing process m bidirectional ski r...
import sys from array import array # noqa: F401 def input(): return sys.stdin.buffer.readline().decode('utf-8') class UnionFind(object): __slots__ = ['nodes'] def __init__(self, n: int): self.nodes = [-1] * n def find(self, x: int) -> int: if self.nodes[x] < 0: return ...
{ "input": [ "3 4\n1 3\n2 3\n1 2\n1 2\n", "27 29\n12 11\n21 20\n19 26\n16 24\n22 4\n1 3\n23 5\n9 1\n4 3\n21 23\n22 8\n14 6\n25 13\n7 20\n9 16\n3 20\n23 19\n17 10\n13 18\n8 14\n23 25\n25 27\n19 15\n19 15\n17 24\n12 27\n18 11\n25 5\n22 17\n", "15 29\n6 11\n14 3\n10 4\n14 7\n6 14\n7 15\n13 8\n10 13\n4 14\n15...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: A ski base is planned to be built in Walrusland. Recently, however, the project is still in the constructing phase. A large land lot was chosen for the construction. It contains n ski...
958_C1. Encryption (easy)_11253
Rebel spy Heidi has just obtained the plans for the Death Star from the Empire and, now on her way to safety, she is trying to break the encryption of the plans (of course they are encrypted – the Empire may be evil, but it is not stupid!). The encryption has several levels of security, and here is how the first one lo...
n,p = map(int,input().split()) a = list(map(int,input().split())) forward = [a[0]] for i in range(1,n): forward.append(forward[-1] + a[i]) sm = sum(a) mx = -float('inf') for i in range(n-1): mx = max(mx,(forward[i]%p) + ((sm -forward[i] )%p)) print(mx)
{ "input": [ "4 10\n3 4 7 2\n", "10 12\n16 3 24 13 9 8 7 5 12 12\n", "10 5 12\n16 3 24 13 9 8 7 5 12 12\n", "5 50\n1 1 1 1 1\n", "5 50\n100 150 200 100 50\n", "4 3 10\n3 4 7 2\n", "2 2\n9 9\n", "2 2\n8 8\n", "10 5 12\n16 3 24 13 9 8 5 5 12 12\n", "5 50\n1 2 1 1 1\n", "5 50\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Rebel spy Heidi has just obtained the plans for the Death Star from the Empire and, now on her way to safety, she is trying to break the encryption of the plans (of course they are en...
p02568 AtCoder Library Practice Contest - Range Affine Range Sum_11268
You are given an array a_0, a_1, ..., a_{N-1} of length N. Process Q queries of the following types. * `0 l r b c`: For each i = l, l+1, \dots, {r - 1}, set a_i \gets b \times a_i + c. * `1 l r`: Print \sum_{i = l}^{r - 1} a_i \bmod 998244353. Constraints * 1 \leq N, Q \leq 500000 * 0 \leq a_i, c < 998244353 * 1 \le...
#!usr/bin/env python3 from collections import defaultdict, deque, Counter, OrderedDict from bisect import bisect_left, bisect_right from functools import reduce, lru_cache from heapq import heappush, heappop, heapify import itertools import math, fractions import sys, copy def L(): return sys.stdin.readline().split()...
{ "input": [ "5 7\n1 2 3 4 5\n1 0 5\n0 2 4 100 101\n1 0 3\n0 1 3 102 103\n1 2 5\n0 2 5 104 105\n1 0 5", "5 7\n1 2 3 4 5\n1 0 5\n0 2 4 100 101\n1 0 3\n0 1 5 102 103\n1 2 5\n0 2 5 104 105\n1 0 5", "5 7\n1 2 3 4 5\n1 0 5\n0 2 4 100 101\n1 0 3\n0 2 5 102 103\n1 2 5\n0 2 5 104 105\n1 0 5", "5 7\n2 2 3 4 5\...
5ATCODER
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_0, a_1, ..., a_{N-1} of length N. Process Q queries of the following types. * `0 l r b c`: For each i = l, l+1, \dots, {r - 1}, set a_i \gets b \times a_i + ...
p02699 AtCoder Beginner Contest 164 - Sheep and Wolves_11272
There are S sheep and W wolves. If the number of wolves is greater than or equal to that of sheep, the wolves will attack the sheep. If the wolves will attack the sheep, print `unsafe`; otherwise, print `safe`. Constraints * 1 \leq S \leq 100 * 1 \leq W \leq 100 Input Input is given from Standard Input in the fol...
s,w = map(int, input().split()) print("safe" if w<s else "unsafe")
{ "input": [ "4 5", "100 2", "10 10", "1 5", "101 2", "5 10", "1 6", "111 2", "8 10", "0 6", "111 0", "11 10", "-1 6", "111 -1", "6 10", "-1 9", "101 -1", "3 10", "-1 7", "001 -1", "5 14", "0 7", "001 0", "1 14", "0 10...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are S sheep and W wolves. If the number of wolves is greater than or equal to that of sheep, the wolves will attack the sheep. If the wolves will attack the sheep, print `unsa...
p02965 AtCoder Grand Contest 036 - GP 2_11276
We have a sequence of N integers: x=(x_0,x_1,\cdots,x_{N-1}). Initially, x_i=0 for each i (0 \leq i \leq N-1). Snuke will perform the following operation exactly M times: * Choose two distinct indices i, j (0 \leq i,j \leq N-1,\ i \neq j). Then, replace x_i with x_i+2 and x_j with x_j+1. Find the number of differe...
n,m=map(int,input().split()) w,u=3*m,n-1 o,f,i=998244353,[1],1 while i<w+n:f+=[f[-1]*i%o];i+=1 c=lambda n,k=u:f[n]*pow(f[n-k],o-2,o)*pow(f[k],o-2,o) a=c(w+u)-n*c(n+m-2) while~-n>m<w:m+=2;a-=c(n,m)*c(2*u+w-m>>1) print(a%o)
{ "input": [ "3 2", "100000 50000", "10 10", "2 2", "100001 50000", "5 10", "0 2", "100001 27098", "5 7", "101001 27098", "6 7", "101000 27098", "3 7", "101000 9586", "3 10", "101000 14296", "2 10", "101000 4853", "101000 3325", "101001 3...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: We have a sequence of N integers: x=(x_0,x_1,\cdots,x_{N-1}). Initially, x_i=0 for each i (0 \leq i \leq N-1). Snuke will perform the following operation exactly M times: * Choose t...
p03248 AtCoder Regular Contest 103 - Tr/ee_11282
You are given a string s of length n. Does a tree with n vertices that satisfies the following conditions exist? * The vertices are numbered 1,2,..., n. * The edges are numbered 1,2,..., n-1, and Edge i connects Vertex u_i and v_i. * If the i-th character in s is `1`, we can have a connected component of size i by rem...
def die(): print(-1); exit() s = input() n = len(s) if s[-1] == '1': die() if s[0] == '0': die() for i in range(n-1): if s[i] != s[-i-2]: die() root = last = 1 for i in range(n-1): last+= 1 print(root, last) if s[i] == '1': root = last
{ "input": [ "1110", "1111", "1010", "1011", "0111", "1000", "1100", "0011", "1001", "0100", "0110", "0001", "0101", "0010", "1101", "0000", "0111", "1011", "0010", "0101", "0011", "0000", "0100", "1001", "1100", "...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given a string s of length n. Does a tree with n vertices that satisfies the following conditions exist? * The vertices are numbered 1,2,..., n. * The edges are numbered 1,2,...
p03399 AtCoder Beginner Contest 092 - Traveling Budget_11286
You planned a trip using trains and buses. The train fare will be A yen (the currency of Japan) if you buy ordinary tickets along the way, and B yen if you buy an unlimited ticket. Similarly, the bus fare will be C yen if you buy ordinary tickets along the way, and D yen if you buy an unlimited ticket. Find the minimu...
A = [int(input()) for i in range(4)] print(min(A[0],A[1]) + min(A[2],A[3]))
{ "input": [ "549\n817\n715\n603", "555\n555\n400\n200", "600\n300\n220\n420", "549\n838\n715\n603", "555\n312\n400\n200", "600\n548\n220\n420", "549\n838\n715\n182", "555\n312\n400\n206", "600\n548\n220\n156", "600\n548\n220\n118", "549\n838\n115\n182", "555\n134\n728\...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You planned a trip using trains and buses. The train fare will be A yen (the currency of Japan) if you buy ordinary tickets along the way, and B yen if you buy an unlimited ticket. Si...
p03564 AtCoder Beginner Contest 076 - Addition and Multiplication_11290
Square1001 has seen an electric bulletin board displaying the integer 1. He can perform the following operations A and B to change this value: * Operation A: The displayed value is doubled. * Operation B: The displayed value increases by K. Square1001 needs to perform these operations N times in total. Find the min...
n=int(input()) k=int(input()) s=1 for i in range(n): s=min(s+k, s*2) print(s)
{ "input": [ "10\n10", "4\n3", "10\n17", "4\n4", "10\n15", "4\n7", "10\n11", "4\n2", "10\n14", "4\n0", "10\n24", "4\n-1", "10\n9", "4\n-2", "10\n4", "4\n-4", "10\n1", "4\n-5", "10\n2", "4\n-3", "4\n1", "10\n-1", "4\n6", "1...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Square1001 has seen an electric bulletin board displaying the integer 1. He can perform the following operations A and B to change this value: * Operation A: The displayed value is d...
p03719 AtCoder Beginner Contest 061 - Between Two Integers_11294
You are given three integers A, B and C. Determine whether C is not less than A and not greater than B. Constraints * -100≤A,B,C≤100 * A, B and C are all integers. Input Input is given from Standard Input in the following format: A B C Output If the condition is satisfied, print `Yes`; otherwise, print `No`. ...
a,b,c=map(int,input().split());print('YNeos'[a>c or b<c::2])
{ "input": [ "6 5 4", "2 2 2", "1 3 2", "7 5 4", "-1 2 -1", "2 0 2", "1 0 2", "7 5 3", "2 -1 2", "1 1 2", "7 3 3", "2 -1 0", "1 1 0", "7 1 3", "2 0 0", "2 1 0", "7 1 4", "2 1 -1", "2 0 1", "7 0 4", "2 2 -1", "2 1 2", "7 -1 4",...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given three integers A, B and C. Determine whether C is not less than A and not greater than B. Constraints * -100≤A,B,C≤100 * A, B and C are all integers. Input Input is ...
p03879 CODE FESTIVAL 2016 Grand Final(Parallel) - Inscribed Bicycle_11298
Snuke received a triangle as a birthday present. The coordinates of the three vertices were (x_1, y_1), (x_2, y_2), and (x_3, y_3). He wants to draw two circles with the same radius inside the triangle such that the two circles do not overlap (but they may touch). Compute the maximum possible radius of the circles. C...
from math import hypot x1, y1, x2, y2, x3, y3 = map(int, open(0).read().split()) a = hypot(x1 - x2, y1 - y2) b = hypot(x2 - x3, y2 - y3) c = hypot(x3 - x1, y3 - y1) R = abs((x2 - x1) * (y3 - y1) - (x3 - x1) * (y2 - y1)) / (a + b + c) m = max(a, b, c) r = m / (2 + m / R) print("{:.12f}".format(r))
{ "input": [ "3 1\n1 5\n4 9", "0 0\n1 1\n2 0", "3 1\n1 5\n1 9", "0 -1\n1 1\n2 0", "3 1\n1 5\n1 15", "0 -1\n1 1\n1 0", "3 2\n1 5\n1 15", "-1 -1\n1 1\n1 0", "3 2\n2 5\n1 15", "-1 -1\n1 1\n2 0", "3 4\n2 5\n1 15", "-1 0\n1 1\n2 0", "3 6\n2 5\n1 15", "-2 0\n1 1\n2 0"...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Snuke received a triangle as a birthday present. The coordinates of the three vertices were (x_1, y_1), (x_2, y_2), and (x_3, y_3). He wants to draw two circles with the same radius ...
p04040 AtCoder Regular Contest 058 - Iroha and a Grid_11302
We have a large square grid with H rows and W columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell. However, she cannot enter the cells in the intersection of the bottom A rows and the leftmost B columns. (That is, there ...
from sys import stdin, stdout, stderr, setrecursionlimit from functools import lru_cache setrecursionlimit(10**7) mod = 10**9 + 7 def solve(): def binom(n, k): res = (modfact[n] * factinv[k]) % mod res = (res * factinv[n - k]) % mod return res h, w, a, b = map(int, input().split()) ...
{ "input": [ "2 3 1 1", "100000 100000 99999 99999", "100000 100000 44444 55555", "10 7 3 4", "10 7 6 4", "10 8 6 4", "17 8 6 4", "17 8 6 6", "2 4 1 1", "100000 100000 99999 72298", "100000 100000 43938 55555", "10 13 6 4", "17 8 5 6", "3 4 1 1", "100000 100...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: We have a large square grid with H rows and W columns. Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the bott...
p00121 Seven Puzzle_11306
The 7 puzzle consists of 8 square cards and a frame that fits them snugly. Each card is numbered 0, 1, 2, ..., 7 to distinguish them from each other. You can arrange two cards vertically and four cards horizontally in the frame. 7 When you start the puzzle, first put all the cards in the frame. Only 0 cards in the fra...
from collections import deque import copy swap = [[1, 4], [0, 2, 5], [1, 3, 6], [2, 7], [0, 5], [1, 4, 6], [2, 5, 7], [3, 6]] def bfs(): ia = list(range(8)) count = {str(ia): 0} que = deque() que.append((ia, 0)) while len(que) != 0: state, cnt = que.popleft() # pos:0????????? ...
{ "input": [ "0 1 2 3 4 5 6 7\n1 0 2 3 4 5 6 7\n7 6 5 4 3 2 1 0", "1 0 2 3 4 5 6 7\n1 0 2 3 4 5 6 7\n7 6 5 4 3 2 1 0", "0 1 2 3 4 5 6 7\n0 1 2 3 4 5 6 7\n7 6 5 4 3 2 1 0", "1 0 2 3 4 5 6 7\n1 0 2 3 4 5 6 7\n7 6 5 4 3 2 1 0" ], "output": [ "0\n1\n28", "1\n1\n28\n", "0\n0\n28\n", "1\...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: The 7 puzzle consists of 8 square cards and a frame that fits them snugly. Each card is numbered 0, 1, 2, ..., 7 to distinguish them from each other. You can arrange two cards vertica...
p00254 All Numbers Lead to 6174_11310
Do the following for a four-digit number N consisting of numbers 0-9. 1. Let L be the number obtained as a result of arranging the numerical values ​​of each of the N digits in descending order. 2. Let S be the number obtained as a result of arranging the numerical values ​​of each of the N digits in ascending order. ...
while True: number=int(input()) if number==0000: break trial=0 while True: if number==6174: print(trial) break box=[] for i in range(4): a=number%10 number=int(number/10) box.append(a) if box[0]==box[...
{ "input": [ "6174\n2012\n3333\n0000", "6174\n3985\n3333\n0000", "6174\n1779\n3333\n0000", "6174\n1779\n2211\n0000", "6174\n2012\n3078\n0000", "6174\n3985\n5889\n0000", "6174\n2012\n3639\n0000", "6174\n1794\n3333\n0000", "6174\n1779\n1275\n0000", "6174\n1289\n3078\n0000", "...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Do the following for a four-digit number N consisting of numbers 0-9. 1. Let L be the number obtained as a result of arranging the numerical values ​​of each of the N digits in desce...
p00440 Longest Steps_11314
problem There are n cards with one integer from 1 to n and one blank card. Of these n + 1 cards, k cards are given, but 1 ≤ k ≤ n. You can write one integer from 1 to n on a blank card. I want to make a continuous sequence of integers as long as possible with just a given card. Write a program that outputs the maximu...
anss = [] flag = False def main(): N, K = [int(i) for i in input().split()] if N == K == 0: global flag flag = True return A = [int(input()) for _ in range(K)] A.sort() zero = False if A[0] == 0: zero = True prev = -1 last_island = -1 current_streak = ...
{ "input": [ "7 5\n6\n2\n4\n7\n1\n7 5\n6\n2\n0\n4\n7\n0 0", "7 5\n6\n2\n4\n7\n1\n7 5\n5\n2\n0\n4\n7\n0 0", "7 5\n6\n2\n4\n7\n1\n7 5\n5\n2\n0\n1\n7\n0 0", "9 5\n6\n2\n4\n7\n1\n7 5\n5\n2\n1\n4\n7\n0 0", "14 5\n6\n0\n4\n7\n1\n7 5\n5\n2\n0\n4\n7\n0 0", "7 5\n6\n2\n3\n7\n1\n7 5\n6\n2\n0\n4\n7\n0 0"...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: problem There are n cards with one integer from 1 to n and one blank card. Of these n + 1 cards, k cards are given, but 1 ≤ k ≤ n. You can write one integer from 1 to n on a blank ca...
p00631 Split Up!_11318
Brave Ponta and his best friend, Brave Gonta, have come to Luida's bar in search of friends to embark on an epic adventure. There are many warriors, monks and wizards in the tavern who are itching to go on an adventure. Gonta, who is kind-hearted, cared for Ponta and said, "You can choose your friends first." On the ...
def main(): while True: n = int(input()) if n == 0: break alst = list(map(int, input().split())) s = sum(alst) alst = [a * 2 for a in alst] lst = [-s] for a in alst: lst.extend([i + a for i in lst]) print(min(map(abs, lst))) main()
{ "input": [ "5\n1 2 3 4 5\n4\n2 3 5 7\n0", "5\n1 2 3 4 5\n4\n2 3 5 10\n0", "5\n1 2 3 4 5\n4\n1 3 5 10\n0", "5\n1 2 3 4 5\n4\n1 3 4 10\n0", "5\n1 3 3 4 5\n4\n2 3 5 7\n0", "5\n1 2 3 4 4\n4\n1 3 4 10\n0", "5\n1 3 3 4 5\n4\n2 3 5 10\n0", "5\n1 2 3 4 5\n4\n0 3 5 11\n0", "5\n1 4 3 4 20\...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Brave Ponta and his best friend, Brave Gonta, have come to Luida's bar in search of friends to embark on an epic adventure. There are many warriors, monks and wizards in the tavern wh...
p00775 Vampire_11322
Vampire Mr. C is a vampire. If he is exposed to the sunlight directly, he turns into ash. Nevertheless, last night, he attended to the meeting of Immortal and Corpse Programmers Circle, and he has to go home in the near dawn. Fortunately, there are many tall buildings around Mr. C's home, and while the sunlight is blo...
while True: r, n = list(map(int, input().split())) if r==0: break b = [0 for i in range(60)] for i in range(n): ll, rr, x = list(map(int, input().split())) for j in range(ll, rr): b[30+j] = max(b[30+j], x) b[30-r-1], b[30+r] = 1e9, 1e9 ans = 1e9 for x in range(30-r, 30+r+1): t = (r...
{ "input": [ "2 3\n-2 -1 3\n0 1 3\n2 3 3\n2 2\n-2 0 4\n0 2 3\n2 6\n-3 3 1\n-2 3 2\n-1 3 3\n0 3 4\n1 3 5\n2 3 6\n2 6\n-3 3 1\n-3 2 2\n-3 1 3\n-3 0 4\n-3 -1 5\n-3 -2 6\n0 0", "2 3\n-3 -1 3\n0 1 3\n2 3 3\n2 2\n-2 0 4\n0 2 3\n2 6\n-3 3 1\n-2 3 2\n-1 3 3\n0 3 4\n1 3 5\n2 3 6\n2 6\n-3 3 1\n-3 2 2\n-3 1 3\n-3 0 4\n-...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Vampire Mr. C is a vampire. If he is exposed to the sunlight directly, he turns into ash. Nevertheless, last night, he attended to the meeting of Immortal and Corpse Programmers Circ...
p00906 One-Dimensional Cellular Automaton_11325
There is a one-dimensional cellular automaton consisting of N cells. Cells are numbered from 0 to N − 1. Each cell has a state represented as a non-negative integer less than M. The states of cells evolve through discrete time steps. We denote the state of the i-th cell at time t as S(i, t). The state at time t + 1 is...
from operator import mul def dot(v1, v2): return sum(map(mul, v1, v2)) def mat_mul(A, B, m): tB = tuple(zip(*B)) return [[dot(A_i, B_j) % m for B_j in tB] for A_i in A] def mat_pow(X, n, m): s = len(X) A = [[0] * s for i in range(s)] for i in range(s): A[i][i] = 1 while n > 0:...
{ "input": [ "5 4 1 3 2 0\n0 1 2 0 1\n5 7 1 3 2 1\n0 1 2 0 1\n5 13 1 3 2 11\n0 1 2 0 1\n5 5 2 0 1 100\n0 1 2 0 1\n6 6 0 2 3 1000\n0 1 2 0 1 4\n20 1000 0 2 3 1000000000\n0 1 2 0 1 0 1 2 0 1 0 1 2 0 1 0 1 2 0 1\n30 2 1 0 1 1000000000\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0\n30 2 1 1 1 100000000...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There is a one-dimensional cellular automaton consisting of N cells. Cells are numbered from 0 to N − 1. Each cell has a state represented as a non-negative integer less than M. The ...
p01040 Friday the 13th_11328
Problem "Ritsumeikan University Competitive Programming Camp" will be held this year as well. I am very much looking forward to this annual training camp. However, I couldn't stand my desires and splurged before the training camp, so I couldn't afford it. So I decided to use the cheapest Seishun 18 Ticket to get to Mi...
def check_uruu(y): if y % 400 == 0: return True elif y % 100 == 0: return False elif y % 4 == 0: return True else: return False nouruu = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] uruu = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31] Y1, M1, D1, Y2, M2, D2 = map(...
{ "input": [ "2015 3 13 2015 3 13", "2015 2 14 2015 3 15", "1234 5 6 789012345678901234 5 6", "2015 3 2 2015 3 13", "1045 2 14 2015 3 15", "1234 5 4 789012345678901234 5 6", "2015 3 3 2015 2 13", "2015 3 6 3448 2 13", "2015 2 6 3448 3 13", "2015 2 6 3516 3 13", "3203 2 2 35...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Problem "Ritsumeikan University Competitive Programming Camp" will be held this year as well. I am very much looking forward to this annual training camp. However, I couldn't stand m...