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
652/B
652
B
Python 3
TESTS
4
46
0
203414002
def sort(n, arr): if n == 1: return arr elif n == 2: return arr elif n == 3: (arr[1], arr[2]) = (arr[2], arr[1]) return arr newarr = [0] * n newarr[0] = arr[0] newarr[1] = arr[-1] j = 1 for i in range(2, n, 2): newarr[i] = arr[j] j += 1 ...
16
31
0
158245507
a=int(input()) b=sorted(map(int,input().split())) i=0 while(i<a//2): print(b[i],b[-i-1],end=" ") i+=1 if a%2:print(b[a//2])
Educational Codeforces Round 10
ICPC
2,016
1
256
z-sort
A student of z-school found a kind of sorting called z-sort. The array a with n elements are z-sorted if two conditions hold: 1. ai ≥ ai - 1 for all even i, 2. ai ≤ ai - 1 for all odd i > 1. For example the arrays [1,2,1,2] and [1,1,1,1] are z-sorted while the array [1,2,3,4] isn’t z-sorted. Can you make the array z...
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of elements in the array a. The second line contains n integers ai (1 ≤ ai ≤ 109) — the elements of the array a.
If it's possible to make the array a z-sorted print n space separated integers ai — the elements after z-sort. Otherwise print the only word "Impossible".
null
null
[{"input": "4\n1 2 2 1", "output": "1 2 1 2"}, {"input": "5\n1 3 2 2 5", "output": "1 5 2 3 2"}]
1,000
["sortings"]
16
[{"input": "4\r\n1 2 2 1\r\n", "output": "1 2 1 2\r\n"}, {"input": "5\r\n1 3 2 2 5\r\n", "output": "1 5 2 3 2\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "1 1 1 1 1 1 1 1 1 1\r\n"}, {"input": "10\r\n1 9 7 6 2 4 7 8 1 3\r\n", "output": "1 9 1 8 2 7 3 7 4 6\r\n"...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input with open(input_path) as f: n = int(f.readline().strip()) a = list(map(int, f.readline().split())) a_sorted = sorted(a) # Read reference output with ope...
true
239/B
239
B
Python 3
TESTS
3
62
0
184154428
def print_digits(seq): printed_digits = [] cp = 0 dp = 1 prev_sign = False while cp >= 0 and cp < len(seq): # if CP is pointing to a digit if seq[cp].isdigit(): # interpreter prints that digit printed_digits.append(seq[cp]) # the value of the seque...
33
92
0
154844086
n, q = map(int, input().split()) S = [-1]+list(map(lambda x: ord(x)-ord('0'), input()))+[-1] D = [12, 14] for _ in range(q): l, r = map(int, input().split()) s = S[l-1:r+2] s[0] = s[-1] = -1 c = [0]*10 dp, p = 1, 1 i = s[p] while i!= -1: if i==14: dp = 1 if s[p+1] in D: s.pop(p) else: p += 1 ...
Codeforces Round 148 (Div. 2)
CF
2,012
2
256
Easy Tape Programming
There is a programming language in which every program is a non-empty sequence of "<" and ">" signs and digits. Let's explain how the interpreter of this programming language works. A program is interpreted using movement of instruction pointer (IP) which consists of two parts. - Current character pointer (CP); - Dire...
The first line of input contains two integers n and q (1 ≤ n, q ≤ 100) — represents the length of the sequence s and the number of queries. The second line contains s, a sequence of "<", ">" and digits (0..9) written from left to right. Note, that the characters of s are not separated with spaces. The next q lines ea...
For each query print 10 space separated integers: x0, x1, ..., x9 where xi equals the number of times the interpreter prints i while running the corresponding program. Print answers to the queries in the order they are given in input.
null
null
[{"input": "7 4\n1>3>22<\n1 3\n4 7\n7 7\n1 7", "output": "0 1 0 1 0 0 0 0 0 0\n2 2 2 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n2 3 2 1 0 0 0 0 0 0"}]
1,500
["brute force", "implementation"]
33
[{"input": "7 4\r\n1>3>22<\r\n1 3\r\n4 7\r\n7 7\r\n1 7\r\n", "output": "0 1 0 1 0 0 0 0 0 0 \r\n2 2 2 0 0 0 0 0 0 0 \r\n0 0 0 0 0 0 0 0 0 0 \r\n2 3 2 1 0 0 0 0 0 0 \r\n"}, {"input": "5 2\r\n>>>>>\r\n1 5\r\n1 2\r\n", "output": "0 0 0 0 0 0 0 0 0 0 \r\n0 0 0 0 0 0 0 0 0 0 \r\n"}, {"input": "1 3\r\n9\r\n1 1\r\n1 1\r\n1 1\...
false
stdio
null
true
659/D
659
D
Python 3
TESTS
5
109
0
51043755
n = int(input()) coordenates = [] for _ in range(n+1): d = input().split() coordenates.append(d) direction = 'N' # print(coordenates) # coordenates.pop(0) # print(coordenates) counter = 0 for p in range(1, len(coordenates)-1): # print('Direcao: {}, p({}, {})'.format(direction, p[0], p[1])) if direction == 'N' and...
22
46
0
198028928
if __name__ == "__main__": n = int(input()) x_anterior = None y_anterior = None sentido_atual = None curvas_perigosas = 0 for i in range(n + 1): x, y = map(int, input().split()) if x_anterior is None: x_anterior = x y_anterior = y continue ...
Codeforces Round 346 (Div. 2)
CF
2,016
1
256
Bicycle Race
Maria participates in a bicycle race. The speedway takes place on the shores of Lake Lucerne, just repeating its contour. As you know, the lake shore consists only of straight sections, directed to the north, south, east or west. Let's introduce a system of coordinates, directing the Ox axis from west to east, and th...
The first line of the input contains an integer n (4 ≤ n ≤ 1000) — the number of straight sections of the track. The following (n + 1)-th line contains pairs of integers (xi, yi) ( - 10 000 ≤ xi, yi ≤ 10 000). The first of these points is the starting position. The i-th straight section of the track begins at the poin...
Print a single integer — the number of dangerous turns on the track.
null
The first sample corresponds to the picture: The picture shows that you can get in the water under unfortunate circumstances only at turn at the point (1, 1). Thus, the answer is 1.
[{"input": "6\n0 0\n0 1\n1 1\n1 2\n2 2\n2 0\n0 0", "output": "1"}, {"input": "16\n1 1\n1 5\n3 5\n3 7\n2 7\n2 9\n6 9\n6 7\n5 7\n5 3\n4 3\n4 4\n3 4\n3 2\n5 2\n5 1\n1 1", "output": "6"}]
1,500
["geometry", "implementation", "math"]
22
[{"input": "6\r\n0 0\r\n0 1\r\n1 1\r\n1 2\r\n2 2\r\n2 0\r\n0 0\r\n", "output": "1\r\n"}, {"input": "16\r\n1 1\r\n1 5\r\n3 5\r\n3 7\r\n2 7\r\n2 9\r\n6 9\r\n6 7\r\n5 7\r\n5 3\r\n4 3\r\n4 4\r\n3 4\r\n3 2\r\n5 2\r\n5 1\r\n1 1\r\n", "output": "6\r\n"}, {"input": "4\r\n-10000 -10000\r\n-10000 10000\r\n10000 10000\r\n10000 -1...
false
stdio
null
true
652/B
652
B
Python 3
TESTS
4
46
6,963,200
131528755
# link : https://codeforces.com/problemset/problem/652/B # sorting def check(l): for i in range(len(l)): if (i+1)%2==0: if not l[i]>=l[i-1]: return False else: if not l[i]<=l[i-1]: return False return True n = int(input()) l = [int(x)...
16
31
0
158697219
n = int(input()) a = sorted(list(map(int,input().split()))) d = [] for i in range(len(a)): d += [a[i]] d += [a[n - 1 - i]] if n+n<n: d += [a[n]] print(*d[0:len(a)])
Educational Codeforces Round 10
ICPC
2,016
1
256
z-sort
A student of z-school found a kind of sorting called z-sort. The array a with n elements are z-sorted if two conditions hold: 1. ai ≥ ai - 1 for all even i, 2. ai ≤ ai - 1 for all odd i > 1. For example the arrays [1,2,1,2] and [1,1,1,1] are z-sorted while the array [1,2,3,4] isn’t z-sorted. Can you make the array z...
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of elements in the array a. The second line contains n integers ai (1 ≤ ai ≤ 109) — the elements of the array a.
If it's possible to make the array a z-sorted print n space separated integers ai — the elements after z-sort. Otherwise print the only word "Impossible".
null
null
[{"input": "4\n1 2 2 1", "output": "1 2 1 2"}, {"input": "5\n1 3 2 2 5", "output": "1 5 2 3 2"}]
1,000
["sortings"]
16
[{"input": "4\r\n1 2 2 1\r\n", "output": "1 2 1 2\r\n"}, {"input": "5\r\n1 3 2 2 5\r\n", "output": "1 5 2 3 2\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "1 1 1 1 1 1 1 1 1 1\r\n"}, {"input": "10\r\n1 9 7 6 2 4 7 8 1 3\r\n", "output": "1 9 1 8 2 7 3 7 4 6\r\n"...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input with open(input_path) as f: n = int(f.readline().strip()) a = list(map(int, f.readline().split())) a_sorted = sorted(a) # Read reference output with ope...
true
776/A
776
A
Python 3
TESTS
4
108
102,400
48473229
Initial = input() n = int(input()) print(Initial) for i in range(n): X = list(input().split()) Initial = Initial.replace(X[0], X[1]) print(Initial)
57
46
0
146008993
v1,v2 =map(str, input().split()) n = int(input()) x=[] x.append(v1) x.append(v2) print(*x) for i in range(n): v11,v12 = map(str,input().split()) x.remove(v11) x.append(v12) print(*x)
ICM Technex 2017 and Codeforces Round 400 (Div. 1 + Div. 2, combined)
CF
2,017
2
256
A Serial Killer
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim. The killer starts with two potential victims on his first day, selects one of these two, kills selected ...
First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer n (1 ≤ n ≤ 1000), the number of days. Next n lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second ...
Output n + 1 lines, the i-th line should contain the two persons from which the killer selects for the i-th murder. The (n + 1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order.
null
In first example, the killer starts with ross and rachel. - After day 1, ross is killed and joey appears. - After day 2, rachel is killed and phoebe appears. - After day 3, phoebe is killed and monica appears. - After day 4, monica is killed and chandler appears.
[{"input": "ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler", "output": "ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler"}, {"input": "icm codeforces\n1\ncodeforces technex", "output": "icm codeforces\nicm technex"}]
900
["brute force", "implementation", "strings"]
57
[{"input": "ross rachel\r\n4\r\nross joey\r\nrachel phoebe\r\nphoebe monica\r\nmonica chandler\r\n", "output": "ross rachel\r\njoey rachel\r\njoey phoebe\r\njoey monica\r\njoey chandler\r\n"}, {"input": "icm codeforces\r\n1\r\ncodeforces technex\r\n", "output": "icm codeforces\r\nicm technex\r\n"}, {"input": "a b\r\n3\...
false
stdio
import sys def main(): input_path, output_path, submission_path = sys.argv[1:4] with open(output_path, 'r') as f: correct_lines = [line.strip() for line in f.readlines()] with open(submission_path, 'r') as f: submission_lines = [line.strip() for line in f.readlines()] if ...
true
776/A
776
A
Python 3
TESTS
4
62
0
110443681
initial = input() n = int(input()) for i in range(n): line = input().split() print(initial) initial = initial.replace(line[0],line[1]) print(initial)
57
46
0
146789097
names = set(input().split(' ')) print(' '.join(names)) n = int(input()) for i in range(n): a,b = input().split(' ') if a in names: names.remove(a) names.add(b) else: names.remove(b) names.add(a) print(' '.join(names))
ICM Technex 2017 and Codeforces Round 400 (Div. 1 + Div. 2, combined)
CF
2,017
2
256
A Serial Killer
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim. The killer starts with two potential victims on his first day, selects one of these two, kills selected ...
First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer n (1 ≤ n ≤ 1000), the number of days. Next n lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second ...
Output n + 1 lines, the i-th line should contain the two persons from which the killer selects for the i-th murder. The (n + 1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order.
null
In first example, the killer starts with ross and rachel. - After day 1, ross is killed and joey appears. - After day 2, rachel is killed and phoebe appears. - After day 3, phoebe is killed and monica appears. - After day 4, monica is killed and chandler appears.
[{"input": "ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler", "output": "ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler"}, {"input": "icm codeforces\n1\ncodeforces technex", "output": "icm codeforces\nicm technex"}]
900
["brute force", "implementation", "strings"]
57
[{"input": "ross rachel\r\n4\r\nross joey\r\nrachel phoebe\r\nphoebe monica\r\nmonica chandler\r\n", "output": "ross rachel\r\njoey rachel\r\njoey phoebe\r\njoey monica\r\njoey chandler\r\n"}, {"input": "icm codeforces\r\n1\r\ncodeforces technex\r\n", "output": "icm codeforces\r\nicm technex\r\n"}, {"input": "a b\r\n3\...
false
stdio
import sys def main(): input_path, output_path, submission_path = sys.argv[1:4] with open(output_path, 'r') as f: correct_lines = [line.strip() for line in f.readlines()] with open(submission_path, 'r') as f: submission_lines = [line.strip() for line in f.readlines()] if ...
true
48/C
48
C
PyPy 3
TESTS
3
154
0
131959952
from sys import stdin inp = stdin.readline n = int(inp()) arr = [int(x) for x in inp().split()] arr = ([0] + arr) diff = [arr[i] - arr[i-1] for i in range(n)] d1 = d2 = 0 length = 0 for i in range(n-1): if diff[i] < diff[i+1]: d1 = diff[i] d2 = diff[i+1] length = i + 1 break if ...
45
124
819,200
32153506
n = int(input()) zap = list(map(int, input().split())) upperbound = float('inf') lowerbound = -float('inf') counter = 1 for item in zap: upperbound = min(upperbound, 10/counter + 10 * item / counter) counter += 1 k = 1 for item in zap: lowerbound = max(lowerbound, item * 10 / k) k += 1 benzonthela...
School Personal Contest #3 (Winter Computer School 2010/11) - Codeforces Beta Round 45 (ACM-ICPC Rules)
ICPC
2,010
2
256
The Race
Every year a race takes place on the motorway between cities A and B. This year Vanya decided to take part in the race and drive his own car that has been around and bears its own noble name — The Huff-puffer. So, Vasya leaves city A on the Huff-puffer, besides, at the very beginning he fills the petrol tank with α li...
The first line contains an integer n (1 ≤ n ≤ 1000) which represents the number of petrol stations where Vanya has stopped. The next line has n space-separated integers which represent the numbers of the stations. The numbers are positive and do not exceed 106, they are given in the increasing order. No two numbers in ...
Print in the first line "unique" (without quotes) if the answer can be determined uniquely. In the second line print the number of the station where the next stop will take place. If the answer is not unique, print in the first line "not unique".
null
In the second example the answer is not unique. For example, if α = 10, we'll have such a sequence as 1, 2, 3, and if α = 14, the sequence will be 1, 2, 4.
[{"input": "3\n1 2 4", "output": "unique\n5"}, {"input": "2\n1 2", "output": "not unique"}]
1,800
["math"]
45
[{"input": "3\r\n1 2 4\r\n", "output": "unique\r\n5\r\n"}, {"input": "2\r\n1 2\r\n", "output": "not unique\r\n"}, {"input": "1\r\n5\r\n", "output": "not unique\r\n"}, {"input": "3\r\n1 3 4\r\n", "output": "unique\r\n6\r\n"}, {"input": "5\r\n1 2 3 5 6\r\n", "output": "unique\r\n7\r\n"}, {"input": "6\r\n1 2 3 5 6 7\r\n",...
false
stdio
null
true
652/B
652
B
Python 3
TESTS
4
46
4,608,000
16939827
n = int(input()) k = sorted(map(int, input().split())) w = -(-n // 2) print(*[k[(w * i) % n] for i in range(n)])
16
31
0
158726733
n=int(input()) a=input().split()[:] for i in range(n): a[i]=int(a[i]) b=sorted(a) for i in range(1,len(a),2): b.insert(i,b[len(b)-1]) b.pop(len(b)-1) for i in range(len(b)): print(b[i],end=' ')
Educational Codeforces Round 10
ICPC
2,016
1
256
z-sort
A student of z-school found a kind of sorting called z-sort. The array a with n elements are z-sorted if two conditions hold: 1. ai ≥ ai - 1 for all even i, 2. ai ≤ ai - 1 for all odd i > 1. For example the arrays [1,2,1,2] and [1,1,1,1] are z-sorted while the array [1,2,3,4] isn’t z-sorted. Can you make the array z...
The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of elements in the array a. The second line contains n integers ai (1 ≤ ai ≤ 109) — the elements of the array a.
If it's possible to make the array a z-sorted print n space separated integers ai — the elements after z-sort. Otherwise print the only word "Impossible".
null
null
[{"input": "4\n1 2 2 1", "output": "1 2 1 2"}, {"input": "5\n1 3 2 2 5", "output": "1 5 2 3 2"}]
1,000
["sortings"]
16
[{"input": "4\r\n1 2 2 1\r\n", "output": "1 2 1 2\r\n"}, {"input": "5\r\n1 3 2 2 5\r\n", "output": "1 5 2 3 2\r\n"}, {"input": "1\r\n1\r\n", "output": "1\r\n"}, {"input": "10\r\n1 1 1 1 1 1 1 1 1 1\r\n", "output": "1 1 1 1 1 1 1 1 1 1\r\n"}, {"input": "10\r\n1 9 7 6 2 4 7 8 1 3\r\n", "output": "1 9 1 8 2 7 3 7 4 6\r\n"...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input with open(input_path) as f: n = int(f.readline().strip()) a = list(map(int, f.readline().split())) a_sorted = sorted(a) # Read reference output with ope...
true
659/D
659
D
Python 3
TESTS
5
124
512,000
71407401
def onde(ponto1, ponto2): if ponto1[0] > ponto2[0] and ponto1[1] == ponto2[1]: return 'w' if ponto1[0] < ponto2[0] and ponto1[1] == ponto2[1]: return 'e' if ponto1[0] == ponto2[0] and ponto1[1] < ponto2[1]: return 'n' if ponto1[0] == ponto2[0] and ponto1[1] > ponto2[1]: return 's' def turn_left...
22
46
0
200306127
n=int(input()) print(int(((n-2)/2)-1))
Codeforces Round 346 (Div. 2)
CF
2,016
1
256
Bicycle Race
Maria participates in a bicycle race. The speedway takes place on the shores of Lake Lucerne, just repeating its contour. As you know, the lake shore consists only of straight sections, directed to the north, south, east or west. Let's introduce a system of coordinates, directing the Ox axis from west to east, and th...
The first line of the input contains an integer n (4 ≤ n ≤ 1000) — the number of straight sections of the track. The following (n + 1)-th line contains pairs of integers (xi, yi) ( - 10 000 ≤ xi, yi ≤ 10 000). The first of these points is the starting position. The i-th straight section of the track begins at the poin...
Print a single integer — the number of dangerous turns on the track.
null
The first sample corresponds to the picture: The picture shows that you can get in the water under unfortunate circumstances only at turn at the point (1, 1). Thus, the answer is 1.
[{"input": "6\n0 0\n0 1\n1 1\n1 2\n2 2\n2 0\n0 0", "output": "1"}, {"input": "16\n1 1\n1 5\n3 5\n3 7\n2 7\n2 9\n6 9\n6 7\n5 7\n5 3\n4 3\n4 4\n3 4\n3 2\n5 2\n5 1\n1 1", "output": "6"}]
1,500
["geometry", "implementation", "math"]
22
[{"input": "6\r\n0 0\r\n0 1\r\n1 1\r\n1 2\r\n2 2\r\n2 0\r\n0 0\r\n", "output": "1\r\n"}, {"input": "16\r\n1 1\r\n1 5\r\n3 5\r\n3 7\r\n2 7\r\n2 9\r\n6 9\r\n6 7\r\n5 7\r\n5 3\r\n4 3\r\n4 4\r\n3 4\r\n3 2\r\n5 2\r\n5 1\r\n1 1\r\n", "output": "6\r\n"}, {"input": "4\r\n-10000 -10000\r\n-10000 10000\r\n10000 10000\r\n10000 -1...
false
stdio
null
true
362/A
362
A
Python 3
PRETESTS
7
46
307,200
5105399
def main(): n = int(input()) out = "" for t in range(n): knights = [0 for i in range(8)] valid = [False for i in range(8)] for i in range(8): line = input() for j in range(8): #print((i%2)*4 + j%4, line[j]) if line[j] == '.': valid[(i%2)*4 + j%4] = True ...
45
46
0
223013756
n = int(input()) testcases = [] for i in range(n): # _ = input() chess = [] for _ in range(8): points = input() chess.append(points) if i != n-1: new_line = input() testcases.append(chess) for chess in testcases: def main(): poss_k = [] for i in range...
Codeforces Round 212 (Div. 2)
CF
2,013
1
256
Two Semiknights Meet
A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares backward and 2 to the right and 2 squares backward and 2 to the le...
The first line contains number t (1 ≤ t ≤ 50) — the number of boards. Each board is described by a matrix of characters, consisting of 8 rows and 8 columns. The matrix consists of characters ".", "#", "K", representing an empty good square, a bad square and the semiknight's position, correspondingly. It is guaranteed t...
For each test, print on a single line the answer to the problem: "YES", if the semiknights can meet and "NO" otherwise.
null
Consider the first board from the sample. We will assume the rows and columns of the matrix to be numbered 1 through 8 from top to bottom and from left to right, correspondingly. The knights can meet, for example, in square (2, 7). The semiknight from square (4, 1) goes to square (2, 3) and the semiknight goes from squ...
[{"input": "2\n........\n........\n......#.\nK..##..#\n.......#\n...##..#\n......#.\nK.......\n........\n........\n..#.....\n..#..#..\n..####..\n...##...\n........\n....K#K#", "output": "YES\nNO"}]
1,500
["greedy", "math"]
45
[{"input": "2\r\n........\r\n........\r\n......#.\r\nK..##..#\r\n.......#\r\n...##..#\r\n......#.\r\nK.......\r\n\r\n........\r\n........\r\n..#.....\r\n..#..#..\r\n..####..\r\n...##...\r\n........\r\n....K#K#\r\n", "output": "YES\r\nNO\r\n"}, {"input": "3\r\n........\r\n........\r\n..#.....\r\n..#..#..\r\n..####..\r\n...
false
stdio
null
true
514/D
514
D
PyPy 3-64
TESTS
5
62
614,400
197864000
# ﷽ from collections import deque import sys input = lambda: sys.stdin.readline().strip() mod=7+10**9 class RangeQuery: def __init__(self, data, default=0, func=max): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) s...
35
1,996
120,217,600
192669643
def rl(): return list(map(int,input().split())) def ri(): return int(input()) def rs(): return input() def rm(): return map(int,input().split()) from math import log2,floor def main(): n,l,k=rm() rb=[] for i in range(n): rb.append(rl()) rb=[[rb[i][j] for i in range(len(rb))] for ...
Codeforces Round 291 (Div. 2)
CF
2,015
2
256
R2D2 and Droid Army
An army of n droids is lined up in one row. Each droid is described by m integers a1, a2, ..., am, where ai is the number of details of the i-th type in this droid's mechanism. R2-D2 wants to destroy the sequence of consecutive droids of maximum length. He has m weapons, the i-th weapon can affect all the droids in the...
The first line contains three integers n, m, k (1 ≤ n ≤ 105, 1 ≤ m ≤ 5, 0 ≤ k ≤ 109) — the number of droids, the number of detail types and the number of available shots, respectively. Next n lines follow describing the droids. Each line contains m integers a1, a2, ..., am (0 ≤ ai ≤ 108), where ai is the number of det...
Print m space-separated integers, where the i-th number is the number of shots from the weapon of the i-th type that the robot should make to destroy the subsequence of consecutive droids of the maximum length. If there are multiple optimal solutions, print any of them. It is not necessary to make exactly k shots, th...
null
In the first test the second, third and fourth droids will be destroyed. In the second test the first and second droids will be destroyed.
[{"input": "5 2 4\n4 0\n1 2\n2 1\n0 2\n1 3", "output": "2 2"}, {"input": "3 2 4\n1 2\n1 3\n2 2", "output": "1 3"}]
2,000
["binary search", "data structures", "two pointers"]
35
[{"input": "5 2 4\r\n4 0\r\n1 2\r\n2 1\r\n0 2\r\n1 3\r\n", "output": "2 2\r\n"}, {"input": "3 2 4\r\n1 2\r\n1 3\r\n2 2\r\n", "output": "1 3\r\n"}, {"input": "1 1 0\r\n0\r\n", "output": "0\r\n"}, {"input": "1 1 0\r\n1\r\n", "output": "0\r\n"}, {"input": "1 1 1\r\n0\r\n", "output": "0\r\n"}, {"input": "4 5 33\r\n2 10 2 3...
false
stdio
null
true
967/B
967
B
Python 3
TESTS
24
234
6,348,800
39336912
n,A,B = map(int,input().split(' ')) s = list(map(int,input().split(' '))) adf = s[0] s = sorted(s,reverse=True) c = 0 S = sum(s) s.remove(adf) t = (adf*A)/S i = 0 while (t<B and i<n-1): t = (t*S)/(S-s[i]) S = S-s[i] i = i+1 c = c+1 print(c)
26
78
13,516,800
197520959
hole, l, need = map(int,input().split()) a = list(map(int,input().split())) x = a.pop(0) b = x*l / need a.sort(reverse=True) y = sum(a)+x p = 0 while b<y: y -= a[p] p +=1 print(p)
Codeforces Round 477 (rated, Div. 2, based on VK Cup 2018 Round 3)
CF
2,018
1
256
Watering System
Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for $$$n$$$ flowers and so it looks like a pipe with $$$n$$$ holes. Arkady can only use the water that flows from the first hole. Arkady can block some of the holes, and then pour $$$A$$$ liters of water into the...
The first line contains three integers $$$n$$$, $$$A$$$, $$$B$$$ ($$$1 \le n \le 100\,000$$$, $$$1 \le B \le A \le 10^4$$$) — the number of holes, the volume of water Arkady will pour into the system, and the volume he wants to get out of the first hole. The second line contains $$$n$$$ integers $$$s_1, s_2, \ldots, s...
Print a single integer — the number of holes Arkady should block.
null
In the first example Arkady should block at least one hole. After that, $$$\frac{10 \cdot 2}{6} \approx 3.333$$$ liters of water will flow out of the first hole, and that suits Arkady. In the second example even without blocking any hole, $$$\frac{80 \cdot 3}{10} = 24$$$ liters will flow out of the first hole, that is...
[{"input": "4 10 3\n2 2 2 2", "output": "1"}, {"input": "4 80 20\n3 2 1 4", "output": "0"}, {"input": "5 10 10\n1000 1 1 1 1", "output": "4"}]
1,000
["math", "sortings"]
26
[{"input": "4 10 3\r\n2 2 2 2\r\n", "output": "1\r\n"}, {"input": "4 80 20\r\n3 2 1 4\r\n", "output": "0\r\n"}, {"input": "5 10 10\r\n1000 1 1 1 1\r\n", "output": "4\r\n"}, {"input": "10 300 100\r\n20 1 3 10 8 5 3 6 4 3\r\n", "output": "1\r\n"}, {"input": "10 300 100\r\n20 25 68 40 60 37 44 85 23 96\r\n", "output": "8\...
false
stdio
null
true
496/D
496
D
Python 3
TESTS
6
46
0
12833880
import math n = int(input()) games = list(map(int, input().split())) PETYA = 0 GENA = 1 pontos = [[0], [0]] for i in range(0, n): if (games[i] == 1): pontos[PETYA].append(pontos[PETYA][i] + 1) pontos[GENA].append(pontos[GENA][i]) else: pontos[PETYA].append(pontos[PETYA][i]) pontos[GENA].append(pontos[GENA...
53
1,372
10,649,600
9303276
#!/usr/bin/env python3 import itertools n = int(input()) a = [int(x) for x in input().split()] winner = a[-1] looser = 3 - winner serve_win_cnt, serve_loose_cnt, win_pos, loose_pos, result = [0], [0], [-1], [-1], [] win_cnt = a.count(winner) for i in range(n): if a[i] == winner: win_pos.append(i) el...
Codeforces Round 283 (Div. 2)
CF
2,014
2
256
Tennis Game
Petya and Gena love playing table tennis. A single match is played according to the following rules: a match consists of multiple sets, each set consists of multiple serves. Each serve is won by one of the players, this player scores one point. As soon as one of the players scores t points, he wins the set; then the ne...
The first line contains a single integer n — the length of the sequence of games (1 ≤ n ≤ 105). The second line contains n space-separated integers ai. If ai = 1, then the i-th serve was won by Petya, if ai = 2, then the i-th serve was won by Gena. It is not guaranteed that at least one option for numbers s and t cor...
In the first line print a single number k — the number of options for numbers s and t. In each of the following k lines print two integers si and ti — the option for numbers s and t. Print the options in the order of increasing si, and for equal si — in the order of increasing ti.
null
null
[{"input": "5\n1 2 1 2 1", "output": "2\n1 3\n3 1"}, {"input": "4\n1 1 1 1", "output": "3\n1 4\n2 2\n4 1"}, {"input": "4\n1 2 1 2", "output": "0"}, {"input": "8\n2 1 2 1 1 1 1 1", "output": "3\n1 6\n2 3\n6 1"}]
1,900
["binary search"]
53
[{"input": "5\r\n1 2 1 2 1\r\n", "output": "2\r\n1 3\r\n3 1\r\n"}, {"input": "4\r\n1 1 1 1\r\n", "output": "3\r\n1 4\r\n2 2\r\n4 1\r\n"}, {"input": "4\r\n1 2 1 2\r\n", "output": "0\r\n"}, {"input": "8\r\n2 1 2 1 1 1 1 1\r\n", "output": "3\r\n1 6\r\n2 3\r\n6 1\r\n"}, {"input": "14\r\n2 1 2 1 1 1 1 2 1 1 2 1 2 1\r\n", "o...
false
stdio
null
true
362/C
362
C
Python 3
PRETESTS
2
46
307,200
5106086
def main(): n = int(input()) arr = input().split(" ") arr = [int(a) for a in arr] imp = 0 cnt = 0 tot = 0 for i in range(n): tot += abs(i - arr[i]) for i in range(n): for j in range(i+1, n): improvement = abs(arr[i] - i) + abs(arr[j] - j) - abs(arr[i] - j) - abs(arr[j] - i) ...
38
1,434
10,444,800
71195138
arr = [0 for i in range(5001)] def insertion_sort(n, a): def modify(t): while t > 0: arr[t] += 1 t -= t & (-t) def query(t): res = 0 while t < 5001: res += arr[t] t += t & (-t) return res s = 0 ans = 0 way = 0 f...
Codeforces Round 212 (Div. 2)
CF
2,013
2
256
Insertion Sort
Petya is a beginner programmer. He has already mastered the basics of the C++ language and moved on to learning algorithms. The first algorithm he encountered was insertion sort. Petya has already written the code that implements this algorithm and sorts the given integer zero-indexed array a of size n in the non-decre...
The first line contains a single integer n (2 ≤ n ≤ 5000) — the length of the permutation. The second line contains n different integers from 0 to n - 1, inclusive — the actual permutation.
Print two integers: the minimum number of times the swap function is executed and the number of such pairs (i, j) that swapping the elements of the input permutation with indexes i and j leads to the minimum number of the executions.
null
In the first sample the appropriate pairs are (0, 3) and (0, 4). In the second sample the appropriate pairs are (0, 4), (1, 4), (2, 4) and (3, 4).
[{"input": "5\n4 0 3 1 2", "output": "3 2"}, {"input": "5\n1 2 3 4 0", "output": "3 4"}]
1,900
["data structures", "dp", "implementation", "math"]
38
[{"input": "5\r\n4 0 3 1 2\r\n", "output": "3 2\r\n"}, {"input": "5\r\n1 2 3 4 0\r\n", "output": "3 4\r\n"}, {"input": "5\r\n1 3 4 0 2\r\n", "output": "4 5\r\n"}, {"input": "10\r\n9 8 7 6 5 4 3 2 1 0\r\n", "output": "28 1\r\n"}, {"input": "5\r\n0 4 1 3 2\r\n", "output": "1 1\r\n"}, {"input": "6\r\n3 0 1 4 5 2\r\n", "ou...
false
stdio
null
true
362/C
362
C
Python 3
TESTS
2
31
307,200
5519437
n, a = int(input()), list(map(int, input().split())) s = t = 0 r = sum(max(i - j, 0) for i, j in enumerate(a)) for i in range(n - 1): for j in range(i + 1, n): d = max(i - a[i], 0) + max(j - a[j], 0) - max(j - a[i], 0) - max(i - a[j], 0) if s < d: s, t = d, 1 elif s == d: t += 1 print(r - s,...
38
1,434
10,444,800
71195138
arr = [0 for i in range(5001)] def insertion_sort(n, a): def modify(t): while t > 0: arr[t] += 1 t -= t & (-t) def query(t): res = 0 while t < 5001: res += arr[t] t += t & (-t) return res s = 0 ans = 0 way = 0 f...
Codeforces Round 212 (Div. 2)
CF
2,013
2
256
Insertion Sort
Petya is a beginner programmer. He has already mastered the basics of the C++ language and moved on to learning algorithms. The first algorithm he encountered was insertion sort. Petya has already written the code that implements this algorithm and sorts the given integer zero-indexed array a of size n in the non-decre...
The first line contains a single integer n (2 ≤ n ≤ 5000) — the length of the permutation. The second line contains n different integers from 0 to n - 1, inclusive — the actual permutation.
Print two integers: the minimum number of times the swap function is executed and the number of such pairs (i, j) that swapping the elements of the input permutation with indexes i and j leads to the minimum number of the executions.
null
In the first sample the appropriate pairs are (0, 3) and (0, 4). In the second sample the appropriate pairs are (0, 4), (1, 4), (2, 4) and (3, 4).
[{"input": "5\n4 0 3 1 2", "output": "3 2"}, {"input": "5\n1 2 3 4 0", "output": "3 4"}]
1,900
["data structures", "dp", "implementation", "math"]
38
[{"input": "5\r\n4 0 3 1 2\r\n", "output": "3 2\r\n"}, {"input": "5\r\n1 2 3 4 0\r\n", "output": "3 4\r\n"}, {"input": "5\r\n1 3 4 0 2\r\n", "output": "4 5\r\n"}, {"input": "10\r\n9 8 7 6 5 4 3 2 1 0\r\n", "output": "28 1\r\n"}, {"input": "5\r\n0 4 1 3 2\r\n", "output": "1 1\r\n"}, {"input": "6\r\n3 0 1 4 5 2\r\n", "ou...
false
stdio
null
true
363/D
363
D
Python 3
TESTS
1
31
0
225753908
def check(x, a, b, k): a.sort() ans = k for i in range(1, x + 1): ans += min(0, a[i - 1] - b[i - 1]) if ans < 0: return False a.sort(reverse=True) return ans >= 0 def main(): n, m, k = map(int, input().split()) a = list(map(int, input().split())) b = list(ma...
34
764
10,035,200
182758780
n, m, a = map(int, input().split()) b, p = sorted(map(int, input().split())), sorted(map(int, input().split())) def f(k): return sum(max(0, p[i] - b[n - k + i]) for i in range(k)) def g(k): return sum(min(b[n - k + i], p[i]) for i in range(k)) x, y, d = 0, min(n, m) + 1, a while y - x > 1: k = (x + y) ...
Codeforces Round 211 (Div. 2)
CF
2,013
1
256
Renting Bikes
A group of n schoolboys decided to ride bikes. As nobody of them has a bike, the boys need to rent them. The renting site offered them m bikes. The renting price is different for different bikes, renting the j-th bike costs pj rubles. In total, the boys' shared budget is a rubles. Besides, each of them has his own pe...
The first line of the input contains three integers n, m and a (1 ≤ n, m ≤ 105; 0 ≤ a ≤ 109). The second line contains the sequence of integers b1, b2, ..., bn (1 ≤ bi ≤ 104), where bi is the amount of the i-th boy's personal money. The third line contains the sequence of integers p1, p2, ..., pm (1 ≤ pj ≤ 109), where ...
Print two integers r and s, where r is the maximum number of schoolboys that can rent a bike and s is the minimum total personal money needed to rent r bikes. If the schoolchildren cannot rent any bikes, then r = s = 0.
null
In the first sample both schoolchildren can rent a bike. For instance, they can split the shared budget in half (5 rubles each). In this case one of them will have to pay 1 ruble from the personal money and the other one will have to pay 2 rubles from the personal money. In total, they spend 3 rubles of their personal ...
[{"input": "2 2 10\n5 5\n7 6", "output": "2 3"}, {"input": "4 5 2\n8 1 1 2\n6 3 7 5 2", "output": "3 8"}]
1,800
["binary search", "greedy"]
34
[{"input": "2 2 10\r\n5 5\r\n7 6\r\n", "output": "2 3\r\n"}, {"input": "4 5 2\r\n8 1 1 2\r\n6 3 7 5 2\r\n", "output": "3 8\r\n"}, {"input": "1 1 2\r\n1\r\n2\r\n", "output": "1 0\r\n"}, {"input": "4 1 1\r\n3 2 3 2\r\n3\r\n", "output": "1 2\r\n"}, {"input": "1 4 1\r\n3\r\n2 4 5 5\r\n", "output": "1 1\r\n"}, {"input": "3 ...
false
stdio
null
true
776/A
776
A
Python 3
TESTS
4
62
6,860,800
34713874
step = input() + "\n" num = int(input()) res = str(step) for _ in range(num): sat = input().split() step = step.replace(sat[0],sat[1]) res += step print(res)
57
46
0
150138014
x, y = input().split() print(x, y) for _ in range(int(input())): a, b = input().split() if x == a: x = b elif y == a: y = b print(x, y)
ICM Technex 2017 and Codeforces Round 400 (Div. 1 + Div. 2, combined)
CF
2,017
2
256
A Serial Killer
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim. The killer starts with two potential victims on his first day, selects one of these two, kills selected ...
First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer n (1 ≤ n ≤ 1000), the number of days. Next n lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second ...
Output n + 1 lines, the i-th line should contain the two persons from which the killer selects for the i-th murder. The (n + 1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order.
null
In first example, the killer starts with ross and rachel. - After day 1, ross is killed and joey appears. - After day 2, rachel is killed and phoebe appears. - After day 3, phoebe is killed and monica appears. - After day 4, monica is killed and chandler appears.
[{"input": "ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler", "output": "ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler"}, {"input": "icm codeforces\n1\ncodeforces technex", "output": "icm codeforces\nicm technex"}]
900
["brute force", "implementation", "strings"]
57
[{"input": "ross rachel\r\n4\r\nross joey\r\nrachel phoebe\r\nphoebe monica\r\nmonica chandler\r\n", "output": "ross rachel\r\njoey rachel\r\njoey phoebe\r\njoey monica\r\njoey chandler\r\n"}, {"input": "icm codeforces\r\n1\r\ncodeforces technex\r\n", "output": "icm codeforces\r\nicm technex\r\n"}, {"input": "a b\r\n3\...
false
stdio
import sys def main(): input_path, output_path, submission_path = sys.argv[1:4] with open(output_path, 'r') as f: correct_lines = [line.strip() for line in f.readlines()] with open(submission_path, 'r') as f: submission_lines = [line.strip() for line in f.readlines()] if ...
true
776/A
776
A
Python 3
TESTS
4
62
0
113036513
a = list(map(str, input().split())) n = int(input()) print(*a) for i in range(n): died, replaced = map(str, input().split()) a = [a1.replace(died, replaced) for a1 in a] print(*a)
57
46
0
150217031
a = list(input().split()) n = int(input()) print(a[0], a[1]) for _ in range(n): a1, a2 = input().split() if a1 == a[0]: a[0] = a2 if a1 == a[1]: a[1] = a2 print(a[0], a[1])
ICM Technex 2017 and Codeforces Round 400 (Div. 1 + Div. 2, combined)
CF
2,017
2
256
A Serial Killer
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim. The killer starts with two potential victims on his first day, selects one of these two, kills selected ...
First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer n (1 ≤ n ≤ 1000), the number of days. Next n lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second ...
Output n + 1 lines, the i-th line should contain the two persons from which the killer selects for the i-th murder. The (n + 1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order.
null
In first example, the killer starts with ross and rachel. - After day 1, ross is killed and joey appears. - After day 2, rachel is killed and phoebe appears. - After day 3, phoebe is killed and monica appears. - After day 4, monica is killed and chandler appears.
[{"input": "ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler", "output": "ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler"}, {"input": "icm codeforces\n1\ncodeforces technex", "output": "icm codeforces\nicm technex"}]
900
["brute force", "implementation", "strings"]
57
[{"input": "ross rachel\r\n4\r\nross joey\r\nrachel phoebe\r\nphoebe monica\r\nmonica chandler\r\n", "output": "ross rachel\r\njoey rachel\r\njoey phoebe\r\njoey monica\r\njoey chandler\r\n"}, {"input": "icm codeforces\r\n1\r\ncodeforces technex\r\n", "output": "icm codeforces\r\nicm technex\r\n"}, {"input": "a b\r\n3\...
false
stdio
import sys def main(): input_path, output_path, submission_path = sys.argv[1:4] with open(output_path, 'r') as f: correct_lines = [line.strip() for line in f.readlines()] with open(submission_path, 'r') as f: submission_lines = [line.strip() for line in f.readlines()] if ...
true
776/A
776
A
Python 3
TESTS
4
93
307,200
93124350
s = input() n = int(input()) killed = [0]*n for i in range(n): killed[i] = input().split() print(s) for i in range(n): s = s.replace(killed[i][0], killed[i][1]) print(s)
57
46
0
154658931
import sys input = sys.stdin.readline w = set(input().split()) print(*w) for _ in range(int(input())): s = input().split() w = set(s) ^ w print(*w)
ICM Technex 2017 and Codeforces Round 400 (Div. 1 + Div. 2, combined)
CF
2,017
2
256
A Serial Killer
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim. The killer starts with two potential victims on his first day, selects one of these two, kills selected ...
First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer n (1 ≤ n ≤ 1000), the number of days. Next n lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second ...
Output n + 1 lines, the i-th line should contain the two persons from which the killer selects for the i-th murder. The (n + 1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order.
null
In first example, the killer starts with ross and rachel. - After day 1, ross is killed and joey appears. - After day 2, rachel is killed and phoebe appears. - After day 3, phoebe is killed and monica appears. - After day 4, monica is killed and chandler appears.
[{"input": "ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler", "output": "ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler"}, {"input": "icm codeforces\n1\ncodeforces technex", "output": "icm codeforces\nicm technex"}]
900
["brute force", "implementation", "strings"]
57
[{"input": "ross rachel\r\n4\r\nross joey\r\nrachel phoebe\r\nphoebe monica\r\nmonica chandler\r\n", "output": "ross rachel\r\njoey rachel\r\njoey phoebe\r\njoey monica\r\njoey chandler\r\n"}, {"input": "icm codeforces\r\n1\r\ncodeforces technex\r\n", "output": "icm codeforces\r\nicm technex\r\n"}, {"input": "a b\r\n3\...
false
stdio
import sys def main(): input_path, output_path, submission_path = sys.argv[1:4] with open(output_path, 'r') as f: correct_lines = [line.strip() for line in f.readlines()] with open(submission_path, 'r') as f: submission_lines = [line.strip() for line in f.readlines()] if ...
true
280/B
280
B
Python 3
TESTS
3
78
7,065,600
38004537
n=int(input()) def CalculateMaxXor(arr,n): MaxXor=arr[0]^arr[1] stack=[] for i in range(0,n): while stack and stack[-1]<arr[i]: stack.pop() stack.append(arr[i]) if len(stack)>=2: MaxXor=max(MaxXor,stack[-1]^stack[-2]) return MaxXor print(CalculateMaxXor(list(map(int,input().split())),n))
56
93
15,360,000
200601294
def mp(): return map(int, input().split()) n = input() a = [*mp()] s = [] z = 0 for i in a: while s: x = s[-1] z = max(z, x ^ i) if x > i: break s.pop() s.append(i) print(z)
Codeforces Round 172 (Div. 1)
CF
2,013
1
256
Maximum Xor Secondary
Bike loves looking for the second maximum element in the sequence. The second maximum element in the sequence of distinct numbers x1, x2, ..., xk (k > 1) is such maximum element xj, that the following inequality holds: $$x_j \neq \max_{i=1}^{k} x_i$$. The lucky number of the sequence of distinct positive integers x1, ...
The first line contains integer n (1 < n ≤ 105). The second line contains n distinct integers s1, s2, ..., sn (1 ≤ si ≤ 109).
Print a single integer — the maximum lucky number among all lucky numbers of sequences s[l..r].
null
For the first sample you can choose s[4..5] = {4, 3} and its lucky number is (4 xor 3) = 7. You can also choose s[1..2]. For the second sample you must choose s[2..5] = {8, 3, 5, 7}.
[{"input": "5\n5 2 1 4 3", "output": "7"}, {"input": "5\n9 8 3 5 7", "output": "15"}]
1,800
["data structures", "implementation", "two pointers"]
56
[{"input": "5\r\n5 2 1 4 3\r\n", "output": "7\r\n"}, {"input": "5\r\n9 8 3 5 7\r\n", "output": "15\r\n"}, {"input": "10\r\n76969694 71698884 32888447 31877010 65564584 87864180 7850891 1505323 17879621 15722446\r\n", "output": "128869996\r\n"}, {"input": "10\r\n4547989 39261040 94929326 38131456 26174500 7152864 712958...
false
stdio
null
true
280/B
280
B
Python 3
TESTS
3
31
0
148668012
def check(arr): l=[] l.append(arr[0]) i=1 mx=0 while i<len(arr): while len(l)>1 and l[-1]<=arr[i]: l.pop() l.append(arr[i]) s=l[-1]^l[-2] if s>mx: mx=s i+=1 return mx n=int(input()) arr=list(map(int,input().split())) print(check(arr))
56
93
15,872,000
167073112
import sys input = sys.stdin.readline n = int(input()) s = list(map(int, input().split())) ans = 0 st = [] # every v can be the second max, max on left or right for v in s: # decreasing stack # st[-1] second max, v max(max on right) while st and st[-1] < v: ans = max(st.pop() ^ v, ans) # v se...
Codeforces Round 172 (Div. 1)
CF
2,013
1
256
Maximum Xor Secondary
Bike loves looking for the second maximum element in the sequence. The second maximum element in the sequence of distinct numbers x1, x2, ..., xk (k > 1) is such maximum element xj, that the following inequality holds: $$x_j \neq \max_{i=1}^{k} x_i$$. The lucky number of the sequence of distinct positive integers x1, ...
The first line contains integer n (1 < n ≤ 105). The second line contains n distinct integers s1, s2, ..., sn (1 ≤ si ≤ 109).
Print a single integer — the maximum lucky number among all lucky numbers of sequences s[l..r].
null
For the first sample you can choose s[4..5] = {4, 3} and its lucky number is (4 xor 3) = 7. You can also choose s[1..2]. For the second sample you must choose s[2..5] = {8, 3, 5, 7}.
[{"input": "5\n5 2 1 4 3", "output": "7"}, {"input": "5\n9 8 3 5 7", "output": "15"}]
1,800
["data structures", "implementation", "two pointers"]
56
[{"input": "5\r\n5 2 1 4 3\r\n", "output": "7\r\n"}, {"input": "5\r\n9 8 3 5 7\r\n", "output": "15\r\n"}, {"input": "10\r\n76969694 71698884 32888447 31877010 65564584 87864180 7850891 1505323 17879621 15722446\r\n", "output": "128869996\r\n"}, {"input": "10\r\n4547989 39261040 94929326 38131456 26174500 7152864 712958...
false
stdio
null
true
776/A
776
A
Python 3
TESTS
4
61
0
29606665
a=input() print(a) for i in range(int(input())): x,y=input().split() a=a.replace(x,y) print(a)
57
46
0
164733818
a,b = list(input().split()) n = int(input()) print(a, b) for i in range(n): c,d = list(input().split()) if a==c: a=d elif b==c: b=d print(a,b)
ICM Technex 2017 and Codeforces Round 400 (Div. 1 + Div. 2, combined)
CF
2,017
2
256
A Serial Killer
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim. The killer starts with two potential victims on his first day, selects one of these two, kills selected ...
First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer n (1 ≤ n ≤ 1000), the number of days. Next n lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second ...
Output n + 1 lines, the i-th line should contain the two persons from which the killer selects for the i-th murder. The (n + 1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order.
null
In first example, the killer starts with ross and rachel. - After day 1, ross is killed and joey appears. - After day 2, rachel is killed and phoebe appears. - After day 3, phoebe is killed and monica appears. - After day 4, monica is killed and chandler appears.
[{"input": "ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler", "output": "ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler"}, {"input": "icm codeforces\n1\ncodeforces technex", "output": "icm codeforces\nicm technex"}]
900
["brute force", "implementation", "strings"]
57
[{"input": "ross rachel\r\n4\r\nross joey\r\nrachel phoebe\r\nphoebe monica\r\nmonica chandler\r\n", "output": "ross rachel\r\njoey rachel\r\njoey phoebe\r\njoey monica\r\njoey chandler\r\n"}, {"input": "icm codeforces\r\n1\r\ncodeforces technex\r\n", "output": "icm codeforces\r\nicm technex\r\n"}, {"input": "a b\r\n3\...
false
stdio
import sys def main(): input_path, output_path, submission_path = sys.argv[1:4] with open(output_path, 'r') as f: correct_lines = [line.strip() for line in f.readlines()] with open(submission_path, 'r') as f: submission_lines = [line.strip() for line in f.readlines()] if ...
true
776/A
776
A
PyPy 3-64
TESTS
4
77
3,481,600
206252672
ans = [] fn = input() ans.append(fn) for i in range(int(input())): kd,new = input().split(" ") if kd == fn.split(" ")[0] or kd == fn.split(" ")[1]: fn = fn.replace(kd,new) ans.append(fn) for i in ans: print(i)
57
46
0
167957368
if __name__ == '__main__': f, s = input().split(' ') print(f + ' ' + s) n = int(input()) for i in range(n): ft, st = input().split(' ') if f == ft: f = st else: s = st print(f + ' ' + s)
ICM Technex 2017 and Codeforces Round 400 (Div. 1 + Div. 2, combined)
CF
2,017
2
256
A Serial Killer
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim. The killer starts with two potential victims on his first day, selects one of these two, kills selected ...
First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer n (1 ≤ n ≤ 1000), the number of days. Next n lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second ...
Output n + 1 lines, the i-th line should contain the two persons from which the killer selects for the i-th murder. The (n + 1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order.
null
In first example, the killer starts with ross and rachel. - After day 1, ross is killed and joey appears. - After day 2, rachel is killed and phoebe appears. - After day 3, phoebe is killed and monica appears. - After day 4, monica is killed and chandler appears.
[{"input": "ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler", "output": "ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler"}, {"input": "icm codeforces\n1\ncodeforces technex", "output": "icm codeforces\nicm technex"}]
900
["brute force", "implementation", "strings"]
57
[{"input": "ross rachel\r\n4\r\nross joey\r\nrachel phoebe\r\nphoebe monica\r\nmonica chandler\r\n", "output": "ross rachel\r\njoey rachel\r\njoey phoebe\r\njoey monica\r\njoey chandler\r\n"}, {"input": "icm codeforces\r\n1\r\ncodeforces technex\r\n", "output": "icm codeforces\r\nicm technex\r\n"}, {"input": "a b\r\n3\...
false
stdio
import sys def main(): input_path, output_path, submission_path = sys.argv[1:4] with open(output_path, 'r') as f: correct_lines = [line.strip() for line in f.readlines()] with open(submission_path, 'r') as f: submission_lines = [line.strip() for line in f.readlines()] if ...
true
776/A
776
A
Python 3
TESTS
4
93
7,168,000
87838095
s = input() day = int(input()) victim = [s] while day > 0 : k = input().split() v = victim[-1].replace(k[0],k[-1]) victim.append(v) day -= 1 for y in victim: print (y)
57
46
0
168855018
a={*input().split()} print(*a) for _ in[0]*int(input()): b,c=input().split() a=a-{b}|{c} print(*a)
ICM Technex 2017 and Codeforces Round 400 (Div. 1 + Div. 2, combined)
CF
2,017
2
256
A Serial Killer
Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim. The killer starts with two potential victims on his first day, selects one of these two, kills selected ...
First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer n (1 ≤ n ≤ 1000), the number of days. Next n lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second ...
Output n + 1 lines, the i-th line should contain the two persons from which the killer selects for the i-th murder. The (n + 1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order.
null
In first example, the killer starts with ross and rachel. - After day 1, ross is killed and joey appears. - After day 2, rachel is killed and phoebe appears. - After day 3, phoebe is killed and monica appears. - After day 4, monica is killed and chandler appears.
[{"input": "ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler", "output": "ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler"}, {"input": "icm codeforces\n1\ncodeforces technex", "output": "icm codeforces\nicm technex"}]
900
["brute force", "implementation", "strings"]
57
[{"input": "ross rachel\r\n4\r\nross joey\r\nrachel phoebe\r\nphoebe monica\r\nmonica chandler\r\n", "output": "ross rachel\r\njoey rachel\r\njoey phoebe\r\njoey monica\r\njoey chandler\r\n"}, {"input": "icm codeforces\r\n1\r\ncodeforces technex\r\n", "output": "icm codeforces\r\nicm technex\r\n"}, {"input": "a b\r\n3\...
false
stdio
import sys def main(): input_path, output_path, submission_path = sys.argv[1:4] with open(output_path, 'r') as f: correct_lines = [line.strip() for line in f.readlines()] with open(submission_path, 'r') as f: submission_lines = [line.strip() for line in f.readlines()] if ...
true
280/B
280
B
Python 3
TESTS
3
109
409,600
70600445
#!/usr/bin/env python # coding: utf-8 # In[2]: from collections import deque stack=deque() n=int(input()) a=list(map(int,input().split())) res=a[0]^a[1] l=0 for i in range(n): while stack and stack[-1]<a[i]: stack.pop() l-=1 stack.append(a[i]) l+=1 if l>1: res=...
56
93
16,281,600
167104502
import sys input = sys.stdin.readline n = int(input()) s = list(map(int, input().split())) stack, res = [], 0 for i in range(n): while stack and stack[-1] < s[i]: res = max(res, stack[-1] ^ s[i]) stack.pop() stack.append(s[i]) if len(stack) > 1: res = max(res, stack[-2] ^ stack[-1]) ...
Codeforces Round 172 (Div. 1)
CF
2,013
1
256
Maximum Xor Secondary
Bike loves looking for the second maximum element in the sequence. The second maximum element in the sequence of distinct numbers x1, x2, ..., xk (k > 1) is such maximum element xj, that the following inequality holds: $$x_j \neq \max_{i=1}^{k} x_i$$. The lucky number of the sequence of distinct positive integers x1, ...
The first line contains integer n (1 < n ≤ 105). The second line contains n distinct integers s1, s2, ..., sn (1 ≤ si ≤ 109).
Print a single integer — the maximum lucky number among all lucky numbers of sequences s[l..r].
null
For the first sample you can choose s[4..5] = {4, 3} and its lucky number is (4 xor 3) = 7. You can also choose s[1..2]. For the second sample you must choose s[2..5] = {8, 3, 5, 7}.
[{"input": "5\n5 2 1 4 3", "output": "7"}, {"input": "5\n9 8 3 5 7", "output": "15"}]
1,800
["data structures", "implementation", "two pointers"]
56
[{"input": "5\r\n5 2 1 4 3\r\n", "output": "7\r\n"}, {"input": "5\r\n9 8 3 5 7\r\n", "output": "15\r\n"}, {"input": "10\r\n76969694 71698884 32888447 31877010 65564584 87864180 7850891 1505323 17879621 15722446\r\n", "output": "128869996\r\n"}, {"input": "10\r\n4547989 39261040 94929326 38131456 26174500 7152864 712958...
false
stdio
null
true
280/B
280
B
Python 3
TESTS
3
46
0
148669691
def solve(v: list): ans = v[0]^v[1] st = [] n = len(v) for i in range(n): while len(st) > 0 and st[-1] < v[i]: st.pop(-1) st.append(v[i]) if len(st) >= 2: ans = max(ans, st[-1]^st[-2]) return ans if __name__ == '__main__': n = int(input()) ...
56
108
14,745,600
167086536
n = int(input()) a = list(map(int, input().split())) stack = [] res = 0 for i, v in enumerate(a): while stack and stack[-1] < v: res = max(res, stack.pop() ^ v) if stack: res = max(res, stack[-1] ^ v) stack.append(v) print(res)
Codeforces Round 172 (Div. 1)
CF
2,013
1
256
Maximum Xor Secondary
Bike loves looking for the second maximum element in the sequence. The second maximum element in the sequence of distinct numbers x1, x2, ..., xk (k > 1) is such maximum element xj, that the following inequality holds: $$x_j \neq \max_{i=1}^{k} x_i$$. The lucky number of the sequence of distinct positive integers x1, ...
The first line contains integer n (1 < n ≤ 105). The second line contains n distinct integers s1, s2, ..., sn (1 ≤ si ≤ 109).
Print a single integer — the maximum lucky number among all lucky numbers of sequences s[l..r].
null
For the first sample you can choose s[4..5] = {4, 3} and its lucky number is (4 xor 3) = 7. You can also choose s[1..2]. For the second sample you must choose s[2..5] = {8, 3, 5, 7}.
[{"input": "5\n5 2 1 4 3", "output": "7"}, {"input": "5\n9 8 3 5 7", "output": "15"}]
1,800
["data structures", "implementation", "two pointers"]
56
[{"input": "5\r\n5 2 1 4 3\r\n", "output": "7\r\n"}, {"input": "5\r\n9 8 3 5 7\r\n", "output": "15\r\n"}, {"input": "10\r\n76969694 71698884 32888447 31877010 65564584 87864180 7850891 1505323 17879621 15722446\r\n", "output": "128869996\r\n"}, {"input": "10\r\n4547989 39261040 94929326 38131456 26174500 7152864 712958...
false
stdio
null
true
282/B
282
B
PyPy 3-64
TESTS
2
92
0
228546199
n = int(input()) A,G = 0,0 s = "" for i in range(n): a,b = map(int,input().split()) if(A==G): if(a<b): A+=a s+="A" else: G+=b s+="G" elif(A-G>500): G+=b s+="G" elif(G-A>500): A+=a s+="A" else: if(...
54
1,652
10,752,000
229981075
import sys n = int(sys.stdin.readline()) d = 0 for _ in range(n): a, g = map(int, sys.stdin.readline().split()) if d + a <= 500: d += a print('A', end='') else: d -= g print('G', end='')# 1698396157.2401366
Codeforces Round 173 (Div. 2)
CF
2,013
5
256
Painting Eggs
The Bitlandians are quite weird people. They have very peculiar customs. As is customary, Uncle J. wants to have n eggs painted for Bitruz (an ancient Bitland festival). He has asked G. and A. to do the work. The kids are excited because just as is customary, they're going to be paid for the job! Overall uncle J. ha...
The first line contains integer n (1 ≤ n ≤ 106) — the number of eggs. Next n lines contain two integers ai and gi each (0 ≤ ai, gi ≤ 1000; ai + gi = 1000): ai is the price said by A. for the i-th egg and gi is the price said by G. for the i-th egg.
If it is impossible to assign the painting, print "-1" (without quotes). Otherwise print a string, consisting of n letters "G" and "A". The i-th letter of this string should represent the child who will get the i-th egg in the required distribution. Letter "A" represents A. and letter "G" represents G. If we denote th...
null
null
[{"input": "2\n1 999\n999 1", "output": "AG"}, {"input": "3\n400 600\n400 600\n400 600", "output": "AGA"}]
1,500
["greedy", "math"]
54
[{"input": "2\r\n1 999\r\n999 1\r\n", "output": "AG\r\n"}, {"input": "3\r\n400 600\r\n400 600\r\n400 600\r\n", "output": "AGA\r\n"}, {"input": "2\r\n500 500\r\n500 500\r\n", "output": "AG\r\n"}, {"input": "1\r\n1 999\r\n", "output": "A\r\n"}, {"input": "10\r\n1 999\r\n1 999\r\n1 999\r\n1 999\r\n1 999\r\n1 999\r\n1 999\...
false
stdio
import sys def main(input_path, output_path, submission_path): # Read input data with open(input_path) as f: n = int(f.readline()) eggs = [tuple(map(int, line.split())) for line in f] # Read reference and submission outputs with open(output_path) as f: ref_output = f.read()...
true
282/B
282
B
Python 3
TESTS
2
60
0
228749425
t = int(input()) sa = 0 sg = 0 ans = "" for i in range(t): a, g = map(int, input().split()) if a < g and abs(sa + a - sg) <= 500: sa = sa + a ans = ans + 'A' else: sg = sg + g ans = ans + 'G' print(ans)
54
3,898
156,057,600
229604446
n = int(input()) eggs = [] for i in range(n): a, g = map(int, input().split()) eggs.append((a, g)) result = [] total_a_payment = 0 total_g_payment = 0 for a, g in eggs: if total_a_payment + a - total_g_payment <= 500: result.append('A') total_a_payment += a else: result.appen...
Codeforces Round 173 (Div. 2)
CF
2,013
5
256
Painting Eggs
The Bitlandians are quite weird people. They have very peculiar customs. As is customary, Uncle J. wants to have n eggs painted for Bitruz (an ancient Bitland festival). He has asked G. and A. to do the work. The kids are excited because just as is customary, they're going to be paid for the job! Overall uncle J. ha...
The first line contains integer n (1 ≤ n ≤ 106) — the number of eggs. Next n lines contain two integers ai and gi each (0 ≤ ai, gi ≤ 1000; ai + gi = 1000): ai is the price said by A. for the i-th egg and gi is the price said by G. for the i-th egg.
If it is impossible to assign the painting, print "-1" (without quotes). Otherwise print a string, consisting of n letters "G" and "A". The i-th letter of this string should represent the child who will get the i-th egg in the required distribution. Letter "A" represents A. and letter "G" represents G. If we denote th...
null
null
[{"input": "2\n1 999\n999 1", "output": "AG"}, {"input": "3\n400 600\n400 600\n400 600", "output": "AGA"}]
1,500
["greedy", "math"]
54
[{"input": "2\r\n1 999\r\n999 1\r\n", "output": "AG\r\n"}, {"input": "3\r\n400 600\r\n400 600\r\n400 600\r\n", "output": "AGA\r\n"}, {"input": "2\r\n500 500\r\n500 500\r\n", "output": "AG\r\n"}, {"input": "1\r\n1 999\r\n", "output": "A\r\n"}, {"input": "10\r\n1 999\r\n1 999\r\n1 999\r\n1 999\r\n1 999\r\n1 999\r\n1 999\...
false
stdio
import sys def main(input_path, output_path, submission_path): # Read input data with open(input_path) as f: n = int(f.readline()) eggs = [tuple(map(int, line.split())) for line in f] # Read reference and submission outputs with open(output_path) as f: ref_output = f.read()...
true
469/B
469
B
Python 3
TESTS
2
31
0
225074152
p, q, l, r = map(int, input().split()) line_x = [] while p: a, b = map(int, input().split()) line_x.append([a, b]) p -= 1 line_z = [] while q: a, b = map(int, input().split()) line_z.append([a, b]) q -= 1 n_line = [] for i in range(len(line_x)): for j in range(len(li...
31
62
0
7875077
def inter(A, B, t): for i in B: if (i + t) in A: return True return False p, q, r, l = map(int, input().split()) X = set() Z = set() for i in range(p): b, e = map(int, input().split()) for i in range(b, e + 1): Z.add(i) for i in range(q): b, e = map(int, input().split()...
Codeforces Round 268 (Div. 2)
CF
2,014
1
256
Chat Online
Little X and Little Z are good friends. They always chat online. But both of them have schedules. Little Z has fixed schedule. He always online at any moment of time between a1 and b1, between a2 and b2, ..., between ap and bp (all borders inclusive). But the schedule of Little X is quite strange, it depends on the ti...
The first line contains four space-separated integers p, q, l, r (1 ≤ p, q ≤ 50; 0 ≤ l ≤ r ≤ 1000). Each of the next p lines contains two space-separated integers ai, bi (0 ≤ ai < bi ≤ 1000). Each of the next q lines contains two space-separated integers cj, dj (0 ≤ cj < dj ≤ 1000). It's guaranteed that bi < ai + 1 ...
Output a single integer — the number of moments of time from the segment [l, r] which suit for online conversation.
null
null
[{"input": "1 1 0 4\n2 3\n0 1", "output": "3"}, {"input": "2 3 0 20\n15 17\n23 26\n1 4\n7 11\n15 17", "output": "20"}]
1,300
["implementation"]
31
[{"input": "1 1 0 4\r\n2 3\r\n0 1\r\n", "output": "3\r\n"}, {"input": "2 3 0 20\r\n15 17\r\n23 26\r\n1 4\r\n7 11\r\n15 17\r\n", "output": "20\r\n"}, {"input": "5 2 27 452\r\n148 154\r\n421 427\r\n462 470\r\n777 786\r\n969 978\r\n245 247\r\n313 322\r\n", "output": "54\r\n"}, {"input": "3 6 25 785\r\n273 275\r\n391 397\r...
false
stdio
null
true
774/F
774
F
Python 3
TESTS
2
46
5,529,600
26153159
n = int(input()) a = list(map(int, input().split())) ans = 100000 min = 10000000000 if ((n % 7) == 0): for i in range(6, n, 7): if a[i] < min: ans = i min = a[i] else: i = 7 % n while True: if a[i] < min: ans = i min = a[i] i = (i + 7) ...
88
155
7,680,000
173867248
import sys def Min(x, y): if x > y: return y else: return x def Gcd(x, y): if x == 0: return y else: return Gcd(y % x, x) def Lcm(x, y): return x * y // Gcd(x, y) n = int(input()) a = [int(i) for i in input().split()] d = [int(0) for i in range(0, n)] ok = 0...
VK Cup 2017 - Wild Card Round 1
ICPC
2,017
3
256
Pens And Days Of Week
Stepan has n pens. Every day he uses them, and on the i-th day he uses the pen number i. On the (n + 1)-th day again he uses the pen number 1, on the (n + 2)-th — he uses the pen number 2 and so on. On every working day (from Monday to Saturday, inclusive) Stepan spends exactly 1 milliliter of ink of the pen he uses t...
The first line contains the integer n (1 ≤ n ≤ 50 000) — the number of pens Stepan has. The second line contains the sequence of integers a1, a2, ..., an (1 ≤ ai ≤ 109), where ai is equal to the number of milliliters of ink which the pen number i currently has.
Print the index of the pen which will run out of ink before all (it means that there will be no ink left in it), if Stepan will use pens according to the conditions described above. Pens are numbered in the order they are given in input data. The numeration begins from one. Note that the answer is always unambiguous,...
null
In the first test Stepan uses ink of pens as follows: 1. on the day number 1 (Monday) Stepan will use the pen number 1, after that there will be 2 milliliters of ink in it; 2. on the day number 2 (Tuesday) Stepan will use the pen number 2, after that there will be 2 milliliters of ink in it; 3. on the day number 3 (We...
[{"input": "3\n3 3 3", "output": "2"}, {"input": "5\n5 4 5 4 4", "output": "5"}]
2,700
["*special", "binary search", "number theory"]
88
[{"input": "3\r\n3 3 3\r\n", "output": "2\r\n"}, {"input": "5\r\n5 4 5 4 4\r\n", "output": "5\r\n"}, {"input": "28\r\n2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033\r\n", "output": "1\r\n"}, {"input": "7\r\n10 10 10 10 10 10 10...
false
stdio
null
true
716/A
716
A
PyPy 3-64
TESTS
54
170
12,595,200
153783613
n, c = [int(i) for i in input().split()] arr = [int(i) for i in input().split()] count = 0 a = 0 flag = False for i in range(1,n): flag = True b = arr[i] if abs(a-b)<=c: count += 1 else: count = 0 a = arr[i] print(count+1)
81
77
13,209,600
204541880
n,c = map(int,input().split()) a = list(map(int,input().split())) m = 0 for i in range(1,len(a)): if((a[-i] - a[-(i+1)]) <= c): m = m+1 continue else: break print(m+1)
Codeforces Round 372 (Div. 2)
CF
2,016
2
256
Crazy Computer
ZS the Coder is coding on a crazy computer. If you don't type in a word for a c consecutive seconds, everything you typed disappear! More formally, if you typed a word at second a and then the next word at second b, then if b - a ≤ c, just the new word is appended to other words on the screen. If b - a > c, then every...
The first line contains two integers n and c (1 ≤ n ≤ 100 000, 1 ≤ c ≤ 109) — the number of words ZS the Coder typed and the crazy computer delay respectively. The next line contains n integers t1, t2, ..., tn (1 ≤ t1 < t2 < ... < tn ≤ 109), where ti denotes the second when ZS the Coder typed the i-th word.
Print a single positive integer, the number of words that remain on the screen after all n words was typed, in other words, at the second tn.
null
The first sample is already explained in the problem statement. For the second sample, after typing the first word at the second 1, it disappears because the next word is typed at the second 3 and 3 - 1 > 1. Similarly, only 1 word will remain at the second 9. Then, a word is typed at the second 10, so there will be tw...
[{"input": "6 5\n1 3 8 14 19 20", "output": "3"}, {"input": "6 1\n1 3 5 7 9 10", "output": "2"}]
800
["implementation"]
81
[{"input": "6 5\r\n1 3 8 14 19 20\r\n", "output": "3"}, {"input": "6 1\r\n1 3 5 7 9 10\r\n", "output": "2"}, {"input": "1 1\r\n1000000000\r\n", "output": "1"}, {"input": "5 5\r\n1 7 12 13 14\r\n", "output": "4"}, {"input": "2 1000000000\r\n1 1000000000\r\n", "output": "2"}, {"input": "3 5\r\n1 10 20\r\n", "output": "1"...
false
stdio
null
true
964/B
964
B
Python 3
TESTS
12
109
0
45684411
n, a, b, c, t = map(int, input().split()) y = list(map(int, input().split()[:n])) su, r = 0, 0 if c - b > 0: for i in range(1, n): su += c * i for i in range(n - 1): r += a - (b * y[i]) print(su + r + y[-1]) else: su = n * a print(su)
60
62
0
178951013
R=lambda:map(int,input().split()) n,A,B,C,T=R() print(sum(A+max(0,C-B)*(T-t)for t in R()))
Tinkoff Internship Warmup Round 2018 and Codeforces Round 475 (Div. 2)
CF
2,018
1
256
Messages
There are n incoming messages for Vasya. The i-th message is going to be received after ti minutes. Each message has a cost, which equals to A initially. After being received, the cost of a message decreases by B each minute (it can become negative). Vasya can read any message after receiving it at any moment of time. ...
The first line contains five integers n, A, B, C and T (1 ≤ n, A, B, C, T ≤ 1000). The second string contains n integers ti (1 ≤ ti ≤ T).
Output one integer  — the answer to the problem.
null
In the first sample the messages must be read immediately after receiving, Vasya receives A points for each message, n·A = 20 in total. In the second sample the messages can be read at any integer moment. In the third sample messages must be read at the moment T. This way Vasya has 1, 2, 3, 4 and 0 unread messages at...
[{"input": "4 5 5 3 5\n1 5 5 4", "output": "20"}, {"input": "5 3 1 1 3\n2 2 2 1 1", "output": "15"}, {"input": "5 5 3 4 5\n1 2 3 4 5", "output": "35"}]
1,300
["math"]
60
[{"input": "4 5 5 3 5\r\n1 5 5 4\r\n", "output": "20\r\n"}, {"input": "5 3 1 1 3\r\n2 2 2 1 1\r\n", "output": "15\r\n"}, {"input": "5 5 3 4 5\r\n1 2 3 4 5\r\n", "output": "35\r\n"}, {"input": "1 6 4 3 9\r\n2\r\n", "output": "6\r\n"}, {"input": "10 9 7 5 3\r\n3 3 3 3 2 3 2 2 3 3\r\n", "output": "90\r\n"}, {"input": "44 ...
false
stdio
null
true
713/C
713
C
Python 3
TESTS
4
46
4,505,600
134049564
import heapq def solve(arr): sortH = [] result = 0 inc = 0 heapq.heappush(sortH, arr[0]) for i in range(1, len(arr)): inc += 1 val = sortH[-1] + inc if arr[i] <= val: result += val - arr[i] #result += 1 heapq.heappop(sortH) heapq.heappush(sortH, arr[i] - inc) heapq.heappush(sortH, arr[i] -...
57
140
204,800
233257658
import heapq n = int(input()) d = list(map(int,input().split())) pq = [-d[0]] heapq.heapify(pq) ans = 0 for i in range(1,n): temp = i - d[i] heapq.heappush(pq,temp) if heapq.nsmallest(1,pq)[0] < temp: ans += temp - heapq.nsmallest(1,pq)[0] heapq.heappushpop(pq,temp) print(ans)
Codeforces Round 371 (Div. 1)
CF
2,016
5
256
Sonya and Problem Wihtout a Legend
Sonya was unable to think of a story for this problem, so here comes the formal description. You are given the array containing n positive integers. At one turn you can pick any element and increase or decrease it by 1. The goal is the make the array strictly increasing by making the minimum possible number of operati...
The first line of the input contains a single integer n (1 ≤ n ≤ 3000) — the length of the array. Next line contains n integer ai (1 ≤ ai ≤ 109).
Print the minimum number of operation required to make the array strictly increasing.
null
In the first sample, the array is going to look as follows: 2 3 5 6 7 9 11 |2 - 2| + |1 - 3| + |5 - 5| + |11 - 6| + |5 - 7| + |9 - 9| + |11 - 11| = 9 And for the second sample: 1 2 3 4 5 |5 - 1| + |4 - 2| + |3 - 3| + |2 - 4| + |1 - 5| = 12
[{"input": "7\n2 1 5 11 5 9 11", "output": "9"}, {"input": "5\n5 4 3 2 1", "output": "12"}]
2,300
["dp", "sortings"]
57
[{"input": "7\r\n2 1 5 11 5 9 11\r\n", "output": "9\r\n"}, {"input": "5\r\n5 4 3 2 1\r\n", "output": "12\r\n"}, {"input": "2\r\n1 1000\r\n", "output": "0\r\n"}, {"input": "2\r\n1000 1\r\n", "output": "1000\r\n"}, {"input": "5\r\n100 80 60 70 90\r\n", "output": "54\r\n"}, {"input": "10\r\n10 16 17 11 1213 1216 1216 1209...
false
stdio
null
true
964/B
964
B
Python 3
TESTS
12
93
7,065,600
37403351
n,a,b,c,t=map(int,input().split()) l=list(map(int,input().split())) if (c<=b): print(n*a) else: s=0 for i in l: s+=(c-b)*(n-i) print(s+n*a)
60
62
0
228224082
n, A, B, C, T = map(int, input().split()) t = [int(i) for i in input().split()] score = 0 for time in t: if C * (T - time) + A - B * (T - time) > A: score += C * (T - time) + A - B * (T - time) else: score += A print(score)
Tinkoff Internship Warmup Round 2018 and Codeforces Round 475 (Div. 2)
CF
2,018
1
256
Messages
There are n incoming messages for Vasya. The i-th message is going to be received after ti minutes. Each message has a cost, which equals to A initially. After being received, the cost of a message decreases by B each minute (it can become negative). Vasya can read any message after receiving it at any moment of time. ...
The first line contains five integers n, A, B, C and T (1 ≤ n, A, B, C, T ≤ 1000). The second string contains n integers ti (1 ≤ ti ≤ T).
Output one integer  — the answer to the problem.
null
In the first sample the messages must be read immediately after receiving, Vasya receives A points for each message, n·A = 20 in total. In the second sample the messages can be read at any integer moment. In the third sample messages must be read at the moment T. This way Vasya has 1, 2, 3, 4 and 0 unread messages at...
[{"input": "4 5 5 3 5\n1 5 5 4", "output": "20"}, {"input": "5 3 1 1 3\n2 2 2 1 1", "output": "15"}, {"input": "5 5 3 4 5\n1 2 3 4 5", "output": "35"}]
1,300
["math"]
60
[{"input": "4 5 5 3 5\r\n1 5 5 4\r\n", "output": "20\r\n"}, {"input": "5 3 1 1 3\r\n2 2 2 1 1\r\n", "output": "15\r\n"}, {"input": "5 5 3 4 5\r\n1 2 3 4 5\r\n", "output": "35\r\n"}, {"input": "1 6 4 3 9\r\n2\r\n", "output": "6\r\n"}, {"input": "10 9 7 5 3\r\n3 3 3 3 2 3 2 2 3 3\r\n", "output": "90\r\n"}, {"input": "44 ...
false
stdio
null
true
964/B
964
B
Python 3
TESTS
12
108
0
48377129
n, A, B, C, T = map(int, input().split()) t = list(map(int, input().split())) d = C - B if d < 0: print(n * A) else: num = 0 for i in range(n): num += (C - B) * (n - t[i]) num += A print(num)
60
77
0
164538326
import sys input = sys.stdin.readline n, A, B, C, T = map(int, input().split()) t = [i for i in map(int, input().split()) if i <= T] c = A*len(t) if B >= C: print(c) else: x = C-B for i in t: c += (T-i)*x print(c)
Tinkoff Internship Warmup Round 2018 and Codeforces Round 475 (Div. 2)
CF
2,018
1
256
Messages
There are n incoming messages for Vasya. The i-th message is going to be received after ti minutes. Each message has a cost, which equals to A initially. After being received, the cost of a message decreases by B each minute (it can become negative). Vasya can read any message after receiving it at any moment of time. ...
The first line contains five integers n, A, B, C and T (1 ≤ n, A, B, C, T ≤ 1000). The second string contains n integers ti (1 ≤ ti ≤ T).
Output one integer  — the answer to the problem.
null
In the first sample the messages must be read immediately after receiving, Vasya receives A points for each message, n·A = 20 in total. In the second sample the messages can be read at any integer moment. In the third sample messages must be read at the moment T. This way Vasya has 1, 2, 3, 4 and 0 unread messages at...
[{"input": "4 5 5 3 5\n1 5 5 4", "output": "20"}, {"input": "5 3 1 1 3\n2 2 2 1 1", "output": "15"}, {"input": "5 5 3 4 5\n1 2 3 4 5", "output": "35"}]
1,300
["math"]
60
[{"input": "4 5 5 3 5\r\n1 5 5 4\r\n", "output": "20\r\n"}, {"input": "5 3 1 1 3\r\n2 2 2 1 1\r\n", "output": "15\r\n"}, {"input": "5 5 3 4 5\r\n1 2 3 4 5\r\n", "output": "35\r\n"}, {"input": "1 6 4 3 9\r\n2\r\n", "output": "6\r\n"}, {"input": "10 9 7 5 3\r\n3 3 3 3 2 3 2 2 3 3\r\n", "output": "90\r\n"}, {"input": "44 ...
false
stdio
null
true
370/B
370
B
Python 3
PRETESTS
5
62
0
5370016
import sys f = sys.stdin #f = open("input.txt", "r") n = int(f.readline()) a = f.read().strip().split("\n") players = [[int(k) for k in i.split()[1:]] for i in a] winners = [True for i in range(len(players))] for index, player in enumerate(players): if any(i == player for i in players[index+1:]): winne...
24
62
5,017,600
19912743
n = int(input()) a = [] for i in range(n): li = list(map(int, input().split())) a.append(set(li[1:])) for i in range(n): s = a[i] joke = 1 for j in range(n): t = a[j] if t <= s and i != j: joke = 0 break print("YES" * joke + "NO" * (1 - joke))
Codeforces Round 217 (Div. 2)
CF
2,013
1
256
Berland Bingo
Lately, a national version of a bingo game has become very popular in Berland. There are n players playing the game, each player has a card with numbers. The numbers on each card are distinct, but distinct cards can have equal numbers. The card of the i-th player contains mi numbers. During the game the host takes num...
The first line of the input contains integer n (1 ≤ n ≤ 100) — the number of the players. Then follow n lines, each line describes a player's card. The line that describes a card starts from integer mi (1 ≤ mi ≤ 100) that shows how many numbers the i-th player's card has. Then follows a sequence of integers ai, 1, ai, ...
Print n lines, the i-th line must contain word "YES" (without the quotes), if the i-th player can win, and "NO" (without the quotes) otherwise.
null
null
[{"input": "3\n1 1\n3 2 4 1\n2 10 11", "output": "YES\nNO\nYES"}, {"input": "2\n1 1\n1 1", "output": "NO\nNO"}]
1,300
["implementation"]
24
[{"input": "3\r\n1 1\r\n3 2 4 1\r\n2 10 11\r\n", "output": "YES\r\nNO\r\nYES\r\n"}, {"input": "2\r\n1 1\r\n1 1\r\n", "output": "NO\r\nNO\r\n"}, {"input": "1\r\n1 1\r\n", "output": "YES\r\n"}, {"input": "2\r\n1 2\r\n1 3\r\n", "output": "YES\r\nYES\r\n"}, {"input": "2\r\n1 1\r\n2 1 2\r\n", "output": "YES\r\nNO\r\n"}, {"i...
false
stdio
null
true
632/B
632
B
PyPy 3-64
TESTS
13
296
67,072,000
211919103
n=int(input()) ls=list(map(int,input().split())) lz=list(input()) if len(set(lz))==1: print(sum(ls)) else: sumb=0 for i in range(n): if lz[i]=='B': sumb+=ls[i] sumb1=sumb max_front=0 for i in range(n): if lz[i]=='A': sumb1+=ls[i] elif lz[i]=='B': ...
17
218
63,180,800
194184018
import sys input = lambda :sys.stdin.readline()[:-1] ni = lambda :int(input()) na = lambda :list(map(int,input().split())) yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES") no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO") #######################################...
Educational Codeforces Round 9
ICPC
2,016
1.5
256
Alice, Bob, Two Teams
Alice and Bob are playing a game. The game involves splitting up game pieces into two teams. There are n pieces, and the i-th piece has a strength pi. The way to split up game pieces is split into several steps: 1. First, Alice will split the pieces into two different groups A and B. This can be seen as writing the a...
The first line contains integer n (1 ≤ n ≤ 5·105) — the number of game pieces. The second line contains n integers pi (1 ≤ pi ≤ 109) — the strength of the i-th piece. The third line contains n characters A or B — the assignment of teams after the first step (after Alice's step).
Print the only integer a — the maximum strength Bob can achieve.
null
In the first sample Bob should flip the suffix of length one. In the second sample Bob should flip the prefix or the suffix (here it is the same) of length 5. In the third sample Bob should do nothing.
[{"input": "5\n1 2 3 4 5\nABABA", "output": "11"}, {"input": "5\n1 2 3 4 5\nAAAAA", "output": "15"}, {"input": "1\n1\nB", "output": "1"}]
1,400
["brute force", "constructive algorithms"]
17
[{"input": "5\r\n1 2 3 4 5\r\nABABA\r\n", "output": "11\r\n"}, {"input": "5\r\n1 2 3 4 5\r\nAAAAA\r\n", "output": "15\r\n"}, {"input": "1\r\n1\r\nB\r\n", "output": "1\r\n"}, {"input": "10\r\n1 9 7 6 2 4 7 8 1 3\r\nABBABAABBB\r\n", "output": "33\r\n"}, {"input": "100\r\n591 417 888 251 792 847 685 3 182 461 102 348 555 ...
false
stdio
null
true
632/B
632
B
PyPy 3
TESTS
5
140
0
92467061
import sys n = int(sys.stdin.buffer.readline().decode('utf-8')) a = list(map(int, sys.stdin.buffer.readline().decode('utf-8').split())) s = sys.stdin.buffer.readline().decode('utf-8').rstrip() bob = 0 for i, c in enumerate(s): if c == 'B': bob += a[i] ans = bob for i, c in zip(range(n-1, -1, -1), reverse...
17
218
72,601,600
176102634
from sys import stdin input=lambda :stdin.readline()[:-1] n=int(input()) a=list(map(int,input().split())) s=input() ans=0 for i in range(n): if s[i]=='A': ans+=a[i] def calc(a,s): mx=0 tmp=0 for i in range(n): if s[i]=='A': tmp-=a[i] else: tmp+=a[i] mx=max(mx,tmp) return mx prin...
Educational Codeforces Round 9
ICPC
2,016
1.5
256
Alice, Bob, Two Teams
Alice and Bob are playing a game. The game involves splitting up game pieces into two teams. There are n pieces, and the i-th piece has a strength pi. The way to split up game pieces is split into several steps: 1. First, Alice will split the pieces into two different groups A and B. This can be seen as writing the a...
The first line contains integer n (1 ≤ n ≤ 5·105) — the number of game pieces. The second line contains n integers pi (1 ≤ pi ≤ 109) — the strength of the i-th piece. The third line contains n characters A or B — the assignment of teams after the first step (after Alice's step).
Print the only integer a — the maximum strength Bob can achieve.
null
In the first sample Bob should flip the suffix of length one. In the second sample Bob should flip the prefix or the suffix (here it is the same) of length 5. In the third sample Bob should do nothing.
[{"input": "5\n1 2 3 4 5\nABABA", "output": "11"}, {"input": "5\n1 2 3 4 5\nAAAAA", "output": "15"}, {"input": "1\n1\nB", "output": "1"}]
1,400
["brute force", "constructive algorithms"]
17
[{"input": "5\r\n1 2 3 4 5\r\nABABA\r\n", "output": "11\r\n"}, {"input": "5\r\n1 2 3 4 5\r\nAAAAA\r\n", "output": "15\r\n"}, {"input": "1\r\n1\r\nB\r\n", "output": "1\r\n"}, {"input": "10\r\n1 9 7 6 2 4 7 8 1 3\r\nABBABAABBB\r\n", "output": "33\r\n"}, {"input": "100\r\n591 417 888 251 792 847 685 3 182 461 102 348 555 ...
false
stdio
null
true
631/A
631
A
Python 3
TESTS
17
46
0
221237685
n=int(input()) array=list(map(int, input().split())) brray=list(map(int, input().split())) ora=array[0] orb=brray[0] for a in range(1,n-1): ora=ora|array[a] for b in range(1,n-1): orb=orb|brray[b] print(ora+orb)
27
46
0
159654424
n = int(input()) x = list(map(int ,input().split())) y = list(map(int ,input().split())) summix = 0 for num in range(len(x)): summix = summix | x[num] summiy = 0 for num in range(len(y)): summiy = summiy | y[num] print(summix + summiy)
Codeforces Round 344 (Div. 2)
CF
2,016
1
256
Interview
Blake is a CEO of a large company called "Blake Technologies". He loves his company very much and he thinks that his company should be the best. That is why every candidate needs to pass through the interview that consists of the following problem. We define function f(x, l, r) as a bitwise OR of integers xl, xl + 1, ...
The first line of the input contains a single integer n (1 ≤ n ≤ 1000) — the length of the arrays. The second line contains n integers ai (0 ≤ ai ≤ 109). The third line contains n integers bi (0 ≤ bi ≤ 109).
Print a single integer — the maximum value of sum f(a, l, r) + f(b, l, r) among all possible 1 ≤ l ≤ r ≤ n.
null
Bitwise OR of two non-negative integers a and b is the number c = a OR b, such that each of its digits in binary notation is 1 if and only if at least one of a or b have 1 in the corresponding position in binary notation. In the first sample, one of the optimal answers is l = 2 and r = 4, because f(a, 2, 4) + f(b, 2, ...
[{"input": "5\n1 2 4 3 2\n2 3 3 12 1", "output": "22"}, {"input": "10\n13 2 7 11 8 4 9 8 5 1\n5 7 18 9 2 3 0 11 8 6", "output": "46"}]
900
["brute force", "implementation"]
27
[{"input": "5\r\n1 2 4 3 2\r\n2 3 3 12 1\r\n", "output": "22"}, {"input": "10\r\n13 2 7 11 8 4 9 8 5 1\r\n5 7 18 9 2 3 0 11 8 6\r\n", "output": "46"}, {"input": "25\r\n12 30 38 109 81 124 80 33 38 48 29 78 96 48 96 27 80 77 102 65 80 113 31 118 35\r\n25 64 95 13 12 6 111 80 85 16 61 119 23 65 73 65 20 95 124 18 28 79 1...
false
stdio
null
true
847/A
847
A
Python 3
TESTS
7
46
204,800
233303279
import math class node(): def __init__(self, prev, next): self.value = None self.vprev = prev self.vnext = next self.prev = prev self.next = next class DoublyLL(): def __init__(self): self.leading = False self.tailing = False self.head = None ...
23
62
307,200
106529941
if __name__ == '__main__': n=int(input()) arr=[[0,0]] for i in range(n): arr.append(list(map(int,input().split()))) #d_link=[[0,0]] end=0 for i in range(1,n+1): if not arr[i][0]: arr[end][1]=i arr[i][0]=end j=i while arr[j][1]: j=arr[j][1] end=j for i in range(1,n+1): print(*arr[i])
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,017
2
256
Union of Doubly Linked Lists
Doubly linked list is one of the fundamental data structures. A doubly linked list is a sequence of elements, each containing information about the previous and the next elements of the list. In this problem all lists have linear structure. I.e. each element except the first has exactly one previous element, each eleme...
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of memory cells where the doubly linked lists are located. Each of the following n lines contains two integers li, ri (0 ≤ li, ri ≤ n) — the cells of the previous and the next element of list for cell i. Value li = 0 if element in cell i has no prev...
Print n lines, the i-th line must contain two integers li and ri — the cells of the previous and the next element of list for cell i after all lists from the input are united in a single list. If there are many solutions print any of them.
null
null
[{"input": "7\n4 7\n5 0\n0 0\n6 1\n0 2\n0 4\n1 0", "output": "4 7\n5 6\n0 5\n6 1\n3 2\n2 4\n1 0"}]
1,500
["implementation"]
23
[{"input": "7\r\n4 7\r\n5 0\r\n0 0\r\n6 1\r\n0 2\r\n0 4\r\n1 0\r\n", "output": "4 7\r\n5 6\r\n0 5\r\n6 1\r\n3 2\r\n2 4\r\n1 0\r\n"}, {"input": "2\r\n2 0\r\n0 1\r\n", "output": "2 0\r\n0 1\r\n"}, {"input": "1\r\n0 0\r\n", "output": "0 0\r\n"}, {"input": "4\r\n0 2\r\n1 0\r\n0 4\r\n3 0\r\n", "output": "0 2\r\n1 3\r\n2 4\r...
false
stdio
null
true
847/A
847
A
PyPy 3-64
TESTS
12
77
0
191445963
n = int(input()) a = [] tl = tr = 0 for i in range(n): l, r = map(int, input().split()) a.append([str(l), str(i+1), str(r)]) if l == 0: tl += 1 if r == 0: tr += 1 if tl==1 and tr==1: for i in range(0, n): print(int(a[i][0]), int(a[i][2])) else: s = '' p = a.copy() L = ['0'] ...
23
62
1,740,800
172512257
n=int(input()) mp=dict() arr=list() cnct=[-1]*15 for i in range(1,n+1): x,y=[int(a) for a in input().split()] arr.append([x,y]) mp[i]=[x,y] tog=list() for i in range(1,n+1): fi,lst=-1,-1 j=mp[i][0] if j==0:fi=i else: while 1: if mp[j][0]==0:break j=mp[j][0] ...
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,017
2
256
Union of Doubly Linked Lists
Doubly linked list is one of the fundamental data structures. A doubly linked list is a sequence of elements, each containing information about the previous and the next elements of the list. In this problem all lists have linear structure. I.e. each element except the first has exactly one previous element, each eleme...
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of memory cells where the doubly linked lists are located. Each of the following n lines contains two integers li, ri (0 ≤ li, ri ≤ n) — the cells of the previous and the next element of list for cell i. Value li = 0 if element in cell i has no prev...
Print n lines, the i-th line must contain two integers li and ri — the cells of the previous and the next element of list for cell i after all lists from the input are united in a single list. If there are many solutions print any of them.
null
null
[{"input": "7\n4 7\n5 0\n0 0\n6 1\n0 2\n0 4\n1 0", "output": "4 7\n5 6\n0 5\n6 1\n3 2\n2 4\n1 0"}]
1,500
["implementation"]
23
[{"input": "7\r\n4 7\r\n5 0\r\n0 0\r\n6 1\r\n0 2\r\n0 4\r\n1 0\r\n", "output": "4 7\r\n5 6\r\n0 5\r\n6 1\r\n3 2\r\n2 4\r\n1 0\r\n"}, {"input": "2\r\n2 0\r\n0 1\r\n", "output": "2 0\r\n0 1\r\n"}, {"input": "1\r\n0 0\r\n", "output": "0 0\r\n"}, {"input": "4\r\n0 2\r\n1 0\r\n0 4\r\n3 0\r\n", "output": "0 2\r\n1 3\r\n2 4\r...
false
stdio
null
true
629/B
629
B
Python 3
TESTS
2
46
4,915,200
24259389
a=int(input()) ma=[] md=[] fa=[] fd=[] for i in range(a): y=input().split() if y[0]=='M': ma.append(int(y[1])) md.append(int(y[2])+1) else: fa.append(int(y[1])) fd.append(int(y[2])+1) ma.sort() md.sort() fa.sort() fd.sort() m=0 f=0 mx=0 mpa=0 fpa=0 mda=0 fda=0 for i in range(...
76
77
0
16253890
readInts=lambda: list(map(int, input().split())) n = int(input()) num = [[0,0] for i in range(370)] for i in range(n): s,u,v = (input().split()) u=int(u) v=int(v) c=int(s=='F') num[u][c]+=1 num[v+1][c]-=1 x=0;y=0 ret=0 for i in range(367): x+=num[i][0] y+=num[i][1] ret=max(ret,min(x...
Codeforces Round 343 (Div. 2)
CF
2,016
2
256
Far Relative’s Problem
Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has n friends and each of them can come to the party in a specific range of days of the year from ai to bi. Of course, Famil Door wants to have as many friends celebrating together with him as possible. Far cars are as weird as Far Far A...
The first line of the input contains a single integer n (1 ≤ n ≤ 5000) — then number of Famil Door's friends. Then follow n lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers ai and bi (1 ≤ ai ≤ bi ≤ 3...
Print the maximum number of people that may come to Famil Door's party.
null
In the first sample, friends 3 and 4 can come on any day in range [117, 128]. In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140.
[{"input": "4\nM 151 307\nF 343 352\nF 117 145\nM 24 128", "output": "2"}, {"input": "6\nM 128 130\nF 128 131\nF 131 140\nF 131 141\nM 131 200\nM 140 200", "output": "4"}]
1,100
["brute force"]
76
[{"input": "4\r\nM 151 307\r\nF 343 352\r\nF 117 145\r\nM 24 128\r\n", "output": "2\r\n"}, {"input": "6\r\nM 128 130\r\nF 128 131\r\nF 131 140\r\nF 131 141\r\nM 131 200\r\nM 140 200\r\n", "output": "4\r\n"}, {"input": "1\r\nF 68 307\r\n", "output": "0\r\n"}, {"input": "40\r\nM 55 363\r\nF 117 252\r\nM 157 282\r\nF 322 ...
false
stdio
null
true
629/B
629
B
Python 3
TESTS
2
46
307,200
228671645
import array import collections import math sums = lambda n: int(n * (n + 1) / 2) # sum from 1 to n sumsqur = lambda n: int( (n) * (n + 1) * (2*n +1)/6) # sum square from 1 to n def im(): return map(int, input().split()) def il(): return list(map(int, input().split())) def ii(): return int(input()) # "abcdefghijkl...
76
77
0
16297037
def main(): n = int(input()) mf = ([0] * 367, [0] * 367) for _ in range(n): tmp = input().split() l = mf[tmp[0] == 'F'] l[int(tmp[1]) - 1] += 1 l[int(tmp[2])] -= 1 res = [] m = f = 0 for a, b in zip(*mf): m += a f += b res.append(m if m < f...
Codeforces Round 343 (Div. 2)
CF
2,016
2
256
Far Relative’s Problem
Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has n friends and each of them can come to the party in a specific range of days of the year from ai to bi. Of course, Famil Door wants to have as many friends celebrating together with him as possible. Far cars are as weird as Far Far A...
The first line of the input contains a single integer n (1 ≤ n ≤ 5000) — then number of Famil Door's friends. Then follow n lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers ai and bi (1 ≤ ai ≤ bi ≤ 3...
Print the maximum number of people that may come to Famil Door's party.
null
In the first sample, friends 3 and 4 can come on any day in range [117, 128]. In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140.
[{"input": "4\nM 151 307\nF 343 352\nF 117 145\nM 24 128", "output": "2"}, {"input": "6\nM 128 130\nF 128 131\nF 131 140\nF 131 141\nM 131 200\nM 140 200", "output": "4"}]
1,100
["brute force"]
76
[{"input": "4\r\nM 151 307\r\nF 343 352\r\nF 117 145\r\nM 24 128\r\n", "output": "2\r\n"}, {"input": "6\r\nM 128 130\r\nF 128 131\r\nF 131 140\r\nF 131 141\r\nM 131 200\r\nM 140 200\r\n", "output": "4\r\n"}, {"input": "1\r\nF 68 307\r\n", "output": "0\r\n"}, {"input": "40\r\nM 55 363\r\nF 117 252\r\nM 157 282\r\nF 322 ...
false
stdio
null
true
962/E
962
E
PyPy 3
TESTS
4
93
20,172,800
129283674
n = int(input()) XC = [] for i in range(n): x, c = map(str, input().split()) x = int(x) XC.append((x, c)) XC.sort() INF = 10**18 preB = -INF preR = -INF preP = -INF ans = 0 for i, (x, c) in enumerate(XC): if c == 'B': if preB < preP: if preP != -INF: ans += x-preP ...
45
358
11,776,000
129791972
import sys input = sys.stdin.readline def solve(): n = int(input()) p = None B = [] R = [] r = 0 for i in range(n): x, c = input().split() x = int(x) if c == 'B': B.append(x) elif c == 'R': R.append(x) else: if p is None: if len(B) != 0: r += x - B[0] if len(R) != 0: r += x ...
Educational Codeforces Round 42 (Rated for Div. 2)
ICPC
2,018
2
256
Byteland, Berland and Disputed Cities
The cities of Byteland and Berland are located on the axis $$$Ox$$$. In addition, on this axis there are also disputed cities, which belong to each of the countries in their opinion. Thus, on the line $$$Ox$$$ there are three types of cities: - the cities of Byteland, - the cities of Berland, - disputed cities. Recen...
The first line contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^{5}$$$) — the number of cities. The following $$$n$$$ lines contains an integer $$$x_i$$$ and the letter $$$c_i$$$ ($$$-10^{9} \le x_i \le 10^{9}$$$) — the coordinate of the city and its type. If the city belongs to Byteland, $$$c_i$$$ equals ...
Print the minimal total length of such set of cables, that if we delete all Berland cities ($$$c_i$$$='R'), it will be possible to find a way from any remaining city to any other remaining city, moving only by cables. Similarly, if we delete all Byteland cities ($$$c_i$$$='B'), it will be possible to find a way from an...
null
In the first example, you should connect the first city with the second, the second with the third, and the third with the fourth. The total length of the cables will be $$$5 + 3 + 4 = 12$$$. In the second example there are no disputed cities, so you need to connect all the neighboring cities of Byteland and all the n...
[{"input": "4\n-5 R\n0 P\n3 P\n7 B", "output": "12"}, {"input": "5\n10 R\n14 B\n16 B\n21 R\n32 R", "output": "24"}]
2,200
["constructive algorithms", "greedy"]
45
[{"input": "4\r\n-5 R\r\n0 P\r\n3 P\r\n7 B\r\n", "output": "12\r\n"}, {"input": "5\r\n10 R\r\n14 B\r\n16 B\r\n21 R\r\n32 R\r\n", "output": "24\r\n"}, {"input": "10\r\n66 R\r\n67 R\r\n72 R\r\n73 R\r\n76 R\r\n78 B\r\n79 B\r\n83 B\r\n84 B\r\n85 P\r\n", "output": "26\r\n"}, {"input": "10\r\n61 R\r\n64 R\r\n68 R\r\n71 R\r\n...
false
stdio
null
true
774/B
774
B
Python 3
TESTS
3
46
4,915,200
26151061
n, m, d = list(map(int, input().split())) a = [] b = [] for i in range(n): a.append(list(map(int, input().split()))) for i in range(m): b.append(list(map(int, input().split()))) a = sorted(a, key=lambda x: x[0]) b = sorted(b, key=lambda x: x[0]) tc, td = 0, 0 tc += a[-1][0] tc += b[-1][0] td += a[-1][1] t...
44
904
35,123,200
217501504
n, m, d = map(int, input().split()) ph = [[int(j) for j in input().split()] for i in range(n)] inf = [[int(j) for j in input().split()] for i in range(m)] for i in range(n): ph[i][1] = -ph[i][1] for i in range(m): inf[i][1] = -inf[i][1] ph.sort(reverse=True) inf.sort(reverse=True) sw, sc = 0, 0 for p in inf: ...
VK Cup 2017 - Wild Card Round 1
ICPC
2,017
3
256
Significant Cups
Stepan is a very experienced olympiad participant. He has n cups for Physics olympiads and m cups for Informatics olympiads. Each cup is characterized by two parameters — its significance ci and width wi. Stepan decided to expose some of his cups on a shelf with width d in such a way, that: - there is at least one Ph...
The first line contains three integers n, m and d (1 ≤ n, m ≤ 100 000, 1 ≤ d ≤ 109) — the number of cups for Physics olympiads, the number of cups for Informatics olympiads and the width of the shelf. Each of the following n lines contains two integers ci and wi (1 ≤ ci, wi ≤ 109) — significance and width of the i-th ...
Print the maximum possible total significance, which Stepan can get exposing cups on the shelf with width d, considering all the rules described in the statement. If there is no way to expose cups on the shelf, then print 0.
null
In the first example Stepan has only one Informatics cup which must be exposed on the shelf. Its significance equals 3 and width equals 2, so after Stepan exposes it, the width of free space on the shelf becomes equal to 6. Also, Stepan must expose the second Physics cup (which has width 5), because it is the most sign...
[{"input": "3 1 8\n4 2\n5 5\n4 2\n3 2", "output": "8"}, {"input": "4 3 12\n3 4\n2 4\n3 5\n3 4\n3 5\n5 2\n3 4", "output": "11"}, {"input": "2 2 2\n5 3\n6 3\n4 2\n8 1", "output": "0"}]
2,100
["*special", "binary search", "data structures", "two pointers"]
44
[{"input": "3 1 8\r\n4 2\r\n5 5\r\n4 2\r\n3 2\r\n", "output": "8\r\n"}, {"input": "4 3 12\r\n3 4\r\n2 4\r\n3 5\r\n3 4\r\n3 5\r\n5 2\r\n3 4\r\n", "output": "11\r\n"}, {"input": "2 2 2\r\n5 3\r\n6 3\r\n4 2\r\n8 1\r\n", "output": "0\r\n"}, {"input": "10 10 229\r\n15 17\r\n5 4\r\n4 15\r\n4 17\r\n15 11\r\n7 6\r\n5 19\r\n14 ...
false
stdio
null
true
850/C
850
C
Python 3
TESTS
6
62
307,200
30084178
#!/usr/bin/env python import sys from operator import itemgetter def sieve(limit): is_prime = [True] * limit is_prime[0] = False indx = 0 while indx < limit: if is_prime[indx]: num = indx + 1 yield num mul = 1 while mul * num <= limit: ...
57
124
3,686,400
113129030
import sys input = sys.stdin.buffer.readline from collections import Counter games = Counter() # prime : bitmask of if that power of the prime exists def add_primes(a): i = 2 while i*i <= a: cnt = 0 while a % i == 0: a //= i cnt += 1 if cnt: games[i...
Codeforces Round 432 (Div. 1, based on IndiaHacks Final Round 2017)
CF
2,017
1
256
Arpa and a game with Mojtaba
Mojtaba and Arpa are playing a game. They have a list of n numbers in the game. In a player's turn, he chooses a number pk (where p is a prime number and k is a positive integer) such that pk divides at least one number in the list. For each number in the list divisible by pk, call it x, the player will delete x and a...
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of elements in the list. The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) — the elements of the list.
If Mojtaba wins, print "Mojtaba", otherwise print "Arpa" (without quotes). You can print each letter in any case (upper or lower).
null
In the first sample test, Mojtaba can't move. In the second sample test, Mojtaba chooses p = 17 and k = 1, then the list changes to [1, 1, 1, 1]. In the third sample test, if Mojtaba chooses p = 17 and k = 1, then Arpa chooses p = 17 and k = 1 and wins, if Mojtaba chooses p = 17 and k = 2, then Arpa chooses p = 17 an...
[{"input": "4\n1 1 1 1", "output": "Arpa"}, {"input": "4\n1 1 17 17", "output": "Mojtaba"}, {"input": "4\n1 1 17 289", "output": "Arpa"}, {"input": "5\n1 2 3 4 5", "output": "Arpa"}]
2,200
["bitmasks", "dp", "games"]
57
[{"input": "4\r\n1 1 1 1\r\n", "output": "Arpa\r\n"}, {"input": "4\r\n1 1 17 17\r\n", "output": "Mojtaba\r\n"}, {"input": "4\r\n1 1 17 289\r\n", "output": "Arpa\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n", "output": "Arpa\r\n"}, {"input": "10\r\n10 14 16 9 17 13 12 4 6 10\r\n", "output": "Mojtaba\r\n"}, {"input": "10\r\n13 1...
false
stdio
null
true
847/K
847
K
Python 3
TESTS
0
15
0
173321507
n,a,b,f,k =map(int, input().split()) ans = 0 d = {} next = '' for i in range(0,n): x=input() y,z = x.split() if x in d: if y == next: d[x]+=b else: d[x]+=a else: d[x]=0 if y == next: d[x]+=b else: d[x]+=a next = z sorted_values = sorted(d.values()) # Sort the values...
55
62
4,608,000
30477812
def main(): trips, reg, cheap, cards, card_cost = map(int, input().split()) costs = [] indexes = {} total = 0 last = "" for i in range(trips): a, b = input().split() pair = (min(a, b), max(a, b)) if pair in indexes: index = indexes[pair] else: costs.append(0) indexes[pai...
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest, qualification stage (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,017
4
256
Travel Cards
In the evening Polycarp decided to analyze his today's travel expenses on public transport. The bus system in the capital of Berland is arranged in such a way that each bus runs along the route between two stops. Each bus has no intermediate stops. So each of the buses continuously runs along the route from one stop t...
The first line contains five integers n, a, b, k, f (1 ≤ n ≤ 300, 1 ≤ b < a ≤ 100, 0 ≤ k ≤ 300, 1 ≤ f ≤ 1000) where: - n — the number of Polycarp trips, - a — the cost of a regualar single trip, - b — the cost of a trip after a transshipment, - k — the maximum number of travel cards Polycarp can buy, - f — the cost of...
Print the smallest amount of money Polycarp could have spent today, if he can purchase no more than k travel cards.
null
In the first example Polycarp can buy travel card for the route "BerBank $$\leftarrow$$ University" and spend 8 burles. Note that his second trip "University" $$\rightarrow$$ "BerMall" was made after transshipment, so for this trip Polycarp payed 3 burles. So the minimum total sum equals to 8 + 3 = 11 burles. In the s...
[{"input": "3 5 3 1 8\nBerBank University\nUniversity BerMall\nUniversity BerBank", "output": "11"}, {"input": "4 2 1 300 1000\na A\nA aa\naa AA\nAA a", "output": "5"}]
1,800
["greedy", "implementation", "sortings"]
55
[{"input": "3 5 3 1 8\r\nBerBank University\r\nUniversity BerMall\r\nUniversity BerBank\r\n", "output": "11\r\n"}, {"input": "4 2 1 300 1000\r\na A\r\nA aa\r\naa AA\r\nAA a\r\n", "output": "5\r\n"}, {"input": "2 2 1 0 1\r\naca BCBA\r\nBCBA aca\r\n", "output": "3\r\n"}, {"input": "2 2 1 2 1\r\nBDDB C\r\nC BDDB\r\n", "ou...
false
stdio
null
true
629/B
629
B
Python 3
PRETESTS
2
61
0
16237793
n = int(input()) day = [[0, 0] for i in range(368)] for i in range(n): a, b, c = (input().split()) if(a == "M"): day[int(b)][0] += 1 day[int(c)+1][0] -= 1 else: day[int(b)][1] += 1 day[int(c)+1][1] -= 1 w = 0 m = 0 ans = 0 for i in day: w += i[0] m += i[1] if(w == m): ans = max(m+w, ans) print(ans)
76
77
0
16339988
n = int(input()) f, m = [0]*368, [0]*368 for i in range(n): s, a, b = input().split() if s == 'F': f[int(a)] += 1 f[int(b)+1] -= 1 elif s == 'M': m[int(a)] += 1 m[int(b)+1] -= 1 for i in range(1, len(f)): f[i] += f[i-1] m[i] += m[i-1] print(max([min(f[i], m[i])*2 f...
Codeforces Round 343 (Div. 2)
CF
2,016
2
256
Far Relative’s Problem
Famil Door wants to celebrate his birthday with his friends from Far Far Away. He has n friends and each of them can come to the party in a specific range of days of the year from ai to bi. Of course, Famil Door wants to have as many friends celebrating together with him as possible. Far cars are as weird as Far Far A...
The first line of the input contains a single integer n (1 ≤ n ≤ 5000) — then number of Famil Door's friends. Then follow n lines, that describe the friends. Each line starts with a capital letter 'F' for female friends and with a capital letter 'M' for male friends. Then follow two integers ai and bi (1 ≤ ai ≤ bi ≤ 3...
Print the maximum number of people that may come to Famil Door's party.
null
In the first sample, friends 3 and 4 can come on any day in range [117, 128]. In the second sample, friends with indices 3, 4, 5 and 6 can come on day 140.
[{"input": "4\nM 151 307\nF 343 352\nF 117 145\nM 24 128", "output": "2"}, {"input": "6\nM 128 130\nF 128 131\nF 131 140\nF 131 141\nM 131 200\nM 140 200", "output": "4"}]
1,100
["brute force"]
76
[{"input": "4\r\nM 151 307\r\nF 343 352\r\nF 117 145\r\nM 24 128\r\n", "output": "2\r\n"}, {"input": "6\r\nM 128 130\r\nF 128 131\r\nF 131 140\r\nF 131 141\r\nM 131 200\r\nM 140 200\r\n", "output": "4\r\n"}, {"input": "1\r\nF 68 307\r\n", "output": "0\r\n"}, {"input": "40\r\nM 55 363\r\nF 117 252\r\nM 157 282\r\nF 322 ...
false
stdio
null
true
963/B
963
B
PyPy 3-64
TESTS
2
46
614,400
155876435
import sys from collections import deque from array import array class graph: def __init__(self, n): self.n, self.gdict = n, [[] for _ in range(n + 1)] self.l = [0] * (n + 1) def add_edge(self, node1, node2, w=None): self.gdict[node1].append(node2) self.gdict[node2].append(nod...
95
826
48,742,400
101823725
from collections import defaultdict,deque import sys import bisect import math input=sys.stdin.readline mod=1000000007 def bfs(root,count): q=deque([root]) vis.add(root) while q: vertex=q.popleft() for child in graph[vertex]: if ans[child]==0: ans[child]=count+1 ...
Tinkoff Internship Warmup Round 2018 and Codeforces Round 475 (Div. 1)
CF
2,018
1
256
Destruction of a Tree
You are given a tree (a graph with n vertices and n - 1 edges in which it's possible to reach any vertex from any other vertex using only its edges). A vertex can be destroyed if this vertex has even degree. If you destroy a vertex, all edges connected to it are also deleted. Destroy all vertices in the given tree or...
The first line contains integer n (1 ≤ n ≤ 2·105) — number of vertices in a tree. The second line contains n integers p1, p2, ..., pn (0 ≤ pi ≤ n). If pi ≠ 0 there is an edge between vertices i and pi. It is guaranteed that the given graph is a tree.
If it's possible to destroy all vertices, print "YES" (without quotes), otherwise print "NO" (without quotes). If it's possible to destroy all vertices, in the next n lines print the indices of the vertices in order you destroy them. If there are multiple correct answers, print any.
null
In the first example at first you have to remove the vertex with index 1 (after that, the edges (1, 2) and (1, 4) are removed), then the vertex with index 2 (and edges (2, 3) and (2, 5) are removed). After that there are no edges in the tree, so you can remove remaining vertices in any order.
[{"input": "5\n0 1 2 1 2", "output": "YES\n1\n2\n3\n5\n4"}, {"input": "4\n0 1 2 3", "output": "NO"}]
2,000
["constructive algorithms", "dfs and similar", "dp", "greedy", "trees"]
95
[{"input": "5\r\n0 1 2 1 2\r\n", "output": "YES\r\n1\r\n2\r\n3\r\n5\r\n4\r\n"}, {"input": "4\r\n0 1 2 3\r\n", "output": "NO\r\n"}, {"input": "1\r\n0\r\n", "output": "YES\r\n1\r\n"}, {"input": "8\r\n3 1 4 0 4 2 4 5\r\n", "output": "NO\r\n"}, {"input": "100\r\n81 96 65 28 4 40 5 49 5 89 48 70 94 70 17 58 58 1 61 19 45 33...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input with open(input_path) as f: n = int(f.readline()) p = list(map(int, f.readline().split())) # Read reference output with open(output_path) as f_ref: ...
true
855/A
855
A
PyPy 3-64
TESTS
3
46
0
228422490
n=int(input("")) l=[] for i in range(n): x=input() l.append(x) for j in range(n): z=0 for m in range(j): if l[i]==l[m]: z+=1 else: z+=0 if z!=0: print("YES") else: print("NO")
55
46
0
144955619
n=int(input()) lst=[] for i in range(n): st=input() if(st in lst): print("YES") else: print("NO") lst.append(st)
Manthan, Codefest 17
CF
2,017
2
256
Tom Riddle's Diary
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they ...
First line of input contains an integer n (1 ≤ n ≤ 100) — the number of names in the list. Next n lines each contain a string si, consisting of lowercase English letters. The length of each string is between 1 and 100.
Output n lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not. You can print each letter in any case (upper or lower).
null
In test case 1, for i = 5 there exists j = 3 such that si = sj and j < i, which means that answer for i = 5 is "YES".
[{"input": "6\ntom\nlucius\nginny\nharry\nginny\nharry", "output": "NO\nNO\nNO\nNO\nYES\nYES"}, {"input": "3\na\na\na", "output": "NO\nYES\nYES"}]
800
["brute force", "implementation", "strings"]
55
[{"input": "6\r\ntom\r\nlucius\r\nginny\r\nharry\r\nginny\r\nharry\r\n", "output": "NO\r\nNO\r\nNO\r\nNO\r\nYES\r\nYES\r\n"}, {"input": "3\r\na\r\na\r\na\r\n", "output": "NO\r\nYES\r\nYES\r\n"}, {"input": "1\r\nzn\r\n", "output": "NO\r\n"}, {"input": "9\r\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnb...
false
stdio
null
true
855/A
855
A
Python 3
TESTS
3
31
0
146609408
n=int(input()) s=[] for i in range(n): s.append(input()) flag=0 for i in range(n): for j in range(i): if s[j]==s[i]: flag=1 break if flag==1: print("YES") if flag==0: print("NO")
55
46
0
144955926
n=int(input()) a=[] for i in range(n): l=input() if(l in a): print('Yes') else: a.append(l) print('No')
Manthan, Codefest 17
CF
2,017
2
256
Tom Riddle's Diary
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they ...
First line of input contains an integer n (1 ≤ n ≤ 100) — the number of names in the list. Next n lines each contain a string si, consisting of lowercase English letters. The length of each string is between 1 and 100.
Output n lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not. You can print each letter in any case (upper or lower).
null
In test case 1, for i = 5 there exists j = 3 such that si = sj and j < i, which means that answer for i = 5 is "YES".
[{"input": "6\ntom\nlucius\nginny\nharry\nginny\nharry", "output": "NO\nNO\nNO\nNO\nYES\nYES"}, {"input": "3\na\na\na", "output": "NO\nYES\nYES"}]
800
["brute force", "implementation", "strings"]
55
[{"input": "6\r\ntom\r\nlucius\r\nginny\r\nharry\r\nginny\r\nharry\r\n", "output": "NO\r\nNO\r\nNO\r\nNO\r\nYES\r\nYES\r\n"}, {"input": "3\r\na\r\na\r\na\r\n", "output": "NO\r\nYES\r\nYES\r\n"}, {"input": "1\r\nzn\r\n", "output": "NO\r\n"}, {"input": "9\r\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnb...
false
stdio
null
true
855/A
855
A
Python 3
TESTS
3
31
0
221466945
n = int(input()) a = [] b = 0 for i in range(n): c = input() a.append(c) for i in range(0,n): for j in range(0,i): if(i!=j): if(a[i]==a[j]): b+=1 else: continue if(b>0): print("YES") else: print("NO")
55
46
0
144956037
names = int(input()) #the number of names in the list. vaish = [] for i in range(names): vaish.append(input()) for i in range(names): flag = 0 for j in range(i): if vaish[i] == vaish[j]: flag = 1 break if flag: print("YES") else: print("NO")
Manthan, Codefest 17
CF
2,017
2
256
Tom Riddle's Diary
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they ...
First line of input contains an integer n (1 ≤ n ≤ 100) — the number of names in the list. Next n lines each contain a string si, consisting of lowercase English letters. The length of each string is between 1 and 100.
Output n lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not. You can print each letter in any case (upper or lower).
null
In test case 1, for i = 5 there exists j = 3 such that si = sj and j < i, which means that answer for i = 5 is "YES".
[{"input": "6\ntom\nlucius\nginny\nharry\nginny\nharry", "output": "NO\nNO\nNO\nNO\nYES\nYES"}, {"input": "3\na\na\na", "output": "NO\nYES\nYES"}]
800
["brute force", "implementation", "strings"]
55
[{"input": "6\r\ntom\r\nlucius\r\nginny\r\nharry\r\nginny\r\nharry\r\n", "output": "NO\r\nNO\r\nNO\r\nNO\r\nYES\r\nYES\r\n"}, {"input": "3\r\na\r\na\r\na\r\n", "output": "NO\r\nYES\r\nYES\r\n"}, {"input": "1\r\nzn\r\n", "output": "NO\r\n"}, {"input": "9\r\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnb...
false
stdio
null
true
38/D
38
D
Python 3
TESTS
3
62
0
197034283
n = int(input()) k = 1 x_1, y_1, x_2, y_2 = list(map(abs, map(int, input().split()))) for cord in range(n-1): x_1_new, y_1_new, x_2_new, y_2_new = list(map(abs, map(int, input().split()))) S_intersect = (min(x_2,x_2_new) - (max(x_1, x_1_new) - min(x_1, x_1_new))) * (min(y_2,y_2_new) - (max(y_1, y_1_new) - min(y...
64
342
22,220,800
86059864
n = int(input()) l = [] m = [] for i in range(n): X1, Y1, X2, Y2 = map(int, input().split()) m1 = (abs(X2 - X1)) ** 3 l.append([X1, Y1, X2, Y2]) m.append(m1) X1, Y1, X2, Y2 = l[0][0], l[0][1], l[0][2], l[0][3] if X1 > X2: X2, X1 = X1, X2 if Y1 > Y2: Y1, Y2 = Y2, Y1 ans = n for i in range(1, n): for ...
School Personal Contest #1 (Winter Computer School 2010/11) - Codeforces Beta Round 38 (ACM-ICPC Rules)
ICPC
2,010
2
256
Vasya the Architect
Once Vasya played bricks. All the bricks in the set had regular cubical shape. Vasya vas a talented architect, however the tower he built kept falling apart. Let us consider the building process. Vasya takes a brick and puts it on top of the already built tower so that the sides of the brick are parallel to the sides ...
The first input file contains an integer n (1 ≤ n ≤ 100) which is the number of bricks. Each of the next n lines contains four numbers xi, 1, yi, 1, xi, 2, yi, 2 (xi, 1 ≠ xi, 2, |xi, 1 - xi, 2| = |yi, 1 - yi, 2|) which are the coordinates of the opposite angles of the base of the brick number i. The coordinates are int...
Print the number of bricks in the maximal stable tower.
null
null
[{"input": "2\n0 0 3 3\n1 0 4 3", "output": "2"}, {"input": "2\n0 0 3 3\n2 0 5 3", "output": "1"}, {"input": "3\n0 0 3 3\n1 0 4 3\n2 0 5 3", "output": "3"}]
1,900
["implementation"]
64
[{"input": "2\r\n0 0 3 3\r\n1 0 4 3\r\n", "output": "2\r\n"}, {"input": "2\r\n0 0 3 3\r\n2 0 5 3\r\n", "output": "1\r\n"}, {"input": "3\r\n0 0 3 3\r\n1 0 4 3\r\n2 0 5 3\r\n", "output": "3\r\n"}, {"input": "5\r\n7 -10 -8 5\r\n4 -7 -5 2\r\n2 -5 -3 0\r\n-9 48 50 -11\r\n50 -4 -2 48\r\n", "output": "3\r\n"}, {"input": "5\r\...
false
stdio
null
true
855/A
855
A
PyPy 3
TESTS
3
139
0
73856708
tests = int(input()) list =[] for number in range(tests): a= str(input()) list.append(a) flag = 0 for temp in range(tests): for temp1 in range(temp): if list[temp]==list[temp1]: flag = 1 break if flag : print('YES') else: print('NO')
55
46
0
144956224
l=[] n=int(input()) for x in range(n): name=input() if name in l: print("YES") else: print("NO") l.append(name)
Manthan, Codefest 17
CF
2,017
2
256
Tom Riddle's Diary
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they ...
First line of input contains an integer n (1 ≤ n ≤ 100) — the number of names in the list. Next n lines each contain a string si, consisting of lowercase English letters. The length of each string is between 1 and 100.
Output n lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not. You can print each letter in any case (upper or lower).
null
In test case 1, for i = 5 there exists j = 3 such that si = sj and j < i, which means that answer for i = 5 is "YES".
[{"input": "6\ntom\nlucius\nginny\nharry\nginny\nharry", "output": "NO\nNO\nNO\nNO\nYES\nYES"}, {"input": "3\na\na\na", "output": "NO\nYES\nYES"}]
800
["brute force", "implementation", "strings"]
55
[{"input": "6\r\ntom\r\nlucius\r\nginny\r\nharry\r\nginny\r\nharry\r\n", "output": "NO\r\nNO\r\nNO\r\nNO\r\nYES\r\nYES\r\n"}, {"input": "3\r\na\r\na\r\na\r\n", "output": "NO\r\nYES\r\nYES\r\n"}, {"input": "1\r\nzn\r\n", "output": "NO\r\n"}, {"input": "9\r\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnb...
false
stdio
null
true
855/A
855
A
Python 3
TESTS
3
108
0
82166064
n = int(input()) a = 0 b = [] c = [] j = "NO" while a < n: a += 1 s = input() if s in b: j = "YES" b.append(s) c.append(j) for x in c: print(x)
55
46
0
144956240
n=int(input()) s=set() for i in range(n): a=input() if a in s: print("YES") else: print("NO") s.add(a)
Manthan, Codefest 17
CF
2,017
2
256
Tom Riddle's Diary
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they ...
First line of input contains an integer n (1 ≤ n ≤ 100) — the number of names in the list. Next n lines each contain a string si, consisting of lowercase English letters. The length of each string is between 1 and 100.
Output n lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not. You can print each letter in any case (upper or lower).
null
In test case 1, for i = 5 there exists j = 3 such that si = sj and j < i, which means that answer for i = 5 is "YES".
[{"input": "6\ntom\nlucius\nginny\nharry\nginny\nharry", "output": "NO\nNO\nNO\nNO\nYES\nYES"}, {"input": "3\na\na\na", "output": "NO\nYES\nYES"}]
800
["brute force", "implementation", "strings"]
55
[{"input": "6\r\ntom\r\nlucius\r\nginny\r\nharry\r\nginny\r\nharry\r\n", "output": "NO\r\nNO\r\nNO\r\nNO\r\nYES\r\nYES\r\n"}, {"input": "3\r\na\r\na\r\na\r\n", "output": "NO\r\nYES\r\nYES\r\n"}, {"input": "1\r\nzn\r\n", "output": "NO\r\n"}, {"input": "9\r\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnb...
false
stdio
null
true
855/A
855
A
Python 3
TESTS
3
93
0
78579053
n = int(input()) lis = [] for i in range(n): s = input() lis.append(s) flag = 0 for i in range(n): for j in range(n): if j<i and lis[j]==lis[i]: flag=1 if flag==1: print("YES") else: print("NO")
55
46
0
144956397
a = [] for _ in range(int(input())): name = input() if name not in a: a.append(name) print("NO") else: print("YES")
Manthan, Codefest 17
CF
2,017
2
256
Tom Riddle's Diary
Harry Potter is on a mission to destroy You-Know-Who's Horcruxes. The first Horcrux that he encountered in the Chamber of Secrets is Tom Riddle's diary. The diary was with Ginny and it forced her to open the Chamber of Secrets. Harry wants to know the different people who had ever possessed the diary to make sure they ...
First line of input contains an integer n (1 ≤ n ≤ 100) — the number of names in the list. Next n lines each contain a string si, consisting of lowercase English letters. The length of each string is between 1 and 100.
Output n lines each containing either "YES" or "NO" (without quotes), depending on whether this string was already present in the stream or not. You can print each letter in any case (upper or lower).
null
In test case 1, for i = 5 there exists j = 3 such that si = sj and j < i, which means that answer for i = 5 is "YES".
[{"input": "6\ntom\nlucius\nginny\nharry\nginny\nharry", "output": "NO\nNO\nNO\nNO\nYES\nYES"}, {"input": "3\na\na\na", "output": "NO\nYES\nYES"}]
800
["brute force", "implementation", "strings"]
55
[{"input": "6\r\ntom\r\nlucius\r\nginny\r\nharry\r\nginny\r\nharry\r\n", "output": "NO\r\nNO\r\nNO\r\nNO\r\nYES\r\nYES\r\n"}, {"input": "3\r\na\r\na\r\na\r\n", "output": "NO\r\nYES\r\nYES\r\n"}, {"input": "1\r\nzn\r\n", "output": "NO\r\n"}, {"input": "9\r\nliyzmbjwnzryjokufuxcqtzwworjeoxkbaqrujrhdidqdvwdfzilwszgnzglnnb...
false
stdio
null
true
774/D
774
D
Python 3
TESTS
17
155
9,523,200
164246086
from hashlib import blake2b n,l,r = map(int,input().split()) a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] al = a[:l-1] ar = a[r:] bl = b[:l-1] br = b[r:] al.sort() bl.sort() ar.sort() br.sort() if al == bl and ar == br: print('TRUTH') else: print('LIE')
52
93
15,155,200
26152014
s = input().split(" ") o = input().split(" ") f = input().split(" ") flag =0 for i in range(0,int(s[1])-1): if o[i]!=f[i]: flag =1 break if flag == 0: for i in range(int(s[2]),int(s[0])): if o[i]!=f[i]: flag =1 break if flag == 0: print ("TRUTH") else: print ("LIE")
VK Cup 2017 - Wild Card Round 1
ICPC
2,017
2
256
Lie or Truth
Vasya has a sequence of cubes and exactly one integer is written on each cube. Vasya exhibited all his cubes in a row. So the sequence of numbers written on the cubes in the order from the left to the right equals to a1, a2, ..., an. While Vasya was walking, his little brother Stepan played with Vasya's cubes and chan...
The first line contains three integers n, l, r (1 ≤ n ≤ 105, 1 ≤ l ≤ r ≤ n) — the number of Vasya's cubes and the positions told by Stepan. The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ n) — the sequence of integers written on cubes in the Vasya's order. The third line contains the sequence b1, b2, ...
Print "LIE" (without quotes) if it is guaranteed that Stepan deceived his brother. In the other case, print "TRUTH" (without quotes).
null
In the first example there is a situation when Stepan said the truth. Initially the sequence of integers on the cubes was equal to [3, 4, 2, 3, 1]. Stepan could at first swap cubes on positions 2 and 3 (after that the sequence of integers on cubes became equal to [3, 2, 4, 3, 1]), and then swap cubes in positions 3 and...
[{"input": "5 2 4\n3 4 2 3 1\n3 2 3 4 1", "output": "TRUTH"}, {"input": "3 1 2\n1 2 3\n3 1 2", "output": "LIE"}, {"input": "4 2 4\n1 1 1 1\n1 1 1 1", "output": "TRUTH"}]
1,500
["*special", "constructive algorithms", "implementation", "sortings"]
52
[{"input": "5 2 4\r\n3 4 2 3 1\r\n3 2 3 4 1\r\n", "output": "TRUTH\r\n"}, {"input": "3 1 2\r\n1 2 3\r\n3 1 2\r\n", "output": "LIE\r\n"}, {"input": "4 2 4\r\n1 1 1 1\r\n1 1 1 1\r\n", "output": "TRUTH\r\n"}, {"input": "5 1 3\r\n2 2 2 1 2\r\n2 2 2 1 2\r\n", "output": "TRUTH\r\n"}, {"input": "7 1 4\r\n2 5 5 5 4 3 4\r\n2 5 ...
false
stdio
null
true
859/D
859
D
PyPy 3
TESTS
13
140
716,800
52623876
n = int(input()) # Using the same index I would for a tree m = 2**n P = [[int(x)/100.0 for x in input().split()] for _ in range(m)] state = [[0.0]*64 for _ in range(2*m)] for i in range(m): state[m+i][i] = 1.0 for i in reversed(range(1,m)): for j in range(m): for k in range(j,m): # x ...
19
62
0
30774075
n = int(input()) m = 1 << n p = [list(map(int, input().split())) for i in range(m)] u, x = [1] * m, [0] * m v, y = u[:], x[:] for i in range(n): d = 1 << i for j in range(m): s = d * (j // d ^ 1) v[j] = u[j] * sum(u[k] * p[j][k] for k in range(s, s + d)) / 100 y[j] = max(x[s: s + d]) + x...
MemSQL Start[c]UP 3.0 - Round 1
CF
2,017
2
256
Third Month Insanity
The annual college sports-ball tournament is approaching, which for trademark reasons we'll refer to as Third Month Insanity. There are a total of 2N teams participating in the tournament, numbered from 1 to 2N. The tournament lasts N rounds, with each round eliminating half the teams. The first round consists of 2N - ...
Input will begin with a line containing N (2 ≤ N ≤ 6). 2N lines follow, each with 2N integers. The j-th column of the i-th row indicates the percentage chance that team i will defeat team j, unless i = j, in which case the value will be 0. It is guaranteed that the i-th column of the j-th row plus the j-th column of t...
Print the maximum possible expected score over all possible brackets. Your answer must be correct to within an absolute or relative error of 10 - 9. Formally, let your answer be a, and the jury's answer be b. Your answer will be considered correct, if $${ \frac { | a - b | } { \operatorname* { m a x } ( 1, | b | ) } }...
null
In the first example, you should predict teams 1 and 4 to win in round 1, and team 1 to win in round 2. Recall that the winner you predict in round 2 must also be predicted as a winner in round 1.
[{"input": "2\n0 40 100 100\n60 0 40 40\n0 60 0 45\n0 60 55 0", "output": "1.75"}, {"input": "3\n0 0 100 0 100 0 0 0\n100 0 100 0 0 0 100 100\n0 0 0 100 100 0 0 0\n100 100 0 0 0 0 100 100\n0 100 0 100 0 0 100 0\n100 100 100 100 100 0 0 0\n100 0 100 0 0 100 0 0\n100 0 100 0 100 100 100 0", "output": "12"}, {"input": "2\...
2,100
["dp", "probabilities", "trees"]
19
[{"input": "2\r\n0 40 100 100\r\n60 0 40 40\r\n0 60 0 45\r\n0 60 55 0\r\n", "output": "1.75\r\n"}, {"input": "3\r\n0 0 100 0 100 0 0 0\r\n100 0 100 0 0 0 100 100\r\n0 0 0 100 100 0 0 0\r\n100 100 0 0 0 0 100 100\r\n0 100 0 100 0 0 100 0\r\n100 100 100 100 100 0 0 0\r\n100 0 100 0 0 100 0 0\r\n100 0 100 0 100 100 100 0\...
false
stdio
import sys def main(): input_path = sys.argv[1] correct_output_path = sys.argv[2] submission_output_path = sys.argv[3] # Read correct output try: with open(correct_output_path, 'r') as f: correct_line = f.readline().strip() correct = float(correct_line) except: ...
true
523/A
523
A
Python 3
TESTS
1
46
0
20797534
I=input R=range w,h=map(int,I().split()) t=[I()for _ in R(h)] for r in[[t[i][j]*2for i in R(h)][::-1]for j in R(w)]:s=''.join(r);print(s+'\n'+s)
24
46
0
10275176
w, h = map(int, input().split()) s = [] for i in range(h): s.append(input()) a = [] for i in range(w): a.append([0] * h) for i in range(h): for j in range(w): a[j][i] = s[i][j] for i in range(w): st = '' for c in a[i]: st += c * 2 print(st) print(st)
VK Cup 2015 - Qualification Round 2
CF
2,015
2
256
Rotate, Flip and Zoom
Polycarp is writing the prototype of a graphic editor. He has already made up his mind that the basic image transformations in his editor will be: rotate the image 90 degrees clockwise, flip the image horizontally (symmetry relative to the vertical line, that is, the right part of the image moves to the left, and vice ...
The first line contains two integers, w and h (1 ≤ w, h ≤ 100) — the width and height of an image in pixels. The picture is given in h lines, each line contains w characters — each character encodes the color of the corresponding pixel of the image. The line consists only of characters "." and "*", as the image is mono...
Print 2w lines, each containing 2h characters — the result of consecutive implementing of the three transformations, described above.
null
null
[{"input": "3 2\n.*.\n.*.", "output": "....\n....\n****\n****\n....\n...."}, {"input": "9 20\n**.......\n****.....\n******...\n*******..\n..******.\n....****.\n......***\n*.....***\n*********\n*********\n*********\n*********\n....**...\n...****..\n..******.\n.********\n****..***\n***...***\n**.....**\n*.......*", "outp...
1,200
["*special", "implementation"]
24
[{"input": "3 2\r\n.*.\r\n.*.\r\n", "output": "....\r\n....\r\n****\r\n****\r\n....\r\n....\r\n"}, {"input": "9 20\r\n**.......\r\n****.....\r\n******...\r\n*******..\r\n..******.\r\n....****.\r\n......***\r\n*.....***\r\n*********\r\n*********\r\n*********\r\n*********\r\n....**...\r\n...****..\r\n..******.\r\n.******...
false
stdio
null
true
859/G
859
G
PyPy 3-64
TESTS
2
46
512,000
132474480
from sys import stdin inp = stdin.readline def divisors(x): ans = [] u = x for i in range(2, u+1): if x//i == x/i: ans.append(i) while x//i == x/i: x //= i if x == 1: break return ans n = int(inp()) s = inp().strip() div = divisors(...
70
93
6,144,000
227486527
def factor(n): ps = [] for i in range(2, n): if i * i > n: break if n % i == 0: e = 0 while n % i == 0: e += 1 n //= i ps += [(i, e)] if n > 1: ps += [(n, 1)] return ps n = int(input()) a = list(map...
MemSQL Start[c]UP 3.0 - Round 1
CF
2,017
1
256
Circle of Numbers
n evenly spaced points have been marked around the edge of a circle. There is a number written at each point. You choose a positive real number k. Then you may repeatedly select a set of 2 or more points which are evenly spaced, and either increase all numbers at points in the set by k or decrease all numbers at points...
The first line of input contains an integer n (3 ≤ n ≤ 100000), the number of points along the circle. The following line contains a string s with exactly n digits, indicating the numbers initially present at each of the points, in clockwise order.
Print "YES" (without quotes) if there is some sequence of operations that results in all numbers being 0, otherwise "NO" (without quotes). You can print each letter in any case (upper or lower).
null
If we label the points from 1 to n, then for the first test case we can set k = 1. Then we increase the numbers at points 7 and 22 by 1, then decrease the numbers at points 7, 17, and 27 by 1, then decrease the numbers at points 4, 10, 16, 22, and 28 by 1.
[{"input": "30\n000100000100000110000000001100", "output": "YES"}, {"input": "6\n314159", "output": "NO"}]
3,000
["math"]
70
[{"input": "30\r\n000100000100000110000000001100\r\n", "output": "YES\r\n"}, {"input": "6\r\n314159\r\n", "output": "NO\r\n"}, {"input": "3\r\n000\r\n", "output": "YES\r\n"}, {"input": "15\r\n522085220852208\r\n", "output": "YES\r\n"}, {"input": "300\r\n518499551238825328417663140237955446550596254299485115465325550413...
false
stdio
null
true
22/E
22
E
Python 3
TESTS
9
60
204,800
212313098
from sys import stdin class UnionFind: def __init__(self, size:int): self.data = list(range(size)) def find(self, x:int)->int: if self.data[x] == x: return x self.data[x] = self.find(self.data[x]) return self.data[x] def union(self, x:int, y:int): x...
40
592
12,800,000
98755646
n = int(input()) g = [int(i) - 1 for i in input().split()] def solve(n, g): vertex_id = [-1]*n current_id = 0 starts_a_cycle = [-1]*n cycle_vertex_sample = [] start_on_cycle = [] cycle_index_by_ID = [] cycle_count = 0 for v in range(n): if vertex_id[v] != -1: continue ...
Codeforces Beta Round 22 (Div. 2 Only)
ICPC
2,010
2
256
Scheme
To learn as soon as possible the latest news about their favourite fundamentally new operating system, BolgenOS community from Nizhni Tagil decided to develop a scheme. According to this scheme a community member, who is the first to learn the news, calls some other member, the latter, in his turn, calls some third mem...
The first input line contains number n (2 ≤ n ≤ 105) — amount of BolgenOS community members. The second line contains n space-separated integer numbers fi (1 ≤ fi ≤ n, i ≠ fi) — index of a person, to whom calls a person with index i.
In the first line output one number — the minimum amount of instructions to add. Then output one of the possible variants to add these instructions into the scheme, one instruction in each line. If the solution is not unique, output any.
null
null
[{"input": "3\n3 3 2", "output": "1\n3 1"}, {"input": "7\n2 3 1 3 4 4 1", "output": "3\n2 5\n2 6\n3 7"}]
2,300
["dfs and similar", "graphs", "trees"]
40
[{"input": "3\r\n3 3 2\r\n", "output": "1\r\n3 1\r\n"}, {"input": "7\r\n2 3 1 3 4 4 1\r\n", "output": "3\r\n1 5\r\n1 6\r\n1 7\r\n"}, {"input": "2\r\n2 1\r\n", "output": "0\r\n"}, {"input": "3\r\n2 3 1\r\n", "output": "0\r\n"}, {"input": "4\r\n2 4 4 3\r\n", "output": "1\r\n4 1\r\n"}, {"input": "5\r\n5 3 5 2 3\r\n", "out...
false
stdio
import sys from collections import defaultdict def main(input_path, output_path, submission_output_path): # Read input with open(input_path) as f: n = int(f.readline()) f_list = list(map(int, f.readline().split())) # Read submission output with open(submission_output_path) as f: ...
true
523/A
523
A
PyPy 3
TESTS
1
93
0
10299918
def main(): w,h = [int(i) for i in input().split()] p = [] for i in range(h): s = input() p.append(s) p = zip(*p) for s in p: print("".join(s)*2) print("".join(s)*2) main()
24
46
0
144008423
w, h = map(int, input().split()) li = [] for i in range(h): temp = list(input()) li.append(temp) for i in (range(w)): temp = '' for j in (range(h)): temp += 2*li[j][i] print(temp) print(temp)
VK Cup 2015 - Qualification Round 2
CF
2,015
2
256
Rotate, Flip and Zoom
Polycarp is writing the prototype of a graphic editor. He has already made up his mind that the basic image transformations in his editor will be: rotate the image 90 degrees clockwise, flip the image horizontally (symmetry relative to the vertical line, that is, the right part of the image moves to the left, and vice ...
The first line contains two integers, w and h (1 ≤ w, h ≤ 100) — the width and height of an image in pixels. The picture is given in h lines, each line contains w characters — each character encodes the color of the corresponding pixel of the image. The line consists only of characters "." and "*", as the image is mono...
Print 2w lines, each containing 2h characters — the result of consecutive implementing of the three transformations, described above.
null
null
[{"input": "3 2\n.*.\n.*.", "output": "....\n....\n****\n****\n....\n...."}, {"input": "9 20\n**.......\n****.....\n******...\n*******..\n..******.\n....****.\n......***\n*.....***\n*********\n*********\n*********\n*********\n....**...\n...****..\n..******.\n.********\n****..***\n***...***\n**.....**\n*.......*", "outp...
1,200
["*special", "implementation"]
24
[{"input": "3 2\r\n.*.\r\n.*.\r\n", "output": "....\r\n....\r\n****\r\n****\r\n....\r\n....\r\n"}, {"input": "9 20\r\n**.......\r\n****.....\r\n******...\r\n*******..\r\n..******.\r\n....****.\r\n......***\r\n*.....***\r\n*********\r\n*********\r\n*********\r\n*********\r\n....**...\r\n...****..\r\n..******.\r\n.******...
false
stdio
null
true
523/A
523
A
Python 3
PRETESTS
1
46
0
10274372
w, h = map(int, input().split()) listGorizontal = [] listVertical = [] for i in range(h): listGorizontal.append(input()) for i in range(h): s = "" for j in listGorizontal[i]: s += j*2 listVertical.append(s) s = "" k = 1 for i in range(2*w): for j in range(h): s += 2 * listVertical[h ...
24
46
102,400
10275054
a, b = [int(i) for i in input().split()] matrix_in = [[0 for i in range(a)] for j in range(b)] for i in range(b): line = input() for j in range(a): matrix_in[i][j] = line[j] # Right rotate and flip matrix_rotated = [[0 for i in range(b)] for j in range(a)] for i in range(a): for j in range(b): ...
VK Cup 2015 - Qualification Round 2
CF
2,015
2
256
Rotate, Flip and Zoom
Polycarp is writing the prototype of a graphic editor. He has already made up his mind that the basic image transformations in his editor will be: rotate the image 90 degrees clockwise, flip the image horizontally (symmetry relative to the vertical line, that is, the right part of the image moves to the left, and vice ...
The first line contains two integers, w and h (1 ≤ w, h ≤ 100) — the width and height of an image in pixels. The picture is given in h lines, each line contains w characters — each character encodes the color of the corresponding pixel of the image. The line consists only of characters "." and "*", as the image is mono...
Print 2w lines, each containing 2h characters — the result of consecutive implementing of the three transformations, described above.
null
null
[{"input": "3 2\n.*.\n.*.", "output": "....\n....\n****\n****\n....\n...."}, {"input": "9 20\n**.......\n****.....\n******...\n*******..\n..******.\n....****.\n......***\n*.....***\n*********\n*********\n*********\n*********\n....**...\n...****..\n..******.\n.********\n****..***\n***...***\n**.....**\n*.......*", "outp...
1,200
["*special", "implementation"]
24
[{"input": "3 2\r\n.*.\r\n.*.\r\n", "output": "....\r\n....\r\n****\r\n****\r\n....\r\n....\r\n"}, {"input": "9 20\r\n**.......\r\n****.....\r\n******...\r\n*******..\r\n..******.\r\n....****.\r\n......***\r\n*.....***\r\n*********\r\n*********\r\n*********\r\n*********\r\n....**...\r\n...****..\r\n..******.\r\n.******...
false
stdio
null
true
523/A
523
A
Python 3
TESTS
1
61
0
16471976
w, h = map(int, input().split()) help = [input() for i in range(h)] data = [[None for i in range(h)] for j in range(w)] for i in range(w): for j in range(h): data[i][j] = help[j][i] for i in range(w): data[i] = data[i] + data[i][::-1] for i in range(w): a = '' for j in range(len(data[i])): ...
24
46
204,800
192440188
# LUOGU_RID: 101574102 m, n = map(int,input().split()) t = [input()for _ in range(n)] for r in [[t[i][j] * 2 for i in range(n)] for j in range(m)]: s=''.join(r); print(s + '\n' + s)
VK Cup 2015 - Qualification Round 2
CF
2,015
2
256
Rotate, Flip and Zoom
Polycarp is writing the prototype of a graphic editor. He has already made up his mind that the basic image transformations in his editor will be: rotate the image 90 degrees clockwise, flip the image horizontally (symmetry relative to the vertical line, that is, the right part of the image moves to the left, and vice ...
The first line contains two integers, w and h (1 ≤ w, h ≤ 100) — the width and height of an image in pixels. The picture is given in h lines, each line contains w characters — each character encodes the color of the corresponding pixel of the image. The line consists only of characters "." and "*", as the image is mono...
Print 2w lines, each containing 2h characters — the result of consecutive implementing of the three transformations, described above.
null
null
[{"input": "3 2\n.*.\n.*.", "output": "....\n....\n****\n****\n....\n...."}, {"input": "9 20\n**.......\n****.....\n******...\n*******..\n..******.\n....****.\n......***\n*.....***\n*********\n*********\n*********\n*********\n....**...\n...****..\n..******.\n.********\n****..***\n***...***\n**.....**\n*.......*", "outp...
1,200
["*special", "implementation"]
24
[{"input": "3 2\r\n.*.\r\n.*.\r\n", "output": "....\r\n....\r\n****\r\n****\r\n....\r\n....\r\n"}, {"input": "9 20\r\n**.......\r\n****.....\r\n******...\r\n*******..\r\n..******.\r\n....****.\r\n......***\r\n*.....***\r\n*********\r\n*********\r\n*********\r\n*********\r\n....**...\r\n...****..\r\n..******.\r\n.******...
false
stdio
null
true
216/E
216
E
Python 3
TESTS
4
92
0
11926259
k, b, n = map(int, input().split()) digits = list(map(int, input().split())) def conv(t): if t == 0: return k - 1 return t if b == 0: r = digits.count(0) print(r * (r + 1) // 2) else: count = dict() count[0] = 1 pref_sum = 0 answer = 0 for d in digits: pref_sum = ...
41
436
10,956,800
11926614
k, b, n = map(int, input().split()) digits = list(map(int, input().split())) def ans0(): j = -1 answer = 0 for i in range(n): if digits[i] != 0 or i < j: continue j = i while j < n and digits[j] == 0: j += 1 r = j - i answer += r * (r + 1) ...
Codeforces Round 133 (Div. 2)
CF
2,012
2
256
Martian Luck
You know that the Martians use a number system with base k. Digit b (0 ≤ b < k) is considered lucky, as the first contact between the Martians and the Earthlings occurred in year b (by Martian chronology). A digital root d(x) of number x is a number that consists of a single digit, resulting after cascading summing of...
The first line contains three integers k, b and n (2 ≤ k ≤ 109, 0 ≤ b < k, 1 ≤ n ≤ 105). The second line contains string s as a sequence of n integers, representing digits in the k-base notation: the i-th integer equals ai (0 ≤ ai < k) — the i-th digit of string s. The numbers in the lines are space-separated.
Print a single integer — the number of substrings that are lucky numbers. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
null
In the first sample the following substrings have the sought digital root: s[1... 2] = "3 2", s[1... 3] = "3 2 0", s[3... 4] = "0 5", s[4... 4] = "5" and s[2... 6] = "2 0 5 6 1".
[{"input": "10 5 6\n3 2 0 5 6 1", "output": "5"}, {"input": "7 6 4\n3 5 0 4", "output": "1"}, {"input": "257 0 3\n0 0 256", "output": "3"}]
2,000
["math", "number theory"]
41
[{"input": "10 5 6\r\n3 2 0 5 6 1\r\n", "output": "5"}, {"input": "7 6 4\r\n3 5 0 4\r\n", "output": "1"}, {"input": "257 0 3\r\n0 0 256\r\n", "output": "3"}, {"input": "2 1 1\r\n0\r\n", "output": "0"}, {"input": "2 0 20\r\n1 1 1 0 1 1 1 1 0 0 0 0 1 0 0 0 0 1 0 1\r\n", "output": "22"}, {"input": "100 29 33\r\n28 89 23 1...
false
stdio
null
true
22/E
22
E
PyPy 3
TESTS
8
278
0
95000968
import sys from array import array # noqa: F401 def input(): return sys.stdin.buffer.readline().decode('utf-8') n = int(input()) a = [0] + list(map(int, input().split())) rev = [[] for _ in range(n + 1)] indeg = [0] * (n + 1) for i in range(1, n + 1): indeg[a[i]] += 1 rev[a[i]].append(i) _indeg = ind...
40
1,714
90,931,200
157748457
order = [] # Psuedo-topological ordering (we don't care about cycles) visited = set() next_id = 0 nodes = {} # Maps from node to component id components = [] # Maps from component id to a set of nodes def dfs3(start, get_neighbors): ''' Iterative implementation of DFS. Doing DFS with rec...
Codeforces Beta Round 22 (Div. 2 Only)
ICPC
2,010
2
256
Scheme
To learn as soon as possible the latest news about their favourite fundamentally new operating system, BolgenOS community from Nizhni Tagil decided to develop a scheme. According to this scheme a community member, who is the first to learn the news, calls some other member, the latter, in his turn, calls some third mem...
The first input line contains number n (2 ≤ n ≤ 105) — amount of BolgenOS community members. The second line contains n space-separated integer numbers fi (1 ≤ fi ≤ n, i ≠ fi) — index of a person, to whom calls a person with index i.
In the first line output one number — the minimum amount of instructions to add. Then output one of the possible variants to add these instructions into the scheme, one instruction in each line. If the solution is not unique, output any.
null
null
[{"input": "3\n3 3 2", "output": "1\n3 1"}, {"input": "7\n2 3 1 3 4 4 1", "output": "3\n2 5\n2 6\n3 7"}]
2,300
["dfs and similar", "graphs", "trees"]
40
[{"input": "3\r\n3 3 2\r\n", "output": "1\r\n3 1\r\n"}, {"input": "7\r\n2 3 1 3 4 4 1\r\n", "output": "3\r\n1 5\r\n1 6\r\n1 7\r\n"}, {"input": "2\r\n2 1\r\n", "output": "0\r\n"}, {"input": "3\r\n2 3 1\r\n", "output": "0\r\n"}, {"input": "4\r\n2 4 4 3\r\n", "output": "1\r\n4 1\r\n"}, {"input": "5\r\n5 3 5 2 3\r\n", "out...
false
stdio
import sys from collections import defaultdict def main(input_path, output_path, submission_output_path): # Read input with open(input_path) as f: n = int(f.readline()) f_list = list(map(int, f.readline().split())) # Read submission output with open(submission_output_path) as f: ...
true
859/D
859
D
Python 3
TESTS
13
62
307,200
30405153
n = int(input()) props = [] def preproc(a): return float(a)/100. for i in range(pow(2,n)): props.append(list(map(preproc, input().split()))) wining_props = [] # list of lists. First index -- number of round, second -- num of team, value -- prop of wining wining_props_first_round = [] for i in range(0, (2 *...
19
218
3,993,600
52624119
n = int(input()) # Using the same index I would for a tree m = 2**n points = [0]*(2*m) points[1] = 2**(n-1) for i in range(1,m): x = points[i]//2 points[2*i] = x points[2*i+1] = x P = [[int(x)/100.0 for x in input().split()] for _ in range(m)] state = [[0.0]*64 for _ in range(2*m)] for i in range(m): ...
MemSQL Start[c]UP 3.0 - Round 1
CF
2,017
2
256
Third Month Insanity
The annual college sports-ball tournament is approaching, which for trademark reasons we'll refer to as Third Month Insanity. There are a total of 2N teams participating in the tournament, numbered from 1 to 2N. The tournament lasts N rounds, with each round eliminating half the teams. The first round consists of 2N - ...
Input will begin with a line containing N (2 ≤ N ≤ 6). 2N lines follow, each with 2N integers. The j-th column of the i-th row indicates the percentage chance that team i will defeat team j, unless i = j, in which case the value will be 0. It is guaranteed that the i-th column of the j-th row plus the j-th column of t...
Print the maximum possible expected score over all possible brackets. Your answer must be correct to within an absolute or relative error of 10 - 9. Formally, let your answer be a, and the jury's answer be b. Your answer will be considered correct, if $${ \frac { | a - b | } { \operatorname* { m a x } ( 1, | b | ) } }...
null
In the first example, you should predict teams 1 and 4 to win in round 1, and team 1 to win in round 2. Recall that the winner you predict in round 2 must also be predicted as a winner in round 1.
[{"input": "2\n0 40 100 100\n60 0 40 40\n0 60 0 45\n0 60 55 0", "output": "1.75"}, {"input": "3\n0 0 100 0 100 0 0 0\n100 0 100 0 0 0 100 100\n0 0 0 100 100 0 0 0\n100 100 0 0 0 0 100 100\n0 100 0 100 0 0 100 0\n100 100 100 100 100 0 0 0\n100 0 100 0 0 100 0 0\n100 0 100 0 100 100 100 0", "output": "12"}, {"input": "2\...
2,100
["dp", "probabilities", "trees"]
19
[{"input": "2\r\n0 40 100 100\r\n60 0 40 40\r\n0 60 0 45\r\n0 60 55 0\r\n", "output": "1.75\r\n"}, {"input": "3\r\n0 0 100 0 100 0 0 0\r\n100 0 100 0 0 0 100 100\r\n0 0 0 100 100 0 0 0\r\n100 100 0 0 0 0 100 100\r\n0 100 0 100 0 0 100 0\r\n100 100 100 100 100 0 0 0\r\n100 0 100 0 0 100 0 0\r\n100 0 100 0 100 100 100 0\...
false
stdio
import sys def main(): input_path = sys.argv[1] correct_output_path = sys.argv[2] submission_output_path = sys.argv[3] # Read correct output try: with open(correct_output_path, 'r') as f: correct_line = f.readline().strip() correct = float(correct_line) except: ...
true
20/C
20
C
PyPy 3
TESTS
30
436
17,100,800
83314710
from sys import stdin import heapq def main(): n, m = map(int, stdin.readline().split()) adj = [[] for _ in range(n + 1)] for _ in range(m): x, y, w = map(int, stdin.readline().split()) if x == y: continue adj[x].append((y, w)) adj[y].append((x, w)) max_val ...
33
233
26,624,000
208734321
from heapq import * from sys import * f = lambda: map(int, stdin.readline().split()) inf = 1 << 40 n, m = f() k = n + 1 g = [[] for i in range(k)] for j in range(m): u, v, l = f() g[u].append((v, l)) g[v].append((u, l)) d = [inf] * k d[1] = 0 p = [0] * k q = [1] while q: h = heappop(q) v, l = h % k,...
Codeforces Alpha Round 20 (Codeforces format)
CF
2,010
1
64
Dijkstra?
You are given a weighted undirected graph. The vertices are enumerated from 1 to n. Your task is to find the shortest path between the vertex 1 and the vertex n.
The first line contains two integers n and m (2 ≤ n ≤ 105, 0 ≤ m ≤ 105), where n is the number of vertices and m is the number of edges. Following m lines contain one edge each in form ai, bi and wi (1 ≤ ai, bi ≤ n, 1 ≤ wi ≤ 106), where ai, bi are edge endpoints and wi is the length of the edge. It is possible that th...
Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them.
null
null
[{"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "output": "1 4 3 5"}, {"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "output": "1 4 3 5"}]
1,900
["graphs", "shortest paths"]
33
[{"input": "5 6\r\n1 2 2\r\n2 5 5\r\n2 3 4\r\n1 4 1\r\n4 3 3\r\n3 5 1\r\n", "output": "1 4 3 5 "}, {"input": "5 6\r\n1 2 2\r\n2 5 5\r\n2 3 4\r\n1 4 1\r\n4 3 3\r\n3 5 1\r\n", "output": "1 4 3 5 "}, {"input": "2 1\r\n1 2 1\r\n", "output": "1 2 "}, {"input": "3 1\r\n1 2 1\r\n", "output": "-1"}, {"input": "3 3\r\n1 2 1\r\n...
false
stdio
null
true
383/A
383
A
Python 3
TESTS
2
93
307,200
72068713
from sys import stdin def f(n, s): n = n.rstrip('\n') s = s.rstrip('\n') s = s.split(' ') i = j = 0 ans = 0 ct = 0 while i < len(s): j = i while j < len(s) - 1 and s[j] == s[j+1]: j += 1 if j == len(s) - 1: return ans else: if s[j] == '1' and s[j+1] == '0': ct += 1 ans += ct i = j +...
42
92
6,041,600
17072338
def main(): input() i = res = 0 for c in input()[::2]: if c == "1": i += 1 else: res += i print(res) if __name__ == '__main__': main()
Codeforces Round 225 (Div. 1)
CF
2,014
1
256
Milking cows
Iahub helps his grandfather at the farm. Today he must milk the cows. There are n cows sitting in a row, numbered from 1 to n from left to right. Each cow is either facing to the left or facing to the right. When Iahub milks a cow, all the cows that see the current cow get scared and lose one unit of the quantity of mi...
The first line contains an integer n (1 ≤ n ≤ 200000). The second line contains n integers a1, a2, ..., an, where ai is 0 if the cow number i is facing left, and 1 if it is facing right.
Print a single integer, the minimum amount of lost milk. Please, do not write the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
null
In the first sample Iahub milks the cows in the following order: cow 3, cow 4, cow 2, cow 1. When he milks cow 3, cow 4 loses 1 unit of milk. After that, no more milk is lost.
[{"input": "4\n0 0 1 0", "output": "1"}, {"input": "5\n1 0 1 0 1", "output": "3"}]
1,600
["data structures", "greedy"]
42
[{"input": "4\r\n0 0 1 0\r\n", "output": "1"}, {"input": "5\r\n1 0 1 0 1\r\n", "output": "3"}, {"input": "50\r\n1 1 0 1 1 1 1 1 1 0 0 1 1 0 1 1 0 0 1 0 1 1 0 1 1 1 1 0 1 0 1 0 1 1 1 0 0 0 0 0 0 0 1 1 0 1 0 0 1 0\r\n", "output": "416"}, {"input": "100\r\n1 1 0 0 1 1 1 1 0 1 1 1 1 1 1 1 0 0 0 0 0 0 1 1 0 1 0 0 0 0 1 1 1 ...
false
stdio
null
true
20/C
20
C
Python 3
TESTS
30
686
18,329,600
74378577
import heapq n,m=map(int,input().split()) inf=10**10 d=[[] for _ in range(n)] b=[0]+[inf]*(n-1) c=[-1]*n hist=[(0,0)] for i in range(m): x,y,w=map(int,input().split()) d[x-1].append((w,y-1)) d[y-1].append((w,x-1)) while hist: min_p=heapq.heappop(hist) min_ind=min_p[1] for p in d[min_ind]: ...
33
264
29,491,200
214729466
from sys import stdin def input(): return stdin.readline()[:-1] INF = 10**18 N, E = map(int, input().split()) G = [[] for _ in range(N)] for _ in range(E): a, b, w = map(int, input().split()) a -= 1 b -= 1 G[a].append((b, w)) G[b].append((a, w)) dists = [INF] * N dists[0] = 0 parent = [-1] * N ...
Codeforces Alpha Round 20 (Codeforces format)
CF
2,010
1
64
Dijkstra?
You are given a weighted undirected graph. The vertices are enumerated from 1 to n. Your task is to find the shortest path between the vertex 1 and the vertex n.
The first line contains two integers n and m (2 ≤ n ≤ 105, 0 ≤ m ≤ 105), where n is the number of vertices and m is the number of edges. Following m lines contain one edge each in form ai, bi and wi (1 ≤ ai, bi ≤ n, 1 ≤ wi ≤ 106), where ai, bi are edge endpoints and wi is the length of the edge. It is possible that th...
Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them.
null
null
[{"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "output": "1 4 3 5"}, {"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "output": "1 4 3 5"}]
1,900
["graphs", "shortest paths"]
33
[{"input": "5 6\r\n1 2 2\r\n2 5 5\r\n2 3 4\r\n1 4 1\r\n4 3 3\r\n3 5 1\r\n", "output": "1 4 3 5 "}, {"input": "5 6\r\n1 2 2\r\n2 5 5\r\n2 3 4\r\n1 4 1\r\n4 3 3\r\n3 5 1\r\n", "output": "1 4 3 5 "}, {"input": "2 1\r\n1 2 1\r\n", "output": "1 2 "}, {"input": "3 1\r\n1 2 1\r\n", "output": "-1"}, {"input": "3 3\r\n1 2 1\r\n...
false
stdio
null
true
765/A
765
A
Python 3
TESTS
4
31
0
150983195
n,home,d=int(input()),input(),dict() for i in range(n): s=input() d[s[:3]]=s[5:] t=home while True: try: home=d[home] if home==t:print('home');break except: print('contest');break
23
46
0
136532132
#!/usr/bin/env python # coding=utf-8 ''' Author: Deean Date: 2021-11-22 23:29:43 LastEditTime: 2021-11-22 23:31:44 Description: Neverending competitions FilePath: CF765A.py ''' def func(): n = int(input()) home = input().strip() for _ in range(n): a, b = input().strip().split("->") print("home...
Codeforces Round 397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined)
CF
2,017
2
512
Neverending competitions
There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back. Jinotega's best friends, team ...
In the first line of input there is a single integer n: the number of Jinotega's flights (1 ≤ n ≤ 100). In the second line there is a string of 3 capital Latin letters: the name of Jinotega's home airport. In the next n lines there is flight information, one flight per line, in form "XXX->YYY", where "XXX" is the name ...
If Jinotega is now at home, print "home" (without quotes), otherwise print "contest".
null
In the first sample Jinotega might first fly from SVO to CDG and back, and then from SVO to LHR and back, so now they should be at home. In the second sample Jinotega must now be at RAP because a flight from RAP back to SVO is not on the list.
[{"input": "4\nSVO\nSVO->CDG\nLHR->SVO\nSVO->LHR\nCDG->SVO", "output": "home"}, {"input": "3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP", "output": "contest"}]
900
["implementation", "math"]
23
[{"input": "4\r\nSVO\r\nSVO->CDG\r\nLHR->SVO\r\nSVO->LHR\r\nCDG->SVO\r\n", "output": "home\r\n"}, {"input": "3\r\nSVO\r\nSVO->HKT\r\nHKT->SVO\r\nSVO->RAP\r\n", "output": "contest\r\n"}, {"input": "1\r\nESJ\r\nESJ->TSJ\r\n", "output": "contest\r\n"}, {"input": "2\r\nXMR\r\nFAJ->XMR\r\nXMR->FAJ\r\n", "output": "home\r\n"...
false
stdio
null
true
961/C
961
C
PyPy 3
TESTS
5
124
2,355,200
105153792
a=int(input()) l=[] total=0 for i in range(4): line='' for x in [0]*a: line+=input() l.append(line) input() if i!=3 else 0 l=sorted(l,key=lambda i: i[0::2].count('1'))[::-1] for z,v in enumerate(l): if z<2: for i in range(a**2): total += v[i]!='0' if i%2 else v[i]!='...
19
46
0
211838146
new_n = int(input()) c = [0] * 4 for k in range(4): for i in range(new_n): s = input() for j in range(new_n): if (i + j) % 2 != int(s[j]): c[k] += 1 if k < 3: input() c.sort() result = c[0] + c[1] + 2 * new_n * new_n - c[2] - c[3] print(result)
Educational Codeforces Round 41 (Rated for Div. 2)
ICPC
2,018
1
256
Chessboard
Magnus decided to play a classic chess game. Though what he saw in his locker shocked him! His favourite chessboard got broken into 4 pieces, each of size n by n, n is always odd. And what's even worse, some squares were of wrong color. j-th square of the i-th row of k-th piece of the board has color ak, i, j; 1 being ...
The first line contains odd integer n (1 ≤ n ≤ 100) — the size of all pieces of the board. Then 4 segments follow, each describes one piece of the board. Each consists of n lines of n characters; j-th one of i-th line is equal to 1 if the square is black initially and 0 otherwise. Segments are separated by an empty li...
Print one number — minimum number of squares Magnus should recolor to be able to obtain a valid chessboard.
null
null
[{"input": "1\n0\n0\n1\n0", "output": "1"}, {"input": "3\n101\n010\n101\n101\n000\n101\n010\n101\n011\n010\n101\n010", "output": "2"}]
1,400
["bitmasks", "brute force", "implementation"]
19
[{"input": "1\r\n0\r\n\r\n0\r\n\r\n1\r\n\r\n0\r\n", "output": "1\r\n"}, {"input": "3\r\n101\r\n010\r\n101\r\n\r\n101\r\n000\r\n101\r\n\r\n010\r\n101\r\n011\r\n\r\n010\r\n101\r\n010\r\n", "output": "2\r\n"}, {"input": "3\r\n000\r\n000\r\n000\r\n\r\n111\r\n111\r\n111\r\n\r\n111\r\n111\r\n111\r\n\r\n000\r\n000\r\n000\r\n"...
false
stdio
null
true
62/D
62
D
Python 3
TESTS
7
92
0
139385183
def build_home_path(n: int, m: int, old_path: list) -> list: """ Parameters: :n (int): number of rooms :m (int): number of corridors :old_path (list): old build path :return: new build path """ list_graf = {} m = len(old_path) - 1 for i in range(m): if old_path[i] - 1 in ...
30
124
819,200
187019306
n,m = map(int,input().split()) m+=1 p = list(map(lambda x:int(x)-1,input().split())) a = [0]*m q = [[False]*n for i in range(n)] d = [[] for i in range(n)] for i in range(1,m): d[p[i]].append(p[i-1]) d[p[i-1]].append(p[i]) for i in range(n): d[i].sort() s = [(p[0],True,p[0])] l = 0 while s: v,f,vv = s[-...
Codeforces Beta Round 58
CF
2,011
2
256
Wormhouse
Arnie the Worm has finished eating an apple house yet again and decided to move. He made up his mind on the plan, the way the rooms are located and how they are joined by corridors. He numbered all the rooms from 1 to n. All the corridors are bidirectional. Arnie wants the new house to look just like the previous one....
The first line contains two integers n and m (3 ≤ n ≤ 100, 3 ≤ m ≤ 2000). It is the number of rooms and corridors in Arnie's house correspondingly. The next line contains m + 1 positive integers that do not exceed n. They are the description of Arnie's old path represented as a list of rooms he visited during the gnawi...
Print m + 1 positive integers that do not exceed n. Those numbers are the description of the new path, according to which Arnie should gnaw out his new house. If it is impossible to find new path you should print out No solution. The first number in your answer should be equal to the last one. Also it should be equal t...
null
null
[{"input": "3 3\n1 2 3 1", "output": "1 3 2 1"}, {"input": "3 3\n1 3 2 1", "output": "No solution"}]
2,300
["dfs and similar", "graphs"]
30
[{"input": "3 3\r\n1 2 3 1\r\n", "output": "1 3 2 1 "}, {"input": "3 3\r\n1 3 2 1\r\n", "output": "No solution"}, {"input": "4 4\r\n1 2 4 3 1\r\n", "output": "1 3 4 2 1 "}, {"input": "6 7\r\n3 2 4 1 6 5 1 3\r\n", "output": "No solution"}, {"input": "8 12\r\n4 6 5 1 4 3 1 8 3 7 8 5 4\r\n", "output": "4 6 5 1 4 3 1 8 7 3...
false
stdio
null
true
376/B
376
B
PyPy 3
TESTS
28
202
3,481,600
68067323
n,m=map(int,input().split()) A=[0]*(n+1) ans=0 for _ in range(m): a,b,c=map(int,input().split()) A[a]+=c A[b]-=c for i in range(n): if A[i]>=0: ans+=A[i] print(ans)
29
46
0
155106961
l = input().split() n, m = int(l[0]), int(l[1]) graph = {} for _ in range(m): a, b, c = [int(x) for x in input().split()] if graph.get(a): graph[a].append((b, c)) else: graph[a] = [(b, c)] debt = [0] * (n+1) visited = [False] * (n+1) for i in range(1, n+1): if visited[i]: cont...
Codeforces Round 221 (Div. 2)
CF
2,013
1
256
I.O.U.
Imagine that there is a group of three friends: A, B and С. A owes B 20 rubles and B owes C 20 rubles. The total sum of the debts is 40 rubles. You can see that the debts are not organized in a very optimal manner. Let's rearrange them like that: assume that A owes C 20 rubles and B doesn't owe anything to anybody. The...
The first line contains two integers n and m (1 ≤ n ≤ 100; 0 ≤ m ≤ 104). The next m lines contain the debts. The i-th line contains three integers ai, bi, ci (1 ≤ ai, bi ≤ n; ai ≠ bi; 1 ≤ ci ≤ 100), which mean that person ai owes person bi ci rubles. Assume that the people are numbered by integers from 1 to n. It is ...
Print a single integer — the minimum sum of debts in the optimal rearrangement.
null
In the first sample, you can assume that person number 1 owes 8 rubles to person number 2, 1 ruble to person number 3 and 1 ruble to person number 4. He doesn't owe anybody else anything. In the end, the total debt equals 10. In the second sample, there are no debts. In the third sample, you can annul all the debts.
[{"input": "5 3\n1 2 10\n2 3 1\n2 4 1", "output": "10"}, {"input": "3 0", "output": "0"}, {"input": "4 3\n1 2 1\n2 3 1\n3 1 1", "output": "0"}]
1,300
["implementation"]
29
[{"input": "5 3\r\n1 2 10\r\n2 3 1\r\n2 4 1\r\n", "output": "10\r\n"}, {"input": "3 0\r\n", "output": "0\r\n"}, {"input": "4 3\r\n1 2 1\r\n2 3 1\r\n3 1 1\r\n", "output": "0\r\n"}, {"input": "20 28\r\n1 5 6\r\n1 12 7\r\n1 13 4\r\n1 15 7\r\n1 20 3\r\n2 4 1\r\n2 15 6\r\n3 5 3\r\n3 8 10\r\n3 13 8\r\n3 20 6\r\n4 6 10\r\n4 1...
false
stdio
null
true
376/B
376
B
Python 3
TESTS
28
77
0
119685638
n, m = map(int, input().split()) l = [0]*102 for i in range(m): a, b, c = map(int, input().split()) l[a] += c l[b] -= c sum = 0 for i in range(n): if l[i] > 0: sum += l[i] print(sum)
29
46
0
168900387
n,m=[int(i) for i in input().split()] ; dic=dict() ; cou=0 for i in range(1,n+1): dic[i]=0 for i in range(m): a,b,c=list(map(int,input().split())) dic[a]-=c ; dic[b]+=c for i in dic.values(): if i>0:cou+=i print(cou)
Codeforces Round 221 (Div. 2)
CF
2,013
1
256
I.O.U.
Imagine that there is a group of three friends: A, B and С. A owes B 20 rubles and B owes C 20 rubles. The total sum of the debts is 40 rubles. You can see that the debts are not organized in a very optimal manner. Let's rearrange them like that: assume that A owes C 20 rubles and B doesn't owe anything to anybody. The...
The first line contains two integers n and m (1 ≤ n ≤ 100; 0 ≤ m ≤ 104). The next m lines contain the debts. The i-th line contains three integers ai, bi, ci (1 ≤ ai, bi ≤ n; ai ≠ bi; 1 ≤ ci ≤ 100), which mean that person ai owes person bi ci rubles. Assume that the people are numbered by integers from 1 to n. It is ...
Print a single integer — the minimum sum of debts in the optimal rearrangement.
null
In the first sample, you can assume that person number 1 owes 8 rubles to person number 2, 1 ruble to person number 3 and 1 ruble to person number 4. He doesn't owe anybody else anything. In the end, the total debt equals 10. In the second sample, there are no debts. In the third sample, you can annul all the debts.
[{"input": "5 3\n1 2 10\n2 3 1\n2 4 1", "output": "10"}, {"input": "3 0", "output": "0"}, {"input": "4 3\n1 2 1\n2 3 1\n3 1 1", "output": "0"}]
1,300
["implementation"]
29
[{"input": "5 3\r\n1 2 10\r\n2 3 1\r\n2 4 1\r\n", "output": "10\r\n"}, {"input": "3 0\r\n", "output": "0\r\n"}, {"input": "4 3\r\n1 2 1\r\n2 3 1\r\n3 1 1\r\n", "output": "0\r\n"}, {"input": "20 28\r\n1 5 6\r\n1 12 7\r\n1 13 4\r\n1 15 7\r\n1 20 3\r\n2 4 1\r\n2 15 6\r\n3 5 3\r\n3 8 10\r\n3 13 8\r\n3 20 6\r\n4 6 10\r\n4 1...
false
stdio
null
true
20/C
20
C
Python 3
TESTS
30
592
40,448,000
10739823
from sys import stdin, stdout from collections import deque from operator import itemgetter # trying out Moore's algorithm again, this time with edges # sorted by their weight within the adjacency list def moore(graph, source, target): INF = 1 << 20 n = len(graph) Q = deque([source]) in_queu...
33
280
34,304,000
208891058
from heapq import heappop, heappush from math import inf from sys import stdin def dijkstra(graph, start): dist = [inf] * len(graph) dist[start] = 0 parent = [-1] * len(graph) q = [(0, start)] while q: d, u = heappop(q) if d > dist[u]: continue for v, w in gr...
Codeforces Alpha Round 20 (Codeforces format)
CF
2,010
1
64
Dijkstra?
You are given a weighted undirected graph. The vertices are enumerated from 1 to n. Your task is to find the shortest path between the vertex 1 and the vertex n.
The first line contains two integers n and m (2 ≤ n ≤ 105, 0 ≤ m ≤ 105), where n is the number of vertices and m is the number of edges. Following m lines contain one edge each in form ai, bi and wi (1 ≤ ai, bi ≤ n, 1 ≤ wi ≤ 106), where ai, bi are edge endpoints and wi is the length of the edge. It is possible that th...
Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them.
null
null
[{"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "output": "1 4 3 5"}, {"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "output": "1 4 3 5"}]
1,900
["graphs", "shortest paths"]
33
[{"input": "5 6\r\n1 2 2\r\n2 5 5\r\n2 3 4\r\n1 4 1\r\n4 3 3\r\n3 5 1\r\n", "output": "1 4 3 5 "}, {"input": "5 6\r\n1 2 2\r\n2 5 5\r\n2 3 4\r\n1 4 1\r\n4 3 3\r\n3 5 1\r\n", "output": "1 4 3 5 "}, {"input": "2 1\r\n1 2 1\r\n", "output": "1 2 "}, {"input": "3 1\r\n1 2 1\r\n", "output": "-1"}, {"input": "3 3\r\n1 2 1\r\n...
false
stdio
null
true
20/C
20
C
PyPy 3-64
TESTS
30
265
37,683,200
208677279
#from math import ceil, sqrt #from collections import defaultdict from heapq import heapify, heappush, heappop import io, os, sys input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline #input().decode().rstrip('\r\n') #print = lambda x: sys.stdout.write(str(x) + "\n") II = lambda: int(input()) MII = lambda: ...
33
295
28,876,800
168909132
import sys from heapq import heappop, heappush input = sys.stdin.readline def dijkstra(graph, start=0): n = len(graph) dist, parents = [float('inf')] * n, [-1] * n dist[start] = 0.0 queue = [(0.0, start)] while queue: path_len, v = heappop(queue) if path_len == dist[v]: ...
Codeforces Alpha Round 20 (Codeforces format)
CF
2,010
1
64
Dijkstra?
You are given a weighted undirected graph. The vertices are enumerated from 1 to n. Your task is to find the shortest path between the vertex 1 and the vertex n.
The first line contains two integers n and m (2 ≤ n ≤ 105, 0 ≤ m ≤ 105), where n is the number of vertices and m is the number of edges. Following m lines contain one edge each in form ai, bi and wi (1 ≤ ai, bi ≤ n, 1 ≤ wi ≤ 106), where ai, bi are edge endpoints and wi is the length of the edge. It is possible that th...
Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them.
null
null
[{"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "output": "1 4 3 5"}, {"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "output": "1 4 3 5"}]
1,900
["graphs", "shortest paths"]
33
[{"input": "5 6\r\n1 2 2\r\n2 5 5\r\n2 3 4\r\n1 4 1\r\n4 3 3\r\n3 5 1\r\n", "output": "1 4 3 5 "}, {"input": "5 6\r\n1 2 2\r\n2 5 5\r\n2 3 4\r\n1 4 1\r\n4 3 3\r\n3 5 1\r\n", "output": "1 4 3 5 "}, {"input": "2 1\r\n1 2 1\r\n", "output": "1 2 "}, {"input": "3 1\r\n1 2 1\r\n", "output": "-1"}, {"input": "3 3\r\n1 2 1\r\n...
false
stdio
null
true
20/C
20
C
Python 3
TESTS
30
686
61,337,600
208020050
import heapq INF = 10 ** 9 class Edge: def __init__(self, u, v, weight): self.u = u self.v = v self.weight = weight def main(): n, m = map(int, input().split()) edg = [[] for _ in range(n)] for _ in range(m): a, b, w = map(int, input().split()) edg[a - 1]....
33
342
30,310,400
191299941
import heapq import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def dijkstra(s): dist = [inf] * (n + 1) dist[s] = 0 visit = [0] * (n + 1) parent = [-1] * (n + 1) p = [] heapq.heappush(p, (dist[s], s)) while p: d, u = heapq.heappop(p) if dist[u] <...
Codeforces Alpha Round 20 (Codeforces format)
CF
2,010
1
64
Dijkstra?
You are given a weighted undirected graph. The vertices are enumerated from 1 to n. Your task is to find the shortest path between the vertex 1 and the vertex n.
The first line contains two integers n and m (2 ≤ n ≤ 105, 0 ≤ m ≤ 105), where n is the number of vertices and m is the number of edges. Following m lines contain one edge each in form ai, bi and wi (1 ≤ ai, bi ≤ n, 1 ≤ wi ≤ 106), where ai, bi are edge endpoints and wi is the length of the edge. It is possible that th...
Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them.
null
null
[{"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "output": "1 4 3 5"}, {"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "output": "1 4 3 5"}]
1,900
["graphs", "shortest paths"]
33
[{"input": "5 6\r\n1 2 2\r\n2 5 5\r\n2 3 4\r\n1 4 1\r\n4 3 3\r\n3 5 1\r\n", "output": "1 4 3 5 "}, {"input": "5 6\r\n1 2 2\r\n2 5 5\r\n2 3 4\r\n1 4 1\r\n4 3 3\r\n3 5 1\r\n", "output": "1 4 3 5 "}, {"input": "2 1\r\n1 2 1\r\n", "output": "1 2 "}, {"input": "3 1\r\n1 2 1\r\n", "output": "-1"}, {"input": "3 3\r\n1 2 1\r\n...
false
stdio
null
true
20/C
20
C
Python 3
TESTS
30
608
21,094,400
42408979
import sys import heapq V, E = map(int, input().strip().split()) adj = [[] for _ in range(V+1)] for _ in range(E): u, v, w = map(int, input().strip().split()) adj[u].append((v, w)) adj[v].append((u, w)) #INF = 1000000000000 INF = sys.maxsize prev = [-1]*(V+1) dist = [INF]*(V+1) vis = [0]*(V+1) dist[1] =...
33
358
47,206,400
129270968
""" https://codeforces.com/problemset/problem/20/C?locale=ru """ from heapq import heappop, heappush from collections import defaultdict from sys import stdout, stdin from io import IOBase, BytesIO from os import read, write, fstat BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): ...
Codeforces Alpha Round 20 (Codeforces format)
CF
2,010
1
64
Dijkstra?
You are given a weighted undirected graph. The vertices are enumerated from 1 to n. Your task is to find the shortest path between the vertex 1 and the vertex n.
The first line contains two integers n and m (2 ≤ n ≤ 105, 0 ≤ m ≤ 105), where n is the number of vertices and m is the number of edges. Following m lines contain one edge each in form ai, bi and wi (1 ≤ ai, bi ≤ n, 1 ≤ wi ≤ 106), where ai, bi are edge endpoints and wi is the length of the edge. It is possible that th...
Write the only integer -1 in case of no path. Write the shortest path in opposite case. If there are many solutions, print any of them.
null
null
[{"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "output": "1 4 3 5"}, {"input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1", "output": "1 4 3 5"}]
1,900
["graphs", "shortest paths"]
33
[{"input": "5 6\r\n1 2 2\r\n2 5 5\r\n2 3 4\r\n1 4 1\r\n4 3 3\r\n3 5 1\r\n", "output": "1 4 3 5 "}, {"input": "5 6\r\n1 2 2\r\n2 5 5\r\n2 3 4\r\n1 4 1\r\n4 3 3\r\n3 5 1\r\n", "output": "1 4 3 5 "}, {"input": "2 1\r\n1 2 1\r\n", "output": "1 2 "}, {"input": "3 1\r\n1 2 1\r\n", "output": "-1"}, {"input": "3 3\r\n1 2 1\r\n...
false
stdio
null
true
765/A
765
A
Python 3
TESTS
4
46
4,608,000
25318933
n = int(input()) native = input() a = [[str(i) for i in input().split("->")] for j in range(n)] A = set() B = set() for i in range(n): A.add(a[i][0]) B.add(a[i][1]) if A == B: print("home") else: print("contest")
23
46
0
153767018
n = int(input()) start = input() empty_array = [] for i in range(n): flights = input() flights = flights.split('->') empty_array.append(flights) goes_back = [] goes_to = [] for i in range(len(empty_array)): if (empty_array[i])[1] == start: goes_back.append((empty_array[i])[0]) if (empty_a...
Codeforces Round 397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined)
CF
2,017
2
512
Neverending competitions
There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back. Jinotega's best friends, team ...
In the first line of input there is a single integer n: the number of Jinotega's flights (1 ≤ n ≤ 100). In the second line there is a string of 3 capital Latin letters: the name of Jinotega's home airport. In the next n lines there is flight information, one flight per line, in form "XXX->YYY", where "XXX" is the name ...
If Jinotega is now at home, print "home" (without quotes), otherwise print "contest".
null
In the first sample Jinotega might first fly from SVO to CDG and back, and then from SVO to LHR and back, so now they should be at home. In the second sample Jinotega must now be at RAP because a flight from RAP back to SVO is not on the list.
[{"input": "4\nSVO\nSVO->CDG\nLHR->SVO\nSVO->LHR\nCDG->SVO", "output": "home"}, {"input": "3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP", "output": "contest"}]
900
["implementation", "math"]
23
[{"input": "4\r\nSVO\r\nSVO->CDG\r\nLHR->SVO\r\nSVO->LHR\r\nCDG->SVO\r\n", "output": "home\r\n"}, {"input": "3\r\nSVO\r\nSVO->HKT\r\nHKT->SVO\r\nSVO->RAP\r\n", "output": "contest\r\n"}, {"input": "1\r\nESJ\r\nESJ->TSJ\r\n", "output": "contest\r\n"}, {"input": "2\r\nXMR\r\nFAJ->XMR\r\nXMR->FAJ\r\n", "output": "home\r\n"...
false
stdio
null
true
388/C
388
C
PyPy 3
TESTS
10
218
4,710,400
92522423
from sys import stdin from collections import deque import heapq n = int(stdin.readline()) piles = [] for x in range(n): a = deque([int(x) for x in stdin.readline().split()][1:]) piles.append(a) ciel = [(-x[0],i) for i,x in enumerate(piles)] jiro = [(-x[-1],i) for i,x in enumerate(piles)] heapq.heapify(ciel)...
43
46
102,400
153944789
import collections import math import sys need_two = 0 def main(): n = int(input()) odds = [] first = 0 second = 0 for i in range(n): c = list(map(int, input().split()))[1:] if len(c) % 2 == 1: odds.append(c[len(c) // 2]) first += sum(c[:len(c) // 2]) ...
Codeforces Round 228 (Div. 1)
CF
2,014
1
256
Fox and Card Game
Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card. The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom o...
The first line contain an integer n (1 ≤ n ≤ 100). Each of the next n lines contains a description of the pile: the first integer in the line is si (1 ≤ si ≤ 100) — the number of cards in the i-th pile; then follow si positive integers c1, c2, ..., ck, ..., csi (1 ≤ ck ≤ 1000) — the sequence of the numbers on the cards...
Print two integers: the sum of Ciel's cards and the sum of Jiro's cards if they play optimally.
null
In the first example, Ciel will take the cards with number 100 and 1, Jiro will take the card with number 10. In the second example, Ciel will take cards with numbers 2, 8, 6, 5, 9 and Jiro will take cards with numbers 4, 7, 1, 3.
[{"input": "2\n1 100\n2 1 10", "output": "101 10"}, {"input": "1\n9 2 8 6 5 9 4 7 1 3", "output": "30 15"}, {"input": "3\n3 1 3 2\n3 5 4 6\n2 8 7", "output": "18 18"}, {"input": "3\n3 1000 1000 1000\n6 1000 1000 1000 1000 1000 1000\n5 1000 1000 1000 1000 1000", "output": "7000 7000"}]
2,000
["games", "greedy", "sortings"]
43
[{"input": "2\r\n1 100\r\n2 1 10\r\n", "output": "101 10\r\n"}, {"input": "1\r\n9 2 8 6 5 9 4 7 1 3\r\n", "output": "30 15\r\n"}, {"input": "3\r\n3 1 3 2\r\n3 5 4 6\r\n2 8 7\r\n", "output": "18 18\r\n"}, {"input": "3\r\n3 1000 1000 1000\r\n6 1000 1000 1000 1000 1000 1000\r\n5 1000 1000 1000 1000 1000\r\n", "output": "7...
false
stdio
null
true
873/C
873
C
PyPy 3-64
TESTS
12
92
1,843,200
183824927
import sys input = sys.stdin.readline n, m, k = map(int, input().split()) a1, a2 = 0, 0 for w in zip(*[input()[:-1].split() for _ in range(n)]): k = min(n, k) c = w[:k].count('1') a = c b = 0 f = 0 for i in range(n-k): if w[i+k] == '1': c += 1 if w[i] == '1': ...
20
46
0
181353049
num,num2,num3=map(int,input().split()) cont1,cont2=0,0 result=[list(map(int,input().split())) for i in range(num)] for i in zip(*result): a,b=0,0 for j in range(num-num3+1): f,h=sum(i[j:j + num3]),sum(i[:j]) if f>a:a,b=f,h cont1 += a cont2 += b print(cont1,cont2,end=' ')
Educational Codeforces Round 30
ICPC
2,017
1
256
Strange Game On Matrix
Ivan is playing a strange game. He has a matrix a with n rows and m columns. Each element of the matrix is equal to either 0 or 1. Rows and columns are 1-indexed. Ivan can replace any number of ones in this matrix with zeroes. After that, his score in the game will be calculated as follows: 1. Initially Ivan's score ...
The first line contains three integer numbers n, m and k (1 ≤ k ≤ n ≤ 100, 1 ≤ m ≤ 100). Then n lines follow, i-th of them contains m integer numbers — the elements of i-th row of matrix a. Each number is either 0 or 1.
Print two numbers: the maximum possible score Ivan can get and the minimum number of replacements required to get this score.
null
In the first example Ivan will replace the element a1, 2.
[{"input": "4 3 2\n0 1 0\n1 0 1\n0 1 0\n1 1 1", "output": "4 1"}, {"input": "3 2 1\n1 0\n0 1\n0 0", "output": "2 0"}]
1,600
["greedy", "two pointers"]
20
[{"input": "4 3 2\r\n0 1 0\r\n1 0 1\r\n0 1 0\r\n1 1 1\r\n", "output": "4 1\r\n"}, {"input": "3 2 1\r\n1 0\r\n0 1\r\n0 0\r\n", "output": "2 0\r\n"}, {"input": "3 4 2\r\n0 1 1 1\r\n1 0 1 1\r\n1 0 0 1\r\n", "output": "7 0\r\n"}, {"input": "3 57 3\r\n1 0 0 1 1 0 1 1 0 0 0 0 1 0 1 0 0 0 0 0 0 1 0 0 0 0 1 0 0 1 1 0 1 1 1 1 0...
false
stdio
null
true
466/D
466
D
PyPy 3-64
TESTS
5
124
9,420,800
216071842
import sys import os # import time import bisect # import functools import math import random # import re from collections import Counter, defaultdict, deque # from copy import deepcopy from functools import cmp_to_key, lru_cache, reduce from heapq import heapify, heappop, heappush, heappushpop, nlargest, nsmallest fr...
28
77
1,433,600
231045511
f = lambda: map(int, input().split()) n, h = f() s, i = 1, 0 for j in f(): j = h - j if j < 0 or abs(j - i) > 1: exit(print(0)) if j <= i: s = s * (j + 1) % 1000000007 i = j print(0 if i > 1 else s)
Codeforces Round 266 (Div. 2)
CF
2,014
1
256
Increase Sequence
Peter has a sequence of integers a1, a2, ..., an. Peter wants all numbers in the sequence to equal h. He can perform the operation of "adding one on the segment [l, r]": add one to all elements of the sequence with indices from l to r (inclusive). At that, Peter never chooses any element as the beginning of the segment...
The first line contains two integers n, h (1 ≤ n, h ≤ 2000). The next line contains n integers a1, a2, ..., an (0 ≤ ai ≤ 2000).
Print a single integer — the answer to the problem modulo 1000000007 (109 + 7).
null
null
[{"input": "3 2\n1 1 1", "output": "4"}, {"input": "5 1\n1 1 1 1 1", "output": "1"}, {"input": "4 3\n3 2 1 1", "output": "0"}]
2,100
["combinatorics", "dp"]
28
[{"input": "3 2\r\n1 1 1\r\n", "output": "4\r\n"}, {"input": "5 1\r\n1 1 1 1 1\r\n", "output": "1\r\n"}, {"input": "4 3\r\n3 2 1 1\r\n", "output": "0\r\n"}, {"input": "1 2000\r\n2000\r\n", "output": "1\r\n"}, {"input": "3 2\r\n2 1 1\r\n", "output": "2\r\n"}, {"input": "3 4\r\n4 3 2\r\n", "output": "0\r\n"}, {"input": "...
false
stdio
null
true
187/A
187
A
PyPy 3
TESTS
5
186
23,142,400
31480206
n = int(input()) l1 = [int(x) for x in input().split()] l2 = [int(x) for x in input().split()] used = set() j = len(l1)-1 answ = 0 for i in range(len(l2)-1, -1, -1): if l2[i] in used: continue while j >= 0 and l1[j] != l2[i]: used.add(l1[j]) j-=1 answ += 1 if j >= 0 and ...
58
340
31,539,200
203854212
import sys input = lambda: sys.stdin.readline().rstrip() N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) pre = -1 j = 0 for i in range(N): while j<N and A[i]!=B[j]: j+=1 if j<N and A[i]==B[j]: pre = i+1 print(N-pre)
Codeforces Round 119 (Div. 1)
CF
2,012
2
256
Permutations
Happy PMP is freshman and he is learning about algorithmic problems. He enjoys playing algorithmic games a lot. One of the seniors gave Happy PMP a nice game. He is given two permutations of numbers 1 through n and is asked to convert the first one to the second. In one move he can remove the last number from the perm...
The first line contains a single integer n (1 ≤ n ≤ 2·105) — the quantity of the numbers in the both given permutations. Next line contains n space-separated integers — the first permutation. Each number between 1 to n will appear in the permutation exactly once. Next line describe the second permutation in the same ...
Print a single integer denoting the minimum number of moves required to convert the first permutation to the second.
null
In the first sample, he removes number 1 from end of the list and places it at the beginning. After that he takes number 2 and places it between 1 and 3. In the second sample, he removes number 5 and inserts it after 1. In the third sample, the sequence of changes are like this: - 1 5 2 3 4 - 1 4 5 2 3 - 1 3 4 5 2 -...
[{"input": "3\n3 2 1\n1 2 3", "output": "2"}, {"input": "5\n1 2 3 4 5\n1 5 2 3 4", "output": "1"}, {"input": "5\n1 5 2 3 4\n1 2 3 4 5", "output": "3"}]
1,500
["greedy"]
58
[{"input": "3\r\n3 2 1\r\n1 2 3\r\n", "output": "2\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n1 5 2 3 4\r\n", "output": "1\r\n"}, {"input": "5\r\n1 5 2 3 4\r\n1 2 3 4 5\r\n", "output": "3\r\n"}, {"input": "1\r\n1\r\n1\r\n", "output": "0\r\n"}, {"input": "7\r\n6 1 7 3 4 5 2\r\n6 1 7 3 4 5 2\r\n", "output": "0\r\n"}, {"input": ...
false
stdio
null
true
187/A
187
A
Python 3
TESTS
5
186
0
56744638
class CodeforcesTask187ASolution: def __init__(self): self.result = '' self.sequence1 = [] self.sequence2 = [] def read_input(self): input() self.sequence1 = [int(x) for x in input().split(" ")] self.sequence2 = [int(x) for x in input().split(" ")] def proce...
58
436
25,088,000
127588617
n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) i = j = 0 for j in range(n): if b[j] == a[i]: i = i + 1 print(n-i)
Codeforces Round 119 (Div. 1)
CF
2,012
2
256
Permutations
Happy PMP is freshman and he is learning about algorithmic problems. He enjoys playing algorithmic games a lot. One of the seniors gave Happy PMP a nice game. He is given two permutations of numbers 1 through n and is asked to convert the first one to the second. In one move he can remove the last number from the perm...
The first line contains a single integer n (1 ≤ n ≤ 2·105) — the quantity of the numbers in the both given permutations. Next line contains n space-separated integers — the first permutation. Each number between 1 to n will appear in the permutation exactly once. Next line describe the second permutation in the same ...
Print a single integer denoting the minimum number of moves required to convert the first permutation to the second.
null
In the first sample, he removes number 1 from end of the list and places it at the beginning. After that he takes number 2 and places it between 1 and 3. In the second sample, he removes number 5 and inserts it after 1. In the third sample, the sequence of changes are like this: - 1 5 2 3 4 - 1 4 5 2 3 - 1 3 4 5 2 -...
[{"input": "3\n3 2 1\n1 2 3", "output": "2"}, {"input": "5\n1 2 3 4 5\n1 5 2 3 4", "output": "1"}, {"input": "5\n1 5 2 3 4\n1 2 3 4 5", "output": "3"}]
1,500
["greedy"]
58
[{"input": "3\r\n3 2 1\r\n1 2 3\r\n", "output": "2\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n1 5 2 3 4\r\n", "output": "1\r\n"}, {"input": "5\r\n1 5 2 3 4\r\n1 2 3 4 5\r\n", "output": "3\r\n"}, {"input": "1\r\n1\r\n1\r\n", "output": "0\r\n"}, {"input": "7\r\n6 1 7 3 4 5 2\r\n6 1 7 3 4 5 2\r\n", "output": "0\r\n"}, {"input": ...
false
stdio
null
true
187/A
187
A
Python 3
TESTS
5
92
0
14346657
n = int(input()) permutation = list(map(int, input().split())) target = list(map(int, input().split())) cont = 0 for i in range(0, n): if (permutation[i] != target[i]): cont += 1 for j in range(i + 1, n): if (permutation[j] == target[i]): aux = permutation[0:i] aux.append(permutation[j]) aux.extend(...
58
496
39,116,800
170973235
n=int(input()) arr=list(map(int,input().split())) out=list(map(int,input().split())) mp=dict() ans=0 for i in range(n): mp[arr[i]]=i for i in range(n): mp[out[i]]+=ans if i==mp[out[i]]:continue ans+=1 print(ans)
Codeforces Round 119 (Div. 1)
CF
2,012
2
256
Permutations
Happy PMP is freshman and he is learning about algorithmic problems. He enjoys playing algorithmic games a lot. One of the seniors gave Happy PMP a nice game. He is given two permutations of numbers 1 through n and is asked to convert the first one to the second. In one move he can remove the last number from the perm...
The first line contains a single integer n (1 ≤ n ≤ 2·105) — the quantity of the numbers in the both given permutations. Next line contains n space-separated integers — the first permutation. Each number between 1 to n will appear in the permutation exactly once. Next line describe the second permutation in the same ...
Print a single integer denoting the minimum number of moves required to convert the first permutation to the second.
null
In the first sample, he removes number 1 from end of the list and places it at the beginning. After that he takes number 2 and places it between 1 and 3. In the second sample, he removes number 5 and inserts it after 1. In the third sample, the sequence of changes are like this: - 1 5 2 3 4 - 1 4 5 2 3 - 1 3 4 5 2 -...
[{"input": "3\n3 2 1\n1 2 3", "output": "2"}, {"input": "5\n1 2 3 4 5\n1 5 2 3 4", "output": "1"}, {"input": "5\n1 5 2 3 4\n1 2 3 4 5", "output": "3"}]
1,500
["greedy"]
58
[{"input": "3\r\n3 2 1\r\n1 2 3\r\n", "output": "2\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n1 5 2 3 4\r\n", "output": "1\r\n"}, {"input": "5\r\n1 5 2 3 4\r\n1 2 3 4 5\r\n", "output": "3\r\n"}, {"input": "1\r\n1\r\n1\r\n", "output": "0\r\n"}, {"input": "7\r\n6 1 7 3 4 5 2\r\n6 1 7 3 4 5 2\r\n", "output": "0\r\n"}, {"input": ...
false
stdio
null
true
187/A
187
A
PyPy 3-64
TESTS
5
92
0
176234627
import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) d = [0]*(n+1) for i, j in enumerate(b): d[j] = i c = 0 f = 0 for i in range(n): x = d[a[i]] if x == i: f += 1 if c == 0: continue c = max(c, n-1...
58
654
18,124,800
41983347
u,d,x,n=0,0,0,int(input()) # n = [0 for i in range(n+10)] f=list(map(int,input().split())) s=list(map(int,input().split())) while d<n: if s[d]!=f[u]: x+=1 d+=1 else: d+=1 u+=1 print(x)
Codeforces Round 119 (Div. 1)
CF
2,012
2
256
Permutations
Happy PMP is freshman and he is learning about algorithmic problems. He enjoys playing algorithmic games a lot. One of the seniors gave Happy PMP a nice game. He is given two permutations of numbers 1 through n and is asked to convert the first one to the second. In one move he can remove the last number from the perm...
The first line contains a single integer n (1 ≤ n ≤ 2·105) — the quantity of the numbers in the both given permutations. Next line contains n space-separated integers — the first permutation. Each number between 1 to n will appear in the permutation exactly once. Next line describe the second permutation in the same ...
Print a single integer denoting the minimum number of moves required to convert the first permutation to the second.
null
In the first sample, he removes number 1 from end of the list and places it at the beginning. After that he takes number 2 and places it between 1 and 3. In the second sample, he removes number 5 and inserts it after 1. In the third sample, the sequence of changes are like this: - 1 5 2 3 4 - 1 4 5 2 3 - 1 3 4 5 2 -...
[{"input": "3\n3 2 1\n1 2 3", "output": "2"}, {"input": "5\n1 2 3 4 5\n1 5 2 3 4", "output": "1"}, {"input": "5\n1 5 2 3 4\n1 2 3 4 5", "output": "3"}]
1,500
["greedy"]
58
[{"input": "3\r\n3 2 1\r\n1 2 3\r\n", "output": "2\r\n"}, {"input": "5\r\n1 2 3 4 5\r\n1 5 2 3 4\r\n", "output": "1\r\n"}, {"input": "5\r\n1 5 2 3 4\r\n1 2 3 4 5\r\n", "output": "3\r\n"}, {"input": "1\r\n1\r\n1\r\n", "output": "0\r\n"}, {"input": "7\r\n6 1 7 3 4 5 2\r\n6 1 7 3 4 5 2\r\n", "output": "0\r\n"}, {"input": ...
false
stdio
null
true
324/A1
331
A1
Python 3
TESTS1
7
62
0
4100809
import sys fin = sys.stdin n = int(fin.readline()) a = list(map(int, fin.readline().split())) table = dict() s = [0] * (n + 1) for i in range(n): if a[i] >= 0: rec = table.setdefault(a[i], { 'begin' : i, 'end' : i, 'sum' : a[i] }) rec['end'] = i s[i + 1] = s[i] + a[i] rec['sum'] = ...
18
154
0
29595694
n=int(input()) a=tuple(map(int,input().split())) c={} p={} s=x=y=0 m=-1e18 for i in range(0,len(a)): d=c.get(a[i]) if d!=None and s-d+a[i]*2>m: m=s-d+a[i]*2 x,y=p.get(a[i]),i if(a[i]>0):s+=a[i] if p.get(a[i])==None: p[a[i]]=i c[a[i]]=s a=[str(i+1) for i in range(0,len(a...
ABBYY Cup 3.0 - Finals
ICPC
2,013
2
256
Oh Sweet Beaverette
— Oh my sweet Beaverette, would you fancy a walk along a wonderful woodland belt with me? — Of course, my Smart Beaver! Let us enjoy the splendid view together. How about Friday night? At this point the Smart Beaver got rushing. Everything should be perfect by Friday, so he needed to prepare the belt to the upcoming ...
The first line contains a single integer n — the initial number of trees in the woodland belt, 2 ≤ n. The second line contains space-separated integers ai — the esthetic appeals of each tree. All esthetic appeals do not exceed 109 in their absolute value. - to get 30 points, you need to solve the problem with constrai...
In the first line print two integers — the total esthetic appeal of the woodland belt after the Smart Beaver's intervention and the number of the cut down trees k. In the next line print k integers — the numbers of the trees the Beaver needs to cut down. Assume that the trees are numbered from 1 to n from left to righ...
null
null
[{"input": "5\n1 2 3 1 2", "output": "8 1\n1"}, {"input": "5\n1 -2 3 1 -2", "output": "5 2\n2 5"}]
1,400
[]
18
[{"input": "5\r\n1 2 3 1 2\r\n", "output": "8 1\r\n1 "}, {"input": "5\r\n1 -2 3 1 -2\r\n", "output": "5 2\r\n2 5 "}, {"input": "2\r\n0 0\r\n", "output": "0 0\r\n"}, {"input": "3\r\n0 -1 0\r\n", "output": "0 1\r\n2 "}, {"input": "3\r\n1 1 1\r\n", "output": "3 0\r\n"}, {"input": "4\r\n-1 1 1 -1\r\n", "output": "2 2\r\n1 ...
false
stdio
import sys from collections import defaultdict def main(input_path, output_path, submission_output_path): with open(input_path) as f: n = int(f.readline()) a = list(map(int, f.readline().split())) with open(submission_output_path) as f: lines = f.readlines() if not lines: ...
true
765/A
765
A
Python 3
TESTS
4
61
307,200
107244499
def solve(home, arr): for i,f in enumerate(arr): found = False if f[0] == home: for j,t in enumerate(arr): if t[1] == home and t[0] == f[1]: found = True break if not found: return 'contest' return 'home' def main(): n = int(input()) home = input() arr...
23
46
0
161136608
n = int(input()) home_airport = input() flights = [] for i in range(n): flight = input() departure, arrival = flight.split('->') flights.append((departure, arrival)) if n % 2 == 0: print('home') else: print('contest')
Codeforces Round 397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined)
CF
2,017
2
512
Neverending competitions
There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back. Jinotega's best friends, team ...
In the first line of input there is a single integer n: the number of Jinotega's flights (1 ≤ n ≤ 100). In the second line there is a string of 3 capital Latin letters: the name of Jinotega's home airport. In the next n lines there is flight information, one flight per line, in form "XXX->YYY", where "XXX" is the name ...
If Jinotega is now at home, print "home" (without quotes), otherwise print "contest".
null
In the first sample Jinotega might first fly from SVO to CDG and back, and then from SVO to LHR and back, so now they should be at home. In the second sample Jinotega must now be at RAP because a flight from RAP back to SVO is not on the list.
[{"input": "4\nSVO\nSVO->CDG\nLHR->SVO\nSVO->LHR\nCDG->SVO", "output": "home"}, {"input": "3\nSVO\nSVO->HKT\nHKT->SVO\nSVO->RAP", "output": "contest"}]
900
["implementation", "math"]
23
[{"input": "4\r\nSVO\r\nSVO->CDG\r\nLHR->SVO\r\nSVO->LHR\r\nCDG->SVO\r\n", "output": "home\r\n"}, {"input": "3\r\nSVO\r\nSVO->HKT\r\nHKT->SVO\r\nSVO->RAP\r\n", "output": "contest\r\n"}, {"input": "1\r\nESJ\r\nESJ->TSJ\r\n", "output": "contest\r\n"}, {"input": "2\r\nXMR\r\nFAJ->XMR\r\nXMR->FAJ\r\n", "output": "home\r\n"...
false
stdio
null
true
877/E
877
E
PyPy 3
TESTS
6
93
0
180474384
import bisect import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline def euler_tour(): s = [] s.append(1) now = [0] * (n + 1) t = 1 t1, t2 = [-1] * (n + 1), [-1] * (n + 1) v = [] while s: i = s[-1] if t1[i] == -1: v.append(i) ...
57
1,544
90,316,800
209145397
import math import sys from bisect import * from collections import * from functools import * from heapq import * from itertools import * from random import * from string import * from types import GeneratorType # region fastio input = lambda: sys.stdin.readline().rstrip() sint = lambda: int(input()) mint = lambda: ma...
Codeforces Round 442 (Div. 2)
CF
2,017
2
256
Danil and a Part-time Job
Danil decided to earn some money, so he had found a part-time job. The interview have went well, so now he is a light switcher. Danil works in a rooted tree (undirected connected acyclic graph) with n vertices, vertex 1 is the root of the tree. There is a room in each vertex, light can be switched on or off in each ro...
The first line contains a single integer n (1 ≤ n ≤ 200 000) — the number of vertices in the tree. The second line contains n - 1 space-separated integers p2, p3, ..., pn (1 ≤ pi < i), where pi is the ancestor of vertex i. The third line contains n space-separated integers t1, t2, ..., tn (0 ≤ ti ≤ 1), where ti is 1,...
For each task get v print the number of rooms in the subtree of v, in which the light is turned on.
null
The tree before the task pow 1. The tree after the task pow 1.
[{"input": "4\n1 1 1\n1 0 0 1\n9\nget 1\nget 2\nget 3\nget 4\npow 1\nget 1\nget 2\nget 3\nget 4", "output": "2\n0\n0\n1\n2\n1\n1\n0"}]
2,000
["bitmasks", "data structures", "trees"]
57
[{"input": "4\r\n1 1 1\r\n1 0 0 1\r\n9\r\nget 1\r\nget 2\r\nget 3\r\nget 4\r\npow 1\r\nget 1\r\nget 2\r\nget 3\r\nget 4\r\n", "output": "2\r\n0\r\n0\r\n1\r\n2\r\n1\r\n1\r\n0\r\n"}, {"input": "1\r\n\r\n1\r\n4\r\npow 1\r\nget 1\r\npow 1\r\nget 1\r\n", "output": "0\r\n1\r\n"}, {"input": "10\r\n1 2 1 3 4 5 6 8 5\r\n1 0 0 0...
false
stdio
null
true
960/B
960
B
PyPy 3
TESTS
8
93
1,433,600
108174168
n,k1,k2=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) k=k1+k2 c=list() for i in range(n): c.append(abs(a[i]-b[i])) c.sort(reverse=True) i=0 r=n while(r!=0 and k!=0): if(c[i%r]>0): c[i%r]-=1 k-=1 i+=1 if(c[i%r]==0): del c[i%r] r...
80
92
2,969,600
188262926
from heapq import heapify, heappop, heappush def solve(): n, k1, k2 = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) d = [-abs(a[i] - b[i]) for i in range(n)] heapify(d) for i in range(k1+k2): # print(d) item = heappop(d) ...
Divide by Zero 2018 and Codeforces Round 474 (Div. 1 + Div. 2, combined)
CF
2,018
1
256
Minimize the error
You are given two arrays A and B, each of size n. The error, E, between these two arrays is defined $$E = \sum_{i=1}^{n} (a_i - b_i)^2$$. You have to perform exactly k1 operations on array A and exactly k2 operations on array B. In one operation, you have to choose one element of the array and increase or decrease it b...
The first line contains three space-separated integers n (1 ≤ n ≤ 103), k1 and k2 (0 ≤ k1 + k2 ≤ 103, k1 and k2 are non-negative) — size of arrays and number of operations to perform on A and B respectively. Second line contains n space separated integers a1, a2, ..., an ( - 106 ≤ ai ≤ 106) — array A. Third line cont...
Output a single integer — the minimum possible value of $$\sum_{i=1}^{n}(a_i - b_i)^2$$ after doing exactly k1 operations on array A and exactly k2 operations on array B.
null
In the first sample case, we cannot perform any operations on A or B. Therefore the minimum possible error E = (1 - 2)2 + (2 - 3)2 = 2. In the second sample case, we are required to perform exactly one operation on A. In order to minimize error, we increment the first element of A by 1. Now, A = [2, 2]. The error is n...
[{"input": "2 0 0\n1 2\n2 3", "output": "2"}, {"input": "2 1 0\n1 2\n2 2", "output": "0"}, {"input": "2 5 7\n3 4\n14 4", "output": "1"}]
1,500
["data structures", "greedy", "sortings"]
80
[{"input": "2 0 0\r\n1 2\r\n2 3\r\n", "output": "2"}, {"input": "2 1 0\r\n1 2\r\n2 2\r\n", "output": "0"}, {"input": "2 5 7\r\n3 4\r\n14 4\r\n", "output": "1"}, {"input": "2 0 1\r\n1 2\r\n2 2\r\n", "output": "0"}, {"input": "2 1 1\r\n0 0\r\n1 1\r\n", "output": "0"}, {"input": "5 5 5\r\n0 0 0 0 0\r\n0 0 0 0 0\r\n", "out...
false
stdio
null
true
388/C
388
C
Python 3
TESTS
5
124
409,600
51656284
from functools import reduce n = int(input()) cards = [list(map(int, input().split()[1:])) for i in range(n)] mid = [] a, b = 0, 0 add = lambda x=0, y=0: x + y for c in cards: s = len(c) m = s >> 1 if s & 1 == 0: a += reduce(add, c[:m]) b += reduce(add, c[m:]) else: a += reduce(...
43
62
307,200
110070558
p, n = [], int(input()) a = b = 0 for i in range(n): t = list(map(int, input().split())) k = t[0] // 2 + 1 a += sum(t[1: k]) if t[0] & 1: p.append(t[k]) b += sum(t[k + 1: ]) else: b += sum(t[k: ]) p.sort(reverse = True) print(a + sum(p[0 :: 2]), b + sum(p[1 :: 2]))
Codeforces Round 228 (Div. 1)
CF
2,014
1
256
Fox and Card Game
Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card. The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom o...
The first line contain an integer n (1 ≤ n ≤ 100). Each of the next n lines contains a description of the pile: the first integer in the line is si (1 ≤ si ≤ 100) — the number of cards in the i-th pile; then follow si positive integers c1, c2, ..., ck, ..., csi (1 ≤ ck ≤ 1000) — the sequence of the numbers on the cards...
Print two integers: the sum of Ciel's cards and the sum of Jiro's cards if they play optimally.
null
In the first example, Ciel will take the cards with number 100 and 1, Jiro will take the card with number 10. In the second example, Ciel will take cards with numbers 2, 8, 6, 5, 9 and Jiro will take cards with numbers 4, 7, 1, 3.
[{"input": "2\n1 100\n2 1 10", "output": "101 10"}, {"input": "1\n9 2 8 6 5 9 4 7 1 3", "output": "30 15"}, {"input": "3\n3 1 3 2\n3 5 4 6\n2 8 7", "output": "18 18"}, {"input": "3\n3 1000 1000 1000\n6 1000 1000 1000 1000 1000 1000\n5 1000 1000 1000 1000 1000", "output": "7000 7000"}]
2,000
["games", "greedy", "sortings"]
43
[{"input": "2\r\n1 100\r\n2 1 10\r\n", "output": "101 10\r\n"}, {"input": "1\r\n9 2 8 6 5 9 4 7 1 3\r\n", "output": "30 15\r\n"}, {"input": "3\r\n3 1 3 2\r\n3 5 4 6\r\n2 8 7\r\n", "output": "18 18\r\n"}, {"input": "3\r\n3 1000 1000 1000\r\n6 1000 1000 1000 1000 1000 1000\r\n5 1000 1000 1000 1000 1000\r\n", "output": "7...
false
stdio
null
true
388/C
388
C
Python 3
TESTS
6
62
6,963,200
125470197
N=int(input()) C=[[] for i in range(N)] num=0 for i in range(N): L=list(map(int,input().split())) num+=L[0] C[i]=L[1:] Ciel=0 Jiro=0 for i in range(num): if i%2==0: C.sort() C.reverse() Ciel+=C[0][0] del C[0][0] for j in range(N): C[j].reverse() #print(C) else: C.sort() ...
43
77
307,200
104855612
odd = [] first, second = 0, 0 for i in range(int(input())): pile = list(map(int, input().split())) s, pile = pile[0], pile[1:] sh = s >> 1 if (s & 1) == 0: first += sum(pile[:sh]) second += sum(pile[sh:]) else: first += sum(pile[:sh]) second += sum(pile[sh+1:]) ...
Codeforces Round 228 (Div. 1)
CF
2,014
1
256
Fox and Card Game
Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card. The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom o...
The first line contain an integer n (1 ≤ n ≤ 100). Each of the next n lines contains a description of the pile: the first integer in the line is si (1 ≤ si ≤ 100) — the number of cards in the i-th pile; then follow si positive integers c1, c2, ..., ck, ..., csi (1 ≤ ck ≤ 1000) — the sequence of the numbers on the cards...
Print two integers: the sum of Ciel's cards and the sum of Jiro's cards if they play optimally.
null
In the first example, Ciel will take the cards with number 100 and 1, Jiro will take the card with number 10. In the second example, Ciel will take cards with numbers 2, 8, 6, 5, 9 and Jiro will take cards with numbers 4, 7, 1, 3.
[{"input": "2\n1 100\n2 1 10", "output": "101 10"}, {"input": "1\n9 2 8 6 5 9 4 7 1 3", "output": "30 15"}, {"input": "3\n3 1 3 2\n3 5 4 6\n2 8 7", "output": "18 18"}, {"input": "3\n3 1000 1000 1000\n6 1000 1000 1000 1000 1000 1000\n5 1000 1000 1000 1000 1000", "output": "7000 7000"}]
2,000
["games", "greedy", "sortings"]
43
[{"input": "2\r\n1 100\r\n2 1 10\r\n", "output": "101 10\r\n"}, {"input": "1\r\n9 2 8 6 5 9 4 7 1 3\r\n", "output": "30 15\r\n"}, {"input": "3\r\n3 1 3 2\r\n3 5 4 6\r\n2 8 7\r\n", "output": "18 18\r\n"}, {"input": "3\r\n3 1000 1000 1000\r\n6 1000 1000 1000 1000 1000 1000\r\n5 1000 1000 1000 1000 1000\r\n", "output": "7...
false
stdio
null
true
884/A
884
A
Python 3
TESTS
4
61
5,529,600
33616580
n,m=[int(x) for x in input().strip().split()] l=[int(x) for x in input().strip().split()] day=0 for k in l: day=day+1 m=m-(86400-k) if(m==0): break print(day)
16
31
0
228082839
days,time=map(int,input().split()) work=list(map(int,input().split())) count=0 day=86400 for i in range(days): free=0 free=day-work[i] time-=free if time <= 0: count+=1 break else: count+=1 print(count)
Educational Codeforces Round 31
ICPC
2,017
2
256
Book Reading
Recently Luba bought a very interesting book. She knows that it will take t seconds to read the book. Luba wants to finish reading as fast as she can. But she has some work to do in each of n next days. The number of seconds that Luba has to spend working during i-th day is ai. If some free time remains, she can spend...
The first line contains two integers n and t (1 ≤ n ≤ 100, 1 ≤ t ≤ 106) — the number of days and the time required to read the book. The second line contains n integers ai (0 ≤ ai ≤ 86400) — the time Luba has to spend on her work during i-th day.
Print the minimum day Luba can finish reading the book. It is guaranteed that answer doesn't exceed n.
null
null
[{"input": "2 2\n86400 86398", "output": "2"}, {"input": "2 86400\n0 86400", "output": "1"}]
800
["implementation"]
16
[{"input": "2 2\r\n86400 86398\r\n", "output": "2\r\n"}, {"input": "2 86400\r\n0 86400\r\n", "output": "1\r\n"}, {"input": "2 86400\r\n1 86399\r\n", "output": "2\r\n"}, {"input": "100 1000000\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...
false
stdio
null
true
39/B
39
B
Python 3
TESTS
0
60
0
178819525
n=int(input()) a=list(map(int,input().split())) t=0 b=[] for i in range(1,n): if a[i]>0: if a[i-1]<a[i]: b.append(2000+i+1) if len(b)==0: print('0') else: print(len(b)) for i in b: print(i,end=' ')
35
92
0
173338221
n=int(input()) A=list(map(int,input().split())) ANS=[] now=1 for i in range(n): if A[i]==now: ANS.append(2000+i+1) now+=1 print(len(ANS)) print(*ANS)
School Team Contest 1 (Winter Computer School 2010/11)
ICPC
2,010
2
64
Company Income Growth
Petya works as a PR manager for a successful Berland company BerSoft. He needs to prepare a presentation on the company income growth since 2001 (the year of its founding) till now. Petya knows that in 2001 the company income amounted to a1 billion bourles, in 2002 — to a2 billion, ..., and in the current (2000 + n)-th...
The first line contains an integer n (1 ≤ n ≤ 100). The next line contains n integers ai ( - 100 ≤ ai ≤ 100). The number ai determines the income of BerSoft company in the (2000 + i)-th year. The numbers in the line are separated by spaces.
Output k — the maximum possible length of a perfect sequence. In the next line output the sequence of years y1, y2, ..., yk. Separate the numbers by spaces. If the answer is not unique, output any. If no solution exist, output one number 0.
null
null
[{"input": "10\n-2 1 1 3 2 3 4 -10 -2 5", "output": "5\n2002 2005 2006 2007 2010"}, {"input": "3\n-1 -2 -3", "output": "0"}]
1,300
["greedy"]
35
[{"input": "10\r\n-2 1 1 3 2 3 4 -10 -2 5\r\n", "output": "5\r\n2002 2005 2006 2007 2010 "}, {"input": "3\r\n-1 -2 -3\r\n", "output": "0\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "1\r\n0\r\n", "output": "0\r\n"}, {"input": "2\r\n-1 1\r\n", "output": "1\r\n2002 "}, {"input": "2\r\n-1 1\r\n", "output":...
false
stdio
null
true
883/F
883
F
Python 3
TESTS
8
77
6,041,600
31591529
# -*- coding: utf-8 -*- import math import collections import bisect import heapq import time import random import itertools import sys """ created by shhuan at 2017/10/22 12:26 """ N = int(input()) A = [] for i in range(N): A.append(input()) def transform(s): if not s: return "" t = s.replace(...
81
46
0
140150903
n = int(input()) st = set() for i in range(n): word = input() word = word.replace('u', 'oo') while word.replace('kh', 'h') != word: word = word.replace('kh', 'h') st.add(word) print(len(st))
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,017
3
256
Lost in Transliteration
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland s...
The first line contains integer number n (2 ≤ n ≤ 400) — number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Print the minimal number of groups where the words in each group denote the same name.
null
There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khari...
[{"input": "10\nmihail\noolyana\nkooooper\nhoon\nulyana\nkoouper\nmikhail\nkhun\nkuooper\nkkkhoon", "output": "4"}, {"input": "9\nhariton\nhkariton\nbuoi\nkkkhariton\nboooi\nbui\nkhariton\nboui\nboi", "output": "5"}, {"input": "2\nalex\nalex", "output": "1"}]
1,300
["implementation"]
81
[{"input": "10\r\nmihail\r\noolyana\r\nkooooper\r\nhoon\r\nulyana\r\nkoouper\r\nmikhail\r\nkhun\r\nkuooper\r\nkkkhoon\r\n", "output": "4\r\n"}, {"input": "9\r\nhariton\r\nhkariton\r\nbuoi\r\nkkkhariton\r\nboooi\r\nbui\r\nkhariton\r\nboui\r\nboi\r\n", "output": "5\r\n"}, {"input": "2\r\nalex\r\nalex\r\n", "output": "1\r...
false
stdio
null
true
883/F
883
F
Python 3
TESTS
7
62
5,529,600
33323100
n=int(input()) use=set() for i in range(n): s='' fl=False for j in input()[::-1]: if fl and j=='k': continue elif j=='u': s+='oo' elif (j=='h'): fl=True s+='h' else: s+=j fl=False use.add(s[::-1]) pri...
81
46
0
154831410
n=eval(input()) ans=set() for i in range(n): s=input() # print(s) t=0 while t<=100: s=s.replace("u","oo") s=s.replace("kh","h") t+=1 # print(s) ans.add(s) print(len(ans))
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,017
3
256
Lost in Transliteration
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland s...
The first line contains integer number n (2 ≤ n ≤ 400) — number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Print the minimal number of groups where the words in each group denote the same name.
null
There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khari...
[{"input": "10\nmihail\noolyana\nkooooper\nhoon\nulyana\nkoouper\nmikhail\nkhun\nkuooper\nkkkhoon", "output": "4"}, {"input": "9\nhariton\nhkariton\nbuoi\nkkkhariton\nboooi\nbui\nkhariton\nboui\nboi", "output": "5"}, {"input": "2\nalex\nalex", "output": "1"}]
1,300
["implementation"]
81
[{"input": "10\r\nmihail\r\noolyana\r\nkooooper\r\nhoon\r\nulyana\r\nkoouper\r\nmikhail\r\nkhun\r\nkuooper\r\nkkkhoon\r\n", "output": "4\r\n"}, {"input": "9\r\nhariton\r\nhkariton\r\nbuoi\r\nkkkhariton\r\nboooi\r\nbui\r\nkhariton\r\nboui\r\nboi\r\n", "output": "5\r\n"}, {"input": "2\r\nalex\r\nalex\r\n", "output": "1\r...
false
stdio
null
true
884/A
884
A
Python 3
TESTS
4
31
0
208996107
n,t = map(int, input().split()) work_times = list(map(int, input().split())) days = 0 for i in work_times: days += 1 t -= 86400 - i if t == 0: break print(days)
16
46
0
31798236
R=lambda:list(map(int,input().split())) n,t=R() a=R() for i in range(n): t-=86400-a[i] if t<1: print(i+1) exit(0)
Educational Codeforces Round 31
ICPC
2,017
2
256
Book Reading
Recently Luba bought a very interesting book. She knows that it will take t seconds to read the book. Luba wants to finish reading as fast as she can. But she has some work to do in each of n next days. The number of seconds that Luba has to spend working during i-th day is ai. If some free time remains, she can spend...
The first line contains two integers n and t (1 ≤ n ≤ 100, 1 ≤ t ≤ 106) — the number of days and the time required to read the book. The second line contains n integers ai (0 ≤ ai ≤ 86400) — the time Luba has to spend on her work during i-th day.
Print the minimum day Luba can finish reading the book. It is guaranteed that answer doesn't exceed n.
null
null
[{"input": "2 2\n86400 86398", "output": "2"}, {"input": "2 86400\n0 86400", "output": "1"}]
800
["implementation"]
16
[{"input": "2 2\r\n86400 86398\r\n", "output": "2\r\n"}, {"input": "2 86400\r\n0 86400\r\n", "output": "1\r\n"}, {"input": "2 86400\r\n1 86399\r\n", "output": "2\r\n"}, {"input": "100 1000000\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...
false
stdio
null
true
883/F
883
F
Python 3
TESTS
7
62
5,529,600
31686201
n = int(input()) l = [] for i in range(n): l.append(list(str(input()))) for i in range(n): for j in range(len(l[i])): if (l[i])[j] == 'u': (l[i])[j] = 'oo' for i in range(n): j = 0 while (j < len(l[i]) - 1): if (l[i])[j] == 'k' and (l[i])[j+1] == 'h': l[i].remove(...
81
46
0
198725716
import math n=int(input()) l=[] for i in range(n): s=input() while("kh" in s): s=s.replace("kh","h") while("u" in s): s=s.replace("u","oo") l.append(s) print(len(set(l)))
2017-2018 ACM-ICPC, NEERC, Southern Subregional Contest (Online Mirror, ACM-ICPC Rules, Teams Preferred)
ICPC
2,017
3
256
Lost in Transliteration
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name. The second ambiguity is about the Berland s...
The first line contains integer number n (2 ≤ n ≤ 400) — number of the words in the list. The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
Print the minimal number of groups where the words in each group denote the same name.
null
There are four groups of words in the first example. Words in each group denote same name: 1. "mihail", "mikhail" 2. "oolyana", "ulyana" 3. "kooooper", "koouper" 4. "hoon", "khun", "kkkhoon" There are five groups of words in the second example. Words in each group denote same name: 1. "hariton", "kkkhariton", "khari...
[{"input": "10\nmihail\noolyana\nkooooper\nhoon\nulyana\nkoouper\nmikhail\nkhun\nkuooper\nkkkhoon", "output": "4"}, {"input": "9\nhariton\nhkariton\nbuoi\nkkkhariton\nboooi\nbui\nkhariton\nboui\nboi", "output": "5"}, {"input": "2\nalex\nalex", "output": "1"}]
1,300
["implementation"]
81
[{"input": "10\r\nmihail\r\noolyana\r\nkooooper\r\nhoon\r\nulyana\r\nkoouper\r\nmikhail\r\nkhun\r\nkuooper\r\nkkkhoon\r\n", "output": "4\r\n"}, {"input": "9\r\nhariton\r\nhkariton\r\nbuoi\r\nkkkhariton\r\nboooi\r\nbui\r\nkhariton\r\nboui\r\nboi\r\n", "output": "5\r\n"}, {"input": "2\r\nalex\r\nalex\r\n", "output": "1\r...
false
stdio
null
true
884/A
884
A
Python 3
TESTS
4
31
0
223747206
n,t = map(int,input().split()) l = list(map(int,input().split())) ans = 0 for i in range(n): t -= 86400 - l[i] ans += 1 if t == 0: break print(ans)
16
46
0
31798328
n, t = map(int, input().split()) a = list(map(int, input().split())) for i in range(1, n + 1): t -= 86400 - a[i - 1] if (t <= 0): print(i) break
Educational Codeforces Round 31
ICPC
2,017
2
256
Book Reading
Recently Luba bought a very interesting book. She knows that it will take t seconds to read the book. Luba wants to finish reading as fast as she can. But she has some work to do in each of n next days. The number of seconds that Luba has to spend working during i-th day is ai. If some free time remains, she can spend...
The first line contains two integers n and t (1 ≤ n ≤ 100, 1 ≤ t ≤ 106) — the number of days and the time required to read the book. The second line contains n integers ai (0 ≤ ai ≤ 86400) — the time Luba has to spend on her work during i-th day.
Print the minimum day Luba can finish reading the book. It is guaranteed that answer doesn't exceed n.
null
null
[{"input": "2 2\n86400 86398", "output": "2"}, {"input": "2 86400\n0 86400", "output": "1"}]
800
["implementation"]
16
[{"input": "2 2\r\n86400 86398\r\n", "output": "2\r\n"}, {"input": "2 86400\r\n0 86400\r\n", "output": "1\r\n"}, {"input": "2 86400\r\n1 86399\r\n", "output": "2\r\n"}, {"input": "100 1000000\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...
false
stdio
null
true