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
977_F. Consecutive Subsequence_25983
You are given an integer array of length n. You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to [x, x + 1, ..., x + k - 1] for some value x and length k. Subsequence ...
n=int(input()) l=list(map(int,input().split())) d={} dp=[0 for i in range(n)] ind=dp[:] dp[0]=1 d[l[0]]=0 for i in range(1,len(l)): if l[i]-1 in d: dp[i]=1+dp[d[l[i]-1]] ind[i]=d[l[i]-1] else: dp[i]=1 d[l[i]]=i print(max(dp)) i=dp.index(max(dp)) mx=max(dp) ans=[] while mx: ans.ap...
{ "input": [ "4\n10 9 8 7\n", "6\n1 3 5 2 4 6\n", "7\n3 3 4 7 5 6 8\n", "9\n6 7 8 3 4 5 9 10 11\n", "1\n1337\n", "2\n456 123\n", "7\n3 3 4 5 6 7 8\n", "12\n1 2 3 4 5 6 7 8 9 10 11 12\n", "7\n100 3 4 7 5 6 8\n", "1\n2487\n", "7\n3 3 4 0 6 7 8\n", "12\n1 2 3 4 5 6 7 0 9 1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given an integer array of length n. You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive ...
p02785 AtCoder Beginner Contest 153 - Fennec vs Monster_26000
Fennec is fighting with N monsters. The health of the i-th monster is H_i. Fennec can do the following two actions: * Attack: Fennec chooses one monster. That monster's health will decrease by 1. * Special Move: Fennec chooses one monster. That monster's health will become 0. There is no way other than Attack and...
R = lambda: map(int, input().split()) n, k = R() print(sum(sorted(R())[:n - k]) if k < n else 0)
{ "input": [ "3 0\n1000000000 1000000000 1000000000", "8 9\n7 9 3 2 3 8 4 6", "3 1\n4 1 5", "3 0\n1000000000 1000000000 1010000000", "8 8\n7 9 3 2 3 8 4 6", "3 1\n0 1 5", "3 0\n1000000000 1000000000 1110000000", "3 0\n1100000000 1000000000 1110000000", "3 0\n1100000000 1000000001 1...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Fennec is fighting with N monsters. The health of the i-th monster is H_i. Fennec can do the following two actions: * Attack: Fennec chooses one monster. That monster's health will...
p02921 AtCoder Beginner Contest 139 - Tenki_26004
You will be given a string S of length 3 representing the weather forecast for three days in the past. The i-th character (1 \leq i \leq 3) of S represents the forecast for the i-th day. `S`, `C`, and `R` stand for sunny, cloudy, and rainy, respectively. You will also be given a string T of length 3 representing the ...
S = input() T = input() print(sum([1 for s,t in zip(S,T) if s == t]))
{ "input": [ "CSS\nCSR", "RRR\nSSS", "SSR\nSSR", "CSS\nBSR", "SRR\nSSR", "SSR\nRTS", "STR\nSTR", "RSR\nSSS", "SSC\nBSR", "RSR\nSSR", "SSR\nRSS", "SSC\nRSB", "RTR\nSSR", "CSS\nRSB", "RTR\nSTR", "SSR\nRTR", "CSR\nRSB", "SRS\nRTR", "CSR\nBSR", ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You will be given a string S of length 3 representing the weather forecast for three days in the past. The i-th character (1 \leq i \leq 3) of S represents the forecast for the i-th ...
p03056 AtCoder Grand Contest 033 - Complexity_26007
Note the unusual memory limit. For a rectangular grid where each square is painted white or black, we define its complexity as follows: * If all the squares are black or all the squares are white, the complexity is 0. * Otherwise, divide the grid into two subgrids by a line parallel to one of the sides of the grid, a...
H, W = map(int, input().split()) A = [[1 if a == "#" else 0 for a in input()] for _ in range(H)] X = [[[-2] * (H + 2) for _ in range(W + 2)] for _ in range(H + 2)] Y = [[[-2] * (W + 2) for _ in range(W + 2)] for _ in range(H + 2)] for i in range(H): Xi = X[i] Yi = Y[i] for j in range(W): Xi[j][i] =...
{ "input": [ "3 3\n...\n.##\n.##", "6 7\n.####.#\n....#.\n....#.\n....#.\n.####.#\n....##", "5 7\n.####.#\n....#.\n....#.\n....#.\n.####.#\n....##", "5 7\n.####.$\n....#.\n.#....\n....#.\n.####.#\n....\"#", "2 3\n...\n.##\n.##", "2 1\n...\n.##\n.##", "2 7\n####..$\n....#.\n.#....\n....#.\n...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Note the unusual memory limit. For a rectangular grid where each square is painted white or black, we define its complexity as follows: * If all the squares are black or all the squ...
p03200 AtCoder Grand Contest 029 - Irreversible operation_26011
There are N Reversi pieces arranged in a row. (A Reversi piece is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=`B`, the i-th piece from the left is showing black; If S_i=`W`, the i-th piece from the left is showing white. Consider performing the f...
s = input() num = 0 st = 0 for i,x in enumerate(s): if x=='W': num += (i-st) st += 1 print(num)
{ "input": [ "BWBWBW", "BBW", "WBWBWB", "BBX", "WBWBVB", "BXB", "WBWBUB", "BYB", "WBWBUC", "CYB", "WBWBTC", "CYA", "WBWBVC", "CAY", "WBVBVC", "CAX", "AYC", "BYA", "XBB", "XCB", "XDB", "XEB", "YDB", "DYB", "BYD", "B...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are N Reversi pieces arranged in a row. (A Reversi piece is a disc with a black side and a white side.) The state of each piece is represented by a string S of length N. If S_i=...
p03347 AtCoder Grand Contest 024 - Sequence Growing Easy_26015
There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X. You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required. * Choose...
N = int(input()) A = [0] + [int(input()) for i in range(N)] if A[1] != 0: print(-1) quit() ans = 0 for i, a in enumerate(A[1:], 1): pre_a = A[i-1] if a - pre_a >= 2: print(-1) quit() elif a > pre_a: ans += 1 else: ans += a print(ans)
{ "input": [ "3\n1\n2\n1", "9\n0\n1\n1\n0\n1\n2\n2\n1\n2", "4\n0\n1\n1\n2", "3\n0\n2\n1", "4\n0\n0\n1\n2", "3\n0\n1\n0", "3\n0\n0\n0", "9\n0\n1\n1\n0\n2\n2\n2\n1\n2", "3\n0\n2\n2", "9\n0\n1\n1\n0\n2\n2\n2\n1\n4", "4\n0\n0\n0\n2", "3\n0\n1\n2", "9\n0\n1\n1\n0\n2\n2\n...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X. You are given a sequence A of length N. The i-th element of A is A_i. Det...
p03507 Code Festival Team Relay (Parallel) - Garden_26019
In your garden, there is a long and narrow flowerbed that stretches infinitely to the east. You have decided to plant N kinds of flowers in this empty flowerbed. For convenience, we will call these N kinds of flowers Flower 1, 2, …, N. Also, we will call the position that is p centimeters from the west end of the flowe...
def main(): import sys input = sys.stdin.buffer.readline N, K = (int(i) for i in input().split()) WD = [[int(i) for i in input().split()] for j in range(N)] ma_w = 0 ma_d = 0 for w, d in WD: if ma_w < w: ma_w = w if ma_d < d: ma_d = d def is_ok(X)...
{ "input": [ "1 1000000000\n1000000000000000000 1000000000", "2 6\n20 10\n25 15", "3 9\n10 10\n10 10\n10 10", "2 5\n20 10\n25 15", "3 9\n16 10\n10 10\n10 10", "2 5\n20 16\n25 15", "2 5\n20 13\n25 15", "2 6\n20 10\n43 15", "3 9\n10 10\n7 10\n10 10", "3 9\n10 10\n7 10\n10 18", ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: In your garden, there is a long and narrow flowerbed that stretches infinitely to the east. You have decided to plant N kinds of flowers in this empty flowerbed. For convenience, we w...
p03668 AtCoder Grand Contest 017 - Game on Tree_26023
There is a tree with N vertices numbered 1, 2, ..., N. The edges of the tree are denoted by (x_i, y_i). On this tree, Alice and Bob play a game against each other. Starting from Alice, they alternately perform the following operation: * Select an existing edge and remove it from the tree, disconnecting it into two se...
import sys sys.setrecursionlimit(10 ** 7) n = int(input()) edges = [[] for i in range(n)] for i in range(n - 1): x, y = map(int, input().split()) edges[x - 1].append(y - 1) edges[y - 1].append(x - 1) def grundy_dfs(cur, prev): res = 0 for next_ in edges[cur]: if next_ == prev: co...
{ "input": [ "5\n1 2\n2 3\n2 4\n4 5", "5\n1 2\n2 3\n1 4\n4 5", "7\n1 2\n3 7\n4 6\n2 3\n2 4\n1 5", "6\n1 2\n2 4\n5 1\n6 3\n3 2", "5\n1 2\n1 3\n2 4\n4 5", "5\n1 2\n2 3\n1 5\n4 5", "5\n1 2\n1 3\n2 4\n4 0", "6\n2 2\n2 4\n5 1\n6 3\n3 2", "6\n2 2\n2 4\n5 1\n6 4\n3 2", "6\n2 2\n2 2\n5...
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, 2, ..., N. The edges of the tree are denoted by (x_i, y_i). On this tree, Alice and Bob play a game against each other. Starting from Alic...
p03823 AtCoder Grand Contest 009 - Division into Two_26026
There is a set consisting of N distinct integers. The i-th smallest element in this set is S_i. We want to divide this set into two sets, X and Y, such that: * The absolute difference of any two distinct elements in X is A or greater. * The absolute difference of any two distinct elements in Y is B or greater. How ...
import sys input = sys.stdin.readline from bisect import bisect_left, bisect_right INF = 10**18 + 100 N,A,B = map(int,input().split()) S = [-INF] + [int(x) for x in sys.stdin.read().split()] MOD = 10**9 + 7 dpX = [0] * (N+1) # 最後にYを選んだとして、直前に選んだXがどこにあるか dpY = [0] * (N+1) # 最後にXを選んだとして、直前に選んだYがどこにあるか dpX[0] = 1 dpY[...
{ "input": [ "5 3 7\n1\n3\n6\n9\n12", "3 3 4\n5\n6\n7", "8 2 9\n3\n4\n5\n13\n15\n22\n26\n32", "7 5 3\n0\n2\n4\n7\n8\n11\n15", "3 3 4\n9\n6\n7", "8 2 9\n3\n4\n5\n7\n15\n22\n26\n32", "3 3 4\n0\n6\n7", "8 2 9\n3\n0\n5\n7\n15\n22\n26\n32", "5 3 2\n1\n3\n6\n9\n12", "8 2 9\n3\n4\n5\n...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There is a set consisting of N distinct integers. The i-th smallest element in this set is S_i. We want to divide this set into two sets, X and Y, such that: * The absolute differenc...
p03990 AtCoder Grand Contest 005 - Sugigma: The Showdown_26029
Sigma and Sugim are playing a game. The game is played on a graph with N vertices numbered 1 through N. The graph has N-1 red edges and N-1 blue edges, and the N-1 edges in each color forms a tree. The red edges are represented by pairs of integers (a_i, b_i), and the blue edges are represented by pairs of integers (c...
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 # 998244353 input=lambda:sys.stdin.readline().rstrip() def resolve(): n,x,y=map(int,input().split()) x-=1; y-=1 E1=[[] for _ in range(n)] E2=[[] for _ in range(n)] for _ in range(n-1): u,v=map(int,input().split()) ...
{ "input": [ "4 1 2\n1 2\n3 4\n2 4\n1 2\n3 4\n1 3", "5 1 2\n1 2\n1 3\n1 4\n4 5\n2 1\n1 3\n1 5\n5 4", "3 3 1\n1 2\n2 3\n1 2\n2 3", "4 1 2\n1 2\n1 3\n1 4\n2 1\n2 3\n1 4", "4 2 1\n1 2\n3 4\n2 4\n1 2\n3 4\n1 3", "4 1 2\n1 4\n3 4\n2 4\n1 2\n3 4\n1 3", "4 2 1\n1 4\n3 4\n4 4\n1 2\n3 4\n1 3", ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Sigma and Sugim are playing a game. The game is played on a graph with N vertices numbered 1 through N. The graph has N-1 red edges and N-1 blue edges, and the N-1 edges in each colo...
p00078 Magic Square_26033
The numbers 1 to n x n are contained in the n x n square squares one by one, and the sum of the squares in any vertical column and the sum of the squares in any horizontal column are diagonal squares. Those with the same sum of eyes are called magic squares. There are the following methods to create a magic square wit...
while 1: n = int(input()) if n == 0: break l = [[ 0 for i in range(n)] for j in range(n)] i = n//2 + 1 j = n//2 l[i][j] = ' 1' c = 2 d = '{: >4}'.format(c) for x in range(n**2 - 1): i = (i + 1) % n j = (j + 1) % n while l[i][j] != 0: i...
{ "input": [ "3\n5\n0", "3\n0\n0", "3\n7\n0", "3\n3\n0", "3\n11\n0", "3\n9\n0", "3\n15\n0", "3\n19\n0", "3\n17\n0", "3\n27\n0", "3\n13\n0", "3\n23\n0", "3\n29\n0", "3\n0\n-1", "3\n0\n-2", "3\n0\n-3", "3\n0\n1", "3\n0\n-5", "3\n0\n2", "3\n...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: The numbers 1 to n x n are contained in the n x n square squares one by one, and the sum of the squares in any vertical column and the sum of the squares in any horizontal column are ...
p00210 The Squares_26037
The huge maze The Squares has been newly completed in the famous theme park. Evacuation drills must be conducted under the guidance of the fire department, but the time required for the drills cannot be predicted due to the huge maze. Therefore, you decided to develop an evacuation drill simulator based on the followin...
from sys import stdin # from line_profiler import LineProfiler def main(): head = [[8,1,2,4],[1,2,4,8],[2,4,8,1],[4,8,1,2]] while(True): W,H = map(int, stdin.readline().split()) m = [[0]*W for _ in range(H)] ps = [] if not (W or H): break for h in range(H): ...
{ "input": [ "10 3\n##########\n#E.......X\n##########\n4 4\n####\n#N.#\n#..X\n####\n5 5\n#####\n#N..#\n###.X\n#S..#\n#####\n6 6\n######\n#..#X#\n#.EE.#\n####N#\n#....#\n######\n8 8\n##X#####\n#....E.#\n#####.##\n#.#...##\n#.W.#..#\n#.#.N#.X\n#X##.#.#\n########\n0 0", "10 3\n\nE.......X\n\n4 4\n\nN.#\n..X\n\n...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: The huge maze The Squares has been newly completed in the famous theme park. Evacuation drills must be conducted under the guidance of the fire department, but the time required for t...
p00587 Binary Tree Intersection And Union_26042
Given two binary trees, we consider the “intersection” and “union” of them. Here, we distinguish the left and right child of a node when it has only one child. The definitions of them are very simple. First of all, draw a complete binary tree (a tree whose nodes have either 0 or 2 children and leaves have the same dept...
import re class bintree(): def __init__(self, str1): self.str1 = str1 if self.str1[1] != ",": c = 0 counter = 0 for s in str1[1:]: counter += 1 if s == "(": c += 1 elif s == ")": ...
{ "input": [ "i ((,),(,)) ((,(,)),)\nu ((,),(,)) ((,(,)),)" ], "output": [ "((,),)\n((,(,)),(,))" ] }
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Given two binary trees, we consider the “intersection” and “union” of them. Here, we distinguish the left and right child of a node when it has only one child. The definitions of them...
p00864 Grey Area_26048
Dr. Grey is a data analyst, who visualizes various aspects of data received from all over the world everyday. He is extremely good at sophisticated visualization tools, but yet his favorite is a simple self-made histogram generator. Figure 1 is an example of histogram automatically produced by his histogram. <image> ...
# coding: utf-8 while 1: n,w=map(int,input().split()) if n==0: break dic={} mx=-1 max_section=-1 for i in range(1+100//w): dic[i]=0 for i in range(n): x=int(input()) dic[x//w]+=1 mx=max(mx,dic[x//w]) max_section=max(max_section,x//w) ans=0 ...
{ "input": [ "3 50\n100\n0\n100\n3 50\n100\n100\n50\n10 10\n1\n2\n3\n4\n5\n16\n17\n18\n29\n30\n0 0", "3 50\n100\n0\n100\n3 50\n100\n100\n50\n10 10\n1\n2\n3\n4\n5\n16\n17\n18\n29\n53\n0 0", "3 50\n100\n0\n100\n3 50\n100\n100\n50\n10 10\n1\n2\n3\n8\n5\n16\n17\n18\n29\n65\n0 0", "3 50\n100\n0\n100\n3 50\...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Dr. Grey is a data analyst, who visualizes various aspects of data received from all over the world everyday. He is extremely good at sophisticated visualization tools, but yet his fa...
p01127 X-Ray Screening System_26053
This is the story of 20XX. The number of air passengers increased as a result of the stable energy supply by the renewable power network and the invention of liquefied synthetic fuel. However, the threat of terrorism by aircraft still exists, and the importance of fast and highly reliable automatic baggage inspection s...
n = int(input()) for _ in range(n): h, w = map(int, input().split()) mp = [list(input()) for _ in range(h)] range_dic = {} keys = [] for y in range(h): for x in range(w): c = mp[y][x] if c in range_dic: x1, x2, y1, y2 = range_dic[c] range_dic[c] = (min(x, x1), max(x, x2), min(y...
{ "input": [ "6\n1 1\n.\n3 3\n...\n.W.\n...\n10 10\n..........\n.DDDDCCC..\n.DDDDCCC..\n.DDDDCCC..\nADDDDCCC..\nAAA..CCC..\nAAABBBBC..\nAAABBBB...\n..BBBBB...\n..........\n10 10\n..........\n.DDDDDD...\n.DDDDCCC..\n.DDDDCCC..\nADDDDCCC..\nAAA..CCC..\nAAABBBBC..\nAAABBBB...\n..BBBBB...\n..........\n10 10\nR..E..C....
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: This is the story of 20XX. The number of air passengers increased as a result of the stable energy supply by the renewable power network and the invention of liquefied synthetic fuel....
p01426 Vector Compression_26057
You are recording a result of a secret experiment, which consists of a large set of N-dimensional vectors. Since the result may become very large, you are thinking of compressing it. Fortunately you already have a good compression method for vectors with small absolute values, all you have to do is to preprocess the ve...
import sys readline = sys.stdin.readline write = sys.stdout.write def calc(V, es, r): mins = [(10**18, -1)]*V for s, t, w in es: mins[t] = min(mins[t], (w, s)) mins[r] = (-1, -1) group = [0]*V comp = [0]*V cnt = 0 used = [0]*V for v in range(V): if not used[v]: ...
{ "input": [ "2 3\n1.0 1.0\n-1.0 0.0\n0.5 0.5", "4 3\n1.0 1.0 0.0 0.0\n-1.0 0.0 -1.0 0.0\n0.5 0.5 0.5 0.5", "1 1\n1.0", "2 3\n1.2834290847607077 1.0\n-1.0 0.0\n0.5 0.5", "4 3\n1.0 1.0 0.0 0.40562788475787737\n-1.0 0.0 -1.0 0.0\n0.5 0.5 0.5 0.5", "2 1\n1.0", "2 3\n1.2834290847607077 1.0\n-1...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are recording a result of a secret experiment, which consists of a large set of N-dimensional vectors. Since the result may become very large, you are thinking of compressing it. ...
p01742 Dictionary_26060
Sunuke-kun's dictionary contains the words s1, ..., sn, which consist of n lowercase letters. This satisfies s1 <... <sn when compared in lexicographical order. Unfortunately, some characters are faint and unreadable. Unreadable characters are represented by?. Find out how many ways to restore the dictionary by replaci...
# seishin.py import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): MOD = 10**9 + 7 N = int(readline()) M = 20 L = 26 ca = ord('a') cq = ord('?') S = [[ca-1]*M for i in range(N)] for i in range(N): s = readline().strip() S[i][:len(s)] = map(ord, s...
{ "input": [ "2\n?sum??mer\nc??a??mp", "3\nsnuje\n????e\nsnule", "2\n?rum??mer\nc??a??mp", "3\nsnuje\n????e\neluns", "2\n?rum??mer\nc@?a??mp", "3\nsunje\n????e\neluns", "2\n?rum??mer\ncA?a??mp", "3\nsunje\n@???e\neluns", "2\nrem??mur?\ncA?a??mp", "3\nsunje\n@???e\nsnule", "...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Sunuke-kun's dictionary contains the words s1, ..., sn, which consist of n lowercase letters. This satisfies s1 <... <sn when compared in lexicographical order. Unfortunately, some ch...
p01882 We don't wanna work!_26063
Example Input 4 Durett 7 Gayles 3 Facenda 6 Daughtery 0 1 + Mccourtney 2 Output Mccourtney is not working now. Durett is working hard now.
from heapq import heappush, heappop, heapify import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): N = int(readline()) P = []; Q = [] E = []; R = {} L = N + 20000 for i in range(N): s, a = readline().split(); a = int(a) * L + i E.append(s) Q.append((...
{ "input": [ "4\nDurett 7\nGayles 3\nFacenda 6\nDaughtery 0\n1\n+ Mccourtney 2", "4\nDurett 7\nGayles 3\nFacenda 6\nyrethguaD 0\n1\n+ Mccourtney 2", "4\nDurett 7\nGayles 3\nFacenda 10\nyrethguaD 0\n1\n+ Mccourtney 2", "4\nDurett 10\nGayles 4\nF`cenda 10\nyrethguaD 0\n1\n+ Mccourtney 1", "4\nDurett...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Example Input 4 Durett 7 Gayles 3 Facenda 6 Daughtery 0 1 + Mccourtney 2 Output Mccourtney is not working now. Durett is working hard now. ### Input: 4 Durett 7 Gayles 3 Facenda...
p02019 Training_26065
E-training Nene is writing a program to look up $ N $ integers $ V_1, V_2, V_3, \ cdots, V_N $ for programming training. As told by his instructor, Umiko, Nene wrote a program to look up multiples of 2, 3, and 6. Multiples of 2 were $ A $, multiples of 3 were $ B $, and multiples of 6 were $ C $. Umiko told me to l...
n,a,b,c = map(int,input().split()) print(n - (a+b-c))
{ "input": [ "6 3 2 1", "6 5 2 1", "9 5 2 1", "12 5 2 1", "0 5 2 1", "-1 5 2 1", "-1 0 2 0", "-1 0 1 0", "-2 0 2 0", "-2 0 8 0", "0 -2 2 -1", "0 -2 1 0", "2 -1 0 -1", "2 -1 -1 0", "2 -2 -1 0", "2 -2 -2 1", "3 -2 -2 1", "4 -2 -2 1", "8 -1 -2 -...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: E-training Nene is writing a program to look up $ N $ integers $ V_1, V_2, V_3, \ cdots, V_N $ for programming training. As told by his instructor, Umiko, Nene wrote a program to lo...
p02302 Convex Cut_26070
<image> As shown in the figure above, cut a convex polygon g by a line p1p2 and print the area of the cut polygon which is on the left-hand side of the line. g is represented by a sequence of points p1, p2,..., pn where line segments connecting pi and pi+1 (1 ≤ i ≤ n−1) are sides of the convex polygon. The line segm...
def cross(a: complex, b: complex) -> float: return a.real * b.imag - a.imag * b.real def cross_point(c: complex, d: complex) -> complex: global lt, lv vec = d - c v1 = cross(lv, vec) v2 = cross(lv, lt - c) return c + v2 / v1 * vec if __name__ == "__main__": n = int(input()) points = ...
{ "input": [ "4\n1 1\n4 1\n4 3\n1 3\n2\n2 0 2 4\n2 4 2 0", "4\n1 1\n4 1\n4 3\n1 3\n2\n2 0 2 5\n2 4 2 0", "4\n1 1\n4 1\n4 3\n0 3\n2\n2 0 2 5\n2 4 2 0", "4\n1 1\n4 2\n4 3\n0 3\n2\n2 0 2 5\n2 4 2 0", "4\n1 1\n4 2\n4 3\n0 3\n2\n2 0 2 5\n0 4 2 0", "4\n1 1\n4 2\n4 3\n0 3\n2\n2 0 2 0\n0 4 2 0", "...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: <image> As shown in the figure above, cut a convex polygon g by a line p1p2 and print the area of the cut polygon which is on the left-hand side of the line. g is represented by a ...
p02449 Permutation_26073
For given a sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$, print the previous permutation and the next permutation in lexicographic order. Constraints * $1 \leq n \leq 9$ * $a_i$ consist of $1, 2, ..., n$ Input A sequence is given in the following format. $n$ $a_0 \; a_1 \; ... \; a_{n-1}$ Output Print the previ...
import operator def permutations(li): """Returns a list of previous, current, and next permutations of li. >>> permutations([1, 2]) [[1, 2], [2, 1]] >>> permutations([1, 3, 2]) [[1, 2, 3], [1, 3, 2], [2, 1, 3]] """ def perm(op): def func(xs): i = len(xs) - 1 ...
{ "input": [ "3\n3 2 1", "3\n2 1 3", "3\n3 3 1", "3\n3 1 3", "3\n3 3 2", "3\n6 1 3", "3\n3 5 2", "3\n11 1 3", "3\n0 5 2", "3\n11 1 4", "3\n0 10 2", "3\n6 1 4", "3\n0 10 1", "3\n6 1 6", "3\n0 13 1", "3\n6 0 6", "3\n0 13 2", "3\n6 0 4", "3\n0 6...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: For given a sequence $A = \\{a_0, a_1, ..., a_{n-1}\\}$, print the previous permutation and the next permutation in lexicographic order. Constraints * $1 \leq n \leq 9$ * $a_i$ cons...
1015_E2. Stars Drawing (Hard Edition)_26083
A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be a positive number (i.e. rays of length 0 are not allowed). Let's consider...
# ---------------------------iye ha aam zindegi--------------------------------------------- import math import heapq, bisect import sys from collections import deque, defaultdict from fractions import Fraction import sys mod = 10 ** 9 + 7 mod1 = 998244353 #sys.setrecursionlimit(300000) # ------------------------------...
{ "input": [ "5 5\n.*...\n****.\n.****\n..**.\n.....\n", "6 8\n....*...\n...**...\n..*****.\n...**...\n....*...\n........\n", "3 3\n*.*\n.*.\n*.*\n", "5 5\n.*...\n***..\n.*...\n.*...\n.....\n", "3 3\n.*.\n***\n**.\n", "3 3\n**.\n***\n.*.\n", "3 3\n.*.\n***\n.*.\n", "3 3\n...\n...\n...\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size o...
1103_A. Grid game_26093
You are given a 4x4 grid. You play a game — there is a sequence of tiles, each of them is either 2x1 or 1x2. Your task is to consequently place all tiles from the given sequence in the grid. When tile is placed, each cell which is located in fully occupied row or column is deleted (cells are deleted at the same time in...
b= [['3 4','1 4'],['1 1','1 3']];o = [0,0] for i in map(int,input()):print(b[i][o[i]%2]);o[i] +=1
{ "input": [ "010\n", "010\n", "1\n", "011110\n", "0\n", "01\n", "000\n", "011100\n", "011\n", "100\n", "011101\n", "111\n", "101\n", "001101\n", "110\n", "001\n", "001111\n", "101111\n", "101101\n", "111101\n", "111100\n", "11100...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given a 4x4 grid. You play a game — there is a sequence of tiles, each of them is either 2x1 or 1x2. Your task is to consequently place all tiles from the given sequence in th...
1131_A. Sea Battle_26097
In order to make the "Sea Battle" game more interesting, Boris decided to add a new ship type to it. The ship consists of two rectangles. The first rectangle has a width of w_1 and a height of h_1, while the second rectangle has a width of w_2 and a height of h_2, where w_1 ≥ w_2. In this game, exactly one ship is used...
w1, h1, w2, h2 = map(int, input().split()) if w2 > w1: res = w1 + 1 + h1 + h2 + 1 + w2 + 1 + h2 + (w1 - w2) + h1 + 1 else: res = (w1 + h1 + h2) * 2 + 4 print(res)
{ "input": [ "2 1 2 1\n", "2 2 1 2\n", "1 1 1 1\n", "24 25 16 38\n", "1000000 1000000 1000000 1000000\n", "100000000 100000000 99999999 100000000\n", "1000000 1000000 999999 1000000\n", "23 1 12 2\n", "1000000 1 1000000 1\n", "100000000 1 100000000 1\n", "18 3 8 15\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: In order to make the "Sea Battle" game more interesting, Boris decided to add a new ship type to it. The ship consists of two rectangles. The first rectangle has a width of w_1 and a ...
1151_C. Problem for Nazar_26101
Nazar, a student of the scientific lyceum of the Kingdom of Kremland, is known for his outstanding mathematical abilities. Today a math teacher gave him a very difficult task. Consider two infinite sets of numbers. The first set consists of odd positive numbers (1, 3, 5, 7, …), and the second set consists of even posi...
import math def Solve(x): if x == 0: return 0 stage = int(math.floor(math.log(x,2))) odd = math.ceil(stage/2) even = math.floor(stage/2) even_terms = 2*(pow(4,even)-1)//3 odd_terms = (pow(4,odd)-1)//3 total = even_terms+odd_terms if (stage+1)%2 == 0: even_terms += x...
{ "input": [ "5 14\n", "1 3\n", "88005553535 99999999999\n", "101 102\n", "707992299833239702 823650821768525121\n", "181925 50919323688216219\n", "31 32\n", "4 938109031727472839\n", "10 10005\n", "83 402908796418729484\n", "527941 442152825894997769\n", "1008798900629...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Nazar, a student of the scientific lyceum of the Kingdom of Kremland, is known for his outstanding mathematical abilities. Today a math teacher gave him a very difficult task. Consid...
1173_B. Nauuo and Chess_26105
Nauuo is a girl who loves playing chess. One day she invented a game by herself which needs n chess pieces to play on a m× m chessboard. The rows and columns are numbered from 1 to m. We denote a cell on the intersection of the r-th row and c-th column as (r,c). The game's goal is to place n chess pieces numbered fro...
import sys import math from functools import reduce n = int(input()) m = 1 while True: if m * 2 <= n: m += 1 else: break print(m) for x in range(m): print(1, x+1) t = n - m for _ in range(n - m): print(m, m - t + 1) t -= 1
{ "input": [ "2\n", "4\n", "706\n", "6\n", "33\n", "90\n", "7\n", "365\n", "1000\n", "758\n", "667\n", "695\n", "10\n", "508\n", "255\n", "979\n", "298\n", "99\n", "233\n", "850\n", "666\n", "734\n", "643\n", "826\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Nauuo is a girl who loves playing chess. One day she invented a game by herself which needs n chess pieces to play on a m× m chessboard. The rows and columns are numbered from 1 to m...
122_B. Lucky Substring_26111
Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya was delivered a string s, containing only digits. He needs to find a string that * ...
s=input() s=s.strip('0') four=s.count('4') seven=s.count('7') if '4' not in s and '7' not in s: print(-1) else: if four>=seven: print('4') else: print('7')
{ "input": [ "472747\n", "16\n", "047\n", "94894948577777777884888\n", "74\n", "94872076199824813574576121510803\n", "1925\n", "9589\n", "07\n", "6363333480463521971676988087733137609715\n", "44\n", "637789221789855555993957058\n", "747474747474747474747474747474747...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, ...
1251_A. Broken Keyboard_26115
Recently Polycarp noticed that some of the buttons of his keyboard are malfunctioning. For simplicity, we assume that Polycarp's keyboard contains 26 buttons (one for each letter of the Latin alphabet). Each button is either working fine or malfunctioning. To check which buttons need replacement, Polycarp pressed som...
''' @judge CodeForces @id 1251A @name Broken Keyboard @tag Simulation ''' from sys import stdin from itertools import groupby def solve(s): return ''.join(sorted(set(map(lambda p: str(p[0]), filter(lambda p: len(list(p[1])) & 1, groupby(s)))))) input() for line in stdin: print(solve(line.strip()))
{ "input": [ "4\na\nzzaaz\nccff\ncbddbb\n", "1\naababbaaamr\n", "1\naabambaaamr\n", "1\ndeep\n", "1\namrb\n", "1\namraa\n", "1\nsrijande\n", "1\nqw\n", "1\namra\n", "1\namrdd\n", "1\nartijakls\n", "1\namr\n", "1\nammr\n", "1\nlksjnksjfksjfksjfksjnfksjfsksjdf\n",...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Recently Polycarp noticed that some of the buttons of his keyboard are malfunctioning. For simplicity, we assume that Polycarp's keyboard contains 26 buttons (one for each letter of t...
1313_E. Concatenation with intersection_26121
Vasya had three strings a, b and s, which consist of lowercase English letters. The lengths of strings a and b are equal to n, the length of the string s is equal to m. Vasya decided to choose a substring of the string a, then choose a substring of the string b and concatenate them. Formally, he chooses a segment [l_...
import sys, logging logging.basicConfig(level=logging.INFO) logging.disable(logging.INFO) def build(S, n): Z = [0 for i in range(3 * n + 3)] #logging.info(S) n = len(S) L = 0 R = 0 Z[0] = n for i in range(1, n): if(i > R): L = R = i while(R < n and S[R] == S[...
{ "input": [ "5 4\nazaza\nzazaz\nazaz\n", "6 5\naabbaa\nbaaaab\naaaaa\n", "9 12\nabcabcabc\nxyzxyzxyz\nabcabcayzxyz\n", "50 100\nejdbvpkfoymumiujhtplntndyfkkujqvkgipbrbycmwzawcely\nyomcgzecbzkvaeziqmbkoknfavurydjupmsfnsthvdgookxfdx\nejdbvpkfoymumiujhtplntndyfkkujqvkgipbrbycmwzawcelyyomcgzecbzkvaeziqmb...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Vasya had three strings a, b and s, which consist of lowercase English letters. The lengths of strings a and b are equal to n, the length of the string s is equal to m. Vasya decide...
1336_C. Kaavi and Magic Spell_26125
Kaavi, the mysterious fortune teller, deeply believes that one's fate is inevitable and unavoidable. Of course, she makes her living by predicting others' future. While doing divination, Kaavi believes that magic spells can provide great power for her to see the future. <image> Kaavi has a string T of length m and a...
mod = 998244353 eps = 10**-9 def main(): import sys input = sys.stdin.readline S = input().rstrip('\n') S = S[::-1] T = input().rstrip('\n') NS = len(S) NT = len(T) dp = [[0] * (NT+1) for _ in range(NS+1)] dp[0][0] = 1 for i in range(NS): s = S[i] for j in ran...
{ "input": [ "defineintlonglong\nsignedmain\n", "rotator\nrotator\n", "cacdcdbbbb\nbdcaccdbbb\n", "abab\nba\n", "eternalalexandersookeustzeouuanisafqaqautomaton\nnoiol\n", "acacdddadaddcbbbbdacb\nbabbbcadddacacdaddbdc\n", "yz\nzy\n", "tqlrrtidhfpgevosrsya\nysrsvgphitrrqtldfeoa\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Kaavi, the mysterious fortune teller, deeply believes that one's fate is inevitable and unavoidable. Of course, she makes her living by predicting others' future. While doing divinati...
1358_F. Tasty Cookie_26128
Oh, no! The coronavirus has caught you, and now you're sitting in a dark cellar, with tied legs (but not hands). You have a delicious cookie, a laptop in front of you, and your ideal development environment is open. The coronavirus convinces you to solve the following problem. You are given two arrays A and B of size...
import sys int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def SI(): return sy...
{ "input": [ "2\n5 7\n5 7\n", "3\n1 2 1\n2 1 2\n", "2\n10 1\n13 14\n", "2\n1 1\n300000 1\n", "3\n682 411 6652\n993380064727 76407967827 3056063792\n", "2\n2 1\n768816015401 236766656640\n", "3\n1 2 1\n994501956360 1410320 1\n", "2\n1 1\n1 200001\n", "8\n16 41 26 27 10 23 12 50\n675...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Oh, no! The coronavirus has caught you, and now you're sitting in a dark cellar, with tied legs (but not hands). You have a delicious cookie, a laptop in front of you, and your ideal...
1379_B. Dubious Cyrpto_26132
Pasha loves to send strictly positive integers to his friends. Pasha cares about security, therefore when he wants to send an integer n, he encrypts it in the following way: he picks three integers a, b and c such that l ≤ a,b,c ≤ r, and then he computes the encrypted value m = n ⋅ a + b - c. Unfortunately, an adversa...
#!/usr/local/bin/python3 """ Given l, r, m, you know that m = n*a + b - c for some l <= a,b,c <= r, and n is an integer. Can you find a,b,c? (any value is fine) Examples l,r,m = 10,20,90 Choose 10 <= a,b,c <= 20 s.t. 90 = n*a + b - c a=10,b=10,c=10,n=9 l,r,m = 8,9,95 Choose 8 <= a,b,c <= 9 try a=...
{ "input": [ "2\n4 6 13\n2 3 1\n", "20\n10 12 43\n25 49 1\n5 7 39\n8 9 44\n16 17 50\n30 40 975\n601 801 1000\n100 102 909\n599 799 1000\n503 997 9\n194 383 5\n90000 100000 709999\n75000 100000 124999\n375000 499999 625001\n375000 500000 624999\n300000 400000 499999\n250000 500000 1\n70000 80000 2272770257\n70...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Pasha loves to send strictly positive integers to his friends. Pasha cares about security, therefore when he wants to send an integer n, he encrypts it in the following way: he picks ...
1399_F. Yet Another Segments Subset_26136
You are given n segments on a coordinate axis OX. The i-th segment has borders [l_i; r_i]. All points x, for which l_i ≤ x ≤ r_i holds, belong to the i-th segment. Your task is to choose the maximum by size (the number of segments) subset of the given set of segments such that each pair of segments in this subset eith...
def f(sl): sl.sort(key=lambda s:(s[1],-s[0])) tl = sorted(list(set([s[0] for s in sl] + [s[1] for s in sl]))) cd = {tl[i]:i for i in range(len(tl))} csl = [[] for i in range(len(tl))] for s0,s1 in sl: csl[cd[s1]].append(cd[s0]) # start dp! n = len(tl) dp = [[len(csl[0])]] #d...
{ "input": [ "4\n4\n1 5\n2 4\n2 3\n3 4\n5\n1 5\n2 3\n2 5\n3 5\n2 2\n3\n1 3\n2 4\n2 3\n7\n1 10\n2 8\n2 5\n3 4\n4 4\n6 8\n7 7\n", "1\n1\n100000 100001\n", "1\n1\n1 200000\n", "1\n1\n1 99274\n", "4\n4\n1 5\n2 4\n2 3\n3 4\n5\n1 5\n2 3\n2 5\n3 5\n2 2\n3\n1 3\n2 4\n2 3\n7\n1 10\n2 8\n0 5\n3 4\n4 4\n6 8\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given n segments on a coordinate axis OX. The i-th segment has borders [l_i; r_i]. All points x, for which l_i ≤ x ≤ r_i holds, belong to the i-th segment. Your task is to ch...
1442_C. Graph Transpositions_26140
You are given a directed graph of n vertices and m edges. Vertices are numbered from 1 to n. There is a token in vertex 1. The following actions are allowed: * Token movement. To move the token from vertex u to vertex v if there is an edge u → v in the graph. This action takes 1 second. * Graph transposition. T...
# region fastio # from https://codeforces.com/contest/1333/submission/75948789 import sys, io, os BUFSIZE = 8192 class FastIO(io.IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = io.BytesIO() self.writable = "x" in file.mode or "r" not in file.mo...
{ "input": [ "4 3\n2 1\n2 3\n4 3\n", "4 4\n1 2\n2 3\n3 4\n4 1\n", "50 49\n1 3\n6 46\n47 25\n11 49\n47 10\n26 10\n12 38\n45 38\n24 39\n34 22\n36 3\n21 16\n43 44\n45 23\n2 31\n26 13\n28 42\n43 30\n12 27\n32 44\n24 25\n28 20\n15 19\n6 48\n41 7\n15 17\n8 9\n2 48\n33 5\n33 23\n4 19\n40 31\n11 9\n40 39\n35 27\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 directed graph of n vertices and m edges. Vertices are numbered from 1 to n. There is a token in vertex 1. The following actions are allowed: * Token movement. To...
1468_E. Four Segments_26144
Monocarp wants to draw four line segments on a sheet of paper. He wants the i-th segment to have its length equal to a_i (1 ≤ i ≤ 4). These segments can intersect with each other, and each segment should be either horizontal or vertical. Monocarp wants to draw the segments in such a way that they enclose a rectangular...
t = int(input()) while (t): a = list(map(int,input().split())) a.sort() print(a[0]*a[2]) t -= 1
{ "input": [ "4\n1 2 3 4\n5 5 5 5\n3 1 4 1\n100 20 20 100\n", "4\n1 0 3 4\n5 5 5 5\n3 1 4 1\n100 20 20 100\n", "4\n1 1 3 4\n5 5 5 5\n3 1 4 1\n100 20 20 100\n", "4\n1 1 3 4\n5 5 3 5\n3 1 4 1\n100 20 20 100\n", "4\n1 1 3 4\n5 5 3 5\n1 1 4 1\n100 20 20 101\n", "4\n1 1 3 4\n5 5 3 5\n1 1 4 1\n101 2...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Monocarp wants to draw four line segments on a sheet of paper. He wants the i-th segment to have its length equal to a_i (1 ≤ i ≤ 4). These segments can intersect with each other, and...
1492_D. Genius's Gambit_26148
You are given three integers a, b, k. Find two binary integers x and y (x ≥ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form) has exactly k ones. You are not allowed to use leading zeros for x and y. Input The only line contains three integers a, b, and k (...
#tests = int(input()) #for t in range(tests): #n = int(input()) a, b, k = list(map(int, input().split())) if a == 0 and k!=0: print('No') elif k ==0: print('Yes') print('1'*b + '0'*a) print('1'*b + '0'*a) elif b==1 or k > (a+b-2): print('No') else: shift = a+b-2-k print('Yes') ans_1 = ...
{ "input": [ "4 2 3\n", "3 2 5\n", "3 2 1\n", "5 5 8\n", "7 7 12\n", "1436 1488 2427\n", "0 20 5\n", "10 1 0\n", "2 4 4\n", "79 113 191\n", "199999 1 199999\n", "5 5 5\n", "1353 1579 2909\n", "104 90 191\n", "0 6 1\n", "3 4 1\n", "100014 15 100026\n"...
2CODEFORCES
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, k. Find two binary integers x and y (x ≥ y) such that 1. both x and y consist of a zeroes and b ones; 2. x - y (also written in binary form)...
1515_E. Phoenix and Computers_26152
There are n computers in a row, all originally off, and Phoenix wants to turn all of them on. He will manually turn on computers one at a time. At any point, if computer i-1 and computer i+1 are both on, computer i (2 ≤ i ≤ n-1) will turn on automatically if it is not already on. Note that Phoenix cannot manually turn ...
#!/usr/bin/env python import os import sys from io import BytesIO, IOBase def main(): n, MOD = map(int, input().split()) factorial = [1] for i in range(2, n + 1): factorial.append(factorial[-1] * i % MOD) for i in range(len(factorial)): factorial[i] = pow(factorial[i], MOD - 2, MOD) ...
{ "input": [ "400 234567899\n", "4 100000007\n", "3 100000007\n", "6 100000007\n", "5 999999937\n", "350 999999733\n", "398 999999733\n", "399 999999733\n", "7 100000007\n", "100 999999733\n", "400 999999733\n", "397 999999733\n", "400 100000007\n", "272 1000000...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are n computers in a row, all originally off, and Phoenix wants to turn all of them on. He will manually turn on computers one at a time. At any point, if computer i-1 and compu...
1542_D. Priority Queue_26155
You are given a sequence A, where its elements are either in the form + x or -, where x is an integer. For such a sequence S where its elements are either in the form + x or -, define f(S) as follows: * iterate through S's elements from the first one to the last one, and maintain a multiset T as you iterate through...
MOD = 998244353 def solve(): n = int(input()) ans = 0 arr = [] for i in range(n): a = list(input().split()) if len(a) == 2: arr.append(int(a[1])) else: arr.append(0) for cur in range(n): if arr[cur]: dp = [0] * (n+1) d...
{ "input": [ "15\n+ 2432543\n-\n+ 4567886\n+ 65638788\n-\n+ 578943\n-\n-\n+ 62356680\n-\n+ 711111\n-\n+ 998244352\n-\n-\n", "4\n-\n+ 1\n+ 2\n-\n", "3\n+ 489111368\n+ 489111368\n+ 489111368\n", "3\n+ 202794029\n+ 810021800\n+ 810021800\n", "2\n+ 717107178\n+ 717107178\n", "4\n+ 68335221\n+ 6833...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given a sequence A, where its elements are either in the form + x or -, where x is an integer. For such a sequence S where its elements are either in the form + x or -, defin...
16_D. Logging_26159
The main server of Gomble company received a log of one top-secret process, the name of which can't be revealed. The log was written in the following format: «[date:time]: message», where for each «[date:time]» value existed not more than 10 lines. All the files were encoded in a very complicated manner, and only one p...
from sys import stdin lines = int(stdin.readline()) days = 1 count = 0 h1 = 0 m1 = 0 for x in range(lines): log = stdin.readline().strip() hour = int(log[1:3]) if hour == 12: hour = 0 if log[7] =='p': hour += 12 minute = int(log[4:6]) #print(hour,minute) #print(h1,m1) if hour < h1 or hour =...
{ "input": [ "5\n[05:00 a.m.]: Server is started\n[05:00 a.m.]: Rescan initialized\n[01:13 p.m.]: Request processed\n[01:10 p.m.]: Request processed\n[11:40 p.m.]: Rescan completed\n", "3\n[09:00 a.m.]: User logged in\n[08:00 a.m.]: User logged in\n[07:00 a.m.]: User logged in\n", "5\n[11:49 a.m.]: maapap...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: The main server of Gomble company received a log of one top-secret process, the name of which can't be revealed. The log was written in the following format: «[date:time]: message», w...
190_B. Surrounded_26163
So, the Berland is at war with its eternal enemy Flatland again, and Vasya, an accountant, was assigned to fulfil his duty to the nation. Right now the situation in Berland is dismal — their both cities are surrounded! The armies of flatlanders stand on the borders of circles, the circles' centers are in the surround...
import sys import math a,b,c=map(int,sys.stdin.readline().split()) d,e,f=map(int,sys.stdin.readline().split()) ds=math.sqrt((a-d)**2+(b-e)**2) if ds>=c+f: print((ds-c-f)/2) elif ds<=abs(c-f): print((abs(c-f)-ds)/2) else: print(0)
{ "input": [ "0 0 1\n6 0 3\n", "-10 10 3\n10 -10 3\n", "41 17 3\n71 -86 10\n", "826 4417 2901\n833 -2286 3802\n", "0 3278 2382\n2312 1 1111\n", "659 -674 277\n-345 -556 127\n", "2587 4850 3327\n3278 -204 1774\n", "-6 3 8\n7 2 1\n", "4763 2945 956\n3591 9812 180\n", "0 1 3\n1 -1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: So, the Berland is at war with its eternal enemy Flatland again, and Vasya, an accountant, was assigned to fulfil his duty to the nation. Right now the situation in Berland is disma...
214_B. Hometask_26167
Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you? You are given a set of digits, your task is to find the maximum integer that you can mak...
def hometask(arr): n="0" if arr.count(0)==0: return -1 arr.remove(0) ans=[] arr=sorted(arr,reverse=True) while arr : c=sum(arr)%3 if c==0: break flag=True for i in range(len(arr)-1,-1,-1): if arr[i]%3==c: arr.pop(i) ...
{ "input": [ "1\n0\n", "11\n3 4 5 4 5 3 5 3 4 4 0\n", "8\n3 2 5 1 5 2 2 3\n", "3\n0 0 1\n", "3\n1 0 0\n", "12\n3 1 2 3 2 0 2 2 2 0 2 3\n", "10\n1 0 0 0 0 0 0 0 0 0\n", "8\n3 3 6 3 0 7 7 9\n", "4\n0 0 0 0\n", "12\n5 3 3 3 2 5 5 1 2 1 4 1\n", "10\n3 0 1 1 1 1 1 1 1 1\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new ta...
238_B. Boring Partition_26171
This problem is the most boring one you've ever seen. Given a sequence of integers a1, a2, ..., an and a non-negative integer h, our goal is to partition the sequence into two subsequences (not necessarily consist of continuous elements). Each element of the original sequence should be contained in exactly one of the...
#https://codeforces.com/problemset/problem/238/B n, h = map(int, input().split()) a = list(map(int, input().split())) b = [[x, i] for i, x in enumerate(a)] b = sorted(b, key=lambda x:x[0]) def solve(a, n, h): if n == 2: return 0, [1, 1] min_ = (a[-1][0] + a[-2][0]) - (a[0][0] + a[1][0]) ...
{ "input": [ "5 10\n0 1 0 2 1\n", "3 2\n1 2 3\n", "5 10000000\n1 1 2 2 100000000\n", "2 5\n23921862 23921857\n", "12 3\n7878607 7878605 7878605 7878613 7878612 7878609 7878609 7878608 7878609 7878611 7878609 7878613\n", "4 3\n16194884 16194881 16194881 16194883\n", "20 10\n12986238 1298623...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: This problem is the most boring one you've ever seen. Given a sequence of integers a1, a2, ..., an and a non-negative integer h, our goal is to partition the sequence into two subse...
262_E. Maxim and Matrix_26175
Maxim loves to fill in a matrix in a special manner. Here is a pseudocode of filling in a matrix of size (m + 1) × (m + 1): <image> Maxim asks you to count, how many numbers m (1 ≤ m ≤ n) are there, such that the sum of values in the cells in the row number m + 1 of the resulting matrix equals t. Expression (x xor y...
def comb(n, r): if r > n or r < 0: return 0 r = min(r, n-r) result = 1 for i in range(1, r+1): result = result*(n+1-i)//i return result def F(n, t): if t == 0: return 1 elif n == 0: return 0 elif n == 1: return int(t == 1) m = len(bin(n)) - 3 ...
{ "input": [ "1000000000000 1048576\n", "3 3\n", "1 1\n", "3 2\n", "445762753 268435456\n", "144342486 67108864\n", "257655784 16384\n", "341001112 155173936\n", "329622201 19482151\n", "987654321987 1048576\n", "58797441 33554432\n", "4890852 16\n", "70 32\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Maxim loves to fill in a matrix in a special manner. Here is a pseudocode of filling in a matrix of size (m + 1) × (m + 1): <image> Maxim asks you to count, how many numbers m (1 ≤ ...
334_C. Secrets_26183
Gerald has been selling state secrets at leisure. All the secrets cost the same: n marks. The state which secrets Gerald is selling, has no paper money, only coins. But there are coins of all positive integer denominations that are powers of three: 1 mark, 3 marks, 9 marks, 27 marks and so on. There are no coins of oth...
n = int(input()) res = 1 x = 1 while x <= n: if n%x != 0: res = max(res, (n+x-1)//x) x *= 3 print(res)
{ "input": [ "1\n", "4\n", "16677181699666569\n", "52013157885656046\n", "1129718145924\n", "29442431889534807\n", "3\n", "58061299250691018\n", "81\n", "2\n", "10\n", "93886356235159944\n", "72900000000000\n", "243\n", "70414767176369958\n", "5559060566...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Gerald has been selling state secrets at leisure. All the secrets cost the same: n marks. The state which secrets Gerald is selling, has no paper money, only coins. But there are coin...
357_C. Knight Tournament_26187
Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knights in the kingdom and they in turn agreed to participate in this grand event. As for you, you're just a simple peasant. There's no surprise that you slept in this morning and were late for the tourname...
n, m = map(int, input().split()) p, d = [0] * (n + 2), list(range(1, n + 3)) for i in range(m): l, r, x = map(int, input().split()) while l < x: if p[l]: k = d[l] d[l] = x l = k else: d[l], p[l] = x, x l += 1 l += 1 ...
{ "input": [ "4 3\n1 2 1\n1 3 3\n1 4 4\n", "8 4\n3 5 4\n3 7 6\n2 8 8\n1 8 1\n", "11 8\n3 5 5\n8 9 9\n4 6 6\n8 10 10\n5 7 7\n2 7 2\n10 11 11\n1 11 1\n", "3 1\n1 3 2\n", "10 7\n8 9 9\n3 4 3\n2 3 2\n1 5 2\n6 7 6\n6 10 10\n1 10 10\n", "11 7\n7 8 8\n5 6 5\n1 3 3\n7 9 9\n5 10 10\n10 11 11\n1 11 4\n"...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Hooray! Berl II, the king of Berland is making a knight tournament. The king has already sent the message to all knights in the kingdom and they in turn agreed to participate in this ...
401_A. Vanya and Cards_26193
Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. The only limit is, the number on each card doesn't exceed x in the absolute value. Natasha doesn't like when Vanya spends a long time pla...
inp = input().split(' ') n = int(inp[0]) x = int(inp[1]) su = 0 inp = input().split(' ') for i in inp: su += int(i) count = 0 while su!=0: count += 1 if su > 0: su += max(-x, -su) else: su += min(x, -su) print(count)
{ "input": [ "3 2\n-1 1 2\n", "2 3\n-2 -2\n", "93 273\n-268 -170 -163 19 -69 18 -244 35 -34 125 -224 -48 179 -247 127 -150 271 -49 -102 201 84 -151 -70 -46 -16 216 240 127 3 218 -209 223 -227 -201 228 -8 203 46 -100 -207 126 255 40 -58 -217 93 172 -97 23 183 102 -92 -157 -117 173 47 144 -235 -227 -62 -128...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Vanya loves playing. He even has a special set of cards to play with. Each card has a single integer. The number on the card can be positive, negative and can even be equal to zero. T...
429_B. Working out_26197
Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix a with n lines and m columns. Let number a[i][j] represents the calories burned by performing workout at the cell of gym in the i-th line and the j-th column. Iahub starts with ...
# -*- coding:utf-8 -*- """ created by shuangquan.huang at 1/7/20 """ import collections import time import os import sys import bisect import heapq from typing import List def solve(N, M, A): dpa = [[0 for _ in range(M+2)] for _ in range(N+2)] dpb = [[0 for _ in range(M+2)] for _ in range(N+2)] dpc = ...
{ "input": [ "3 3\n100 100 100\n100 1 100\n100 100 100\n", "3 3\n3 1 2\n3 2 0\n2 3 2\n", "4 5\n87882 40786 3691 85313 46694\n28884 16067 3242 97367 78518\n4250 35501 9780 14435 19004\n64673 65438 56977 64495 27280\n", "3 3\n1 1 1\n0 10000 0\n1 1 1\n", "3 3\n1 10 1\n1 10 1\n1 10 1\n", "3 3\n9 0...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix a with n lines and m columns. Let number ...
450_E. Jzzhu and Apples_26201
Jzzhu has picked n apples from his big apple tree. All the apples are numbered from 1 to n. Now he wants to sell them to an apple store. Jzzhu will pack his apples into groups and then sell them. Each group must contain two apples, and the greatest common divisor of numbers of the apples in each group must be greater...
import math apples=int(input()) if apples<=3: print(0) else: halfpr=int(apples/2) def primes(n): primeslistsa=[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, ...
{ "input": [ "6\n", "2\n", "9\n", "3\n", "10\n", "5\n", "1\n", "100\n", "5249\n", "10007\n", "30011\n", "0\n", "17\n", "8434\n", "12360\n", "26335\n", "4\n", "7\n", "11\n", "14851\n", "8378\n", "25386\n", "18\n", "110\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Jzzhu has picked n apples from his big apple tree. All the apples are numbered from 1 to n. Now he wants to sell them to an apple store. Jzzhu will pack his apples into groups and t...
497_B. Tennis Game_26208
Petya and Gena love playing table tennis. A single match is played according to the following rules: a match consists of multiple sets, each set consists of multiple serves. Each serve is won by one of the players, this player scores one point. As soon as one of the players scores t points, he wins the set; then the ne...
n = int(input()) line = input().split() lst = [] for num in line: lst.append(int(num)) cnt1 = [0] cnt2 = [0] c1 = 0 c2 = 0 for num in lst: if num == 1: c1 += 1 cnt1.append(c2) else: c2 += 1 cnt2.append(c1) w = lst[n - 1] ans = [] c1 = len(cnt1) c2 = len(cnt2) for t in ran...
{ "input": [ "4\n1 2 1 2\n", "8\n2 1 2 1 1 1 1 1\n", "4\n1 1 1 1\n", "5\n1 2 1 2 1\n", "82\n1 1 1 2 2 2 2 1 1 1 2 2 2 2 1 1 1 2 2 2 1 1 1 1 2 2 2 1 1 1 1 2 2 2 2 1 1 1 1 2 2 2 1 1 1 2 2 2 2 1 1 1 1 2 2 2 1 1 1 2 2 2 1 1 1 2 2 2 2 1 1 1 2 2 2 1 1 1 1 2 2 2\n", "14\n2 1 2 1 1 1 1 2 1 1 2 1 2 1\n...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Petya and Gena love playing table tennis. A single match is played according to the following rules: a match consists of multiple sets, each set consists of multiple serves. Each serv...
548_A. Mike and Fax_26214
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string s. <image> He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly k mess...
def isPalindrome(t): for i in range(len(t)//2): if t[i] != t[len(t)-i-1]: return False return True s = input() k = int(input()) if len(s) % k: print('NO') else: t = len(s)//k for i in range(k): if not isPalindrome(s[i*t: i*t+t]): print('NO') break ...
{ "input": [ "saddastavvat\n2\n", "saba\n2\n", "rbehjxpblnzfgeebpkvzznwtzszghjuuxovreapmwehqyjymrkmksffbdpbdyegulabsmjiykeeqtuvqqyxlitpxjdpwmqtlmudqsksgwqekvwfjdsggzajcpsyserkctpbajgzdbiqaekfaepnecezdzamqszpwfvhlannszgaiewvcdnnvzhblmuzjtqeyjcqjqoxatavavokyxokuxwuqueskktxnxraihnqovrfykpzsyjmrhqsvbobzsnfqwv...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and ...
574_C. Bear and Poker_26218
Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are n players (including Limak himself) and right now all of them have bids on the table. i-th of them has bid with size ai dollars. Each player can double his bid any number of times and triple his bid any number of ...
n = int(input()) arr = [int(x) for x in input().split()] for i in range(n): while arr[i]%2==0: arr[i]/=2 while arr[i]%3==0: arr[i]/=3 print("Yes" if all(arr[0]==arr[i] for i in range(n))else "No")
{ "input": [ "4\n75 150 75 50\n", "3\n100 150 250\n", "2\n49 42\n", "20\n958692492 954966768 77387000 724664764 101294996 614007760 202904092 555293973 707655552 108023967 73123445 612562357 552908390 914853758 915004122 466129205 122853497 814592742 373389439 818473058\n", "3\n335544320 71744535 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Limak is an old brown bear. He often plays poker with his friends. Today they went to a casino. There are n players (including Limak himself) and right now all of them have bids on th...
596_A. Wilbur and Swimming Pool_26222
After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned...
def judgeTwoPoints( pa , pb ): if pa[0] != pb[0] and pa[1] != pb[1]: #print( "ok!" , pa , pb , abs( pa[0] - pb[0] ) * abs( pa[1] - pb[1] ) ) return abs( pa[0] - pb[0] ) * abs( pa[1] - pb[1] ) else: return -1 def solve( pts , n ): if n == 1: return -1 pts.sort() if n...
{ "input": [ "1\n1 1\n", "2\n0 0\n1 1\n", "3\n0 0\n0 3\n3 0\n", "3\n-679 301\n240 -23\n-679 -23\n", "2\n-457 82\n260 -662\n", "3\n0 1\n1 0\n0 0\n", "1\n-717 916\n", "4\n-64 -509\n-64 960\n634 -509\n634 960\n", "3\n2 1\n2 4\n6 1\n", "3\n1 0\n1 -1\n0 0\n", "3\n-2 -1\n-1 -1\n-...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of...
617_C. Watering Flowers_26226
A flowerbed has many flowers and two fountains. You can adjust the water pressure and set any values r1(r1 ≥ 0) and r2(r2 ≥ 0), giving the distances at which the water is spread from the first and second fountain respectively. You have to set such r1 and r2 that all the flowers are watered, that is, for each flower, t...
f = lambda: map(int, input().split()) n, a, b, c, d = f() t = [] for i in range(n): x, y = f() t.append(((x - a) ** 2 + (y - b) ** 2, (x - c) ** 2 + (y - d) ** 2)) t.sort() s = 8e14 q = 0 for u, v in reversed(t): s = min(s, u + q) q = max(q, v) print(min(s, q))
{ "input": [ "2 -1 0 5 3\n0 2\n5 2\n", "4 0 0 5 0\n9 4\n8 3\n-1 0\n1 4\n", "10 -68 10 87 22\n30 89\n82 -97\n-52 25\n76 -22\n-20 95\n21 25\n2 -3\n45 -7\n-98 -56\n-15 16\n", "1 -10000000 -10000000 -10000000 -9999999\n10000000 10000000\n", "5 -6 -4 0 10\n-7 6\n-9 7\n-5 -1\n-2 1\n-8 10\n", "10 -18...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: A flowerbed has many flowers and two fountains. You can adjust the water pressure and set any values r1(r1 ≥ 0) and r2(r2 ≥ 0), giving the distances at which the water is spread from...
637_D. Running with Obstacles_26230
A sportsman starts from point xstart = 0 and runs to point with coordinate xfinish = m (on a straight line). Also, the sportsman can jump — to jump, he should first take a run of length of not less than s meters (in this case for these s meters his path should have no obstacles), and after that he can jump over a lengt...
n,m,s,d=map(int,input().split()) x=list(map(int,input().split()))+[m+s+1] x.sort() cur=l=0 ans=[] while l<m: r=min(x[cur]-1,m) ans.append(("RUN",r-l)) if r==m: break if r-l<s: print("IMPOSSIBLE") exit() t=x[cur]+1 while x[cur+1]-1-t<s: cur+=1 t=x[cur]+1 if t-r>d: print("IMPOSSIBLE"...
{ "input": [ "2 9 2 3\n6 4\n", "3 10 1 3\n3 4 7\n", "3 12000 2000 245\n3000 9003 7001\n", "13 91 1 3\n5 12 17 22 29 36 43 49 57 64 70 74 84\n", "9 82 14 4\n10 18 28 38 46 55 64 74 79\n", "8 51 2 1\n6 14 20 26 29 35 40 48\n", "3 20000 4000 3502\n5000 8500 15000\n", "4 10 1 7\n2 4 6 8\n"...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: A sportsman starts from point xstart = 0 and runs to point with coordinate xfinish = m (on a straight line). Also, the sportsman can jump — to jump, he should first take a run of leng...
665_D. Simple Subset_26234
A tuple of positive integers {x1, x2, ..., xk} is called simple if for all pairs of positive integers (i, j) (1 ≤ i < j ≤ k), xi + xj is a prime. You are given an array a with n positive integers a1, a2, ..., an (not necessary distinct). You want to find a simple subset of the array a with the maximum size. A prime n...
n = int(input()) L = list(map(int, input().split())) P = [-1 for _ in range(2000001)] def premier(n): if P[n] >= 0: return P[n] for i in range(2,int(n**0.5)+1): if n%i==0: P[n] = False return False P[n] = True return True e = L.count(1) if n == 1: print(1) ...
{ "input": [ "2\n2 2\n", "2\n2 3\n", "2\n83 14\n", "3\n2 1 1\n", "2\n999996 999997\n", "3\n1 13 13\n", "3\n2 7 12\n", "3\n5 8 1\n", "3\n1 3 14\n", "5\n1 1 1 8 3\n", "2\n1 1\n", "10\n10 10 1 2 3 3 1 2 1 5\n", "6\n2 5 1 1 1 1\n", "2\n999997 999994\n", "3\n3 6 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: A tuple of positive integers {x1, x2, ..., xk} is called simple if for all pairs of positive integers (i, j) (1 ≤ i < j ≤ k), xi + xj is a prime. You are given an array a with n posi...
68_B. Energy exchange_26238
It is well known that the planet suffers from the energy crisis. Little Petya doesn't like that and wants to save the world. For this purpose he needs every accumulator to contain the same amount of energy. Initially every accumulator has some amount of energy: the i-th accumulator has ai units of energy. Energy can be...
def check(a, k, cur): need = 0 have = 0 for x in a: if x < cur: need += cur - x else: have += (x - cur) * (1 - k / 100) return need <= have n, k = [int(x) for x in input().split()] a = [int(x) for x in input().split()] l = 0 r = 1000 for i in range(100): cur = (l + r) / 2 if check(a, k, cur): l = cur...
{ "input": [ "2 90\n1 11\n", "3 50\n4 2 1\n", "14 6\n256 465 759 589 242 824 638 985 506 128 809 105 301 827\n", "1 20\n784\n", "102 99\n73 348 420 956 955 436 69 714 87 480 102 555 933 215 452 167 157 593 863 816 337 471 371 574 862 967 581 543 330 348 221 640 378 250 500 428 866 379 1 723 880 99...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: It is well known that the planet suffers from the energy crisis. Little Petya doesn't like that and wants to save the world. For this purpose he needs every accumulator to contain the...
711_E. ZS and The Birthday Paradox_26242
ZS the Coder has recently found an interesting concept called the Birthday Paradox. It states that given a random set of 23 people, there is around 50% chance that some two of them share the same birthday. ZS the Coder finds this very interesting, and decides to test this with the inhabitants of Udayland. In Udayland,...
#copied import math n, k = [int(x) for x in input().split()] if n<70 and k>2**n: print(1,1) exit(0) mod = int(1e6)+3 def fastpow(a,b): t, ans = a, 1 while b: if(b&1): ans = ans*t%mod t = t*t %mod b>>=1 return ans t=k-1 cnt=0 while t: # gets highest possible pow ...
{ "input": [ "1 3\n", "4 3\n", "3 2\n", "27811605053083586 516548918254320722\n", "121125188014443608 400338158982406735\n", "768753603103944226 868940\n", "545838312215845682 715670\n", "160986032904427725 153429\n", "78305076165311264 280970\n", "452811696339558207 443394\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 recently found an interesting concept called the Birthday Paradox. It states that given a random set of 23 people, there is around 50% chance that some two of them sh...
778_B. Bitwise Formula_26251
Bob recently read about bitwise operations used in computers: AND, OR and XOR. He have studied their properties and invented a new game. Initially, Bob chooses integer m, bit depth of the game, which means that all numbers in the game will consist of m bits. Then he asks Peter to choose some m-bit number. After that, ...
#from math import * from sys import * from decimal import * def main(): n,k=(int(z) for z in stdin.readline().split()) d=[] nm=[0]*n bt1=[False]*(n+1) bt2=[False]*(n+1) bt2[-1]=True nam=dict() nam["?"]=-1 for i in range(n): fl=0 s=stdin.readline()[:-1].split(" := ") ...
{ "input": [ "5 1\na := 1\nbb := 0\ncx := ? OR a\nd := ? XOR ?\ne := d AND bb\n", "3 3\na := 101\nb := 011\nc := ? XOR b\n", "2 109\na := 1010101010100000000000011111111111111111111111111111111111111111111000000000000000000000000000111111111111111\nb := ? XOR a\n", "12 14\na := 01100010000111\nb := ? ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Bob recently read about bitwise operations used in computers: AND, OR and XOR. He have studied their properties and invented a new game. Initially, Bob chooses integer m, bit depth o...
802_E. Marmots (medium)_26255
Good job! Now that Heidi is able to distinguish between Poisson and uniform distributions, she is in a good position to actually estimate the populations. Can you help Heidi estimate each village's population? Input Same as the easy version. Output Output one line per village, in the same order as provided in the ...
def sampleVariance(V): X = sum(V) / len(V) S = 0.0 for x in V: S += (X-x)**2 S /= (len(V)-1) return (X, S) #That awkward moment when you realized that variance is sigma^2 but you just took the stat course this semester for i in range(int(input())): V = list(map(int, input().split())) ...
{ "input": [], "output": [] }
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Good job! Now that Heidi is able to distinguish between Poisson and uniform distributions, she is in a good position to actually estimate the populations. Can you help Heidi estimate...
825_A. Binary Protocol_26259
Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm: * Each digit is represented with number of '1' characters equal to the value of that digit (for 0 it is zero ones). * Digits are written one by one in ...
x = int(input()) a = input() l = 0 c = [] v = '' b = a.split("0") for i in b: g = len(i) c.append(g) for p in c: v += str(p) print(v)
{ "input": [ "3\n111\n", "9\n110011101\n", "5\n10001\n", "1\n1\n", "8\n10101010\n", "2\n10\n", "14\n11001100011000\n", "31\n1000011111111100011110111111111\n", "53\n10110111011110111110111111011111110111111110111111111\n", "10\n1000000000\n", "3\n100\n", "89\n1111111110...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Polycarp has just invented a new binary protocol for data transmission. He is encoding positive integer decimal number to binary string using following algorithm: * Each digit is r...
847_L. Berland SU Computer Network_26262
In the computer network of the Berland State University there are n routers numbered from 1 to n. Some pairs of routers are connected by patch cords. Information can be transmitted over patch cords in both direction. The network is arranged in such a way that communication between any two routers (directly or through o...
import math import sys read = sys.stdin.readline n = int(read()) sub = [[] for _ in range(n)] for i in range(n): data = read().strip() for j in data.split('-'): tree = list(map(int, j.split(':')[1].split(','))) for k in range(len(tree)): tree[k] -= 1 sub[i].append(sorted(tree...
{ "input": [ "5\n4:2,5,3,4\n1:4-1:1-2:5,3\n4:4,5,2,1\n4:2,1,3,5\n1:3-3:4,2,1\n", "3\n1:2-1:3\n1:1-1:3\n1:1-1:2\n", "3\n2:3,2\n1:1-1:3\n2:1,2\n", "4\n2:2,3-1:4\n3:4,3,1\n3:2,4,1\n1:2-2:1,3\n", "10\n2:7,4-2:5,8-1:3-1:6-1:2-2:10,9\n9:6,7,3,4,10,8,9,5,1\n9:2,1,7,6,9,4,8,10,5\n8:5,2,1,3,6,9,10,8-1:7\n1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: In the computer network of the Berland State University there are n routers numbered from 1 to n. Some pairs of routers are connected by patch cords. Information can be transmitted ov...
896_A. Nephren gives a riddle_26269
What are you doing at the end of the world? Are you busy? Will you save us? <image> Nephren is playing a game with little leprechauns. She gives them an infinite array of strings, f0... ∞. f0 is "What are you doing at the end of the world? Are you busy? Will you save us?". She wants to let more people know about i...
f0 = 'What are you doing at the end of the world? Are you busy? Will you save us?' ft1, ft2, ft3 = 'What are you doing while sending "', '"? Are you busy? Will you send "', '"?' flen = [2 * 10 ** 18] * (10 ** 5 + 1) flen[0] = len(f0) for i in range(1, 56): flen[i] = len(ft1) + len(ft2) + len(ft3) + 2 * flen[i-1] ...
{ "input": [ "10\n4 1825\n3 75\n3 530\n4 1829\n4 1651\n3 187\n4 584\n4 255\n4 774\n2 474\n", "3\n1 1\n1 2\n1 111111111111\n", "5\n0 69\n1 194\n1 139\n0 47\n1 66\n", "1\n0 1\n", "10\n5 1\n5 34\n5 35\n5 2254\n5 2255\n5 2286\n5 2287\n5 4506\n5 4507\n5 4508\n", "10\n10 1\n10 34\n10 35\n10 73182\n1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: What are you doing at the end of the world? Are you busy? Will you save us? <image> Nephren is playing a game with little leprechauns. She gives them an infinite array of strings, ...
917_B. MADMAX_26273
As we all know, Max is the best video game player among her friends. Her friends were so jealous of hers, that they created an actual game just to prove that she's not the best at games. The game is played on a directed acyclic graph (a DAG) with n vertices and m edges. There's a character written on each edge, a lower...
def mat(shape, inital_val=None): if len(shape) > 1: return [mat(shape[1:], inital_val) for _ in range(shape[0])] else: return [inital_val] * shape[0] def main(): n, m = [int(x) for x in input().split()] graph = [{} for _ in range(n)] for _ in range(m): v, u, c ...
{ "input": [ "4 4\n1 2 b\n1 3 a\n2 4 c\n3 4 b\n", "5 8\n5 3 h\n1 2 c\n3 1 c\n3 2 r\n5 1 r\n4 3 z\n5 4 r\n5 2 h\n", "8 20\n2 4 a\n1 8 a\n1 2 v\n8 4 h\n1 7 w\n5 4 h\n2 8 h\n7 4 i\n4 3 w\n6 8 l\n1 4 v\n1 3 g\n5 3 b\n1 6 a\n7 3 w\n6 4 f\n6 7 g\n7 8 n\n5 8 g\n2 6 j\n", "3 2\n1 3 l\n2 1 v\n", "2 1\n1 2 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: As we all know, Max is the best video game player among her friends. Her friends were so jealous of hers, that they created an actual game just to prove that she's not the best at gam...
93_B. End of Exams_26277
Students love to celebrate their holidays. Especially if the holiday is the day of the end of exams! Despite the fact that Igor K., unlike his groupmates, failed to pass a programming test, he decided to invite them to go to a cafe so that each of them could drink a bottle of... fresh cow milk. Having entered the cafe...
import sys from array import array # noqa: F401 def input(): return sys.stdin.buffer.readline().decode('utf-8') n, w, m = map(int, input().split()) w = float(w) eps = 1e-9 req = n * w / m cup = [req] * m ans = [[] for _ in range(m)] j = 0 for i in range(n): milk = w cnt = 0 while j < m and milk > ...
{ "input": [ "5 500 2\n", "2 500 3\n", "4 100 7\n", "4 100 5\n", "17 100 10\n", "44 371 47\n", "2 632 19\n", "13 557 13\n", "24 704 30\n", "28 380 29\n", "24 836 25\n", "13 503 9\n", "35 462 50\n", "50 1000 49\n", "2 227 11\n", "1 736 10\n", "26 856 ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Students love to celebrate their holidays. Especially if the holiday is the day of the end of exams! Despite the fact that Igor K., unlike his groupmates, failed to pass a programmin...
p02626 AtCoder Beginner Contest 172 - Unfair Nim_26295
There are N piles of stones. The i-th pile has A_i stones. Aoki and Takahashi are about to use them to play the following game: * Starting with Aoki, the two players alternately do the following operation: * Operation: Choose one pile of stones, and remove one or more stones from it. * When a player is unable to do t...
import sys from functools import lru_cache read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N, *A = map(int, read().split()) a, b = A[:2] xor = 0 for x in A[2:]: xor ^= x INF = 10**13 @lru_cache(None) def F(a, b, xor): if (a & 1) ^ (b & 1) != (xor & 1...
{ "input": [ "2\n3 5", "3\n4294967297 8589934593 12884901890", "8\n10 9 8 7 6 5 4 3", "2\n5 3", "3\n1 1 2", "2\n3 6", "2\n5 5", "2\n7 5", "8\n10 9 8 8 6 9 7 3", "2\n5 1", "2\n11 1", "2\n21 1", "2\n19 1", "2\n7 -1", "3\n869 1 534", "2\n12 0", "3\n4294...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are N piles of stones. The i-th pile has A_i stones. Aoki and Takahashi are about to use them to play the following game: * Starting with Aoki, the two players alternately do ...
p02757 AtCoder Beginner Contest 158 - Divisible Substring_26299
Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S - there are N \times (N + 1) / 2 of them - are divisible by P when regarded as integers written in base ten. Here substrings starting with a `0`...
n,m=map(int,input().split());s=input();l=[0]*m;a,t,p=0,0,1 if 10%m: for i in s[::-1]:l[t%m]+=1;t+=int(i)*p;a+=l[t%m];p=p*10%m else:a=sum(i+1 for i in range(n) if int(s[i])%m<1) print(a)
{ "input": [ "4 3\n3543", "20 11\n33883322005544116655", "4 2\n2020", "20 8\n33883322005544116655", "20 5\n33883322005544116655", "20 5\n35091597582718018558", "20 3\n35091597582718018558", "20 5\n34713145004890865366", "20 5\n63523169932268849551", "20 2\n33883322005544116655"...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Takahashi has a string S of length N consisting of digits from `0` through `9`. He loves the prime number P. He wants to know how many non-empty (contiguous) substrings of S - there ...
p02892 AtCoder Grand Contest 039 - Graph Partition_26302
Given is a connected undirected graph with N vertices and M edges. The vertices are numbered 1 to N, and the edges are described by a grid of characters S. If S_{i,j} is `1`, there is an edge connecting Vertex i and j; otherwise, there is no such edge. Determine whether it is possible to divide the vertices into non-e...
from collections import deque import sys sys.setrecursionlimit(10**6) input = sys.stdin.readline n = int(input()) edge = [[] for _ in range(n)] mat = [[1000] * n for _ in range(n)] for i in range(n): s = input().rstrip() for j, ch in enumerate(s): if ch == "1": mat[i][j] = 1 if ...
{ "input": [ "2\n01\n10", "6\n010110\n101001\n010100\n101000\n100000\n010000", "3\n011\n101\n110", "3\n011\n111\n110", "3\n010\n101\n010", "3\n011\n111\n111", "3\n011\n110\n111", "6\n010111\n101001\n010100\n101000\n100000\n010000", "3\n010\n101\n110", "3\n011\n011\n110", "3...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Given is a connected undirected graph with N vertices and M edges. The vertices are numbered 1 to N, and the edges are described by a grid of characters S. If S_{i,j} is `1`, there is...
p03027 M-SOLUTIONS Programming Contest - Product of Arithmetic Progression_26306
Consider the following arithmetic progression with n terms: * x, x + d, x + 2d, \ldots, x + (n-1)d What is the product of all terms in this sequence? Compute the answer modulo 1\ 000\ 003. You are given Q queries of this form. In the i-th query, compute the answer in case x = x_i, d = d_i, n = n_i. Constraints *...
p,M,f=pow,1000003,[1] for i in range(1,M):f.append(f[i-1]*i%M) for _ in'_'*int(input()):x,d,n=map(int,input().split());t=x*p(d,M-2,M)%M;print([p(x,n,M),(M-n>=t>0)*1and f[t+n-1]*p(f[t-1],M-2,M)*p(d,n,M)%M][d>0])
{ "input": [ "2\n7 2 4\n12345 67890 2019", "2\n7 2 4\n12345 17991 2019", "2\n7 2 0\n12345 17991 2019", "2\n7 2 0\n12345 17991 2755", "2\n7 2 0\n9796 17991 2755", "2\n7 2 4\n12345 86689 2019", "2\n7 2 4\n12345 17991 226", "2\n7 2 0\n12345 25838 2019", "2\n7 2 1\n9796 17991 2755", ...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Consider the following arithmetic progression with n terms: * x, x + d, x + 2d, \ldots, x + (n-1)d What is the product of all terms in this sequence? Compute the answer modulo 1\ ...
p03168 Educational DP Contest - Coins_26310
Let N be a positive odd number. There are N coins, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), when Coin i is tossed, it comes up heads with probability p_i and tails with probability 1 - p_i. Taro has tossed all the N coins. Find the probability of having more heads than tails. Constraints * N is an od...
n=int(input()) p=list(map(float,input().split())) dp=[[0 for _ in range(n+1)]for _ in range(n)] dp[0][0]=1-p[0] dp[0][1]=p[0] for i in range(1,n): for j in range(i+2): dp[i][j]=dp[i-1][j-1]*p[i]+dp[i-1][j]*(1-p[i]) print(sum(dp[-1][(n+1)//2:]))
{ "input": [ "5\n0.42 0.01 0.42 0.99 0.42", "1\n0.50", "3\n0.30 0.60 0.80", "5\n1.024501914223776 0.01 0.42 0.99 0.42", "1\n1.0727834824798", "3\n0.5605093833878567 0.60 0.80", "5\n1.024501914223776 0.01 0.5446982864891694 0.99 0.42", "1\n1.4147366857390051", "3\n0.63370309829039 0...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Let N be a positive odd number. There are N coins, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), when Coin i is tossed, it comes up heads with probability p_i and tails wit...
p03313 AtCoder Regular Contest 100 - Or Plus Max_26314
There is an integer sequence of length 2^N: A_0, A_1, ..., A_{2^N-1}. (Note that the sequence is 0-indexed.) For every integer K satisfying 1 \leq K \leq 2^N-1, solve the following problem: * Let i and j be integers. Find the maximum value of A_i + A_j where 0 \leq i < j \leq 2^N-1 and (i or j) \leq K. Here, or denot...
n = int(input()) aaa = list(map(int, input().split())) n2 = 1 << n dp = [[a, 0] for a in aaa] for j in range(n): b = 1 << j for i in range(n2): if not i & b: dpi, dpk = dp[i], dp[i | b] if dpk[0] < dpi[0]: dpk[1] = max(dpk[0], dpi[1]) dpk[0] = dpi...
{ "input": [ "2\n1 2 3 1", "3\n10 71 84 33 6 47 23 25", "4\n75 26 45 72 81 47 97 97 2 2 25 82 84 17 56 32", "2\n1 2 3 2", "3\n10 71 84 33 6 32 23 25", "4\n75 26 45 72 81 47 97 97 2 2 25 95 84 17 56 32", "2\n0 2 3 2", "3\n10 71 155 33 6 32 23 25", "4\n75 26 45 112 81 47 97 97 2 2 25...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There is an integer sequence of length 2^N: A_0, A_1, ..., A_{2^N-1}. (Note that the sequence is 0-indexed.) For every integer K satisfying 1 \leq K \leq 2^N-1, solve the following p...
p03470 AtCoder Beginner Contest 085 - Kagami Mochi_26318
An X-layered kagami mochi (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have...
n,*d=map(int,open(0).read().split());print(len(set(d)))
{ "input": [ "7\n50\n30\n50\n100\n50\n80\n30", "3\n15\n15\n15", "4\n10\n8\n8\n6", "7\n50\n30\n50\n100\n50\n80\n35", "3\n29\n15\n15", "4\n10\n8\n14\n6", "3\n29\n15\n14", "7\n50\n40\n91\n110\n50\n34\n59", "7\n50\n40\n91\n110\n3\n34\n59", "3\n1\n1\n1", "7\n50\n30\n50\n100\n50\...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: An X-layered kagami mochi (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi dire...
p03632 AtCoder Beginner Contest 070 - Two Switches_26322
Alice and Bob are controlling a robot. They each have one switch that controls the robot. Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up. Bob started holding down his button C second after the start-up, and released his button D second...
a,b,c,d=map(int,input().split()) print(max(0,min(d,b)-max(a,c)))
{ "input": [ "10 90 20 80", "0 75 25 100", "0 33 66 99", "10 17 20 80", "1 75 25 100", "1 80 25 100", "-1 2 1 10", "10 90 20 58", "0 75 22 100", "1 72 25 100", "1 34 25 100", "-1 3 1 10", "0 75 36 100", "0 98 66 99", "19 90 29 58", "0 148 36 100", "1...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Alice and Bob are controlling a robot. They each have one switch that controls the robot. Alice started holding down her button A second after the start-up of the robot, and released ...
p03790 AtCoder Grand Contest 011 - Train Service Planning_26325
There is a railroad in Takahashi Kingdom. The railroad consists of N sections, numbered 1, 2, ..., N, and N+1 stations, numbered 0, 1, ..., N. Section i directly connects the stations i-1 and i. A train takes exactly A_i minutes to run through section i, regardless of direction. Each of the N sections is either single-...
import sys def merge_delay_pattern(k, half1, half2): len1 = len(half1) len2 = len(half2) start, delay1_next = half1[0] start2 = half2[0][0] time1 = start - start2 mid_start = start + time1 + delay1_next offset2_num_period = (mid_start - start2) // k offset2_phase = mid_start - offset2_...
{ "input": [ "3 10\n4 1\n3 1\n4 1", "6 4\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1", "20 987654321\n129662684 2\n162021979 1\n458437539 1\n319670097 2\n202863355 1\n112218745 1\n348732033 1\n323036578 1\n382398703 1\n55854389 1\n283445191 1\n151300613 1\n693338042 2\n191178308 2\n386707193 1\n204580036 1\n335134457 1...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There is a railroad in Takahashi Kingdom. The railroad consists of N sections, numbered 1, 2, ..., N, and N+1 stations, numbered 0, 1, ..., N. Section i directly connects the stations...
p03958 CODE FESTIVAL 2016 qual C - K Cakes_26329
There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all. There are T types of cake, and the number of the cakes of type i (1 ≤ i ≤ T) is a_i. Eating the same type of cake two days in a row would be no fun, so Mr. Takahashi would like to decide the order for eating ...
#!/usr/bin/env python3 k,t = map(int,input().split()) a = list(map(int,input().split())) print(max(0,2*(max(a)-(k+1)//2)-1))
{ "input": [ "7 3\n3 2 2", "6 3\n1 4 1", "100 1\n100", "7 3\n4 2 2", "6 2\n1 4 1", "100 2\n100", "110 2\n110", "7 3\n2 2 2", "7 3\n2 1 2", "7 3\n0 1 2", "7 3\n0 1 1", "7 3\n0 1 0", "7 3\n-1 1 1", "7 5\n-1 1 1", "7 3\n4 1 2", "6 2\n1 0 1", "7 3\n2 2 1...
5ATCODER
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: There are K pieces of cakes. Mr. Takahashi would like to eat one cake per day, taking K days to eat them all. There are T types of cake, and the number of the cakes of type i (1 ≤ i ...
p00050 Apple and Peach_26333
Fukushima Prefecture is also famous for producing fruits, and among them, peaches and apples boast one of the highest production volumes in Japan. By the way, when I made a print manuscript of an English pamphlet for sale, I mistakenly wrote the description about apples and the description about peaches in reverse. Yo...
a,p,t='apple','peach','_' print(input().replace(a,t).replace(p,a).replace(t,p))
{ "input": [ "the cost of one peach is higher than that of one apple.", "the cost of one peach is higher than th`t of one apple.", "the cost of ooe peach is higher than th`t of one apple.", "the cost of ooe peach is higher than th`t of eno apple.", "the cpst of ooe peach is higher than th`t of eno...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Fukushima Prefecture is also famous for producing fruits, and among them, peaches and apples boast one of the highest production volumes in Japan. By the way, when I made a print manu...
p00180 Demolition of Bridges_26337
Water Country Water Deven has n cities. Each city is surrounded by water and looks like an island country. Water Deven has m bridges, and transportation between cities is carried out by these bridges, which allows you to travel to and from all cities. Recently, it was decided to reduce the maintenance cost of the brid...
class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * (n+1) def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): ...
{ "input": [ "5 6\n0 2 1\n2 1 3\n2 3 8\n1 3 2\n3 4 5\n1 4 4\n3 3\n1 2 3\n2 0 3\n0 1 3\n0 0", "5 6\n0 2 1\n2 1 3\n2 3 8\n1 3 1\n3 4 5\n1 4 4\n3 3\n1 2 3\n2 0 3\n0 1 3\n0 0", "5 6\n0 2 1\n2 1 3\n2 3 8\n1 3 3\n3 4 5\n1 4 4\n3 3\n1 2 3\n2 0 3\n0 1 3\n0 0", "5 6\n0 2 1\n2 1 3\n2 3 8\n1 3 0\n3 4 5\n1 4 4\n3...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Water Country Water Deven has n cities. Each city is surrounded by water and looks like an island country. Water Deven has m bridges, and transportation between cities is carried out ...
p00336 Repeated Spell_26340
We, the researchers who discovered and investigated the ancient nation Iwashiro, finally discovered the temple in the center of Iwashiro. A lithograph dedicated to the god of Iwashiro was stored in the temple. On the lithograph, two strings were written, one for each sentence and one for the spell. In Iwashiro, how ma...
t = input() b = input() MOD = 10**9 + 7 cnts = [0]*(len(b)+1) cnts[0] = 1 for c in t: for i in range(len(b)-1, -1, -1): if c == b[i]: cnts[i+1] = (cnts[i+1] + cnts[i]) % MOD print(cnts[-1])
{ "input": [ "data\nstructure", "aaaabaaaabaaaabaaaab\naaaaa", "abab\nab", "data\nerutcurts", "aaaabaaaabaaaabaaaab\nbaaaa", "abaa\nab", "aaaabaaaabaaaabaaaab\naabaa", "aaaabaaaabaa`abaaaab\naabaa", "aaaabaaaabaa`ababaaa\naabaa", "aaaabaaaabaa`ababaaa\na`baa", "aaaabaaaabaa...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: We, the researchers who discovered and investigated the ancient nation Iwashiro, finally discovered the temple in the center of Iwashiro. A lithograph dedicated to the god of Iwashiro...
p00527 Take the 'IOI' train_26343
Take the'IOI'train A new railway has been laid in IOI. Trains running on railways in IOI are a combination of several vehicles, and there are two types of vehicles, I and O. Vehicles can only be connected to different types of vehicles. Also, because the train has a driver's seat, the cars at both ends of the train mu...
def main(): M, N = map(int, input().split()) S = input() T = input() INF = 10**18 dp0 = [[0]*(N+1) for i in range(M+1)] dp1 = [[-INF]*(N+1) for i in range(M+1)] for p in range(M+1): for q in range(N+1): v0 = dp0[p][q] v1 = dp1[p][q] if p < M: ...
{ "input": [ "5 5\nOIOOI\nOOIOI", "5 0\nOIOOI\nOOIOI", "5 5\nOIOOI\nIOIOO", "0 9\nOIOOI\nIOIOO", "0 0\nOIOOI\nOOIOI", "5 0\nOIOOI\nOOIPI", "5 9\nOIOOI\nIOIOO", "5 0\nOIOOI\nOOINI", "5 5\nIOOIO\nIOIOO", "5 1\nOIOOI\nOOIPI", "5 1\nOIOOI\nOOIPH", "5 0\nOIOOI\nOOIPH", "...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Take the'IOI'train A new railway has been laid in IOI. Trains running on railways in IOI are a combination of several vehicles, and there are two types of vehicles, I and O. Vehicles...
p00694 Strange Key_26346
Professor Tsukuba invented a mysterious jewelry box that can be opened with a special gold key whose shape is very strange. It is composed of gold bars joined at their ends. Each gold bar has the same length and is placed parallel to one of the three orthogonal axes in a three dimensional space, i.e., x-axis, y-axis an...
def solve(sentence): now = [0, 0, 0] # x,y,z num_p = {} positions = [] for s in sentence: if s.isdecimal(): if s in num_p: now = num_p[s] else: num_p[s] = now else: sign = 1 if s[0] == "+" else -1 if s[1] ==...
{ "input": [ "19\n 1 +x 1 +y +z 3 +z\n 3 +y -z +x +y -z -x +z 2 +z\n 2 +y\n19\n 1 +x 1 +y +z 3 +y -z +x +y -z -x +z 2 +y\n 3 +z\n 2 +z\n19\n 1 +x 1 +y +z 3 +z\n 3 +y -z +x +y -z -x +z 2 +y\n 2 +z\n18\n 1 -y\n 1 +y -z +x\n 1 +z +y +x +z +y -x -y 2 -y\n 2 +z\n3 +x +y +z\n3 +y +z -x\n0", "19\n1 +x 1...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Professor Tsukuba invented a mysterious jewelry box that can be opened with a special gold key whose shape is very strange. It is composed of gold bars joined at their ends. Each gold...
p01398 Swap Cipher_26353
Problem A: Swap crypto A 2D enthusiast at R University, he often writes embarrassing sentences that blush when seen by people. Therefore, in order for a third party to not be able to see the text he is writing, he encrypts the text using a method called swap encryption that he devised independently. In swap encryption...
while True: n = int(input()) if n == 0:break mes = list(input()) mes = [ord(c) - ord("a") for c in mes] ablst = [tuple(map(int, input().split())) for _ in range(n)] ablst.reverse() for a, b in ablst: a -= 1 b -= 1 mes[b], mes[a] = (mes[a] + (b - a)) % 26, (mes[b] + (b - a)) % 26 mes = [chr(i...
{ "input": [ "1\ntojxo\n1 4\n5\nuhcqmlmkv\n4 5\n6 9\n3 6\n1 7\n3 6\n5\nshzxadexonr\n8 9\n3 9\n5 8\n4 9\n10 11\n0", "1\ntojxo\n1 4\n5\nuhcqmlmkv\n4 5\n6 9\n3 6\n1 7\n3 6\n5\nshzxadexonr\n8 9\n3 9\n5 9\n4 9\n10 11\n0", "1\ntojxo\n1 4\n5\nuhcqmlnkv\n4 5\n6 9\n3 6\n1 7\n3 6\n5\nshzxadexonr\n8 9\n3 9\n5 8\n4 9...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Problem A: Swap crypto A 2D enthusiast at R University, he often writes embarrassing sentences that blush when seen by people. Therefore, in order for a third party to not be able to...
p01551 DNA_26356
A gene is a string consisting of `A`,` T`, `G`,` C`. The genes in this world are strangely known to obey certain syntactic rules. Syntax rules are given in the following form: Non-terminal symbol 1: Symbol 1_1 Symbol 1_2 ... Symbol 1_n1 Non-terminal symbol 2: Symbol 2_1 Symbol 2_2 ... Symbol 2_n2 ... Non-terminal sy...
from collections import defaultdict import sys def solve(): readline = sys.stdin.readline write = sys.stdout.write MOD = 10**9 + 7 Na, Nt, Ng, Nc = map(int, readline().split()) L = Na + Nt + Ng + Nc M = int(readline()) MP = {} S = [] for i in range(M): s = readline().strip() ...
{ "input": [ "1 1 1 2\n1\nk: [ATG] [ATG] [ATG] [C] [C]", "3 1 1 1\n3\ninv: at b b b\nat: [ATG] b\nb: [C]", "1 0 1 0\n3\ndna: a b\na: [AT]\nb: [GC]", "1 0 1 2\n1\nk: [ATG] [ATG] [ATG] [C] [C]", "1 1 1 2\n1\nk: [ASG] [ATG] [ATG] [C] [C]", "2 1 1 1\n3\ninv: at b b b\nat: [ATG] b\nb: [C]", "0 ...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: A gene is a string consisting of `A`,` T`, `G`,` C`. The genes in this world are strangely known to obey certain syntactic rules. Syntax rules are given in the following form: Non-...
p01852 Finger Counting_26360
Problem statement Meatishi can increase or decrease the number of fingers. There are n buns in front of Nikunishi-kun. Meatishi is trying to count the number of steamed buns by breaking his finger. There are only two shapes that Nishikun's fingers can take, whether they are broken or not. Nikunishi understands binary ...
n = int(input()) print(0 * (n == 0) + len(str(bin(n))[2:]) * (n != 0))
{ "input": [ "0", "1", "2", "4", "9", "19", "38", "83", "159", "296", "000", "545", "1241", "2473", "6042", "9030", "17679", "33209", "96405", "140502", "299812", "763679", "1237235", "3", "7", "5", "6", "8...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Problem statement Meatishi can increase or decrease the number of fingers. There are n buns in front of Nikunishi-kun. Meatishi is trying to count the number of steamed buns by break...
p02274 The Number of Inversions_26366
For a given sequence $A = \\{a_0, a_1, ... a_{n-1}\\}$, the number of pairs $(i, j)$ where $a_i > a_j$ and $i < j$, is called the number of inversions. The number of inversions is equal to the number of swaps of Bubble Sort defined in the following program: bubbleSort(A) cnt = 0 // the number of inversions for i = 0 ...
import bisect #int bit[n+1],n def sum(i):#[1,i]のsumを求める s = 0 while(i > 0): s += bit[i] i = i&(i-1) return s def add(i,x):#i番目にxを加算 i & (-i):iの最後の1のbit while(i <= n): bit[i] += x i += i & (-i) n = int(input()) a = list(map(int,input().split())) aa = sorted(a) bit = [0...
{ "input": [ "3\n3 1 2", "5\n3 5 2 1 4", "3\n6 1 2", "5\n3 10 2 1 4", "3\n6 1 0", "5\n3 10 1 1 4", "3\n0 -1 1", "5\n1 6 1 0 0", "3\n-2 -2 -2", "5\n0 -13 17 1 0", "5\n2 0 -1 -2 -1", "5\n4 1 0 0 -1", "5\n2 1 0 -1 -3", "3\n6 2 0", "5\n5 10 1 1 4", "3\n6 2 1...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: For a given sequence $A = \\{a_0, a_1, ... a_{n-1}\\}$, the number of pairs $(i, j)$ where $a_i > a_j$ and $i < j$, is called the number of inversions. The number of inversions is equ...
p02421 Card Game_26370
Taro and Hanako are playing card games. They have n cards each, and they compete n turns. At each turn Taro and Hanako respectively puts out a card. The name of the animal consisting of alphabetical letters is written on each card, and the bigger one in lexicographical order becomes the winner of that turn. The winner ...
n = int(input()) t = 0 h = 0 for _ in range(n): tc, hc = input().split() if tc > hc: t += 3 elif tc < hc: h += 3 else: t += 1 h += 1 print(t, h)
{ "input": [ "3\ncat dog\nfish fish\nlion tiger", "3\nact dog\nfish fish\nlion tiger", "3\nact god\nfish fith\nlion tiger", "3\nuea goe\ndirh giuh\nnojk tiger", "3\nvea hpg\njrie giug\nnpjk rhget", "3\nv`f ggn\njrhd jgug\njnok ehrug", "3\nact god\nfish fish\nlion tiger", "3\nact god\nf...
6AIZU
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Taro and Hanako are playing card games. They have n cards each, and they compete n turns. At each turn Taro and Hanako respectively puts out a card. The name of the animal consisting ...
1003_A. Polycarp's Pockets_26380
Polycarp has n coins, the value of the i-th coin is a_i. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket. For example, if Polycarp has got six coins represented as an array a = [1, 2, 4, 3, 3, 2], he can distribute the coins into two ...
n = int(input()) mn = list(map(int, input().split())) k = 1 for i in range(1, 101): s = mn.count(i) if s > k: k = s print(k)
{ "input": [ "6\n1 2 4 3 3 2\n", "1\n100\n", "3\n58 59 58\n", "3\n1 1 1\n", "100\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n", "15\n1 1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Polycarp has n coins, the value of the i-th coin is a_i. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same ...
1027_B. Numbers on the Chessboard_26384
You are given a chessboard of size n × n. It is filled with numbers from 1 to n^2 in the following way: the first ⌈ (n^2)/(2) ⌉ numbers from 1 to ⌈ (n^2)/(2) ⌉ are written in the cells with even sum of coordinates from left to right from top to bottom. The rest n^2 - ⌈ (n^2)/(2) ⌉ numbers from ⌈ (n^2)/(2) ⌉ + 1 to n^2 ...
import sys n,q=map(int,sys.stdin.readline().strip().split()) nc=n # print(n,q) if(n%2==0): n2=int((n*n)/2) else: n2=int((n*n)/2)+1 n1=int(n/2) if(1==1): for i in range(q): x,y=map(int,sys.stdin.readline().strip().split()) # print(n,q,x,y) x1=int(x/2) y1=int(y/2) ...
{ "input": [ "5 4\n2 1\n4 2\n3 3\n3 4\n", "4 5\n1 1\n4 4\n4 3\n3 2\n2 4\n", "1 1\n1 1\n", "2 4\n1 1\n2 1\n1 2\n2 2\n", "2 4\n1 1\n2 2\n1 2\n2 2\n", "5 4\n2 1\n4 4\n3 3\n3 4\n", "4 5\n2 1\n4 4\n4 3\n3 2\n2 4\n", "2 4\n1 1\n2 2\n2 2\n2 2\n", "5 4\n2 1\n4 4\n3 3\n5 4\n", "4 5\n2 1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given a chessboard of size n × n. It is filled with numbers from 1 to n^2 in the following way: the first ⌈ (n^2)/(2) ⌉ numbers from 1 to ⌈ (n^2)/(2) ⌉ are written in the cell...
1091_D. New Year and the Permutation Concatenation_26392
Let n be an integer. Consider all permutations on integers 1 to n in lexicographic order, and concatenate them into one big sequence p. For example, if n = 3, then p = [1, 2, 3, 1, 3, 2, 2, 1, 3, 2, 3, 1, 3, 1, 2, 3, 2, 1]. The length of this sequence will be n ⋅ n!. Let 1 ≤ i ≤ j ≤ n ⋅ n! be a pair of indices. We cal...
n = int(input()) f_n = n cnt = 0 for k in range(n-1, 0, -1): cnt += f_n f_n *= k if f_n >= 998244353: f_n %= 998244353 print((n*f_n-cnt)%998244353)
{ "input": [ "4\n", "10\n", "3\n", "20\n", "8\n", "1872\n", "771623\n", "623847\n", "1\n", "324\n", "14\n", "15\n", "259813\n", "11\n", "2\n", "13\n", "98232\n", "17\n", "898934\n", "18\n", "6\n", "1248\n", "1000000\n", "9...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Let n be an integer. Consider all permutations on integers 1 to n in lexicographic order, and concatenate them into one big sequence p. For example, if n = 3, then p = [1, 2, 3, 1, 3,...
1110_B. Tape_26396
You have a long stick, consisting of m segments enumerated from 1 to m. Each segment is 1 centimeter long. Sadly, some segments are broken and need to be repaired. You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise, a piece...
n, m, k = (int(x) for x in input().split()) b = [int(x) for x in input().split()] deltaB = sorted([b[i + 1] - b[i] for i in range(n - 1)]) print(sum(deltaB[:n - k]) + k)
{ "input": [ "4 100 2\n20 30 75 80\n", "5 100 3\n1 2 4 60 87\n", "4 10 4\n1 3 6 10\n", "2 1000000000 1\n1 1000000000\n", "3 8 3\n1 2 6\n", "3 8 2\n4 6 8\n", "4 8 2\n2 3 6 8\n", "4 8 1\n3 4 6 8\n", "5 8 1\n2 4 5 6 7\n", "5 8 3\n3 5 6 7 8\n", "1 1000000000 1\n228\n", "4 8...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You have a long stick, consisting of m segments enumerated from 1 to m. Each segment is 1 centimeter long. Sadly, some segments are broken and need to be repaired. You have an infini...
1158_C. Permutation recovery_26402
Vasya has written some permutation p_1, p_2, …, p_n of integers from 1 to n, so for all 1 ≤ i ≤ n it is true that 1 ≤ p_i ≤ n and all p_1, p_2, …, p_n are different. After that he wrote n numbers next_1, next_2, …, next_n. The number next_i is equal to the minimal index i < j ≤ n, such that p_j > p_i. If there is no su...
import sys input = sys.stdin.readline T = int(input()) for _ in range(T): n = int(input()) l = list(map(int, input().split())) stack = [] out = [-1] * n curr = 0 works = True for i in range(n): while stack and stack[-1][0] == i: _, j = stack.pop() curr +...
{ "input": [ "6\n3\n2 3 4\n2\n3 3\n3\n-1 -1 -1\n3\n3 4 -1\n1\n2\n4\n4 -1 4 5\n", "6\n3\n2 3 4\n2\n3 3\n3\n-1 -1 -1\n3\n3 4 -1\n1\n2\n4\n4 -1 4 5\n", "10\n4\n2 4 4 5\n4\n2 -1 4 -1\n4\n4 5 5 5\n4\n2 3 4 5\n4\n2 3 4 5\n4\n-1 3 4 5\n4\n-1 3 4 5\n4\n3 3 4 5\n4\n3 5 5 5\n4\n5 4 5 5\n", "10\n4\n2 4 4 5\n4\n2...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Vasya has written some permutation p_1, p_2, …, p_n of integers from 1 to n, so for all 1 ≤ i ≤ n it is true that 1 ≤ p_i ≤ n and all p_1, p_2, …, p_n are different. After that he wro...
1180_B. Nick and Array_26406
Nick had received an awesome array of integers a=[a_1, a_2, ..., a_n] as a gift for his 5 birthday from his mother. He was already going to explore its various properties but after unpacking he was disappointed a lot because the product a_1 ⋅ a_2 ⋅ ... a_n of its elements seemed to him not large enough. He was ready t...
n=int(input()) list1=[*map(int,input().split())] list2=[] if n%2==0: for element in list1: if element>=0: print(-element-1) else: print(element) else: for element in list1: if element>=0: list2.append(-element-1) else: list2.append(...
{ "input": [ "1\n0\n", "4\n2 2 2 2\n", "3\n-3 -3 2\n", "3\n-1 -1 0\n", "3\n10 10 -10\n", "3\n-6 0 4\n", "3\n-79 -58 -55\n", "3\n-5 3 3\n", "4\n0 0 0 0\n", "5\n0 0 0 -4 -3\n", "5\n-4 0 0 0 1\n", "3\n-1 0 1\n", "1\n-2\n", "3\n-3 3 2\n", "3\n-5 -1 1\n", "3\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Nick had received an awesome array of integers a=[a_1, a_2, ..., a_n] as a gift for his 5 birthday from his mother. He was already going to explore its various properties but after un...
1199_B. Water Lily_26410
While sailing on a boat, Inessa noticed a beautiful water lily flower above the lake's surface. She came closer and it turned out that the lily was exactly H centimeters above the water surface. Inessa grabbed the flower and sailed the distance of L centimeters. Exactly at this point the flower touched the water surfac...
import math h, l = input().split() h = int(h) l = int(l) a = float((pow(l,2)-pow(h,2))/(2*h)) print(a)
{ "input": [ "3 5\n", "1 2\n", "3510 4371\n", "207434 496771\n", "117 485\n", "1 6\n", "999999 1000000\n", "1 100\n", "91306 947926\n", "882942 924458\n", "7882 399082\n", "1395 6977\n", "1 1000000\n", "324 637\n", "2115 5821\n", "5 9\n", "61 464\n",...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: While sailing on a boat, Inessa noticed a beautiful water lily flower above the lake's surface. She came closer and it turned out that the lily was exactly H centimeters above the wat...
1216_A. Prefixes_26414
Nikolay got a string s of even length n, which consists only of lowercase Latin letters 'a' and 'b'. Its positions are numbered from 1 to n. He wants to modify his string so that every its prefix of even length has an equal amount of letters 'a' and 'b'. To achieve that, Nikolay can perform the following operation arb...
l = int(input()) s = list(input().strip()) ct = 0 for i in range(0,l-1,2): if s[i] == s[i+1]: ct += 1 if s[i] == 'a': s[i] = 'b' else: s[i] = 'a' print(ct) print(''.join(s))
{ "input": [ "6\nababab\n", "4\nbbbb\n", "2\naa\n", "4\nbbbb\n", "6\nbbbbba\n", "8\nbbbabbba\n", "8\nbbabbbaa\n", "4\nbbba\n", "6\nabbbbb\n", "8\nbbbababa\n", "8\nababbbba\n", "6\nbababa\n", "4\nabbb\n", "6\nbbbbbb\n", "8\nabababbb\n", "8\naabbbbba\n", ...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Nikolay got a string s of even length n, which consists only of lowercase Latin letters 'a' and 'b'. Its positions are numbered from 1 to n. He wants to modify his string so that eve...
1239_B. The World Is Just a Programming Task (Hard Version)_26418
This is a harder version of the problem. In this version, n ≤ 300 000. Vasya is an experienced developer of programming competitions' problems. As all great minds at some time, Vasya faced a creative crisis. To improve the situation, Petya gifted him a string consisting of opening and closing brackets only. Petya beli...
def get_bal(): bal = [0] * n bal[0] = u[0] for i in range(1, n): bal[i] = bal[i - 1] + u[i] min_b = min(bal) ans = 0 for i in range(n): if bal[i] == min_b: ans += 1 return ans n = int(input()) u = list(input()) for i in range(n): if u[i] == '(': u[i]...
{ "input": [ "6\n)))(()\n", "10\n()()())(()\n", "12\n)(()(()())()\n", "100\n((()()))(()()))(())))((()((()()))(()))())((()(())(((())())((()))())))((()(())((())(())())))(()((())(\n", "1\n(\n", "10\n())(((()))\n", "499\n)(()))))(())(((())())()()(())))(()))))(())))()())()(((((()))()(())()()(((...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: This is a harder version of the problem. In this version, n ≤ 300 000. Vasya is an experienced developer of programming competitions' problems. As all great minds at some time, Vasya...
1257_D. Yet Another Monster Killing Problem_26422
You play a computer game. In this game, you lead a party of m heroes, and you have to clear a dungeon with n monsters. Each monster is characterized by its power a_i. Each hero is characterized by his power p_i and endurance s_i. The heroes clear the dungeon day by day. In the beginning of each day, you choose a hero ...
import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.wri...
{ "input": [ "2\n6\n2 3 11 14 1 8\n2\n3 2\n100 1\n5\n3 5 100 2 3\n2\n30 5\n90 1\n", "2\n6\n2 3 11 14 1 8\n2\n3 2\n100 1\n5\n3 5 100 2 3\n2\n30 5\n95 1\n", "2\n6\n3 3 11 14 1 8\n2\n3 1\n100 1\n5\n3 5 100 2 3\n2\n30 5\n90 1\n", "2\n6\n2 3 11 14 1 8\n2\n3 2\n000 1\n5\n3 5 100 2 3\n2\n30 5\n90 1\n", "...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You play a computer game. In this game, you lead a party of m heroes, and you have to clear a dungeon with n monsters. Each monster is characterized by its power a_i. Each hero is cha...
1300_D. Aerodynamic_26427
Guy-Manuel and Thomas are going to build a polygon spaceship. You're given a strictly convex (i. e. no three points are collinear) polygon P which is defined by coordinates of its vertices. Define P(x,y) as a polygon obtained by translating P by vector \overrightarrow {(x,y)}. The picture below depicts an example of t...
import sys import math from collections import defaultdict from collections import deque from itertools import combinations from itertools import permutations input = lambda : sys.stdin.readline().rstrip() read = lambda : list(map(int, input().split())) go = lambda : 1/0 def write(*args, sep="\n"): for i in args: ...
{ "input": [ "4\n1 0\n4 1\n3 4\n0 3\n", "8\n0 0\n1 0\n2 1\n3 3\n4 6\n3 6\n2 5\n1 3\n", "3\n100 86\n50 0\n150 0\n", "6\n-99555247 -9420873\n-68495517 -72858523\n-56392372 -82582689\n-45496035 -89051170\n-76555765 -25613520\n-88658910 -15889354\n", "4\n15618728 -98772746\n91392611 40588059\n88444454...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Guy-Manuel and Thomas are going to build a polygon spaceship. You're given a strictly convex (i. e. no three points are collinear) polygon P which is defined by coordinates of its ve...
1324_E. Sleeping Schedule_26431
Vova had a pretty weird sleeping schedule. There are h hours in a day. Vova will sleep exactly n times. The i-th time he will sleep exactly after a_i hours from the time he woke up. You can assume that Vova woke up exactly at the beginning of this story (the initial time is 0). Each time Vova sleeps exactly one day (in...
def indices(arr): ind = [] for i, val in enumerate(arr): if val >= 0: ind.append(i) return ind def e(hours, mem, lo, hi, hour_day): for i in range(len(hours)): # for each day non_zero = indices(mem[i]) for v in non_zero: next_hour = (v + hours[i]) % ho...
{ "input": [ "7 24 21 23\n16 17 14 20 20 11 22\n", "62 51 43 50\n40 36 14 6 44 12 23 23 50 37 15 14 21 16 6 9 40 21 20 11 21 6 34 50 40 43 44 30 12 41 28 39 31 34 12 32 9 33 45 9 13 22 48 24 11 5 24 21 46 26 14 47 10 18 42 2 40 30 46 47 22 3\n", "39 14 6 10\n1 10 13 7 6 11 1 2 2 11 6 3 10 3 13 7 4 5 8 7 9...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Vova had a pretty weird sleeping schedule. There are h hours in a day. Vova will sleep exactly n times. The i-th time he will sleep exactly after a_i hours from the time he woke up. Y...
1343_D. Constant Palindrome Sum_26435
You are given an array a consisting of n integers (it is guaranteed that n is even, i.e. divisible by 2). All a_i does not exceed some integer k. Your task is to replace the minimum number of elements (replacement is the following operation: choose some index i from 1 to n and replace a_i with some integer in range [1...
from bisect import bisect_left from collections import Counter def solve(n, k, a): s = [a[i] + a[n-i-1] for i in range(n//2)] amin = sorted([min(a[i], a[n-i-1]) for i in range(n//2)]) amax = sorted([max(a[i], a[n-i-1]) for i in range(n//2)]) ans = float('inf') counter = Counter(s) fo...
{ "input": [ "4\n4 2\n1 2 1 2\n4 3\n1 2 2 1\n8 7\n6 1 1 7 6 3 4 6\n6 6\n5 2 6 1 3 4\n", "1\n100\n86 366 161 188 28 209 450 355 100 241 153 5 249 238 333 368 423 173 284 416 451 311 114 258 150 113 239 441 454 422 418 20 409 212 63 205 287 68 70 152 349 345 86 335 473 481 143 171 439 445 12 281 47 224 158 31 1...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given an array a consisting of n integers (it is guaranteed that n is even, i.e. divisible by 2). All a_i does not exceed some integer k. Your task is to replace the minimum ...
1365_E. Maximum Subsequence Value_26439
Ridhiman challenged Ashish to find the maximum valued subsequence of an array a of size n consisting of positive integers. The value of a non-empty subsequence of k elements of a is defined as ∑ 2^i over all integers i ≥ 0 such that at least max(1, k - 2) elements of the subsequence have the i-th bit set in their bin...
n = int(input()) l = list(map(int,input().split())) ans = 0 for i in range(n): for j in range(i,n): for k in range(j,n):ans = max(ans,l[i] | l[j] | l[k]) print(ans)
{ "input": [ "3\n3 1 4\n", "4\n7 7 1 1\n", "1\n1\n", "3\n2 1 3\n", "2\n3 4\n", "10\n582366931603099761 314858607473442114 530263190370309150 871012489649491233 877068367969362781 671646356752418008 390155369686708364 958695211216189893 919124874293325142 196726357117434998\n", "20\n5410323...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: Ridhiman challenged Ashish to find the maximum valued subsequence of an array a of size n consisting of positive integers. The value of a non-empty subsequence of k elements of a is...
1385_E. Directing Edges_26443
You are given a graph consisting of n vertices and m edges. It is not guaranteed that the given graph is connected. Some edges are already directed and you can't change their direction. Other edges are undirected and you have to choose some direction for all these edges. You have to direct undirected edges in such a w...
from sys import stdin, gettrace from collections import deque if gettrace(): inputi = input else: def input(): return next(stdin)[:-1] def inputi(): return stdin.buffer.readline() def solve(): n,m = map(int, inputi().split()) dadjs = [[] for _ in range(n)] dadjd = [set() fo...
{ "input": [ "4\n3 1\n0 1 3\n5 5\n0 2 1\n1 1 5\n1 5 4\n0 5 2\n1 3 5\n4 5\n1 1 2\n0 4 3\n1 3 1\n0 2 3\n1 2 4\n4 5\n1 4 1\n1 1 3\n0 1 2\n1 2 4\n1 3 2\n", "4\n3 1\n0 1 3\n5 5\n1 2 1\n1 1 5\n1 5 4\n0 5 2\n1 3 5\n4 5\n1 1 2\n0 4 3\n1 3 1\n0 2 3\n1 2 4\n4 5\n1 4 1\n1 1 3\n0 1 2\n1 2 4\n1 3 2\n", "4\n3 1\n0 1 3\...
2CODEFORCES
Below is a problem description that describes the problem. Write code in Python that appropriately solves the problem. ### Description: You are given a graph consisting of n vertices and m edges. It is not guaranteed that the given graph is connected. Some edges are already directed and you can't change their directio...
1407_C. Chocolate Bunny_26446
This is an interactive problem. We hid from you a permutation p of length n, consisting of the elements from 1 to n. You want to guess it. To do that, you can give us 2 different indices i and j, and we will reply with p_{i} mod p_{j} (remainder of division p_{i} by p_{j}). We have enough patience to answer at most 2...
import sys DEBUG = False def debug(*args): if not DEBUG: return print("\033[0;31m", end="", file=sys.stderr) print(*args, file=sys.stderr) print("\033[0m", end="", file=sys.stderr) sys.stderr.flush() def readInt(): line = input() while line == "": line = input() resu...
{ "input": [ "3\n\n1\n\n2\n\n1\n\n0", "8\n4 8 2 6 3 1 5 7\n", "10\n5 1 6 2 8 3 4 10 9 7\n", "4\n3 4 1 2\n", "5\n1 4 2 3 5\n", "3\n1 3 2\n", "5\n5 4 3 2 1\n", "10\n10 1 2 3 4 5 9 8 7 6\n", "7\n6 1 2 3 4 5 7\n", "1\n1\n", "2\n1 2\n", "2\n2 1\n", "10\n5 9 6 10 2 4 1 7 ...
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. We hid from you a permutation p of length n, consisting of the elements from 1 to n. You want to guess it. To do that, you can give us 2 different ind...