problem_id
stringlengths
3
7
contestId
stringclasses
660 values
problem_index
stringclasses
27 values
programmingLanguage
stringclasses
3 values
testset
stringclasses
5 values
incorrect_passedTestCount
float64
0
146
incorrect_timeConsumedMillis
float64
15
4.26k
incorrect_memoryConsumedBytes
float64
0
271M
incorrect_submission_id
stringlengths
7
9
incorrect_source
stringlengths
10
27.7k
correct_passedTestCount
float64
2
360
correct_timeConsumedMillis
int64
30
8.06k
correct_memoryConsumedBytes
int64
0
475M
correct_submission_id
stringlengths
7
9
correct_source
stringlengths
28
21.2k
contest_name
stringclasses
664 values
contest_type
stringclasses
3 values
contest_start_year
int64
2.01k
2.02k
time_limit
float64
0.5
15
memory_limit
float64
64
1.02k
title
stringlengths
2
54
description
stringlengths
35
3.16k
input_format
stringlengths
67
1.76k
output_format
stringlengths
18
1.06k
⌀
interaction_format
null
note
stringclasses
840 values
examples
stringlengths
34
1.16k
rating
int64
800
3.4k
⌀
tags
stringclasses
533 values
testset_size
int64
2
360
official_tests
stringlengths
44
19.7M
official_tests_complete
bool
1 class
input_mode
stringclasses
1 value
generated_checker
stringclasses
231 values
executable
bool
1 class
793/A
793
A
Python 3
TESTS
21
140
9,523,200
75689481
s,d=map(int,input().split()) l=list(map(int,input().split())) r=min(l) p=sum(l) u=p-(r*s) if u%d==0: print(u//d) else: print(-1)
88
108
16,179,200
123917895
a,b=map(int,input().split()) c=list(map(int,input().split())) mi=min(c) for i in c: if (i-mi)%b:print(-1);exit() print((sum(c)-a*mi )//b)
Tinkoff Challenge - Elimination Round
CF
2,017
1
256
Oleg and shares
Oleg the bank client checks share prices every day. There are n share prices he is interested in. Today he observed that each second exactly one of these prices decreases by k rubles (note that each second exactly one price changes, but at different seconds different prices can change). Prices can become negative. Oleg...
The first line contains two integers n and k (1 ≤ n ≤ 105, 1 ≤ k ≤ 109) — the number of share prices, and the amount of rubles some price decreases each second. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the initial prices.
Print the only line containing the minimum number of seconds needed for prices to become equal, of «-1» if it is impossible.
null
Consider the first example. Suppose the third price decreases in the first second and become equal 12 rubles, then the first price decreases and becomes equal 9 rubles, and in the third second the third price decreases again and becomes equal 9 rubles. In this case all prices become equal 9 rubles in 3 seconds. There...
[{"input": "3 3\n12 9 15", "output": "3"}, {"input": "2 2\n10 9", "output": "-1"}, {"input": "4 1\n1 1000000000 1000000000 1000000000", "output": "2999999997"}]
900
["implementation", "math"]
88
[{"input": "3 3\r\n12 9 15\r\n", "output": "3"}, {"input": "2 2\r\n10 9\r\n", "output": "-1"}, {"input": "4 1\r\n1 1000000000 1000000000 1000000000\r\n", "output": "2999999997"}, {"input": "1 11\r\n123\r\n", "output": "0"}, {"input": "20 6\r\n38 86 86 50 98 62 32 2 14 62 98 50 2 50 32 38 62 62 8 14\r\n", "output": "151...
false
stdio
null
true
356/C
356
C
Python 3
TESTS
3
93
307,200
92567009
n=int(input()) people=list(map(int,input().split())) if sum(people)>n*4 or sum(people)<3 or sum(people)==5: print(-1) else: dict_count = {1:0,2:0,3:0,4:0} num_si=len(people)%3 num_san=len(people)//3-num_si for key in people: dict_count[key] = dict_count.get(key, 0) + 1 if dict_count[1]==...
141
607
14,745,600
42135284
#! /usr/bin/env python n = int(input()) counts = [0] * 5 nums = [int(x) for x in input().split()] for x in nums: counts[x] += 1 s = sum(nums) if s > 2 and s != 5: ans = 0 if counts[1] >= counts[2]: ans += counts[2] counts[3] += counts[2] counts[1] -= counts[2] ans += 2 * (c...
Codeforces Round 207 (Div. 1)
CF
2,013
1
256
Compartments
A team of students from the city S is sent to the All-Berland Olympiad in Informatics. Traditionally, they go on the train. All students have bought tickets in one carriage, consisting of n compartments (each compartment has exactly four people). We know that if one compartment contain one or two students, then they ge...
The first line contains integer n (1 ≤ n ≤ 106) — the number of compartments in the carriage. The second line contains n integers a1, a2, ..., an showing how many students ride in each compartment (0 ≤ ai ≤ 4). It is guaranteed that at least one student is riding in the train.
If no sequence of swapping seats with other people leads to the desired result, print number "-1" (without the quotes). In another case, print the smallest number of people you need to persuade to swap places.
null
null
[{"input": "5\n1 2 2 4 3", "output": "2"}, {"input": "3\n4 1 1", "output": "2"}, {"input": "4\n0 3 0 4", "output": "0"}]
2,100
["combinatorics", "constructive algorithms", "greedy", "implementation"]
141
[{"input": "5\r\n1 2 2 4 3\r\n", "output": "2\r\n"}, {"input": "3\r\n4 1 1\r\n", "output": "2\r\n"}, {"input": "4\r\n0 3 0 4\r\n", "output": "0\r\n"}, {"input": "5\r\n4 4 3 3 1\r\n", "output": "1\r\n"}, {"input": "5\r\n4 3 4 2 4\r\n", "output": "1\r\n"}, {"input": "10\r\n2 1 2 3 4 1 3 4 4 4\r\n", "output": "2\r\n"}, {"...
false
stdio
null
true
79/C
79
C
Python 3
TESTS
7
124
0
21629152
#On récupère les données chaine = input() n = int(input()) borings = [""] * n for i in range(n): borings[i] = input(); #Approche dynamique def f(debut): if debut == len(chaine) - 1: return 0, 0 length, pos = f(debut+1) n_len = len(chaine) - debut for bi in borings: end = chaine....
80
436
716,800
5639831
s, n = input(), int(input()) t = [input() for i in range(n)] def f(i): global t for j in range(n): if i < j: if len(t[j]) < len(t[i]) and t[j] in t[i]: return False elif j < i and t[j] in t[i]: return False return True t = [t[i] for i in range(n) if f(i)] n = len(s) r = [0] * n...
Codeforces Beta Round 71
CF
2,011
2
256
Beaver
After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string s, and she tried to remember the string s correctly. However, Ciel fee...
In the first line there is a string s. The length of s will be between 1 and 105, inclusive. In the second line there is a single integer n (1 ≤ n ≤ 10). Next n lines, there is a string bi (1 ≤ i ≤ n). Each length of bi will be between 1 and 10, inclusive. Each character of the given strings will be either a English...
Output in the first line two space-separated integers len and pos: the length of the longest contiguous substring of s that does not contain any bi, and the first position of the substring (0-indexed). The position pos must be between 0 and |s| - len inclusive, where |s| is the length of string s. If there are several...
null
In the first sample, the solution is traight_alon. In the second sample, the solution is an empty string, so the output can be «0 0», «0 1», «0 2», and so on. In the third sample, the solution is either nagio or oisii.
[{"input": "Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse", "output": "12 4"}, {"input": "IhaveNoIdea\n9\nI\nh\na\nv\ne\nN\no\nI\nd", "output": "0 0"}, {"input": "unagioisii\n2\nioi\nunagi", "output": "5 5"}]
1,800
["data structures", "dp", "greedy", "hashing", "strings", "two pointers"]
80
[{"input": "Go_straight_along_this_street\r\n5\r\nstr\r\nlong\r\ntree\r\nbiginteger\r\nellipse\r\n", "output": "12 4\r\n"}, {"input": "IhaveNoIdea\r\n9\r\nI\r\nh\r\na\r\nv\r\ne\r\nN\r\no\r\nI\r\nd\r\n", "output": "0 0\r\n"}, {"input": "unagioisii\r\n2\r\nioi\r\nunagi\r\n", "output": "5 5\r\n"}, {"input": "abcabcabcabc\...
false
stdio
import sys def main(): input_path, output_path, submission_path = sys.argv[1:] # Read input with open(input_path, 'r') as f: s = f.readline().strip() n = int(f.readline()) forbidden = [f.readline().strip() for _ in range(n)] # Read submission output try: wi...
true
581/C
581
C
PyPy 3-64
TESTS
4
46
0
201116195
from sys import stdin ,stdout input=stdin.readline inp=lambda : map(int,input().split()) def print(*args, end='\n', sep=' ') -> None: stdout.write(sep.join(map(str, args)) + end) n,k=inp() ; arr=list(inp()) ; arr2=[] ;ans=0 for i in range(n) : arr2.append([-(arr[i]%10) , arr[i]]) arr2.sort() for i in range...
98
124
6,553,600
204989006
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n, k = map(int, input().split()) a = list(map(int, input().split())) cnt = [0] * 101 for i in a: cnt[i] += 1 for i in range(1, 11): for j in range(10, 101, 10): u = cnt[j - i] c = min(u * i, k) // i cnt[j - ...
Codeforces Round 322 (Div. 2)
CF
2,015
1
256
Developing Skills
Petya loves computer games. Finally a game that he's been waiting for so long came out! The main character of this game has n different skills, each of which is characterized by an integer ai from 0 to 100. The higher the number ai is, the higher is the i-th skill of the character. The total rating of the character is...
The first line of the input contains two positive integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ 107) — the number of skills of the character and the number of units of improvements at Petya's disposal. The second line of the input contains a sequence of n integers ai (0 ≤ ai ≤ 100), where ai characterizes the level of the i-...
The first line of the output should contain a single non-negative integer — the maximum total rating of the character that Petya can get using k or less improvement units.
null
In the first test case the optimal strategy is as follows. Petya has to improve the first skill to 10 by spending 3 improvement units, and the second skill to 10, by spending one improvement unit. Thus, Petya spends all his improvement units and the total rating of the character becomes equal to lfloor frac{100}{10} r...
[{"input": "2 4\n7 9", "output": "2"}, {"input": "3 8\n17 15 19", "output": "5"}, {"input": "2 2\n99 100", "output": "20"}]
1,400
["implementation", "math", "sortings"]
98
[{"input": "2 4\r\n7 9\r\n", "output": "2\r\n"}, {"input": "3 8\r\n17 15 19\r\n", "output": "5\r\n"}, {"input": "2 2\r\n99 100\r\n", "output": "20\r\n"}, {"input": "100 10000\r\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
false
stdio
null
true
798/B
798
B
Python 3
TESTS
46
93
512,000
146538383
from collections import defaultdict words = defaultdict(list) indices= defaultdict(list) tc=int(input()) ind=1 wl="" wrds=[] wordlen=0 for j in range(tc): s=input() wrds.append(s) if(j==0): wl=s wordlen=len(wl) for i in range(len(wl)): words[wl[0]].append(wl) indices[wl[0]].append(ind) ww=wl[0] #print(ww) ...
99
62
5,529,600
26546464
import sys import math n = int(input()) s = [] for i in range(n): st = input(); s.append(st); inds = [] ans = 50000000 for o in range(n): fail = False cur = 0 for i in range(n): s2 = s[i] + s[i] v = s2.find(s[o]) if v == -1: fail = True cur += v if f...
Codeforces Round 410 (Div. 2)
CF
2,017
2
256
Mike and strings
Mike has n strings s1, s2, ..., sn each consisting of lowercase English letters. In one move he can choose a string si, erase the first character and append it to the end of the string. For example, if he has the string "coolmike", in one move he can transform it into the string "oolmikec". Now Mike asks himself: what...
The first line contains integer n (1 ≤ n ≤ 50) — the number of strings. This is followed by n lines which contain a string each. The i-th line corresponding to string si. Lengths of strings are equal. Lengths of each string is positive and don't exceed 50.
Print the minimal number of moves Mike needs in order to make all the strings equal or print - 1 if there is no solution.
null
In the first sample testcase the optimal scenario is to perform operations in such a way as to transform all strings into "zwoxz".
[{"input": "4\nxzzwo\nzwoxz\nzzwox\nxzzwo", "output": "5"}, {"input": "2\nmolzv\nlzvmo", "output": "2"}, {"input": "3\nkc\nkc\nkc", "output": "0"}, {"input": "3\naa\naa\nab", "output": "-1"}]
1,300
["brute force", "dp", "strings"]
99
[{"input": "4\r\nxzzwo\r\nzwoxz\r\nzzwox\r\nxzzwo\r\n", "output": "5\r\n"}, {"input": "2\r\nmolzv\r\nlzvmo\r\n", "output": "2\r\n"}, {"input": "3\r\nkc\r\nkc\r\nkc\r\n", "output": "0\r\n"}, {"input": "3\r\naa\r\naa\r\nab\r\n", "output": "-1\r\n"}, {"input": "3\r\nkwkb\r\nkbkw\r\nbkwk\r\n", "output": "3\r\n"}, {"input":...
false
stdio
null
true
377/A
377
A
PyPy 3
TESTS
15
701
27,238,400
145535162
from random import randint, shuffle def neighbours(i, j): global n, m Dx = [-1, 0, 1, 0] Dy = [0, 1, 0, -1] ret = [] for dx, dy in zip(Dx, Dy): x = i + dx y = j + dy if 0 <= x < n and 0 <= y < m: ret.append((x, y)) return ret n, m, k = map(int, input().split()) G = [list(input().strip()) for _ in range...
89
249
19,148,800
172807201
import math import os import sys from bisect import bisect_left, bisect_right import math from collections import Counter, defaultdict, deque from functools import lru_cache from heapq import heappop, heappush import sys from io import BytesIO, IOBase # Fast IO Region BUFSIZE = 8192 import math import os import sys fr...
Codeforces Round 222 (Div. 1)
CF
2,013
2
256
Maze
Pavel loves grid mazes. A grid maze is an n × m rectangle maze where each cell is either empty, or is a wall. You can go from one cell to another only if both cells are empty and have a common side. Pavel drew a grid maze with all empty cells forming a connected area. That is, you can go from any empty cell to any oth...
The first line contains three integers n, m, k (1 ≤ n, m ≤ 500, 0 ≤ k < s), where n and m are the maze's height and width, correspondingly, k is the number of walls Pavel wants to add and letter s represents the number of empty cells in the original maze. Each of the next n lines contains m characters. They describe t...
Print n lines containing m characters each: the new maze that fits Pavel's requirements. Mark the empty cells that you transformed into walls as "X", the other cells must be left without changes (that is, "." and "#"). It is guaranteed that a solution exists. If there are multiple solutions you can output any of them.
null
null
[{"input": "3 4 2\n#..#\n..#.\n#...", "output": "#.X#\nX.#.\n#..."}, {"input": "5 4 5\n#...\n#.#.\n.#..\n...#\n.#.#", "output": "#XXX\n#X#.\nX#..\n...#\n.#.#"}]
1,600
["dfs and similar"]
89
[{"input": "3 4 2\r\n#..#\r\n..#.\r\n#...\r\n", "output": "#.X#\r\nX.#.\r\n#...\r\n"}, {"input": "5 4 5\r\n#...\r\n#.#.\r\n.#..\r\n...#\r\n.#.#\r\n", "output": "#XXX\r\n#X#.\r\nX#..\r\n...#\r\n.#.#\r\n"}, {"input": "3 3 2\r\n...\r\n.#.\r\n...\r\n", "output": "X..\r\nX#.\r\n...\r\n"}, {"input": "3 3 2\r\n#.#\r\n...\r\n#...
false
stdio
import sys from collections import deque def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path) as f: lines = f.readlines() first_line = lines[0].strip().split() n, m, k = map(int, first_line[:3]) original = [line.strip() ...
true
138/A
138
A
Python 3
TESTS
4
122
307,200
15386254
#!/usr/bin/python3 N,K = [int(x) for x in input().strip().split()] #"aabb", "abab", "abba", "aaaa"; vowels = ['a','e','i','o','u'] schm = [] def check(val): for x in schm: if x == val or x == 4:continue return False return True def parse(line): k = K for x in range(-1,-len(line)-1,-1): if line[x] in vowels...
80
280
0
41983153
n, k = map(int, input().split()) ve = 'aeiou' abba, aabb, abab = 1, 1, 1 for j in range(n): a = ['']*4 for i in range(4): a[i] = input() l = len(a[i]) curr = 0 while l > 0 and curr < k: l -= 1 if a[i][l] in ve: curr += 1 ...
Codeforces Beta Round 99 (Div. 1)
CF
2,011
2
256
Literature Lesson
Vera adores poems. All the poems Vera knows are divided into quatrains (groups of four lines) and in each quatrain some lines contain rhymes. Let's consider that all lines in the poems consist of lowercase Latin letters (without spaces). Letters "a", "e", "i", "o", "u" are considered vowels. Two lines rhyme if their ...
The first line contains two integers n and k (1 ≤ n ≤ 2500, 1 ≤ k ≤ 5) — the number of quatrains in the poem and the vowel's number, correspondingly. Next 4n lines contain the poem. Each line is not empty and only consists of small Latin letters. The total length of the lines does not exceed 104. If we assume that the...
Print the rhyme scheme of the poem as "aabb", "abab", "abba", "aaaa"; or "NO" if the poem does not belong to any of the above mentioned schemes.
null
In the last sample both quatrains have rhymes but finding the common scheme is impossible, so the answer is "NO".
[{"input": "1 1\nday\nmay\nsun\nfun", "output": "aabb"}, {"input": "1 1\nday\nmay\ngray\nway", "output": "aaaa"}, {"input": "2 1\na\na\na\na\na\na\ne\ne", "output": "aabb"}, {"input": "2 1\nday\nmay\nsun\nfun\ntest\nhill\nfest\nthrill", "output": "NO"}]
1,600
["implementation"]
80
[{"input": "1 1\r\nday\r\nmay\r\nsun\r\nfun\r\n", "output": "aabb\r\n"}, {"input": "1 1\r\nday\r\nmay\r\ngray\r\nway\r\n", "output": "aaaa\r\n"}, {"input": "2 1\r\na\r\na\r\na\r\na\r\na\r\na\r\ne\r\ne\r\n", "output": "aabb\r\n"}, {"input": "2 1\r\nday\r\nmay\r\nsun\r\nfun\r\ntest\r\nhill\r\nfest\r\nthrill\r\n", "output...
false
stdio
null
true
962/B
962
B
PyPy 3
TESTS
23
140
3,174,400
94204442
from sys import stdin,stdout from math import gcd st=lambda:list(stdin.readline().strip()) li=lambda:list(map(int,stdin.readline().split())) mp=lambda:map(int,stdin.readline().split()) inp=lambda:int(stdin.readline()) pr=lambda n: stdout.write(str(n)+"\n") mod=1000000007 def solve(): n,a,b=mp() ans=0 s=...
93
77
11,878,400
185453304
n,a,b = [int(x) for x in input().split()] s = [i for i in input()] if a < b: a,b = b,a preva = False prevb = False ans = 0 for i in range(n): if s[i] == '*': preva = False prevb = False else: if preva == False and a > 0: a -= 1 ans += 1 preva = Tru...
Educational Codeforces Round 42 (Rated for Div. 2)
ICPC
2,018
2
256
Students in Railway Carriage
There are $$$n$$$ consecutive seat places in a railway carriage. Each place is either empty or occupied by a passenger. The university team for the Olympiad consists of $$$a$$$ student-programmers and $$$b$$$ student-athletes. Determine the largest number of students from all $$$a+b$$$ students, which you can put in t...
The first line contain three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$1 \le n \le 2\cdot10^{5}$$$, $$$0 \le a, b \le 2\cdot10^{5}$$$, $$$a + b > 0$$$) — total number of seat places in the railway carriage, the number of student-programmers and the number of student-athletes. The second line contains a string with len...
Print the largest number of students, which you can put in the railway carriage so that no student-programmer is sitting next to a student-programmer and no student-athlete is sitting next to a student-athlete.
null
In the first example you can put all student, for example, in the following way: *.AB* In the second example you can put four students, for example, in the following way: *BAB*B In the third example you can put seven students, for example, in the following way: B*ABAB**A*B The letter A means a student-programmer, an...
[{"input": "5 1 1\n*...*", "output": "2"}, {"input": "6 2 3\n*...*.", "output": "4"}, {"input": "11 3 10\n.*....**.*.", "output": "7"}, {"input": "3 2 3\n***", "output": "0"}]
1,300
["constructive algorithms", "greedy", "implementation"]
93
[{"input": "5 1 1\r\n*...*\r\n", "output": "2\r\n"}, {"input": "6 2 3\r\n*...*.\r\n", "output": "4\r\n"}, {"input": "11 3 10\r\n.*....**.*.\r\n", "output": "7\r\n"}, {"input": "3 2 3\r\n***\r\n", "output": "0\r\n"}, {"input": "9 5 3\r\n*...*...*\r\n", "output": "6\r\n"}, {"input": "9 2 4\r\n*...*...*\r\n", "output": "6...
false
stdio
null
true
676/C
676
C
PyPy 3
TESTS
68
187
28,979,200
87642405
import os from math import* n,k=map(int,input().split()) arr=input() arr=list(arr) a=list(filter(lambda x:x=="a",arr)) b=list(filter(lambda x:x=="b",arr)) x="" if len(a)>=len(b): x="b" else: x="a" if k==0: ans=0 count=1 for i in range(n-1): if arr[i]==arr[i+1]: count+=1 else: if ans<count: ans=coun...
117
77
2,355,200
175277835
n,k=map(int,input().split()) c=k s=input() L=0 R=0 ans=0 a=0 b=0 while R<n and L<n: le=R-L+1 if le >ans: if s[R]=='a': a+=1 else: b+=1 if a>b and b<=k: ans=le elif a<=b and a<=k: ans=le else: if s[L]=='a': ...
Codeforces Round 354 (Div. 2)
CF
2,016
1
256
Vasya and String
High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters. Vasya can change no more than k characters of the original string. W...
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, 0 ≤ k ≤ n) — the length of the string and the maximum number of characters to change. The second line contains the string, consisting of letters 'a' and 'b' only.
Print the only integer — the maximum beauty of the string Vasya can achieve by changing no more than k characters.
null
In the first sample, Vasya can obtain both strings "aaaa" and "bbbb". In the second sample, the optimal answer is obtained with the string "aaaaabaa" or with the string "aabaaaaa".
[{"input": "4 2\nabba", "output": "4"}, {"input": "8 1\naabaabaa", "output": "5"}]
1,500
["binary search", "dp", "strings", "two pointers"]
117
[{"input": "4 2\r\nabba\r\n", "output": "4\r\n"}, {"input": "8 1\r\naabaabaa\r\n", "output": "5\r\n"}, {"input": "1 0\r\na\r\n", "output": "1\r\n"}, {"input": "1 1\r\nb\r\n", "output": "1\r\n"}, {"input": "1 0\r\nb\r\n", "output": "1\r\n"}, {"input": "1 1\r\na\r\n", "output": "1\r\n"}, {"input": "10 10\r\nbbbbbbbbbb\r\...
false
stdio
null
true
676/E
676
E
Python 3
TESTS
8
93
307,200
83182763
import sys n, k = sys.stdin.readline().split(" ") n = int(n) k = int(k) a = [] i = 0 faltan = 0 turno = 0 while i <= n: a.append(sys.stdin.readline()[:-1]) if(a[-1] == "?"): faltan += 1 else: turno = 1 - turno i += 1 gano = False if(k == 0): if(a[0] == 0): gano = True ...
89
218
28,876,800
18248585
import sys import math def calculate(A, k, x): res = 0 if abs(k) >= 2: for a in reversed(A): res = k*res + a if abs(res) > x: return float('inf') return res else: for a in reversed(A): res = k*res + a return res def solve(...
Codeforces Round 354 (Div. 2)
CF
2,016
1
256
The Last Fight Between Human and AI
100 years have passed since the last victory of the man versus computer in Go. Technologies made a huge step forward and robots conquered the Earth! It's time for the final fight between human and robot that will decide the faith of the planet. The following game was chosen for the fights: initially there is a polynom...
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, |k| ≤ 10 000) — the size of the polynomial and the integer k. The i-th of the following n + 1 lines contain character '?' if the coefficient near xi - 1 is yet undefined or the integer value ai, if the coefficient is already known ( - 10 000 ≤...
Print "Yes" (without quotes) if the human has winning strategy, or "No" (without quotes) otherwise.
null
In the first sample, computer set a0 to - 1 on the first move, so if human can set coefficient a1 to 0.5 and win. In the second sample, all coefficients are already set and the resulting polynomial is divisible by x - 100, so the human has won.
[{"input": "1 2\n-1\n?", "output": "Yes"}, {"input": "2 100\n-10000\n0\n1", "output": "Yes"}, {"input": "4 5\n?\n1\n?\n1\n?", "output": "No"}]
2,400
["math"]
89
[{"input": "1 2\r\n-1\r\n?\r\n", "output": "Yes\r\n"}, {"input": "2 100\r\n-10000\r\n0\r\n1\r\n", "output": "Yes"}, {"input": "4 5\r\n?\r\n1\r\n?\r\n1\r\n?\r\n", "output": "No"}, {"input": "68 -9959\r\n-3666\r\n-3501\r\n9169\r\n5724\r\n1478\r\n-643\r\n-3039\r\n-5537\r\n-4295\r\n-1856\r\n-6720\r\n6827\r\n-39\r\n-9509\r\...
false
stdio
null
true
676/E
676
E
PyPy 3
TESTS
8
93
0
197670205
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n, k = map(int, input().split()) a = [input().rstrip().decode() for _ in range(n + 1)] inf = pow(10, 9) + 1 b = [inf if i == "?" else int(i) for i in a] c = 0 for i in b: if i ^ inf: c += 1 if not k: ans = "No" if b[0] ...
89
265
7,168,000
18110108
n,k = map(int,input().split()) s = 0 a = 0 l = [] f = False for i in range(n+1): v = input() if v == '?': a += 1 if k == 0 and i == 0: f = True elif a==0: l.append(int(v)) l.reverse() if a == 0 and k != 0: for i in l: s = k*s + i if s ...
Codeforces Round 354 (Div. 2)
CF
2,016
1
256
The Last Fight Between Human and AI
100 years have passed since the last victory of the man versus computer in Go. Technologies made a huge step forward and robots conquered the Earth! It's time for the final fight between human and robot that will decide the faith of the planet. The following game was chosen for the fights: initially there is a polynom...
The first line of the input contains two integers n and k (1 ≤ n ≤ 100 000, |k| ≤ 10 000) — the size of the polynomial and the integer k. The i-th of the following n + 1 lines contain character '?' if the coefficient near xi - 1 is yet undefined or the integer value ai, if the coefficient is already known ( - 10 000 ≤...
Print "Yes" (without quotes) if the human has winning strategy, or "No" (without quotes) otherwise.
null
In the first sample, computer set a0 to - 1 on the first move, so if human can set coefficient a1 to 0.5 and win. In the second sample, all coefficients are already set and the resulting polynomial is divisible by x - 100, so the human has won.
[{"input": "1 2\n-1\n?", "output": "Yes"}, {"input": "2 100\n-10000\n0\n1", "output": "Yes"}, {"input": "4 5\n?\n1\n?\n1\n?", "output": "No"}]
2,400
["math"]
89
[{"input": "1 2\r\n-1\r\n?\r\n", "output": "Yes\r\n"}, {"input": "2 100\r\n-10000\r\n0\r\n1\r\n", "output": "Yes"}, {"input": "4 5\r\n?\r\n1\r\n?\r\n1\r\n?\r\n", "output": "No"}, {"input": "68 -9959\r\n-3666\r\n-3501\r\n9169\r\n5724\r\n1478\r\n-643\r\n-3039\r\n-5537\r\n-4295\r\n-1856\r\n-6720\r\n6827\r\n-39\r\n-9509\r\...
false
stdio
null
true
900/A
900
A
Python 3
TESTS
27
390
0
40556281
d={} d[0],d[1]=0,0 n=int(input()) for i in range(n): a,b=map(int,input().split()) if (a<0 and b<0) or (a<0 and b>0): d[0]+=1 else: d[1]+=1 if d[0]==0 and d[1]==n: print('YES') elif d[1]==0 and d[0]==n: print('YES') elif d[0]==1 and d[1]==n-1: print('YES') elif d[1]==1 and d[0]==n-1: print('YES') else: print...
71
171
0
200906483
pos = 0 neg = 0 for i in range(int(input())): a = int((input().split())[0]) if a > 0: pos += 1 else: neg += 1 if (neg <= 1 and pos >= 1) or (pos <= 1 and neg >= 1): print("Yes") else: print("No") # Wed Apr 05 2023 21:44:47 GMT+0300 (Moscow Standard Time)
Codeforces Round 450 (Div. 2)
CF
2,017
1
256
Find Extra One
You have n distinct points on a plane, none of them lie on OY axis. Check that there is a point after removal of which the remaining points are located on one side of the OY axis.
The first line contains a single positive integer n (2 ≤ n ≤ 105). The following n lines contain coordinates of the points. The i-th of these lines contains two single integers xi and yi (|xi|, |yi| ≤ 109, xi ≠ 0). No two points coincide.
Print "Yes" if there is such a point, "No" — otherwise. You can print every letter in any case (upper or lower).
null
In the first example the second point can be removed. In the second example there is no suitable for the condition point. In the third example any point can be removed.
[{"input": "3\n1 1\n-1 -1\n2 -1", "output": "Yes"}, {"input": "4\n1 1\n2 2\n-1 1\n-2 2", "output": "No"}, {"input": "3\n1 2\n2 1\n4 60", "output": "Yes"}]
800
["geometry", "implementation"]
71
[{"input": "3\r\n1 1\r\n-1 -1\r\n2 -1\r\n", "output": "Yes"}, {"input": "4\r\n1 1\r\n2 2\r\n-1 1\r\n-2 2\r\n", "output": "No"}, {"input": "3\r\n1 2\r\n2 1\r\n4 60\r\n", "output": "Yes"}, {"input": "10\r\n1 1\r\n2 2\r\n3 3\r\n4 4\r\n5 5\r\n6 6\r\n7 7\r\n8 8\r\n9 9\r\n-1 -1\r\n", "output": "Yes"}, {"input": "2\r\n1000000...
false
stdio
null
true
733/C
733
C
PyPy 3
TESTS
3
187
307,200
76748324
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...
138
77
307,200
21948315
def takefirst(a, s): curs = 0 for i in range(len(a)): curs += a[i] if curs == s: return i if curs > s: return -1 return -1 def maxid(a): if len(a) == 1: return 0 m = max(a) if a[0] == m: if a[1] < m: return 0 if a[-1] ==...
Codeforces Round 378 (Div. 2)
CF
2,016
1
256
Epidemic in Monstropolis
There was an epidemic in Monstropolis and all monsters became sick. To recover, all monsters lined up in queue for an appointment to the only doctor in the city. Soon, monsters became hungry and began to eat each other. One monster can eat other monster if its weight is strictly greater than the weight of the monster...
The first line contains single integer n (1 ≤ n ≤ 500) — the number of monsters in the initial queue. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the initial weights of the monsters. The third line contains single integer k (1 ≤ k ≤ n) — the number of monsters in the queue after the joke. Th...
In case if no actions could lead to the final queue, print "NO" (without quotes) in the only line. Otherwise print "YES" (without quotes) in the first line. In the next n - k lines print actions in the chronological order. In each line print x — the index number of the monster in the current queue which eats and, sepa...
null
In the first example, initially there were n = 6 monsters, their weights are [1, 2, 2, 2, 1, 2] (in order of queue from the first monster to the last monster). The final queue should be [5, 5]. The following sequence of eatings leads to the final queue: - the second monster eats the monster to the left (i.e. the first...
[{"input": "6\n1 2 2 2 1 2\n2\n5 5", "output": "YES\n2 L\n1 R\n4 L\n3 L"}, {"input": "5\n1 2 3 4 5\n1\n15", "output": "YES\n5 L\n4 L\n3 L\n2 L"}, {"input": "5\n1 1 1 3 3\n3\n2 1 6", "output": "NO"}]
1,800
["constructive algorithms", "dp", "greedy", "two pointers"]
139
[{"input": "6\r\n1 2 2 2 1 2\r\n2\r\n5 5\r\n", "output": "YES\r\n2 L\r\n1 R\r\n4 L\r\n3 L\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n1\r\n15\r\n", "output": "YES\r\n5 L\r\n4 L\r\n3 L\r\n2 L\r\n"}, {"input": "5\r\n1 1 1 3 3\r\n3\r\n2 1 6\r\n", "output": "NO"}, {"input": "5\r\n1 1 1 1 2\r\n3\r\n1 1 4\r\n", "output": "YES\r\n5 L...
false
stdio
import sys def read_file(path): with open(path, 'r') as f: return f.read().splitlines() input_path, output_path, submission_path = sys.argv[1], sys.argv[2], sys.argv[3] input_lines = read_file(input_path) n = int(input_lines[0]) a = list(map(int, input_lines[1].split())) k = int(input_lines[2]) b = list(...
true
900/A
900
A
Python 3
TESTS
27
390
5,632,000
34491219
def findQuad(pt): if pt[0] > 0 and pt[1] > 0: return 0 elif pt[0] < 0 and pt[1] > 0: return 1 elif pt[0] < 0 and pt[1] < 0: return 1 else: return 0 num = int(input()) cnt = [0,0] for _ in range(num): cnt[findQuad([int(x) for x in input().strip().split( " " )])] += 1 if cnt[0] == 1 or cnt[1] == 1 or cnt[0]...
71
171
0
221431492
n = int(input()) p = 0 o = 0 for i in range(n): s, t = map(int, input().split()) if s > 0: p += 1 else: o+=1 if (p == 1 or o == 1) or (p == 0 or o == 0): print("Yes") else: print("No")
Codeforces Round 450 (Div. 2)
CF
2,017
1
256
Find Extra One
You have n distinct points on a plane, none of them lie on OY axis. Check that there is a point after removal of which the remaining points are located on one side of the OY axis.
The first line contains a single positive integer n (2 ≤ n ≤ 105). The following n lines contain coordinates of the points. The i-th of these lines contains two single integers xi and yi (|xi|, |yi| ≤ 109, xi ≠ 0). No two points coincide.
Print "Yes" if there is such a point, "No" — otherwise. You can print every letter in any case (upper or lower).
null
In the first example the second point can be removed. In the second example there is no suitable for the condition point. In the third example any point can be removed.
[{"input": "3\n1 1\n-1 -1\n2 -1", "output": "Yes"}, {"input": "4\n1 1\n2 2\n-1 1\n-2 2", "output": "No"}, {"input": "3\n1 2\n2 1\n4 60", "output": "Yes"}]
800
["geometry", "implementation"]
71
[{"input": "3\r\n1 1\r\n-1 -1\r\n2 -1\r\n", "output": "Yes"}, {"input": "4\r\n1 1\r\n2 2\r\n-1 1\r\n-2 2\r\n", "output": "No"}, {"input": "3\r\n1 2\r\n2 1\r\n4 60\r\n", "output": "Yes"}, {"input": "10\r\n1 1\r\n2 2\r\n3 3\r\n4 4\r\n5 5\r\n6 6\r\n7 7\r\n8 8\r\n9 9\r\n-1 -1\r\n", "output": "Yes"}, {"input": "2\r\n1000000...
false
stdio
null
true
900/A
900
A
PyPy 3-64
TESTS
27
638
9,932,800
212368884
left=0 right=0 for _ in range(int(input())): x,y=map(int,input().split()) if x<0 and y<0 : left += 1 elif x<0 and y>0: left +=1 else: right += 1 if left<=1 or right<=1: print("Yes") else: print("No")
71
171
2,048,000
208897528
n = int(input()) l1 = [] l2 = [] for i in range(n): a = input().split() x = int(a[0]) y = int(a[1]) if x > 0: l1.append(1) else: l2.append(1) if len(l1) <= 1 or len(l2) <= 1: print("Yes") else: print("No") # Wed Jun 07 2023 16:16:45 GMT+0300 (Moscow Standard Time)
Codeforces Round 450 (Div. 2)
CF
2,017
1
256
Find Extra One
You have n distinct points on a plane, none of them lie on OY axis. Check that there is a point after removal of which the remaining points are located on one side of the OY axis.
The first line contains a single positive integer n (2 ≤ n ≤ 105). The following n lines contain coordinates of the points. The i-th of these lines contains two single integers xi and yi (|xi|, |yi| ≤ 109, xi ≠ 0). No two points coincide.
Print "Yes" if there is such a point, "No" — otherwise. You can print every letter in any case (upper or lower).
null
In the first example the second point can be removed. In the second example there is no suitable for the condition point. In the third example any point can be removed.
[{"input": "3\n1 1\n-1 -1\n2 -1", "output": "Yes"}, {"input": "4\n1 1\n2 2\n-1 1\n-2 2", "output": "No"}, {"input": "3\n1 2\n2 1\n4 60", "output": "Yes"}]
800
["geometry", "implementation"]
71
[{"input": "3\r\n1 1\r\n-1 -1\r\n2 -1\r\n", "output": "Yes"}, {"input": "4\r\n1 1\r\n2 2\r\n-1 1\r\n-2 2\r\n", "output": "No"}, {"input": "3\r\n1 2\r\n2 1\r\n4 60\r\n", "output": "Yes"}, {"input": "10\r\n1 1\r\n2 2\r\n3 3\r\n4 4\r\n5 5\r\n6 6\r\n7 7\r\n8 8\r\n9 9\r\n-1 -1\r\n", "output": "Yes"}, {"input": "2\r\n1000000...
false
stdio
null
true
982/A
982
A
Python 3
TESTS
16
108
0
39766999
a=int(input()) b=input() s='10'*a if a<=3: if b==s[:(a)]: print('Yes') else: print('No') elif a==4: if b==s[:a]: print('yes') elif '1001' in b: print('yes') else: print("no") else: if '000' in b: print('no') elif '11' in b: print('no')...
55
46
0
228949254
n = int(input()) s = input() s = "0" + s + "0" if "000" not in s and "11" not in s: print("Yes") else: print("No")
Codeforces Round 484 (Div. 2)
CF
2,018
1
256
Row
You're given a row with $$$n$$$ chairs. We call a seating of people "maximal" if the two following conditions hold: 1. There are no neighbors adjacent to anyone seated. 2. It's impossible to seat one more person without violating the first rule. The seating is given as a string consisting of zeros and ones ($$$0$$$ m...
The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of chairs. The next line contains a string of $$$n$$$ characters, each of them is either zero or one, describing the seating.
Output "Yes" (without quotation marks) if the seating is "maximal". Otherwise print "No". You are allowed to print letters in whatever case you'd like (uppercase or lowercase).
null
In sample case one the given seating is maximal. In sample case two the person at chair three has a neighbour to the right. In sample case three it is possible to seat yet another person into chair three.
[{"input": "3\n101", "output": "Yes"}, {"input": "4\n1011", "output": "No"}, {"input": "5\n10001", "output": "No"}]
1,200
["brute force", "constructive algorithms"]
55
[{"input": "3\r\n101\r\n", "output": "Yes\r\n"}, {"input": "4\r\n1011\r\n", "output": "No\r\n"}, {"input": "5\r\n10001\r\n", "output": "No\r\n"}, {"input": "1\r\n0\r\n", "output": "No\r\n"}, {"input": "1\r\n1\r\n", "output": "Yes\r\n"}, {"input": "100\r\n01010010101010010100100101010010101001010010010010100101010100101...
false
stdio
null
true
976/E
976
E
Python 3
TESTS
9
982
28,057,600
37770116
n, a, b = [int(x) for x in input().split()] mul = 2 ** a ms = [] for _ in range(n): h, d = [int(x) for x in input().split()] ms.append((h, d)) if b > 1: m = max(ms, key=lambda x: (x[0] * mul - x[0])) else: m = max(ms, key=lambda x: (x[0] * mul - x[1], x[0])) ms.remove(m) res = m[1] if b: res = m...
71
452
20,787,200
164051000
from sys import stdin,exit import heapq #Parsea una línea def parser(): return map(int, stdin.readline().split()) #Recibiendo los valores de n, a y b n,a,b=parser() #Máximo de hechizos de tipo 2 que tiene sentido utilizar b=min(b,n) #Inicializando las listas de vida y daño hp=[] dmg=[] #Recibiendo los parámetr...
Educational Codeforces Round 43 (Rated for Div. 2)
ICPC
2,018
1
256
Well played!
Recently Max has got himself into popular CCG "BrainStone". As "BrainStone" is a pretty intellectual game, Max has to solve numerous hard problems during the gameplay. Here is one of them: Max owns n creatures, i-th of them can be described with two numbers — its health hpi and its damage dmgi. Max also has two types ...
The first line contains three integers n, a, b (1 ≤ n ≤ 2·105, 0 ≤ a ≤ 20, 0 ≤ b ≤ 2·105) — the number of creatures, spells of the first type and spells of the second type, respectively. The i-th of the next n lines contain two number hpi and dmgi (1 ≤ hpi, dmgi ≤ 109) — description of the i-th creature.
Print single integer — maximum total damage creatures can deal.
null
In the first example Max should use the spell of the first type on the second creature, then the spell of the second type on the same creature. Then total damage will be equal to 15 + 6·2 = 27. In the second example Max should use the spell of the second type on the first creature, then the spell of the second type on...
[{"input": "2 1 1\n10 15\n6 1", "output": "27"}, {"input": "3 0 3\n10 8\n7 11\n5 2", "output": "26"}]
2,100
["greedy", "sortings"]
71
[{"input": "2 1 1\r\n10 15\r\n6 1\r\n", "output": "27\r\n"}, {"input": "3 0 3\r\n10 8\r\n7 11\r\n5 2\r\n", "output": "26\r\n"}, {"input": "1 0 0\r\n2 1\r\n", "output": "1\r\n"}, {"input": "1 0 200000\r\n1 2\r\n", "output": "2\r\n"}, {"input": "7 5 7\r\n29 25\r\n84 28\r\n34 34\r\n14 76\r\n85 9\r\n40 57\r\n99 88\r\n", "o...
false
stdio
null
true
769/C
769
C
PyPy 3
TESTS
48
389
46,284,800
25241476
def next_opt(s, x): if x[0]+1 != len(s): if s[x[0] + 1][x[1]] != '*': return ('D', (x[0]+1, x[1])) if x[1]-1 != -1: if s[x[0]][x[1]-1] != '*': return ('L', (x[0], x[1]-1)) if x[1] + 1 != len(s[0]): if s[x[0]][x[1] + 1] != '*': return ('R', (x[0], x...
89
374
49,971,200
230444836
from collections import deque n, m, k = map(int, input().split()) g = [input() for _ in range(n)] dists = [[float('inf')] * m for _ in range(n)] for i in range(n): for j in range(m): if g[i][j] == 'X': start, end = i, j dists[start][end] = 0 res = [] direct = ['D', 'L', 'R', 'U'] directs = [(1, 0), (0, -1),...
VK Cup 2017 - Qualification 1
CF
2,017
15
256
Cycle In Maze
The Robot is in a rectangular maze of size n × m. Each cell of the maze is either empty or occupied by an obstacle. The Robot can move between neighboring cells on the side left (the symbol "L"), right (the symbol "R"), up (the symbol "U") or down (the symbol "D"). The Robot can move to the cell only if it is empty. In...
The first line contains three integers n, m and k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 106) — the size of the maze and the length of the cycle. Each of the following n lines contains m symbols — the description of the maze. If the symbol equals to "." the current cell is empty. If the symbol equals to "*" the current cell is occ...
Print the lexicographically minimum Robot's way with the length exactly k, which starts and ends in the cell where initially Robot is. If there is no such way, print "IMPOSSIBLE"(without quotes).
null
In the first sample two cyclic ways for the Robot with the length 2 exist — "UD" and "RL". The second cycle is lexicographically less. In the second sample the Robot should move in the following way: down, left, down, down, left, left, left, right, right, right, up, up, right, up. In the third sample the Robot can't ...
[{"input": "2 3 2\n.**\nX..", "output": "RL"}, {"input": "5 6 14\n..***.\n*...X.\n..*...\n..*.**\n....*.", "output": "DLDDLLLRRRUURU"}, {"input": "3 3 4\n***\n*X*\n***", "output": "IMPOSSIBLE"}]
1,700
["*special", "dfs and similar", "graphs", "greedy", "shortest paths"]
89
[{"input": "2 3 2\r\n.**\r\nX..\r\n", "output": "RL\r\n"}, {"input": "5 6 14\r\n..***.\r\n*...X.\r\n..*...\r\n..*.**\r\n....*.\r\n", "output": "DLDDLLLRRRUURU\r\n"}, {"input": "3 3 4\r\n***\r\n*X*\r\n***\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "1 1 1\r\nX\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "1 2 2\r\nX.\r...
false
stdio
null
true
426/B
426
B
Python 3
TESTS
5
46
0
9347611
n,m=input().split() n,m=int(n),int(m) lis=[] for i in range(n): lis.append(input().split()) def sym(lis): c=1 if len(lis)%2!=0: c=0 else: for i in range(len(lis)//2): if lis[i]!=lis[len(lis)-1-i]: c=0 break return c while sym(lis)==1: lis...
65
46
0
163438333
n, m = map(int, input().split()) arr = [input() for i in range(n)] while n % 2 == 0 and arr[:n] == list(reversed(arr[:n])): n //= 2 print(n)
Codeforces Round 243 (Div. 2)
CF
2,014
1
256
Sereja and Mirroring
Let's assume that we are given a matrix b of size x × y, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2x × y matrix c which has the following properties: - the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; - the lower half of matrix c (rows with number...
The first line contains two integers, n and m (1 ≤ n, m ≤ 100). Each of the next n lines contains m integers — the elements of matrix a. The i-th line contains integers ai1, ai2, ..., aim (0 ≤ aij ≤ 1) — the i-th row of the matrix a.
In the single line, print the answer to the problem — the minimum number of rows of matrix b.
null
In the first test sample the answer is a 2 × 3 matrix b: If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:
[{"input": "4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "output": "2"}, {"input": "3 3\n0 0 0\n0 0 0\n0 0 0", "output": "3"}, {"input": "8 1\n0\n1\n1\n0\n0\n1\n1\n0", "output": "2"}]
1,300
["implementation"]
65
[{"input": "4 3\r\n0 0 1\r\n1 1 0\r\n1 1 0\r\n0 0 1\r\n", "output": "2\r\n"}, {"input": "3 3\r\n0 0 0\r\n0 0 0\r\n0 0 0\r\n", "output": "3\r\n"}, {"input": "8 1\r\n0\r\n1\r\n1\r\n0\r\n0\r\n1\r\n1\r\n0\r\n", "output": "2\r\n"}, {"input": "10 4\r\n0 0 1 0\r\n0 0 1 0\r\n1 1 0 1\r\n0 0 1 1\r\n1 0 1 0\r\n1 0 1 0\r\n0 0 1 1\...
false
stdio
null
true
769/C
769
C
Python 3
TESTS
48
966
12,902,400
25228636
def down(row, col): try: if lab[row + 1][col] != '*': return True except IndexError: return False return False def left(row, col): if col == 0: return False try: if lab[row][col - 1] != '*': return True except IndexError: retur...
89
2,449
156,467,200
154562650
from collections import deque n, m, k = map(int, input().split()) if k % 2 != 0: print("IMPOSSIBLE") exit() grid = [[] for _ in range(n)] sr, sc = -1, -1 # starting row and column for r in range(n): grid[r] = input() c = grid[r].find('X') if c != -1: sr, sc = r, c # D L R U directions = {'...
VK Cup 2017 - Qualification 1
CF
2,017
15
256
Cycle In Maze
The Robot is in a rectangular maze of size n × m. Each cell of the maze is either empty or occupied by an obstacle. The Robot can move between neighboring cells on the side left (the symbol "L"), right (the symbol "R"), up (the symbol "U") or down (the symbol "D"). The Robot can move to the cell only if it is empty. In...
The first line contains three integers n, m and k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 106) — the size of the maze and the length of the cycle. Each of the following n lines contains m symbols — the description of the maze. If the symbol equals to "." the current cell is empty. If the symbol equals to "*" the current cell is occ...
Print the lexicographically minimum Robot's way with the length exactly k, which starts and ends in the cell where initially Robot is. If there is no such way, print "IMPOSSIBLE"(without quotes).
null
In the first sample two cyclic ways for the Robot with the length 2 exist — "UD" and "RL". The second cycle is lexicographically less. In the second sample the Robot should move in the following way: down, left, down, down, left, left, left, right, right, right, up, up, right, up. In the third sample the Robot can't ...
[{"input": "2 3 2\n.**\nX..", "output": "RL"}, {"input": "5 6 14\n..***.\n*...X.\n..*...\n..*.**\n....*.", "output": "DLDDLLLRRRUURU"}, {"input": "3 3 4\n***\n*X*\n***", "output": "IMPOSSIBLE"}]
1,700
["*special", "dfs and similar", "graphs", "greedy", "shortest paths"]
89
[{"input": "2 3 2\r\n.**\r\nX..\r\n", "output": "RL\r\n"}, {"input": "5 6 14\r\n..***.\r\n*...X.\r\n..*...\r\n..*.**\r\n....*.\r\n", "output": "DLDDLLLRRRUURU\r\n"}, {"input": "3 3 4\r\n***\r\n*X*\r\n***\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "1 1 1\r\nX\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "1 2 2\r\nX.\r...
false
stdio
null
true
769/C
769
C
Python 3
TESTS
48
1,044
14,848,000
25219973
a=input().split(' ') n=int(a[0]) m=int(a[1]) k=int(a[2]) path='' ar=[] impos=False for i in range(n): a=input() ar.append(list(a)) for j in range(m): if ar[i][j]=='X': xi=i xj=j if k%2==1: impos=True else: for i in range(int(k/2)): if xi!=n-1 and ar[xi+1][xj]!...
89
374
49,971,200
230444836
from collections import deque n, m, k = map(int, input().split()) g = [input() for _ in range(n)] dists = [[float('inf')] * m for _ in range(n)] for i in range(n): for j in range(m): if g[i][j] == 'X': start, end = i, j dists[start][end] = 0 res = [] direct = ['D', 'L', 'R', 'U'] directs = [(1, 0), (0, -1),...
VK Cup 2017 - Qualification 1
CF
2,017
15
256
Cycle In Maze
The Robot is in a rectangular maze of size n × m. Each cell of the maze is either empty or occupied by an obstacle. The Robot can move between neighboring cells on the side left (the symbol "L"), right (the symbol "R"), up (the symbol "U") or down (the symbol "D"). The Robot can move to the cell only if it is empty. In...
The first line contains three integers n, m and k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 106) — the size of the maze and the length of the cycle. Each of the following n lines contains m symbols — the description of the maze. If the symbol equals to "." the current cell is empty. If the symbol equals to "*" the current cell is occ...
Print the lexicographically minimum Robot's way with the length exactly k, which starts and ends in the cell where initially Robot is. If there is no such way, print "IMPOSSIBLE"(without quotes).
null
In the first sample two cyclic ways for the Robot with the length 2 exist — "UD" and "RL". The second cycle is lexicographically less. In the second sample the Robot should move in the following way: down, left, down, down, left, left, left, right, right, right, up, up, right, up. In the third sample the Robot can't ...
[{"input": "2 3 2\n.**\nX..", "output": "RL"}, {"input": "5 6 14\n..***.\n*...X.\n..*...\n..*.**\n....*.", "output": "DLDDLLLRRRUURU"}, {"input": "3 3 4\n***\n*X*\n***", "output": "IMPOSSIBLE"}]
1,700
["*special", "dfs and similar", "graphs", "greedy", "shortest paths"]
89
[{"input": "2 3 2\r\n.**\r\nX..\r\n", "output": "RL\r\n"}, {"input": "5 6 14\r\n..***.\r\n*...X.\r\n..*...\r\n..*.**\r\n....*.\r\n", "output": "DLDDLLLRRRUURU\r\n"}, {"input": "3 3 4\r\n***\r\n*X*\r\n***\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "1 1 1\r\nX\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "1 2 2\r\nX.\r...
false
stdio
null
true
985/B
985
B
Python 3
TESTS
24
2,917
4,812,800
38576856
from sys import exit n, m = list(map(int, input().split())) s = [] for i in range(n): s.append(input()) for i in range(n): for j in range(m): for k in range(i+1, n): if s[i][j] == s[k][j] or s[i][j]=='0': break else: break else: break else: ...
67
124
1,945,600
38626893
n, m = map(int, input().split()) a = [int(input(), 2) for _ in range(n)] l = a[::] r = a[::] f = 2**m - 1 for i in range(1, n): l[i] |= l[i-1] r[-i-1] |= r[-i] res = False for i in range(n): x = l[i-1] if i != 0 else 0 y = r[i+1] if i != n-1 else 0 if (x | y) == f: res = True bre...
Educational Codeforces Round 44 (Rated for Div. 2)
ICPC
2,018
3
256
Switches and Lamps
You are given n switches and m lamps. The i-th switch turns on some subset of the lamps. This information is given as the matrix a consisting of n rows and m columns where ai, j = 1 if the i-th switch turns on the j-th lamp and ai, j = 0 if the i-th switch is not connected to the j-th lamp. Initially all m lamps are t...
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 2000) — the number of the switches and the number of the lamps. The following n lines contain m characters each. The character ai, j is equal to '1' if the i-th switch turns on the j-th lamp and '0' otherwise. It is guaranteed that if you press all...
Print "YES" if there is a switch that if you will ignore it and press all the other n - 1 switches then all m lamps will be turned on. Print "NO" if there is no such switch.
null
null
[{"input": "4 5\n10101\n01000\n00111\n10000", "output": "YES"}, {"input": "4 5\n10100\n01000\n00110\n00101", "output": "NO"}]
1,200
["implementation"]
67
[{"input": "4 5\r\n10101\r\n01000\r\n00111\r\n10000\r\n", "output": "YES\r\n"}, {"input": "4 5\r\n10100\r\n01000\r\n00110\r\n00101\r\n", "output": "NO\r\n"}, {"input": "1 5\r\n11111\r\n", "output": "NO\r\n"}, {"input": "10 1\r\n1\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n1\r\n", "output": "YES\r\n"}, {"input": "1 1\r\...
false
stdio
null
true
733/C
733
C
Python 3
TESTS
3
93
6,963,200
89514840
from array import array n = int(input()) a = array('L', (int(x) for x in input().split())) k = int(input()) b = array('L', (int(x) for x in input().split())) valid = True i = 0 j = 0 cw = 0 p = [] store = [] while valid: while cw < b[j]: cw += a[i] p.append(a[i]) i += 1 if cw == b[j]: cw = 0 j += 1 st...
139
77
409,600
22128470
def partition(array1, c): acc = 0 a1 = [] max_num = 0 max_num_start = 0 max_num_end = 0 upd_max_num_end = True first = array1[0] all_equal = True right_value = False for i, num in enumerate(array1): acc += num a1.append(num) if num != first: ...
Codeforces Round 378 (Div. 2)
CF
2,016
1
256
Epidemic in Monstropolis
There was an epidemic in Monstropolis and all monsters became sick. To recover, all monsters lined up in queue for an appointment to the only doctor in the city. Soon, monsters became hungry and began to eat each other. One monster can eat other monster if its weight is strictly greater than the weight of the monster...
The first line contains single integer n (1 ≤ n ≤ 500) — the number of monsters in the initial queue. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the initial weights of the monsters. The third line contains single integer k (1 ≤ k ≤ n) — the number of monsters in the queue after the joke. Th...
In case if no actions could lead to the final queue, print "NO" (without quotes) in the only line. Otherwise print "YES" (without quotes) in the first line. In the next n - k lines print actions in the chronological order. In each line print x — the index number of the monster in the current queue which eats and, sepa...
null
In the first example, initially there were n = 6 monsters, their weights are [1, 2, 2, 2, 1, 2] (in order of queue from the first monster to the last monster). The final queue should be [5, 5]. The following sequence of eatings leads to the final queue: - the second monster eats the monster to the left (i.e. the first...
[{"input": "6\n1 2 2 2 1 2\n2\n5 5", "output": "YES\n2 L\n1 R\n4 L\n3 L"}, {"input": "5\n1 2 3 4 5\n1\n15", "output": "YES\n5 L\n4 L\n3 L\n2 L"}, {"input": "5\n1 1 1 3 3\n3\n2 1 6", "output": "NO"}]
1,800
["constructive algorithms", "dp", "greedy", "two pointers"]
139
[{"input": "6\r\n1 2 2 2 1 2\r\n2\r\n5 5\r\n", "output": "YES\r\n2 L\r\n1 R\r\n4 L\r\n3 L\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n1\r\n15\r\n", "output": "YES\r\n5 L\r\n4 L\r\n3 L\r\n2 L\r\n"}, {"input": "5\r\n1 1 1 3 3\r\n3\r\n2 1 6\r\n", "output": "NO"}, {"input": "5\r\n1 1 1 1 2\r\n3\r\n1 1 4\r\n", "output": "YES\r\n5 L...
false
stdio
import sys def read_file(path): with open(path, 'r') as f: return f.read().splitlines() input_path, output_path, submission_path = sys.argv[1], sys.argv[2], sys.argv[3] input_lines = read_file(input_path) n = int(input_lines[0]) a = list(map(int, input_lines[1].split())) k = int(input_lines[2]) b = list(...
true
769/C
769
C
Python 3
TESTS
48
2,558
12,288,000
25218093
''' Этот код посвящается самой красивой девушке, Синициной Оле ''' n,m,k=list(map(int,input().split())) s=[] f=0 fc=[0,0] answer='' def get(y,x): if x<0 or y<0 or y>n-1 or x>m-1: return '' return s[y][x] if k%2!=0: print('IMPOSSIBLE') else: for i in range(n): s.append(list(map...
89
2,449
156,467,200
154562650
from collections import deque n, m, k = map(int, input().split()) if k % 2 != 0: print("IMPOSSIBLE") exit() grid = [[] for _ in range(n)] sr, sc = -1, -1 # starting row and column for r in range(n): grid[r] = input() c = grid[r].find('X') if c != -1: sr, sc = r, c # D L R U directions = {'...
VK Cup 2017 - Qualification 1
CF
2,017
15
256
Cycle In Maze
The Robot is in a rectangular maze of size n × m. Each cell of the maze is either empty or occupied by an obstacle. The Robot can move between neighboring cells on the side left (the symbol "L"), right (the symbol "R"), up (the symbol "U") or down (the symbol "D"). The Robot can move to the cell only if it is empty. In...
The first line contains three integers n, m and k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 106) — the size of the maze and the length of the cycle. Each of the following n lines contains m symbols — the description of the maze. If the symbol equals to "." the current cell is empty. If the symbol equals to "*" the current cell is occ...
Print the lexicographically minimum Robot's way with the length exactly k, which starts and ends in the cell where initially Robot is. If there is no such way, print "IMPOSSIBLE"(without quotes).
null
In the first sample two cyclic ways for the Robot with the length 2 exist — "UD" and "RL". The second cycle is lexicographically less. In the second sample the Robot should move in the following way: down, left, down, down, left, left, left, right, right, right, up, up, right, up. In the third sample the Robot can't ...
[{"input": "2 3 2\n.**\nX..", "output": "RL"}, {"input": "5 6 14\n..***.\n*...X.\n..*...\n..*.**\n....*.", "output": "DLDDLLLRRRUURU"}, {"input": "3 3 4\n***\n*X*\n***", "output": "IMPOSSIBLE"}]
1,700
["*special", "dfs and similar", "graphs", "greedy", "shortest paths"]
89
[{"input": "2 3 2\r\n.**\r\nX..\r\n", "output": "RL\r\n"}, {"input": "5 6 14\r\n..***.\r\n*...X.\r\n..*...\r\n..*.**\r\n....*.\r\n", "output": "DLDDLLLRRRUURU\r\n"}, {"input": "3 3 4\r\n***\r\n*X*\r\n***\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "1 1 1\r\nX\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "1 2 2\r\nX.\r...
false
stdio
null
true
426/B
426
B
Python 3
TESTS
35
62
307,200
6718210
n, m = [int(c) for c in input().split()] field = [] for i in range(n): field.append([int(c) for c in input().split()]) min = n s = 1 while min > 0 and min % 2 == 0 and s: if field[min // 2 - 1] == field[min // 2]: min = min // 2 else: s = 0 print(min)
65
46
0
206694419
def main(): n, m = map(int, input().split()) a = [] for _ in range(n): row = list(map(int, input().split())) a.append(row) t = n while t % 2 == 0: f = 1 i = 0 while i < t // 2: for j in range(m): if a[i][j] != a[t - i - 1][j]: ...
Codeforces Round 243 (Div. 2)
CF
2,014
1
256
Sereja and Mirroring
Let's assume that we are given a matrix b of size x × y, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2x × y matrix c which has the following properties: - the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; - the lower half of matrix c (rows with number...
The first line contains two integers, n and m (1 ≤ n, m ≤ 100). Each of the next n lines contains m integers — the elements of matrix a. The i-th line contains integers ai1, ai2, ..., aim (0 ≤ aij ≤ 1) — the i-th row of the matrix a.
In the single line, print the answer to the problem — the minimum number of rows of matrix b.
null
In the first test sample the answer is a 2 × 3 matrix b: If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:
[{"input": "4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "output": "2"}, {"input": "3 3\n0 0 0\n0 0 0\n0 0 0", "output": "3"}, {"input": "8 1\n0\n1\n1\n0\n0\n1\n1\n0", "output": "2"}]
1,300
["implementation"]
65
[{"input": "4 3\r\n0 0 1\r\n1 1 0\r\n1 1 0\r\n0 0 1\r\n", "output": "2\r\n"}, {"input": "3 3\r\n0 0 0\r\n0 0 0\r\n0 0 0\r\n", "output": "3\r\n"}, {"input": "8 1\r\n0\r\n1\r\n1\r\n0\r\n0\r\n1\r\n1\r\n0\r\n", "output": "2\r\n"}, {"input": "10 4\r\n0 0 1 0\r\n0 0 1 0\r\n1 1 0 1\r\n0 0 1 1\r\n1 0 1 0\r\n1 0 1 0\r\n0 0 1 1\...
false
stdio
null
true
426/B
426
B
Python 3
TESTS
35
109
307,200
69656269
n,m=map(int,input().split()) mat=[] for i in range(n): mat.append([list(map(int,input().split()))]) i=n l=n while i%2==0: l=i//2-1 # print(mat[l],mat[l+1]) if mat[l]!=mat[l+1]: print(i) exit() i=i//2 print(i)
65
46
0
207525081
n, m = map(int, input().split()) mat = [input() for _ in range(n)] while n > 1 and n % 2 == 0: if mat[:n] != list(reversed(mat[:n])): break n //= 2 print(n)
Codeforces Round 243 (Div. 2)
CF
2,014
1
256
Sereja and Mirroring
Let's assume that we are given a matrix b of size x × y, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2x × y matrix c which has the following properties: - the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; - the lower half of matrix c (rows with number...
The first line contains two integers, n and m (1 ≤ n, m ≤ 100). Each of the next n lines contains m integers — the elements of matrix a. The i-th line contains integers ai1, ai2, ..., aim (0 ≤ aij ≤ 1) — the i-th row of the matrix a.
In the single line, print the answer to the problem — the minimum number of rows of matrix b.
null
In the first test sample the answer is a 2 × 3 matrix b: If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:
[{"input": "4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "output": "2"}, {"input": "3 3\n0 0 0\n0 0 0\n0 0 0", "output": "3"}, {"input": "8 1\n0\n1\n1\n0\n0\n1\n1\n0", "output": "2"}]
1,300
["implementation"]
65
[{"input": "4 3\r\n0 0 1\r\n1 1 0\r\n1 1 0\r\n0 0 1\r\n", "output": "2\r\n"}, {"input": "3 3\r\n0 0 0\r\n0 0 0\r\n0 0 0\r\n", "output": "3\r\n"}, {"input": "8 1\r\n0\r\n1\r\n1\r\n0\r\n0\r\n1\r\n1\r\n0\r\n", "output": "2\r\n"}, {"input": "10 4\r\n0 0 1 0\r\n0 0 1 0\r\n1 1 0 1\r\n0 0 1 1\r\n1 0 1 0\r\n1 0 1 0\r\n0 0 1 1\...
false
stdio
null
true
769/C
769
C
Python 3
TESTS
48
77
8,089,600
25241730
n,m,k=map(int,input().split()) x=[] for i in range (n+2): if i==0 or i==n+1: x.append('*'*(m+2)) else: x.append('*'+input()+'*') f=x[i].find('X') if f>-1: a=i b=f if k%2==1 or (x[a-1][b]=='*' and x[a+1][b]=='*' and x[a][b-1]=='*' and x[a][b+1]=='*'): p...
89
374
49,971,200
230444836
from collections import deque n, m, k = map(int, input().split()) g = [input() for _ in range(n)] dists = [[float('inf')] * m for _ in range(n)] for i in range(n): for j in range(m): if g[i][j] == 'X': start, end = i, j dists[start][end] = 0 res = [] direct = ['D', 'L', 'R', 'U'] directs = [(1, 0), (0, -1),...
VK Cup 2017 - Qualification 1
CF
2,017
15
256
Cycle In Maze
The Robot is in a rectangular maze of size n × m. Each cell of the maze is either empty or occupied by an obstacle. The Robot can move between neighboring cells on the side left (the symbol "L"), right (the symbol "R"), up (the symbol "U") or down (the symbol "D"). The Robot can move to the cell only if it is empty. In...
The first line contains three integers n, m and k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 106) — the size of the maze and the length of the cycle. Each of the following n lines contains m symbols — the description of the maze. If the symbol equals to "." the current cell is empty. If the symbol equals to "*" the current cell is occ...
Print the lexicographically minimum Robot's way with the length exactly k, which starts and ends in the cell where initially Robot is. If there is no such way, print "IMPOSSIBLE"(without quotes).
null
In the first sample two cyclic ways for the Robot with the length 2 exist — "UD" and "RL". The second cycle is lexicographically less. In the second sample the Robot should move in the following way: down, left, down, down, left, left, left, right, right, right, up, up, right, up. In the third sample the Robot can't ...
[{"input": "2 3 2\n.**\nX..", "output": "RL"}, {"input": "5 6 14\n..***.\n*...X.\n..*...\n..*.**\n....*.", "output": "DLDDLLLRRRUURU"}, {"input": "3 3 4\n***\n*X*\n***", "output": "IMPOSSIBLE"}]
1,700
["*special", "dfs and similar", "graphs", "greedy", "shortest paths"]
89
[{"input": "2 3 2\r\n.**\r\nX..\r\n", "output": "RL\r\n"}, {"input": "5 6 14\r\n..***.\r\n*...X.\r\n..*...\r\n..*.**\r\n....*.\r\n", "output": "DLDDLLLRRRUURU\r\n"}, {"input": "3 3 4\r\n***\r\n*X*\r\n***\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "1 1 1\r\nX\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "1 2 2\r\nX.\r...
false
stdio
null
true
769/C
769
C
Python 3
TESTS
48
3,493
15,052,800
25240210
import sys n, m, k = map(int, input().split()) A = [] for i in range(n): A.append(list(input())) for j in range(m): if A[i][j] == 'X': x, y = i, j if k % 2 == 1: print('IMPOSSIBLE') sys.exit() s = [' ']*k k //= 2 A[x][y] = '.' for i in range(k): if x+1 < n and A[x+1][y] == '.': ...
89
2,449
156,467,200
154562650
from collections import deque n, m, k = map(int, input().split()) if k % 2 != 0: print("IMPOSSIBLE") exit() grid = [[] for _ in range(n)] sr, sc = -1, -1 # starting row and column for r in range(n): grid[r] = input() c = grid[r].find('X') if c != -1: sr, sc = r, c # D L R U directions = {'...
VK Cup 2017 - Qualification 1
CF
2,017
15
256
Cycle In Maze
The Robot is in a rectangular maze of size n × m. Each cell of the maze is either empty or occupied by an obstacle. The Robot can move between neighboring cells on the side left (the symbol "L"), right (the symbol "R"), up (the symbol "U") or down (the symbol "D"). The Robot can move to the cell only if it is empty. In...
The first line contains three integers n, m and k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 106) — the size of the maze and the length of the cycle. Each of the following n lines contains m symbols — the description of the maze. If the symbol equals to "." the current cell is empty. If the symbol equals to "*" the current cell is occ...
Print the lexicographically minimum Robot's way with the length exactly k, which starts and ends in the cell where initially Robot is. If there is no such way, print "IMPOSSIBLE"(without quotes).
null
In the first sample two cyclic ways for the Robot with the length 2 exist — "UD" and "RL". The second cycle is lexicographically less. In the second sample the Robot should move in the following way: down, left, down, down, left, left, left, right, right, right, up, up, right, up. In the third sample the Robot can't ...
[{"input": "2 3 2\n.**\nX..", "output": "RL"}, {"input": "5 6 14\n..***.\n*...X.\n..*...\n..*.**\n....*.", "output": "DLDDLLLRRRUURU"}, {"input": "3 3 4\n***\n*X*\n***", "output": "IMPOSSIBLE"}]
1,700
["*special", "dfs and similar", "graphs", "greedy", "shortest paths"]
89
[{"input": "2 3 2\r\n.**\r\nX..\r\n", "output": "RL\r\n"}, {"input": "5 6 14\r\n..***.\r\n*...X.\r\n..*...\r\n..*.**\r\n....*.\r\n", "output": "DLDDLLLRRRUURU\r\n"}, {"input": "3 3 4\r\n***\r\n*X*\r\n***\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "1 1 1\r\nX\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "1 2 2\r\nX.\r...
false
stdio
null
true
769/C
769
C
Python 3
TESTS
48
1,403
11,878,400
25223267
n, m, k = map(int, input().split()) board = [input() for i in range(n)] def is_possible(wanted_x, wanted_y): if wanted_x < m and wanted_x >= 0 and wanted_y < n and wanted_y >= 0: if board[wanted_y][wanted_x] != '*': return True return False if k%2: print('IMPOSSIBLE') else: way = '' ...
89
374
49,971,200
230444836
from collections import deque n, m, k = map(int, input().split()) g = [input() for _ in range(n)] dists = [[float('inf')] * m for _ in range(n)] for i in range(n): for j in range(m): if g[i][j] == 'X': start, end = i, j dists[start][end] = 0 res = [] direct = ['D', 'L', 'R', 'U'] directs = [(1, 0), (0, -1),...
VK Cup 2017 - Qualification 1
CF
2,017
15
256
Cycle In Maze
The Robot is in a rectangular maze of size n × m. Each cell of the maze is either empty or occupied by an obstacle. The Robot can move between neighboring cells on the side left (the symbol "L"), right (the symbol "R"), up (the symbol "U") or down (the symbol "D"). The Robot can move to the cell only if it is empty. In...
The first line contains three integers n, m and k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 106) — the size of the maze and the length of the cycle. Each of the following n lines contains m symbols — the description of the maze. If the symbol equals to "." the current cell is empty. If the symbol equals to "*" the current cell is occ...
Print the lexicographically minimum Robot's way with the length exactly k, which starts and ends in the cell where initially Robot is. If there is no such way, print "IMPOSSIBLE"(without quotes).
null
In the first sample two cyclic ways for the Robot with the length 2 exist — "UD" and "RL". The second cycle is lexicographically less. In the second sample the Robot should move in the following way: down, left, down, down, left, left, left, right, right, right, up, up, right, up. In the third sample the Robot can't ...
[{"input": "2 3 2\n.**\nX..", "output": "RL"}, {"input": "5 6 14\n..***.\n*...X.\n..*...\n..*.**\n....*.", "output": "DLDDLLLRRRUURU"}, {"input": "3 3 4\n***\n*X*\n***", "output": "IMPOSSIBLE"}]
1,700
["*special", "dfs and similar", "graphs", "greedy", "shortest paths"]
89
[{"input": "2 3 2\r\n.**\r\nX..\r\n", "output": "RL\r\n"}, {"input": "5 6 14\r\n..***.\r\n*...X.\r\n..*...\r\n..*.**\r\n....*.\r\n", "output": "DLDDLLLRRRUURU\r\n"}, {"input": "3 3 4\r\n***\r\n*X*\r\n***\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "1 1 1\r\nX\r\n", "output": "IMPOSSIBLE\r\n"}, {"input": "1 2 2\r\nX.\r...
false
stdio
null
true
837/C
837
C
Python 3
TESTS
26
62
307,200
29645334
n,x,y=map(int,input().split()) a=[] for _ in range(n): x1,y1=map(int,input().split()) b=[] b.append(x1) b.append(y1) if x-x1>y-y1 and x-x1>0 and y-y1>=0: b.append(x-x1) b.append(y) elif x-x1<y-y1 and y-y1>0 and x-x1>=0: b.append(y- y1) b.append(x) elif x-x1==y...
51
46
307,200
30736420
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Mon Aug 7 23:58:26 2017 @author: root """ # question: http://codeforces.com/contest/837/problem/C def compatible(arr1, arr2, a, b): # l, m, n, o, l = arr1[0] m = arr1[1] n = arr2[0] o = arr2[1] # (2, 3) (9, 11) as_it_is = l + ...
Educational Codeforces Round 26
ICPC
2,017
1
256
Two Seals
One very important person has a piece of paper in the form of a rectangle a × b. Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size xi × yi. Each impression must be parallel to the sides of the piece of paper (but seal can be rotated by 90 degrees). A very importa...
The first line contains three integer numbers n, a and b (1 ≤ n, a, b ≤ 100). Each of the next n lines contain two numbers xi, yi (1 ≤ xi, yi ≤ 100).
Print the largest total area that can be occupied by two seals. If you can not select two seals, print 0.
null
In the first example you can rotate the second seal by 90 degrees. Then put impression of it right under the impression of the first seal. This will occupy all the piece of paper. In the second example you can't choose the last seal because it doesn't fit. By choosing the first and the third seals you occupy the large...
[{"input": "2 2 2\n1 2\n2 1", "output": "4"}, {"input": "4 10 9\n2 3\n1 1\n5 10\n9 11", "output": "56"}, {"input": "3 10 10\n6 6\n7 7\n20 5", "output": "0"}]
1,500
["brute force", "implementation"]
51
[{"input": "2 2 2\r\n1 2\r\n2 1\r\n", "output": "4\r\n"}, {"input": "4 10 9\r\n2 3\r\n1 1\r\n5 10\r\n9 11\r\n", "output": "56\r\n"}, {"input": "3 10 10\r\n6 6\r\n7 7\r\n20 5\r\n", "output": "0\r\n"}, {"input": "2 1 1\r\n1 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2 1 2\r\n1 1\r\n1 1\r\n", "output": "2\r\n"}, {"inpu...
false
stdio
null
true
847/E
847
E
Python 3
TESTS
2
46
0
161267729
import sys n = int(sys.stdin.readline()) s = sys.stdin.readline().strip() a = [] b = [] for i in range(n): if s[i] == '*': b.append(i) elif s[i] == 'P': a.append(i) def check(t): p = 0 for x in a: y = b[p] if x - y > t: return False if y - x > t: ...
77
124
12,595,200
201938431
from collections import deque N = int(input()) st = input() iapos, ppos = [], [] for i in range(N): if st[i] == '*': iapos.append(i) elif st[i] == "P": ppos.append(i) iapos = iapos[::-1] def works(n): apos = iapos.copy() for pac in ppos: if not apos: return True ...
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,017
1
256
Packmen
A game field is a strip of 1 × n square cells. In some cells there are Packmen, in some cells — asterisks, other cells are empty. Packman can move to neighboring cell in 1 time unit. If there is an asterisk in the target cell then Packman eats it. Packman doesn't spend any time to eat an asterisk. In the initial mome...
The first line contains a single integer n (2 ≤ n ≤ 105) — the length of the game field. The second line contains the description of the game field consisting of n symbols. If there is symbol '.' in position i — the cell i is empty. If there is symbol '*' in position i — in the cell i contains an asterisk. If there is...
Print minimum possible time after which Packmen can eat all asterisks.
null
In the first example Packman in position 4 will move to the left and will eat asterisk in position 1. He will spend 3 time units on it. During the same 3 time units Packman in position 6 will eat both of neighboring with it asterisks. For example, it can move to the left and eat asterisk in position 5 (in 1 time unit) ...
[{"input": "7\n*..P*P*", "output": "3"}, {"input": "10\n.**PP.*P.*", "output": "2"}]
1,800
["binary search", "dp"]
77
[{"input": "7\r\n*..P*P*\r\n", "output": "3\r\n"}, {"input": "10\r\n.**PP.*P.*\r\n", "output": "2\r\n"}, {"input": "19\r\n**P.*..*..P..*.*P**\r\n", "output": "7\r\n"}, {"input": "12\r\nP**.*P*P*P**\r\n", "output": "3\r\n"}, {"input": "17\r\n.*P*P**P**.**P...\r\n", "output": "3\r\n"}, {"input": "58\r\n..P.P*.P*.P...PPP....
false
stdio
null
true
220/A
220
A
Python 3
TESTS
32
389
8,396,800
8218811
n,inp = int(input()), [int(i) for i in input().split(" ")] for i in range(n): if i == n - 1: print("YES") exit() if inp[i] > inp[i+1]: j = i for i in range(j+1,len(inp[j+1:])): if i == len(inp[j+1:]): print("NO") exit() if i...
96
93
10,649,600
146842582
import sys input = [int(x) for x in sys.stdin.buffer.read().split()] s = input[1:] s.sort() diff = 0 for i in range(len(s)): if s[i] != input[i + 1]: diff += 1 if diff > 2: print("NO") else: print("YES")
Codeforces Round 136 (Div. 1)
CF
2,012
2
256
Little Elephant and Problem
The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array a of length n and possibly swapped some elements of the array. The Little Elephant doesn't want to call the police until he understands if he could have accidentally changed the array himself. He thinks that he could ...
The first line contains a single integer n (2 ≤ n ≤ 105) — the size of array a. The next line contains n positive integers, separated by single spaces and not exceeding 109, — array a. Note that the elements of the array are not necessarily distinct numbers.
In a single line print "YES" (without the quotes) if the Little Elephant could have accidentally changed the array himself, and "NO" (without the quotes) otherwise.
null
In the first sample the array has already been sorted, so to sort it, we need 0 swap operations, that is not more than 1. Thus, the answer is "YES". In the second sample we can sort the array if we swap elements 1 and 3, so we need 1 swap operation to sort the array. Thus, the answer is "YES". In the third sample we ...
[{"input": "2\n1 2", "output": "YES"}, {"input": "3\n3 2 1", "output": "YES"}, {"input": "4\n4 3 2 1", "output": "NO"}]
1,300
["implementation", "sortings"]
96
[{"input": "2\r\n1 2\r\n", "output": "YES\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "YES\r\n"}, {"input": "4\r\n4 3 2 1\r\n", "output": "NO\r\n"}, {"input": "3\r\n1 3 2\r\n", "output": "YES\r\n"}, {"input": "2\r\n2 1\r\n", "output": "YES\r\n"}, {"input": "9\r\n7 7 8 8 10 10 10 10 1000000000\r\n", "output": "YES\r\n"...
false
stdio
null
true
540/B
540
B
PyPy 3-64
TESTS
1
46
28,774,400
225500087
def check(x, y, arr: list, n): sum_ = sum(arr) arr.sort() return sum_ <= x and arr[(n + 1) // 2 - 1] == y def main(): n, k, p, x, y = map(int, input().split()) i_median = (n + 1) // 2 count_low_median = 0 arr = [] x_new = x if x < y: return -1 if k != 0: arr = ...
78
62
4,710,400
10950542
n, k, p, x, y = map(int, input().split()) a = list(map(int, input().split())) a.sort() marks = [] if (n > 1): while (len(a) < n) and (len(a) <= (n+1)//2-2 or (n+1)//2-2 < 0 or a[(n+1)//2-2] >= y): a = [1] + a marks.append(1) else: marks = [y] a = [y] marks += [y] * (n - len(a)) a += [y] *...
Codeforces Round 301 (Div. 2)
CF
2,015
2
256
School Marks
Little Vova studies programming in an elite school. Vova and his classmates are supposed to write n progress tests, for each test they will get a mark from 1 to p. Vova is very smart and he can write every test for any mark, but he doesn't want to stand out from the crowd too much. If the sum of his marks for all tests...
The first line contains 5 space-separated integers: n, k, p, x and y (1 ≤ n ≤ 999, n is odd, 0 ≤ k < n, 1 ≤ p ≤ 1000, n ≤ x ≤ n·p, 1 ≤ y ≤ p). Here n is the number of tests that Vova is planned to write, k is the number of tests he has already written, p is the maximum possible mark for a test, x is the maximum total n...
If Vova cannot achieve the desired result, print "-1". Otherwise, print n - k space-separated integers — the marks that Vova should get for the remaining tests. If there are multiple possible solutions, print any of them.
null
The median of sequence a1, ..., an where n is odd (in this problem n is always odd) is the element staying on (n + 1) / 2 position in the sorted list of ai. In the first sample the sum of marks equals 3 + 5 + 4 + 4 + 1 = 17, what doesn't exceed 18, that means that Vova won't be disturbed by his classmates. And the med...
[{"input": "5 3 5 18 4\n3 5 4", "output": "4 1"}, {"input": "5 3 5 16 4\n5 5 5", "output": "-1"}]
1,700
["greedy", "implementation"]
78
[{"input": "5 3 5 18 4\r\n3 5 4\r\n", "output": "4 1\r\n"}, {"input": "5 3 5 16 4\r\n5 5 5\r\n", "output": "-1\r\n"}, {"input": "5 3 5 17 4\r\n5 5 5\r\n", "output": "1 1\r\n"}, {"input": "5 3 5 12 1\r\n5 5 1\r\n", "output": "-1\r\n"}, {"input": "5 3 5 13 1\r\n5 5 1\r\n", "output": "1 1\r\n"}, {"input": "7 4 5 26 5\r\n5...
false
stdio
import sys def main(input_path, output_path, submission_path): with open(input_path, 'r') as f_in: n, k, p, x, y = map(int, f_in.readline().split()) existing = list(map(int, f_in.readline().split())) with open(submission_path, 'r') as f_sub: submission_line = f_sub.read().strip() ...
true
733/C
733
C
PyPy 3
TESTS
68
171
1,843,200
71907930
import sys input = sys.stdin.readline n = int(input()) a = [int(i) for i in input().split()] m = int(input()) b = [int(i) for i in input().split()] j = n-1 ans = [] for k in range(m-1, -1, -1): sm = 0 i = j while i >= 0: sm += a[i] if sm == b[k]: if i == j: pass...
138
78
307,200
21950023
import sys def main(): n = int(sys.stdin.readline()[:-1]) a = [int(x) for x in sys.stdin.readline()[:-1].split()] k = int(sys.stdin.readline()[:-1]) b = [int(x) for x in sys.stdin.readline()[:-1].split()] last = 0 menu = [] largest = [] if sum(a) != sum(b): sys.stdout.write('NO')...
Codeforces Round 378 (Div. 2)
CF
2,016
1
256
Epidemic in Monstropolis
There was an epidemic in Monstropolis and all monsters became sick. To recover, all monsters lined up in queue for an appointment to the only doctor in the city. Soon, monsters became hungry and began to eat each other. One monster can eat other monster if its weight is strictly greater than the weight of the monster...
The first line contains single integer n (1 ≤ n ≤ 500) — the number of monsters in the initial queue. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 106) — the initial weights of the monsters. The third line contains single integer k (1 ≤ k ≤ n) — the number of monsters in the queue after the joke. Th...
In case if no actions could lead to the final queue, print "NO" (without quotes) in the only line. Otherwise print "YES" (without quotes) in the first line. In the next n - k lines print actions in the chronological order. In each line print x — the index number of the monster in the current queue which eats and, sepa...
null
In the first example, initially there were n = 6 monsters, their weights are [1, 2, 2, 2, 1, 2] (in order of queue from the first monster to the last monster). The final queue should be [5, 5]. The following sequence of eatings leads to the final queue: - the second monster eats the monster to the left (i.e. the first...
[{"input": "6\n1 2 2 2 1 2\n2\n5 5", "output": "YES\n2 L\n1 R\n4 L\n3 L"}, {"input": "5\n1 2 3 4 5\n1\n15", "output": "YES\n5 L\n4 L\n3 L\n2 L"}, {"input": "5\n1 1 1 3 3\n3\n2 1 6", "output": "NO"}]
1,800
["constructive algorithms", "dp", "greedy", "two pointers"]
139
[{"input": "6\r\n1 2 2 2 1 2\r\n2\r\n5 5\r\n", "output": "YES\r\n2 L\r\n1 R\r\n4 L\r\n3 L\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n1\r\n15\r\n", "output": "YES\r\n5 L\r\n4 L\r\n3 L\r\n2 L\r\n"}, {"input": "5\r\n1 1 1 3 3\r\n3\r\n2 1 6\r\n", "output": "NO"}, {"input": "5\r\n1 1 1 1 2\r\n3\r\n1 1 4\r\n", "output": "YES\r\n5 L...
false
stdio
import sys def read_file(path): with open(path, 'r') as f: return f.read().splitlines() input_path, output_path, submission_path = sys.argv[1], sys.argv[2], sys.argv[3] input_lines = read_file(input_path) n = int(input_lines[0]) a = list(map(int, input_lines[1].split())) k = int(input_lines[2]) b = list(...
true
665/D
665
D
Python 3
TESTS
7
61
0
18864060
import math def prime(n): if n % 2 == 0 and n > 2: return False return all(n % i for i in range(3, int(math.sqrt(n)) + 1, 2)) n = int(input()) l = list(map(int, input().split())) if l.count(1) > 1: for i in range(n): if l[i] != 1: if prime(1 + l[i]): print(1 + l.count(1)) for j in rang...
66
373
31,641,600
17472783
import math N = 2000001 sq = math.floor(N ** 0.5) isprime = [True] * N for p in range(2, N): if isprime[p]: for i in range(p**2, N, p): isprime[i] = False def solve(): n = int(input()) A = [int(x) for x in input().split()] odd = list(filter(lambda x: x%2, A)) even = list(filter...
Educational Codeforces Round 12
ICPC
2,016
1
256
Simple Subset
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. ...
The first line contains integer n (1 ≤ n ≤ 1000) — the number of integers in the array a. The second line contains n integers ai (1 ≤ ai ≤ 106) — the elements of the array a.
On the first line print integer m — the maximum possible size of simple subset of a. On the second line print m integers bl — the elements of the simple subset of the array a with the maximum size. If there is more than one solution you can print any of them. You can print the elements of the subset in any order.
null
null
[{"input": "2\n2 3", "output": "2\n3 2"}, {"input": "2\n2 2", "output": "1\n2"}, {"input": "3\n2 1 1", "output": "3\n1 1 2"}, {"input": "2\n83 14", "output": "2\n14 83"}]
1,800
["constructive algorithms", "greedy", "number theory"]
66
[{"input": "2\r\n2 3\r\n", "output": "2\r\n3 2\r\n"}, {"input": "2\r\n2 2\r\n", "output": "1\r\n2\r\n"}, {"input": "3\r\n2 1 1\r\n", "output": "3\r\n1 1 2\r\n"}, {"input": "2\r\n83 14\r\n", "output": "2\r\n14 83\r\n"}, {"input": "10\r\n10 10 1 2 3 3 1 2 1 5\r\n", "output": "4\r\n1 1 10 1\r\n"}, {"input": "100\r\n314 90...
false
stdio
import sys from collections import Counter def sieve(max_limit): sieve = [True] * (max_limit + 1) sieve[0] = sieve[1] = False for i in range(2, int(max_limit**0.5) + 1): if sieve[i]: sieve[i*i : max_limit+1 : i] = [False]*len(sieve[i*i : max_limit+1 : i]) return sieve max_sum = 2 *...
true
638/B
638
B
Python 3
PRETESTS
9
46
5,120,000
16839637
def link(dic, start, ans): ans.append(start) for i in range(len(dic)): if start in dic.keys() and dic[start] != -1: ans.append(dic[start]) start = dic[start] else: break return n = int(input()) answer = {} for i in range(n): k = list(input()) ...
67
62
4,915,200
16852579
from sys import exit n = int(input()) a = [] for i in range(n): s = input() for j in range(len(a)): check = a[j] if s in check: break if check in s: a[j] = s break else: a.append(s) br_flag = False while True: for j in range(len(a)): ...
VK Cup 2016 - Qualification Round 2
CF
2,016
1
256
Making Genome in Berland
Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can have 26 distinct nucleotide types, a nucleotide of each type can occur at most once. If we assign distinct En...
The first line of the input contains a positive integer n (1 ≤ n ≤ 100) — the number of genome fragments. Each of the next lines contains one descriptions of a fragment. Each fragment is a non-empty string consisting of distinct small letters of the English alphabet. It is not guaranteed that the given fragments are d...
In the single line of the output print the genome of the minimum length that contains all the given parts. All the nucleotides in the genome must be distinct. If there are multiple suitable strings, print the string of the minimum length. If there also are multiple suitable strings, you can print any of them.
null
null
[{"input": "3\nbcd\nab\ncdef", "output": "abcdef"}, {"input": "4\nx\ny\nz\nw", "output": "xyzw"}]
1,500
["*special", "dfs and similar", "strings"]
67
[{"input": "3\r\nbcd\r\nab\r\ncdef\r\n", "output": "abcdef\r\n"}, {"input": "4\r\nx\r\ny\r\nz\r\nw\r\n", "output": "xyzw\r\n"}, {"input": "25\r\nef\r\nfg\r\ngh\r\nhi\r\nij\r\njk\r\nkl\r\nlm\r\nmn\r\nno\r\nab\r\nbc\r\ncd\r\nde\r\nop\r\npq\r\nqr\r\nrs\r\nst\r\ntu\r\nuv\r\nvw\r\nwx\r\nxy\r\nyz\r\n", "output": "abcdefghijk...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path) as f: n = int(f.readline().strip()) fragments = [line.strip() for line in f] with open(output_path) as f: correct_output = f.read().strip() ...
true
540/B
540
B
PyPy 3
TESTS
11
139
1,433,600
97678364
def no(): print(-1) exit() n, k, p, x, y = map(int, input().split()) a = list(map(int, input().split())) a.sort() xx = sum(a) nk = n - k if xx + nk > x: no() ans = [p]*nk ans1 = p * nk + xx i = 0 posl = nk do = 0 while ans1 > x: ans[i] = 1 ans1 -= p - 1 i += 1 do += 1 i -= 1 a += ans a.sort(...
78
77
4,710,400
10948569
from bisect import insort tot, wr, ma, mas, mis = map(int, input().split()) s = sorted(map(int, input().split())) res = [] while wr < tot: if not s or (s[wr // 2] < mis or s[wr // 2 - 1] < mis): res.append(mis) insort(s, mis) else: res.append(1) insort(s, 1) wr += 1 if sum(s...
Codeforces Round 301 (Div. 2)
CF
2,015
2
256
School Marks
Little Vova studies programming in an elite school. Vova and his classmates are supposed to write n progress tests, for each test they will get a mark from 1 to p. Vova is very smart and he can write every test for any mark, but he doesn't want to stand out from the crowd too much. If the sum of his marks for all tests...
The first line contains 5 space-separated integers: n, k, p, x and y (1 ≤ n ≤ 999, n is odd, 0 ≤ k < n, 1 ≤ p ≤ 1000, n ≤ x ≤ n·p, 1 ≤ y ≤ p). Here n is the number of tests that Vova is planned to write, k is the number of tests he has already written, p is the maximum possible mark for a test, x is the maximum total n...
If Vova cannot achieve the desired result, print "-1". Otherwise, print n - k space-separated integers — the marks that Vova should get for the remaining tests. If there are multiple possible solutions, print any of them.
null
The median of sequence a1, ..., an where n is odd (in this problem n is always odd) is the element staying on (n + 1) / 2 position in the sorted list of ai. In the first sample the sum of marks equals 3 + 5 + 4 + 4 + 1 = 17, what doesn't exceed 18, that means that Vova won't be disturbed by his classmates. And the med...
[{"input": "5 3 5 18 4\n3 5 4", "output": "4 1"}, {"input": "5 3 5 16 4\n5 5 5", "output": "-1"}]
1,700
["greedy", "implementation"]
78
[{"input": "5 3 5 18 4\r\n3 5 4\r\n", "output": "4 1\r\n"}, {"input": "5 3 5 16 4\r\n5 5 5\r\n", "output": "-1\r\n"}, {"input": "5 3 5 17 4\r\n5 5 5\r\n", "output": "1 1\r\n"}, {"input": "5 3 5 12 1\r\n5 5 1\r\n", "output": "-1\r\n"}, {"input": "5 3 5 13 1\r\n5 5 1\r\n", "output": "1 1\r\n"}, {"input": "7 4 5 26 5\r\n5...
false
stdio
import sys def main(input_path, output_path, submission_path): with open(input_path, 'r') as f_in: n, k, p, x, y = map(int, f_in.readline().split()) existing = list(map(int, f_in.readline().split())) with open(submission_path, 'r') as f_sub: submission_line = f_sub.read().strip() ...
true
665/D
665
D
PyPy 3-64
TESTS
7
109
18,227,200
209957663
def rl(): return list(map(int,input().split())) def ri(): return int(input()) def rs(): return input() def rm(): return map(int,input().split()) def sieve(n): p=[0]*(n+1) p[0]=p[1]=-1 for i in range(2,n): if p[i]==-1: continue j=i*2 while j<n+1: p[j]=-1 ...
66
685
26,624,000
213965325
import sys input = lambda: sys.stdin.readline().rstrip() q = [0] * (1000000 + 1) prime = [0] * (2000000 + 1) for i in range(2, int(2e6 + 1)): for j in range(2 * i, int(2e6 + 1), i): prime[j] = 1 n = int(input()) a = list(map(int, input().split())) for i in range(len(a)): q[a[i]] += 1 if q[1] >= 2: ...
Educational Codeforces Round 12
ICPC
2,016
1
256
Simple Subset
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. ...
The first line contains integer n (1 ≤ n ≤ 1000) — the number of integers in the array a. The second line contains n integers ai (1 ≤ ai ≤ 106) — the elements of the array a.
On the first line print integer m — the maximum possible size of simple subset of a. On the second line print m integers bl — the elements of the simple subset of the array a with the maximum size. If there is more than one solution you can print any of them. You can print the elements of the subset in any order.
null
null
[{"input": "2\n2 3", "output": "2\n3 2"}, {"input": "2\n2 2", "output": "1\n2"}, {"input": "3\n2 1 1", "output": "3\n1 1 2"}, {"input": "2\n83 14", "output": "2\n14 83"}]
1,800
["constructive algorithms", "greedy", "number theory"]
66
[{"input": "2\r\n2 3\r\n", "output": "2\r\n3 2\r\n"}, {"input": "2\r\n2 2\r\n", "output": "1\r\n2\r\n"}, {"input": "3\r\n2 1 1\r\n", "output": "3\r\n1 1 2\r\n"}, {"input": "2\r\n83 14\r\n", "output": "2\r\n14 83\r\n"}, {"input": "10\r\n10 10 1 2 3 3 1 2 1 5\r\n", "output": "4\r\n1 1 10 1\r\n"}, {"input": "100\r\n314 90...
false
stdio
import sys from collections import Counter def sieve(max_limit): sieve = [True] * (max_limit + 1) sieve[0] = sieve[1] = False for i in range(2, int(max_limit**0.5) + 1): if sieve[i]: sieve[i*i : max_limit+1 : i] = [False]*len(sieve[i*i : max_limit+1 : i]) return sieve max_sum = 2 *...
true
79/C
79
C
Python 3
TESTS
3
154
5,427,200
21603132
import functools def pre_KMP(word): # Tableau qui dit à quel indice j peut recommencer à comparer lorsque l'égalité foire à l'indice i r = [0] * (len(word) + 1) for i in range(0, len(word) + 1): j = 1 while j < i and word[j:i] != word[:i - j]: j += 1 r[i] = i - j ...
80
436
716,800
5639831
s, n = input(), int(input()) t = [input() for i in range(n)] def f(i): global t for j in range(n): if i < j: if len(t[j]) < len(t[i]) and t[j] in t[i]: return False elif j < i and t[j] in t[i]: return False return True t = [t[i] for i in range(n) if f(i)] n = len(s) r = [0] * n...
Codeforces Beta Round 71
CF
2,011
2
256
Beaver
After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string s, and she tried to remember the string s correctly. However, Ciel fee...
In the first line there is a string s. The length of s will be between 1 and 105, inclusive. In the second line there is a single integer n (1 ≤ n ≤ 10). Next n lines, there is a string bi (1 ≤ i ≤ n). Each length of bi will be between 1 and 10, inclusive. Each character of the given strings will be either a English...
Output in the first line two space-separated integers len and pos: the length of the longest contiguous substring of s that does not contain any bi, and the first position of the substring (0-indexed). The position pos must be between 0 and |s| - len inclusive, where |s| is the length of string s. If there are several...
null
In the first sample, the solution is traight_alon. In the second sample, the solution is an empty string, so the output can be «0 0», «0 1», «0 2», and so on. In the third sample, the solution is either nagio or oisii.
[{"input": "Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse", "output": "12 4"}, {"input": "IhaveNoIdea\n9\nI\nh\na\nv\ne\nN\no\nI\nd", "output": "0 0"}, {"input": "unagioisii\n2\nioi\nunagi", "output": "5 5"}]
1,800
["data structures", "dp", "greedy", "hashing", "strings", "two pointers"]
80
[{"input": "Go_straight_along_this_street\r\n5\r\nstr\r\nlong\r\ntree\r\nbiginteger\r\nellipse\r\n", "output": "12 4\r\n"}, {"input": "IhaveNoIdea\r\n9\r\nI\r\nh\r\na\r\nv\r\ne\r\nN\r\no\r\nI\r\nd\r\n", "output": "0 0\r\n"}, {"input": "unagioisii\r\n2\r\nioi\r\nunagi\r\n", "output": "5 5\r\n"}, {"input": "abcabcabcabc\...
false
stdio
import sys def main(): input_path, output_path, submission_path = sys.argv[1:] # Read input with open(input_path, 'r') as f: s = f.readline().strip() n = int(f.readline()) forbidden = [f.readline().strip() for _ in range(n)] # Read submission output try: wi...
true
138/A
138
A
Python 3
TESTS
61
124
102,400
180094424
#z=int(input()) from decimal import * for contorr in range(1): dictionar={} dictionar['a']=1 dictionar['e']=1 dictionar['o']=1 dictionar['u']=1 dictionar['i']=1 n,k=list(map(int, input().split())) posibil=1 answ=set() for i in range(n): lista=[] partial=[] for j in range(4): lista.append(input()...
80
342
7,372,800
218291655
n, k = map(int, input().split()) res = "aaaa" for _ in range(n): suff = [""] * 4 for i in range(4): str = input().strip() tmp = 0 for r in range(len(str) - 1, -1, -1): suff[i] += str[r] if str[r] in ['a', 'e', 'i', 'o', 'u']: tmp += 1 i...
Codeforces Beta Round 99 (Div. 1)
CF
2,011
2
256
Literature Lesson
Vera adores poems. All the poems Vera knows are divided into quatrains (groups of four lines) and in each quatrain some lines contain rhymes. Let's consider that all lines in the poems consist of lowercase Latin letters (without spaces). Letters "a", "e", "i", "o", "u" are considered vowels. Two lines rhyme if their ...
The first line contains two integers n and k (1 ≤ n ≤ 2500, 1 ≤ k ≤ 5) — the number of quatrains in the poem and the vowel's number, correspondingly. Next 4n lines contain the poem. Each line is not empty and only consists of small Latin letters. The total length of the lines does not exceed 104. If we assume that the...
Print the rhyme scheme of the poem as "aabb", "abab", "abba", "aaaa"; or "NO" if the poem does not belong to any of the above mentioned schemes.
null
In the last sample both quatrains have rhymes but finding the common scheme is impossible, so the answer is "NO".
[{"input": "1 1\nday\nmay\nsun\nfun", "output": "aabb"}, {"input": "1 1\nday\nmay\ngray\nway", "output": "aaaa"}, {"input": "2 1\na\na\na\na\na\na\ne\ne", "output": "aabb"}, {"input": "2 1\nday\nmay\nsun\nfun\ntest\nhill\nfest\nthrill", "output": "NO"}]
1,600
["implementation"]
80
[{"input": "1 1\r\nday\r\nmay\r\nsun\r\nfun\r\n", "output": "aabb\r\n"}, {"input": "1 1\r\nday\r\nmay\r\ngray\r\nway\r\n", "output": "aaaa\r\n"}, {"input": "2 1\r\na\r\na\r\na\r\na\r\na\r\na\r\ne\r\ne\r\n", "output": "aabb\r\n"}, {"input": "2 1\r\nday\r\nmay\r\nsun\r\nfun\r\ntest\r\nhill\r\nfest\r\nthrill\r\n", "output...
false
stdio
null
true
709/B
709
B
PyPy 3
TESTS
4
93
307,200
121754963
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...
81
78
13,926,400
205961713
''' Online Python Compiler. Code, Compile, Run and Debug python program online. Write your code in this editor and press "Run" button to execute it. ''' n,a=map(int,input().split()) l=list(map(int,input().split())) l.sort() if n==1: print(0) else: if a<=l[0]: ...
AIM Tech Round 3 (Div. 2)
CF
2,016
1
256
Checkpoints
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x1, x2, ..., xn. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary order...
The first line of the input contains two integers n and a (1 ≤ n ≤ 100 000, - 1 000 000 ≤ a ≤ 1 000 000) — the number of checkpoints and Vasya's starting position respectively. The second line contains n integers x1, x2, ..., xn ( - 1 000 000 ≤ xi ≤ 1 000 000) — coordinates of the checkpoints.
Print one integer — the minimum distance Vasya has to travel in order to visit at least n - 1 checkpoint.
null
In the first sample Vasya has to visit at least two checkpoints. The optimal way to achieve this is the walk to the third checkpoints (distance is 12 - 10 = 2) and then proceed to the second one (distance is 12 - 7 = 5). The total distance is equal to 2 + 5 = 7. In the second sample it's enough to visit only one check...
[{"input": "3 10\n1 7 12", "output": "7"}, {"input": "2 0\n11 -10", "output": "10"}, {"input": "5 0\n0 0 1000 0 0", "output": "0"}]
1,500
["greedy", "implementation", "sortings"]
81
[{"input": "3 10\r\n1 7 12\r\n", "output": "7\r\n"}, {"input": "2 0\r\n11 -10\r\n", "output": "10\r\n"}, {"input": "5 0\r\n0 0 1000 0 0\r\n", "output": "0\r\n"}, {"input": "1 0\r\n0\r\n", "output": "0\r\n"}, {"input": "2 1\r\n4 -8\r\n", "output": "3\r\n"}, {"input": "3 4\r\n4 2 4\r\n", "output": "0\r\n"}, {"input": "4 ...
false
stdio
null
true
600/C
600
C
Python 3
TESTS
6
46
0
194302225
s = input() count = [0 for _ in range(26)] for c in s: count[ord(c) - ord('a')] += 1 f = 0 for cnt in count: if cnt & 1: f += 1 x = f // 2 left, right = 0, 25 while x > 0 and left < right: while not count[right] or not (count[right] & 1): right -= 1 while not count[left] or not (count[...
66
62
2,457,600
194305370
def solve(): s = input() a = [0] * 26 for c in s: a[ord(c)-ord('a')] += 1 l, r = 0, 25 while l < r: if a[l] & 1 and a[r] & 1: a[l] += 1 a[r] -= 1 l += 1 r -= 1 elif a[l] & 1 == 0: l += 1 elif a[r] & 1 ==...
Educational Codeforces Round 2
ICPC
2,015
2
256
Make Palindrome
A string is called palindrome if it reads the same from left to right and from right to left. For example "kazak", "oo", "r" and "mikhailrubinchikkihcniburliahkim" are palindroms, but strings "abb" and "ij" are not. You are given string s consisting of lowercase Latin letters. At once you can choose any position in th...
The only line contains string s (1 ≤ |s| ≤ 2·105) consisting of only lowercase Latin letters.
Print the lexicographically smallest palindrome that can be obtained with the minimal number of changes.
null
null
[{"input": "aabc", "output": "abba"}, {"input": "aabcd", "output": "abcba"}]
1,800
["constructive algorithms", "greedy", "strings"]
66
[{"input": "aabc\r\n", "output": "abba\r\n"}, {"input": "aabcd\r\n", "output": "abcba\r\n"}, {"input": "u\r\n", "output": "u\r\n"}, {"input": "ttttt\r\n", "output": "ttttt\r\n"}, {"input": "xxxvvvxxvv\r\n", "output": "vvvxxxxvvv\r\n"}, {"input": "wrwrwfrrfrffrrwwwffffwrfrrwfrrfrwwfwfrwfwfwffwrrwfrrrwwwfrrrwfrrfwrwwrwrr...
false
stdio
null
true
699/A
699
A
Python 3
TESTS
40
171
22,835,200
124934586
n=int(input()) s=input() l=list(map(int,input().split())) res=float("inf") ans=False if n==1: print(0) else: for i in range(n-1): if (s[i]=="R" and s[i+1]=="L"): ans=True res=min(res,abs(l[i]-l[i+1])//2) if not ans: print(-1) else: print(res)
85
93
17,203,200
214264926
# Enter your code here. Read input from STDIN. Print output to STDOUT if __name__ == '__main__': n = int(input().strip()) s = input().strip() cord = [int(x) for x in input().strip().split(" ")] ans = float("inf") for i in range(n-1): if s[i] == "R" and s[i+1] == "L": x = (cord[i+1] - cord[i]) // 2 if x < ...
Codeforces Round 363 (Div. 2)
CF
2,016
2
256
Launch of Collider
There will be a launch of a new, powerful and unusual collider very soon, which located along a straight line. n particles will be launched inside it. All of them are located in a straight line and there can not be two or more particles located in the same point. The coordinates of the particles coincide with the dista...
The first line contains the positive integer n (1 ≤ n ≤ 200 000) — the number of particles. The second line contains n symbols "L" and "R". If the i-th symbol equals "L", then the i-th particle will move to the left, otherwise the i-th symbol equals "R" and the i-th particle will move to the right. The third line con...
In the first line print the only integer — the first moment (in microseconds) when two particles are at the same point and there will be an explosion. Print the only integer -1, if the collision of particles doesn't happen.
null
In the first sample case the first explosion will happen in 1 microsecond because the particles number 1 and 2 will simultaneously be at the same point with the coordinate 3. In the second sample case there will be no explosion because there are no particles which will simultaneously be at the same point.
[{"input": "4\nRLRL\n2 4 6 10", "output": "1"}, {"input": "3\nLLR\n40 50 60", "output": "-1"}]
1,000
["implementation"]
85
[{"input": "4\r\nRLRL\r\n2 4 6 10\r\n", "output": "1\r\n"}, {"input": "3\r\nLLR\r\n40 50 60\r\n", "output": "-1\r\n"}, {"input": "4\r\nRLLR\r\n46 230 264 470\r\n", "output": "92\r\n"}, {"input": "6\r\nLLRLLL\r\n446 492 650 844 930 970\r\n", "output": "97\r\n"}, {"input": "8\r\nRRLLLLLL\r\n338 478 512 574 594 622 834 92...
false
stdio
null
true
989/B
989
B
Python 3
TESTS
20
109
307,200
80750944
n,p=map(int,input().split()) s=list(input()); cnt=0; oe=0 for i in range(n): if i+p<n and (s[i]==s[i+p]=='1' or s[i]==s[i+p]=='0'): cnt+=1 if cnt==n-p: break if s[i]=='.': if oe%2: s[i]='1' else: s[i]='0' oe=1-oe if i+p<n and s[i+p]=='.': if s[i]=='1': s[i+p]=...
59
46
0
146429806
tc=list(map(int, input().rstrip().split())) n=tc[0] p=tc[1] s=input() ar=[] for i in range(n): ar.append(s[i]) flg=0 for i in range(n-p): if(ar[i]==ar[i+p] and ar[i]!='.'): flg=0 elif(ar[i]==ar[i+p]=='.'): ar[i]='1' ar[i+p]='0' flg=1 break else: flg=1 ...
Codeforces Round 487 (Div. 2)
CF
2,018
1
256
A Tide of Riverscape
The records are expressed as a string $$$s$$$ of characters '0', '1' and '.', where '0' denotes a low tide, '1' denotes a high tide, and '.' denotes an unknown one (either high or low). You are to help Mino determine whether it's possible that after replacing each '.' independently with '0' or '1', a given integer $$$...
The first line contains two space-separated integers $$$n$$$ and $$$p$$$ ($$$1 \leq p \leq n \leq 2000$$$) — the length of the given string and the supposed period, respectively. The second line contains a string $$$s$$$ of $$$n$$$ characters — Mino's records. $$$s$$$ only contains characters '0', '1' and '.', and con...
Output one line — if it's possible that $$$p$$$ is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)).
null
In the first example, $$$7$$$ is not a period of the resulting string because the $$$1$$$-st and $$$8$$$-th characters of it are different. In the second example, $$$6$$$ is not a period of the resulting string because the $$$4$$$-th and $$$10$$$-th characters of it are different. In the third example, $$$9$$$ is alw...
[{"input": "10 7\n1.0.1.0.1.", "output": "1000100010"}, {"input": "10 6\n1.0.1.1000", "output": "1001101000"}, {"input": "10 9\n1........1", "output": "No"}]
1,200
["constructive algorithms", "strings"]
59
[{"input": "10 7\r\n1.0.1.0.1.\r\n", "output": "1000100010\r\n"}, {"input": "10 6\r\n1.0.1.1000\r\n", "output": "1001101000\r\n"}, {"input": "10 9\r\n1........1\r\n", "output": "No\r\n"}, {"input": "1 1\r\n.\r\n", "output": "No\r\n"}, {"input": "5 1\r\n0...1\r\n", "output": "00001\r\n"}, {"input": "17 10\r\n..1.100..1....
false
stdio
import sys def main(): input_path = sys.argv[1] ref_path = sys.argv[2] sub_path = sys.argv[3] with open(input_path, 'r') as f: n, p = map(int, f.readline().split()) s = f.readline().strip() with open(ref_path, 'r') as f: ref_output = f.read().strip() with open(sub_pat...
true
900/A
900
A
Python 3
TESTS
26
420
9,728,000
104807863
n=int(input()) l=[] for i in range(n): l.append(list(map(int,input().split()))) d={1:0,2:0} c=0 for i in range(n): if((l[i][0]>0 and l[i][1]>0) or (l[i][0]>0 and l[i][1]<0)): d[1]+=1 if((l[i][0]<0 and l[i][1]>0) or (l[i][0]<0 and l[i][1]<0)): d[2]+=1 if(min(d[1],d[2])>1): c=1 ...
71
186
6,758,400
128439264
n = int(input()) num = sum(int(input().split()[0]) > 0 for i in range(n)) print("Yes" if num <= 1 or num >= n - 1 else "No")
Codeforces Round 450 (Div. 2)
CF
2,017
1
256
Find Extra One
You have n distinct points on a plane, none of them lie on OY axis. Check that there is a point after removal of which the remaining points are located on one side of the OY axis.
The first line contains a single positive integer n (2 ≤ n ≤ 105). The following n lines contain coordinates of the points. The i-th of these lines contains two single integers xi and yi (|xi|, |yi| ≤ 109, xi ≠ 0). No two points coincide.
Print "Yes" if there is such a point, "No" — otherwise. You can print every letter in any case (upper or lower).
null
In the first example the second point can be removed. In the second example there is no suitable for the condition point. In the third example any point can be removed.
[{"input": "3\n1 1\n-1 -1\n2 -1", "output": "Yes"}, {"input": "4\n1 1\n2 2\n-1 1\n-2 2", "output": "No"}, {"input": "3\n1 2\n2 1\n4 60", "output": "Yes"}]
800
["geometry", "implementation"]
71
[{"input": "3\r\n1 1\r\n-1 -1\r\n2 -1\r\n", "output": "Yes"}, {"input": "4\r\n1 1\r\n2 2\r\n-1 1\r\n-2 2\r\n", "output": "No"}, {"input": "3\r\n1 2\r\n2 1\r\n4 60\r\n", "output": "Yes"}, {"input": "10\r\n1 1\r\n2 2\r\n3 3\r\n4 4\r\n5 5\r\n6 6\r\n7 7\r\n8 8\r\n9 9\r\n-1 -1\r\n", "output": "Yes"}, {"input": "2\r\n1000000...
false
stdio
null
true
989/B
989
B
PyPy 3
TESTS
42
155
1,638,400
60741039
n, p = map(int, input().split()) s = list(input()) possible = False if n % p == 0: k = p n -= p else: k = n % p for i in range(k): for j in range(1, n // p + 1): if s[i + (j - 1) * p] != '.' : if s[i + j * p] == '.': s[i + j * p] = str((int(s[i + (j - 1) * p]) + 1) % ...
59
46
0
207019108
t=int(input().split()[1]) k=list(input()) # tide i=next((i for i,(x,y)in enumerate(zip(k,k[t:]))if not x==y!='.'),-1) if i<0:print('No') else: #reverse if k[i]=='.':k[i]='01'[k[i+t]in'.0'] if k[i+t]=='.':k[i+t]='01'[k[i]=='0'] # a tideof reverse print(''.join(k).replace('.','0'))
Codeforces Round 487 (Div. 2)
CF
2,018
1
256
A Tide of Riverscape
The records are expressed as a string $$$s$$$ of characters '0', '1' and '.', where '0' denotes a low tide, '1' denotes a high tide, and '.' denotes an unknown one (either high or low). You are to help Mino determine whether it's possible that after replacing each '.' independently with '0' or '1', a given integer $$$...
The first line contains two space-separated integers $$$n$$$ and $$$p$$$ ($$$1 \leq p \leq n \leq 2000$$$) — the length of the given string and the supposed period, respectively. The second line contains a string $$$s$$$ of $$$n$$$ characters — Mino's records. $$$s$$$ only contains characters '0', '1' and '.', and con...
Output one line — if it's possible that $$$p$$$ is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)).
null
In the first example, $$$7$$$ is not a period of the resulting string because the $$$1$$$-st and $$$8$$$-th characters of it are different. In the second example, $$$6$$$ is not a period of the resulting string because the $$$4$$$-th and $$$10$$$-th characters of it are different. In the third example, $$$9$$$ is alw...
[{"input": "10 7\n1.0.1.0.1.", "output": "1000100010"}, {"input": "10 6\n1.0.1.1000", "output": "1001101000"}, {"input": "10 9\n1........1", "output": "No"}]
1,200
["constructive algorithms", "strings"]
59
[{"input": "10 7\r\n1.0.1.0.1.\r\n", "output": "1000100010\r\n"}, {"input": "10 6\r\n1.0.1.1000\r\n", "output": "1001101000\r\n"}, {"input": "10 9\r\n1........1\r\n", "output": "No\r\n"}, {"input": "1 1\r\n.\r\n", "output": "No\r\n"}, {"input": "5 1\r\n0...1\r\n", "output": "00001\r\n"}, {"input": "17 10\r\n..1.100..1....
false
stdio
import sys def main(): input_path = sys.argv[1] ref_path = sys.argv[2] sub_path = sys.argv[3] with open(input_path, 'r') as f: n, p = map(int, f.readline().split()) s = f.readline().strip() with open(ref_path, 'r') as f: ref_output = f.read().strip() with open(sub_pat...
true
623/A
623
A
Python 3
TESTS
2
46
204,800
15831363
def main(): n, m = map(int, input().split()) g = [[0] * n for i in range(n)] for i in range(m): x, y = map(int, input().split()) g[x-1][y-1] = 1 g[y-1][x-1] = 1 a, c = -1, -1 for i in range(n): for j in range(i+1,n): if(g[i][j] == 0): a, c = i, j if((a, c) == (-1, -1)): print("Yes") print("a"*...
106
998
10,240,000
197642839
f = lambda: map(int, input().split()) n, m = f() p = [1 << i for i in range(n)] for i in range(m): x, y = f() x -= 1 y -= 1 p[x] |= 1 << y p[y] |= 1 << x s = set(p) b = (1 << n) - 1 t = {} if b in s: t[b] = 'b' s.remove(b) if len(s) == 2: a, c = s if a | c == b and bool(a & c) == (b ...
AIM Tech Round (Div. 1)
CF
2,016
2
256
Graph and String
One day student Vasya was sitting on a lecture and mentioned a string s1s2... sn, consisting of letters "a", "b" and "c" that was written on his desk. As the lecture was boring, Vasya decided to complete the picture by composing a graph G with the following properties: - G has exactly n vertices, numbered from 1 to n....
The first line of the input contains two integers n and m $$( 1 \leq n \leq 500, 0 \leq m \leq \frac { n ( n - 1 ) } { 2 } )$$ — the number of vertices and edges in the graph found by Petya, respectively. Each of the next m lines contains two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the edges of the graph G. It ...
In the first line print "Yes" (without the quotes), if the string s Petya is interested in really exists and "No" (without the quotes) otherwise. If the string s exists, then print it on the second line of the output. The length of s must be exactly n, it must consist of only letters "a", "b" and "c" only, and the gra...
null
In the first sample you are given a graph made of two vertices with an edge between them. So, these vertices can correspond to both the same and adjacent letters. Any of the following strings "aa", "ab", "ba", "bb", "bc", "cb", "cc" meets the graph's conditions. In the second sample the first vertex is connected to al...
[{"input": "2 1\n1 2", "output": "Yes\naa"}, {"input": "4 3\n1 2\n1 3\n1 4", "output": "No"}]
1,800
["constructive algorithms", "graphs"]
106
[{"input": "2 1\r\n1 2\r\n", "output": "Yes\r\naa\r\n"}, {"input": "4 3\r\n1 2\r\n1 3\r\n1 4\r\n", "output": "No\r\n"}, {"input": "4 4\r\n1 2\r\n1 3\r\n1 4\r\n3 4\r\n", "output": "Yes\r\nbacc\r\n"}, {"input": "1 0\r\n", "output": "Yes\r\na\r\n"}, {"input": "8 28\r\n3 2\r\n4 2\r\n7 4\r\n6 3\r\n3 7\r\n8 1\r\n3 4\r\n5 1\r...
false
stdio
import sys def main(): input_path = sys.argv[1] ref_output_path = sys.argv[2] sub_output_path = sys.argv[3] # Read input with open(input_path) as f: n, m = map(int, f.readline().split()) edges = [] for _ in range(m): u, v = map(int, f.readline().split()) ...
true
822/B
822
B
Python 3
TESTS
3
62
6,963,200
128116752
#822B (64No. Problem B) n,m = map(int,input().split()) s,t = input(),input() if (s == t): print(0) else: if (len(s) == 1 and len(t) == 1): print(1) else: r = m-n+1 e = n check = [] for i in range(r): check.append(t[i:e]) e+=1 # print(check) m = 0 rchunk = '' ...
113
77
2,150,400
220126290
n, m = map(int, input().split()) s = input() t = input() m = len(t) mn = [float('inf'), []] def cmp(x): ret = [0, []] for i in range(n): if s[i] != x[i]: ret[0] = max(ret[0], 0) + 1 ret[1].append(i + 1) return ret for i in range(m - n + 1): mn = min(mn, cmp(t[i: ...
Codeforces Round 422 (Div. 2)
CF
2,017
1
256
Crossword solving
Erelong Leha was bored by calculating of the greatest common divisor of two factorials. Therefore he decided to solve some crosswords. It's well known that it is a very interesting occupation though it can be very difficult from time to time. In the course of solving one of the crosswords, Leha had to solve a simple ta...
The first line contains two integers n and m (1 ≤ n ≤ m ≤ 1000) — the length of the string s and the length of the string t correspondingly. The second line contains n lowercase English letters — string s. The third line contains m lowercase English letters — string t.
In the first line print single integer k — the minimal number of symbols that need to be replaced. In the second line print k distinct integers denoting the positions of symbols in the string s which need to be replaced. Print the positions in any order. If there are several solutions print any of them. The numbering ...
null
null
[{"input": "3 5\nabc\nxaybz", "output": "2\n2 3"}, {"input": "4 10\nabcd\nebceabazcd", "output": "1\n2"}]
1,000
["brute force", "implementation", "strings"]
113
[{"input": "3 5\r\nabc\r\nxaybz\r\n", "output": "2\r\n2 3 \r\n"}, {"input": "4 10\r\nabcd\r\nebceabazcd\r\n", "output": "1\r\n2 \r\n"}, {"input": "1 1\r\na\r\na\r\n", "output": "0\r\n\r\n"}, {"input": "1 1\r\na\r\nz\r\n", "output": "1\r\n1 \r\n"}, {"input": "3 5\r\naaa\r\naaaaa\r\n", "output": "0\r\n\r\n"}, {"input": "...
false
stdio
null
true
796/C
796
C
PyPy 3-64
TESTS
5
77
3,481,600
215808441
# Problem: C. Bank Hacking # Contest: Codeforces - Codeforces Round 408 (Div. 2) # URL: https://codeforces.com/problemset/problem/796/C # Memory Limit: 256 MB # Time Limit: 2000 ms import sys import random from types import GeneratorType import bisect import io, os from bisect import * from collections import * from c...
129
576
88,166,400
215848244
from sys import stdin def RI(): return int(stdin.readline()[:-1]) def RILIST(): return [int(i) for i in stdin.readline()[:-1].split()] def lower_bound(l,r,f): while l < r: mid = (l+r) // 2 if f(mid) : r = mid else: l = mid+1 return l def main(): n...
Codeforces Round 408 (Div. 2)
CF
2,017
2
256
Bank Hacking
Although Inzane successfully found his beloved bone, Zane, his owner, has yet to return. To search for Zane, he would need a lot of money, of which he sadly has none. To deal with the problem, he has decided to hack the banks. There are n banks, numbered from 1 to n. There are also n - 1 wires connecting the banks. Al...
The first line contains one integer n (1 ≤ n ≤ 3·105) — the total number of banks. The second line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — the strengths of the banks. Each of the next n - 1 lines contains two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — meaning that there is a wire directly connec...
Print one integer — the minimum strength of the computer Inzane needs to accomplish the goal.
null
In the first sample, Inzane can hack all banks using a computer with strength 5. Here is how: - Initially, strengths of the banks are [1, 2, 3, 4, 5]. - He hacks bank 5, then strengths of the banks become [1, 2, 4, 5,  - ]. - He hacks bank 4, then strengths of the banks become [1, 3, 5,  - ,  - ]. - He hacks bank 3, t...
[{"input": "5\n1 2 3 4 5\n1 2\n2 3\n3 4\n4 5", "output": "5"}, {"input": "7\n38 -29 87 93 39 28 -55\n1 2\n2 5\n3 2\n2 4\n1 7\n7 6", "output": "93"}, {"input": "5\n1 2 7 6 7\n1 5\n5 3\n3 4\n2 4", "output": "8"}]
1,900
["constructive algorithms", "data structures", "dp", "trees"]
129
[{"input": "5\r\n1 2 3 4 5\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n", "output": "5"}, {"input": "7\r\n38 -29 87 93 39 28 -55\r\n1 2\r\n2 5\r\n3 2\r\n2 4\r\n1 7\r\n7 6\r\n", "output": "93"}, {"input": "5\r\n1 2 7 6 7\r\n1 5\r\n5 3\r\n3 4\r\n2 4\r\n", "output": "8"}, {"input": "3\r\n2 2 2\r\n3 2\r\n1 2\r\n", "output": "3"}, {"inp...
false
stdio
null
true
814/B
814
B
Python 3
TESTS
36
61
409,600
27638881
n = int(input()) a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] x = [] a_used = [False] * (n+1) b_used = [False] * (n+1) for i in range(len(a)): a_used[a[i]] = True b_used[b[i]] = True if a[i] != b[i]: x.append(i) if len(x) == 2: for i in range(len(x)): if a...
54
61
0
187165092
import sys input = sys.stdin.buffer.readline def process(A, B): n = len(A) d = [[[], []] for i in range(n+1)] for i in range(n): ai = A[i] d[ai][0].append(i) bi = B[i] d[bi][1].append(i) answer = [None for i in range(n)] used = [0 for i in range(n+1)] extra = [...
Codeforces Round 418 (Div. 2)
CF
2,017
1
256
An express train to reveries
Sengoku still remembers the mysterious "colourful meteoroids" she discovered with Lala-chan when they were little. In particular, one of the nights impressed her deeply, giving her the illusion that all her fancies would be realized. On that night, Sengoku constructed a permutation p1, p2, ..., pn of integers from 1 t...
The first line of input contains a positive integer n (2 ≤ n ≤ 1 000) — the length of Sengoku's permutation, being the length of both meteor outbursts at the same time. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ n) — the sequence of colours in the first meteor outburst. The third li...
Output n space-separated integers p1, p2, ..., pn, denoting a possible permutation Sengoku could have had. If there are more than one possible answer, output any one of them. Input guarantees that such permutation exists.
null
In the first sample, both 1, 2, 5, 4, 3 and 1, 2, 3, 4, 5 are acceptable outputs. In the second sample, 5, 4, 2, 3, 1 is the only permutation to satisfy the constraints.
[{"input": "5\n1 2 3 4 3\n1 2 5 4 5", "output": "1 2 5 4 3"}, {"input": "5\n4 4 2 3 1\n5 4 5 3 1", "output": "5 4 2 3 1"}, {"input": "4\n1 1 3 4\n1 4 3 4", "output": "1 2 3 4"}]
1,300
["constructive algorithms"]
54
[{"input": "5\r\n1 2 3 4 3\r\n1 2 5 4 5\r\n", "output": "1 2 5 4 3\r\n"}, {"input": "5\r\n4 4 2 3 1\r\n5 4 5 3 1\r\n", "output": "5 4 2 3 1\r\n"}, {"input": "4\r\n1 1 3 4\r\n1 4 3 4\r\n", "output": "1 2 3 4\r\n"}, {"input": "10\r\n1 2 3 4 7 6 7 8 9 10\r\n1 2 3 4 5 6 5 8 9 10\r\n", "output": "1 2 3 4 5 6 7 8 9 10\r\n"},...
false
stdio
import sys def is_permutation(p, n): if len(p) != n: return False seen = [False] * (n + 1) for num in p: if not (1 <= num <= n) or seen[num]: return False seen[num] = True return True def main(input_path, output_path, submission_path): with open(input_path) as f...
true
416/D
416
D
Python 3
TESTS
17
62
0
6500833
import sys n = int(sys.stdin.readline()) if n <= 2: print(1) sys.exit(0) a = [int(s) for s in sys.stdin.readline().split()] # number of arithmetic progressions seg = [-1 for i in range(0,n)] # start and end positive number for a arithmetic progressions # eg # -1 6 -1 2 -1 [start=1 (the number 6), end=3 (the num...
84
373
16,384,000
6954252
n = int(input()) a = list(map(int, input().split())) i = 0 ans = 0 while i < n: ans += 1 i1 = i while i1 < n and a[i1] == -1: i1 += 1 if i1 == n: break i2 = i1 + 1 while i2 < n and a[i2] == -1: i2 += 1 if i2 == n: break dist = i2 - i1 step = (a[i2] - a...
Codeforces Round 241 (Div. 2)
CF
2,014
1
256
Population Size
Polycarpus develops an interesting theory about the interrelation of arithmetic progressions with just everything in the world. His current idea is that the population of the capital of Berland changes over time like an arithmetic progression. Well, or like multiple arithmetic progressions. Polycarpus believes that if...
The first line of the input contains integer n (1 ≤ n ≤ 2·105) — the number of elements in the sequence. The second line contains integer values a1, a2, ..., an separated by a space (1 ≤ ai ≤ 109 or ai = - 1).
Print the minimum number of arithmetic progressions that you need to write one after another to get sequence a. The positions marked as -1 in a can be represented by any positive integers.
null
null
[{"input": "9\n8 6 4 2 1 4 7 10 2", "output": "3"}, {"input": "9\n-1 6 -1 2 -1 4 7 -1 2", "output": "3"}, {"input": "5\n-1 -1 -1 -1 -1", "output": "1"}, {"input": "7\n-1 -1 4 5 1 2 3", "output": "2"}]
2,400
["greedy", "implementation", "math"]
84
[{"input": "9\r\n8 6 4 2 1 4 7 10 2\r\n", "output": "3\r\n"}, {"input": "9\r\n-1 6 -1 2 -1 4 7 -1 2\r\n", "output": "3\r\n"}, {"input": "5\r\n-1 -1 -1 -1 -1\r\n", "output": "1\r\n"}, {"input": "7\r\n-1 -1 4 5 1 2 3\r\n", "output": "2\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n65\r\n", "output": ...
false
stdio
null
true
416/D
416
D
PyPy 3
TESTS
17
109
0
10236959
R = lambda: list(map(int, input().split())) n = int(input()) a = R() INF = 10000000000 delta = INF ans = 1 for i in range(1, n): if a[i] != -1 and a[i - 1] != -1 and a[i] - a[i - 1] != delta: if delta != INF: ans += 1 delta = INF else: delta = a[i] - a[i - 1] ...
84
171
27,648,000
302828817
import sys,math,heapq from collections import Counter #sys.setrecursionlimit(200000) #fin = open('input.txt', 'r') #input = lambda: fin.readline().strip() input=lambda: sys.stdin.readline().strip() import random RANDOM = random.getrandbits(20) class Wrapper(int): def __init__(self, x): int.__init__(x) ...
Codeforces Round 241 (Div. 2)
CF
2,014
1
256
Population Size
Polycarpus develops an interesting theory about the interrelation of arithmetic progressions with just everything in the world. His current idea is that the population of the capital of Berland changes over time like an arithmetic progression. Well, or like multiple arithmetic progressions. Polycarpus believes that if...
The first line of the input contains integer n (1 ≤ n ≤ 2·105) — the number of elements in the sequence. The second line contains integer values a1, a2, ..., an separated by a space (1 ≤ ai ≤ 109 or ai = - 1).
Print the minimum number of arithmetic progressions that you need to write one after another to get sequence a. The positions marked as -1 in a can be represented by any positive integers.
null
null
[{"input": "9\n8 6 4 2 1 4 7 10 2", "output": "3"}, {"input": "9\n-1 6 -1 2 -1 4 7 -1 2", "output": "3"}, {"input": "5\n-1 -1 -1 -1 -1", "output": "1"}, {"input": "7\n-1 -1 4 5 1 2 3", "output": "2"}]
2,400
["greedy", "implementation", "math"]
84
[{"input": "9\r\n8 6 4 2 1 4 7 10 2\r\n", "output": "3\r\n"}, {"input": "9\r\n-1 6 -1 2 -1 4 7 -1 2\r\n", "output": "3\r\n"}, {"input": "5\r\n-1 -1 -1 -1 -1\r\n", "output": "1\r\n"}, {"input": "7\r\n-1 -1 4 5 1 2 3\r\n", "output": "2\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n65\r\n", "output": ...
false
stdio
null
true
814/B
814
B
Python 3
TESTS
30
109
307,200
49654680
n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) k = [] c = [0] * (n + 1) for i in range(n): if a[i] != b[i]: k.append(i) c[a[i]] += 1 p = 0 for i in range(1, n + 1): if i not in a: p = i break if len(k) == 1: a[k[0]] = p print(" ".jo...
54
61
307,200
27647162
import sys input = sys.stdin.readline n = int(input()) a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] perm = [-1 for i in range(n)] avail = set() for i in range(1,n+1): avail.add(i) for i in range(n): if a[i] == b[i]: avail.remove(a[i]) perm[i] = a[i] def diff...
Codeforces Round 418 (Div. 2)
CF
2,017
1
256
An express train to reveries
Sengoku still remembers the mysterious "colourful meteoroids" she discovered with Lala-chan when they were little. In particular, one of the nights impressed her deeply, giving her the illusion that all her fancies would be realized. On that night, Sengoku constructed a permutation p1, p2, ..., pn of integers from 1 t...
The first line of input contains a positive integer n (2 ≤ n ≤ 1 000) — the length of Sengoku's permutation, being the length of both meteor outbursts at the same time. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ n) — the sequence of colours in the first meteor outburst. The third li...
Output n space-separated integers p1, p2, ..., pn, denoting a possible permutation Sengoku could have had. If there are more than one possible answer, output any one of them. Input guarantees that such permutation exists.
null
In the first sample, both 1, 2, 5, 4, 3 and 1, 2, 3, 4, 5 are acceptable outputs. In the second sample, 5, 4, 2, 3, 1 is the only permutation to satisfy the constraints.
[{"input": "5\n1 2 3 4 3\n1 2 5 4 5", "output": "1 2 5 4 3"}, {"input": "5\n4 4 2 3 1\n5 4 5 3 1", "output": "5 4 2 3 1"}, {"input": "4\n1 1 3 4\n1 4 3 4", "output": "1 2 3 4"}]
1,300
["constructive algorithms"]
54
[{"input": "5\r\n1 2 3 4 3\r\n1 2 5 4 5\r\n", "output": "1 2 5 4 3\r\n"}, {"input": "5\r\n4 4 2 3 1\r\n5 4 5 3 1\r\n", "output": "5 4 2 3 1\r\n"}, {"input": "4\r\n1 1 3 4\r\n1 4 3 4\r\n", "output": "1 2 3 4\r\n"}, {"input": "10\r\n1 2 3 4 7 6 7 8 9 10\r\n1 2 3 4 5 6 5 8 9 10\r\n", "output": "1 2 3 4 5 6 7 8 9 10\r\n"},...
false
stdio
import sys def is_permutation(p, n): if len(p) != n: return False seen = [False] * (n + 1) for num in p: if not (1 <= num <= n) or seen[num]: return False seen[num] = True return True def main(input_path, output_path, submission_path): with open(input_path) as f...
true
814/B
814
B
Python 3
TESTS
30
109
0
49376041
n=int(input()) l=list(map(int,input().split())) l1=list(map(int,input().split())) l2=[] k=0 s=set(l) for i in range(n) : if l[i]==l1[i] : l2.append(l[i]) else : if l.count(l[i])>1 : if k==0 : if l1[i] not in s : l2.append(l1[i]) ...
54
62
307,200
27635390
import sys n = int(input()) a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] p1, p2, p3, p4 = [], [], [], [] cur = 0 for i in range(n): if a[i] == b[i]: for p in (p1, p2, p3, p4): p.append(a[i]) elif cur == 0: p1.append(a[i]) p2.append(a[i]) ...
Codeforces Round 418 (Div. 2)
CF
2,017
1
256
An express train to reveries
Sengoku still remembers the mysterious "colourful meteoroids" she discovered with Lala-chan when they were little. In particular, one of the nights impressed her deeply, giving her the illusion that all her fancies would be realized. On that night, Sengoku constructed a permutation p1, p2, ..., pn of integers from 1 t...
The first line of input contains a positive integer n (2 ≤ n ≤ 1 000) — the length of Sengoku's permutation, being the length of both meteor outbursts at the same time. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ n) — the sequence of colours in the first meteor outburst. The third li...
Output n space-separated integers p1, p2, ..., pn, denoting a possible permutation Sengoku could have had. If there are more than one possible answer, output any one of them. Input guarantees that such permutation exists.
null
In the first sample, both 1, 2, 5, 4, 3 and 1, 2, 3, 4, 5 are acceptable outputs. In the second sample, 5, 4, 2, 3, 1 is the only permutation to satisfy the constraints.
[{"input": "5\n1 2 3 4 3\n1 2 5 4 5", "output": "1 2 5 4 3"}, {"input": "5\n4 4 2 3 1\n5 4 5 3 1", "output": "5 4 2 3 1"}, {"input": "4\n1 1 3 4\n1 4 3 4", "output": "1 2 3 4"}]
1,300
["constructive algorithms"]
54
[{"input": "5\r\n1 2 3 4 3\r\n1 2 5 4 5\r\n", "output": "1 2 5 4 3\r\n"}, {"input": "5\r\n4 4 2 3 1\r\n5 4 5 3 1\r\n", "output": "5 4 2 3 1\r\n"}, {"input": "4\r\n1 1 3 4\r\n1 4 3 4\r\n", "output": "1 2 3 4\r\n"}, {"input": "10\r\n1 2 3 4 7 6 7 8 9 10\r\n1 2 3 4 5 6 5 8 9 10\r\n", "output": "1 2 3 4 5 6 7 8 9 10\r\n"},...
false
stdio
import sys def is_permutation(p, n): if len(p) != n: return False seen = [False] * (n + 1) for num in p: if not (1 <= num <= n) or seen[num]: return False seen[num] = True return True def main(input_path, output_path, submission_path): with open(input_path) as f...
true
814/B
814
B
Python 3
TESTS
44
62
409,600
27637131
n = int(input()) a = [int(num) for num in input().split()] b = [int(num) for num in input().split()] difs = [] for ind, (fst, scd) in enumerate(zip(a, b)): if fst != scd: difs.append(ind) res = None if len(difs) == 1: res = list(a) res.remove(res[difs[0]]) res.insert(difs[0], sum(range(1, n + ...
54
62
307,200
27638925
import sys def main(): n=int(sys.stdin.readline().rstrip()) a=list(map(int,sys.stdin.readline().split())) b=list(map(int,sys.stdin.readline().split())) items=set(range(1,n+1)) coords=[] p=[-1]*n for i in range(n): if a[i]==b[i]: items.remove(a[i]) p...
Codeforces Round 418 (Div. 2)
CF
2,017
1
256
An express train to reveries
Sengoku still remembers the mysterious "colourful meteoroids" she discovered with Lala-chan when they were little. In particular, one of the nights impressed her deeply, giving her the illusion that all her fancies would be realized. On that night, Sengoku constructed a permutation p1, p2, ..., pn of integers from 1 t...
The first line of input contains a positive integer n (2 ≤ n ≤ 1 000) — the length of Sengoku's permutation, being the length of both meteor outbursts at the same time. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ n) — the sequence of colours in the first meteor outburst. The third li...
Output n space-separated integers p1, p2, ..., pn, denoting a possible permutation Sengoku could have had. If there are more than one possible answer, output any one of them. Input guarantees that such permutation exists.
null
In the first sample, both 1, 2, 5, 4, 3 and 1, 2, 3, 4, 5 are acceptable outputs. In the second sample, 5, 4, 2, 3, 1 is the only permutation to satisfy the constraints.
[{"input": "5\n1 2 3 4 3\n1 2 5 4 5", "output": "1 2 5 4 3"}, {"input": "5\n4 4 2 3 1\n5 4 5 3 1", "output": "5 4 2 3 1"}, {"input": "4\n1 1 3 4\n1 4 3 4", "output": "1 2 3 4"}]
1,300
["constructive algorithms"]
54
[{"input": "5\r\n1 2 3 4 3\r\n1 2 5 4 5\r\n", "output": "1 2 5 4 3\r\n"}, {"input": "5\r\n4 4 2 3 1\r\n5 4 5 3 1\r\n", "output": "5 4 2 3 1\r\n"}, {"input": "4\r\n1 1 3 4\r\n1 4 3 4\r\n", "output": "1 2 3 4\r\n"}, {"input": "10\r\n1 2 3 4 7 6 7 8 9 10\r\n1 2 3 4 5 6 5 8 9 10\r\n", "output": "1 2 3 4 5 6 7 8 9 10\r\n"},...
false
stdio
import sys def is_permutation(p, n): if len(p) != n: return False seen = [False] * (n + 1) for num in p: if not (1 <= num <= n) or seen[num]: return False seen[num] = True return True def main(input_path, output_path, submission_path): with open(input_path) as f...
true
814/B
814
B
Python 3
TESTS
30
77
614,400
27666126
from collections import Counter def read(): return map(int, input().split()) n = int(input()) a = list(read()) b = list(read()) x, = [i for i, j in Counter(a).items() if j > 1] v, = set(range(1, n + 1)) - set(a) for i in range(n): if a[i] != b[i] and a[i] == x: a[i] = v break print(*a)
54
62
307,200
27640722
from operator import eq n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) al = [False for _ in range(n)] bl = [False for _ in range(n)] for i in range(n): al[a[i]-1] = True bl[b[i]-1] = True for i,e in enumerate(al): if not e: ak = i+1 for i,e in enumerate...
Codeforces Round 418 (Div. 2)
CF
2,017
1
256
An express train to reveries
Sengoku still remembers the mysterious "colourful meteoroids" she discovered with Lala-chan when they were little. In particular, one of the nights impressed her deeply, giving her the illusion that all her fancies would be realized. On that night, Sengoku constructed a permutation p1, p2, ..., pn of integers from 1 t...
The first line of input contains a positive integer n (2 ≤ n ≤ 1 000) — the length of Sengoku's permutation, being the length of both meteor outbursts at the same time. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ n) — the sequence of colours in the first meteor outburst. The third li...
Output n space-separated integers p1, p2, ..., pn, denoting a possible permutation Sengoku could have had. If there are more than one possible answer, output any one of them. Input guarantees that such permutation exists.
null
In the first sample, both 1, 2, 5, 4, 3 and 1, 2, 3, 4, 5 are acceptable outputs. In the second sample, 5, 4, 2, 3, 1 is the only permutation to satisfy the constraints.
[{"input": "5\n1 2 3 4 3\n1 2 5 4 5", "output": "1 2 5 4 3"}, {"input": "5\n4 4 2 3 1\n5 4 5 3 1", "output": "5 4 2 3 1"}, {"input": "4\n1 1 3 4\n1 4 3 4", "output": "1 2 3 4"}]
1,300
["constructive algorithms"]
54
[{"input": "5\r\n1 2 3 4 3\r\n1 2 5 4 5\r\n", "output": "1 2 5 4 3\r\n"}, {"input": "5\r\n4 4 2 3 1\r\n5 4 5 3 1\r\n", "output": "5 4 2 3 1\r\n"}, {"input": "4\r\n1 1 3 4\r\n1 4 3 4\r\n", "output": "1 2 3 4\r\n"}, {"input": "10\r\n1 2 3 4 7 6 7 8 9 10\r\n1 2 3 4 5 6 5 8 9 10\r\n", "output": "1 2 3 4 5 6 7 8 9 10\r\n"},...
false
stdio
import sys def is_permutation(p, n): if len(p) != n: return False seen = [False] * (n + 1) for num in p: if not (1 <= num <= n) or seen[num]: return False seen[num] = True return True def main(input_path, output_path, submission_path): with open(input_path) as f...
true
814/B
814
B
Python 3
TESTS
30
77
307,200
27745175
n, a, b = int(input()), list(map(int, input().split())), list(map(int, input().split())) c = [1] + [0] * n for ai in a: c[ai] += 1 d, e = c.index(0), c.index(2) ei1 = a.index(e) ei2 = a.index(e, ei1 + 1) a[ei1 if a[ei1] != b[ei1] else ei2] = d print(' '.join(map(str, a)))
54
62
307,200
27644132
n = int(input()) a = input().split() b = input().split() a = [int(i) for i in a] b = [int(i) for i in b] counter = [-1 for i in range(n)] k_a = 0 k_a_i1, k_a_i2 = -1, -1 for i in range(n): if counter[a[i] - 1] != -1: k_a = a[i] k_a_i1, k_a_i2 = counter[a[i] - 1], i counter[a[i] - 1] = i g_a =...
Codeforces Round 418 (Div. 2)
CF
2,017
1
256
An express train to reveries
Sengoku still remembers the mysterious "colourful meteoroids" she discovered with Lala-chan when they were little. In particular, one of the nights impressed her deeply, giving her the illusion that all her fancies would be realized. On that night, Sengoku constructed a permutation p1, p2, ..., pn of integers from 1 t...
The first line of input contains a positive integer n (2 ≤ n ≤ 1 000) — the length of Sengoku's permutation, being the length of both meteor outbursts at the same time. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ n) — the sequence of colours in the first meteor outburst. The third li...
Output n space-separated integers p1, p2, ..., pn, denoting a possible permutation Sengoku could have had. If there are more than one possible answer, output any one of them. Input guarantees that such permutation exists.
null
In the first sample, both 1, 2, 5, 4, 3 and 1, 2, 3, 4, 5 are acceptable outputs. In the second sample, 5, 4, 2, 3, 1 is the only permutation to satisfy the constraints.
[{"input": "5\n1 2 3 4 3\n1 2 5 4 5", "output": "1 2 5 4 3"}, {"input": "5\n4 4 2 3 1\n5 4 5 3 1", "output": "5 4 2 3 1"}, {"input": "4\n1 1 3 4\n1 4 3 4", "output": "1 2 3 4"}]
1,300
["constructive algorithms"]
54
[{"input": "5\r\n1 2 3 4 3\r\n1 2 5 4 5\r\n", "output": "1 2 5 4 3\r\n"}, {"input": "5\r\n4 4 2 3 1\r\n5 4 5 3 1\r\n", "output": "5 4 2 3 1\r\n"}, {"input": "4\r\n1 1 3 4\r\n1 4 3 4\r\n", "output": "1 2 3 4\r\n"}, {"input": "10\r\n1 2 3 4 7 6 7 8 9 10\r\n1 2 3 4 5 6 5 8 9 10\r\n", "output": "1 2 3 4 5 6 7 8 9 10\r\n"},...
false
stdio
import sys def is_permutation(p, n): if len(p) != n: return False seen = [False] * (n + 1) for num in p: if not (1 <= num <= n) or seen[num]: return False seen[num] = True return True def main(input_path, output_path, submission_path): with open(input_path) as f...
true
356/C
356
C
PyPy 3
TESTS
7
405
53,145,600
92569143
import math n=int(input()) arr=list(map(int,input().strip().split(' '))) dic=[0 for i in range(5)] sum=0 for i in arr: sum+=i dic[i]+=1 if sum in [1,2,5]: print(-1) quit() res=0 res+=dic[1] dic[2]-=dic[1] if dic[2]>0: if dic[2]>dic[4]: res+=dic[4] else: res+=dic[2] dic[2]-=di...
141
607
14,745,600
42135284
#! /usr/bin/env python n = int(input()) counts = [0] * 5 nums = [int(x) for x in input().split()] for x in nums: counts[x] += 1 s = sum(nums) if s > 2 and s != 5: ans = 0 if counts[1] >= counts[2]: ans += counts[2] counts[3] += counts[2] counts[1] -= counts[2] ans += 2 * (c...
Codeforces Round 207 (Div. 1)
CF
2,013
1
256
Compartments
A team of students from the city S is sent to the All-Berland Olympiad in Informatics. Traditionally, they go on the train. All students have bought tickets in one carriage, consisting of n compartments (each compartment has exactly four people). We know that if one compartment contain one or two students, then they ge...
The first line contains integer n (1 ≤ n ≤ 106) — the number of compartments in the carriage. The second line contains n integers a1, a2, ..., an showing how many students ride in each compartment (0 ≤ ai ≤ 4). It is guaranteed that at least one student is riding in the train.
If no sequence of swapping seats with other people leads to the desired result, print number "-1" (without the quotes). In another case, print the smallest number of people you need to persuade to swap places.
null
null
[{"input": "5\n1 2 2 4 3", "output": "2"}, {"input": "3\n4 1 1", "output": "2"}, {"input": "4\n0 3 0 4", "output": "0"}]
2,100
["combinatorics", "constructive algorithms", "greedy", "implementation"]
141
[{"input": "5\r\n1 2 2 4 3\r\n", "output": "2\r\n"}, {"input": "3\r\n4 1 1\r\n", "output": "2\r\n"}, {"input": "4\r\n0 3 0 4\r\n", "output": "0\r\n"}, {"input": "5\r\n4 4 3 3 1\r\n", "output": "1\r\n"}, {"input": "5\r\n4 3 4 2 4\r\n", "output": "1\r\n"}, {"input": "10\r\n2 1 2 3 4 1 3 4 4 4\r\n", "output": "2\r\n"}, {"...
false
stdio
null
true
814/B
814
B
Python 3
TESTS
36
62
409,600
27666374
def read(): return map(int, input().split()) n = int(input()) a = list(read()) b = list(read()) v, = set(range(1, n + 1)) - set(a) p = list(a) for i in range(n): if a[i] != b[i]: p[i] = v if len([1 for i in range(n) if p[i] != b[i]]) == 1: break p[i] = a[i] print(*p)
54
62
307,200
27646325
size = int(input()) a = [int(elem) for elem in input().split()] b = [int(elem) for elem in input().split()] right = [] a_remain = [] b_remain = [] cand = [] for idx in range(size): if a[idx] == b[idx]: right.append(a[idx]) else: right.append(0) a_remain.append(a[idx]) b_remain.a...
Codeforces Round 418 (Div. 2)
CF
2,017
1
256
An express train to reveries
Sengoku still remembers the mysterious "colourful meteoroids" she discovered with Lala-chan when they were little. In particular, one of the nights impressed her deeply, giving her the illusion that all her fancies would be realized. On that night, Sengoku constructed a permutation p1, p2, ..., pn of integers from 1 t...
The first line of input contains a positive integer n (2 ≤ n ≤ 1 000) — the length of Sengoku's permutation, being the length of both meteor outbursts at the same time. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ n) — the sequence of colours in the first meteor outburst. The third li...
Output n space-separated integers p1, p2, ..., pn, denoting a possible permutation Sengoku could have had. If there are more than one possible answer, output any one of them. Input guarantees that such permutation exists.
null
In the first sample, both 1, 2, 5, 4, 3 and 1, 2, 3, 4, 5 are acceptable outputs. In the second sample, 5, 4, 2, 3, 1 is the only permutation to satisfy the constraints.
[{"input": "5\n1 2 3 4 3\n1 2 5 4 5", "output": "1 2 5 4 3"}, {"input": "5\n4 4 2 3 1\n5 4 5 3 1", "output": "5 4 2 3 1"}, {"input": "4\n1 1 3 4\n1 4 3 4", "output": "1 2 3 4"}]
1,300
["constructive algorithms"]
54
[{"input": "5\r\n1 2 3 4 3\r\n1 2 5 4 5\r\n", "output": "1 2 5 4 3\r\n"}, {"input": "5\r\n4 4 2 3 1\r\n5 4 5 3 1\r\n", "output": "5 4 2 3 1\r\n"}, {"input": "4\r\n1 1 3 4\r\n1 4 3 4\r\n", "output": "1 2 3 4\r\n"}, {"input": "10\r\n1 2 3 4 7 6 7 8 9 10\r\n1 2 3 4 5 6 5 8 9 10\r\n", "output": "1 2 3 4 5 6 7 8 9 10\r\n"},...
false
stdio
import sys def is_permutation(p, n): if len(p) != n: return False seen = [False] * (n + 1) for num in p: if not (1 <= num <= n) or seen[num]: return False seen[num] = True return True def main(input_path, output_path, submission_path): with open(input_path) as f...
true
814/B
814
B
PyPy 3
TESTS
30
109
512,000
27769884
import sys l = int(sys.stdin.readline()) a = list(map(int, sys.stdin.readline().split())) b = list(map(int, sys.stdin.readline().split())) digits = [0] * (l + 1) diff_digits = [] for i in range(l): digits[a[i]] += 1 if a[i] != b[i]: diff_digits.append(i) res = a[:] if len(diff_digits) == 1: dd ...
54
62
307,200
27646876
import sys read=lambda:sys.stdin.readline().rstrip() readi=lambda:int(sys.stdin.readline()) writeln=lambda x:sys.stdout.write(str(x)+"\n") write=lambda x:sys.stdout.write(x) N = readi() A = list(map(int, read().split())) B = list(map(int, read().split())) ncntA = [0]*(N+1) ncntB = [0]*(N+1) diff = [] for i in range(N):...
Codeforces Round 418 (Div. 2)
CF
2,017
1
256
An express train to reveries
Sengoku still remembers the mysterious "colourful meteoroids" she discovered with Lala-chan when they were little. In particular, one of the nights impressed her deeply, giving her the illusion that all her fancies would be realized. On that night, Sengoku constructed a permutation p1, p2, ..., pn of integers from 1 t...
The first line of input contains a positive integer n (2 ≤ n ≤ 1 000) — the length of Sengoku's permutation, being the length of both meteor outbursts at the same time. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ n) — the sequence of colours in the first meteor outburst. The third li...
Output n space-separated integers p1, p2, ..., pn, denoting a possible permutation Sengoku could have had. If there are more than one possible answer, output any one of them. Input guarantees that such permutation exists.
null
In the first sample, both 1, 2, 5, 4, 3 and 1, 2, 3, 4, 5 are acceptable outputs. In the second sample, 5, 4, 2, 3, 1 is the only permutation to satisfy the constraints.
[{"input": "5\n1 2 3 4 3\n1 2 5 4 5", "output": "1 2 5 4 3"}, {"input": "5\n4 4 2 3 1\n5 4 5 3 1", "output": "5 4 2 3 1"}, {"input": "4\n1 1 3 4\n1 4 3 4", "output": "1 2 3 4"}]
1,300
["constructive algorithms"]
54
[{"input": "5\r\n1 2 3 4 3\r\n1 2 5 4 5\r\n", "output": "1 2 5 4 3\r\n"}, {"input": "5\r\n4 4 2 3 1\r\n5 4 5 3 1\r\n", "output": "5 4 2 3 1\r\n"}, {"input": "4\r\n1 1 3 4\r\n1 4 3 4\r\n", "output": "1 2 3 4\r\n"}, {"input": "10\r\n1 2 3 4 7 6 7 8 9 10\r\n1 2 3 4 5 6 5 8 9 10\r\n", "output": "1 2 3 4 5 6 7 8 9 10\r\n"},...
false
stdio
import sys def is_permutation(p, n): if len(p) != n: return False seen = [False] * (n + 1) for num in p: if not (1 <= num <= n) or seen[num]: return False seen[num] = True return True def main(input_path, output_path, submission_path): with open(input_path) as f...
true
814/B
814
B
Python 3
TESTS
36
62
307,200
27719659
n = int(input()) a = list(map(int, input().split(' '))) b = list(map(int, input().split(' '))) output = [0] * n a_hash = [0] * (n + 1) b_hash = [0] * (n + 1) for i, j in zip(a, b): a_hash[i] = 1 b_hash[j] = 1 for i in range(1, n + 1): if a_hash[i] == 0: a_req = i if b_hash[i] == 0: b_req...
54
62
307,200
27648022
n=int(input()) a=[int(x) for x in input().split()] b=[int(x) for x in input().split()] c=[0]*n d=set([x for x in range(1,n+1)]) for x in range(n): if a[x]==b[x]: c[x]=a[x] d.remove(a[x]) elif a.count(a[x])+b.count(a[x])==1: c[x]=a[x] d.remove(a[x]) elif a.count(b[x])+b.count(...
Codeforces Round 418 (Div. 2)
CF
2,017
1
256
An express train to reveries
Sengoku still remembers the mysterious "colourful meteoroids" she discovered with Lala-chan when they were little. In particular, one of the nights impressed her deeply, giving her the illusion that all her fancies would be realized. On that night, Sengoku constructed a permutation p1, p2, ..., pn of integers from 1 t...
The first line of input contains a positive integer n (2 ≤ n ≤ 1 000) — the length of Sengoku's permutation, being the length of both meteor outbursts at the same time. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ n) — the sequence of colours in the first meteor outburst. The third li...
Output n space-separated integers p1, p2, ..., pn, denoting a possible permutation Sengoku could have had. If there are more than one possible answer, output any one of them. Input guarantees that such permutation exists.
null
In the first sample, both 1, 2, 5, 4, 3 and 1, 2, 3, 4, 5 are acceptable outputs. In the second sample, 5, 4, 2, 3, 1 is the only permutation to satisfy the constraints.
[{"input": "5\n1 2 3 4 3\n1 2 5 4 5", "output": "1 2 5 4 3"}, {"input": "5\n4 4 2 3 1\n5 4 5 3 1", "output": "5 4 2 3 1"}, {"input": "4\n1 1 3 4\n1 4 3 4", "output": "1 2 3 4"}]
1,300
["constructive algorithms"]
54
[{"input": "5\r\n1 2 3 4 3\r\n1 2 5 4 5\r\n", "output": "1 2 5 4 3\r\n"}, {"input": "5\r\n4 4 2 3 1\r\n5 4 5 3 1\r\n", "output": "5 4 2 3 1\r\n"}, {"input": "4\r\n1 1 3 4\r\n1 4 3 4\r\n", "output": "1 2 3 4\r\n"}, {"input": "10\r\n1 2 3 4 7 6 7 8 9 10\r\n1 2 3 4 5 6 5 8 9 10\r\n", "output": "1 2 3 4 5 6 7 8 9 10\r\n"},...
false
stdio
import sys def is_permutation(p, n): if len(p) != n: return False seen = [False] * (n + 1) for num in p: if not (1 <= num <= n) or seen[num]: return False seen[num] = True return True def main(input_path, output_path, submission_path): with open(input_path) as f...
true
814/B
814
B
PyPy 3
TESTS
36
140
1,843,200
58561919
input() a = list(map(int, input().split())) b = list(map(int, input().split())) g = 0 p = 1 h = [1 for i in range(len(a))] for i in range(len(a)): if a[i] != b[i]: g += 1 else: h[a[i] - 1] = 0 for i in range(len(a)): if a[i] != b[i]: if g == 1: for j in range(len(h)): ...
54
62
307,200
27650903
import sys def check(a, b, c): ctr1 = 0 ctr2 = 0 for i in range(len(a)): if (a[i] != b[i]): ctr1 += 1 if (a[i] != c[i]): ctr2 += 1 if (ctr1 == 1 and ctr2 == 1): return 1 return 0 n = int(input()) a = list(map(int, input().split())) b = list(map(int, ...
Codeforces Round 418 (Div. 2)
CF
2,017
1
256
An express train to reveries
Sengoku still remembers the mysterious "colourful meteoroids" she discovered with Lala-chan when they were little. In particular, one of the nights impressed her deeply, giving her the illusion that all her fancies would be realized. On that night, Sengoku constructed a permutation p1, p2, ..., pn of integers from 1 t...
The first line of input contains a positive integer n (2 ≤ n ≤ 1 000) — the length of Sengoku's permutation, being the length of both meteor outbursts at the same time. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ n) — the sequence of colours in the first meteor outburst. The third li...
Output n space-separated integers p1, p2, ..., pn, denoting a possible permutation Sengoku could have had. If there are more than one possible answer, output any one of them. Input guarantees that such permutation exists.
null
In the first sample, both 1, 2, 5, 4, 3 and 1, 2, 3, 4, 5 are acceptable outputs. In the second sample, 5, 4, 2, 3, 1 is the only permutation to satisfy the constraints.
[{"input": "5\n1 2 3 4 3\n1 2 5 4 5", "output": "1 2 5 4 3"}, {"input": "5\n4 4 2 3 1\n5 4 5 3 1", "output": "5 4 2 3 1"}, {"input": "4\n1 1 3 4\n1 4 3 4", "output": "1 2 3 4"}]
1,300
["constructive algorithms"]
54
[{"input": "5\r\n1 2 3 4 3\r\n1 2 5 4 5\r\n", "output": "1 2 5 4 3\r\n"}, {"input": "5\r\n4 4 2 3 1\r\n5 4 5 3 1\r\n", "output": "5 4 2 3 1\r\n"}, {"input": "4\r\n1 1 3 4\r\n1 4 3 4\r\n", "output": "1 2 3 4\r\n"}, {"input": "10\r\n1 2 3 4 7 6 7 8 9 10\r\n1 2 3 4 5 6 5 8 9 10\r\n", "output": "1 2 3 4 5 6 7 8 9 10\r\n"},...
false
stdio
import sys def is_permutation(p, n): if len(p) != n: return False seen = [False] * (n + 1) for num in p: if not (1 <= num <= n) or seen[num]: return False seen[num] = True return True def main(input_path, output_path, submission_path): with open(input_path) as f...
true
749/C
749
C
Python 3
TESTS
1
30
716,800
204525660
import queue n = int(input()) s = input() D = queue.Queue() R = queue.Queue() for i in range(n): if s[i] == 'D': D.put(i + 1) else: R.put(i + 1) while True: if D.empty(): print("R", end='') break elif R.empty(): print("D", end='') break if D.queue...
144
156
9,318,400
191699283
from collections import deque import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n = int(input()) s = list(input().rstrip()) q = deque([(i & 2) - 1 for i in s]) c = 0 z = [0] * 2 for i in s: z[(i & 2) // 2] += 1 while min(z): u = q.popleft() if c * u >= 0: q.append(u) ...
Codeforces Round 388 (Div. 2)
CF
2,016
1
256
Voting
There are n employees in Alternative Cake Manufacturing (ACM). They are now voting on some very important question and the leading world media are trying to predict the outcome of the vote. Each of the employees belongs to one of two fractions: depublicans or remocrats, and these two fractions have opposite opinions o...
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of employees. The next line contains n characters. The i-th character is 'D' if the i-th employee is from depublicans fraction or 'R' if he is from remocrats.
Print 'D' if the outcome of the vote will be suitable for depublicans and 'R' if remocrats will win.
null
Consider one of the voting scenarios for the first sample: 1. Employee 1 denies employee 5 to vote. 2. Employee 2 denies employee 3 to vote. 3. Employee 3 has no right to vote and skips his turn (he was denied by employee 2). 4. Employee 4 denies employee 2 to vote. 5. Employee 5 has no right to vote and skips his tur...
[{"input": "5\nDDRRR", "output": "D"}, {"input": "6\nDDRRRR", "output": "R"}]
1,500
["greedy", "implementation", "two pointers"]
144
[{"input": "5\r\nDDRRR\r\n", "output": "D\r\n"}, {"input": "6\r\nDDRRRR\r\n", "output": "R\r\n"}, {"input": "1\r\nD\r\n", "output": "D\r\n"}, {"input": "1\r\nR\r\n", "output": "R\r\n"}, {"input": "2\r\nDR\r\n", "output": "D\r\n"}, {"input": "3\r\nRDD\r\n", "output": "D\r\n"}, {"input": "3\r\nDRD\r\n", "output": "D\r\n"...
false
stdio
null
true
79/C
79
C
Python 3
TESTS
11
186
307,200
100986998
s = input() n = int(input()) b = [] for i in range(n): b.append(input()) s_original = s s_list = [s] for bi in b: new_s_list = [] for s in s_list: part_list = s.split(bi) if len(part_list) <= 1: new_s_list.append(s) continue for i, part in enumerate(part_list...
80
436
716,800
5639831
s, n = input(), int(input()) t = [input() for i in range(n)] def f(i): global t for j in range(n): if i < j: if len(t[j]) < len(t[i]) and t[j] in t[i]: return False elif j < i and t[j] in t[i]: return False return True t = [t[i] for i in range(n) if f(i)] n = len(s) r = [0] * n...
Codeforces Beta Round 71
CF
2,011
2
256
Beaver
After Fox Ciel got off a bus, she found that the bus she was on was a wrong bus and she lost her way in a strange town. However, she fortunately met her friend Beaver Taro and asked which way to go to her castle. Taro's response to her was a string s, and she tried to remember the string s correctly. However, Ciel fee...
In the first line there is a string s. The length of s will be between 1 and 105, inclusive. In the second line there is a single integer n (1 ≤ n ≤ 10). Next n lines, there is a string bi (1 ≤ i ≤ n). Each length of bi will be between 1 and 10, inclusive. Each character of the given strings will be either a English...
Output in the first line two space-separated integers len and pos: the length of the longest contiguous substring of s that does not contain any bi, and the first position of the substring (0-indexed). The position pos must be between 0 and |s| - len inclusive, where |s| is the length of string s. If there are several...
null
In the first sample, the solution is traight_alon. In the second sample, the solution is an empty string, so the output can be «0 0», «0 1», «0 2», and so on. In the third sample, the solution is either nagio or oisii.
[{"input": "Go_straight_along_this_street\n5\nstr\nlong\ntree\nbiginteger\nellipse", "output": "12 4"}, {"input": "IhaveNoIdea\n9\nI\nh\na\nv\ne\nN\no\nI\nd", "output": "0 0"}, {"input": "unagioisii\n2\nioi\nunagi", "output": "5 5"}]
1,800
["data structures", "dp", "greedy", "hashing", "strings", "two pointers"]
80
[{"input": "Go_straight_along_this_street\r\n5\r\nstr\r\nlong\r\ntree\r\nbiginteger\r\nellipse\r\n", "output": "12 4\r\n"}, {"input": "IhaveNoIdea\r\n9\r\nI\r\nh\r\na\r\nv\r\ne\r\nN\r\no\r\nI\r\nd\r\n", "output": "0 0\r\n"}, {"input": "unagioisii\r\n2\r\nioi\r\nunagi\r\n", "output": "5 5\r\n"}, {"input": "abcabcabcabc\...
false
stdio
import sys def main(): input_path, output_path, submission_path = sys.argv[1:] # Read input with open(input_path, 'r') as f: s = f.readline().strip() n = int(f.readline()) forbidden = [f.readline().strip() for _ in range(n)] # Read submission output try: wi...
true
350/E
350
E
Python 3
TESTS
3
592
102,400
4645127
#!/usr/bin/python3 def readln(): return tuple(map(int, input().split())) n, m, k = readln() if k == n or n * (n - 1) == 2 * m: print(-1) else: b = 1 for a in sorted(readln()): if a != b: break b += 1 if b == 1: s, f = 2, 3 elif b == 2: s, f = 1, 3 el...
62
186
8,806,400
143405248
n,m,k=map(int,input().split()) if k==n or m>(n-1)*(n-2)//2+n-k:print(-1) else: bn=[int(i)-1 for i in input().split()] mkd,edg=[False]*n,[] for i in bn:mkd[i]=True nbn=[i for i in range(n) if not mkd[i]] for i in nbn:edg.append((bn[0],i)) for i in range(1,len(bn)):edg.append((nbn[0],bn[i])) for i in range(n-1): ...
Codeforces Round 203 (Div. 2)
CF
2,013
1
256
Wrong Floyd
Valera conducts experiments with algorithms that search for shortest paths. He has recently studied the Floyd's algorithm, so it's time to work with it. Valera's already written the code that counts the shortest distance between any pair of vertexes in a non-directed connected graph from n vertexes and m edges, contai...
The first line of the input contains three integers n, m, k (3 ≤ n ≤ 300, 2 ≤ k ≤ n , $$n-1 \leq m \leq \frac{n(n-1)}{2}$$) — the number of vertexes, the number of edges and the number of marked vertexes. The second line of the input contains k space-separated integers a1, a2, ... ak (1 ≤ ai ≤ n) — the numbers of the ...
If the graph doesn't exist, print -1 on a single line. Otherwise, print m lines, each containing two integers u, v — the description of the edges of the graph Valera's been looking for.
null
null
[{"input": "3 2 2\n1 2", "output": "1 3\n2 3"}, {"input": "3 3 2\n1 2", "output": "-1"}]
2,200
["brute force", "constructive algorithms", "dfs and similar", "graphs"]
62
[{"input": "3 2 2\r\n1 2\r\n", "output": "1 3\r\n2 3\r\n"}, {"input": "3 3 2\r\n1 2\r\n", "output": "-1\r\n"}, {"input": "300 43056 2\r\n5 6\r\n", "output": "5 1\n 6 ...
false
stdio
import sys from collections import deque def valeras_algorithm(n, edges, marked_nodes): INF = float('inf') d = [[INF] * (n+1) for _ in range(n+1)] for i in range(1, n+1): d[i][i] = 0 for u, v in edges: d[u][v] = 1 d[v][u] = 1 marked = set(marked_nodes) for a in marked: ...
true
796/C
796
C
Python 3
TESTS
9
1,201
27,648,000
26532523
n = int(input()) a = [int(x) for x in input().split()] max_val = max(a) max_cnt = a.count(max_val) max_neigh = {} for i in range(n-1): u,v = [int(x) for x in input().split()] if a[u-1] == max_val: if u not in max_neigh: max_neigh[u] = set([u]) max_neigh[u].add(v) if a[v-1] =...
129
1,310
85,708,800
189018427
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def sparse_table(a): table = [] s0, l = a, 1 table.append(s0) while 2 * l <= len(a): s = [max(s0[i], s0[i + l]) for i in range(len(s0) - l)] table.append(list(s)) s0 = s l *= 2 return tab...
Codeforces Round 408 (Div. 2)
CF
2,017
2
256
Bank Hacking
Although Inzane successfully found his beloved bone, Zane, his owner, has yet to return. To search for Zane, he would need a lot of money, of which he sadly has none. To deal with the problem, he has decided to hack the banks. There are n banks, numbered from 1 to n. There are also n - 1 wires connecting the banks. Al...
The first line contains one integer n (1 ≤ n ≤ 3·105) — the total number of banks. The second line contains n integers a1, a2, ..., an ( - 109 ≤ ai ≤ 109) — the strengths of the banks. Each of the next n - 1 lines contains two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — meaning that there is a wire directly connec...
Print one integer — the minimum strength of the computer Inzane needs to accomplish the goal.
null
In the first sample, Inzane can hack all banks using a computer with strength 5. Here is how: - Initially, strengths of the banks are [1, 2, 3, 4, 5]. - He hacks bank 5, then strengths of the banks become [1, 2, 4, 5,  - ]. - He hacks bank 4, then strengths of the banks become [1, 3, 5,  - ,  - ]. - He hacks bank 3, t...
[{"input": "5\n1 2 3 4 5\n1 2\n2 3\n3 4\n4 5", "output": "5"}, {"input": "7\n38 -29 87 93 39 28 -55\n1 2\n2 5\n3 2\n2 4\n1 7\n7 6", "output": "93"}, {"input": "5\n1 2 7 6 7\n1 5\n5 3\n3 4\n2 4", "output": "8"}]
1,900
["constructive algorithms", "data structures", "dp", "trees"]
129
[{"input": "5\r\n1 2 3 4 5\r\n1 2\r\n2 3\r\n3 4\r\n4 5\r\n", "output": "5"}, {"input": "7\r\n38 -29 87 93 39 28 -55\r\n1 2\r\n2 5\r\n3 2\r\n2 4\r\n1 7\r\n7 6\r\n", "output": "93"}, {"input": "5\r\n1 2 7 6 7\r\n1 5\r\n5 3\r\n3 4\r\n2 4\r\n", "output": "8"}, {"input": "3\r\n2 2 2\r\n3 2\r\n1 2\r\n", "output": "3"}, {"inp...
false
stdio
null
true
413/C
413
C
PyPy 3
TESTS
6
140
0
68654823
n , m = map(int,input().split()) que =list(map(int,input().split())) #print(que) auc = list(map(int,input().split())) s = sum(que) for i in auc: s-=que[i-1] auc.sort(reverse=True) for i in auc: if que[i-1]<s: s*=2 else: s+=que[i-1] print(s)
67
61
0
136224257
n,m=list(map(int,input().split())) l=list(map(int,input().split())) ls=list(map(int,input().split())) s=set(ls) ans=0 t=[] for i in range(n): if i+1 not in s: ans+=l[i] else: t.append(l[i]) t.sort(reverse=True) for i in t: if ans<i: ans+=i else: ans+=ans print(ans)
Coder-Strike 2014 - Round 2
CF
2,014
1
256
Jeopardy!
'Jeopardy!' is an intellectual game where players answer questions and earn points. Company Q conducts a simplified 'Jeopardy!' tournament among the best IT companies. By a lucky coincidence, the old rivals made it to the finals: company R1 and company R2. The finals will have n questions, m of them are auction questi...
The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 100; m ≤ min(n, 30)) — the total number of questions and the number of auction questions, correspondingly. The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 107) — the prices of the questions. The third line contains m ...
In the single line, print the answer to the problem — the maximum points the R2 company can get if it plays optimally well. It is guaranteed that the answer fits into the integer 64-bit signed type.
null
null
[{"input": "4 1\n1 3 7 5\n3", "output": "18"}, {"input": "3 2\n10 3 8\n2 3", "output": "40"}, {"input": "2 2\n100 200\n1 2", "output": "400"}]
1,400
["greedy", "math"]
67
[{"input": "4 1\r\n1 3 7 5\r\n3\r\n", "output": "18\r\n"}, {"input": "3 2\r\n10 3 8\r\n2 3\r\n", "output": "40\r\n"}, {"input": "2 2\r\n100 200\r\n1 2\r\n", "output": "400\r\n"}, {"input": "1 1\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "2 2\r\n1 5\r\n1 2\r\n", "output": "10\r\n"}, {"input": "5 3\r\n5 8 7 1 9\r\n2 5...
false
stdio
null
true
847/E
847
E
Python 3
TESTS
17
62
716,800
162748719
from typing import List from collections import deque, Counter from bisect import * import heapq from functools import cmp_to_key, reduce def main(): n, s = int(input()), input() a, b = [], [] for i, it in enumerate(s): if it == "*": a.append(i) elif it == "P": b.ap...
77
140
7,372,800
121279819
''' pacman->food pacman->food->food :hmmge: larges smaller val smallest larger val ''' def check(mid,p,f): ptr=0 for x in p: From=x To=x while ptr<len(f): From=min(From,f[ptr]) To=max(To,f[ptr]) need=To-From+min(To-x,x-From) if need>mid: break ptr+=1 if ptr==len(f): return 1 return 0 de...
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,017
1
256
Packmen
A game field is a strip of 1 × n square cells. In some cells there are Packmen, in some cells — asterisks, other cells are empty. Packman can move to neighboring cell in 1 time unit. If there is an asterisk in the target cell then Packman eats it. Packman doesn't spend any time to eat an asterisk. In the initial mome...
The first line contains a single integer n (2 ≤ n ≤ 105) — the length of the game field. The second line contains the description of the game field consisting of n symbols. If there is symbol '.' in position i — the cell i is empty. If there is symbol '*' in position i — in the cell i contains an asterisk. If there is...
Print minimum possible time after which Packmen can eat all asterisks.
null
In the first example Packman in position 4 will move to the left and will eat asterisk in position 1. He will spend 3 time units on it. During the same 3 time units Packman in position 6 will eat both of neighboring with it asterisks. For example, it can move to the left and eat asterisk in position 5 (in 1 time unit) ...
[{"input": "7\n*..P*P*", "output": "3"}, {"input": "10\n.**PP.*P.*", "output": "2"}]
1,800
["binary search", "dp"]
77
[{"input": "7\r\n*..P*P*\r\n", "output": "3\r\n"}, {"input": "10\r\n.**PP.*P.*\r\n", "output": "2\r\n"}, {"input": "19\r\n**P.*..*..P..*.*P**\r\n", "output": "7\r\n"}, {"input": "12\r\nP**.*P*P*P**\r\n", "output": "3\r\n"}, {"input": "17\r\n.*P*P**P**.**P...\r\n", "output": "3\r\n"}, {"input": "58\r\n..P.P*.P*.P...PPP....
false
stdio
null
true
173/B
173
B
Python 3
TESTS
17
280
409,600
45175789
from collections import deque inf = 1000000000000 tmp = list(map(int, input().split(' ')[:2])) n = tmp[0] m = tmp[1] graph = [[]for _ in range(n)] for i in range(n): tmp = input() graph[i] = tmp used = [False]*(n + m) finalGraph = [[] for _ in range(n + m)] for i in range(n): for j in range(m): #pri...
105
466
16,179,200
162293632
import sys from array import array from collections import deque class graph: def __init__(self, n): self.n, self.gdict = n, [array('i') for _ in range(n + 1)] def add_edge(self, node1, node2): self.gdict[node1].append(node2) self.gdict[node2].append(node1) def bfs_util(self, roo...
Croc Champ 2012 - Round 1
CF
2,012
2
256
Chamber of Secrets
"The Chamber of Secrets has been opened again" — this news has spread all around Hogwarts and some of the students have been petrified due to seeing the basilisk. Dumbledore got fired and now Harry is trying to enter the Chamber of Secrets. These aren't good news for Lord Voldemort. The problem is, he doesn't want anyb...
The first line of the input contains two integer numbers n and m (2 ≤ n, m ≤ 1000). Each of the next n lines contains m characters. Each character is either "." or "#" and represents one cell of the Chamber grid. It's "." if the corresponding cell is empty and "#" if it's a regular column.
Print the minimum number of columns to make magic or -1 if it's impossible to do.
null
The figure above shows the first sample test. In the first sample we should make both columns magic. The dragon figure represents the basilisk and the binoculars represent the person who will enter the Chamber of secrets. The black star shows the place where the person will be petrified. Yellow lines represent basilisk...
[{"input": "3 3\n.#.\n...\n.#.", "output": "2"}, {"input": "4 3\n##.\n...\n.#.\n.#.", "output": "2"}]
1,800
["dfs and similar", "shortest paths"]
105
[{"input": "3 3\r\n.#.\r\n...\r\n.#.\r\n", "output": "2\r\n"}, {"input": "4 3\r\n##.\r\n...\r\n.#.\r\n.#.\r\n", "output": "2\r\n"}, {"input": "3 3\r\n###\r\n###\r\n###\r\n", "output": "2\r\n"}, {"input": "3 4\r\n..##\r\n....\r\n..#.\r\n", "output": "2\r\n"}, {"input": "4 3\r\n#.#\r\n...\r\n...\r\n.##\r\n", "output": "2...
false
stdio
null
true
356/C
356
C
Python 3
TESTS
7
546
14,848,000
92601008
import math n=int(input()) arr=list(map(int,input().strip().split(' '))) dic=[0 for i in range(5)] sum=0 for i in arr: sum+=i dic[i]+=1 if sum in [1,2,5]: print(-1) quit() res=0 res+=dic[1] dic[2]-=dic[1] if dic[2]>0: if dic[2]>dic[4]: res+=dic[4] else: res+=dic[2] dic[2]-=di...
141
607
14,745,600
42135284
#! /usr/bin/env python n = int(input()) counts = [0] * 5 nums = [int(x) for x in input().split()] for x in nums: counts[x] += 1 s = sum(nums) if s > 2 and s != 5: ans = 0 if counts[1] >= counts[2]: ans += counts[2] counts[3] += counts[2] counts[1] -= counts[2] ans += 2 * (c...
Codeforces Round 207 (Div. 1)
CF
2,013
1
256
Compartments
A team of students from the city S is sent to the All-Berland Olympiad in Informatics. Traditionally, they go on the train. All students have bought tickets in one carriage, consisting of n compartments (each compartment has exactly four people). We know that if one compartment contain one or two students, then they ge...
The first line contains integer n (1 ≤ n ≤ 106) — the number of compartments in the carriage. The second line contains n integers a1, a2, ..., an showing how many students ride in each compartment (0 ≤ ai ≤ 4). It is guaranteed that at least one student is riding in the train.
If no sequence of swapping seats with other people leads to the desired result, print number "-1" (without the quotes). In another case, print the smallest number of people you need to persuade to swap places.
null
null
[{"input": "5\n1 2 2 4 3", "output": "2"}, {"input": "3\n4 1 1", "output": "2"}, {"input": "4\n0 3 0 4", "output": "0"}]
2,100
["combinatorics", "constructive algorithms", "greedy", "implementation"]
141
[{"input": "5\r\n1 2 2 4 3\r\n", "output": "2\r\n"}, {"input": "3\r\n4 1 1\r\n", "output": "2\r\n"}, {"input": "4\r\n0 3 0 4\r\n", "output": "0\r\n"}, {"input": "5\r\n4 4 3 3 1\r\n", "output": "1\r\n"}, {"input": "5\r\n4 3 4 2 4\r\n", "output": "1\r\n"}, {"input": "10\r\n2 1 2 3 4 1 3 4 4 4\r\n", "output": "2\r\n"}, {"...
false
stdio
null
true
138/A
138
A
PyPy 3
TESTS
47
560
4,915,200
103179125
n,k=list(map(int,input().split())) l=[] for i in range(4*n): l.append(input()) poss=0 lst=[] for i in l: c=0 n=len(i) for j in range(n-1,-1,-1): if(i[j]=='a' or i[j]=='e' or i[j]=='i' or i[j]=='o' or i[j]=='u'): c+=1 else: continue if(c==k): lst.append(i[j...
80
466
9,523,200
209914478
vowels = set(["a", "e", "i", "o", "u"]) def kth_vowel_position(s, k): i = len(s) - 1 while i >= 0 and k > 0: if s[i] in vowels: k -= 1 if k == 0: break i -= 1 else: return -1 return len(s) - i n, k = map(int, input().split()) types = {"aaaa", "...
Codeforces Beta Round 99 (Div. 1)
CF
2,011
2
256
Literature Lesson
Vera adores poems. All the poems Vera knows are divided into quatrains (groups of four lines) and in each quatrain some lines contain rhymes. Let's consider that all lines in the poems consist of lowercase Latin letters (without spaces). Letters "a", "e", "i", "o", "u" are considered vowels. Two lines rhyme if their ...
The first line contains two integers n and k (1 ≤ n ≤ 2500, 1 ≤ k ≤ 5) — the number of quatrains in the poem and the vowel's number, correspondingly. Next 4n lines contain the poem. Each line is not empty and only consists of small Latin letters. The total length of the lines does not exceed 104. If we assume that the...
Print the rhyme scheme of the poem as "aabb", "abab", "abba", "aaaa"; or "NO" if the poem does not belong to any of the above mentioned schemes.
null
In the last sample both quatrains have rhymes but finding the common scheme is impossible, so the answer is "NO".
[{"input": "1 1\nday\nmay\nsun\nfun", "output": "aabb"}, {"input": "1 1\nday\nmay\ngray\nway", "output": "aaaa"}, {"input": "2 1\na\na\na\na\na\na\ne\ne", "output": "aabb"}, {"input": "2 1\nday\nmay\nsun\nfun\ntest\nhill\nfest\nthrill", "output": "NO"}]
1,600
["implementation"]
80
[{"input": "1 1\r\nday\r\nmay\r\nsun\r\nfun\r\n", "output": "aabb\r\n"}, {"input": "1 1\r\nday\r\nmay\r\ngray\r\nway\r\n", "output": "aaaa\r\n"}, {"input": "2 1\r\na\r\na\r\na\r\na\r\na\r\na\r\ne\r\ne\r\n", "output": "aabb\r\n"}, {"input": "2 1\r\nday\r\nmay\r\nsun\r\nfun\r\ntest\r\nhill\r\nfest\r\nthrill\r\n", "output...
false
stdio
null
true
1489/D
988
B
PyPy 3-64
TESTS
33
77
1,536,000
189911316
import sys input = lambda: sys.stdin.readline().rstrip() # ----------------------- # n = int(input()) S = [input() for _ in range(n)] ok = [[] for _ in range(n+1)] for i in range(n): tmp = 0 for j in range(n): if i == j: continue if S[i] in S[j]: tmp += 1 ok[tmp].append(S[i]) ok.reverse() ...
56
31
0
145145329
n=int(input()) l=[] for _ in range(n): s=input().rstrip() l.append(s) a=sorted(l,key=lambda x:(len(x))) f=0 for i in range(n-1): if a[i] not in a[i+1]: f=1 break if f==0: print("YES") for x in a: print(x) else:print("NO")
Kotlin Heroes: Practice 6
ICPC
2,021
1
256
Substrings Sort
You are given $$$n$$$ strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such a way that for every string, all strings that are placed before it are its substrings. String $$$a$$$ is a substring of string $$$b$$$ if it is possible to choose several consecutive letters ...
The first line contains an integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of strings. The next $$$n$$$ lines contain the given strings. The number of letters in each string is from $$$1$$$ to $$$100$$$, inclusive. Each string consists of lowercase English letters. Some strings might be equal.
If it is impossible to reorder $$$n$$$ given strings in required order, print "NO" (without quotes). Otherwise print "YES" (without quotes) and $$$n$$$ given strings in required order.
null
In the second example you cannot reorder the strings because the string "abab" is not a substring of the string "abacaba".
[{"input": "5\na\naba\nabacaba\nba\naba", "output": "YES\na\nba\naba\naba\nabacaba"}, {"input": "5\na\nabacaba\nba\naba\nabab", "output": "NO"}, {"input": "3\nqwerty\nqwerty\nqwerty", "output": "YES\nqwerty\nqwerty\nqwerty"}]
null
["*special", "sortings"]
56
[{"input": "5\r\na\r\naba\r\nabacaba\r\nba\r\naba\r\n", "output": "YES\r\na\r\nba\r\naba\r\naba\r\nabacaba\r\n"}, {"input": "5\r\na\r\nabacaba\r\nba\r\naba\r\nabab\r\n", "output": "NO\r\n"}, {"input": "3\r\nqwerty\r\nqwerty\r\nqwerty\r\n", "output": "YES\r\nqwerty\r\nqwerty\r\nqwerty\r\n"}, {"input": "1\r\nwronganswer\...
false
stdio
null
true
671/A
671
A
PyPy 3-64
TESTS
24
1,450
156,569,600
133293366
from sys import stdin from functools import lru_cache def main(): input = stdin.readline @lru_cache(None) def dist(x,y): return ((x[0]-y[0])**2+(x[1]-y[1])**2)**0.5 ax,ay,bx,by,tx,ty = [int(i) for i in input().split()] trash = (tx,ty); A=(ax,ay); B=(bx,by) n = int(input()) bottles ...
148
1,075
9,625,600
18006264
from math import hypot ax, ay, bx, by, tx, ty = map(int, input().split()) n = int(input()) ans = 0 p1, p2, beg, end = [0]*n, [0]*n, [0]*n, [0]*n def pref(x): return beg[x] if x >= 0 else 0 def suff(x): return end[x] if x < n else 0 def ex(x): return max(pref(x-1), suff(x+1)) for i in range(n): x...
Codeforces Round 352 (Div. 1)
CF
2,016
2
256
Recycling Bottles
It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin. We can think Central Perk as coordinate plane. There are n bottles on the ground, the i-th bottle is located at position (xi, yi). Both Adil and Bera can c...
First line of the input contains six integers ax, ay, bx, by, tx and ty (0 ≤ ax, ay, bx, by, tx, ty ≤ 109) — initial positions of Adil, Bera and recycling bin respectively. The second line contains a single integer n (1 ≤ n ≤ 100 000) — the number of bottles on the ground. Then follow n lines, each of them contains t...
Print one real number — the minimum possible total distance Adil and Bera need to walk in order to put all bottles into recycling bin. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checke...
null
Consider the first sample. Adil will use the following path: $$(3,1)\rightarrow(2,1)\rightarrow(0,0)\rightarrow(1,1)\rightarrow(0,0)$$. Bera will use the following path: $$(1,2)\rightarrow(2,3)\rightarrow(0,0)$$. Adil's path will be $$1 + \sqrt{5} + \sqrt{2} + \sqrt{2}$$ units long, while Bera's path will be $$\sqrt...
[{"input": "3 1 1 2 0 0\n3\n1 1\n2 1\n2 3", "output": "11.084259940083"}, {"input": "5 0 4 2 2 0\n5\n5 2\n3 0\n5 5\n3 5\n3 3", "output": "33.121375178000"}]
1,800
["dp", "geometry", "greedy", "implementation"]
148
[{"input": "3 1 1 2 0 0\r\n3\r\n1 1\r\n2 1\r\n2 3\r\n", "output": "11.084259940083\r\n"}, {"input": "5 0 4 2 2 0\r\n5\r\n5 2\r\n3 0\r\n5 5\r\n3 5\r\n3 3\r\n", "output": "33.121375178000\r\n"}, {"input": "107 50 116 37 104 118\r\n12\r\n16 78\r\n95 113\r\n112 84\r\n5 88\r\n54 85\r\n112 80\r\n19 98\r\n25 14\r\n48 76\r\n95...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(output_path) as f: correct = f.read().strip() with open(submission_path) as f: submission = f.read().strip() try: correct_val = float(correct) subm...
true
671/A
671
A
PyPy 3-64
TESTS
24
795
68,403,200
133293159
from sys import stdin input = stdin.readline ax,ay,bx,by,tx,ty = [int(i) for i in input().split()] n = int(input()) bottles = [[int(i) for i in input().split()] for _ in range(n)] tc = 0 for i,j in bottles: tc += 2 * ((tx - i)**2 + (ty - j)**2)**0.5 mincost = tc a = [] b = [] for i,[x,y] in enumerate(bottles): ...
148
1,216
27,648,000
18104468
read = lambda: map(int, input().split()) ax, ay, bx, by, tx, ty = read() n = int(input()) p = [tuple(read()) for i in range(n)] a, b = [], [] for i in range(n): x, y = p[i] pt = ((tx - x) ** 2 + (ty - y) ** 2) ** 0.5 pa = ((ax - x) ** 2 + (ay - y) ** 2) ** 0.5 pb = ((bx - x) ** 2 + (by - y) ** ...
Codeforces Round 352 (Div. 1)
CF
2,016
2
256
Recycling Bottles
It was recycling day in Kekoland. To celebrate it Adil and Bera went to Central Perk where they can take bottles from the ground and put them into a recycling bin. We can think Central Perk as coordinate plane. There are n bottles on the ground, the i-th bottle is located at position (xi, yi). Both Adil and Bera can c...
First line of the input contains six integers ax, ay, bx, by, tx and ty (0 ≤ ax, ay, bx, by, tx, ty ≤ 109) — initial positions of Adil, Bera and recycling bin respectively. The second line contains a single integer n (1 ≤ n ≤ 100 000) — the number of bottles on the ground. Then follow n lines, each of them contains t...
Print one real number — the minimum possible total distance Adil and Bera need to walk in order to put all bottles into recycling bin. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checke...
null
Consider the first sample. Adil will use the following path: $$(3,1)\rightarrow(2,1)\rightarrow(0,0)\rightarrow(1,1)\rightarrow(0,0)$$. Bera will use the following path: $$(1,2)\rightarrow(2,3)\rightarrow(0,0)$$. Adil's path will be $$1 + \sqrt{5} + \sqrt{2} + \sqrt{2}$$ units long, while Bera's path will be $$\sqrt...
[{"input": "3 1 1 2 0 0\n3\n1 1\n2 1\n2 3", "output": "11.084259940083"}, {"input": "5 0 4 2 2 0\n5\n5 2\n3 0\n5 5\n3 5\n3 3", "output": "33.121375178000"}]
1,800
["dp", "geometry", "greedy", "implementation"]
148
[{"input": "3 1 1 2 0 0\r\n3\r\n1 1\r\n2 1\r\n2 3\r\n", "output": "11.084259940083\r\n"}, {"input": "5 0 4 2 2 0\r\n5\r\n5 2\r\n3 0\r\n5 5\r\n3 5\r\n3 3\r\n", "output": "33.121375178000\r\n"}, {"input": "107 50 116 37 104 118\r\n12\r\n16 78\r\n95 113\r\n112 84\r\n5 88\r\n54 85\r\n112 80\r\n19 98\r\n25 14\r\n48 76\r\n95...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(output_path) as f: correct = f.read().strip() with open(submission_path) as f: submission = f.read().strip() try: correct_val = float(correct) subm...
true
989/B
989
B
Python 3
TESTS
20
78
102,400
39173546
n, p = [int(i) for i in input().split()] s = list(input()) ok = 0 for i in range(n - p): if s[i] != '.' and s[i + p] != '.' and s[i] != s[i + p]: ok = 1 break elif s[i] == '.' or s[i + p] == '.': if s[i] == '1': s[i + p] = '0' else: s[i] = '0' ok =...
59
61
0
164120302
n,p=map(int,input().split()) s=list(input()) i=next((i for i,(x,y)in enumerate(zip(s,s[p:]))if not x==y!='.'),-1) if i<0: print('No') else: if s[i]=='.':s[i]='01'[s[i+p]in'.0'] if s[i+p]=='.':s[i+p]='01'[s[i]=='0'] print(''.join(s).replace('.','0'))
Codeforces Round 487 (Div. 2)
CF
2,018
1
256
A Tide of Riverscape
The records are expressed as a string $$$s$$$ of characters '0', '1' and '.', where '0' denotes a low tide, '1' denotes a high tide, and '.' denotes an unknown one (either high or low). You are to help Mino determine whether it's possible that after replacing each '.' independently with '0' or '1', a given integer $$$...
The first line contains two space-separated integers $$$n$$$ and $$$p$$$ ($$$1 \leq p \leq n \leq 2000$$$) — the length of the given string and the supposed period, respectively. The second line contains a string $$$s$$$ of $$$n$$$ characters — Mino's records. $$$s$$$ only contains characters '0', '1' and '.', and con...
Output one line — if it's possible that $$$p$$$ is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)).
null
In the first example, $$$7$$$ is not a period of the resulting string because the $$$1$$$-st and $$$8$$$-th characters of it are different. In the second example, $$$6$$$ is not a period of the resulting string because the $$$4$$$-th and $$$10$$$-th characters of it are different. In the third example, $$$9$$$ is alw...
[{"input": "10 7\n1.0.1.0.1.", "output": "1000100010"}, {"input": "10 6\n1.0.1.1000", "output": "1001101000"}, {"input": "10 9\n1........1", "output": "No"}]
1,200
["constructive algorithms", "strings"]
59
[{"input": "10 7\r\n1.0.1.0.1.\r\n", "output": "1000100010\r\n"}, {"input": "10 6\r\n1.0.1.1000\r\n", "output": "1001101000\r\n"}, {"input": "10 9\r\n1........1\r\n", "output": "No\r\n"}, {"input": "1 1\r\n.\r\n", "output": "No\r\n"}, {"input": "5 1\r\n0...1\r\n", "output": "00001\r\n"}, {"input": "17 10\r\n..1.100..1....
false
stdio
import sys def main(): input_path = sys.argv[1] ref_path = sys.argv[2] sub_path = sys.argv[3] with open(input_path, 'r') as f: n, p = map(int, f.readline().split()) s = f.readline().strip() with open(ref_path, 'r') as f: ref_output = f.read().strip() with open(sub_pat...
true
732/B
732
B
Python 3
TESTS
11
46
0
203739260
n , k = map(int , input().split()) l = list(map(int , input().split())) l2 = l[: : ] pt1 , pt2 , add1,add2,resadd1,resadd2 = 0 , 1 , 0 ,0 , 0 , 0 while pt2 != n : if l[pt1] +l[pt2] < k : add1 = k - (l[pt1] +l[pt2]) if l[pt1] <= l[pt2] : l[pt2] += add1 else : l[p...
70
46
0
194052973
length, all_walks = [int(x) for x in input().split()] planned_walks = [int(x) for x in input().split()] additional_walks = [0] * length additional_walks[0] = planned_walks[0] for i in range(1, length): if additional_walks[i - 1] + planned_walks[i] >= all_walks: additional_walks[i] = planned_walks[i] e...
Codeforces Round 377 (Div. 2)
CF
2,016
1
256
Cormen — The Best Friend Of a Man
Recently a dog was bought for Polycarp. The dog's name is Cormen. Now Polycarp has a lot of troubles. For example, Cormen likes going for a walk. Empirically Polycarp learned that the dog needs at least k walks for any two consecutive days in order to feel good. For example, if k = 5 and yesterday Polycarp went for a ...
The first line contains two integers n and k (1 ≤ n, k ≤ 500) — the number of days and the minimum number of walks with Cormen for any two consecutive days. The second line contains integers a1, a2, ..., an (0 ≤ ai ≤ 500) — the number of walks with Cormen on the i-th day which Polycarp has already planned.
In the first line print the smallest number of additional walks that Polycarp should do during the next n days so that Cormen will feel good during all days. In the second line print n integers b1, b2, ..., bn, where bi — the total number of walks on the i-th day according to the found solutions (ai ≤ bi for all i fro...
null
null
[{"input": "3 5\n2 0 1", "output": "4\n2 3 2"}, {"input": "3 1\n0 0 0", "output": "1\n0 1 0"}, {"input": "4 6\n2 4 3 5", "output": "0\n2 4 3 5"}]
1,000
["dp", "greedy"]
70
[{"input": "3 5\r\n2 0 1\r\n", "output": "4\r\n2 3 2\r\n"}, {"input": "3 1\r\n0 0 0\r\n", "output": "1\r\n0 1 0\r\n"}, {"input": "4 6\r\n2 4 3 5\r\n", "output": "0\r\n2 4 3 5\r\n"}, {"input": "5 1\r\n0 0 0 0 1\r\n", "output": "2\r\n0 1 0 1 1\r\n"}, {"input": "10 500\r\n164 44 238 205 373 249 87 30 239 90\r\n", "output"...
false
stdio
null
true
725/A
725
A
PyPy 3-64
TESTS
8
46
409,600
206621969
a=int(input()) b=input() if b.count('><')>1: print(0) elif b.count('><')==0: print(a) else: ans=0 l=0 f=0 for i in range(a-1): if b[i]=='>': l+=1 else: if f: ans+=1 l=0 if b[i]=='>' and b[i+1]=='<': ans+=l ...
78
46
204,800
156019679
n = int(input()) s = input() print(n-len(s.lstrip('<').rstrip('>')))
Canada Cup 2016
CF
2,016
2
256
Jumping Ball
In a new version of the famous Pinball game, one of the most important parts of the game field is a sequence of n bumpers. The bumpers are numbered with integers from 1 to n from left to right. There are two types of bumpers. They are denoted by the characters '<' and '>'. When the ball hits the bumper at position i it...
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the length of the sequence of bumpers. The second line contains the string, which consists of the characters '<' and '>'. The character at the i-th position of this string corresponds to the type of the i-th bumper.
Print one integer — the number of positions in the sequence such that the ball will eventually fall from the game field if it starts at that position.
null
In the first sample, the ball will fall from the field if starts at position 1 or position 2. In the second sample, any starting position will result in the ball falling from the field.
[{"input": "4\n<<><", "output": "2"}, {"input": "5\n>>>>>", "output": "5"}, {"input": "4\n>><<", "output": "0"}]
1,000
["implementation"]
78
[{"input": "4\r\n<<><\r\n", "output": "2\r\n"}, {"input": "5\r\n>>>>>\r\n", "output": "5\r\n"}, {"input": "4\r\n>><<\r\n", "output": "0\r\n"}, {"input": "3\r\n<<>\r\n", "output": "3\r\n"}, {"input": "3\r\n<<<\r\n", "output": "3\r\n"}, {"input": "3\r\n><<\r\n", "output": "0\r\n"}, {"input": "1\r\n<\r\n", "output": "1\r\...
false
stdio
null
true
989/B
989
B
PyPy 3
TESTS
30
108
1,740,800
108473893
n, p = map(int, input().split()) s = str(input()) t = [0]*n for i in range(n): if s[i] != '.': t[i] = s[i] else: if i-p >= 0: t[i] = str(1-int(t[i-p])) else: if i+p <= n-1: if s[i+p] != '.': t[i] = str(1-int(t[i+p])) ...
59
62
307,200
106992127
# Problem: B. A Tide of Riverscape # Contest: Codeforces - Codeforces Round #487 (Div. 2) # URL: https://codeforces.com/problemset/problem/989/B # Memory Limit: 256 MB # Time Limit: 1000 ms # User: anky # # Powered by CP Editor (https://cpeditor.org) n, k = map(int, input().split()) ss = input() s = [] for i in ss: ...
Codeforces Round 487 (Div. 2)
CF
2,018
1
256
A Tide of Riverscape
The records are expressed as a string $$$s$$$ of characters '0', '1' and '.', where '0' denotes a low tide, '1' denotes a high tide, and '.' denotes an unknown one (either high or low). You are to help Mino determine whether it's possible that after replacing each '.' independently with '0' or '1', a given integer $$$...
The first line contains two space-separated integers $$$n$$$ and $$$p$$$ ($$$1 \leq p \leq n \leq 2000$$$) — the length of the given string and the supposed period, respectively. The second line contains a string $$$s$$$ of $$$n$$$ characters — Mino's records. $$$s$$$ only contains characters '0', '1' and '.', and con...
Output one line — if it's possible that $$$p$$$ is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)).
null
In the first example, $$$7$$$ is not a period of the resulting string because the $$$1$$$-st and $$$8$$$-th characters of it are different. In the second example, $$$6$$$ is not a period of the resulting string because the $$$4$$$-th and $$$10$$$-th characters of it are different. In the third example, $$$9$$$ is alw...
[{"input": "10 7\n1.0.1.0.1.", "output": "1000100010"}, {"input": "10 6\n1.0.1.1000", "output": "1001101000"}, {"input": "10 9\n1........1", "output": "No"}]
1,200
["constructive algorithms", "strings"]
59
[{"input": "10 7\r\n1.0.1.0.1.\r\n", "output": "1000100010\r\n"}, {"input": "10 6\r\n1.0.1.1000\r\n", "output": "1001101000\r\n"}, {"input": "10 9\r\n1........1\r\n", "output": "No\r\n"}, {"input": "1 1\r\n.\r\n", "output": "No\r\n"}, {"input": "5 1\r\n0...1\r\n", "output": "00001\r\n"}, {"input": "17 10\r\n..1.100..1....
false
stdio
import sys def main(): input_path = sys.argv[1] ref_path = sys.argv[2] sub_path = sys.argv[3] with open(input_path, 'r') as f: n, p = map(int, f.readline().split()) s = f.readline().strip() with open(ref_path, 'r') as f: ref_output = f.read().strip() with open(sub_pat...
true
138/A
138
A
Python 3
TESTS
1
124
0
112728613
# https://codeforces.com/problemset/problem/138/A import sys VOWELS = {"a", "e", "i", "o", "u"} def parse_quatrain(lines, k: int) -> str: q = dict() out = { "aaaa": False, "aabb": False, "abab": False, "abba": False, } for i, l in enumerate(lines): rhyme = e...
80
498
4,198,400
81670879
def find(s,k): ek=0 sw="" vow=set() vow.add('a') vow.add('e') vow.add('i') vow.add('o') vow.add('u') for i in range(len(s)-1,-1,-1): if s[i] in vow: ek+=1 sw+=s[i] if ek==k: return sw return "-1" n,k=map(int,input().split()) l=[] to...
Codeforces Beta Round 99 (Div. 1)
CF
2,011
2
256
Literature Lesson
Vera adores poems. All the poems Vera knows are divided into quatrains (groups of four lines) and in each quatrain some lines contain rhymes. Let's consider that all lines in the poems consist of lowercase Latin letters (without spaces). Letters "a", "e", "i", "o", "u" are considered vowels. Two lines rhyme if their ...
The first line contains two integers n and k (1 ≤ n ≤ 2500, 1 ≤ k ≤ 5) — the number of quatrains in the poem and the vowel's number, correspondingly. Next 4n lines contain the poem. Each line is not empty and only consists of small Latin letters. The total length of the lines does not exceed 104. If we assume that the...
Print the rhyme scheme of the poem as "aabb", "abab", "abba", "aaaa"; or "NO" if the poem does not belong to any of the above mentioned schemes.
null
In the last sample both quatrains have rhymes but finding the common scheme is impossible, so the answer is "NO".
[{"input": "1 1\nday\nmay\nsun\nfun", "output": "aabb"}, {"input": "1 1\nday\nmay\ngray\nway", "output": "aaaa"}, {"input": "2 1\na\na\na\na\na\na\ne\ne", "output": "aabb"}, {"input": "2 1\nday\nmay\nsun\nfun\ntest\nhill\nfest\nthrill", "output": "NO"}]
1,600
["implementation"]
80
[{"input": "1 1\r\nday\r\nmay\r\nsun\r\nfun\r\n", "output": "aabb\r\n"}, {"input": "1 1\r\nday\r\nmay\r\ngray\r\nway\r\n", "output": "aaaa\r\n"}, {"input": "2 1\r\na\r\na\r\na\r\na\r\na\r\na\r\ne\r\ne\r\n", "output": "aabb\r\n"}, {"input": "2 1\r\nday\r\nmay\r\nsun\r\nfun\r\ntest\r\nhill\r\nfest\r\nthrill\r\n", "output...
false
stdio
null
true
815/A
815
A
PyPy 3
TESTS
13
186
25,395,200
87058974
import sys input=sys.stdin.readline n,m=list(map(int,input().split())) a=[] g=[] e=[] for i in range(n): g.append(list(map(int,input().split()))) e.extend(["row "+str(i+1)]*min(g[i])) a.append([min(g[i])]*m) for i in range(m): b=[] t=[] for j in range(n): b.append(g[j][i]) t.app...
177
171
9,420,800
144079686
# cook your dish here n,m=map(int,input().split()) g=[] d=[] dd=[] for i in range(n): g.append(list(map(int,input().split()))) d.append([0]*m) dd.append([0]*m) ans1,ans2,v,u=[],[],[],[] for i in range(n): mm=10**(9) for j in range(m): mm=min(mm,g[i][j]) for j in range(m): d[i][j]...
Codeforces Round 419 (Div. 1)
CF
2,017
2
512
Karen and Game
On the way to school, Karen became fixated on the puzzle game on her phone! The game is played as follows. In each level, you have a grid with n rows and m columns. Each cell originally contains the number 0. One move consists of choosing one row or column, and adding 1 to all of the cells in that row or column. To ...
The first line of input contains two integers, n and m (1 ≤ n, m ≤ 100), the number of rows and the number of columns in the grid, respectively. The next n lines each contain m integers. In particular, the j-th integer in the i-th of these rows contains gi, j (0 ≤ gi, j ≤ 500).
If there is an error and it is actually not possible to beat the level, output a single integer -1. Otherwise, on the first line, output a single integer k, the minimum number of moves necessary to beat the level. The next k lines should each contain one of the following, describing the moves in the order they must b...
null
In the first test case, Karen has a grid with 3 rows and 5 columns. She can perform the following 4 moves to beat the level: In the second test case, Karen has a grid with 3 rows and 3 columns. It is clear that it is impossible to beat the level; performing any move will create three 1s on the grid, but it is required...
[{"input": "3 5\n2 2 2 3 2\n0 0 0 1 0\n1 1 1 2 1", "output": "4\nrow 1\nrow 1\ncol 4\nrow 3"}, {"input": "3 3\n0 0 0\n0 1 0\n0 0 0", "output": "-1"}, {"input": "3 3\n1 1 1\n1 1 1\n1 1 1", "output": "3\nrow 1\nrow 2\nrow 3"}]
1,700
["brute force", "greedy", "implementation"]
177
[{"input": "3 5\r\n2 2 2 3 2\r\n0 0 0 1 0\r\n1 1 1 2 1\r\n", "output": "4\r\nrow 1\r\nrow 1\r\ncol 4\r\nrow 3\r\n"}, {"input": "3 3\r\n0 0 0\r\n0 1 0\r\n0 0 0\r\n", "output": "-1\r\n"}, {"input": "3 3\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n", "output": "3\r\nrow 1\r\nrow 2\r\nrow 3\r\n"}, {"input": "3 5\r\n2 4 2 2 3\r\n0 2 0 0 ...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path, 'r') as f: n, m = map(int, f.readline().split()) grid = [list(map(int, f.readline().split())) for _ in range(n)] possible = True g1_1 = grid[0][0] if n...
true
815/A
815
A
Python 3
TESTS
13
186
5,324,800
27926936
"""Проверка обнуления матрицы""" def t_row(): t=0 for i in range(nm[0]): for j in range(nm[1]): if a[i][j]>=rez_row[i]: a[i][j]=a[i][j]-rez_row[i] if a[i][j]== 0: t+=1 return(t) def t_col(): t=0 for j in range(nm[1]): for i in ...
177
186
14,540,800
218402129
import sys input = lambda: sys.stdin.readline().rstrip() import math from heapq import heappush , heappop from collections import defaultdict,deque,Counter from bisect import * N,M = map(int, input().split()) AA = [] for _ in range(N): AA.append(list(map(int, input().split()))) #print(A) def deal1(A,N,M): B =...
Codeforces Round 419 (Div. 1)
CF
2,017
2
512
Karen and Game
On the way to school, Karen became fixated on the puzzle game on her phone! The game is played as follows. In each level, you have a grid with n rows and m columns. Each cell originally contains the number 0. One move consists of choosing one row or column, and adding 1 to all of the cells in that row or column. To ...
The first line of input contains two integers, n and m (1 ≤ n, m ≤ 100), the number of rows and the number of columns in the grid, respectively. The next n lines each contain m integers. In particular, the j-th integer in the i-th of these rows contains gi, j (0 ≤ gi, j ≤ 500).
If there is an error and it is actually not possible to beat the level, output a single integer -1. Otherwise, on the first line, output a single integer k, the minimum number of moves necessary to beat the level. The next k lines should each contain one of the following, describing the moves in the order they must b...
null
In the first test case, Karen has a grid with 3 rows and 5 columns. She can perform the following 4 moves to beat the level: In the second test case, Karen has a grid with 3 rows and 3 columns. It is clear that it is impossible to beat the level; performing any move will create three 1s on the grid, but it is required...
[{"input": "3 5\n2 2 2 3 2\n0 0 0 1 0\n1 1 1 2 1", "output": "4\nrow 1\nrow 1\ncol 4\nrow 3"}, {"input": "3 3\n0 0 0\n0 1 0\n0 0 0", "output": "-1"}, {"input": "3 3\n1 1 1\n1 1 1\n1 1 1", "output": "3\nrow 1\nrow 2\nrow 3"}]
1,700
["brute force", "greedy", "implementation"]
177
[{"input": "3 5\r\n2 2 2 3 2\r\n0 0 0 1 0\r\n1 1 1 2 1\r\n", "output": "4\r\nrow 1\r\nrow 1\r\ncol 4\r\nrow 3\r\n"}, {"input": "3 3\r\n0 0 0\r\n0 1 0\r\n0 0 0\r\n", "output": "-1\r\n"}, {"input": "3 3\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n", "output": "3\r\nrow 1\r\nrow 2\r\nrow 3\r\n"}, {"input": "3 5\r\n2 4 2 2 3\r\n0 2 0 0 ...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path, 'r') as f: n, m = map(int, f.readline().split()) grid = [list(map(int, f.readline().split())) for _ in range(n)] possible = True g1_1 = grid[0][0] if n...
true
815/A
815
A
PyPy 3-64
TESTS
13
93
35,430,400
157557842
import os, sys from io import BytesIO, IOBase from collections import defaultdict, deque, Counter from bisect import bisect_left, bisect_right from heapq import heappush, heappop from functools import lru_cache from itertools import accumulate import math # Fast IO Region BUFSIZE = 8192 class FastIO(IOBase): ne...
177
186
27,648,000
131115050
n,m = map(int,input().split()) arr = [] for _ in range(n): arr.append(list(map(int,input().split()))) row = [505]*n col = [505]*m s = 0 for i in range(n): for j in range(m): row[i] = min(row[i],arr[i][j]) col[j] = min(col[j],arr[i][j]) s+= arr[i][j] ans = [] if n<=m: for i in range(n...
Codeforces Round 419 (Div. 1)
CF
2,017
2
512
Karen and Game
On the way to school, Karen became fixated on the puzzle game on her phone! The game is played as follows. In each level, you have a grid with n rows and m columns. Each cell originally contains the number 0. One move consists of choosing one row or column, and adding 1 to all of the cells in that row or column. To ...
The first line of input contains two integers, n and m (1 ≤ n, m ≤ 100), the number of rows and the number of columns in the grid, respectively. The next n lines each contain m integers. In particular, the j-th integer in the i-th of these rows contains gi, j (0 ≤ gi, j ≤ 500).
If there is an error and it is actually not possible to beat the level, output a single integer -1. Otherwise, on the first line, output a single integer k, the minimum number of moves necessary to beat the level. The next k lines should each contain one of the following, describing the moves in the order they must b...
null
In the first test case, Karen has a grid with 3 rows and 5 columns. She can perform the following 4 moves to beat the level: In the second test case, Karen has a grid with 3 rows and 3 columns. It is clear that it is impossible to beat the level; performing any move will create three 1s on the grid, but it is required...
[{"input": "3 5\n2 2 2 3 2\n0 0 0 1 0\n1 1 1 2 1", "output": "4\nrow 1\nrow 1\ncol 4\nrow 3"}, {"input": "3 3\n0 0 0\n0 1 0\n0 0 0", "output": "-1"}, {"input": "3 3\n1 1 1\n1 1 1\n1 1 1", "output": "3\nrow 1\nrow 2\nrow 3"}]
1,700
["brute force", "greedy", "implementation"]
177
[{"input": "3 5\r\n2 2 2 3 2\r\n0 0 0 1 0\r\n1 1 1 2 1\r\n", "output": "4\r\nrow 1\r\nrow 1\r\ncol 4\r\nrow 3\r\n"}, {"input": "3 3\r\n0 0 0\r\n0 1 0\r\n0 0 0\r\n", "output": "-1\r\n"}, {"input": "3 3\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n", "output": "3\r\nrow 1\r\nrow 2\r\nrow 3\r\n"}, {"input": "3 5\r\n2 4 2 2 3\r\n0 2 0 0 ...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path, 'r') as f: n, m = map(int, f.readline().split()) grid = [list(map(int, f.readline().split())) for _ in range(n)] possible = True g1_1 = grid[0][0] if n...
true
709/B
709
B
PyPy 3-64
TESTS
8
62
0
202900357
import sys input = lambda: sys.stdin.readline().rstrip() from bisect import * N,a = map(int, input().split()) A = list(map(int, input().split())) A.sort() if N==1: exit(print(0)) if a<=A[0]: exit(print(A[-2]-a)) elif a>=A[-1]: exit(print(a-A[1])) idx = bisect_left(A, a) ans = min(a-A[0]+A[-2]-A[0], A[-1...
81
93
13,107,200
220580066
a = input().split(" ") num_of_checkpoints = int(a[0]) start = int(a[1]) checkpoints = [int(e) for e in input().split()] checkpoints.sort() if num_of_checkpoints == 1: print(0) elif start <= checkpoints[0]: d = checkpoints[num_of_checkpoints - 2] - start print(d) elif start >= checkpoints[num_of_checkpoin...
AIM Tech Round 3 (Div. 2)
CF
2,016
1
256
Checkpoints
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x1, x2, ..., xn. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary order...
The first line of the input contains two integers n and a (1 ≤ n ≤ 100 000, - 1 000 000 ≤ a ≤ 1 000 000) — the number of checkpoints and Vasya's starting position respectively. The second line contains n integers x1, x2, ..., xn ( - 1 000 000 ≤ xi ≤ 1 000 000) — coordinates of the checkpoints.
Print one integer — the minimum distance Vasya has to travel in order to visit at least n - 1 checkpoint.
null
In the first sample Vasya has to visit at least two checkpoints. The optimal way to achieve this is the walk to the third checkpoints (distance is 12 - 10 = 2) and then proceed to the second one (distance is 12 - 7 = 5). The total distance is equal to 2 + 5 = 7. In the second sample it's enough to visit only one check...
[{"input": "3 10\n1 7 12", "output": "7"}, {"input": "2 0\n11 -10", "output": "10"}, {"input": "5 0\n0 0 1000 0 0", "output": "0"}]
1,500
["greedy", "implementation", "sortings"]
81
[{"input": "3 10\r\n1 7 12\r\n", "output": "7\r\n"}, {"input": "2 0\r\n11 -10\r\n", "output": "10\r\n"}, {"input": "5 0\r\n0 0 1000 0 0\r\n", "output": "0\r\n"}, {"input": "1 0\r\n0\r\n", "output": "0\r\n"}, {"input": "2 1\r\n4 -8\r\n", "output": "3\r\n"}, {"input": "3 4\r\n4 2 4\r\n", "output": "0\r\n"}, {"input": "4 ...
false
stdio
null
true
989/B
989
B
Python 3
TESTS
25
46
0
148164423
n,p=map(int,input().split()) s = list(input()) flag = 0 for i in range(n-p): if flag!=1: if s[i]=='.': if s[i+p]=='.': s[i]='1' s[i+p]='0' flag=1 elif s[i+p]=='0': s[i]='1' flag=1 elif s[i+p]...
59
77
0
39169145
def read_nums(): return [int(x) for x in input().split()] def main(): n, p = read_nums() s = list(input()) for i in range(n - p): one, two = s[i], s[i + p] if (one, two) == ('.', '.'): s[i] = '1' s[i + p] = '0' print(''.join(s).replace('.', '0')) ...
Codeforces Round 487 (Div. 2)
CF
2,018
1
256
A Tide of Riverscape
The records are expressed as a string $$$s$$$ of characters '0', '1' and '.', where '0' denotes a low tide, '1' denotes a high tide, and '.' denotes an unknown one (either high or low). You are to help Mino determine whether it's possible that after replacing each '.' independently with '0' or '1', a given integer $$$...
The first line contains two space-separated integers $$$n$$$ and $$$p$$$ ($$$1 \leq p \leq n \leq 2000$$$) — the length of the given string and the supposed period, respectively. The second line contains a string $$$s$$$ of $$$n$$$ characters — Mino's records. $$$s$$$ only contains characters '0', '1' and '.', and con...
Output one line — if it's possible that $$$p$$$ is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)).
null
In the first example, $$$7$$$ is not a period of the resulting string because the $$$1$$$-st and $$$8$$$-th characters of it are different. In the second example, $$$6$$$ is not a period of the resulting string because the $$$4$$$-th and $$$10$$$-th characters of it are different. In the third example, $$$9$$$ is alw...
[{"input": "10 7\n1.0.1.0.1.", "output": "1000100010"}, {"input": "10 6\n1.0.1.1000", "output": "1001101000"}, {"input": "10 9\n1........1", "output": "No"}]
1,200
["constructive algorithms", "strings"]
59
[{"input": "10 7\r\n1.0.1.0.1.\r\n", "output": "1000100010\r\n"}, {"input": "10 6\r\n1.0.1.1000\r\n", "output": "1001101000\r\n"}, {"input": "10 9\r\n1........1\r\n", "output": "No\r\n"}, {"input": "1 1\r\n.\r\n", "output": "No\r\n"}, {"input": "5 1\r\n0...1\r\n", "output": "00001\r\n"}, {"input": "17 10\r\n..1.100..1....
false
stdio
import sys def main(): input_path = sys.argv[1] ref_path = sys.argv[2] sub_path = sys.argv[3] with open(input_path, 'r') as f: n, p = map(int, f.readline().split()) s = f.readline().strip() with open(ref_path, 'r') as f: ref_output = f.read().strip() with open(sub_pat...
true
709/B
709
B
PyPy 3-64
TESTS
2
62
0
224058062
import sys input = sys.stdin.buffer.readline def process(X, a): n = len(X) X.sort() if n==1: answer = 0 elif n==2: x1, x2 = X answer = min(abs(x1-a), abs(x2-a)) else: answer = float('inf') x1, x2 = X[0], X[-2] if a < x1: answer = min(a...
81
93
13,516,800
176846972
import sys input = sys.stdin.readline n, a = map(int, input().split()) w = sorted(map(int, input().split())) if n == 1: print(0) exit() if a <= w[0]: print(w[-2]-a) elif a >= w[-1]: print(a - w[1]) else: print(min(abs(w[-2]-a) + w[-2]-w[0], abs(w[-1]-a) + w[-1]-w[1], abs(a-w[1]) + w[-1]-w[1], abs(a...
AIM Tech Round 3 (Div. 2)
CF
2,016
1
256
Checkpoints
Vasya takes part in the orienteering competition. There are n checkpoints located along the line at coordinates x1, x2, ..., xn. Vasya starts at the point with coordinate a. His goal is to visit at least n - 1 checkpoint in order to finish the competition. Participant are allowed to visit checkpoints in arbitrary order...
The first line of the input contains two integers n and a (1 ≤ n ≤ 100 000, - 1 000 000 ≤ a ≤ 1 000 000) — the number of checkpoints and Vasya's starting position respectively. The second line contains n integers x1, x2, ..., xn ( - 1 000 000 ≤ xi ≤ 1 000 000) — coordinates of the checkpoints.
Print one integer — the minimum distance Vasya has to travel in order to visit at least n - 1 checkpoint.
null
In the first sample Vasya has to visit at least two checkpoints. The optimal way to achieve this is the walk to the third checkpoints (distance is 12 - 10 = 2) and then proceed to the second one (distance is 12 - 7 = 5). The total distance is equal to 2 + 5 = 7. In the second sample it's enough to visit only one check...
[{"input": "3 10\n1 7 12", "output": "7"}, {"input": "2 0\n11 -10", "output": "10"}, {"input": "5 0\n0 0 1000 0 0", "output": "0"}]
1,500
["greedy", "implementation", "sortings"]
81
[{"input": "3 10\r\n1 7 12\r\n", "output": "7\r\n"}, {"input": "2 0\r\n11 -10\r\n", "output": "10\r\n"}, {"input": "5 0\r\n0 0 1000 0 0\r\n", "output": "0\r\n"}, {"input": "1 0\r\n0\r\n", "output": "0\r\n"}, {"input": "2 1\r\n4 -8\r\n", "output": "3\r\n"}, {"input": "3 4\r\n4 2 4\r\n", "output": "0\r\n"}, {"input": "4 ...
false
stdio
null
true
989/B
989
B
PyPy 3
TESTS
30
155
1,331,200
78772827
#from sys import stdin #input=stdin.readline #from collections import deque,counter #s="abcdefghijklmnopqrstuvwxyz" #s,q=set(),deque() #vow=['a','e','i','o','u'] #t=[[0 for i in range(n)]for j in range(n)] '''def gcd(x,y): while y: x,y=y%x,x return y''' #n=int(input()) #n,k=map(int, input().split()) #a...
59
77
2,355,200
155220368
def process(S, p): n = len(S) d = [[[], [], []] for i in range(p)] answer = [S[i] for i in range(n)] for i in range(n): i1 = i % p if S[i]=='0': j = 0 elif S[i]=='1': j = 1 else: j = 2 d[i1][j].append(i) works = False fo...
Codeforces Round 487 (Div. 2)
CF
2,018
1
256
A Tide of Riverscape
The records are expressed as a string $$$s$$$ of characters '0', '1' and '.', where '0' denotes a low tide, '1' denotes a high tide, and '.' denotes an unknown one (either high or low). You are to help Mino determine whether it's possible that after replacing each '.' independently with '0' or '1', a given integer $$$...
The first line contains two space-separated integers $$$n$$$ and $$$p$$$ ($$$1 \leq p \leq n \leq 2000$$$) — the length of the given string and the supposed period, respectively. The second line contains a string $$$s$$$ of $$$n$$$ characters — Mino's records. $$$s$$$ only contains characters '0', '1' and '.', and con...
Output one line — if it's possible that $$$p$$$ is not a period of the resulting string, output any one of such strings; otherwise output "No" (without quotes, you can print letters in any case (upper or lower)).
null
In the first example, $$$7$$$ is not a period of the resulting string because the $$$1$$$-st and $$$8$$$-th characters of it are different. In the second example, $$$6$$$ is not a period of the resulting string because the $$$4$$$-th and $$$10$$$-th characters of it are different. In the third example, $$$9$$$ is alw...
[{"input": "10 7\n1.0.1.0.1.", "output": "1000100010"}, {"input": "10 6\n1.0.1.1000", "output": "1001101000"}, {"input": "10 9\n1........1", "output": "No"}]
1,200
["constructive algorithms", "strings"]
59
[{"input": "10 7\r\n1.0.1.0.1.\r\n", "output": "1000100010\r\n"}, {"input": "10 6\r\n1.0.1.1000\r\n", "output": "1001101000\r\n"}, {"input": "10 9\r\n1........1\r\n", "output": "No\r\n"}, {"input": "1 1\r\n.\r\n", "output": "No\r\n"}, {"input": "5 1\r\n0...1\r\n", "output": "00001\r\n"}, {"input": "17 10\r\n..1.100..1....
false
stdio
import sys def main(): input_path = sys.argv[1] ref_path = sys.argv[2] sub_path = sys.argv[3] with open(input_path, 'r') as f: n, p = map(int, f.readline().split()) s = f.readline().strip() with open(ref_path, 'r') as f: ref_output = f.read().strip() with open(sub_pat...
true
173/B
173
B
PyPy 3-64
TESTS
17
124
2,048,000
230608251
from collections import deque n, m = tuple(int(x) for x in input().split()) rows = [[] for i in range(n)] columns = [[] for i in range(m)] visited = set() for i in range(n): temp = input() for j in range(m): if temp[j] == "#": rows[i].append(j) columns[j].append(i) stack = [(0,Tr...
105
498
37,785,600
231047697
from collections import deque def main(): input_line = input().split() n = int(input_line[0]) m = int(input_line[1]) graph = [[] for _ in range(n+m)] for i in range(n): line = input() for j in range(m): if line[j] == '#': graph[i].append(n+j) ...
Croc Champ 2012 - Round 1
CF
2,012
2
256
Chamber of Secrets
"The Chamber of Secrets has been opened again" — this news has spread all around Hogwarts and some of the students have been petrified due to seeing the basilisk. Dumbledore got fired and now Harry is trying to enter the Chamber of Secrets. These aren't good news for Lord Voldemort. The problem is, he doesn't want anyb...
The first line of the input contains two integer numbers n and m (2 ≤ n, m ≤ 1000). Each of the next n lines contains m characters. Each character is either "." or "#" and represents one cell of the Chamber grid. It's "." if the corresponding cell is empty and "#" if it's a regular column.
Print the minimum number of columns to make magic or -1 if it's impossible to do.
null
The figure above shows the first sample test. In the first sample we should make both columns magic. The dragon figure represents the basilisk and the binoculars represent the person who will enter the Chamber of secrets. The black star shows the place where the person will be petrified. Yellow lines represent basilisk...
[{"input": "3 3\n.#.\n...\n.#.", "output": "2"}, {"input": "4 3\n##.\n...\n.#.\n.#.", "output": "2"}]
1,800
["dfs and similar", "shortest paths"]
105
[{"input": "3 3\r\n.#.\r\n...\r\n.#.\r\n", "output": "2\r\n"}, {"input": "4 3\r\n##.\r\n...\r\n.#.\r\n.#.\r\n", "output": "2\r\n"}, {"input": "3 3\r\n###\r\n###\r\n###\r\n", "output": "2\r\n"}, {"input": "3 4\r\n..##\r\n....\r\n..#.\r\n", "output": "2\r\n"}, {"input": "4 3\r\n#.#\r\n...\r\n...\r\n.##\r\n", "output": "2...
false
stdio
null
true
815/A
815
A
Python 3
TESTS
13
124
1,126,400
48907992
n,m=map(int,input().split()) L=[list(map(int,input().split())) for i in range(n)] w=[0 for i in range(n)] w1=[0 for i in range(m)] for i in range(n) : w[i]=min(L[i]) for i in range(m) : for j in range(n) : ma=0 ma=max(L[j][i]-w[j],ma) w1[i]=ma for i in range(n) : for j in range(m) : ...
177
202
9,830,400
103378188
n, m = [int(i) for i in input().split(' ')] g = [] c, f = 0, 0 ans = '' def row(): global n, m, g, c, ans for i in range(n): t = min(g[i]) c += t ans += ('row %d\n' % (i+1))*t for j in range(m): g[i][j] -= t def col(): global n, m, g, c, ans for i in range...
Codeforces Round 419 (Div. 1)
CF
2,017
2
512
Karen and Game
On the way to school, Karen became fixated on the puzzle game on her phone! The game is played as follows. In each level, you have a grid with n rows and m columns. Each cell originally contains the number 0. One move consists of choosing one row or column, and adding 1 to all of the cells in that row or column. To ...
The first line of input contains two integers, n and m (1 ≤ n, m ≤ 100), the number of rows and the number of columns in the grid, respectively. The next n lines each contain m integers. In particular, the j-th integer in the i-th of these rows contains gi, j (0 ≤ gi, j ≤ 500).
If there is an error and it is actually not possible to beat the level, output a single integer -1. Otherwise, on the first line, output a single integer k, the minimum number of moves necessary to beat the level. The next k lines should each contain one of the following, describing the moves in the order they must b...
null
In the first test case, Karen has a grid with 3 rows and 5 columns. She can perform the following 4 moves to beat the level: In the second test case, Karen has a grid with 3 rows and 3 columns. It is clear that it is impossible to beat the level; performing any move will create three 1s on the grid, but it is required...
[{"input": "3 5\n2 2 2 3 2\n0 0 0 1 0\n1 1 1 2 1", "output": "4\nrow 1\nrow 1\ncol 4\nrow 3"}, {"input": "3 3\n0 0 0\n0 1 0\n0 0 0", "output": "-1"}, {"input": "3 3\n1 1 1\n1 1 1\n1 1 1", "output": "3\nrow 1\nrow 2\nrow 3"}]
1,700
["brute force", "greedy", "implementation"]
177
[{"input": "3 5\r\n2 2 2 3 2\r\n0 0 0 1 0\r\n1 1 1 2 1\r\n", "output": "4\r\nrow 1\r\nrow 1\r\ncol 4\r\nrow 3\r\n"}, {"input": "3 3\r\n0 0 0\r\n0 1 0\r\n0 0 0\r\n", "output": "-1\r\n"}, {"input": "3 3\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n", "output": "3\r\nrow 1\r\nrow 2\r\nrow 3\r\n"}, {"input": "3 5\r\n2 4 2 2 3\r\n0 2 0 0 ...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path, 'r') as f: n, m = map(int, f.readline().split()) grid = [list(map(int, f.readline().split())) for _ in range(n)] possible = True g1_1 = grid[0][0] if n...
true
815/A
815
A
Python 3
TESTS
13
811
6,041,600
27968582
n, m = 0, 0 steps_nr = 0 def get_input(): global n, m matrix = [] nm_arr = [int(x) for x in input().split()] n, m = nm_arr[0], nm_arr[1] for i in range(n): row = [int(x) for x in input().split()] matrix.append(row) return matrix def dec_col(matrix, j): for i in range(n): matrix[i][j] = matrix[i][j] - 1 ...
177
218
16,588,800
171266599
from collections import defaultdict as dc n,m=[int(x) for x in input().split()] arr=list() check=dc(lambda:False) check2=dc(lambda:False) ans,ans2=list(),list() for _ in range(n): tmp=list(map(int,input().split())) arr.append(tmp) pair,pair2=list(),list() for i in range(n): tmp=list() for j in range(m):...
Codeforces Round 419 (Div. 1)
CF
2,017
2
512
Karen and Game
On the way to school, Karen became fixated on the puzzle game on her phone! The game is played as follows. In each level, you have a grid with n rows and m columns. Each cell originally contains the number 0. One move consists of choosing one row or column, and adding 1 to all of the cells in that row or column. To ...
The first line of input contains two integers, n and m (1 ≤ n, m ≤ 100), the number of rows and the number of columns in the grid, respectively. The next n lines each contain m integers. In particular, the j-th integer in the i-th of these rows contains gi, j (0 ≤ gi, j ≤ 500).
If there is an error and it is actually not possible to beat the level, output a single integer -1. Otherwise, on the first line, output a single integer k, the minimum number of moves necessary to beat the level. The next k lines should each contain one of the following, describing the moves in the order they must b...
null
In the first test case, Karen has a grid with 3 rows and 5 columns. She can perform the following 4 moves to beat the level: In the second test case, Karen has a grid with 3 rows and 3 columns. It is clear that it is impossible to beat the level; performing any move will create three 1s on the grid, but it is required...
[{"input": "3 5\n2 2 2 3 2\n0 0 0 1 0\n1 1 1 2 1", "output": "4\nrow 1\nrow 1\ncol 4\nrow 3"}, {"input": "3 3\n0 0 0\n0 1 0\n0 0 0", "output": "-1"}, {"input": "3 3\n1 1 1\n1 1 1\n1 1 1", "output": "3\nrow 1\nrow 2\nrow 3"}]
1,700
["brute force", "greedy", "implementation"]
177
[{"input": "3 5\r\n2 2 2 3 2\r\n0 0 0 1 0\r\n1 1 1 2 1\r\n", "output": "4\r\nrow 1\r\nrow 1\r\ncol 4\r\nrow 3\r\n"}, {"input": "3 3\r\n0 0 0\r\n0 1 0\r\n0 0 0\r\n", "output": "-1\r\n"}, {"input": "3 3\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n", "output": "3\r\nrow 1\r\nrow 2\r\nrow 3\r\n"}, {"input": "3 5\r\n2 4 2 2 3\r\n0 2 0 0 ...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path, 'r') as f: n, m = map(int, f.readline().split()) grid = [list(map(int, f.readline().split())) for _ in range(n)] possible = True g1_1 = grid[0][0] if n...
true
584/C
584
C
PyPy 3-64
TESTS
12
873
11,366,400
185177097
from heapq import heapify, heappop, heappush, nlargest from collections import Counter, defaultdict from sys import stdin, stdout from math import ceil, floor, sqrt from functools import reduce,lru_cache # n,m = map(int,stdin.readline().split()) # stdout.write(str(arr[x-y]-arr[x])+'\n') # reps = int(stdin.readline()) ...
78
77
7,065,600
194565172
def solve(): n, t = map(int, input().split()) s1 = input() s2 = input() s3 = ['']*n d = 0 for i in range(n): if s1[i] == s2[i]: s3[i] = s1[i] else: d += 1 for c in 'abc': if c != s1[i] and c != s2[i]: s3[i] =...
Codeforces Round 324 (Div. 2)
CF
2,015
1
256
Marina and Vasya
Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly t characters. Help Vasya find at least one such string. More formally, you are given two strings s1, s2 of length n and number t. Let's denote as f(a, b) the number of characters in which strings a and ...
The first line contains two integers n and t (1 ≤ n ≤ 105, 0 ≤ t ≤ n). The second line contains string s1 of length n, consisting of lowercase English letters. The third line contain string s2 of length n, consisting of lowercase English letters.
Print a string of length n, differing from string s1 and from s2 in exactly t characters. Your string should consist only from lowercase English letters. If such string doesn't exist, print -1.
null
null
[{"input": "3 2\nabc\nxyc", "output": "ayd"}, {"input": "1 0\nc\nb", "output": "-1"}]
1,700
["constructive algorithms", "greedy", "strings"]
78
[{"input": "3 2\r\nabc\r\nxyc\r\n", "output": "bac"}, {"input": "1 0\r\nc\r\nb\r\n", "output": "-1\r\n"}, {"input": "1 1\r\na\r\na\r\n", "output": "b"}, {"input": "2 1\r\naa\r\naa\r\n", "output": "ab"}, {"input": "3 1\r\nbcb\r\nbca\r\n", "output": "bcc"}, {"input": "4 3\r\nccbb\r\ncaab\r\n", "output": "cbca"}, {"input"...
false
stdio
import sys def hamming(s1, s2): return sum(c1 != c2 for c1, c2 in zip(s1, s2)) def solution_exists(n, t, s1, s2): a = sum(c1 == c2 for c1, c2 in zip(s1, s2)) d = n - a min_k = max(d - t, 0) max_k = min(d // 2, a + d - t) return min_k <= max_k def main(): input_path = sys.argv[1] outpu...
true
416/D
416
D
Python 3
TESTS
13
62
5,529,600
31666178
num_elements = int(input()) total_seq = input().split(" ") for i in range(num_elements): total_seq[i] = int(total_seq[i]) for i in range(num_elements): if total_seq[i] != -1: total_seq = total_seq[i:] break seqs = [] delta = 0.5 start = 0 prev = -1 distance = 0 total = 0 for i in range(len(total_seq)): distanc...
84
373
16,384,000
6954252
n = int(input()) a = list(map(int, input().split())) i = 0 ans = 0 while i < n: ans += 1 i1 = i while i1 < n and a[i1] == -1: i1 += 1 if i1 == n: break i2 = i1 + 1 while i2 < n and a[i2] == -1: i2 += 1 if i2 == n: break dist = i2 - i1 step = (a[i2] - a...
Codeforces Round 241 (Div. 2)
CF
2,014
1
256
Population Size
Polycarpus develops an interesting theory about the interrelation of arithmetic progressions with just everything in the world. His current idea is that the population of the capital of Berland changes over time like an arithmetic progression. Well, or like multiple arithmetic progressions. Polycarpus believes that if...
The first line of the input contains integer n (1 ≤ n ≤ 2·105) — the number of elements in the sequence. The second line contains integer values a1, a2, ..., an separated by a space (1 ≤ ai ≤ 109 or ai = - 1).
Print the minimum number of arithmetic progressions that you need to write one after another to get sequence a. The positions marked as -1 in a can be represented by any positive integers.
null
null
[{"input": "9\n8 6 4 2 1 4 7 10 2", "output": "3"}, {"input": "9\n-1 6 -1 2 -1 4 7 -1 2", "output": "3"}, {"input": "5\n-1 -1 -1 -1 -1", "output": "1"}, {"input": "7\n-1 -1 4 5 1 2 3", "output": "2"}]
2,400
["greedy", "implementation", "math"]
84
[{"input": "9\r\n8 6 4 2 1 4 7 10 2\r\n", "output": "3\r\n"}, {"input": "9\r\n-1 6 -1 2 -1 4 7 -1 2\r\n", "output": "3\r\n"}, {"input": "5\r\n-1 -1 -1 -1 -1\r\n", "output": "1\r\n"}, {"input": "7\r\n-1 -1 4 5 1 2 3\r\n", "output": "2\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n65\r\n", "output": ...
false
stdio
null
true
815/A
815
A
PyPy 3-64
TESTS
13
139
10,035,200
216494705
import sys input = lambda: sys.stdin.readline().rstrip() from collections import deque,defaultdict,Counter from itertools import permutations,combinations from bisect import * from heapq import * from math import ceil,gcd,lcm,floor,comb alph = 'abcdefghijklmnopqrstuvwxyz' #pow(x,mod-2,mod) N,M = map(int,input().split(...
177
249
4,300,800
27861114
n,m = map(int,input().split()) grid = [] for _ in range(n): grid.append(list(map(int,input().split()))) count = 0 moves = [] grid2 = [] for row in grid: grid2.append(row[:]) def do_row(grid,row): global count r = row row = grid[row] m = min(row) count += m for _ in range(m): m...
Codeforces Round 419 (Div. 1)
CF
2,017
2
512
Karen and Game
On the way to school, Karen became fixated on the puzzle game on her phone! The game is played as follows. In each level, you have a grid with n rows and m columns. Each cell originally contains the number 0. One move consists of choosing one row or column, and adding 1 to all of the cells in that row or column. To ...
The first line of input contains two integers, n and m (1 ≤ n, m ≤ 100), the number of rows and the number of columns in the grid, respectively. The next n lines each contain m integers. In particular, the j-th integer in the i-th of these rows contains gi, j (0 ≤ gi, j ≤ 500).
If there is an error and it is actually not possible to beat the level, output a single integer -1. Otherwise, on the first line, output a single integer k, the minimum number of moves necessary to beat the level. The next k lines should each contain one of the following, describing the moves in the order they must b...
null
In the first test case, Karen has a grid with 3 rows and 5 columns. She can perform the following 4 moves to beat the level: In the second test case, Karen has a grid with 3 rows and 3 columns. It is clear that it is impossible to beat the level; performing any move will create three 1s on the grid, but it is required...
[{"input": "3 5\n2 2 2 3 2\n0 0 0 1 0\n1 1 1 2 1", "output": "4\nrow 1\nrow 1\ncol 4\nrow 3"}, {"input": "3 3\n0 0 0\n0 1 0\n0 0 0", "output": "-1"}, {"input": "3 3\n1 1 1\n1 1 1\n1 1 1", "output": "3\nrow 1\nrow 2\nrow 3"}]
1,700
["brute force", "greedy", "implementation"]
177
[{"input": "3 5\r\n2 2 2 3 2\r\n0 0 0 1 0\r\n1 1 1 2 1\r\n", "output": "4\r\nrow 1\r\nrow 1\r\ncol 4\r\nrow 3\r\n"}, {"input": "3 3\r\n0 0 0\r\n0 1 0\r\n0 0 0\r\n", "output": "-1\r\n"}, {"input": "3 3\r\n1 1 1\r\n1 1 1\r\n1 1 1\r\n", "output": "3\r\nrow 1\r\nrow 2\r\nrow 3\r\n"}, {"input": "3 5\r\n2 4 2 2 3\r\n0 2 0 0 ...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path, 'r') as f: n, m = map(int, f.readline().split()) grid = [list(map(int, f.readline().split())) for _ in range(n)] possible = True g1_1 = grid[0][0] if n...
true
837/C
837
C
Python 3
TESTS
12
62
4,915,200
29167804
n, a, b = map(int, input().split()) s = [0] * n for i in range(n): s[i] = tuple(map(int, input().split())) ans = 0 for i in range(n): if s[i][0] > a and s[i][1] > b or\ s[i][0] > a and s[i][1] > a: continue cur = [s[i][0], s[i][1]] for orientation in range(2): cur[0], c...
51
61
0
182757967
def cal(x1,y1,x2,y2,a,b): return x1+x2<=a and max(y1,y2)<=b n , a , b = map( int , input().split() ) xy = [] for i in range(n): x , y = map( int , input().split() ) xy.append((x,y)) ans = 0 for i in range(n): for j in range(i+1,n): for p1 in range(2): for p2 in range(2): if cal(xy[i][p1],xy[i][1-p1],xy[j][...
Educational Codeforces Round 26
ICPC
2,017
1
256
Two Seals
One very important person has a piece of paper in the form of a rectangle a × b. Also, he has n seals. Each seal leaves an impression on the paper in the form of a rectangle of the size xi × yi. Each impression must be parallel to the sides of the piece of paper (but seal can be rotated by 90 degrees). A very importa...
The first line contains three integer numbers n, a and b (1 ≤ n, a, b ≤ 100). Each of the next n lines contain two numbers xi, yi (1 ≤ xi, yi ≤ 100).
Print the largest total area that can be occupied by two seals. If you can not select two seals, print 0.
null
In the first example you can rotate the second seal by 90 degrees. Then put impression of it right under the impression of the first seal. This will occupy all the piece of paper. In the second example you can't choose the last seal because it doesn't fit. By choosing the first and the third seals you occupy the large...
[{"input": "2 2 2\n1 2\n2 1", "output": "4"}, {"input": "4 10 9\n2 3\n1 1\n5 10\n9 11", "output": "56"}, {"input": "3 10 10\n6 6\n7 7\n20 5", "output": "0"}]
1,500
["brute force", "implementation"]
51
[{"input": "2 2 2\r\n1 2\r\n2 1\r\n", "output": "4\r\n"}, {"input": "4 10 9\r\n2 3\r\n1 1\r\n5 10\r\n9 11\r\n", "output": "56\r\n"}, {"input": "3 10 10\r\n6 6\r\n7 7\r\n20 5\r\n", "output": "0\r\n"}, {"input": "2 1 1\r\n1 1\r\n1 1\r\n", "output": "0\r\n"}, {"input": "2 1 2\r\n1 1\r\n1 1\r\n", "output": "2\r\n"}, {"inpu...
false
stdio
null
true
1010/C
1010
C
PyPy 3
TESTS
62
342
38,707,200
128931200
def process(A, k): s = set([]) for x in A: x = x % k if x not in s: s.add(x) s2 = set([]) while len(s) > 0: for x in s: break for i in range(1, k+1): x2 = (i*x) % k if x2 not in s2: s2.add(x2) for x i...
107
233
10,444,800
40803271
import sys import os def gcd(a, b): if a > b: return gcd(b, a) if a == 0: return b return gcd(b % a, a) def build(n, d): print(n // d) r = [] for i in range(n // d): r.append(i * d) print(' '.join(map(str, r))) def solve(k, a): d = k for note in a: ...
Codeforces Round 499 (Div. 1)
CF
2,018
1
256
Border
Astronaut Natasha arrived on Mars. She knows that the Martians are very poor aliens. To ensure a better life for the Mars citizens, their emperor decided to take tax from every tourist who visited the planet. Natasha is the inhabitant of Earth, therefore she had to pay the tax to enter the territory of Mars. There are...
The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 100\,000$$$, $$$2 \le k \le 100\,000$$$) — the number of denominations of banknotes and the base of the number system on Mars. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — denominations of ban...
On the first line output the number of values $$$d$$$ for which Natasha can make the Martians happy. In the second line, output all these values in increasing order. Print all numbers in decimal notation.
null
Consider the first test case. It uses the octal number system. If you take one banknote with the value of $$$12$$$, you will get $$$14_8$$$ in octal system. The last digit is $$$4_8$$$. If you take one banknote with the value of $$$12$$$ and one banknote with the value of $$$20$$$, the total value will be $$$32$$$. I...
[{"input": "2 8\n12 20", "output": "2\n0 4"}, {"input": "3 10\n10 20 30", "output": "1\n0"}]
1,800
["number theory"]
107
[{"input": "2 8\r\n12 20\r\n", "output": "2\r\n0 4 "}, {"input": "3 10\r\n10 20 30\r\n", "output": "1\r\n0 "}, {"input": "5 10\r\n20 16 4 16 2\r\n", "output": "5\r\n0 2 4 6 8 "}, {"input": "10 5\r\n4 6 8 6 4 10 2 10 8 6\r\n", "output": "5\r\n0 1 2 3 4 "}, {"input": "20 25\r\n15 10 5 20 10 5 15 5 15 10 15 5 5 5 5 10 15 ...
false
stdio
null
true
584/C
584
C
PyPy 3-64
TESTS
39
61
5,734,400
194523416
n,t = map(int, input().split()) s1 = input() s2 = input() sl = [''] * n flag = True cnt = 0 for i in range(n): if s1[i] != s2[i]: cnt += 1 ld = i if t*2 < cnt: print(-1) else: tt = (2*t-cnt) // 2 for i in range(n): if s1[i] == s2[i]: if tt > 0: tt -= ...
78
92
12,083,200
194545026
n, t = map(int, input().split()) s1 = input() s2 = input() same, diff = [], [] for i, (c1, c2) in enumerate(zip(s1, s2)): if c1 == c2: same.append(i) else: diff.append(i) p, s = n-t, len(same) res = ['']*n if p>s and (p-s)*2>len(diff): print(-1) exit() if p<=s: for i in same[:p]: res[i] = s1...
Codeforces Round 324 (Div. 2)
CF
2,015
1
256
Marina and Vasya
Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly t characters. Help Vasya find at least one such string. More formally, you are given two strings s1, s2 of length n and number t. Let's denote as f(a, b) the number of characters in which strings a and ...
The first line contains two integers n and t (1 ≤ n ≤ 105, 0 ≤ t ≤ n). The second line contains string s1 of length n, consisting of lowercase English letters. The third line contain string s2 of length n, consisting of lowercase English letters.
Print a string of length n, differing from string s1 and from s2 in exactly t characters. Your string should consist only from lowercase English letters. If such string doesn't exist, print -1.
null
null
[{"input": "3 2\nabc\nxyc", "output": "ayd"}, {"input": "1 0\nc\nb", "output": "-1"}]
1,700
["constructive algorithms", "greedy", "strings"]
78
[{"input": "3 2\r\nabc\r\nxyc\r\n", "output": "bac"}, {"input": "1 0\r\nc\r\nb\r\n", "output": "-1\r\n"}, {"input": "1 1\r\na\r\na\r\n", "output": "b"}, {"input": "2 1\r\naa\r\naa\r\n", "output": "ab"}, {"input": "3 1\r\nbcb\r\nbca\r\n", "output": "bcc"}, {"input": "4 3\r\nccbb\r\ncaab\r\n", "output": "cbca"}, {"input"...
false
stdio
import sys def hamming(s1, s2): return sum(c1 != c2 for c1, c2 in zip(s1, s2)) def solution_exists(n, t, s1, s2): a = sum(c1 == c2 for c1, c2 in zip(s1, s2)) d = n - a min_k = max(d - t, 0) max_k = min(d // 2, a + d - t) return min_k <= max_k def main(): input_path = sys.argv[1] outpu...
true
426/B
426
B
Python 3
TESTS
14
77
0
6506383
n, m = map(int, input().split()) if n & 1: print(m) else: k, t = n // 2, [int(input()[:: 2], 2) for i in range(n)] while True: if t[: k] != t[k: 2 * k][:: -1]: print(2 * k) break elif k & 1: print(k) break k //= 2
65
46
102,400
170108856
import collections import heapq import sys import math import itertools import bisect import os def values(): return tuple(map(int, sys.stdin.readline().split())) def inp(): return int(sys.stdin.readline()) def inpstr(): return sys.stdin.readline().strip() def words(): return sys.stdin.readline(...
Codeforces Round 243 (Div. 2)
CF
2,014
1
256
Sereja and Mirroring
Let's assume that we are given a matrix b of size x × y, let's determine the operation of mirroring matrix b. The mirroring of matrix b is a 2x × y matrix c which has the following properties: - the upper half of matrix c (rows with numbers from 1 to x) exactly matches b; - the lower half of matrix c (rows with number...
The first line contains two integers, n and m (1 ≤ n, m ≤ 100). Each of the next n lines contains m integers — the elements of matrix a. The i-th line contains integers ai1, ai2, ..., aim (0 ≤ aij ≤ 1) — the i-th row of the matrix a.
In the single line, print the answer to the problem — the minimum number of rows of matrix b.
null
In the first test sample the answer is a 2 × 3 matrix b: If we perform a mirroring operation with this matrix, we get the matrix a that is given in the input:
[{"input": "4 3\n0 0 1\n1 1 0\n1 1 0\n0 0 1", "output": "2"}, {"input": "3 3\n0 0 0\n0 0 0\n0 0 0", "output": "3"}, {"input": "8 1\n0\n1\n1\n0\n0\n1\n1\n0", "output": "2"}]
1,300
["implementation"]
65
[{"input": "4 3\r\n0 0 1\r\n1 1 0\r\n1 1 0\r\n0 0 1\r\n", "output": "2\r\n"}, {"input": "3 3\r\n0 0 0\r\n0 0 0\r\n0 0 0\r\n", "output": "3\r\n"}, {"input": "8 1\r\n0\r\n1\r\n1\r\n0\r\n0\r\n1\r\n1\r\n0\r\n", "output": "2\r\n"}, {"input": "10 4\r\n0 0 1 0\r\n0 0 1 0\r\n1 1 0 1\r\n0 0 1 1\r\n1 0 1 0\r\n1 0 1 0\r\n0 0 1 1\...
false
stdio
null
true
416/D
416
D
Python 3
TESTS
13
62
0
6363695
n = int(input()) a = list(map(int, input().split())) j = -1 k = -1 ans = 1 for i in range(len(a)): if a[i] == -1: continue if j == -1: j = i elif k == -1 or (a[k] - a[j]) * (i - k) == (a[i] - a[k]) * (k - j): k = i else: j, k = i, -1 ans += 1 print(ans)
84
171
27,648,000
302828817
import sys,math,heapq from collections import Counter #sys.setrecursionlimit(200000) #fin = open('input.txt', 'r') #input = lambda: fin.readline().strip() input=lambda: sys.stdin.readline().strip() import random RANDOM = random.getrandbits(20) class Wrapper(int): def __init__(self, x): int.__init__(x) ...
Codeforces Round 241 (Div. 2)
CF
2,014
1
256
Population Size
Polycarpus develops an interesting theory about the interrelation of arithmetic progressions with just everything in the world. His current idea is that the population of the capital of Berland changes over time like an arithmetic progression. Well, or like multiple arithmetic progressions. Polycarpus believes that if...
The first line of the input contains integer n (1 ≤ n ≤ 2·105) — the number of elements in the sequence. The second line contains integer values a1, a2, ..., an separated by a space (1 ≤ ai ≤ 109 or ai = - 1).
Print the minimum number of arithmetic progressions that you need to write one after another to get sequence a. The positions marked as -1 in a can be represented by any positive integers.
null
null
[{"input": "9\n8 6 4 2 1 4 7 10 2", "output": "3"}, {"input": "9\n-1 6 -1 2 -1 4 7 -1 2", "output": "3"}, {"input": "5\n-1 -1 -1 -1 -1", "output": "1"}, {"input": "7\n-1 -1 4 5 1 2 3", "output": "2"}]
2,400
["greedy", "implementation", "math"]
84
[{"input": "9\r\n8 6 4 2 1 4 7 10 2\r\n", "output": "3\r\n"}, {"input": "9\r\n-1 6 -1 2 -1 4 7 -1 2\r\n", "output": "3\r\n"}, {"input": "5\r\n-1 -1 -1 -1 -1\r\n", "output": "1\r\n"}, {"input": "7\r\n-1 -1 4 5 1 2 3\r\n", "output": "2\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "1\r\n65\r\n", "output": ...
false
stdio
null
true
799/D
799
D
PyPy 3-64
TESTS
5
62
1,843,200
203459483
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def binary_search(c1, c2): m = (c1 + c2 + 1) // 2 while abs(c1 - c2) > 1: m = (c1 + c2 + 1) // 2 if ok(m): c2 = m else: c1 = m m = max(m - 1, 0) while not ok(m): m += ...
103
62
2,560,000
230893177
f = lambda: map(int, input().split()) a, b, h, w, n = f() c = sorted(list(f()), key=lambda x: -x) d = {(h, w), (w, h)} for i, q in enumerate([1] + c): for u, v in d.copy(): h, w = u, v * q if a <= w and b <= h or a <= h and b <= w: print(i) exit() d.add((h, w)) ...
Playrix Codescapes Cup (Codeforces Round 413, rated, Div. 1 + Div. 2)
CF
2,017
1
256
Field expansion
In one of the games Arkady is fond of the game process happens on a rectangular field. In the game process Arkady can buy extensions for his field, each extension enlarges one of the field sizes in a particular number of times. Formally, there are n extensions, the i-th of them multiplies the width or the length (by Ar...
The first line contains five integers a, b, h, w and n (1 ≤ a, b, h, w, n ≤ 100 000) — the sizes of the rectangle needed to be placed, the initial sizes of the field and the number of available extensions. The second line contains n integers a1, a2, ..., an (2 ≤ ai ≤ 100 000), where ai equals the integer a side multip...
Print the minimum number of extensions needed to reach Arkady's goal. If it is not possible to place the rectangle on the field with all extensions, print -1. If the rectangle can be placed on the initial field, print 0.
null
In the first example it is enough to use any of the extensions available. For example, we can enlarge h in 5 times using the second extension. Then h becomes equal 10 and it is now possible to place the rectangle on the field.
[{"input": "3 3 2 4 4\n2 5 4 10", "output": "1"}, {"input": "3 3 3 3 5\n2 3 5 4 2", "output": "0"}, {"input": "5 5 1 2 3\n2 2 3", "output": "-1"}, {"input": "3 4 1 1 3\n2 3 2", "output": "3"}]
2,100
["brute force", "dp", "meet-in-the-middle"]
103
[{"input": "3 3 2 4 4\r\n2 5 4 10\r\n", "output": "1\r\n"}, {"input": "3 3 3 3 5\r\n2 3 5 4 2\r\n", "output": "0\r\n"}, {"input": "5 5 1 2 3\r\n2 2 3\r\n", "output": "-1\r\n"}, {"input": "3 4 1 1 3\r\n2 3 2\r\n", "output": "3\r\n"}, {"input": "572 540 6 2 12\r\n2 3 2 2 2 3 3 3 2 2 2 2\r\n", "output": "-1\r\n"}, {"input...
false
stdio
null
true
799/D
799
D
PyPy 3-64
TESTS
5
46
512,000
136790607
def process(A, a, b, h, w): if a > b: a, b = b, a if h > w: h, w = w, h A.sort() answer = 0 while len(A) > 0 and (h < a or w < b): a1 = A.pop() if a/h > b/w: h*=a1 else: w*=a1 if h > w: h, w = w, h answer+=1 ...
103
826
2,150,400
27034917
import sys MAXV = 100010 d = [0] * MAXV a, b, h, w, n = map(int,input().split()) arr = input().split() for it in range(n): arr[it] = int(arr[it]) # print(arr) # print(a, b, h, w, n) def solve(a, b, h, w, z, product, it): # print(">", a, b, h, w, z, product, it) k = 0 if a % h: k = a // h...
Playrix Codescapes Cup (Codeforces Round 413, rated, Div. 1 + Div. 2)
CF
2,017
1
256
Field expansion
In one of the games Arkady is fond of the game process happens on a rectangular field. In the game process Arkady can buy extensions for his field, each extension enlarges one of the field sizes in a particular number of times. Formally, there are n extensions, the i-th of them multiplies the width or the length (by Ar...
The first line contains five integers a, b, h, w and n (1 ≤ a, b, h, w, n ≤ 100 000) — the sizes of the rectangle needed to be placed, the initial sizes of the field and the number of available extensions. The second line contains n integers a1, a2, ..., an (2 ≤ ai ≤ 100 000), where ai equals the integer a side multip...
Print the minimum number of extensions needed to reach Arkady's goal. If it is not possible to place the rectangle on the field with all extensions, print -1. If the rectangle can be placed on the initial field, print 0.
null
In the first example it is enough to use any of the extensions available. For example, we can enlarge h in 5 times using the second extension. Then h becomes equal 10 and it is now possible to place the rectangle on the field.
[{"input": "3 3 2 4 4\n2 5 4 10", "output": "1"}, {"input": "3 3 3 3 5\n2 3 5 4 2", "output": "0"}, {"input": "5 5 1 2 3\n2 2 3", "output": "-1"}, {"input": "3 4 1 1 3\n2 3 2", "output": "3"}]
2,100
["brute force", "dp", "meet-in-the-middle"]
103
[{"input": "3 3 2 4 4\r\n2 5 4 10\r\n", "output": "1\r\n"}, {"input": "3 3 3 3 5\r\n2 3 5 4 2\r\n", "output": "0\r\n"}, {"input": "5 5 1 2 3\r\n2 2 3\r\n", "output": "-1\r\n"}, {"input": "3 4 1 1 3\r\n2 3 2\r\n", "output": "3\r\n"}, {"input": "572 540 6 2 12\r\n2 3 2 2 2 3 3 3 2 2 2 2\r\n", "output": "-1\r\n"}, {"input...
false
stdio
null
true
525/C
525
C
Python 3
TESTS
7
249
12,697,600
32702980
n=int(input()) l=list(map(int,input().split())) l=sorted(l) l=l[::-1] k=0 b=-1 for i in range(n-1) : if l[i]==l[i+1] and b==-1 : b=l[i] l[i+1]=-1 if l[i]==l[i+1] and b!=1 : k+=b*l[i] b=-1 l[i]=-1 if l[i]==l[i+1]+1 and b==-1: b=l[i]-1 l[i+1]=-1 if ...
96
140
7,680,000
14422985
# coding=utf-8 n = input() l = list(map(int, input().split())) a, b = 0, 0 result = 0 for i in sorted(l, reverse=True): if a == 0 or a > i + 1: a = i elif b == 0: a, b = 0, i else: result += i * b a, b = 0, 0 print(result)
Codeforces Round 297 (Div. 2)
CF
2,015
2
256
Ilya and Sticks
In the evening, after the contest Ilya was bored, and he really felt like maximizing. He remembered that he had a set of n sticks and an instrument. Each stick is characterized by its length li. Ilya decided to make a rectangle from the sticks. And due to his whim, he decided to make rectangles in such a way that maxi...
The first line of the input contains a positive integer n (1 ≤ n ≤ 105) — the number of the available sticks. The second line of the input contains n positive integers li (2 ≤ li ≤ 106) — the lengths of the sticks.
The first line of the output must contain a single non-negative integer — the maximum total area of the rectangles that Ilya can make from the available sticks.
null
null
[{"input": "4\n2 4 4 2", "output": "8"}, {"input": "4\n2 2 3 5", "output": "0"}, {"input": "4\n100003 100004 100005 100006", "output": "10000800015"}]
1,600
["greedy", "math", "sortings"]
96
[{"input": "4\r\n2 4 4 2\r\n", "output": "8\r\n"}, {"input": "4\r\n2 2 3 5\r\n", "output": "0\r\n"}, {"input": "4\r\n100003 100004 100005 100006\r\n", "output": "10000800015\r\n"}, {"input": "8\r\n5 3 3 3 3 4 4 4\r\n", "output": "25\r\n"}, {"input": "10\r\n123 124 123 124 2 2 2 2 9 9\r\n", "output": "15270\r\n"}, {"inp...
false
stdio
null
true