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
31/D
31
D
Python 3
TESTS
1
92
0
190465947
w,h,n=map(int,input().split()) N=101 x=[[0]*N for _ in range(N)] y=[[0]*N for _ in range(N)] x[0][w],y[h][0],p=2,2,[] for a,b,c,d in [[*map(int,input().split())] for i in range(n)]: m,n=sorted([(a,b),(c,d)]) x[m[0]][m[1]]=1 y[m[0]][m[1]]=1 if m[0]==n[0]: x[n[0]][n[1]]=2 else: y[n[0]]...
33
218
307,200
85902665
WHn = [[0,0]] # WHn[0].extend(list(map(int, input().split(' ')))) WHn[0].extend([int(x) for x in input().split(' ')]) n = range(WHn[0][-1]) lines = [] lines_aux = [] for i in n: lines.append( [int(x) for x in input().split(' ')] ) lines_aux.append(True) while any(lines_aux): for i in n: if ...
Codeforces Beta Round 31 (Div. 2, Codeforces format)
CF
2,010
2
256
Chocolate
Bob has a rectangular chocolate bar of the size W × H. He introduced a cartesian coordinate system so that the point (0, 0) corresponds to the lower-left corner of the bar, and the point (W, H) corresponds to the upper-right corner. Bob decided to split the bar into pieces by breaking it. Each break is a segment parall...
The first line contains 3 integers W, H and n (1 ≤ W, H, n ≤ 100) — width of the bar, height of the bar and amount of breaks. Each of the following n lines contains four integers xi, 1, yi, 1, xi, 2, yi, 2 — coordinates of the endpoints of the i-th break (0 ≤ xi, 1 ≤ xi, 2 ≤ W, 0 ≤ yi, 1 ≤ yi, 2 ≤ H, or xi, 1 = xi, 2, ...
Output n + 1 numbers — areas of the resulting parts in the increasing order.
null
null
[{"input": "2 2 2\n1 0 1 2\n0 1 1 1", "output": "1 1 2"}, {"input": "2 2 3\n1 0 1 2\n0 1 1 1\n1 1 2 1", "output": "1 1 1 1"}, {"input": "2 4 2\n0 1 2 1\n0 3 2 3", "output": "2 2 4"}]
2,000
["dfs and similar", "implementation"]
33
[{"input": "2 2 2\r\n1 0 1 2\r\n0 1 1 1\r\n", "output": "1 1 2 "}, {"input": "2 2 3\r\n1 0 1 2\r\n0 1 1 1\r\n1 1 2 1\r\n", "output": "1 1 1 1 "}, {"input": "2 4 2\r\n0 1 2 1\r\n0 3 2 3\r\n", "output": "2 2 4 "}, {"input": "5 5 3\r\n2 1 2 5\r\n0 1 5 1\r\n4 0 4 1\r\n", "output": "1 4 8 12 "}, {"input": "10 10 4\r\n9 0 9 ...
false
stdio
null
true
19/A
19
A
Python 3
TESTS
3
124
5,632,000
35554519
teams,n = [], int(input()) for notused in range(n): teams.append([input(), 0, 0, 0]) for notused in range(n*(n-1)//2): players, score = input().split(" ") players,score = players.split("-"), list(map(int, score.split(":"))) for team in teams: if team[0] == players[0]: if score[0] > s...
29
92
102,400
205467181
class Info: def __init__(self, newTeamName, newPoints, newGoalDiff, newScoredGoals): self.teamName = newTeamName self.points = newPoints self.goalDiff = newGoalDiff self.scoredGoals = newScoredGoals def __str__(self): return f'teamName: \'{self.teamName}\', points: {self...
Codeforces Beta Round 19
ICPC
2,010
2
64
World Football Cup
Everyone knows that 2010 FIFA World Cup is being held in South Africa now. By the decision of BFA (Berland's Football Association) next World Cup will be held in Berland. BFA took the decision to change some World Cup regulations: - the final tournament features n teams (n is always even) - the first n / 2 teams (acco...
The first input line contains the only integer n (1 ≤ n ≤ 50) — amount of the teams, taking part in the final tournament of World Cup. The following n lines contain the names of these teams, a name is a string of lower-case and upper-case Latin letters, its length doesn't exceed 30 characters. The following n·(n - 1) /...
Output n / 2 lines — names of the teams, which managed to get through to the knockout stage in lexicographical order. Output each name in a separate line. No odd characters (including spaces) are allowed. It's guaranteed that the described regulations help to order the teams without ambiguity.
null
null
[{"input": "4\nA\nB\nC\nD\nA-B 1:1\nA-C 2:2\nA-D 1:0\nB-C 1:0\nB-D 0:3\nC-D 0:3", "output": "A\nD"}, {"input": "2\na\nA\na-A 2:1", "output": "a"}]
1,400
["implementation"]
29
[{"input": "4\r\nA\r\nB\r\nC\r\nD\r\nA-B 1:1\r\nA-C 2:2\r\nA-D 1:0\r\nB-C 1:0\r\nB-D 0:3\r\nC-D 0:3\r\n", "output": "A\r\nD\r\n"}, {"input": "2\r\na\r\nA\r\na-A 2:1\r\n", "output": "a\r\n"}, {"input": "2\r\nEULEUbCmfrmqxtzvg\r\nuHGRmKUhDcxcfqyruwzen\r\nuHGRmKUhDcxcfqyruwzen-EULEUbCmfrmqxtzvg 13:92\r\n", "output": "EULE...
false
stdio
null
true
19/A
19
A
Python 3
TESTS
3
124
204,800
112877762
import sys from collections import defaultdict POINTS_WIN = 3 POINTS_DRAW = 1 POINTS_LOSS = 0 def sort_order(item: dict) -> tuple: return -item["points"], -item["score_diff"], -item["score"] def ranking(teams: list, games: list) -> list: teams_data = {t: defaultdict(int, {"name": t}) for t in teams} f...
29
92
102,400
217802461
class heSo: def __init__(self) -> None: self.scoredGoals = 0; self.missedGoals = 0; self.points = 0; class solve: def __init__(self) -> None: self.n = 0; self.team = dict(); def vao(self) -> None: self.n = int(input()); for _ in range(self.n): ...
Codeforces Beta Round 19
ICPC
2,010
2
64
World Football Cup
Everyone knows that 2010 FIFA World Cup is being held in South Africa now. By the decision of BFA (Berland's Football Association) next World Cup will be held in Berland. BFA took the decision to change some World Cup regulations: - the final tournament features n teams (n is always even) - the first n / 2 teams (acco...
The first input line contains the only integer n (1 ≤ n ≤ 50) — amount of the teams, taking part in the final tournament of World Cup. The following n lines contain the names of these teams, a name is a string of lower-case and upper-case Latin letters, its length doesn't exceed 30 characters. The following n·(n - 1) /...
Output n / 2 lines — names of the teams, which managed to get through to the knockout stage in lexicographical order. Output each name in a separate line. No odd characters (including spaces) are allowed. It's guaranteed that the described regulations help to order the teams without ambiguity.
null
null
[{"input": "4\nA\nB\nC\nD\nA-B 1:1\nA-C 2:2\nA-D 1:0\nB-C 1:0\nB-D 0:3\nC-D 0:3", "output": "A\nD"}, {"input": "2\na\nA\na-A 2:1", "output": "a"}]
1,400
["implementation"]
29
[{"input": "4\r\nA\r\nB\r\nC\r\nD\r\nA-B 1:1\r\nA-C 2:2\r\nA-D 1:0\r\nB-C 1:0\r\nB-D 0:3\r\nC-D 0:3\r\n", "output": "A\r\nD\r\n"}, {"input": "2\r\na\r\nA\r\na-A 2:1\r\n", "output": "a\r\n"}, {"input": "2\r\nEULEUbCmfrmqxtzvg\r\nuHGRmKUhDcxcfqyruwzen\r\nuHGRmKUhDcxcfqyruwzen-EULEUbCmfrmqxtzvg 13:92\r\n", "output": "EULE...
false
stdio
null
true
19/A
19
A
Python 3
TESTS
3
124
0
141663393
n = int(input()) d ={} for i in range(n): n1 = input() d[n1] = 0 for i in range((n*(n-1))//2): s1,s2 = input().split() a,b = s1.split('-') score_a,score_b = s2.split(':') score_a = int(score_a) score_b = int(score_b) if(score_a>score_b): d[a]+=3 elif(score_a == score_b): ...
29
122
102,400
166676630
from functools import cmp_to_key class Team: def __init__(self, newTeamName, newPoints, newGoalDiff, newScoredGoals): self.teamName = newTeamName self.points = newPoints self.goalDiff = newGoalDiff self.scoredGoals = newScoredGoals def __str__(self): return f"TeamName:...
Codeforces Beta Round 19
ICPC
2,010
2
64
World Football Cup
Everyone knows that 2010 FIFA World Cup is being held in South Africa now. By the decision of BFA (Berland's Football Association) next World Cup will be held in Berland. BFA took the decision to change some World Cup regulations: - the final tournament features n teams (n is always even) - the first n / 2 teams (acco...
The first input line contains the only integer n (1 ≤ n ≤ 50) — amount of the teams, taking part in the final tournament of World Cup. The following n lines contain the names of these teams, a name is a string of lower-case and upper-case Latin letters, its length doesn't exceed 30 characters. The following n·(n - 1) /...
Output n / 2 lines — names of the teams, which managed to get through to the knockout stage in lexicographical order. Output each name in a separate line. No odd characters (including spaces) are allowed. It's guaranteed that the described regulations help to order the teams without ambiguity.
null
null
[{"input": "4\nA\nB\nC\nD\nA-B 1:1\nA-C 2:2\nA-D 1:0\nB-C 1:0\nB-D 0:3\nC-D 0:3", "output": "A\nD"}, {"input": "2\na\nA\na-A 2:1", "output": "a"}]
1,400
["implementation"]
29
[{"input": "4\r\nA\r\nB\r\nC\r\nD\r\nA-B 1:1\r\nA-C 2:2\r\nA-D 1:0\r\nB-C 1:0\r\nB-D 0:3\r\nC-D 0:3\r\n", "output": "A\r\nD\r\n"}, {"input": "2\r\na\r\nA\r\na-A 2:1\r\n", "output": "a\r\n"}, {"input": "2\r\nEULEUbCmfrmqxtzvg\r\nuHGRmKUhDcxcfqyruwzen\r\nuHGRmKUhDcxcfqyruwzen-EULEUbCmfrmqxtzvg 13:92\r\n", "output": "EULE...
false
stdio
null
true
713/C
713
C
Python 3
TESTS
1
77
6,963,200
126556899
def test(a): result=all(a[i]<=a[i+1] for i in range(len(a)-1)) return result n=int(input()) a=list(map(int, input().split())) d=0 while test(a)==False: while a[0]>a[1]: a[0]-=1 d+=1 for i in range(1,n-1): while a[i]>a[i+1]: a[i+1]+=1 d+=1 print(d)
57
171
8,294,400
174346205
import sys import io import os # region IO BUFSIZE = 8192 class FastIO(io.IOBase): newlines = 0 def __init__(self, file): self._file = file self._fd = file.fileno() self.buffer = io.BytesIO() self.writable = "x" in file.mode or "r" not in file.mode s...
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
16/E
16
E
Python 3
TESTS
1
186
6,656,000
91466375
n = int(input()) for i in range(n): mul = 1 arr = list(map(float,input().split())) for j in range(n): if j!=i: mul = mul * arr[j] print(mul,end=" ")
20
934
4,300,800
181369804
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n = int(input()) a = [list(map(float, input().split())) for _ in range(n)] pow2 = [1] for _ in range(n): pow2.append(2 * pow2[-1]) m = pow2[n] dp = [0] * m dp[-1] = 1 for i in range(m - 1, 0, -1): x = [] for j in range(n): ...
Codeforces Beta Round 16 (Div. 2 Only)
ICPC
2,010
3
128
Fish
n fish, numbered from 1 to n, live in a lake. Every day right one pair of fish meet, and the probability of each other pair meeting is the same. If two fish with indexes i and j meet, the first will eat up the second with the probability aij, and the second will eat up the first with the probability aji = 1 - aij. The ...
The first line contains integer n (1 ≤ n ≤ 18) — the amount of fish in the lake. Then there follow n lines with n real numbers each — matrix a. aij (0 ≤ aij ≤ 1) — the probability that fish with index i eats up fish with index j. It's guaranteed that the main diagonal contains zeros only, and for other elements the fol...
Output n space-separated real numbers accurate to not less than 6 decimal places. Number with index i should be equal to the probability that fish with index i will survive to be the last in the lake.
null
null
[{"input": "2\n0 0.5\n0.5 0", "output": "0.500000 0.500000"}, {"input": "5\n0 1 1 1 1\n0 0 0.5 0.5 0.5\n0 0.5 0 0.5 0.5\n0 0.5 0.5 0 0.5\n0 0.5 0.5 0.5 0", "output": "1.000000 0.000000 0.000000 0.000000 0.000000"}]
1,900
["bitmasks", "dp", "probabilities"]
20
[{"input": "2\r\n0 0.5\r\n0.5 0\r\n", "output": "0.500000 0.500000 "}, {"input": "4\r\n0 0.5 0.5 0.5\r\n0.5 0 0.5 0.5\r\n0.5 0.5 0 0.5\r\n0.5 0.5 0.5 0\r\n", "output": "0.250000 0.250000 0.250000 0.250000 "}, {"input": "5\r\n0 1 1 1 1\r\n0 0 0.5 0.5 0.5\r\n0 0.5 0 0.5 0.5\r\n0 0.5 0.5 0 0.5\r\n0 0.5 0.5 0.5 0\r\n", "ou...
false
stdio
import sys def read_floats_from_file(path): with open(path, 'r') as f: line = f.readline().strip() return list(map(float, line.split())) def main(): input_path, output_path, submission_path = sys.argv[1:4] expected = read_floats_from_file(output_path) submission = read_floats_from_fil...
true
16/E
16
E
Python 3
TESTS
1
60
0
182130459
n = int(input()) a = [] for i in range(n): a.append(list(map(float, input().split()))) output = [0] * n for i in range(n): p = 1 for j in range(n): if i != j: p *= a[i][j] output[i] = format(p, '.6f') for x in range(n): if x == n - 1: print(output[x]) else: pr...
20
1,090
7,372,800
180427251
def Is_bit_on(mask, i): return ((mask >> i) & 1) == 1 def turn_bit_off(mask, i): return ~(1 << i) & mask def turn_bit_on(mask, i): return (1 << i) | mask def count_on_bit(mask, n): count = 0 for i in range(n): if Is_bit_on(mask, i): count += 1 return count n = int(input()...
Codeforces Beta Round 16 (Div. 2 Only)
ICPC
2,010
3
128
Fish
n fish, numbered from 1 to n, live in a lake. Every day right one pair of fish meet, and the probability of each other pair meeting is the same. If two fish with indexes i and j meet, the first will eat up the second with the probability aij, and the second will eat up the first with the probability aji = 1 - aij. The ...
The first line contains integer n (1 ≤ n ≤ 18) — the amount of fish in the lake. Then there follow n lines with n real numbers each — matrix a. aij (0 ≤ aij ≤ 1) — the probability that fish with index i eats up fish with index j. It's guaranteed that the main diagonal contains zeros only, and for other elements the fol...
Output n space-separated real numbers accurate to not less than 6 decimal places. Number with index i should be equal to the probability that fish with index i will survive to be the last in the lake.
null
null
[{"input": "2\n0 0.5\n0.5 0", "output": "0.500000 0.500000"}, {"input": "5\n0 1 1 1 1\n0 0 0.5 0.5 0.5\n0 0.5 0 0.5 0.5\n0 0.5 0.5 0 0.5\n0 0.5 0.5 0.5 0", "output": "1.000000 0.000000 0.000000 0.000000 0.000000"}]
1,900
["bitmasks", "dp", "probabilities"]
20
[{"input": "2\r\n0 0.5\r\n0.5 0\r\n", "output": "0.500000 0.500000 "}, {"input": "4\r\n0 0.5 0.5 0.5\r\n0.5 0 0.5 0.5\r\n0.5 0.5 0 0.5\r\n0.5 0.5 0.5 0\r\n", "output": "0.250000 0.250000 0.250000 0.250000 "}, {"input": "5\r\n0 1 1 1 1\r\n0 0 0.5 0.5 0.5\r\n0 0.5 0 0.5 0.5\r\n0 0.5 0.5 0 0.5\r\n0 0.5 0.5 0.5 0\r\n", "ou...
false
stdio
import sys def read_floats_from_file(path): with open(path, 'r') as f: line = f.readline().strip() return list(map(float, line.split())) def main(): input_path, output_path, submission_path = sys.argv[1:4] expected = read_floats_from_file(output_path) submission = read_floats_from_fil...
true
167/A
167
A
PyPy 3
TESTS
1
140
1,638,400
117057941
import collections import functools import math import sys def In(): return map(int, sys.stdin.readline().split()) input = sys.stdin.readline import functools import math import sys def In(): return map(int, sys.stdin.readline().split()) input = sys.stdin.readline def wiztroll(): def calcnewd(old,...
57
218
12,697,600
183322705
import sys input = sys.stdin.readline n, a, d = map(int, input().split()) p = [0]*n for i in range(n): t, v = map(int,input().split()) x = v/a y = (2*d/a) ** 0.5 p[i] = t+y if y < x else t + d/v + x/2 p[i] = max(p[i-1],p[i]) print('\n'.join(map(str, p)))
Codeforces Round 114 (Div. 1)
CF
2,012
1
256
Wizards and Trolleybuses
In some country live wizards. They love to ride trolleybuses. A city in this country has a trolleybus depot with n trolleybuses. Every day the trolleybuses leave the depot, one by one and go to the final station. The final station is at a distance of d meters from the depot. We know for the i-th trolleybus that it lea...
The first input line contains three space-separated integers n, a, d (1 ≤ n ≤ 105, 1 ≤ a, d ≤ 106) — the number of trolleybuses, their maximum acceleration and the distance from the depot to the final station, correspondingly. Next n lines contain pairs of integers ti vi (0 ≤ t1 < t2... < tn - 1 < tn ≤ 106, 1 ≤ vi ≤ 1...
For each trolleybus print a single line the time it arrives to the final station. Print the times for the trolleybuses in the order in which the trolleybuses are given in the input. The answer will be accepted if the absolute or relative error doesn't exceed 10 - 4.
null
In the first sample the second trolleybus will catch up with the first one, that will happen at distance 510.5 meters from the depot. The trolleybuses will go the remaining 9489.5 meters together at speed 10 meters per second. As a result, both trolleybuses will arrive to the final station by the moment of time 1000.5 ...
[{"input": "3 10 10000\n0 10\n5 11\n1000 1", "output": "1000.5000000000\n1000.5000000000\n11000.0500000000"}, {"input": "1 2 26\n28 29", "output": "33.0990195136"}]
1,600
["implementation", "math"]
57
[{"input": "3 10 10000\r\n0 10\r\n5 11\r\n1000 1\r\n", "output": "1000.5000000000\r\n1000.5000000000\r\n11000.0500000000\r\n"}, {"input": "1 2 26\r\n28 29\r\n", "output": "33.0990195136\r\n"}, {"input": "7 8 3\r\n1 3\r\n5 26\r\n7 3\r\n10 15\r\n18 7\r\n21 17\r\n23 21\r\n", "output": "2.1875000000\r\n5.8660254038\r\n8.18...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path) as f: n, a, d = map(int, f.readline().split()) # Read correct output correct = [] with open(output_path) as f: for line in f: line = li...
true
355/B
355
B
Python 3
TESTS
0
30
0
232588311
def min_burles_sum(c1, c2, c3, c4, n, m, bus_rides, trolley_rides): bus_cost = min(c1 * ride for ride in bus_rides) trolley_cost = min(c1 * ride for ride in trolley_rides) unlimited_both_cost = min(c4, min(c2, c3) * (min(bus_rides) + min(trolley_rides))) return min(bus_cost + trolley_cost, unlimited_bo...
27
46
307,200
4779983
c1,c2,c3,c4=map(int, input().split()) n,m=map(int, input().split()) a=list(map(int, input().split())) b=list(map(int, input().split())) mn1,mn2=0,0 for i in range(n): if(a[i]<c2//c1+1): mn1+=c1*a[i] else: mn1+=c2 for i in range(m): if(b[i]<c2//c1+1): mn2+=c1*b[i] else: mn...
Codeforces Round 206 (Div. 2)
CF
2,013
1
256
Vasya and Public Transport
Vasya often uses public transport. The transport in the city is of two types: trolleys and buses. The city has n buses and m trolleys, the buses are numbered by integers from 1 to n, the trolleys are numbered by integers from 1 to m. Public transport is not free. There are 4 types of tickets: 1. A ticket for one ride...
The first line contains four integers c1, c2, c3, c4 (1 ≤ c1, c2, c3, c4 ≤ 1000) — the costs of the tickets. The second line contains two integers n and m (1 ≤ n, m ≤ 1000) — the number of buses and trolleys Vasya is going to use. The third line contains n integers ai (0 ≤ ai ≤ 1000) — the number of times Vasya is go...
Print a single number — the minimum sum of burles Vasya will have to spend on the tickets.
null
In the first sample the profitable strategy is to buy two tickets of the first type (for the first bus), one ticket of the second type (for the second bus) and one ticket of the third type (for all trolleys). It totals to (2·1) + 3 + 7 = 12 burles. In the second sample the profitable strategy is to buy one ticket of t...
[{"input": "1 3 7 19\n2 3\n2 5\n4 4 4", "output": "12"}, {"input": "4 3 2 1\n1 3\n798\n1 2 3", "output": "1"}, {"input": "100 100 8 100\n3 5\n7 94 12\n100 1 47 0 42", "output": "16"}]
1,100
["greedy", "implementation"]
27
[{"input": "1 3 7 19\r\n2 3\r\n2 5\r\n4 4 4\r\n", "output": "12\r\n"}, {"input": "4 3 2 1\r\n1 3\r\n798\r\n1 2 3\r\n", "output": "1\r\n"}, {"input": "100 100 8 100\r\n3 5\r\n7 94 12\r\n100 1 47 0 42\r\n", "output": "16\r\n"}, {"input": "3 103 945 1000\r\n7 9\r\n34 35 34 35 34 35 34\r\n0 0 0 0 0 0 0 0 0\r\n", "output": ...
false
stdio
null
true
16/E
16
E
PyPy 3-64
TESTS
1
92
0
226065864
n = int(input()) a = [[float(x) for x in input().split()] for _ in range(n)] products = [1] * n for row in a: for c, p in enumerate(row): products[c] *= 1-p for p in products: print(f'{p:f}', end=' ')
20
1,526
10,444,800
176502052
def get_bit_count(value): n = 0 while value: n += 1 value &= value-1 return n def pMove(ss, s, p, fish, n): num = 0 x = get_bit_count(ss) den = (x * (x - 1)) / 2 for i in range(n): if s & (1 << i) != 0: num += p[i][fish] return num / den def dp(n, p, s, ...
Codeforces Beta Round 16 (Div. 2 Only)
ICPC
2,010
3
128
Fish
n fish, numbered from 1 to n, live in a lake. Every day right one pair of fish meet, and the probability of each other pair meeting is the same. If two fish with indexes i and j meet, the first will eat up the second with the probability aij, and the second will eat up the first with the probability aji = 1 - aij. The ...
The first line contains integer n (1 ≤ n ≤ 18) — the amount of fish in the lake. Then there follow n lines with n real numbers each — matrix a. aij (0 ≤ aij ≤ 1) — the probability that fish with index i eats up fish with index j. It's guaranteed that the main diagonal contains zeros only, and for other elements the fol...
Output n space-separated real numbers accurate to not less than 6 decimal places. Number with index i should be equal to the probability that fish with index i will survive to be the last in the lake.
null
null
[{"input": "2\n0 0.5\n0.5 0", "output": "0.500000 0.500000"}, {"input": "5\n0 1 1 1 1\n0 0 0.5 0.5 0.5\n0 0.5 0 0.5 0.5\n0 0.5 0.5 0 0.5\n0 0.5 0.5 0.5 0", "output": "1.000000 0.000000 0.000000 0.000000 0.000000"}]
1,900
["bitmasks", "dp", "probabilities"]
20
[{"input": "2\r\n0 0.5\r\n0.5 0\r\n", "output": "0.500000 0.500000 "}, {"input": "4\r\n0 0.5 0.5 0.5\r\n0.5 0 0.5 0.5\r\n0.5 0.5 0 0.5\r\n0.5 0.5 0.5 0\r\n", "output": "0.250000 0.250000 0.250000 0.250000 "}, {"input": "5\r\n0 1 1 1 1\r\n0 0 0.5 0.5 0.5\r\n0 0.5 0 0.5 0.5\r\n0 0.5 0.5 0 0.5\r\n0 0.5 0.5 0.5 0\r\n", "ou...
false
stdio
import sys def read_floats_from_file(path): with open(path, 'r') as f: line = f.readline().strip() return list(map(float, line.split())) def main(): input_path, output_path, submission_path = sys.argv[1:4] expected = read_floats_from_file(output_path) submission = read_floats_from_fil...
true
961/E
961
E
PyPy 3
TESTS
3
218
0
58887987
from sys import stdin from sys import setrecursionlimit as SRL; SRL(10**7) rd = stdin.readline rrd = lambda: map(int, rd().strip().split()) n = int(rd()) a = list(rrd()) bit = [0] * (n+10) def get(x): tot = 0 while x: tot += bit[x] x -= x&(-x) return tot def ins(x): while x<=(n+1):...
30
498
44,236,800
128480912
from collections import defaultdict import sys input = sys.stdin.readline def make_tree(n): tree = [0] * (n + 1) return tree def get_sum(i): s = 0 while i > 0: s += tree[i] i -= i & -i return s def get_sum_segment(s, t): if s > t: return 0 ans = get_sum(t) - get_su...
Educational Codeforces Round 41 (Rated for Div. 2)
ICPC
2,018
2
256
Tufurama
One day Polycarp decided to rewatch his absolute favourite episode of well-known TV series "Tufurama". He was pretty surprised when he got results only for season 7 episode 3 with his search query of "Watch Tufurama season 3 episode 7 online full hd free". This got Polycarp confused — what if he decides to rewatch the ...
The first line contains one integer n (1 ≤ n ≤ 2·105) — the number of seasons. The second line contains n integers separated by space a1, a2, ..., an (1 ≤ ai ≤ 109) — number of episodes in each season.
Print one integer — the number of pairs x and y (x < y) such that there exist both season x episode y and season y episode x.
null
Possible pairs in the second example: 1. x = 1, y = 2 (season 1 episode 2 $$\text{The formula used to produce the text is not provided in the image.}$$ season 2 episode 1); 2. x = 2, y = 3 (season 2 episode 3 $$\text{The formula used to produce the text is not provided in the image.}$$ season 3 episode 2); 3. x = 1, y...
[{"input": "5\n1 2 3 4 5", "output": "0"}, {"input": "3\n8 12 7", "output": "3"}, {"input": "3\n3 2 1", "output": "2"}]
1,900
["data structures"]
30
[{"input": "5\r\n1 2 3 4 5\r\n", "output": "0\r\n"}, {"input": "3\r\n8 12 7\r\n", "output": "3\r\n"}, {"input": "3\r\n3 2 1\r\n", "output": "2\r\n"}, {"input": "5\r\n2 3 4 5 6\r\n", "output": "4\r\n"}, {"input": "8\r\n7 2 6 6 5 1 4 9\r\n", "output": "9\r\n"}, {"input": "10\r\n1000000000 1000000000 1000000000 1000000000...
false
stdio
null
true
962/E
962
E
PyPy 3
TESTS
0
61
20,172,800
129567902
class SegTree: def __init__(self, init_val, ide_ele, segfunc): self.n = len(init_val) self.num = 2**(self.n-1).bit_length() self.ide_ele = ide_ele self.segfunc = segfunc self.seg = [ide_ele]*2*self.num # set_val for i in range(self.n): self.seg[i+s...
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
665/B
665
B
PyPy 3-64
TESTS
3
46
0
147572563
n,m,k=map(int,input().split()) arr=list(map(int,input().split())) quer=[] for i in range(m): quer.append(list(map(int,input().split()))) ans=0 for i in range(m): a=quer[i] for j in a: d=arr.index(j) ans+=d+1 for ind in range(d-1,-1,-1): arr[ind+1]=arr[ind] arr[0]=...
10
61
5,120,000
18482341
ln=input().split(" ") n=int(ln[0]) m=int(ln[1]) k=int(ln[2]) x=0 pila=input().split(" ") for i in range(n): cus=input().split(" ") for j in range(m): ind=pila.index(cus[j]) x=x+ind+1 pila.insert(0,pila.pop(ind)) print(x)
Educational Codeforces Round 12
ICPC
2,016
1
256
Shopping
Ayush is a cashier at the shopping center. Recently his department has started a ''click and collect" service which allows users to shop online. The store contains k items. n customers have already used the above service. Each user paid for m items. Let aij denote the j-th item in the i-th person's order. Due to the ...
The first line contains three integers n, m and k (1 ≤ n, k ≤ 100, 1 ≤ m ≤ k) — the number of users, the number of items each user wants to buy and the total number of items at the market. The next line contains k distinct integers pl (1 ≤ pl ≤ k) denoting the initial positions of the items in the store. The items are...
Print the only integer t — the total time needed for Ayush to process all the orders.
null
Customer 1 wants the items 1 and 5. pos(1) = 3, so the new positions are: [1, 3, 4, 2, 5]. pos(5) = 5, so the new positions are: [5, 1, 3, 4, 2]. Time taken for the first customer is 3 + 5 = 8. Customer 2 wants the items 3 and 1. pos(3) = 3, so the new positions are: [3, 5, 1, 4, 2]. pos(1) = 3, so the new positi...
[{"input": "2 2 5\n3 4 1 2 5\n1 5\n3 1", "output": "14"}]
1,400
["brute force"]
10
[{"input": "2 2 5\r\n3 4 1 2 5\r\n1 5\r\n3 1\r\n", "output": "14\r\n"}, {"input": "4 4 4\r\n1 2 3 4\r\n3 4 2 1\r\n4 3 2 1\r\n4 1 2 3\r\n4 1 2 3\r\n", "output": "59\r\n"}, {"input": "1 1 1\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "10 1 100\r\n1 55 67 75 40 86 24 84 82 26 81 23 70 79 51 54 21 78 31 98 68 93 66 88 99...
false
stdio
null
true
241/A
241
A
PyPy 3
TESTS
5
248
102,400
62920711
# CF 241/A 1300 # S = supply in city i # D = distance from c[i] to c[i + 1] # k = refresh interval # min time to arrive at C[n] where n = m + 1 def f(k, D, S): n = len(D) lastpositive = n fuel = 0 for i in range(n - 1, -1, -1): fuel += (S[i] - D[i]) if fuel >= 0: lastposi...
52
62
307,200
4927898
n, k = map(int, input().split()) l, a = list(map(int, input().split())), list(map(int, input().split())) v, t, s = 0, 0, sum(l) for i in range(n): l[i] -= a[i] L, A = [l[0]], [a[0]] for i in range(1, n): if a[i] <= A[-1]: L[-1] += l[i] else: A.append(a[i]) L.append(l[i]) for i in range(len(A...
Bayan 2012-2013 Elimination Round (ACM ICPC Rules, English statements)
ICPC
2,012
2
256
Old Peykan
There are n cities in the country where the Old Peykan lives. These cities are located on a straight line, we'll denote them from left to right as c1, c2, ..., cn. The Old Peykan wants to travel from city c1 to cn using roads. There are (n - 1) one way roads, the i-th road goes from city ci to city ci + 1 and is di kil...
The first line of the input contains two space-separated integers m and k (1 ≤ m, k ≤ 1000). The value m specifies the number of roads between cities which is equal to n - 1. The next line contains m space-separated integers d1, d2, ..., dm (1 ≤ di ≤ 1000) and the following line contains m space-separated integers s1,...
In the only line of the output print a single integer — the minimum time required for The Old Peykan to reach city cn from city c1.
null
In the second sample above, the Old Peykan stays in c1 for 3 hours.
[{"input": "4 6\n1 2 5 2\n2 3 3 4", "output": "10"}, {"input": "2 3\n5 6\n5 5", "output": "14"}]
1,300
["greedy"]
52
[{"input": "4 6\r\n1 2 5 2\r\n2 3 3 4\r\n", "output": "10\r\n"}, {"input": "2 3\r\n5 6\r\n5 5\r\n", "output": "14\r\n"}, {"input": "24 3\r\n11 8 8 12 17 4 4 25 39 37 31 32 38 34 29 29 34 39 39 39 17 9 24 6\r\n3 5 4 3 3 3 4 3 4 3 3 3 3 4 3 3 4 3 4 3 3 3 3 3\r\n", "output": "862\r\n"}, {"input": "43 5\r\n6 7 15 12 15 7 2...
false
stdio
null
true
1298/E
978
F
PyPy 3-64
TESTS
4
62
0
230899558
class UFDS: def __init__(self, n): self.parents = list(range(n)) self.ranks = [0] * n self.sizes = [1] * n self.numdisjoint = n def find(self, x): xp = x children = [] while xp != self.parents[xp]: children.append(xp) xp = self.par...
41
561
33,177,600
226929994
# https://codeforces.com/contest/978 import sys input = lambda: sys.stdin.readline().rstrip() # faster! n, k = map(int, input().split()) r = list(map(int, input().split())) ans = [0] * n idx = sorted(range(n), key=lambda i: r[i]) duplicate = 0 for i in range(1, n): if r[idx[i]] == r[idx[i - 1]]: ans[i...
Kotlin Heroes: Practice 3
ICPC
2,020
3
256
Mentors
In BerSoft $$$n$$$ programmers work, the programmer $$$i$$$ is characterized by a skill $$$r_i$$$. A programmer $$$a$$$ can be a mentor of a programmer $$$b$$$ if and only if the skill of the programmer $$$a$$$ is strictly greater than the skill of the programmer $$$b$$$ $$$(r_a > r_b)$$$ and programmers $$$a$$$ and $...
The first line contains two integers $$$n$$$ and $$$k$$$ $$$(2 \le n \le 2 \cdot 10^5$$$, $$$0 \le k \le \min(2 \cdot 10^5, \frac{n \cdot (n - 1)}{2}))$$$ — total number of programmers and number of pairs of programmers which are in a quarrel. The second line contains a sequence of integers $$$r_1, r_2, \dots, r_n$$$ ...
Print $$$n$$$ integers, the $$$i$$$-th number should be equal to the number of programmers, for which the $$$i$$$-th programmer can be a mentor. Programmers are numbered in the same order that their skills are given in the input.
null
In the first example, the first programmer can not be mentor of any other (because only the second programmer has a skill, lower than first programmer skill, but they are in a quarrel). The second programmer can not be mentor of any other programmer, because his skill is minimal among others. The third programmer can b...
[{"input": "4 2\n10 4 10 15\n1 2\n4 3", "output": "0 0 1 2"}, {"input": "10 4\n5 4 1 5 4 3 7 1 2 5\n4 6\n2 1\n10 8\n3 5", "output": "5 4 0 5 3 3 9 0 2 5"}]
null
["*special", "data structures", "implementation"]
41
[{"input": "4 2\r\n10 4 10 15\r\n1 2\r\n4 3\r\n", "output": "0 0 1 2 \r\n"}, {"input": "10 4\r\n5 4 1 5 4 3 7 1 2 5\r\n4 6\r\n2 1\r\n10 8\r\n3 5\r\n", "output": "5 4 0 5 3 3 9 0 2 5 \r\n"}, {"input": "2 0\r\n3 1\r\n", "output": "1 0 \r\n"}, {"input": "2 0\r\n1 1\r\n", "output": "0 0 \r\n"}, {"input": "10 35\r\n32202222...
false
stdio
null
true
1298/E
978
F
PyPy 3-64
TESTS
4
62
0
213140394
from collections import * import sys input = sys.stdin.readline MOD = 10**9 + 7 def read_array(factory): return [factory(num) for num in input().strip().split()] def print_array(arr): print(" ".join(map(str, arr))) # Left insertion point since strictly greater for mentor def bin_search(arr, target): lo,...
41
576
52,736,000
172445737
import sys input = sys.stdin.readline import bisect n, k = map(int, input().split()) w = list(map(int, input().split())) q = sorted(w) d = [[] for i in range(n)] for i in range(k): a, b = map(lambda x:int(x)-1, input().split()) d[a].append(b) d[b].append(a) for i in range(n): x = bisect.bisect_left(q...
Kotlin Heroes: Practice 3
ICPC
2,020
3
256
Mentors
In BerSoft $$$n$$$ programmers work, the programmer $$$i$$$ is characterized by a skill $$$r_i$$$. A programmer $$$a$$$ can be a mentor of a programmer $$$b$$$ if and only if the skill of the programmer $$$a$$$ is strictly greater than the skill of the programmer $$$b$$$ $$$(r_a > r_b)$$$ and programmers $$$a$$$ and $...
The first line contains two integers $$$n$$$ and $$$k$$$ $$$(2 \le n \le 2 \cdot 10^5$$$, $$$0 \le k \le \min(2 \cdot 10^5, \frac{n \cdot (n - 1)}{2}))$$$ — total number of programmers and number of pairs of programmers which are in a quarrel. The second line contains a sequence of integers $$$r_1, r_2, \dots, r_n$$$ ...
Print $$$n$$$ integers, the $$$i$$$-th number should be equal to the number of programmers, for which the $$$i$$$-th programmer can be a mentor. Programmers are numbered in the same order that their skills are given in the input.
null
In the first example, the first programmer can not be mentor of any other (because only the second programmer has a skill, lower than first programmer skill, but they are in a quarrel). The second programmer can not be mentor of any other programmer, because his skill is minimal among others. The third programmer can b...
[{"input": "4 2\n10 4 10 15\n1 2\n4 3", "output": "0 0 1 2"}, {"input": "10 4\n5 4 1 5 4 3 7 1 2 5\n4 6\n2 1\n10 8\n3 5", "output": "5 4 0 5 3 3 9 0 2 5"}]
null
["*special", "data structures", "implementation"]
41
[{"input": "4 2\r\n10 4 10 15\r\n1 2\r\n4 3\r\n", "output": "0 0 1 2 \r\n"}, {"input": "10 4\r\n5 4 1 5 4 3 7 1 2 5\r\n4 6\r\n2 1\r\n10 8\r\n3 5\r\n", "output": "5 4 0 5 3 3 9 0 2 5 \r\n"}, {"input": "2 0\r\n3 1\r\n", "output": "1 0 \r\n"}, {"input": "2 0\r\n1 1\r\n", "output": "0 0 \r\n"}, {"input": "10 35\r\n32202222...
false
stdio
null
true
1298/E
978
F
Python 3
TESTS
3
31
307,200
208836481
import copy n,k=map(int,input().split()) skills=list(map(int,input().split())) mot3arkin=[[]for i in range(n+1)] for i in range(k): x,y=map(int,input().split()) mot3arkin[x].append(y) mot3arkin[y].append(x) skills1=copy.deepcopy(skills) skills1.sort(reverse=True) for i in range(1,n+1): adad=0 may9ar...
41
623
51,097,600
226929592
# https://codeforces.com/contest/978 import sys input = lambda: sys.stdin.readline().rstrip() # faster! n, k = map(int, input().split()) r = list(map(int, input().split())) xy = [tuple(map(lambda x: int(x) - 1, input().split())) for _ in range(k)] idx = sorted(range(n), key=lambda i: r[i]) ans = [0] * n duplicate...
Kotlin Heroes: Practice 3
ICPC
2,020
3
256
Mentors
In BerSoft $$$n$$$ programmers work, the programmer $$$i$$$ is characterized by a skill $$$r_i$$$. A programmer $$$a$$$ can be a mentor of a programmer $$$b$$$ if and only if the skill of the programmer $$$a$$$ is strictly greater than the skill of the programmer $$$b$$$ $$$(r_a > r_b)$$$ and programmers $$$a$$$ and $...
The first line contains two integers $$$n$$$ and $$$k$$$ $$$(2 \le n \le 2 \cdot 10^5$$$, $$$0 \le k \le \min(2 \cdot 10^5, \frac{n \cdot (n - 1)}{2}))$$$ — total number of programmers and number of pairs of programmers which are in a quarrel. The second line contains a sequence of integers $$$r_1, r_2, \dots, r_n$$$ ...
Print $$$n$$$ integers, the $$$i$$$-th number should be equal to the number of programmers, for which the $$$i$$$-th programmer can be a mentor. Programmers are numbered in the same order that their skills are given in the input.
null
In the first example, the first programmer can not be mentor of any other (because only the second programmer has a skill, lower than first programmer skill, but they are in a quarrel). The second programmer can not be mentor of any other programmer, because his skill is minimal among others. The third programmer can b...
[{"input": "4 2\n10 4 10 15\n1 2\n4 3", "output": "0 0 1 2"}, {"input": "10 4\n5 4 1 5 4 3 7 1 2 5\n4 6\n2 1\n10 8\n3 5", "output": "5 4 0 5 3 3 9 0 2 5"}]
null
["*special", "data structures", "implementation"]
41
[{"input": "4 2\r\n10 4 10 15\r\n1 2\r\n4 3\r\n", "output": "0 0 1 2 \r\n"}, {"input": "10 4\r\n5 4 1 5 4 3 7 1 2 5\r\n4 6\r\n2 1\r\n10 8\r\n3 5\r\n", "output": "5 4 0 5 3 3 9 0 2 5 \r\n"}, {"input": "2 0\r\n3 1\r\n", "output": "1 0 \r\n"}, {"input": "2 0\r\n1 1\r\n", "output": "0 0 \r\n"}, {"input": "10 35\r\n32202222...
false
stdio
null
true
1298/E
978
F
PyPy 3-64
TESTS
4
46
0
179489888
n, k = map(int, input().split()) t = list(map(int, input().split())) t = list(enumerate(t)) r = sorted(t, key=lambda x: x[1]) #print(r) kol = [0] * n ans = [0] * n cnt = 0 for i in range(n - 1): if r[i][1] < r[i + 1][1]: kol[i + 1] = kol[i] + 1 + cnt cnt = 0 else: kol[i + 1] = kol[i] cnt += 1 #print(kol) for ...
41
639
57,856,000
211072288
import sys input = lambda: sys.stdin.readline().rstrip() from collections import deque,defaultdict,Counter from itertools import permutations,combinations from bisect import * from heapq import * from math import ceil,gcd,lcm,floor,comb N,M = map(int,input().split()) A = list(map(int,input().split())) P = [[] for _ in...
Kotlin Heroes: Practice 3
ICPC
2,020
3
256
Mentors
In BerSoft $$$n$$$ programmers work, the programmer $$$i$$$ is characterized by a skill $$$r_i$$$. A programmer $$$a$$$ can be a mentor of a programmer $$$b$$$ if and only if the skill of the programmer $$$a$$$ is strictly greater than the skill of the programmer $$$b$$$ $$$(r_a > r_b)$$$ and programmers $$$a$$$ and $...
The first line contains two integers $$$n$$$ and $$$k$$$ $$$(2 \le n \le 2 \cdot 10^5$$$, $$$0 \le k \le \min(2 \cdot 10^5, \frac{n \cdot (n - 1)}{2}))$$$ — total number of programmers and number of pairs of programmers which are in a quarrel. The second line contains a sequence of integers $$$r_1, r_2, \dots, r_n$$$ ...
Print $$$n$$$ integers, the $$$i$$$-th number should be equal to the number of programmers, for which the $$$i$$$-th programmer can be a mentor. Programmers are numbered in the same order that their skills are given in the input.
null
In the first example, the first programmer can not be mentor of any other (because only the second programmer has a skill, lower than first programmer skill, but they are in a quarrel). The second programmer can not be mentor of any other programmer, because his skill is minimal among others. The third programmer can b...
[{"input": "4 2\n10 4 10 15\n1 2\n4 3", "output": "0 0 1 2"}, {"input": "10 4\n5 4 1 5 4 3 7 1 2 5\n4 6\n2 1\n10 8\n3 5", "output": "5 4 0 5 3 3 9 0 2 5"}]
null
["*special", "data structures", "implementation"]
41
[{"input": "4 2\r\n10 4 10 15\r\n1 2\r\n4 3\r\n", "output": "0 0 1 2 \r\n"}, {"input": "10 4\r\n5 4 1 5 4 3 7 1 2 5\r\n4 6\r\n2 1\r\n10 8\r\n3 5\r\n", "output": "5 4 0 5 3 3 9 0 2 5 \r\n"}, {"input": "2 0\r\n3 1\r\n", "output": "1 0 \r\n"}, {"input": "2 0\r\n1 1\r\n", "output": "0 0 \r\n"}, {"input": "10 35\r\n32202222...
false
stdio
null
true
1298/E
978
F
PyPy 3-64
TESTS
4
61
0
230899970
input = __import__('sys').stdin.readline if __name__ == "__main__": n, k = map(int, input().split()) programers = list(map(int, input().split())) pairs = {} for _ in range(k): a, b = map(int, input().split()) pairs[a - 1] = b-1 pairs[b - 1] = a-1 ans = [0] * n for i in ra...
41
670
40,448,000
38179172
import sys,bisect read=lambda:map(int,sys.stdin.buffer.readline().split()) n,k=read() r=list(read()) v=r.copy() v.sort() t=[bisect.bisect_left(v,x) for x in r] for _ in range(k): a,b=read();a-=1;b-=1 if r[a]>r[b]: t[a]-=1 if r[b]>r[a]: t[b]-=1 print(*t)
Kotlin Heroes: Practice 3
ICPC
2,020
3
256
Mentors
In BerSoft $$$n$$$ programmers work, the programmer $$$i$$$ is characterized by a skill $$$r_i$$$. A programmer $$$a$$$ can be a mentor of a programmer $$$b$$$ if and only if the skill of the programmer $$$a$$$ is strictly greater than the skill of the programmer $$$b$$$ $$$(r_a > r_b)$$$ and programmers $$$a$$$ and $...
The first line contains two integers $$$n$$$ and $$$k$$$ $$$(2 \le n \le 2 \cdot 10^5$$$, $$$0 \le k \le \min(2 \cdot 10^5, \frac{n \cdot (n - 1)}{2}))$$$ — total number of programmers and number of pairs of programmers which are in a quarrel. The second line contains a sequence of integers $$$r_1, r_2, \dots, r_n$$$ ...
Print $$$n$$$ integers, the $$$i$$$-th number should be equal to the number of programmers, for which the $$$i$$$-th programmer can be a mentor. Programmers are numbered in the same order that their skills are given in the input.
null
In the first example, the first programmer can not be mentor of any other (because only the second programmer has a skill, lower than first programmer skill, but they are in a quarrel). The second programmer can not be mentor of any other programmer, because his skill is minimal among others. The third programmer can b...
[{"input": "4 2\n10 4 10 15\n1 2\n4 3", "output": "0 0 1 2"}, {"input": "10 4\n5 4 1 5 4 3 7 1 2 5\n4 6\n2 1\n10 8\n3 5", "output": "5 4 0 5 3 3 9 0 2 5"}]
null
["*special", "data structures", "implementation"]
41
[{"input": "4 2\r\n10 4 10 15\r\n1 2\r\n4 3\r\n", "output": "0 0 1 2 \r\n"}, {"input": "10 4\r\n5 4 1 5 4 3 7 1 2 5\r\n4 6\r\n2 1\r\n10 8\r\n3 5\r\n", "output": "5 4 0 5 3 3 9 0 2 5 \r\n"}, {"input": "2 0\r\n3 1\r\n", "output": "1 0 \r\n"}, {"input": "2 0\r\n1 1\r\n", "output": "0 0 \r\n"}, {"input": "10 35\r\n32202222...
false
stdio
null
true
469/B
469
B
Python 3
TESTS
1
30
0
225550094
def function(little_x): for i in range(len(little_x)): little_x[i][0] = little_x[i][0] + 1 little_x[i][1] = little_x[i][1] + 1 return little_x result = 0 p, q, l, r = map(int, input().split()) z = [] x = [] for i in range(p): a, b = map(int, input().split()) z.append([a, b]) for i in r...
31
93
2,048,000
224035520
p, q, l, r = map(int, input().split()) intervals = [False] * 1001 for k in range(p): i, j = map(int, input().split()) for index in range(i, j+1): intervals[index] = True arr = [] for k in range(q): i, j = map(int, input().split()) arr.append((i, j)) res = 0 for i in range(l, r+1): for x,...
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
520/C
520
C
PyPy 3-64
TESTS
0
30
0
224964163
import sys input = sys.stdin.readline from collections import Counter n = int(input()) chars = input() cnt = Counter(chars) value_cnts = Counter(cnt.values()) ans = 1 mod = 10 ** 9 + 7 for idx in range(n): ans *= value_cnts[cnt[chars[idx]]] ans %= mod print(ans)
25
62
204,800
10113424
n = int(input()) s = input() num = s.count("A") num1 = s.count("C") num2 = s.count("T") num3 = s.count("G") num4 = max(num,num1,num2,num3) num5 = 0 if num == num4: num5 += 1 if num1 == num4: num5 += 1 if num2 == num4: num5 += 1 if num3 == num4: num5 += 1 if num5 == 1 or n == 1: print(1) else: pr...
Codeforces Round 295 (Div. 2)
CF
2,015
2
256
DNA Alignment
Vasya became interested in bioinformatics. He's going to write an article about similar cyclic DNA sequences, so he invented a new method for determining the similarity of cyclic sequences. Let's assume that strings s and t have the same length n, then the function h(s, t) is defined as the number of positions in whic...
The first line of the input contains a single integer n (1 ≤ n ≤ 105). The second line of the input contains a single string of length n, consisting of characters "ACGT".
Print a single number — the answer modulo 109 + 7.
null
Please note that if for two distinct strings t1 and t2 values ρ(s, t1) и ρ(s, t2) are maximum among all possible t, then both strings must be taken into account in the answer even if one of them can be obtained by a circular shift of another one. In the first sample, there is ρ("C", "C") = 1, for the remaining strings...
[{"input": "1\nC", "output": "1"}, {"input": "2\nAG", "output": "4"}, {"input": "3\nTTT", "output": "1"}]
1,500
["math", "strings"]
25
[{"input": "1\r\nC\r\n", "output": "1\r\n"}, {"input": "2\r\nAG\r\n", "output": "4\r\n"}, {"input": "3\r\nTTT\r\n", "output": "1\r\n"}, {"input": "4\r\nGACT\r\n", "output": "256\r\n"}, {"input": "1\r\nT\r\n", "output": "1\r\n"}, {"input": "2\r\nAG\r\n", "output": "4\r\n"}, {"input": "3\r\nGCA\r\n", "output": "27\r\n"},...
false
stdio
null
true
802/M
802
M
Python 3
TESTS
1
30
4,198,400
135260545
a,b=input().split();print(sum(list(map(int,input().split()))[:int(b)]))
14
46
0
192618520
# LUOGU_RID: 101671699 n, k, *a = map(int, open(0).read().split()) print(sum(sorted(a)[:k]))
Helvetic Coding Contest 2017 online mirror (teams allowed, unrated)
ICPC
2,017
2
256
April Fools' Problem (easy)
The marmots have prepared a very easy problem for this year's HC2 – this one. It involves numbers n, k and a sequence of n positive integers a1, a2, ..., an. They also came up with a beautiful and riveting story for the problem statement. It explains what the input means, what the program should output, and it also rea...
The first line of the input contains two space-separated integers n and k (1 ≤ k ≤ n ≤ 2200). The second line contains n space-separated integers a1, ..., an (1 ≤ ai ≤ 104).
Output one number.
null
null
[{"input": "8 5\n1 1 1 1 1 1 1 1", "output": "5"}, {"input": "10 3\n16 8 2 4 512 256 32 128 64 1", "output": "7"}, {"input": "5 1\n20 10 50 30 46", "output": "10"}, {"input": "6 6\n6 6 6 6 6 6", "output": "36"}, {"input": "1 1\n100", "output": "100"}]
1,200
["greedy", "sortings"]
14
[{"input": "8 5\r\n1 1 1 1 1 1 1 1\r\n", "output": "5"}, {"input": "10 3\r\n16 8 2 4 512 256 32 128 64 1\r\n", "output": "7"}, {"input": "5 1\r\n20 10 50 30 46\r\n", "output": "10"}, {"input": "6 6\r\n6 6 6 6 6 6\r\n", "output": "36"}, {"input": "1 1\r\n100\r\n", "output": "100"}, {"input": "1 1\r\n1\r\n", "output": "1...
false
stdio
null
true
69/B
69
B
PyPy 3-64
TESTS
2
92
0
180501312
n, m = map(int, input().split()) people = [] races = 0 for _ in range(m): a = list(map(int, input().split())) races = max(races, a[1]) people.append(a) ans = 0 for section in range(1, races + 1): curr = 0 for person in range(m): if people[person][0] <= section <= people[person][1] and people[person][2] <...
67
154
0
108454863
import math #t=int(input()) #lst = list(map(int, input().strip().split(' '))) n,m = map(int, input().strip().split(' ')) lst=[0]*n time=[10000]*n for i in range(m): l,r,t,c = map(int, input().strip().split(' ')) for j in range(l,r+1): if t<time[j-1]: time[j-1]=t lst[j-1]=c print(...
Codeforces Beta Round 63 (Div. 2)
CF
2,011
2
256
Bets
In Chelyabinsk lives a much respected businessman Nikita with a strange nickname "Boss". Once Nikita decided to go with his friend Alex to the Summer Biathlon World Cup. Nikita, as a very important person, received a token which allows to place bets on each section no more than on one competitor. To begin with friends...
The first line contains two integers n and m (1 ≤ n, m ≤ 100). Then follow m lines, each containing 4 integers li, ri, ti, ci (1 ≤ li ≤ ri ≤ n, 1 ≤ ti, ci ≤ 1000).
Print a single integer, the maximal profit in roubles that the friends can get. In each of n sections it is not allowed to place bets on more than one sportsman.
null
In the first test the optimal bet is: in the 1-2 sections on biathlete 1, in section 3 on biathlete 3, in section 4 on biathlete 4. Total: profit of 5 rubles for 1 section, the profit of 5 rubles for 2 section, profit of 30 rubles for a 3 section, profit of 20 rubles for 4 section. Total profit 60 rubles. In the secon...
[{"input": "4 4\n1 4 20 5\n1 3 21 10\n3 3 4 30\n3 4 4 20", "output": "60"}, {"input": "8 4\n1 5 24 10\n2 4 6 15\n4 6 30 50\n6 7 4 20", "output": "105"}]
1,200
["greedy", "implementation"]
67
[{"input": "4 4\r\n1 4 20 5\r\n1 3 21 10\r\n3 3 4 30\r\n3 4 4 20\r\n", "output": "60"}, {"input": "8 4\r\n1 5 24 10\r\n2 4 6 15\r\n4 6 30 50\r\n6 7 4 20\r\n", "output": "105"}, {"input": "2 2\r\n1 2 3 1\r\n2 2 3 10\r\n", "output": "2"}, {"input": "20 30\r\n15 17 54 46\r\n4 18 26 18\r\n18 20 49 94\r\n12 12 83 12\r\n11 1...
false
stdio
null
true
617/C
617
C
PyPy 3
TESTS
6
155
3,686,400
228382968
import math import sys #input = sys.stdin.readline USE_FILE = False def calc_distance(x1, y1, x2, y2): return (x1 - x2) ** 2 + (y1 - y2) ** 2 def main(): n, x1, y1, x2, y2 = [int(i) for i in input().split()] points = [] d = [] for i in range(n): x, y = tuple(map(int, input().split())) ...
31
78
307,200
15529005
#!/usr/bin/env python3 from itertools import islice import math def squared_distance(p1, p2): return (p1[0] - p2[0]) ** 2 + (p1[1] - p2[1]) ** 2 def main(): n, x1, y1, x2, y2 = list(map(int, input().split())) f1, f2 = (x1, y1), (x2, y2) flowers = sorted([(int(x), int(y)) for x, y in (input().split()...
Codeforces Round 340 (Div. 2)
CF
2,016
2
256
Watering Flowers
A flowerbed has many flowers and two fountains. You can adjust the water pressure and set any values r1(r1 ≥ 0) and r2(r2 ≥ 0), giving the distances at which the water is spread from the first and second fountain respectively. You have to set such r1 and r2 that all the flowers are watered, that is, for each flower, t...
The first line of the input contains integers n, x1, y1, x2, y2 (1 ≤ n ≤ 2000, - 107 ≤ x1, y1, x2, y2 ≤ 107) — the number of flowers, the coordinates of the first and the second fountain. Next follow n lines. The i-th of these lines contains integers xi and yi ( - 107 ≤ xi, yi ≤ 107) — the coordinates of the i-th flo...
Print the minimum possible value r12 + r22. Note, that in this problem optimal answer is always integer.
null
The first sample is (r12 = 5, r22 = 1): The second sample is (r12 = 1, r22 = 32):
[{"input": "2 -1 0 5 3\n0 2\n5 2", "output": "6"}, {"input": "4 0 0 5 0\n9 4\n8 3\n-1 0\n1 4", "output": "33"}]
1,600
["implementation"]
31
[{"input": "2 -1 0 5 3\r\n0 2\r\n5 2\r\n", "output": "6\r\n"}, {"input": "4 0 0 5 0\r\n9 4\r\n8 3\r\n-1 0\r\n1 4\r\n", "output": "33\r\n"}, {"input": "5 -6 -4 0 10\r\n-7 6\r\n-9 7\r\n-5 -1\r\n-2 1\r\n-8 10\r\n", "output": "100\r\n"}, {"input": "10 -68 10 87 22\r\n30 89\r\n82 -97\r\n-52 25\r\n76 -22\r\n-20 95\r\n21 25\r...
false
stdio
null
true
665/B
665
B
PyPy 3-64
TESTS
3
46
0
147573049
n,m,k=map(int,input().split()) arr=list(map(int,input().split())) quer=[] for i in range(m): quer.append(list(map(int,input().split()))) ans=0 for i in range(m): a=quer[i] for j in a: d=arr.index(j) ans+=d+1 arr.pop(d) arr=[j]+arr print(ans)
10
62
0
212894629
import sys readline=sys.stdin.readline N,M,K=map(int,readline().split()) P=list(map(int,readline().split())) ans=0 for n in range(N): A=list(map(int,readline().split())) for a in A: i=P.index(a) ans+=i+1 P=[a]+P[:i]+P[i+1:] print(ans)
Educational Codeforces Round 12
ICPC
2,016
1
256
Shopping
Ayush is a cashier at the shopping center. Recently his department has started a ''click and collect" service which allows users to shop online. The store contains k items. n customers have already used the above service. Each user paid for m items. Let aij denote the j-th item in the i-th person's order. Due to the ...
The first line contains three integers n, m and k (1 ≤ n, k ≤ 100, 1 ≤ m ≤ k) — the number of users, the number of items each user wants to buy and the total number of items at the market. The next line contains k distinct integers pl (1 ≤ pl ≤ k) denoting the initial positions of the items in the store. The items are...
Print the only integer t — the total time needed for Ayush to process all the orders.
null
Customer 1 wants the items 1 and 5. pos(1) = 3, so the new positions are: [1, 3, 4, 2, 5]. pos(5) = 5, so the new positions are: [5, 1, 3, 4, 2]. Time taken for the first customer is 3 + 5 = 8. Customer 2 wants the items 3 and 1. pos(3) = 3, so the new positions are: [3, 5, 1, 4, 2]. pos(1) = 3, so the new positi...
[{"input": "2 2 5\n3 4 1 2 5\n1 5\n3 1", "output": "14"}]
1,400
["brute force"]
10
[{"input": "2 2 5\r\n3 4 1 2 5\r\n1 5\r\n3 1\r\n", "output": "14\r\n"}, {"input": "4 4 4\r\n1 2 3 4\r\n3 4 2 1\r\n4 3 2 1\r\n4 1 2 3\r\n4 1 2 3\r\n", "output": "59\r\n"}, {"input": "1 1 1\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "10 1 100\r\n1 55 67 75 40 86 24 84 82 26 81 23 70 79 51 54 21 78 31 98 68 93 66 88 99...
false
stdio
null
true
178/A1
178
A1
Python 3
TESTS1
4
186
307,200
95153124
import math n = int(input()) seq = list(map(lambda x: int(x), input().split())) last = seq[n - 1] def roundPO2(v): v = v - 1; v = v | v >> 1; v = v | v >> 2; v = v | v >> 4; v = v | v >> 8; v = v | v >> 16; v = v + 1; return v for k in range(1, n): move = 0 stacking = dict() ...
12
62
0
190196910
import math n=int(input()) a=[int(x) for x in input().split()] steps=0 for i in range(1, n): t=(int)(math.log2(n-i)) steps+=a[i-1] a[i+(2**t)-1]+=a[i-1] a[i-1]=0 print(steps)
ABBYY Cup 2.0 - Hard
ICPC
2,012
2
256
Educational Game
The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below. The playing field is a sequence of n non-negative integers ai numbered from 1 to n. The goal of the game is to make numbers a1, a2, ..., ak (i.e. some prefix of the sequenc...
The first input line contains a single integer n. The second line contains n integers ai (0 ≤ ai ≤ 104), separated by single spaces. The input limitations for getting 20 points are: - 1 ≤ n ≤ 300 The input limitations for getting 50 points are: - 1 ≤ n ≤ 2000 The input limitations for getting 100 points are: - 1 ...
Print exactly n - 1 lines: the k-th output line must contain the minimum number of moves needed to make the first k elements of the original sequence ai equal to zero. 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
null
[{"input": "4\n1 0 1 2", "output": "1\n1\n3"}, {"input": "8\n1 2 3 4 5 6 7 8", "output": "1\n3\n6\n10\n16\n24\n40"}]
1,000
[]
12
[{"input": "4\r\n1 0 1 2\r\n", "output": "1\r\n1\r\n3\r\n"}, {"input": "8\r\n1 2 3 4 5 6 7 8\r\n", "output": "1\r\n3\r\n6\r\n10\r\n16\r\n24\r\n40\r\n"}, {"input": "5\r\n4 1 4 7 6\r\n", "output": "4\r\n5\r\n9\r\n17\r\n"}, {"input": "9\r\n13 13 7 11 3 9 3 5 5\r\n", "output": "13\r\n26\r\n33\r\n44\r\n47\r\n69\r\n79\r\n117...
false
stdio
null
true
175/B
175
B
Python 3
TESTS
3
92
0
27107788
n = int(input()) player_points = {} for _ in range(n): name, points = input().split() points = int(points) if name in player_points: if player_points[name] < points: player_points[name] = points else: player_points[name] = points points_list = sorted(player_points.values()...
46
342
24,064,000
131139063
from collections import defaultdict, OrderedDict n = int(input()) u = defaultdict(int) for _ in range(n) : name, score = input().split() u[name] = max(u[name], int(score)) scoreToPlayers = defaultdict(list) for pl in u : scoreToPlayers[u[pl]].append(pl) v = OrderedDict(sorted(scoreToPlayers.items())) res = ...
Codeforces Round 115
CF
2,012
2
256
Plane of Tanks: Pro
Vasya has been playing Plane of Tanks with his friends the whole year. Now it is time to divide the participants into several categories depending on their results. A player is given a non-negative integer number of points in each round of the Plane of Tanks. Vasya wrote results for each round of the last year. He has...
The first line contains the only integer number n (1 ≤ n ≤ 1000) — a number of records with the players' results. Each of the next n lines contains a player's name and the amount of points, obtained by the player for the round, separated with a space. The name contains not less than 1 and no more than 10 characters. T...
Print on the first line the number m — the number of players, who participated in one round at least. Each one of the next m lines should contain a player name and a category he belongs to, separated with space. Category can be one of the following: "noob", "random", "average", "hardcore" or "pro" (without quotes). Th...
null
In the first example the best result, obtained by artem is not worse than the result that 25% of players have (his own result), so he belongs to category "noob". vasya and kolya have best results not worse than the results that 75% players have (both of them and artem), so they belong to category "random". igor has bes...
[{"input": "5\nvasya 100\nvasya 200\nartem 100\nkolya 200\nigor 250", "output": "4\nartem noob\nigor pro\nkolya random\nvasya random"}, {"input": "3\nvasya 200\nkolya 1000\nvasya 1000", "output": "2\nkolya pro\nvasya pro"}]
1,400
["implementation"]
78
[{"input": "5\r\nvasya 100\r\nvasya 200\r\nartem 100\r\nkolya 200\r\nigor 250\r\n", "output": "4\r\nartem noob\r\nigor pro\r\nkolya random\r\nvasya random\r\n"}, {"input": "3\r\nvasya 200\r\nkolya 1000\r\nvasya 1000\r\n", "output": "2\r\nkolya pro\r\nvasya pro\r\n"}, {"input": "1\r\nvasya 1000\r\n", "output": "1\r\nvas...
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()) players = {} for _ in range(n): name, points = f.readline().strip().split() points = int(points) if name not in players ...
true
60/E
60
E
Python 3
TESTS
3
186
307,200
91180189
import sys I = lambda: int(input()) RL = readline = lambda: sys.stdin.readline().strip('\n') RM = readmap = lambda x = int: map(x,readline().split(' ')) #E n,x,y,p = RM() a = [*RM()] s = temps = sum(a) ends = a[0] + a[-1] for i in range(x): temps = (3*temps - ends)%p ends = a[0] + a[-2] + x*a[-1] for i in range(...
58
2,088
80,179,200
99377097
#!/usr/bin/pypy3 from sys import stdin, stdout input, print = stdin.readline, stdout.write p = 0 def readints(): return list(map(int, input().split())) def writeln(x): print(str(x) + '\n') def mod(x): return (x % p + p) % p def matmul(a, b): n = len(a) c = [[0 for x in range(n)] for y in range(n...
Codeforces Beta Round 56
CF
2,011
3
256
Mushroom Gnomes
Once upon a time in the thicket of the mushroom forest lived mushroom gnomes. They were famous among their neighbors for their magic mushrooms. Their magic nature made it possible that between every two neighboring mushrooms every minute grew another mushroom with the weight equal to the sum of weights of two neighbori...
The first line contains four integers n, x, y, p (1 ≤ n ≤ 106, 0 ≤ x, y ≤ 1018, x + y > 0, 2 ≤ p ≤ 109) which represent the number of mushrooms, the number of minutes after the first replanting, the number of minutes after the second replanting and the module. The next line contains n integers ai which represent the mu...
The answer should contain a single number which is the total weights of the mushrooms modulo p in the end after x + y minutes.
null
null
[{"input": "2 1 0 657276545\n1 2", "output": "6"}, {"input": "2 1 1 888450282\n1 2", "output": "14"}, {"input": "4 5 0 10000\n1 2 3 4", "output": "1825"}]
2,600
["math", "matrices"]
58
[{"input": "2 1 0 657276545\r\n1 2\r\n", "output": "6\r\n"}, {"input": "2 1 1 888450282\r\n1 2\r\n", "output": "14\r\n"}, {"input": "4 5 0 10000\r\n1 2 3 4\r\n", "output": "1825\r\n"}, {"input": "4 0 8 78731972\r\n1 52 76 81\r\n", "output": "1108850\r\n"}, {"input": "4 0 8 414790855\r\n1 88 97 99\r\n", "output": "15418...
false
stdio
null
true
886/F
886
F
Python 3
PRETESTS
2
108
16,896,000
32266125
n=int(input()) a=[[0]*2000 for i in range(2000)] for i in range(n): s=input().split() k1=int(s[0])-1 k2=int(s[1])-1 a[k1][k2]=1 k=-1 for i in range(n): for j in range(i,n): if a[i][j]==a[j][i] and a[j][i]!=0: k+=2 print(k)
51
794
19,046,400
211944348
from fractions import Fraction import time class Point: def __init__(self, x, y): self.x = x self.y = y def to_tuple(self): return (self.x, self.y) def __repr__(self): return "Point({}, {})".format(self.x, self.y) def __eq__(self, other): return self.to_tuple...
Технокубок 2018 - Отборочный Раунд 3
CF
2,017
2
256
Symmetric Projections
You are given a set of n points on the plane. A line containing the origin is called good, if projection of the given set to this line forms a symmetric multiset of points. Find the total number of good lines. Multiset is a set where equal elements are allowed. Multiset is called symmetric, if there is a point P on t...
The first line contains a single integer n (1 ≤ n ≤ 2000) — the number of points in the set. Each of the next n lines contains two integers xi and yi ( - 106 ≤ xi, yi ≤ 106) — the coordinates of the points. It is guaranteed that no two points coincide.
If there are infinitely many good lines, print -1. Otherwise, print single integer — the number of good lines.
null
Picture to the first sample test: In the second sample, any line containing the origin is good.
[{"input": "3\n1 2\n2 1\n3 3", "output": "3"}, {"input": "2\n4 3\n1 2", "output": "-1"}]
2,900
["geometry"]
51
[{"input": "3\r\n1 2\r\n2 1\r\n3 3\r\n", "output": "3\r\n"}, {"input": "2\r\n4 3\r\n1 2\r\n", "output": "-1\r\n"}, {"input": "6\r\n0 4\r\n1 5\r\n2 1\r\n3 2\r\n4 3\r\n5 0\r\n", "output": "5\r\n"}, {"input": "1\r\n5 2\r\n", "output": "-1\r\n"}, {"input": "4\r\n2 4\r\n1 2\r\n0 0\r\n-2 -4\r\n", "output": "1\r\n"}, {"input"...
false
stdio
null
true
713/C
713
C
Python 3
TESTS
0
31
0
200936261
n = int(input()) a = list(map(int, input().split())) ops = 0 prev = a[0] for i in range(1, n): if a[i] <= prev: diff = prev - a[i] + 1 a[i] += diff ops += diff prev = a[i] print(ops)
57
187
7,168,000
174348022
from heapq import heappop, heappush, heapreplace import sys import io import os # region IO BUFSIZE = 8192 class FastIO(io.IOBase): newlines = 0 def __init__(self, file): self._file = file self._fd = file.fileno() self.buffer = io.BytesIO() self.writable = "...
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
292/A
292
A
Python 3
TESTS
1
218
0
53372785
r = lambda: int(input()) ra = lambda: [*map(int, input().split())] a = [] t, q, mq = 0, 0, 0 n = r() for i in range(n): a.append(ra()) for i in range(n): if i==0: q = a[i][1] t = a[i][0] else: q+= a[i][1]-a[i][0]+t if q<0: q = 0 if q>mq: mq = q...
38
154
0
14651197
pt, s, vs = 0, 0, 0 for i in range(int(input())): t, c = map(int, input().split()) s = max(s - (t - pt), 0) + c vs = max(vs, s) pt = t print(pt + s, vs)
Croc Champ 2013 - Round 1
CF
2,013
2
256
SMSC
Some large corporation where Polycarpus works has its own short message service center (SMSC). The center's task is to send all sorts of crucial information. Polycarpus decided to check the efficiency of the SMSC. For that, he asked to give him the statistics of the performance of the SMSC for some period of time. In ...
The first line contains a single integer n (1 ≤ n ≤ 103) — the number of tasks of the SMSC. Next n lines contain the tasks' descriptions: the i-th line contains two space-separated integers ti and ci (1 ≤ ti, ci ≤ 106) — the time (the second) when the i-th task was received and the number of messages to send, correspon...
In a single line print two space-separated integers — the time when the last text message was sent and the maximum queue size at a certain moment of time.
null
In the first test sample: - second 1: the first message has appeared in the queue, the queue's size is 1; - second 2: the first message is sent, the second message has been received, the queue's size is 1; - second 3: the second message is sent, the queue's size is 0, Thus, the maximum size of the queue is 1, the las...
[{"input": "2\n1 1\n2 1", "output": "3 1"}, {"input": "1\n1000000 10", "output": "1000010 10"}, {"input": "3\n3 3\n4 3\n5 3", "output": "12 7"}]
1,100
["implementation"]
38
[{"input": "2\r\n1 1\r\n2 1\r\n", "output": "3 1\r\n"}, {"input": "1\r\n1000000 10\r\n", "output": "1000010 10\r\n"}, {"input": "3\r\n3 3\r\n4 3\r\n5 3\r\n", "output": "12 7\r\n"}, {"input": "1\r\n1 1\r\n", "output": "2 1\r\n"}, {"input": "2\r\n1 11\r\n100 10\r\n", "output": "110 11\r\n"}, {"input": "4\r\n1 10\r\n2 9\r...
false
stdio
null
true
768/E
768
E
PyPy 3-64
TESTS
0
31
0
205295822
n=input i=int a=0 for _ in range(i(n())):a^=i((8*i(n())+8)**0.5-1)//2 print(['YES','NO'][a&1])
71
1,294
0
230897029
ans=0 for _ in range(int(input())): ans^=int((8*int(input())+1)**0.5-1)//2 print(['YES', 'NO'][ans>0])
Divide by Zero 2017 and Codeforces Round 399 (Div. 1 + Div. 2, combined)
CF
2,017
3
256
Game of Stones
Sam has been teaching Jon the Game of Stones to sharpen his mind and help him devise a strategy to fight the white walkers. The rules of this game are quite simple: - The game starts with n piles of stones indexed from 1 to n. The i-th pile contains si stones. - The players make their moves alternatively. A move is co...
First line consists of a single integer n (1 ≤ n ≤ 106) — the number of piles. Each of next n lines contains an integer si (1 ≤ si ≤ 60) — the number of stones in i-th pile.
Print a single line containing "YES" (without quotes) if Jon wins, otherwise print "NO" (without quotes)
null
In the first case, Sam removes all the stones and Jon loses. In second case, the following moves are possible by Sam: $$\{1,2\} \rightarrow \{0,2\}, \{1,2\} \rightarrow \{1,0\}, \{1,2\} \rightarrow \{1,1\}$$ In each of these cases, last move can be made by Jon to win the game as follows: $${ \{ 0, 2 \} } \rightarrow ...
[{"input": "1\n5", "output": "NO"}, {"input": "2\n1\n2", "output": "YES"}]
2,100
["bitmasks", "dp", "games"]
71
[{"input": "1\r\n5\r\n", "output": "NO"}, {"input": "2\r\n1\r\n2\r\n", "output": "YES"}, {"input": "3\r\n34\r\n44\r\n21\r\n", "output": "NO"}, {"input": "6\r\n34\r\n44\r\n21\r\n55\r\n1\r\n36\r\n", "output": "NO"}, {"input": "14\r\n34\r\n44\r\n21\r\n55\r\n1\r\n36\r\n53\r\n31\r\n58\r\n59\r\n11\r\n40\r\n20\r\n32\r\n", "ou...
false
stdio
null
true
366/D
366
D
Python 3
TESTS
1
62
1,228,800
19067340
from sys import stdin, stdout, stderr, exit from math import log, factorial import re from queue import PriorityQueue import functools from time import time # inputf = open('input.txt', 'r') # outputf = open('output.txt', 'w') def readil(): return list(map(int, stdin.readline().strip().split())) class time_it(...
30
1,029
12,185,600
218085952
class Node: def __init__(self, a, b, l, r): self.a = a self.b = b self.l = l self.r = r def func(a, p): if p[a] == -1 or p[a] == a: return a p[a] = func(p[a], p) return p[a] n, m = map(int, input().split()) node = [] for _ in range(m): a, b, l, r = map(int, in...
Codeforces Round 214 (Div. 2)
CF
2,013
3
256
Dima and Trap Graph
Dima and Inna love spending time together. The problem is, Seryozha isn't too enthusiastic to leave his room for some reason. But Dima and Inna love each other so much that they decided to get criminal... Dima constructed a trap graph. He shouted: "Hey Seryozha, have a look at my cool graph!" to get his roommate inter...
The first line of the input contains two integers n and m (2 ≤ n ≤ 103, 0 ≤ m ≤ 3·103). Then follow m lines describing the edges. Each line contains four integers ak, bk, lk and rk (1 ≤ ak, bk ≤ n, 1 ≤ lk ≤ rk ≤ 106). The numbers mean that in the trap graph the k-th edge connects nodes ak and bk, this edge corresponds ...
In a single line of the output print an integer — the maximum loyalty among all paths from the first node to the n-th one. If such paths do not exist or the maximum loyalty equals 0, print in a single line "Nice work, Dima!" without the quotes.
null
Explanation of the first example. Overall, we have 2 ways to get from node 1 to node 4: first you must go along the edge 1-2 with range [1-10], then along one of the two edges 2-4. One of them contains range [3-5], that is, we can pass through with numbers 3, 4, 5. So the loyalty of such path is 3. If we go along ed...
[{"input": "4 4\n1 2 1 10\n2 4 3 5\n1 3 1 5\n2 4 2 7", "output": "6"}, {"input": "5 6\n1 2 1 10\n2 5 11 20\n1 4 2 5\n1 3 10 11\n3 4 12 10000\n4 5 6 6", "output": "Nice work, Dima!"}]
2,000
["binary search", "data structures", "dfs and similar", "dsu", "shortest paths", "two pointers"]
30
[{"input": "4 4\r\n1 2 1 10\r\n2 4 3 5\r\n1 3 1 5\r\n2 4 2 7\r\n", "output": "6\r\n"}, {"input": "5 6\r\n1 2 1 10\r\n2 5 11 20\r\n1 4 2 5\r\n1 3 10 11\r\n3 4 12 10000\r\n4 5 6 6\r\n", "output": "Nice work, Dima!\r\n"}, {"input": "6 6\r\n1 2 1 10\r\n2 3 1 10\r\n3 6 1 1\r\n1 4 1 4\r\n4 5 1 3\r\n5 6 1 3\r\n", "output": "3...
false
stdio
null
true
618/B
618
B
Python 3
TESTS
2
61
4,608,000
24031245
n = int(input()) b = [] for i in range(n): b.append(max([int(i) for i in input().split()])) for i in range(n): if b[i] == n-1: b[i+1] = n print(b[i], end=' ')
23
46
0
15655973
n = int(input()) a = [list(map(int, input().split(' '))) for i in range(n)] ans = [0]*n for i in range(1, n+1): for j in range(n): if ans[j] == 0 and a[j].count(i) == n-i: ans[j] = str(i) break print(' '.join(ans))
Wunder Fund Round 2016 (Div. 1 + Div. 2 combined)
CF
2,016
2
256
Guess the Permutation
Bob has a permutation of integers from 1 to n. Denote this permutation as p. The i-th element of p will be denoted as pi. For all pairs of distinct integers i, j between 1 and n, he wrote the number ai, j = min(pi, pj). He writes ai, i = 0 for all integer i from 1 to n. Bob gave you all the values of ai, j that he wro...
The first line of the input will contain a single integer n (2 ≤ n ≤ 50). The next n lines will contain the values of ai, j. The j-th number on the i-th line will represent ai, j. The i-th number on the i-th line will be 0. It's guaranteed that ai, j = aj, i and there is at least one solution consistent with the infor...
Print n space separated integers, which represents a permutation that could have generated these values. If there are multiple possible solutions, print any of them.
null
In the first case, the answer can be {1, 2} or {2, 1}. In the second case, another possible answer is {2, 4, 5, 1, 3}.
[{"input": "2\n0 1\n1 0", "output": "2 1"}, {"input": "5\n0 2 2 1 2\n2 0 4 1 3\n2 4 0 1 3\n1 1 1 0 1\n2 3 3 1 0", "output": "2 5 4 1 3"}]
1,100
["constructive algorithms"]
23
[{"input": "2\r\n0 1\r\n1 0\r\n", "output": "2 1\r\n"}, {"input": "5\r\n0 2 2 1 2\r\n2 0 4 1 3\r\n2 4 0 1 3\r\n1 1 1 0 1\r\n2 3 3 1 0\r\n", "output": "2 5 4 1 3\r\n"}, {"input": "10\r\n0 1 5 2 5 3 4 5 5 5\r\n1 0 1 1 1 1 1 1 1 1\r\n5 1 0 2 6 3 4 6 6 6\r\n2 1 2 0 2 2 2 2 2 2\r\n5 1 6 2 0 3 4 8 8 7\r\n3 1 3 2 3 0 3 3 3 3\...
false
stdio
import sys def main(input_path, output_path, sub_path): with open(input_path) as f: lines = [line.strip() for line in f.readlines()] n = int(lines[0]) a = [list(map(int, line.split())) for line in lines[1:n+1]] with open(sub_path) as f: sub_line = f.read().strip() p = list(map(...
true
318/B
318
B
PyPy 3-64
TESTS
3
122
0
220882281
s = input() n = len(s) count = 0 left = 0 right = 0 while right < n: if s[right:right+5] == "heavy": while s[left:left+5] != "heavy": left += 1 count += 1 left += 5 right += 1 print(count + 1)
30
186
9,625,600
231252091
z=r=0 for w in input().split("heavy"):r+=w.count("metal")*z;z+=1 print(r)
Codeforces Round 188 (Div. 2)
CF
2,013
2
256
Strings of Power
Volodya likes listening to heavy metal and (occasionally) reading. No wonder Volodya is especially interested in texts concerning his favourite music style. Volodya calls a string powerful if it starts with "heavy" and ends with "metal". Finding all powerful substrings (by substring Volodya means a subsequence of cons...
Input contains a single non-empty string consisting of the lowercase Latin alphabet letters. Length of this string will not be greater than 106 characters.
Print exactly one number — the number of powerful substrings of the given string. Please, do not use the %lld specifier to read or write 64-bit integers in C++. It is preferred to use the cin, cout streams or the %I64d specifier.
null
In the first sample the string "heavymetalisheavymetal" contains powerful substring "heavymetal" twice, also the whole string "heavymetalisheavymetal" is certainly powerful. In the second sample the string "heavymetalismetal" contains two powerful substrings: "heavymetal" and "heavymetalismetal".
[{"input": "heavymetalisheavymetal", "output": "3"}, {"input": "heavymetalismetal", "output": "2"}, {"input": "trueheavymetalissotruewellitisalsosoheavythatyoucanalmostfeeltheweightofmetalonyou", "output": "3"}]
1,300
["implementation", "strings", "two pointers"]
30
[{"input": "heavymetalisheavymetal\r\n", "output": "3"}, {"input": "heavymetalismetal\r\n", "output": "2"}, {"input": "trueheavymetalissotruewellitisalsosoheavythatyoucanalmostfeeltheweightofmetalonyou\r\n", "output": "3"}, {"input": "fpgzbvhheavymheheavyzmheavyavyebknkhheavyhsbqmmetheavyalmetalheavyyomtua\r\n", "outpu...
false
stdio
null
true
618/B
618
B
Python 3
TESTS
2
109
307,200
57066612
n = int(input()) l = [] for i in range(n): temp = input().split(' ') t = [] for j in range(len(temp)): t.append(int(temp[j])) l.append(t) o = [0 for i in range(n)] o[0] = l[0][1] for i in range(1, n): if l[0][i] < o[0]: o[i] = l[0][i] while 0 in o: if o.count(0) == 1: for...
23
46
0
15661546
n=int(input());v=[];tmp=0;t=False for i in range(n): v.append([0 for i in range(n+1)]) p=[0 for i in range(n)]; for i in range(n): inp=list(map(int,input().split(" "))) for k in inp: v[i][k]+=1 for i in range(1,n+1): for j in range(n): if ((p[j]==0) and (v[j][i]==n-i)): p[j]=...
Wunder Fund Round 2016 (Div. 1 + Div. 2 combined)
CF
2,016
2
256
Guess the Permutation
Bob has a permutation of integers from 1 to n. Denote this permutation as p. The i-th element of p will be denoted as pi. For all pairs of distinct integers i, j between 1 and n, he wrote the number ai, j = min(pi, pj). He writes ai, i = 0 for all integer i from 1 to n. Bob gave you all the values of ai, j that he wro...
The first line of the input will contain a single integer n (2 ≤ n ≤ 50). The next n lines will contain the values of ai, j. The j-th number on the i-th line will represent ai, j. The i-th number on the i-th line will be 0. It's guaranteed that ai, j = aj, i and there is at least one solution consistent with the infor...
Print n space separated integers, which represents a permutation that could have generated these values. If there are multiple possible solutions, print any of them.
null
In the first case, the answer can be {1, 2} or {2, 1}. In the second case, another possible answer is {2, 4, 5, 1, 3}.
[{"input": "2\n0 1\n1 0", "output": "2 1"}, {"input": "5\n0 2 2 1 2\n2 0 4 1 3\n2 4 0 1 3\n1 1 1 0 1\n2 3 3 1 0", "output": "2 5 4 1 3"}]
1,100
["constructive algorithms"]
23
[{"input": "2\r\n0 1\r\n1 0\r\n", "output": "2 1\r\n"}, {"input": "5\r\n0 2 2 1 2\r\n2 0 4 1 3\r\n2 4 0 1 3\r\n1 1 1 0 1\r\n2 3 3 1 0\r\n", "output": "2 5 4 1 3\r\n"}, {"input": "10\r\n0 1 5 2 5 3 4 5 5 5\r\n1 0 1 1 1 1 1 1 1 1\r\n5 1 0 2 6 3 4 6 6 6\r\n2 1 2 0 2 2 2 2 2 2\r\n5 1 6 2 0 3 4 8 8 7\r\n3 1 3 2 3 0 3 3 3 3\...
false
stdio
import sys def main(input_path, output_path, sub_path): with open(input_path) as f: lines = [line.strip() for line in f.readlines()] n = int(lines[0]) a = [list(map(int, line.split())) for line in lines[1:n+1]] with open(sub_path) as f: sub_line = f.read().strip() p = list(map(...
true
618/B
618
B
Python 3
TESTS
2
108
0
52303661
n = int(input()) x = list() for i in range(n): y = input().split(' ') y = [int(k) for k in y] y = int(max(y)) x.append(y) s = set() for i in range(n): s.add(i+1) for i in range(len(x)): if x[i] in x[i+1:]: tmp = x[i+1:].index(x[i]) + i t = x[i] + 1 while t not in s: t += 1 s.remove(t...
23
46
0
15984403
#Problem 618B Codeforce Wunder Fund Round 2016 (Div. 1 + Div. 2 combined) n = int(input()) a = [0] * n res = ['0'] * n for j in range(0,n): a[j] = [int(num) for num in input().split()] maxx = 0 for i in range(0,n): if a[j][i] > maxx: maxx = a[j][i] res[j] = str(maxx) for j in range(0...
Wunder Fund Round 2016 (Div. 1 + Div. 2 combined)
CF
2,016
2
256
Guess the Permutation
Bob has a permutation of integers from 1 to n. Denote this permutation as p. The i-th element of p will be denoted as pi. For all pairs of distinct integers i, j between 1 and n, he wrote the number ai, j = min(pi, pj). He writes ai, i = 0 for all integer i from 1 to n. Bob gave you all the values of ai, j that he wro...
The first line of the input will contain a single integer n (2 ≤ n ≤ 50). The next n lines will contain the values of ai, j. The j-th number on the i-th line will represent ai, j. The i-th number on the i-th line will be 0. It's guaranteed that ai, j = aj, i and there is at least one solution consistent with the infor...
Print n space separated integers, which represents a permutation that could have generated these values. If there are multiple possible solutions, print any of them.
null
In the first case, the answer can be {1, 2} or {2, 1}. In the second case, another possible answer is {2, 4, 5, 1, 3}.
[{"input": "2\n0 1\n1 0", "output": "2 1"}, {"input": "5\n0 2 2 1 2\n2 0 4 1 3\n2 4 0 1 3\n1 1 1 0 1\n2 3 3 1 0", "output": "2 5 4 1 3"}]
1,100
["constructive algorithms"]
23
[{"input": "2\r\n0 1\r\n1 0\r\n", "output": "2 1\r\n"}, {"input": "5\r\n0 2 2 1 2\r\n2 0 4 1 3\r\n2 4 0 1 3\r\n1 1 1 0 1\r\n2 3 3 1 0\r\n", "output": "2 5 4 1 3\r\n"}, {"input": "10\r\n0 1 5 2 5 3 4 5 5 5\r\n1 0 1 1 1 1 1 1 1 1\r\n5 1 0 2 6 3 4 6 6 6\r\n2 1 2 0 2 2 2 2 2 2\r\n5 1 6 2 0 3 4 8 8 7\r\n3 1 3 2 3 0 3 3 3 3\...
false
stdio
import sys def main(input_path, output_path, sub_path): with open(input_path) as f: lines = [line.strip() for line in f.readlines()] n = int(lines[0]) a = [list(map(int, line.split())) for line in lines[1:n+1]] with open(sub_path) as f: sub_line = f.read().strip() p = list(map(...
true
665/B
665
B
PyPy 3-64
TESTS
3
62
0
167288122
from sys import stdin def inta(arr): return [int(x) for x in arr] def sr(): return stdin.readline().strip() from collections import deque n, m, k = inta(sr().split()) ps = inta(sr().split()) q = deque(ps) sm = 0 for _ in range(m): w = inta(sr().split()) for ww in w: for i, v in enume...
10
62
1,740,800
211415219
n,m,k=map(int,input().split()) l=list(map(int,input().split())) ans=0 while n: n-=1 temp=list(map(int,input().split())) pos=-1 for i in range(m): for j in range(k): if(l[j]==temp[i]): pos=j+1 ans+=pos # print(pos) break ...
Educational Codeforces Round 12
ICPC
2,016
1
256
Shopping
Ayush is a cashier at the shopping center. Recently his department has started a ''click and collect" service which allows users to shop online. The store contains k items. n customers have already used the above service. Each user paid for m items. Let aij denote the j-th item in the i-th person's order. Due to the ...
The first line contains three integers n, m and k (1 ≤ n, k ≤ 100, 1 ≤ m ≤ k) — the number of users, the number of items each user wants to buy and the total number of items at the market. The next line contains k distinct integers pl (1 ≤ pl ≤ k) denoting the initial positions of the items in the store. The items are...
Print the only integer t — the total time needed for Ayush to process all the orders.
null
Customer 1 wants the items 1 and 5. pos(1) = 3, so the new positions are: [1, 3, 4, 2, 5]. pos(5) = 5, so the new positions are: [5, 1, 3, 4, 2]. Time taken for the first customer is 3 + 5 = 8. Customer 2 wants the items 3 and 1. pos(3) = 3, so the new positions are: [3, 5, 1, 4, 2]. pos(1) = 3, so the new positi...
[{"input": "2 2 5\n3 4 1 2 5\n1 5\n3 1", "output": "14"}]
1,400
["brute force"]
10
[{"input": "2 2 5\r\n3 4 1 2 5\r\n1 5\r\n3 1\r\n", "output": "14\r\n"}, {"input": "4 4 4\r\n1 2 3 4\r\n3 4 2 1\r\n4 3 2 1\r\n4 1 2 3\r\n4 1 2 3\r\n", "output": "59\r\n"}, {"input": "1 1 1\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "10 1 100\r\n1 55 67 75 40 86 24 84 82 26 81 23 70 79 51 54 21 78 31 98 68 93 66 88 99...
false
stdio
null
true
618/B
618
B
Python 3
TESTS
2
31
0
145716658
N = int(input()) ans = [0] * N for i in range(N): perm = list(map(int, input().split())) ans[i] = max(max(perm), ans[i]) last = ans[i] for j in range(i + 1, N): if (ans[i] == perm[j]): ans[j] = last + 1 last = ans[j] elif (ans[i] < perm[j]): ans[j] = ans[i] ans[i] = pe...
23
46
0
146889653
n=int(input()) a=[] for i in range(n): a.append(list(map(int,input().split()))) k=a[0][1] s=[0]*n for i in range(n): f=0 for j in range(n): f=max(a[i][j],f) if f in s: s[i]=n else: s[i]=f s=list(map(str,s)) print(" ".join(s))
Wunder Fund Round 2016 (Div. 1 + Div. 2 combined)
CF
2,016
2
256
Guess the Permutation
Bob has a permutation of integers from 1 to n. Denote this permutation as p. The i-th element of p will be denoted as pi. For all pairs of distinct integers i, j between 1 and n, he wrote the number ai, j = min(pi, pj). He writes ai, i = 0 for all integer i from 1 to n. Bob gave you all the values of ai, j that he wro...
The first line of the input will contain a single integer n (2 ≤ n ≤ 50). The next n lines will contain the values of ai, j. The j-th number on the i-th line will represent ai, j. The i-th number on the i-th line will be 0. It's guaranteed that ai, j = aj, i and there is at least one solution consistent with the infor...
Print n space separated integers, which represents a permutation that could have generated these values. If there are multiple possible solutions, print any of them.
null
In the first case, the answer can be {1, 2} or {2, 1}. In the second case, another possible answer is {2, 4, 5, 1, 3}.
[{"input": "2\n0 1\n1 0", "output": "2 1"}, {"input": "5\n0 2 2 1 2\n2 0 4 1 3\n2 4 0 1 3\n1 1 1 0 1\n2 3 3 1 0", "output": "2 5 4 1 3"}]
1,100
["constructive algorithms"]
23
[{"input": "2\r\n0 1\r\n1 0\r\n", "output": "2 1\r\n"}, {"input": "5\r\n0 2 2 1 2\r\n2 0 4 1 3\r\n2 4 0 1 3\r\n1 1 1 0 1\r\n2 3 3 1 0\r\n", "output": "2 5 4 1 3\r\n"}, {"input": "10\r\n0 1 5 2 5 3 4 5 5 5\r\n1 0 1 1 1 1 1 1 1 1\r\n5 1 0 2 6 3 4 6 6 6\r\n2 1 2 0 2 2 2 2 2 2\r\n5 1 6 2 0 3 4 8 8 7\r\n3 1 3 2 3 0 3 3 3 3\...
false
stdio
import sys def main(input_path, output_path, sub_path): with open(input_path) as f: lines = [line.strip() for line in f.readlines()] n = int(lines[0]) a = [list(map(int, line.split())) for line in lines[1:n+1]] with open(sub_path) as f: sub_line = f.read().strip() p = list(map(...
true
282/B
282
B
Python 3
TESTS
1
62
0
230848452
n = int(input()) eggs = [] for i in range(n): a, g = map(int, input().split()) eggs.append((g - a, i)) eggs.sort(reverse=True) a_count = n // 2 g_count = n - a_count if abs(sum([eggs[i][0] for i in range(a_count)]) - sum([eggs[i][0] for i in range(g_count)])) > 500: print("-1") else: ans = ["G"] * n ...
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
852/B
852
B
PyPy 3-64
TESTS
1
61
132,198,400
221227648
import sys sys.setrecursionlimit(100000) input=lambda:sys.stdin.readline().strip() write=lambda x:sys.stdout.write(str(x)+'\n') # from decimal import Decimal # from random import randint # from copy import deepcopy from collections import deque,Counter # from heapq import heapify,heappush,heappop # from bisect import ...
20
779
122,265,600
157949693
import sys from array import array class Matrix: def __init__(self, r, c, mat=None, id=None): self.r, self.c = r, c if mat != None: self.mat = [[mat[i][j] for j in range(c)] for i in range(r)] else: self.mat = [[0 for i in range(c)] for j in range(r)] ...
Bubble Cup X - Finals [Online Mirror]
ICPC
2,017
2
256
Neural Network country
Due to the recent popularity of the Deep learning new countries are starting to look like Neural Networks. That is, the countries are being built deep with many layers, each layer possibly having many cities. They also have one entry, and one exit point. There are exactly L layers, each having N cities. Let us look at...
The first line of input contains N (1 ≤ N ≤ 106), L (2 ≤ L ≤ 105) and M (2 ≤ M ≤ 100), the number of cities in each layer, the number of layers and the number that travelling cost should be divisible by, respectively. Second, third and fourth line contain N integers each denoting costs 0 ≤ cost ≤ M from entry point to...
Output a single integer, the number of paths Doctor G. can take which have total cost divisible by M, modulo 109 + 7.
null
This is a country with 3 layers, each layer having 2 cities. Paths $$6 \rightarrow 2 \rightarrow 2 \rightarrow 3$$, and $$6 \rightarrow 2 \rightarrow 1 \rightarrow 4$$ are the only paths having total cost divisible by 13. Notice that input edges for layer cities have the same cost, and that they are same for all layers...
[{"input": "2 3 13\n4 6\n2 1\n3 4", "output": "2"}]
2,000
["dp", "matrices"]
20
[{"input": "2 3 13\r\n4 6\r\n2 1\r\n3 4\r\n", "output": "2"}, {"input": "2 4 5\r\n1 1\r\n1 1\r\n1 1\r\n", "output": "16"}, {"input": "1 1234 5\r\n1\r\n1\r\n1\r\n", "output": "1"}, {"input": "3 2 2\r\n0 1 0\r\n0 0 1\r\n1 1 0\r\n", "output": "3"}, {"input": "5 4 3\r\n2 1 0 1 2\r\n0 1 2 1 0\r\n1 2 1 0 2\r\n", "output": "2...
false
stdio
null
true
16/E
16
E
Python 3
TESTS
1
60
0
215457537
import sys; input = sys.stdin.readline def dfs(i, p, v): if v == (1 << n) - 1: return 1 if dp[p][v] > -1: return dp[p][v] dp[p][v] = 1 for q in range(n): if not v & (1 << q): dp[p][v] *= a[i][q] * dfs(i, q, v | (1 << q)) return dp[p][v] n = int(input()) a = [lis...
20
1,528
28,364,800
127222158
# By the grace of Goddess Saraswati and Durga# # Author: Vaibhav Tiwari # import os, sys, math from io import BytesIO, IOBase def main(): n = int(input()) prob = [] for i in range(n): prob.append(arrin(float)) FishBitmaskIterative(n,prob) # Fast IO Region BUFSIZE = 8192 class FastIO(IOBa...
Codeforces Beta Round 16 (Div. 2 Only)
ICPC
2,010
3
128
Fish
n fish, numbered from 1 to n, live in a lake. Every day right one pair of fish meet, and the probability of each other pair meeting is the same. If two fish with indexes i and j meet, the first will eat up the second with the probability aij, and the second will eat up the first with the probability aji = 1 - aij. The ...
The first line contains integer n (1 ≤ n ≤ 18) — the amount of fish in the lake. Then there follow n lines with n real numbers each — matrix a. aij (0 ≤ aij ≤ 1) — the probability that fish with index i eats up fish with index j. It's guaranteed that the main diagonal contains zeros only, and for other elements the fol...
Output n space-separated real numbers accurate to not less than 6 decimal places. Number with index i should be equal to the probability that fish with index i will survive to be the last in the lake.
null
null
[{"input": "2\n0 0.5\n0.5 0", "output": "0.500000 0.500000"}, {"input": "5\n0 1 1 1 1\n0 0 0.5 0.5 0.5\n0 0.5 0 0.5 0.5\n0 0.5 0.5 0 0.5\n0 0.5 0.5 0.5 0", "output": "1.000000 0.000000 0.000000 0.000000 0.000000"}]
1,900
["bitmasks", "dp", "probabilities"]
20
[{"input": "2\r\n0 0.5\r\n0.5 0\r\n", "output": "0.500000 0.500000 "}, {"input": "4\r\n0 0.5 0.5 0.5\r\n0.5 0 0.5 0.5\r\n0.5 0.5 0 0.5\r\n0.5 0.5 0.5 0\r\n", "output": "0.250000 0.250000 0.250000 0.250000 "}, {"input": "5\r\n0 1 1 1 1\r\n0 0 0.5 0.5 0.5\r\n0 0.5 0 0.5 0.5\r\n0 0.5 0.5 0 0.5\r\n0 0.5 0.5 0.5 0\r\n", "ou...
false
stdio
import sys def read_floats_from_file(path): with open(path, 'r') as f: line = f.readline().strip() return list(map(float, line.split())) def main(): input_path, output_path, submission_path = sys.argv[1:4] expected = read_floats_from_file(output_path) submission = read_floats_from_fil...
true
665/B
665
B
PyPy 3
TESTS
3
124
0
100181319
n,m,k = map(int,input().split()) P = list(map(int,input().split())) count = 0 for i in range(m): X = list(map(int,input().split())) for j in X: t = P.index(j) count += (t+1) P = [j] + P[:t] + P[t+1:] print(count)
10
62
1,945,600
213961757
n, m, k = map(int, input().split()) p = list(map(int, input().split())) t = 0 for _ in range(n): a = list(map(int, input().split())) for i in a: pos = p.index(i) t += pos + 1 p = [i] + p[:pos] + p[pos + 1:] print(t)
Educational Codeforces Round 12
ICPC
2,016
1
256
Shopping
Ayush is a cashier at the shopping center. Recently his department has started a ''click and collect" service which allows users to shop online. The store contains k items. n customers have already used the above service. Each user paid for m items. Let aij denote the j-th item in the i-th person's order. Due to the ...
The first line contains three integers n, m and k (1 ≤ n, k ≤ 100, 1 ≤ m ≤ k) — the number of users, the number of items each user wants to buy and the total number of items at the market. The next line contains k distinct integers pl (1 ≤ pl ≤ k) denoting the initial positions of the items in the store. The items are...
Print the only integer t — the total time needed for Ayush to process all the orders.
null
Customer 1 wants the items 1 and 5. pos(1) = 3, so the new positions are: [1, 3, 4, 2, 5]. pos(5) = 5, so the new positions are: [5, 1, 3, 4, 2]. Time taken for the first customer is 3 + 5 = 8. Customer 2 wants the items 3 and 1. pos(3) = 3, so the new positions are: [3, 5, 1, 4, 2]. pos(1) = 3, so the new positi...
[{"input": "2 2 5\n3 4 1 2 5\n1 5\n3 1", "output": "14"}]
1,400
["brute force"]
10
[{"input": "2 2 5\r\n3 4 1 2 5\r\n1 5\r\n3 1\r\n", "output": "14\r\n"}, {"input": "4 4 4\r\n1 2 3 4\r\n3 4 2 1\r\n4 3 2 1\r\n4 1 2 3\r\n4 1 2 3\r\n", "output": "59\r\n"}, {"input": "1 1 1\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "10 1 100\r\n1 55 67 75 40 86 24 84 82 26 81 23 70 79 51 54 21 78 31 98 68 93 66 88 99...
false
stdio
null
true
618/B
618
B
Python 3
TESTS
2
46
0
15906070
__author__ = 'Admin' n = int(input()) m = [list(map(int, input().split())) for j in range(n)] ans = [] for i in range(n): ans.append(max(m[i])) if max(m[i]) == ans[i - 1] and len(ans) > 1: ans[i] += 1 print(*ans)
23
46
0
152729567
n=int(input()) a=[] for _ in range(n): l=list(map(int,input().strip().split())) a.append(l) ans=[-1]*n for i in range(n): for j in range(n): if a[i][j]!=0: if ans[j]==-1: if ans[i]==-1: ans[i]=a[i][j] else: ans[j]=a[...
Wunder Fund Round 2016 (Div. 1 + Div. 2 combined)
CF
2,016
2
256
Guess the Permutation
Bob has a permutation of integers from 1 to n. Denote this permutation as p. The i-th element of p will be denoted as pi. For all pairs of distinct integers i, j between 1 and n, he wrote the number ai, j = min(pi, pj). He writes ai, i = 0 for all integer i from 1 to n. Bob gave you all the values of ai, j that he wro...
The first line of the input will contain a single integer n (2 ≤ n ≤ 50). The next n lines will contain the values of ai, j. The j-th number on the i-th line will represent ai, j. The i-th number on the i-th line will be 0. It's guaranteed that ai, j = aj, i and there is at least one solution consistent with the infor...
Print n space separated integers, which represents a permutation that could have generated these values. If there are multiple possible solutions, print any of them.
null
In the first case, the answer can be {1, 2} or {2, 1}. In the second case, another possible answer is {2, 4, 5, 1, 3}.
[{"input": "2\n0 1\n1 0", "output": "2 1"}, {"input": "5\n0 2 2 1 2\n2 0 4 1 3\n2 4 0 1 3\n1 1 1 0 1\n2 3 3 1 0", "output": "2 5 4 1 3"}]
1,100
["constructive algorithms"]
23
[{"input": "2\r\n0 1\r\n1 0\r\n", "output": "2 1\r\n"}, {"input": "5\r\n0 2 2 1 2\r\n2 0 4 1 3\r\n2 4 0 1 3\r\n1 1 1 0 1\r\n2 3 3 1 0\r\n", "output": "2 5 4 1 3\r\n"}, {"input": "10\r\n0 1 5 2 5 3 4 5 5 5\r\n1 0 1 1 1 1 1 1 1 1\r\n5 1 0 2 6 3 4 6 6 6\r\n2 1 2 0 2 2 2 2 2 2\r\n5 1 6 2 0 3 4 8 8 7\r\n3 1 3 2 3 0 3 3 3 3\...
false
stdio
import sys def main(input_path, output_path, sub_path): with open(input_path) as f: lines = [line.strip() for line in f.readlines()] n = int(lines[0]) a = [list(map(int, line.split())) for line in lines[1:n+1]] with open(sub_path) as f: sub_line = f.read().strip() p = list(map(...
true
387/B
387
B
Python 3
TESTS
9
93
7,372,800
37442934
n, m = map(int, input().split()) A = list(map(int, input().split())) B = list(map(int, input().split())) count = 0 i = 0 if B[0] >= A[n-1]: if n > m: print(n-m) exit() else: print(0) exit() for j in range(0, m): if B[j] >= A[i]: i += 1 if i == n - 1: print...
41
46
204,800
140628444
inp=list(map(int,input().split())) n=inp[0] # min num of problems m=inp[1] # num of problems he has a=list(map(int,input().split())) # problems to put b=list(map(int,input().split())) # problems he already has la=len(a) lb=len(b) pa=0 # pointer in first array pb=0 # pointer in second array c=0 while(pb<lb and pa...
Codeforces Round 227 (Div. 2)
CF
2,014
1
256
George and Round
George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by integer bi. To make the round good, he needs to put at least n problems there. Besides, he needs to have at least one problem...
The first line contains two integers n and m (1 ≤ n, m ≤ 3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 106) — the requirements for the complexity of the problems in a good r...
Print a single integer — the answer to the problem.
null
In the first sample the set of the prepared problems meets the requirements for a good round. In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round. In the third sample it is very easy to get a good round if come up with and prepare extra problems wi...
[{"input": "3 5\n1 2 3\n1 2 2 3 3", "output": "0"}, {"input": "3 5\n1 2 3\n1 1 1 1 1", "output": "2"}, {"input": "3 1\n2 3 4\n1", "output": "3"}]
1,200
["brute force", "greedy", "two pointers"]
41
[{"input": "3 5\r\n1 2 3\r\n1 2 2 3 3\r\n", "output": "0\r\n"}, {"input": "3 5\r\n1 2 3\r\n1 1 1 1 1\r\n", "output": "2\r\n"}, {"input": "3 1\r\n2 3 4\r\n1\r\n", "output": "3\r\n"}, {"input": "29 100\r\n20 32 41 67 72 155 331 382 399 412 465 470 484 511 515 529 616 637 679 715 733 763 826 843 862 903 925 979 989\r\n15 ...
false
stdio
null
true
387/B
387
B
PyPy 3
TESTS
10
202
2,252,800
69478316
n,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) c=0 for i in range(len(a)): for j in range(len(b)): if a[i]==b[j]: a[i]=-1 b[j]=-1 break for i in range(len(a)): for j in range(len(b)): if b[j]>a[i]: a[...
41
46
204,800
143479221
n,m=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) a.sort() b.sort() res=0 n-=1 m-=1 while n>=0 and m>=0: if a[n]>b[m]: res+=1 else: m-=1 n-=1 res+=1+n print(res)
Codeforces Round 227 (Div. 2)
CF
2,014
1
256
George and Round
George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by integer bi. To make the round good, he needs to put at least n problems there. Besides, he needs to have at least one problem...
The first line contains two integers n and m (1 ≤ n, m ≤ 3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 106) — the requirements for the complexity of the problems in a good r...
Print a single integer — the answer to the problem.
null
In the first sample the set of the prepared problems meets the requirements for a good round. In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round. In the third sample it is very easy to get a good round if come up with and prepare extra problems wi...
[{"input": "3 5\n1 2 3\n1 2 2 3 3", "output": "0"}, {"input": "3 5\n1 2 3\n1 1 1 1 1", "output": "2"}, {"input": "3 1\n2 3 4\n1", "output": "3"}]
1,200
["brute force", "greedy", "two pointers"]
41
[{"input": "3 5\r\n1 2 3\r\n1 2 2 3 3\r\n", "output": "0\r\n"}, {"input": "3 5\r\n1 2 3\r\n1 1 1 1 1\r\n", "output": "2\r\n"}, {"input": "3 1\r\n2 3 4\r\n1\r\n", "output": "3\r\n"}, {"input": "29 100\r\n20 32 41 67 72 155 331 382 399 412 465 470 484 511 515 529 616 637 679 715 733 763 826 843 862 903 925 979 989\r\n15 ...
false
stdio
null
true
803/E
803
E
Python 3
TESTS
1
46
4,915,200
31540074
def ch(s): k=0 for i in s: if i=='W': k+=1 elif i=='L': k-=1 if (k<=-d) or (k>=d): return False break return True def lastch(s): k=0 for i in s: if i=='W': k+=1 elif i=='L': k-=1 i...
28
967
14,540,800
28180685
N,k=list(map(int,input().strip().split(' '))) S=input() # num of W-num of L=j, j>k means k-j dp=[[0 for j in range(2*k+1)]for i in range(N)] #print(dp) for i in range(len(S)): if i==0: if S[0]=='W': dp[0][1]='W' elif S[0]=='L': dp[0][-1]='L' elif S[0]=='D': ...
Educational Codeforces Round 20
ICPC
2,017
2
256
Roma and Poker
Each evening Roma plays online poker on his favourite website. The rules of poker on this website are a bit strange: there are always two players in a hand, there are no bets, and the winner takes 1 virtual bourle from the loser. Last evening Roma started to play poker. He decided to spend no more than k virtual bourl...
The first line contains two numbers n (the length of Roma's sequence) and k (1 ≤ n, k ≤ 1000). The second line contains the sequence s consisting of characters W, L, D and ?. There are exactly n characters in this sequence.
If there is no valid sequence that can be obtained from s by replacing all ? characters by W, L or D, print NO. Otherwise print this sequence. If there are multiple answers, print any of them.
null
null
[{"input": "3 2\nL??", "output": "LDL"}, {"input": "3 1\nW??", "output": "NO"}, {"input": "20 5\n?LLLLLWWWWW?????????", "output": "WLLLLLWWWWWWWWLWLWDW"}]
2,000
["dp", "graphs"]
28
[{"input": "3 2\r\nL??\r\n", "output": "LDL\r\n"}, {"input": "3 1\r\nW??\r\n", "output": "NO\r\n"}, {"input": "20 5\r\n?LLLLLWWWWW?????????\r\n", "output": "WLLLLLWWWWWWWWLWLWDW\r\n"}, {"input": "5 5\r\n?WDDD\r\n", "output": "NO\r\n"}, {"input": "5 3\r\n??D??\r\n", "output": "WWDDW\r\n"}, {"input": "10 1\r\nD??W?WL?DW\...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path, 'r') as f: n, k = map(int, f.readline().split()) s = f.readline().strip() with open(submission_path, 'r') as f: submission = f.read().strip() ...
true
803/E
803
E
PyPy 3
TESTS
1
218
1,536,000
54652573
#Bhargey Mehta (Sophomore) #DA-IICT, Gandhinagar import sys, math, queue #sys.stdin = open("input.txt", "r") MOD = 10**9+7 sys.setrecursionlimit(1000000) def solve(n, k): if abs(k) > K: return False if dp[n][k] is not None: return dp[n][k] #print(s[n-1], n, k) if s[n-1] == 'W': ...
28
62
409,600
26883241
def ma(): s=input() v=s.split(' ') n=int(v[0]) k=int(v[1]) s=input() dp=[[0,0] for _ in range(n+1)] flag=True for i in range (1,n): c=s[i-1] if c=='?': dp[i][0]=min(dp[i-1][0]+1 ,k-1) dp[i][1]=max(dp[i-1][1]-1 ,-k+1) elif c=='D': ...
Educational Codeforces Round 20
ICPC
2,017
2
256
Roma and Poker
Each evening Roma plays online poker on his favourite website. The rules of poker on this website are a bit strange: there are always two players in a hand, there are no bets, and the winner takes 1 virtual bourle from the loser. Last evening Roma started to play poker. He decided to spend no more than k virtual bourl...
The first line contains two numbers n (the length of Roma's sequence) and k (1 ≤ n, k ≤ 1000). The second line contains the sequence s consisting of characters W, L, D and ?. There are exactly n characters in this sequence.
If there is no valid sequence that can be obtained from s by replacing all ? characters by W, L or D, print NO. Otherwise print this sequence. If there are multiple answers, print any of them.
null
null
[{"input": "3 2\nL??", "output": "LDL"}, {"input": "3 1\nW??", "output": "NO"}, {"input": "20 5\n?LLLLLWWWWW?????????", "output": "WLLLLLWWWWWWWWLWLWDW"}]
2,000
["dp", "graphs"]
28
[{"input": "3 2\r\nL??\r\n", "output": "LDL\r\n"}, {"input": "3 1\r\nW??\r\n", "output": "NO\r\n"}, {"input": "20 5\r\n?LLLLLWWWWW?????????\r\n", "output": "WLLLLLWWWWWWWWLWLWDW\r\n"}, {"input": "5 5\r\n?WDDD\r\n", "output": "NO\r\n"}, {"input": "5 3\r\n??D??\r\n", "output": "WWDDW\r\n"}, {"input": "10 1\r\nD??W?WL?DW\...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path, 'r') as f: n, k = map(int, f.readline().split()) s = f.readline().strip() with open(submission_path, 'r') as f: submission = f.read().strip() ...
true
803/E
803
E
Python 3
TESTS
0
31
4,915,200
26731327
n, k = map(int, input().split()) s=input() won=0 lost=0 drawn=0 un=0 for i in range(n): if s[i]=='W': won+=1 elif s[i]=='L': lost+=1 elif s[i]=='D': drawn+=1 else: un+=1 if won>=lost+k: print('NO') else: if won+un>=k and (won!=k or s[-1]=='?'): s=list(s)...
28
93
20,889,600
180996735
n,k=map(int,input().split()) s=input() m=2*k+1 dp=[[0]*m for i in range(n+1)] dp[0][k]=1 for i in range(n): if s[i]=='L' or s[i]=='?': for j in range(m-1): dp[i+1][j]|=dp[i][j+1] if s[i]=='D' or s[i]=='?': for j in range(m): dp[i+1][j]|=dp[i][j] if s[i]=='W' or s[i]=='?': for j in range(1,...
Educational Codeforces Round 20
ICPC
2,017
2
256
Roma and Poker
Each evening Roma plays online poker on his favourite website. The rules of poker on this website are a bit strange: there are always two players in a hand, there are no bets, and the winner takes 1 virtual bourle from the loser. Last evening Roma started to play poker. He decided to spend no more than k virtual bourl...
The first line contains two numbers n (the length of Roma's sequence) and k (1 ≤ n, k ≤ 1000). The second line contains the sequence s consisting of characters W, L, D and ?. There are exactly n characters in this sequence.
If there is no valid sequence that can be obtained from s by replacing all ? characters by W, L or D, print NO. Otherwise print this sequence. If there are multiple answers, print any of them.
null
null
[{"input": "3 2\nL??", "output": "LDL"}, {"input": "3 1\nW??", "output": "NO"}, {"input": "20 5\n?LLLLLWWWWW?????????", "output": "WLLLLLWWWWWWWWLWLWDW"}]
2,000
["dp", "graphs"]
28
[{"input": "3 2\r\nL??\r\n", "output": "LDL\r\n"}, {"input": "3 1\r\nW??\r\n", "output": "NO\r\n"}, {"input": "20 5\r\n?LLLLLWWWWW?????????\r\n", "output": "WLLLLLWWWWWWWWLWLWDW\r\n"}, {"input": "5 5\r\n?WDDD\r\n", "output": "NO\r\n"}, {"input": "5 3\r\n??D??\r\n", "output": "WWDDW\r\n"}, {"input": "10 1\r\nD??W?WL?DW\...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] with open(input_path, 'r') as f: n, k = map(int, f.readline().split()) s = f.readline().strip() with open(submission_path, 'r') as f: submission = f.read().strip() ...
true
178/A1
178
A3
Python 3
TESTS3
2
216
0
54093826
mod = 1000000007 ii = lambda : int(input()) si = lambda : input() dgl = lambda : list(map(int, input())) f = lambda : map(int, input().split()) il = lambda : list(map(int, input().split())) ls = lambda : list(input()) n=ii() l=il() i=0 while 2**i<n-1: i+=1 i-=1 sm=0 for j in range(n-1): if j+2**i>n-1: i...
12
62
0
216157202
from math import log2, floor n, a = int(input()), [int(i) for i in input().split()] res = [0] * (n - 1) for k in range(n - 1): if k > 0: res[k] += res[k - 1] res[k] += a[k] p = floor(log2(n - 1 - k)) a[k + 2 ** p] += a[k] print(*res, sep="\n")
ABBYY Cup 2.0 - Hard
ICPC
2,012
2
256
Educational Game
The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below. The playing field is a sequence of n non-negative integers ai numbered from 1 to n. The goal of the game is to make numbers a1, a2, ..., ak (i.e. some prefix of the sequenc...
The first input line contains a single integer n. The second line contains n integers ai (0 ≤ ai ≤ 104), separated by single spaces. The input limitations for getting 20 points are: - 1 ≤ n ≤ 300 The input limitations for getting 50 points are: - 1 ≤ n ≤ 2000 The input limitations for getting 100 points are: - 1 ...
Print exactly n - 1 lines: the k-th output line must contain the minimum number of moves needed to make the first k elements of the original sequence ai equal to zero. 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
null
[{"input": "4\n1 0 1 2", "output": "1\n1\n3"}, {"input": "8\n1 2 3 4 5 6 7 8", "output": "1\n3\n6\n10\n16\n24\n40"}]
1,000
[]
12
[{"input": "4\r\n1 0 1 2\r\n", "output": "1\r\n1\r\n3\r\n"}, {"input": "8\r\n1 2 3 4 5 6 7 8\r\n", "output": "1\r\n3\r\n6\r\n10\r\n16\r\n24\r\n40\r\n"}, {"input": "5\r\n4 1 4 7 6\r\n", "output": "4\r\n5\r\n9\r\n17\r\n"}, {"input": "9\r\n13 13 7 11 3 9 3 5 5\r\n", "output": "13\r\n26\r\n33\r\n44\r\n47\r\n69\r\n79\r\n117...
false
stdio
null
true
839/C
839
C
Python 3
TESTS
38
607
152,268,800
120278205
from collections import defaultdict from sys import * import threading setrecursionlimit(10**9) threading.stack_size(10**8) def solve(): def dfs(d,a,vis,node): vis[node]=True if len(d[node])==1 and node!=1: a[node]=0 return for neighbor in d[node]: if vis[...
40
265
29,286,400
227297198
from collections import deque import sys;input = sys.stdin.readline S = lambda : input().strip() L = lambda :list(map(int, input().split())) I = lambda :int(input().strip()) T = lambda :map(int, input().split()) mod = int(1e9) + 7 n = I() graph = [[] for i in range(n)] for i in range(n-1): a,b = T() graph[a...
Codeforces Round 428 (Div. 2)
CF
2,017
2
256
Journey
There are n cities and n - 1 roads in the Seven Kingdoms, each road connects two cities and we can reach any city from any other by the roads. Theon and Yara Greyjoy are on a horse in the first city, they are starting traveling through the roads. But the weather is foggy, so they can’t see where the horse brings them....
The first line contains a single integer n (1 ≤ n ≤ 100000) — number of cities. Then n - 1 lines follow. The i-th line of these lines contains two integers ui and vi (1 ≤ ui, vi ≤ n, ui ≠ vi) — the cities connected by the i-th road. It is guaranteed that one can reach any city from any other by the roads.
Print a number — the expected length of their journey. The journey starts in the city 1. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6. Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, ...
null
In the first sample, their journey may end in cities 3 or 4 with equal probability. The distance to city 3 is 1 and to city 4 is 2, so the expected length is 1.5. In the second sample, their journey may end in city 4 or 5. The distance to the both cities is 2, so the expected length is 2.
[{"input": "4\n1 2\n1 3\n2 4", "output": "1.500000000000000"}, {"input": "5\n1 2\n1 3\n3 4\n2 5", "output": "2.000000000000000"}]
1,500
["dfs and similar", "dp", "graphs", "probabilities", "trees"]
40
[{"input": "4\r\n1 2\r\n1 3\r\n2 4\r\n", "output": "1.500000000000000\r\n"}, {"input": "5\r\n1 2\r\n1 3\r\n3 4\r\n2 5\r\n", "output": "2.000000000000000\r\n"}, {"input": "70\r\n1 25\r\n57 1\r\n18 1\r\n65 1\r\n38 1\r\n1 41\r\n1 5\r\n1 69\r\n1 3\r\n31 1\r\n1 8\r\n1 9\r\n53 1\r\n70 1\r\n45 1\r\n1 24\r\n1 42\r\n1 30\r\n1 1...
false
stdio
import sys def main(): input_path = sys.argv[1] correct_output_path = sys.argv[2] submission_output_path = sys.argv[3] with open(correct_output_path, 'r') as f: correct_output = f.read().strip() with open(submission_output_path, 'r') as f: submission_output = f.read().strip() ...
true
1006/A
1006
A
Python 3
TESTS
0
15
0
171178049
n = int(input()) # input the array arr = [int(x) for x in input().split()] new_array = [] for number in arr: if number % 2 == 0: new_array.append(number - 1) else: new_array.append(number + 1) [print(x, end=" ") for x in new_array]
18
46
0
121020549
n=int(input()) li=list(map(int,input().split())) for i in range(n): if li[i]%2==0: li[i]-=1 print(" ".join([str(ele) for ele in li]))
Codeforces Round 498 (Div. 3)
ICPC
2,018
1
256
Adjacent Replacements
Mishka got an integer array $$$a$$$ of length $$$n$$$ as a birthday present (what a surprise!). Mishka doesn't like this present and wants to change it somehow. He has invented an algorithm and called it "Mishka's Adjacent Replacements Algorithm". This algorithm can be represented as a sequence of steps: - Replace ea...
The first line of the input contains one integer number $$$n$$$ ($$$1 \le n \le 1000$$$) — the number of elements in Mishka's birthday present (surprisingly, an array). The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of the array.
Print $$$n$$$ integers — $$$b_1, b_2, \dots, b_n$$$, where $$$b_i$$$ is the final value of the $$$i$$$-th element of the array after applying "Mishka's Adjacent Replacements Algorithm" to the array $$$a$$$. Note that you cannot change the order of elements in the array.
null
The first example is described in the problem statement.
[{"input": "5\n1 2 4 5 10", "output": "1 1 3 5 9"}, {"input": "10\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000", "output": "9999 9 50605065 1 5 89 5 999999999 60506055 999999999"}]
800
["implementation"]
18
[{"input": "5\r\n1 2 4 5 10\r\n", "output": "1 1 3 5 9\r\n"}, {"input": "10\r\n10000 10 50605065 1 5 89 5 999999999 60506056 1000000000\r\n", "output": "9999 9 50605065 1 5 89 5 999999999 60506055 999999999\r\n"}, {"input": "1\r\n999999999\r\n", "output": "999999999\r\n"}, {"input": "1\r\n1000000000\r\n", "output": "99...
false
stdio
null
true
1009/E
1009
E
Python 3
TESTS
4
140
614,400
40387540
from sys import stdin #from math import * line = stdin.readline().rstrip().split() n = int(line[0]) numbers = list(map(int, stdin.readline().rstrip().split())) total = 0 for i in range(len(numbers)): num = pow(2, n-(i+1), 998244353)/2 num *= (n+2-(i+1)) num *= numbers[i] num %= 998244353 total +...
38
280
82,432,000
151372217
import sys mod = 998244353 add = lambda a, b: (a + b) % mod mult = lambda a, b: (a * b) % mod input = lambda: sys.stdin.buffer.readline().decode().strip() n, a = int(input()), [int(x) for x in input().split()] ans, lst, po = 0, 0, 1 for i in range(n - 1, -1, -1): new = add(lst, po) ans = add(ans, mult(new, a...
Educational Codeforces Round 47 (Rated for Div. 2)
ICPC
2,018
1.5
256
Intercity Travelling
Leha is planning his journey from Moscow to Saratov. He hates trains, so he has decided to get from one city to another by car. The path from Moscow to Saratov can be represented as a straight line (well, it's not that straight in reality, but in this problem we will consider it to be straight), and the distance betwe...
The first line contains one number $$$n$$$ ($$$1 \le n \le 10^6$$$) — the distance from Moscow to Saratov. The second line contains $$$n$$$ integer numbers $$$a_1$$$, $$$a_2$$$, ..., $$$a_n$$$ ($$$1 \le a_1 \le a_2 \le \dots \le a_n \le 10^6$$$), where $$$a_i$$$ is the difficulty of $$$i$$$-th kilometer after Leha has...
Print one number — $$$p \cdot 2^{n - 1}$$$, taken modulo $$$998244353$$$.
null
null
[{"input": "2\n1 2", "output": "5"}, {"input": "4\n1 3 3 7", "output": "60"}]
2,000
["combinatorics", "math", "probabilities"]
38
[{"input": "2\r\n1 2\r\n", "output": "5\r\n"}, {"input": "4\r\n1 3 3 7\r\n", "output": "60\r\n"}, {"input": "100\r\n3 3 3 4 7 8 8 8 9 9 10 12 12 13 14 14 15 15 16 17 17 20 21 21 22 22 23 25 29 31 36 37 37 38 39 40 41 41 41 42 43 44 45 46 46 47 47 49 49 49 51 52 52 53 54 55 59 59 59 60 62 63 63 64 66 69 70 71 71 72 74 7...
false
stdio
null
true
472/D
472
D
Python 3
TESTS
1
31
0
213886947
# LUOGU_RID: 115731710 print ("YES")
47
545
57,036,800
177433089
from math import inf from collections import * import math, os, sys, heapq, bisect, random,threading from functools import lru_cache from itertools import * import sys def inp(): return sys.stdin.readline().rstrip("\r\n") def out(var): sys.stdout.write(str(var)) # for fast output, always take string def inpu(): return...
Codeforces Round 270
CF
2,014
2
256
Design Tutorial: Inverse the Problem
There is an easy way to obtain a new task from an old one called "Inverse the problem": we give an output of the original task, and ask to generate an input, such that solution to the original problem will produce the output we provided. The hard task of Topcoder Open 2014 Round 2C, InverseRMQ, is a good example. Now ...
The first line contains an integer n (1 ≤ n ≤ 2000) — the number of nodes in that graph. Then next n lines each contains n integers di, j (0 ≤ di, j ≤ 109) — the distance between node i and node j.
If there exists such a tree, output "YES", otherwise output "NO".
null
In the first example, the required tree exists. It has one edge between nodes 1 and 2 with weight 2, another edge between nodes 1 and 3 with weight 7. In the second example, it is impossible because d1, 1 should be 0, but it is 1. In the third example, it is impossible because d1, 2 should equal d2, 1.
[{"input": "3\n0 2 7\n2 0 9\n7 9 0", "output": "YES"}, {"input": "3\n1 2 7\n2 0 9\n7 9 0", "output": "NO"}, {"input": "3\n0 2 2\n7 0 9\n7 9 0", "output": "NO"}, {"input": "3\n0 1 1\n1 0 1\n1 1 0", "output": "NO"}, {"input": "2\n0 0\n0 0", "output": "NO"}]
1,900
["dfs and similar", "dsu", "shortest paths", "trees"]
47
[{"input": "3\r\n0 2 7\r\n2 0 9\r\n7 9 0\r\n", "output": "YES\r\n"}, {"input": "3\r\n1 2 7\r\n2 0 9\r\n7 9 0\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 2 2\r\n7 0 9\r\n7 9 0\r\n", "output": "NO\r\n"}, {"input": "3\r\n0 1 1\r\n1 0 1\r\n1 1 0\r\n", "output": "NO\r\n"}, {"input": "2\r\n0 0\r\n0 0\r\n", "output": "NO\r\n...
false
stdio
null
true
62/D
62
D
PyPy 3-64
TESTS
3
92
0
223030823
import sys N = 0 old_path = [] def read_input(): global N, old_path readline = sys.stdin.readline N, M = [int(w) for w in readline().split()] old_path = [int(w) for w in readline().split()] def solve(): def dfs(node: int, fit: bool)-> bool: # print(node, fit, stk) if len(stk) == l...
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
618/B
618
B
Python 3
TESTS
2
46
0
15690439
n=int(input()) a=[] for i in range(n): a.append([int(i) for i in input().split(' ')]) b=[-1 for i in range(n)] for i in range(n): cnum=set([]) for j in range(n): cnum.add(a[i][j]) if len(cnum)==n: for j in range(n): if a[i][j]==0: if j==n-1: ...
23
46
0
184312367
n = int(input()) for i in range(n): a = input() a = a.split() a = [int(x) for x in a] a_s = set(a) if len(a_s) == n: b = a.copy() b[a.index(0)] = n break for i in b: print(i, end=' ')
Wunder Fund Round 2016 (Div. 1 + Div. 2 combined)
CF
2,016
2
256
Guess the Permutation
Bob has a permutation of integers from 1 to n. Denote this permutation as p. The i-th element of p will be denoted as pi. For all pairs of distinct integers i, j between 1 and n, he wrote the number ai, j = min(pi, pj). He writes ai, i = 0 for all integer i from 1 to n. Bob gave you all the values of ai, j that he wro...
The first line of the input will contain a single integer n (2 ≤ n ≤ 50). The next n lines will contain the values of ai, j. The j-th number on the i-th line will represent ai, j. The i-th number on the i-th line will be 0. It's guaranteed that ai, j = aj, i and there is at least one solution consistent with the infor...
Print n space separated integers, which represents a permutation that could have generated these values. If there are multiple possible solutions, print any of them.
null
In the first case, the answer can be {1, 2} or {2, 1}. In the second case, another possible answer is {2, 4, 5, 1, 3}.
[{"input": "2\n0 1\n1 0", "output": "2 1"}, {"input": "5\n0 2 2 1 2\n2 0 4 1 3\n2 4 0 1 3\n1 1 1 0 1\n2 3 3 1 0", "output": "2 5 4 1 3"}]
1,100
["constructive algorithms"]
23
[{"input": "2\r\n0 1\r\n1 0\r\n", "output": "2 1\r\n"}, {"input": "5\r\n0 2 2 1 2\r\n2 0 4 1 3\r\n2 4 0 1 3\r\n1 1 1 0 1\r\n2 3 3 1 0\r\n", "output": "2 5 4 1 3\r\n"}, {"input": "10\r\n0 1 5 2 5 3 4 5 5 5\r\n1 0 1 1 1 1 1 1 1 1\r\n5 1 0 2 6 3 4 6 6 6\r\n2 1 2 0 2 2 2 2 2 2\r\n5 1 6 2 0 3 4 8 8 7\r\n3 1 3 2 3 0 3 3 3 3\...
false
stdio
import sys def main(input_path, output_path, sub_path): with open(input_path) as f: lines = [line.strip() for line in f.readlines()] n = int(lines[0]) a = [list(map(int, line.split())) for line in lines[1:n+1]] with open(sub_path) as f: sub_line = f.read().strip() p = list(map(...
true
816/B
816
B
Python 3
TESTS
13
2,074
28,364,800
39247722
from sys import stdin,stdout n,k,q=map(int,input().split()) a=[[] for i in range(200001)];b=[0]*200001 for i in range(1,n+1): c,d=(int(x) for x in stdin.readline().split()) a[c].append(d);a[d].append(c) c=0 for i in range(1,200001): r=0 for j in a[i]: if j>i: c+=1 elif i==j: ...
45
296
11,059,200
167938606
def main(): n, k, q = map(int, fin().split()) p = [0]*int(2e5+2) for i in range(n): l,r = map(int, fin().split()) p[l] += 1; p[r+1] -= 1 for i in range(1, int(2e5+2)): p[i] += p[i-1] for i in range(1, int(2e5+2)): if p[i] >= k: p[i] = p[i-1]+1 ...
Codeforces Round 419 (Div. 2)
CF
2,017
2.5
512
Karen and Coffee
To stay woke and attentive during classes, Karen needs some coffee! Karen, a coffee aficionado, wants to know the optimal temperature for brewing the perfect cup of coffee. Indeed, she has spent some time reading several recipe books, including the universally acclaimed "The Art of the Covfefe". She knows n coffee re...
The first line of input contains three integers, n, k (1 ≤ k ≤ n ≤ 200000), and q (1 ≤ q ≤ 200000), the number of recipes, the minimum number of recipes a certain temperature must be recommended by to be admissible, and the number of questions Karen has, respectively. The next n lines describe the recipes. Specificall...
For each question, output a single integer on a line by itself, the number of admissible integer temperatures between a and b degrees, inclusive.
null
In the first test case, Karen knows 3 recipes. 1. The first one recommends brewing the coffee between 91 and 94 degrees, inclusive. 2. The second one recommends brewing the coffee between 92 and 97 degrees, inclusive. 3. The third one recommends brewing the coffee between 97 and 99 degrees, inclusive. A temperature i...
[{"input": "3 2 4\n91 94\n92 97\n97 99\n92 94\n93 97\n95 96\n90 100", "output": "3\n3\n0\n4"}, {"input": "2 1 1\n1 1\n200000 200000\n90 100", "output": "0"}]
1,400
["binary search", "data structures", "implementation"]
45
[{"input": "3 2 4\r\n91 94\r\n92 97\r\n97 99\r\n92 94\r\n93 97\r\n95 96\r\n90 100\r\n", "output": "3\r\n3\r\n0\r\n4\r\n"}, {"input": "2 1 1\r\n1 1\r\n200000 200000\r\n90 100\r\n", "output": "0\r\n"}, {"input": "1 1 1\r\n1 1\r\n1 1\r\n", "output": "1\r\n"}, {"input": "1 1 1\r\n200000 200000\r\n200000 200000\r\n", "outpu...
false
stdio
null
true
618/B
618
B
Python 3
PRETESTS
2
61
0
15661337
n = int(input()) a = [list(map(int, input().split())) for _ in range(n)] res = list() perm = list() for i in range(n): res.append(len({a[i][j] for j in range(n)}) - 1) if i >= 1 and res[i] == res[i-1]: perm.append((i, i-1, res[i])) res[i] += 1 wrong = False for x in range(i+1): ...
23
46
102,400
145463044
from collections import Counter n = int(input()) p = [0] * n hash_map = {} found = set() for i in range(1, n + 1): hash_map[i] = n - i for i in range(n): array = list(map(int, input().split())) count = Counter(array) for k, v in count.items(): for k1, v2 in hash_map.items(): if 1 <...
Wunder Fund Round 2016 (Div. 1 + Div. 2 combined)
CF
2,016
2
256
Guess the Permutation
Bob has a permutation of integers from 1 to n. Denote this permutation as p. The i-th element of p will be denoted as pi. For all pairs of distinct integers i, j between 1 and n, he wrote the number ai, j = min(pi, pj). He writes ai, i = 0 for all integer i from 1 to n. Bob gave you all the values of ai, j that he wro...
The first line of the input will contain a single integer n (2 ≤ n ≤ 50). The next n lines will contain the values of ai, j. The j-th number on the i-th line will represent ai, j. The i-th number on the i-th line will be 0. It's guaranteed that ai, j = aj, i and there is at least one solution consistent with the infor...
Print n space separated integers, which represents a permutation that could have generated these values. If there are multiple possible solutions, print any of them.
null
In the first case, the answer can be {1, 2} or {2, 1}. In the second case, another possible answer is {2, 4, 5, 1, 3}.
[{"input": "2\n0 1\n1 0", "output": "2 1"}, {"input": "5\n0 2 2 1 2\n2 0 4 1 3\n2 4 0 1 3\n1 1 1 0 1\n2 3 3 1 0", "output": "2 5 4 1 3"}]
1,100
["constructive algorithms"]
23
[{"input": "2\r\n0 1\r\n1 0\r\n", "output": "2 1\r\n"}, {"input": "5\r\n0 2 2 1 2\r\n2 0 4 1 3\r\n2 4 0 1 3\r\n1 1 1 0 1\r\n2 3 3 1 0\r\n", "output": "2 5 4 1 3\r\n"}, {"input": "10\r\n0 1 5 2 5 3 4 5 5 5\r\n1 0 1 1 1 1 1 1 1 1\r\n5 1 0 2 6 3 4 6 6 6\r\n2 1 2 0 2 2 2 2 2 2\r\n5 1 6 2 0 3 4 8 8 7\r\n3 1 3 2 3 0 3 3 3 3\...
false
stdio
import sys def main(input_path, output_path, sub_path): with open(input_path) as f: lines = [line.strip() for line in f.readlines()] n = int(lines[0]) a = [list(map(int, line.split())) for line in lines[1:n+1]] with open(sub_path) as f: sub_line = f.read().strip() p = list(map(...
true
665/B
665
B
PyPy 3-64
TESTS
1
30
0
167703286
import sys input = sys.stdin.readline n, m, k = map(int, input().split()) w = list(map(int, input().split())) d = [0]*(k+1) for i in range(k): d[w[i]] = i+1 c = 0 for _ in range(n): q = list(map(int, input().split())) for i in q: c += d[i] for j in range(1, k): if d[j] < d[i]: ...
10
62
2,048,000
167704599
import sys input = sys.stdin.readline n, m, k = map(int, input().split()) d = list(map(int, input().split())) x = [0]*(k+1) for i in range(k): x[d[i]] = i+1 c = 0 for _ in range(n): q = list(map(int, input().split())) for i in q: a = x[i] - 1 c += a+1 d = [d[a]] + d[:a] + d[a+1:] ...
Educational Codeforces Round 12
ICPC
2,016
1
256
Shopping
Ayush is a cashier at the shopping center. Recently his department has started a ''click and collect" service which allows users to shop online. The store contains k items. n customers have already used the above service. Each user paid for m items. Let aij denote the j-th item in the i-th person's order. Due to the ...
The first line contains three integers n, m and k (1 ≤ n, k ≤ 100, 1 ≤ m ≤ k) — the number of users, the number of items each user wants to buy and the total number of items at the market. The next line contains k distinct integers pl (1 ≤ pl ≤ k) denoting the initial positions of the items in the store. The items are...
Print the only integer t — the total time needed for Ayush to process all the orders.
null
Customer 1 wants the items 1 and 5. pos(1) = 3, so the new positions are: [1, 3, 4, 2, 5]. pos(5) = 5, so the new positions are: [5, 1, 3, 4, 2]. Time taken for the first customer is 3 + 5 = 8. Customer 2 wants the items 3 and 1. pos(3) = 3, so the new positions are: [3, 5, 1, 4, 2]. pos(1) = 3, so the new positi...
[{"input": "2 2 5\n3 4 1 2 5\n1 5\n3 1", "output": "14"}]
1,400
["brute force"]
10
[{"input": "2 2 5\r\n3 4 1 2 5\r\n1 5\r\n3 1\r\n", "output": "14\r\n"}, {"input": "4 4 4\r\n1 2 3 4\r\n3 4 2 1\r\n4 3 2 1\r\n4 1 2 3\r\n4 1 2 3\r\n", "output": "59\r\n"}, {"input": "1 1 1\r\n1\r\n1\r\n", "output": "1\r\n"}, {"input": "10 1 100\r\n1 55 67 75 40 86 24 84 82 26 81 23 70 79 51 54 21 78 31 98 68 93 66 88 99...
false
stdio
null
true
500/C
500
C
PyPy 3-64
TESTS
1
61
0
155356502
n, m = map(int, input().split()) w = list(map(int, input().split())) b = list(map(int, input().split())) s, l = set(), [] for x in b: if x not in s: l.append(x) s.add(x) for j in range(1, n + 1): if j not in s: l.append(s) ans = 0 for x in b: i = l.index(x) ans += sum(l[: i]) ...
35
62
2,150,400
200815663
import sys input = lambda: sys.stdin.readline().rstrip() N,M = map(int, input().split()) W = list(map(int, input().split())) B = list(map(int, input().split())) seen = [0]*(N+1) A = [] for b in B: if seen[b]==0: A.append(b) seen[b]=1 ans = 0 for b in B: cnt = 0 for i in range(N): if A[i]==b: ans+=cnt ...
Good Bye 2014
CF
2,014
2
256
New Year Book Reading
New Year is coming, and Jaehyun decided to read many books during 2015, unlike this year. He has n books numbered by integers from 1 to n. The weight of the i-th (1 ≤ i ≤ n) book is wi. As Jaehyun's house is not large enough to have a bookshelf, he keeps the n books by stacking them vertically. When he wants to read a...
The first line contains two space-separated integers n (2 ≤ n ≤ 500) and m (1 ≤ m ≤ 1000) — the number of books, and the number of days for which Jaehyun would read books. The second line contains n space-separated integers w1, w2, ..., wn (1 ≤ wi ≤ 100) — the weight of each book. The third line contains m space sepa...
Print the minimum total weight of books he should lift, which can be achieved by rearranging the order of stacked books.
null
Here's a picture depicting the example. Each vertical column presents the stacked books.
[{"input": "3 5\n1 2 3\n1 3 2 3 1", "output": "12"}]
1,600
["constructive algorithms", "greedy", "implementation", "math"]
35
[{"input": "3 5\r\n1 2 3\r\n1 3 2 3 1\r\n", "output": "12\r\n"}, {"input": "3 3\r\n10 20 30\r\n1 2 3\r\n", "output": "40\r\n"}, {"input": "2 2\r\n10 12\r\n2 1\r\n", "output": "12\r\n"}, {"input": "10 10\r\n61 59 97 16 2 94 57 48 91 93\r\n2 8 6 5 3 1 3 4 9 10\r\n", "output": "2137\r\n"}, {"input": "50 50\r\n75 71 23 37 ...
false
stdio
null
true
500/C
500
C
PyPy 3-64
TESTS
1
62
0
185165980
import sys input = sys.stdin.readline from collections import deque n, m = map(int, input().split()) w = list(map(int, input().split())) s = list(map(int, input().split())) d = [0]*(n+1) f = deque([]) c = 0 for i in s: if d[i] == 0: d[i] = 1 c += sum(f) f.appendleft(i) else: for...
35
77
2,252,800
192615660
n,m = list(map(int,input().split())) w = list(map(int,input().split())) a = list(map(int,input().split())) li = [] vis = [False]*n for i in range(m): if vis[a[i] - 1] == False: li.append(a[i] - 1) vis[a[i] - 1] = True ans = 0 for i in range(m): weigh = 0 for j in range(len(li)): if l...
Good Bye 2014
CF
2,014
2
256
New Year Book Reading
New Year is coming, and Jaehyun decided to read many books during 2015, unlike this year. He has n books numbered by integers from 1 to n. The weight of the i-th (1 ≤ i ≤ n) book is wi. As Jaehyun's house is not large enough to have a bookshelf, he keeps the n books by stacking them vertically. When he wants to read a...
The first line contains two space-separated integers n (2 ≤ n ≤ 500) and m (1 ≤ m ≤ 1000) — the number of books, and the number of days for which Jaehyun would read books. The second line contains n space-separated integers w1, w2, ..., wn (1 ≤ wi ≤ 100) — the weight of each book. The third line contains m space sepa...
Print the minimum total weight of books he should lift, which can be achieved by rearranging the order of stacked books.
null
Here's a picture depicting the example. Each vertical column presents the stacked books.
[{"input": "3 5\n1 2 3\n1 3 2 3 1", "output": "12"}]
1,600
["constructive algorithms", "greedy", "implementation", "math"]
35
[{"input": "3 5\r\n1 2 3\r\n1 3 2 3 1\r\n", "output": "12\r\n"}, {"input": "3 3\r\n10 20 30\r\n1 2 3\r\n", "output": "40\r\n"}, {"input": "2 2\r\n10 12\r\n2 1\r\n", "output": "12\r\n"}, {"input": "10 10\r\n61 59 97 16 2 94 57 48 91 93\r\n2 8 6 5 3 1 3 4 9 10\r\n", "output": "2137\r\n"}, {"input": "50 50\r\n75 71 23 37 ...
false
stdio
null
true
504/D
504
D
PyPy 3
TESTS
0
139
2,048,000
72290029
buck = [[0, 0] for i in range(2500)] m = int(input()) for i in range(m): a = int(input()) ok = True br = 1 for j in range(2500, -1, -1): if a & (1 << j): if(buck[j][0]): a ^= buck[j][0] br ^= buck[j][1] else: ok = False ...
52
1,107
12,492,800
153501116
m = int(input()) base = [] for i in range(m): a = int(input()) need=0 for v,bitset in base: if a^v<a: need^=bitset a^=v if a: print(0) base.append((a,need^(1<<i))) else: res = [] for d in range(i): if need&(1<<d): ...
Codeforces Round 285 (Div. 1)
CF
2,015
2
256
Misha and XOR
After Misha's birthday he had many large numbers left, scattered across the room. Now it's time to clean up and Misha needs to put them in a basket. He ordered this task to his pet robot that agreed to complete the task at certain conditions. Before the robot puts a number x to the basket, Misha should answer the quest...
The first line contains number m (1 ≤ m ≤ 2000), showing how many numbers are scattered around the room. The next m lines contain the numbers in the order in which the robot puts them in the basket. Each number is a positive integer strictly less than 10600 that doesn't contain leading zeroes.
For each number either print a 0 on the corresponding line, if the number cannot be represented as a XOR sum of numbers that are in the basket, or print integer k showing how many numbers are in the representation and the indexes of these numbers. Separate the numbers by spaces. Each number can occur in the representat...
null
The XOR sum of numbers is the result of bitwise sum of numbers modulo 2.
[{"input": "7\n7\n6\n5\n4\n3\n2\n1", "output": "0\n0\n0\n3 0 1 2\n2 1 2\n2 0 2\n2 0 1"}, {"input": "2\n5\n5", "output": "0\n1 0"}]
2,700
["bitmasks"]
52
[{"input": "7\r\n7\r\n6\r\n5\r\n4\r\n3\r\n2\r\n1\r\n", "output": "0\r\n0\r\n0\r\n3 0 1 2\r\n2 1 2\r\n2 0 2\r\n2 0 1\r\n"}, {"input": "2\r\n5\r\n5\r\n", "output": "0\r\n1 0\r\n"}, {"input": "10\r\n81\r\n97\r\n12\r\n2\r\n16\r\n96\r\n80\r\n99\r\n6\r\n83\r\n", "output": "0\r\n0\r\n0\r\n0\r\n0\r\n0\r\n3 0 1 5\r\n2 1 3\r\n0\...
false
stdio
null
true
1009/G
1009
G
Python 3
TESTS
1
93
0
43482751
a = input() n = int(input()) m = len(a) se={} for z in range(n): p,q = input().split(" ") p = int(p)-1 s = [] for i in q: if i in a: s.append(i) s.sort() se[p]=s[0] stri="" if len(se)<=0: print("Impossible") exit() for i in se.keys(): j = a.find(se[i]) a = a[:...
57
233
10,137,600
167672037
import sys, os, io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline s = list(input().rstrip()) pow2 = [1] for _ in range(6): pow2.append(2 * pow2[-1]) p = pow2[6] cnt = [0] * p for i in s: cnt[pow2[i - 97]] += 1 sp = set(pow2) u = [[pow2[i]] for i in range(6)] for i in range(1, p): if i in sp: ...
Educational Codeforces Round 47 (Rated for Div. 2)
ICPC
2,018
2
256
Allowed Letters
Polycarp has just launched his new startup idea. The niche is pretty free and the key vector of development sounds really promising, so he easily found himself some investors ready to sponsor the company. However, he is yet to name the startup! Actually, Polycarp has already came up with the name but some improvement ...
The first line is the string $$$s$$$ ($$$1 \le |s| \le 10^5$$$) — the name Polycarp has came up with. The string consists only of lowercase Latin letters from "a" to "f". The second line contains a single integer $$$m$$$ ($$$0 \le m \le |s|$$$) — the number of investors. The $$$i$$$-th of the next $$$m$$$ lines conta...
If Polycarp can't produce any valid name then print "Impossible". Otherwise print the smallest lexicographically name Polycarp can obtain by swapping letters in string $$$s$$$ such that the letter at every position is among the allowed ones.
null
null
[{"input": "bedefead\n5\n2 e\n1 dc\n5 b\n7 ef\n6 ef", "output": "deadbeef"}, {"input": "abacaba\n0", "output": "aaaabbc"}, {"input": "fc\n2\n1 cfab\n2 f", "output": "cf"}]
2,400
["bitmasks", "flows", "graph matchings", "graphs", "greedy"]
57
[{"input": "bedefead\r\n5\r\n2 e\r\n1 dc\r\n5 b\r\n7 ef\r\n6 ef\r\n", "output": "deadbeef\r\n"}, {"input": "abacaba\r\n0\r\n", "output": "aaaabbc\r\n"}, {"input": "fc\r\n2\r\n1 cfab\r\n2 f\r\n", "output": "cf\r\n"}, {"input": "bbcbbc\r\n6\r\n1 c\r\n2 c\r\n3 b\r\n4 ab\r\n5 ab\r\n6 ab\r\n", "output": "ccbbbb\r\n"}, {"inp...
false
stdio
null
true
430/A
430
A
Python 3
PRETESTS
2
61
0
6593116
n, m = map(int, input().split()) points = input().split() segments = [input().split() for _ in range(m)] print('1 0 ' * (n // 2) + ('1' if n % 2 else ''))
12
61
0
10409824
R = lambda: list(map(int, input().split())) n, m = R() a = R() exist = [False for i in range(200)] for i in range(m): l, r = R() for j in a: if l <= j <= r: exist[j] = True b = a[:] b.sort() ans = [0 for i in range(200)] flag = 0 for i in b: if exist[i]: ans[i]=flag ...
Codeforces Round 245 (Div. 2)
CF
2,014
1
256
Points and Segments (easy)
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segme...
The first line of input contains two integers: n (1 ≤ n ≤ 100) and m (1 ≤ m ≤ 100). The next line contains n space-separated integers x1, x2, ..., xn (0 ≤ xi ≤ 100) — the coordinates of the points. The following m lines contain the descriptions of the m segments. Each line contains two integers li and ri (0 ≤ li ≤ ri ≤...
If there is no good drawing for a given test, output a single integer -1. Otherwise output n integers, each integer must be 0 or 1. The i-th number denotes the color of the i-th point (0 is red, and 1 is blue). If there are multiple good drawings you can output any of them.
null
null
[{"input": "3 3\n3 7 14\n1 5\n6 10\n11 15", "output": "0 0 0"}, {"input": "3 4\n1 2 3\n1 2\n2 3\n5 6\n2 2", "output": "1 0 1"}]
1,600
["constructive algorithms", "sortings"]
12
[{"input": "3 3\r\n3 7 14\r\n1 5\r\n6 10\r\n11 15\r\n", "output": "0 0 0"}, {"input": "3 4\r\n1 2 3\r\n1 2\r\n2 3\r\n5 6\r\n2 2\r\n", "output": "1 0 1 "}, {"input": "10 10\r\n3 4 2 6 1 9 0 5 8 7\r\n5 7\r\n2 6\r\n0 1\r\n5 6\r\n3 4\r\n2 5\r\n2 10\r\n4 6\r\n3 6\r\n3 7\r\n", "output": "0 1 1 1 0 0 1 0 1 0 "}, {"input": "3 ...
false
stdio
import sys def read_ints(file): return list(map(int, file.read().split())) def main(input_path, output_path, submission_path): with open(input_path) as f: n, m = map(int, f.readline().split()) points = list(map(int, f.readline().split())) segments = [tuple(map(int, f.readline().split()...
true
430/A
430
A
Python 3
PRETESTS
2
61
0
6593524
n, m = map(int, input().split()) points = input().split() segments = [input().split() for _ in range(m)] ans = list() for i in range(n): ans.append('1' if i % 2 else '0') print(' '.join(ans))
12
61
0
15914387
input() P=list(map(int,input().split())) for a,b in sorted([[P.index(p),i%2]for i,p in enumerate(sorted(P))]):print(b)
Codeforces Round 245 (Div. 2)
CF
2,014
1
256
Points and Segments (easy)
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segme...
The first line of input contains two integers: n (1 ≤ n ≤ 100) and m (1 ≤ m ≤ 100). The next line contains n space-separated integers x1, x2, ..., xn (0 ≤ xi ≤ 100) — the coordinates of the points. The following m lines contain the descriptions of the m segments. Each line contains two integers li and ri (0 ≤ li ≤ ri ≤...
If there is no good drawing for a given test, output a single integer -1. Otherwise output n integers, each integer must be 0 or 1. The i-th number denotes the color of the i-th point (0 is red, and 1 is blue). If there are multiple good drawings you can output any of them.
null
null
[{"input": "3 3\n3 7 14\n1 5\n6 10\n11 15", "output": "0 0 0"}, {"input": "3 4\n1 2 3\n1 2\n2 3\n5 6\n2 2", "output": "1 0 1"}]
1,600
["constructive algorithms", "sortings"]
12
[{"input": "3 3\r\n3 7 14\r\n1 5\r\n6 10\r\n11 15\r\n", "output": "0 0 0"}, {"input": "3 4\r\n1 2 3\r\n1 2\r\n2 3\r\n5 6\r\n2 2\r\n", "output": "1 0 1 "}, {"input": "10 10\r\n3 4 2 6 1 9 0 5 8 7\r\n5 7\r\n2 6\r\n0 1\r\n5 6\r\n3 4\r\n2 5\r\n2 10\r\n4 6\r\n3 6\r\n3 7\r\n", "output": "0 1 1 1 0 0 1 0 1 0 "}, {"input": "3 ...
false
stdio
import sys def read_ints(file): return list(map(int, file.read().split())) def main(input_path, output_path, submission_path): with open(input_path) as f: n, m = map(int, f.readline().split()) points = list(map(int, f.readline().split())) segments = [tuple(map(int, f.readline().split()...
true
430/A
430
A
Python 3
TESTS
2
46
4,608,000
25555550
n, m = map(int, input().split()) c = list(map(int, input().split())) d = [] for i in range(m): #d.append(list(map(int, input().spilt()))) a = input() output = [] for i in range(n): if i % 2 == 0: output.append("0") else: output.append("1") print(" ".join(output))
12
61
0
149664726
def main(): a = input() b = [int(i) for i in input().split()] n = len(b) c = [(i, index) for index, i in enumerate(b)] c.sort() res = [0]*n flag = 0 for i, j in c: res[j] = flag flag ^= 1 print(" ".join(str(i) for i in res)) main()
Codeforces Round 245 (Div. 2)
CF
2,014
1
256
Points and Segments (easy)
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segme...
The first line of input contains two integers: n (1 ≤ n ≤ 100) and m (1 ≤ m ≤ 100). The next line contains n space-separated integers x1, x2, ..., xn (0 ≤ xi ≤ 100) — the coordinates of the points. The following m lines contain the descriptions of the m segments. Each line contains two integers li and ri (0 ≤ li ≤ ri ≤...
If there is no good drawing for a given test, output a single integer -1. Otherwise output n integers, each integer must be 0 or 1. The i-th number denotes the color of the i-th point (0 is red, and 1 is blue). If there are multiple good drawings you can output any of them.
null
null
[{"input": "3 3\n3 7 14\n1 5\n6 10\n11 15", "output": "0 0 0"}, {"input": "3 4\n1 2 3\n1 2\n2 3\n5 6\n2 2", "output": "1 0 1"}]
1,600
["constructive algorithms", "sortings"]
12
[{"input": "3 3\r\n3 7 14\r\n1 5\r\n6 10\r\n11 15\r\n", "output": "0 0 0"}, {"input": "3 4\r\n1 2 3\r\n1 2\r\n2 3\r\n5 6\r\n2 2\r\n", "output": "1 0 1 "}, {"input": "10 10\r\n3 4 2 6 1 9 0 5 8 7\r\n5 7\r\n2 6\r\n0 1\r\n5 6\r\n3 4\r\n2 5\r\n2 10\r\n4 6\r\n3 6\r\n3 7\r\n", "output": "0 1 1 1 0 0 1 0 1 0 "}, {"input": "3 ...
false
stdio
import sys def read_ints(file): return list(map(int, file.read().split())) def main(input_path, output_path, submission_path): with open(input_path) as f: n, m = map(int, f.readline().split()) points = list(map(int, f.readline().split())) segments = [tuple(map(int, f.readline().split()...
true
430/A
430
A
PyPy 3-64
TESTS
2
61
0
201609464
import sys input = sys.stdin.readline n, m = map(int, input().split()) w = [str(j) for i, j in sorted([(j[0], i%2) for i, j in enumerate([(j, i) for i, j in enumerate(map(int, input().split()))])])] for i in range(m): a, b = map(int, input().split()) print(' '.join(w))
12
61
0
200627128
N,M = map(int, input().split()) A = list(map(int, input().split())) B = [] for _ in range(M): a,b = map(int, input().split()) B.append((a,b)) B = [] for i,a in enumerate(A): B.append((a,i)) B.sort() ans = [0]*N for i,(a,j) in enumerate(B): ans[j] = i%2 print(*ans)
Codeforces Round 245 (Div. 2)
CF
2,014
1
256
Points and Segments (easy)
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segme...
The first line of input contains two integers: n (1 ≤ n ≤ 100) and m (1 ≤ m ≤ 100). The next line contains n space-separated integers x1, x2, ..., xn (0 ≤ xi ≤ 100) — the coordinates of the points. The following m lines contain the descriptions of the m segments. Each line contains two integers li and ri (0 ≤ li ≤ ri ≤...
If there is no good drawing for a given test, output a single integer -1. Otherwise output n integers, each integer must be 0 or 1. The i-th number denotes the color of the i-th point (0 is red, and 1 is blue). If there are multiple good drawings you can output any of them.
null
null
[{"input": "3 3\n3 7 14\n1 5\n6 10\n11 15", "output": "0 0 0"}, {"input": "3 4\n1 2 3\n1 2\n2 3\n5 6\n2 2", "output": "1 0 1"}]
1,600
["constructive algorithms", "sortings"]
12
[{"input": "3 3\r\n3 7 14\r\n1 5\r\n6 10\r\n11 15\r\n", "output": "0 0 0"}, {"input": "3 4\r\n1 2 3\r\n1 2\r\n2 3\r\n5 6\r\n2 2\r\n", "output": "1 0 1 "}, {"input": "10 10\r\n3 4 2 6 1 9 0 5 8 7\r\n5 7\r\n2 6\r\n0 1\r\n5 6\r\n3 4\r\n2 5\r\n2 10\r\n4 6\r\n3 6\r\n3 7\r\n", "output": "0 1 1 1 0 0 1 0 1 0 "}, {"input": "3 ...
false
stdio
import sys def read_ints(file): return list(map(int, file.read().split())) def main(input_path, output_path, submission_path): with open(input_path) as f: n, m = map(int, f.readline().split()) points = list(map(int, f.readline().split())) segments = [tuple(map(int, f.readline().split()...
true
430/A
430
A
Python 3
TESTS
2
46
4,608,000
23984177
n, m = map(int, input().split()) points = list(map(int, input().split())) for i in range(m): l, r = map(int, input().split()) print(' '.join([str(i%2) for i in range(n)]))
12
62
0
6595409
n, m = map(int, input().split()) points = list(map(int, input().split())) segments = [input().split() for _ in range(m)] sorted_points = sorted(points) ans = [-1] * n for i in range(n): c = '0' if i % 2 else '1' ans[points.index(sorted_points[i])] = c print(' '.join(ans))
Codeforces Round 245 (Div. 2)
CF
2,014
1
256
Points and Segments (easy)
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segme...
The first line of input contains two integers: n (1 ≤ n ≤ 100) and m (1 ≤ m ≤ 100). The next line contains n space-separated integers x1, x2, ..., xn (0 ≤ xi ≤ 100) — the coordinates of the points. The following m lines contain the descriptions of the m segments. Each line contains two integers li and ri (0 ≤ li ≤ ri ≤...
If there is no good drawing for a given test, output a single integer -1. Otherwise output n integers, each integer must be 0 or 1. The i-th number denotes the color of the i-th point (0 is red, and 1 is blue). If there are multiple good drawings you can output any of them.
null
null
[{"input": "3 3\n3 7 14\n1 5\n6 10\n11 15", "output": "0 0 0"}, {"input": "3 4\n1 2 3\n1 2\n2 3\n5 6\n2 2", "output": "1 0 1"}]
1,600
["constructive algorithms", "sortings"]
12
[{"input": "3 3\r\n3 7 14\r\n1 5\r\n6 10\r\n11 15\r\n", "output": "0 0 0"}, {"input": "3 4\r\n1 2 3\r\n1 2\r\n2 3\r\n5 6\r\n2 2\r\n", "output": "1 0 1 "}, {"input": "10 10\r\n3 4 2 6 1 9 0 5 8 7\r\n5 7\r\n2 6\r\n0 1\r\n5 6\r\n3 4\r\n2 5\r\n2 10\r\n4 6\r\n3 6\r\n3 7\r\n", "output": "0 1 1 1 0 0 1 0 1 0 "}, {"input": "3 ...
false
stdio
import sys def read_ints(file): return list(map(int, file.read().split())) def main(input_path, output_path, submission_path): with open(input_path) as f: n, m = map(int, f.readline().split()) points = list(map(int, f.readline().split())) segments = [tuple(map(int, f.readline().split()...
true
430/A
430
A
Python 3
TESTS
2
46
4,608,000
23985512
n, m = map(int, input().split()) map(int, input().split()) for i in range(m): l, r = map(int, input().split()) print(' '.join([str(i%2) for i in range(1, n+1)]))
12
62
0
6599924
n,m=list(map(int,input().split())) points = [(v,i) for i,v in enumerate(map(int,input().split()))] for _ in range(m): input() blue=True ans=[0]*n points = sorted(points) for p in points: v,i = p ans[i] = int(blue) blue=not blue for v in ans: print(v,end=' ') print()
Codeforces Round 245 (Div. 2)
CF
2,014
1
256
Points and Segments (easy)
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segme...
The first line of input contains two integers: n (1 ≤ n ≤ 100) and m (1 ≤ m ≤ 100). The next line contains n space-separated integers x1, x2, ..., xn (0 ≤ xi ≤ 100) — the coordinates of the points. The following m lines contain the descriptions of the m segments. Each line contains two integers li and ri (0 ≤ li ≤ ri ≤...
If there is no good drawing for a given test, output a single integer -1. Otherwise output n integers, each integer must be 0 or 1. The i-th number denotes the color of the i-th point (0 is red, and 1 is blue). If there are multiple good drawings you can output any of them.
null
null
[{"input": "3 3\n3 7 14\n1 5\n6 10\n11 15", "output": "0 0 0"}, {"input": "3 4\n1 2 3\n1 2\n2 3\n5 6\n2 2", "output": "1 0 1"}]
1,600
["constructive algorithms", "sortings"]
12
[{"input": "3 3\r\n3 7 14\r\n1 5\r\n6 10\r\n11 15\r\n", "output": "0 0 0"}, {"input": "3 4\r\n1 2 3\r\n1 2\r\n2 3\r\n5 6\r\n2 2\r\n", "output": "1 0 1 "}, {"input": "10 10\r\n3 4 2 6 1 9 0 5 8 7\r\n5 7\r\n2 6\r\n0 1\r\n5 6\r\n3 4\r\n2 5\r\n2 10\r\n4 6\r\n3 6\r\n3 7\r\n", "output": "0 1 1 1 0 0 1 0 1 0 "}, {"input": "3 ...
false
stdio
import sys def read_ints(file): return list(map(int, file.read().split())) def main(input_path, output_path, submission_path): with open(input_path) as f: n, m = map(int, f.readline().split()) points = list(map(int, f.readline().split())) segments = [tuple(map(int, f.readline().split()...
true
430/A
430
A
Python 3
PRETESTS
2
46
0
6590143
#Points and Segments 2 a,b=input().split() points=int(a) segments=int(b) #Next line input, n point locations. coordinates=[] coordinates=input().split() coordinates=[int(a) for a in coordinates] coordinates=sorted(coordinates) #Next m lines, get start and end of segments in a list all_segments=[] for segment in rang...
12
62
0
6600263
input() P=list(map(int,input().split())) l=sorted([[P.index(p),i%2] for i,p in enumerate(sorted(P))]) for a,b in l:print(b)
Codeforces Round 245 (Div. 2)
CF
2,014
1
256
Points and Segments (easy)
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segme...
The first line of input contains two integers: n (1 ≤ n ≤ 100) and m (1 ≤ m ≤ 100). The next line contains n space-separated integers x1, x2, ..., xn (0 ≤ xi ≤ 100) — the coordinates of the points. The following m lines contain the descriptions of the m segments. Each line contains two integers li and ri (0 ≤ li ≤ ri ≤...
If there is no good drawing for a given test, output a single integer -1. Otherwise output n integers, each integer must be 0 or 1. The i-th number denotes the color of the i-th point (0 is red, and 1 is blue). If there are multiple good drawings you can output any of them.
null
null
[{"input": "3 3\n3 7 14\n1 5\n6 10\n11 15", "output": "0 0 0"}, {"input": "3 4\n1 2 3\n1 2\n2 3\n5 6\n2 2", "output": "1 0 1"}]
1,600
["constructive algorithms", "sortings"]
12
[{"input": "3 3\r\n3 7 14\r\n1 5\r\n6 10\r\n11 15\r\n", "output": "0 0 0"}, {"input": "3 4\r\n1 2 3\r\n1 2\r\n2 3\r\n5 6\r\n2 2\r\n", "output": "1 0 1 "}, {"input": "10 10\r\n3 4 2 6 1 9 0 5 8 7\r\n5 7\r\n2 6\r\n0 1\r\n5 6\r\n3 4\r\n2 5\r\n2 10\r\n4 6\r\n3 6\r\n3 7\r\n", "output": "0 1 1 1 0 0 1 0 1 0 "}, {"input": "3 ...
false
stdio
import sys def read_ints(file): return list(map(int, file.read().split())) def main(input_path, output_path, submission_path): with open(input_path) as f: n, m = map(int, f.readline().split()) points = list(map(int, f.readline().split())) segments = [tuple(map(int, f.readline().split()...
true
430/A
430
A
Python 3
TESTS
2
46
0
6619187
n, m = map(int, input().split()) print('0 1 ' * (n // 2) + '0' * (n & 1))
12
62
0
6602943
import sys read = lambda t=int:list(map(t,sys.stdin.readline().split())) _, M = read() xs = read() for _ in range(M): _ = read() xs = sorted((x,i) for i,x in enumerate(xs)) xs = sorted((i,j) for j,(x,i) in enumerate(xs)) print(" ".join(str(j%2) for _,j in xs))
Codeforces Round 245 (Div. 2)
CF
2,014
1
256
Points and Segments (easy)
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segme...
The first line of input contains two integers: n (1 ≤ n ≤ 100) and m (1 ≤ m ≤ 100). The next line contains n space-separated integers x1, x2, ..., xn (0 ≤ xi ≤ 100) — the coordinates of the points. The following m lines contain the descriptions of the m segments. Each line contains two integers li and ri (0 ≤ li ≤ ri ≤...
If there is no good drawing for a given test, output a single integer -1. Otherwise output n integers, each integer must be 0 or 1. The i-th number denotes the color of the i-th point (0 is red, and 1 is blue). If there are multiple good drawings you can output any of them.
null
null
[{"input": "3 3\n3 7 14\n1 5\n6 10\n11 15", "output": "0 0 0"}, {"input": "3 4\n1 2 3\n1 2\n2 3\n5 6\n2 2", "output": "1 0 1"}]
1,600
["constructive algorithms", "sortings"]
12
[{"input": "3 3\r\n3 7 14\r\n1 5\r\n6 10\r\n11 15\r\n", "output": "0 0 0"}, {"input": "3 4\r\n1 2 3\r\n1 2\r\n2 3\r\n5 6\r\n2 2\r\n", "output": "1 0 1 "}, {"input": "10 10\r\n3 4 2 6 1 9 0 5 8 7\r\n5 7\r\n2 6\r\n0 1\r\n5 6\r\n3 4\r\n2 5\r\n2 10\r\n4 6\r\n3 6\r\n3 7\r\n", "output": "0 1 1 1 0 0 1 0 1 0 "}, {"input": "3 ...
false
stdio
import sys def read_ints(file): return list(map(int, file.read().split())) def main(input_path, output_path, submission_path): with open(input_path) as f: n, m = map(int, f.readline().split()) points = list(map(int, f.readline().split())) segments = [tuple(map(int, f.readline().split()...
true
430/A
430
A
Python 3
TESTS
2
46
0
6961224
n, m = map(int, input().split()) a = list(map(int, input().split())) for i in range(m): x, y = map(int, input().split()) for i in range(n): print(i % 2, end = ' ')
12
62
0
6612737
from operator import * R = lambda: map(int, input().split()) n, m = R() x = sorted(enumerate(R()), key=itemgetter(1)) y = [0] * n for i in range(n): y[x[i][0]] = i % 2 print(' '.join(map(str, y)))
Codeforces Round 245 (Div. 2)
CF
2,014
1
256
Points and Segments (easy)
Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One of them is the following. Iahub wants to draw n distinct points and m segme...
The first line of input contains two integers: n (1 ≤ n ≤ 100) and m (1 ≤ m ≤ 100). The next line contains n space-separated integers x1, x2, ..., xn (0 ≤ xi ≤ 100) — the coordinates of the points. The following m lines contain the descriptions of the m segments. Each line contains two integers li and ri (0 ≤ li ≤ ri ≤...
If there is no good drawing for a given test, output a single integer -1. Otherwise output n integers, each integer must be 0 or 1. The i-th number denotes the color of the i-th point (0 is red, and 1 is blue). If there are multiple good drawings you can output any of them.
null
null
[{"input": "3 3\n3 7 14\n1 5\n6 10\n11 15", "output": "0 0 0"}, {"input": "3 4\n1 2 3\n1 2\n2 3\n5 6\n2 2", "output": "1 0 1"}]
1,600
["constructive algorithms", "sortings"]
12
[{"input": "3 3\r\n3 7 14\r\n1 5\r\n6 10\r\n11 15\r\n", "output": "0 0 0"}, {"input": "3 4\r\n1 2 3\r\n1 2\r\n2 3\r\n5 6\r\n2 2\r\n", "output": "1 0 1 "}, {"input": "10 10\r\n3 4 2 6 1 9 0 5 8 7\r\n5 7\r\n2 6\r\n0 1\r\n5 6\r\n3 4\r\n2 5\r\n2 10\r\n4 6\r\n3 6\r\n3 7\r\n", "output": "0 1 1 1 0 0 1 0 1 0 "}, {"input": "3 ...
false
stdio
import sys def read_ints(file): return list(map(int, file.read().split())) def main(input_path, output_path, submission_path): with open(input_path) as f: n, m = map(int, f.readline().split()) points = list(map(int, f.readline().split())) segments = [tuple(map(int, f.readline().split()...
true
432/C
432
C
PyPy 3-64
TESTS
0
31
512,000
160994544
import sys from array import array def count_prime(n): prim[0] = prim[1] = 0 for i in range(2, n + 1): if prim[i]: for j in range(i * 2, n + 1, i): prim[j] = 0 input = lambda: sys.stdin.buffer.readline().decode().strip() n, a = int(input()), array('i', [int(x) - 1 for x i...
30
997
37,478,400
6630802
# from random import shuffle # f = open("out.txt", "w") # n = 1000 # test = list(range(1, n + 1)) # shuffle(test) # print(n, file=f) # print(' '.join(map(str, test)), file=f) from bisect import * from sys import stdin f = stdin # open("out.txt", "r") n = int(f.readline()) primes = [1] * (n + 1) primes[0] = 0 prime...
Codeforces Round 246 (Div. 2)
CF
2,014
2
256
Prime Swaps
You have an array a[1], a[2], ..., a[n], containing distinct integers from 1 to n. Your task is to sort this array in increasing order with the following operation (you may need to apply it multiple times): - choose two indexes, i and j (1 ≤ i < j ≤ n; (j - i + 1) is a prime number); - swap the elements on positions i...
The first line contains integer n (1 ≤ n ≤ 105). The next line contains n distinct integers a[1], a[2], ..., a[n] (1 ≤ a[i] ≤ n).
In the first line, print integer k (0 ≤ k ≤ 5n) — the number of used operations. Next, print the operations. Each operation must be printed as "i j" (1 ≤ i < j ≤ n; (j - i + 1) is a prime). If there are multiple answers, you can print any of them.
null
null
[{"input": "3\n3 2 1", "output": "1\n1 3"}, {"input": "2\n1 2", "output": "0"}, {"input": "4\n4 2 3 1", "output": "3\n2 4\n1 2\n2 4"}]
1,800
["greedy", "sortings"]
30
[{"input": "3\r\n3 2 1\r\n", "output": "1\r\n1 3\r\n"}, {"input": "2\r\n1 2\r\n", "output": "0\r\n"}, {"input": "4\r\n4 2 3 1\r\n", "output": "3\r\n2 4\r\n1 2\r\n2 4\r\n"}, {"input": "10\r\n10 9 8 7 6 5 4 3 2 1\r\n", "output": "15\r\n4 10\r\n2 4\r\n1 2\r\n3 9\r\n2 3\r\n4 8\r\n3 4\r\n5 7\r\n4 5\r\n5 6\r\n6 7\r\n8 10\r\n...
false
stdio
null
true
140/B
140
B
Python 3
TESTS
0
62
0
11600827
import sys from itertools import * from math import * def solve(): n = int(input()) tab = [list(map(int, input().split())) for _ in range(n)] alex = list(map(int, input().split())) willget = [[0]*n for _ in range(n)] has = list() for row in range(n): hasrow = list() for val in al...
17
186
4,710,400
220623198
import sys input = lambda: sys.stdin.readline().rstrip() from collections import deque,defaultdict,Counter from itertools import permutations,combinations from bisect import * from heapq import * from math import ceil,gcd,lcm,floor,comb alph = 'abcdefghijklmnopqrstuvwxyz' #pow(x,mod-2,mod) N = int(input()) A = [list(m...
Codeforces Round 100
CF
2,012
2
256
New Year Cards
As meticulous Gerald sets the table, Alexander finished another post on Codeforces and begins to respond to New Year greetings from friends. Alexander has n friends, and each of them sends to Alexander exactly one e-card. Let us number his friends by numbers from 1 to n in the order in which they send the cards. Let's ...
The first line contains an integer n (2 ≤ n ≤ 300) — the number of Alexander's friends, equal to the number of cards. Next n lines contain his friends' preference lists. Each list consists of n different integers from 1 to n. The last line contains Alexander's preference list in the same format.
Print n space-separated numbers: the i-th number should be the number of the friend, whose card Alexander receives right before he should send a card to the i-th friend. If there are several solutions, print any of them.
null
In the sample, the algorithm of actions Alexander and his friends perform is as follows: 1. Alexander receives card 1 from the first friend. 2. Alexander sends the card he has received (at the moment he only has one card, and therefore it is the most preferable for him) to friends with the numbers 2 and 3. 3. Alexande...
[{"input": "4\n1 2 3 4\n4 1 3 2\n4 3 1 2\n3 4 2 1\n3 1 2 4", "output": "2 1 1 4"}]
1,800
["brute force", "greedy", "implementation"]
17
[{"input": "4\r\n1 2 3 4\r\n4 1 3 2\r\n4 3 1 2\r\n3 4 2 1\r\n3 1 2 4\r\n", "output": "2 1 1 3\r\n"}, {"input": "2\r\n1 2\r\n2 1\r\n2 1\r\n", "output": "2 1\r\n"}, {"input": "3\r\n1 2 3\r\n2 3 1\r\n1 3 2\r\n3 2 1\r\n", "output": "2 3 1\r\n"}, {"input": "5\r\n1 4 2 3 5\r\n5 1 3 4 2\r\n3 2 4 1 5\r\n1 4 5 3 2\r\n5 2 3 4 1\...
false
stdio
null
true
140/B
140
B
PyPy 3
TESTS
4
280
0
82171629
n = int(input()) frnd = [list(map(int, input().split() )) for _ in range(n)] ara = list(map(int, input().split() )) pref = [0]*(n+1) ans = [0]*(n) for i in range(n): pref[ara[i]] = i+1 def better(ro, x, y): if x == ro: return y if y == ro: return x if pref[x] < pref[y]: return x return min(x, y) # pri...
17
248
4,300,800
166805289
n = int(input()) friends = [] friends_inverse = [] for _ in range(n): friend = list(map(int, input().split())) friends.append(friend) friends_inverse.append([friend.index(i + 1) for i in range(n)]) alex = list(map(int, input().split())) alex_inverse = [alex.index(i + 1) for i in range(n)] output = {k: -1...
Codeforces Round 100
CF
2,012
2
256
New Year Cards
As meticulous Gerald sets the table, Alexander finished another post on Codeforces and begins to respond to New Year greetings from friends. Alexander has n friends, and each of them sends to Alexander exactly one e-card. Let us number his friends by numbers from 1 to n in the order in which they send the cards. Let's ...
The first line contains an integer n (2 ≤ n ≤ 300) — the number of Alexander's friends, equal to the number of cards. Next n lines contain his friends' preference lists. Each list consists of n different integers from 1 to n. The last line contains Alexander's preference list in the same format.
Print n space-separated numbers: the i-th number should be the number of the friend, whose card Alexander receives right before he should send a card to the i-th friend. If there are several solutions, print any of them.
null
In the sample, the algorithm of actions Alexander and his friends perform is as follows: 1. Alexander receives card 1 from the first friend. 2. Alexander sends the card he has received (at the moment he only has one card, and therefore it is the most preferable for him) to friends with the numbers 2 and 3. 3. Alexande...
[{"input": "4\n1 2 3 4\n4 1 3 2\n4 3 1 2\n3 4 2 1\n3 1 2 4", "output": "2 1 1 4"}]
1,800
["brute force", "greedy", "implementation"]
17
[{"input": "4\r\n1 2 3 4\r\n4 1 3 2\r\n4 3 1 2\r\n3 4 2 1\r\n3 1 2 4\r\n", "output": "2 1 1 3\r\n"}, {"input": "2\r\n1 2\r\n2 1\r\n2 1\r\n", "output": "2 1\r\n"}, {"input": "3\r\n1 2 3\r\n2 3 1\r\n1 3 2\r\n3 2 1\r\n", "output": "2 3 1\r\n"}, {"input": "5\r\n1 4 2 3 5\r\n5 1 3 4 2\r\n3 2 4 1 5\r\n1 4 5 3 2\r\n5 2 3 4 1\...
false
stdio
null
true
908/F
908
F
Python 3
PRETESTS
3
46
5,529,600
33788830
n=int(input()) ar=[input().split() for x in range(n)] G,R,B=[],[],[] for x in ar: if x[1]=='G':G.append(int(x[0])) elif x[1]=='R':R.append(int(x[0])) elif x[1]=='B':B.append(int(x[0])) sum=0 for i in range(len(G)-1): x1,x2=G[i],G[i+1] while R and R[0] < x1: sum+=abs(R[0]-x1) del R[0]...
44
842
83,660,800
33823019
import sys n = int(input()) pos = [] ind = 0 inp = [s for line in sys.stdin.readlines() for s in line.split()] color = [] costs = 0 reds = [] greens = [] blues = [] for i in range(n): a,b = inp[ind],inp[ind+1] ind+=2 pos.append(int(a)) color.append(b) if b=='R': reds.append(i) elif b=...
Good Bye 2017
CF
2,017
2
256
New Year and Rainbow Roads
Roy and Biv have a set of n points on the infinite number line. Each point has one of 3 colors: red, green, or blue. Roy and Biv would like to connect all the points with some edges. Edges can be drawn between any of the two of the given points. The cost of an edge is equal to the distance between the two points it c...
The first line will contain an integer n (1 ≤ n ≤ 300 000), the number of points. The next n lines will contain two tokens pi and ci (pi is an integer, 1 ≤ pi ≤ 109, ci is a uppercase English letter 'R', 'G' or 'B'), denoting the position of the i-th point and the color of the i-th point. 'R' means red, 'G' denotes gr...
Print a single integer, the minimum cost way to solve the problem.
null
In the first sample, it is optimal to draw edges between the points (1,2), (1,4), (3,4). These have costs 4, 14, 5, respectively.
[{"input": "4\n1 G\n5 R\n10 B\n15 G", "output": "23"}, {"input": "4\n1 G\n2 R\n3 B\n10 G", "output": "12"}]
2,400
["graphs", "greedy", "implementation"]
44
[{"input": "4\r\n1 G\r\n5 R\r\n10 B\r\n15 G\r\n", "output": "23\r\n"}, {"input": "4\r\n1 G\r\n2 R\r\n3 B\r\n10 G\r\n", "output": "12\r\n"}, {"input": "4\r\n1 G\r\n123123 R\r\n987987987 B\r\n1000000000 G\r\n", "output": "1012135134\r\n"}, {"input": "1\r\n3 R\r\n", "output": "0\r\n"}]
false
stdio
null
true
898/C
898
C
PyPy 3
TESTS
4
124
20,172,800
80229575
# itne me hi thakk gaye? n = int(input()) phone_book = {} for i in range(n): inp = input().split() name = inp[0] count = int(inp[1]) phs = [i for i in inp[2:]] if name in phone_book: v, inp_arr = phone_book[name] else: v, inp_arr = set(), [] for phonenumber in phs: if phonenumber in v: pass else: ...
59
62
5,529,600
33297607
n = int(input()) p = {} o = {} for i in range(n): e = input().split() if not e[0] in p: p[e[0]] = [] for x in e[2:]: p[e[0]].append((len(x), x[::-1])) for i in p: for x in sorted(p[i])[::-1]: f = False if not i in o: o[i] = [] for z in o[i]: ...
Codeforces Round 451 (Div. 2)
CF
2,017
2
256
Phone Numbers
Vasya has several phone books, in which he recorded the telephone numbers of his friends. Each of his friends can have one or several phone numbers. Vasya decided to organize information about the phone numbers of friends. You will be given n strings — all entries from Vasya's phone books. Each entry starts with a fri...
First line contains the integer n (1 ≤ n ≤ 20) — number of entries in Vasya's phone books. The following n lines are followed by descriptions of the records in the format described in statement. Names of Vasya's friends are non-empty strings whose length does not exceed 10. They consists only of lowercase English lett...
Print out the ordered information about the phone numbers of Vasya's friends. First output m — number of friends that are found in Vasya's phone books. The following m lines must contain entries in the following format "name number_of_phone_numbers phone_numbers". Phone numbers should be separated by a space. Each rec...
null
null
[{"input": "2\nivan 1 00123\nmasha 1 00123", "output": "2\nmasha 1 00123\nivan 1 00123"}, {"input": "3\nkarl 2 612 12\npetr 1 12\nkatya 1 612", "output": "3\nkatya 1 612\npetr 1 12\nkarl 1 612"}, {"input": "4\nivan 3 123 123 456\nivan 2 456 456\nivan 8 789 3 23 6 56 9 89 2\ndasha 2 23 789", "output": "2\ndasha 2 23 789...
1,400
["implementation", "strings"]
59
[{"input": "2\r\nivan 1 00123\r\nmasha 1 00123\r\n", "output": "2\r\nmasha 1 00123 \r\nivan 1 00123 \r\n"}, {"input": "3\r\nkarl 2 612 12\r\npetr 1 12\r\nkatya 1 612\r\n", "output": "3\r\nkatya 1 612 \r\npetr 1 12 \r\nkarl 1 612 \r\n"}, {"input": "4\r\nivan 3 123 123 456\r\nivan 2 456 456\r\nivan 8 789 3 23 6 56 9 89 2...
false
stdio
import sys from collections import defaultdict def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read input and build friends data friends = defaultdict(set) with open(input_path, 'r') as f: n = int(f.readline()) for _ in range(n): ...
true
617/C
617
C
PyPy 3
TESTS
3
77
0
228381968
import math import sys #input = sys.stdin.readline USE_FILE = False def calc_distance(x1, y1, x2, y2): return (x1 - x2) ** 2 + (y1 - y2) ** 2 def main(): n, x1, y1, x2, y2 = [int(i) for i in input().split()] points = [] d = [] for i in range(n): x, y = tuple(map(int, input().split())) ...
31
93
512,000
15525144
import math n, x1, y1, x2, y2 = [int(x) for x in input().split()] points = [] for i in range(n): points.append(tuple(int(x) for x in input().split())) d = lambda p1, p2: (p1[0] - p2[0])**2 + (p1[1] - p2[1])**2 first = (x1, y1) second = (x2, y2) distances = [(d(first, point), d(second, point)) for point in points] d...
Codeforces Round 340 (Div. 2)
CF
2,016
2
256
Watering Flowers
A flowerbed has many flowers and two fountains. You can adjust the water pressure and set any values r1(r1 ≥ 0) and r2(r2 ≥ 0), giving the distances at which the water is spread from the first and second fountain respectively. You have to set such r1 and r2 that all the flowers are watered, that is, for each flower, t...
The first line of the input contains integers n, x1, y1, x2, y2 (1 ≤ n ≤ 2000, - 107 ≤ x1, y1, x2, y2 ≤ 107) — the number of flowers, the coordinates of the first and the second fountain. Next follow n lines. The i-th of these lines contains integers xi and yi ( - 107 ≤ xi, yi ≤ 107) — the coordinates of the i-th flo...
Print the minimum possible value r12 + r22. Note, that in this problem optimal answer is always integer.
null
The first sample is (r12 = 5, r22 = 1): The second sample is (r12 = 1, r22 = 32):
[{"input": "2 -1 0 5 3\n0 2\n5 2", "output": "6"}, {"input": "4 0 0 5 0\n9 4\n8 3\n-1 0\n1 4", "output": "33"}]
1,600
["implementation"]
31
[{"input": "2 -1 0 5 3\r\n0 2\r\n5 2\r\n", "output": "6\r\n"}, {"input": "4 0 0 5 0\r\n9 4\r\n8 3\r\n-1 0\r\n1 4\r\n", "output": "33\r\n"}, {"input": "5 -6 -4 0 10\r\n-7 6\r\n-9 7\r\n-5 -1\r\n-2 1\r\n-8 10\r\n", "output": "100\r\n"}, {"input": "10 -68 10 87 22\r\n30 89\r\n82 -97\r\n-52 25\r\n76 -22\r\n-20 95\r\n21 25\r...
false
stdio
null
true
908/F
908
F
PyPy 3-64
TESTS
12
1,964
87,347,200
203971619
def calculate_minimum_cost(n, points): total_cost = 0 partial_cost = 0 max_red = max_blue = 0 last_red = last_blue = last_green = -1 for i in range(n): pos, color = points[i] if color in ('R', 'G'): if last_red != -1: max_red = max(max_red, p...
44
1,107
204,800
113280821
#collaborated with Prasoon Shakya n = int(input()) R,G,B=0,0,0 maxR,maxG,maxB=0,0,0 Cost = 0 for i in range(n): temp_input = input().split(" ") value = int(temp_input[0]) choice=temp_input[1] if choice == "R" or choice == "G": if R: Cost += value - R ma...
Good Bye 2017
CF
2,017
2
256
New Year and Rainbow Roads
Roy and Biv have a set of n points on the infinite number line. Each point has one of 3 colors: red, green, or blue. Roy and Biv would like to connect all the points with some edges. Edges can be drawn between any of the two of the given points. The cost of an edge is equal to the distance between the two points it c...
The first line will contain an integer n (1 ≤ n ≤ 300 000), the number of points. The next n lines will contain two tokens pi and ci (pi is an integer, 1 ≤ pi ≤ 109, ci is a uppercase English letter 'R', 'G' or 'B'), denoting the position of the i-th point and the color of the i-th point. 'R' means red, 'G' denotes gr...
Print a single integer, the minimum cost way to solve the problem.
null
In the first sample, it is optimal to draw edges between the points (1,2), (1,4), (3,4). These have costs 4, 14, 5, respectively.
[{"input": "4\n1 G\n5 R\n10 B\n15 G", "output": "23"}, {"input": "4\n1 G\n2 R\n3 B\n10 G", "output": "12"}]
2,400
["graphs", "greedy", "implementation"]
44
[{"input": "4\r\n1 G\r\n5 R\r\n10 B\r\n15 G\r\n", "output": "23\r\n"}, {"input": "4\r\n1 G\r\n2 R\r\n3 B\r\n10 G\r\n", "output": "12\r\n"}, {"input": "4\r\n1 G\r\n123123 R\r\n987987987 B\r\n1000000000 G\r\n", "output": "1012135134\r\n"}, {"input": "1\r\n3 R\r\n", "output": "0\r\n"}]
false
stdio
null
true
1006/D
1006
D
PyPy 3
TESTS
2
155
23,654,400
122371601
for _ in range(1): n=int(input()) st=input() rt=input() l=len(st) i=0 j=l-1 count=0 while i <=j: if i==j: count =count +0 if st[i] ==rt[j] else count +1 elif st[i] ==rt[i] and st[j] ==rt[j]: count +=0 elif st[i] ==rt[j] and rt[i] ==st[j]: ...
23
61
614,400
204964848
n=int(input()) a,b=input(),input() k=n//2 c=a[k]!=b[k]and n%2 for z,w,x,y in zip(a[:k],a[::-1],b,b[::-1]):c+=z!=w if x==y else len({x,y}-{z,w}) print(c)
Codeforces Round 498 (Div. 3)
ICPC
2,018
2
256
Two Strings Swaps
You are given two strings $$$a$$$ and $$$b$$$ consisting of lowercase English letters, both of length $$$n$$$. The characters of both strings have indices from $$$1$$$ to $$$n$$$, inclusive. You are allowed to do the following changes: - Choose any index $$$i$$$ ($$$1 \le i \le n$$$) and swap characters $$$a_i$$$ and...
The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of strings $$$a$$$ and $$$b$$$. The second line contains the string $$$a$$$ consisting of exactly $$$n$$$ lowercase English letters. The third line contains the string $$$b$$$ consisting of exactly $$$n$$$ lowercase English...
Print a single integer — the minimum number of preprocess moves to apply before changes, so that it is possible to make the string $$$a$$$ equal to string $$$b$$$ with a sequence of changes from the list above.
null
In the first example preprocess moves are as follows: $$$a_1 := $$$'b', $$$a_3 := $$$'c', $$$a_4 := $$$'a' and $$$a_5:=$$$'b'. Afterwards, $$$a = $$$"bbcabba". Then we can obtain equal strings by the following sequence of changes: $$$swap(a_2, b_2)$$$ and $$$swap(a_2, a_6)$$$. There is no way to use fewer than $$$4$$$ ...
[{"input": "7\nabacaba\nbacabaa", "output": "4"}, {"input": "5\nzcabd\ndbacz", "output": "0"}]
1,700
["implementation"]
23
[{"input": "7\r\nabacaba\r\nbacabaa\r\n", "output": "4\r\n"}, {"input": "5\r\nzcabd\r\ndbacz\r\n", "output": "0\r\n"}, {"input": "1\r\na\r\nb\r\n", "output": "1\r\n"}, {"input": "5\r\nahmad\r\nyogaa\r\n", "output": "3\r\n"}]
false
stdio
null
true
1006/D
1006
D
Python 3
TESTS
2
171
819,200
105080961
n= int(input()) a=input() b=input() ans=0 if n%2==0: i2=n//2 else: i2=n//2+1 for i in range(i2): if i==i2-1: if n%2!=0: if a[i]!=b[i]: ans+=1 #print('a') else: if a[i]==a[n-i-1] or b[i]==b[n-i-1]: if not (a[i]==b[i] and ...
23
77
409,600
197554073
n=int(input()) a,b=input(),input() k=n//2 c=a[k]!=b[k]and n%2 for u,v,x,y in zip(a[:k],a[::-1],b,b[::-1]):c+=(len({x,y}-{u,v}),u!=v)[x==y] print(c)
Codeforces Round 498 (Div. 3)
ICPC
2,018
2
256
Two Strings Swaps
You are given two strings $$$a$$$ and $$$b$$$ consisting of lowercase English letters, both of length $$$n$$$. The characters of both strings have indices from $$$1$$$ to $$$n$$$, inclusive. You are allowed to do the following changes: - Choose any index $$$i$$$ ($$$1 \le i \le n$$$) and swap characters $$$a_i$$$ and...
The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of strings $$$a$$$ and $$$b$$$. The second line contains the string $$$a$$$ consisting of exactly $$$n$$$ lowercase English letters. The third line contains the string $$$b$$$ consisting of exactly $$$n$$$ lowercase English...
Print a single integer — the minimum number of preprocess moves to apply before changes, so that it is possible to make the string $$$a$$$ equal to string $$$b$$$ with a sequence of changes from the list above.
null
In the first example preprocess moves are as follows: $$$a_1 := $$$'b', $$$a_3 := $$$'c', $$$a_4 := $$$'a' and $$$a_5:=$$$'b'. Afterwards, $$$a = $$$"bbcabba". Then we can obtain equal strings by the following sequence of changes: $$$swap(a_2, b_2)$$$ and $$$swap(a_2, a_6)$$$. There is no way to use fewer than $$$4$$$ ...
[{"input": "7\nabacaba\nbacabaa", "output": "4"}, {"input": "5\nzcabd\ndbacz", "output": "0"}]
1,700
["implementation"]
23
[{"input": "7\r\nabacaba\r\nbacabaa\r\n", "output": "4\r\n"}, {"input": "5\r\nzcabd\r\ndbacz\r\n", "output": "0\r\n"}, {"input": "1\r\na\r\nb\r\n", "output": "1\r\n"}, {"input": "5\r\nahmad\r\nyogaa\r\n", "output": "3\r\n"}]
false
stdio
null
true
1006/D
1006
D
PyPy 3
TESTS
2
171
28,364,800
86324973
n = int(input()) a = list(input()) b = list(input()) ans=0 for i in range(n//2): # print(i,n-i-1,a,b) l1 = [a[i],a[n-i-1]] l2 = [b[i],b[n-i-1]] # print(set(l1+l2)) if len(set(l1+l2))==4: ans+=2 elif len(set(l1+l2))==3: if l1[0]==l1[1]: ans+=2 elif l1[0]==l2[0] o...
23
77
512,000
214462893
n=int(input()) a=input() b=input() ans=0 if n%2!=0: if a[n//2]!=b[n//2]: ans+=1 for i in range(n//2): if b[i]==b[n-1-i]: if a[i]!=a[n-1-i]: ans+=1 continue if b[i]!=a[i] and b[i]!=a[n-1-i]: ans+=1 if b[n-1-i]!=a[i] and b[n-1-i]!=a[n-1-i]: ans+=1 print(...
Codeforces Round 498 (Div. 3)
ICPC
2,018
2
256
Two Strings Swaps
You are given two strings $$$a$$$ and $$$b$$$ consisting of lowercase English letters, both of length $$$n$$$. The characters of both strings have indices from $$$1$$$ to $$$n$$$, inclusive. You are allowed to do the following changes: - Choose any index $$$i$$$ ($$$1 \le i \le n$$$) and swap characters $$$a_i$$$ and...
The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of strings $$$a$$$ and $$$b$$$. The second line contains the string $$$a$$$ consisting of exactly $$$n$$$ lowercase English letters. The third line contains the string $$$b$$$ consisting of exactly $$$n$$$ lowercase English...
Print a single integer — the minimum number of preprocess moves to apply before changes, so that it is possible to make the string $$$a$$$ equal to string $$$b$$$ with a sequence of changes from the list above.
null
In the first example preprocess moves are as follows: $$$a_1 := $$$'b', $$$a_3 := $$$'c', $$$a_4 := $$$'a' and $$$a_5:=$$$'b'. Afterwards, $$$a = $$$"bbcabba". Then we can obtain equal strings by the following sequence of changes: $$$swap(a_2, b_2)$$$ and $$$swap(a_2, a_6)$$$. There is no way to use fewer than $$$4$$$ ...
[{"input": "7\nabacaba\nbacabaa", "output": "4"}, {"input": "5\nzcabd\ndbacz", "output": "0"}]
1,700
["implementation"]
23
[{"input": "7\r\nabacaba\r\nbacabaa\r\n", "output": "4\r\n"}, {"input": "5\r\nzcabd\r\ndbacz\r\n", "output": "0\r\n"}, {"input": "1\r\na\r\nb\r\n", "output": "1\r\n"}, {"input": "5\r\nahmad\r\nyogaa\r\n", "output": "3\r\n"}]
false
stdio
null
true
1006/D
1006
D
Python 3
TESTS
2
187
716,800
105091812
n= int(input()) a=input() b=input() ans=0 if n%2==0: i2=n//2 else: i2=n//2+1 for i in range(i2): if i==i2-1: if n%2!=0: if a[i]!=b[i]: ans+=1 else: ans1=0 s1=[a[i],a[n-i-1],b[i],b[n-i-1]] d=dict() for j in s1: ...
23
77
2,867,200
178717549
n=int(input()) a=input() b=input() ans=0 if n%2==0: for i in range(n//2): temp=len(set([a[i],b[i],a[n-1-i],b[n-1-i]])) if temp==4 or (temp==3 and a[i]==a[n-1-i]): ans+=2 elif temp==3: ans+=1 elif temp==2 and [a[i],b[i],a[n-1-i],b[n-1-i]].count(a[i])!=2: ...
Codeforces Round 498 (Div. 3)
ICPC
2,018
2
256
Two Strings Swaps
You are given two strings $$$a$$$ and $$$b$$$ consisting of lowercase English letters, both of length $$$n$$$. The characters of both strings have indices from $$$1$$$ to $$$n$$$, inclusive. You are allowed to do the following changes: - Choose any index $$$i$$$ ($$$1 \le i \le n$$$) and swap characters $$$a_i$$$ and...
The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of strings $$$a$$$ and $$$b$$$. The second line contains the string $$$a$$$ consisting of exactly $$$n$$$ lowercase English letters. The third line contains the string $$$b$$$ consisting of exactly $$$n$$$ lowercase English...
Print a single integer — the minimum number of preprocess moves to apply before changes, so that it is possible to make the string $$$a$$$ equal to string $$$b$$$ with a sequence of changes from the list above.
null
In the first example preprocess moves are as follows: $$$a_1 := $$$'b', $$$a_3 := $$$'c', $$$a_4 := $$$'a' and $$$a_5:=$$$'b'. Afterwards, $$$a = $$$"bbcabba". Then we can obtain equal strings by the following sequence of changes: $$$swap(a_2, b_2)$$$ and $$$swap(a_2, a_6)$$$. There is no way to use fewer than $$$4$$$ ...
[{"input": "7\nabacaba\nbacabaa", "output": "4"}, {"input": "5\nzcabd\ndbacz", "output": "0"}]
1,700
["implementation"]
23
[{"input": "7\r\nabacaba\r\nbacabaa\r\n", "output": "4\r\n"}, {"input": "5\r\nzcabd\r\ndbacz\r\n", "output": "0\r\n"}, {"input": "1\r\na\r\nb\r\n", "output": "1\r\n"}, {"input": "5\r\nahmad\r\nyogaa\r\n", "output": "3\r\n"}]
false
stdio
null
true
267/A
267
A
Python 3
TESTS
5
62
307,200
103888044
n = int(input()) otv = 0 for i in range(n): a, b = map(int, input().split()) while (a > 0) and (b > 0): if abs(a - b) > 1000: otv = max(a,b) // min(a,b) if a > b: a = max(a,b) % min(a,b) else: b = max(a,b) % min(a,b) else: ...
35
46
0
149466395
t = int(input()) while t > 0: t-=1 counter = int(0) a, b = map(int, input().split()) while a != 0 and b != 0 : if(a < b): a, b = b, a counter += (a // b) a %= b print(counter)
Codeforces Testing Round 5
CF
2,013
1
256
Subtractions
You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) to pair (4,13), it transforms (5,5) to (0,5). You've got some num...
The first line contains the number of pairs n (1 ≤ n ≤ 1000). Then follow n lines, each line contains a pair of positive integers ai, bi (1 ≤ ai, bi ≤ 109).
Print the sought number of operations for each pair on a single line.
null
null
[{"input": "2\n4 17\n7 987654321", "output": "8\n141093479"}]
900
["math", "number theory"]
35
[{"input": "2\r\n4 17\r\n7 987654321\r\n", "output": "8\r\n141093479\r\n"}, {"input": "10\r\n7 987654321\r\n7 987654321\r\n7 987654321\r\n7 987654321\r\n7 987654321\r\n7 987654321\r\n7 987654321\r\n7 987654321\r\n7 987654321\r\n7 987654321\r\n", "output": "141093479\r\n141093479\r\n141093479\r\n141093479\r\n141093479\r...
false
stdio
null
true
847/K
847
K
Python 3
TESTS
0
15
0
206245698
n, a, b, k, f = map(int, input().split()) stops = {} total_cost = 0 for _ in range(n): start_stop, finish_stop = input().split() if start_stop != finish_stop: stops[(start_stop, finish_stop)] = stops.get((start_stop, finish_stop), 0) + 1 total_cost += a else: total_cost += b sorted...
55
92
0
150973369
n,a,b,k,f = map(int,input().split()) poezd = {} sum = 0 prev = "" for i in range(n): ost =ost_key= input() ost_arr = ost.split() if ost not in poezd.keys(): if ost_arr[1]+" "+ost_arr[0] in poezd.keys(): ost_key = ost_arr[1]+" "+ost_arr[0] else: poezd[ost_key] = {"a":0...
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
172/C
172
C
Python 3
TESTS
0
30
0
155527034
def solution_task3(): data = input().split(" ") n = int(data[0]) m = int(data[1]) students = {} for i in range(n): data = input().split(" ") students[int(data[0])] = int(data[1]) total_time = 0 bus = [] result_dict = {} for key, value in students.items(): bus...
66
857
5,120,000
193001159
n,m=map(int,input().split()) ti=[] xi=[] for _ in range(n): t,x=map(int,input().split()) ti.append(t) xi.append(x) t=0 for k in range(0,n,m): maxt=max(ti[min(n,k+m)-1],t) dicti={} for j in range(k,min(n,k+m)): dicti[xi[j]]=dicti.get(xi[j],0)+1 dicti=dict(sorted(dicti.items())) t=...
Croc Champ 2012 - Qualification Round
CF
2,012
1
256
Bus
There is a bus stop near the university. The lessons are over, and n students come to the stop. The i-th student will appear at the bus stop at time ti (all ti's are distinct). We shall assume that the stop is located on the coordinate axis Ox, at point x = 0, and the bus goes along the ray Ox, that is, towards the po...
The first line contains two space-separated integers n, m (1 ≤ n, m ≤ 105) — the number of students and the number of passengers the bus can transport, correspondingly. Next n lines contain descriptions of the students, one per line. Each line contains a pair of integers ti, xi (1 ≤ ti ≤ 105, 1 ≤ xi ≤ 104). The lines a...
Print n numbers w1, w2, ..., wn, wi — the moment of time when the i-th student got off the bus. Print the numbers on one line and separate them with single spaces.
null
In the first sample the bus waits for the first student for 3 units of time and drives him to his destination in additional 5 units of time. So the student leaves the bus at the moment of time 3 + 5 = 8. In the second sample the capacity of the bus equals 1, that's why it will drive the first student alone. This stude...
[{"input": "1 10\n3 5", "output": "8"}, {"input": "2 1\n3 5\n4 5", "output": "8 19"}, {"input": "5 4\n3 5\n4 5\n5 5\n6 5\n7 1", "output": "11 11 11 11 20"}, {"input": "20 4\n28 13\n31 13\n35 6\n36 4\n52 6\n53 4\n83 2\n84 4\n87 1\n93 6\n108 4\n113 6\n116 1\n125 2\n130 2\n136 13\n162 2\n166 4\n184 1\n192 2", "output": "5...
1,500
["*special", "implementation", "sortings"]
66
[{"input": "1 10\r\n3 5\r\n", "output": "8\r\n"}, {"input": "2 1\r\n3 5\r\n4 5\r\n", "output": "8 19\r\n"}, {"input": "5 4\r\n3 5\r\n4 5\r\n5 5\r\n6 5\r\n7 1\r\n", "output": "11 11 11 11 20\r\n"}, {"input": "20 4\r\n28 13\r\n31 13\r\n35 6\r\n36 4\r\n52 6\r\n53 4\r\n83 2\r\n84 4\r\n87 1\r\n93 6\r\n108 4\r\n113 6\r\n116 ...
false
stdio
null
true
401/B
401
B
PyPy 3-64
TESTS
0
30
512,000
145737187
import math def main_function(): x, k = [int(u) for u in input().split(" ")] x -= 1 dif = x - k hashy = [0 for i in range(x + 1)] for i in range(k): l = [int(j) for j in input().split(" ")] print(hashy) print(l) if ...
47
77
0
5984004
#!/usr/bin/env python3 def main(): x, t = map(int, input().split()) markers = [1] * (x - 1) for c in range(t): r = [int(n) for n in input().split()] markers[r[1] - 1] = 0 if r[0] == 1: markers[r[2] - 1] = 0 c = 0 max_num = 0 min_num = 0 for i in markers:...
Codeforces Round 235 (Div. 2)
CF
2,014
1
256
Sereja and Contests
Sereja is a coder and he likes to take part in Codesorfes rounds. However, Uzhland doesn't have good internet connection, so Sereja sometimes skips rounds. Codesorfes has rounds of two types: Div1 (for advanced coders) and Div2 (for beginner coders). Two rounds, Div1 and Div2, can go simultaneously, (Div1 round cannot...
The first line contains two integers: x (1 ≤ x ≤ 4000) — the round Sereja is taking part in today, and k (0 ≤ k < 4000) — the number of rounds he took part in. Next k lines contain the descriptions of the rounds that Sereja took part in before. If Sereja took part in one of two simultaneous rounds, the corresponding l...
Print in a single line two integers — the minimum and the maximum number of rounds that Sereja could have missed.
null
In the second sample we have unused identifiers of rounds 1, 6, 7. The minimum number of rounds Sereja could have missed equals to 2. In this case, the round with the identifier 1 will be a usual Div2 round and the round with identifier 6 will be synchronous with the Div1 round. The maximum number of rounds equals 3. ...
[{"input": "3 2\n2 1\n2 2", "output": "0 0"}, {"input": "9 3\n1 2 3\n2 8\n1 4 5", "output": "2 3"}, {"input": "10 0", "output": "5 9"}]
1,200
["greedy", "implementation", "math"]
47
[{"input": "3 2\r\n2 1\r\n2 2\r\n", "output": "0 0"}, {"input": "9 3\r\n1 2 3\r\n2 8\r\n1 4 5\r\n", "output": "2 3"}, {"input": "10 0\r\n", "output": "5 9"}, {"input": "10 2\r\n1 1 2\r\n1 8 9\r\n", "output": "3 5"}, {"input": "9 3\r\n1 4 5\r\n1 1 2\r\n1 6 7\r\n", "output": "2 2"}, {"input": "7 2\r\n2 3\r\n1 5 6\r\n", "...
false
stdio
null
true
401/B
401
B
Python 3
TESTS
0
109
204,800
89823657
x,k=list(map(int,input().split())) r=[0] for i in range(k): l=list(map(int,input().split())) for i in l[1:]: r.append(i) r.sort() f=[] j=0 for i in range(1,x): if i==r[j]: j=j+1 if j+1<=len(r)-1 else j else: f.append(i) m1,m2=0,len(f) i=0 while i<len(f): if i+1<=len(f)-1 and ...
47
77
102,400
5980805
#!/usr/bin/python -SOO x,n = map(int,input().strip().split()) s = set(range(1,x)) for _ in range(n): xs = list(map(int,input().strip().split())) if xs[0] == 2: s.remove(xs[1]) else: s.remove(xs[1]) s.remove(xs[2]) m,i= 0,0 s = sorted(s) while i < len(s): if i==len(s)-1: m...
Codeforces Round 235 (Div. 2)
CF
2,014
1
256
Sereja and Contests
Sereja is a coder and he likes to take part in Codesorfes rounds. However, Uzhland doesn't have good internet connection, so Sereja sometimes skips rounds. Codesorfes has rounds of two types: Div1 (for advanced coders) and Div2 (for beginner coders). Two rounds, Div1 and Div2, can go simultaneously, (Div1 round cannot...
The first line contains two integers: x (1 ≤ x ≤ 4000) — the round Sereja is taking part in today, and k (0 ≤ k < 4000) — the number of rounds he took part in. Next k lines contain the descriptions of the rounds that Sereja took part in before. If Sereja took part in one of two simultaneous rounds, the corresponding l...
Print in a single line two integers — the minimum and the maximum number of rounds that Sereja could have missed.
null
In the second sample we have unused identifiers of rounds 1, 6, 7. The minimum number of rounds Sereja could have missed equals to 2. In this case, the round with the identifier 1 will be a usual Div2 round and the round with identifier 6 will be synchronous with the Div1 round. The maximum number of rounds equals 3. ...
[{"input": "3 2\n2 1\n2 2", "output": "0 0"}, {"input": "9 3\n1 2 3\n2 8\n1 4 5", "output": "2 3"}, {"input": "10 0", "output": "5 9"}]
1,200
["greedy", "implementation", "math"]
47
[{"input": "3 2\r\n2 1\r\n2 2\r\n", "output": "0 0"}, {"input": "9 3\r\n1 2 3\r\n2 8\r\n1 4 5\r\n", "output": "2 3"}, {"input": "10 0\r\n", "output": "5 9"}, {"input": "10 2\r\n1 1 2\r\n1 8 9\r\n", "output": "3 5"}, {"input": "9 3\r\n1 4 5\r\n1 1 2\r\n1 6 7\r\n", "output": "2 2"}, {"input": "7 2\r\n2 3\r\n1 5 6\r\n", "...
false
stdio
null
true
723/D
723
D
PyPy 3-64
TESTS
2
62
0
211993901
import sys input = lambda: sys.stdin.readline().rstrip() from collections import deque,defaultdict,Counter from itertools import permutations,combinations from bisect import * from heapq import * from math import ceil,gcd,lcm,floor,comb #pow(x,mod-2,mod) def check(N,M,x,y): global vis,P if 0<x<M-1 and 0<y<N-1 a...
26
77
716,800
21172235
def find_neigh(t,x,y): return [(i,j) for (i,j) in [(x-1,y),(x+1,y),(x,y-1),(x,y+1),(x,y+1)] if t[i][j]=='.'] def lake(table): return [(i,j) for i in range(0,len(table)-1) for j in range(0, len(table[i])-1) if table[i][j] == '.'] stack=set() def the_lake(tabl...
Codeforces Round 375 (Div. 2)
CF
2,016
2
256
Lakes in Berland
The map of Berland is a rectangle of the size n × m, which consists of cells of size 1 × 1. Each cell is either land or water. The map is surrounded by the ocean. Lakes are the maximal regions of water cells, connected by sides, which are not connected with the ocean. Formally, lake is a set of water cells, such that ...
The first line of the input contains three integers n, m and k (1 ≤ n, m ≤ 50, 0 ≤ k ≤ 50) — the sizes of the map and the number of lakes which should be left on the map. The next n lines contain m characters each — the description of the map. Each of the characters is either '.' (it means that the corresponding cell ...
In the first line print the minimum number of cells which should be transformed from water to land. In the next n lines print m symbols — the map after the changes. The format must strictly follow the format of the map in the input data (there is no need to print the size of the map). If there are several answers, pri...
null
In the first example there are only two lakes — the first consists of the cells (2, 2) and (2, 3), the second consists of the cell (4, 3). It is profitable to cover the second lake because it is smaller. Pay attention that the area of water in the lower left corner is not a lake because this area share a border with th...
[{"input": "5 4 1\n****\n*..*\n****\n**.*\n..**", "output": "1\n****\n*..*\n****\n****\n..**"}, {"input": "3 3 0\n***\n*.*\n***", "output": "1\n***\n***\n***"}]
1,600
["dfs and similar", "dsu", "graphs", "greedy", "implementation"]
26
[{"input": "5 4 1\r\n****\r\n*..*\r\n****\r\n**.*\r\n..**\r\n", "output": "1\r\n****\r\n*..*\r\n****\r\n****\r\n..**\r\n"}, {"input": "3 3 0\r\n***\r\n*.*\r\n***\r\n", "output": "1\r\n***\r\n***\r\n***\r\n"}, {"input": "3 5 1\r\n.**.*\r\n*.*.*\r\n***..\r\n", "output": "0\r\n.**.*\r\n*.*.*\r\n***..\r\n"}, {"input": "3 5...
false
stdio
import sys from sys import argv def main(): input_path = argv[1] output_path = argv[2] submission_path = argv[3] with open(input_path, 'r') as f: input_lines = f.read().splitlines() n, m, k = map(int, input_lines[0].split()) original_map = input_lines[1:n+1] with open(output_path,...
true
722/F
722
F
PyPy 3-64
TESTS
3
108
4,096,000
218252901
from io import BytesIO, IOBase 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, heappu...
73
1,575
43,315,200
189445525
import sys, random input = lambda : sys.stdin.readline().rstrip() write = lambda x: sys.stdout.write(x+"\n"); writef = lambda x: print("{:.12f}".format(x)) debug = lambda x: sys.stderr.write(x+"\n") YES="Yes"; NO="No"; pans = lambda v: print(YES if v else NO); INF=10**18 LI = lambda : list(map(int, input().split()));...
Intel Code Challenge Elimination Round (Div. 1 + Div. 2, combined)
CF
2,016
2
256
Cyclic Cipher
You are given n sequences. Each sequence consists of positive integers, not exceeding m. All integers in one sequence are distinct, but the same integer may appear in multiple sequences. The length of the i-th sequence is ki. Each second integers in each of the sequences are shifted by one to the left, i.e. integers a...
The first line of the input contains two integers n and m (1 ≤ n, m ≤ 100 000) — the number of sequences and the maximum integer that can appear in the sequences. Then follow n lines providing the sequences. Each of them starts with an integer ki (1 ≤ ki ≤ 40) — the number of integers in the sequence, proceeded by ki ...
Print m integers, the i-th of them should be equal to the length of the longest segment of the array with all its values equal to i during the first 10100 seconds.
null
null
[{"input": "3 4\n3 3 4 1\n4 1 3 4 2\n3 3 1 4", "output": "2\n1\n3\n2"}, {"input": "5 5\n2 3 1\n4 5 1 3 2\n4 2 1 3 5\n1 3\n2 5 3", "output": "3\n1\n4\n0\n1"}, {"input": "4 6\n3 4 5 3\n2 6 3\n2 3 6\n3 3 6 5", "output": "0\n0\n2\n1\n1\n2"}]
2,800
["chinese remainder theorem", "data structures", "implementation", "number theory", "two pointers"]
73
[{"input": "3 4\r\n3 3 4 1\r\n4 1 3 4 2\r\n3 3 1 4\r\n", "output": "2\r\n1\r\n3\r\n2\r\n"}, {"input": "5 5\r\n2 3 1\r\n4 5 1 3 2\r\n4 2 1 3 5\r\n1 3\r\n2 5 3\r\n", "output": "3\r\n1\r\n4\r\n0\r\n1\r\n"}, {"input": "4 6\r\n3 4 5 3\r\n2 6 3\r\n2 3 6\r\n3 3 6 5\r\n", "output": "0\r\n0\r\n2\r\n1\r\n1\r\n2\r\n"}, {"input": ...
false
stdio
null
true
908/F
908
F
Python 3
TESTS
3
46
204,800
181818000
class Aresta: def __init__(self,vertice_1,vertice_2,peso): self.vertice_1 = vertice_1 self.vertice_2 = vertice_2 self.peso = peso class Vertice: def __init__(self,cor,posicao): self.cor = cor self.posicao = posicao class Oferta: def __init__(self,x,y,z) : ...
44
1,185
307,200
113258056
#Problem Set F: Collaborated with no one n = int(input()) result = 0 temp = 0 b_red = 0 b_blue = 0 final_red = -1 final_blue = -1 final_green = -(1<<60) for i in range(n): cost_colorList = input().split() cost = int(cost_colorList[0]) color = cost_colorList[1] if color == 'R' or color == 'G':...
Good Bye 2017
CF
2,017
2
256
New Year and Rainbow Roads
Roy and Biv have a set of n points on the infinite number line. Each point has one of 3 colors: red, green, or blue. Roy and Biv would like to connect all the points with some edges. Edges can be drawn between any of the two of the given points. The cost of an edge is equal to the distance between the two points it c...
The first line will contain an integer n (1 ≤ n ≤ 300 000), the number of points. The next n lines will contain two tokens pi and ci (pi is an integer, 1 ≤ pi ≤ 109, ci is a uppercase English letter 'R', 'G' or 'B'), denoting the position of the i-th point and the color of the i-th point. 'R' means red, 'G' denotes gr...
Print a single integer, the minimum cost way to solve the problem.
null
In the first sample, it is optimal to draw edges between the points (1,2), (1,4), (3,4). These have costs 4, 14, 5, respectively.
[{"input": "4\n1 G\n5 R\n10 B\n15 G", "output": "23"}, {"input": "4\n1 G\n2 R\n3 B\n10 G", "output": "12"}]
2,400
["graphs", "greedy", "implementation"]
44
[{"input": "4\r\n1 G\r\n5 R\r\n10 B\r\n15 G\r\n", "output": "23\r\n"}, {"input": "4\r\n1 G\r\n2 R\r\n3 B\r\n10 G\r\n", "output": "12\r\n"}, {"input": "4\r\n1 G\r\n123123 R\r\n987987987 B\r\n1000000000 G\r\n", "output": "1012135134\r\n"}, {"input": "1\r\n3 R\r\n", "output": "0\r\n"}]
false
stdio
null
true
908/F
908
F
Python 3
TESTS
4
62
5,529,600
33905656
n=int(input()) prer=preg=preb=0 ans=ansb=ansr=0 for i in range(n): inp=input().split() pla=int(inp[0]) col=inp[1] if col=='R': if prer<=preg: ansr=pla-preg prer=pla elif col=='B': if preb<=preg: ansb=pla-preg preb=pla else: if preg=...
44
1,388
56,320,000
202729801
""" F. New Year and Rainbow Roads (https://codeforces.com/problemset/problem/908/F) 1. n points, each point has one color: RED, GREEN or BLUE. 2. Roy and Biv wanna connect all points with some edges. 3. The cost of an edge is its distance between another point. 4. All points needs to be connected. (directly or indirec...
Good Bye 2017
CF
2,017
2
256
New Year and Rainbow Roads
Roy and Biv have a set of n points on the infinite number line. Each point has one of 3 colors: red, green, or blue. Roy and Biv would like to connect all the points with some edges. Edges can be drawn between any of the two of the given points. The cost of an edge is equal to the distance between the two points it c...
The first line will contain an integer n (1 ≤ n ≤ 300 000), the number of points. The next n lines will contain two tokens pi and ci (pi is an integer, 1 ≤ pi ≤ 109, ci is a uppercase English letter 'R', 'G' or 'B'), denoting the position of the i-th point and the color of the i-th point. 'R' means red, 'G' denotes gr...
Print a single integer, the minimum cost way to solve the problem.
null
In the first sample, it is optimal to draw edges between the points (1,2), (1,4), (3,4). These have costs 4, 14, 5, respectively.
[{"input": "4\n1 G\n5 R\n10 B\n15 G", "output": "23"}, {"input": "4\n1 G\n2 R\n3 B\n10 G", "output": "12"}]
2,400
["graphs", "greedy", "implementation"]
44
[{"input": "4\r\n1 G\r\n5 R\r\n10 B\r\n15 G\r\n", "output": "23\r\n"}, {"input": "4\r\n1 G\r\n2 R\r\n3 B\r\n10 G\r\n", "output": "12\r\n"}, {"input": "4\r\n1 G\r\n123123 R\r\n987987987 B\r\n1000000000 G\r\n", "output": "1012135134\r\n"}, {"input": "1\r\n3 R\r\n", "output": "0\r\n"}]
false
stdio
null
true
1006/D
1006
D
PyPy 3-64
TESTS
2
140
7,168,000
218217374
import sys input = lambda: sys.stdin.readline().rstrip() import math from heapq import heappush , heappop from collections import defaultdict,deque,Counter from bisect import * N = int(input()) S = input() T = input() def check(C): keys = list(C.keys()) if len(keys)>2: return False if len(keys)==1...
23
77
2,969,600
183641682
n = int(input()) a = input() b = input() ans = 0 for i in range(n//2): sa = [a[i], a[n-i-1]] sb = [b[i], b[n-i-1]] sa.sort() sb.sort() #print(sa, sb) if sb[0] == sb[1]: if not sa[0] == sa[1]: ans += 1 else: if sa[0] == sa[1]: if sa[0] == sb[0] or sa...
Codeforces Round 498 (Div. 3)
ICPC
2,018
2
256
Two Strings Swaps
You are given two strings $$$a$$$ and $$$b$$$ consisting of lowercase English letters, both of length $$$n$$$. The characters of both strings have indices from $$$1$$$ to $$$n$$$, inclusive. You are allowed to do the following changes: - Choose any index $$$i$$$ ($$$1 \le i \le n$$$) and swap characters $$$a_i$$$ and...
The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of strings $$$a$$$ and $$$b$$$. The second line contains the string $$$a$$$ consisting of exactly $$$n$$$ lowercase English letters. The third line contains the string $$$b$$$ consisting of exactly $$$n$$$ lowercase English...
Print a single integer — the minimum number of preprocess moves to apply before changes, so that it is possible to make the string $$$a$$$ equal to string $$$b$$$ with a sequence of changes from the list above.
null
In the first example preprocess moves are as follows: $$$a_1 := $$$'b', $$$a_3 := $$$'c', $$$a_4 := $$$'a' and $$$a_5:=$$$'b'. Afterwards, $$$a = $$$"bbcabba". Then we can obtain equal strings by the following sequence of changes: $$$swap(a_2, b_2)$$$ and $$$swap(a_2, a_6)$$$. There is no way to use fewer than $$$4$$$ ...
[{"input": "7\nabacaba\nbacabaa", "output": "4"}, {"input": "5\nzcabd\ndbacz", "output": "0"}]
1,700
["implementation"]
23
[{"input": "7\r\nabacaba\r\nbacabaa\r\n", "output": "4\r\n"}, {"input": "5\r\nzcabd\r\ndbacz\r\n", "output": "0\r\n"}, {"input": "1\r\na\r\nb\r\n", "output": "1\r\n"}, {"input": "5\r\nahmad\r\nyogaa\r\n", "output": "3\r\n"}]
false
stdio
null
true
1006/D
1006
D
PyPy 3
TESTS
2
155
2,662,400
83916243
""" 616C """ """ 1152B """ # import math # import sys def main(): # n ,m= map(int,input().split()) # arr = list(map(int,input().split())) # b = list(map(int,input().split())) # n = int(input()) # string = str(input()) # TODO: # 1> LEETCODE FIRST PROBLEM WRITE # 2> VALERYINE AND DEQUEUE n = int(input()) str1 =...
23
78
3,584,000
154192240
n=int(input()) a=input() b=input() ans=0 for i in range(n//2): seen=set() if b[i]==b[n-i-1]: if a[i]==a[n-i-1]: ans+=0 else: ans+=1 else : seen.add(b[i]) if b[n-i-1] in seen: seen.remove(b[n-i-1]) else : seen.add(b[n-i-1...
Codeforces Round 498 (Div. 3)
ICPC
2,018
2
256
Two Strings Swaps
You are given two strings $$$a$$$ and $$$b$$$ consisting of lowercase English letters, both of length $$$n$$$. The characters of both strings have indices from $$$1$$$ to $$$n$$$, inclusive. You are allowed to do the following changes: - Choose any index $$$i$$$ ($$$1 \le i \le n$$$) and swap characters $$$a_i$$$ and...
The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of strings $$$a$$$ and $$$b$$$. The second line contains the string $$$a$$$ consisting of exactly $$$n$$$ lowercase English letters. The third line contains the string $$$b$$$ consisting of exactly $$$n$$$ lowercase English...
Print a single integer — the minimum number of preprocess moves to apply before changes, so that it is possible to make the string $$$a$$$ equal to string $$$b$$$ with a sequence of changes from the list above.
null
In the first example preprocess moves are as follows: $$$a_1 := $$$'b', $$$a_3 := $$$'c', $$$a_4 := $$$'a' and $$$a_5:=$$$'b'. Afterwards, $$$a = $$$"bbcabba". Then we can obtain equal strings by the following sequence of changes: $$$swap(a_2, b_2)$$$ and $$$swap(a_2, a_6)$$$. There is no way to use fewer than $$$4$$$ ...
[{"input": "7\nabacaba\nbacabaa", "output": "4"}, {"input": "5\nzcabd\ndbacz", "output": "0"}]
1,700
["implementation"]
23
[{"input": "7\r\nabacaba\r\nbacabaa\r\n", "output": "4\r\n"}, {"input": "5\r\nzcabd\r\ndbacz\r\n", "output": "0\r\n"}, {"input": "1\r\na\r\nb\r\n", "output": "1\r\n"}, {"input": "5\r\nahmad\r\nyogaa\r\n", "output": "3\r\n"}]
false
stdio
null
true
1006/D
1006
D
PyPy 3
TESTS
2
155
4,812,800
120343576
from sys import stdin, stdout from itertools import accumulate nmbr = lambda: int(input()) lst = lambda: list(map(int, input().split())) def fn(x,y,c1,c2): return int(x!=c1)+int(y!=c2) for _ in range(1):#nmbr()): n=nmbr() # n,k=lst() s1=input() s2=input() ans=0 l,r=0,n-1 while l<=r: ...
23
93
512,000
214462808
# LUOGU_RID: 116435796 n=int(input()) a=input() b=input() ans=0 if n%2!=0: if a[n//2]!=b[n//2]: ans+=1 for i in range(n//2): if b[i]==b[n-1-i]: if a[i]!=a[n-1-i]: ans+=1 continue if b[i]!=a[i] and b[i]!=a[n-1-i]: ans+=1 if b[n-1-i]!=a[i] and b[n-1-i]!=a[n-1-i]...
Codeforces Round 498 (Div. 3)
ICPC
2,018
2
256
Two Strings Swaps
You are given two strings $$$a$$$ and $$$b$$$ consisting of lowercase English letters, both of length $$$n$$$. The characters of both strings have indices from $$$1$$$ to $$$n$$$, inclusive. You are allowed to do the following changes: - Choose any index $$$i$$$ ($$$1 \le i \le n$$$) and swap characters $$$a_i$$$ and...
The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of strings $$$a$$$ and $$$b$$$. The second line contains the string $$$a$$$ consisting of exactly $$$n$$$ lowercase English letters. The third line contains the string $$$b$$$ consisting of exactly $$$n$$$ lowercase English...
Print a single integer — the minimum number of preprocess moves to apply before changes, so that it is possible to make the string $$$a$$$ equal to string $$$b$$$ with a sequence of changes from the list above.
null
In the first example preprocess moves are as follows: $$$a_1 := $$$'b', $$$a_3 := $$$'c', $$$a_4 := $$$'a' and $$$a_5:=$$$'b'. Afterwards, $$$a = $$$"bbcabba". Then we can obtain equal strings by the following sequence of changes: $$$swap(a_2, b_2)$$$ and $$$swap(a_2, a_6)$$$. There is no way to use fewer than $$$4$$$ ...
[{"input": "7\nabacaba\nbacabaa", "output": "4"}, {"input": "5\nzcabd\ndbacz", "output": "0"}]
1,700
["implementation"]
23
[{"input": "7\r\nabacaba\r\nbacabaa\r\n", "output": "4\r\n"}, {"input": "5\r\nzcabd\r\ndbacz\r\n", "output": "0\r\n"}, {"input": "1\r\na\r\nb\r\n", "output": "1\r\n"}, {"input": "5\r\nahmad\r\nyogaa\r\n", "output": "3\r\n"}]
false
stdio
null
true
351/E
351
E
Python 3
TESTS
1
62
0
228196194
n = int(input()) sequence = list(map(int, input().split())) positive_count = 0 negative_count = 0 for num in sequence: if num > 0: positive_count += 1 elif num < 0: negative_count += 1 inversions = min(positive_count, negative_count) print(inversions)
36
280
3,686,400
150804902
import sys input = sys.stdin.buffer.readline def process(A): n = len(A) S = [1 for i in range(n)] d = {} for i in range(n): ai = abs(A[i]) if ai not in d: d[ai] = [] d[ai].append(i) L = sorted(d) answer = 0 while len(L) > 0: ai = L.pop() f...
Codeforces Round 204 (Div. 1)
CF
2,013
2
256
Jeff and Permutation
Jeff's friends know full well that the boy likes to get sequences and arrays for his birthday. Thus, Jeff got sequence p1, p2, ..., pn for his birthday. Jeff hates inversions in sequences. An inversion in sequence a1, a2, ..., an is a pair of indexes i, j (1 ≤ i < j ≤ n), such that an inequality ai > aj holds. Jeff c...
The first line contains integer n (1 ≤ n ≤ 2000). The next line contains n integers — sequence p1, p2, ..., pn (|pi| ≤ 105). The numbers are separated by spaces.
In a single line print the answer to the problem — the minimum number of inversions Jeff can get.
null
null
[{"input": "2\n2 1", "output": "0"}, {"input": "9\n-2 0 -1 0 -1 2 1 0 -1", "output": "6"}]
2,200
["greedy"]
36
[{"input": "2\r\n2 1\r\n", "output": "0\r\n"}, {"input": "9\r\n-2 0 -1 0 -1 2 1 0 -1\r\n", "output": "6\r\n"}, {"input": "9\r\n0 0 1 1 0 0 1 0 1\r\n", "output": "5\r\n"}, {"input": "8\r\n0 1 2 -1 -2 1 -2 2\r\n", "output": "3\r\n"}, {"input": "24\r\n-1 -1 2 2 0 -2 2 -1 0 0 2 -2 3 0 2 -3 0 -3 -1 1 0 0 -1 -2\r\n", "output...
false
stdio
null
true
68/B
68
B
Python 3
TESTS
2
154
5,529,600
33962531
n, k = map(int, input().split()) a = list(map(int, input().split())) result = sum(a)/n eps = 0.0000000001 while True: transferred = (100-k)/100 * sum(map(lambda x: x-result if x-result>0 else 0, a)) missing = sum(map(lambda x: result-x if result-x>0 else 0, a)) if abs(transferred - missing) < eps: ...
42
154
3,072,000
194515194
import bisect I = lambda: list(map(int, input().split())) n, k = I() k /= 100 a = I() l = 0 r = 1000 sumie = sum(a) while r - l > 1e-7: mid = (l+r) / 2 sum_transfer = 0 for x in a: if x > mid: sum_transfer += x-mid if n*mid < sumie - sum_transfer*k: l = mid else: ...
Codeforces Beta Round 62
CF
2,011
2
256
Energy exchange
It is well known that the planet suffers from the energy crisis. Little Petya doesn't like that and wants to save the world. For this purpose he needs every accumulator to contain the same amount of energy. Initially every accumulator has some amount of energy: the i-th accumulator has ai units of energy. Energy can be...
First line of the input contains two integers n and k (1 ≤ n ≤ 10000, 0 ≤ k ≤ 99) — number of accumulators and the percent of energy that is lost during transfers. Next line contains n integers a1, a2, ... , an — amounts of energy in the first, second, .., n-th accumulator respectively (0 ≤ ai ≤ 1000, 1 ≤ i ≤ n).
Output maximum possible amount of energy that can remain in each of accumulators after the transfers of energy. The absolute or relative error in the answer should not exceed 10 - 6.
null
null
[{"input": "3 50\n4 2 1", "output": "2.000000000"}, {"input": "2 90\n1 11", "output": "1.909090909"}]
1,600
["binary search"]
42
[{"input": "3 50\r\n4 2 1\r\n", "output": "2.000000000\r\n"}, {"input": "2 90\r\n1 11\r\n", "output": "1.909090909\r\n"}, {"input": "5 26\r\n42 65 23 43 64\r\n", "output": "45.415178571\r\n"}, {"input": "5 45\r\n964 515 454 623 594\r\n", "output": "594.109756098\r\n"}, {"input": "1 20\r\n784\r\n", "output": "784.000000...
false
stdio
import sys def main(): input_path = sys.argv[1] output_path = sys.argv[2] submission_path = sys.argv[3] # Read reference output with open(output_path, 'r') as f: ref_line = f.readline().strip() try: E_ref = float(ref_line) except: print(0) ...
true
509/C
509
C
Python 3
TESTS
3
93
307,200
89816479
import math n = int(input()) last=0 for i in range(n): a = int(input()) dig = math.ceil(a/9) s='' if i==0: while a>9: s += '9' a-=9 s += str(a) last = int(s) print(last) else: while a>9: s += '9' a-=9 s ...
21
93
5,427,200
153762868
import sys def get_max(su, le): div, mod = divmod(su, 9) ret = ['9'] * div if mod: ret = [str(mod)] + ret if le - len(ret) > 0: x = str(int(ret.pop(0)) - 1) ret = ['1', x] + ret if le - len(ret) > 0: ret = [ret[0]] + ['0'] * (le - len(ret)) + ret[1:] ...
Codeforces Round 289 (Div. 2, ACM ICPC Rules)
ICPC
2,015
2
256
Sums of Digits
Vasya had a strictly increasing sequence of positive integers a1, ..., an. Vasya used it to build a new sequence b1, ..., bn, where bi is the sum of digits of ai's decimal representation. Then sequence ai got lost and all that remained is sequence bi. Vasya wonders what the numbers ai could be like. Of all the possibl...
The first line contains a single integer number n (1 ≤ n ≤ 300). Next n lines contain integer numbers b1, ..., bn  — the required sums of digits. All bi belong to the range 1 ≤ bi ≤ 300.
Print n integer numbers, one per line — the correct option for numbers ai, in order of following in sequence. The sequence should be strictly increasing. The sum of digits of the i-th number should be equal to bi. If there are multiple sequences with least possible number an, print any of them. Print the numbers witho...
null
null
[{"input": "3\n1\n2\n3", "output": "1\n2\n3"}, {"input": "3\n3\n2\n1", "output": "3\n11\n100"}]
2,000
["dp", "greedy", "implementation"]
21
[{"input": "3\r\n1\r\n2\r\n3\r\n", "output": "1\r\n2\r\n3\r\n"}, {"input": "3\r\n3\r\n2\r\n1\r\n", "output": "3\r\n11\r\n100\r\n"}, {"input": "10\r\n1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n1\r\n", "output": "1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n"}, {"input": "10\r\n8\r\n8\r\n5\r\n1\r\n2\r\n7\r\n3\r\n...
false
stdio
null
true
1006/D
1006
D
PyPy 3
TESTS
2
124
3,993,600
116210236
from sys import stdin from collections import Counter input = stdin.readline n = int(input()) a = input().rstrip() b = input().rstrip() ans = 0 for i in range(n // 2): x = [a[i], a[n-i-1], b[i], b[n-i-1]] c = Counter(x) y = c.values() if len(y) == 4: ans += 2 elif len(y) == 3: if x[...
23
93
2,457,600
197431902
# https://codeforces.com/contest/1006 import sys input = lambda: sys.stdin.readline().rstrip() # faster! def solve_case(): n = int(input()) a = input() b = input() ans = 0 for i in range(n // 2): l = len({a[i], a[n - 1 - i], b[i], b[n - 1 - i]}) if l == 1: ans += 0 ...
Codeforces Round 498 (Div. 3)
ICPC
2,018
2
256
Two Strings Swaps
You are given two strings $$$a$$$ and $$$b$$$ consisting of lowercase English letters, both of length $$$n$$$. The characters of both strings have indices from $$$1$$$ to $$$n$$$, inclusive. You are allowed to do the following changes: - Choose any index $$$i$$$ ($$$1 \le i \le n$$$) and swap characters $$$a_i$$$ and...
The first line of the input contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of strings $$$a$$$ and $$$b$$$. The second line contains the string $$$a$$$ consisting of exactly $$$n$$$ lowercase English letters. The third line contains the string $$$b$$$ consisting of exactly $$$n$$$ lowercase English...
Print a single integer — the minimum number of preprocess moves to apply before changes, so that it is possible to make the string $$$a$$$ equal to string $$$b$$$ with a sequence of changes from the list above.
null
In the first example preprocess moves are as follows: $$$a_1 := $$$'b', $$$a_3 := $$$'c', $$$a_4 := $$$'a' and $$$a_5:=$$$'b'. Afterwards, $$$a = $$$"bbcabba". Then we can obtain equal strings by the following sequence of changes: $$$swap(a_2, b_2)$$$ and $$$swap(a_2, a_6)$$$. There is no way to use fewer than $$$4$$$ ...
[{"input": "7\nabacaba\nbacabaa", "output": "4"}, {"input": "5\nzcabd\ndbacz", "output": "0"}]
1,700
["implementation"]
23
[{"input": "7\r\nabacaba\r\nbacabaa\r\n", "output": "4\r\n"}, {"input": "5\r\nzcabd\r\ndbacz\r\n", "output": "0\r\n"}, {"input": "1\r\na\r\nb\r\n", "output": "1\r\n"}, {"input": "5\r\nahmad\r\nyogaa\r\n", "output": "3\r\n"}]
false
stdio
null
true
436/C
436
C
Python 3
TESTS
2
108
307,200
48892505
import heapq import math import sys def find_parent(a): if parents[a] != a: parents[a] = find_parent(parents[a]) return parents[a] def make_union(a, b): pa = find_parent(a) pb = find_parent(b) if pa == pb: return False ra = ranks[pa] rb = ranks[pb] if ra <= rb: ...
30
1,964
62,873,600
232798881
import heapq total_bytes = 0 messages_sent = [] def send_message(messages, weight, start_ind): global total_bytes global messages_sent num_messages = len(messages) num_rows = len(messages[1]) num_cols = len(messages[1][0]) sent = [False] * num_messages # Send the first message tota...
Zepto Code Rush 2014
CF
2,014
2
256
Dungeons and Candies
During the loading of the game "Dungeons and Candies" you are required to get descriptions of k levels from the server. Each description is a map of an n × m checkered rectangular field. Some cells of the field contain candies (each cell has at most one candy). An empty cell is denoted as "." on the map, but if a cell ...
The first line contains four integers n, m, k, w (1 ≤ n, m ≤ 10; 1 ≤ k, w ≤ 1000). Then follows the description of k levels. Each level is described by n lines, each line contains m characters. Each character is either a letter of the English alphabet or a dot ("."). Please note that the case of the letters matters.
In the first line print the required minimum number of transferred bytes. Then print k pairs of integers x1, y1, x2, y2, ..., xk, yk, describing the way to transfer levels. Pair xi, yi means that level xi needs to be transferred by way yi. If yi equals 0, that means that the level must be transferred using the first w...
null
null
[{"input": "2 3 3 2\nA.A\n...\nA.a\n..C\nX.Y\n...", "output": "14\n1 0\n2 1\n3 1"}, {"input": "1 1 4 1\nA\n.\nB\n.", "output": "3\n1 0\n2 0\n4 2\n3 0"}, {"input": "1 3 5 2\nABA\nBBB\nBBA\nBAB\nABB", "output": "11\n1 0\n3 1\n2 3\n4 2\n5 1"}]
1,800
["dsu", "graphs", "greedy", "trees"]
30
[{"input": "2 3 3 2\r\nA.A\r\n...\r\nA.a\r\n..C\r\nX.Y\r\n...\r\n", "output": "14\r\n1 0\r\n2 1\r\n3 1\r\n"}, {"input": "1 1 4 1\r\nA\r\n.\r\nB\r\n.\r\n", "output": "3\r\n1 0\r\n2 0\r\n4 2\r\n3 0\r\n"}, {"input": "1 3 5 2\r\nABA\r\nBBB\r\nBBA\r\nBAB\r\nABB\r\n", "output": "11\r\n1 0\r\n3 1\r\n2 3\r\n4 2\r\n5 1\r\n"}, {...
false
stdio
import sys def read_levels(input_path): with open(input_path) as f: lines = [line.strip() for line in f.readlines() if line.strip()] first_line = lines[0].split() n, m, k, w = map(int, first_line) levels = [None] # 1-based indexing idx = 1 for _ in range(k): level = [] ...
true